Peano 4
Loading...
Searching...
No Matches
Leapfrog.cpph
Go to the documentation of this file.
1#include "equation_of_state.h"
2#include "hydro_dimensions.h"
3#include "kernel_hydro.h"
8
9
10template <typename Particle>
12 Particle* particle
13) {
14 const double timeStepSize = Particle::getSpecies().getMinTimeStepSize();
15
16 // Use V_full here, not V
17 particle->setX(particle->getX() + timeStepSize * particle->getV_full());
18
19 assertion1(tarch::la::isEntryFinite(particle->getX()), particle->toString());
20
21 // Flag this particle as Moved
22 particle->setMoveState(Particle::MoveState::Moved);
23}
24
25
26template <typename Particle>
27void swift2::kernels::legacy::hydro_predict_extra(Particle* localParticle) {
28
29 const int hydroDimensions = localParticle->getHydroDimensions();
30 const double timeStepSize = localParticle->getSpecies().getMinTimeStepSize();
31 // When integrating in time with cosmology, the three times below will all
32 // have different factors/powers of the expansion factor `a` absorbed in them.
33 // For now, without cosmology, they are identical.
34 const double dt_kick_hydro = timeStepSize;
35 const double dt_drift = timeStepSize;
36 const double dt_therm = timeStepSize;
37
38
39 // Predict velocities for hydro terms
40 localParticle->setV(
41 localParticle->getV() + localParticle->getA() * dt_kick_hydro
42 );
43
44 // Predict additional particle fields forward in time after the Drift step
45
46 // Predict the internal energy
47 localParticle->setU(
48 localParticle->getU() + localParticle->getUDot() * dt_therm
49 );
50
51 // Predict smoothing length
52 const double h_inv = 1.0 / localParticle->getSmoothingLength();
53 const double w1 = localParticle->getHDot() * h_inv * dt_drift;
54 localParticle->setSmoothingLength(
55 localParticle->getSmoothingLength() * std::exp(w1)
56 );
57
58 // Predict density
59 const double w2 = -hydroDimensions * w1;
60 localParticle->setDensity(localParticle->getDensity() * std::exp(w2));
61
62 localParticle->setU(std::max(localParticle->getU(), 0.0));
63
64 // Compute the new pressure
65 const double pressure = eos::gas_pressure_from_internal_energy(
66 localParticle->getDensity(),
67 localParticle->getU()
68 );
69
70 // Compute the new sound speed
71 const double soundspeed = eos::gas_soundspeed_from_pressure(
72 localParticle->getDensity(),
73 pressure
74 );
75
76 localParticle->setPressure(pressure);
77 localParticle->setSoundSpeed(soundspeed);
78 localParticle->setV_sig_AV(
79 std::max(localParticle->getV_sig_AV(), 2.0 * soundspeed)
80 );
81}
82
83
84template <typename Particle>
86 Particle* particle
87) {
88 const double timeStepSizeKick = 0.5
89 * Particle::getSpecies().getMinTimeStepSize();
90
91 /* Kick the particle */
92 particle->setV_full(
93 particle->getV_full() + timeStepSizeKick * particle->getA()
94 );
95
97}
98
99
100template <typename Particle>
102 Particle* localParticle
103) {
104
105 // Re-set the predicted velocities
106 localParticle->setV(localParticle->getV_full());
107
108 // Re-set the entropy
109 localParticle->setU(localParticle->getU_full());
110
111 // Re-compute the pressure
112 const double pressure = eos::gas_pressure_from_internal_energy(
113 localParticle->getDensity(),
114 localParticle->getU()
115 );
116
117 // Compute the new sound speed
118 const double soundspeed = eos::gas_soundspeed_from_pressure(
119 localParticle->getDensity(),
120 pressure
121 );
122
123 // Update variables
124 localParticle->setPressure(pressure);
125 localParticle->setSoundSpeed(soundspeed);
126 localParticle->setV_sig_AV(
127 std::max(localParticle->getV_sig_AV(), 2.0 * soundspeed)
128 );
129}
130
131
132template <typename Particle>
134 Particle* localParticle
135) {
136
137 // TODO: apply correct cosmology factors
138 double dt_kick_therm = 0.5 * localParticle->getSpecies().getMinTimeStepSize();
139
140 // Integrate the internal energy forward in time
141 const double delta_u = localParticle->getUDot() * dt_kick_therm;
142
143 // Do not decrease the energy by more than a factor of 2
144 localParticle->setU_full(std::max(
145 localParticle->getU_full() + delta_u,
146 localParticle->getU_full() * 0.5
147 ));
148
149 /* Check against absolute minimum.
150 * Default value is zero. */
151 if (localParticle->getU_full() < 0.0) {
152 localParticle->setU_full(0.0);
153 localParticle->setUDot(0.0);
154 }
155}
#define assertion1(expr, param)
contains functions and definitions related to the equation of state of ideal gases.
File containing macro-riddled functions related to dimensions.
Kernel functions for SPH.
void leapfrog_drift_global_time_step_size(Particle *particle)
Update a particle with the leapfrog KDK integrator.
Definition Leapfrog.cpph:11
void hydro_predict_extra(Particle *localParticle)
Predict additional particle fields forward in time when drifting.
Definition Leapfrog.cpph:27
void hydro_kick_extra_global_time_step_size(Particle *localParticle)
Kick the additional variables.
void leapfrog_kick_global_time_step_size(Particle *particle)
Kick steps.
Definition Leapfrog.cpph:85
void hydro_reset_predicted_values(Particle *localParticle)
Sets the values to be predicted in the drifts to their values at a kick time.
int isEntryFinite(const Vector< Size, Scalar > &vector)