MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
context.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef CONTEXT_H
8#define CONTEXT_H
14
15#include <list>
17#include "UTIL/functions.h"
18#include "contexttypes.h"
19#include "enums.h"
20
21class IONetcdf;
22class IOToml;
23
25template <VariableType p>
27template <>
29 using type = MString;
30};
31template <>
33 using type = MInt;
34};
35template <>
37 using type = MFloat;
38};
39template <>
41 using type = MBool;
42};
43template <class T>
45template <>
47 static const VariableType type = MSTRING;
48 static const MString name() { return "MString"; }
49};
50template <>
52 static const VariableType type = MINT;
53 static const MString name() { return "MInt"; }
54};
55template <>
57 static const VariableType type = MFLOAT;
58 static const MString name() { return "MFloat"; }
59};
60template <>
62 static const VariableType type = MBOOL;
63 static const MString name() { return "MBool"; }
64};
65
80class Context {
81 public:
82 static void readPropertyFile(FileType, const MString& fileName);
83
84 // returns the length of the property 'name' of solver 'solverId'. If solverId is skipped, the length
85 // of the basic property 'name' is returned
86 static MInt propertyLength(const MString& name, MInt solverId = m_noSolvers);
87
89 static void assertPropertyLength(const MString& name, const MInt length, const MInt solverId = m_noSolvers);
90
91 // returns the solverId of the property 'name' of solver 'solverId'. If solverId is skipped, the solverId
92 // of the basic property 'name' is returned (only used in checkPropertyViolation)
93 static MInt propertySolverId(const MString& name, MInt solverId = m_noSolvers);
94
95 // returns true if the property 'name' of solver 'solverId' or the basic property 'name' exists.
96 static MBool propertyExists(const MString& name, MInt solver = m_noSolvers);
97
98 // returns true only if the property 'name' of solver 'solverId' exists
99 static MBool solverPropertyExists(const MString& name, MInt solver);
100
101 static void clear();
102
103 static void init();
104
105 static void addProperty(MProperty*);
106
107 static void writeProperties(char* fileName);
108
109 static void writePropertiesHumanReadable();
110
111 static void initializationProcessFinished();
112
113 static void communicateProperties();
114
115 static std::list<MProperty*>* receiveProperties(MInt rank);
116
117 static void sendProperties(MInt rank);
118
119 static void checkPropertyViolation(MInt partnerrank, std::list<MProperty*>* prop);
120
122 static MString propertyFileName() { return m_name; }
123
126
127 static void dump(const MString& fileName);
128
129 private:
138 static std::pair<propertyMap::iterator, propertyMap::iterator> m_pair;
143
144 //-------------Get Properties New approach--------------//
145 public:
146 // Returns the value of a basic property. If the basic property does not
147 // exist, the default value will be returned.
148 template <typename T>
149 static T getBasicProperty(const MString name, const MString& nameOfCallingFunction, const T* default_value,
150 MInt pos = 0) {
151 const MBool hasDefault = (default_value != nullptr);
152 return getBasicPropertyOverloaded(nameOfCallingFunction, name, hasDefault, default_value, pos);
153 }
154
155 // Returns the value of a basic property. Since no default value exists in this case,
156 // the requested basic property is required. If it does not exist an error message will
157 // be returned.
158 template <typename T>
159 static T getBasicProperty(const MString name, const MString& nameOfCallingFunction, MInt pos = 0) {
160 T* defaultValue = nullptr;
161 return getBasicPropertyOverloaded(nameOfCallingFunction, name, false, defaultValue, pos);
162 }
163
164 // Returns the value of a solver property. If the solver property of the solver with
165 // id solverId does not exist, the basic property will be returned.
166 // If the top level property also does not exist, the default value will be returned.
167 template <typename T>
168 static T getSolverProperty(const MString name, const MInt solverId, const MString& nameOfCallingFunction,
169 const T* default_value, MInt pos = 0) {
170 return getSolverPropertyOverloaded(nameOfCallingFunction, name, solverId, true, default_value, pos);
171 }
172
173 // Returns the value of a solver property. If the solver property of the solver with
174 // id solverId does not exist, the basic property will be returned.
175 // Since no default value exists in this case, the requested solver property is
176 // required. If it does not exist an error message will be returned.
177 template <typename T>
178 static T getSolverProperty(const MString name, const MInt solverId, const MString& nameOfCallingFunction,
179 MInt pos = 0) {
180 T* defaultValue = nullptr;
181 return getSolverPropertyOverloaded(nameOfCallingFunction, name, solverId, false, defaultValue, pos);
182 }
183
184 private:
185 // overloaded and implicit versions of getBasicProperty() and getSolverProperty()
186 template <typename T, typename F>
187 static T getBasicPropertyImplicit(const MString& nameOfCallingFunction, const MString& name, MBool has_default,
188 const T* defaultValue, MInt position, F&& f);
189
190 static MInt getBasicPropertyOverloaded(const MString& nameOfCallingFunction, const MString& name, MBool has_default,
191 const MInt* default_value, MInt pos);
192
193 static MFloat getBasicPropertyOverloaded(const MString& nameOfCallingFunction, const MString& name, MBool has_default,
194 const MFloat* default_value, MInt pos);
195
196 static MString getBasicPropertyOverloaded(const MString& nameOfCallingFunction, const MString& name,
197 MBool has_default, const MString* default_value, MInt pos);
198
199 static MBool getBasicPropertyOverloaded(const MString& nameOfCallingFunction, const MString& name, MBool has_default,
200 const MBool* default_value, MInt pos);
201
202 template <typename T, typename F>
203 static T getSolverPropertyImplicit(const MString& nameOfCallingFunction, const MString& name, const MInt solverId,
204 MBool has_default, const T* defaultValue, MInt position, F&& f);
205
206 static MInt getSolverPropertyOverloaded(const MString& nameOfCallingFunction, const MString& name,
207 const MInt solverId, MBool has_default, const MInt* default_value, MInt pos);
208
209 static MFloat getSolverPropertyOverloaded(const MString& nameOfCallingFunction, const MString& name,
210 const MInt solverId, MBool has_default, const MFloat* default_value,
211 MInt pos);
212
213 static MString getSolverPropertyOverloaded(const MString& nameOfCallingFunction, const MString& name,
214 const MInt solverId, MBool has_default, const MString* default_value,
215 MInt pos);
216
217 static MBool getSolverPropertyOverloaded(const MString& nameOfCallingFunction, const MString& name,
218 const MInt solverId, MBool has_default, const MBool* default_value,
219 MInt pos);
220
221 static MBool isSameValue(const MFloat v1, const MFloat v2) { return approx(v1, v2, MFloatEps); }
222 static MBool isSameValue(const MBool v1, const MBool v2) { return (v1 == v2); }
223 static MBool isSameValue(const MInt v1, const MInt v2) { return (v1 == v2); }
224 static MBool isSameValue(const MString v1, const MString v2) { return (v1 == v2); }
225};
226
228inline MInt read_nDim() {
240 MInt nDim = -1;
241 nDim = Context::getBasicProperty<MInt>("nDim", AT_, &nDim);
242
243 if(nDim == -1) {
256 nDim = Context::getBasicProperty<MInt>("spaceDimensions", AT_);
257 }
258 if(nDim == -1) {
259 mTerm(1, AT_, "nDim / spaceDimensions property not found");
260 }
261 return nDim;
262}
263
264#endif
static void communicateProperties()
Communicates properties to check if default falues match.
Definition: context.cpp:773
static MBool m_checkingProperties
Definition: context.h:142
static propertyMap * m_propertyMapLowercase
Definition: context.h:135
static void initializationProcessFinished()
Sets flag to forbide property access.
Definition: context.cpp:745
static MString m_propertyFileText
Definition: context.h:140
static T getBasicProperty(const MString name, const MString &nameOfCallingFunction, const T *default_value, MInt pos=0)
Definition: context.h:149
static void dump(const MString &fileName)
Dump all properties to text file.
Definition: context.cpp:1362
static void init()
This intializes the property Map.
Definition: context.cpp:482
static T getBasicProperty(const MString name, const MString &nameOfCallingFunction, MInt pos=0)
Definition: context.h:159
static MString propertyFileName()
Return name of most recently read property file.
Definition: context.h:122
static void writeProperties(char *fileName)
static void sendProperties(MInt rank)
Sends the property list to another cpu.
Definition: context.cpp:1052
static void checkPropertyViolation(MInt partnerrank, std::list< MProperty * > *prop)
Checks if local properties differ from received properties.
Definition: context.cpp:1256
static MInt propertySolverId(const MString &name, MInt solverId=m_noSolvers)
Returns the number of elements of a property.
Definition: context.cpp:576
static MInt propertyLength(const MString &name, MInt solverId=m_noSolvers)
Returns the number of elements of a property.
Definition: context.cpp:538
static MBool isSameValue(const MInt v1, const MInt v2)
Definition: context.h:223
static IOToml * m_IOToml
Definition: context.h:131
static std::pair< propertyMap::iterator, propertyMap::iterator > m_pair
Definition: context.h:138
static MInt getSolverPropertyOverloaded(const MString &nameOfCallingFunction, const MString &name, const MInt solverId, MBool has_default, const MInt *default_value, MInt pos)
Definition: context.cpp:343
static IONetcdf * m_IONetcdf
Definition: context.h:130
static T getSolverProperty(const MString name, const MInt solverId, const MString &nameOfCallingFunction, const T *default_value, MInt pos=0)
Definition: context.h:168
static MInt getBasicPropertyOverloaded(const MString &nameOfCallingFunction, const MString &name, MBool has_default, const MInt *default_value, MInt pos)
Definition: context.cpp:197
static void addProperty(MProperty *)
This method adds properties.
Definition: context.cpp:453
static void writePropertiesHumanReadable()
Write the properties into a text file.
Definition: context.cpp:600
static assembly * m_assembly
Definition: context.h:137
static void clear()
Definition: context.cpp:418
static MString propertyFileText()
Return unprocessed content of most recently read property file.
Definition: context.h:125
static T getBasicPropertyImplicit(const MString &nameOfCallingFunction, const MString &name, MBool has_default, const T *defaultValue, MInt position, F &&f)
Returns the value of the requested basic level property (implicit).
Definition: context.cpp:126
static void readPropertyFile(FileType, const MString &fileName)
static void assertPropertyLength(const MString &name, const MInt length, const MInt solverId=m_noSolvers)
Assert that the length of a property matches the given length.
Definition: context.cpp:559
static MBool solverPropertyExists(const MString &name, MInt solver)
Checks existence of a solver property details This function returns true, if the solver property with...
Definition: context.cpp:519
static T getSolverPropertyImplicit(const MString &nameOfCallingFunction, const MString &name, const MInt solverId, MBool has_default, const T *defaultValue, MInt position, F &&f)
Returns the value of the requested solver property (implicit).
Definition: context.cpp:265
static MBool isSameValue(const MBool v1, const MBool v2)
Definition: context.h:222
static MInt m_noSolvers
Definition: context.h:133
static zoneMap * m_zoneMap
Definition: context.h:136
static MBool propertyExists(const MString &name, MInt solver=m_noSolvers)
This function checks if a property exists in general.
Definition: context.cpp:494
static propertyMap * m_propertyMap
Definition: context.h:134
static T getSolverProperty(const MString name, const MInt solverId, const MString &nameOfCallingFunction, MInt pos=0)
Definition: context.h:178
static MInt m_fileType
Definition: context.h:141
static std::list< MProperty * > * receiveProperties(MInt rank)
Receives a property list from another cpu.
Definition: context.cpp:866
static MString m_propertyFileOutputName
Definition: context.h:139
static MString m_name
Definition: context.h:132
static MBool isSameValue(const MString v1, const MString v2)
Definition: context.h:224
static MBool isSameValue(const MFloat v1, const MFloat v2)
Definition: context.h:221
Definition: iotoml.h:25
std::map< MString, MZone * > zoneMap
Definition: contexttypes.h:17
std::multimap< MString, MProperty * > propertyMap
Definition: contexttypes.h:15
FileType
Definition: enums.h:18
VariableType
Definition: enums.h:269
@ MINT
Definition: enums.h:269
@ MFLOAT
Definition: enums.h:269
@ MBOOL
Definition: enums.h:269
@ MSTRING
Definition: enums.h:269
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29
MBool approx(const T &, const U &, const T)
Definition: functions.h:272
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58
Type traits for enum type.
Definition: context.h:26
static const MString name()
Definition: context.h:63
static const MString name()
Definition: context.h:58
static const MString name()
Definition: context.h:53
static const MString name()
Definition: context.h:48
Definition: contexttypes.h:19