GEOS
SolidMechanicsLagrangianFEM.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_SOLIDMECHANICS_SOLIDMECHANICSLAGRANGIANFEM_HPP_
21 #define GEOS_PHYSICSSOLVERS_SOLIDMECHANICS_SOLIDMECHANICSLAGRANGIANFEM_HPP_
22 
24 #include "common/TimingMacros.hpp"
27 #include "mesh/mpiCommunications/CommunicationTools.hpp"
28 #include "mesh/mpiCommunications/MPI_iCommData.hpp"
30 
32 
33 namespace geos
34 {
35 
42 {
43 public:
44 
46  static string coupledSolverAttributePrefix() { return "solid"; }
47 
54  {
55  QuasiStatic,
58  };
59 
65  SolidMechanicsLagrangianFEM( const string & name,
66  Group * const parent );
67 
71  static string catalogName() { return "SolidMechanicsLagrangianFEM"; }
75  string getCatalogName() const override { return catalogName(); }
76 
77  virtual void initializePreSubGroups() override;
78 
79  virtual void registerDataOnMesh( Group & meshBodies ) override;
80 
87  virtual
88  real64 solverStep( real64 const & time_n,
89  real64 const & dt,
90  integer const cycleNumber,
91  DomainPartition & domain ) override;
92 
93  virtual
94  real64 explicitStep( real64 const & time_n,
95  real64 const & dt,
96  integer const cycleNumber,
97  DomainPartition & domain ) override;
98 
99  virtual void
100  implicitStepSetup( real64 const & time_n,
101  real64 const & dt,
102  DomainPartition & domain ) override;
103 
104  virtual void
105  setupDofs( DomainPartition const & domain,
106  DofManager & dofManager ) const override;
107 
108  virtual void
110  DofManager & dofManager,
111  CRSMatrix< real64, globalIndex > & localMatrix,
112  ParallelVector & rhs,
113  ParallelVector & solution,
114  bool setSparsity = true ) override;
115 
116  virtual void
118  DofManager & dofManager,
119  CRSMatrix< real64, globalIndex > & localMatrix,
120  SparsityPattern< globalIndex > & pattern ) override;
121 
122  virtual std::unique_ptr< PreconditionerBase< LAInterface > >
123  createPreconditioner( DomainPartition & domain ) const override;
124 
125  virtual void
126  assembleSystem( real64 const time,
127  real64 const dt,
128  DomainPartition & domain,
129  DofManager const & dofManager,
130  CRSMatrixView< real64, globalIndex const > const & localMatrix,
131  arrayView1d< real64 > const & localRhs ) override;
132 
133  virtual void solveLinearSystem( DofManager const & dofManager,
134  ParallelMatrix & matrix,
135  ParallelVector & rhs,
136  ParallelVector & solution,
137  integer const cycleNumber,
138  integer const nonlinearIteration ) override;
139 
140  virtual void
141  applySystemSolution( DofManager const & dofManager,
142  arrayView1d< real64 const > const & localSolution,
143  real64 const scalingFactor,
144  real64 const dt,
145  DomainPartition & domain ) override;
146 
147  virtual void updateState( DomainPartition & domain ) override
148  {
149  // There should be nothing to update
150  GEOS_UNUSED_VAR( domain );
151  };
152 
153  virtual void applyBoundaryConditions( real64 const time,
154  real64 const dt,
155  DomainPartition & domain,
156  DofManager const & dofManager,
157  CRSMatrixView< real64, globalIndex const > const & localMatrix,
158  arrayView1d< real64 > const & localRhs ) override;
159 
160  virtual real64
161  calculateResidualNorm( real64 const & time_n,
162  real64 const & dt,
163  DomainPartition const & domain,
164  DofManager const & dofManager,
165  arrayView1d< real64 const > const & localRhs ) override;
166 
167  virtual void resetStateToBeginningOfStep( DomainPartition & domain ) override;
168 
169  virtual void implicitStepComplete( real64 const & time,
170  real64 const & dt,
171  DomainPartition & domain ) override;
172 
176  template< typename TYPE_LIST,
177  typename KERNEL_WRAPPER,
178  typename ... PARAMS >
179  real64 assemblyLaunch( MeshLevel & mesh,
180  DofManager const & dofManager,
181  string_array const & regionNames,
182  string const & materialNamesString,
183  CRSMatrixView< real64, globalIndex const > const & localMatrix,
184  arrayView1d< real64 > const & localRhs,
185  real64 const dt,
186  PARAMS && ... params );
187 
188  real64 explicitKernelDispatch( MeshLevel & mesh,
189  string_array const & targetRegions,
190  string const & finiteElementName,
191  real64 const dt,
192  std::string const & elementListName );
193 
204  DofManager const & dofManager,
205  DomainPartition & domain,
206  CRSMatrixView< real64, globalIndex const > const & localMatrix,
207  arrayView1d< real64 > const & localRhs );
208 
209  void applyTractionBC( real64 const time,
210  DofManager const & dofManager,
211  DomainPartition & domain,
212  arrayView1d< real64 > const & localRhs );
213 
214  void applyChomboPressure( DofManager const & dofManager,
215  DomainPartition & domain,
216  arrayView1d< real64 > const & localRhs );
217 
218 
219  void applyContactConstraint( DofManager const & dofManager,
220  DomainPartition & domain,
221  CRSMatrixView< real64, globalIndex const > const & localMatrix,
222  arrayView1d< real64 > const & localRhs );
223 
224  virtual real64
226  DofManager const & dofManager,
227  arrayView1d< real64 const > const & localSolution ) override;
228 
229  void enableFixedStressPoromechanicsUpdate();
230 
231  virtual void saveSequentialIterationState( DomainPartition & domain ) override;
232 
234  {
235  static constexpr char const * newmarkGammaString() { return "newmarkGamma"; }
236  static constexpr char const * newmarkBetaString() { return "newmarkBeta"; }
237  static constexpr char const * massDampingString() { return "massDamping"; }
238  static constexpr char const * stiffnessDampingString() { return "stiffnessDamping"; }
239  static constexpr char const * timeIntegrationOptionString() { return "timeIntegrationOption"; }
240  static constexpr char const * maxNumResolvesString() { return "maxNumResolves"; }
241  static constexpr char const * strainTheoryString() { return "strainTheory"; }
242  static constexpr char const * solidMaterialNamesString() { return "solidMaterialNames"; }
243  static constexpr char const * contactRelationNameString() { return "contactRelationName"; }
244  static constexpr char const * noContactRelationNameString() { return "NOCONTACT"; }
245  static constexpr char const * maxForceString() { return "maxForce"; }
246  static constexpr char const * elemsAttachedToSendOrReceiveNodesString() { return "elemsAttachedToSendOrReceiveNodes"; }
247  static constexpr char const * elemsNotAttachedToSendOrReceiveNodesString() { return "elemsNotAttachedToSendOrReceiveNodes"; }
248  static constexpr char const * surfaceGeneratorNameString() { return "surfaceGeneratorName"; }
249 
250  static constexpr char const * sendOrReceiveNodesString() { return "sendOrReceiveNodes";}
251  static constexpr char const * nonSendOrReceiveNodesString() { return "nonSendOrReceiveNodes";}
252  static constexpr char const * targetNodesString() { return "targetNodes";}
253  static constexpr char const * forceString() { return "Force";}
254 
255  static constexpr char const * contactPenaltyStiffnessString() { return "contactPenaltyStiffness"; }
256 
257  };
258 
259  SortedArray< localIndex > & getElemsAttachedToSendOrReceiveNodes( ElementSubRegionBase & subRegion )
260  {
261  return subRegion.getReference< SortedArray< localIndex > >( viewKeyStruct::elemsAttachedToSendOrReceiveNodesString() );
262  }
263 
264  SortedArray< localIndex > & getElemsNotAttachedToSendOrReceiveNodes( ElementSubRegionBase & subRegion )
265  {
266  return subRegion.getReference< SortedArray< localIndex > >( viewKeyStruct::elemsNotAttachedToSendOrReceiveNodesString() );
267  }
268 
269  real64 & getMaxForce() { return m_maxForce; }
270  real64 const & getMaxForce() const { return m_maxForce; }
271 
272  void computeRigidBodyModes( DomainPartition & domain ) const;
273 
274  arrayView1d< ParallelVector > const & getRigidBodyModes( DomainPartition & domain ) const
275  {
276  computeRigidBodyModes( domain );
277  return m_rigidBodyModes;
278  }
279 
280  /*
281  * @brief Utility function to set the stress initialization flag
282  * @param[in] performStressInitialization true if the solver has to initialize stress, false otherwise
283  */
284  void setStressInitialization( bool const performStressInitialization )
285  {
286  m_performStressInitialization = performStressInitialization;
287  }
288 
289  TimeIntegrationOption timeIntegrationOption() const { return m_timeIntegrationOption; }
290 
291 protected:
292  virtual void postInputInitialization() override;
293 
294  void initializeMass( MeshLevel & mesh, CellElementSubRegion & subRegion );
295 
297 
298  virtual void setConstitutiveNamesCallSuper( ElementSubRegionBase & subRegion ) const override;
299 
300  real64 m_newmarkGamma;
301  real64 m_newmarkBeta;
302  real64 m_massDamping;
303  real64 m_stiffnessDamping;
304  TimeIntegrationOption m_timeIntegrationOption;
305  real64 m_maxForce = 0.0;
306  integer m_maxNumResolves;
307  integer m_strainTheory;
308 
313 
316 
317  real64 m_contactPenaltyStiffness;
318 
319 private:
320 
321  string m_contactRelationName;
322 
323  PhysicsSolverBase *m_surfaceGenerator;
324  string m_surfaceGeneratorName;
325 };
326 
328  "QuasiStatic",
329  "ImplicitDynamic",
330  "ExplicitDynamic" );
331 
332 //**********************************************************************************************************************
333 //**********************************************************************************************************************
334 //**********************************************************************************************************************
335 
336 
337 template< typename TYPE_LIST,
338  typename KERNEL_WRAPPER,
339  typename ... PARAMS >
340 real64 SolidMechanicsLagrangianFEM::assemblyLaunch( MeshLevel & mesh,
341  DofManager const & dofManager,
342  string_array const & regionNames,
343  string const & materialNamesString,
344  CRSMatrixView< real64, globalIndex const > const & localMatrix,
345  arrayView1d< real64 > const & localRhs,
346  real64 const dt,
347  PARAMS && ... params )
348 {
350 
351  NodeManager const & nodeManager = mesh.getNodeManager();
352 
353  string const dofKey = dofManager.getKey( fields::solidMechanics::totalDisplacement::key() );
354  arrayView1d< globalIndex const > const & dofNumber = nodeManager.getReference< globalIndex_array >( dofKey );
355 
356  real64 const gravityVectorData[3] = LVARRAY_TENSOROPS_INIT_LOCAL_3( gravityVector() );
357 
358  KERNEL_WRAPPER kernelWrapper( dofNumber,
359  dofManager.rankOffset(),
360  localMatrix,
361  localRhs,
362  dt,
363  gravityVectorData,
364  std::forward< PARAMS >( params )... );
365 
366  return finiteElement::
367  regionBasedKernelApplication< parallelDevicePolicy< >,
368  TYPE_LIST >( mesh,
369  regionNames,
370  this->getDiscretizationName(),
371  materialNamesString,
372  kernelWrapper );
373 
374 }
375 
376 } /* namespace geos */
377 
378 #endif /* GEOS_PHYSICSSOLVERS_SOLIDMECHANICS_SOLIDMECHANICSLAGRANGIANFEM_HPP_ */
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns,...
Definition: DofManager.hpp:45
globalIndex rankOffset(string const &fieldName) const
string const & getKey(string const &fieldName) const
Return the key used to record the field in the DofManager.
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:42
NodeManager const & getNodeManager() const
Get the node manager.
Definition: MeshLevel.hpp:155
The NodeManager class provides an interface to ObjectManagerBase in order to manage node data.
Definition: NodeManager.hpp:46
Base class for all physics solvers.
string getDiscretizationName() const
return the name of the discretization object
R1Tensor const gravityVector() const
return the value of the gravity vector specified in PhysicsSolverManager
bool m_performStressInitialization
Flag to indicate that the solver is going to perform stress initialization.
virtual void registerDataOnMesh(Group &meshBodies) override
Register wrappers that contain data on the mesh objects.
bool m_isFixedStressPoromechanicsUpdate
Flag to indicate that the solver is running in fixed stress (sequential) mode.
virtual void initializePreSubGroups() override
Called by Initialize() prior to initializing sub-Groups.
virtual void saveSequentialIterationState(DomainPartition &domain) override
Save the state of the solver for sequential iteration.
SolidMechanicsLagrangianFEM(const string &name, Group *const parent)
virtual void initializePostInitialConditionsPreSubGroups() override
Called by InitializePostInitialConditions() prior to initializing sub-Groups.
void applyDisplacementBCImplicit(real64 const time, DofManager const &dofManager, DomainPartition &domain, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)
array1d< ParallelVector > m_rigidBodyModes
Rigid body modes; TODO remove mutable hack.
virtual void setConstitutiveNamesCallSuper(ElementSubRegionBase &subRegion) const override
This function sets constitutive name fields on an ElementSubRegionBase, and calls the base function i...
virtual real64 scalingForSystemSolution(DomainPartition &domain, DofManager const &dofManager, arrayView1d< real64 const > const &localSolution) override
Function to determine if the solution vector should be scaled back in order to maintain a known const...
virtual void postInputInitialization() override
static string coupledSolverAttributePrefix()
String used to form the solverName used to register single-physics solvers in CoupledSolver.
GEOS_DECLTYPE_AUTO_RETURN getReference(LOOKUP_TYPE const &lookup) const
Look up a wrapper and get reference to wrapped object.
Definition: Group.hpp:1273
virtual void setupSystem(DomainPartition &domain, DofManager &dofManager, CRSMatrix< real64, globalIndex > &localMatrix, ParallelVector &rhs, ParallelVector &solution, bool setSparsity=true) override
Set up the linear system (DOF indices and sparsity patterns)
virtual void applySystemSolution(DofManager const &dofManager, arrayView1d< real64 const > const &localSolution, real64 const scalingFactor, real64 const dt, DomainPartition &domain) override
Function to apply the solution vector to the state.
virtual real64 calculateResidualNorm(real64 const &time_n, real64 const &dt, DomainPartition const &domain, DofManager const &dofManager, arrayView1d< real64 const > const &localRhs) override
calculate the norm of the global system residual
virtual void implicitStepComplete(real64 const &time, real64 const &dt, DomainPartition &domain) override
perform cleanup for implicit timestep
virtual real64 explicitStep(real64 const &time_n, real64 const &dt, integer const cycleNumber, DomainPartition &domain) override
Entry function for an explicit time integration step.
virtual std::unique_ptr< PreconditionerBase< LAInterface > > createPreconditioner(DomainPartition &domain) const override
Create a preconditioner for this solver's linear system.
virtual void assembleSystem(real64 const time, real64 const dt, DomainPartition &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs) override
function to assemble the linear system matrix and rhs
virtual void applyBoundaryConditions(real64 const time, real64 const dt, DomainPartition &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs) override
apply boundary condition to system
virtual void resetStateToBeginningOfStep(DomainPartition &domain) override
reset state of physics back to the beginning of the step.
virtual void updateState(DomainPartition &domain) override
Recompute all dependent quantities from primary variables (including constitutive models)
virtual real64 solverStep(real64 const &time_n, real64 const &dt, integer const cycleNumber, DomainPartition &domain) override
entry function to perform a solver step
virtual void setupDofs(DomainPartition const &domain, DofManager &dofManager) const override
Populate degree-of-freedom manager with fields relevant to this solver.
virtual void setSparsityPattern(DomainPartition &domain, DofManager &dofManager, CRSMatrix< real64, globalIndex > &localMatrix, SparsityPattern< globalIndex > &pattern) override
Set the sparsity pattern of the linear system matrix.
virtual void solveLinearSystem(DofManager const &dofManager, ParallelMatrix &matrix, ParallelVector &rhs, ParallelVector &solution, integer const cycleNumber, integer const nonlinearIteration) override
function to apply a linear system solver to the assembled system.
virtual void implicitStepSetup(real64 const &time_n, real64 const &dt, DomainPartition &domain) override
function to perform setup for implicit timestep
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
stdVector< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:361
array1d< globalIndex > globalIndex_array
A 1-dimensional array of geos::globalIndex types.
Definition: DataTypes.hpp:370
LvArray::CRSMatrix< T, COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > CRSMatrix
Alias for CRS Matrix class.
Definition: DataTypes.hpp:305
std::string string
String type.
Definition: DataTypes.hpp:90
LvArray::SparsityPattern< COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > SparsityPattern
Alias for Sparsity pattern class.
Definition: DataTypes.hpp:297
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:309
LvArray::SortedArray< T, localIndex, LvArray::ChaiBuffer > SortedArray
A sorted array of local indices.
Definition: DataTypes.hpp:266
LAInterface::ParallelMatrix ParallelMatrix
Alias for ParallelMatrix.
int integer
Signed integer type.
Definition: DataTypes.hpp:81
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:175
ENUM_STRINGS(LinearSolverParameters::SolverType, "direct", "cg", "gmres", "fgmres", "bicgstab", "richardson", "preconditioner")
Declare strings associated with enumeration values.
LAInterface::ParallelVector ParallelVector
Alias for ParallelVector.
Structure to hold scoped key names.