20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_HYDROSTATICPRESSUREKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_HYDROSTATICPRESSUREKERNEL_HPP
25 #include "common/GEOS_RAJA_Interface.hpp"
26 #include "constitutive/fluid/multifluid/MultiFluidBase.hpp"
32 namespace isothermalCompositionalMultiphaseBaseKernels
41 static real64 constexpr MIN_FOR_PHASE_PRESENCE = 1e-12;
45 FAILED_TO_CONVERGE = 0,
46 DETECTED_MULTIPHASE_FLOW = 1,
50 template<
typename FLUID_WRAPPER >
52 computeHydrostaticPressure(
integer const numComps,
55 integer const maxNumEquilIterations,
56 real64 const & equilTolerance,
57 real64 const (&gravVector)[ 3 ],
58 FLUID_WRAPPER fluidWrapper,
61 real64 const & refElevation,
64 real64 const & newElevation,
76 StackArray<
real64, 4, constitutive::MultiFluidBase::MAX_NUM_PHASES *constitutive::MultiFluidBase::MAX_NUM_COMPONENTS,
77 constitutive::multifluid::LAYOUT_PHASE_COMP > phaseCompFrac( 1, 1, numPhases, numComps );
80 bool isSinglePhaseFlow =
true;
84 real64 const gravCoef = gravVector[2] * ( refElevation - newElevation );
85 real64 const temp = tempTableWrapper.
compute( &newElevation );
86 for(
integer ic = 0; ic < numComps; ++ic )
88 compFrac[0][ic] = compFracTableWrappers[ic].compute( &newElevation );
93 real64 pres0 = refPres - refPhaseMassDens[ipInit] * gravCoef;
98 constitutive::MultiFluidBase::KernelWrapper::computeValues( fluidWrapper,
107 phaseInternalEnergy[0][0],
110 pres1 = refPres - 0.5 * ( refPhaseMassDens[ipInit] + phaseMassDens[0][0][ipInit] ) * gravCoef;
114 bool equilHasConverged =
false;
115 for(
integer eqIter = 0; eqIter < maxNumEquilIterations; ++eqIter )
119 equilHasConverged = ( LvArray::math::abs( pres0 - pres1 ) < equilTolerance );
123 if( equilHasConverged )
128 for(
integer ip = 0; ip < numPhases; ++ip )
130 if( phaseFrac[0][0][ip] > MIN_FOR_PHASE_PRESENCE )
135 if( numberOfPhases > 1 )
137 isSinglePhaseFlow =
false;
144 constitutive::MultiFluidBase::KernelWrapper::computeValues( fluidWrapper,
153 phaseInternalEnergy[0][0],
156 pres1 = refPres - 0.5 * ( refPhaseMassDens[ipInit] + phaseMassDens[0][0][ipInit] ) * gravCoef;
162 for(
integer ip = 0; ip < numPhases; ++ip )
164 newPhaseMassDens[ip] = phaseMassDens[0][0][ip];
167 if( !equilHasConverged )
169 return ReturnType::FAILED_TO_CONVERGE;
171 else if( !isSinglePhaseFlow )
173 return ReturnType::DETECTED_MULTIPHASE_FLOW;
177 return ReturnType::SUCCESS;
181 template<
typename FLUID_WRAPPER >
187 integer const maxNumEquilIterations,
188 real64 const equilTolerance,
189 real64 const (&gravVector)[ 3 ],
190 real64 const & minElevation,
191 real64 const & elevationIncrement,
192 real64 const & datumElevation,
194 FLUID_WRAPPER fluidWrapper,
201 ReturnType returnVal = ReturnType::SUCCESS;
214 real64 datumTotalDens = 0.0;
216 real64 const datumTemp = tempTableWrapper.
compute( &datumElevation );
217 for(
integer ic = 0; ic < numComps; ++ic )
219 datumCompFrac[0][ic] = compFracTableWrappers[ic].compute( &datumElevation );
221 constitutive::MultiFluidBase::KernelWrapper::computeValues( fluidWrapper,
225 datumPhaseFrac[0][0],
226 datumPhaseDens[0][0],
227 datumPhaseMassDens[0][0],
228 datumPhaseVisc[0][0],
229 datumPhaseEnthalpy[0][0],
230 datumPhaseInternalEnergy[0][0],
231 datumPhaseCompFrac[0][0],
236 forAll< parallelHostPolicy >( size, [=] (
localIndex const i )
238 real64 const elevation = minElevation + i * elevationIncrement;
239 elevationValues[0][i] = elevation;
241 integer const iRef = LvArray::sortedArrayManipulation::find( elevationValues[0].begin(),
242 elevationValues[0].size(),
250 for(
integer ip = 0; ip < numPhases; ++ip )
252 datumPhaseMassDensTmp[ip] = datumPhaseMassDens[0][0][ip];
255 ReturnType
const refReturnVal =
256 computeHydrostaticPressure( numComps,
259 maxNumEquilIterations,
263 compFracTableWrappers,
267 datumPhaseMassDensTmp,
268 elevationValues[0][iRef],
269 pressureValues[iRef],
270 phaseMassDens[iRef] );
271 if( refReturnVal == ReturnType::FAILED_TO_CONVERGE )
273 return ReturnType::FAILED_TO_CONVERGE;
275 else if( refReturnVal == ReturnType::DETECTED_MULTIPHASE_FLOW )
277 returnVal = ReturnType::DETECTED_MULTIPHASE_FLOW;
282 localIndex const numEntriesAboveRef = size - iRef - 1;
283 forAll< serialPolicy >( numEntriesAboveRef, [=, &returnVal] (
localIndex const i )
285 ReturnType
const returnValAboveRef =
286 computeHydrostaticPressure( numComps,
289 maxNumEquilIterations,
293 compFracTableWrappers,
295 elevationValues[0][iRef+i],
296 pressureValues[iRef+i],
297 phaseMassDens[iRef+i],
298 elevationValues[0][iRef+i+1],
299 pressureValues[iRef+i+1],
300 phaseMassDens[iRef+i+1] );
301 if( returnValAboveRef == ReturnType::FAILED_TO_CONVERGE )
303 returnVal = ReturnType::FAILED_TO_CONVERGE;
305 else if( ( returnValAboveRef == ReturnType::DETECTED_MULTIPHASE_FLOW ) &&
306 ( returnVal != ReturnType::FAILED_TO_CONVERGE ) )
308 returnVal = ReturnType::DETECTED_MULTIPHASE_FLOW;
316 forAll< serialPolicy >( numEntriesBelowRef, [=, &returnVal] (
localIndex const i )
318 ReturnType
const returnValBelowRef =
319 computeHydrostaticPressure( numComps,
322 maxNumEquilIterations,
326 compFracTableWrappers,
328 elevationValues[0][iRef-i],
329 pressureValues[iRef-i],
330 phaseMassDens[iRef-i],
331 elevationValues[0][iRef-i-1],
332 pressureValues[iRef-i-1],
333 phaseMassDens[iRef-i-1] );
334 if( returnValBelowRef == ReturnType::FAILED_TO_CONVERGE )
336 returnVal = ReturnType::FAILED_TO_CONVERGE;
338 else if( ( returnValBelowRef == ReturnType::DETECTED_MULTIPHASE_FLOW ) &&
339 ( returnVal != ReturnType::FAILED_TO_CONVERGE ) )
341 returnVal = ReturnType::DETECTED_MULTIPHASE_FLOW;
GEOS_HOST_DEVICE real64 compute(IN_ARRAY const &input) const
Interpolate in the table.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Array< T, 2, PERMUTATION > array2d
Alias for 2D array.
Array< T, 3, PERMUTATION > array3d
Alias for 3D array.
LvArray::StackArray< T, NDIM, PERMUTATION, localIndex, MAXSIZE > StackArray
Multidimensional stack-based array type. See LvArray:StackArray for details.
double real64
64-bit floating point type.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
ArraySlice< T, 1, USD > arraySlice1d
Alias for 1D array slice.
std::int32_t integer
Signed integer type.
Array< T, 4, PERMUTATION > array4d
Alias for 4D array.
Array< T, 1 > array1d
Alias for 1D array.