Skip to content

Commit

Permalink
Add wind tests to the test suite (non dusty winds)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsiess committed Jul 4, 2023
1 parent 4fb4649 commit fdbdff2
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 10 deletions.
4 changes: 3 additions & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -685,13 +685,15 @@ else
SRCTESTMPI =
endif

SRCTESTWIND= wind_equations.F90 wind.F90 inject_wind.f90

SRCTESTS=utils_testsuite.f90 ${TEST_FASTMATH} test_kernel.f90 \
test_dust.F90 test_growth.f90 test_smol.F90 \
test_nonidealmhd.F90 directsum.f90 test_gravity.f90 \
test_derivs.F90 test_cooling.f90 test_eos_stratified.f90 \
test_eos.f90 test_externf.f90 test_rwdump.f90 \
test_step.F90 test_indtstep.F90 set_disc.F90 test_setdisc.F90 \
test_hierarchical.f90 test_damping.f90 \
test_hierarchical.f90 test_damping.f90 $(SRCTESTWIND) test_wind.f90 \
test_link.F90 test_kdtree.F90 test_part.f90 test_ptmass.f90 test_luminosity.F90\
test_gnewton.f90 test_corotate.f90 test_geometry.f90 \
${SRCTESTMPI} test_sedov.F90 test_poly.f90 test_radiation.F90 \
Expand Down
2 changes: 2 additions & 0 deletions build/Makefile_setups
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@ ifeq ($(SETUP), test)
MHD=yes
DUST=yes
RADIATION=yes
SINK_RADIATION=yes
INJECT_PARTICLES=yes
KERNEL=cubic
endif

Expand Down
12 changes: 6 additions & 6 deletions src/main/inject_wind.F90
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ module inject
real:: wind_temperature
#else
integer:: sonic_type = 0
real:: wind_velocity_km_s = 30.
real:: wind_mass_rate_Msun_yr = 1.d-8
real:: wind_injection_radius_au = 1.1
real:: wind_temperature = 3000.
real:: wind_velocity_km_s = 20.
real:: wind_mass_rate_Msun_yr = 1.d-5
real:: wind_injection_radius_au = 2.
real:: wind_temperature = 2500.
#endif
integer :: iboundary_spheres = 5
integer :: iwind_resolution = 10
integer :: nfill_domain = 10
integer :: iwind_resolution = 5
integer :: nfill_domain = 0
real :: outer_boundary_au = 30.
real :: wind_shell_spacing = 1.
real :: pulsation_period
Expand Down
2 changes: 1 addition & 1 deletion src/setup/setup_wind.f90
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ subroutine set_default_parameters_wind()

wind_gamma = 5./3.
if (isothermal) then
T_wind = 30000.
T_wind = 30000.
temp_exponent = 0.5
! primary_racc_au = 0.465
! primary_mass_msun = 1.5
Expand Down
176 changes: 176 additions & 0 deletions src/tests/test_wind.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
!--------------------------------------------------------------------------!
! The Phantom Smoothed Particle Hydrodynamics code, by Daniel Price et al. !
! Copyright (c) 2007-2023 The Authors (see AUTHORS) !
! See LICENCE file for usage and distribution conditions !
! http://phantomsph.bitbucket.io/ !
!--------------------------------------------------------------------------!
module testwind
!
! Unit tests of the step module
!
! :References: None
!
! :Owner: Lionel Siess
!
! :Runtime parameters: None
!
! :Dependencies: boundary, checksetup, deriv, dim, eos, io, mpidomain,
! mpiutils, options, part, physcon, step_lf_global, testutils, timestep,
! timestep_ind, timing, unifdis, viscosity
!
implicit none
public :: test_wind

private

contains
!----------------------------------------------------------
!+
! Unit tests of timestepping and boundary crossing
!+
!----------------------------------------------------------
subroutine test_wind(ntests,npass)
use io, only:iprint,id,master,iverbose
use boundary, only:set_boundary
use options, only:icooling,ieos,tolh,alpha,alphau,alphaB,avdecayconst,beta
use physcon, only:au,solarm,mass_proton_cgs,kboltz,solarl
use units, only:umass,set_units,utime,unit_energ,udist!,unit_velocity
use inject, only:init_inject,inject_particles
use eos, only:gmw,ieos,init_eos,gamma!,polyk
use part, only:npart,init_part,nptmass,xyzmh_ptmass,vxyz_ptmass,xyzh,vxyzu,nptmass,&
npartoftype,igas,iTeff,iLum,iReff,massoftype,ntot,hfact
use physcon, only:au,solarm,mass_proton_cgs,kboltz, solarl
use timestep, only:time,tmax,dt,dtmax,nsteps,dtrad,dtforce,dtcourant,dterr,print_dtlog,&
tolv,C_cour,C_force
use testutils, only:checkval,update_test_scores
use dim, only:isothermal
use step_lf_global, only:step,init_step
use partinject, only:update_injected_particles
use timestep_ind, only:nbinmax
use wind, only:trvurho_1D
use damping, only:idamp

integer, intent(inout) :: ntests,npass

integer :: i,ierr,nerror,istepfrac,npart_old,nfailed(9)
real :: dtinject,dtlast,t,default_particle_mass,dtext,dtnew,dtprint,dtmaxold,tprint

if (id==master) write(*,"(/,a,/)") '--> TESTING WIND MODULE'

call set_units(dist=au,mass=solarm,G=1.)
call init_part()

call set_boundary(-50.,50.,-50.,50.,-50.,50.)

!set propertie of mass loosing sink particle
nptmass = 1
xyzmh_ptmass(4,1) = 1.2*solarm/umass
xyzmh_ptmass(5,1) = 0.6*au/udist
xyzmh_ptmass(iTeff,1) = 2500.
xyzmh_ptmass(iReff,1) = au/udist
xyzmh_ptmass(iLum,1) = 9150.47 *solarl * utime / unit_energ

!
! for binary wind simulations the particle mass is IRRELEVANT
! since it will be over-written on the first call to init_inject
!
default_particle_mass = 1.e-11
massoftype(igas) = default_particle_mass * (solarm / umass)

gmw = 2.381
if (isothermal) then
gamma = 1.
ieos = 1
else
gamma = 1.66666667
ieos = 2
endif
!polyk = kboltz*T_wind/(mass_proton_cgs * gmw * unit_velocity**2)

call init_eos(ieos,ierr)

iverbose = 1
hfact = 1.2
tolv = 1.e-2
tolh = 1.e-4
C_cour = 0.3
C_force = 0.25
nsteps = 0
alpha = 0.
alphau = 1.
alphaB = 0.
beta = 2.
idamp = 0
avdecayconst = 0.1
icooling = 0
dtmax = 1.
tmax = 4.
tprint = tmax
dt = 0.
dtinject = huge(dtinject)
dtrad = huge(dtrad)
t = 0.
dtnew = 0.


!nfailed(:) = 0
!call check_setup(nerror,nwarn)

istepfrac = 0
nfailed(:) = 0
call init_inject(nerror)
npart_old = npart
call inject_particles(t,0.,xyzh,vxyzu,xyzmh_ptmass,vxyz_ptmass,&
npart,npartoftype,dtinject)
call update_injected_particles(npart_old,npart,istepfrac,nbinmax,t,dtmax,dt,dtinject)
call checkval(massoftype(igas),6.820748526700016e-10,epsilon(0.),&
nfailed(1),'no errors in setting particle mass')

! check 1D wind profile
i = size(trvurho_1D(1,:))
call checkval(trvurho_1D(2,i),4.842415565250280e13,epsilon(0.),nfailed(2),'outer wind radius')
call checkval(trvurho_1D(3,i),4.394906290427863e5,epsilon(0.),nfailed(3),'outer wind velocity')
call checkval(trvurho_1D(4,i),1.722094044441452e11,epsilon(0.),nfailed(4),'outer wind temperature')
call checkval(trvurho_1D(5,i),4.867190322165297e-14,epsilon(0.),nfailed(5),'outer wind density')

dt = dtinject

do while (t < tmax)

dtext = dt
if (id==master) write(*,*) ' t = ',t,' dt = ',dt
!
! injection of new particles into simulation
!
npart_old=npart
call inject_particles(t,dtlast,xyzh,vxyzu,xyzmh_ptmass,vxyz_ptmass,npart,npartoftype,dtinject)
call update_injected_particles(npart_old,npart,istepfrac,nbinmax,t,dtmax,dt,dtinject)
dtmaxold = dtmax
nsteps = nsteps+1

call step(npart,npart,t,dt,dtext,dtnew)

t = t + dt
time = t

dtlast = dt
dtprint = min(tprint,tmax) - t + epsilon(dtmax)
if (dtprint <= epsilon(dtmax) .or. dtprint >= (1.0-1e-8)*dtmax ) dtprint = dtmax + epsilon(dtmax)
dt = min(dtforce,dtcourant,dterr,dtmax+epsilon(dtmax),dtprint,dtinject,dtrad)
if (id==master) call print_dtlog(iprint,time,dt,dtforce,dtcourant,dterr,dtmax,dtrad,dtprint,dtinject,ntot)


enddo

call checkval(xyzmh_ptmass(4,1),1.199993907707417d0,epsilon(0.),nfailed(6),'sink particle mass')
call checkval(xyzmh_ptmass(7,1),0.,epsilon(0.),nfailed(7),'mass accreted')
call checkval(npart,12992,0,nfailed(8),'number of ejected particles')
call checkval(xyzmh_ptmass(15,1),1.591640703559762d-6,epsilon(0.),nfailed(9),'wind mass loss rate')

call update_test_scores(ntests,nfailed,npass)

if (id==master) write(*,"(/,a)") '<-- STEP TEST COMPLETE'

end subroutine test_wind

end module testwind
15 changes: 13 additions & 2 deletions src/tests/testsuite.F90
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ subroutine testsuite(string,first,last,ntests,npass,nfail)
use testeos, only:test_eos
use testcooling, only:test_cooling
use testgeometry, only:test_geometry
use testwind, only:test_wind
use testpoly, only:test_poly
use testdamping, only:test_damping
use testradiation,only:test_radiation
Expand All @@ -77,7 +78,7 @@ subroutine testsuite(string,first,last,ntests,npass,nfail)
logical :: testall,dolink,dokdtree,doderivs,dokernel,dostep,dorwdump,dosmol
logical :: doptmass,dognewton,dosedov,doexternf,doindtstep,dogravity,dogeom
logical :: dosetdisc,doeos,docooling,dodust,donimhd,docorotate,doany,dogrowth
logical :: dogr,doradiation,dopart,dopoly,dompi,dohier,dodamp
logical :: dogr,doradiation,dopart,dopoly,dompi,dohier,dodamp,dowind
#ifdef FINVSQRT
logical :: usefsqrt,usefinvsqrt
#endif
Expand Down Expand Up @@ -129,6 +130,7 @@ subroutine testsuite(string,first,last,ntests,npass,nfail)
dompi = .false.
dohier = .false.
dodamp = .false.
dowind = .false.

if (index(string,'deriv') /= 0) doderivs = .true.
if (index(string,'grav') /= 0) dogravity = .true.
Expand All @@ -149,10 +151,11 @@ subroutine testsuite(string,first,last,ntests,npass,nfail)
if (index(string,'mpi') /= 0) dompi = .true.
if (index(string,'hier') /= 0) dohier = .true.
if (index(string,'damp') /= 0) dodamp = .true.
if (index(string,'wind') /= 0) dowind = .true.

doany = any((/doderivs,dogravity,dodust,dogrowth,donimhd,dorwdump,&
doptmass,docooling,dogeom,dogr,dosmol,doradiation,&
dopart,dopoly,dohier,dodamp/))
dopart,dopoly,dohier,dodamp,dowind/))

select case(trim(string))
case('kernel','kern')
Expand Down Expand Up @@ -191,6 +194,8 @@ subroutine testsuite(string,first,last,ntests,npass,nfail)
dogrowth = .true.
case('nimhd')
donimhd = .true.
case('wind')
dowind = .true.
case('mpi')
dompi = .true.
case default
Expand Down Expand Up @@ -390,6 +395,12 @@ subroutine testsuite(string,first,last,ntests,npass,nfail)
call test_radiation(ntests,npass)
call set_default_options_testsuite(iverbose) ! restore defaults
endif
!--test of wind module
!
if (dowind.or.testall) then
call test_wind(ntests,npass)
call set_default_options_testsuite(iverbose) ! restore defaults
endif
!
!--now do a "real" calculation, putting it all together (Sedov blast wave)
!
Expand Down

0 comments on commit fdbdff2

Please sign in to comment.