20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_SOLUTIONSCALINGKERNEL_HPP
29 namespace isothermalCompositionalMultiphaseBaseKernels
49 using Base::m_compDens;
51 using Base::m_compDensScalingFactor;
70 real64 const maxAbsolutePresChange,
71 real64 const maxCompFracChange,
72 real64 const maxRelativeCompDensChange,
89 pressureScalingFactor,
90 compDensScalingFactor ),
92 m_maxAbsolutePresChange( maxAbsolutePresChange ),
93 m_maxCompFracChange( maxCompFracChange ),
94 m_maxRelativeCompDensChange( maxRelativeCompDensChange )
108 real64 _localMaxDeltaPres,
110 real64 _localMaxDeltaTemp,
112 real64 _localMaxDeltaCompDens,
114 real64 _localMinPresScalingFactor,
115 real64 _localMinTempScalingFactor,
116 real64 _localMinCompDensScalingFactor )
118 Base::StackVariables( _localMinVal ),
119 localMaxDeltaPres( _localMaxDeltaPres ),
120 localMaxDeltaPresLoc( _localMaxDeltaPresLoc ),
121 localMaxDeltaTemp( _localMaxDeltaTemp ),
122 localMaxDeltaTempLoc( _localMaxDeltaTempLoc ),
123 localMaxDeltaCompDens( _localMaxDeltaCompDens ),
124 localMaxDeltaCompDensLoc( _localMaxDeltaCompDensLoc ),
125 localMinPresScalingFactor( _localMinPresScalingFactor ),
126 localMinTempScalingFactor( _localMinTempScalingFactor ),
127 localMinCompDensScalingFactor( _localMinCompDensScalingFactor )
134 real64 localMaxDeltaCompDens;
137 real64 localMinPresScalingFactor;
138 real64 localMinTempScalingFactor;
139 real64 localMinCompDensScalingFactor;
150 template<
typename POLICY,
typename KERNEL_TYPE >
153 KERNEL_TYPE
const & kernelComponent )
155 RAJA::ReduceMin< ReducePolicy< POLICY >,
real64 > globalScalingFactor( 1.0 );
157 RAJA::ReduceMaxLoc< ReducePolicy< POLICY >,
real64 > maxDeltaPres( std::numeric_limits< real64 >::min(), -1 );
158 RAJA::ReduceMaxLoc< ReducePolicy< POLICY >,
real64 > maxDeltaTemp( std::numeric_limits< real64 >::min(), -1 );
159 RAJA::ReduceMaxLoc< ReducePolicy< POLICY >,
real64 > maxDeltaCompDens( std::numeric_limits< real64 >::min(), -1 );
161 RAJA::ReduceMin< ReducePolicy< POLICY >,
real64 > minPresScalingFactor( 1.0 );
162 RAJA::ReduceMin< ReducePolicy< POLICY >,
real64 > minTempScalingFactor( 1.0 );
163 RAJA::ReduceMin< ReducePolicy< POLICY >,
real64 > minCompDensScalingFactor( 1.0 );
167 if( kernelComponent.ghostRank( ei ) >= 0 )
173 kernelComponent.setup( ei, stack );
174 kernelComponent.compute( ei, stack );
176 globalScalingFactor.min( stack.localMinVal );
178 maxDeltaPres.maxloc( stack.localMaxDeltaPres, ei );
179 maxDeltaTemp.maxloc( stack.localMaxDeltaTemp, ei );
180 maxDeltaCompDens.maxloc( stack.localMaxDeltaCompDens, ei );
182 minPresScalingFactor.min( stack.localMinPresScalingFactor );
183 minTempScalingFactor.min( stack.localMinTempScalingFactor );
184 minCompDensScalingFactor.min( stack.localMinCompDensScalingFactor );
189 maxDeltaPres.getLoc(),
191 maxDeltaTemp.getLoc(),
192 maxDeltaCompDens.get(),
193 maxDeltaCompDens.getLoc(),
194 minPresScalingFactor.get(),
195 minTempScalingFactor.get(),
196 minCompDensScalingFactor.get() );
201 StackVariables & stack )
const
205 stack.localMaxDeltaPres = 0.0;
206 stack.localMaxDeltaPresLoc = -1;
207 stack.localMaxDeltaTemp = 0.0;
208 stack.localMaxDeltaTempLoc = -1;
209 stack.localMaxDeltaCompDens = 0.0;
210 stack.localMaxDeltaCompDensLoc =-1;
212 stack.localMinPresScalingFactor = 1.0;
213 stack.localMinTempScalingFactor = 1.0;
214 stack.localMinCompDensScalingFactor = 1.0;
236 template<
typename FUNC = NoOpFunc >
240 FUNC && kernelOp = NoOpFunc{} )
const
242 real64 constexpr eps = minDensForDivision;
247 if( stack.localMaxDeltaPres < absPresChange )
249 stack.localMaxDeltaPres = absPresChange;
253 real64 presScalingFactor = 1.0;
255 if( m_maxAbsolutePresChange > 0.0 )
257 if( absPresChange > m_maxAbsolutePresChange )
259 presScalingFactor = m_maxAbsolutePresChange / absPresChange;
262 else if( pres > eps )
264 real64 const relativePresChange = absPresChange / pres;
271 if( stack.localMinVal > presScalingFactor )
273 stack.localMinVal = presScalingFactor;
275 if( stack.localMinPresScalingFactor > presScalingFactor )
277 stack.localMinPresScalingFactor = presScalingFactor;
283 prevTotalDens += m_compDens[ei][ic];
286 m_compDensScalingFactor[ei] = 1.0;
293 if( stack.localMaxDeltaCompDens < absCompDensChange )
295 stack.localMaxDeltaCompDens = absCompDensChange;
304 real64 const maxAbsCompDensChange = m_maxCompFracChange * prevTotalDens;
305 if( absCompDensChange > maxAbsCompDensChange && absCompDensChange > eps )
307 real64 const compScalingFactor = maxAbsCompDensChange / absCompDensChange;
308 m_compDensScalingFactor[ei] = LvArray::math::min( m_compDensScalingFactor[ei], compScalingFactor );
309 if( stack.localMinVal > compScalingFactor )
311 stack.localMinVal = compScalingFactor;
313 if( stack.localMinCompDensScalingFactor > compScalingFactor )
315 stack.localMinCompDensScalingFactor = compScalingFactor;
320 real64 const maxRelCompDensChange = m_maxRelativeCompDensChange * LvArray::math::max( m_compDens[ei][ic], 1.0 );
321 if( absCompDensChange > maxRelCompDensChange && absCompDensChange > eps )
323 real64 const compScalingFactor = maxRelCompDensChange / absCompDensChange;
324 m_compDensScalingFactor[ei] = LvArray::math::min( m_compDensScalingFactor[ei], compScalingFactor );
325 if( stack.localMinVal > compScalingFactor )
327 stack.localMinVal = compScalingFactor;
329 if( stack.localMinCompDensScalingFactor > compScalingFactor )
331 stack.localMinCompDensScalingFactor = compScalingFactor;
344 real64 const m_maxAbsolutePresChange;
345 real64 const m_maxCompFracChange;
346 real64 const m_maxRelativeCompDensChange;
371 template<
typename POLICY >
373 createAndLaunch(
real64 const maxRelativePresChange,
374 real64 const maxAbsolutePresChange,
375 real64 const maxCompFracChange,
376 real64 const maxRelativeCompDensChange,
387 SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxCompFracChange, maxRelativeCompDensChange, rankOffset,
388 numComp, dofKey, subRegion, localSolution, pressure, compDens, pressureScalingFactor, compDensScalingFactor );
389 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.