2022-11-28 23:47:44 +11:00
|
|
|
!
|
|
|
|
! project "gravity field"
|
|
|
|
!
|
|
|
|
!-----------------------------------------------------------------------
|
|
|
|
module realfield
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
!-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
function compute_gravity(ix, iy, body)
|
|
|
|
|
|
|
|
integer, intent(in) :: ix, iy
|
|
|
|
type(massbody), intent(in) :: body
|
|
|
|
real :: compute_gravity
|
|
|
|
real :: rx, ry, dist
|
|
|
|
|
|
|
|
rx = real(ix) - body%posx
|
|
|
|
ry = real(iy) - body%posy
|
|
|
|
|
|
|
|
dist = sqrt( (rx*rx) + (ry*ry) )
|
|
|
|
if (dist .LT. 0.15) then
|
|
|
|
write (0, *) "dist too small ", dist
|
|
|
|
compute_gravity = 0e0
|
|
|
|
endif
|
|
|
|
|
|
|
|
compute_gravity = body%mass * (dist ** 2)
|
|
|
|
|
|
|
|
end function
|
|
|
|
|
|
|
|
!-----------------------------------------------------------------------
|
|
|
|
!-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
end module
|