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,
85  ElementViewConst< arrayView2d< real64 const > > const & dDens_dPres,
86  real64 const & timeAtBeginningOfStep,
87  real64 const & dt,
89  arrayView1d< real64 > const & localRhs )
90  {
91  using Order = BoundaryStencil::Order;
92 
97 
98  forAll< parallelDevicePolicy<> >( stencil.size(), [=] GEOS_HOST_DEVICE ( localIndex const iconn )
99  {
100  // working variables
101  real64 localFlux = 0.0;
102  real64 localFluxJacobian = 0.0;
103 
104  localIndex const er = seri( iconn, Order::ELEM );
105  localIndex const esr = sesri( iconn, Order::ELEM );
106  localIndex const ei = sefi( iconn, Order::ELEM );
107  real64 const areaFraction = weight( iconn, Order::ELEM );
108 
109  // compute the aquifer influx rate using the pressure influence function and the aquifer props
110  real64 dAquiferVolFlux_dPres = 0.0;
111  real64 const aquiferVolFlux = aquiferBCWrapper.compute( timeAtBeginningOfStep,
112  dt,
113  pres[er][esr][ei],
114  pres_n[er][esr][ei],
115  gravCoef[er][esr][ei],
116  areaFraction,
117  dAquiferVolFlux_dPres );
118 
119  // compute the phase/component aquifer flux
120  AquiferBCKernel::compute( aquiferVolFlux,
121  dAquiferVolFlux_dPres,
122  aquiferDens,
123  dens[er][esr][ei][0],
124  dDens_dPres[er][esr][ei][0],
125  dt,
126  localFlux,
127  localFluxJacobian );
128 
129  // Add to residual/jacobian
130  if( ghostRank[er][esr][ei] < 0 )
131  {
132  globalIndex const globalRow = dofNumber[er][esr][ei];
133  localIndex const localRow = LvArray::integerConversion< localIndex >( globalRow - rankOffset );
134  GEOS_ASSERT_GE( localRow, 0 );
135  GEOS_ASSERT_GT( localMatrix.numRows(), localRow );
136 
137  RAJA::atomicAdd( parallelDeviceAtomic{}, &localRhs[localRow], localFlux );
138  localMatrix.addToRow< parallelDeviceAtomic >( localRow,
139  &dofNumber[er][esr][ei],
140  &localFluxJacobian,
141  1 );
142  }
143  } );
144  }
145 
146 };
147 
148 } // namespace singlePhaseFVMKernels
149 
150 } // namespace geos
151 
152 #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
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.