GEOS
PhaseComponentFlux.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_PHASECOMPONENTFLUX_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASECOMPONENTFLUX_HPP
22 
23 #include "common/DataLayouts.hpp"
24 #include "common/DataTypes.hpp"
25 #include "constitutive/fluid/multifluid/Layouts.hpp"
27 
28 
29 namespace geos
30 {
31 
32 namespace isothermalCompositionalMultiphaseFVMKernelUtilities
33 {
34 
35 template< typename VIEWTYPE >
36 using ElementViewConst = ElementRegionManager::ElementViewConst< VIEWTYPE >;
37 
38 using Deriv = constitutive::multifluid::DerivativeOffset;
39 
41 {
61  template< localIndex numComp, localIndex numFluxSupportPoints >
63  static void
64  compute( localIndex const ip,
65  localIndex const k_up,
66  localIndex const ( &seri )[numFluxSupportPoints],
67  localIndex const ( &sesri )[numFluxSupportPoints],
68  localIndex const ( &sei )[numFluxSupportPoints],
69  ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const & phaseCompFrac,
70  ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const & dPhaseCompFrac,
71  ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const & dCompFrac_dCompDens,
72  real64 const & phaseFlux,
73  real64 const ( &dPhaseFlux_dP )[numFluxSupportPoints],
74  real64 const ( &dPhaseFlux_dC )[numFluxSupportPoints][numComp],
75  real64 ( & compFlux )[numComp],
76  real64 ( & dCompFlux_dP )[numFluxSupportPoints][numComp],
77  real64 ( & dCompFlux_dC )[numFluxSupportPoints][numComp][numComp] )
78  {
79  localIndex const er_up = seri[k_up];
80  localIndex const esr_up = sesri[k_up];
81  localIndex const ei_up = sei[k_up];
82 
83  real64 dProp_dC[numComp]{};
84 
85  // slice some constitutive arrays to avoid too much indexing in component loop
86  arraySlice1d< real64 const, constitutive::multifluid::USD_PHASE_COMP-3 > phaseCompFracSub =
87  phaseCompFrac[er_up][esr_up][ei_up][0][ip];
88  arraySlice2d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC-3 > dPhaseCompFracSub =
89  dPhaseCompFrac[er_up][esr_up][ei_up][0][ip];
90 
91  // compute component fluxes and derivatives using upstream cell composition
92  for( integer ic = 0; ic < numComp; ++ic )
93  {
94  real64 const ycp = phaseCompFracSub[ic];
95  compFlux[ic] += phaseFlux * ycp;
96 
97  // derivatives stemming from phase flux
98  for( integer ke = 0; ke < numFluxSupportPoints; ++ke )
99  {
100  dCompFlux_dP[ke][ic] += dPhaseFlux_dP[ke] * ycp;
101  for( integer jc = 0; jc < numComp; ++jc )
102  {
103  dCompFlux_dC[ke][ic][jc] += dPhaseFlux_dC[ke][jc] * ycp;
104  }
105  }
106 
107  // additional derivatives stemming from upstream cell phase composition
108  dCompFlux_dP[k_up][ic] += phaseFlux * dPhaseCompFracSub[ic][Deriv::dP];
109 
110  // convert derivatives of comp fraction w.r.t. comp fractions to derivatives w.r.t. comp densities
111  applyChainRule( numComp,
112  dCompFrac_dCompDens[er_up][esr_up][ei_up],
113  dPhaseCompFracSub[ic],
114  dProp_dC,
115  Deriv::dC );
116  for( integer jc = 0; jc < numComp; ++jc )
117  {
118  dCompFlux_dC[k_up][ic][jc] += phaseFlux * dProp_dC[jc];
119  }
120  }
121  }
122 };
123 
124 } // namespace isothermalCompositionalMultiPhaseFVMKernelUtilities
125 
126 } // namespace geos
127 
128 #endif // GEOS_PHYSICSSOLVERS_FLUIDFLOW_COMPOSITIONAL_PHASECOMPONENTFLUX_HPP
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
ArraySlice< T, 2, USD > arraySlice2d
Alias for 2D array slice.
Definition: DataTypes.hpp:200
ArrayView< T, 5, USD > arrayView5d
Alias for 5D array view.
Definition: DataTypes.hpp:244
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
ArrayView< T, 4, USD > arrayView4d
Alias for 4D array view.
Definition: DataTypes.hpp:228
ArrayView< T, 3, USD > arrayView3d
Alias for 3D array view.
Definition: DataTypes.hpp:212
static GEOS_HOST_DEVICE void compute(localIndex const ip, localIndex const k_up, localIndex const (&seri)[numFluxSupportPoints], localIndex const (&sesri)[numFluxSupportPoints], localIndex const (&sei)[numFluxSupportPoints], ElementViewConst< arrayView4d< real64 const, constitutive::multifluid::USD_PHASE_COMP > > const &phaseCompFrac, ElementViewConst< arrayView5d< real64 const, constitutive::multifluid::USD_PHASE_COMP_DC > > const &dPhaseCompFrac, ElementViewConst< arrayView3d< real64 const, compflow::USD_COMP_DC > > const &dCompFrac_dCompDens, real64 const &phaseFlux, real64 const (&dPhaseFlux_dP)[numFluxSupportPoints], real64 const (&dPhaseFlux_dC)[numFluxSupportPoints][numComp], real64(&compFlux)[numComp], real64(&dCompFlux_dP)[numFluxSupportPoints][numComp], real64(&dCompFlux_dC)[numFluxSupportPoints][numComp][numComp])
Compute the component flux for a given phase.