GEOSX
EmbeddedSurfaceToCellStencil.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_EMBEDDEDSURFACETOCELLSTENCIL_HPP_
20 #define GEOS_FINITEVOLUME_EMBEDDEDSURFACETOCELLSTENCIL_HPP_
21 
22 #include "StencilBase.hpp"
23 
24 namespace geos
25 {
26 
30 class EmbeddedSurfaceToCellStencilWrapper : public StencilWrapperBase< TwoPointStencilTraits >
31 {
32 public:
33 
35  template< typename VIEWTYPE >
37 
46  IndexContainerType const & elementSubRegionIndices,
47  IndexContainerType const & elementIndices,
48  WeightContainerType const & weights );
49 
54  localIndex size() const
55  {
56  return m_elementRegionIndices.size( 0 );
57  }
58 
66  constexpr localIndex stencilSize( localIndex const index ) const
67  {
68  GEOS_UNUSED_VAR( index );
69  return maxStencilSize;
70  }
71 
79  constexpr localIndex numPointsInFlux( localIndex const index ) const
80  {
81  GEOS_UNUSED_VAR( index );
82  return maxNumPointsInFlux;
83  }
84 
94  void computeWeights( localIndex const iconn,
95  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
96  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar,
97  real64 ( &weight )[1][2],
98  real64 ( &dWeight_dVar )[1][2] ) const;
99 
109  void computeWeights( localIndex iconn,
110  real64 ( &weight )[1][2],
111  real64 ( &dWeight_dVar )[1][2] ) const;
112 
124  void computeWeights( localIndex const iconn,
125  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
126  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar1,
127  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar2,
128  real64 ( &weight )[1][2],
129  real64 ( &dWeight_dVar1 )[1][2],
130  real64 ( &dWeight_dVar2 )[1][2] ) const;
131 
139  real64 ( & stabilizationWeight )[1][2] ) const
140  { GEOS_UNUSED_VAR( iconn, stabilizationWeight ); }
141 
150 
159 
160 };
161 
165 class EmbeddedSurfaceToCellStencil final : public StencilBase< TwoPointStencilTraits, EmbeddedSurfaceToCellStencil >
166 {
167 public:
168 
169  virtual void move( LvArray::MemorySpace const space ) override;
170 
171  virtual void add( localIndex const numPts,
172  localIndex const * const elementRegionIndices,
173  localIndex const * const elementSubRegionIndices,
174  localIndex const * const elementIndices,
175  real64 const * const weights,
176  localIndex const connectorIndex ) override;
177 
180 
186 
191  virtual localIndex size() const override
192  { return m_elementRegionIndices.size( 0 ); }
193 
199  constexpr localIndex stencilSize( localIndex const index ) const
200  {
201  GEOS_UNUSED_VAR( index );
202  return maxStencilSize;
203  }
204 
205 private:
206 
207 };
208 
210 inline void
213  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
214  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar,
215  real64 ( & weight )[1][2],
216  real64 ( & dWeight_dVar )[1][2] ) const
217 {
218  localIndex const er0 = m_elementRegionIndices[iconn][0];
219  localIndex const esr0 = m_elementSubRegionIndices[iconn][0];
220  localIndex const ei0 = m_elementIndices[iconn][0];
221 
222  localIndex const er1 = m_elementRegionIndices[iconn][1];
223  localIndex const esr1 = m_elementSubRegionIndices[iconn][1];
224  localIndex const ei1 = m_elementIndices[iconn][1];
225 
226  // Will change when implementing collocation points. Will use fracture normal to project the permeability
227  real64 const t0 = m_weights[iconn][0] * LvArray::tensorOps::l2Norm< 3 >( coefficient[er0][esr0][ei0][0] );
228  // We consider the 3rd component of the permeability which is the normal one.
229  real64 const t1 = m_weights[iconn][1] * coefficient[er1][esr1][ei1][0][2];
230 
231  real64 const sumOfTrans = t0+t1;
232  real64 const value = t0*t1/sumOfTrans;
233 
234  weight[0][0] = value;
235  weight[0][1] = -value;
236 
237  // We consider the 3rd component of the permeability which is the normal one.
238  real64 const dt0 = m_weights[iconn][0] * dCoeff_dVar[er0][esr0][ei0][0][0];
239  real64 const dt1 = m_weights[iconn][1] * dCoeff_dVar[er1][esr1][ei1][0][2];
240 
241  dWeight_dVar[0][0] = ( dt0 * t1 * sumOfTrans - dt0 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
242  dWeight_dVar[0][1] = ( t0 * dt1 * sumOfTrans - dt1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
243 }
244 
246 inline void
249  real64 ( & weight )[1][2],
250  real64 ( & dWeight_dVar )[1][2] ) const
251 {
252  real64 const t0 = m_weights[iconn][0];
253  real64 const t1 = m_weights[iconn][1];
254 
255  real64 const sumOfTrans = t0+t1;
256  real64 const value = t0*t1/sumOfTrans;
257 
258  weight[0][0] = value;
259  weight[0][1] = -value;
260 
261  dWeight_dVar[0][0] = 0;
262  dWeight_dVar[0][1] = 0;
263 }
264 
266 inline void
269  CoefficientAccessor< arrayView3d< real64 const > > const & coefficient,
270  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar1,
271  CoefficientAccessor< arrayView3d< real64 const > > const & dCoeff_dVar2,
272  real64 (& weight)[1][2],
273  real64 (& dWeight_dVar1 )[1][2],
274  real64 (& dWeight_dVar2 )[1][2] ) const
275 {
276  localIndex const er0 = m_elementRegionIndices[iconn][0];
277  localIndex const esr0 = m_elementSubRegionIndices[iconn][0];
278  localIndex const ei0 = m_elementIndices[iconn][0];
279 
280  localIndex const er1 = m_elementRegionIndices[iconn][1];
281  localIndex const esr1 = m_elementSubRegionIndices[iconn][1];
282  localIndex const ei1 = m_elementIndices[iconn][1];
283 
284  // Will change when implementing collocation points. Will use fracture normal to project the permeability
285  real64 const t0 = m_weights[iconn][0] * LvArray::tensorOps::l2Norm< 3 >( coefficient[er0][esr0][ei0][0] );
286  // We consider the 3rd component of the permeability which is the normal one.
287  real64 const t1 = m_weights[iconn][1] * coefficient[er1][esr1][ei1][0][2];
288 
289  real64 const sumOfTrans = t0+t1;
290  real64 const value = t0*t1/sumOfTrans;
291 
292  weight[0][0] = value;
293  weight[0][1] = -value;
294 
295  // We consider the 3rd component of the permeability which is the normal one.
296  real64 const dt0_dVar1 = m_weights[iconn][0] * dCoeff_dVar1[er0][esr0][ei0][0][0];
297  real64 const dt1_dVar1 = m_weights[iconn][1] * dCoeff_dVar1[er1][esr1][ei1][0][2];
298  real64 const dt0_dVar2 = m_weights[iconn][0] * dCoeff_dVar2[er0][esr0][ei0][0][0];
299  real64 const dt1_dVar2 = m_weights[iconn][1] * dCoeff_dVar2[er1][esr1][ei1][0][2];
300 
301  dWeight_dVar1[0][0] = ( dt0_dVar1 * t1 * sumOfTrans - dt0_dVar1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
302  dWeight_dVar1[0][1] = ( t0 * dt1_dVar1 * sumOfTrans - dt1_dVar1 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
303 
304  dWeight_dVar2[0][0] = ( dt0_dVar2 * t1 * sumOfTrans - dt0_dVar2 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
305  dWeight_dVar2[0][1] = ( t0 * dt1_dVar2 * sumOfTrans - dt1_dVar2 * t0 * t1 ) / ( sumOfTrans * sumOfTrans );
306 }
307 
309 inline void
312 {
313  // only the fracture side is modified, k=1
314  localIndex constexpr k = 1;
315  localIndex const er = m_elementRegionIndices[iconn][k];
316  localIndex const esr = m_elementSubRegionIndices[iconn][k];
317  localIndex const ei = m_elementIndices[iconn][k];
318 
319  m_weights[iconn][k] = m_weights[iconn][k] * hydraulicAperture[er][esr][ei];
320 }
321 
323 inline void
326 {
327  // only the fracture side is modified, k=1
328  localIndex constexpr k = 1;
329  localIndex const er = m_elementRegionIndices[iconn][k];
330  localIndex const esr = m_elementSubRegionIndices[iconn][k];
331  localIndex const ei = m_elementIndices[iconn][k];
332 
333  m_weights[iconn][k] = m_weights[iconn][k] / hydraulicAperture[er][esr][ei];
334 }
335 
336 } /* namespace geos */
337 
338 #endif /* GEOS_FINITEVOLUME_EMBEDDEDSURFACETOCELLSTENCIL_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...
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:220
double real64
64-bit floating point type.
Definition: DataTypes.hpp:139
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
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