GEOS
StatisticsKernel.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 GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_STATISTICSKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_STATISTICSKERNEL_HPP
22 
23 #include "common/DataTypes.hpp"
24 #include "common/GEOS_RAJA_Interface.hpp"
25 
26 namespace geos
27 {
28 
29 namespace singlePhaseBaseKernels
30 {
31 
32 /******************************** StatisticsKernel ********************************/
33 
35 {
36  static void
37  saveDeltaPressure( localIndex const size,
38  arrayView1d< real64 const > const & pres,
39  arrayView1d< real64 const > const & initPres,
40  arrayView1d< real64 > const & deltaPres )
41  {
42  forAll< parallelDevicePolicy<> >( size, [=] GEOS_HOST_DEVICE ( localIndex const ei )
43  {
44  deltaPres[ei] = pres[ei] - initPres[ei];
45  } );
46  }
47 
48  static void
49  launch( SortedArrayView< localIndex const > const & targetSet,
50  arrayView1d< integer const > const & elemGhostRank,
51  arrayView1d< real64 const > const & volume,
52  arrayView1d< real64 const > const & pres,
53  arrayView1d< real64 const > const & deltaPres,
54  arrayView1d< real64 const > const & temp,
55  arrayView1d< real64 const > const & refPorosity,
56  arrayView2d< real64 const > const & porosity,
58  globalIndex & elemCount,
59  real64 & minPres,
60  real64 & avgPresNumerator,
61  real64 & maxPres,
62  real64 & minDeltaPres,
63  real64 & maxDeltaPres,
64  real64 & minTemp,
65  real64 & avgTempNumerator,
66  real64 & maxTemp,
67  real64 & totalUncompactedPoreVol,
68  real64 & totalPoreVol,
69  real64 & totalMass )
70  {
71  RAJA::ReduceSum< parallelDeviceReduce, localIndex > subRegionElemCount( 0 );
72 
73  RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinPres( LvArray::NumericLimits< real64 >::max );
74  RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgPresNumerator( 0.0 );
75  RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPres( -LvArray::NumericLimits< real64 >::max );
76 
77  RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinDeltaPres( LvArray::NumericLimits< real64 >::max );
78  RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxDeltaPres( -LvArray::NumericLimits< real64 >::max );
79 
80  RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinTemp( LvArray::NumericLimits< real64 >::max );
81  RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgTempNumerator( 0.0 );
82  RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTemp( -LvArray::NumericLimits< real64 >::max );
83 
84  RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalUncompactedPoreVol( 0.0 );
85  RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalPoreVol( 0.0 );
86  RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalMass( 0.0 );
87 
88  forAll< parallelDevicePolicy<> >( targetSet.size(),
89  [=] GEOS_HOST_DEVICE ( localIndex const setElemId )
90  {
91  localIndex ei = targetSet[setElemId];
92 
93  if( elemGhostRank[ei] >= 0 )
94  return;
95 
96  // To match our "reference", we have to use reference porosity here, not the actual porosity when we compute averages
97  real64 const uncompactedPoreVol = volume[ei] * refPorosity[ei];
98  real64 const dynamicPoreVol = volume[ei] * porosity[ei][0];
99 
100  subRegionElemCount += 1;
101 
102  subRegionMinPres.min( pres[ei] );
103  subRegionAvgPresNumerator += uncompactedPoreVol * pres[ei];
104  subRegionMaxPres.max( pres[ei] );
105 
106  subRegionMinDeltaPres.min( deltaPres[ei] );
107  subRegionMaxDeltaPres.max( deltaPres[ei] );
108 
109  subRegionMinTemp.min( temp[ei] );
110  subRegionAvgTempNumerator += uncompactedPoreVol * temp[ei];
111  subRegionMaxTemp.max( temp[ei] );
112 
113  subRegionTotalUncompactedPoreVol += uncompactedPoreVol;
114  subRegionTotalPoreVol += dynamicPoreVol;
115  subRegionTotalMass += dynamicPoreVol * density[ei][0];
116  } );
117 
118  elemCount = globalIndex( subRegionElemCount.get() );
119 
120  minPres = subRegionMinPres.get();
121  avgPresNumerator = subRegionAvgPresNumerator.get();
122  maxPres = subRegionMaxPres.get();
123 
124  minDeltaPres = subRegionMinDeltaPres.get();
125  maxDeltaPres = subRegionMaxDeltaPres.get();
126 
127  minTemp = subRegionMinTemp.get();
128  avgTempNumerator = subRegionAvgTempNumerator.get();
129  maxTemp = subRegionMaxTemp.get();
130 
131  totalUncompactedPoreVol = subRegionTotalUncompactedPoreVol.get();
132  totalPoreVol = subRegionTotalPoreVol.get();
133  totalMass = subRegionTotalMass.get();
134  }
135 };
136 
137 } // namespace singlePhaseBaseKernels
138 
139 } // namespace geos
140 
141 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_STATISTICSKERNEL_HPP
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:87
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
LvArray::SortedArrayView< T, localIndex, LvArray::ChaiBuffer > SortedArrayView
A sorted array view of local indices.
Definition: DataTypes.hpp:270
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:195