GEOS
SolutionScalingKernel.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_SOLUTIONSCALINGKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_SOLUTIONSCALINGKERNEL_HPP
22 
23 #include "common/DataTypes.hpp"
24 #include "common/GEOS_RAJA_Interface.hpp"
25 
26 namespace geos
27 {
28 
29 namespace singlePhaseBaseKernels
30 {
31 
32 /******************************** SolutionScalingKernel ********************************/
33 
39 {
50 };
51 
53 {
54  template< typename POLICY >
55  static SolutionScalingData launch( arrayView1d< real64 const > const & localSolution,
56  globalIndex const rankOffset,
57  arrayView1d< globalIndex const > const & dofNumber,
58  arrayView1d< integer const > const & ghostRank,
59  real64 const maxAbsolutePresChange,
60  arrayView1d< real64 > pressureScalingFactor )
61  {
62  RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > scalingFactor( 1.0 );
63  RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPres( 0.0 );
64 
65  forAll< POLICY >( dofNumber.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) mutable
66  {
67  if( ghostRank[ei] < 0 && dofNumber[ei] >= 0 )
68  {
69  pressureScalingFactor[ei] = 1.0;
70 
71  localIndex const lid = dofNumber[ei] - rankOffset;
72 
73  // compute the change in pressure
74  real64 const absPresChange = LvArray::math::abs( localSolution[lid] );
75  maxDeltaPres.max( absPresChange );
76 
77  // maxAbsolutePresChange <= 0.0 means that scaling is disabled, and we are only collecting maxDeltaPres in this kernel
78  if( maxAbsolutePresChange > 0.0 && absPresChange > maxAbsolutePresChange )
79  {
80  real64 const presScalingFactor = maxAbsolutePresChange / absPresChange;
81  pressureScalingFactor[ei] = presScalingFactor;
82  scalingFactor.min( presScalingFactor );
83  }
84  }
85 
86  } );
87 
88  SolutionScalingData scalingData;
89  scalingData.scalingFactor = scalingFactor.get();
90  scalingData.maxDeltaPres = maxDeltaPres.get();
91  scalingData.minPresScalingFactor = scalingFactor.get();
92  return scalingData;
93  }
94 
95 };
96 
97 } // namespace singlePhaseBaseKernels
98 
99 } // namespace geos
100 
101 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_SOLUTIONSCALINGKERNEL_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
Rank-local reductions from the single-phase solution scaling kernels.
real64 maxDeltaPres
the maximum absolute pressure change (before scaling)
real64 scalingFactor
the Newton update scaling factor
real64 maxDeltaTemp
the maximum absolute temperature change (before scaling)
real64 minTempScalingFactor
the minimum temperature scaling factor
real64 minPresScalingFactor
the minimum pressure scaling factor