Skip to content

Commit 903536c

Browse files
neutrinocerosglesur
authored andcommitted
ENH: add randm function to idfx namespace
1 parent 58e74ca commit 903536c

File tree

14 files changed

+31
-250
lines changed

14 files changed

+31
-250
lines changed

src/global.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,25 @@ void IdefixOutStream::enableLogFile() {
103103
this->logFileEnabled = true;
104104
}
105105

106+
107+
/*********************************************/
108+
/**
109+
Customized random number generator
110+
Allow one to have consistant random numbers
111+
generators on different architectures.
112+
**/
113+
/*********************************************/
114+
real randm(void) {
115+
const int a = 16807;
116+
const int m = 2147483647;
117+
static int in0 = 13763 + 2417*prank;
118+
int q;
119+
120+
/* find random number */
121+
q = static_cast<int>(fmod(static_cast<double>(a) * in0, m));
122+
in0 = q;
123+
124+
return static_cast<real>(static_cast<double>(q) / static_cast<double>(m));
125+
}
126+
106127
} // namespace idfx

src/global.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace idfx {
1515
int initialize(); // Initialisation routine for idefix
16+
real randm(); // Custom random number generator
1617
class IdefixOutStream;
1718
class IdefixErrStream;
1819
class Profiler;

test/HD/FargoPlanet/setup.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,6 @@ real qpGlob;
1515
real RpGlob;
1616
real thicknessSmoothingGlob;
1717

18-
/*********************************************/
19-
/**
20-
Customized random number generator
21-
Allow one to have consistant random numbers
22-
generators on different architectures.
23-
**/
24-
/*********************************************/
25-
real randm(void) {
26-
const int a = 16807;
27-
const int m = 2147483647;
28-
static int in0 = 13763 + 2417*idfx::prank;
29-
int q;
30-
31-
/* find random number */
32-
q= (int) fmod((double) a * in0, m);
33-
in0=q;
34-
35-
return((real) ((double) q/(double)m));
36-
}
37-
3818

3919
void MySoundSpeed(DataBlock &data, const real t, IdefixArray3D<real> &cs) {
4020
IdefixArray1D<real> x1=data.x[IDIR];

test/HD/RWI-cavity/setup.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@ real jump_radius_glob{-1};
1111
real jump_width_glob{-1};
1212

1313

14-
real randm(void) {
15-
// Customized random number generator
16-
// Allow one to have consistent random numbers
17-
// generators on different architectures.
18-
const int a = 16807;
19-
const int m = 2147483647;
20-
static int in0 = 13763 + 2417*idfx::prank;
21-
int q;
22-
23-
/* find random number */
24-
q = (int) fmod((double) a * in0, m);
25-
in0=q;
26-
27-
return((real) ((double) q/(double)m));
28-
}
29-
3014

3115
// hydro functions to enroll
3216
// note that everywhere we make the assumption GM = 1, so that
@@ -110,7 +94,7 @@ void Setup::InitFlow(DataBlock &data) {
11094

11195
// add some random noise to the radial velocity component break the
11296
// axial symmetry and let the instability grow
113-
d.Vc(VX1,k,j,i) = d.Vc(VX2,k,j,i) * aspect_ratio * 1e-1*(0.5-randm());
97+
d.Vc(VX1,k,j,i) = d.Vc(VX2,k,j,i) * aspect_ratio * 1e-1*(0.5-idfx::randm());
11498

11599
}
116100
}

test/HD/ShearingBox/setup.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,6 @@ Analysis *analysis;
1010

1111
//#define STRATIFIED
1212

13-
/*********************************************/
14-
/**
15-
Customized random number generator
16-
Allow one to have consistant random numbers
17-
generators on different architectures.
18-
**/
19-
/*********************************************/
20-
real randm(void) {
21-
const int a = 16807;
22-
const int m = 2147483647;
23-
static int in0 = 13763 + 2417*idfx::prank;
24-
int q;
25-
26-
/* find random number */
27-
q= (int) fmod((double) a * in0, m);
28-
in0=q;
29-
30-
return((real) ((double) q/(double)m));
31-
}
32-
3313
void BodyForce(DataBlock &data, const real t, IdefixArray4D<real> &force) {
3414
idfx::pushRegion("BodyForce");
3515
IdefixArray1D<real> x = data.x[IDIR];

test/HD/VSI/setup.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,6 @@ real AmMidGlob;
99
real gammaGlob;
1010
real densityFloorGlob;
1111

12-
/*********************************************/
13-
/**
14-
Customized random number generator
15-
Allow one to have consistant random numbers
16-
generators on different architectures.
17-
**/
18-
/*********************************************/
19-
real randm(void) {
20-
const int a = 16807;
21-
const int m = 2147483647;
22-
static int in0 = 13763 + 2417*idfx::prank;
23-
int q;
24-
25-
/* find random number */
26-
q= (int) fmod((double) a * in0, m);
27-
in0=q;
28-
29-
return((real) ((double) q/(double)m));
30-
}
31-
3212

3313
void MySoundSpeed(DataBlock &data, const real t, IdefixArray3D<real> &cs) {
3414
IdefixArray1D<real> r=data.x[IDIR];
@@ -126,7 +106,7 @@ void Setup::InitFlow(DataBlock &data) {
126106

127107
d.Vc(RHO,k,j,i) = 1.0/(R*sqrt(R))*exp(1.0/(cs2)*(1/r-1/R));
128108
d.Vc(VX1,k,j,i) = 0.0;
129-
d.Vc(VX2,k,j,i) = 1e-1*(0.5-randm());
109+
d.Vc(VX2,k,j,i) = 1e-1*(0.5-idfx::randm());
130110
d.Vc(VX3,k,j,i) = Vk*sqrt(R/r-2.5*epsilon*epsilon);
131111

132112
}

test/HD/ViscousDisk/setup.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,6 @@ real gammaGlob;
1010
real densityFloorGlob;
1111
real alphaGlob;
1212

13-
/*********************************************/
14-
/**
15-
Customized random number generator
16-
Allow one to have consistant random numbers
17-
generators on different architectures.
18-
**/
19-
/*********************************************/
20-
real randm(void) {
21-
const int a = 16807;
22-
const int m = 2147483647;
23-
static int in0 = 13763 + 2417*idfx::prank;
24-
int q;
25-
26-
/* find random number */
27-
q= (int) fmod((double) a * in0, m);
28-
in0=q;
29-
30-
return((real) ((double) q/(double)m));
31-
}
32-
3313

3414
void MySoundSpeed(DataBlock &data, const real t, IdefixArray3D<real> &cs) {
3515
IdefixArray1D<real> r=data.x[IDIR];

test/HD/ViscousFlowPastCylinder/setup.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
11
#include "idefix.hpp"
22
#include "setup.hpp"
33

4-
/*********************************************/
5-
/**
6-
Customized random number generator
7-
Allow one to have consistant random numbers
8-
generators on different architectures.
9-
**/
10-
/*********************************************/
11-
real randm(void) {
12-
const int a = 16807;
13-
const int m = 2147483647;
14-
static int in0 = 13763 + 2417*idfx::prank;
15-
int q;
16-
17-
/* find random number */
18-
q= (int) fmod((double) a * in0, m);
19-
in0=q;
20-
21-
return((real) ((double) q/(double)m));
22-
}
23-
24-
254
// User-defined boundaries
265
void UserdefBoundary(DataBlock & data, int dir, BoundarySide side, const real t) {
276
if(dir==IDIR) {
@@ -85,8 +64,8 @@ void Setup::InitFlow(DataBlock &data) {
8564
// Flow past a cylinder
8665

8766
d.Vc(RHO,k,j,i) = ONE_F;
88-
d.Vc(VX1,k,j,i) = COS(d.x[JDIR](j))+0.02*(randm()-0.5);
89-
d.Vc(VX2,k,j,i) = -SIN(d.x[JDIR](j))+0.02*(randm()-0.5);
67+
d.Vc(VX1,k,j,i) = COS(d.x[JDIR](j))+0.02*(idfx::randm()-0.5);
68+
d.Vc(VX2,k,j,i) = -SIN(d.x[JDIR](j))+0.02*(idfx::randm()-0.5);
9069

9170
#if HAVE_ENERGY
9271
d.Vc(PRS,k,j,i) = ONE_F;

test/MHD/AmbipolarShearingBox/setup.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,6 @@ static real shear;
77

88
//#define STRATIFIED
99

10-
/*********************************************/
11-
/**
12-
Customized random number generator
13-
Allow one to have consistant random numbers
14-
generators on different architectures.
15-
**/
16-
/*********************************************/
17-
real randm(void) {
18-
const int a = 16807;
19-
const int m = 2147483647;
20-
static int in0 = 13763 + 2417*idfx::prank;
21-
int q;
22-
23-
/* find random number */
24-
q= (int) fmod((double) a * in0, m);
25-
in0=q;
26-
27-
return((real) ((double) q/(double)m));
28-
}
29-
30-
// Default constructor
31-
32-
3310
// UserStep, here only gravity (vertical and radial)
3411
void UserStep(DataBlock &data, const real t, const real dt) {
3512
Kokkos::Profiling::pushRegion("Setup::UserStep");
@@ -93,9 +70,9 @@ void Setup::InitFlow(DataBlock &data) {
9370
d.Vc(RHO,k,j,i) = 1.0;
9471
#endif
9572
d.Vc(PRS,k,j,i) = d.Vc(RHO,k,j,i)/cs2*gammaIdeal;
96-
d.Vc(VX1,k,j,i) = 1e-4*(randm()-0.5);
73+
d.Vc(VX1,k,j,i) = 1e-4*(idfx::randm()-0.5);
9774
d.Vc(VX2,k,j,i) = shear*x;
98-
d.Vc(VX3,k,j,i) = 1e-4*(randm()-0.5);
75+
d.Vc(VX3,k,j,i) = 1e-4*(idfx::randm()-0.5);
9976

10077
d.Vs(BX1s,k,j,i) = 0;
10178
d.Vs(BX2s,k,j,i) = B0y;

test/MHD/AmbipolarWind/setup.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,6 @@ real gammaGlob;
1111
real densityFloorGlob;
1212
real trSmoothingGlob;
1313

14-
/*********************************************/
15-
/**
16-
Customized random number generator
17-
Allow one to have consistant random numbers
18-
generators on different architectures.
19-
**/
20-
/*********************************************/
21-
real randm(void) {
22-
const int a = 16807;
23-
const int m = 2147483647;
24-
static int in0 = 13763 + 2417*idfx::prank;
25-
int q;
26-
27-
/* find random number */
28-
q= (int) fmod((double) a * in0, m);
29-
in0=q;
30-
31-
return((real) ((double) q/(double)m));
32-
}
3314

3415
KOKKOS_INLINE_FUNCTION real computeDensityFloor(real R, real z, real d_floor_0, real Rin, real c0){
3516

0 commit comments

Comments
 (0)