27 use,
intrinsic :: iso_fortran_env
43 real(real64),
pointer :: system_mass(:) => null()
44 real(real64),
pointer :: system_pos(:,:) => null()
46 integer,
public :: partner_np = 0
47 real(real64),
allocatable,
public :: partner_mass(:)
48 real(real64),
allocatable,
public :: partner_pos(:,:)
64 class(interaction_partner_t),
target,
intent(inout) :: partner
65 class(gravity_t),
pointer :: this
71 this%label =
"gravity"
73 this%partner => partner
77 this%system_quantities = [
character(8) ::
"position",
"mass"]
80 this%couplings_from_partner = [
character(8) ::
"position",
"mass"]
86 subroutine gravity_init(this, dim, system_np, system_mass, system_pos)
87 class(gravity_t),
intent(inout) :: this
88 integer,
intent(in) :: dim
89 integer,
intent(in) :: system_np
90 real(real64),
target,
intent(in) :: system_mass(:)
91 real(real64),
target,
intent(in) :: system_pos(:,:)
96 this%system_np = system_np
97 safe_allocate(this%force(1:dim, 1:system_np))
99 this%system_mass => system_mass
100 this%system_pos => system_pos
107 class(gravity_t),
intent(inout) :: this
110 real(real64),
parameter :: GG = 6.67430e-11_real64
111 real(real64) :: dist3
114 assert(
allocated(this%partner_mass))
115 assert(
allocated(this%partner_pos))
117 do ip = 1, this%system_np
118 do jp = 1, this%partner_np
119 if (this%intra_interaction .and. ip == jp ) cycle
121 dist3 = sum((this%partner_pos(1:this%dim, jp) - this%system_pos(1:this%dim, ip))**2)**(
m_three/
m_two)
123 this%force(1:this%dim, ip) = (this%partner_pos(1:this%dim, jp) - this%system_pos(1:this%dim, ip)) &
124 / (dist3 +
m_epsilon) * (gg * this%system_mass(ip) * this%partner_mass(jp))
133 class(gravity_t),
intent(inout) :: this
136 real(real64),
parameter :: gg = 6.67430e-11_real64
141 assert(
allocated(this%partner_mass))
142 assert(
allocated(this%partner_pos))
145 do ip = 1, this%system_np
146 do jp = 1, this%partner_np
147 if (this%intra_interaction .and. ip == jp ) cycle
149 dist =
sqrt(sum((this%partner_pos(1:this%dim, jp) - this%system_pos(1:this%dim, ip))**2))
151 this%energy = this%energy -
m_half / (dist +
m_epsilon) * (gg * this%system_mass(ip) * this%partner_mass(jp))
166 nullify(this%system_mass)
167 nullify(this%system_pos)
168 safe_deallocate_a(this%partner_pos)
169 safe_deallocate_a(this%partner_mass)
170 safe_deallocate_a(this%force)
double sqrt(double __x) __attribute__((__nothrow__
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_half
real(real64), parameter, public m_three
subroutine gravity_calculate_energy(this)
subroutine gravity_calculate(this)
class(gravity_t) function, pointer gravity_constructor(partner)
subroutine gravity_init(this, dim, system_np, system_mass, system_pos)
subroutine gravity_finalize(this)
This module defines the abstract interaction_t class, and some auxiliary classes for interactions.
subroutine, public interaction_end(this)
This module defines classes and functions for interaction partners.
Gravity interaction between two systems of particles. This should be used for testing purposes only....