GEOS
FaceElementToCellStencil.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_FACEELEMENTTOCELLSTENCIL_HPP_
21 #define GEOS_FINITEVOLUME_FACEELEMENTTOCELLSTENCIL_HPP_
22 
23 #include "StencilBase.hpp"
24 
25 namespace geos
26 {
27 
31 class FaceElementToCellStencilWrapper : public StencilWrapperBase< TwoPointStencilTraits >
32 {
33 public:
34 
36  template< typename VIEWTYPE >
38 
49  FaceElementToCellStencilWrapper( IndexContainerType const & elementRegionIndices,
50  IndexContainerType const & elementSubRegionIndices,
51  IndexContainerType const & elementIndices,
52  WeightContainerType const & weights,
53  arrayView2d< real64 > const & faceNormal,
54  arrayView2d< real64 > const & cellToFaceVec,
55  arrayView1d< real64 > const & transMultiplier );
56 
63  localIndex size() const
64  {
65  return m_elementRegionIndices.size( 0 );
66  }
67 
75  constexpr localIndex stencilSize( localIndex index ) const
76  {
77  GEOS_UNUSED_VAR( index );
78  return maxStencilSize;
79  }
80 
88  constexpr localIndex numPointsInFlux( localIndex index ) const
89  {
90  GEOS_UNUSED_VAR( index );
91  return maxNumPointsInFlux;
92  }
93 
103  void computeWeights( localIndex iconn,
104  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
105  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar,
106  real64 ( &weight )[1][2],
107  real64 ( &dWeight_dVar )[1][2] ) const;
108 
118  void computeWeights( localIndex iconn,
119  real64 ( &weight )[1][2],
120  real64 ( &dWeight_dVar )[1][2] ) const;
121 
133  void computeWeights( localIndex iconn,
134  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
135  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar1,
136  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar2,
137  real64 ( &weight )[1][2],
138  real64 ( &dWeight_dVar1 )[1][2],
139  real64 ( &dWeight_dVar2 )[1][2] ) const;
140 
148  real64 ( & stabilizationWeight )[1][2] ) const
149  { GEOS_UNUSED_VAR( iconn, stabilizationWeight ); }
150 
159 
168 
169 private:
170 
172  arrayView2d< real64 > m_faceNormal;
173 
175  arrayView2d< real64 > m_cellToFaceVec;
176 
178  arrayView1d< real64 > m_transMultiplier;
179 };
180 
186 class FaceElementToCellStencil final : public StencilBase< TwoPointStencilTraits, FaceElementToCellStencil >
187 {
188 public:
189 
194 
195  virtual void move( LvArray::MemorySpace const space ) override;
196 
197  virtual void add( localIndex const numPts,
198  localIndex const * const elementRegionIndices,
199  localIndex const * const elementSubRegionIndices,
200  localIndex const * const elementIndices,
201  real64 const * const weights,
202  localIndex const connectorIndex ) override;
203 
210  void addVectors( real64 const & transMultiplier,
211  real64 const (&faceNormal)[3],
212  real64 const (&cellToFaceVec)[3] );
213 
216 
222 
227  virtual localIndex size() const override
228  { return m_elementRegionIndices.size( 0 ); }
229 
234  virtual void reserve( localIndex const size ) override;
235 
241  constexpr localIndex stencilSize( localIndex index ) const
242  {
243  GEOS_UNUSED_VAR( index );
244  return maxStencilSize;
245  }
246 
247 private:
248 
249  array2d< real64 > m_faceNormal;
250  array2d< real64 > m_cellToFaceVec;
251  array1d< real64 > m_transMultiplier;
252 };
253 
256  computeWeights( localIndex const iconn,
257  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
258  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar,
259  real64 ( & weight )[1][2],
260  real64 ( & dWeight_dVar )[1][2] ) const
261 {
262  localIndex const er0 = m_elementRegionIndices[iconn][0];
263  localIndex const esr0 = m_elementSubRegionIndices[iconn][0];
264  localIndex const ei0 = m_elementIndices[iconn][0];
265 
266  localIndex const er1 = m_elementRegionIndices[iconn][1];
267  localIndex const esr1 = m_elementSubRegionIndices[iconn][1];
268  localIndex const ei1 = m_elementIndices[iconn][1];
269 
270  real64 faceConormal[3];
271 
272  // Will change when implementing collocation points.
273  LvArray::tensorOps::hadamardProduct< 3 >( faceConormal, coefficient[er0][esr0][ei0][0], m_faceNormal[iconn] );
274  real64 t0 = m_weights[iconn][0] * LvArray::tensorOps::AiBi< 3 >( m_cellToFaceVec[iconn], faceConormal );
275  if( t0 < 0.0 )
276  {
277  LvArray::tensorOps::hadamardProduct< 3 >( faceConormal,
278  coefficient[er0][esr0][ei0][0],
279  m_cellToFaceVec[iconn] );
280  t0 = m_weights[iconn][0] * LvArray::tensorOps::AiBi< 3 >( m_cellToFaceVec[iconn], faceConormal );
281  }
282 
283  // We consider the 3rd component of the permeability which is the normal one.
284  real64 const t1 = m_weights[iconn][1] * coefficient[er1][esr1][ei1][0][2];
285 
286  real64 const sumOfTrans = t0+t1;
287  real64 const value = m_transMultiplier[iconn]*t0*t1/sumOfTrans;
288 
289  weight[0][0] = value;
290  weight[0][1] = -value;
291 
292  // We consider the 3rd component of the permeability which is the normal one.
293  real64 const dt0 = m_weights[iconn][0] * dCoeff_dVar[er0][esr0][ei0][0][0];
294  real64 const dt1 = m_weights[iconn][1] * dCoeff_dVar[er1][esr1][ei1][0][2];
295 
296  dWeight_dVar[0][0] = m_transMultiplier[iconn] * ( dt0 * t1 * sumOfTrans - dt0 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
297  dWeight_dVar[0][1] = m_transMultiplier[iconn] * ( t0 * dt1 * sumOfTrans - dt1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
298 }
299 
301 inline void
304  real64 ( & weight )[1][2],
305  real64 ( & dWeight_dVar )[1][2] ) const
306 {
307  // Will change when implementing collocation points.
308  real64 const t0 = m_weights[iconn][0] * LvArray::tensorOps::AiBi< 3 >( m_cellToFaceVec[iconn], m_faceNormal[iconn] );
309  real64 const t1 = m_weights[iconn][1];
310 
311  real64 const sumOfTrans = t0+t1;
312  real64 const value = m_transMultiplier[iconn]*t0*t1/sumOfTrans;
313 
314  weight[0][0] = value;
315  weight[0][1] = -value;
316 
317  dWeight_dVar[0][0] = 0.0;
318  dWeight_dVar[0][1] = 0.0;
319 }
320 
322 inline void
324  computeWeights( localIndex const iconn,
325  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
326  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar1,
327  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar2,
328  real64 (& weight)[1][2],
329  real64 (& dWeight_dVar1 )[1][2],
330  real64 (& dWeight_dVar2 )[1][2] ) const
331 {
332  localIndex const er0 = m_elementRegionIndices[iconn][0];
333  localIndex const esr0 = m_elementSubRegionIndices[iconn][0];
334  localIndex const ei0 = m_elementIndices[iconn][0];
335 
336  localIndex const er1 = m_elementRegionIndices[iconn][1];
337  localIndex const esr1 = m_elementSubRegionIndices[iconn][1];
338  localIndex const ei1 = m_elementIndices[iconn][1];
339 
340  real64 faceConormal[3];
341 
342  // Will change when implementing collocation points.
343  LvArray::tensorOps::hadamardProduct< 3 >( faceConormal, coefficient[er0][esr0][ei0][0], m_faceNormal[iconn] );
344  real64 t0 = m_weights[iconn][0] * LvArray::tensorOps::AiBi< 3 >( m_cellToFaceVec[iconn], faceConormal );
345  if( t0 < 0.0 )
346  {
347  LvArray::tensorOps::hadamardProduct< 3 >( faceConormal,
348  coefficient[er0][esr0][ei0][0],
349  m_cellToFaceVec[iconn] );
350  t0 = m_weights[iconn][0] * LvArray::tensorOps::AiBi< 3 >( m_cellToFaceVec[iconn], faceConormal );
351  }
352  // We consider the 3rd component of the permeability which is the normal one.
353  real64 const t1 = m_weights[iconn][1] * coefficient[er1][esr1][ei1][0][2];
354 
355  real64 const sumOfTrans = t0+t1;
356  real64 const value = m_transMultiplier[iconn]*t0*t1/sumOfTrans;
357 
358  weight[0][0] = value;
359  weight[0][1] = -value;
360 
361  // We consider the 3rd component of the permeability which is the normal one.
362  real64 const dt0_dVar1 = m_weights[iconn][0] * dCoeff_dVar1[er0][esr0][ei0][0][0];
363  real64 const dt1_dVar1 = m_weights[iconn][1] * dCoeff_dVar1[er1][esr1][ei1][0][2];
364  real64 const dt0_dVar2 = m_weights[iconn][0] * dCoeff_dVar2[er0][esr0][ei0][0][0];
365  real64 const dt1_dVar2 = m_weights[iconn][1] * dCoeff_dVar2[er1][esr1][ei1][0][2];
366 
367  dWeight_dVar1[0][0] = m_transMultiplier[iconn] * ( dt0_dVar1 * t1 * sumOfTrans - dt0_dVar1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
368  dWeight_dVar1[0][1] = m_transMultiplier[iconn] * ( t0 * dt1_dVar1 * sumOfTrans - dt1_dVar1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
369 
370  dWeight_dVar2[0][0] = m_transMultiplier[iconn] * ( dt0_dVar2 * t1 * sumOfTrans - dt0_dVar2 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
371  dWeight_dVar2[0][1] = m_transMultiplier[iconn] * ( t0 * dt1_dVar2 * sumOfTrans - dt1_dVar2 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
372 }
373 
375 inline void
378 {
379  // only the fracture side is modified, k=1
380  localIndex constexpr k = 1;
381  localIndex const er = m_elementRegionIndices[iconn][k];
382  localIndex const esr = m_elementSubRegionIndices[iconn][k];
383  localIndex const ei = m_elementIndices[iconn][k];
384 
385  m_weights[iconn][k] = m_weights[iconn][k] * hydraulicAperture[er][esr][ei];
386 }
387 
389 inline void
392 {
393  // only the fracture side is modified, k=1
394  localIndex constexpr k = 1;
395  localIndex const er = m_elementRegionIndices[iconn][k];
396  localIndex const esr = m_elementSubRegionIndices[iconn][k];
397  localIndex const ei = m_elementIndices[iconn][k];
398 
399  m_weights[iconn][k] = m_weights[iconn][k] / hydraulicAperture[er][esr][ei];
400 }
401 
402 } /* namespace geos */
403 
404 #endif /* GEOS_FINITEVOLUME_FACEELEMENTTOCELLSTENCIL_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...
virtual localIndex size() const override
Return the stencil size.
KernelWrapper createKernelWrapper() const
Create an update kernel wrapper.
virtual void reserve(localIndex const size) override
Reserve the size of the stencil.
void addVectors(real64 const &transMultiplier, real64 const (&faceNormal)[3], real64 const (&cellToFaceVec)[3])
Adds the vectors need to compute weights needed in kernels.
virtual void move(LvArray::MemorySpace const space) override
Move the data arrays associated with the stencil to a specified memory space.
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 index) const
Give the number of points in a stencil entry.
FaceElementToCellStencil()
Default constructor.
Provides access to the FaceElementToCellStencil that may be called from a kernel function.
GEOS_HOST_DEVICE constexpr GEOS_FORCE_INLINE localIndex stencilSize(localIndex index) const
Give the number of stencil entries for the provided index.
FaceElementToCellStencilWrapper(IndexContainerType const &elementRegionIndices, IndexContainerType const &elementSubRegionIndices, IndexContainerType const &elementIndices, WeightContainerType const &weights, arrayView2d< real64 > const &faceNormal, arrayView2d< real64 > const &cellToFaceVec, arrayView1d< real64 > const &transMultiplier)
Constructor.
GEOS_HOST_DEVICE GEOS_FORCE_INLINE localIndex size() const
Give the number of stencil entries.
GEOS_HOST_DEVICE void computeWeights(localIndex 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 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)
ElementRegionManager::ElementViewConst< VIEWTYPE > CoefficientAccessor
Coefficient view accessory type.
GEOS_HOST_DEVICE void computeStabilizationWeights(localIndex iconn, real64(&stabilizationWeight)[1][2]) const
Compute the stabilization weights.
GEOS_HOST_DEVICE constexpr GEOS_FORCE_INLINE localIndex numPointsInFlux(localIndex index) const
Give the number of points between which the flux is.
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)
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:179
Array< T, 2, PERMUTATION > array2d
Alias for 2D array.
Definition: DataTypes.hpp:191
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:195
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:175
ArrayView< T, 3, USD > arrayView3d
Alias for 3D array view.
Definition: DataTypes.hpp:211
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