13 #include <spdlog/spdlog.h>
14 #include <tclap/CmdLine.h>
22 #include <xmmintrin.h>
30 #include <vtkMPIController.h>
31 #include <vtkSmartPointer.h>
43 #include "InfoLib/CMakeInfo.h"
53 int main(
int argc,
char* argv[])
57 "OpenGeoSys-6 software.\n"
58 "Copyright (c) 2012-2021, OpenGeoSys Community "
59 "(http://www.opengeosys.org) "
60 "Distributed under a Modified BSD License. "
61 "See accompanying file LICENSE.txt or "
62 "http://www.opengeosys.org/project/license\n"
65 "CMake arguments: " + CMakeInfoLib::CMakeInfo::cmake_args,
68 "CMake arguments: " + CMakeInfoLib::CMakeInfo::cmake_args);
70 TCLAP::ValueArg<std::string> reference_path_arg(
72 "Run output result comparison after successful simulation comparing to "
73 "all files in the given path. This requires test definitions to be "
74 "present in the project file.",
76 cmd.add(reference_path_arg);
78 TCLAP::UnlabeledValueArg<std::string> project_arg(
80 "Path to the ogs6 project file.",
86 TCLAP::MultiArg<std::string> xml_patch_files(
88 "the xml patch file(s) which is (are) applied (in the given order) to "
91 cmd.add(xml_patch_files);
93 TCLAP::ValueArg<std::string> outdir_arg(
"o",
"output-directory",
94 "the output directory to write to",
98 TCLAP::ValueArg<std::string> log_level_arg(
100 "the verbosity of logging messages: none, error, warn, info, debug, "
109 cmd.add(log_level_arg);
111 TCLAP::SwitchArg nonfatal_arg(
"",
112 "config-warnings-nonfatal",
113 "warnings from parsing the configuration "
114 "file will not trigger program abortion");
115 cmd.add(nonfatal_arg);
117 TCLAP::SwitchArg unbuffered_cout_arg(
"",
"unbuffered-std-out",
118 "use unbuffered standard output");
119 cmd.add(unbuffered_cout_arg);
123 TCLAP::SwitchArg enable_fpe_arg(
"",
"enable-fpe",
124 "enables floating point exceptions");
125 cmd.add(enable_fpe_arg);
128 cmd.parse(argc, argv);
131 if (unbuffered_cout_arg.isSet())
133 std::cout.setf(std::ios::unitbuf);
137 spdlog::set_pattern(
"%^%l:%$ %v");
138 spdlog::set_error_handler(
139 [](
const std::string& msg)
141 std::cerr <<
"spdlog error: " << msg << std::endl;
142 OGS_FATAL(
"spdlog logger error occurred.");
145 INFO(
"This is OpenGeoSys-6 version {:s}.",
150 if (enable_fpe_arg.isSet())
154 _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID);
157 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
162 #ifdef OGS_USE_PYTHON
170 auto const start_time = std::chrono::system_clock::now();
172 INFO(
"OGS started on {:s}.", time_str);
175 std::unique_ptr<ApplicationsLib::TestDefinition> test_definition;
176 auto ogs_status = EXIT_SUCCESS;
180 bool solver_succeeded =
false;
183 linear_solver_library_setup(argc, argv);
184 #if defined(USE_PETSC)
185 vtkSmartPointer<vtkMPIController> controller =
186 vtkSmartPointer<vtkMPIController>::New();
187 controller->Initialize(&argc, &argv, 1);
188 vtkMPIController::SetGlobalController(controller);
192 MPI_Comm_rank(PETSC_COMM_WORLD, &mpi_rank);
193 spdlog::set_pattern(
fmt::format(
"[{}] %^%l:%$ %v", mpi_rank));
200 project_arg.getValue(), !nonfatal_arg.getValue(),
201 "OpenGeoSysProject", xml_patch_files.getValue());
208 outdir_arg.getValue());
210 if (!reference_path_arg.isSet())
212 project_config->ignoreConfigParameter(
"test_definition");
217 std::make_unique<ApplicationsLib::TestDefinition>(
219 project_config->getConfigSubtree(
"test_definition"),
220 reference_path_arg.getValue(),
221 outdir_arg.getValue());
222 if (test_definition->numberOfTests() == 0)
225 "No tests were constructed from the test definitions, "
226 "but reference solutions path was given.");
229 INFO(
"Cleanup possible output files before running ogs.");
233 auto isInsituConfigured =
false;
235 if (
auto t = project_config->getConfigSubtreeOptional(
"insitu"))
239 t->getConfigSubtree(
"scripts"),
241 isInsituConfigured =
true;
244 project_config->ignoreConfigParameter(
"insitu");
247 INFO(
"Initialize processes.");
254 project_config.checkAndInvalidate();
261 INFO(
"Solve processes.");
265 solver_succeeded = time_loop.loop();
268 if (isInsituConfigured)
271 INFO(
"[time] Execution took {:g} s.", run_time.
elapsed());
273 #if defined(USE_PETSC)
274 controller->Finalize(1);
282 ogs_status = solver_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
284 catch (std::exception& e)
287 ogs_status = EXIT_FAILURE;
291 auto const end_time = std::chrono::system_clock::now();
293 INFO(
"OGS terminated on {:s}.", time_str);
296 if (ogs_status == EXIT_FAILURE)
298 ERR(
"OGS terminated with error.");
302 if (test_definition ==
nullptr)
309 INFO(
"##########################################");
310 INFO(
"# Running tests #");
311 INFO(
"##########################################");
313 if (!test_definition->runTests())
315 ERR(
"One of the tests failed.");
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
Definition of the RunTime class.
static void assertNoSwallowedErrors()
Asserts that there have not been any errors reported in the destructor.
double elapsed() const
Get the elapsed time in seconds.
void start()
Start the timer.
void initialize()
initialize output, convergence criterion, etc.
ProcessLib::TimeLoop & getTimeLoop()
std::vector< std::unique_ptr< ProcessLib::Process > > const & getProcesses() const
Provides read access to the process container.
pybind11::scoped_interpreter setupEmbeddedPython()
std::string const & getProjectDirectory()
Returns the directory where the prj file resides.
void setConsoleLogLevel(std::string const &level_string)
std::string extractPath(std::string const &pathname)
std::string formatDate(std::chrono::time_point< std::chrono::system_clock > const &time)
std::string format(const char *format_str,...)
void setProjectDirectory(std::string const &dir)
Sets the project directory.
ConfigTreeTopLevel makeConfigTree(const std::string &filepath, const bool be_ruthless, const std::string &toplevel_tag, const std::vector< std::string > &patch_files)
void removeFiles(std::vector< std::string > const &files)
GITINFOLIB_EXPORT const std::string ogs_version
void Initialize(BaseLib::ConfigTree const &scripts_config, std::string const &path)
int main(int argc, char *argv[])
Implementation of OpenGeoSys simulation application.