GEOS
ThermalSourceFluxComputeKernel.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_SINGLEPHASEREACTIVE_THERMALSOURCEFLUXCOMPUTEKERNELS_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEREACTIVE_THERMALSOURCEFLUXCOMPUTEKERNELS_HPP
22 
24 
25 namespace geos
26 {
27 
28 namespace thermalSinglePhaseReactiveBaseKernels
29 {
30 
31 /******************************** SourceFluxComputeKernel ********************************/
32 
37 template< integer NUM_DOF, integer NUM_SPECIES, typename BASE_FLUID_TYPE >
38 class SourceFluxComputeKernel : public singlePhaseReactiveBaseKernels::SourceFluxComputeKernel< NUM_DOF, NUM_SPECIES, BASE_FLUID_TYPE >
39 {
40 
41 public:
42 
44  using Base::numSpecies;
45  using Base::numDof;
46  using Base::numEqn;
48  using Base::m_localMatrix;
49  using Base::m_localRhs;
50 
51  using DerivOffset = constitutive::singlefluid::DerivativeOffsetC< 1 >;
52 
53  SourceFluxComputeKernel( globalIndex const rankOffset,
54  arrayView1d< globalIndex const > const dofNumber,
56  arrayView1d< real64 const > const rhsContributionArrayView,
57  real64 const sizeScalingFactor,
58  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
60  arrayView1d< real64 > const & localRhs,
61  RAJA::ReduceSum< parallelDeviceReduce, real64 > massProd )
62  :
63  Base( rankOffset,
64  dofNumber,
66  rhsContributionArrayView,
67  sizeScalingFactor,
68  fluid,
69  localMatrix,
70  localRhs,
71  massProd ),
72  m_enthalpy( fluid.enthalpy() ),
73  m_dEnthalpy( fluid.dEnthalpy() )
74  {}
75 
81  {
82 public:
83 
87  {}
88 
92  using Base::StackVariables::totalInflowMass;
93 
96 
99 
100  };
101 
110  StackVariables & stack ) const
111  {
112  Base::computeSourceFlux( ei, stack );
113 
114  real64 const scaledInflowMass = stack.totalInflowMass / m_sizeScalingFactor;
115 
116  stack.localEnergyRhs += m_enthalpy[ei][0] * scaledInflowMass;
117  stack.localEnergyJacobian[0] = scaledInflowMass * m_dEnthalpy[ei][0][DerivOffset::dP];
118  stack.localEnergyJacobian[numDof-numSpecies-1] = scaledInflowMass * m_dEnthalpy[ei][0][DerivOffset::dT];
119  }
120 
127  void complete( localIndex const ei,
128  StackVariables & stack ) const
129  {
130  Base::complete( ei, stack );
131 
132  if( stack.totalInflowMass > 0.0 )
133  {
134  globalIndex const energyRowIndex = stack.massRowIndex + 1;
135  m_localRhs[energyRowIndex] += stack.localEnergyRhs;
136 
137  m_localMatrix.template addToRow< serialAtomic >( energyRowIndex,
138  stack.dofIndices,
139  stack.localEnergyJacobian,
140  numDof );
141  }
142  }
143 
144 protected:
145 
149 
150 };
151 
156 {
157 public:
158 
174  template< typename POLICY, typename BASE_FLUID_TYPE >
175  static void
176  createAndLaunch( integer const numSpecies,
177  globalIndex const rankOffset,
178  arrayView1d< globalIndex const > const dofNumber,
179  arrayView1d< integer const > const elemGhostRank,
180  SortedArrayView< localIndex const > const targetSet,
181  arrayView1d< real64 const > const rhsContributionArrayView,
182  real64 const sizeScalingFactor,
183  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
184  CRSMatrixView< real64, globalIndex const > const & localMatrix,
185  arrayView1d< real64 > const & localRhs,
186  RAJA::ReduceSum< parallelDeviceReduce, real64 > massProd )
187  {
188  singlePhaseReactiveBaseKernels::
189  internal::kernelLaunchSelectorCompSwitch( numSpecies, [&] ( auto NS )
190  {
191  integer constexpr NUM_SPECIES = NS();
192  integer constexpr NUM_DOF = 2+NS();
193 
194  SourceFluxComputeKernel< NUM_DOF, NUM_SPECIES, BASE_FLUID_TYPE > kernel( rankOffset, dofNumber, elemGhostRank, rhsContributionArrayView, sizeScalingFactor, fluid, localMatrix, localRhs,
195  massProd );
197  } );
198  }
199 };
200 } // namespace thermalSinglePhaseReactiveBaseKernels
201 
202 } // namespace geos
203 
204 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEREACTIVE_THERMALSOURCEFLUXCOMPUTEKERNELS_HPP
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
Define the interface for the assembly kernel in charge of source flux.
CRSMatrixView< real64, globalIndex const > const m_localMatrix
View on the local CRS matrix.
GEOS_HOST_DEVICE void complete(localIndex const GEOS_UNUSED_PARAM(ei), StackVariables &stack) const
Performs the complete phase for the kernel.
GEOS_HOST_DEVICE void computeSourceFlux(localIndex const ei, StackVariables &stack) const
Compute the local source flux contributions to the residual and Jacobian.
GEOS_HOST_DEVICE integer elemGhostRank(localIndex const ei) const
Getter for the ghost rank of an element.
static constexpr integer numSpecies
Compile time value for the number of primary species.
static constexpr integer numEqn
Compute time value for the number of equations.
static constexpr integer numDof
Compute time value for the number of degrees of freedom.
arrayView1d< real64 > const m_localRhs
View on the local RHS.
static void createAndLaunch(integer const numSpecies, globalIndex const rankOffset, arrayView1d< globalIndex const > const dofNumber, arrayView1d< integer const > const elemGhostRank, SortedArrayView< localIndex const > const targetSet, arrayView1d< real64 const > const rhsContributionArrayView, real64 const sizeScalingFactor, constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const &fluid, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs, RAJA::ReduceSum< parallelDeviceReduce, real64 > massProd)
Create a new kernel and launch.
Define the interface for the assembly kernel in charge of source flux.
CRSMatrixView< real64, globalIndex const > const m_localMatrix
View on the local CRS matrix.
arrayView2d< real64 const, constitutive::singlefluid::USD_FLUID > const m_enthalpy
Views on enthalpies.
GEOS_HOST_DEVICE void computeSourceFlux(localIndex const ei, StackVariables &stack) const
Compute the local source flux contributions to the residual and Jacobian.
static constexpr integer numSpecies
Compile time value for the number of primary species.
GEOS_HOST_DEVICE void complete(localIndex const ei, StackVariables &stack) const
Performs the complete phase for the kernel.
static constexpr integer numDof
Compute time value for the number of degrees of freedom.
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::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:309
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
int integer
Signed integer type.
Definition: DataTypes.hpp:81
ArrayView< T, 3, USD > arrayView3d
Alias for 3D array view.
Definition: DataTypes.hpp:211
Kernel variables (dof numbers, jacobian and residual) located on the stack.
globalIndex dofIndices[numDof]
Index of the matrix row/column corresponding to the dof in this element.
real64 localSpeciesJacobian[numSpecies][numDof]
Storage for the element local Jacobian matrix for species rows.
localIndex massRowIndex
Index of the local row corresponding to this element.
Kernel variables (dof numbers, jacobian and residual) located on the stack.
real64 localEnergyJacobian[numDof]
Storage for the element local Jacobian matrix for energy row.
real64 localEnergyRhs
Storage for the element local residual vector for energy row.