3 Initialisation snippet for the Sedov Blast problem in different spatial dimensions.
4 Returns a string with C++ code.
11 * Code inserted via the python initialisation snippet library.
12 * Do not modify unless you know what you are doing.
13 * Template located in src/exaparty/api/scenario/SedovBlast.py
17 * Initial Conditions: Sedov Blast.
19 * Particles are initialised at rest in regular grid configuration and periodic BC.
20 * Energy is injected to a (or group of) central particle and the blast should propagate
21 * isotropically, up to boundary effects.
22 * See, e.g., Springel and Hernquist, Mon. Not. R. Astron. Soc. 333, 649–664 (2002).
27 using namespace ::exaparty::kernels::legacy::kernelHydro;
29 // Internal search radius used by Peano and with max value R = grid_size/2
30 tarch::la::Vector<Dimensions,double> GridSize = marker.h();
31 const double GridSizeHalf_x = 0.5 * GridSize(0);
33 const double h_max = particle->getSmlMax();
34 const double H_max = h_max * kernel_gamma;
35 double search_radius = 0.999 * std::min(H_max, GridSizeHalf_x);
37 particle->setSearchRadius( search_radius );
39 // Constant background density field
40 particle->setDensity ( 1.0 );
42 particle->setMass( particle->getDensity() * std::pow((DomainSize(0) / (double) HYDRO_PART_NUMBER) , HYDRO_DIMENSIONS) );
44 // Initial estimate for smoothing length
45 const double eta_fac = particle->getEtaFactor();
46 double h = eta_fac * std::pow(particle->getMass() / particle->getDensity(), 1.0 / HYDRO_DIMENSIONS) ;
47 h = std::min(h, h_max);
48 particle->setSmoothingLength(h);
51 const double pressure = 1.e-6;
52 particle->setPressure( pressure );
54 // the setup below (how many particles we'll inject, and how we
55 // split up the energy between them) depends on an even number of
56 // regularly distributed particles.
57 assert((static_cast<int>(HYDRO_PART_NUMBER) % 2) == 0);
60 // Initialise the blast
61 const double BLAST_ENERGY = 1.0;
62 double SPIKE_RADIUS = 1.001 * DomainSize(0) / HYDRO_PART_NUMBER;
63 double BLAST_FRACTION = 1. / 3.;
64 if (HYDRO_DIMENSIONS == 2) {
65 SPIKE_RADIUS = 2.751 * DomainSize(0) / HYDRO_PART_NUMBER;
66 BLAST_FRACTION = 1. / 21.;
68 if (HYDRO_DIMENSIONS == 3) {
69 SPIKE_RADIUS = 1.701 * DomainSize(0) / HYDRO_PART_NUMBER;
70 BLAST_FRACTION = 1. / 19.;
73 tarch::la::Vector<Dimensions,double> blast_center = 0.5 * DomainSize + DomainOffset;
75 const double dist_blast = tarch::la::norm2( particle->getX() - blast_center );
78 // Inject energy evenly into group of central particles
79 if ( tarch::la::smallerEquals( dist_blast, SPIKE_RADIUS ) ) {
80 particle->setU( BLAST_ENERGY * BLAST_FRACTION / particle->getMass() );
83 ::exaparty::kernels::legacy::eos::gas_internal_energy_from_pressure( particle->getDensity(), pressure )
87 /* Initialize remaining fields */
90 for(int d=0; d<Dimensions; d++){
96 for(int d=0; d<Dimensions; d++){
97 particle->setRot_v (d,0);
100 /* For 1D and 2D sims, we only get one component, i.e. scalar */
101 particle->setRot_v(0);
104 /* Initialise the "extended" arrays */
105 particle->setV_full(particle->getV());
106 particle->setU_full(particle->getU());
108 particle->setUDot (0.0);
109 particle->setHDot (0.0);
110 particle->setWcount(0.0);
111 particle->setF (0.0);
112 particle->setRho_dh(0.0);
113 particle->setWcount_dh(0.0);
115 particle->setHasNoNeighbours(false);
116 particle->setSmoothingLengthIterCount(0);
118 // Artificial viscosity scheme
119 particle->setDiv_v (0.0);
120 particle->setV_sig_AV(2.0 * particle->getSoundSpeed());
121 particle->setBalsara (0.0);
123 particle->setCellHasUpdatedParticle(false);
127 // Set a reproducible particle ID assuming we're distributing particles on a regular grid
129 int MAX_PART_NUMBER = 2147483646;
130 if (HYDRO_DIMENSIONS==2) {
131 // ~ sqrt int max - 1
132 MAX_PART_NUMBER = 46339;
134 else if (HYDRO_DIMENSIONS==3) {
135 // ~ cbrt int max - 1
136 MAX_PART_NUMBER = 1289;
139 double xp = particle->getX(0);
140 double oneOverDx = MAX_PART_NUMBER / DomainSize[0];
141 int i = (int) ((xp - DomainOffset[0]) * oneOverDx);
144 // Assuming here we're running 1D experiments on a 2D grid,
145 // as we always do, then we don't need compile time macro guards.
146 if (HYDRO_DIMENSIONS > 1) {
147 double yp = particle->getX(1);
148 double oneOverDy = MAX_PART_NUMBER / DomainSize[1];
149 int j = (int) ((yp - DomainOffset[1]) * oneOverDy);
150 partid += j * MAX_PART_NUMBER;
153 // For 3D, we need the guard.
155 if (HYDRO_DIMENSIONS > 2){
156 double zp = particle->getX(2);
157 double oneOverDz = MAX_PART_NUMBER / DomainSize[2];
158 int k = (int) ((zp - DomainOffset[2]) * oneOverDz);
159 partid += k * MAX_PART_NUMBER * MAX_PART_NUMBER;
163 particle->setPartid(partid);
165 #endif // PeanoDebug > 0
168 /* End of inserted block */
Initialisation snippet for the Sedov Blast problem in different spatial dimensions.