GEOS
AcousticMatricesSEMKernel.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 
20 #ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICMATRICESSEMKERNEL_HPP_
21 #define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICMATRICESSEMKERNEL_HPP_
22 
23 namespace geos
24 {
25 
27 {
28 
29  template< typename FE_TYPE >
30  struct MassMatrix
31  {
32 
33  MassMatrix( FE_TYPE const & finiteElement )
34  : m_finiteElement( finiteElement )
35  {}
50  template< typename EXEC_POLICY, typename ATOMIC_POLICY >
51  void
55  arrayView1d< real32 const > const velocity,
56  arrayView1d< real32 const > const density,
57  arrayView1d< real32 > const mass )
58 
59  {
60  forAll< EXEC_POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const e )
61  {
62 
63  real32 const invC2 = 1.0 / ( density[e] * pow( velocity[e], 2 ) );
64  // only the eight corners of the mesh cell are needed to compute the Jacobian
65  real64 xLocal[ 8 ][ 3 ];
66  for( localIndex a = 0; a < 8; ++a )
67  {
68  localIndex const nodeIndex = elemsToNodes( e, FE_TYPE::meshIndexToLinearIndex3D( a ) );
69  for( localIndex i = 0; i < 3; ++i )
70  {
71  xLocal[a][i] = nodeCoords( nodeIndex, i );
72  }
73  }
74  constexpr localIndex numQuadraturePointsPerElem = FE_TYPE::numQuadraturePoints;
75  for( localIndex q = 0; q < numQuadraturePointsPerElem; ++q )
76  {
77  real32 const localIncrement = invC2 * m_finiteElement.computeMassTerm( q, xLocal );
78  RAJA::atomicAdd< ATOMIC_POLICY >( &mass[elemsToNodes( e, q )], localIncrement );
79  }
80  } ); // end loop over element
81  }
82 
83  FE_TYPE const & m_finiteElement;
84 
85  };
86  template< typename FE_TYPE >
88  {
89 
90  DampingMatrix( FE_TYPE const & finiteElement )
92  {}
93 
108  template< typename EXEC_POLICY, typename ATOMIC_POLICY >
109  void
112  arrayView2d< localIndex const > const elemsToFaces,
113  ArrayOfArraysView< localIndex const > const facesToNodes,
114  arrayView1d< integer const > const facesDomainBoundaryIndicator,
115  arrayView1d< localIndex const > const freeSurfaceFaceIndicator,
116  arrayView1d< real32 const > const velocity,
117  arrayView1d< real32 const > const density,
118  arrayView1d< real32 > const damping )
119  {
120  forAll< EXEC_POLICY >( size, [=] GEOS_HOST_DEVICE ( localIndex const e )
121  {
122  for( localIndex i = 0; i < elemsToFaces.size( 1 ); ++i )
123  {
124  localIndex const f = elemsToFaces( e, i );
125  // face on the domain boundary and not on free surface
126  if( facesDomainBoundaryIndicator[f] == 1 && freeSurfaceFaceIndicator[f] != 1 )
127  {
128  // only the four corners of the mesh face are needed to compute the Jacobian
129  real64 xLocal[ 4 ][ 3 ];
130  for( localIndex a = 0; a < 4; ++a )
131  {
132  localIndex const nodeIndex = facesToNodes( f, FE_TYPE::meshIndexToLinearIndex2D( a ) );
133  for( localIndex d = 0; d < 3; ++d )
134  {
135  xLocal[a][d] = nodeCoords( nodeIndex, d );
136  }
137  }
138  real32 const alpha = 1.0 / (density[e] * velocity[e]);
139  constexpr localIndex numNodesPerFace = FE_TYPE::numNodesPerFace;
140  for( localIndex q = 0; q < numNodesPerFace; ++q )
141  {
142  real32 const localIncrement = alpha * m_finiteElement.computeDampingTerm( q, xLocal );
143  RAJA::atomicAdd< ATOMIC_POLICY >( &damping[facesToNodes( f, q )], localIncrement );
144  }
145  }
146  }
147  } );
148  }
149 
151  FE_TYPE const & m_finiteElement;
152 
153  };
154 
155 
156 
157 };
158 
159 } // namespace geos
160 
161 #endif //GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICMATRICESSEMKERNEL_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
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, arrayView1d< real32 const > const velocity, arrayView1d< real32 const > const density, arrayView1d< real32 > const damping)
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 velocity, arrayView1d< real32 const > const density, arrayView1d< real32 > const mass)
Launches the precomputation of the mass matrices.