OGS
Simulation Class Referencefinal

Detailed Description

Definition at line 20 of file Simulation.h.

#include <Simulation.h>

Public Member Functions

OGS_EXPORT_SYMBOL Simulation (int argc, char *argv[])
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 double currentTime () const
OGS_EXPORT_SYMBOL double endTime () const
OGS_EXPORT_SYMBOL bool executeTimeStep ()
OGS_EXPORT_SYMBOL bool executeSimulation ()
OGS_EXPORT_SYMBOL void outputLastTimeStep () const
OGS_EXPORT_SYMBOL MeshLib::MeshgetMesh (std::string const &name)
OGS_EXPORT_SYMBOL std::vector< std::string > getMeshNames () const
OGS_EXPORT_SYMBOL std::optional< ApplicationsLib::TestDefinitiongetTestDefinition () const
OGS_EXPORT_SYMBOL ~Simulation ()

Static Public Member Functions

static OGS_EXPORT_SYMBOL int runTestDefinitions (std::optional< ApplicationsLib::TestDefinition > &test_definition)

Private Attributes

std::shared_ptr< ApplicationsLib::LinearSolverLibrarySetuplinear_solver_library_setup
vtkSmartPointer< vtkMPIController > controller
std::unique_ptr< ProjectDataproject_data
std::optional< ApplicationsLib::TestDefinitiontest_definition
bool isInsituConfigured = false

Constructor & Destructor Documentation

◆ Simulation()

Simulation::Simulation ( int argc,
char * argv[] )

Definition at line 21 of file Simulation.cpp.

23 create(argc, argv)},
24#if defined(USE_PETSC)
25 controller(vtkSmartPointer<vtkMPIController>::New()),
26#endif
27 test_definition{std::nullopt}
28{
29#if defined(USE_PETSC)
30 controller->Initialize(&argc, &argv, 1);
31 vtkMPIController::SetGlobalController(controller);
32#endif
33}
std::shared_ptr< ApplicationsLib::LinearSolverLibrarySetup > linear_solver_library_setup
Definition Simulation.h:50
std::optional< ApplicationsLib::TestDefinition > test_definition
Definition Simulation.h:55
vtkSmartPointer< vtkMPIController > controller
Definition Simulation.h:52
OGS_EXPORT_SYMBOL static std::shared_ptr< LinearSolverLibrarySetup > create(int argc, char *argv[])

References controller, linear_solver_library_setup, and test_definition.

◆ ~Simulation()

Simulation::~Simulation ( )

Definition at line 178 of file Simulation.cpp.

179{
180#ifdef OGS_USE_INSITU
182 {
184 }
185#endif
186#if defined(USE_PETSC)
187 controller->Finalize(1);
188#endif
189}
bool isInsituConfigured
Definition Simulation.h:57
void Finalize()
Definition Adaptor.cpp:55

References controller, InSituLib::Finalize(), and isInsituConfigured.

Member Function Documentation

◆ currentTime()

double Simulation::currentTime ( ) const

Definition at line 109 of file Simulation.cpp.

110{
111 auto const& time_loop = project_data->getTimeLoop();
112 return time_loop.currentTime()();
113}
std::unique_ptr< ProjectData > project_data
Definition Simulation.h:54

References project_data.

◆ endTime()

double Simulation::endTime ( ) const

Definition at line 115 of file Simulation.cpp.

116{
117 auto const& time_loop = project_data->getTimeLoop();
118 return time_loop.endTime()();
119}

References project_data.

◆ executeSimulation()

bool Simulation::executeSimulation ( )

Definition at line 150 of file Simulation.cpp.

151{
152 INFO("Solve processes.");
153 auto& time_loop = project_data->getTimeLoop();
154 while (time_loop.currentTime() < time_loop.endTime())
155 {
156 time_loop.executeTimeStep();
157 if (!time_loop.calculateNextTimeStep())
158 {
159 break;
160 }
161 }
162
163 return time_loop.successful_time_step;
164}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28

References INFO(), and project_data.

Referenced by main().

◆ executeTimeStep()

bool Simulation::executeTimeStep ( )

Definition at line 121 of file Simulation.cpp.

122{
123 auto& time_loop = project_data->getTimeLoop();
124 if (time_loop.currentTime() < time_loop.endTime())
125 {
126 auto const result = time_loop.executeTimeStep();
127 time_loop.calculateNextTimeStep();
128 return result;
129 }
130 return false;
131}

References project_data.

◆ getMesh()

MeshLib::Mesh & Simulation::getMesh ( std::string const & name)

Definition at line 133 of file Simulation.cpp.

134{
135 return project_data->getMesh(name);
136}

References project_data.

◆ getMeshNames()

std::vector< std::string > Simulation::getMeshNames ( ) const

Definition at line 138 of file Simulation.cpp.

139{
140 return project_data->getMeshNames();
141}

References project_data.

◆ getTestDefinition()

std::optional< ApplicationsLib::TestDefinition > Simulation::getTestDefinition ( ) const

Definition at line 172 of file Simulation.cpp.

174{
175 return test_definition;
176}

References test_definition.

Referenced by main().

◆ initializeDataStructures()

void Simulation::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 )
Input File Parameter
prj__test_definition
Input File Parameter
prj__insitu
Input File Parameter
prj__insitu__scripts

Definition at line 35 of file Simulation.cpp.

41{
42 INFO("Reading project file {}.",
43 std::filesystem::relative(project).string());
44 DBUG("Project file: {}.", std::filesystem::absolute(project).string());
45
46 std::stringstream prj_stream;
47 BaseLib::prepareProjectFile(prj_stream, project, xml_patch_file_names,
48 write_prj, outdir);
49 auto project_config = BaseLib::makeConfigTree(
50 project, !nonfatal, "OpenGeoSysProject", prj_stream);
51
52 if (!reference_path_is_set)
53 { // Ignore the test_definition section.
54 project_config.ignoreConfigParameter("test_definition");
55 }
56 else
57 {
58 test_definition = ApplicationsLib::TestDefinition(
60 project_config.getConfigSubtree("test_definition"), reference_path,
61 outdir);
62 if (test_definition->numberOfTests() == 0)
63 {
65 "No tests were constructed from the test definitions, "
66 "but reference solutions path was given.");
67 }
68
69 INFO("Cleanup possible output files before running ogs.");
70 BaseLib::removeFiles(test_definition->getOutputFiles());
71 }
72#ifdef OGS_USE_INSITU
74 if (auto t = project_config.getConfigSubtreeOptional("insitu"))
75 {
78 t->getConfigSubtree("scripts"),
79 BaseLib::extractPath(project));
80 isInsituConfigured = true;
81 }
82#else
83 project_config.ignoreConfigParameter("insitu");
84#endif
85
86 project_data = std::make_unique<ProjectData>(project_config, outdir,
87 mesh_dir, script_dir);
88
89 INFO("Initialize processes.");
90 for (auto& p : project_data->getProcesses())
91 {
92 p->initialize(project_data->getMedia());
93 }
94
95 // Check intermediately that config parsing went fine.
96 checkAndInvalidate(project_config);
98
99 auto& time_loop = project_data->getTimeLoop();
100 auto time_value = time_loop.currentTime()();
101 INFO("Time step #0 started. Time: {}. Step size: 0.", time_value);
102
103 BaseLib::RunTime init_timer;
104 init_timer.start();
105 time_loop.initialize();
106 INFO("Time step #0 took {:g} s.", init_timer.elapsed());
107}
#define OGS_FATAL(...)
Definition Error.h:19
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
static void assertNoSwallowedErrors()
Asserts that there have not been any errors reported in the destructor.
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:31
void start()
Start the timer.
Definition RunTime.h:21
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.
void checkAndInvalidate(ConfigTree &conf)
This is an overloaded member function, provided for convenience. It differs from the above function o...
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)
void removeFiles(std::vector< std::string > const &files)
void Initialize(BaseLib::ConfigTree const &scripts_config, std::string const &path)
Definition Adaptor.cpp:23

References BaseLib::ConfigTree::assertNoSwallowedErrors(), DBUG(), BaseLib::RunTime::elapsed(), BaseLib::extractPath(), INFO(), InSituLib::Initialize(), isInsituConfigured, BaseLib::makeConfigTree(), OGS_FATAL, BaseLib::prepareProjectFile(), project_data, BaseLib::removeFiles(), BaseLib::RunTime::start(), and test_definition.

Referenced by main().

◆ outputLastTimeStep()

void Simulation::outputLastTimeStep ( ) const

Definition at line 166 of file Simulation.cpp.

167{
168 auto const& time_loop = project_data->getTimeLoop();
169 time_loop.outputLastTimeStep();
170}

References project_data.

Referenced by main().

◆ runTestDefinitions()

int Simulation::runTestDefinitions ( std::optional< ApplicationsLib::TestDefinition > & test_definition)
static

Definition at line 191 of file Simulation.cpp.

193{
194 if (!test_definition)
195 {
196 auto const end_time = std::chrono::system_clock::now();
197 auto const time_str = BaseLib::formatDate(end_time);
198 DBUG("No test definition was found. No tests will be executed.");
199 INFO("OGS completed on {:s}.", time_str);
200 return EXIT_SUCCESS;
201 }
202
203 INFO("");
204 INFO("##########################################");
205 INFO("# Running tests #");
206 INFO("##########################################");
207 INFO("");
208 auto status = test_definition->runTests();
209 auto const end_time = std::chrono::system_clock::now();
210 auto const time_str = BaseLib::formatDate(end_time);
211 if (status)
212 {
213 INFO("OGS completed on {:s}.", time_str);
214 }
215 else
216 {
217 ERR("OGS terminated on {:s}. One of the tests failed.", time_str);
218 return EXIT_FAILURE;
219 }
220 return EXIT_SUCCESS;
221}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::string formatDate(std::chrono::time_point< std::chrono::system_clock > const &time)

References DBUG(), ERR(), BaseLib::formatDate(), INFO(), and test_definition.

Referenced by OGSSimulation::executeSimulation(), and main().

Member Data Documentation

◆ controller

vtkSmartPointer<vtkMPIController> Simulation::controller
private

Definition at line 52 of file Simulation.h.

Referenced by Simulation(), and ~Simulation().

◆ isInsituConfigured

bool Simulation::isInsituConfigured = false
private

Definition at line 57 of file Simulation.h.

Referenced by ~Simulation(), and initializeDataStructures().

◆ linear_solver_library_setup

std::shared_ptr<ApplicationsLib::LinearSolverLibrarySetup> Simulation::linear_solver_library_setup
private

Definition at line 50 of file Simulation.h.

Referenced by Simulation().

◆ project_data

std::unique_ptr<ProjectData> Simulation::project_data
private

◆ test_definition

std::optional<ApplicationsLib::TestDefinition> Simulation::test_definition
private

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