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 Total, S.A
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 
64  SolutionScalingKernel( real64 const maxRelativePresChange,
65  real64 const maxAbsolutePresChange,
66  real64 const maxRelativeTempChange,
67  real64 const maxCompFracChange,
68  real64 const maxRelativeCompDensChange,
69  globalIndex const rankOffset,
70  integer const numComp,
71  string const dofKey,
72  ElementSubRegionBase const & subRegion,
73  arrayView1d< real64 const > const localSolution,
74  arrayView1d< real64 const > const pressure,
75  arrayView1d< real64 const > const temperature,
77  arrayView1d< real64 > pressureScalingFactor,
78  arrayView1d< real64 > compDensScalingFactor,
79  arrayView1d< real64 > temperatureScalingFactor,
80  integer const temperatureOffset )
81  : Base( maxRelativePresChange,
82  maxAbsolutePresChange,
83  maxCompFracChange,
84  maxRelativeCompDensChange,
85  rankOffset,
86  numComp,
87  dofKey,
88  subRegion,
89  localSolution,
90  pressure,
91  compDens,
92  pressureScalingFactor,
93  compDensScalingFactor ),
94  m_maxRelativeTempChange( maxRelativeTempChange ),
95  m_temperature( temperature ),
96  m_temperatureScalingFactor( temperatureScalingFactor ),
97  m_temperatureOffset( temperatureOffset )
98  {}
99 
106  void compute( localIndex const ei,
107  StackVariables & stack ) const
108  {
109  computeScalingFactor( ei, stack );
110  }
111 
119  StackVariables & stack ) const
120  {
121  real64 constexpr eps = isothermalCompositionalMultiphaseBaseKernels::minDensForDivision;
122  Base::computeScalingFactor( ei, stack, [&] ()
123  {
124  // compute the change in temperature
125  real64 const temp = m_temperature[ei];
126  real64 const absTempChange = LvArray::math::abs( m_localSolution[stack.localRow + m_temperatureOffset] );
127  if( stack.localMaxDeltaTemp < absTempChange )
128  {
129  stack.localMaxDeltaTemp = absTempChange;
130  }
131 
132  m_temperatureScalingFactor[ei] = 1.0;
133 
134  if( temp > eps )
135  {
136  real64 const relativeTempChange = absTempChange / temp;
137  if( relativeTempChange > m_maxRelativeTempChange )
138  {
139  real64 const tempScalingFactor = m_maxRelativeTempChange / relativeTempChange;
140  m_temperatureScalingFactor[ei] = tempScalingFactor;
141  if( stack.localMinVal > tempScalingFactor )
142  {
143  stack.localMinVal = tempScalingFactor;
144  }
145  if( stack.localMinTempScalingFactor > tempScalingFactor )
146  {
147  stack.localMinTempScalingFactor = tempScalingFactor;
148  }
149  }
150  }
151  } );
152  }
153 
154 protected:
155 
158 
161 
164 
167 };
168 
173 {
174 public:
175 
190  template< typename POLICY >
192  createAndLaunch( real64 const maxRelativePresChange,
193  real64 const maxAbsolutePresChange,
194  real64 const maxRelativeTempChange,
195  real64 const maxCompFracChange,
196  real64 const maxRelativeCompDensChange,
197  arrayView1d< real64 const > const pressure,
198  arrayView1d< real64 const > const temperature,
200  arrayView1d< real64 > pressureScalingFactor,
201  arrayView1d< real64 > compDensScalingFactor,
202  arrayView1d< real64 > temperatureScalingFactor,
203  globalIndex const rankOffset,
204  integer const numComp,
205  string const dofKey,
206  ElementSubRegionBase & subRegion,
207  arrayView1d< real64 const > const localSolution,
208  integer const temperatureOffset )
209  {
210  SolutionScalingKernel kernel( maxRelativePresChange, maxAbsolutePresChange, maxRelativeTempChange,
211  maxCompFracChange, maxRelativeCompDensChange,
212  rankOffset, numComp, dofKey, subRegion, localSolution,
213  pressure, temperature, compDens, pressureScalingFactor,
214  compDensScalingFactor, temperatureScalingFactor, temperatureOffset );
215  return thermalCompositionalMultiphaseBaseKernels::
216  SolutionScalingKernel::launch< POLICY >( subRegion.size(), kernel );
217  }
218 
219 };
220 
221 } // namespace thermalCompositionalMultiphaseBaseKernels
222 
223 } // namespace geos
224 
225 
226 #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 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 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:180
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:88
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:196