MFEM v4.8.0
Finite element discretization library
Loading...
Searching...
No Matches
ex10.cpp
Go to the documentation of this file.
1// MFEM Example 10
2//
3// Compile with: make ex10
4//
5// Sample runs:
6// ex10 -m ../data/beam-quad.mesh -s 23 -r 2 -o 2 -dt 3
7// ex10 -m ../data/beam-tri.mesh -s 23 -r 2 -o 2 -dt 3
8// ex10 -m ../data/beam-hex.mesh -s 22 -r 1 -o 2 -dt 3
9// ex10 -m ../data/beam-tet.mesh -s 22 -r 1 -o 2 -dt 3
10// ex10 -m ../data/beam-wedge.mesh -s 22 -r 1 -o 2 -dt 3
11// ex10 -m ../data/beam-quad.mesh -s 4 -r 2 -o 2 -dt 0.03 -vs 20
12// ex10 -m ../data/beam-hex.mesh -s 4 -r 1 -o 2 -dt 0.05 -vs 20
13// ex10 -m ../data/beam-quad-amr.mesh -s 23 -r 2 -o 2 -dt 3
14//
15// Description: This examples solves a time dependent nonlinear elasticity
16// problem of the form dv/dt = H(x) + S v, dx/dt = v, where H is a
17// hyperelastic model and S is a viscosity operator of Laplacian
18// type. The geometry of the domain is assumed to be as follows:
19//
20// +---------------------+
21// boundary --->| |
22// attribute 1 | |
23// (fixed) +---------------------+
24//
25// The example demonstrates the use of nonlinear operators (the
26// class HyperelasticOperator defining H(x)), as well as their
27// implicit time integration using a Newton method for solving an
28// associated reduced backward-Euler type nonlinear equation
29// (class ReducedSystemOperator). Each Newton step requires the
30// inversion of a Jacobian matrix, which is done through a
31// (preconditioned) inner solver. Note that implementing the
32// method HyperelasticOperator::ImplicitSolve is the only
33// requirement for high-order implicit (SDIRK) time integration.
34//
35// We recommend viewing examples 2 and 9 before viewing this
36// example.
37
38#include "mfem.hpp"
39#include <memory>
40#include <iostream>
41#include <fstream>
42
43using namespace std;
44using namespace mfem;
45
46class ReducedSystemOperator;
47
48/** After spatial discretization, the hyperelastic model can be written as a
49 * system of ODEs:
50 * dv/dt = -M^{-1}*(H(x) + S*v)
51 * dx/dt = v,
52 * where x is the vector representing the deformation, v is the velocity field,
53 * M is the mass matrix, S is the viscosity matrix, and H(x) is the nonlinear
54 * hyperelastic operator.
55 *
56 * Class HyperelasticOperator represents the right-hand side of the above
57 * system of ODEs. */
58class HyperelasticOperator : public TimeDependentOperator
59{
60protected:
61 FiniteElementSpace &fespace;
62
63 BilinearForm M, S;
65 real_t viscosity;
66 HyperelasticModel *model;
67
68 CGSolver M_solver; // Krylov solver for inverting the mass matrix M
69 DSmoother M_prec; // Preconditioner for the mass matrix M
70
71 /** Nonlinear operator defining the reduced backward Euler equation for the
72 velocity. Used in the implementation of method ImplicitSolve. */
73 ReducedSystemOperator *reduced_oper;
74
75 /// Newton solver for the reduced backward Euler equation
76 NewtonSolver newton_solver;
77
78 /// Solver for the Jacobian solve in the Newton method
79 Solver *J_solver;
80 /// Preconditioner for the Jacobian solve in the Newton method
81 Solver *J_prec;
82
83 mutable Vector z; // auxiliary vector
84
85public:
86 HyperelasticOperator(FiniteElementSpace &f, Array<int> &ess_bdr,
87 real_t visc, real_t mu, real_t K);
88
89 /// Compute the right-hand side of the ODE system.
90 void Mult(const Vector &vx, Vector &dvx_dt) const override;
91 /** Solve the Backward-Euler equation: k = f(x + dt*k, t), for the unknown k.
92 This is the only requirement for high-order SDIRK implicit integration.*/
93 void ImplicitSolve(const real_t dt, const Vector &x, Vector &k) override;
94
95 real_t ElasticEnergy(const Vector &x) const;
96 real_t KineticEnergy(const Vector &v) const;
97 void GetElasticEnergyDensity(const GridFunction &x, GridFunction &w) const;
98
99 ~HyperelasticOperator() override;
100};
101
102/** Nonlinear operator of the form:
103 k --> (M + dt*S)*k + H(x + dt*v + dt^2*k) + S*v,
104 where M and S are given BilinearForms, H is a given NonlinearForm, v and x
105 are given vectors, and dt is a scalar. */
106class ReducedSystemOperator : public Operator
107{
108private:
109 BilinearForm *M, *S;
110 NonlinearForm *H;
111 mutable SparseMatrix *Jacobian;
112 real_t dt;
113 const Vector *v, *x;
114 mutable Vector w, z;
115
116public:
117 ReducedSystemOperator(BilinearForm *M_, BilinearForm *S_, NonlinearForm *H_);
118
119 /// Set current dt, v, x values - needed to compute action and Jacobian.
120 void SetParameters(real_t dt_, const Vector *v_, const Vector *x_);
121
122 /// Compute y = H(x + dt (v + dt k)) + M k + S (v + dt k).
123 void Mult(const Vector &k, Vector &y) const override;
124
125 /// Compute J = M + dt S + dt^2 grad_H(x + dt (v + dt k)).
126 Operator &GetGradient(const Vector &k) const override;
127
128 ~ReducedSystemOperator() override;
129};
130
131
132/** Function representing the elastic energy density for the given hyperelastic
133 model+deformation. Used in HyperelasticOperator::GetElasticEnergyDensity. */
134class ElasticEnergyCoefficient : public Coefficient
135{
136private:
137 HyperelasticModel &model;
138 const GridFunction &x;
139 DenseMatrix J;
140
141public:
142 ElasticEnergyCoefficient(HyperelasticModel &m, const GridFunction &x_)
143 : model(m), x(x_) { }
144 real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override;
145 ~ElasticEnergyCoefficient() override { }
146};
147
148void InitialDeformation(const Vector &x, Vector &y);
149
150void InitialVelocity(const Vector &x, Vector &v);
151
152void visualize(ostream &os, Mesh *mesh, GridFunction *deformed_nodes,
153 GridFunction *field, const char *field_name = NULL,
154 bool init_vis = false);
155
156
157int main(int argc, char *argv[])
158{
159 // 1. Parse command-line options.
160 const char *mesh_file = "../data/beam-quad.mesh";
161 int ref_levels = 2;
162 int order = 2;
163 int ode_solver_type = 23;
164 real_t t_final = 300.0;
165 real_t dt = 3.0;
166 real_t visc = 1e-2;
167 real_t mu = 0.25;
168 real_t K = 5.0;
169 bool visualization = true;
170 int vis_steps = 1;
171
172 OptionsParser args(argc, argv);
173 args.AddOption(&mesh_file, "-m", "--mesh",
174 "Mesh file to use.");
175 args.AddOption(&ref_levels, "-r", "--refine",
176 "Number of times to refine the mesh uniformly.");
177 args.AddOption(&order, "-o", "--order",
178 "Order (degree) of the finite elements.");
179 args.AddOption(&ode_solver_type, "-s", "--ode-solver",
180 ODESolver::Types.c_str());
181 args.AddOption(&t_final, "-tf", "--t-final",
182 "Final time; start time is 0.");
183 args.AddOption(&dt, "-dt", "--time-step",
184 "Time step.");
185 args.AddOption(&visc, "-v", "--viscosity",
186 "Viscosity coefficient.");
187 args.AddOption(&mu, "-mu", "--shear-modulus",
188 "Shear modulus in the Neo-Hookean hyperelastic model.");
189 args.AddOption(&K, "-K", "--bulk-modulus",
190 "Bulk modulus in the Neo-Hookean hyperelastic model.");
191 args.AddOption(&visualization, "-vis", "--visualization", "-no-vis",
192 "--no-visualization",
193 "Enable or disable GLVis visualization.");
194 args.AddOption(&vis_steps, "-vs", "--visualization-steps",
195 "Visualize every n-th timestep.");
196 args.Parse();
197 if (!args.Good())
198 {
199 args.PrintUsage(cout);
200 return 1;
201 }
202 args.PrintOptions(cout);
203
204 // 2. Read the mesh from the given mesh file. We can handle triangular,
205 // quadrilateral, tetrahedral and hexahedral meshes with the same code.
206 Mesh *mesh = new Mesh(mesh_file, 1, 1);
207 int dim = mesh->Dimension();
208
209 // 3. Define the ODE solver used for time integration. Several implicit
210 // singly diagonal implicit Runge-Kutta (SDIRK) methods, as well as
211 // explicit Runge-Kutta methods are available.
212 unique_ptr<ODESolver> ode_solver = ODESolver::Select(ode_solver_type);
213
214 // 4. Refine the mesh to increase the resolution. In this example we do
215 // 'ref_levels' of uniform refinement, where 'ref_levels' is a
216 // command-line parameter.
217 for (int lev = 0; lev < ref_levels; lev++)
218 {
219 mesh->UniformRefinement();
220 }
221
222 // 5. Define the vector finite element spaces representing the mesh
223 // deformation x, the velocity v, and the initial configuration, x_ref.
224 // Define also the elastic energy density, w, which is in a discontinuous
225 // higher-order space. Since x and v are integrated in time as a system,
226 // we group them together in block vector vx, with offsets given by the
227 // fe_offset array.
228 H1_FECollection fe_coll(order, dim);
229 FiniteElementSpace fespace(mesh, &fe_coll, dim);
230
231 int fe_size = fespace.GetTrueVSize();
232 cout << "Number of velocity/deformation unknowns: " << fe_size << endl;
233 Array<int> fe_offset(3);
234 fe_offset[0] = 0;
235 fe_offset[1] = fe_size;
236 fe_offset[2] = 2*fe_size;
237
238 BlockVector vx(fe_offset);
239 GridFunction v, x;
240 v.MakeTRef(&fespace, vx.GetBlock(0), 0);
241 x.MakeTRef(&fespace, vx.GetBlock(1), 0);
242
243 GridFunction x_ref(&fespace);
244 mesh->GetNodes(x_ref);
245
246 L2_FECollection w_fec(order + 1, dim);
247 FiniteElementSpace w_fespace(mesh, &w_fec);
248 GridFunction w(&w_fespace);
249
250 // 6. Set the initial conditions for v and x, and the boundary conditions on
251 // a beam-like mesh (see description above).
253 v.ProjectCoefficient(velo);
254 v.SetTrueVector();
256 x.ProjectCoefficient(deform);
257 x.SetTrueVector();
258
259 Array<int> ess_bdr(fespace.GetMesh()->bdr_attributes.Max());
260 ess_bdr = 0;
261 ess_bdr[0] = 1; // boundary attribute 1 (index 0) is fixed
262
263 // 7. Initialize the hyperelastic operator, the GLVis visualization and print
264 // the initial energies.
265 HyperelasticOperator oper(fespace, ess_bdr, visc, mu, K);
266
267 socketstream vis_v, vis_w;
268 if (visualization)
269 {
270 char vishost[] = "localhost";
271 int visport = 19916;
272 vis_v.open(vishost, visport);
273 vis_v.precision(8);
275 visualize(vis_v, mesh, &x, &v, "Velocity", true);
276 vis_w.open(vishost, visport);
277 if (vis_w)
278 {
279 oper.GetElasticEnergyDensity(x, w);
280 vis_w.precision(8);
281 visualize(vis_w, mesh, &x, &w, "Elastic energy density", true);
282 }
283 cout << "GLVis visualization paused."
284 << " Press space (in the GLVis window) to resume it.\n";
285 }
286
287 real_t ee0 = oper.ElasticEnergy(x.GetTrueVector());
288 real_t ke0 = oper.KineticEnergy(v.GetTrueVector());
289 cout << "initial elastic energy (EE) = " << ee0 << endl;
290 cout << "initial kinetic energy (KE) = " << ke0 << endl;
291 cout << "initial total energy (TE) = " << (ee0 + ke0) << endl;
292
293 real_t t = 0.0;
294 oper.SetTime(t);
295 ode_solver->Init(oper);
296
297 // 8. Perform time-integration (looping over the time iterations, ti, with a
298 // time-step dt).
299 bool last_step = false;
300 for (int ti = 1; !last_step; ti++)
301 {
302 real_t dt_real = min(dt, t_final - t);
303
304 ode_solver->Step(vx, t, dt_real);
305
306 last_step = (t >= t_final - 1e-8*dt);
307
308 if (last_step || (ti % vis_steps) == 0)
309 {
310 real_t ee = oper.ElasticEnergy(x.GetTrueVector());
311 real_t ke = oper.KineticEnergy(v.GetTrueVector());
312
313 cout << "step " << ti << ", t = " << t << ", EE = " << ee << ", KE = "
314 << ke << ", ΔTE = " << (ee+ke)-(ee0+ke0) << endl;
315
316 if (visualization)
317 {
319 visualize(vis_v, mesh, &x, &v);
320 if (vis_w)
321 {
322 oper.GetElasticEnergyDensity(x, w);
323 visualize(vis_w, mesh, &x, &w);
324 }
325 }
326 }
327 }
328
329 // 9. Save the displaced mesh, the velocity and elastic energy.
330 {
332 GridFunction *nodes = &x;
333 int owns_nodes = 0;
334 mesh->SwapNodes(nodes, owns_nodes);
335 ofstream mesh_ofs("deformed.mesh");
336 mesh_ofs.precision(8);
337 mesh->Print(mesh_ofs);
338 mesh->SwapNodes(nodes, owns_nodes);
339 ofstream velo_ofs("velocity.sol");
340 velo_ofs.precision(8);
341 v.Save(velo_ofs);
342 ofstream ee_ofs("elastic_energy.sol");
343 ee_ofs.precision(8);
344 oper.GetElasticEnergyDensity(x, w);
345 w.Save(ee_ofs);
346 }
347
348 // 10. Free the used memory.
349 delete mesh;
350
351 return 0;
352}
353
354
355void visualize(ostream &os, Mesh *mesh, GridFunction *deformed_nodes,
356 GridFunction *field, const char *field_name, bool init_vis)
357{
358 if (!os)
359 {
360 return;
361 }
362
363 GridFunction *nodes = deformed_nodes;
364 int owns_nodes = 0;
365
366 mesh->SwapNodes(nodes, owns_nodes);
367
368 os << "solution\n" << *mesh << *field;
369
370 mesh->SwapNodes(nodes, owns_nodes);
371
372 if (init_vis)
373 {
374 os << "window_size 800 800\n";
375 os << "window_title '" << field_name << "'\n";
376 if (mesh->SpaceDimension() == 2)
377 {
378 os << "view 0 0\n"; // view from top
379 os << "keys jl\n"; // turn off perspective and light
380 }
381 os << "keys cm\n"; // show colorbar and mesh
382 // update value-range; keep mesh-extents fixed
383 os << "autoscale value\n";
384 os << "pause\n";
385 }
386 os << flush;
387}
388
389
390ReducedSystemOperator::ReducedSystemOperator(
392 : Operator(M_->Height()), M(M_), S(S_), H(H_), Jacobian(NULL),
393 dt(0.0), v(NULL), x(NULL), w(height), z(height)
394{ }
395
396void ReducedSystemOperator::SetParameters(real_t dt_, const Vector *v_,
397 const Vector *x_)
398{
399 dt = dt_; v = v_; x = x_;
400}
401
402void ReducedSystemOperator::Mult(const Vector &k, Vector &y) const
403{
404 // compute: y = H(x + dt*(v + dt*k)) + M*k + S*(v + dt*k)
405 add(*v, dt, k, w);
406 add(*x, dt, w, z);
407 H->Mult(z, y);
408 M->AddMult(k, y);
409 S->AddMult(w, y);
410}
411
412Operator &ReducedSystemOperator::GetGradient(const Vector &k) const
413{
414 delete Jacobian;
415 Jacobian = Add(1.0, M->SpMat(), dt, S->SpMat());
416 add(*v, dt, k, w);
417 add(*x, dt, w, z);
418 SparseMatrix *grad_H = dynamic_cast<SparseMatrix *>(&H->GetGradient(z));
419 Jacobian->Add(dt*dt, *grad_H);
420 return *Jacobian;
421}
422
423ReducedSystemOperator::~ReducedSystemOperator()
424{
425 delete Jacobian;
426}
427
428
429HyperelasticOperator::HyperelasticOperator(FiniteElementSpace &f,
430 Array<int> &ess_bdr, real_t visc,
431 real_t mu, real_t K)
432 : TimeDependentOperator(2*f.GetTrueVSize(), (real_t) 0.0), fespace(f),
433 M(&fespace), S(&fespace), H(&fespace),
434 viscosity(visc), z(height/2)
435{
436#if defined(MFEM_USE_DOUBLE)
437 const real_t rel_tol = 1e-8;
438 const real_t newton_abs_tol = 0.0;
439#elif defined(MFEM_USE_SINGLE)
440 const real_t rel_tol = 1e-3;
441 const real_t newton_abs_tol = 1e-4;
442#else
443#error "Only single and double precision are supported!"
444 const real_t rel_tol = real_t(1);
445 const real_t newton_abs_tol = real_t(0);
446#endif
447 const int skip_zero_entries = 0;
448
449 const real_t ref_density = 1.0; // density in the reference configuration
450 ConstantCoefficient rho0(ref_density);
451 M.AddDomainIntegrator(new VectorMassIntegrator(rho0));
452 M.Assemble(skip_zero_entries);
453 Array<int> ess_tdof_list;
454 fespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list);
455 SparseMatrix tmp;
456 M.FormSystemMatrix(ess_tdof_list, tmp);
457
458 M_solver.iterative_mode = false;
459 M_solver.SetRelTol(rel_tol);
460 M_solver.SetAbsTol(0.0);
461 M_solver.SetMaxIter(30);
462 M_solver.SetPrintLevel(0);
463 M_solver.SetPreconditioner(M_prec);
464 M_solver.SetOperator(M.SpMat());
465
466 model = new NeoHookeanModel(mu, K);
467 H.AddDomainIntegrator(new HyperelasticNLFIntegrator(model));
468 H.SetEssentialTrueDofs(ess_tdof_list);
469
470 ConstantCoefficient visc_coeff(viscosity);
471 S.AddDomainIntegrator(new VectorDiffusionIntegrator(visc_coeff));
472 S.Assemble(skip_zero_entries);
473 S.FormSystemMatrix(ess_tdof_list, tmp);
474
475 reduced_oper = new ReducedSystemOperator(&M, &S, &H);
476
477#ifndef MFEM_USE_SUITESPARSE
478 J_prec = new DSmoother(1);
479 MINRESSolver *J_minres = new MINRESSolver;
480 J_minres->SetRelTol(rel_tol);
481 J_minres->SetAbsTol(0.0);
482 J_minres->SetMaxIter(300);
483 J_minres->SetPrintLevel(-1);
484 J_minres->SetPreconditioner(*J_prec);
485 J_solver = J_minres;
486#else
487 J_solver = new UMFPackSolver;
488 J_prec = NULL;
489#endif
490
491 newton_solver.iterative_mode = false;
492 newton_solver.SetSolver(*J_solver);
493 newton_solver.SetOperator(*reduced_oper);
494 newton_solver.SetPrintLevel(1); // print Newton iterations
495 newton_solver.SetRelTol(rel_tol);
496 newton_solver.SetAbsTol(newton_abs_tol);
497 newton_solver.SetMaxIter(10);
498}
499
500void HyperelasticOperator::Mult(const Vector &vx, Vector &dvx_dt) const
501{
502 // Create views to the sub-vectors v, x of vx, and dv_dt, dx_dt of dvx_dt
503 int sc = height/2;
504 Vector v(vx.GetData() + 0, sc);
505 Vector x(vx.GetData() + sc, sc);
506 Vector dv_dt(dvx_dt.GetData() + 0, sc);
507 Vector dx_dt(dvx_dt.GetData() + sc, sc);
508
509 H.Mult(x, z);
510 if (viscosity != 0.0)
511 {
512 S.AddMult(v, z);
513 }
514 z.Neg(); // z = -z
515 M_solver.Mult(z, dv_dt);
516
517 dx_dt = v;
518}
519
520void HyperelasticOperator::ImplicitSolve(const real_t dt,
521 const Vector &vx, Vector &dvx_dt)
522{
523 int sc = height/2;
524 Vector v(vx.GetData() + 0, sc);
525 Vector x(vx.GetData() + sc, sc);
526 Vector dv_dt(dvx_dt.GetData() + 0, sc);
527 Vector dx_dt(dvx_dt.GetData() + sc, sc);
528
529 // By eliminating kx from the coupled system:
530 // kv = -M^{-1}*[H(x + dt*kx) + S*(v + dt*kv)]
531 // kx = v + dt*kv
532 // we reduce it to a nonlinear equation for kv, represented by the
533 // reduced_oper. This equation is solved with the newton_solver
534 // object (using J_solver and J_prec internally).
535 reduced_oper->SetParameters(dt, &v, &x);
536 Vector zero; // empty vector is interpreted as zero r.h.s. by NewtonSolver
537 newton_solver.Mult(zero, dv_dt);
538 MFEM_VERIFY(newton_solver.GetConverged(), "Newton solver did not converge.");
539 add(v, dt, dv_dt, dx_dt);
540}
541
542real_t HyperelasticOperator::ElasticEnergy(const Vector &x) const
543{
544 return H.GetEnergy(x);
545}
546
547real_t HyperelasticOperator::KineticEnergy(const Vector &v) const
548{
549 return 0.5*M.InnerProduct(v, v);
550}
551
552void HyperelasticOperator::GetElasticEnergyDensity(
553 const GridFunction &x, GridFunction &w) const
554{
555 ElasticEnergyCoefficient w_coeff(*model, x);
556 w.ProjectCoefficient(w_coeff);
557}
558
559HyperelasticOperator::~HyperelasticOperator()
560{
561 delete J_solver;
562 delete J_prec;
563 delete reduced_oper;
564 delete model;
565}
566
567
568real_t ElasticEnergyCoefficient::Eval(ElementTransformation &T,
569 const IntegrationPoint &ip)
570{
571 model.SetTransformation(T);
572 x.GetVectorGradient(T, J);
573 // return model.EvalW(J); // in reference configuration
574 return model.EvalW(J)/J.Det(); // in deformed configuration
575}
576
577
579{
580 // set the initial configuration to be the same as the reference, stress
581 // free, configuration
582 y = x;
583}
584
585void InitialVelocity(const Vector &x, Vector &v)
586{
587 const int dim = x.Size();
588 const real_t s = 0.1/64.;
589
590 v = 0.0;
591 v(dim-1) = s*x(0)*x(0)*(8.0-x(0));
592 v(0) = -s*x(0)*x(0);
593}
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
Definition array.cpp:68
A "square matrix" operator for the associated FE space and BLFIntegrators The sum of all the BLFInteg...
void AddMult(const Vector &x, Vector &y, const real_t a=1.0) const override
Add the matrix vector multiple to a vector: .
real_t InnerProduct(const Vector &x, const Vector &y) const
Compute .
const SparseMatrix & SpMat() const
Returns a const reference to the sparse matrix: .
A class to handle Vectors in a block fashion.
Vector & GetBlock(int i)
Get the i-th vector in the block.
Conjugate gradient method.
Definition solvers.hpp:538
void Mult(const Vector &b, Vector &x) const override
Iterative solution of the linear system using the Conjugate Gradient method.
Definition solvers.cpp:751
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
A coefficient that is constant across space and time.
Data type for scaled Jacobi-type smoother of sparse matrix.
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
real_t Det() const
Definition densemat.cpp:516
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:244
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
Definition fespace.hpp:851
Mesh * GetMesh() const
Returns the mesh.
Definition fespace.hpp:679
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:31
void GetVectorGradient(ElementTransformation &tr, DenseMatrix &grad) const
Compute the vector gradient with respect to the physical element variable.
void SetTrueVector()
Shortcut for calling GetTrueDofs() with GetTrueVector() as argument.
Definition gridfunc.hpp:147
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
void MakeTRef(FiniteElementSpace *f, real_t *tv)
Associate a new FiniteElementSpace and new true-dof data with the GridFunction.
Definition gridfunc.cpp:251
void SetFromTrueVector()
Shortcut for calling SetFromTrueDofs() with GetTrueVector() as argument.
Definition gridfunc.hpp:153
const Vector & GetTrueVector() const
Read only access to the (optional) internal true-dof Vector.
Definition gridfunc.hpp:133
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Arbitrary order H1-conforming (continuous) finite elements.
Definition fe_coll.hpp:275
Abstract class for hyperelastic models.
virtual real_t EvalW(const DenseMatrix &Jpt) const =0
Evaluate the strain energy density function, W = W(Jpt).
void SetTransformation(ElementTransformation &Ttr_)
Class for integration point with weight.
Definition intrules.hpp:35
void SetRelTol(real_t rtol)
Definition solvers.hpp:229
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
Definition solvers.cpp:72
void SetMaxIter(int max_it)
Definition solvers.hpp:231
bool GetConverged() const
Returns true if the last call to Mult() converged successfully.
Definition solvers.hpp:282
void SetAbsTol(real_t atol)
Definition solvers.hpp:230
Arbitrary order "L2-conforming" discontinuous finite elements.
Definition fe_coll.hpp:346
MINRES method.
Definition solvers.hpp:653
void SetPreconditioner(Solver &pr) override
This should be called before SetOperator.
Definition solvers.hpp:665
Mesh data type.
Definition mesh.hpp:64
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
Definition mesh.hpp:290
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
Definition mesh.hpp:2433
int Dimension() const
Dimension of the reference space used within the elements.
Definition mesh.hpp:1216
int SpaceDimension() const
Dimension of the physical space containing the mesh.
Definition mesh.hpp:1219
void GetNodes(Vector &node_coord) const
Definition mesh.cpp:9294
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Definition mesh.cpp:11295
void SwapNodes(GridFunction *&nodes, int &own_nodes_)
Swap the internal node GridFunction pointer and ownership flag members with the given ones.
Definition mesh.cpp:9343
Newton's method for solving F(x)=b for a given operator F.
Definition solvers.hpp:692
void Mult(const Vector &b, Vector &x) const override
Solve the nonlinear system with right-hand side b.
Definition solvers.cpp:1912
Operator & GetGradient(const Vector &x) const override
Compute the gradient Operator of the NonlinearForm corresponding to the state x.
virtual real_t GetEnergy(const Vector &x) const
Compute the energy corresponding to the state x.
void Mult(const Vector &x, Vector &y) const override
Evaluate the action of the NonlinearForm.
static MFEM_EXPORT std::string Types
Definition ode.hpp:187
static MFEM_EXPORT std::unique_ptr< ODESolver > Select(const int ode_solver_type)
Definition ode.cpp:34
Abstract operator.
Definition operator.hpp:25
int height
Dimension of the output / number of rows in the matrix.
Definition operator.hpp:27
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
Definition optparser.hpp:82
bool Good() const
Return true if the command line options were parsed successfully.
Base class for solvers.
Definition operator.hpp:780
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
Definition operator.hpp:783
Data type sparse matrix.
Definition sparsemat.hpp:51
void Add(const int i, const int j, const real_t val)
Base abstract class for first order time dependent operators.
Definition operator.hpp:332
virtual void SetTime(const real_t t_)
Set the current time.
Definition operator.hpp:394
Direct sparse solver using UMFPACK.
Definition solvers.hpp:1121
A general vector function coefficient.
Vector data type.
Definition vector.hpp:82
void Neg()
(*this) = -(*this)
Definition vector.cpp:375
int Size() const
Returns the size of the vector.
Definition vector.hpp:226
real_t * GetData() const
Return a pointer to the beginning of the Vector data.
Definition vector.hpp:235
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
void visualize(ostream &os, Mesh *mesh, GridFunction *deformed_nodes, GridFunction *field, const char *field_name=NULL, bool init_vis=false)
Definition ex10.cpp:355
void InitialDeformation(const Vector &x, Vector &y)
Definition ex10.cpp:578
void InitialVelocity(const Vector &x, Vector &v)
Definition ex10.cpp:585
int dim
Definition ex24.cpp:53
real_t mu
Definition ex25.cpp:140
int main()
void add(const Vector &v1, const Vector &v2, Vector &v)
Definition vector.cpp:391
float real_t
Definition config.hpp:43
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30
void Add(const DenseMatrix &A, const DenseMatrix &B, real_t alpha, DenseMatrix &C)
C = A + alpha*B.
const char vishost[]
std::array< int, NCMesh::MaxFaceNodes > nodes