MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
elastoperator.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_ELASTICITY_OPERATOR
13#define MFEM_ELASTICITY_OPERATOR
14
15#include "mfem.hpp"
16
17namespace mfem
18{
19
20/**
21 * @class ElasticityOperator
22 * @brief Parallel finite element operator for linear and nonlinear elasticity.
23 *
24 * This class sets up and evaluates finite element operators for elasticity on a parallel mesh.
25 * It supports both linear and nonlinear (Neo-Hookean) formulations.
26 * Features include evaluation of energy, gradient, and Hessian for use in optimization solvers.
27 */
28class ElasticityOperator
29{
30private:
31 MPI_Comm comm;
32
33 /// Toggle for nonlinear formulation (true = Neo-Hookean, false = linear elasticity).
34 bool nonlinear = false;
35
36 /// Tracks whether the linear system has been formed.
37 bool formsystem = false;
38
39 ParMesh * pmesh = nullptr;
40
41 /// Essential boundary attribute markers.
42 Array<int> ess_bdr, ess_bdr_attr;
43
44 /// Essential DOFs (true DOF list) and component-based attributes.
45 Array<int> ess_tdof_list, ess_bdr_attr_comp;
46
47 /// Polynomial order of the FE basis (default = 1).
48 int order=1;
49
50 /// Global number of true DOFs in the FE space.
51 int globalntdofs;
52
53 /// Finite element collection (H1).
54 FiniteElementCollection * fec = nullptr;
55
56 /// Parallel finite element space for displacement.
57 ParFiniteElementSpace * fes = nullptr;
58
59 /// Underlying operator: bilinear form (linear) or nonlinear form (nonlinear).
60 Operator * op = nullptr;
61
62 /// Linear form for RHS assembly.
63 ParLinearForm * b = nullptr;
64
65 /// Current solution
66 ParGridFunction x;
67
68 // System matrix
69 HypreParMatrix *K=nullptr;
70
71 /// Right-hand side (B) and solution vector (X).
72 Vector B, X;
73
74 /// Neumann pressure coefficient (for traction BCs).
75 ConstantCoefficient pressure_cf;
76
77 /// Material parameters:
78 /// - Linear: c1 = λ (1ˢᵗ Lame parameter), c2 = μ (2ⁿᵈ Lame parameter or shear modulus)
79 /// - Nonlinear: c1 = G (shear modulus), c2 = K (bulk modulus)
80 Vector c1, c2;
81 PWConstCoefficient c1_cf, c2_cf;
82
83 /// Hyperelastic material model (only for nonlinear case).
84 NeoHookeanModel * material_model = nullptr;
85
86 /// Reference configuration displacement
87 Vector xref;
88
89 /// Internal setup functions
90 void Init();
91 void SetEssentialBC();
92 void SetUpOperator();
93
94public:
95 /** @brief Construct an ElasticityOperator.
96 * @param pmesh_ Parallel mesh.
97 * @param ess_bdr_attr_ Array of essential boundary attributes.
98 * @param ess_bdr_attr_comp_ Component index for each essential boundary attribute.
99 * @param E Vector of Young’s modulus values (per attribute).
100 * @param nu Vector of Poisson’s ratio values (per attribute).
101 * @param nonlinear_ If true, setup nonlinear hyperelasticity.
102 */
103 ElasticityOperator(ParMesh * pmesh_, Array<int> & ess_bdr_attr_,
104 Array<int> & ess_bdr_attr_comp_,
105 const Vector & E, const Vector & nu, bool nonlinear_ = false);
106
107 /// Set material parameters from vectors of Young’s modulus (E) and Poisson’s ratio (ν).
108 void SetParameters(const Vector & E, const Vector & nu);
109
110 /// Apply Neumann (pressure) boundary condition on a set of boundary markers.
111 void SetNeumanPressureData(ConstantCoefficient &f, Array<int> & bdr_marker);
112
113 /// Apply Dirichlet (displacement) boundary condition on a set of boundary markers.
114 void SetDisplacementDirichletData(const Vector & delta, Array<int> essbdr);
115
116 /// Assemble and form the linear system (matrix and RHS).
117 void FormLinearSystem();
118
119 /// Reset and reassemble the RHS linear form.
120 void UpdateRHS();
121
122 ParMesh * GetMesh() const { return pmesh; };
123 MPI_Comm GetComm() const { return comm; };
124
125 ParFiniteElementSpace * GetFESpace() const { return fes; };
126
127 int GetGlobalNumDofs() const { return globalntdofs; };
128
129 const Array<int> & GetEssentialDofs() const { return ess_tdof_list; };
130
131 /// Get the displacement with essential boundary conditions applied.
132 void Getxrefbc(Vector & xrefbc) const {x.GetTrueDofs(xrefbc);}
133
134 /// Compute the elastic energy functional at a given displacement vector.
135 real_t GetEnergy(const Vector & u) const;
136
137 /// Compute the gradient of the energy functional at a given displacement vector.
138 void GetGradient(const Vector & u, Vector & gradE) const;
139
140 /// Get the Hessian (stiffness matrix) at a given displacement vector.
142
143 /// Check if the operator is nonlinear.
144 bool IsNonlinear() { return nonlinear; }
145
146 /// Destructor (cleans up FE space, operator, and material model).
148};
149
150}
151
152#endif
ParMesh * GetMesh() const
ElasticityOperator(ParMesh *pmesh_, Array< int > &ess_bdr_attr_, Array< int > &ess_bdr_attr_comp_, const Vector &E, const Vector &nu, bool nonlinear_=false)
Construct an ElasticityOperator.
void FormLinearSystem()
Assemble and form the linear system (matrix and RHS).
ParFiniteElementSpace * GetFESpace() const
void UpdateRHS()
Reset and reassemble the RHS linear form.
void SetNeumanPressureData(ConstantCoefficient &f, Array< int > &bdr_marker)
Apply Neumann (pressure) boundary condition on a set of boundary markers.
const Array< int > & GetEssentialDofs() const
bool IsNonlinear()
Check if the operator is nonlinear.
~ElasticityOperator()
Destructor (cleans up FE space, operator, and material model).
void GetGradient(const Vector &u, Vector &gradE) const
Compute the gradient of the energy functional at a given displacement vector.
void SetParameters(const Vector &E, const Vector &nu)
Set material parameters from vectors of Young’s modulus (E) and Poisson’s ratio (ν).
HypreParMatrix * GetHessian(const Vector &u)
Get the Hessian (stiffness matrix) at a given displacement vector.
void Getxrefbc(Vector &xrefbc) const
Get the displacement with essential boundary conditions applied.
void SetDisplacementDirichletData(const Vector &delta, Array< int > essbdr)
Apply Dirichlet (displacement) boundary condition on a set of boundary markers.
real_t GetEnergy(const Vector &u) const
Compute the elastic energy functional at a given displacement vector.
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:419
Operator(int s=0)
Construct a square Operator with given size s (default 0).
Definition operator.hpp:59
Abstract parallel finite element space.
Definition pfespace.hpp:31
Class for parallel meshes.
Definition pmesh.hpp:34
Vector data type.
Definition vector.hpp:82
real_t delta
Definition lissajous.cpp:43
real_t u(const Vector &xvec)
Definition lor_mms.hpp:22
float real_t
Definition config.hpp:46
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30