GEOS
AccumulationKernels.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_ACCUMULATIONKERNELS_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_ACCUMULATIONKERNELS_HPP
22 
23 #include "common/DataTypes.hpp"
24 #include "common/GEOS_RAJA_Interface.hpp"
25 #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp"
26 #include "constitutive/solid/CoupledSolidBase.hpp"
28 #include "codingUtilities/Utilities.hpp"
29 
30 namespace geos
31 {
32 
33 namespace singlePhaseBaseKernels
34 {
35 
36 /******************************** AccumulationKernel ********************************/
37 
42 template< typename SUBREGION_TYPE, integer NUM_DOF >
44 {
45 
46 public:
47 
49  static constexpr integer numDof = NUM_DOF;
50 
52  static constexpr integer numEqn = NUM_DOF;
53 
64  AccumulationKernel( globalIndex const rankOffset,
65  string const dofKey,
66  SUBREGION_TYPE const & subRegion,
67  constitutive::SingleFluidBase const & fluid,
68  constitutive::CoupledSolidBase const & solid,
70  arrayView1d< real64 > const & localRhs )
71  :
72  m_rankOffset( rankOffset ),
73  m_dofNumber( subRegion.template getReference< array1d< globalIndex > >( dofKey ) ),
74  m_elemGhostRank( subRegion.ghostRank() ),
75  m_volume( subRegion.getElementVolume() ),
76  m_deltaVolume( subRegion.template getField< fields::flow::deltaVolume >() ),
77  m_porosity( solid.getPorosity() ),
78  m_dPoro_dPres( solid.getDporosity_dPressure() ),
79  m_density( fluid.density() ),
80  m_dDensity_dPres( fluid.dDensity_dPressure() ),
81  m_mass_n( subRegion.template getField< fields::flow::mass_n >() ),
82  m_localMatrix( localMatrix ),
83  m_localRhs( localRhs )
84  {}
85 
91  {
92 public:
93 
94  // Pore volume information
95 
98 
101 
102  // Residual information
103 
106 
109 
112 
115 
116  };
117 
124  integer elemGhostRank( localIndex const ei ) const
125  { return m_elemGhostRank( ei ); }
126 
127 
134  void setup( localIndex const ei,
135  StackVariables & stack ) const
136  {
137  // initialize the pore volume
138  stack.poreVolume = ( m_volume[ei] + m_deltaVolume[ei] ) * m_porosity[ei][0];
139  stack.dPoreVolume_dPres = ( m_volume[ei] + m_deltaVolume[ei] ) * m_dPoro_dPres[ei][0];
140 
141  // set row index and degrees of freedom indices for this element
142  stack.localRow = m_dofNumber[ei] - m_rankOffset;
143  for( integer idof = 0; idof < numDof; ++idof )
144  {
145  stack.dofIndices[idof] = m_dofNumber[ei] + idof;
146  }
147  }
148 
156  template< typename FUNC = NoOpFunc >
159  StackVariables & stack,
160  FUNC && kernelOp = NoOpFunc{} ) const
161  {
162  // Residual contribution is mass conservation in the cell
163  stack.localResidual[0] = stack.poreVolume * m_density[ei][0] - m_mass_n[ei];
164 
165  // Derivative of residual wrt to pressure in the cell
166  stack.localJacobian[0][0] = stack.dPoreVolume_dPres * m_density[ei][0] + m_dDensity_dPres[ei][0] * stack.poreVolume;
167 
168  // Customize the kernel with this lambda
169  kernelOp();
170  }
171 
179  StackVariables & stack ) const
180  {
181  // add contribution to global residual and jacobian (no need for atomics here)
182  m_localMatrix.template addToRow< serialAtomic >( stack.localRow,
183  stack.dofIndices,
184  stack.localJacobian[0],
185  numDof );
186  m_localRhs[stack.localRow] += stack.localResidual[0];
187 
188  }
189 
197  template< typename POLICY, typename KERNEL_TYPE >
198  static void
199  launch( localIndex const numElems,
200  KERNEL_TYPE const & kernelComponent )
201  {
203 
204  forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei )
205  {
206  if( kernelComponent.elemGhostRank( ei ) >= 0 )
207  {
208  return;
209  }
210 
211  typename KERNEL_TYPE::StackVariables stack;
212 
213  kernelComponent.setup( ei, stack );
214  kernelComponent.computeAccumulation( ei, stack );
215  kernelComponent.complete( ei, stack );
216  } );
217  }
218 
219 protected:
220 
223 
226 
229 
232  arrayView1d< real64 const > const m_deltaVolume;
233 
236  arrayView2d< real64 const > const m_dPoro_dPres;
237 
240  arrayView2d< real64 const > const m_dDensity_dPres;
241 
244 
249 
250 };
251 
256 class SurfaceElementAccumulationKernel : public AccumulationKernel< SurfaceElementSubRegion, 1 >
257 {
258 
259 public:
260 
262 
274  string const dofKey,
275  SurfaceElementSubRegion const & subRegion,
276  constitutive::SingleFluidBase const & fluid,
277  constitutive::CoupledSolidBase const & solid,
278  CRSMatrixView< real64, globalIndex const > const & localMatrix,
279  arrayView1d< real64 > const & localRhs )
280  : Base( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs )
281  , m_creationMass( subRegion.getField< fields::flow::massCreated >() )
282  {}
283 
292  Base::StackVariables & stack ) const
293  {
294  Base::computeAccumulation( ei, stack, [&] ()
295  {
296  if( Base::m_mass_n[ei] > 1.1 * m_creationMass[ei] )
297  {
298  stack.localResidual[0] += m_creationMass[ei] * 0.25;
299  }
300  } );
301  }
302 
303 protected:
304 
305  arrayView1d< real64 const > const m_creationMass;
306 
307 };
308 
313 {
314 public:
315 
327  template< typename POLICY, typename SUBREGION_TYPE >
328  static void
329  createAndLaunch( globalIndex const rankOffset,
330  string const dofKey,
331  SUBREGION_TYPE const & subRegion,
332  constitutive::SingleFluidBase const & fluid,
333  constitutive::CoupledSolidBase const & solid,
334  CRSMatrixView< real64, globalIndex const > const & localMatrix,
335  arrayView1d< real64 > const & localRhs )
336  {
337  if constexpr ( std::is_base_of_v< CellElementSubRegion, SUBREGION_TYPE > )
338  {
339  integer constexpr NUM_DOF = 1;
340  AccumulationKernel< CellElementSubRegion, NUM_DOF > kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs );
341  AccumulationKernel< CellElementSubRegion, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel );
342  }
343  else if constexpr ( std::is_base_of_v< SurfaceElementSubRegion, SUBREGION_TYPE > )
344  {
345  SurfaceElementAccumulationKernel kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs );
346  SurfaceElementAccumulationKernel::launch< POLICY >( subRegion.size(), kernel );
347  }
348  else
349  {
350  GEOS_UNUSED_VAR( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs );
351  GEOS_ERROR( "Unsupported subregion type: " << typeid(SUBREGION_TYPE).name() );
352  }
353  }
354 
355 };
356 
357 } // namespace singlePhaseBaseKernels
358 
359 } // namespace geos
360 
361 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_ACCUMULATIONKERNELS_HPP
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:84
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
Definition: GeosxMacros.hpp:72
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:157
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
static void createAndLaunch(globalIndex const rankOffset, string const dofKey, SUBREGION_TYPE const &subRegion, constitutive::SingleFluidBase const &fluid, constitutive::CoupledSolidBase const &solid, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)
Create a new kernel and launch.
Define the interface for the assembly kernel in charge of accumulation.
arrayView2d< real64 const > const m_density
Views on density.
arrayView2d< real64 const > const m_porosity
Views on the porosity.
static void launch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Performs the kernel launch.
GEOS_HOST_DEVICE void computeAccumulation(localIndex const ei, StackVariables &stack, FUNC &&kernelOp=NoOpFunc{}) const
Compute the local accumulation contributions to the residual and Jacobian.
AccumulationKernel(globalIndex const rankOffset, string const dofKey, SUBREGION_TYPE const &subRegion, constitutive::SingleFluidBase const &fluid, constitutive::CoupledSolidBase const &solid, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)
Constructor.
arrayView1d< globalIndex const > const m_dofNumber
View on the dof numbers.
arrayView1d< real64 const > const m_mass_n
View on mass.
static constexpr integer numDof
Compute time value for the number of degrees of freedom.
GEOS_HOST_DEVICE void complete(localIndex const GEOS_UNUSED_PARAM(ei), StackVariables &stack) const
Performs the complete phase for the kernel.
arrayView1d< real64 > const m_localRhs
View on the local RHS.
arrayView1d< real64 const > const m_volume
View on the element volumes.
GEOS_HOST_DEVICE integer elemGhostRank(localIndex const ei) const
Getter for the ghost rank of an element.
CRSMatrixView< real64, globalIndex const > const m_localMatrix
View on the local CRS matrix.
GEOS_HOST_DEVICE void setup(localIndex const ei, StackVariables &stack) const
Performs the setup phase for the kernel.
arrayView1d< integer const > const m_elemGhostRank
View on the ghost ranks.
static constexpr integer numEqn
Compute time value for the number of equations.
globalIndex const m_rankOffset
Offset for my MPI rank.
Define the interface for the assembly kernel in charge of accumulation in SurfaceElementSubRegion.
SurfaceElementAccumulationKernel(globalIndex const rankOffset, string const dofKey, SurfaceElementSubRegion const &subRegion, constitutive::SingleFluidBase const &fluid, constitutive::CoupledSolidBase const &solid, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)
Constructor.
GEOS_HOST_DEVICE void computeAccumulation(localIndex const ei, Base::StackVariables &stack) const
Compute the local accumulation contributions to the residual and Jacobian.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:310
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:88
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
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:196
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:176
Kernel variables (dof numbers, jacobian and residual) located on the stack.
real64 localJacobian[numEqn][numDof]
Storage for the element local Jacobian matrix.
localIndex localRow
Index of the local row corresponding to this element.
globalIndex dofIndices[numDof]
Index of the matrix row/column corresponding to the dof in this element.
real64 localResidual[numEqn]
Storage for the element local residual vector.
real64 dPoreVolume_dPres
Derivative of pore volume with respect to pressure.