19 #include "LvArray/src/math.hpp"
21 #include "common/format/Format.hpp"
27 #include "mesh/CellElementSubRegion.hpp"
29 #include "mesh/MeshLevel.hpp"
36 bool const statsOutputEnabled ):
37 dataRepository::
Group( targetName, parent ),
38 m_time( std::numeric_limits< double >::lowest() )
47 template<
typename Impl >
50 bool const statsOutputEnabled ):
51 m_ownerDataContext( ownerDataContext ),
52 m_statsOutputEnabled( statsOutputEnabled ),
53 m_meshBodies( meshBodies )
56 template<
typename Impl >
60 solver.forDiscretizationOnMeshTargets( m_meshBodies, [&] (
string const & meshBodyName,
66 if( meshStatsGroup ==
nullptr )
67 meshStatsGroup = &mesh.
registerGroup( ViewKeys::statisticsString() );
70 string const & ownerName = getOwnerName();
72 GEOS_FMT(
"A statistics aggregator have already been requested for '{}'.",
84 m_discretizationsPaths.push_back( path );
88 template<
typename Impl >
95 for(
auto const & path : m_discretizationsPaths )
100 StatsGroupType & meshRegionsStats = registerStatsFunc( statisticsGroup,
101 ViewKeys::regionsStatisticsString() );
103 for(
size_t i = 0; i < path.m_regionNames.size(); ++i )
106 StatsGroupType & regionStats = registerStatsFunc( meshRegionsStats,
111 registerStatsFunc( regionStats,
112 subRegion.getName() );
120 GEOS_FMT(
"Missing region for computing statistics:\n- {} regions,\n- {} sub-regions.",
121 getOwnerName(), regionCount, subRegionCount ),
122 m_ownerDataContext );
124 m_regionStatsState.m_isEnabled =
true;
125 m_regionStatsState.m_isDirty =
true;
128 template<
typename Impl >
132 for(
auto const & path : m_discretizationsPaths )
135 StatsGroupType & meshRegionsStats = getRegionsStatistics( mesh );
137 func( mesh, meshRegionsStats );
141 template<
typename Impl >
143 StatsAggregatorBase< Impl >::forRegionStatistics( MeshLevel & mesh,
144 StatsGroupType & meshRegionsStatistics,
145 RegionStatsFunc< CellElementRegion >
const & func )
const
147 ElementRegionManager & elemManager = mesh.getElemManager();
148 meshRegionsStatistics.template forSubGroups< StatsGroupType >( [&] ( StatsGroupType & regionStatistics )
150 string_view targetName = regionStatistics.getTargetName();
153 func( region, regionStatistics );
157 template<
typename Impl >
160 StatsGroupType & regionStatistics,
163 regionStatistics.template forSubGroups< StatsGroupType >( [&] ( StatsGroupType & subRegionStatistics )
165 string_view targetName = subRegionStatistics.getTargetName();
167 func( subRegion, subRegionStatistics );
171 template<
typename Impl >
175 real64 const timePrecisionScale = LvArray::math::max( LvArray::math::abs( timeRequest ),
176 LvArray::math::abs( stats.m_time ) );
177 static constexpr
real64 timeRelTol = 1.0e-12;
180 !m_regionStatsState.m_isDirty &&
181 LvArray::math::abs( timeRequest - stats.m_time ) < timeRelTol * timePrecisionScale;
184 template<
typename Impl >
188 m_regionStatsState.m_isDirty =
true;
191 template<
typename Impl >
200 forRegionStatistics( [&, timeRequest] (
MeshLevel & mesh, StatsGroupType & meshRegionsStats )
202 forRegionStatistics( mesh,
206 forRegionStatistics( region,
210 initStats( subRegionStats, timeRequest );
211 computeSubRegionRankStats( subRegion, subRegionStats );
217 forRegionStatistics( [&, timeRequest] (
MeshLevel & mesh, StatsGroupType & meshRegionsStats )
219 initStats( meshRegionsStats, timeRequest );
221 forRegionStatistics( mesh,
225 initStats( regionStats, timeRequest );
227 forRegionStatistics( region,
231 aggregateStats( regionStats, subRegionStats );
233 mpiAggregateStats( subRegionStats );
234 postAggregateStats( subRegionStats );
237 aggregateStats( meshRegionsStats, regionStats );
239 mpiAggregateStats( regionStats );
240 postAggregateStats( regionStats );
243 mpiAggregateStats( meshRegionsStats );
244 postAggregateStats( meshRegionsStats );
247 m_regionStatsState.m_isDirty =
false;
252 template<
typename Impl >
261 template<
typename Impl >
268 return instanceStatisticsGroup;
271 template<
typename Impl >
272 typename StatsAggregatorBase< Impl >::StatsGroupType &
273 StatsAggregatorBase< Impl >::
274 getRegionsStatistics( MeshLevel & mesh )
const
277 dataRepository::Group & instanceStatisticsGroup = getInstanceStatisticsGroup( mesh );
278 return instanceStatisticsGroup.getGroup< StatsGroupType >( ViewKeys::regionsStatisticsString() );
281 template<
typename Impl >
282 typename StatsAggregatorBase< Impl >::StatsGroupType &
286 StatsGroupType & meshRegionsStats = getRegionsStatistics( mesh );
287 StatsGroupType *
const stats = meshRegionsStats.template getGroupPointer< StatsGroupType >(
string( regionName ) );
289 GEOS_FMT(
"Region '{}' not found to get region statistics, is it a target of the reservoir solver?\n"
290 "Available target regions:\n- {}",
291 regionName, stringutilities::join( meshRegionsStats.getSubGroupsNames(),
"\n- " ) ),
#define GEOS_ERROR_IF(COND,...)
Conditionally raise a hard error and terminate the program.
#define GEOS_ERROR_IF_NE_MSG(lhs, rhs,...)
Raise a hard error if two values are not equal.
#define GEOS_THROW_IF(COND, MSG,...)
Conditionally raise a hard error and terminate the program.
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
void forElementSubRegions(LAMBDA &&lambda) const
Apply a lambda to all subregions.
SUBREGIONTYPE const & getSubRegion(KEY_TYPE const &key) const
Get a reference to a subregion.
The ElementRegionManager class provides an interface to ObjectManagerBase in order to manage ElementR...
T const & getRegion(KEY_TYPE const &key) const
Get a element region.
The class is used to manage mesh body.
MeshLevel & getMeshLevel(T const &level) const
Get a reference to a MeshLevel.
Class facilitating the representation of a multi-level discretization of a MeshBody.
ElementRegionManager const & getElemManager() const
Get the element region manager.
RegionStatisticsBase(string const &targetName, dataRepository::Group *const parent, bool statsOutputEnabled)
Construct a new Region Statistics Base object.
Reponsible of computing physical statistics over the grid, registering the result in the data reposit...
void initStatisticsAggregation(SolverType &solver)
Enable the computation of any statistics, initialize data structure to collect them....
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.
void setDirty()
set the statistics as dirty, ensuring isComputed() will be false until the next computation.
MeshLevel & getMeshLevel(DiscretizationGroupPath const &path) const
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 &®isterStatsFunc)
Enable the computation of region statistics, initialize data structure to collect them....
bool computeRegionsStatistics(real64 const timeRequest)
Compute statistics on the mesh discretizations (average field pressure, etc) Results are reduced on r...
T * getGroupPointer(KEY const &key)
Return a pointer to a sub-group of the current Group.
localIndex getIndexInParent() const
Get the group's index within its parent group.
T & registerGroup(string const &name, std::unique_ptr< T > newObject)
Register a new Group as a sub-group of current Group.
void setRestartFlags(RestartFlags flags)
Set flags that control restart output of this group.
string const & getName() const
Get group name.
T & getGroup(KEY const &key)
Return a reference to a sub-group of the current Group.
bool hasGroup(string const &name) const
Check whether a sub-group exists.
@ WRITE_AND_READ
Write and read from restart.
@ NO_WRITE
Do not write into restart.
stdVector< string > string_array
A 1-dimensional array of geos::string types.
std::string string
String type.
double real64
64-bit floating point type.
int integer
Signed integer type.
std::string_view string_view
String type.