Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ContinuitySolver< NDIM, T > Class Template Reference

#include <continuity_solver.h>

Inheritance diagram for ContinuitySolver< NDIM, T >:
Collaboration diagram for ContinuitySolver< NDIM, T >:

Public Member Functions

 ContinuitySolver ()
 
 ContinuitySolver (unsigned int N, bool verbose=true)
 
 ContinuitySolver (unsigned int N, unsigned int Nmin, bool verbose=true)
 
 ContinuitySolver (MultiGrid< NDIM, T > &source, bool verbose=true)
 
void set_rhomax (double rhomax)
 
void set_rhomin (double rhomin)
 
void set_growthfachubble (double growthfachubble)
 
bfunc (T delta_rho)
 
l_operator (unsigned int level, std::vector< unsigned int > &index_list, bool addsource)
 
dl_operator (unsigned int level, std::vector< unsigned int > &index_list)
 
- Public Member Functions inherited from MultiGridSolver< NDIM, T >
 MultiGridSolver ()
 
 MultiGridSolver (size_t N)
 
 MultiGridSolver (size_t N, bool verbose)
 
 MultiGridSolver (size_t N, size_t Nmin, bool verbose)
 
size_t get_istep () const
 
T * get_y (size_t level=0)
 
T const * get_y (size_t level=0) const
 
Grid< NDIM, T > & get_grid (size_t level=0)
 
const Grid< NDIM, T > & get_grid (size_t level=0) const
 
MultiGrid< NDIM, T > & get_mlt_grid (size_t level=0)
 
const MultiGrid< NDIM, T > & get_mlt_grid (size_t level=0) const
 
T * get_external_field (size_t level, size_t field)
 
T const * get_external_field (size_t level, size_t field) const
 
Grid< NDIM, T > & get_external_grid (size_t level, size_t field)
 
const Grid< NDIM, T > & get_external_grid (size_t level, size_t field) const
 
size_t get_external_field_size () const
 
get_multigrid_source (size_t level, size_t i) const
 
void set_epsilon (double eps_converge)
 
void set_maxsteps (size_t maxsteps)
 
void set_ngs_sweeps (size_t ngs_fine, size_t ngs_coarse)
 
void set_convergence_criterion_residual (bool use_residual)
 
void set_Nlevel (size_t N)
 
size_t get_N (size_t level=0) const
 
size_t get_Ntot (size_t level=0) const
 
size_t get_Nlevel () const
 
void add_external_grid (MultiGrid< NDIM, T > *field)
 
void set_initial_guess (T guess)
 
void set_initial_guess (T *guess)
 
void set_initial_guess (Grid< NDIM, T > &guess)
 
Exit_Status solve ()
 
void clear ()
 
virtual T upd_operator (const T f, const size_t level, const std::vector< size_t > &index_list, const T h) const
 
virtual T l_operator (const size_t level, const std::vector< size_t > &index_list, bool addsource, const T h) const
 
virtual T dl_operator (const size_t level, const std::vector< size_t > &index_list, const T h) const
 
virtual void correct_sol (Grid< NDIM, T > &f, const Grid< NDIM, T > &corr, const size_t level)
 
virtual Exit_Status check_convergence ()
 
virtual void check_solution (size_t level, Grid< NDIM, T > &sol)
 
void check_solution (size_t level)
 

Private Attributes

double _rhomin = 0.1
 
double _rhomax = 1e30
 
double _growthfachubble = 0.5
 

Additional Inherited Members

- Public Types inherited from MultiGridSolver< NDIM, T >
enum  Exit_Status {
  Exit_Status::SUCCESS, Exit_Status::FAILURE, Exit_Status::SLOW, Exit_Status::ITERATE,
  Exit_Status::MAX_STEPS
}
 
- Public Attributes inherited from MultiGridSolver< NDIM, T >
bool _store_all_residual = false
 
std::vector< double_res_domain_array
 
- Protected Member Functions inherited from MultiGridSolver< NDIM, T >
void get_neighbor_gridindex (std::vector< size_t > &index_list, size_t i, size_t ngrid)
 
- Protected Attributes inherited from MultiGridSolver< NDIM, T >
bool _verbose
 
bool _conv_criterion_residual = true
 
double _eps_converge = 1e-5
 
size_t _maxsteps = 1000
 
size_t _istep_vcycle = 0
 
double _rms_res
 
double _rms_res_i
 
double _rms_res_old
 

Detailed Description

template<unsigned int NDIM, typename T>
class ContinuitySolver< NDIM, T >

Definition at line 25 of file continuity_solver.h.

Constructor & Destructor Documentation

template<unsigned int NDIM, typename T>
ContinuitySolver< NDIM, T >::ContinuitySolver ( )
inline

Definition at line 34 of file continuity_solver.h.

34 {}
template<unsigned int NDIM, typename T>
ContinuitySolver< NDIM, T >::ContinuitySolver ( unsigned int  N,
bool  verbose = true 
)
inline

Definition at line 35 of file continuity_solver.h.

template<unsigned int NDIM, typename T>
ContinuitySolver< NDIM, T >::ContinuitySolver ( unsigned int  N,
unsigned int  Nmin,
bool  verbose = true 
)
inline

Definition at line 36 of file continuity_solver.h.

36 : MultiGridSolver<NDIM,T>(N, Nmin, verbose) {} ;
template<unsigned int NDIM, typename T>
ContinuitySolver< NDIM, T >::ContinuitySolver ( MultiGrid< NDIM, T > &  source,
bool  verbose = true 
)
inline

Definition at line 37 of file continuity_solver.h.

References MultiGridSolver< NDIM, T >::add_external_grid().

37  : MultiGridSolver<NDIM,T>(source.get_N(), source.get_Nmin(), verbose) {
39  }
size_t get_Nmin() const
Definition: multigrid.cpp:116
size_t get_N(size_t level=0) const
Definition: multigrid.cpp:90
void add_external_grid(MultiGrid< NDIM, T > *field)

Member Function Documentation

template<unsigned int NDIM, typename T>
T ContinuitySolver< NDIM, T >::bfunc ( delta_rho)
inline

Definition at line 53 of file continuity_solver.h.

References max(), and anonymous_namespace{chameleon.cpp}::min().

Referenced by ContinuitySolver< NDIM, T >::dl_operator(), and ContinuitySolver< NDIM, T >::l_operator().

53  {
54  return std::min( std::max(1.0 + delta_rho, _rhomin) , _rhomax);
55  }
static T max(const std::vector< T > &data)
Definition: core_app.cpp:61
T min(const std::vector< T > &data)
Definition: chameleon.cpp:140
template<unsigned int NDIM, typename T>
T ContinuitySolver< NDIM, T >::dl_operator ( unsigned int  level,
std::vector< unsigned int > &  index_list 
)
inline

Definition at line 94 of file continuity_solver.h.

References ContinuitySolver< NDIM, T >::bfunc(), Catch::cout(), MultiGridSolver< NDIM, T >::get_external_field(), ccl_test_distances::h, and growth_allz::T.

94  {
95  unsigned int i = index_list[0];
96 
97  // Gridspacing
98  T h = 1.0/T( MultiGridSolver<NDIM,T>::get_N(level) );
99 
100  // Solution and pde-source grid at current level
102 
103  // Derivative of the kinetic term
104  T dkinetic = 0.0;
105  T boff = bfunc(delta[i]);
106  for(unsigned int j = 0; j < NDIM; j++){
107  unsigned int iminus = index_list[2*j+1];
108  unsigned int iplus = index_list[2*j+2];
109  T bminus = 0.5 * ( bfunc(delta[iminus]) + boff );
110  T bplus = 0.5 * ( bfunc(delta[iplus]) + boff );
111  dkinetic += -(bplus + bminus);
112  }
113 
114  // The derivative of the source is zero as there is no field dependence
115  T dsource = 0.0;
116 
117  // Check for error
118  T dl = dkinetic/(h*h) - dsource;
119  if(fabs(dl) < 1e-5){
120  std::cout << "Error: dl = " << dl << " delta_rho = " << delta[i] << " b = " << boff << std::endl;
121  exit(1);
122  }
123 
124  return dl;
125  }
T bfunc(T delta_rho)
T * get_external_field(size_t level, size_t field)
std::ostream & cout()
template<unsigned int NDIM, typename T>
T ContinuitySolver< NDIM, T >::l_operator ( unsigned int  level,
std::vector< unsigned int > &  index_list,
bool  addsource 
)
inline

Definition at line 58 of file continuity_solver.h.

References ContinuitySolver< NDIM, T >::bfunc(), MultiGridSolver< NDIM, T >::get_external_field(), MultiGridSolver< NDIM, T >::get_multigrid_source(), MultiGridSolver< NDIM, T >::get_y(), ccl_test_distances::h, and growth_allz::T.

58  {
59  unsigned int i = index_list[0];
60 
61  // Gridspacing
62  T h = 1.0/T( MultiGridSolver<NDIM,T>::get_N(level) );
63 
64  // Solution and pde-source grid at current level
65  T *phi = MultiGridSolver<NDIM,T>::get_y(level);
67 
68  // Compute the kinetic term D[b Df] (in 1D this is phi''_i = phi_{i+1} + phi_{i-1} - 2 phi_{i} )
69  T kinetic = 0.0;
70  T f = phi[i];
71  T boff = bfunc(delta[i]);
72  for(unsigned int j = 0; j < NDIM; j++){
73  unsigned int iminus = index_list[2*j+1];
74  unsigned int iplus = index_list[2*j+2];
75  T fminus = phi[iminus];
76  T fplus = phi[iplus];
77  T bminus = 0.5 * ( bfunc(delta[iminus]) + boff );
78  T bplus = 0.5 * ( bfunc(delta[iplus]) + boff );
79  kinetic += bplus * (fplus - f) - bminus * (f - fminus);
80  }
81 
82  // The right hand side of the PDE with the source term arising
83  // from restricting the equation down to the lower level
84  T source = -_growthfachubble * delta[i];
85  if( level > 0 && addsource ){
87  }
88 
89  // The discretized equation of motion L_{ijk...}(phi)
90  return kinetic/(h*h) - source;
91  }
T bfunc(T delta_rho)
T * get_y(size_t level=0)
T * get_external_field(size_t level, size_t field)
T get_multigrid_source(size_t level, size_t i) const
template<unsigned int NDIM, typename T>
void ContinuitySolver< NDIM, T >::set_growthfachubble ( double  growthfachubble)
inline

Definition at line 49 of file continuity_solver.h.

References growthfachubble.

Referenced by main().

49  {
51  }
DType growthfachubble
Definition: continuity.cpp:31
template<unsigned int NDIM, typename T>
void ContinuitySolver< NDIM, T >::set_rhomax ( double  rhomax)
inline

Definition at line 41 of file continuity_solver.h.

Referenced by main().

41  {
42  _rhomax = rhomax;
43  }
template<unsigned int NDIM, typename T>
void ContinuitySolver< NDIM, T >::set_rhomin ( double  rhomin)
inline

Definition at line 45 of file continuity_solver.h.

Referenced by main().

45  {
46  _rhomin = rhomin;
47  }

Member Data Documentation

template<unsigned int NDIM, typename T>
double ContinuitySolver< NDIM, T >::_growthfachubble = 0.5
private

Definition at line 30 of file continuity_solver.h.

template<unsigned int NDIM, typename T>
double ContinuitySolver< NDIM, T >::_rhomax = 1e30
private

Definition at line 29 of file continuity_solver.h.

template<unsigned int NDIM, typename T>
double ContinuitySolver< NDIM, T >::_rhomin = 0.1
private

Definition at line 28 of file continuity_solver.h.


The documentation for this class was generated from the following file: