OGS
OGSSimulation Class Reference

Detailed Description

Definition at line 80 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 83 of file ogs_python_module.cpp.

84 {
85 int argc = argv_str.size();
86 char** argv = new char*[argc];
87 for (int i = 0; i < argc; ++i)
88 {
89 argv[i] = argv_str[i].data();
90 }
91
92 CommandLineArguments cli_args;
93 try
94 {
95 cli_args = parseCommandLineArguments(argc, argv, false);
96 }
97 catch (TCLAP::ArgException const& e)
98 {
99 std::cerr << "Parsing the OGS commandline failed: " << e.what()
100 << '\n';
101
102 // "mangle" TCLAP's status
103 throw(e);
104 }
105 catch (TCLAP::ExitException const& e)
106 {
107 throw(e);
108 }
109
111
112 DBUG("OGSSimulation::OGSSimulation(std::vector<std::string>&)");
113
114 INFO(
115 "This is OpenGeoSys-6 version {:s}. Log version: {:d}, Log level: "
116 "{:s}.",
118
120
121 {
122 auto const start_time = std::chrono::system_clock::now();
123 auto const time_str = BaseLib::formatDate(start_time);
124 // todo ask Tobias: started vs starts
125 INFO("OGS starts on {:s} in serial mode / Python embedded mode.",
126 time_str);
127 }
128 try
129 {
130 simulation = std::make_unique<Simulation>(argc, argv);
131 simulation->initializeDataStructures(
132 std::move(cli_args.project),
133 std::move(cli_args.xml_patch_file_names),
134 cli_args.reference_path_is_set,
135 std::move(cli_args.reference_path), cli_args.nonfatal,
136 std::move(cli_args.outdir), std::move(cli_args.mesh_dir),
137 std::move(cli_args.script_dir), cli_args.write_prj);
138 }
139 catch (std::exception& e)
140 {
141 ERR("{}", e.what());
142 ogs_status = EXIT_FAILURE;
144 throw(e);
145 }
146 INFO("OpenGeoSys is now initialized.");
147 }
CommandLineArguments parseCommandLineArguments(int argc, char *argv[], bool const exit_on_exception)
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
std::unique_ptr< Simulation > simulation
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
std::string formatDate(std::chrono::time_point< std::chrono::system_clock > const &time)
void unsetProjectDirectory()
Unsets the project directory.
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, BaseLib::unsetProjectDirectory(), CommandLineArguments::write_prj, and CommandLineArguments::xml_patch_file_names.

Member Function Documentation

◆ currentTime()

double OGSSimulation::currentTime ( ) const
inline

Definition at line 214 of file ogs_python_module.cpp.

214{ return simulation->currentTime(); }

References simulation.

Referenced by PYBIND11_MODULE().

◆ endTime()

double OGSSimulation::endTime ( ) const
inline

Definition at line 216 of file ogs_python_module.cpp.

216{ return simulation->endTime(); }

References simulation.

Referenced by PYBIND11_MODULE().

◆ executeSimulation()

int OGSSimulation::executeSimulation ( )
inline

Definition at line 149 of file ogs_python_module.cpp.

150 {
151 BaseLib::RunTime run_time;
152
153 {
154 auto const start_time = std::chrono::system_clock::now();
155 auto const time_str = BaseLib::formatDate(start_time);
156 INFO("OGS started on {:s} in serial mode.", time_str);
157 }
158
159 std::optional<ApplicationsLib::TestDefinition> test_definition{
160 std::nullopt};
161
162 try
163 {
164 run_time.start();
165 bool solver_succeeded = simulation->executeSimulation();
166 simulation->outputLastTimeStep();
167 test_definition = simulation->getTestDefinition();
168
169 if (solver_succeeded)
170 {
171 INFO("[time] Simulation completed. It took {:g} s.",
172 run_time.elapsed());
173 }
174 else
175 {
176 INFO("[time] Simulation failed. It took {:g} s.",
177 run_time.elapsed());
178 }
179 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
180 }
181 catch (std::exception& e)
182 {
183 ERR("{}", e.what());
184 ogs_status = EXIT_FAILURE;
185 }
186
187 if (ogs_status == EXIT_FAILURE)
188 {
189 auto const end_time = std::chrono::system_clock::now();
190 auto const time_str = BaseLib::formatDate(end_time);
191 ERR("OGS terminated with error on {:s}.", time_str);
192 return EXIT_FAILURE;
193 }
194
195 return Simulation::runTestDefinitions(test_definition);
196 }
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:42
void start()
Start the timer.
Definition RunTime.h:32
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 198 of file ogs_python_module.cpp.

199 {
200 auto ogs_status = EXIT_SUCCESS;
201 try
202 {
203 bool solver_succeeded = simulation->executeTimeStep();
204 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
205 }
206 catch (std::exception& e)
207 {
208 ERR("{}", e.what());
209 ogs_status = EXIT_FAILURE;
210 }
211 return ogs_status;
212 }

References ERR(), ogs_status, and simulation.

Referenced by PYBIND11_MODULE().

◆ finalize()

void OGSSimulation::finalize ( )
inline

Definition at line 244 of file ogs_python_module.cpp.

245 {
246 simulation->outputLastTimeStep();
247 simulation.reset(nullptr);
248
249 // Unset project dir to make multiple OGS runs in one Python session
250 // possible.
252 }

References simulation, and BaseLib::unsetProjectDirectory().

Referenced by PYBIND11_MODULE().

◆ getMesh()

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

Definition at line 218 of file ogs_python_module.cpp.

219 {
220 auto const mesh_it = mesh_mapping.find(name);
221 if (mesh_it != mesh_mapping.end())
222 {
223 INFO("found OGSMesh '{}' with address: {}", name,
224 fmt::ptr(&(mesh_it->second)));
225 return mesh_it->second;
226 }
227
228 auto const& [it, success] =
229 mesh_mapping.insert({name, OGSMesh(simulation->getMesh(name))});
230 if (!success)
231 {
232 OGS_FATAL("Could not access mesh '{}'.", name);
233 }
234 INFO("insert OGSMesh '{}' with address: {}", name,
235 fmt::ptr(&(it->second)));
236 return it->second;
237 }
#define OGS_FATAL(...)
Definition Error.h:26
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 239 of file ogs_python_module.cpp.

240 {
241 return simulation->getMeshNames();
242 }

References simulation.

Referenced by PYBIND11_MODULE().

Member Data Documentation

◆ mesh_mapping

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

Definition at line 258 of file ogs_python_module.cpp.

Referenced by getMesh().

◆ ogs_status

int OGSSimulation::ogs_status = EXIT_SUCCESS
private

Definition at line 255 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: