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

Member Function Documentation

◆ currentTime()

double OGSSimulation::currentTime ( ) const
inline

Definition at line 213 of file ogs_python_module.cpp.

213{ return simulation->currentTime(); }

Referenced by PYBIND11_MODULE().

◆ endTime()

double OGSSimulation::endTime ( ) const
inline

Definition at line 215 of file ogs_python_module.cpp.

215{ return simulation->endTime(); }

Referenced by PYBIND11_MODULE().

◆ executeSimulation()

int OGSSimulation::executeSimulation ( )
inline

Definition at line 148 of file ogs_python_module.cpp.

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

Referenced by PYBIND11_MODULE().

◆ executeTimeStep()

int OGSSimulation::executeTimeStep ( )
inline

Definition at line 197 of file ogs_python_module.cpp.

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

References ERR().

Referenced by PYBIND11_MODULE().

◆ finalize()

void OGSSimulation::finalize ( )
inline

Definition at line 243 of file ogs_python_module.cpp.

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

References BaseLib::unsetProjectDirectory().

Referenced by PYBIND11_MODULE().

◆ getMesh()

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

Definition at line 217 of file ogs_python_module.cpp.

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

References INFO(), and OGS_FATAL.

Referenced by PYBIND11_MODULE().

◆ getMeshNames()

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

Definition at line 238 of file ogs_python_module.cpp.

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

Referenced by PYBIND11_MODULE().

Member Data Documentation

◆ mesh_mapping

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

Definition at line 257 of file ogs_python_module.cpp.

◆ ogs_status

int OGSSimulation::ogs_status = EXIT_SUCCESS
private

Definition at line 254 of file ogs_python_module.cpp.

◆ simulation

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

Definition at line 256 of file ogs_python_module.cpp.


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