GEOS
FieldStatisticsBase.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 SRC_CORECOMPONENTS_PHYSICSSOLVERS_FIELDSTATISTICSBASE_HPP_
21 #define SRC_CORECOMPONENTS_PHYSICSSOLVERS_FIELDSTATISTICSBASE_HPP_
22 
24 #include "physicsSolvers/PhysicsSolverManager.hpp"
25 #include "mesh/MeshLevel.hpp"
27 
28 namespace geos
29 {
30 
36 template< typename SOLVER >
38 {
39 public:
40 
46  FieldStatisticsBase( const string & name,
47  Group * const parent )
48  : TaskBase( name, parent ),
49  m_solver( nullptr ),
50  m_outputDir( joinPath( OutputBase::getOutputDirectory(), name ) )
51  {
53 
54  string const key = SOLVER::coupledSolverAttributePrefix() + "SolverName";
55  registerWrapper( key, &m_solverName ).
56  setRTTypeName( rtTypes::CustomTypes::groupNameRef ).
58  setDescription( "Name of the " + SOLVER::coupledSolverAttributePrefix() + " solver" );
59 
60  this->registerWrapper( viewKeyStruct::writeCSVFlagString(), &m_writeCSV ).
61  setApplyDefaultValue( 0 ).
63  setDescription( "Write statistics into a CSV file" );
64  }
65 
73  virtual bool execute( real64 const time_n,
74  real64 const dt,
75  integer const cycleNumber,
76  integer const eventCounter,
77  real64 const eventProgress,
78  DomainPartition & domain ) override = 0;
79 
82 protected:
83 
84  void postInputInitialization() override
85  {
86  Group & problemManager = this->getGroupByPath( "/Problem" );
87  Group & physicsSolverManager = problemManager.getGroup( "Solvers" );
88 
89  m_solver = physicsSolverManager.getGroupPointer< SOLVER >( m_solverName );
90  GEOS_THROW_IF( m_solver == nullptr,
91  GEOS_FMT( "{}: Could not find solver '{}' of type {}",
93  m_solverName, LvArray::system::demangleType< SOLVER >() ),
94  InputError );
95 
96  // create dir for output
97  if( m_writeCSV > 0 )
98  {
99  if( MpiWrapper::commRank() == 0 )
100  {
101  makeDirsForPath( m_outputDir );
102  }
103  // wait till the dir is created by rank 0
104  MPI_Barrier( MPI_COMM_WORLD );
105  }
106  }
107 
109  {
110  static constexpr char const * writeCSVFlagString() { return "writeCSV"; }
111  };
112 
114  SOLVER * m_solver;
115 
116  // Output directory
117  string const m_outputDir;
118 
119  // Flag to enable writing CSV output
120  integer m_writeCSV;
121 
122 private:
123 
125  string m_solverName;
126 
127 };
128 
129 
130 } /* namespace geos */
131 
132 #endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_FIELDSTATISTICSBASE_HPP_ */
#define GEOS_THROW_IF(EXP, msg, TYPE)
Conditionally throw an exception.
Definition: Logger.hpp:151
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
FieldStatisticsBase(const string &name, Group *const parent)
Constructor for the statistics class.
void postInputInitialization() override
SOLVER * m_solver
Pointer to the physics solver.
T & getGroupByPath(string const &path)
Retrieve a group from the hierarchy using a path.
Definition: Group.hpp:380
Wrapper< TBASE > & registerWrapper(string const &name, wrapperMap::KeyIndex::index_type *const rkey=nullptr)
Create and register a Wrapper around a new object.
T * getGroupPointer(KEY const &key)
Return a pointer to a sub-group of the current Group.
Definition: Group.hpp:317
DataContext const & getDataContext() const
Definition: Group.hpp:1343
T & getGroup(KEY const &key)
Return a reference to a sub-group of the current Group.
Definition: Group.hpp:336
virtual bool execute(real64 const time_n, real64 const dt, integer const cycleNumber, integer const eventCounter, real64 const eventProgress, DomainPartition &domain) override=0
Main extension point of executable targets.
@ OPTIONAL
Optional in input.
@ REQUIRED
Required in input.
void makeDirsForPath(std::string const &path)
Make directories for path.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
std::string joinPath(ARGS const &... args)
Join parts of a path.
Definition: Path.hpp:189
Exception class used to report errors in user input.
Definition: Logger.hpp:502