Peano
Loading...
Searching...
No Matches
NohProblem.py
Go to the documentation of this file.
1# @todo: add dependence on SPH scheme (only minimal SPH ATM)
2# @todo: add dependence on input parameters, e.g. grid size ...
3
4
6 """
7 Initialisation snippet for the Noh problem in different spatial dimensions.
8 Returns a string with C++ code.
9 """
10
11 def __init__(self, dimensions):
12 if dimensions == 2 or dimensions == 3:
14
15 /*
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
19 */
20
21 /*
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.
25 */
26
27 // for kernel_gamma
28 using namespace ::exaparty::kernels::legacy::kernelHydro;
29
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);
33
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);
37
38 particle->setSearchRadius( search_radius );
39
40 // Constant background density field
41 particle->setDensity ( 1.0 );
42
43 particle->setMass( particle->getDensity() * std::pow((DomainSize(0) / (double) HYDRO_PART_NUMBER) , HYDRO_DIMENSIONS) );
44
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);
50
51 // Set neglibible background pressure
52 particle->setPressure( 1e-6 );
53
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 );
57
58 // Compute the sound speed
59 const double soundspeed = ::exaparty::kernels::legacy::eos::gas_soundspeed_from_internal_energy( particle->getU() );
60 particle->setSoundSpeed(soundspeed);
61
62 /*
63 * Set initial velocity for the spherical collapse
64 */
65
66 // Box centre
67 tarch::la::Vector<Dimensions,double> x_0 = DomainOffset + 0.5 * DomainSize;
68
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);
72
73 // Cap min value of distance
74 norm_dist = std::max(norm_dist, 1e-10);
75
76 // Set velocity
77 tarch::la::Vector<Dimensions,double> v_ini = -1.0 * dist / norm_dist;
78
79 particle->setV( v_ini );
80
81 // Initialize remaining fields
82
83 // Vectors
84 for(int d=0; d<Dimensions; d++){
85 particle->setA(d,0.);
86 }
87
88 #if Dimensions < 3
89 // For 2D sims, we only get one component
90 particle->setRot_v(0.);
91 #else
92 for(int d=0; d<Dimensions; d++){
93 particle->setRot_v(d, 0.);
94 }
95 #endif
96
97
98 /* Initialise the "extended" arrays */
99 particle->setV_full(particle->getV());
100 particle->setU_full(particle->getU());
101
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);
108
109 particle->setHasNoNeighbours(false);
110 particle->setSmoothingLengthIterCount(0);
111
112 // Artificial viscosity scheme
113 particle->setDiv_v (0.0);
114 particle->setV_sig_AV(2.0 * particle->getSoundSpeed());
115 particle->setBalsara (0.0);
116
117 particle->setCellHasUpdatedParticle(false);
118
119 #if PeanoDebug > 0
120
121 // Set a reproducible particle ID assuming we're distributing particles on a regular grid
122 // int max - 1
123 int MAX_PART_NUMBER = 2147483646;
124 if (HYDRO_DIMENSIONS==2) {
125 // ~ sqrt int max - 1
126 MAX_PART_NUMBER = 46339;
127 }
128 else if (HYDRO_DIMENSIONS==3) {
129 // ~ cbrt int max - 1
130 MAX_PART_NUMBER = 1289;
131 }
132
133 double xp = particle->getX(0);
134 double oneOverDx = MAX_PART_NUMBER / DomainSize[0];
135 int i = (int) ((xp - DomainOffset[0]) * oneOverDx);
136 int partid = i;
137
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;
145 }
146
147 // For 3D, we need the guard.
148 #if Dimensions > 2
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;
154 }
155 #endif
156
157 particle->setPartid(partid);
158
159 #endif // PeanoDebug > 0
160
161 logDebug( "Init()", "dist = " << dist );
162 logDebug( "Init()", "v_ini = " << v_ini );
163 logDebug( "Init()", "Particle: " << particle->toString() );
164
165
166 /* End of inserted block from src/exaparty/api/scenario/NohProblem.py */
167
168 """
169 else:
170 print("dimensions not supported!")
Initialisation snippet for the Noh problem in different spatial dimensions.
Definition NohProblem.py:5