Skip to content

Commit bb0f20e

Browse files
authored
Merge pull request #315 from hsinhaoHHuang/Refine_Par_EquilibriumIC
Improve Par_EquilibriumIC
2 parents b2189a1 + 2abbc20 commit bb0f20e

28 files changed

+3399
-2158
lines changed

doc/wiki/Initial-Conditions.md

Lines changed: 266 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,272 @@ See also
290290
[[ Add Problem-specific Grid Fields and Particle Attributes | Adding-New-Simulations#v-add-problem-specific-grid-fields-and-particle-attributes ]] for adding user-defined particle attributes.
291291

292292
GAMER has a built-in routine for constructing a particle initial condition in equilibrium
293-
(e.g., Plummer, NFW, tabular). Please refer to the test problem `Hydro/ParticleEquilibriumIC`
294-
for its usage.
293+
(e.g., Plummer, NFW, tabular). Here are the steps to use it:
294+
295+
1. Step 1: Include the header in the test problem source code file:
296+
297+
```C++
298+
#include "Par_EquilibriumIC.h"
299+
```
300+
301+
2. Step 2: Declare a constructor object of class `Par_EquilibriumIC` inside `Par_Init_ByFunction()`:
302+
303+
```C++
304+
Par_EquilibriumIC( const char* Cloud_Type );
305+
```
306+
307+
- Parameters
308+
309+
- `Cloud_Type` : `char*`
310+
311+
Type of this particle cloud.
312+
Supported types include "Table", "Plummer", "NFW", "Burkert", "Jaffe", "Hernquist", and "Einasto".
313+
314+
- Example Usage
315+
316+
`Par_EquilibriumIC Cloud_Constructor( "Plummer" );` creates a cloud of the Plummer model.
317+
318+
3. Step 3: Set the parameters for the constructor object by calling the following functions:
319+
320+
a. Set the parameters related to the construction of the particle cloud
321+
322+
```C++
323+
setParticleParameters( const long ParNum, const double MaxR, const int NBin, const int RSeed )
324+
```
325+
326+
- Parameters
327+
328+
- `ParNum` : `long`
329+
330+
Number of particles of the particle cloud.
331+
332+
- `MaxR` : `double`
333+
334+
Maximum radius for the scattered particles in this cloud.
335+
336+
- `NBin` : `int`
337+
338+
Number of bins of radial profiles inside the `MaxR`.
339+
340+
- `RSeed` : `int`
341+
342+
Random seed for setting the particle position and velocity.
343+
344+
- Notes
345+
346+
- These parameters are mandatory in all cases.
347+
348+
- Example Usage
349+
350+
`Cloud_Constructor.setParticleParameters( 1000000, 10.0, 1024, 123 );` sets the number of particles as `1000000`, the maximum radius as `10.0` (in code units), the number of bins as `1024`, and the random seed as `123`.
351+
352+
b. Set the filename for the density profile table
353+
354+
```C++
355+
setDensProfTableFilename( const char* DensProfTableFilename )
356+
```
357+
358+
- Parameters
359+
360+
- `DensProfTableFilename` : `char*`
361+
362+
Filename for the density profile table.
363+
364+
- Notes
365+
366+
- Required only for `Cloud_Type == "Table"`; useless for other types.
367+
368+
- Example Usage
369+
370+
`Cloud_Constructor.setDensProfTableFilename( "MyDensityProfile" );` sets the density profile to follow the table "MyDensityProfile".
371+
372+
c. Set the parameters for the analytical models
373+
374+
```C++
375+
setModelParameters( const double Rho0, const double R0 )
376+
```
377+
378+
- Parameters
379+
380+
- `Rho0` : `double`
381+
382+
Scale density in the density profile.
383+
384+
- `R0` : `double`
385+
386+
Scale radius in the density profile.
387+
388+
- Notes
389+
390+
- The scale density and scale radius are general but may have different names in different models. Please check the definition in `AnalyticalDensProf_*` in `src/Particle/Par_EquilibriumIC.cpp` for details.
391+
392+
- Required only for `Cloud_Type != "Table"`; useless for `Cloud_Type == "Table"`.
393+
394+
- Example Usage:
395+
396+
`Cloud_Constructor.setModelParameters( 1.0, 0.1 );` sets the scale density as `1.0` and scale radius as `0.1` in code units.
397+
398+
d. Set the power factor in the Einasto model
399+
400+
```C++
401+
setEinastoPowerFactor( const double EinastoPowerFactor )
402+
```
403+
404+
- Parameters
405+
406+
- `EinastoPowerFactor` : `double`
407+
408+
The power factor in the Einasto density profile.
409+
410+
- Notes
411+
412+
- Required only for `Cloud_Type == "Einasto"`; useless for other types.
413+
414+
- Please refer to `AnalyticalDensProf_Einasto()` in `src/Particle/Par_EquilibriumIC.cpp` for details.
415+
416+
- Example Usage
417+
418+
`Cloud_Constructor.setEinastoPowerFactor( 1.0 );` sets the Einasto power factor to `1.0`.
419+
420+
e. Set the parameters to add the external potential during the construction
421+
422+
```C++
423+
setExtPotParameters( const int AddingExternalPotential_Analytical, const int Addin gExternalPotential_Table, const char* ExtPotTableFilename )
424+
```
425+
426+
- Parameters
427+
428+
- `AddingExternalPotential_Analytical` : `int`
429+
430+
Whether adding an analytical external potential (0=off, 1=on);
431+
Currently, the users must define their analytical functions hard-coded in
432+
433+
```C++
434+
double UserDefAnalaytical_ExtPot( const double r )
435+
```
436+
inside `src/Particle/Par_EquilibriumIC.cpp`.
437+
438+
- `AddingExternalPotential_Table` : `int`
439+
440+
Whether adding an external potential from a table (0=off, 1=on);
441+
The users have to provide an external potenial table as a runtime input file.
442+
443+
- `ExtPotTableFilename` : `char*`
444+
445+
Filename for the external potential table. Required for `AddingExternalPotential_Table`; useless for `AddingExternalPotential_Analytical`.
446+
447+
- Notes
448+
449+
- This is optional. The default is off if this function is not called.
450+
451+
- This functionality is different and independent from adding external potential in the simulations.
452+
453+
- `AddingExternalPotential_Analytical` and `AddingExternalPotential_Table` cannot be both on.
454+
455+
- Example Usage
456+
457+
`Cloud_Constructor.setExtPotParameters( 0, 1, "MyExtPotTable" );` sets the external potential from the table "MyExtPotTable".
458+
459+
f. Set the cloud center and bulk velocity in the simulations
460+
461+
```C++
462+
setCenterAndBulkVel( const double Center_X, const double Center_Y, const double Center_Z, const double BulkVel_X, const double BulkVel_Y, const double BulkVel_Z )
463+
```
464+
465+
- Parameters
466+
467+
- `Center_X` : `double`
468+
469+
x coordinate of the center
470+
471+
- `Center_Y` : `double`
472+
473+
y coordinate of the center
474+
475+
- `Center_Z` : `double`
476+
477+
z coordinate of the center
478+
479+
- `BulkVel_X` : `double`
480+
481+
x component of the bulk velocity
482+
483+
- `BulkVel_Y` : `double`
484+
485+
y component of the bulk velocity
486+
487+
- `BulkVel_Z` : `double`
488+
489+
z component of the bulk velocity
490+
491+
- Notes
492+
493+
- Required for `constructParticles()`, as this only shifts the positions and velocities of all the particles and does not affect the internal distribution.
494+
495+
- Example Usage
496+
497+
`Cloud_Constructor.setCenterAndBulkVel( 1.0, 2.0, 3.0, 0.1, 0.2, 0.3 );` sets the cloud to be located at `[1.0, 2.0, 3.0]` and with a bulk velocity of `[0.1, 0.2, 0.3]` in code units.
498+
499+
4. Step 4: Call the construction function to calculate the radial profiles and distribution function for this cloud:
500+
501+
```C++
502+
constructDistribution()
503+
```
504+
505+
- Notes
506+
507+
- One must have called `set*()` in advance (as in the previous step).
508+
509+
- This should be called before `constructParticles()`.
510+
511+
- Example Usage
512+
513+
`Cloud_Constructor.constructDistribution();`
514+
515+
5. Step 5: Call the following function to set the particle initial conditions for a cloud that is in an equilibrium state:
516+
517+
```C++
518+
constructParticles( real_par *Mass_AllRank, real_par *Pos_AllRank[3], real_par *Vel_AllRank[3], const long Par_Idx0 )
519+
```
520+
521+
- Parameters
522+
523+
- `Mass_AllRank` : `real_par*`
524+
525+
An array of all particles' masses to be set.
526+
527+
- `Pos_AllRank` : `real_par*`
528+
529+
An array of all particles' position vectors to be set.
530+
531+
- `Vel_AllRank` : `real_par*`
532+
533+
An array of all particles' velocity vectors to be set.
534+
535+
- `Par_Idx0` : `long`
536+
537+
Starting index of particles in this cloud.
538+
539+
- Notes
540+
541+
- One must have called `constructDistribution()` in advance (as in the previous step).
542+
543+
- Note that this function is not parallelized currently. One can only call it by the root rank and scatter the constructed particles to other ranks later.
544+
545+
- Example Usage
546+
547+
`Cloud_Constructor.constructParticles( ParMass, ParPosX, ParVelX, (long)0 );` sets the particles' attributes in `Par_Init_ByFunction()` in a serial case.
548+
For parallelized simulations, please see `src/TestProblem/Hydro/ParticleEquilibriumIC/Par_Init_ByFunction_ParEqmIC.cpp` for instructions on how to construct all particles by one rank and scatter them out.
549+
550+
6. After the particles are constructed, one can access the object’s following attributes to check the numerical results:
551+
552+
- `Cloud_Constructor.TotCloudMass` is the total enclosed mass within the maximum radius of this cloud.
553+
554+
- `Cloud_Constructor.ParticleMass` is the particle mass as the total enclosed mass divided by the number of particles in the cloud.
555+
556+
- `Cloud_Constructor.TotCloudMassError` is the total enclosed mass relative error compared to the analytical expectation.
557+
558+
For pratical examples, please refer to the test problems `Hydro/ParticleEquilibriumIC` and `ELBDM/HaloMerger`.
295559
296560
297561
## Setting IC from Files

0 commit comments

Comments
 (0)