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_SINGLEPHASEREACTIVE_ACCUMULATIONKERNELS_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEREACTIVE_ACCUMULATIONKERNELS_HPP
22 
23 #include "common/DataLayouts.hpp"
24 #include "common/DataTypes.hpp"
25 #include "constitutive/fluid/reactivefluid/ReactiveSinglePhaseFluid.hpp"
26 #include "constitutive/fluid/reactivefluid/ReactiveFluidLayouts.hpp"
27 #include "constitutive/solid/CoupledSolidBase.hpp"
29 #include "physicsSolvers/fluidFlow/kernels/singlePhase/reactive/KernelLaunchSelectors.hpp"
30 
31 namespace geos
32 {
33 
34 namespace singlePhaseReactiveBaseKernels
35 {
36 
37 /******************************** AccumulationKernel ********************************/
38 
43 template< typename SUBREGION_TYPE, integer NUM_DOF, integer NUM_SPECIES, typename BASE_FLUID_TYPE >
44 class AccumulationKernel : public singlePhaseBaseKernels::AccumulationKernel< SUBREGION_TYPE, NUM_DOF >
45 {
46 
47 public:
48 
50  using Base::numDof;
51  using Base::numEqn;
52  using Base::m_rankOffset;
53  using Base::m_dofNumber;
55  using Base::m_localMatrix;
56  using Base::m_localRhs;
57  using Base::m_dMass;
58 
60  using DerivOffset = constitutive::singlefluid::DerivativeOffsetC< 0 >;
61 
63  static constexpr integer numSpecies = NUM_SPECIES;
64 
75  AccumulationKernel( globalIndex const rankOffset,
76  string const dofKey,
77  SUBREGION_TYPE const & subRegion,
78  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
79  constitutive::CoupledSolidBase const & solid,
80  real64 const & dt,
82  arrayView1d< real64 > const & localRhs )
83  : Base( rankOffset, dofKey, subRegion, localMatrix, localRhs ),
84  m_dt( dt ),
85  m_volume( subRegion.getElementVolume() ),
86  m_deltaVolume( subRegion.template getField< fields::flow::deltaVolume >() ),
87  m_porosity( solid.getPorosity() ),
88  m_dPoro_dPres( solid.getDporosity_dPressure() ),
89  // m_dDensity_dLogPrimaryConc( fluid.dDensity_dLogPrimaryConc() ),
90  // m_dPoro_dLogPrimaryConc( solid.getDporosity_dLogPrimaryConc() ),
91  m_primarySpeciesAggregateConcentration( fluid.primarySpeciesAggregateConcentration() ),
92  // m_dPrimarySpeciesAggregateConcentration_dPres( fluid.dPrimarySpeciesAggregateConcentration_dPres() ),
93  m_dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations( fluid.dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations() ),
94  m_primarySpeciesAggregateKineticRate( fluid.aggregateSpeciesRates() ),
95  // m_dPrimarySpeciesAggregateKineticRate_dPres( fluid.dPrimarySpeciesAggregateKineticRate_dPres() ),
96  m_dPrimarySpeciesAggregateKineticRate_dLogPrimaryConc( fluid.dAggregateSpeciesRates_dLogPrimarySpeciesConcentrations() ),
97  m_primarySpeciesAggregateMole_n( subRegion.template getField< fields::flow::primarySpeciesAggregateMole_n >() )
98  {}
99 
105  {
106 public:
107 
111  {}
112 
117 
118  // Pore volume information
119 
122 
125 
128 
129  };
130 
137  void setup( localIndex const ei,
138  StackVariables & stack ) const
139  {
140  // initialize the pore volume
141  stack.poreVolume = ( m_volume[ei] + m_deltaVolume[ei] ) * m_porosity[ei][0];
142  stack.dPoreVolume_dPres = ( m_volume[ei] + m_deltaVolume[ei] ) * m_dPoro_dPres[ei][0];
143 
144  Base::setup( ei, stack );
145 
146  // // is - index of the primary species
147  // for( integer is = 0; is < numSpecies; ++is )
148  // {
149  // stack.dPoreVolume_dLogPrimaryConc[is] = ( m_volume[ei] + m_deltaVolume[ei] ) * m_dPoro_dLogPrimaryConc[ei][is]
150  // }
151  }
152 
161  StackVariables & stack ) const
162  {
163  // Residual[is] += (primarySpeciesAggregateConcentration[is] * stack.poreVolume - primarySpeciesAggregateMole_n[is])
164  // - dt * m_volume * primarySpeciesKineticRate[is] // To Check: what's the unit of the kinetic rate
165 
166  Base::computeAccumulation( ei, stack );
167 
168  // Step 1: assemble the derivatives of the total mass equation w.r.t log of primary species concentration
169  // for( integer is = 0; is < numSpecies; ++is )
170  // {
171  // stack.localJacobian[0][is+numDof-numSpecies] = stack.poreVolume * m_dDensity_dLogPrimaryConc[ei][is] +
172  // stack.dPoreVolume_dLogPrimaryConc[is] * m_density[ei][0];
173  // }
174 
175  arraySlice2d< real64 const,
176  constitutive::reactivefluid::USD_SPECIES_DC -
177  2 > dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations = m_dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations[ei][0];
178  arraySlice2d< real64 const, constitutive::reactivefluid::USD_SPECIES_DC - 2 > dPrimarySpeciesAggregateKineticRate_dLogPrimaryConc = m_dPrimarySpeciesAggregateKineticRate_dLogPrimaryConc[ei][0];
179 
180  for( integer is = 0; is < numSpecies; ++is )
181  {
182  // Step 2: assemble the accumulation term of the species mass balance equation
183  // Step 2.1: residual
184  // Primary species mole amount in pore volume
185  stack.localResidual[is+numEqn-numSpecies] -= m_primarySpeciesAggregateMole_n[ei][is];
186  stack.localResidual[is+numEqn-numSpecies] += m_primarySpeciesAggregateConcentration[ei][0][is] * stack.poreVolume;
187 
188  // Reaction term
189  stack.localResidual[is+numEqn-numSpecies] -= m_dt * ( m_volume[ei] + m_deltaVolume[ei] ) * m_primarySpeciesAggregateKineticRate[ei][0][is];
190 
191  // Step 2.1: jacobian
192  // Drivative of primary species amount in pore volume wrt pressure
193  stack.localJacobian[is+numEqn-numSpecies][0] += stack.dPoreVolume_dPres * m_primarySpeciesAggregateConcentration[ei][0][is]
194  /* + stack.poreVolume * m_dTotalPrimarySpeciesConcentration_dPres[ei][is] */;
195  // // Derivative of reaction term wrt pressure
196  // stack.localJacobian[is+numEqn-numSpecies][0] -= m_dt * ( m_volume[ei] + m_deltaVolume[ei] ) *
197  // m_dPrimarySpeciesTotalKineticRate_dPres[is];
198 
199  // Derivative wrt log of primary species concentration
200  for( integer js = 0; js < numSpecies; ++js )
201  {
202  stack.localJacobian[is+numEqn-numSpecies][js+numDof-numSpecies] = /* stack.dPoreVolume_dLogPrimaryConc[js] *
203  m_primarySpeciesAggregateConcentration[ei][0][is]
204  + */stack.poreVolume * dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations[is][js]; // To
205  // check
206  // if
207  // the
208  // permutation
209  // is
210  // consistent
211 
212  stack.localJacobian[is+numEqn-numSpecies][js+numDof-numSpecies] -= m_dt * ( m_volume[ei] + m_deltaVolume[ei] ) * dPrimarySpeciesAggregateKineticRate_dLogPrimaryConc[is][js];
213  }
214  }
215  }
216 
223  void complete( localIndex const ei,
224  StackVariables & stack ) const
225  {
226  // Step 1: assemble the total mass balance equation
227  // - the total mass balance equations (i = 0)
228  Base::complete( ei, stack );
229 
230  // Step 2: assemble the primary species mole amount balance equation
231  // - the species mole amount balance equations (i = numEqn-numSpecies to i = numEqn-1)
232  integer const beginRowSpecies = numEqn-numSpecies;
233  for( integer i = 0; i < numSpecies; ++i )
234  {
235  m_localRhs[stack.localRow + beginRowSpecies + i] += stack.localResidual[beginRowSpecies+i];
236  m_localMatrix.template addToRow< serialAtomic >( stack.localRow + beginRowSpecies + i,
237  stack.dofIndices,
238  stack.localJacobian[beginRowSpecies + i],
239  numDof );
240  }
241  }
242 
243 protected:
244 
246  real64 const m_dt;
247 
250  arrayView1d< real64 const > const m_deltaVolume;
251 
254  arrayView2d< real64 const > const m_dPoro_dPres;
255 
256  // // View on the derivatives of fluid density wrt log of primary species concentration
257  // arrayView2d< real64 const, compflow::USD_COMP > m_dDensity_dLogPrimaryConc;
258 
259  // // View on the derivatives of porosity wrt log of primary species concentration
260  // arrayView2d< real64 const, compflow::USD_COMP > m_dPoro_dLogPrimaryConc;
261 
262  // View on the total concentration of ions that contain the primary species
263  arrayView3d< real64 const, constitutive::reactivefluid::USD_SPECIES > m_primarySpeciesAggregateConcentration;
264 
265  // // View on the derivatives of aggregate concentration for the primary species wrt pressure
266  // arrayView2d< real64 const, compflow::USD_COMP > m_dPrimarySpeciesAggregateConcentration_dPres;
267 
268  // View on the derivatives of total ion concentration for the primary species wrt log of primary species concentration
269  arrayView4d< real64 const, constitutive::reactivefluid::USD_SPECIES_DC > m_dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations;
270 
271  // View on the aggregate kinetic rate of primary species from all reactions
273 
274  // // View on the derivatives of aggregate kinetic rate of primary species wrt pressure
275  // arrayView2d< real64 const, compflow::USD_COMP > m_dPrimarySpeciesAggregateKineticRate_dPres;
276 
277  // View on the derivatives of aggregate kinetic rate of primary species wrt log of primary species concentration
278  arrayView4d< real64 const, constitutive::reactivefluid::USD_SPECIES_DC > m_dPrimarySpeciesAggregateKineticRate_dLogPrimaryConc;
279 
280  // View on primary species mole amount from previous time step
281  arrayView2d< real64 const, compflow::USD_COMP > m_primarySpeciesAggregateMole_n;
282 };
283 
288 {
289 public:
290 
304  template< typename POLICY, typename SUBREGION_TYPE, typename BASE_FLUID_TYPE >
305  static void
306  createAndLaunch( integer const numSpecies,
307  real64 const dt,
308  globalIndex const rankOffset,
309  string const dofKey,
310  SUBREGION_TYPE const & subRegion,
311  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
312  constitutive::CoupledSolidBase const & solid,
313  CRSMatrixView< real64, globalIndex const > const & localMatrix,
314  arrayView1d< real64 > const & localRhs )
315  {
316  internal::kernelLaunchSelectorCompSwitch( numSpecies, [&] ( auto NS )
317  {
318  integer constexpr NUM_SPECIES = NS();
319  integer constexpr NUM_DOF = 1+NS();
320  AccumulationKernel< SUBREGION_TYPE, NUM_DOF, NUM_SPECIES, BASE_FLUID_TYPE > kernel( rankOffset, dofKey, subRegion, fluid, solid, dt, localMatrix, localRhs );
322  } );
323  }
324 };
325 
326 } // namespace singlePhaseReactiveBaseKernels
327 
328 } // namespace geos
329 
330 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASEREACTIVE_ACCUMULATIONKERNELS_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.
GEOS_HOST_DEVICE void computeAccumulation(localIndex const ei, StackVariables &stack, FUNC &&kernelOp=NoOpFunc{}) const
Compute the local accumulation contributions to the residual and Jacobian.
arrayView1d< globalIndex const > const m_dofNumber
View on the dof numbers.
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.
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.
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 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.
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.
arrayView2d< real64 const > const m_porosity
Views on the porosity.
static constexpr integer numEqn
Compute time value for the number of equations.
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
ArraySlice< T, 2, USD > arraySlice2d
Alias for 2D array slice.
Definition: DataTypes.hpp:199
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, 4, USD > arrayView4d
Alias for 4D array view.
Definition: DataTypes.hpp:227
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.
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_dLogPrimaryConc[numSpecies]
Derivative of pore volume with respect to each primary species concentration.
real64 dPoreVolume_dPres
Derivative of pore volume with respect to pressure.