GEOS
ExplicitSmallStrain_impl.hpp
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_SOLIDMECHANICS_KERNELS_EXPLICITSMALLTRAIN_IMPL_HPP_
21 #define GEOS_PHYSICSSOLVERS_SOLIDMECHANICS_KERNELS_EXPLICITSMALLTRAIN_IMPL_HPP_
22 
23 //#include "ExplicitFiniteStrain.hpp"
24 #include "ExplicitSmallStrain.hpp"
25 
26 
27 namespace geos
28 {
29 
31 namespace solidMechanicsLagrangianFEMKernels
32 {
33 
34 
35 template< typename SUBREGION_TYPE,
36  typename CONSTITUTIVE_TYPE,
37  typename FE_TYPE >
39  EdgeManager const & edgeManager,
40  FaceManager const & faceManager,
41  localIndex const targetRegionIndex,
42  SUBREGION_TYPE const & elementSubRegion,
43  FE_TYPE const & finiteElementSpace,
44  CONSTITUTIVE_TYPE & inputConstitutiveType,
45  real64 const dt,
46  string const elementListName ):
47  Base( elementSubRegion,
48  finiteElementSpace,
49  inputConstitutiveType ),
50  m_X( nodeManager.referencePosition()),
51  m_u( nodeManager.getField< fields::solidMechanics::totalDisplacement >() ),
52  m_vel( nodeManager.getField< fields::solidMechanics::velocity >() ),
53  m_acc( nodeManager.getField< fields::solidMechanics::acceleration >() ),
54  m_dt( dt ),
55  m_elementList( elementSubRegion.template getReference< SortedArray< localIndex > >( elementListName ).toViewConst() )
56 {
57  GEOS_UNUSED_VAR( edgeManager );
58  GEOS_UNUSED_VAR( faceManager );
59  GEOS_UNUSED_VAR( targetRegionIndex );
60 }
61 
62 
63 template< typename SUBREGION_TYPE,
64  typename CONSTITUTIVE_TYPE,
65  typename FE_TYPE >
67 inline
69  StackVariables & stack ) const
70 {
71  for( localIndex a=0; a< numNodesPerElem; ++a )
72  {
73  localIndex const nodeIndex = m_elemsToNodes( k, a );
74  for( int i=0; i<numDofPerTrialSupportPoint; ++i )
75  {
76 #if defined(CALC_FEM_SHAPE_IN_KERNEL)
77  stack.xLocal[ a ][ i ] = m_X[ nodeIndex ][ i ];
78 #endif
79 
80 #if UPDATE_STRESS==2
81  stack.varLocal[ a ][ i ] = m_vel[ nodeIndex ][ i ] * m_dt;
82 #else
83  stack.varLocal[ a ][ i ] = m_u[ nodeIndex ][ i ];
84 #endif
85  }
86  }
87 }
88 
89 template< typename SUBREGION_TYPE,
90  typename CONSTITUTIVE_TYPE,
91  typename FE_TYPE >
93 inline
95  localIndex const q,
96  StackVariables & stack ) const
97 {
98 //#define USE_JACOBIAN
99 #if !defined( USE_JACOBIAN )
100  real64 dNdX[ numNodesPerElem ][ 3 ];
101  real64 const detJ = m_finiteElementSpace.template getGradN< FE_TYPE >( k, q, stack.xLocal, dNdX );
103  real64 strain[6] = {0};
104  //real64 timeIncrement = 0.0;
105  FE_TYPE::symmetricGradient( dNdX, stack.varLocal, strain );
106 
107  real64 stressLocal[ 6 ] = {0};
108 #if UPDATE_STRESS == 2
109  m_constitutiveUpdate.smallStrainUpdate_StressOnly( k, q, m_dt, strain, stressLocal );
110 #else
111  m_constitutiveUpdate.smallStrainNoStateUpdate_StressOnly( k, q, strain, stressLocal );
112 #endif
113 
114  for( localIndex c = 0; c < 6; ++c )
115  {
116 #if UPDATE_STRESS == 2
117  stressLocal[ c ] *= -detJ;
118 #elif UPDATE_STRESS == 1
119  stressLocal[ c ] = -( stressLocal[ c ] + m_constitutiveUpdate.m_newStress( k, q, c ) ) * detJ; // TODO: decide on
120  // initial stress
121  // strategy
122 #else
123  stressLocal[ c ] *= -detJ;
124 #endif
125  }
126 
127  FE_TYPE::plusGradNajAij( dNdX, stressLocal, stack.fLocal );
128 
129 #else
130  real64 invJ[3][3];
131  real64 const detJ = FE_TYPE::inverseJacobianTransformation( q, stack.xLocal, invJ );
132 
133  real64 strain[6] = {0};
134  FE_TYPE::symmetricGradient( q, invJ, stack.varLocal, strain );
135 
136  real64 stressLocal[ 6 ] = {0};
137 #if UPDATE_STRESS == 2
138  m_constitutiveUpdate.smallStrainUpdate_StressOnly( k, q, m_dt, strain, stressLocal );
139 #else
140  m_constitutiveUpdate.smallStrainNoStateUpdate_StressOnly( k, q, strain, stressLocal );
141 #endif
142 
143  for( localIndex c = 0; c < 6; ++c )
144  {
145 #if UPDATE_STRESS == 2
146  stressLocal[ c ] *= detJ;
147 #elif UPDATE_STRESS == 1
148  stressLocal[ c ] = ( stressLocal[ c ] + m_constitutiveUpdate.m_newStress( k, q, c ) ) * DETJ; // TODO: decide on
149  // initial stress
150  // strategy
151 #else
152  stressLocal[ c ] *= DETJ;
153 #endif
154  }
155 
156  FE_TYPE::plusGradNajAij( q, invJ, stressLocal, stack.fLocal );
157 #endif
158 }
159 
160 template< typename SUBREGION_TYPE,
161  typename CONSTITUTIVE_TYPE,
162  typename FE_TYPE >
164 inline
166  StackVariables const & stack ) const
167 {
168  for( localIndex a = 0; a < numNodesPerElem; ++a )
169  {
170  localIndex const nodeIndex = m_elemsToNodes( k, a );
171  for( int b = 0; b < numDofPerTestSupportPoint; ++b )
172  {
173  RAJA::atomicAdd< parallelDeviceAtomic >( &m_acc( nodeIndex, b ), stack.fLocal[ a ][ b ] );
174  }
175  }
176  return 0;
177 }
178 
179 template< typename SUBREGION_TYPE,
180  typename CONSTITUTIVE_TYPE,
181  typename FE_TYPE >
182 template< typename POLICY,
183  typename KERNEL_TYPE >
184 real64
186  KERNEL_TYPE const & kernelComponent )
187 {
189 
190  GEOS_UNUSED_VAR( numElems );
191 
192  localIndex const numProcElems = kernelComponent.m_elementList.size();
193  forAll< POLICY >( numProcElems,
194  [=] GEOS_DEVICE ( localIndex const index )
195  {
196  localIndex const k = kernelComponent.m_elementList[ index ];
197 
198  typename KERNEL_TYPE::StackVariables stack;
199 
200  kernelComponent.setup( k, stack );
201  for( integer q=0; q<KERNEL_TYPE::numQuadraturePointsPerElem; ++q )
202  {
203  kernelComponent.quadraturePointKernel( k, q, stack );
204  }
205  kernelComponent.complete( k, stack );
206  } );
207  return 0;
208 }
209 
210 
211 #undef UPDATE_STRESS
212 
213 } // namespace solidMechanicsLagrangianFEMKernels
214 
215 } // namespace geos
216 
217 #endif //GEOS_PHYSICSSOLVERS_SOLIDMECHANICS_KERNELS_EXPLICITSMALLTRAIN_IMPL_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_DEVICE
Marks a device-only function.
Definition: GeosxMacros.hpp:47
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
This class provides an interface to ObjectManagerBase in order to manage edge data.
Definition: EdgeManager.hpp:43
The FaceManager class provides an interface to ObjectManagerBase in order to manage face data.
Definition: FaceManager.hpp:44
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data.
Definition: NodeManager.hpp:46
static real64 kernelLaunch(localIndex const numElems, KERNEL_TYPE const &kernelComponent)
Kernel Launcher.
GEOS_HOST_DEVICE void setup(localIndex const k, StackVariables &stack) const
Performs the setup phase for the kernel.
ExplicitSmallStrain(NodeManager &nodeManager, EdgeManager const &edgeManager, FaceManager const &faceManager, localIndex const targetRegionIndex, SUBREGION_TYPE const &elementSubRegion, FE_TYPE const &finiteElementSpace, CONSTITUTIVE_TYPE &inputConstitutiveType, real64 const dt, string const elementListName)
Constructor.
GEOS_HOST_DEVICE void quadraturePointKernel(localIndex const k, localIndex const q, StackVariables &stack) const
Performs a state update at a quadrature point.
GEOS_HOST_DEVICE real64 complete(localIndex const k, StackVariables const &stack) const
Performs the complete phase for the kernel.
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
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
LvArray::SortedArray< T, localIndex, LvArray::ChaiBuffer > SortedArray
A sorted array of local indices.
Definition: DataTypes.hpp:267
real64 varLocal[numNodesPerElem][numDofPerTestSupportPoint]
C-array stack storage for element local primary variable values.
real64 fLocal[numNodesPerElem][numDofPerTrialSupportPoint]
C-array stack storage for the element local force.