GEOS
LagrangeBasis1.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 Total, S.A
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 
16 #ifndef GEOS_FINITEELEMENT_ELEMENTFORMULATIONS_ELEMENTFORMULATIONS_LAGRANGEBASIS1_HPP_
17 #define GEOS_FINITEELEMENT_ELEMENTFORMULATIONS_ELEMENTFORMULATIONS_LAGRANGEBASIS1_HPP_
18 
23 #include "common/DataTypes.hpp"
24 
25 namespace geos
26 {
27 namespace finiteElement
28 {
29 
40 {
41 public:
43  constexpr static localIndex numSupportPoints = 2;
44 
52  constexpr static real64 weight( const int q )
53  {
54  GEOS_UNUSED_VAR( q );
55  return 1.0;
56  }
57 
66  constexpr static real64 parentSupportCoord( const localIndex supportPointIndex )
67  {
68  return -1.0 + 2.0 * (supportPointIndex & 1);
69  }
70 
80  constexpr static real64 value( const int index,
81  const real64 xi )
82  {
83  return 0.5 + 0.5 * xi * parentSupportCoord( index );
84  }
85 
86 
94  constexpr static real64 value0( const real64 xi )
95  {
96  return 0.5 - 0.5 * xi;
97  }
98 
106  constexpr static real64 value1( const real64 xi )
107  {
108  return 0.5 + 0.5 * xi;
109  }
110 
118  constexpr static real64 valueBubble( const real64 xi )
119  {
120  return 1.0 - pow( xi, 2 );
121  }
122 
123 
134  constexpr static real64 gradient( const int index,
135  const real64 xi )
136  {
137  GEOS_UNUSED_VAR( xi );
138  return 0.5 * parentSupportCoord( index );
139  }
140 
149  constexpr static real64 gradient0( const real64 xi )
150  {
151  GEOS_UNUSED_VAR( xi );
152  return -0.5;
153  }
154 
163  constexpr static real64 gradient1( const real64 xi )
164  {
165  GEOS_UNUSED_VAR( xi );
166  return 0.5;
167  }
168 
177  constexpr static real64 gradientBubble( const real64 xi )
178  {
179  return -2.0*xi;
180  }
181 
191  constexpr static real64 gradientAt( const int q,
192  const int )
193  {
194  return q == 0 ? -0.5 : 0.5;
195  }
196 
216  {
218  constexpr static localIndex numSupportPoints = 4;
219 
229  constexpr static int linearIndex( const int i,
230  const int j )
231  {
232  return i + 2 * j;
233  }
234 
244  constexpr static void multiIndex( const int linearIndex,
245  int & i0,
246  int & i1 )
247  {
248  i0 = ( linearIndex & 1 );
249  i1 = ( linearIndex & 2 ) >> 1;
250  }
251 
261  static void value( real64 const (&coords)[2],
262  real64 (& N)[numSupportPoints] )
263  {
264  for( int a=0; a<2; ++a )
265  {
266  for( int b=0; b<2; ++b )
267  {
268  const int lindex = LagrangeBasis1::TensorProduct2D::linearIndex( a, b );
269  N[ lindex ] = LagrangeBasis1::value( a, coords[0] ) *
270  LagrangeBasis1::value( b, coords[1] );
271  }
272  }
273  }
274 
284  static void valueBubble( real64 const (&coords)[2],
285  real64 (& N)[1] )
286  {
287  N[0] = LagrangeBasis1::valueBubble( coords[0] ) *
288  LagrangeBasis1::valueBubble( coords[1] );
289  }
290 
298  constexpr static real64 parentCoords0( localIndex const linearIndex )
299  {
300  return -1.0 + 2.0 * (linearIndex & 1);
301  }
302 
310  constexpr static real64 parentCoords1( localIndex const linearIndex )
311  {
312  return -1.0 + ( linearIndex & 2 );
313  }
314 
315  };
316 
339  {
341  constexpr static localIndex numSupportPoints = 8;
342 
344  constexpr static localIndex numSupportFaces = 6;
345 
356  constexpr static int linearIndex( const int i,
357  const int j,
358  const int k )
359  {
360  return i + 2 * j + 4 * k;
361  }
362 
373  constexpr static void multiIndex( const int linearIndex,
374  int & i0,
375  int & i1,
376  int & i2 )
377  {
378  i0 = ( linearIndex & 1 );
379  i1 = ( linearIndex & 2 ) >> 1;
380  i2 = ( linearIndex & 4 ) >> 2;
381  }
382 
392  static void value( real64 const (&coords)[3],
393  real64 (& N)[numSupportPoints] )
394  {
395  for( int a=0; a<2; ++a )
396  {
397  for( int b=0; b<2; ++b )
398  {
399  for( int c=0; c<2; ++c )
400  {
401  const int lindex = LagrangeBasis1::TensorProduct3D::linearIndex( a, b, c );
402  N[ lindex ] = LagrangeBasis1::value( a, coords[0] ) *
403  LagrangeBasis1::value( b, coords[1] ) *
404  LagrangeBasis1::value( c, coords[2] );
405  }
406  }
407  }
408  }
409 
419  static void valueFaceBubble( real64 const (&coords)[3],
420  real64 (& N)[numSupportFaces] )
421  {
422  N[ 0 ] = LagrangeBasis1::valueBubble( coords[0] ) *
423  LagrangeBasis1::value( 0, coords[1] ) *
424  LagrangeBasis1::valueBubble( coords[2] );
425 
426  N[ 1 ] = LagrangeBasis1::valueBubble( coords[0] ) *
427  LagrangeBasis1::valueBubble( coords[1] ) *
428  LagrangeBasis1::value( 0, coords[2] );
429 
430  N[ 2 ] = LagrangeBasis1::value( 0, coords[0] ) *
431  LagrangeBasis1::valueBubble( coords[1] ) *
432  LagrangeBasis1::valueBubble( coords[2] );
433 
434  N[ 3 ] = LagrangeBasis1::value( 1, coords[0] ) *
435  LagrangeBasis1::valueBubble( coords[1] ) *
436  LagrangeBasis1::valueBubble( coords[2] );
437 
438  N[ 4 ] = LagrangeBasis1::valueBubble( coords[0] ) *
439  LagrangeBasis1::value( 1, coords[1] ) *
440  LagrangeBasis1::valueBubble( coords[2] );
441 
442  N[ 5 ] = LagrangeBasis1::valueBubble( coords[0] ) *
443  LagrangeBasis1::valueBubble( coords[1] ) *
444  LagrangeBasis1::value( 1, coords[2] );
445  }
446 
456  static void gradientFaceBubble( real64 const (&coords)[3],
457  real64 (& dNdXi)[numSupportFaces][3] )
458  {
459  dNdXi[0][0] = LagrangeBasis1::gradientBubble( coords[0] ) *
460  LagrangeBasis1::value( 0, coords[1] ) *
461  LagrangeBasis1::valueBubble( coords[2] );
462  dNdXi[0][1] = LagrangeBasis1::valueBubble( coords[0] ) *
463  LagrangeBasis1::gradient( 0, coords[1] ) *
464  LagrangeBasis1::valueBubble( coords[2] );
465  dNdXi[0][2] = LagrangeBasis1::valueBubble( coords[0] ) *
466  LagrangeBasis1::value( 0, coords[1] ) *
467  LagrangeBasis1::gradientBubble( coords[2] );
468 
469  dNdXi[1][0] = LagrangeBasis1::gradientBubble( coords[0] ) *
470  LagrangeBasis1::valueBubble( coords[1] ) *
471  LagrangeBasis1::value( 0, coords[2] );
472  dNdXi[1][1] = LagrangeBasis1::valueBubble( coords[0] ) *
473  LagrangeBasis1::gradientBubble( coords[1] ) *
474  LagrangeBasis1::value( 0, coords[2] );
475  dNdXi[1][2] = LagrangeBasis1::valueBubble( coords[0] ) *
476  LagrangeBasis1::valueBubble( coords[1] ) *
477  LagrangeBasis1::gradient( 0, coords[2] );
478 
479  dNdXi[2][0] = LagrangeBasis1::gradient( 0, coords[0] ) *
480  LagrangeBasis1::valueBubble( coords[1] ) *
481  LagrangeBasis1::valueBubble( coords[2] );
482  dNdXi[2][1] = LagrangeBasis1::value( 0, coords[0] ) *
483  LagrangeBasis1::gradientBubble( coords[1] ) *
484  LagrangeBasis1::valueBubble( coords[2] );
485  dNdXi[2][2] = LagrangeBasis1::value( 0, coords[0] ) *
486  LagrangeBasis1::valueBubble( coords[1] ) *
487  LagrangeBasis1::gradientBubble( coords[2] );
488 
489  dNdXi[3][0] = LagrangeBasis1::gradient( 1, coords[0] ) *
490  LagrangeBasis1::valueBubble( coords[1] ) *
491  LagrangeBasis1::valueBubble( coords[2] );
492  dNdXi[3][1] = LagrangeBasis1::value( 1, coords[0] ) *
493  LagrangeBasis1::gradientBubble( coords[1] ) *
494  LagrangeBasis1::valueBubble( coords[2] );
495  dNdXi[3][2] = LagrangeBasis1::value( 1, coords[0] ) *
496  LagrangeBasis1::valueBubble( coords[1] ) *
497  LagrangeBasis1::gradientBubble( coords[2] );
498 
499  dNdXi[4][0] = LagrangeBasis1::gradientBubble( coords[0] ) *
500  LagrangeBasis1::value( 1, coords[1] ) *
501  LagrangeBasis1::valueBubble( coords[2] );
502  dNdXi[4][1] = LagrangeBasis1::valueBubble( coords[0] ) *
503  LagrangeBasis1::gradient( 1, coords[1] ) *
504  LagrangeBasis1::valueBubble( coords[2] );
505  dNdXi[4][2] = LagrangeBasis1::valueBubble( coords[0] ) *
506  LagrangeBasis1::value( 1, coords[1] ) *
507  LagrangeBasis1::gradientBubble( coords[2] );
508 
509  dNdXi[5][0] = LagrangeBasis1::gradientBubble( coords[0] ) *
510  LagrangeBasis1::valueBubble( coords[1] ) *
511  LagrangeBasis1::value( 1, coords[2] );
512  dNdXi[5][1] = LagrangeBasis1::valueBubble( coords[0] ) *
513  LagrangeBasis1::gradientBubble( coords[1] ) *
514  LagrangeBasis1::value( 1, coords[2] );
515  dNdXi[5][2] = LagrangeBasis1::valueBubble( coords[0] ) *
516  LagrangeBasis1::valueBubble( coords[1] ) *
517  LagrangeBasis1::gradient( 1, coords[2] );
518  }
519 
527  constexpr static real64 parentCoords0( localIndex const linearIndex )
528  {
529  return -1.0 + 2.0 * (linearIndex & 1);
530  }
531 
539  constexpr static real64 parentCoords1( localIndex const linearIndex )
540  {
541  return -1.0 + ( linearIndex & 2 );
542  }
543 
551  constexpr static real64 parentCoords2( localIndex const linearIndex )
552  {
553  return -1.0 + 0.5 * ( linearIndex & 4 );
554  }
555 
556  };
557 
558 };
559 
560 }
561 }
562 
563 
564 #endif /* GEOS_FINITEELEMENT_ELEMENTFORMULATIONS_ELEMENTFORMULATIONS_LAGRANGEBASIS1_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
constexpr static localIndex numSupportPoints
The number of support points for the basis.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 gradientBubble(const real64 xi)
The gradient of the bubble basis function for support point 1 evaluated at a point along the axes.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 gradient1(const real64 xi)
The gradient of the basis function for support point 1 evaluated at a point along the axes.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 valueBubble(const real64 xi)
The value of the bubble basis function.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 gradient0(const real64 xi)
The gradient of the basis function for support point 0 evaluated at a point along the axes.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 gradient(const int index, const real64 xi)
The gradient of the basis function for a support point evaluated at a point along the axes.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 gradientAt(const int q, const int)
The gradient of the basis function for a support point evaluated at a given support point....
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 weight(const int q)
The value of the weight for the given support point.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 value0(const real64 xi)
The value of the basis function for the 0 support point.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 parentSupportCoord(const localIndex supportPointIndex)
Calculate the parent coordinates for the xi0 direction, given the linear index of a support point.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 value1(const real64 xi)
The value of the basis function for the 1 support point.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 value(const int index, const real64 xi)
The value of the basis function for a support point evaluated at a point along the axes.
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
GEOS_HOST_DEVICE static GEOS_FORCE_INLINE void valueBubble(real64 const (&coords)[2], real64(&N)[1])
The value of the bubble basis function evaluated at a point along the axes.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE int linearIndex(const int i, const int j)
Calculates the linear index for support/quadrature points from ijk coordinates.
GEOS_HOST_DEVICE static GEOS_FORCE_INLINE void value(real64 const (&coords)[2], real64(&N)[numSupportPoints])
The value of the basis function for a support point evaluated at a point along the axes.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE void multiIndex(const int linearIndex, int &i0, int &i1)
Calculate the Cartesian/TensorProduct index given the linear index of a support point.
constexpr static localIndex numSupportPoints
The number of support points in the basis.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 parentCoords1(localIndex const linearIndex)
The parent coordinates for a support point in the xi1 direction.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 parentCoords0(localIndex const linearIndex)
The parent coordinates for a support point in the xi0 direction.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 parentCoords2(localIndex const linearIndex)
The parent coordinates for a support point in the xi2 direction.
constexpr static localIndex numSupportPoints
The number of support points in the basis.
GEOS_HOST_DEVICE static GEOS_FORCE_INLINE void value(real64 const (&coords)[3], real64(&N)[numSupportPoints])
The value of the basis function for a support point evaluated at a point along the axes.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 parentCoords1(localIndex const linearIndex)
The parent coordinates for a support point in the xi1 direction.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE void multiIndex(const int linearIndex, int &i0, int &i1, int &i2)
Calculate the Cartesian/TensorProduct index given the linear index of a support point.
GEOS_HOST_DEVICE static GEOS_FORCE_INLINE void gradientFaceBubble(real64 const (&coords)[3], real64(&dNdXi)[numSupportFaces][3])
The value of the bubble basis function derivatives for a support face evaluated at a point along the ...
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE int linearIndex(const int i, const int j, const int k)
Calculates the linear index for support/quadrature points from ijk coordinates.
GEOS_HOST_DEVICE static GEOS_FORCE_INLINE void valueFaceBubble(real64 const (&coords)[3], real64(&N)[numSupportFaces])
The value of the bubble basis function for a support face evaluated at a point along the axes.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 parentCoords0(localIndex const linearIndex)
The parent coordinates for a support point in the xi0 direction.
constexpr static localIndex numSupportFaces
The number of support faces in the basis.