20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP
23 #include "LvArray/src/math.hpp"
30 namespace isothermalCompositionalMultiphaseBaseKernels
50 using Base::m_compDens;
65 integer const allowNegativePressure,
67 real64 const scalingFactor,
87 pressureScalingFactor,
88 compDensScalingFactor ),
93 m_negPressureIds( negPressureIds ),
94 m_negDensityIds( negDensityIds ),
95 m_negTotalDensityIds( negTotalDensityIds )
106 Base::StackVariables()
112 real64 _localMinNegTotalDens )
114 Base::StackVariables( _localMinVal ),
115 localMinNegPres( _localMinNegPres ),
116 localMinNegDens( _localMinNegDens ),
117 localMinNegTotalDens( _localMinNegTotalDens )
122 real64 localMinNegTotalDens;
148 template<
typename POLICY,
typename KERNEL_TYPE >
151 KERNEL_TYPE
const & kernelComponent )
153 using reducePolicy = ReducePolicy< POLICY >;
154 using atomicPolicy = AtomicPolicy< POLICY >;
156 RAJA::ReduceMin< reducePolicy, integer > globalMinVal( 1 );
158 RAJA::ReduceMin< reducePolicy, real64 > minPres( 0.0 );
159 RAJA::ReduceMin< reducePolicy, real64 > minDens( 0.0 );
160 RAJA::ReduceMin< reducePolicy, real64 > minTotalDens( 0.0 );
164 if( kernelComponent.ghostRank( ei ) >= 0 )
170 kernelComponent.setup( ei, stack );
171 kernelComponent.compute( ei, stack );
173 globalMinVal.min( stack.localMinVal );
175 minPres.min( stack.localMinNegPres );
176 minDens.min( stack.localMinNegDens );
177 minTotalDens.min( stack.localMinNegTotalDens );
179 if( stack.localNumNegPres > 0 )
180 kernelComponent.m_negPressureIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegPres } );
182 if( stack.localNumNegDens > 0 )
183 kernelComponent.m_negDensityIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegDens } );
185 if( stack.localNumNegTotalDens > 0 )
186 kernelComponent.m_negDensityIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegTotalDens } );
192 minTotalDens.get() );
201 stack.localMinNegPres = 0.0;
202 stack.localMinNegDens = 0.0;
203 stack.localMinNegTotalDens = 0.0;
205 stack.localNumNegPres = 0;
206 stack.localNumNegDens = 0;
207 stack.localNumNegTotalDens = 0;
229 template<
typename FUNC = NoOpFunc >
233 FUNC && kernelOp = NoOpFunc{} )
const
235 bool const localScaling =
m_scalingType == compositionalMultiphaseUtilities::ScalingType::Local;
239 stack.localMinVal = 0;
243 stack.localNumNegPres += 1;
245 if( newPres < stack.localMinNegPres )
246 stack.localMinNegPres = newPres;
258 totalDens += newDens;
261 bool const isNewDensNegative = newDens < 0.0;
262 bool const isNewDensTooLow = newDens <= 0.0;
263 stack.localMinVal = isNewDensNegative ? 0 : stack.localMinVal;
264 stack.localNumNegDens += isNewDensTooLow;
265 stack.localMinNegDens = isNewDensTooLow ?
266 LvArray::math::min( stack.localMinNegDens, newDens ) :
267 stack.localMinNegDens;
275 totalDens += LvArray::math::max( newDens, 0.0 );
279 bool const isNewDensTooLow = newDens <= 0.0;
280 stack.localNumNegDens += isNewDensTooLow;
281 stack.localMinNegDens = isNewDensTooLow ?
282 LvArray::math::min( stack.localMinNegDens, newDens ) :
283 stack.localMinNegDens;
287 bool const isNewTotalDensTooLow = totalDens <= 0.0;
288 stack.localNumNegTotalDens += isNewTotalDensTooLow;
289 stack.localMinNegTotalDens = isNewTotalDensTooLow ?
290 LvArray::math::min( stack.localMinNegTotalDens, totalDens ) :
291 stack.localMinNegTotalDens;
337 template<
typename POLICY >
340 integer const allowNegativePressure,
342 real64 const scalingFactor,
356 SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor,
357 pressure, compDens, pressureScalingFactor, compDensScalingFactor, rankOffset,
358 numComp, dofKey, subRegion, localSolution, negPressureIds, negDensityIds,
359 negTotalDensityIds );
360 return SolutionCheckKernel::launch< POLICY >( subRegion.
size(), kernel );
ScalingType
Solution scaling type, used in CompositionalMultiphaseFVM.
#define GEOS_HOST_DEVICE
Marks a host-device function.
Collects and reports elements ids and data using an atomic counter. This class provides functionality...
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
static SolutionCheckKernel::KernelStats createAndLaunch(integer const allowCompDensChopping, integer const allowNegativePressure, compositionalMultiphaseUtilities::ScalingType const scalingType, real64 const scalingFactor, arrayView1d< real64 const > const pressure, arrayView2d< real64 const, compflow::USD_COMP > const compDens, arrayView1d< real64 > pressureScalingFactor, arrayView1d< real64 > compDensScalingFactor, globalIndex const rankOffset, integer const numComp, string const dofKey, ElementSubRegionBase &subRegion, arrayView1d< real64 const > const localSolution, ElementsReporterCollector const &negPressureIds, ElementsReporterCollector const &negDensityIds, ElementsReporterCollector const &negTotalDensityIds)
Create a new kernel and launch.
Define the kernel for checking the updated solution.
SolutionCheckKernel(integer const allowCompDensChopping, integer const allowNegativePressure, compositionalMultiphaseUtilities::ScalingType const scalingType, real64 const scalingFactor, arrayView1d< real64 const > const pressure, arrayView2d< real64 const, compflow::USD_COMP > const compDens, arrayView1d< real64 > pressureScalingFactor, arrayView1d< real64 > compDensScalingFactor, globalIndex const rankOffset, integer const numComp, string const dofKey, ElementSubRegionBase const &subRegion, arrayView1d< real64 const > const localSolution, ElementsReporterCollector const &negPressureIds, ElementsReporterCollector const &negDensityIds, ElementsReporterCollector const &negTotalDensityIds)
Create a new kernel instance.
static KernelStats launch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Performs the kernel launch.
GEOS_HOST_DEVICE void computeSolutionCheck(localIndex const ei, StackVariables &stack, FUNC &&kernelOp=NoOpFunc{}) const
Compute the local value of the check.
integer const m_allowNegativePressure
flag to allow negative pressure values
real64 const m_scalingFactor
scaling factor
GEOS_HOST_DEVICE void compute(localIndex const ei, StackVariables &stack) const
Compute the local value.
compositionalMultiphaseUtilities::ScalingType const m_scalingType
scaling type (global or local)
integer const m_allowCompDensChopping
flag to allow the component density chopping
Define the kernel for scaling the solution and check its validity.
arrayView1d< integer const > const m_ghostRank
View on the ghost ranks.
globalIndex const m_rankOffset
Offset for my MPI rank.
arrayView1d< real64 const > const m_localSolution
View on the local residual.
arrayView1d< real64 > const m_pressureScalingFactor
View on the scaling factors.
arrayView1d< globalIndex const > const m_dofNumber
View on the dof numbers.
GEOS_HOST_DEVICE void setup(localIndex const ei, StackVariables &stack) const
Performs the setup phase for the kernel.
arrayView1d< real64 const > const m_pressure
View on the primary variables.
real64 const m_numComp
Number of components.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
double real64
64-bit floating point type.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
int integer
Signed integer type.
Kernel variables (dof numbers, jacobian and residual) located on the stack.
Kernel variables located on the stack.
Kernel variables located on the stack.