2022-11-28 23:47:44 +11:00
|
|
|
!
|
|
|
|
! project "gravity field"
|
|
|
|
!
|
|
|
|
!-----------------------------------------------------------------------
|
|
|
|
module realfield
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
!-----------------------------------------------------------------------
|
2022-11-30 12:52:16 +11:00
|
|
|
! definition of structures
|
|
|
|
!
|
2022-11-28 23:47:44 +11:00
|
|
|
type massbody
|
|
|
|
real :: posx, posy
|
2022-11-30 06:31:45 +11:00
|
|
|
real :: mass = 1.0
|
|
|
|
integer :: serial = 666
|
2022-11-28 23:47:44 +11:00
|
|
|
end type
|
|
|
|
|
|
|
|
!-----------------------------------------------------------------------
|
|
|
|
contains
|
2022-11-30 06:31:45 +11:00
|
|
|
!-----------------------------------------------------------------------
|
2022-11-28 23:47:44 +11:00
|
|
|
|
2022-11-30 12:52:16 +11:00
|
|
|
function compute_gravity(fx, fy, body)
|
|
|
|
real, intent(in) :: fx, fy
|
2022-11-28 23:47:44 +11:00
|
|
|
type(massbody), intent(in) :: body
|
|
|
|
real :: compute_gravity
|
2022-11-30 12:52:16 +11:00
|
|
|
real :: rx, ry, dist
|
2022-11-28 23:47:44 +11:00
|
|
|
|
2022-11-30 12:52:16 +11:00
|
|
|
rx = fx - body%posx
|
|
|
|
ry = fy - body%posy
|
2022-11-28 23:47:44 +11:00
|
|
|
dist = sqrt( (rx*rx) + (ry*ry) )
|
2022-11-30 12:52:16 +11:00
|
|
|
if (dist .LT. 4.50) then
|
2022-11-28 23:47:44 +11:00
|
|
|
write (0, *) "dist too small ", dist
|
|
|
|
compute_gravity = 0e0
|
|
|
|
endif
|
2022-11-30 12:52:16 +11:00
|
|
|
compute_gravity = body%mass / (dist ** 2)
|
2022-11-28 23:47:44 +11:00
|
|
|
|
|
|
|
end function
|
|
|
|
|
|
|
|
!-----------------------------------------------------------------------
|
|
|
|
!-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
end module
|