GEOS
AquiferBCKernel.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_AQUIFERBCKERNEL_HPP
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_AQUIFERBCKERNEL_HPP
22 
23 #include "common/DataTypes.hpp"
24 #include "common/GEOS_RAJA_Interface.hpp"
27 
28 namespace geos
29 {
30 
31 namespace singlePhaseFVMKernels
32 {
33 
34 /******************************** AquiferBCKernel ********************************/
35 
40 {
41 
48  template< typename VIEWTYPE >
50 
52  static void
53  compute( real64 const & aquiferVolFlux,
54  real64 const & dAquiferVolFlux_dPres,
55  real64 const & aquiferDens,
56  real64 const & dens,
57  real64 const & dDens_dPres,
58  real64 const & dt,
59  real64 & localFlux,
60  real64 & localFluxJacobian )
61  {
62  if( aquiferVolFlux > 0 ) // aquifer is upstream
63  {
64  localFlux -= dt * aquiferVolFlux * aquiferDens;
65  localFluxJacobian -= dt * dAquiferVolFlux_dPres * aquiferDens;
66  }
67  else // reservoir is upstream
68  {
69  localFlux -= dt * aquiferVolFlux * dens;
70  localFluxJacobian -= dt * (dAquiferVolFlux_dPres * dens + aquiferVolFlux * dDens_dPres);
71  }
72  }
73 
74  static void
75  launch( BoundaryStencil const & stencil,
76  globalIndex const rankOffset,
79  AquiferBoundaryCondition::KernelWrapper const & aquiferBCWrapper,
80  real64 const & aquiferDens,
86  real64 const & timeAtBeginningOfStep,
87  real64 const & dt,
89  arrayView1d< real64 > const & localRhs )
90  {
91  using Order = BoundaryStencil::Order;
92  using Deriv = constitutive::singlefluid::DerivativeOffset;
93 
98 
99  forAll< parallelDevicePolicy<> >( stencil.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn )
100  {
101  // working variables
102  real64 localFlux = 0.0;
103  real64 localFluxJacobian = 0.0;
104 
105  localIndex const er = seri( iconn, Order::ELEM );
106  localIndex const esr = sesri( iconn, Order::ELEM );
107  localIndex const ei = sefi( iconn, Order::ELEM );
108  real64 const areaFraction = weight( iconn, Order::ELEM );
109 
110  // compute the aquifer influx rate using the pressure influence function and the aquifer props
111  real64 dAquiferVolFlux_dPres = 0.0;
112  real64 const aquiferVolFlux = aquiferBCWrapper.compute( timeAtBeginningOfStep,
113  dt,
114  pres[er][esr][ei],
115  pres_n[er][esr][ei],
116  gravCoef[er][esr][ei],
117  areaFraction,
118  dAquiferVolFlux_dPres );
119 
120  // compute the phase/component aquifer flux
121  AquiferBCKernel::compute( aquiferVolFlux,
122  dAquiferVolFlux_dPres,
123  aquiferDens,
124  dens[er][esr][ei][0],
125  dDens[er][esr][ei][0][Deriv::dP],
126  dt,
127  localFlux,
128  localFluxJacobian );
129 
130  // Add to residual/jacobian
131  if( ghostRank[er][esr][ei] < 0 )
132  {
133  globalIndex const globalRow = dofNumber[er][esr][ei];
134  localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - rankOffset );
135  GEOS_ASSERT_GE( localRow, 0 );
136  GEOS_ASSERT_GT( localMatrix.numRows(), localRow );
137 
138  RAJA::atomicAdd( parallelDeviceAtomic{}, &localRhs[localRow], localFlux );
139  localMatrix.addToRow< parallelDeviceAtomic >( localRow,
140  &dofNumber[er][esr][ei],
141  &localFluxJacobian,
142  1 );
143  }
144  } );
145  }
146 
147 };
148 
149 } // namespace singlePhaseFVMKernels
150 
151 } // namespace geos
152 
153 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_SINGLEPHASE_AQUIFERBCKERNEL_HPP
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
#define GEOS_ASSERT_GT(lhs, rhs)
Assert that one value compares greater than the other in debug builds.
Definition: Logger.hpp:440
#define GEOS_ASSERT_GE(lhs, rhs)
Assert that one value compares greater than or equal to the other in debug builds.
Definition: Logger.hpp:455
GEOS_HOST_DEVICE real64 compute(real64 const &timeAtBeginningOfStep, real64 const &dt, real64 const &reservoirPressure, real64 const &reservoirPressure_n, real64 const &reservoirGravCoef, real64 const &areaFraction, real64 &dAquiferVolFlux_dPres) const
Compute the aquifer-reservoir volumetric flux.
Provides management of the boundary stencil points (stencils used to prescribe boundary conditions on...
virtual localIndex size() const override
Give the number of stencil entries.
typename ElementViewAccessor< VIEWTYPE >::NestedViewTypeConst ElementViewConst
The ElementViewAccessor at the ElementRegionManager level is the type resulting from ElementViewAcces...
TRAITS::IndexContainerViewConstType getElementSubRegionIndices() const
Const access to the element subregions indices.
TRAITS::IndexContainerViewConstType getElementIndices() const
Const access to the element indices.
TRAITS::WeightContainerViewConstType getWeights() const
Const access to the stencil weights.
TRAITS::IndexContainerViewConstType getElementRegionIndices() const
Const access to the element regions indices.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:310
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
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:196
ArrayView< T, 3, USD > arrayView3d
Alias for 3D array view.
Definition: DataTypes.hpp:212
Defines the order of element/face in the stencil.
LvArray::typeManipulation::NestedViewTypeConst< IndexContainerType > IndexContainerViewConstType
The array view to const type for the stencil indices.
Definition: StencilBase.hpp:47
LvArray::typeManipulation::NestedViewTypeConst< WeightContainerType > WeightContainerViewConstType
The array view to const type for the stencil weights.
Definition: StencilBase.hpp:53
Functions to assemble aquifer boundary condition contributions to residual and Jacobian.
ElementRegionManager::ElementViewConst< VIEWTYPE > ElementViewConst
The type for element-based data. Consists entirely of ArrayView's.