GEOS
ThermalSolutionScalingKernel.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALSOLUTIONSCALINGKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALSOLUTIONSCALINGKERNEL_HPP
22 
24 
25 namespace geos
26 {
27 
28 namespace thermalCompositionalMultiphaseBaseKernels
29 {
30 
31 /******************************** SolutionScalingKernel ********************************/
32 
38 {
39 public:
40 
42  using Base::m_numComp;
44 
65  SolutionScalingKernel( real64 const maxRelativePresChange,
66  real64 const maxAbsolutePresChange,
67  real64 const maxRelativeTempChange,
68  real64 const maxAbsoluteTempChange,
69  real64 const maxCompFracChange,
70  real64 const maxRelativeCompDensChange,
71  globalIndex const rankOffset,
72  integer const numComp,
73  string const dofKey,
74  ElementSubRegionBase const & subRegion,
75  arrayView1d< real64 const > const localSolution,
76  arrayView1d< real64 const > const pressure,
77  arrayView1d< real64 const > const temperature,
79  arrayView1d< real64 > pressureScalingFactor,
80  arrayView1d< real64 > compDensScalingFactor,
81  arrayView1d< real64 > temperatureScalingFactor,
82  integer const temperatureOffset )
83  : Base( maxRelativePresChange,
84  maxAbsolutePresChange,
85  maxCompFracChange,
86  maxRelativeCompDensChange,
87  rankOffset,
88  numComp,
89  dofKey,
90  subRegion,
91  localSolution,
92  pressure,
93  compDens,
94  pressureScalingFactor,
95  compDensScalingFactor ),
96  m_maxRelativeTempChange( maxRelativeTempChange ),
97  m_maxAbsoluteTempChange( maxAbsoluteTempChange ),
98  m_temperature( temperature ),
99  m_temperatureScalingFactor( temperatureScalingFactor ),
100  m_temperatureOffset( temperatureOffset )
101  {}
102 
109  void compute( localIndex const ei,
110  StackVariables & stack ) const
111  {
112  computeScalingFactor( ei, stack );
113  }
114 
122  StackVariables & stack ) const
123  {
124  real64 constexpr eps = isothermalCompositionalMultiphaseBaseKernels::minDensForDivision;
125  Base::computeScalingFactor( ei, stack, [&] ()
126  {
127  // compute the change in temperature
128  real64 const temp = m_temperature[ei];
129  real64 const absTempChange = LvArray::math::abs( m_localSolution[stack.localRow + m_temperatureOffset] );
130  if( stack.localMaxDeltaTemp < absTempChange )
131  {
132  stack.localMaxDeltaTemp = absTempChange;
133  }
134 
135  // compute temperature scaling factor
136  real64 tempScalingFactor = 1.0;
137  // the stricter of the absolute and relative change limits is applied
138  if( m_maxAbsoluteTempChange > 0.0 ) // maxAbsoluteTempChange <= 0.0 means that absolute scaling is disabled
139  {
140  if( absTempChange > m_maxAbsoluteTempChange )
141  {
142  tempScalingFactor = m_maxAbsoluteTempChange / absTempChange;
143  }
144  }
145  if( temp > eps )
146  {
147  real64 const relativeTempChange = absTempChange / temp;
148  if( relativeTempChange > m_maxRelativeTempChange )
149  {
150  tempScalingFactor = LvArray::math::min( tempScalingFactor, m_maxRelativeTempChange / relativeTempChange );
151  }
152  }
153  m_temperatureScalingFactor[ei] = tempScalingFactor;
154  if( stack.localMinVal > tempScalingFactor )
155  {
156  stack.localMinVal = tempScalingFactor;
157  }
158  if( stack.localMinTempScalingFactor > tempScalingFactor )
159  {
160  stack.localMinTempScalingFactor = tempScalingFactor;
161  }
162  } );
163  }
164 
165 protected:
166 
169  real64 const m_maxAbsoluteTempChange;
170 
173 
176 
179 };
180 
185 {
186 public:
187 
203  template< typename POLICY >
205  createAndLaunch( real64 const maxRelativePresChange,
206  real64 const maxAbsolutePresChange,
207  real64 const maxRelativeTempChange,
208  real64 const maxAbsoluteTempChange,
209  real64 const maxCompFracChange,
210  real64 const maxRelativeCompDensChange,
211  arrayView1d< real64 const > const pressure,
212  arrayView1d< real64 const > const temperature,
214  arrayView1d< real64 > pressureScalingFactor,
215  arrayView1d< real64 > compDensScalingFactor,
216  arrayView1d< real64 > temperatureScalingFactor,
217  globalIndex const rankOffset,
218  integer const numComp,
219  string const dofKey,
220  ElementSubRegionBase & subRegion,
221  arrayView1d< real64 const > const localSolution,
222  integer const temperatureOffset )
223  {
224  SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxRelativeTempChange, maxAbsoluteTempChange,
225  maxCompFracChange, maxRelativeCompDensChange,
226  rankOffset, numComp, dofKey, subRegion, localSolution,
227  pressure, temperature, compDens, pressureScalingFactor,
228  compDensScalingFactor, temperatureScalingFactor, temperatureOffset );
229  return thermalCompositionalMultiphaseBaseKernels::
230  SolutionScalingKernel::launch< POLICY >( subRegion.size(), kernel );
231  }
232 
233 };
234 
235 } // namespace thermalCompositionalMultiphaseBaseKernels
236 
237 } // namespace geos
238 
239 
240 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_THERMALSOLUTIONSCALINGKERNEL_HPP
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
Definition: Group.hpp:1315
GEOS_HOST_DEVICE void computeScalingFactor(localIndex const ei, StackVariables &stack, FUNC &&kernelOp=NoOpFunc{}) const
Compute the local value of the scaling factor.
static SolutionScalingKernel::StackVariables createAndLaunch(real64 const maxRelativePresChange, real64 const maxAbsolutePresChange, real64 const maxRelativeTempChange, real64 const maxAbsoluteTempChange, real64 const maxCompFracChange, real64 const maxRelativeCompDensChange, arrayView1d< real64 const > const pressure, arrayView1d< real64 const > const temperature, arrayView2d< real64 const, compflow::USD_COMP > const compDens, arrayView1d< real64 > pressureScalingFactor, arrayView1d< real64 > compDensScalingFactor, arrayView1d< real64 > temperatureScalingFactor, globalIndex const rankOffset, integer const numComp, string const dofKey, ElementSubRegionBase &subRegion, arrayView1d< real64 const > const localSolution, integer const temperatureOffset)
Create a new kernel and launch.
GEOS_HOST_DEVICE void compute(localIndex const ei, StackVariables &stack) const
Compute the local value.
arrayView1d< real64 > const m_temperatureScalingFactor
View on the scaling factor.
real64 const m_maxRelativeTempChange
Max allowed changes in primary variables.
arrayView1d< real64 const > const m_temperature
View on the primary variables.
GEOS_HOST_DEVICE void computeScalingFactor(localIndex const ei, StackVariables &stack) const
Compute the local value of the scaling factor.
SolutionScalingKernel(real64 const maxRelativePresChange, real64 const maxAbsolutePresChange, real64 const maxRelativeTempChange, real64 const maxAbsoluteTempChange, 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, arrayView1d< real64 const > const temperature, arrayView2d< real64 const, compflow::USD_COMP > const compDens, arrayView1d< real64 > pressureScalingFactor, arrayView1d< real64 > compDensScalingFactor, arrayView1d< real64 > temperatureScalingFactor, integer const temperatureOffset)
Create a new kernel instance.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:87
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:195
int integer
Signed integer type.
Definition: DataTypes.hpp:81