12#include <argparse.hpp>
28 constexpr static inline const char *getSingleBlockAppName(
const EulerModel model)
32 else if (model ==
NS_SA)
34 else if (model ==
NS_2D)
36 else if (model ==
NS_3D)
44 else if (model ==
NS_EX)
48 return "_error_app_name_";
78 template <EulerModel model>
81 using namespace std::literals;
85 std::string defaultConfJson =
"../cases/"s + getSingleBlockAppName(model) +
"_default_config.json"s;
86 std::string confJson =
"../cases/"s + getSingleBlockAppName(model) +
"_config.json";
87 std::vector<std::string> overwriteKeys, overwriteValues;
90 std::string read_configPath;
92 mainParser.add_argument(
"field_n_variables").default_value<
int>(5).scan<
'i',
int>();
93 mainParser.add_argument(
"config").default_value(
"");
94 mainParser.add_argument(
"-k",
"--overwrite_key")
95 .help(
"keys to the json entries to overwrite")
97 .default_value<std::vector<std::string>>({});
98 mainParser.add_argument(
"-v",
"--overwrite_value")
99 .help(
"values to the json entries to overwrite")
101 .default_value<std::vector<std::string>>({});
102 mainParser.add_argument(
"--debug").flag().default_value(
false);
103 mainParser.add_argument(
"--emit-schema")
104 .help(
"Print JSON Schema for this solver's configuration and exit")
106 .default_value(
false);
113 mainParser.parse_args(argc, argv);
114 if (mainParser.get<
bool>(
"--debug"))
119 read_configPath = mainParser.get(
"config");
120 if (!read_configPath.empty())
122 confJson = read_configPath;
123 std::filesystem::path p(read_configPath);
126 defaultConfJson =
getStringForcePath(p.parent_path()) +
"/"s + getSingleBlockAppName(model) +
"_default_config.json"s;
128 overwriteKeys = mainParser.get<std::vector<std::string>>(
"--overwrite_key");
129 overwriteValues = mainParser.get<std::vector<std::string>>(
"--overwrite_value");
130 if (overwriteKeys.size() != overwriteValues.size())
131 throw std::runtime_error(
"overwrite keys and values not matching");
133 catch (
const std::exception &
err)
135 std::cerr <<
err.what() << std::endl;
136 std::cerr << mainParser;
141 if (mainParser.get<
bool>(
"--emit-schema"))
143 int nVars = getnVarsFixed(model);
145 nVars = mainParser.get<
int>(
"field_n_variables");
153 std::string schemaDefaultFile =
"/tmp/dnds_schema_defaults_" + std::to_string(mpi.rank) +
".json";
154 solver.ConfigureFromJson(schemaDefaultFile,
false);
161 nlohmann::ordered_json schema = TConfig::schema(
162 std::string(
"DNDSR ") + getSingleBlockAppName(model) +
" configuration");
163 schema[
"$schema"] =
"http://json-schema.org/draft-07/schema#";
164 schema[
"title"] = schema[
"description"];
165 std::cout << schema.dump(4) << std::endl;
166 std::filesystem::remove(schemaDefaultFile);
170 std::filesystem::remove(schemaDefaultFile);
176 int nVars = getnVarsFixed(model);
178 nVars = mainParser.get<
int>(
"field_n_variables");
185 log() <<
"Reading configuration from " << confJson << std::endl;
186 log() <<
"Using default configuration from " << defaultConfJson << std::endl;
189 solver.
ConfigureFromJson(defaultConfJson,
true, confJson, overwriteKeys, overwriteValues);
193 catch (
const std::exception &e)
195 std::cerr <<
"DNDS top-level exception: " << e.what() << std::endl;
200 std::cerr <<
"Unknown exception" << std::endl;
Top-level solver orchestrator for compressible Navier-Stokes / Euler simulations.
#define DNDS_VERSION_STRING
Fallback when the build system did not inject the version string.
Top-level solver orchestrator for compressible Navier-Stokes / Euler equations.
void RunImplicitEuler()
Run the main implicit time-marching loop.
void ReadMeshAndInitialize()
Read the mesh and initialize the full solver pipeline.
void ConfigureFromJson(const std::string &jsonName, bool read=false, const std::string &jsonMergeName="", const std::vector< std::string > &overwriteKeys={}, const std::vector< std::string > &overwriteValues={})
Load or write solver configuration from/to a JSON file.
static CommStrategy & Instance()
Access the process-wide singleton.
ArrayCommType GetArrayStrategy()
Current array-pack strategy.
void MPIDebugHold(const MPIInfo &mpi)
If isDebugging is set, block every rank in a busy-wait loop so the user can attach a debugger and ins...
bool isDebugging
Flag consulted by MPIDebugHold and assert_false_info_mpi.
int RunSingleBlockConsoleApp(int argc, char *argv[])
Main entry point for single-block solver console applications.
EulerModel
Enumerates the available compressible flow solver model configurations.
@ NS_2EQ_3D
NS + 2-equation RANS, 3D geometry (7 vars).
@ NS_SA_3D
NS + Spalart-Allmaras, 3D geometry (6 vars).
@ NS
Navier-Stokes, 2D geometry, 3D physics (5 vars).
@ NS_EX_3D
Extended NS, 3D geometry, dynamic nVars (Eigen::Dynamic).
@ NS_SA
NS + Spalart-Allmaras, 2D geometry (6 vars).
@ NS_2EQ
NS + 2-equation RANS, 2D geometry (7 vars).
@ NS_3D
Navier-Stokes, 3D geometry, 3D physics (5 vars).
@ NS_EX
Extended NS, 2D geometry, dynamic nVars (Eigen::Dynamic).
@ NS_2D
NS with 2D physics (2 velocity components, 4 vars). The only model with dim=2.
MPI_int Barrier(MPI_Comm comm)
Wrapper over MPI_Barrier.
int GetMPIThreadLevel()
Return the MPI thread-support level the current process was initialised with.
void RegisterSignalHandler()
Install SEGV / ABRT handlers that print a backtrace via DNDS_signal_handler.
DNDS_CONSTANT const rowsize DynamicSize
Template parameter flag: "row width is set at runtime but uniform".
std::string getStringForcePath(const std::filesystem::path::string_type &v)
Portable conversion of a platform-native path string to std::string.
std::ostream & log()
Return the current DNDSR log stream (either std::cout or the installed file).
std::string GetSetVersionName(const std::string &ver)
Read/set the build version string accessible from code.
Complete solver configuration, serializable to/from JSON.
Lightweight bundle of an MPI communicator and the calling rank's coordinates.