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
34using InputModulePtr = std::shared_ptr<const InputModule>;
35using BackgroundModulePtr = std::shared_ptr<const BackgroundModule>;
36using ThermodynamicsModulePtr = std::shared_ptr<const ThermodynamicsModule>;
37using PerturbationsModulePtr = std::shared_ptr<const PerturbationsModule>;
38using PrimordialModulePtr = std::shared_ptr<const PrimordialModule>;
39using NonlinearModulePtr = std::shared_ptr<const NonlinearModule>;
40using TransferModulePtr = std::shared_ptr<const TransferModule>;
41using SpectraModulePtr = std::shared_ptr<const SpectraModule>;
42using LensingModulePtr = std::shared_ptr<const LensingModule>;
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 _HUGE_ 1.e99
68
69#define _EPSILON_ 1.e-10
70
71#define _OUTPUTPRECISION_ 12
73#define _COLUMNWIDTH_ \
74 24
76#define _DELIMITER_ "\t"
78#ifndef __CLASSDIR__
79#define __CLASSDIR__ \
80 "."
81#endif
82
85inline int index_symmetric_matrix(int i1, int i2, int N) {
86 return (i1 <= i2) ? (i2 + N * i1 - (i1 * (i1 + 1)) / 2) : (i1 + N * i2 - (i2 * (i2 + 1)) / 2);
87}
88/* @endcond */
89// needed because of weird openmp bug on macosx lion...
90
91/* macro for defining indices (usually one, sometimes a block) */
92#define class_define_index(index, condition, running_index, number_of_indices) \
93 { \
94 if (condition) { \
95 (index) = running_index; \
96 (running_index) += (number_of_indices); \
97 } \
98 }
99
100/* macros for writing formatted output */
101#define class_fprintf_double(file, output, condition) \
102 { \
103 if (condition) \
104 fprintf(file, "%*.*e ", _COLUMNWIDTH_, _OUTPUTPRECISION_, output); \
105 }
106
107#define class_fprintf_int(file, output, condition) \
108 { \
109 if (condition) \
110 fprintf(file, \
111 "%*d%*s ", \
112 std::max(0, _COLUMNWIDTH_ - _OUTPUTPRECISION_ - 5), \
113 output, \
114 _OUTPUTPRECISION_ + 5, \
115 " "); \
116 }
117
118#define class_fprintf_columntitle(file, title, condition, colnum) \
119 { \
120 if (condition) \
121 fprintf(file, \
122 "%*s%2d:%-*s ", \
123 std::max(0, \
124 std::min(_COLUMNWIDTH_ - _OUTPUTPRECISION_ - 6 - 3, \
125 _COLUMNWIDTH_ - ((int) strlen(title)) - 3)), \
126 "", \
127 (colnum)++, \
128 _OUTPUTPRECISION_ + 6, \
129 title); \
130 }
131
132#define class_store_columntitle(titlestring, title, condition) \
133 { \
134 if (condition) { \
135 (titlestring) += (title); \
136 (titlestring) += _DELIMITER_; \
137 } \
138 }
139
140#define class_store_double(storage, value, condition, dataindex) \
141 { \
142 if (condition) \
143 (storage)[(dataindex)++] = value; \
144 }
145
146#define class_store_double_or_default(storage, value, condition, dataindex, defaultvalue) \
147 { \
148 if (condition) \
149 (storage)[(dataindex)++] = value; \
150 else \
151 (storage)[(dataindex)++] = defaultvalue; \
152 }
153
154#ifdef __cplusplus
155/* Not in the extern "C" block: takes a std::string& (a C++ type), so it cannot
156 * have C language linkage; guarded by __cplusplus so C translation units never
157 * see this declaration. */
158int get_number_of_titles(const std::string& titlestring);
159/* The first title that occurs twice in a title string, or "" if every title is
160 * unique. A column's title is its key in classy's dicts and in readers of the
161 * .dat files, so a repeated title silently hides one of the two columns. */
162std::string first_duplicate_title(const std::string& titlestring);
163#endif
164
165#endif
Definition parser.h:23