-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.h
executable file
·191 lines (181 loc) · 6.59 KB
/
configuration.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
* Copyright 2019 United Kingdom Research and Innovation
*
* Authors: See AUTHORS
*
* Contact: [[email protected] and/or [email protected]]
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice
* this list of conditions and the following disclaimer in the documentation
* and or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*! @brief Head files for configuration
* @author Jianping Meng
* @details Declaring data structure for holding configuration parameters.
* The configuration currently follows the HiLeMMS definition.
* Usage: use Config() to get the constant pointer of the data structure.
*/
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
#include <fstream>
#include <iostream>
#include <streambuf>
#include <string>
#include <vector>
#include <map>
#include <type_traits>
#include "json.hpp"
#include "type.h"
#include "ops_lib_core.h"
#ifdef OPS_MPI
#include "ops_mpi_core.h"
#endif
#include "model.h"
#include "model_host_device.h"
#include "flowfield_host_device.h"
#include "boundary.h"
/**
* Structure for holding various input parameters.
*/
struct Configuration {
std::string caseName;
SizeType spaceDim{3};
std::vector<std::string> compoNames;
std::vector<int> compoIds;
std::vector<std::string> lattNames;
std::vector<VariableTypes> macroVarTypes;
std::vector<std::string> macroVarNames;
std::vector<int> macroVarIds;
std::vector<int> macroCompoIds;
std::vector<CollisionType> CollisionTypes;
std::vector<int> CollisionCompoIds;
std::vector<BodyForceType> bodyForceTypes;
std::vector<SizeType> bodyForceCompoIds;
std::vector<InitialType> initialTypes;
std::vector<int> initialConditionCompoId;
SchemeType schemeType{Scheme_StreamCollision};
std::vector<std::string> blockNames;
std::vector<int> blockIds;
std::vector<int> blockSize;
std::vector<int> fromBlockIds;
std::vector<int> toBlockIds;
std::vector<BoundarySurface> fromBoundarySurface;
std::vector<BoundarySurface> toBoundarySurface;
std::vector<VertexType> blockConnectionType;
std::map<int, std::vector<Real>> startPos;
Real meshSize;
std::vector<Real> tauRef;
bool transient{true};
Real convergenceCriteria{-1};
SizeType timeStepsToRun{0};
SizeType currentTimeStep{0};
SizeType checkPeriod{1000};
std::vector<BlockBoundary> blockBoundaryConfig;
};
/**
* @brief Reading the parameters from a input file in the json format
*
* @details In the MPI mode, the whole input file will be broadcasted to all
* nodes by the root rank 0
*
* @param configFileName configuration file name
*/
void ReadConfiguration(std::string& configFileName);
/** Get the pointer to the data structure holding various parameters
*/
const Configuration& Config();
const nlohmann::json& JsonConfig();
template <typename T>
void Query(T& value, const std::string& key) {
const nlohmann::json& jsonConfig{JsonConfig()};
if (jsonConfig.contains(key)) {
if (jsonConfig[key].is_null()) {
ops_printf(
"Error! Please insert the %s item into the configuration!\n",
key.c_str());
assert(jsonConfig[key].is_null());
};
value = jsonConfig[key].get<T>();
} else {
ops_printf("Error! Please supply %s in the configuration!\n",
key.c_str());
assert(jsonConfig.contains(key));
}
}
/**
* @brief Get non-mandatory options from JSON configuration file
*
* @tparam T Option type
* @param value Option value
* @param key Option name
*/
template <typename T>
void Check(T& value, const std::string& key) {
const nlohmann::json& jsonConfig{JsonConfig()};
bool haveKey{true};
if (!jsonConfig.contains(key)) {
ops_printf("Warning! %s is not defined in the configuration!\n",
key.c_str());
haveKey = false;
} else {
if (jsonConfig[key].is_null()) {
ops_printf("Warning! %s is empty in the configuration!\n",
key.c_str());
haveKey = false;
};
}
if (haveKey) {
value = jsonConfig[key].get<T>();
};
}
template <typename T>
void Query(T& value, const std::string& key0, const std::string& key1) {
const nlohmann::json& jsonConfig{JsonConfig()};
if (!jsonConfig.contains(key0)) {
ops_printf("Error! Please supply %s in the configuration!\n",
key0.c_str());
assert(jsonConfig.contains(key0));
}
if (!jsonConfig[key0].contains(key1)) {
ops_printf("Error! Please supply %s : %s in the configuration!\n",
key0.c_str(), key1.c_str());
assert(jsonConfig[key0].contains(key1));
}
if (jsonConfig[key0][key1].is_null()) {
ops_printf(
"Error! Please insert the %s->%s item into the configuration!\n",
key0.c_str(), key1.c_str());
assert(jsonConfig[key0][key1].is_null());
};
value = jsonConfig[key0][key1].get<T>();
}
/**
* @brief Get the Config File From Cmd object.
* @param findConfig if a configuration file is specified.
* @param fileName the configuration file name.
* @param argc the command line argument number.
* @param argv the command line arguments.
*/
void GetConfigFileFromCmd(bool& findConfig, std::string& fileName,
const int argc, const char** argv);
#endif // CONFIGURATION_H