GEOS
StatisticsAggregatorBase.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_STATISTICSAGGREGATOR_HPP_
21 #define SRC_CORECOMPONENTS_PHYSICSSOLVERS_STATISTICSAGGREGATOR_HPP_
22 
23 #include "common/DataTypes.hpp"
25 #include "dataRepository/Group.hpp"
27 #include "mesh/MeshBody.hpp"
28 #include "mesh/MeshLevel.hpp"
29 
30 namespace geos
31 {
32 
39 {
40 public:
41 
44 
53  RegionStatisticsBase( string const & targetName,
54  dataRepository::Group * const parent,
55  bool statsOutputEnabled );
56 
62  { return getName(); }
63 
64 };
65 
66 template< typename T >
68 
76 template< typename Impl >
78 {
79 public:
80 
81  using SolverType = typename StatsAggregatorTraits< Impl >::SolverType;
82 
83  using StatsGroupType = typename StatsAggregatorTraits< Impl >::StatsGroupType;
84 
92  template< typename OwnerType >
93  using RegionStatsFunc = std::function< void ( OwnerType &,
94  StatsGroupType & ) >;
95 
101  using RegionStatsRegisterFunc = std::function< StatsGroupType & ( dataRepository::Group &,
102  string const & ) >;
103 
107  struct ViewKeys
108  {
110  constexpr static char const * statisticsString() { return "statistics"; }
112  constexpr static char const * regionsStatisticsString() { return "regionsStatistics"; }
113  };
114 
123  StatsAggregatorBase( dataRepository::DataContext const & ownerDataContext,
124  dataRepository::Group & meshBodies,
125  bool statsOutputEnabled );
126 
134  void initStatisticsAggregation( SolverType & solver );
135 
136  void forRegionStatistics( RegionStatsFunc< MeshLevel > const & functor ) const;
137 
138  void forRegionStatistics( MeshLevel & mesh,
139  StatsGroupType & meshRegionsStatistics,
140  RegionStatsFunc< CellElementRegion > const & functor ) const;
141 
142  void forRegionStatistics( CellElementRegion & region,
143  StatsGroupType & regionStatistics,
144  RegionStatsFunc< CellElementSubRegion > const & functor ) const;
145 
151  bool isComputed( real64 const timeRequest, StatsGroupType const & stats );
152 
156  void setDirty();
157 
164  bool computeRegionsStatistics( real64 const timeRequest );
165 
169  string const & getOwnerName() const
170  { return m_ownerDataContext.getTargetName(); }
171 
176  { return m_warnings; }
177 
178  dataRepository::Group & getInstanceStatisticsGroup( MeshLevel & mesh ) const;
179 
180  StatsGroupType & getRegionsStatistics( MeshLevel & mesh ) const;
181 
188  StatsGroupType & getRegionStatistics( MeshLevel & mesh, string_view regionName ) const;
189 
190 protected:
191 
192  struct StatsState
193  {
194  bool m_isEnabled = false;
195  bool m_isDirty = false;
196  };
197 
199  {
200  localIndex m_meshBody;
201  localIndex m_meshLevel;
202  string_array m_regionNames;
203  };
204 
207 
210 
211  dataRepository::Group & m_meshBodies;
212 
213  stdVector< DiscretizationGroupPath > m_discretizationsPaths;
214 
217 
220 
227  void enableRegionStatisticsAggregation( RegionStatsRegisterFunc && registerStatsFunc );
228 
233  MeshLevel & getMeshLevel( DiscretizationGroupPath const & path ) const;
234 
242  void initStats( StatsGroupType & stats, real64 time ) const
243  { static_cast< Impl const * >(this)->initStats( stats, time ); }
244 
251  void computeSubRegionRankStats( CellElementSubRegion & subRegion, StatsGroupType & subRegionStats ) const
252  { static_cast< Impl const * >(this)->computeSubRegionRankStats( subRegion, subRegionStats ); }
253 
260  void aggregateStats( StatsGroupType & stats, StatsGroupType const & other ) const
261  { static_cast< Impl const * >(this)->aggregateStats( stats, other ); }
262 
268  void mpiAggregateStats( StatsGroupType & stats ) const
269  { static_cast< Impl const * >(this)->mpiAggregateStats( stats ); }
270 
276  void postAggregateStats( StatsGroupType & stats )
277  { static_cast< Impl * >(this)->postAggregateStats( stats ); }
278 
279 };
280 
281 } /* namespace geos */
282 
283 #endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_STATISTICSAGGREGATOR_HPP_ */
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:42
Output data group to contain the result of a given stat aggregator on the dataRepository....
RegionStatisticsBase(string const &targetName, dataRepository::Group *const parent, bool statsOutputEnabled)
Construct a new Region Statistics Base object.
real64 m_time
Time of statistics computation (std::numeric_limits< double >::lowest() if not initialized)
Reponsible of computing physical statistics over the grid, registering the result in the data reposit...
void computeSubRegionRankStats(CellElementSubRegion &subRegion, StatsGroupType &subRegionStats) const
Compute the rank-local stats for the given sub-region and store the results in the given stats group.
stdVector< string > const & getWarnings() const
void initStats(StatsGroupType &stats, real64 time) const
Initialize all statistics values to aggregable default values, before any computation / reduction for...
void postAggregateStats(StatsGroupType &stats)
Do the final computations for the statistics. Must be called after computations & aggregations.
void initStatisticsAggregation(SolverType &solver)
Enable the computation of any statistics, initialize data structure to collect them....
void mpiAggregateStats(StatsGroupType &stats) const
Aggregate all instance statistics with those of other ranks.
std::function< StatsGroupType &(dataRepository::Group &, string const &) > RegionStatsRegisterFunc
A functor that can be used to register a statistics Group instance. Parameters:
StatsAggregatorBase(dataRepository::DataContext const &ownerDataContext, dataRepository::Group &meshBodies, bool statsOutputEnabled)
Construct a new Stats Aggregator object.
bool const m_statsOutputEnabled
If true, the stats are to save in the output HDF5.
void setDirty()
set the statistics as dirty, ensuring isComputed() will be false until the next computation.
MeshLevel & getMeshLevel(DiscretizationGroupPath const &path) const
StatsState m_regionStatsState
The current state of the region statistics.
std::function< void(OwnerType &, StatsGroupType &) > RegionStatsFunc
Standard function signature for any functor that applies on statistics group instances (StatsGroupTyp...
StatsGroupType & getRegionStatistics(MeshLevel &mesh, string_view regionName) const
bool isComputed(real64 const timeRequest, StatsGroupType const &stats)
void enableRegionStatisticsAggregation(RegionStatsRegisterFunc &&registerStatsFunc)
Enable the computation of region statistics, initialize data structure to collect them....
dataRepository::DataContext const & m_ownerDataContext
void aggregateStats(StatsGroupType &stats, StatsGroupType const &other) const
Aggregate all instance statistics with those of another instance on the current rank.
bool computeRegionsStatistics(real64 const timeRequest)
Compute statistics on the mesh discretizations (average field pressure, etc) Results are reduced on r...
string const & getTargetName() const
Definition: DataContext.hpp:81
string const & getName() const
Get group name.
Definition: Group.hpp:1329
stdVector< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:361
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
std::string_view string_view
String type.
Definition: DataTypes.hpp:93
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector
constexpr static char const * regionsStatisticsString()
String for the region statistics group.
constexpr static char const * statisticsString()
String for the discretization statistics group.