GEOS
EmbeddedSurfaceToCellStencil.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_EMBEDDEDSURFACETOCELLSTENCIL_HPP_
21 #define GEOS_FINITEVOLUME_EMBEDDEDSURFACETOCELLSTENCIL_HPP_
22 
23 #include "StencilBase.hpp"
24 
25 namespace geos
26 {
27 
31 class EmbeddedSurfaceToCellStencilWrapper : public StencilWrapperBase< TwoPointStencilTraits >
32 {
33 public:
34 
36  template< typename VIEWTYPE >
38 
47  IndexContainerType const & elementSubRegionIndices,
48  IndexContainerType const & elementIndices,
49  WeightContainerType const & weights );
50 
55  localIndex size() const
56  {
57  return m_elementRegionIndices.size( 0 );
58  }
59 
67  constexpr localIndex stencilSize( localIndex const index ) const
68  {
69  GEOS_UNUSED_VAR( index );
70  return maxStencilSize;
71  }
72 
80  constexpr localIndex numPointsInFlux( localIndex const index ) const
81  {
82  GEOS_UNUSED_VAR( index );
83  return maxNumPointsInFlux;
84  }
85 
95  void computeWeights( localIndex const iconn,
96  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
97  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar,
98  real64 ( &weight )[1][2],
99  real64 ( &dWeight_dVar )[1][2] ) const;
100 
110  void computeWeights( localIndex iconn,
111  real64 ( &weight )[1][2],
112  real64 ( &dWeight_dVar )[1][2] ) const;
113 
125  void computeWeights( localIndex const iconn,
126  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
127  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar1,
128  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar2,
129  real64 ( &weight )[1][2],
130  real64 ( &dWeight_dVar1 )[1][2],
131  real64 ( &dWeight_dVar2 )[1][2] ) const;
132 
140  real64 ( & stabilizationWeight )[1][2] ) const
141  { GEOS_UNUSED_VAR( iconn, stabilizationWeight ); }
142 
151 
160 
161 };
162 
166 class EmbeddedSurfaceToCellStencil final : public StencilBase< TwoPointStencilTraits, EmbeddedSurfaceToCellStencil >
167 {
168 public:
169 
170  virtual void move( LvArray::MemorySpace const space ) override;
171 
172  virtual void add( localIndex const numPts,
173  localIndex const * const elementRegionIndices,
174  localIndex const * const elementSubRegionIndices,
175  localIndex const * const elementIndices,
176  real64 const * const weights,
177  localIndex const connectorIndex ) override;
178 
181 
187 
192  virtual localIndex size() const override
193  { return m_elementRegionIndices.size( 0 ); }
194 
200  constexpr localIndex stencilSize( localIndex const index ) const
201  {
202  GEOS_UNUSED_VAR( index );
203  return maxStencilSize;
204  }
205 
206 private:
207 
208 };
209 
211 inline void
214  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
215  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar,
216  real64 ( & weight )[1][2],
217  real64 ( & dWeight_dVar )[1][2] ) const
218 {
219  localIndex const er0 = m_elementRegionIndices[iconn][0];
220  localIndex const esr0 = m_elementSubRegionIndices[iconn][0];
221  localIndex const ei0 = m_elementIndices[iconn][0];
222 
223  localIndex const er1 = m_elementRegionIndices[iconn][1];
224  localIndex const esr1 = m_elementSubRegionIndices[iconn][1];
225  localIndex const ei1 = m_elementIndices[iconn][1];
226 
227  // Will change when implementing collocation points. Will use fracture normal to project the permeability
228  real64 const t0 = m_weights[iconn][0] * LvArray::tensorOps::l2Norm< 3 >( coefficient[er0][esr0][ei0][0] );
229  // We consider the 3rd component of the permeability which is the normal one.
230  real64 const t1 = m_weights[iconn][1] * coefficient[er1][esr1][ei1][0][2];
231 
232  real64 const sumOfTrans = t0+t1;
233  real64 const value = t0*t1/sumOfTrans;
234 
235  weight[0][0] = value;
236  weight[0][1] = -value;
237 
238  // We consider the 3rd component of the permeability which is the normal one.
239  real64 const dt0 = m_weights[iconn][0] * dCoeff_dVar[er0][esr0][ei0][0][0];
240  real64 const dt1 = m_weights[iconn][1] * dCoeff_dVar[er1][esr1][ei1][0][2];
241 
242  dWeight_dVar[0][0] = ( dt0 * t1 * sumOfTrans - dt0 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
243  dWeight_dVar[0][1] = ( t0 * dt1 * sumOfTrans - dt1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
244 }
245 
247 inline void
250  real64 ( & weight )[1][2],
251  real64 ( & dWeight_dVar )[1][2] ) const
252 {
253  real64 const t0 = m_weights[iconn][0];
254  real64 const t1 = m_weights[iconn][1];
255 
256  real64 const sumOfTrans = t0+t1;
257  real64 const value = t0*t1/sumOfTrans;
258 
259  weight[0][0] = value;
260  weight[0][1] = -value;
261 
262  dWeight_dVar[0][0] = 0;
263  dWeight_dVar[0][1] = 0;
264 }
265 
267 inline void
270  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
271  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar1,
272  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar2,
273  real64 (& weight)[1][2],
274  real64 (& dWeight_dVar1 )[1][2],
275  real64 (& dWeight_dVar2 )[1][2] ) const
276 {
277  localIndex const er0 = m_elementRegionIndices[iconn][0];
278  localIndex const esr0 = m_elementSubRegionIndices[iconn][0];
279  localIndex const ei0 = m_elementIndices[iconn][0];
280 
281  localIndex const er1 = m_elementRegionIndices[iconn][1];
282  localIndex const esr1 = m_elementSubRegionIndices[iconn][1];
283  localIndex const ei1 = m_elementIndices[iconn][1];
284 
285  // Will change when implementing collocation points. Will use fracture normal to project the permeability
286  real64 const t0 = m_weights[iconn][0] * LvArray::tensorOps::l2Norm< 3 >( coefficient[er0][esr0][ei0][0] );
287  // We consider the 3rd component of the permeability which is the normal one.
288  real64 const t1 = m_weights[iconn][1] * coefficient[er1][esr1][ei1][0][2];
289 
290  real64 const sumOfTrans = t0+t1;
291  real64 const value = t0*t1/sumOfTrans;
292 
293  weight[0][0] = value;
294  weight[0][1] = -value;
295 
296  // We consider the 3rd component of the permeability which is the normal one.
297  real64 const dt0_dVar1 = m_weights[iconn][0] * dCoeff_dVar1[er0][esr0][ei0][0][0];
298  real64 const dt1_dVar1 = m_weights[iconn][1] * dCoeff_dVar1[er1][esr1][ei1][0][2];
299  real64 const dt0_dVar2 = m_weights[iconn][0] * dCoeff_dVar2[er0][esr0][ei0][0][0];
300  real64 const dt1_dVar2 = m_weights[iconn][1] * dCoeff_dVar2[er1][esr1][ei1][0][2];
301 
302  dWeight_dVar1[0][0] = ( dt0_dVar1 * t1 * sumOfTrans - dt0_dVar1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
303  dWeight_dVar1[0][1] = ( t0 * dt1_dVar1 * sumOfTrans - dt1_dVar1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
304 
305  dWeight_dVar2[0][0] = ( dt0_dVar2 * t1 * sumOfTrans - dt0_dVar2 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
306  dWeight_dVar2[0][1] = ( t0 * dt1_dVar2 * sumOfTrans - dt1_dVar2 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
307 }
308 
310 inline void
313 {
314  // only the fracture side is modified, k=1
315  localIndex constexpr k = 1;
316  localIndex const er = m_elementRegionIndices[iconn][k];
317  localIndex const esr = m_elementSubRegionIndices[iconn][k];
318  localIndex const ei = m_elementIndices[iconn][k];
319 
320  m_weights[iconn][k] = m_weights[iconn][k] * hydraulicAperture[er][esr][ei];
321 }
322 
324 inline void
327 {
328  // only the fracture side is modified, k=1
329  localIndex constexpr k = 1;
330  localIndex const er = m_elementRegionIndices[iconn][k];
331  localIndex const esr = m_elementSubRegionIndices[iconn][k];
332  localIndex const ei = m_elementIndices[iconn][k];
333 
334  m_weights[iconn][k] = m_weights[iconn][k] / hydraulicAperture[er][esr][ei];
335 }
336 
337 } /* namespace geos */
338 
339 #endif /* GEOS_FINITEVOLUME_EMBEDDEDSURFACETOCELLSTENCIL_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
typename ElementViewAccessor< VIEWTYPE >::NestedViewTypeConst ElementViewConst
The ElementViewAccessor at the ElementRegionManager level is the type resulting from ElementViewAcces...
Provides management of the interior stencil points for a face elements when using Two-Point flux appr...
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.
constexpr localIndex stencilSize(localIndex const index) const
Give the number of points in a stencil entry.
virtual void move(LvArray::MemorySpace const space) override
Move the data arrays associated with the stencil to a specified memory space.
virtual localIndex size() const override
Return the stencil size.
KernelWrapper createKernelWrapper() const
Create an update kernel wrapper.
Provide access to the EmbeddedSurfaceToCellStencil that may be called from a kernel function.
GEOS_HOST_DEVICE constexpr GEOS_FORCE_INLINE localIndex stencilSize(localIndex const index) const
Give the number of stencil entries for the provided index.
ElementRegionManager::ElementViewConst< VIEWTYPE > CoefficientAccessor
Coefficient view accessory type.
EmbeddedSurfaceToCellStencilWrapper(IndexContainerType const &elementRegionIndices, IndexContainerType const &elementSubRegionIndices, IndexContainerType const &elementIndices, WeightContainerType const &weights)
Constructor.
GEOS_HOST_DEVICE void addHydraulicApertureContribution(localIndex const iconn, ElementRegionManager::ElementViewConst< arrayView1d< real64 const > > hydraulicAperture) const
Add the contribution of the aperture to the weight in the stencil (done after aperture update)
GEOS_HOST_DEVICE void removeHydraulicApertureContribution(localIndex const iconn, ElementRegionManager::ElementViewConst< arrayView1d< real64 const > > hydraulicAperture) const
Remove the contribution of the aperture from the weight in the stencil (done before aperture update)
GEOS_HOST_DEVICE void computeWeights(localIndex const iconn, CoefficientAccessor< arrayView3d< real64 const > > const &coefficient, CoefficientAccessor< arrayView3d< real64 const > > const &dCoeff_dVar, real64(&weight)[1][2], real64(&dWeight_dVar)[1][2]) const
Compute weigths and derivatives w.r.t to one variable.
GEOS_HOST_DEVICE void computeStabilizationWeights(localIndex iconn, real64(&stabilizationWeight)[1][2]) const
Compute the stabilization weights.
localIndex size() const
Give the number of stencil entries.
GEOS_HOST_DEVICE constexpr GEOS_FORCE_INLINE localIndex numPointsInFlux(localIndex const index) const
Give the number of points between which the flux is.
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
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, 3, USD > arrayView3d
Alias for 3D array view.
Definition: DataTypes.hpp:212
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