GEOS
ThermalAccumulationKernels.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_THERMALACCUMULATIONKERNELS_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEREACTIVE_THERMALACCUMULATIONKERNELS_HPP
22 
24 
25 namespace geos
26 {
27 
28 namespace thermalSinglePhaseReactiveBaseKernels
29 {
30 
31 /******************************** AccumulationKernel ********************************/
32 
37 template< typename SUBREGION_TYPE, integer NUM_DOF, integer NUM_SPECIES, typename BASE_FLUID_TYPE >
38 class AccumulationKernel : public singlePhaseReactiveBaseKernels::AccumulationKernel< SUBREGION_TYPE, NUM_DOF, NUM_SPECIES, BASE_FLUID_TYPE >
39 {
40 
41 public:
42 
44  using Base::numDof;
45  using Base::numEqn;
46  using Base::numSpecies;
47  using Base::m_rankOffset;
48  using Base::m_dofNumber;
50  using Base::m_localMatrix;
51  using Base::m_localRhs;
52  using Base::m_dMass;
53  using Base::m_volume;
54  using Base::m_deltaVolume;
55  using Base::m_primarySpeciesAggregateConcentration;
56 
58  using DerivOffset = constitutive::singlefluid::DerivativeOffsetC< 1 >;
69  AccumulationKernel( globalIndex const rankOffset,
70  string const dofKey,
71  SUBREGION_TYPE const & subRegion,
72  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
73  constitutive::CoupledSolidBase const & solid,
74  real64 const & dt,
76  arrayView1d< real64 > const & localRhs )
77  : Base( rankOffset, dofKey, subRegion, fluid, solid, dt, localMatrix, localRhs ),
78  m_energy( subRegion.template getField< fields::flow::energy >() ),
79  m_energy_n( subRegion.template getField< fields::flow::energy_n >() ),
80  m_dEnergy( subRegion.template getField< fields::flow::dEnergy >() ),
81  m_dPoro_dTemp( solid.getDporosity_dTemperature() )
82  // m_dPrimarySpeciesAggregateConcentration_dTemp( fluid.dPrimarySpeciesAggregateConcentration_dTemp() ),
83  // m_dPrimarySpeciesTotalKineticRate_dTemp( fluid.dPrimarySpeciesTotalKineticRate_dTemp() ),
84  {}
85 
91  {
92 public:
93 
97  {}
98 
103  using Base::StackVariables::poreVolume;
104  using Base::StackVariables::dPoreVolume_dLogPrimaryConc;
105 
106  // Pore volume information
107 
110  };
111 
118  void setup( localIndex const ei,
119  StackVariables & stack ) const
120  {
121  Base::setup( ei, stack );
122 
123  stack.dPoreVolume_dTemp = ( m_volume[ei] + m_deltaVolume[ei] ) * m_dPoro_dTemp[ei][0];
124  }
125 
134  StackVariables & stack ) const
135  {
136  Base::computeAccumulation( ei, stack );
137 
138  // Step 1: assemble the derivatives of the mass balance equation w.r.t temperature
139  stack.localJacobian[0][numDof-numSpecies-1] = m_dMass[ei][DerivOffset::dT];
140 
141  // Step 2: assemble the accumulation term of the energy equation
142  // Step 2.1: assemble the residual and derivatives wrt pressure and temperature
143  stack.localResidual[numEqn-numSpecies-1] = m_energy[ei] - m_energy_n[ei];
144  stack.localJacobian[numEqn-numSpecies-1][0] += m_dEnergy[ei][DerivOffset::dP];
145  stack.localJacobian[numEqn-numSpecies-1][numDof-numSpecies-1] += m_dEnergy[ei][DerivOffset::dT];
146 
147  // Step 2.2: assemble the derivatives of the energy equation w.r.t log primary species concentration
148  // for( integer is = 0; is < numSpecies; ++is )
149  // {
150  // stack.localJacobian[numEqn-numSpecies-1][is+numDof-numSpecies] += stack.dPoreVolume_dLogPrimaryConc[is] * m_density[ei][0] *
151  // m_fluidInternalEnergy[ei][0]
152  // - stack.dPoreVolume_dLogPrimaryConc[is] *
153  // m_rockInternalEnergy[ei][0]
154  // + stack.poreVolume * m_dDensity_dLogPrimaryConc[ei][is] *
155  // m_fluidInternalEnergy[ei][0]
156  // + stack.poreVolume * m_density[ei][0] *
157  // m_dFluidInternalEnergy_dLogPrimaryConc[ei][is];
158  // }
159 
160  // Step 3: assemble the derivatives of the species amount balance equation w.r.t temperature
161  for( integer is = 0; is < numSpecies; ++is )
162  {
163  // Drivative of primary species amount in pore volume wrt temperature
164  stack.localJacobian[is+numEqn-numSpecies][numDof-numSpecies-1] += stack.dPoreVolume_dTemp * m_primarySpeciesAggregateConcentration[ei][0][is]
165  /* + stack.poreVolume *
166  m_dPrimarySpeciesAggregateConcentration_dTemp[ei][is] */;
167  // // Derivative of reaction term wrt temperature
168  // stack.localJacobian[is+numEqn-numSpecies][numDof-numSpecies-1] -= m_dt * ( m_volume[ei] + m_deltaVolume[ei] ) *
169  // m_dPrimarySpeciesTotalKineticRate_dTemp[is];
170  }
171  }
172 
179  void complete( localIndex const ei,
180  StackVariables & stack ) const
181  {
182  // Step 1: assemble the total mass balance equation (i = 0)
183  // and species amount balance equation (i = numEqn-numSpecies to i = numEqn-1)
184  Base::complete( ei, stack );
185 
186  // Step 2: assemble the energy equation (i = numEqn-numSpecies-1)
188  m_localMatrix.template addToRow< serialAtomic >( stack.localRow + numEqn-numSpecies-1,
189  stack.dofIndices,
191  numDof );
192  }
193 
194 protected:
195 
198  arrayView1d< real64 const > const m_energy_n;
200 
203 
204  // // View on the derivatives of aggregate concentration for the primary species wrt temperature
205  // arrayView2d< real64 const, compflow::USD_COMP > m_dPrimarySpeciesAggregateConcentration_dTemp;
206 
207  // // View on the derivatives of total kinetic rate of primary species wrt temperature
208  // arrayView2d< real64 const, compflow::USD_COMP > m_dPrimarySpeciesTotalKineticRate_dTemp;
209 
210 };
211 
216 {
217 public:
218 
232  template< typename POLICY, typename SUBREGION_TYPE, typename BASE_FLUID_TYPE >
233  static void
234  createAndLaunch( integer const numSpecies,
235  real64 const dt,
236  globalIndex const rankOffset,
237  string const dofKey,
238  SUBREGION_TYPE const & subRegion,
239  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
240  constitutive::CoupledSolidBase const & solid,
241  CRSMatrixView< real64, globalIndex const > const & localMatrix,
242  arrayView1d< real64 > const & localRhs )
243  {
244  singlePhaseReactiveBaseKernels::
245  internal::kernelLaunchSelectorCompSwitch( numSpecies, [&] ( auto NS )
246  {
247  integer constexpr NUM_SPECIES = NS();
248  integer constexpr NUM_DOF = 2+NS();
249  AccumulationKernel< SUBREGION_TYPE, NUM_DOF, NUM_SPECIES, BASE_FLUID_TYPE > kernel( rankOffset, dofKey, subRegion, fluid, solid, dt, localMatrix, localRhs );
251  } );
252  }
253 };
254 
255 } // namespace thermalSinglePhaseReactiveBaseKernels
256 
257 } // namespace geos
258 
259 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEREACTIVE_THERMALACCUMULATIONKERNELS_HPP
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
Define the interface for the assembly kernel in charge of accumulation.
constitutive::singlefluid::DerivativeOffsetC< 0 > DerivOffset
Note: Derivative lineup only supports dP & dT, not component terms.
Define the interface for the assembly kernel in charge of accumulation.
arrayView1d< globalIndex const > const m_dofNumber
View on the dof numbers.
GEOS_HOST_DEVICE void computeAccumulation(localIndex const ei, StackVariables &stack) const
Compute the local accumulation contributions to the residual and Jacobian.
static constexpr integer numDof
Compute time value for the number of degrees of freedom.
GEOS_HOST_DEVICE void setup(localIndex const ei, StackVariables &stack) const
Performs the setup phase for the kernel.
arrayView1d< real64 > const m_localRhs
View on the local RHS.
GEOS_HOST_DEVICE void complete(localIndex const ei, StackVariables &stack) const
Performs the complete phase for the kernel.
static constexpr integer numSpecies
Compile time value for the number of primary species.
arrayView1d< real64 const > const m_volume
View on the element volumes.
CRSMatrixView< real64, globalIndex const > const m_localMatrix
View on the local CRS matrix.
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.
static void createAndLaunch(integer const numSpecies, real64 const dt, globalIndex const rankOffset, string const dofKey, SUBREGION_TYPE const &subRegion, constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > 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.
GEOS_HOST_DEVICE void setup(localIndex const ei, StackVariables &stack) const
Performs the setup phase for the kernel.
GEOS_HOST_DEVICE void complete(localIndex const ei, StackVariables &stack) const
Performs the complete phase for the kernel.
arrayView2d< real64 const > const m_dPoro_dTemp
Views on the porosity derivative.
static constexpr integer numDof
Compute time value for the number of degrees of freedom.
AccumulationKernel(globalIndex const rankOffset, string const dofKey, SUBREGION_TYPE const &subRegion, constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const &fluid, constitutive::CoupledSolidBase const &solid, real64 const &dt, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)
Constructor.
arrayView1d< real64 > const m_localRhs
View on the local RHS.
CRSMatrixView< real64, globalIndex const > const m_localMatrix
View on the local CRS matrix.
static constexpr integer numEqn
Compute time value for the number of equations.
GEOS_HOST_DEVICE void computeAccumulation(localIndex const ei, 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: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
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:195
int integer
Signed integer type.
Definition: DataTypes.hpp:81
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.
Kernel variables (dof numbers, jacobian and residual) located on the stack.
real64 dPoreVolume_dTemp
Derivative of pore volume with respect to temperature.