GEOS
LagrangeBasis2.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_LAGRANGEBASIS2_HPP_
17 #define GEOS_FINITEELEMENT_ELEMENTFORMULATIONS_ELEMENTFORMULATIONS_LAGRANGEBASIS2_HPP_
22 #include "common/DataTypes.hpp"
23 
24 namespace geos
25 {
26 namespace finiteElement
27 {
28 
39 {
40 public:
42  constexpr static localIndex numSupportPoints = 3;
43 
51  constexpr static real64 weight( const int q )
52  {
53  switch( q )
54  {
55  case 0:
56  case 2:
57  return 1.0/3.0;
58  default:
59  return 4.0/3.0;
60  }
61  }
62 
71  constexpr static real64 parentSupportCoord( const localIndex supportPointIndex )
72  {
73  switch( supportPointIndex )
74  {
75  case 0:
76  return -1.0;
77  break;
78  case 2:
79  return 1.0;
80  case 1:
81  default:
82  return 0.0;
83  }
84  }
85 
95  constexpr static real64 value( const int index,
96  const real64 xi )
97  {
98 
99  switch( index )
100  {
101  case 0:
102  return value0( xi );
103  case 2:
104  return value2( xi );
105  case 1:
106  default:
107  return value1( xi );
108  }
109  }
110 
118  constexpr static real64 value0( const real64 xi )
119  {
120  const real64 xi_div2 = 0.5 * xi;
121  return -xi_div2 + xi_div2 * xi;
122  }
123 
131  constexpr static real64 value1( const real64 xi )
132  {
133  return 1.0 - xi * xi;
134  }
135 
143  constexpr static real64 value2( const real64 xi )
144  {
145  const real64 xi_div2 = 0.5 * xi;
146  return xi_div2 + xi_div2 * xi;
147  }
148 
157  constexpr static real64 gradient0( const real64 xi )
158  {
159  return -0.5 + xi;
160  }
161 
170  constexpr static real64 gradient1( const real64 xi )
171  {
172  return -2 * xi;
173  }
174 
183  constexpr static real64 gradient2( const real64 xi )
184  {
185  return 0.5 + xi;
186  }
187 
197  constexpr static real64 gradient( const int index,
198  const real64 xi )
199  {
200  switch( index )
201  {
202  case 0:
203  return gradient0( xi );
204  case 2:
205  return gradient2( xi );
206  case 1:
207  default:
208  return gradient1( xi );
209  }
210  }
211 
221  constexpr static real64 gradientAt( const int q,
222  const int p )
223  {
224  switch( q )
225  {
226  case 0:
227  return p == 0 ? -1.5 : -0.5;
228  case 1:
229  return p == 0 ? 2.0 : 0.0;
230  case 2:
231  return p == 0 ? -0.5 : 0.5;
232  default:
233  return 0;
234  }
235  }
236 
262  {
263 
265  constexpr static localIndex numSupportPoints = 9;
266 
276  constexpr static int linearIndex( const int i,
277  const int j )
278  {
279  return i + 3 * j;
280  }
281 
282 
283 
293  constexpr static void multiIndex( const int linearIndex,
294  int & i0,
295  int & i1 )
296  {
297 
298  i1 = ( ( linearIndex * 22 ) >> 6 );
299  //i1 = a/3;
300 
301  i0 = linearIndex - i1 * 3;
302  }
303 
313  static void value( real64 const (&coords)[2],
314  real64 (& N)[numSupportPoints] )
315  {
316  for( int a=0; a<3; ++a )
317  {
318  for( int b=0; b<3; ++b )
319  {
320  const int lindex = LagrangeBasis2::TensorProduct2D::linearIndex( a, b );
321  N[ lindex ] = LagrangeBasis2::value( a, coords[0] ) *
322  LagrangeBasis2::value( b, coords[1] );
323  }
324  }
325  }
326  };
327 
365  {
366 
368  constexpr static localIndex numSupportPoints = 27;
369 
380  constexpr static int linearIndex( const int i,
381  const int j,
382  const int k )
383  {
384  return i + 3 * j + 9 * k;
385  }
386 
387 
388 
399  constexpr static void multiIndex( const int linearIndex,
400  int & i0,
401  int & i1,
402  int & i2 )
403  {
404  i2 = ( linearIndex * 29 ) >> 8;
405  //i2 = a/9;
406 
407  i1 = ( ( linearIndex * 22 ) >> 6 ) - i2 * 3;
408  //i1 = a/3 - i2 * 3;
409 
410  i0 = linearIndex - i1 * 3 - i2 * 9;
411  }
412 
422  static void value( const real64 (& coords)[3],
423  real64 (& N)[numSupportPoints] )
424  {
425  for( int a=0; a<3; ++a )
426  {
427  for( int b=0; b<3; ++b )
428  {
429  for( int c=0; c<3; ++c )
430  {
431  const int lindex = LagrangeBasis2::TensorProduct3D::linearIndex( a, b, c );
432  N[ lindex ] = LagrangeBasis2::value( a, coords[0] ) *
433  LagrangeBasis2::value( b, coords[1] ) *
434  LagrangeBasis2::value( c, coords[2] );
435  }
436  }
437  }
438  }
439  };
440 };
441 
442 }
443 }
444 
445 #endif /* GEOS_FINITEELEMENT_ELEMENTFORMULATIONS_ELEMENTFORMULATIONS_LAGRANGEBASIS2_HPP_ */
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
#define GEOS_FORCE_INLINE
Marks a function or lambda for inlining.
Definition: GeosxMacros.hpp:51
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 value0(const real64 xi)
The value of the basis function for support point 0.
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 weight(const int q)
The value of the weight for the given support point.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 gradient2(const real64 xi)
The gradient of the basis function for support point 1 evaluated at a point along the axes.
constexpr static localIndex numSupportPoints
The number of support points for the basis.
GEOS_HOST_DEVICE constexpr static GEOS_FORCE_INLINE real64 gradientAt(const int q, const int p)
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 value1(const real64 xi)
The value of the basis function for support point 1.
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.
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 value2(const real64 xi)
The value of the basis function for support point 2.
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.
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 constexpr static GEOS_FORCE_INLINE int linearIndex(const int i, const int j)
Calculates the linear index for support/quadrature points from ij coordinates.
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.
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.
constexpr static localIndex numSupportPoints
The number of support points in the basis.
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.
constexpr static localIndex numSupportPoints
The number of support points in the basis.
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 value(const real64(&coords)[3], real64(&N)[numSupportPoints])
The value of the basis function for a support point evaluated at a point along the axes.