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 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_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/fluid/singlefluid/SingleFluidUtils.hpp"
27 #include "constitutive/solid/CoupledSolidBase.hpp"
29 #include "codingUtilities/Utilities.hpp"
30 
31 namespace geos
32 {
33 
34 namespace singlePhaseBaseKernels
35 {
36 
37 /******************************** AccumulationKernel ********************************/
38 
43 template< typename SUBREGION_TYPE, integer NUM_DOF >
45 {
46 
47 public:
48  using SingleFluidProp = constitutive::SingleFluidVar< real64, 2, constitutive::singlefluid::LAYOUT_FLUID, constitutive::singlefluid::LAYOUT_FLUID_DER >;
49 
51  static constexpr integer numDof = NUM_DOF;
52 
54  static constexpr integer numEqn = NUM_DOF;
55 
56 
58  static constexpr integer isThermal = NUM_DOF-1;
59  using DerivOffset = constitutive::singlefluid::DerivativeOffsetC< isThermal >;
60 
71  AccumulationKernel( globalIndex const rankOffset,
72  string const dofKey,
73  SUBREGION_TYPE const & subRegion,
74  constitutive::SingleFluidBase const & fluid,
75  constitutive::CoupledSolidBase const & solid,
77  arrayView1d< real64 > const & localRhs )
78  :
79  m_rankOffset( rankOffset ),
80  m_dofNumber( subRegion.template getReference< array1d< globalIndex > >( dofKey ) ),
81  m_elemGhostRank( subRegion.ghostRank() ),
82  m_volume( subRegion.getElementVolume() ),
83  m_deltaVolume( subRegion.template getField< fields::flow::deltaVolume >() ),
84  m_porosity( solid.getPorosity() ),
85  m_dPoro_dPres( solid.getDporosity_dPressure() ),
86  m_density( fluid.density() ),
87  m_dDensity ( fluid.dDensity() ),
88  m_mass_n( subRegion.template getField< fields::flow::mass_n >() ),
89  m_localMatrix( localMatrix ),
90  m_localRhs( localRhs )
91  {}
92 
98  {
99 public:
100 
101  // Pore volume information
102 
105 
108 
109  // Residual information
110 
113 
116 
119 
122 
123  };
124 
131  integer elemGhostRank( localIndex const ei ) const
132  { return m_elemGhostRank( ei ); }
133 
134 
141  void setup( localIndex const ei,
142  StackVariables & stack ) const
143  {
144  // initialize the pore volume
145  stack.poreVolume = ( m_volume[ei] + m_deltaVolume[ei] ) * m_porosity[ei][0];
146  stack.dPoreVolume_dPres = ( m_volume[ei] + m_deltaVolume[ei] ) * m_dPoro_dPres[ei][0];
147 
148  // set row index and degrees of freedom indices for this element
149  stack.localRow = m_dofNumber[ei] - m_rankOffset;
150  for( integer idof = 0; idof < numDof; ++idof )
151  {
152  stack.dofIndices[idof] = m_dofNumber[ei] + idof;
153  }
154  }
155 
163  template< typename FUNC = NoOpFunc >
166  StackVariables & stack,
167  FUNC && kernelOp = NoOpFunc{} ) const
168  {
169  // Residual contribution is mass conservation in the cell
170  stack.localResidual[0] = stack.poreVolume * m_density[ei][0] - m_mass_n[ei];
171  stack.localJacobian[0][0] = stack.dPoreVolume_dPres * m_density[ei][0] + m_dDensity[ei][0][DerivOffset::dP] * stack.poreVolume;
172  // Customize the kernel with this lambda
173  kernelOp();
174  }
175 
183  StackVariables & stack ) const
184  {
185  // add contribution to global residual and jacobian (no need for atomics here)
186  m_localMatrix.template addToRow< serialAtomic >( stack.localRow,
187  stack.dofIndices,
188  stack.localJacobian[0],
189  numDof );
190  m_localRhs[stack.localRow] += stack.localResidual[0];
191 
192  }
193 
201  template< typename POLICY, typename KERNEL_TYPE >
202  static void
203  launch( localIndex const numElems,
204  KERNEL_TYPE const & kernelComponent )
205  {
207 
208  forAll< POLICY >( numElems, [=] GEOS_HOST_DEVICE ( localIndex const ei )
209  {
210  if( kernelComponent.elemGhostRank( ei ) >= 0 )
211  {
212  return;
213  }
214 
215  typename KERNEL_TYPE::StackVariables stack;
216 
217  kernelComponent.setup( ei, stack );
218  kernelComponent.computeAccumulation( ei, stack );
219  kernelComponent.complete( ei, stack );
220  } );
221  }
222 
223 protected:
224 
227 
230 
233 
236  arrayView1d< real64 const > const m_deltaVolume;
237 
240  arrayView2d< real64 const > const m_dPoro_dPres;
241 
245 
248 
253 
254 };
255 
260 class SurfaceElementAccumulationKernel : public AccumulationKernel< SurfaceElementSubRegion, 1 >
261 {
262 
263 public:
264 
266 
278  string const dofKey,
279  SurfaceElementSubRegion const & subRegion,
280  constitutive::SingleFluidBase const & fluid,
281  constitutive::CoupledSolidBase const & solid,
282  CRSMatrixView< real64, globalIndex const > const & localMatrix,
283  arrayView1d< real64 > const & localRhs )
284  : Base( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs )
285  , m_creationMass( subRegion.getField< fields::flow::massCreated >() )
286  {}
287 
296  Base::StackVariables & stack ) const
297  {
298  Base::computeAccumulation( ei, stack, [&] ()
299  {
300  if( Base::m_mass_n[ei] > 1.1 * m_creationMass[ei] )
301  {
302  stack.localResidual[0] += m_creationMass[ei] * 0.25;
303  }
304  } );
305  }
306 
307 protected:
308 
309  arrayView1d< real64 const > const m_creationMass;
310 
311 };
312 
317 {
318 public:
319 
331  template< typename POLICY, typename SUBREGION_TYPE >
332  static void
333  createAndLaunch( globalIndex const rankOffset,
334  string const dofKey,
335  SUBREGION_TYPE const & subRegion,
336  constitutive::SingleFluidBase const & fluid,
337  constitutive::CoupledSolidBase const & solid,
338  CRSMatrixView< real64, globalIndex const > const & localMatrix,
339  arrayView1d< real64 > const & localRhs )
340  {
341  if constexpr ( std::is_base_of_v< CellElementSubRegion, SUBREGION_TYPE > )
342  {
343  integer constexpr NUM_DOF = 1;
344  AccumulationKernel< CellElementSubRegion, NUM_DOF > kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs );
345  AccumulationKernel< CellElementSubRegion, NUM_DOF >::template launch< POLICY >( subRegion.size(), kernel );
346  }
347  else if constexpr ( std::is_base_of_v< SurfaceElementSubRegion, SUBREGION_TYPE > )
348  {
349  SurfaceElementAccumulationKernel kernel( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs );
350  SurfaceElementAccumulationKernel::launch< POLICY >( subRegion.size(), kernel );
351  }
352  else
353  {
354  GEOS_UNUSED_VAR( rankOffset, dofKey, subRegion, fluid, solid, localMatrix, localRhs );
355  GEOS_ERROR( "Unsupported subregion type: " << typeid(SUBREGION_TYPE).name() );
356  }
357  }
358 
359 };
360 
361 } // namespace singlePhaseBaseKernels
362 
363 } // namespace geos
364 
365 #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_porosity
Views on the porosity.
static constexpr integer isThermal
Note: Derivative lineup only supports dP & dT, not component terms.
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.
arrayView2d< real64 const, constitutive::singlefluid::USD_FLUID > const m_density
Views on density.
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
ArrayView< T, 3, USD > arrayView3d
Alias for 3D array view.
Definition: DataTypes.hpp:212
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.