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_SINGLEPHASE_THERMALSOLUTIONSCALINGKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALSOLUTIONSCALINGKERNEL_HPP
22 
23 #include "common/DataTypes.hpp"
24 #include "common/GEOS_RAJA_Interface.hpp"
26 
27 namespace geos
28 {
29 
30 namespace thermalSinglePhaseBaseKernels
31 {
32 
33 /******************************** SolutionScalingKernel ********************************/
34 
36 {
37  template< typename POLICY >
39  launch( arrayView1d< real64 const > const & localSolution,
40  globalIndex const rankOffset,
41  integer const temperatureOffset,
42  arrayView1d< globalIndex const > const & dofNumber,
43  arrayView1d< integer const > const & ghostRank,
44  real64 const maxAbsolutePresChange,
45  real64 const maxAbsoluteTempChange,
46  arrayView1d< real64 > pressureScalingFactor,
47  arrayView1d< real64 > temperatureScalingFactor )
48  {
49  RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > scalingFactor( 1.0 );
50  RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPres( 0.0 );
51  RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaTemp( 0.0 );
52 
53  RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > localMinPresScalingFactor( 1.0 );
54  RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > localMinTempScalingFactor( 1.0 );
55 
56  forAll< POLICY >( dofNumber.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) mutable
57  {
58  if( ghostRank[ei] < 0 && dofNumber[ei] >= 0 )
59  {
60  pressureScalingFactor[ei] = 1.0;
61  temperatureScalingFactor[ei] = 1.0;
62 
63  localIndex const lid = dofNumber[ei] - rankOffset;
64 
65  // compute the change in pressure
66  real64 const absPresChange = LvArray::math::abs( localSolution[lid] );
67  maxDeltaPres.max( absPresChange );
68 
69  // compute the change in temperature
70  real64 const absTempChange = LvArray::math::abs( localSolution[lid + temperatureOffset] );
71  maxDeltaTemp.max( absTempChange );
72 
73  // maxAbsolutePresChange <= 0.0 means that scaling is disabled, and we are only collecting maxDeltaPres in this kernel
74  if( maxAbsolutePresChange > 0.0 && absPresChange > maxAbsolutePresChange )
75  {
76  real64 const presScalingFactor = maxAbsolutePresChange / absPresChange;
77  pressureScalingFactor[ei] = presScalingFactor;
78  scalingFactor.min( presScalingFactor );
79 
80  localMinPresScalingFactor.min( presScalingFactor );
81  }
82 
83  // maxAbsoluteTempChange <= 0.0 means that scaling is disabled, and we are only collecting maxDeltaTemps in this kernel
84  if( maxAbsoluteTempChange > 0.0 && absTempChange > maxAbsoluteTempChange )
85  {
86  real64 const tempScalingFactor = maxAbsoluteTempChange / absTempChange;
87  temperatureScalingFactor[ei] = tempScalingFactor;
88  scalingFactor.min( tempScalingFactor );
89 
90  localMinTempScalingFactor.min( tempScalingFactor );
91  }
92  }
93 
94  } );
95 
97  scalingData.scalingFactor = scalingFactor.get();
98  scalingData.maxDeltaPres = maxDeltaPres.get();
99  scalingData.maxDeltaTemp = maxDeltaTemp.get();
100  scalingData.minPresScalingFactor = localMinPresScalingFactor.get();
101  scalingData.minTempScalingFactor = localMinTempScalingFactor.get();
102  return scalingData;
103  }
104 
105 };
106 
107 } // namespace thermalSinglePhaseBaseKernels
108 
109 } // namespace geos
110 
111 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_THERMALSOLUTIONSCALINGKERNEL_HPP
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
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
int integer
Signed integer type.
Definition: DataTypes.hpp:81
Rank-local reductions from the single-phase solution scaling kernels.
real64 scalingFactor
the Newton update scaling factor