Peano
Loading...
Searching...
No Matches
GreshoChanVortex.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, HYDRO_DIMENSIONS...
3# @todo: add dependence for the background pressure degree of freedom (Mach)
4
5
7 """
8 Initialisation snippet for the Gresho-Chan vortex in different spatial dimensions.
9 Returns a string with C++ code.
10 """
11
12 def __init__(self, dimensions):
13 if dimensions == 2:
15
16 /* Code inserted via the python initialisation snippet library.
17 * Do not modify unless you know what you are doing.
18 */
19
20 /*
21 * Initial Conditions: Gresho-Chan vortex.
22 * We give the particles values for the azhimutal velocity and
23 * pressure in a spherically-symmetric way.
24 *
25 */
26
27 // Internal search radius used by Peano and with max value R = grid_size/2
28 tarch::la::Vector<Dimensions,double> GridSize = marker.h();
29 const double GridSizeHalf_x = 0.5 * GridSize(0);
30
31 const double h_max = particle->getSmlMax();
32 const double H_max = h_max * kernel_gamma;
33 double search_radius = 0.999 * std::min(H_max, GridSizeHalf_x);
34
35 particle->setSearchRadius( search_radius );
36
37 /* Constant density field */
38 particle->setDensity ( 1.0 );
39 particle->setMass( particle->getDensity() / std::pow(HYDRO_PART_NUMBER, HYDRO_DIMENSIONS) );
40
41 /* Initial estimate for smoothing length */
42 const double eta_fac = particle->getEtaFactor();
43 particle->setSmoothingLength( eta_fac * std::pow(particle->getMass()/particle->getDensity(), 1.0 / HYDRO_DIMENSIONS) );
44 particle->setSmoothingLengthPrevious( particle->getSmoothingLength() );
45
46 // Box centre
47 tarch::la::Vector<Dimensions,double> x_0(0.5);
48
49 // Distance of particle to centre
50 tarch::la::Vector<Dimensions,double> pos = particle->getX();
51 tarch::la::Vector<Dimensions,double> dist = pos - x_0;
52 double r = tarch::la::norm2(dist);
53
54 // avoid velocity divergences at r=0
55 r += 1e-10;
56
57 /* Initial azhimutal velocity */
58 double v_phi;
59
60 if( r >= 0 && r < 0.2) {
61 v_phi = 5.0 * r;
62 } else if( r >= 0.2 && r < 0.4){
63 v_phi = 2.0 - 5.0 * r;
64 } else {
65 v_phi = 0;
66 }
67
68 // Set velocity profile
69 tarch::la::Vector<Dimensions,double> v_ini;
70
71 // Get x and y particle coordinates
72 const double pos_x = pos[0];
73 const double pos_y = pos[1];
74
75 v_ini[0] = - v_phi * (pos_y - 0.5) / r;
76 v_ini[1] = v_phi * (pos_x - 0.5) / r;
77
78 particle->setV( v_ini );
79
80 /* Initial pressure profile */
81 double pressure;
82
83 if( r >= 0 && r < 0.2) {
84 pressure = 5.0 + 12.5 * r * r;
85 } else if( r >= 0.2 && r < 0.4){
86 pressure = 9.0 + 12.5 * r * r - 20.0 * r + 4.0 * log( 5.0 * r );
87 } else {
88 pressure = 3.0 + 4.0 * log( 2.0 );
89 }
90
91 // Set pressure profile
92 particle->setPressure( pressure );
93
94 /* Set U from the EoS */
95 double u_ini = ::exaparty::legacy::eos::gas_internal_energy_from_pressure( particle->getDensity(), particle->getPressure() );
96 particle->setU( u_ini );
97
98 /* Set sound speed */
99 const double soundspeed = ::exaparty::legacy::eos::gas_soundspeed_from_internal_energy( particle->getU() );
100 particle->setSoundSpeed(soundspeed);
101
102 /*
103 * Initialize remaining fields
104 */
105
106 // Vectors
107 for(int d=0; d<Dimensions; d++){
108 particle->setA (d,0);
109 particle->setA_prev_step(d,0);
110 }
111
112 /* For 2D sims, we only get one component */
113 particle->setRot_v(0);
114
115 /* Initialise the "extended" arrays */
116 particle->setV_full(particle->getV());
117 particle->setU_full(particle->getU());
118
119 particle->setUDot (0.0);
120 particle->setUDot_prev_step(0.0);
121 particle->setHDot (0.0);
122 particle->setWcount(0.0);
123 particle->setNcount(0 );
124 particle->setF (0.0);
125 particle->setRho_dh(0.0);
126 particle->setWcount_dh(0.0);
127
128 particle->setHLeft (particle->getSmlMin());
129 particle->setHRight(particle->getSmlMax());
130
131 particle->setTimeStepSize(GLOBAL_TIME_STEP_SIZE);
132 particle->setHasConverged(false);
133 particle->setHasNoNeighbours(false);
134 particle->setResidual(0.0);
135 particle->setIterCount(0);
136
137 // Artificial viscosity scheme
138 particle->setDiv_v (0.0);
139 particle->setV_sig_AV(2.0 * particle->getSoundSpeed());
140 particle->setBalsara (0.0);
141
142 /* End of inserted block */
143
144 """
145 else:
146 print("dimensions not supported!")
Initialisation snippet for the Gresho-Chan vortex in different spatial dimensions.