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 Total, S.A
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( localIndex const size,
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,
57  arrayView2d< real64 const > const & density,
58  real64 & minPres,
59  real64 & avgPresNumerator,
60  real64 & maxPres,
61  real64 & minDeltaPres,
62  real64 & maxDeltaPres,
63  real64 & minTemp,
64  real64 & avgTempNumerator,
65  real64 & maxTemp,
66  real64 & totalUncompactedPoreVol,
67  real64 & totalPoreVol,
68  real64 & totalMass )
69  {
70  RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinPres( LvArray::NumericLimits< real64 >::max );
71  RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgPresNumerator( 0.0 );
72  RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPres( -LvArray::NumericLimits< real64 >::max );
73 
74  RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinDeltaPres( LvArray::NumericLimits< real64 >::max );
75  RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxDeltaPres( -LvArray::NumericLimits< real64 >::max );
76 
77  RAJA::ReduceMin< parallelDeviceReduce, real64 > subRegionMinTemp( LvArray::NumericLimits< real64 >::max );
78  RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionAvgTempNumerator( 0.0 );
79  RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTemp( -LvArray::NumericLimits< real64 >::max );
80 
81  RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalUncompactedPoreVol( 0.0 );
82  RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalPoreVol( 0.0 );
83  RAJA::ReduceSum< parallelDeviceReduce, real64 > subRegionTotalMass( 0.0 );
84 
85  forAll< parallelDevicePolicy<> >( size, [=] GEOS_HOST_DEVICE ( localIndex const ei )
86  {
87  if( elemGhostRank[ei] >= 0 )
88  {
89  return;
90  }
91 
92  // To match our "reference", we have to use reference porosity here, not the actual porosity when we compute averages
93  real64 const uncompactedPoreVol = volume[ei] * refPorosity[ei];
94  real64 const dynamicPoreVol = volume[ei] * porosity[ei][0];
95 
96  subRegionMinPres.min( pres[ei] );
97  subRegionAvgPresNumerator += uncompactedPoreVol * pres[ei];
98  subRegionMaxPres.max( pres[ei] );
99 
100  subRegionMinDeltaPres.min( deltaPres[ei] );
101  subRegionMaxDeltaPres.max( deltaPres[ei] );
102 
103  subRegionMinTemp.min( temp[ei] );
104  subRegionAvgTempNumerator += uncompactedPoreVol * temp[ei];
105  subRegionMaxTemp.max( temp[ei] );
106 
107  subRegionTotalUncompactedPoreVol += uncompactedPoreVol;
108  subRegionTotalPoreVol += dynamicPoreVol;
109  subRegionTotalMass += dynamicPoreVol * density[ei][0];
110  } );
111 
112  minPres = subRegionMinPres.get();
113  avgPresNumerator = subRegionAvgPresNumerator.get();
114  maxPres = subRegionMaxPres.get();
115 
116  minDeltaPres = subRegionMinDeltaPres.get();
117  maxDeltaPres = subRegionMaxDeltaPres.get();
118 
119  minTemp = subRegionMinTemp.get();
120  avgTempNumerator = subRegionAvgTempNumerator.get();
121  maxTemp = subRegionMaxTemp.get();
122 
123  totalUncompactedPoreVol = subRegionTotalUncompactedPoreVol.get();
124  totalPoreVol = subRegionTotalPoreVol.get();
125  totalMass = subRegionTotalMass.get();
126  }
127 };
128 
129 } // namespace singlePhaseBaseKernels
130 
131 } // namespace geos
132 
133 #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:180
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:196