77 REAL,
DIMENSION(:,:,:),
POINTER :: r_sec
78 REAL,
DIMENSION(:,:,:,:),
POINTER :: posvec_sec
79 REAL,
DIMENSION(:,:,:,:),
POINTER :: posvec_sec_tmp
80 REAL,
DIMENSION(:,:,:,:),
POINTER :: fr_sec
81 REAL,
DIMENSION(:,:,:,:,:),
POINTER :: fposvec_sec
82 REAL,
POINTER :: mass2
89 REAL,
DIMENSION(:,:,:,:),
POINTER :: pot_sec
118 CLASS(gravity_binary),
INTENT(INOUT) :: this
119 CLASS(mesh_base),
INTENT(IN) :: Mesh
120 CLASS(physics_base),
INTENT(IN) :: Physics
121 TYPE(Dict_TYP),
POINTER :: config
123 TYPE(Dict_TYP),
POINTER :: IO
129 CALL this%InitGravity(mesh,physics,
"binary point masses",config,io)
137 CALL this%Error(
"InitGravity_binary", &
138 "Physics not supported for binary gravity term")
142 this%mass,this%mass2,this%pos(3,2),this%r0(3), &
143 this%omega2(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,2), &
144 this%omega(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX), &
145 this%r_prim(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX),&
146 this%r_sec(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX),&
147 this%posvec_prim(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,3),&
148 this%posvec_prim_tmp(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,3),&
149 this%posvec_sec(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,3),&
150 this%posvec_sec_tmp(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,3),&
151 this%pot(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,4), &
152 this%pot_prim(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,4), &
153 this%pot_sec(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,4), &
154 this%fr_prim(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,3), &
155 this%fr_sec(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,3), &
156 this%fposvec_prim(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,3,3),&
157 this%fposvec_sec(mesh%IGMIN:mesh%IGMAX,mesh%JGMIN:mesh%JGMAX,mesh%KGMIN:mesh%KGMAX,3,3),&
159 IF (err.NE.0)
CALL this%Error(
"InitGravity_pointmass",
"Unable allocate memory!")
162 CALL getattr(config,
"mass1", this%mass, 1.0)
163 CALL setattr(io,
"mass1", ref(this%mass))
166 CALL getattr(config,
"mass2", this%mass2, 1.0)
167 CALL setattr(io,
"mass2", ref(this%mass2))
170 CALL getattr(config,
"excentricity", this%excent, 0.0)
173 CALL getattr(config,
"semimayoraxis", this%semaaxis, 1.0)
176 CALL getattr(config,
"softening1", this%eps1, 0.0)
178 CALL getattr(config,
"softening2", this%eps2, 0.0)
181 CALL getattr(config,
"switchon1", this%switchon, -1.0)
184 CALL getattr(config,
"switchon2", this%switchon2, -1.0)
187 CALL getattr(config,
"omega_rot", this%omega_rot, 0.0)
190 CALL getattr(config,
"mesh_rot", mesh_rot, 0)
191 IF (mesh_rot.EQ.1)
THEN 192 this%omega_rot = mesh%OMEGA
193 this%r0(:) = mesh%rotcent(:)
194 IF (mesh%omega.EQ.0.0) &
195 CALL this%Warning(
"InitGravity_binary",
"Rotating mesh enabled but OMEGA set to zero in mesh")
204 this%period = 2.*pi*sqrt(this%semaaxis/(this%mass+this%mass2)/physics%constants%GN)*this%semaaxis
216 this%omega(mesh%IGMIN:mesh%IMIN+mesh%IM1,:,:) = 1.0
217 this%omega(mesh%IMAX+mesh%IP1:mesh%IGMAX,:,:) = 1.0
218 this%omega(:,mesh%JGMIN:mesh%JMIN+mesh%JM1,:) = 1.0
219 this%omega(:,mesh%JMAX+mesh%JP1:mesh%JGMAX,:) = 1.0
220 this%omega(:,:,mesh%KGMIN:mesh%KMIN+mesh%KM1) = 1.0
221 this%omega(:,:,mesh%KMAX+mesh%KP1:mesh%KGMAX) = 1.0
224 CALL this%SetOutput(mesh,physics,config,io)
225 CALL this%InfoGravity()
234 CLASS(gravity_binary),
INTENT(IN) :: this
236 CHARACTER(LEN=32) :: mass1_str,mass2_str,excent_str,sema_str,omega_str
238 WRITE (mass1_str,
'(ES8.2)') this%mass
239 WRITE (mass2_str,
'(ES8.2)') this%mass2
240 WRITE (excent_str,
'(ES8.2)') this%excent
241 WRITE (sema_str,
'(ES8.2)') this%semaaxis
242 CALL this%Info(
" primary mass: " // trim(mass1_str))
243 CALL this%Info(
" secondary mass: " // trim(mass2_str))
244 CALL this%Info(
" excentricity: " // trim(excent_str))
245 CALL this%Info(
" semi major axis: " // trim(sema_str))
246 IF(this%period.NE.0.0)
THEN 247 WRITE(omega_str,
'(ES8.2)') 2.0*pi/this%period
248 CALL this%Info(
" pattern speed: " // trim(omega_str))
253 SUBROUTINE setoutput(this,Mesh,Physics,config,IO)
256 CLASS(gravity_binary),
INTENT(INOUT) :: this
257 CLASS(mesh_base),
INTENT(IN) :: Mesh
258 CLASS(physics_base),
INTENT(IN) :: Physics
259 TYPE(Dict_TYP),
POINTER :: config,IO
264 CALL this%gravity_pointmass%SetOutput(mesh,physics,config,io)
267 CALL getattr(config,
"output/binpos", valwrite, 0)
268 IF (valwrite .EQ. 1) &
269 CALL setattr(io,
"binpos", this%pos)
286 CLASS(gravity_binary),
INTENT(INOUT) :: this
287 CLASS(mesh_base),
INTENT(IN) :: Mesh
288 CLASS(physics_base),
INTENT(IN) :: Physics
289 CLASS(fluxes_base),
INTENT(IN) :: Fluxes
290 CLASS(marray_compound),
INTENT(INOUT) :: pvar
291 REAL,
INTENT(IN) :: time,dt
297 CALL this%UpdatePositions(time)
301 this%posvec_prim_tmp(:,:,:,1) = this%pos(1,1)
302 this%posvec_prim_tmp(:,:,:,2) = this%pos(2,1)
303 this%posvec_prim_tmp(:,:,:,3) = this%pos(3,1)
304 CALL mesh%Geometry%Convert2Curvilinear(mesh%curv%faces(:,:,:,east,:),this%posvec_prim_tmp(:,:,:,:),this%fposvec_prim(:,:,:,1,:))
305 CALL mesh%Geometry%Convert2Curvilinear(mesh%curv%faces(:,:,:,north,:),this%posvec_prim_tmp(:,:,:,:),this%fposvec_prim(:,:,:,2,:))
306 CALL mesh%Geometry%Convert2Curvilinear(mesh%curv%faces(:,:,:,top,:),this%posvec_prim_tmp(:,:,:,:),this%fposvec_prim(:,:,:,3,:))
307 CALL mesh%Geometry%Convert2Curvilinear(mesh%bcenter,this%posvec_prim_tmp,this%posvec_prim)
309 this%posvec_sec_tmp(:,:,:,1) = this%pos(1,2)
310 this%posvec_sec_tmp(:,:,:,2) = this%pos(2,2)
311 this%posvec_sec_tmp(:,:,:,3) = this%pos(3,2)
312 CALL mesh%Geometry%Convert2Curvilinear(mesh%curv%faces(:,:,:,east,:),this%posvec_sec_tmp(:,:,:,:),this%fposvec_sec(:,:,:,1,:))
313 CALL mesh%Geometry%Convert2Curvilinear(mesh%curv%faces(:,:,:,north,:),this%posvec_sec_tmp(:,:,:,:),this%fposvec_sec(:,:,:,2,:))
314 CALL mesh%Geometry%Convert2Curvilinear(mesh%curv%faces(:,:,:,top,:),this%posvec_sec_tmp(:,:,:,:),this%fposvec_sec(:,:,:,3,:))
315 CALL mesh%Geometry%Convert2Curvilinear(mesh%bcenter,this%posvec_sec_tmp,this%posvec_sec)
321 this%posvec_prim(:,:,:,:) = mesh%posvec%bcenter(:,:,:,:) - this%posvec_prim(:,:,:,:)
322 this%fposvec_prim(:,:,:,1,:) = mesh%posvec%faces(:,:,:,east,:) - this%fposvec_prim(:,:,:,1,:)
323 this%fposvec_prim(:,:,:,2,:) = mesh%posvec%faces(:,:,:,north,:) - this%fposvec_prim(:,:,:,2,:)
324 this%fposvec_prim(:,:,:,3,:) = mesh%posvec%faces(:,:,:,top,:) - this%fposvec_prim(:,:,:,3,:)
326 this%posvec_sec(:,:,:,:) = mesh%posvec%bcenter(:,:,:,:) - this%posvec_sec(:,:,:,:)
327 this%fposvec_sec(:,:,:,1,:) = mesh%posvec%faces(:,:,:,east,:) - this%fposvec_sec(:,:,:,1,:)
328 this%fposvec_sec(:,:,:,2,:) = mesh%posvec%faces(:,:,:,north,:) - this%fposvec_sec(:,:,:,2,:)
329 this%fposvec_sec(:,:,:,3,:) = mesh%posvec%faces(:,:,:,top,:) - this%fposvec_sec(:,:,:,3,:)
333 this%r_prim(:,:,:) = sqrt(this%posvec_prim(:,:,:,1)**2+this%posvec_prim(:,:,:,2)**2+this%posvec_prim(:,:,:,3)**2)
334 this%fr_prim(:,:,:,1) = sqrt(this%fposvec_prim(:,:,:,1,1)**2+this%fposvec_prim(:,:,:,1,2)**2+this%fposvec_prim(:,:,:,1,3)**2)
335 this%fr_prim(:,:,:,2) = sqrt(this%fposvec_prim(:,:,:,2,1)**2+this%fposvec_prim(:,:,:,2,2)**2+this%fposvec_prim(:,:,:,2,3)**2)
336 this%fr_prim(:,:,:,3) = sqrt(this%fposvec_prim(:,:,:,3,1)**2+this%fposvec_prim(:,:,:,3,2)**2+this%fposvec_prim(:,:,:,3,3)**2)
337 this%r_sec(:,:,:) = sqrt(this%posvec_sec(:,:,:,1)**2+this%posvec_sec(:,:,:,2)**2+this%posvec_sec(:,:,:,3)**2)
338 this%fr_sec(:,:,:,1) = sqrt(this%fposvec_sec(:,:,:,1,1)**2+this%fposvec_sec(:,:,:,1,2)**2+this%fposvec_sec(:,:,:,1,3)**2)
339 this%fr_sec(:,:,:,2) = sqrt(this%fposvec_sec(:,:,:,2,1)**2+this%fposvec_sec(:,:,:,2,2)**2+this%fposvec_sec(:,:,:,2,3)**2)
340 this%fr_sec(:,:,:,3) = sqrt(this%fposvec_sec(:,:,:,3,1)**2+this%fposvec_sec(:,:,:,3,2)**2+this%fposvec_sec(:,:,:,3,3)**2)
344 gm1 = physics%Constants%GN*this%GetMass_primary(time)
345 this%omega2(:,:,:,1) = gm1 / (this%r_prim(:,:,:)**3 + this%eps1**3)
348 gm2 = physics%Constants%GN*this%GetMass_secondary(time)
349 this%omega2(:,:,:,2) = gm2 / (this%r_sec(:,:,:)**3 + this%eps2**3)
352 CALL this%gravity_pointmass%CalcPotential(mesh,physics,this%mass,this%r_prim,this%fr_prim,this%pot_prim)
353 CALL this%gravity_pointmass%CalcPotential(mesh,physics,this%mass2,this%r_sec,this%fr_sec,this%pot_sec)
355 this%pot(:,:,:,:) = this%pot_prim(:,:,:,:) + this%pot_sec(:,:,:,:)
359 DO k=mesh%KGMIN,mesh%KGMAX
360 DO j=mesh%JGMIN,mesh%JGMAX
362 DO i=mesh%IGMIN,mesh%IGMAX
363 this%accel%data4d(i,j,k,1:physics%VDIM) = -this%omega2(i,j,k,1) * this%posvec_prim(i,j,k,1:physics%VDIM)&
364 -this%omega2(i,j,k,2) * this%posvec_sec(i,j,k,1:physics%VDIM)
440 CLASS(gravity_binary),
INTENT(INOUT) :: this
441 REAL,
INTENT(IN) :: time
443 REAL :: E,cosE,r,phi,r1
445 REAL,
DIMENSION(2):: plist
449 tau = 2.*pi*modulo(time,this%period)/this%period
456 IF ((tau.GE.0.0) .AND. (tau.LE.pi))
THEN 458 CALL getroot(
func,max(0.0,tau),min(pi,excent+tau),e,err,plist)
461 CALL getroot(
func,max(pi,tau-excent),min(2.*pi,tau),e,err,plist)
464 CALL this%Error(
"UpdatePositions_binary",
"Error in root finding!")
469 r = this%semaaxis * (1.0 - excent*cose)
474 IF (cose.NE.-1.0)
THEN 475 phi = 2.0*atan(sign(sqrt(((1.+excent)*(1.-cose)) &
476 /((1.-excent)*(1.+cose))),pi-e))
483 phi = phi - this%omega_rot * time
487 r1 = this%mass/(this%mass+this%mass2)*r
488 this%pos(1,2) = r1*cos(phi)
489 this%pos(2,2) = r1*sin(phi)
492 this%pos(:,1) = -this%pos(:,2) * this%mass2/this%mass
494 this%pos(:,1) = this%pos(:,1) + this%r0(:)
495 this%pos(:,2) = this%pos(:,2) + this%r0(:)
517 TYPE(
marray_base),
INTENT(INOUT) :: bccsound,h_ext,height
520 this%omega(:,:,:) = sqrt(
this%omega2(:,:,:,1) +
this%omega2(:,:,:,2))
531 REAL,
INTENT(IN) :: time
535 IF(time.LE.
this%switchon)
THEN 536 mass =
this%mass * sin(0.5*pi*time/
this%switchon)**2
547 REAL,
INTENT(IN) :: time
551 IF(time.LE.
this%switchon2)
THEN 552 mass =
this%mass2 * sin(0.5*pi*time/
this%switchon2)**2
562 CLASS(gravity_binary),
INTENT(INOUT) :: this
564 DEALLOCATE(this%mass,this%mass2,this%pos,this%r0,this%omega2,this%omega,&
565 this%r_prim,this%r_sec,this%posvec_prim,this%posvec_prim_tmp, &
566 this%posvec_sec,this%posvec_sec_tmp,this%pot,&
567 this%pot_prim,this%pot_sec,this%fr_prim,this%fr_sec,this%fposvec_prim, &
570 CALL this%Finalize_base()
575 PURE SUBROUTINE func(x,fx,plist)
578 REAL,
INTENT(IN) :: x
579 REAL,
INTENT(IN),
DIMENSION(:),
OPTIONAL :: plist
581 REAL,
INTENT(OUT) :: fx
583 fx = x - plist(1)*sin(x) - plist(2)
subroutine finalize(this)
Destructor of common class.
subroutine infogravity(this)
write binary parameters to screen
subroutine initgravity_binary(this, Mesh, Physics, config, IO)
Constructor of gravity binary module.
type(logging_base), save this
derived class for compound of mesh arrays
base class for mesh arrays
real function getmass_secondary(this, time)
get mass of the primary component, eventually scaled by switch on factor
subroutine updatepositions(this, time)
compute new positions for both components of the binary system
source terms module for gravitational acceleration due to a point mass at the center of the coordinat...
generic gravity terms module providing functionaly common to all gravity terms
subroutine setoutput(this, Mesh, Physics, config, IO)
pure subroutine calcdiskheight_single(this, Mesh, Physics, pvar, bccsound, h_ext, height)
compute the pressure scale height of a disk for the binary potential
subroutine updategravity_single(this, Mesh, Physics, Fluxes, pvar, time, dt)
calculates the resultant gravitational accerleration of a binary system
physics module for 1D,2D and 3D isothermal Euler equations
named integer constants for flavour of state vectors
Dictionary for generic data types.
physics module for 1D,2D and 3D non-isothermal Euler equations
real function getmass_primary(this, time)
get mass of the primary component, eventually scaled by switch on factor
elemental real function, public getdiskheight(cs, omega)
return pressure scale height of a geometrically thin Keplerian disk
base module for numerical flux functions
pure subroutine func(x, fx, plist)
find root of the Kepler equation
source terms module for gravitational acceleration due to two pointmasses