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 
35 {
36  template< typename POLICY >
37  static std::pair< real64, real64 > launch( arrayView1d< real64 const > const & localSolution,
38  globalIndex const rankOffset,
39  arrayView1d< globalIndex const > const & dofNumber,
40  arrayView1d< integer const > const & ghostRank,
41  real64 const maxAbsolutePresChange )
42  {
43  RAJA::ReduceMin< ReducePolicy< POLICY >, real64 > scalingFactor( 1.0 );
44  RAJA::ReduceMax< ReducePolicy< POLICY >, real64 > maxDeltaPres( 0.0 );
45 
46  forAll< POLICY >( dofNumber.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) mutable
47  {
48  if( ghostRank[ei] < 0 && dofNumber[ei] >= 0 )
49  {
50  localIndex const lid = dofNumber[ei] - rankOffset;
51 
52  // compute the change in pressure
53  real64 const absPresChange = LvArray::math::abs( localSolution[lid] );
54  maxDeltaPres.max( absPresChange );
55 
56  // maxAbsolutePresChange <= 0.0 means that scaling is disabled, and we are only collecting maxDeltaPres in this kernel
57  if( maxAbsolutePresChange > 0.0 && absPresChange > maxAbsolutePresChange )
58  {
59  real64 const presScalingFactor = maxAbsolutePresChange / absPresChange;
60  scalingFactor.min( presScalingFactor );
61  }
62  }
63 
64  } );
65 
66  return { scalingFactor.get(), maxDeltaPres.get() };
67  }
68 
69 };
70 
71 } // namespace singlePhaseBaseKernels
72 
73 } // namespace geos
74 
75 #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: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