CLASSpp Manual
Cosmology reference and developer manual
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1
3#include "float.h"
4#include "math.h"
5#include "stdio.h"
6#include "stdlib.h"
7#include "string.h"
8#include "version.h"
9
10#ifdef __cplusplus
11#include <algorithm>
12#include <map>
13#include <memory>
14#include <sstream>
15#include <stdexcept>
16#include <string>
17#include <type_traits>
18#include <utility>
19#include <vector>
20
21#include "exceptions.h"
22
23class InputModule;
24class BackgroundModule;
25class ThermodynamicsModule;
26class PerturbationsModule;
27class PrimordialModule;
28class NonlinearModule;
29class TransferModule;
30class SpectraModule;
31class LensingModule;
32class FileContent;
33
34typedef std::shared_ptr<const InputModule> InputModulePtr;
35typedef std::shared_ptr<const BackgroundModule> BackgroundModulePtr;
36typedef std::shared_ptr<const ThermodynamicsModule> ThermodynamicsModulePtr;
37typedef std::shared_ptr<const PerturbationsModule> PerturbationsModulePtr;
38typedef std::shared_ptr<const PrimordialModule> PrimordialModulePtr;
39typedef std::shared_ptr<const NonlinearModule> NonlinearModulePtr;
40typedef std::shared_ptr<const TransferModule> TransferModulePtr;
41typedef std::shared_ptr<const SpectraModule> SpectraModulePtr;
42typedef std::shared_ptr<const LensingModule> LensingModulePtr;
43#endif
44
45#ifndef __COMMON__
46#define __COMMON__
47
48#include "constants.h"
49#include "errors.h"
50#ifdef __cplusplus
51#include "precision.h"
52#endif
53
54/* _VERSION_ is defined in the generated version.h (from the pyproject.toml
55 version), included above. */
56/* @cond INCLUDE_WITH_DOXYGEN */
57
58#define _MAX_IT_ \
59 10000
61#define _QUADRATURE_MAX_ \
62 250
64#define _QUADRATURE_MAX_BG_ \
65 800
67#define _TOLVAR_ \
68 100.
70#define _HUGE_ 1.e99
71
72#define _EPSILON_ 1.e-10
73
74#define _OUTPUTPRECISION_ 12
76#define _COLUMNWIDTH_ \
77 24
79#define _DELIMITER_ "\t"
81#ifndef __CLASSDIR__
82#define __CLASSDIR__ \
83 "."
84#endif
85
86#define index_symmetric_matrix(i1, i2, N) \
87 (((i1) <= (i2)) \
88 ? ((i2) + N * (i1) - ((i1) * ((i1) + 1)) / 2) \
89 : ((i1) + N * (i2) - \
90 ((i2) * ((i2) + 1)) / \
91 2))
92/* @endcond */
93// needed because of weird openmp bug on macosx lion...
94
95/* macro for defining indices (usually one, sometimes a block) */
96#define class_define_index(index, condition, running_index, number_of_indices) \
97 { \
98 if (condition) { \
99 index = running_index; \
100 running_index += number_of_indices; \
101 } \
102 }
103
104/* macros for writing formatted output */
105#define class_fprintf_double(file, output, condition) \
106 { \
107 if (condition) \
108 fprintf(file, "%*.*e ", _COLUMNWIDTH_, _OUTPUTPRECISION_, output); \
109 }
110
111#define class_fprintf_double_or_default(file, output, condition, defaultvalue) \
112 { \
113 if (condition) \
114 fprintf(file, "%*.*e ", _COLUMNWIDTH_, _OUTPUTPRECISION_, output); \
115 else \
116 fprintf(file, "%*.*e ", _COLUMNWIDTH_, _OUTPUTPRECISION_, defaultvalue); \
117 }
118
119#define class_fprintf_int(file, output, condition) \
120 { \
121 if (condition) \
122 fprintf(file, \
123 "%*d%*s ", \
124 std::max(0, _COLUMNWIDTH_ - _OUTPUTPRECISION_ - 5), \
125 output, \
126 _OUTPUTPRECISION_ + 5, \
127 " "); \
128 }
129
130#define class_fprintf_columntitle(file, title, condition, colnum) \
131 { \
132 if (condition) \
133 fprintf(file, \
134 "%*s%2d:%-*s ", \
135 std::max(0, \
136 std::min(_COLUMNWIDTH_ - _OUTPUTPRECISION_ - 6 - 3, \
137 _COLUMNWIDTH_ - ((int) strlen(title)) - 3)), \
138 "", \
139 colnum++, \
140 _OUTPUTPRECISION_ + 6, \
141 title); \
142 }
143
144#define class_store_columntitle(titlestring, title, condition) \
145 { \
146 if (condition) { \
147 titlestring += title; \
148 titlestring += _DELIMITER_; \
149 } \
150 }
151
152#define class_store_double(storage, value, condition, dataindex) \
153 { \
154 if (condition) \
155 storage[dataindex++] = value; \
156 }
157
158#define class_store_double_or_default(storage, value, condition, dataindex, defaultvalue) \
159 { \
160 if (condition) \
161 storage[dataindex++] = value; \
162 else \
163 storage[dataindex++] = defaultvalue; \
164 }
165
166#ifdef __cplusplus
167/* Not in the extern "C" block: takes a std::string& (a C++ type), so it cannot
168 * have C language linkage; guarded by __cplusplus so C translation units never
169 * see this declaration. */
170int get_number_of_titles(const std::string& titlestring);
171#endif
172
173#endif
Definition parser.h:21