7 Initialisation snippet for the Noh problem in different spatial dimensions.
8 Returns a string with C++ code.
12 if dimensions == 2
or dimensions == 3:
16 * Code inserted via the python initialisation snippet library.
17 * Do not modify unless you know what you are doing.
18 * Template located in src/exaparty/api/scenario/NohProblem.py
22 * Initial Conditions: the Noh problem.
23 * We give particles an initial velocity towards the centre.
24 * Particles will then develop a shock that propagates outwards.
28 using namespace ::exaparty::kernels::legacy::kernelHydro;
30 // Internal search radius used by Peano and with max value R = grid_size/2
31 tarch::la::Vector<Dimensions,double> GridSize = marker.h();
32 const double GridSizeHalf_x = 0.5 * GridSize(0);
34 const double h_max = particle->getSmlMax();
35 const double H_max = h_max * kernel_gamma;
36 double search_radius = 0.999 * std::min(H_max, GridSizeHalf_x);
38 particle->setSearchRadius( search_radius );
40 // Constant background density field
41 particle->setDensity ( 1.0 );
43 particle->setMass( particle->getDensity() * std::pow((DomainSize(0) / (double) HYDRO_PART_NUMBER) , HYDRO_DIMENSIONS) );
45 const double eta_fac = particle->getEtaFactor();
46 // Initial estimate for smoothing length
47 double h = eta_fac * std::pow(particle->getMass() / particle->getDensity(), 1.0 / HYDRO_DIMENSIONS) ;
48 h = std::min(h, h_max);
49 particle->setSmoothingLength(h);
51 // Set neglibible background pressure
52 particle->setPressure( 1e-6 );
54 // Compute the internal energy from the EoS
55 const double internal_energy = ::exaparty::kernels::legacy::eos::gas_internal_energy_from_pressure( particle->getDensity(), particle->getPressure() );
56 particle->setU( internal_energy );
58 // Compute the sound speed
59 const double soundspeed = ::exaparty::kernels::legacy::eos::gas_soundspeed_from_internal_energy( particle->getU() );
60 particle->setSoundSpeed(soundspeed);
63 * Set initial velocity for the spherical collapse
67 tarch::la::Vector<Dimensions,double> x_0 = DomainOffset + 0.5 * DomainSize;
69 // Distance of particle to centre
70 tarch::la::Vector<Dimensions,double> dist = particle->getX() - x_0;
71 double norm_dist = tarch::la::norm2(dist);
73 // Cap min value of distance
74 norm_dist = std::max(norm_dist, 1e-10);
77 tarch::la::Vector<Dimensions,double> v_ini = -1.0 * dist / norm_dist;
79 particle->setV( v_ini );
81 // Initialize remaining fields
84 for(int d=0; d<Dimensions; d++){
89 // For 2D sims, we only get one component
90 particle->setRot_v(0.);
92 for(int d=0; d<Dimensions; d++){
93 particle->setRot_v(d, 0.);
98 /* Initialise the "extended" arrays */
99 particle->setV_full(particle->getV());
100 particle->setU_full(particle->getU());
102 particle->setUDot (0.0);
103 particle->setHDot (0.0);
104 particle->setWcount(0.0);
105 particle->setF (0.0);
106 particle->setRho_dh(0.0);
107 particle->setWcount_dh(0.0);
109 particle->setHasNoNeighbours(false);
110 particle->setSmoothingLengthIterCount(0);
112 // Artificial viscosity scheme
113 particle->setDiv_v (0.0);
114 particle->setV_sig_AV(2.0 * particle->getSoundSpeed());
115 particle->setBalsara (0.0);
117 particle->setCellHasUpdatedParticle(false);
121 // Set a reproducible particle ID assuming we're distributing particles on a regular grid
123 int MAX_PART_NUMBER = 2147483646;
124 if (HYDRO_DIMENSIONS==2) {
125 // ~ sqrt int max - 1
126 MAX_PART_NUMBER = 46339;
128 else if (HYDRO_DIMENSIONS==3) {
129 // ~ cbrt int max - 1
130 MAX_PART_NUMBER = 1289;
133 double xp = particle->getX(0);
134 double oneOverDx = MAX_PART_NUMBER / DomainSize[0];
135 int i = (int) ((xp - DomainOffset[0]) * oneOverDx);
138 // Assuming here we're running 1D experiments on a 2D grid,
139 // as we always do, then we don't need compile time macro guards.
140 if (HYDRO_DIMENSIONS > 1) {
141 double yp = particle->getX(1);
142 double oneOverDy = MAX_PART_NUMBER / DomainSize[1];
143 int j = (int) ((yp - DomainOffset[1]) * oneOverDy);
144 partid += j * MAX_PART_NUMBER;
147 // For 3D, we need the guard.
149 if (HYDRO_DIMENSIONS > 2){
150 double zp = particle->getX(2);
151 double oneOverDz = MAX_PART_NUMBER / DomainSize[2];
152 int k = (int) ((zp - DomainOffset[2]) * oneOverDz);
153 partid += k * MAX_PART_NUMBER * MAX_PART_NUMBER;
157 particle->setPartid(partid);
159 #endif // PeanoDebug > 0
161 logDebug( "Init()", "dist = " << dist );
162 logDebug( "Init()", "v_ini = " << v_ini );
163 logDebug( "Init()", "Particle: " << particle->toString() );
166 /* End of inserted block from src/exaparty/api/scenario/NohProblem.py */
170 print(
"dimensions not supported!")
Initialisation snippet for the Noh problem in different spatial dimensions.
__init__(self, dimensions)