GEOS
GeosxState.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_MAININTERFACE_GEOSXSTATE_HPP_
21 #define GEOS_MAININTERFACE_GEOSXSTATE_HPP_
22 
23 // Source includes
24 #include "common/DataTypes.hpp"
25 #include "common/logger/Logger.hpp"
26 
27 // System includes
28 #include <functional>
29 #include <memory>
30 
31 // Forward declaration of conduit::Node.
32 namespace conduit
33 {
34 class Node;
35 }
36 
37 #if defined( GEOS_USE_CALIPER )
38 //Forward declaration of cali::ConfigManager.
39 namespace cali
40 {
41 class ConfigManager;
42 }
43 #endif
44 
45 
46 namespace geos
47 {
48 
49 // Forward declarations.
50 namespace dataRepository
51 {
52 class Group;
53 }
54 
55 class ProblemManager;
56 class FieldSpecificationManager;
57 class FunctionManager;
58 class CommunicationTools;
59 struct CommandLineOptions;
60 
66 string durationToString( std::chrono::system_clock::duration const duration );
67 
72 enum class State
73 {
74  UNINITIALIZED = 0,
75  INITIALIZED = 1,
76  READY_TO_RUN = 2,
77  COMPLETED = 3
78 };
79 
86 std::ostream & operator<<( std::ostream & os, State const state );
87 
94 {
95 public:
96 
103  explicit GeosxState( std::unique_ptr< CommandLineOptions > && commandLineOptions );
104 
111 
112  GeosxState( GeosxState const & ) = delete;
113  GeosxState( GeosxState && ) = delete;
114  GeosxState & operator=( GeosxState const & ) = delete;
115  GeosxState & operator=( GeosxState && ) = delete;
116 
124 
132 
139  void run();
140 
145  State getState() const
146  { return m_state; }
147 
153  {
154  GEOS_ERROR_IF( m_commandLineOptions == nullptr, "Not initialized." );
155  return *m_commandLineOptions;
156  }
157 
162  conduit::Node & getRootConduitNode()
163  {
164  GEOS_ERROR_IF( m_rootNode == nullptr, "Not initialized." );
165  return *m_rootNode;
166  }
167 
173  {
174  GEOS_ERROR_IF( m_problemManager == nullptr, "Not initialized." );
175  return *m_problemManager;
176  }
177 
185 
191 
197 
202  CommunicationTools & getCommunicationTools()
203  {
204  GEOS_ERROR_IF( m_commTools == nullptr, "Not initialized." );
205  return *m_commTools;
206  }
207 
212  std::chrono::system_clock::duration getInitTime() const
213  { return m_initTime; }
214 
219  std::chrono::system_clock::duration getRunTime() const
220  { return m_runTime; }
221 
222 private:
223 
225  State m_state;
226 
228  std::unique_ptr< CommandLineOptions > m_commandLineOptions;
229 
231  std::unique_ptr< conduit::Node > m_rootNode;
232 
234  std::unique_ptr< ProblemManager > m_problemManager;
235 
237  std::unique_ptr< CommunicationTools > m_commTools;
238 
239 #if defined( GEOS_USE_CALIPER )
241  std::unique_ptr< cali::ConfigManager > m_caliperManager;
242 #endif
243 
245  std::chrono::system_clock::duration m_initTime;
246 
248  std::chrono::system_clock::duration m_runTime;
249 };
250 
256 
257 } // namespace geos
258 
259 #endif /* GEOS_MAININTERFACE_GEOSXSTATE_HPP_ */
#define GEOS_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:142
Holds the global GEOSX state. This is a singleton class, no more than one instance exists at at time....
Definition: GeosxState.hpp:94
ProblemManager & getProblemManager()
Return the ProblemManager.
Definition: GeosxState.hpp:172
State getState() const
Return the current State.
Definition: GeosxState.hpp:145
conduit::Node & getRootConduitNode()
Return the root conduit node.
Definition: GeosxState.hpp:162
~GeosxState()
Destructor.
std::chrono::system_clock::duration getRunTime() const
Return the time taken to run the problem.
Definition: GeosxState.hpp:219
void run()
Run the simulation.
GeosxState(std::unique_ptr< CommandLineOptions > &&commandLineOptions)
Construct a new state from command line options.
dataRepository::Group & getProblemManagerAsGroup()
Return the ProblemManager but as a dataRepository::Group.
CommunicationTools & getCommunicationTools()
Return the CommunicationTools.
Definition: GeosxState.hpp:202
void applyInitialConditions()
Apply initial conditions and if performing a restart overwrites the data repository.
bool initializeDataRepository()
Initialize the Data Repository from the input file.
CommandLineOptions const & getCommandLineOptions()
Return the command line options.
Definition: GeosxState.hpp:152
FunctionManager & getFunctionManager()
Return the FunctionManager.
std::chrono::system_clock::duration getInitTime() const
Return the time taken to setup the problem.
Definition: GeosxState.hpp:212
FieldSpecificationManager & getFieldSpecificationManager()
Return the FieldSpecificationManager.
This is the class handling the operation flow of the problem being ran in GEOS.
GeosxState & getGlobalState()
Return the current GeosxState.
State
A description of the global state.
Definition: GeosxState.hpp:73
@ Node
location is node (like displacements in finite elements)
std::ostream & operator<<(std::ostream &stream, mapBase< K, V, SORTED > const &map)
Stream output operator for map types.
Definition: DataTypes.hpp:356
string durationToString(std::chrono::system_clock::duration const duration)
Return a string representing duration in seconds.