GEOSX
FaceElementToCellStencil.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_FACEELEMENTTOCELLSTENCIL_HPP_
20 #define GEOS_FINITEVOLUME_FACEELEMENTTOCELLSTENCIL_HPP_
21 
22 #include "StencilBase.hpp"
23 
24 namespace geos
25 {
26 
30 class FaceElementToCellStencilWrapper : public StencilWrapperBase< TwoPointStencilTraits >
31 {
32 public:
33 
35  template< typename VIEWTYPE >
37 
48  FaceElementToCellStencilWrapper( IndexContainerType const & elementRegionIndices,
49  IndexContainerType const & elementSubRegionIndices,
50  IndexContainerType const & elementIndices,
51  WeightContainerType const & weights,
52  arrayView2d< real64 > const & faceNormal,
53  arrayView2d< real64 > const & cellToFaceVec,
54  arrayView1d< real64 > const & transMultiplier );
55 
62  localIndex size() const
63  {
64  return m_elementRegionIndices.size( 0 );
65  }
66 
74  constexpr localIndex stencilSize( localIndex index ) const
75  {
76  GEOS_UNUSED_VAR( index );
77  return maxStencilSize;
78  }
79 
87  constexpr localIndex numPointsInFlux( localIndex index ) const
88  {
89  GEOS_UNUSED_VAR( index );
90  return maxNumPointsInFlux;
91  }
92 
102  void computeWeights( localIndex iconn,
103  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
104  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar,
105  real64 ( &weight )[1][2],
106  real64 ( &dWeight_dVar )[1][2] ) const;
107 
117  void computeWeights( localIndex iconn,
118  real64 ( &weight )[1][2],
119  real64 ( &dWeight_dVar )[1][2] ) const;
120 
132  void computeWeights( localIndex iconn,
133  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
134  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar1,
135  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar2,
136  real64 ( &weight )[1][2],
137  real64 ( &dWeight_dVar1 )[1][2],
138  real64 ( &dWeight_dVar2 )[1][2] ) const;
139 
147  real64 ( & stabilizationWeight )[1][2] ) const
148  { GEOS_UNUSED_VAR( iconn, stabilizationWeight ); }
149 
158 
167 
168 private:
169 
171  arrayView2d< real64 > m_faceNormal;
172 
174  arrayView2d< real64 > m_cellToFaceVec;
175 
177  arrayView1d< real64 > m_transMultiplier;
178 };
179 
185 class FaceElementToCellStencil final : public StencilBase< TwoPointStencilTraits, FaceElementToCellStencil >
186 {
187 public:
188 
193 
194  virtual void move( LvArray::MemorySpace const space ) override;
195 
196  virtual void add( localIndex const numPts,
197  localIndex const * const elementRegionIndices,
198  localIndex const * const elementSubRegionIndices,
199  localIndex const * const elementIndices,
200  real64 const * const weights,
201  localIndex const connectorIndex ) override;
202 
209  void addVectors( real64 const & transMultiplier,
210  real64 const (&faceNormal)[3],
211  real64 const (&cellToFaceVec)[3] );
212 
215 
221 
226  virtual localIndex size() const override
227  { return m_elementRegionIndices.size( 0 ); }
228 
233  virtual void reserve( localIndex const size ) override;
234 
240  constexpr localIndex stencilSize( localIndex index ) const
241  {
242  GEOS_UNUSED_VAR( index );
243  return maxStencilSize;
244  }
245 
246 private:
247 
248  array2d< real64 > m_faceNormal;
249  array2d< real64 > m_cellToFaceVec;
250  array1d< real64 > m_transMultiplier;
251 };
252 
255  computeWeights( localIndex const iconn,
256  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
257  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar,
258  real64 ( & weight )[1][2],
259  real64 ( & dWeight_dVar )[1][2] ) const
260 {
261  localIndex const er0 = m_elementRegionIndices[iconn][0];
262  localIndex const esr0 = m_elementSubRegionIndices[iconn][0];
263  localIndex const ei0 = m_elementIndices[iconn][0];
264 
265  localIndex const er1 = m_elementRegionIndices[iconn][1];
266  localIndex const esr1 = m_elementSubRegionIndices[iconn][1];
267  localIndex const ei1 = m_elementIndices[iconn][1];
268 
269  real64 faceConormal[3];
270 
271  // Will change when implementing collocation points.
272  LvArray::tensorOps::hadamardProduct< 3 >( faceConormal, coefficient[er0][esr0][ei0][0], m_faceNormal[iconn] );
273  real64 const t0 = m_weights[iconn][0] * LvArray::tensorOps::AiBi< 3 >( m_cellToFaceVec[iconn], faceConormal );
274  // We consider the 3rd component of the permeability which is the normal one.
275  real64 const t1 = m_weights[iconn][1] * coefficient[er1][esr1][ei1][0][2];
276 
277  real64 const sumOfTrans = t0+t1;
278  real64 const value = m_transMultiplier[iconn]*t0*t1/sumOfTrans;
279 
280  weight[0][0] = value;
281  weight[0][1] = -value;
282 
283  // We consider the 3rd component of the permeability which is the normal one.
284  real64 const dt0 = m_weights[iconn][0] * dCoeff_dVar[er0][esr0][ei0][0][0];
285  real64 const dt1 = m_weights[iconn][1] * dCoeff_dVar[er1][esr1][ei1][0][2];
286 
287  dWeight_dVar[0][0] = ( dt0 * t1 * sumOfTrans - dt0 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
288  dWeight_dVar[0][1] = ( t0 * dt1 * sumOfTrans - dt1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
289 }
290 
292 inline void
295  real64 ( & weight )[1][2],
296  real64 ( & dWeight_dVar )[1][2] ) const
297 {
298  // Will change when implementing collocation points.
299  real64 const t0 = m_weights[iconn][0] * LvArray::tensorOps::AiBi< 3 >( m_cellToFaceVec[iconn], m_faceNormal[iconn] );
300  real64 const t1 = m_weights[iconn][1];
301 
302  real64 const sumOfTrans = t0+t1;
303  real64 const value = m_transMultiplier[iconn]*t0*t1/sumOfTrans;
304 
305  weight[0][0] = value;
306  weight[0][1] = -value;
307 
308  dWeight_dVar[0][0] = 0.0;
309  dWeight_dVar[0][1] = 0.0;
310 }
311 
313 inline void
315  computeWeights( localIndex const iconn,
316  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
317  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar1,
318  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar2,
319  real64 (& weight)[1][2],
320  real64 (& dWeight_dVar1 )[1][2],
321  real64 (& dWeight_dVar2 )[1][2] ) const
322 {
323  localIndex const er0 = m_elementRegionIndices[iconn][0];
324  localIndex const esr0 = m_elementSubRegionIndices[iconn][0];
325  localIndex const ei0 = m_elementIndices[iconn][0];
326 
327  localIndex const er1 = m_elementRegionIndices[iconn][1];
328  localIndex const esr1 = m_elementSubRegionIndices[iconn][1];
329  localIndex const ei1 = m_elementIndices[iconn][1];
330 
331  real64 faceConormal[3];
332 
333  // Will change when implementing collocation points.
334  LvArray::tensorOps::hadamardProduct< 3 >( faceConormal, coefficient[er0][esr0][ei0][0], m_faceNormal[iconn] );
335  real64 const t0 = m_weights[iconn][0] * LvArray::tensorOps::AiBi< 3 >( m_cellToFaceVec[iconn], faceConormal );
336  // We consider the 3rd component of the permeability which is the normal one.
337  real64 const t1 = m_weights[iconn][1] * coefficient[er1][esr1][ei1][0][2];
338 
339  real64 const sumOfTrans = t0+t1;
340  real64 const value = m_transMultiplier[iconn]*t0*t1/sumOfTrans;
341 
342  weight[0][0] = value;
343  weight[0][1] = -value;
344 
345  // We consider the 3rd component of the permeability which is the normal one.
346  real64 const dt0_dVar1 = m_weights[iconn][0] * dCoeff_dVar1[er0][esr0][ei0][0][0];
347  real64 const dt1_dVar1 = m_weights[iconn][1] * dCoeff_dVar1[er1][esr1][ei1][0][2];
348  real64 const dt0_dVar2 = m_weights[iconn][0] * dCoeff_dVar2[er0][esr0][ei0][0][0];
349  real64 const dt1_dVar2 = m_weights[iconn][1] * dCoeff_dVar2[er1][esr1][ei1][0][2];
350 
351  dWeight_dVar1[0][0] = ( dt0_dVar1 * t1 * sumOfTrans - dt0_dVar1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
352  dWeight_dVar1[0][1] = ( t0 * dt1_dVar1 * sumOfTrans - dt1_dVar1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
353 
354  dWeight_dVar2[0][0] = ( dt0_dVar2 * t1 * sumOfTrans - dt0_dVar2 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
355  dWeight_dVar2[0][1] = ( t0 * dt1_dVar2 * sumOfTrans - dt1_dVar2 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
356 }
357 
359 inline void
362 {
363  // only the fracture side is modified, k=1
364  localIndex constexpr k = 1;
365  localIndex const er = m_elementRegionIndices[iconn][k];
366  localIndex const esr = m_elementSubRegionIndices[iconn][k];
367  localIndex const ei = m_elementIndices[iconn][k];
368 
369  m_weights[iconn][k] = m_weights[iconn][k] * hydraulicAperture[er][esr][ei];
370 }
371 
373 inline void
376 {
377  // only the fracture side is modified, k=1
378  localIndex constexpr k = 1;
379  localIndex const er = m_elementRegionIndices[iconn][k];
380  localIndex const esr = m_elementSubRegionIndices[iconn][k];
381  localIndex const ei = m_elementIndices[iconn][k];
382 
383  m_weights[iconn][k] = m_weights[iconn][k] / hydraulicAperture[er][esr][ei];
384 }
385 
386 } /* namespace geos */
387 
388 #endif /* GEOS_FINITEVOLUME_FACEELEMENTTOCELLSTENCIL_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
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: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
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
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