GEOSX
BoundaryStencil.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 TotalEnergies
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOS_FINITEVOLUME_BOUNDARYSTENCIL_HPP_
20 #define GEOS_FINITEVOLUME_BOUNDARYSTENCIL_HPP_
21 
22 #include "StencilBase.hpp"
23 
24 namespace geos
25 {
26 
30 class BoundaryStencilWrapper : public StencilWrapperBase< TwoPointStencilTraits >
31 {
32 public:
33 
35  template< typename VIEWTYPE >
37 
48  BoundaryStencilWrapper( IndexContainerType const & elementRegionIndices,
49  IndexContainerType const & elementSubRegionIndices,
50  IndexContainerType const & elementIndices,
51  WeightContainerType const & weights,
54  arrayView1d< real64 > const & weightMultiplier );
55 
64  void computeWeights( localIndex const iconn,
65  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
66  real64 & weight,
67  real64 ( &dWeight_dCoef )[3] ) const;
68 
75  localIndex size() const
76  { return m_elementRegionIndices.size( 0 ); }
77 
85  constexpr localIndex stencilSize( localIndex const index ) const
86  {
87  GEOS_UNUSED_VAR( index );
88  return maxStencilSize;
89  }
90 
98  constexpr localIndex numPointsInFlux( localIndex const index ) const
99  {
100  GEOS_UNUSED_VAR( index );
101  return maxNumPointsInFlux;
102  }
103 
104 private:
105 
108  arrayView1d< real64 > m_weightMultiplier;
109 };
110 
115 class BoundaryStencil final : public StencilBase< TwoPointStencilTraits, BoundaryStencil >
116 {
117 public:
118 
123 
127  struct Order
128  {
129  static constexpr localIndex ELEM = 0;
130  static constexpr localIndex FACE = 1;
131  };
132 
133  virtual void add( localIndex const numPts,
134  localIndex const * const elementRegionIndices,
135  localIndex const * const elementSubRegionIndices,
136  localIndex const * const elementIndices,
137  real64 const * const weights,
138  localIndex const connectorIndex ) override;
139 
146  void addVectors( real64 const & transMultiplier,
147  real64 const (&faceNormal)[3],
148  real64 const (&cellToFaceVec)[3] );
149 
153  virtual localIndex size() const override
154  {
155  return m_elementRegionIndices.size( 0 );
156  }
157 
163  constexpr localIndex stencilSize( localIndex const index ) const
164  {
165  GEOS_UNUSED_VAR( index );
166  return maxStencilSize;
167  }
168 
171 
177 
178 private:
179 
182  array1d< real64 > m_weightMultiplier;
183 
184 };
185 
187 inline void
189  computeWeights( localIndex const iconn,
190  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
191  real64 & weight,
192  real64 (& dWeight_dCoef)[3] ) const
193 {
197 
198  // Preload data onto the stack
199  real64 faceNormal[3] = LVARRAY_TENSOROPS_INIT_LOCAL_3( m_faceNormal[iconn] );
200  real64 const cellToFace[3] = LVARRAY_TENSOROPS_INIT_LOCAL_3( m_cellToFaceVec[iconn] );
201  arraySlice1d< real64 const > const coef = coefficient[er][esr][ei][0];
202 
203  // Compute the face-cell transmissibility
204  auto const compute = [&]
205  {
206  real64 faceConormal[3];
207  LvArray::tensorOps::hadamardProduct< 3 >( faceConormal, coef, faceNormal );
208  weight = LvArray::tensorOps::AiBi< 3 >( cellToFace, faceConormal );
209  LvArray::tensorOps::hadamardProduct< 3 >( dWeight_dCoef, cellToFace, faceNormal );
210  };
211 
212  compute();
213  if( weight < 0.0 )
214  {
215  // Correct negative weight issue arising from non-K-orthogonal grids
216  // by replacing face normal with c2f vector
217  LvArray::tensorOps::copy< 3 >( faceNormal, cellToFace );
218  compute();
219  }
220 
221  // Scale by face/distance and trans multiplier
222  real64 const mult = m_weights[iconn][BoundaryStencil::Order::ELEM] * m_weightMultiplier[iconn];
223  weight *= mult;
224  LvArray::tensorOps::scale< 3 >( dWeight_dCoef, mult );
225 }
226 
227 } // namespace geos
228 
229 #endif // GEOS_FINITEVOLUME_BOUNDARYSTENCIL_HPP_
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:48
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:83
#define GEOS_FORCE_INLINE
Marks a function or lambda for inlining.
Definition: GeosxMacros.hpp:50
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:220
Array< T, 2, PERMUTATION > array2d
Alias for 2D array.
Definition: DataTypes.hpp:232
double real64
64-bit floating point type.
Definition: DataTypes.hpp:139
ArraySlice< T, 1, USD > arraySlice1d
Alias for 1D array slice.
Definition: DataTypes.hpp:224
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:236
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:216
ArrayView< T, 3, USD > arrayView3d
Alias for 3D array view.
Definition: DataTypes.hpp:252
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:43
static constexpr localIndex maxStencilSize
Maximum number of points in a stencil.
Definition: StencilBase.hpp:61
CONTAINER< real64 > WeightContainerType
The array type that is used to store the weights of the stencil contributors.
Definition: StencilBase.hpp:49
static constexpr localIndex maxNumPointsInFlux
Maximum number of points the flux.
Definition: StencilBase.hpp:58