20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGKERNEL_HPP
24 #include "physicsSolvers/fluidFlow/kernels/compositional/AccumulationKernel.hpp"
30 namespace isothermalCompositionalMultiphaseBaseKernels
50 using Base::m_compDens;
52 using Base::m_compDensScalingFactor;
71 real64 const maxAbsolutePresChange,
72 real64 const maxCompFracChange,
73 real64 const maxRelativeCompDensChange,
90 pressureScalingFactor,
91 compDensScalingFactor ),
93 m_maxAbsolutePresChange( maxAbsolutePresChange ),
94 m_maxCompFracChange( maxCompFracChange ),
95 m_maxRelativeCompDensChange( maxRelativeCompDensChange )
109 real64 _localMaxDeltaPres,
111 real64 _localMaxDeltaTemp,
113 real64 _localMaxDeltaCompDens,
115 real64 _localMinPresScalingFactor,
116 real64 _localMinTempScalingFactor,
117 real64 _localMinCompDensScalingFactor )
119 Base::StackVariables( _localMinVal ),
120 localMaxDeltaPres( _localMaxDeltaPres ),
121 localMaxDeltaPresLoc( _localMaxDeltaPresLoc ),
122 localMaxDeltaTemp( _localMaxDeltaTemp ),
123 localMaxDeltaTempLoc( _localMaxDeltaTempLoc ),
124 localMaxDeltaCompDens( _localMaxDeltaCompDens ),
125 localMaxDeltaCompDensLoc( _localMaxDeltaCompDensLoc ),
126 localMinPresScalingFactor( _localMinPresScalingFactor ),
127 localMinTempScalingFactor( _localMinTempScalingFactor ),
128 localMinCompDensScalingFactor( _localMinCompDensScalingFactor )
135 real64 localMaxDeltaCompDens;
138 real64 localMinPresScalingFactor;
139 real64 localMinTempScalingFactor;
140 real64 localMinCompDensScalingFactor;
151 template<
typename POLICY,
typename KERNEL_TYPE >
154 KERNEL_TYPE
const & kernelComponent )
156 RAJA::ReduceMin< ReducePolicy< POLICY >,
real64 > globalScalingFactor( 1.0 );
158 RAJA::ReduceMaxLoc< ReducePolicy< POLICY >,
real64 > maxDeltaPres( std::numeric_limits< real64 >::min(), -1 );
159 RAJA::ReduceMaxLoc< ReducePolicy< POLICY >,
real64 > maxDeltaTemp( std::numeric_limits< real64 >::min(), -1 );
160 RAJA::ReduceMaxLoc< ReducePolicy< POLICY >,
real64 > maxDeltaCompDens( std::numeric_limits< real64 >::min(), -1 );
162 RAJA::ReduceMin< ReducePolicy< POLICY >,
real64 > minPresScalingFactor( 1.0 );
163 RAJA::ReduceMin< ReducePolicy< POLICY >,
real64 > minTempScalingFactor( 1.0 );
164 RAJA::ReduceMin< ReducePolicy< POLICY >,
real64 > minCompDensScalingFactor( 1.0 );
168 if( kernelComponent.ghostRank( ei ) >= 0 )
174 kernelComponent.setup( ei, stack );
175 kernelComponent.compute( ei, stack );
177 globalScalingFactor.min( stack.localMinVal );
179 maxDeltaPres.maxloc( stack.localMaxDeltaPres, ei );
180 maxDeltaTemp.maxloc( stack.localMaxDeltaTemp, ei );
181 maxDeltaCompDens.maxloc( stack.localMaxDeltaCompDens, ei );
183 minPresScalingFactor.min( stack.localMinPresScalingFactor );
184 minTempScalingFactor.min( stack.localMinTempScalingFactor );
185 minCompDensScalingFactor.min( stack.localMinCompDensScalingFactor );
190 maxDeltaPres.getLoc(),
192 maxDeltaTemp.getLoc(),
193 maxDeltaCompDens.get(),
194 maxDeltaCompDens.getLoc(),
195 minPresScalingFactor.get(),
196 minTempScalingFactor.get(),
197 minCompDensScalingFactor.get() );
202 StackVariables & stack )
const
206 stack.localMaxDeltaPres = 0.0;
207 stack.localMaxDeltaPresLoc = -1;
208 stack.localMaxDeltaTemp = 0.0;
209 stack.localMaxDeltaTempLoc = -1;
210 stack.localMaxDeltaCompDens = 0.0;
211 stack.localMaxDeltaCompDensLoc =-1;
213 stack.localMinPresScalingFactor = 1.0;
214 stack.localMinTempScalingFactor = 1.0;
215 stack.localMinCompDensScalingFactor = 1.0;
237 template<
typename FUNC = NoOpFunc >
241 FUNC && kernelOp = NoOpFunc{} )
const
243 real64 constexpr eps = minDensForDivision;
248 if( stack.localMaxDeltaPres < absPresChange )
250 stack.localMaxDeltaPres = absPresChange;
254 real64 presScalingFactor = 1.0;
256 if( m_maxAbsolutePresChange > 0.0 )
258 if( absPresChange > m_maxAbsolutePresChange )
260 presScalingFactor = m_maxAbsolutePresChange / absPresChange;
263 else if( pres > eps )
265 real64 const relativePresChange = absPresChange / pres;
272 if( stack.localMinVal > presScalingFactor )
274 stack.localMinVal = presScalingFactor;
276 if( stack.localMinPresScalingFactor > presScalingFactor )
278 stack.localMinPresScalingFactor = presScalingFactor;
284 prevTotalDens += m_compDens[ei][ic];
287 m_compDensScalingFactor[ei] = 1.0;
294 if( stack.localMaxDeltaCompDens < absCompDensChange )
296 stack.localMaxDeltaCompDens = absCompDensChange;
305 real64 const maxAbsCompDensChange = m_maxCompFracChange * prevTotalDens;
306 if( absCompDensChange > maxAbsCompDensChange && absCompDensChange > eps )
308 real64 const compScalingFactor = maxAbsCompDensChange / absCompDensChange;
309 m_compDensScalingFactor[ei] = LvArray::math::min( m_compDensScalingFactor[ei], compScalingFactor );
310 if( stack.localMinVal > compScalingFactor )
312 stack.localMinVal = compScalingFactor;
314 if( stack.localMinCompDensScalingFactor > compScalingFactor )
316 stack.localMinCompDensScalingFactor = compScalingFactor;
321 real64 const maxRelCompDensChange = m_maxRelativeCompDensChange * LvArray::math::max( m_compDens[ei][ic], 1.0 );
322 if( absCompDensChange > maxRelCompDensChange && absCompDensChange > eps )
324 real64 const compScalingFactor = maxRelCompDensChange / absCompDensChange;
325 m_compDensScalingFactor[ei] = LvArray::math::min( m_compDensScalingFactor[ei], compScalingFactor );
326 if( stack.localMinVal > compScalingFactor )
328 stack.localMinVal = compScalingFactor;
330 if( stack.localMinCompDensScalingFactor > compScalingFactor )
332 stack.localMinCompDensScalingFactor = compScalingFactor;
345 real64 const m_maxAbsolutePresChange;
346 real64 const m_maxCompFracChange;
347 real64 const m_maxRelativeCompDensChange;
372 template<
typename POLICY >
374 createAndLaunch(
real64 const maxRelativePresChange,
375 real64 const maxAbsolutePresChange,
376 real64 const maxCompFracChange,
377 real64 const maxRelativeCompDensChange,
388 SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxCompFracChange, maxRelativeCompDensChange, rankOffset,
389 numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor );
390 return SolutionScalingKernel::launch< POLICY >( subRegion.
size(), kernel );
#define GEOS_HOST_DEVICE
Marks a host-device function.
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
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.
Define the kernel for scaling the Newton update.
static StackVariables launch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Performs the kernel launch.
GEOS_HOST_DEVICE void computeScalingFactor(localIndex const ei, StackVariables &stack, FUNC &&kernelOp=NoOpFunc{}) const
Compute the local value of the scaling factor.
SolutionScalingKernel(real64 const maxRelativePresChange, real64 const maxAbsolutePresChange, real64 const maxCompFracChange, real64 const maxRelativeCompDensChange, globalIndex const rankOffset, integer const numComp, string const dofKey, ElementSubRegionBase const &subRegion, arrayView1d< real64 const > const localSolution, arrayView1d< real64 const > const pressure, arrayView2d< real64 const, compflow::USD_COMP > const compDens, arrayView1d< real64 > pressureScalingFactor, arrayView1d< real64 > compDensScalingFactor)
Create a new kernel instance.
GEOS_HOST_DEVICE void compute(localIndex const ei, StackVariables &stack) const
Compute the local value.
real64 const m_maxRelativePresChange
Max allowed changes in primary variables.
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).
std::int32_t integer
Signed integer type.
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Kernel variables located on the stack.