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_solventMassFraction( fluid.solventMassFraction() ),
86  m_density( fluid.density() ),
87  m_dDensity( fluid.dDensity() ),
88  m_volume( subRegion.getElementVolume() ),
89  m_deltaVolume( subRegion.template getField< fields::flow::deltaVolume >() ),
90  m_porosity( solid.getPorosity() ),
91  m_dPoro_dPres( solid.getDporosity_dPressure() ),
92  // m_dDensity_dLogPrimaryConc( fluid.dDensity_dLogPrimaryConc() ),
93  // m_dPoro_dLogPrimaryConc( solid.getDporosity_dLogPrimaryConc() ),
94  m_primarySpeciesAggregateConcentration( fluid.primarySpeciesAggregateConcentration() ),
95  // m_dPrimarySpeciesAggregateConcentration_dPres( fluid.dPrimarySpeciesAggregateConcentration_dPres() ),
96  m_dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations( fluid.dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations() ),
97  m_primarySpeciesAggregateKineticRate( fluid.aggregateSpeciesRates() ),
98  // m_dPrimarySpeciesAggregateKineticRate_dPres( fluid.dPrimarySpeciesAggregateKineticRate_dPres() ),
99  m_dPrimarySpeciesAggregateKineticRate_dLogPrimaryConc( fluid.dAggregateSpeciesRates_dLogPrimarySpeciesConcentrations() ),
100  m_primarySpeciesAggregateMole_n( subRegion.template getField< fields::flow::primarySpeciesAggregateMole_n >() )
101  {}
102 
108  {
109 public:
110 
114  {}
115 
120 
121  // Pore volume information
122 
125 
128 
131 
132  };
133 
140  void setup( localIndex const ei,
141  StackVariables & stack ) const
142  {
143  // initialize the pore volume
144  stack.poreVolume = ( m_volume[ei] + m_deltaVolume[ei] ) * m_porosity[ei][0];
145  stack.dPoreVolume_dPres = ( m_volume[ei] + m_deltaVolume[ei] ) * m_dPoro_dPres[ei][0];
146 
147  Base::setup( ei, stack );
148 
149  // // is - index of the primary species
150  // for( integer is = 0; is < numSpecies; ++is )
151  // {
152  // stack.dPoreVolume_dLogPrimaryConc[is] = ( m_volume[ei] + m_deltaVolume[ei] ) * m_dPoro_dLogPrimaryConc[ei][is]
153  // }
154  }
155 
164  StackVariables & stack ) const
165  {
166  // Residual[is] += (primarySpeciesAggregateConcentration[is] * solventMassFraction * density * stack.poreVolume -
167  // primarySpeciesAggregateMole_n[is])
168  // - dt * m_volume * primarySpeciesKineticRate[is]
169 
170  Base::computeAccumulation( ei, stack );
171 
172  // Step 1: assemble the derivatives of the total mass equation w.r.t log of primary species concentration
173  // for( integer is = 0; is < numSpecies; ++is )
174  // {
175  // stack.localJacobian[0][is+numDof-numSpecies] = stack.poreVolume * m_dDensity_dLogPrimaryConc[ei][is] +
176  // stack.dPoreVolume_dLogPrimaryConc[is] * m_density[ei][0];
177  // }
178 
179  arraySlice2d< real64 const,
180  constitutive::reactivefluid::USD_SPECIES_DC -
181  2 > dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations = m_dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations[ei][0];
182  arraySlice2d< real64 const, constitutive::reactivefluid::USD_SPECIES_DC - 2 > dPrimarySpeciesAggregateKineticRate_dLogPrimaryConc = m_dPrimarySpeciesAggregateKineticRate_dLogPrimaryConc[ei][0];
183 
184  for( integer is = 0; is < numSpecies; ++is )
185  {
186  // Step 2: assemble the accumulation term of the species mass balance equation
187  // Step 2.1: residual
188  // Primary species mole amount in pore volume
189  stack.localResidual[is+numEqn-numSpecies] -= m_primarySpeciesAggregateMole_n[ei][is];
190  // moles of species per m^3 of solution: molality * solvent mass fraction * density
191  real64 const aggregateConcMolarity = m_primarySpeciesAggregateConcentration[ei][0][is] * m_solventMassFraction * m_density[ei][0];
192  stack.localResidual[is+numEqn-numSpecies] += aggregateConcMolarity * stack.poreVolume;
193 
194  // Reaction term
195  stack.localResidual[is+numEqn-numSpecies] -= m_dt * ( m_volume[ei] + m_deltaVolume[ei] ) * m_primarySpeciesAggregateKineticRate[ei][0][is];
196 
197  // Step 2.1: jacobian
198  // Derivative of primary species amount in pore volume wrt pressure
199  stack.localJacobian[is+numEqn-numSpecies][0] += stack.dPoreVolume_dPres * aggregateConcMolarity
200  + stack.poreVolume * m_primarySpeciesAggregateConcentration[ei][0][is] * m_solventMassFraction * m_dDensity[ei][0][DerivOffset::dP]
201  /* + stack.poreVolume * m_dTotalPrimarySpeciesConcentration_dPres[ei][is] */;
202  // // Derivative of reaction term wrt pressure
203  // stack.localJacobian[is+numEqn-numSpecies][0] -= m_dt * ( m_volume[ei] + m_deltaVolume[ei] ) *
204  // m_dPrimarySpeciesTotalKineticRate_dPres[is];
205 
206  // Derivative wrt log of primary species concentration
207  for( integer js = 0; js < numSpecies; ++js )
208  {
209  stack.localJacobian[is+numEqn-numSpecies][js+numDof-numSpecies] = /* stack.dPoreVolume_dLogPrimaryConc[js] *
210  m_primarySpeciesAggregateConcentration[ei][0][is]
211  + */stack.poreVolume * dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations[is][js] *
213 
214  stack.localJacobian[is+numEqn-numSpecies][js+numDof-numSpecies] -= m_dt * ( m_volume[ei] + m_deltaVolume[ei] ) * dPrimarySpeciesAggregateKineticRate_dLogPrimaryConc[is][js];
215  }
216  }
217  }
218 
225  void complete( localIndex const ei,
226  StackVariables & stack ) const
227  {
228  // Step 1: assemble the total mass balance equation
229  // - the total mass balance equations (i = 0)
230  Base::complete( ei, stack );
231 
232  // Step 2: assemble the primary species mole amount balance equation
233  // - the species mole amount balance equations (i = numEqn-numSpecies to i = numEqn-1)
234  integer const beginRowSpecies = numEqn-numSpecies;
235  for( integer i = 0; i < numSpecies; ++i )
236  {
237  m_localRhs[stack.localRow + beginRowSpecies + i] += stack.localResidual[beginRowSpecies+i];
238  m_localMatrix.template addToRow< serialAtomic >( stack.localRow + beginRowSpecies + i,
239  stack.dofIndices,
240  stack.localJacobian[beginRowSpecies + i],
241  numDof );
242  }
243  }
244 
245 protected:
246 
248  real64 const m_dt;
249 
252 
256 
259  arrayView1d< real64 const > const m_deltaVolume;
260 
263  arrayView2d< real64 const > const m_dPoro_dPres;
264 
265  // // View on the derivatives of fluid density wrt log of primary species concentration
266  // arrayView2d< real64 const, compflow::USD_COMP > m_dDensity_dLogPrimaryConc;
267 
268  // // View on the derivatives of porosity wrt log of primary species concentration
269  // arrayView2d< real64 const, compflow::USD_COMP > m_dPoro_dLogPrimaryConc;
270 
271  // View on the total concentration of ions that contain the primary species
272  arrayView3d< real64 const, constitutive::reactivefluid::USD_SPECIES > m_primarySpeciesAggregateConcentration;
273 
274  // // View on the derivatives of aggregate concentration for the primary species wrt pressure
275  // arrayView2d< real64 const, compflow::USD_COMP > m_dPrimarySpeciesAggregateConcentration_dPres;
276 
277  // View on the derivatives of total ion concentration for the primary species wrt log of primary species concentration
278  arrayView4d< real64 const, constitutive::reactivefluid::USD_SPECIES_DC > m_dPrimarySpeciesAggregateConcentration_dLogPrimarySpeciesConcentrations;
279 
280  // View on the aggregate kinetic rate of primary species from all reactions
282 
283  // // View on the derivatives of aggregate kinetic rate of primary species wrt pressure
284  // arrayView2d< real64 const, compflow::USD_COMP > m_dPrimarySpeciesAggregateKineticRate_dPres;
285 
286  // View on the derivatives of aggregate kinetic rate of primary species wrt log of primary species concentration
287  arrayView4d< real64 const, constitutive::reactivefluid::USD_SPECIES_DC > m_dPrimarySpeciesAggregateKineticRate_dLogPrimaryConc;
288 
289  // View on primary species mole amount from previous time step
290  arrayView2d< real64 const, compflow::USD_COMP > m_primarySpeciesAggregateMole_n;
291 };
292 
297 {
298 public:
299 
313  template< typename POLICY, typename SUBREGION_TYPE, typename BASE_FLUID_TYPE >
314  static void
315  createAndLaunch( integer const numSpecies,
316  real64 const dt,
317  globalIndex const rankOffset,
318  string const dofKey,
319  SUBREGION_TYPE const & subRegion,
320  constitutive::reactivefluid::ReactiveSinglePhaseFluid< BASE_FLUID_TYPE > const & fluid,
321  constitutive::CoupledSolidBase const & solid,
322  CRSMatrixView< real64, globalIndex const > const & localMatrix,
323  arrayView1d< real64 > const & localRhs )
324  {
325  internal::kernelLaunchSelectorCompSwitch( numSpecies, [&] ( auto NS )
326  {
327  integer constexpr NUM_SPECIES = NS();
328  integer constexpr NUM_DOF = 1+NS();
329  AccumulationKernel< SUBREGION_TYPE, NUM_DOF, NUM_SPECIES, BASE_FLUID_TYPE > kernel( rankOffset, dofKey, subRegion, fluid, solid, dt, localMatrix, localRhs );
331  } );
332  }
333 };
334 
335 } // namespace singlePhaseReactiveBaseKernels
336 
337 } // namespace geos
338 
339 #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.
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...
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.