Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
anonymous_namespace{adhesion.cpp} Namespace Reference

Functions

void gen_init_expot (const Mesh &potential, Mesh &expotential, double nu)
 
double get_summation (const std::vector< double > &exp_aux)
 
void convolution_y1 (Mesh &potential, const std::vector< double > &gaussian, const Mesh &expotential_0)
 
void convolution_y2 (Mesh &potential, const std::vector< double > &gaussian)
 
void convolution_y3 (Mesh &potential, const std::vector< double > &gaussian)
 
void gen_expot (Mesh &potential, const Mesh &expotential_0, double nu, double b)
 

Variables

const double ACC = 1e-10
 
const double log_acc = log(ACC)
 

Function Documentation

void anonymous_namespace{adhesion.cpp}::convolution_y1 ( Mesh potential,
const std::vector< double > &  gaussian,
const Mesh expotential_0 
)

Definition at line 40 of file adhesion.cpp.

References get_summation(), and Mesh::N.

Referenced by gen_expot().

40  {
41  // multi-thread index is y3
42  // compute f1 (x1, y2, y3)
43 
44  const unsigned int N = potential.N;
45  std::vector<FTYPE_t> exp_aux;
46 
47  #pragma omp parallel for private(exp_aux)
48  for (int x1 = 0; x1 < N; x1++){
49  for (int y2 = 0; y2 < N; y2++){
50  for (int y3 = 0; y3 < N; y3++){
51  exp_aux.reserve(N);
52  // fill in exponents
53  for (int y1 = 0; y1 < N; y1++){
54  exp_aux.push_back(expotential_0(y1, y2, y3)+gaussian[std::abs(x1-y1)]);
55  }
56  potential(x1, y2, y3) = get_summation(exp_aux); // potential is now f1
57  exp_aux.clear();
58  }
59  }
60  }
61 }
size_t N
Definition: class_mesh.hpp:102
double get_summation(const std::vector< double > &exp_aux)
Definition: adhesion.cpp:30
void anonymous_namespace{adhesion.cpp}::convolution_y2 ( Mesh potential,
const std::vector< double > &  gaussian 
)

Definition at line 63 of file adhesion.cpp.

References get_summation(), and Mesh::N.

Referenced by gen_expot().

63  {
64  // compute f2 (x1, x2, y3)
65 
66  const unsigned int N = potential.N;
67  std::vector<FTYPE_t> sum_aux;
68  std::vector<FTYPE_t> exp_aux;
69 
70  #pragma omp parallel for private(sum_aux, exp_aux)
71  for (int x1 = 0; x1 < N; x1++){
72  for (int y3 = 0; y3 < N; y3++){
73  sum_aux.reserve(N);
74  for (int x2 = 0; x2 < N; x2++){
75  exp_aux.reserve(N);
76  // fill in exponents
77  for (int y2 = 0; y2 < N; y2++){
78  exp_aux.push_back(potential(x1, y2, y3) + gaussian[abs(x2-y2)]);
79  }
80  sum_aux.push_back(get_summation(exp_aux));
81  exp_aux.clear();
82  }
83 
84  for (int x2 = 0; x2 < N; x2++){
85  potential(x1, x2, y3) = sum_aux[x2]; // potential is now f2
86  }
87  sum_aux.clear();
88  }
89  }
90 }
size_t N
Definition: class_mesh.hpp:102
double get_summation(const std::vector< double > &exp_aux)
Definition: adhesion.cpp:30
void anonymous_namespace{adhesion.cpp}::convolution_y3 ( Mesh potential,
const std::vector< double > &  gaussian 
)

Definition at line 92 of file adhesion.cpp.

References get_summation(), and Mesh::N.

Referenced by gen_expot().

92  {
93  // compute f3 (x1, x2, x3) == expotential(x, b)
94 
95  const unsigned int N = potential.N;
96  std::vector<FTYPE_t> sum_aux;
97  std::vector<FTYPE_t> exp_aux;
98 
99  #pragma omp parallel for private(sum_aux, exp_aux)
100  for (int x1 = 0; x1 < N; x1++){
101  for (int x2 = 0; x2 < N; x2++){
102  sum_aux.reserve(N);
103  for (int x3 = 0; x3 < N; x3++){
104  exp_aux.reserve(N);
105  // fill in exponents
106  for (int y3 = 0; y3 < N; y3++){
107  exp_aux.push_back(potential(x1, x2, y3) + gaussian[abs(x3-y3)]);
108  }
109  sum_aux.push_back(get_summation(exp_aux));
110  exp_aux.clear();
111  }
112  for (int x3 = 0; x3 < N; x3++){
113  potential(x1, x2, x3) = sum_aux[x3]; // potential is now f3
114  }
115  sum_aux.clear();
116  }
117  }
118 }
size_t N
Definition: class_mesh.hpp:102
double get_summation(const std::vector< double > &exp_aux)
Definition: adhesion.cpp:30
void anonymous_namespace{adhesion.cpp}::gen_expot ( Mesh potential,
const Mesh expotential_0,
double  nu,
double  b 
)

Definition at line 120 of file adhesion.cpp.

References convolution_y1(), convolution_y2(), convolution_y3(), and Mesh::N.

Referenced by App_Var_AA::AAImpl::aa_convolution().

121 {
122  /* Computing convolution using direct sum */
123  BOOST_LOG_TRIVIAL(debug) << "Computing expotential in q-space...";
124  /*
125  f(x1, x2, x3) = \int dy^3 { g(y1, y2, y3) * h(x1 - y1) * h(x2 - y2) * h(x3 - y3)}
126  ..
127  f1 (x1, y2, y3) = \int dy1 { g (y1, y2, y3) * h(x1 - y1)} :: N^3 sums of length N
128  f2 (x1, x2, y3) = \int dy2 { f1 (x1, y2, y3) * h(x2 - y2)} :: N^3 sums of length N
129  f3 (x1, x2, x3) = \int dy3 { f2 (x1, x2, y3) * h(x3 - y3)} :: N^3 sums of length N
130  */
131 
132  // store values of exponential - every convolution uses the same exp(-r^2/4bv)
133  std::vector<FTYPE_t> gaussian(expotential_0.N);
134 
135  #pragma omp parallel for
136  for (size_t i = 0; i < expotential_0.N; i++){
137  gaussian[i]=-i*i/(4*b*nu);
138  }
139 
140  convolution_y1(potential, gaussian, expotential_0);
141  convolution_y2(potential, gaussian);
142  convolution_y3(potential, gaussian);
143 }
size_t N
Definition: class_mesh.hpp:102
void convolution_y2(Mesh &potential, const std::vector< double > &gaussian)
Definition: adhesion.cpp:63
void convolution_y1(Mesh &potential, const std::vector< double > &gaussian, const Mesh &expotential_0)
Definition: adhesion.cpp:40
void convolution_y3(Mesh &potential, const std::vector< double > &gaussian)
Definition: adhesion.cpp:92
void anonymous_namespace{adhesion.cpp}::gen_init_expot ( const Mesh potential,
Mesh expotential,
double  nu 
)

Definition at line 21 of file adhesion.cpp.

References Mesh_base< T >::length.

Referenced by App_Var_AA::pot_corr().

22 {
23  BOOST_LOG_TRIVIAL(debug) << "Storing initial expotenital in q-space...";
24  // store exponent only
25  // *expotential = potential; !!! <- do not use this in case potential and expotential are meshes of different size
26  #pragma omp parallel for
27  for (size_t i = 0; i < expotential.length; i++) expotential[i] = -potential[i] / (2*nu);
28 }
size_t length
Definition: class_mesh.hpp:32
double anonymous_namespace{adhesion.cpp}::get_summation ( const std::vector< double > &  exp_aux)

Definition at line 30 of file adhesion.cpp.

References log_acc.

Referenced by convolution_y1(), convolution_y2(), and convolution_y3().

31 {
32  FTYPE_t max_exp = *max_element(exp_aux.begin(), exp_aux.end());
33  FTYPE_t sum = 0;
34  for(auto const& a_exp: exp_aux) {
35  if ((a_exp - max_exp) > log_acc) sum+= exp(a_exp - max_exp);
36  }
37  return max_exp + log(sum);
38 }

Variable Documentation

const double anonymous_namespace{adhesion.cpp}::ACC = 1e-10

Definition at line 18 of file adhesion.cpp.

const double anonymous_namespace{adhesion.cpp}::log_acc = log(ACC)

Definition at line 19 of file adhesion.cpp.

Referenced by get_summation().