diff --git a/run_pm_dmo_NFW_fixed_timestep.md b/run_pm_dmo_NFW_fixed_timestep.md index 517a7530da1c53727621780a4545cdae7d758b33..0a069f7ab2c9940bd74b018131e665a72edff53b 100644 --- a/run_pm_dmo_NFW_fixed_timestep.md +++ b/run_pm_dmo_NFW_fixed_timestep.md @@ -5,15 +5,22 @@ In this example we will use create IC that sample a **NFW profile** and evolve i Here is a first benefit of a modular code: since in `hotwheels `PM is a self-contained module, we can instantiate it an arbitrary number of times. So one can stack seven [PLACEHIGHRESREGION](https://wwwmpa.mpa-garching.mpg.de/gadget4/03_simtypes/) on smaller and smaller regions (a sort of refined mesh) on top of a sampled NFW halo and use PM-only to **get accurate force down to a kpc** (see image). +Install the PM module (will install core,IO, and timestep as dependencies): -Note that to run this module you need access to hotwheels **core, IO, PM,** and **integrate** components. Note that `hotwheels` do not provide parameter or config files. It is up to the user to initalise its sub-library components and connect them. +```bash +pip install 'git+ssh://git@git.ia2.inaf.it/hotwheels/PM.git@v0.0.0alpha' +``` + +And you can run this code: ```python import numpy as np, os, matplotlib as plt -from hotwheels_core import * -from hotwheels_pm import * -from hotwheels_integrate import * -from hotwheels_io import * +from hotwheels.utils import * +from hotwheels.wrap import * +from hotwheels.soas import * +from hotwheels.PM import * +from hotwheels.integrate import * +from hotwheels.io import * # # Step 1: Configure components @@ -21,29 +28,29 @@ from hotwheels_io import * # Configurations are passed to constructors to compile the underlying C libraries. # -mpi = hwc.MPI().init() # Initialize MPI +mpi = MPI().init() # Initialize MPI mym = MyMalloc(alloc_bytes=int(2e9)) # Configure memory allocator with 2GB p = SoA(maxpart=int(1e5), mem=mym) # Configure P to hold 1e5 particles -soas = SoAs(p, mem=mym) # Add P to a multi-type SoA container +soas = SoAs(p) # Add P to a multi-type SoA container # Set up a fixed time-step integrator from 0 to 1 Gyr # Conversion factor for Gyr to internal units gyr_to_cu = 3.086e+16 / (1e9 * 3600 * 24 * 365) -ts = integrate.FixedTimeStep( - soas, +ts = FixedTimeStep( + soas, G=43007.1, # Gravitational constant in specific units - t_from=0., - t_to=1. * gyr_to_cu, + t_from=0., + t_to=1. * gyr_to_cu, MPI=mpi ) # Initialize a NFW profile with scale radius `rs=100` and density `rho0=1e-6` -ic = NFWIC(rs=100., rho0=1e-6, rs_factor=10.) +ic = NFWIC(r_s=100., rho_0=1e-6, r_max_f=10.) # Configure a refined PM grid with 7 stacked high-resolution regions pm = SuperHiResPM( #wrapper to the PM C library - soas=soas, - mem=mym, + soas=soas, + mem=mym, TS=ts, #will use it to attach gravkick callback - MPI=mpi, - pmgrid=128, + MPI=mpi, + pmgrid=128, grids=8, # number of grids to instantiate dt_displacement_factor=0.25 #factor for DtDisplacement ) @@ -59,13 +66,13 @@ if mpi.rank == 0: # Master rank handles compilation # with ( - utils.Panic(Build=build) as panic, # Attach panic handler - utils.Timer(Build=build) as timer, # Attach timer handler + Panic(Build=build) as panic, # Attach panic handler + Timer(Build=build) as timer, # Attach timer handler build.enter(debug=mpi.rank == 0), # Parse compiled objects mpi.enter(pm), # Initialize MPI in the PM module mym.enter(*build.components), # Allocate 2GB memory p, # Allocate particle data structure in MyMalloc - ic.enter(p, mpi.ranks, p.get_maxpart()), # Sample NFW profile + ic.enter(p, mpi.ranks, p.get_maxpart(), ts.G), # Sample NFW profile pm, # Initialize PM and compute first accelerations ts # Compute DriftTables if needed ): @@ -73,7 +80,6 @@ with ( # # 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) @@ -89,4 +95,5 @@ with ( fig.savefig(f'snap{ts.steps}_rank{mpi.rank}.png', bbox_inches='tight', dpi=200) plt.close(fig) -print('Simulation finished') \ No newline at end of file +print('Simulation finished') +``` \ No newline at end of file