Skip to content
Snippets Groups Projects
Commit d194efa1 authored by Antonio Ragagnin's avatar Antonio Ragagnin :speech_balloon:
Browse files

Update run_pm_dmo_NFW_fixed_timestep.md

parent d35af95d
No related branches found
No related tags found
No related merge requests found
...@@ -16,86 +16,80 @@ from hotwheels_integrate import * ...@@ -16,86 +16,80 @@ from hotwheels_integrate import *
from hotwheels_io import * from hotwheels_io import *
# #
# step 1: config of components # Step 1: Configure components
# # This stage configures components without allocating resources.
# at this stage we do not allocate any resource, we just # Configurations are passed to constructors to compile the underlying C libraries.
# pass the right config parameters to the constructors
# in order to compile the underlying C libraries.
# #
#call MPI_Init() mpi = hwc.MPI().init() # Initialize MPI
mpi = hwc.MPI().init() mym = MyMalloc(alloc_bytes=int(2e9)) # Configure memory allocator with 2GB
#configure my malloc with 2GB p = SoA(maxpart=int(1e5), mem=mym) # Configure P to hold 1e5 particles
mym = MyMalloc(alloc_bytes=int(2e9)) soas = SoAs(p, mem=mym) # Add P to a multi-type SoA container
#configure the default particle SoA with 1e5 particles # Set up a fixed time-step integrator from 0 to 1 Gyr
p = SoA(maxpart=int(1e5), mem=mym) # Conversion factor for Gyr to internal units
#add the particle soa to the multi-type particle SoAs
soas = SoAs(p, mem=mym)
# configure the timestep class to go from 0 to 1 Gyr
# note: G=43007.1 in units of length=kpc, velocity=km/s, mass = 1e10Msun
# if G=43007.1, masses are in 1e10Msun/h, and radii are in ckpc/h, then this
# constant converts from Gyr to internal units. Not much to comment about it
gyr_to_cu = 3.086e+16 / (1e9 * 3600 * 24 * 365) gyr_to_cu = 3.086e+16 / (1e9 * 3600 * 24 * 365)
ts = integrate.FixedTimeStep(soas, G=43007.1, t_from=0., t_to=1. * gyr_to_cu, MPI=mpi) ts = integrate.FixedTimeStep(
ic = NFWIC(rs=100., rho0=1e-6, rs_factor=10.) #init the build of a NFW profile with R<10rs, (note that mass is in units of 1e10Msun) soas,
# init a refined PM grids with 7 stacked PLACEHIRESREGION at smaller and smaller scales G=43007.1, # Gravitational constant in specific units
# note that PM needs the time-step integrator class TS to attach its DriftTable and kick callbacks t_from=0.,
pm = SuperHiResPM(soas=soas, mem=mym, TS=ts, MPI=mpi, pmgrid=128, grids=8, dt_displacement_factor=0.25) t_to=1. * gyr_to_cu,
#configure to compile all modules in the current folder MPI=mpi
build = make.Build('./', mpi, pm, ts, mym, *soas.values()) )
#configure generate SoA headers # Initialize a NFW profile with scale radius `rs=100` and density `rho0=1e-6`
headers = OnTheFly(build.build_name, *build.components, generate_user_c=True) ic = NFWIC(rs=100., rho0=1e-6, rs_factor=10.)
# Configure a refined PM grid with 7 stacked high-resolution regions
# pm = SuperHiResPM( #wrapper to the PM C library
# step 2: build SoAs headers and compile C files soas=soas,
# mem=mym,
TS=ts, #will use it to attach gravkick callback
MPI=mpi,
if mpi.rank == 0: #master rank compile and build headers pmgrid=128,
grids=8, # number of grids to instantiate
dt_displacement_factor=0.25 #factor for DtDisplacement
)
build = make.Build('./', mpi, pm, ts, mym, *soas.values()) # Compile all modules in the current directory
headers = OnTheFly(build.build_name, *build.components, generate_user_c=True) # Generate SoA headers
if mpi.rank == 0: # Master rank handles compilation
headers.write() headers.write()
build.compile() build.compile()
# #
# step 3: allocate resources (e.g. MPI, MyMalloc, and allocations within it) # Step 2: Allocate resources
# #
with (utils.Panic(Build=build) as panic, #attach panic handler to C calls with (
utils.Timer(Build=build) as timer, #attach timer handler to C calls utils.Panic(Build=build) as panic, # Attach panic handler
build.enter(debug=mpi.rank == 0), #parse the compiled object files utils.Timer(Build=build) as timer, # Attach timer handler
mpi.enter(pm), #attach MPI init info to PM module build.enter(debug=mpi.rank == 0), # Parse compiled objects
mym.enter(*build.components), #actually allocates the 2GB of ram mpi.enter(pm), # Initialize MPI in the PM module
p, #allocate the particle data stracture in the MyMalloc area mym.enter(*build.components), # Allocate 2GB memory
ic.enter(p, mpi.ranks, p.get_maxpart()), #sample the NFW in the particle SoA `p` fields p, # Allocate particle data structure in MyMalloc
pm, #call pm_init() the PM regions ic.enter(p, mpi.ranks, p.get_maxpart()), # Sample NFW profile
ts #compute DriftTables if necessary pm, # Initialize PM and compute first accelerations
ts # Compute DriftTables if needed
): ):
pm.compute_accelerations() #first acc computation
# #
# step 4: the actual run # Step 3: Main simulation loop
# #
while ts.time < ts.time_end:
ts.find_timesteps() # Determine timesteps
ts.do_first_halfstep_kick() # First kick (includes drift/kick callbacks)
ts.drift() # Update particle positions
pm.compute_accelerations() # Recompute accelerations
ts.do_second_halfstep_kick() # Second kick
while ts.time < ts.time_end: #main run.c loop # Occasionally, generate plots on the master rank
if mpi.rank == 0 and ts.steps % 10 == 0:
ts.find_timesteps() #integrator will find timesteps fig, ax = plt.subplots(1)
#integrator will call halfstep kick, including PM registered drift and kick callbacks
ts.do_first_halfstep_kick()
ts.drift() #integretor will drift
pm.compute_accelerations() #accelerations
#integrator will call halfstep kick, including PM registered drift and kick callbacks
ts.do_second_halfstep_kick()
if mpi.rank == 0 and steps % 10 == 0: #sometimes, master rank will do a plot
f, ax = plt.subplots(1)
ax.hist2d(p['pos'][:, 0], p['pos'][:, 1], bins=128) ax.hist2d(p['pos'][:, 0], p['pos'][:, 1], bins=128)
ax.set_aspect('equal') ax.set_aspect('equal')
pat = os.path.join(os.getenv('HW_BUILD', '.'), 'snap%d_rank%d.png' % (steps, mpi.rank)) path = os.path.join(
f.savefig(pat, bbox_inches='tight', dpi=200) os.getenv('HW_BUILD', '.'), f'snap{ts.steps}_rank{mpi.rank}.png'
plt.close(f) )
fig.savefig(path, bbox_inches='tight', dpi=200)
plt.close(fig)
print('simualtion finished') print('Simulation finished')
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment