Peano
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(),
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 // Reset left-right bounds outside of the density sweep.
83 localParticle->setSmlIterLeftBound(Particle::getSmlMin());
84 localParticle->setSmlIterRightBound(Particle::getSmlMax());
85}
86
87
88template <typename Particle>
90 Particle* particle
91) {
92 const double timeStepSizeKick = 0.5
93 * Particle::getSpecies().getMinTimeStepSize();
94
95 /* Kick the particle */
96 particle->setV_full(
97 particle->getV_full() + timeStepSizeKick * particle->getA()
98 );
99
101}
102
103
104template <typename Particle>
106 Particle* localParticle
107) {
108
109 // Re-set the predicted velocities
110 localParticle->setV(localParticle->getV_full());
111
112 // Re-set the entropy
113 localParticle->setU(localParticle->getU_full());
114
115 // Re-compute the pressure
116 const double pressure = eos::gas_pressure_from_internal_energy(
117 localParticle->getDensity(),
118 localParticle->getU()
119 );
120
121 // Compute the new sound speed
122 const double soundspeed = eos::gas_soundspeed_from_pressure(
123 localParticle->getDensity(),
125 );
126
127 // Update variables
128 localParticle->setPressure(pressure);
129 localParticle->setSoundSpeed(soundspeed);
130 localParticle->setV_sig_AV(
131 std::max(localParticle->getV_sig_AV(), 2.0 * soundspeed)
132 );
133}
134
135
136template <typename Particle>
138 Particle* localParticle
139) {
140
141 // TODO: apply correct cosmology factors
142 double dt_kick_therm = 0.5 * localParticle->getSpecies().getMinTimeStepSize();
143
144 // Integrate the internal energy forward in time
145 const double delta_u = localParticle->getUDot() * dt_kick_therm;
146
147 // Do not decrease the energy by more than a factor of 2
148 localParticle->setU_full(std::max(
149 localParticle->getU_full() + delta_u,
150 localParticle->getU_full() * 0.5
151 ));
152
153 /* Check against absolute minimum.
154 * Default value is zero. */
155 if (localParticle->getU_full() < 0.0) {
156 localParticle->setU_full(0.0);
157 localParticle->setUDot(0.0);
158 }
159}
#define assertion1(expr, param)
float pressure
#define dt_kick_therm
Definition main.cpp:20
#define dt_therm
Definition main.cpp:19
const float soundspeed
Definition hydro.h:373
File containing macro-riddled functions related to dimensions.
const float h_inv
Definition hydro_iact.h:158
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:89
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)
contains functions and definitions related to the equation of state of ideal gases.
Kernel functions for SPH.