Skip to content

Commit 09ac0ac

Browse files
authored
Merge pull request #525 from LeanderSchlegel/time_master
Explicit time in CRPropa
2 parents d39003b + ccc8f26 commit 09ac0ac

26 files changed

+908
-68
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ add_library(crpropa SHARED
405405
src/magneticField/KST24Field.cpp
406406
src/magneticField/CMZField.cpp
407407
src/advectionField/AdvectionField.cpp
408+
src/advectionField/TimeDependentAdvectionField.cpp
408409
src/massDistribution/ConstantDensity.cpp
409410
src/massDistribution/Cordes.cpp
410411
src/massDistribution/Ferriere.cpp

doc/pages/acceleration.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ The exact nature of the dependency is subject of ongoing research. Here,
3030
so far only quasi-linear theory, a simplistic approach to diffusion of charged
3131
particles in magnetic fields is implemented in the corresponding modifier :cpp:class:`crpropa::QuasiLinearTheory`.
3232

33+
In the diffusive picture, the diffusive picture as an interplay between diffusion,
34+
advection and adiabatic cooling. Simple shock configurations are shown in the following
35+
example notebook using the DiffusionSDE module:
3336

37+
.. toctree::
38+
example_notebooks/acceleration/diffusive_shock_acceleration.ipynb
3439

3540

3641

doc/pages/example_notebooks/acceleration/DSA-moving-shock.ipynb

Lines changed: 395 additions & 0 deletions
Large diffs are not rendered by default.

doc/pages/example_notebooks/acceleration/diffusive_shock_acceleration.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"import pandas as pd\n",
4141
"import matplotlib.pyplot as plt\n",
4242
"\n",
43-
"marker= ['.', 's', '^', 'v', '<', '>', 'd', '8']"
43+
"marker = ['.', 's', '^', 'v', '<', '>', 'd', '8']"
4444
]
4545
},
4646
{

doc/pages/galactic_cosmic_rays.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ example notebook.
4747
.. toctree::
4848
example_notebooks/acceleration/diffusive_shock_acceleration.ipynb
4949

50+
In the next example time-dependent advection fields are introduced and acceleration
51+
at a moving shock and stationary shock are compared.
52+
53+
.. toctree::
54+
example_notebooks/acceleration/DSA-moving-shock.ipynb
55+
5056
Momentum Diffusion
5157
^^^^^^^^^^^^^^^^^^
5258

include/CRPropa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include "crpropa/magneticField/turbulentField/TurbulentField.h"
7575

7676
#include "crpropa/advectionField/AdvectionField.h"
77+
#include "crpropa/advectionField/TimeDependentAdvectionField.h"
7778

7879
#include "crpropa/massDistribution/Density.h"
7980
#include "crpropa/massDistribution/Nakanishi.h"

include/crpropa/Candidate.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Candidate: public Referenced {
4747
double currentStep; /**< Size of the currently performed step in [m] comoving units */
4848
double nextStep; /**< Proposed size of the next propagation step in [m] comoving units */
4949
std::string tagOrigin; /**< Name of interaction/source process which created this candidate*/
50+
double time; /**< Time [s] that has passed in the laboratory frame of reference */
5051

5152
static uint64_t nextSerialNumber;
5253
uint64_t serialNumber;
@@ -73,6 +74,8 @@ class Candidate: public Referenced {
7374

7475
void setTrajectoryLength(double length);
7576
double getTrajectoryLength() const;
77+
78+
double getVelocity() const;
7679

7780
void setRedshift(double z);
7881
double getRedshift() const;
@@ -105,6 +108,12 @@ class Candidate: public Referenced {
105108
void setTagOrigin(std::string tagOrigin);
106109
std::string getTagOrigin() const;
107110

111+
/**
112+
Sets the time of the candidate.
113+
*/
114+
void setTime(double t);
115+
double getTime() const;
116+
108117
/**
109118
Make a bid for the next step size: the lowest wins.
110119
*/

include/crpropa/Units.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,19 @@ static const double microsecond = 1e-6 * second;
127127
static const double millisecond = 1e-3 * second;
128128
static const double minute = 60 * second;
129129
static const double hour = 3600 * second;
130+
static const double day = 24 * hour;
131+
static const double year = 365.25 * 24 * hour;
132+
static const double kiloyear = 1e3 * year;
133+
static const double Megayear = 1e6 * year;
134+
static const double Gigayear = 1e9 * year;
130135
static const double ns = nanosecond;
131136
static const double mus = microsecond;
132137
static const double ms = millisecond;
133138
static const double sec = second;
139+
static const double yr = year;
140+
static const double kyr = kiloyear;
141+
static const double Myr = Megayear;
142+
static const double Gyr = Gigayear;
134143

135144
// volume
136145
static const double ccm = cm*cm*cm;

include/crpropa/advectionField/AdvectionField.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class AdvectionField: public Referenced {
2424
public:
2525
virtual ~AdvectionField() {
2626
}
27-
virtual Vector3d getField(const Vector3d &position) const = 0;
28-
virtual double getDivergence(const Vector3d &position) const = 0;
27+
virtual Vector3d getField(const Vector3d &position, const double &time=0) const = 0;
28+
virtual double getDivergence(const Vector3d &position, const double &time=0) const = 0;
2929
};
3030

3131

@@ -37,8 +37,8 @@ class AdvectionFieldList: public AdvectionField {
3737
std::vector<ref_ptr<AdvectionField> > fields;
3838
public:
3939
void addField(ref_ptr<AdvectionField> field);
40-
Vector3d getField(const Vector3d &position) const;
41-
double getDivergence(const Vector3d &position) const;
40+
Vector3d getField(const Vector3d &position, const double &time=0) const;
41+
double getDivergence(const Vector3d &position, const double &time=0) const;
4242
};
4343

4444

@@ -50,8 +50,8 @@ class UniformAdvectionField: public AdvectionField {
5050
Vector3d value;
5151
public:
5252
UniformAdvectionField(const Vector3d &value);
53-
Vector3d getField(const Vector3d &position) const;
54-
double getDivergence(const Vector3d &position) const;
53+
Vector3d getField(const Vector3d &position, const double &time=0) const;
54+
double getDivergence(const Vector3d &position, const double &time=0) const;
5555

5656
std::string getDescription() const;
5757
};
@@ -73,8 +73,8 @@ class ConstantSphericalAdvectionField: public AdvectionField {
7373
*/
7474

7575
ConstantSphericalAdvectionField(const Vector3d origin, double vWind);
76-
Vector3d getField(const Vector3d &position) const;
77-
double getDivergence(const Vector3d &position) const;
76+
Vector3d getField(const Vector3d &position, const double &time=0) const;
77+
double getDivergence(const Vector3d &position, const double &time=0) const;
7878

7979
void setOrigin(const Vector3d origin);
8080
void setVWind(double vMax);
@@ -108,8 +108,8 @@ class SphericalAdvectionField: public AdvectionField {
108108
@param alpha Tuning parameter
109109
*/
110110
SphericalAdvectionField(const Vector3d origin, double radius, double vMax, double tau, double alpha);
111-
Vector3d getField(const Vector3d &position) const;
112-
double getDivergence(const Vector3d &position) const;
111+
Vector3d getField(const Vector3d &position, const double &time=0) const;
112+
double getDivergence(const Vector3d &position, const double &time=0) const;
113113

114114
double getV(const double &r) const;
115115

@@ -144,8 +144,8 @@ class OneDimensionalCartesianShock: public AdvectionField {
144144
@param lShock //shock width
145145
*/
146146
OneDimensionalCartesianShock(double compressionRatio, double vUp, double lShock);
147-
Vector3d getField(const Vector3d &position) const;
148-
double getDivergence(const Vector3d &position) const;
147+
Vector3d getField(const Vector3d &position, const double &time=0) const;
148+
double getDivergence(const Vector3d &position, const double &time=0) const;
149149

150150
void setComp(double compressionRatio);
151151
void setVup(double vUp);
@@ -178,8 +178,8 @@ class OneDimensionalSphericalShock: public AdvectionField {
178178
@param coolUpstream //flag for upstream cooling
179179
*/
180180
OneDimensionalSphericalShock(double rShock, double vUp, double compressionRatio, double lShock, bool coolUpstream);
181-
Vector3d getField(const Vector3d &position) const;
182-
double getDivergence(const Vector3d &position) const;
181+
Vector3d getField(const Vector3d &position, const double &time=0) const;
182+
double getDivergence(const Vector3d &position, const double &time=0) const;
183183

184184
void setComp(double compressionRatio);
185185
void setVup(double vUp);
@@ -217,8 +217,8 @@ class ObliqueAdvectionShock: public AdvectionField {
217217
218218
*/
219219
ObliqueAdvectionShock(double compressionRatio, double vXUp, double vY, double lShock);
220-
Vector3d getField(const Vector3d &position) const;
221-
double getDivergence(const Vector3d &position) const;
220+
Vector3d getField(const Vector3d &position, const double &time=0) const;
221+
double getDivergence(const Vector3d &position, const double &time=0) const;
222222

223223
void setComp(double compressionRatio);
224224
void setVup(double vXUp);
@@ -257,8 +257,8 @@ class SphericalAdvectionShock: public AdvectionField {
257257
*/
258258
SphericalAdvectionShock(const Vector3d origin, double r_0, double v_0, double lambda);
259259

260-
Vector3d getField(const Vector3d &position) const;
261-
double getDivergence(const Vector3d &position) const;
260+
Vector3d getField(const Vector3d &position, const double &time=0) const;
261+
double getDivergence(const Vector3d &position, const double &time=0) const;
262262

263263
double g(double R) const;
264264
double g_prime(double R) const;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#ifndef CRPROPA_TIMEDEPENDENTADVECTIONFIELD_H
2+
#define CRPROPA_TIMEDEPENDENTADVECTIONFIELD_H
3+
4+
#include "crpropa/advectionField/AdvectionField.h"
5+
6+
#include <string>
7+
#include <iostream>
8+
#include <cmath>
9+
#include <cstdlib>
10+
#include <sstream>
11+
12+
#include "crpropa/Vector3.h"
13+
#include "crpropa/Referenced.h"
14+
#include "crpropa/Units.h"
15+
16+
namespace crpropa {
17+
18+
/**
19+
@class OneDimensionalTimeDependentShock
20+
@brief Advection field in x-direction with shock at x = x0 that propagates with a constant speed vsh = v_up - v_down
21+
and width x_sh approximated by a tanh() with variable compression ratio r_comp = v_up/v_down.
22+
Pre- and postshock speeds as well as shock speed must be specified.
23+
The shock position at t=0 can be specified, as well as the time t0 the shock starts to propagate.
24+
*/
25+
class OneDimensionalTimeDependentShock: public AdvectionField {
26+
double v_sh; // shock speed assuming xsh = vsh * t + xsh_0
27+
double v1; // speed behind the shock in lab frame
28+
double v0; // undisturbed speed in lab frame
29+
double l_sh; // shock width
30+
double x_sh0; // shock position at t = 0
31+
double t_sh0; // time the shock starts to propagate, before: vsh=0
32+
public:/** Constructor
33+
@param v_sh; // shock speed
34+
@param v1; // speed behind the shock in lab frame
35+
@param v0; // undisturbed speed in lab frame
36+
@param l_sh; // shock width
37+
*/
38+
OneDimensionalTimeDependentShock(double v_sh, double v1, double v0, double l_sh);
39+
40+
Vector3d getField(const Vector3d &position, const double &time=0) const;
41+
double getDivergence(const Vector3d &position, const double &time=0) const;
42+
43+
void setShockSpeed(double v_sh);
44+
void setSpeeds(double v1, double v0);
45+
void setShockWidth(double l_sh);
46+
void setShockPosition(double x_sh0);
47+
void setShockTime(double t_sh0);
48+
49+
double getVshock() const;
50+
double getV1() const;
51+
double getV0() const;
52+
double getShockWidth() const;
53+
double getShockPosition(double time) const;
54+
double getShockTime() const;
55+
};
56+
57+
/**
58+
@class SedovTaylorBlastWave
59+
@brief Spherical advection field with shock at R(t), velocity vsh(t) and width l_sh approximated by tanh()
60+
Wind solution is given by Kahn 1975, see also Drury 1983 for acceleration at the expanding shock
61+
*/
62+
class SedovTaylorBlastWave: public AdvectionField {
63+
double E0; // energy of the explosion
64+
double rho0; // initial density
65+
double l_sh; // shock width
66+
public:/** Constructor
67+
@param E0 // energy of the explosion
68+
@param rho0 // initial density
69+
70+
*/
71+
SedovTaylorBlastWave(double E0, double rho0, double l_sh);
72+
Vector3d getField(const Vector3d &position, const double &time=0) const;
73+
double getDivergence(const Vector3d &position, const double &time=0) const;
74+
75+
void setShockWidth(double l_sh);
76+
void setEnergy(double E0);
77+
void setDensity(double rho0);
78+
79+
double getShockRadius(double time) const;
80+
double getShockSpeed(double time) const;
81+
double getShockWidth() const;
82+
double getEnergy() const;
83+
double getDensity() const;
84+
};
85+
86+
} // namespace crpropa
87+
88+
#endif // CRPROPA_TIMEDEPENDENTADVECTIONFIELD_H

0 commit comments

Comments
 (0)