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_primarySpeciesAggregateConcentration;
49  using Base::m_density;
50  using Base::m_dDensity;
51  using Base::m_localMatrix;
52  using Base::m_localRhs;
53 
54  using DerivOffset = constitutive::singlefluid::DerivativeOffsetC< 1 >;
55 
56  SourceFluxComputeKernel( globalIndex const rankOffset,
57  arrayView1d< globalIndex const > const dofNumber,
59  arrayView1d< real64 const > const rhsContributionArrayView,
60  real64 const sizeScalingFactor,
61  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
63  arrayView1d< real64 > const & localRhs,
64  RAJA::ReduceSum< parallelDeviceReduce, real64 > massProd )
65  :
66  Base( rankOffset,
67  dofNumber,
69  rhsContributionArrayView,
70  sizeScalingFactor,
71  fluid,
72  localMatrix,
73  localRhs,
74  massProd ),
75  m_enthalpy( fluid.enthalpy() ),
76  m_dEnthalpy( fluid.dEnthalpy() )
77  {}
78 
84  {
85 public:
86 
90  {}
91 
95  using Base::StackVariables::totalInflowMass;
96 
99 
102 
103  };
104 
113  StackVariables & stack ) const
114  {
115  Base::computeSourceFlux( ei, stack );
116 
117  real64 const scaledInflowMass = stack.totalInflowMass / m_sizeScalingFactor;
118 
119  stack.localEnergyRhs += m_enthalpy[ei][0] * scaledInflowMass;
120  stack.localEnergyJacobian[0] = scaledInflowMass * m_dEnthalpy[ei][0][DerivOffset::dP];
121  stack.localEnergyJacobian[numDof-numSpecies-1] = scaledInflowMass * m_dEnthalpy[ei][0][DerivOffset::dT];
122 
123  for( integer i = 0; i < numSpecies; ++i )
124  {
125  stack.localSpeciesJacobian[i][numDof-numSpecies-1] += -m_primarySpeciesAggregateConcentration[ei][0][i] * m_dDensity[ei][0][DerivOffset::dT] / (m_density[ei][0] * m_density[ei][0]) *
126  scaledInflowMass;
127  }
128  }
129 
136  void complete( localIndex const ei,
137  StackVariables & stack ) const
138  {
139  Base::complete( ei, stack );
140 
141  if( stack.totalInflowMass > 0.0 )
142  {
143  globalIndex const energyRowIndex = stack.massRowIndex + 1;
144  m_localRhs[energyRowIndex] += stack.localEnergyRhs;
145 
146  m_localMatrix.template addToRow< serialAtomic >( energyRowIndex,
147  stack.dofIndices,
148  stack.localEnergyJacobian,
149  numDof );
150  }
151  }
152 
153 protected:
154 
158 
159 };
160 
165 {
166 public:
167 
183  template< typename POLICY, typename BASE_FLUID_TYPE >
184  static void
185  createAndLaunch( integer const numSpecies,
186  globalIndex const rankOffset,
187  arrayView1d< globalIndex const > const dofNumber,
188  arrayView1d< integer const > const elemGhostRank,
189  SortedArrayView< localIndex const > const targetSet,
190  arrayView1d< real64 const > const rhsContributionArrayView,
191  real64 const sizeScalingFactor,
192  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
193  CRSMatrixView< real64, globalIndex const > const & localMatrix,
194  arrayView1d< real64 > const & localRhs,
195  RAJA::ReduceSum< parallelDeviceReduce, real64 > massProd )
196  {
197  singlePhaseReactiveBaseKernels::
198  internal::kernelLaunchSelectorCompSwitch( numSpecies, [&] ( auto NS )
199  {
200  integer constexpr NUM_SPECIES = NS();
201  integer constexpr NUM_DOF = 2+NS();
202 
203  SourceFluxComputeKernel< NUM_DOF, NUM_SPECIES, BASE_FLUID_TYPE > kernel( rankOffset, dofNumber, elemGhostRank, rhsContributionArrayView, sizeScalingFactor, fluid, localMatrix, localRhs,
204  massProd );
206  } );
207  }
208 };
209 } // namespace thermalSinglePhaseReactiveBaseKernels
210 
211 } // namespace geos
212 
213 #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.