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 
55  RegionStatisticsBase( string const & targetName,
56  dataRepository::Group * const parent,
57  string_view setName,
58  bool dataOutputEnabled );
59 
65  { return getName(); }
66 
72  { return m_setName; }
73 
74 private:
76  string const m_setName;
77 };
78 
79 template< typename T >
81 
89 template< typename Impl >
91 {
92 public:
93 
94  using SolverType = typename StatsAggregatorTraits< Impl >::SolverType;
95 
96  using StatsGroupType = typename StatsAggregatorTraits< Impl >::StatsGroupType;
97 
98  using SetType = SortedArray< localIndex >;
99 
100  using SetViewType = SortedArrayView< localIndex const >;
101 
109  template< typename OwnerType >
110  using RegionStatsFunc = std::function< void ( OwnerType,
111  StatsGroupType & ) >;
112 
120  using RegionStatsRegisterFunc = std::function< StatsGroupType & ( dataRepository::Group &,
121  string const &,
122  string_view,
123  bool ) >;
124 
128  struct ViewKeys
129  {
131  constexpr static string_view statisticsString() { return "statistics"; }
133  constexpr static string_view setsStatisticsString() { return "setsStatistics"; }
135  constexpr static string_view compoundSetNameString() { return "__compound"; }
136  };
137 
142  {
143  MeshLevel & mesh;
144  string_view setName;
145  };
146 
155  StatsAggregatorBase( dataRepository::DataContext const & ownerDataContext,
156  dataRepository::Group & meshBodies,
157  bool statsOutputEnabled );
158 
165  void initStatisticsAggregation( SolverType & solver );
166 
170  void setDirty();
171 
178  bool computeRegionsStatistics( real64 const timeRequest );
179 
184 
189  void forRegionStatistics( RegionStatsFunc< MeshLevel & > const & functor ) const;
190 
199  void forRegionStatistics( MeshLevel & mesh,
200  StatsGroupType & meshSetsStats,
201  bool enableCompoundSet,
202  RegionStatsFunc< MeshLevelSet > const & functor ) const;
203 
210  void forRegionStatistics( MeshLevelSet meshSet,
211  StatsGroupType & setStats,
212  RegionStatsFunc< CellElementRegion & > const & functor ) const;
213 
220  void forRegionStatistics( CellElementRegion & region,
221  StatsGroupType & setRegionStats,
222  RegionStatsFunc< CellElementSubRegion & > const & functor ) const;
223 
230 
236  StatsGroupType & getMeshLevelStatistics( MeshLevel & mesh ) const;
237 
245  StatsGroupType & getSetStatistics( MeshLevel & mesh, string_view setName = "" ) const;
246 
256  StatsGroupType & getRegionStatistics( MeshLevel & mesh, string_view regionName, string_view setName = "" ) const;
257 
259 
265  bool isComputed( real64 const timeRequest, StatsGroupType const & stats );
266 
272  {return !( m_setNames.empty() || ( m_setNames.size() == 1 && m_setNames.count( "all" ) > 0 ) ); }
273 
279  { return m_setNames.size() > 1; }
280 
284  string const & getOwnerName() const
285  { return m_ownerDataContext.getTargetName(); }
286 
291  { return m_warnings; }
292 
293 protected:
294 
295  struct StatsState
296  {
297  bool m_isEnabled = false;
298  bool m_isDirty = false;
299  };
300 
301  using SetsCompound = stdMap< string, stdMap< string, SetType > >;
302 
304  {
314  SetsCompound m_setsCompound;
315  };
316 
319 
322 
323  dataRepository::Group & m_meshBodies;
324 
328 
331  std::set< string > m_setNames;
332 
335 
338 
341 
351  string_array const & setNames );
352 
357  MeshLevel & getMeshLevel( DiscretizationSetPath const & path ) const;
358 
365  StatsGroupType & getCompoundSetStatistics( MeshLevel & mesh ) const;
366 
371  bool isCompoundSetStatistics( StatsGroupType const & stats ) const;
372 
376  static std::set< string > getMeshLevelPartialSetNames( MeshLevel const & mesh,
377  string_array const & regionNames );
378 
383  void setTargetSets( string_array const & setNames );
384 
392  void initStats( StatsGroupType & stats, real64 time ) const
393  { static_cast< Impl const * >(this)->initStats( stats, time ); }
394 
403  StatsGroupType & subRegionStats,
404  SetType const & targetSet ) const
405  { static_cast< Impl const * >(this)->computeSubRegionRankStats( subRegion, subRegionStats, targetSet ); }
406 
413  void aggregateStats( StatsGroupType & stats, StatsGroupType const & other ) const
414  { static_cast< Impl const * >(this)->aggregateStats( stats, other ); }
415 
421  void mpiAggregateStats( StatsGroupType & stats ) const
422  { static_cast< Impl const * >(this)->mpiAggregateStats( stats ); }
423 
429  void postAggregateStats( StatsGroupType & stats )
430  { static_cast< Impl * >(this)->postAggregateStats( stats ); }
431 
432 };
433 
434 } /* namespace geos */
435 
436 #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, string_view setName, bool dataOutputEnabled)
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...
stdVector< string > const & getWarnings() const
dataRepository::Group & getInstanceStatisticsGroup(MeshLevel &mesh) const
Get the Instance Statistics Group for the given mesh-level.
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, explores the data structure to collect them.
bool m_isAnySetsIntersecting
if true, at least ont set intersects with another, threfore we must compute mesh-level statistics wit...
StatsGroupType & getMeshLevelStatistics(MeshLevel &mesh) const
void mpiAggregateStats(StatsGroupType &stats) const
Aggregate all instance statistics with those of other ranks.
void computeSubRegionRankStats(CellElementSubRegion &subRegion, StatsGroupType &subRegionStats, SetType const &targetSet) const
Compute the rank-local stats for the given sub-region and store the results in the given stats group.
StatsAggregatorBase(dataRepository::DataContext const &ownerDataContext, dataRepository::Group &meshBodies, bool statsOutputEnabled)
Construct a new Stats Aggregator object.
void enableRegionStatisticsAggregation(RegionStatsRegisterFunc &&registerStatsFunc, string_array const &setNames)
Enable the computation of region statistics, initialize data structure to collect them....
StatsGroupType & getRegionStatistics(MeshLevel &mesh, string_view regionName, string_view setName="") const
std::function< void(OwnerType, StatsGroupType &) > RegionStatsFunc
Standard function signature for any functor that applies on statistics group instances (StatsGroupTyp...
MeshLevel & getMeshLevel(DiscretizationSetPath const &path) const
void setDirty()
set the statistics as dirty, ensuring isComputed() will be false until the next computation.
stdVector< DiscretizationSetPath > m_discretizationsPaths
StatsGroupType & getSetStatistics(MeshLevel &mesh, string_view setName="") const
static std::set< string > getMeshLevelPartialSetNames(MeshLevel const &mesh, string_array const &regionNames)
TODO.
StatsState m_regionStatsState
The current state of the region statistics.
StatsGroupType & getCompoundSetStatistics(MeshLevel &mesh) const
bool isCompoundSetStatistics(StatsGroupType const &stats) const
std::function< StatsGroupType &(dataRepository::Group &, string const &, string_view, bool) > RegionStatsRegisterFunc
A functor that can be used to register a statistics Group instance. Parameters:
bool const m_dataOutputEnabled
If true, the stats are to save in the output HDF5.
bool isComputed(real64 const timeRequest, StatsGroupType const &stats)
void forRegionStatistics(RegionStatsFunc< MeshLevel & > const &functor) const
Execute the given functor on each mesh-level (discretization) available for this instance.
void setTargetSets(string_array const &setNames)
Set the statstics target sets to restrict the statistics to.
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
internal::StdMapWrapper< std::map< Key, T, Compare, Allocator >, USE_STD_CONTAINER_BOUNDS_CHECKING > stdMap
LvArray::SortedArray< T, localIndex, LvArray::ChaiBuffer > SortedArray
A sorted array of local indices.
Definition: DataTypes.hpp:266
LvArray::SortedArrayView< T, localIndex, LvArray::ChaiBuffer > SortedArrayView
A sorted array view of local indices.
Definition: DataTypes.hpp:270
std::string_view string_view
String type.
Definition: DataTypes.hpp:93
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector
localIndex m_meshLevel
The id of the mesh level in the mesh body.
string_array m_regionNames
the regions names in the mesh-level / mesh level
localIndex m_meshBody
The id of the mesh body in the "meshBodies" Group.
SetsCompound m_setsCompound
if at least one set intersects with another, a compound of (local element index) set is needed to com...
string_array m_setNames
The names of this mesh-level element sets. If none is specified (empty), "all" elements set is target...
Allow to reference a set in a given MeshLevel structure.
constexpr static string_view statisticsString()
String for the mesh-level statistics group.
constexpr static string_view setsStatisticsString()
String for the region statistics group.
constexpr static string_view compoundSetNameString()
on-purpose generated compound set name