20 #ifndef GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_THERMALSINGLEPHASEPOROMECHANICS_IMPL_HPP_
21 #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_POROMECHANICSKERNELS_THERMALSINGLEPHASEPOROMECHANICS_IMPL_HPP_
23 #include "constitutive/fluid/singlefluid/SingleFluidBase.hpp"
29 namespace thermalPoromechanicsKernels
32 template<
typename SUBREGION_TYPE,
33 typename CONSTITUTIVE_TYPE,
40 SUBREGION_TYPE
const & elementSubRegion,
41 FE_TYPE
const & finiteElementSpace,
42 CONSTITUTIVE_TYPE & inputConstitutiveType,
48 real64 const (&gravityVector)[3],
49 string const inputFlowDofKey,
50 integer const performStressInitialization,
51 string const fluidModelKey ):
58 inputConstitutiveType,
66 performStressInitialization,
68 m_fluidInternalEnergy_n( elementSubRegion.template getConstitutiveModel< constitutive::SingleFluidBase >( elementSubRegion.template getReference<
string >( fluidModelKey ) ).internalEnergy_n() ),
69 m_fluidInternalEnergy( elementSubRegion.template getConstitutiveModel< constitutive::SingleFluidBase >( elementSubRegion.template getReference<
string >( fluidModelKey ) ).internalEnergy() ),
70 m_dFluidInternalEnergy( elementSubRegion.template getConstitutiveModel< constitutive::SingleFluidBase >( elementSubRegion.template getReference<
string >(
71 fluidModelKey ) ).dInternalEnergy() ),
72 m_rockInternalEnergy_n( inputConstitutiveType.getInternalEnergy_n() ),
73 m_rockInternalEnergy( inputConstitutiveType.getInternalEnergy() ),
74 m_dRockInternalEnergy_dTemperature( inputConstitutiveType.getDinternalEnergy_dTemperature() ),
75 m_referenceTemperature( elementSubRegion.template getField< fields::flow::initialTemperature >() ),
76 m_temperature_n( elementSubRegion.template getField< fields::flow::temperature_n >() ),
77 m_temperature( elementSubRegion.template getField< fields::flow::temperature >() )
80 template<
typename SUBREGION_TYPE,
81 typename CONSTITUTIVE_TYPE,
89 Base::setup( k, stack );
91 stack.temperature = m_temperature[k];
92 stack.deltaTemperatureFromLastStep = m_temperature[k] - m_temperature_n[k];
93 stack.deltaTemperature = m_temperature[k] - m_referenceTemperature[k];
96 template<
typename SUBREGION_TYPE,
97 typename CONSTITUTIVE_TYPE,
108 real64 dPorosity_dVolStrain = 0.0;
109 real64 dPorosity_dPressure = 0.0;
110 real64 dPorosity_dTemperature = 0.0;
111 real64 dSolidDensity_dPressure = 0.0;
114 m_constitutiveUpdate.smallStrainUpdatePoromechanics( k, q,
118 stack.deltaTemperature,
119 stack.deltaTemperatureFromLastStep,
120 stack.strainIncrement,
122 stack.dTotalStress_dPressure,
123 stack.dTotalStress_dTemperature,
125 m_performStressInitialization,
128 dPorosity_dVolStrain,
130 dPorosity_dTemperature,
131 dSolidDensity_dPressure );
134 computeBodyForce( k, q,
136 dPorosity_dVolStrain,
138 dPorosity_dTemperature,
139 dSolidDensity_dPressure,
143 computeFluidIncrement( k, q,
146 dPorosity_dVolStrain,
148 dPorosity_dTemperature,
152 template<
typename SUBREGION_TYPE,
153 typename CONSTITUTIVE_TYPE,
161 real64 const & dPorosity_dVolStrain,
162 real64 const & dPorosity_dPressure,
163 real64 const & dPorosity_dTemperature,
164 real64 const & dSolidDensity_dPressure,
167 Base::computeBodyForce( k, q,
169 dPorosity_dVolStrain,
171 dPorosity_dTemperature,
172 dSolidDensity_dPressure,
175 real64 const dMixtureDens_dTemperature =
176 dPorosity_dTemperature * ( -m_solidDensity( k, q ) + m_fluidDensity( k, q ) )
177 + porosity * m_dFluidDensity( k, q, DerivOffset::dT );
179 LvArray::tensorOps::scaledCopy< 3 >( stack.
dBodyForce_dTemperature, m_gravityVector, dMixtureDens_dTemperature );
182 template<
typename SUBREGION_TYPE,
183 typename CONSTITUTIVE_TYPE,
191 real64 const & porosity_n,
192 real64 const & dPorosity_dVolStrain,
193 real64 const & dPorosity_dPressure,
194 real64 const & dPorosity_dTemperature,
198 Base::computeFluidIncrement( k, q,
201 dPorosity_dVolStrain,
203 dPorosity_dTemperature,
211 real64 const fluidMass = porosity * m_fluidDensity( k, q );
212 real64 const fluidEnergy = fluidMass * m_fluidInternalEnergy( k, q );
213 real64 const fluidEnergy_n = porosity_n * m_fluidDensity_n( k, q ) * m_fluidInternalEnergy_n( k, q );
218 + fluidMass * m_dFluidInternalEnergy( k, q, DerivOffset::dP );
220 + fluidMass * m_dFluidInternalEnergy( k, q, DerivOffset::dT );
224 real64 const oneMinusPoro = 1 - porosity;
226 stack.
energyIncrement += oneMinusPoro * m_rockInternalEnergy( k, 0 ) - ( 1 - porosity_n ) * m_rockInternalEnergy_n( k, 0 );
229 stack.
dEnergyIncrement_dTemperature += -dPorosity_dTemperature * m_rockInternalEnergy( k, 0 ) + oneMinusPoro * m_dRockInternalEnergy_dTemperature( k, 0 );
232 template<
typename SUBREGION_TYPE,
233 typename CONSTITUTIVE_TYPE,
239 real64 const ( &dNdX )[numNodesPerElem][3],
243 using namespace PDEUtilities;
245 Base::assembleMomentumBalanceTerms( N, dNdX, detJxW, stack );
247 constexpr FunctionSpace displacementTrialSpace = FE_TYPE::template getFunctionSpace< numDofPerTrialSupportPoint >();
248 constexpr FunctionSpace displacementTestSpace = displacementTrialSpace;
249 constexpr FunctionSpace pressureTrialSpace = FunctionSpace::P0;
253 BilinearFormUtilities::compute< displacementTestSpace,
255 DifferentialOperator::SymmetricGradient,
256 DifferentialOperator::Identity >
260 stack.dTotalStress_dTemperature,
264 BilinearFormUtilities::compute< displacementTestSpace,
266 DifferentialOperator::Identity,
267 DifferentialOperator::Identity >
276 template<
typename SUBREGION_TYPE,
277 typename CONSTITUTIVE_TYPE,
287 using namespace PDEUtilities;
289 Base::assembleElementBasedFlowTerms( dNdX, detJxW, stack );
291 constexpr FunctionSpace displacementTrialSpace = FE_TYPE::template getFunctionSpace< numDofPerTrialSupportPoint >();
292 constexpr FunctionSpace pressureTrialSpace = FunctionSpace::P0;
293 constexpr FunctionSpace pressureTestSpace = pressureTrialSpace;
297 BilinearFormUtilities::compute< pressureTestSpace,
299 DifferentialOperator::Identity,
300 DifferentialOperator::Identity >
310 LinearFormUtilities::compute< pressureTestSpace,
311 DifferentialOperator::Identity >
318 BilinearFormUtilities::compute< pressureTestSpace,
319 displacementTrialSpace,
320 DifferentialOperator::Identity,
321 DifferentialOperator::Divergence >
329 BilinearFormUtilities::compute< pressureTestSpace,
331 DifferentialOperator::Identity,
332 DifferentialOperator::Identity >
340 BilinearFormUtilities::compute< pressureTestSpace,
342 DifferentialOperator::Identity,
343 DifferentialOperator::Identity >
352 template<
typename SUBREGION_TYPE,
353 typename CONSTITUTIVE_TYPE,
364 real64 N[numNodesPerElem]{};
365 real64 dNdX[numNodesPerElem][3]{};
366 FE_TYPE::calcN( q, stack.feStack, N );
367 real64 const detJxW = m_finiteElementSpace.template getGradN< FE_TYPE >( k, q, stack.xLocal,
368 stack.feStack, dNdX );
371 LvArray::tensorOps::fill< 6 >( stack.strainIncrement, 0.0 );
372 FE_TYPE::symmetricGradient( dNdX, stack.uhat_local, stack.strainIncrement );
377 smallStrainUpdate( k, q, stack );
381 assembleMomentumBalanceTerms( N, dNdX, detJxW, stack );
385 assembleElementBasedFlowTerms( dNdX, detJxW, stack );
388 template<
typename SUBREGION_TYPE,
389 typename CONSTITUTIVE_TYPE,
397 real64 const maxForce = Base::complete( k, stack );
400 m_finiteElementSpace.template numSupportPoints< FE_TYPE >( stack.feStack );
401 integer numDisplacementDofs = numSupportPoints * numDofPerTestSupportPoint;
405 for(
int localNode = 0; localNode < numSupportPoints; ++localNode )
407 for(
integer dim = 0; dim < numDofPerTestSupportPoint; ++dim )
409 localIndex const dof = LvArray::integerConversion< localIndex >( stack.localRowDofIndex[numDofPerTestSupportPoint*localNode + dim] - m_dofRankOffset );
412 if( dof < 0 || dof >= m_matrix.numRows() )
417 m_matrix.template addToRowBinarySearchUnsorted< parallelDeviceAtomic >( dof,
426 localIndex const massDof = LvArray::integerConversion< localIndex >( stack.localPressureDofIndex - m_dofRankOffset );
429 if( 0 <= massDof && massDof < m_matrix.numRows() )
431 m_matrix.template addToRow< serialAtomic >( massDof,
442 if( 0 <= energyDof && energyDof < m_matrix.numRows() )
444 m_matrix.template addToRowBinarySearchUnsorted< serialAtomic >( energyDof,
445 stack.localRowDofIndex,
447 numDisplacementDofs );
448 m_matrix.template addToRow< serialAtomic >( energyDof,
449 &stack.localPressureDofIndex,
452 m_matrix.template addToRow< serialAtomic >( energyDof,
463 template<
typename SUBREGION_TYPE,
464 typename CONSTITUTIVE_TYPE,
466 template<
typename POLICY,
467 typename KERNEL_TYPE >
470 KERNEL_TYPE
const & kernelComponent )
475 RAJA::ReduceMax< ReducePolicy< POLICY >,
real64 > maxResidual( 0 );
477 forAll< POLICY >( numElems,
480 typename KERNEL_TYPE::StackVariables stack;
482 kernelComponent.setup( k, stack );
483 for(
integer q=0; q<KERNEL_TYPE::numQuadraturePointsPerElem; ++q )
485 kernelComponent.quadraturePointKernel( k, q, stack );
487 maxResidual.max( kernelComponent.complete( k, stack ) );
489 return maxResidual.get();
#define GEOS_HOST_DEVICE
Marks a host-device function.
#define GEOS_FORCE_INLINE
Marks a function or lambda for inlining.
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
This class provides an interface to ObjectManagerBase in order to manage edge data.
The FaceManager class provides an interface to ObjectManagerBase in order to manage face data.
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data.
Implements kernels for solving quasi-static thermal single-phase poromechanics.
GEOS_HOST_DEVICE void assembleElementBasedFlowTerms(real64 const (&dNdX)[numNodesPerElem][3], real64 const &detJxW, StackVariables &stack) const
Assemble the local mass/energy balance residual and derivatives using fluid mass/energy increment.
static real64 kernelLaunch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Kernel Launcher.
GEOS_HOST_DEVICE void computeFluidIncrement(localIndex const k, localIndex const q, real64 const &porosity, real64 const &porosity_n, real64 const &dPorosity_dVolStrain, real64 const &dPorosity_dPressure, real64 const &dPorosity_dTemperature, StackVariables &stack) const
Helper function to compute the fluid mass/energy increment and its derivatives wrt primary variables.
GEOS_HOST_DEVICE void setup(localIndex const k, StackVariables &stack) const
Copy global values from primary field to a local stack array.
GEOS_HOST_DEVICE void computeBodyForce(localIndex const k, localIndex const q, real64 const &porosity, real64 const &dPorosity_dVolStrain, real64 const &dPorosity_dPressure, real64 const &dPorosity_dTemperature, real64 const &dSolidDensity_dPressure, StackVariables &stack) const
Helper function to compute the body force term (\rho g) and its derivatives wrt primary variables.
GEOS_HOST_DEVICE real64 complete(localIndex const k, StackVariables &stack) const
Performs the complete phase for the kernel.
GEOS_HOST_DEVICE void assembleMomentumBalanceTerms(real64 const (&N)[numNodesPerElem], real64 const (&dNdX)[numNodesPerElem][3], real64 const &detJxW, StackVariables &stack) const
Assemble the local linear momentum balance residual and derivatives using total stress and body force...
ThermalSinglePhasePoromechanics(NodeManager const &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, localIndex const targetRegionIndex, SUBREGION_TYPE const &elementSubRegion, FE_TYPE const &finiteElementSpace, CONSTITUTIVE_TYPE &inputConstitutiveType, arrayView1d< globalIndex const > const inputDispDofNumber, globalIndex const rankOffset, CRSMatrixView< real64, globalIndex const > const inputMatrix, arrayView1d< real64 > const inputRhs, real64 const inputDt, real64 const (&gravityVector)[3], string const inputFlowDofKey, integer const performStressInitialization, string const fluidModelKey)
Constructor.
GEOS_HOST_DEVICE void smallStrainUpdate(localIndex const k, localIndex const q, StackVariables &stack) const
Helper function to compute 1) the total stress, 2) the body force term, and 3) the fluidMass/EnergyIn...
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
std::string string
String type.
double real64
64-bit floating point type.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
std::int32_t integer
Signed integer type.
Kernel variables (dof numbers, jacobian and residual) located on the stack.
Kernel variables allocated on the stack.
real64 dLocalResidualEnergy_dDisplacement[1][numDispDofPerElem]
Derivative of energy balance residual wrt displacement.
real64 dEnergyIncrement_dPressure
Derivative of energy accumulation wrt pressure.
real64 dFluidMassIncrement_dTemperature
Derivative of mass accumulation wrt temperature.
globalIndex localTemperatureDofIndex
C-array storage for the element local row degrees of freedom.
real64 dEnergyIncrement_dVolStrainIncrement
Derivative of energy accumulation wrt volumetric strain increment.
real64 energyIncrement
Energy accumulation.
real64 dEnergyIncrement_dTemperature
Derivative of energy accumulation wrt temperature.
real64 localResidualEnergy[1]
Energy balance residual.
real64 dLocalResidualMass_dTemperature[1][1]
Derivative of mass balance residual wrt pressure.
real64 dLocalResidualEnergy_dPressure[1][1]
Derivative of energy balance residual wrt pressure.
real64 dLocalResidualMomentum_dTemperature[numDispDofPerElem][1]
Derivative of linear momentum balance residual wrt temperature.
real64 dBodyForce_dTemperature[3]
Derivative of body force wrt temperature.
real64 dLocalResidualEnergy_dTemperature[1][1]
Derivative of energy balance residual wrt temperature.