OGS
OGSSimulation Class Reference

Detailed Description

Definition at line 68 of file ogs_python_module.cpp.

Public Member Functions

 OGSSimulation (std::vector< std::string > &argv_str)
int executeSimulation ()
int executeTimeStep ()
double currentTime () const
double endTime () const
OGSMeshgetMesh (std::string const &name)
std::vector< std::string > getMeshNames () const
void finalize ()

Private Attributes

int ogs_status = EXIT_SUCCESS
std::unique_ptr< Simulationsimulation
std::map< std::string, OGSMeshmesh_mapping

Constructor & Destructor Documentation

◆ OGSSimulation()

OGSSimulation::OGSSimulation ( std::vector< std::string > & argv_str)
inlineexplicit

Definition at line 71 of file ogs_python_module.cpp.

72 {
73 int argc = argv_str.size();
74 char** argv = new char*[argc];
75 for (int i = 0; i < argc; ++i)
76 {
77 argv[i] = argv_str[i].data();
78 }
79
80 CommandLineArguments cli_args;
81 try
82 {
83 cli_args = parseCommandLineArguments(argc, argv, false);
84 }
85 catch (TCLAP::ArgException const& e)
86 {
87 std::cerr << "Parsing the OGS commandline failed: " << e.what()
88 << '\n';
89
90 // "mangle" TCLAP's status
91 throw(e);
92 }
93 catch (TCLAP::ExitException const& e)
94 {
95 throw(e);
96 }
97
99
100 DBUG("OGSSimulation::OGSSimulation(std::vector<std::string>&)");
101
102 INFO(
103 "This is OpenGeoSys-6 version {:s}. Log version: {:d}, Log level: "
104 "{:s}.",
106
108
109 {
110 auto const start_time = std::chrono::system_clock::now();
111 auto const time_str = BaseLib::formatDate(start_time);
112 // todo ask Tobias: started vs starts
113 INFO("OGS starts on {:s} in serial mode / Python embedded mode.",
114 time_str);
115 }
116 try
117 {
118 simulation = std::make_unique<Simulation>(argc, argv);
119 simulation->initializeDataStructures(
120 std::move(cli_args.project),
121 std::move(cli_args.xml_patch_file_names),
122 cli_args.reference_path_is_set,
123 std::move(cli_args.reference_path), cli_args.nonfatal,
124 std::move(cli_args.outdir), std::move(cli_args.mesh_dir),
125 std::move(cli_args.script_dir), cli_args.write_prj);
126 }
127 catch (std::exception& e)
128 {
129 ERR("{}", e.what());
130 ogs_status = EXIT_FAILURE;
131 throw(e);
132 }
133 INFO("OpenGeoSys is now initialized.");
134 }
CommandLineArguments parseCommandLineArguments(int argc, char *argv[], bool const exit_on_exception)
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::unique_ptr< Simulation > simulation
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:56
std::string formatDate(std::chrono::time_point< std::chrono::system_clock > const &time)
bool createOutputDirectory(std::string const &dir)
GITINFOLIB_EXPORT const std::string ogs_version
std::vector< std::string > xml_patch_file_names

References BaseLib::createOutputDirectory(), DBUG(), ERR(), BaseLib::formatDate(), INFO(), BaseLib::initOGSLogger(), CommandLineArguments::log_level, CommandLineArguments::mesh_dir, CommandLineArguments::nonfatal, ogs_status, GitInfoLib::GitInfo::ogs_version, CommandLineArguments::outdir, parseCommandLineArguments(), CommandLineArguments::project, CommandLineArguments::reference_path, CommandLineArguments::reference_path_is_set, CommandLineArguments::script_dir, simulation, CommandLineArguments::write_prj, and CommandLineArguments::xml_patch_file_names.

Member Function Documentation

◆ currentTime()

double OGSSimulation::currentTime ( ) const
inline

Definition at line 201 of file ogs_python_module.cpp.

201{ return simulation->currentTime(); }

References simulation.

Referenced by PYBIND11_MODULE().

◆ endTime()

double OGSSimulation::endTime ( ) const
inline

Definition at line 203 of file ogs_python_module.cpp.

203{ return simulation->endTime(); }

References simulation.

Referenced by PYBIND11_MODULE().

◆ executeSimulation()

int OGSSimulation::executeSimulation ( )
inline

Definition at line 136 of file ogs_python_module.cpp.

137 {
138 BaseLib::RunTime run_time;
139
140 {
141 auto const start_time = std::chrono::system_clock::now();
142 auto const time_str = BaseLib::formatDate(start_time);
143 INFO("OGS started on {:s} in serial mode.", time_str);
144 }
145
146 std::optional<ApplicationsLib::TestDefinition> test_definition{
147 std::nullopt};
148
149 try
150 {
151 run_time.start();
152 bool solver_succeeded = simulation->executeSimulation();
153 simulation->outputLastTimeStep();
154 test_definition = simulation->getTestDefinition();
155
156 if (solver_succeeded)
157 {
158 INFO("[time] Simulation completed. It took {:g} s.",
159 run_time.elapsed());
160 }
161 else
162 {
163 INFO("[time] Simulation failed. It took {:g} s.",
164 run_time.elapsed());
165 }
166 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
167 }
168 catch (std::exception& e)
169 {
170 ERR("{}", e.what());
171 ogs_status = EXIT_FAILURE;
172 }
173
174 if (ogs_status == EXIT_FAILURE)
175 {
176 auto const end_time = std::chrono::system_clock::now();
177 auto const time_str = BaseLib::formatDate(end_time);
178 ERR("OGS terminated with error on {:s}.", time_str);
179 return EXIT_FAILURE;
180 }
181
182 return Simulation::runTestDefinitions(test_definition);
183 }
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:31
void start()
Start the timer.
Definition RunTime.h:21
static OGS_EXPORT_SYMBOL int runTestDefinitions(std::optional< ApplicationsLib::TestDefinition > &test_definition)

References BaseLib::RunTime::elapsed(), ERR(), BaseLib::formatDate(), INFO(), ogs_status, Simulation::runTestDefinitions(), simulation, and BaseLib::RunTime::start().

Referenced by PYBIND11_MODULE().

◆ executeTimeStep()

int OGSSimulation::executeTimeStep ( )
inline

Definition at line 185 of file ogs_python_module.cpp.

186 {
187 auto ogs_status = EXIT_SUCCESS;
188 try
189 {
190 bool solver_succeeded = simulation->executeTimeStep();
191 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
192 }
193 catch (std::exception& e)
194 {
195 ERR("{}", e.what());
196 ogs_status = EXIT_FAILURE;
197 }
198 return ogs_status;
199 }

References ERR(), ogs_status, and simulation.

Referenced by PYBIND11_MODULE().

◆ finalize()

void OGSSimulation::finalize ( )
inline

Definition at line 231 of file ogs_python_module.cpp.

232 {
233 simulation->outputLastTimeStep();
234 simulation.reset(nullptr);
235
236 // Check for swallowed ConfigTree errors after Simulation destructor
237 // runs. This catches configuration errors in objects destroyed at end
238 // of scope.
239 try
240 {
242 }
243 catch (std::exception& e)
244 {
245 ERR("{}", e.what());
246 throw;
247 }
248 }
static void assertNoSwallowedErrors()
Asserts that there have not been any errors reported in the destructor.

References BaseLib::ConfigTree::assertNoSwallowedErrors(), ERR(), and simulation.

Referenced by PYBIND11_MODULE().

◆ getMesh()

OGSMesh & OGSSimulation::getMesh ( std::string const & name)
inline

Definition at line 205 of file ogs_python_module.cpp.

206 {
207 auto const mesh_it = mesh_mapping.find(name);
208 if (mesh_it != mesh_mapping.end())
209 {
210 INFO("found OGSMesh '{}' with address: {}", name,
211 fmt::ptr(&(mesh_it->second)));
212 return mesh_it->second;
213 }
214
215 auto const& [it, success] =
216 mesh_mapping.insert({name, OGSMesh(simulation->getMesh(name))});
217 if (!success)
218 {
219 OGS_FATAL("Could not access mesh '{}'.", name);
220 }
221 INFO("insert OGSMesh '{}' with address: {}", name,
222 fmt::ptr(&(it->second)));
223 return it->second;
224 }
#define OGS_FATAL(...)
Definition Error.h:19
std::map< std::string, OGSMesh > mesh_mapping

References INFO(), mesh_mapping, OGS_FATAL, and simulation.

Referenced by PYBIND11_MODULE().

◆ getMeshNames()

std::vector< std::string > OGSSimulation::getMeshNames ( ) const
inline

Definition at line 226 of file ogs_python_module.cpp.

227 {
228 return simulation->getMeshNames();
229 }

References simulation.

Referenced by PYBIND11_MODULE().

Member Data Documentation

◆ mesh_mapping

std::map<std::string, OGSMesh> OGSSimulation::mesh_mapping
private

Definition at line 254 of file ogs_python_module.cpp.

Referenced by getMesh().

◆ ogs_status

int OGSSimulation::ogs_status = EXIT_SUCCESS
private

Definition at line 251 of file ogs_python_module.cpp.

Referenced by OGSSimulation(), executeSimulation(), and executeTimeStep().

◆ simulation

std::unique_ptr<Simulation> OGSSimulation::simulation
private

The documentation for this class was generated from the following file: