GEOS
BoundaryStencil.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_FINITEVOLUME_BOUNDARYSTENCIL_HPP_
21 #define GEOS_FINITEVOLUME_BOUNDARYSTENCIL_HPP_
22 
23 #include "StencilBase.hpp"
24 
25 namespace geos
26 {
27 
31 class BoundaryStencilWrapper : public StencilWrapperBase< TwoPointStencilTraits >
32 {
33 public:
34 
36  template< typename VIEWTYPE >
38 
49  BoundaryStencilWrapper( IndexContainerType const & elementRegionIndices,
50  IndexContainerType const & elementSubRegionIndices,
51  IndexContainerType const & elementIndices,
52  WeightContainerType const & weights,
55  arrayView1d< real64 > const & weightMultiplier );
56 
65  void computeWeights( localIndex const iconn,
66  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
67  real64 & weight,
68  real64 ( &dWeight_dCoef )[3] ) const;
69 
76  localIndex size() const
77  { return m_elementRegionIndices.size( 0 ); }
78 
86  constexpr localIndex stencilSize( localIndex const index ) const
87  {
88  GEOS_UNUSED_VAR( index );
89  return maxStencilSize;
90  }
91 
99  constexpr localIndex numPointsInFlux( localIndex const index ) const
100  {
101  GEOS_UNUSED_VAR( index );
102  return maxNumPointsInFlux;
103  }
104 
105 private:
106 
109  arrayView1d< real64 > m_weightMultiplier;
110 };
111 
116 class BoundaryStencil final : public StencilBase< TwoPointStencilTraits, BoundaryStencil >
117 {
118 public:
119 
124 
128  struct Order
129  {
130  static constexpr localIndex ELEM = 0;
131  static constexpr localIndex FACE = 1;
132  };
133 
134  virtual void add( localIndex const numPts,
135  localIndex const * const elementRegionIndices,
136  localIndex const * const elementSubRegionIndices,
137  localIndex const * const elementIndices,
138  real64 const * const weights,
139  localIndex const connectorIndex ) override;
140 
147  void addVectors( real64 const & transMultiplier,
148  real64 const (&faceNormal)[3],
149  real64 const (&cellToFaceVec)[3] );
150 
154  virtual localIndex size() const override
155  {
156  return m_elementRegionIndices.size( 0 );
157  }
158 
164  constexpr localIndex stencilSize( localIndex const index ) const
165  {
166  GEOS_UNUSED_VAR( index );
167  return maxStencilSize;
168  }
169 
172 
178 
179 private:
180 
183  array1d< real64 > m_weightMultiplier;
184 
185 };
186 
188 inline void
190  computeWeights( localIndex const iconn,
191  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
192  real64 & weight,
193  real64 (& dWeight_dCoef)[3] ) const
194 {
198 
199  // Preload data onto the stack
200  real64 faceNormal[3] = LVARRAY_TENSOROPS_INIT_LOCAL_3( m_faceNormal[iconn] );
201  real64 const cellToFace[3] = LVARRAY_TENSOROPS_INIT_LOCAL_3( m_cellToFaceVec[iconn] );
202  arraySlice1d< real64 const > const coef = coefficient[er][esr][ei][0];
203 
204  // Compute the face-cell transmissibility
205  auto const compute = [&]
206  {
207  real64 faceConormal[3];
208  LvArray::tensorOps::hadamardProduct< 3 >( faceConormal, coef, faceNormal );
209  weight = LvArray::tensorOps::AiBi< 3 >( cellToFace, faceConormal );
210  LvArray::tensorOps::hadamardProduct< 3 >( dWeight_dCoef, cellToFace, faceNormal );
211  };
212 
213  compute();
214  if( weight < 0.0 )
215  {
216  // Correct negative weight issue arising from non-K-orthogonal grids
217  // by replacing face normal with c2f vector
218  LvArray::tensorOps::copy< 3 >( faceNormal, cellToFace );
219  compute();
220  }
221 
222  // Scale by face/distance and trans multiplier
223  real64 const mult = m_weights[iconn][BoundaryStencil::Order::ELEM] * m_weightMultiplier[iconn];
224  weight *= mult;
225  LvArray::tensorOps::scale< 3 >( dWeight_dCoef, mult );
226 }
227 
228 } // namespace geos
229 
230 #endif // GEOS_FINITEVOLUME_BOUNDARYSTENCIL_HPP_
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:84
#define GEOS_FORCE_INLINE
Marks a function or lambda for inlining.
Definition: GeosxMacros.hpp:51
Provides management of the boundary stencil points (stencils used to prescribe boundary conditions on...
virtual void add(localIndex const numPts, localIndex const *const elementRegionIndices, localIndex const *const elementSubRegionIndices, localIndex const *const elementIndices, real64 const *const weights, localIndex const connectorIndex) override
Add an entry to the stencil.
BoundaryStencil()
Constructor.
virtual localIndex size() const override
Give the number of stencil entries.
void addVectors(real64 const &transMultiplier, real64 const (&faceNormal)[3], real64 const (&cellToFaceVec)[3])
Add the vectors need to compute the transmissiblity to the Stencil.
constexpr localIndex stencilSize(localIndex const index) const
Gives the number of points in a stencil entry.
KernelWrapper createKernelWrapper() const
Create an update kernel wrapper.
GEOS_HOST_DEVICE void computeWeights(localIndex const iconn, CoefficientAccessor< arrayView3d< real64 const > > const &coefficient, real64 &weight, real64(&dWeight_dCoef)[3]) const
Compute weights and derivatives w.r.t to the coefficient.
GEOS_HOST_DEVICE GEOS_FORCE_INLINE localIndex size() const
Give the number of stencil entries.
ElementRegionManager::ElementViewConst< VIEWTYPE > CoefficientAccessor
Coefficient view accessory type.
BoundaryStencilWrapper(IndexContainerType const &elementRegionIndices, IndexContainerType const &elementSubRegionIndices, IndexContainerType const &elementIndices, WeightContainerType const &weights, arrayView2d< real64, nodes::REFERENCE_POSITION_USD > const &faceNormal, arrayView2d< real64, nodes::REFERENCE_POSITION_USD > const &cellToFaceVec, arrayView1d< real64 > const &weightMultiplier)
Constructor.
GEOS_HOST_DEVICE constexpr GEOS_FORCE_INLINE localIndex stencilSize(localIndex const index) const
Give the number of points in a stencil entry.
GEOS_HOST_DEVICE constexpr GEOS_FORCE_INLINE localIndex numPointsInFlux(localIndex const index) const
Give the number of points between which the flux is.
typename ElementViewAccessor< VIEWTYPE >::NestedViewTypeConst ElementViewConst
The ElementViewAccessor at the ElementRegionManager level is the type resulting from ElementViewAcces...
Provides management of the interior stencil points when using Two-Point flux approximation.
TRAITS::IndexContainerType m_elementRegionIndices
The container for the element region indices for each point in each stencil.
TRAITS::IndexContainerViewConstType m_elementRegionIndices
The container for the element region indices for each point in each stencil.
TRAITS::IndexContainerViewConstType m_elementSubRegionIndices
The container for the element sub region indices for each point in each stencil.
TRAITS::WeightContainerViewType m_weights
The container for the weights for each point in each stencil.
TRAITS::IndexContainerViewConstType m_elementIndices
The container for the element indices for each point in each stencil.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
Array< T, 2, PERMUTATION > array2d
Alias for 2D array.
Definition: DataTypes.hpp:192
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
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:196
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:176
ArrayView< T, 3, USD > arrayView3d
Alias for 3D array view.
Definition: DataTypes.hpp:212
Defines the order of element/face in the stencil.
static constexpr localIndex ELEM
Order of element index in stencil.
static constexpr localIndex FACE
Order of face index in stencil.
CONTAINER< localIndex > IndexContainerType
The array type that will be used to store the indices of the stencil contributors.
Definition: StencilBase.hpp:44
static constexpr localIndex maxStencilSize
Maximum number of points in a stencil.
Definition: StencilBase.hpp:62
CONTAINER< real64 > WeightContainerType
The array type that is used to store the weights of the stencil contributors.
Definition: StencilBase.hpp:50
static constexpr localIndex maxNumPointsInFlux
Maximum number of points the flux.
Definition: StencilBase.hpp:59