OGS
Simulation Class Referencefinal

Detailed Description

Definition at line 29 of file Simulation.h.

#include <Simulation.h>

Collaboration diagram for Simulation:
[legend]

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)
 
double currentTime () const
 
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::optional< ApplicationsLib::TestDefinitiongetTestDefinition () const
 
OGS_EXPORT_SYMBOL ~Simulation ()
 

Private Attributes

ApplicationsLib::LinearSolverLibrarySetup linear_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 28 of file Simulation.cpp.

29 : linear_solver_library_setup(argc, argv),
30#if defined(USE_PETSC)
31 controller(vtkSmartPointer<vtkMPIController>::New()),
32#endif
33 test_definition{std::nullopt}
34{
35#if defined(USE_PETSC)
36 controller->Initialize(&argc, &argv, 1);
37 vtkMPIController::SetGlobalController(controller);
38
39 { // Can be called only after MPI_INIT.
40 int mpi_rank;
41 MPI_Comm_rank(PETSC_COMM_WORLD, &mpi_rank);
42 spdlog::set_pattern(fmt::format("[{}] %^%l:%$ %v", mpi_rank));
43 }
44#endif
45}
std::optional< ApplicationsLib::TestDefinition > test_definition
Definition Simulation.h:59
ApplicationsLib::LinearSolverLibrarySetup linear_solver_library_setup
Definition Simulation.h:54
vtkSmartPointer< vtkMPIController > controller
Definition Simulation.h:56

References controller.

◆ ~Simulation()

Simulation::~Simulation ( )

Definition at line 175 of file Simulation.cpp.

176{
177#ifdef OGS_USE_INSITU
179 {
181 }
182#endif
183#if defined(USE_PETSC)
184 controller->Finalize(1);
185#endif
186}
bool isInsituConfigured
Definition Simulation.h:61
void Finalize()
Definition Adaptor.cpp:62

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

Member Function Documentation

◆ currentTime()

double Simulation::currentTime ( ) const

Definition at line 115 of file Simulation.cpp.

116{
117 auto const& time_loop = project_data->getTimeLoop();
118 return time_loop.currentTime();
119}
std::unique_ptr< ProjectData > project_data
Definition Simulation.h:58

References project_data.

◆ endTime()

double Simulation::endTime ( ) const

Definition at line 121 of file Simulation.cpp.

122{
123 auto const& time_loop = project_data->getTimeLoop();
124 return time_loop.endTime();
125}

References project_data.

◆ executeSimulation()

bool Simulation::executeSimulation ( )

Definition at line 147 of file Simulation.cpp.

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

References INFO(), and project_data.

◆ executeTimeStep()

bool Simulation::executeTimeStep ( )

Definition at line 127 of file Simulation.cpp.

128{
129 auto& time_loop = project_data->getTimeLoop();
130 if (time_loop.currentTime() < time_loop.endTime())
131 {
132 auto const result = time_loop.executeTimeStep();
133 if (time_loop.calculateNextTimeStep())
134 {
135 time_loop.outputLastTimeStep();
136 }
137 return result;
138 }
139 return false;
140}

References project_data.

◆ getMesh()

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

Definition at line 142 of file Simulation.cpp.

143{
144 return project_data->getMesh(name);
145}

References project_data.

◆ getTestDefinition()

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

Definition at line 169 of file Simulation.cpp.

171{
172 return test_definition;
173}

References test_definition.

◆ 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 47 of file Simulation.cpp.

53{
54 INFO("Reading project file {}.",
55 std::filesystem::absolute(project).string());
56
57 std::stringstream prj_stream;
58 BaseLib::prepareProjectFile(prj_stream, project, xml_patch_file_names,
59 write_prj, outdir);
60 auto project_config = BaseLib::makeConfigTree(
61 project, !nonfatal, "OpenGeoSysProject", prj_stream);
62
63 if (!reference_path_is_set)
64 { // Ignore the test_definition section.
65 project_config.ignoreConfigParameter("test_definition");
66 }
67 else
68 {
71 project_config.getConfigSubtree("test_definition"), reference_path,
72 outdir);
73 if (test_definition->numberOfTests() == 0)
74 {
76 "No tests were constructed from the test definitions, "
77 "but reference solutions path was given.");
78 }
79
80 INFO("Cleanup possible output files before running ogs.");
81 BaseLib::removeFiles(test_definition->getOutputFiles());
82 }
83#ifdef OGS_USE_INSITU
85 if (auto t = project_config.getConfigSubtreeOptional("insitu"))
86 {
89 t->getConfigSubtree("scripts"),
90 BaseLib::extractPath(project));
91 isInsituConfigured = true;
92 }
93#else
94 project_config.ignoreConfigParameter("insitu");
95#endif
96
97 project_data = std::make_unique<ProjectData>(project_config,
99 outdir, mesh_dir, script_dir);
100
101 INFO("Initialize processes.");
102 for (auto& p : project_data->getProcesses())
103 {
104 p->initialize(project_data->getMedia());
105 }
106
107 // Check intermediately that config parsing went fine.
108 checkAndInvalidate(project_config);
110
111 auto& time_loop = project_data->getTimeLoop();
112 time_loop.initialize();
113}
#define OGS_FATAL(...)
Definition Error.h:26
static void assertNoSwallowedErrors()
Asserts that there have not been any errors reported in the destructor.
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 const & getProjectDirectory()
Returns the directory where the prj file resides.
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:30

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

◆ outputLastTimeStep()

void Simulation::outputLastTimeStep ( ) const

Definition at line 163 of file Simulation.cpp.

164{
165 auto const& time_loop = project_data->getTimeLoop();
166 time_loop.outputLastTimeStep();
167}

References project_data.

Member Data Documentation

◆ controller

vtkSmartPointer<vtkMPIController> Simulation::controller
private

Definition at line 56 of file Simulation.h.

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

◆ isInsituConfigured

bool Simulation::isInsituConfigured = false
private

Definition at line 61 of file Simulation.h.

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

◆ linear_solver_library_setup

ApplicationsLib::LinearSolverLibrarySetup Simulation::linear_solver_library_setup
private

Definition at line 54 of file Simulation.h.

◆ project_data

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

◆ test_definition

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

Definition at line 59 of file Simulation.h.

Referenced by getTestDefinition(), and initializeDataStructures().


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