GEOS
GlobalComponentFractionKernel.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_GLOBALCOMPONENTFRACTIONKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP
22 
24 
25 namespace geos
26 {
27 
28 namespace isothermalCompositionalMultiphaseBaseKernels
29 {
30 
31 /******************************** GlobalComponentFractionKernel ********************************/
32 
38 template< integer NUM_COMP >
40 {
41 public:
42 
44  using Base::numComp;
45 
52  : Base(),
53  m_compDens( subRegion.getField< fields::flow::globalCompDensity >() ),
54  m_compFrac( subRegion.getField< fields::flow::globalCompFraction >() ),
55  m_dCompFrac_dCompDens( subRegion.getField< fields::flow::dGlobalCompFraction_dGlobalCompDensity >() )
56  {}
57 
64  template< typename FUNC = NoOpFunc >
66  void compute( localIndex const ei,
67  FUNC && compFractionKernelOp = NoOpFunc{} ) const
68  {
69  arraySlice1d< real64 const, compflow::USD_COMP - 1 > const compDens = m_compDens[ei];
70  arraySlice1d< real64, compflow::USD_COMP - 1 > const compFrac = m_compFrac[ei];
71  arraySlice2d< real64, compflow::USD_COMP_DC - 1 > const dCompFrac_dCompDens = m_dCompFrac_dCompDens[ei];
72 
73  real64 totalDensity = 0.0;
74 
75  for( integer ic = 0; ic < numComp; ++ic )
76  {
77  totalDensity += compDens[ic];
78  }
79 
80  real64 const totalDensityInv = 1.0 / totalDensity;
81 
82  for( integer ic = 0; ic < numComp; ++ic )
83  {
84  compFrac[ic] = compDens[ic] * totalDensityInv;
85  for( integer jc = 0; jc < numComp; ++jc )
86  {
87  dCompFrac_dCompDens[ic][jc] = -compFrac[ic] * totalDensityInv;
88  }
89  dCompFrac_dCompDens[ic][ic] += totalDensityInv;
90  }
91 
92  compFractionKernelOp( compFrac, dCompFrac_dCompDens );
93  }
94 
95 protected:
96 
97  // inputs
98 
99  // Views on component densities
100  arrayView2d< real64 const, compflow::USD_COMP > m_compDens;
101 
102  // outputs
103 
104  // Views on component fraction
105  arrayView2d< real64, compflow::USD_COMP > m_compFrac;
106  arrayView3d< real64, compflow::USD_COMP_DC > m_dCompFrac_dCompDens;
107 
108 };
109 
114 {
115 public:
116 
124  template< typename POLICY >
125  static void
126  createAndLaunch( integer const numComp,
127  ObjectManagerBase & subRegion )
128  {
129  internal::kernelLaunchSelectorCompSwitch( numComp, [&] ( auto NC )
130  {
131  integer constexpr NUM_COMP = NC();
132  GlobalComponentFractionKernel< NUM_COMP > kernel( subRegion );
133  GlobalComponentFractionKernel< NUM_COMP >::template launch< POLICY >( subRegion.size(), kernel );
134  } );
135  }
136 
137 };
138 
139 } // namespace isothermalCompositionalMultiphaseBaseKernels
140 
141 } // namespace geos
142 
143 
144 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_GLOBALCOMPONENTFRACTIONKERNEL_HPP
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
The ObjectManagerBase is the base object of all object managers in the mesh data hierachy.
localIndex size() const
Get the "size" of the group, which determines the number of elements in resizable wrappers.
Definition: Group.hpp:1315
static void createAndLaunch(integer const numComp, ObjectManagerBase &subRegion)
Create a new kernel and launch.
Define the interface for the update kernel in charge of computing the phase volume fractions.
GEOS_HOST_DEVICE void compute(localIndex const ei, FUNC &&compFractionKernelOp=NoOpFunc{}) const
Compute the phase volume fractions in an element.
static constexpr integer numComp
Compile time value for the number of components.
Define the base interface for the property update kernels.
static constexpr integer numComp
Compile time value for the number of components.
ArraySlice< T, 2, USD > arraySlice2d
Alias for 2D array slice.
Definition: DataTypes.hpp:200
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
ArraySlice< T, 1, USD > arraySlice1d
Alias for 1D array slice.
Definition: DataTypes.hpp:184
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82