Peano
Loading...
Searching...
No Matches
SedovBlast.py
Go to the documentation of this file.
2 """
3 Initialisation snippet for the Sedov Blast problem in different spatial dimensions.
4 Returns a string with C++ code.
5 """
6
7 def __init__(self):
9
10 /*
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
14 */
15
16 /*
17 * Initial Conditions: Sedov Blast.
18 *
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).
23 *
24 */
25
26 // for kernel_gamma
27 using namespace ::exaparty::kernels::legacy::kernelHydro;
28
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);
32
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);
36
37 particle->setSearchRadius( search_radius );
38
39 // Constant background density field
40 particle->setDensity ( 1.0 );
41
42 particle->setMass( particle->getDensity() * std::pow((DomainSize(0) / (double) HYDRO_PART_NUMBER) , HYDRO_DIMENSIONS) );
43
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);
49
50 // Set pressure
51 const double pressure = 1.e-6;
52 particle->setPressure( pressure );
53
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);
58
59
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.;
67 }
68 if (HYDRO_DIMENSIONS == 3) {
69 SPIKE_RADIUS = 1.701 * DomainSize(0) / HYDRO_PART_NUMBER;
70 BLAST_FRACTION = 1. / 19.;
71 }
72
73 tarch::la::Vector<Dimensions,double> blast_center = 0.5 * DomainSize + DomainOffset;
74
75 const double dist_blast = tarch::la::norm2( particle->getX() - blast_center );
76
77 // Default method
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() );
81 } else {
82 particle->setU(
83 ::exaparty::kernels::legacy::eos::gas_internal_energy_from_pressure( particle->getDensity(), pressure )
84 );
85 }
86
87 /* Initialize remaining fields */
88
89 // Vectors
90 for(int d=0; d<Dimensions; d++){
91 particle->setV (d,0);
92 particle->setA (d,0);
93 }
94
95 #if Dimensions==3
96 for(int d=0; d<Dimensions; d++){
97 particle->setRot_v (d,0);
98 }
99 #else
100 /* For 1D and 2D sims, we only get one component, i.e. scalar */
101 particle->setRot_v(0);
102 #endif
103
104 /* Initialise the "extended" arrays */
105 particle->setV_full(particle->getV());
106 particle->setU_full(particle->getU());
107
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);
114
115 particle->setHasNoNeighbours(false);
116 particle->setSmoothingLengthIterCount(0);
117
118 // Artificial viscosity scheme
119 particle->setDiv_v (0.0);
120 particle->setV_sig_AV(2.0 * particle->getSoundSpeed());
121 particle->setBalsara (0.0);
122
123 particle->setCellHasUpdatedParticle(false);
124
125 #if PeanoDebug > 0
126
127 // Set a reproducible particle ID assuming we're distributing particles on a regular grid
128 // int max - 1
129 int MAX_PART_NUMBER = 2147483646;
130 if (HYDRO_DIMENSIONS==2) {
131 // ~ sqrt int max - 1
132 MAX_PART_NUMBER = 46339;
133 }
134 else if (HYDRO_DIMENSIONS==3) {
135 // ~ cbrt int max - 1
136 MAX_PART_NUMBER = 1289;
137 }
138
139 double xp = particle->getX(0);
140 double oneOverDx = MAX_PART_NUMBER / DomainSize[0];
141 int i = (int) ((xp - DomainOffset[0]) * oneOverDx);
142 int partid = i;
143
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;
151 }
152
153 // For 3D, we need the guard.
154 #if Dimensions > 2
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;
160 }
161 #endif
162
163 particle->setPartid(partid);
164
165 #endif // PeanoDebug > 0
166
167
168 /* End of inserted block */
169
170 """
Initialisation snippet for the Sedov Blast problem in different spatial dimensions.
Definition SedovBlast.py:1