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 TotalEnergies
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  {
52 
53  registerWrapper( getSolverWrapperKey(), &m_solverName ).
54  setRTTypeName( rtTypes::CustomTypes::groupNameRef ).
56  setDescription( "Name of the " + SOLVER::coupledSolverAttributePrefix() + " solver" );
57 
58  this->registerWrapper( viewKeyStruct::writeCSVFlagString(), &m_writeCSV ).
59  setApplyDefaultValue( 0 ).
61  setDescription( "When set to 1, write the statistics into a CSV file" );
62  }
63 
71  virtual bool execute( real64 const time_n,
72  real64 const dt,
73  integer const cycleNumber,
74  integer const eventCounter,
75  real64 const eventProgress,
76  DomainPartition & domain ) override = 0;
77 
80 protected:
81 
83  {
84  static constexpr char const * writeCSVFlagString() { return "writeCSV"; }
85  };
86 
88  SOLVER * m_solver;
89 
90  // Output directory
91  string const m_outputDir;
92 
93  // Flag to enable writing CSV output
94  integer m_writeCSV;
95 
96  void postInputInitialization() override
97  {
98  Group & problemManager = this->getGroupByPath( "/Problem" );
99  Group & physicsSolverManager = problemManager.getGroup( "Solvers" );
100 
101  m_solver = physicsSolverManager.getGroupPointer< SOLVER >( m_solverName );
102  GEOS_THROW_IF( m_solver == nullptr,
103  GEOS_FMT( "Could not find solver '{}' of type {}",
104  m_solverName, LvArray::system::demangleType< SOLVER >() ),
106 
107  // create dir for output
108  if( m_writeCSV > 0 )
109  {
110  if( MpiWrapper::commRank() == 0 )
111  {
112  makeDirsForPath( m_outputDir );
113  }
114  // wait till the dir is created by rank 0
115  MPI_Barrier( MPI_COMM_WORLD );
116  }
117  }
118 
119  string getSolverWrapperKey() const
120  { return SOLVER::coupledSolverAttributePrefix() + "SolverName"; }
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(COND, MSG,...)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:308
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.
static string const getOutputDirectory()
Get the output directory for function output.
T & getGroupByPath(string const &path)
Retrieve a group from the hierarchy using a path.
Definition: Group.hpp:362
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:299
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:318
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:98
std::string joinPath(ARGS const &... args)
Join parts of a path.
Definition: Path.hpp:179
int integer
Signed integer type.
Definition: DataTypes.hpp:81
Exception class used to report errors in user input.