MFEM  v4.1.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
nonlininteg.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, 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_NONLININTEG
13 #define MFEM_NONLININTEG
14 
15 #include "../config/config.hpp"
16 #include "fe.hpp"
17 #include "coefficient.hpp"
18 #include "fespace.hpp"
19 
20 namespace mfem
21 {
22 
23 /** The abstract base class NonlinearFormIntegrator is used to express the
24  local action of a general nonlinear finite element operator. In addition
25  it may provide the capability to assemble the local gradient operator
26  and to compute the local energy. */
28 {
29 protected:
31 
33  : IntRule(ir) { }
34 
35 public:
36  /** @brief Prescribe a fixed IntegrationRule to use (when @a ir != NULL) or
37  let the integrator choose (when @a ir == NULL). */
38  void SetIntRule(const IntegrationRule *ir) { IntRule = ir; }
39 
40  /// Prescribe a fixed IntegrationRule to use.
41  void SetIntegrationRule(const IntegrationRule &irule) { IntRule = &irule; }
42 
43  /// Perform the local action of the NonlinearFormIntegrator
44  virtual void AssembleElementVector(const FiniteElement &el,
46  const Vector &elfun, Vector &elvect);
47 
48  /// @brief Perform the local action of the NonlinearFormIntegrator resulting
49  /// from a face integral term.
50  virtual void AssembleFaceVector(const FiniteElement &el1,
51  const FiniteElement &el2,
53  const Vector &elfun, Vector &elvect);
54 
55  /// Assemble the local gradient matrix
56  virtual void AssembleElementGrad(const FiniteElement &el,
58  const Vector &elfun, DenseMatrix &elmat);
59 
60  /// @brief Assemble the local action of the gradient of the
61  /// NonlinearFormIntegrator resulting from a face integral term.
62  virtual void AssembleFaceGrad(const FiniteElement &el1,
63  const FiniteElement &el2,
65  const Vector &elfun, DenseMatrix &elmat);
66 
67  /// Compute the local energy
68  virtual double GetElementEnergy(const FiniteElement &el,
70  const Vector &elfun);
71 
72  /// Method defining partial assembly.
73  /** The result of the partial assembly is stored internally so that it can be
74  used later in the methods AddMultPA(). */
75  virtual void AssemblePA(const FiniteElementSpace &fes);
76 
77  /** The result of the partial assembly is stored internally so that it can be
78  used later in the methods AddMultPA().
79  Used with BilinearFormIntegrators that have different spaces. */
80  virtual void AssemblePA(const FiniteElementSpace &trial_fes,
81  const FiniteElementSpace &test_fes);
82 
83  /// Method for partially assembled action.
84  /** Perform the action of integrator on the input @a x and add the result to
85  the output @a y. Both @a x and @a y are E-vectors, i.e. they represent
86  the element-wise discontinuous version of the FE space.
87 
88  This method can be called only after the method AssemblePA() has been
89  called. */
90  virtual void AddMultPA(const Vector &x, Vector &y) const;
91 
93 };
94 
95 /** The abstract base class BlockNonlinearFormIntegrator is
96  a generalization of the NonlinearFormIntegrator class suitable
97  for block state vectors. */
99 {
100 public:
101  /// Compute the local energy
102  virtual double GetElementEnergy(const Array<const FiniteElement *>&el,
104  const Array<const Vector *>&elfun);
105 
106  /// Perform the local action of the BlockNonlinearFormIntegrator
109  const Array<const Vector *> &elfun,
110  const Array<Vector *> &elvec);
111 
112  virtual void AssembleFaceVector(const Array<const FiniteElement *> &el1,
113  const Array<const FiniteElement *> &el2,
115  const Array<const Vector *> &elfun,
116  const Array<Vector *> &elvect);
117 
118  /// Assemble the local gradient matrix
119  virtual void AssembleElementGrad(const Array<const FiniteElement*> &el,
121  const Array<const Vector *> &elfun,
122  const Array2D<DenseMatrix *> &elmats);
123 
124  virtual void AssembleFaceGrad(const Array<const FiniteElement *>&el1,
127  const Array<const Vector *> &elfun,
128  const Array2D<DenseMatrix *> &elmats);
129 
131 };
132 
133 
134 /// Abstract class for hyperelastic models
136 {
137 protected:
138  ElementTransformation *Ttr; /**< Reference-element to target-element
139  transformation. */
140 
141 public:
142  HyperelasticModel() : Ttr(NULL) { }
143  virtual ~HyperelasticModel() { }
144 
145  /// A reference-element to target-element transformation that can be used to
146  /// evaluate Coefficient%s.
147  /** @note It is assumed that _Ttr.SetIntPoint() is already called for the
148  point of interest. */
149  void SetTransformation(ElementTransformation &_Ttr) { Ttr = &_Ttr; }
150 
151  /** @brief Evaluate the strain energy density function, W = W(Jpt).
152  @param[in] Jpt Represents the target->physical transformation
153  Jacobian matrix. */
154  virtual double EvalW(const DenseMatrix &Jpt) const = 0;
155 
156  /** @brief Evaluate the 1st Piola-Kirchhoff stress tensor, P = P(Jpt).
157  @param[in] Jpt Represents the target->physical transformation
158  Jacobian matrix.
159  @param[out] P The evaluated 1st Piola-Kirchhoff stress tensor. */
160  virtual void EvalP(const DenseMatrix &Jpt, DenseMatrix &P) const = 0;
161 
162  /** @brief Evaluate the derivative of the 1st Piola-Kirchhoff stress tensor
163  and assemble its contribution to the local gradient matrix 'A'.
164  @param[in] Jpt Represents the target->physical transformation
165  Jacobian matrix.
166  @param[in] DS Gradient of the basis matrix (dof x dim).
167  @param[in] weight Quadrature weight coefficient for the point.
168  @param[in,out] A Local gradient matrix where the contribution from this
169  point will be added.
170 
171  Computes weight * d(dW_dxi)_d(xj) at the current point, for all i and j,
172  where x1 ... xn are the FE dofs. This function is usually defined using
173  the matrix invariants and their derivatives.
174  */
175  virtual void AssembleH(const DenseMatrix &Jpt, const DenseMatrix &DS,
176  const double weight, DenseMatrix &A) const = 0;
177 };
178 
179 
180 /** Inverse-harmonic hyperelastic model with a strain energy density function
181  given by the formula: W(J) = (1/2) det(J) Tr((J J^t)^{-1}) where J is the
182  deformation gradient. */
184 {
185 protected:
186  mutable DenseMatrix Z, S; // dim x dim
187  mutable DenseMatrix G, C; // dof x dim
188 
189 public:
190  virtual double EvalW(const DenseMatrix &J) const;
191 
192  virtual void EvalP(const DenseMatrix &J, DenseMatrix &P) const;
193 
194  virtual void AssembleH(const DenseMatrix &J, const DenseMatrix &DS,
195  const double weight, DenseMatrix &A) const;
196 };
197 
198 
199 /** Neo-Hookean hyperelastic model with a strain energy density function given
200  by the formula: \f$(\mu/2)(\bar{I}_1 - dim) + (K/2)(det(J)/g - 1)^2\f$ where
201  J is the deformation gradient and \f$\bar{I}_1 = (det(J))^{-2/dim} Tr(J
202  J^t)\f$. The parameters \f$\mu\f$ and K are the shear and bulk moduli,
203  respectively, and g is a reference volumetric scaling. */
205 {
206 protected:
207  mutable double mu, K, g;
210 
211  mutable DenseMatrix Z; // dim x dim
212  mutable DenseMatrix G, C; // dof x dim
213 
214  inline void EvalCoeffs() const;
215 
216 public:
217  NeoHookeanModel(double _mu, double _K, double _g = 1.0)
218  : mu(_mu), K(_K), g(_g), have_coeffs(false) { c_mu = c_K = c_g = NULL; }
219 
221  : mu(0.0), K(0.0), g(1.0), c_mu(&_mu), c_K(&_K), c_g(_g),
222  have_coeffs(true) { }
223 
224  virtual double EvalW(const DenseMatrix &J) const;
225 
226  virtual void EvalP(const DenseMatrix &J, DenseMatrix &P) const;
227 
228  virtual void AssembleH(const DenseMatrix &J, const DenseMatrix &DS,
229  const double weight, DenseMatrix &A) const;
230 };
231 
232 
233 /** Hyperelastic integrator for any given HyperelasticModel.
234 
235  Represents @f$ \int W(Jpt) dx @f$ over a target zone, where W is the
236  @a model's strain energy density function, and Jpt is the Jacobian of the
237  target->physical coordinates transformation. The target configuration is
238  given by the current mesh at the time of the evaluation of the integrator.
239 */
241 {
242 private:
243  HyperelasticModel *model;
244 
245  // Jrt: the Jacobian of the target-to-reference-element transformation.
246  // Jpr: the Jacobian of the reference-to-physical-element transformation.
247  // Jpt: the Jacobian of the target-to-physical-element transformation.
248  // P: represents dW_d(Jtp) (dim x dim).
249  // DSh: gradients of reference shape functions (dof x dim).
250  // DS: gradients of the shape functions in the target (stress-free)
251  // configuration (dof x dim).
252  // PMatI: coordinates of the deformed configuration (dof x dim).
253  // PMatO: reshaped view into the local element contribution to the operator
254  // output - the result of AssembleElementVector() (dof x dim).
255  DenseMatrix DSh, DS, Jrt, Jpr, Jpt, P, PMatI, PMatO;
256 
257 public:
258  /** @param[in] m HyperelasticModel that will be integrated. */
260 
261  /** @brief Computes the integral of W(Jacobian(Trt)) over a target zone
262  @param[in] el Type of FiniteElement.
263  @param[in] Ttr Represents ref->target coordinates transformation.
264  @param[in] elfun Physical coordinates of the zone. */
265  virtual double GetElementEnergy(const FiniteElement &el,
267  const Vector &elfun);
268 
269  virtual void AssembleElementVector(const FiniteElement &el,
271  const Vector &elfun, Vector &elvect);
272 
273  virtual void AssembleElementGrad(const FiniteElement &el,
275  const Vector &elfun, DenseMatrix &elmat);
276 };
277 
278 /** Hyperelastic incompressible Neo-Hookean integrator with the PK1 stress
279  \f$P = \mu F - p F^{-T}\f$ where \f$\mu\f$ is the shear modulus,
280  \f$p\f$ is the pressure, and \f$F\f$ is the deformation gradient */
282 {
283 private:
284  Coefficient *c_mu;
285  DenseMatrix DSh_u, DS_u, J0i, J, J1, Finv, P, F, FinvT;
286  DenseMatrix PMatI_u, PMatO_u, PMatI_p, PMatO_p, Z, G, C;
287  Vector Sh_p;
288 
289 public:
291 
292  virtual double GetElementEnergy(const Array<const FiniteElement *>&el,
294  const Array<const Vector *> &elfun);
295 
296  /// Perform the local action of the NonlinearFormIntegrator
299  const Array<const Vector *> &elfun,
300  const Array<Vector *> &elvec);
301 
302  /// Assemble the local gradient matrix
303  virtual void AssembleElementGrad(const Array<const FiniteElement*> &el,
305  const Array<const Vector *> &elfun,
306  const Array2D<DenseMatrix *> &elmats);
307 };
308 
310 {
311 private:
312  Coefficient *Q{};
313  DenseMatrix dshape, dshapex, EF, gradEF, ELV, elmat_comp;
314  Vector shape;
315  // PA extension
316  Vector pa_data;
317  const DofToQuad *maps; ///< Not owned
318  const GeometricFactors *geom; ///< Not owned
319  int dim, ne, nq;
320 public:
322 
323  VectorConvectionNLFIntegrator() = default;
324 
325  static const IntegrationRule &GetRule(const FiniteElement &fe,
327 
328  virtual void AssembleElementVector(const FiniteElement &el,
330  const Vector &elfun,
331  Vector &elvect);
332 
333  virtual void AssembleElementGrad(const FiniteElement &el,
335  const Vector &elfun,
336  DenseMatrix &elmat);
337 
339 
340  virtual void AssemblePA(const FiniteElementSpace &fes);
341 
342  virtual void AddMultPA(const Vector &x, Vector &y) const;
343 };
344 
345 }
346 
347 #endif
Abstract class for Finite Elements.
Definition: fe.hpp:232
virtual void AddMultPA(const Vector &x, Vector &y) const
Method for partially assembled action.
Definition: nonlininteg.cpp:31
virtual void EvalP(const DenseMatrix &J, DenseMatrix &P) const
Evaluate the 1st Piola-Kirchhoff stress tensor, P = P(Jpt).
virtual double EvalW(const DenseMatrix &J) const
Evaluate the strain energy density function, W = W(Jpt).
virtual void AssembleElementGrad(const Array< const FiniteElement * > &el, ElementTransformation &Tr, const Array< const Vector * > &elfun, const Array2D< DenseMatrix * > &elmats)
Assemble the local gradient matrix.
Class for an integration rule - an Array of IntegrationPoint.
Definition: intrules.hpp:90
virtual void AssembleFaceVector(const Array< const FiniteElement * > &el1, const Array< const FiniteElement * > &el2, FaceElementTransformations &Tr, const Array< const Vector * > &elfun, const Array< Vector * > &elvect)
Definition: nonlininteg.cpp:89
NeoHookeanModel(Coefficient &_mu, Coefficient &_K, Coefficient *_g=NULL)
virtual void AssembleH(const DenseMatrix &J, const DenseMatrix &DS, const double weight, DenseMatrix &A) const
Evaluate the derivative of the 1st Piola-Kirchhoff stress tensor and assemble its contribution to the...
Data type dense matrix using column-major storage.
Definition: densemat.hpp:23
virtual double EvalW(const DenseMatrix &Jpt) const =0
Evaluate the strain energy density function, W = W(Jpt).
Structure for storing mesh geometric factors: coordinates, Jacobians, and determinants of the Jacobia...
Definition: mesh.hpp:1332
virtual void AssembleElementVector(const FiniteElement &el, ElementTransformation &trans, const Vector &elfun, Vector &elvect)
Perform the local action of the NonlinearFormIntegrator.
virtual void EvalP(const DenseMatrix &J, DenseMatrix &P) const
Evaluate the 1st Piola-Kirchhoff stress tensor, P = P(Jpt).
virtual void AssembleFaceGrad(const Array< const FiniteElement * > &el1, const Array< const FiniteElement * > &el2, FaceElementTransformations &Tr, const Array< const Vector * > &elfun, const Array2D< DenseMatrix * > &elmats)
virtual void EvalP(const DenseMatrix &Jpt, DenseMatrix &P) const =0
Evaluate the 1st Piola-Kirchhoff stress tensor, P = P(Jpt).
virtual void AssembleElementGrad(const FiniteElement &el, ElementTransformation &trans, const Vector &elfun, DenseMatrix &elmat)
Assemble the local gradient matrix.
virtual void AssemblePA(const FiniteElementSpace &fes)
Method defining partial assembly.
virtual void AssembleElementGrad(const Array< const FiniteElement * > &el, ElementTransformation &Tr, const Array< const Vector * > &elfun, const Array2D< DenseMatrix * > &elmats)
Assemble the local gradient matrix.
void EvalCoeffs() const
virtual void AssemblePA(const FiniteElementSpace &fes)
Method defining partial assembly.
Definition: nonlininteg.cpp:18
virtual void AssembleFaceGrad(const FiniteElement &el1, const FiniteElement &el2, FaceElementTransformations &Tr, const Vector &elfun, DenseMatrix &elmat)
Assemble the local action of the gradient of the NonlinearFormIntegrator resulting from a face integr...
Definition: nonlininteg.cpp:61
virtual double GetElementEnergy(const Array< const FiniteElement * > &el, ElementTransformation &Tr, const Array< const Vector * > &elfun)
Compute the local energy.
virtual void AssembleElementGrad(const FiniteElement &el, ElementTransformation &Ttr, const Vector &elfun, DenseMatrix &elmat)
Assemble the local gradient matrix.
virtual void AssembleElementVector(const FiniteElement &el, ElementTransformation &Tr, const Vector &elfun, Vector &elvect)
Perform the local action of the NonlinearFormIntegrator.
Definition: nonlininteg.cpp:37
virtual double GetElementEnergy(const FiniteElement &el, ElementTransformation &Ttr, const Vector &elfun)
Computes the integral of W(Jacobian(Trt)) over a target zone.
void trans(const Vector &x, Vector &p)
Definition: toroid.cpp:239
Dynamic 2D array using row-major layout.
Definition: array.hpp:316
void SetTransformation(ElementTransformation &_Ttr)
virtual void AssembleElementGrad(const FiniteElement &el, ElementTransformation &Tr, const Vector &elfun, DenseMatrix &elmat)
Assemble the local gradient matrix.
Definition: nonlininteg.cpp:53
NeoHookeanModel(double _mu, double _K, double _g=1.0)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:87
Base class Coefficient that may optionally depend on time.
Definition: coefficient.hpp:31
virtual void AssembleFaceVector(const FiniteElement &el1, const FiniteElement &el2, FaceElementTransformations &Tr, const Vector &elfun, Vector &elvect)
Perform the local action of the NonlinearFormIntegrator resulting from a face integral term...
Definition: nonlininteg.cpp:45
Structure representing the matrices/tensors needed to evaluate (in reference space) the values...
Definition: fe.hpp:128
ElementTransformation * Ttr
const IntegrationRule * IntRule
Definition: nonlininteg.hpp:30
VectorConvectionNLFIntegrator(Coefficient &q)
virtual void AssembleH(const DenseMatrix &J, const DenseMatrix &DS, const double weight, DenseMatrix &A) const
Evaluate the derivative of the 1st Piola-Kirchhoff stress tensor and assemble its contribution to the...
HyperelasticNLFIntegrator(HyperelasticModel *m)
virtual double EvalW(const DenseMatrix &J) const
Evaluate the strain energy density function, W = W(Jpt).
void SetIntegrationRule(const IntegrationRule &irule)
Prescribe a fixed IntegrationRule to use.
Definition: nonlininteg.hpp:41
virtual void AssembleH(const DenseMatrix &Jpt, const DenseMatrix &DS, const double weight, DenseMatrix &A) const =0
Evaluate the derivative of the 1st Piola-Kirchhoff stress tensor and assemble its contribution to the...
virtual void AssembleElementVector(const Array< const FiniteElement * > &el, ElementTransformation &Tr, const Array< const Vector * > &elfun, const Array< Vector * > &elvec)
Perform the local action of the NonlinearFormIntegrator.
virtual void AddMultPA(const Vector &x, Vector &y) const
Method for partially assembled action.
void SetIntRule(const IntegrationRule *ir)
Prescribe a fixed IntegrationRule to use (when ir != NULL) or let the integrator choose (when ir == N...
Definition: nonlininteg.hpp:38
Abstract class for hyperelastic models.
IncompressibleNeoHookeanIntegrator(Coefficient &_mu)
virtual void AssembleElementVector(const FiniteElement &el, ElementTransformation &Ttr, const Vector &elfun, Vector &elvect)
Perform the local action of the NonlinearFormIntegrator.
virtual double GetElementEnergy(const Array< const FiniteElement * > &el, ElementTransformation &Tr, const Array< const Vector * > &elfun)
Compute the local energy.
Vector data type.
Definition: vector.hpp:48
NonlinearFormIntegrator(const IntegrationRule *ir=NULL)
Definition: nonlininteg.hpp:32
virtual double GetElementEnergy(const FiniteElement &el, ElementTransformation &Tr, const Vector &elfun)
Compute the local energy.
Definition: nonlininteg.cpp:70
static const IntegrationRule & GetRule(const FiniteElement &fe, ElementTransformation &T)
virtual void AssembleElementVector(const Array< const FiniteElement * > &el, ElementTransformation &Tr, const Array< const Vector * > &elfun, const Array< Vector * > &elvec)
Perform the local action of the BlockNonlinearFormIntegrator.
Definition: nonlininteg.cpp:79