GEOS
ElasticMatricesSEMKernel.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_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICMATRICESSEMKERNEL_HPP_
21 #define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICMATRICESSEMKERNEL_HPP_
22 
23 namespace geos
24 {
25 
27 {
28  template< typename FE_TYPE >
29  struct MassMatrix
30  {
31 
32  MassMatrix( FE_TYPE const & finiteElement )
34  {}
35 
47  template< typename EXEC_POLICY, typename ATOMIC_POLICY >
48  void
52  arrayView1d< real32 const > const density,
53  arrayView1d< real32 > const mass )
54 
55  {
56  forAll< EXEC_POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const e )
57  {
58 
59  // only the eight corners of the mesh cell are needed to compute the Jacobian
60  real64 xLocal[ 8 ][ 3 ];
61  for( localIndex a = 0; a < 8; ++a )
62  {
63  localIndex const nodeIndex = elemsToNodes( e, FE_TYPE::meshIndexToLinearIndex3D( a ) );
64  for( localIndex i = 0; i < 3; ++i )
65  {
66  xLocal[a][i] = nodeCoords( nodeIndex, i );
67  }
68  }
69 
70  constexpr localIndex numQuadraturePointsPerElem = FE_TYPE::numQuadraturePoints;
71  for( localIndex q = 0; q < numQuadraturePointsPerElem; ++q )
72  {
73  real32 const localIncrement = density[e] * m_finiteElement.computeMassTerm( q, xLocal );
74  RAJA::atomicAdd< ATOMIC_POLICY >( &mass[elemsToNodes( e, q )], localIncrement );
75  }
76  } ); // end loop over element
77  }
78 
80  FE_TYPE const & m_finiteElement;
81 
82  };
83 
84  template< typename FE_TYPE >
86  {
87 
88  DampingMatrix( FE_TYPE const & finiteElement )
90  {}
91 
110  template< typename EXEC_POLICY, typename ATOMIC_POLICY >
111  void
114  arrayView2d< localIndex const > const elemsToFaces,
115  ArrayOfArraysView< localIndex const > const facesToNodes,
116  arrayView1d< integer const > const facesDomainBoundaryIndicator,
117  arrayView1d< localIndex const > const freeSurfaceFaceIndicator,
118  arrayView2d< real64 const > const faceNormal,
119  arrayView1d< real32 const > const density,
120  arrayView1d< real32 const > const velocityVp,
121  arrayView1d< real32 const > const velocityVs,
122  arrayView1d< real32 > const dampingx,
123  arrayView1d< real32 > const dampingy,
124  arrayView1d< real32 > const dampingz )
125  {
126  forAll< EXEC_POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const e )
127  {
128  for( localIndex i = 0; i < elemsToFaces.size( 1 ); ++i )
129  {
130  localIndex const f = elemsToFaces( e, i );
131  // face on the domain boundary and not on free surface
132  if( facesDomainBoundaryIndicator[f] == 1 && freeSurfaceFaceIndicator[f] != 1 )
133  {
134  // only the four corners of the mesh face are needed to compute the Jacobian
135  real64 xLocal[ 4 ][ 3 ];
136  for( localIndex a = 0; a < 4; ++a )
137  {
138  localIndex const nodeIndex = facesToNodes( f, FE_TYPE::meshIndexToLinearIndex2D( a ) );
139  for( localIndex d = 0; d < 3; ++d )
140  {
141  xLocal[a][d] = nodeCoords( nodeIndex, d );
142  }
143  }
144 
145  real32 const nx = faceNormal( f, 0 ), ny = faceNormal( f, 1 ), nz = faceNormal( f, 2 );
146  constexpr localIndex numNodesPerFace = FE_TYPE::numNodesPerFace;
147  for( localIndex q = 0; q < numNodesPerFace; ++q )
148  {
149  real32 const aux = density[e] * m_finiteElement.computeDampingTerm( q, xLocal );
150  real32 const localIncrementx = aux * ( velocityVp[e] * LvArray::math::abs( nx ) + velocityVs[e] * LvArray::math::sqrt( pow( ny, 2 ) + pow( nz, 2 ) ) );
151  real32 const localIncrementy = aux * ( velocityVp[e] * LvArray::math::abs( ny ) + velocityVs[e] * LvArray::math::sqrt( pow( nx, 2 ) + pow( nz, 2 ) ) );
152  real32 const localIncrementz = aux * ( velocityVp[e] * LvArray::math::abs( nz ) + velocityVs[e] * LvArray::math::sqrt( pow( nx, 2 ) + pow( ny, 2 ) ) );
153 
154  RAJA::atomicAdd< ATOMIC_POLICY >( &dampingx[facesToNodes( f, q )], localIncrementx );
155  RAJA::atomicAdd< ATOMIC_POLICY >( &dampingy[facesToNodes( f, q )], localIncrementy );
156  RAJA::atomicAdd< ATOMIC_POLICY >( &dampingz[facesToNodes( f, q )], localIncrementz );
157  }
158  }
159  }
160  } );
161  }
162 
164  FE_TYPE const & m_finiteElement;
165 
166  };
167 
168 
169 
170 };
171 
172 } // namespace geos
173 
174 #endif //GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICMATRICESSEMKERNEL_HPP_
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
float real32
32-bit floating point type.
Definition: DataTypes.hpp:97
LvArray::ArrayOfArraysView< T, INDEX_TYPE const, CONST_SIZES, LvArray::ChaiBuffer > ArrayOfArraysView
View of array of variable-sized arrays. See LvArray::ArrayOfArraysView for details.
Definition: DataTypes.hpp:286
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
ArrayView< T, 2, USD > arrayView2d
Alias for 2D array view.
Definition: DataTypes.hpp:196
FE_TYPE const & m_finiteElement
The finite element space/discretization object for the element type in the subRegion.
void computeDampingMatrix(localIndex const size, arrayView2d< WaveSolverBase::wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords, arrayView2d< localIndex const > const elemsToFaces, ArrayOfArraysView< localIndex const > const facesToNodes, arrayView1d< integer const > const facesDomainBoundaryIndicator, arrayView1d< localIndex const > const freeSurfaceFaceIndicator, arrayView2d< real64 const > const faceNormal, arrayView1d< real32 const > const density, arrayView1d< real32 const > const velocityVp, arrayView1d< real32 const > const velocityVs, arrayView1d< real32 > const dampingx, arrayView1d< real32 > const dampingy, arrayView1d< real32 > const dampingz)
Launches the precomputation of the damping matrices.
FE_TYPE const & m_finiteElement
The finite element space/discretization object for the element type in the subRegion.
void computeMassMatrix(localIndex const size, arrayView2d< WaveSolverBase::wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords, arrayView2d< localIndex const, cells::NODE_MAP_USD > const elemsToNodes, arrayView1d< real32 const > const density, arrayView1d< real32 > const mass)
Launches the precomputation of the mass matrices.