20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONCHECKKERNEL_HPP
23 #include "LvArray/src/math.hpp"
31 namespace isothermalCompositionalMultiphaseBaseKernels
51 using Base::m_compDens;
66 integer const allowNegativePressure,
68 real64 const scalingFactor,
88 pressureScalingFactor,
89 compDensScalingFactor ),
94 m_negPressureIds( negPressureIds ),
95 m_negDensityIds( negDensityIds ),
96 m_negTotalDensityIds( negTotalDensityIds )
107 Base::StackVariables()
113 real64 _localMinNegTotalDens )
115 Base::StackVariables( _localMinVal ),
116 localMinNegPres( _localMinNegPres ),
117 localMinNegDens( _localMinNegDens ),
118 localMinNegTotalDens( _localMinNegTotalDens )
123 real64 localMinNegTotalDens;
149 template<
typename POLICY,
typename KERNEL_TYPE >
152 KERNEL_TYPE
const & kernelComponent )
154 using reducePolicy = ReducePolicy< POLICY >;
155 using atomicPolicy = AtomicPolicy< POLICY >;
157 RAJA::ReduceMin< reducePolicy, integer > globalMinVal( 1 );
159 RAJA::ReduceMin< reducePolicy, real64 > minPres( 0.0 );
160 RAJA::ReduceMin< reducePolicy, real64 > minDens( 0.0 );
161 RAJA::ReduceMin< reducePolicy, real64 > minTotalDens( 0.0 );
165 if( kernelComponent.ghostRank( ei ) >= 0 )
171 kernelComponent.setup( ei, stack );
172 kernelComponent.compute( ei, stack );
174 globalMinVal.min( stack.localMinVal );
176 minPres.min( stack.localMinNegPres );
177 minDens.min( stack.localMinNegDens );
178 minTotalDens.min( stack.localMinNegTotalDens );
180 if( stack.localNumNegPres > 0 )
181 kernelComponent.m_negPressureIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegPres } );
183 if( stack.localNumNegDens > 0 )
184 kernelComponent.m_negDensityIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegDens } );
186 if( stack.localNumNegTotalDens > 0 )
187 kernelComponent.m_negDensityIds.collectElement( atomicPolicy{}, { ei, stack.localMinNegTotalDens } );
193 minTotalDens.get() );
202 stack.localMinNegPres = 0.0;
203 stack.localMinNegDens = 0.0;
204 stack.localMinNegTotalDens = 0.0;
206 stack.localNumNegPres = 0;
207 stack.localNumNegDens = 0;
208 stack.localNumNegTotalDens = 0;
230 template<
typename FUNC = NoOpFunc >
234 FUNC && kernelOp = NoOpFunc{} )
const
236 bool const localScaling =
m_scalingType == flowSolverUtilities::ScalingType::Local;
240 stack.localMinVal = 0;
244 stack.localNumNegPres += 1;
246 if( newPres < stack.localMinNegPres )
247 stack.localMinNegPres = newPres;
259 totalDens += newDens;
262 bool const isNewDensNegative = newDens < 0.0;
263 bool const isNewDensTooLow = newDens <= 0.0;
264 stack.localMinVal = isNewDensNegative ? 0 : stack.localMinVal;
265 stack.localNumNegDens += isNewDensTooLow;
266 stack.localMinNegDens = isNewDensTooLow ?
267 LvArray::math::min( stack.localMinNegDens, newDens ) :
268 stack.localMinNegDens;
276 totalDens += LvArray::math::max( newDens, 0.0 );
280 bool const isNewDensTooLow = newDens <= 0.0;
281 stack.localNumNegDens += isNewDensTooLow;
282 stack.localMinNegDens = isNewDensTooLow ?
283 LvArray::math::min( stack.localMinNegDens, newDens ) :
284 stack.localMinNegDens;
288 bool const isNewTotalDensTooLow = totalDens <= 0.0;
289 stack.localNumNegTotalDens += isNewTotalDensTooLow;
290 stack.localMinNegTotalDens = isNewTotalDensTooLow ?
291 LvArray::math::min( stack.localMinNegTotalDens, totalDens ) :
292 stack.localMinNegTotalDens;
338 template<
typename POLICY >
341 integer const allowNegativePressure,
343 real64 const scalingFactor,
357 SolutionCheckKernel kernel( allowCompDensChopping, allowNegativePressure, scalingType, scalingFactor,
358 pressure, compDens, pressureScalingFactor, compDensScalingFactor, rankOffset,
359 numComp, dofKey, subRegion, localSolution, negPressureIds, negDensityIds,
360 negTotalDensityIds );
361 return SolutionCheckKernel::launch< POLICY >( subRegion.
size(), kernel );
ScalingType
Solution scaling type.
#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, flowSolverUtilities::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.
flowSolverUtilities::ScalingType const m_scalingType
scaling type (global or local)
static KernelStats launch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Performs the kernel launch.
SolutionCheckKernel(integer const allowCompDensChopping, integer const allowNegativePressure, flowSolverUtilities::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.
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.
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.