Peano 4
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:
14
15 /* Code inserted via the python initialisation snippet library.
16 * Do not modify unless you know what you are doing.
17 */
18
19 /*
20 * Initial Conditions: the Noh problem.
21 * We give particles an initial velocity towards the centre.
22 * Particles will then develop a shock that propagates outwards.
23 *
24 */
25
26 // Internal search radius used by Peano and with max value R = grid_size/2
27 tarch::la::Vector<Dimensions,double> GridSize = marker.h();
28 const double GridSize_x = GridSize(0);
29
30 particle->setSearchRadius( 0.9 * GridSize_x / 2.0);
31
32 /* Constant density field */
33 particle->setDensity ( 1.0 );
34 particle->setMass( particle->getDensity() / std::pow(HYDRO_PART_NUMBER, HYDRO_DIMENSIONS) );
35
36 const double eta_fac = particle->getEtaFactor();
37 /* Initial estimate for smoothing length */
38 particle->setSmoothingLength( eta_fac * std::pow(particle->getMass() / particle->getDensity(), 1.0 / HYDRO_DIMENSIONS) );
39
40 /* Set neglibible internal energy */
41 particle->setU( 1e-6 );
42
43 /* Compute the pressure from the EoS */
44 const double pressure = ::swift2::kernels::legacy::eos::gas_pressure_from_internal_energy( particle->getDensity(), particle->getU() );
45 particle->setPressure( pressure );
46
47 /* Compute the sound speed */
48 const double soundspeed = ::swift2::kernels::legacy::eos::gas_soundspeed_from_internal_energy( particle->getU() );
49 particle->setSoundSpeed(soundspeed);
50
51 /*
52 * Set initial velocity for the spherical collapse
53 */
54
55 // Box centre
56 tarch::la::Vector<Dimensions,double> x_0(0.5);
57
58 // Distance of particle to centre
59 tarch::la::Vector<Dimensions,double> dist = particle->getX() - x_0;
60 double norm_dist = tarch::la::norm2(dist);
61
62 // Cap min value of distance
63 if ( tarch::la::equals(norm_dist, 0.0) ){
64 norm_dist = 1e-10;
65 }
66
67 // Set velocity
68 tarch::la::Vector<Dimensions,double> v_ini = -1.0 * dist / norm_dist;
69
70 particle->setV( v_ini );
71
72 /* Initialize remaining fields */
73
74 // Vectors
75 for(int d=0; d<Dimensions; d++){
76 particle->setA (d,0);
77 }
78
79 /* For 2D sims, we only get one component */
80 particle->setRot_v(0);
81
82 /* Initialise the "extended" arrays */
83 particle->setV_full(particle->getV());
84 particle->setU_full(particle->getU());
85
86 particle->setUDot (0.0);
87 particle->setHDot (0.0);
88 particle->setWcount(0.0);
89 particle->setF (0.0);
90 particle->setRho_dh(0.0);
91 particle->setWcount_dh(0.0);
92
93 particle->setHasNoNeighbours(false);
94 particle->setSmoothingLengthIterCount(0);
95 particle->setIsBoundaryParticle(false);
96
97 // Artificial viscosity scheme
98 particle->setDiv_v (0.0);
99 particle->setV_sig_AV(2.0 * particle->getSoundSpeed());
100 particle->setBalsara (0.0);
101
102 particle->setCellHasUpdatedParticle(false);
103 particle->setPartid(1);
104
105 /* Verbose */
106 logDebug( "Init()", "dist = " << dist );
107 logDebug( "Init()", "v_ini = " << v_ini );
108 logDebug( "Init()", "Particle: " << particle->toString() );
109
110 /* End of inserted block */
111
112 """
113 else:
114 print("dimensions not supported!")
Initialisation snippet for the Noh problem in different spatial dimensions.
Definition NohProblem.py:5