6#include <spdlog/spdlog.h>
26 controller(vtkSmartPointer<vtkMPIController>::New()),
32 vtkMPIController::SetGlobalController(
controller);
37 std::string
const& project,
38 std::vector<std::string>
const& xml_patch_file_names,
39 bool const reference_path_is_set, std::string
const& reference_path,
40 bool const nonfatal, std::string
const& outdir, std::string
const& mesh_dir,
41 std::string
const& script_dir,
bool const write_prj)
43 INFO(
"Reading project file {}.",
44 std::filesystem::relative(project).
string());
45 DBUG(
"Project file: {}.", std::filesystem::absolute(project).
string());
46 DBUG(
"Working directory: {}.", std::filesystem::current_path().
string());
48 std::stringstream prj_stream;
52 project, !nonfatal,
"OpenGeoSysProject", prj_stream);
54 if (!reference_path_is_set)
56 project_config.ignoreConfigParameter(
"test_definition");
62 project_config.getConfigSubtree(
"test_definition"), reference_path,
67 "No tests were constructed from the test definitions, "
68 "but reference solutions path was given.");
71 INFO(
"Cleanup possible output files before running ogs.");
76 if (
auto t = project_config.getConfigSubtreeOptional(
"insitu"))
80 t->getConfigSubtree(
"scripts"),
85 project_config.ignoreConfigParameter(
"insitu");
88 project_data = std::make_unique<ProjectData>(project_config, outdir,
89 mesh_dir, script_dir);
91 INFO(
"Initialize processes.");
98 checkAndInvalidate(project_config);
102 auto time_value = time_loop.currentTime()();
103 INFO(
"Time step #0 started. Time: {}. Step size: 0.", time_value);
107 time_loop.initialize();
108 INFO(
"Time step #0 took {:g} s.", init_timer.
elapsed());
114 return time_loop.currentTime()();
120 return time_loop.endTime()();
126 if (time_loop.currentTime() < time_loop.endTime())
128 auto const result = time_loop.executeTimeStep();
129 time_loop.calculateNextTimeStep();
154 INFO(
"Solve processes.");
156 while (time_loop.currentTime() < time_loop.endTime())
158 time_loop.executeTimeStep();
159 if (!time_loop.calculateNextTimeStep())
165 return time_loop.successful_time_step;
171 time_loop.outputLastTimeStep();
188#if defined(USE_PETSC)
202 auto const end_time = std::chrono::system_clock::now();
204 DBUG(
"No test definition was found. No tests will be executed.");
205 INFO(
"OGS completed on {:s}.", time_str);
209#if defined(USE_PETSC)
212 bool const run_all_tests = !has_xdmfdiff_tests;
213 bool const run_xdmfdiff_tests = has_xdmfdiff_tests && mpi.
rank == 0;
215 bool constexpr run_all_tests =
true;
216 bool constexpr run_xdmfdiff_tests =
false;
219 auto const log_tests_header = []
222 INFO(
"##########################################");
223 INFO(
"# Running tests #");
224 INFO(
"##########################################");
228 auto tests_succeeded =
true;
239#if defined(USE_PETSC)
240 if (has_xdmfdiff_tests)
244 auto xdmfdiff_status = EXIT_SUCCESS;
245 if (run_xdmfdiff_tests)
252 MPI_Bcast(&xdmfdiff_status, 1, MPI_INT, 0, mpi.
communicator);
254 tests_succeeded = tests_succeeded && xdmfdiff_status == EXIT_SUCCESS;
259 if (run_all_tests || run_xdmfdiff_tests)
261 auto const end_time = std::chrono::system_clock::now();
265 INFO(
"OGS completed on {:s}.", time_str);
269 ERR(
"OGS terminated on {:s}. One of the tests failed.", time_str);
272 return tests_succeeded ? EXIT_SUCCESS : EXIT_FAILURE;
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void signalHandler(int signum)
static std::atomic< int > gSignalThatStoppedMe
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.
OGS_EXPORT_SYMBOL double currentTime() const
std::shared_ptr< ApplicationsLib::LinearSolverLibrarySetup > linear_solver_library_setup
OGS_EXPORT_SYMBOL bool executeSimulation()
OGS_EXPORT_SYMBOL std::optional< ApplicationsLib::TestDefinition > getTestDefinition() const
std::unique_ptr< ProjectData > project_data
static OGS_EXPORT_SYMBOL int runTestDefinitions(std::optional< ApplicationsLib::TestDefinition > &test_definition)
std::optional< ApplicationsLib::TestDefinition > test_definition
OGS_EXPORT_SYMBOL MeshLib::Mesh & getMesh(std::string const &name)
OGS_EXPORT_SYMBOL double endTime() const
OGS_EXPORT_SYMBOL ~Simulation()
OGS_EXPORT_SYMBOL void initializeDataStructures(std::string const &project, std::vector< std::string > const &xml_patch_file_names, bool reference_path_is_set, std::string const &reference_path, bool nonfatal, std::string const &outdir, std::string const &mesh_dir, std::string const &script_dir, bool write_prj)
OGS_EXPORT_SYMBOL bool executeTimeStep()
vtkSmartPointer< vtkMPIController > controller
OGS_EXPORT_SYMBOL void outputLastTimeStep() const
OGS_EXPORT_SYMBOL Simulation(int argc, char *argv[])
OGS_EXPORT_SYMBOL std::vector< std::string > getMeshNames() const
static bool allOf(bool const val, Mpi const &mpi=Mpi{OGS_COMM_WORLD})
void prepareProjectFile(std::stringstream &prj_stream, const std::string &filepath, const std::vector< std::string > &patch_files, bool write_prj, const std::string &out_directory)
Applies includes and patch files to project file.
std::string extractPath(std::string const &pathname)
ConfigTree makeConfigTree(const std::string &filepath, const bool be_ruthless, const std::string &toplevel_tag, std::stringstream &prj_stream)
std::string formatDate(std::chrono::time_point< std::chrono::system_clock > const &time)
void removeFiles(std::vector< std::string > const &files)
void Initialize(BaseLib::ConfigTree const &scripts_config, std::string const &path)