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 #include "finiteElement/elementFormulations/FiniteElementOperators.hpp"
27 
28 namespace geos
29 {
30 
32 namespace solidMechanicsLagrangianFEMKernels
33 {
34 
35 
36 template< typename SUBREGION_TYPE,
37  typename CONSTITUTIVE_TYPE,
38  typename FE_TYPE >
40  EdgeManager const & edgeManager,
41  FaceManager const & faceManager,
42  localIndex const targetRegionIndex,
43  SUBREGION_TYPE const & elementSubRegion,
44  FE_TYPE const & finiteElementSpace,
45  CONSTITUTIVE_TYPE & inputConstitutiveType,
46  real64 const dt,
47  string const elementListName ):
48  Base( elementSubRegion,
49  finiteElementSpace,
50  inputConstitutiveType ),
51  m_X( nodeManager.referencePosition()),
52  m_u( nodeManager.getField< fields::solidMechanics::totalDisplacement >() ),
53  m_vel( nodeManager.getField< fields::solidMechanics::velocity >() ),
54  m_acc( nodeManager.getField< fields::solidMechanics::acceleration >() ),
55  m_dt( dt ),
56  m_elementList( elementSubRegion.template getReference< SortedArray< localIndex > >( elementListName ).toViewConst() )
57 {
58  GEOS_UNUSED_VAR( edgeManager );
59  GEOS_UNUSED_VAR( faceManager );
60  GEOS_UNUSED_VAR( targetRegionIndex );
61 }
62 
63 
64 template< typename SUBREGION_TYPE,
65  typename CONSTITUTIVE_TYPE,
66  typename FE_TYPE >
68 inline
70  StackVariables & stack ) const
71 {
72  for( localIndex a=0; a< numNodesPerElem; ++a )
73  {
74  localIndex const nodeIndex = m_elemsToNodes( k, a );
75  for( int i=0; i<numDofPerTrialSupportPoint; ++i )
76  {
77  stack.xLocal[ a ][ i ] = m_X[ nodeIndex ][ i ];
78 #if UPDATE_STRESS==2
79  stack.varLocal[ a ][ i ] = m_vel[ nodeIndex ][ i ] * m_dt;
80 #else
81  stack.varLocal[ a ][ i ] = m_u[ nodeIndex ][ i ];
82 #endif
83  }
84  }
85 }
86 
87 template< typename SUBREGION_TYPE,
88  typename CONSTITUTIVE_TYPE,
89  typename FE_TYPE >
91 inline
93  localIndex const q,
94  StackVariables & stack ) const
95 {
96 //#define USE_JACOBIAN
97 #if !defined( USE_JACOBIAN )
98  real64 dNdX[ numNodesPerElem ][ 3 ];
99  real64 const detJ = FE_TYPE::calcGradN( q, stack.xLocal, dNdX );
101  real64 strain[6] = {0};
102  //real64 timeIncrement = 0.0;
103  finiteElement::feOps::symmetricGradient( dNdX, stack.varLocal, strain );
104 
105  real64 stressLocal[ 6 ] = {0};
106 #if UPDATE_STRESS == 2
107  m_constitutiveUpdate.smallStrainUpdate_StressOnly( k, q, m_dt, strain, stressLocal );
108 #else
109  m_constitutiveUpdate.smallStrainNoStateUpdate_StressOnly( k, q, strain, stressLocal );
110 #endif
111 
112  for( localIndex c = 0; c < 6; ++c )
113  {
114 #if UPDATE_STRESS == 2
115  stressLocal[ c ] *= -detJ;
116 #elif UPDATE_STRESS == 1
117  stressLocal[ c ] = -( stressLocal[ c ] + m_constitutiveUpdate.m_newStress( k, q, c ) ) * detJ; // TODO: decide on
118  // initial stress
119  // strategy
120 #else
121  stressLocal[ c ] *= -detJ;
122 #endif
123  }
124 
125  finiteElement::feOps::plusGradNajAij( dNdX, stressLocal, stack.fLocal );
126 
127 #else
128  real64 invJ[3][3];
129  real64 const detJ = FE_TYPE::inverseJacobianTransformation( q, stack.xLocal, invJ );
130 
131  real64 strain[6] = {0};
132  finiteElement::feOps::symmetricGradient( q, invJ, stack.varLocal, strain );
133 
134  real64 stressLocal[ 6 ] = {0};
135 #if UPDATE_STRESS == 2
136  m_constitutiveUpdate.smallStrainUpdate_StressOnly( k, q, m_dt, strain, stressLocal );
137 #else
138  m_constitutiveUpdate.smallStrainNoStateUpdate_StressOnly( k, q, strain, stressLocal );
139 #endif
140 
141  for( localIndex c = 0; c < 6; ++c )
142  {
143 #if UPDATE_STRESS == 2
144  stressLocal[ c ] *= detJ;
145 #elif UPDATE_STRESS == 1
146  stressLocal[ c ] = ( stressLocal[ c ] + m_constitutiveUpdate.m_newStress( k, q, c ) ) * DETJ; // TODO: decide on
147  // initial stress
148  // strategy
149 #else
150  stressLocal[ c ] *= DETJ;
151 #endif
152  }
153 
154  finiteElement::feOps::plusGradNajAij( q, invJ, stressLocal, stack.fLocal );
155 #endif
156 }
157 
158 template< typename SUBREGION_TYPE,
159  typename CONSTITUTIVE_TYPE,
160  typename FE_TYPE >
162 inline
164  StackVariables const & stack ) const
165 {
166  for( localIndex a = 0; a < numNodesPerElem; ++a )
167  {
168  localIndex const nodeIndex = m_elemsToNodes( k, a );
169  for( int b = 0; b < numDofPerTestSupportPoint; ++b )
170  {
171  RAJA::atomicAdd< parallelDeviceAtomic >( &m_acc( nodeIndex, b ), stack.fLocal[ a ][ b ] );
172  }
173  }
174  return 0;
175 }
176 
177 template< typename SUBREGION_TYPE,
178  typename CONSTITUTIVE_TYPE,
179  typename FE_TYPE >
180 template< typename POLICY,
181  typename KERNEL_TYPE >
182 real64
184  KERNEL_TYPE const & kernelComponent )
185 {
187 
188  GEOS_UNUSED_VAR( numElems );
189 
190  localIndex const numProcElems = kernelComponent.m_elementList.size();
191  forAll< POLICY >( numProcElems,
192  [=] GEOS_DEVICE ( localIndex const index )
193  {
194  localIndex const k = kernelComponent.m_elementList[ index ];
195 
196  typename KERNEL_TYPE::StackVariables stack;
197 
198  kernelComponent.setup( k, stack );
199  for( integer q=0; q<KERNEL_TYPE::numQuadraturePointsPerElem; ++q )
200  {
201  kernelComponent.quadraturePointKernel( k, q, stack );
202  }
203  kernelComponent.complete( k, stack );
204  } );
205  return 0;
206 }
207 
208 
209 #undef UPDATE_STRESS
210 
211 } // namespace solidMechanicsLagrangianFEMKernels
212 
213 } // namespace geos
214 
215 #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:98
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
LvArray::SortedArray< T, localIndex, LvArray::ChaiBuffer > SortedArray
A sorted array of local indices.
Definition: DataTypes.hpp:266
int integer
Signed integer type.
Definition: DataTypes.hpp:81
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.
real64 xLocal[numNodesPerElem][3]
C-array stack storage for element local the nodal positions.