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;
57  using Base::m_density;
58  using Base::m_dDensity;
59 
61  using DerivOffset = constitutive::singlefluid::DerivativeOffsetC< 1 >;
72  AccumulationKernel( globalIndex const rankOffset,
73  string const dofKey,
74  SUBREGION_TYPE const & subRegion,
75  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
76  constitutive::CoupledSolidBase const & solid,
77  real64 const & dt,
79  arrayView1d< real64 > const & localRhs )
80  : Base( rankOffset, dofKey, subRegion, fluid, solid, dt, localMatrix, localRhs ),
81  m_energy( subRegion.template getField< fields::flow::energy >() ),
82  m_energy_n( subRegion.template getField< fields::flow::energy_n >() ),
83  m_dEnergy( subRegion.template getField< fields::flow::dEnergy >() ),
84  m_dPoro_dTemp( solid.getDporosity_dTemperature() )
85  // m_dPrimarySpeciesAggregateConcentration_dTemp( fluid.dPrimarySpeciesAggregateConcentration_dTemp() ),
86  // m_dPrimarySpeciesTotalKineticRate_dTemp( fluid.dPrimarySpeciesTotalKineticRate_dTemp() ),
87  {}
88 
94  {
95 public:
96 
100  {}
101 
106  using Base::StackVariables::poreVolume;
107  using Base::StackVariables::dPoreVolume_dLogPrimaryConc;
108 
109  // Pore volume information
110 
113  };
114 
121  void setup( localIndex const ei,
122  StackVariables & stack ) const
123  {
124  Base::setup( ei, stack );
125 
126  stack.dPoreVolume_dTemp = ( m_volume[ei] + m_deltaVolume[ei] ) * m_dPoro_dTemp[ei][0];
127  }
128 
137  StackVariables & stack ) const
138  {
139  Base::computeAccumulation( ei, stack );
140 
141  // Step 1: assemble the derivatives of the mass balance equation w.r.t temperature
142  stack.localJacobian[0][numDof-numSpecies-1] = m_dMass[ei][DerivOffset::dT];
143 
144  // Step 2: assemble the accumulation term of the energy equation
145  // Step 2.1: assemble the residual and derivatives wrt pressure and temperature
146  stack.localResidual[numEqn-numSpecies-1] = m_energy[ei] - m_energy_n[ei];
147  stack.localJacobian[numEqn-numSpecies-1][0] += m_dEnergy[ei][DerivOffset::dP];
148  stack.localJacobian[numEqn-numSpecies-1][numDof-numSpecies-1] += m_dEnergy[ei][DerivOffset::dT];
149 
150  // Step 2.2: assemble the derivatives of the energy equation w.r.t log primary species concentration
151  // for( integer is = 0; is < numSpecies; ++is )
152  // {
153  // stack.localJacobian[numEqn-numSpecies-1][is+numDof-numSpecies] += stack.dPoreVolume_dLogPrimaryConc[is] * m_density[ei][0] *
154  // m_fluidInternalEnergy[ei][0]
155  // - stack.dPoreVolume_dLogPrimaryConc[is] *
156  // m_rockInternalEnergy[ei][0]
157  // + stack.poreVolume * m_dDensity_dLogPrimaryConc[ei][is] *
158  // m_fluidInternalEnergy[ei][0]
159  // + stack.poreVolume * m_density[ei][0] *
160  // m_dFluidInternalEnergy_dLogPrimaryConc[ei][is];
161  // }
162 
163  // Step 3: assemble the derivatives of the species amount balance equation w.r.t temperature
164  for( integer is = 0; is < numSpecies; ++is )
165  {
166  // Derivative of primary species amount in pore volume wrt temperature
167  real64 const aggregateConcMolality = m_primarySpeciesAggregateConcentration[ei][0][is] * m_solventMassFraction;
169  + stack.poreVolume * m_dDensity[ei][0][DerivOffset::dT] ) * aggregateConcMolality
170  /* + stack.poreVolume * m_density[ei][0] * m_solventMassFraction *
171  m_dPrimarySpeciesAggregateConcentration_dTemp[ei][is] */;
172  // // Derivative of reaction term wrt temperature
173  // stack.localJacobian[is+numEqn-numSpecies][numDof-numSpecies-1] -= m_dt * ( m_volume[ei] + m_deltaVolume[ei] ) *
174  // m_dPrimarySpeciesTotalKineticRate_dTemp[is];
175  }
176  }
177 
184  void complete( localIndex const ei,
185  StackVariables & stack ) const
186  {
187  // Step 1: assemble the total mass balance equation (i = 0)
188  // and species amount balance equation (i = numEqn-numSpecies to i = numEqn-1)
189  Base::complete( ei, stack );
190 
191  // Step 2: assemble the energy equation (i = numEqn-numSpecies-1)
193  m_localMatrix.template addToRow< serialAtomic >( stack.localRow + numEqn-numSpecies-1,
194  stack.dofIndices,
196  numDof );
197  }
198 
199 protected:
200 
203  arrayView1d< real64 const > const m_energy_n;
205 
208 
209  // // View on the derivatives of aggregate concentration for the primary species wrt temperature
210  // arrayView2d< real64 const, compflow::USD_COMP > m_dPrimarySpeciesAggregateConcentration_dTemp;
211 
212  // // View on the derivatives of total kinetic rate of primary species wrt temperature
213  // arrayView2d< real64 const, compflow::USD_COMP > m_dPrimarySpeciesTotalKineticRate_dTemp;
214 
215 };
216 
221 {
222 public:
223 
237  template< typename POLICY, typename SUBREGION_TYPE, typename BASE_FLUID_TYPE >
238  static void
239  createAndLaunch( integer const numSpecies,
240  real64 const dt,
241  globalIndex const rankOffset,
242  string const dofKey,
243  SUBREGION_TYPE const & subRegion,
244  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
245  constitutive::CoupledSolidBase const & solid,
246  CRSMatrixView< real64, globalIndex const > const & localMatrix,
247  arrayView1d< real64 > const & localRhs )
248  {
249  singlePhaseReactiveBaseKernels::
250  internal::kernelLaunchSelectorCompSwitch( numSpecies, [&] ( auto NS )
251  {
252  integer constexpr NUM_SPECIES = NS();
253  integer constexpr NUM_DOF = 2+NS();
254  AccumulationKernel< SUBREGION_TYPE, NUM_DOF, NUM_SPECIES, BASE_FLUID_TYPE > kernel( rankOffset, dofKey, subRegion, fluid, solid, dt, localMatrix, localRhs );
256  } );
257  }
258 };
259 
260 } // namespace thermalSinglePhaseReactiveBaseKernels
261 
262 } // namespace geos
263 
264 #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.
arrayView2d< real64 const, constitutive::singlefluid::USD_FLUID > const m_density
View on the fluid density and its derivatives.
real64 const m_solventMassFraction
Mass fraction of solvent in the solution [-]; molality times this fraction times density is the molar...
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.