MFEM v4.8.0
Finite element discretization library
Loading...
Searching...
No Matches
ex10p.cpp
Go to the documentation of this file.
1// MFEM Example 10 - Parallel Version
2//
3// Compile with: make ex10p
4//
5// Sample runs:
6// mpirun -np 4 ex10p -m ../data/beam-quad.mesh -s 23 -rs 2 -dt 3
7// mpirun -np 4 ex10p -m ../data/beam-tri.mesh -s 23 -rs 2 -dt 3
8// mpirun -np 4 ex10p -m ../data/beam-hex.mesh -s 22 -rs 1 -dt 3
9// mpirun -np 4 ex10p -m ../data/beam-tet.mesh -s 22 -rs 1 -dt 3
10// mpirun -np 4 ex10p -m ../data/beam-wedge.mesh -s 22 -rs 1 -dt 3
11// mpirun -np 4 ex10p -m ../data/beam-quad.mesh -s 4 -rs 2 -dt 0.03 -vs 20
12// mpirun -np 4 ex10p -m ../data/beam-hex.mesh -s 4 -rs 1 -dt 0.05 -vs 20
13// mpirun -np 4 ex10p -m ../data/beam-quad-amr.mesh -s 23 -rs 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 ParFiniteElementSpace &fespace;
62 Array<int> ess_tdof_list;
63
64 ParBilinearForm M, S;
66 real_t viscosity;
67 HyperelasticModel *model;
68
69 HypreParMatrix *Mmat; // Mass matrix from ParallelAssemble()
70 CGSolver M_solver; // Krylov solver for inverting the mass matrix M
71 HypreSmoother M_prec; // Preconditioner for the mass matrix M
72
73 /** Nonlinear operator defining the reduced backward Euler equation for the
74 velocity. Used in the implementation of method ImplicitSolve. */
75 ReducedSystemOperator *reduced_oper;
76
77 /// Newton solver for the reduced backward Euler equation
78 NewtonSolver newton_solver;
79
80 /// Solver for the Jacobian solve in the Newton method
81 Solver *J_solver;
82 /// Preconditioner for the Jacobian solve in the Newton method
83 Solver *J_prec;
84
85 mutable Vector z; // auxiliary vector
86
87public:
88 HyperelasticOperator(ParFiniteElementSpace &f, Array<int> &ess_bdr,
89 real_t visc, real_t mu, real_t K);
90
91 /// Compute the right-hand side of the ODE system.
92 void Mult(const Vector &vx, Vector &dvx_dt) const override;
93 /** Solve the Backward-Euler equation: k = f(x + dt*k, t), for the unknown k.
94 This is the only requirement for high-order SDIRK implicit integration.*/
95 void ImplicitSolve(const real_t dt, const Vector &x, Vector &k) override;
96
97 real_t ElasticEnergy(const ParGridFunction &x) const;
98 real_t KineticEnergy(const ParGridFunction &v) const;
99 void GetElasticEnergyDensity(const ParGridFunction &x,
100 ParGridFunction &w) const;
101
102 ~HyperelasticOperator() override;
103};
104
105/** Nonlinear operator of the form:
106 k --> (M + dt*S)*k + H(x + dt*v + dt^2*k) + S*v,
107 where M and S are given BilinearForms, H is a given NonlinearForm, v and x
108 are given vectors, and dt is a scalar. */
109class ReducedSystemOperator : public Operator
110{
111private:
112 ParBilinearForm *M, *S;
114 mutable HypreParMatrix *Jacobian;
115 real_t dt;
116 const Vector *v, *x;
117 mutable Vector w, z;
118 const Array<int> &ess_tdof_list;
119
120public:
121 ReducedSystemOperator(ParBilinearForm *M_, ParBilinearForm *S_,
122 ParNonlinearForm *H_, const Array<int> &ess_tdof_list);
123
124 /// Set current dt, v, x values - needed to compute action and Jacobian.
125 void SetParameters(real_t dt_, const Vector *v_, const Vector *x_);
126
127 /// Compute y = H(x + dt (v + dt k)) + M k + S (v + dt k).
128 void Mult(const Vector &k, Vector &y) const override;
129
130 /// Compute J = M + dt S + dt^2 grad_H(x + dt (v + dt k)).
131 Operator &GetGradient(const Vector &k) const override;
132
133 ~ReducedSystemOperator() override;
134};
135
136
137/** Function representing the elastic energy density for the given hyperelastic
138 model+deformation. Used in HyperelasticOperator::GetElasticEnergyDensity. */
139class ElasticEnergyCoefficient : public Coefficient
140{
141private:
142 HyperelasticModel &model;
143 const ParGridFunction &x;
144 DenseMatrix J;
145
146public:
147 ElasticEnergyCoefficient(HyperelasticModel &m, const ParGridFunction &x_)
148 : model(m), x(x_) { }
149 real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override;
150 ~ElasticEnergyCoefficient() override { }
151};
152
153void InitialDeformation(const Vector &x, Vector &y);
154
155void InitialVelocity(const Vector &x, Vector &v);
156
157void visualize(ostream &os, ParMesh *mesh,
158 ParGridFunction *deformed_nodes,
159 ParGridFunction *field, const char *field_name = NULL,
160 bool init_vis = false);
161
162
163int main(int argc, char *argv[])
164{
165 // 1. Initialize MPI and HYPRE.
166 Mpi::Init(argc, argv);
167 int myid = Mpi::WorldRank();
168 Hypre::Init();
169
170 // 2. Parse command-line options.
171 const char *mesh_file = "../data/beam-quad.mesh";
172 int ser_ref_levels = 2;
173 int par_ref_levels = 0;
174 int order = 2;
175 int ode_solver_type = 23;
176 real_t t_final = 300.0;
177 real_t dt = 3.0;
178 real_t visc = 1e-2;
179 real_t mu = 0.25;
180 real_t K = 5.0;
181 bool adaptive_lin_rtol = true;
182 bool visualization = true;
183 int vis_steps = 1;
184
185 OptionsParser args(argc, argv);
186 args.AddOption(&mesh_file, "-m", "--mesh",
187 "Mesh file to use.");
188 args.AddOption(&ser_ref_levels, "-rs", "--refine-serial",
189 "Number of times to refine the mesh uniformly in serial.");
190 args.AddOption(&par_ref_levels, "-rp", "--refine-parallel",
191 "Number of times to refine the mesh uniformly in parallel.");
192 args.AddOption(&order, "-o", "--order",
193 "Order (degree) of the finite elements.");
194 args.AddOption(&ode_solver_type, "-s", "--ode-solver",
195 ODESolver::Types.c_str());
196 args.AddOption(&t_final, "-tf", "--t-final",
197 "Final time; start time is 0.");
198 args.AddOption(&dt, "-dt", "--time-step",
199 "Time step.");
200 args.AddOption(&visc, "-v", "--viscosity",
201 "Viscosity coefficient.");
202 args.AddOption(&mu, "-mu", "--shear-modulus",
203 "Shear modulus in the Neo-Hookean hyperelastic model.");
204 args.AddOption(&K, "-K", "--bulk-modulus",
205 "Bulk modulus in the Neo-Hookean hyperelastic model.");
206 args.AddOption(&adaptive_lin_rtol, "-alrtol", "--adaptive-lin-rtol",
207 "-no-alrtol", "--no-adaptive-lin-rtol",
208 "Enable or disable adaptive linear solver rtol.");
209 args.AddOption(&visualization, "-vis", "--visualization", "-no-vis",
210 "--no-visualization",
211 "Enable or disable GLVis visualization.");
212 args.AddOption(&vis_steps, "-vs", "--visualization-steps",
213 "Visualize every n-th timestep.");
214 args.Parse();
215 if (!args.Good())
216 {
217 if (myid == 0)
218 {
219 args.PrintUsage(cout);
220 }
221 return 1;
222 }
223 if (myid == 0)
224 {
225 args.PrintOptions(cout);
226 }
227
228 // 3. Read the serial mesh from the given mesh file on all processors. We can
229 // handle triangular, quadrilateral, tetrahedral and hexahedral meshes
230 // with the same code.
231 Mesh *mesh = new Mesh(mesh_file, 1, 1);
232 int dim = mesh->Dimension();
233
234 // 4. Define the ODE solver used for time integration. Several implicit
235 // singly diagonal implicit Runge-Kutta (SDIRK) methods, as well as
236 // explicit Runge-Kutta methods are available.
237 unique_ptr<ODESolver> ode_solver = ODESolver::Select(ode_solver_type);
238
239 // 5. Refine the mesh in serial to increase the resolution. In this example
240 // we do 'ser_ref_levels' of uniform refinement, where 'ser_ref_levels' is
241 // a command-line parameter.
242 for (int lev = 0; lev < ser_ref_levels; lev++)
243 {
244 mesh->UniformRefinement();
245 }
246
247 // 6. Define a parallel mesh by a partitioning of the serial mesh. Refine
248 // this mesh further in parallel to increase the resolution. Once the
249 // parallel mesh is defined, the serial mesh can be deleted.
250 ParMesh *pmesh = new ParMesh(MPI_COMM_WORLD, *mesh);
251 delete mesh;
252 for (int lev = 0; lev < par_ref_levels; lev++)
253 {
254 pmesh->UniformRefinement();
255 }
256
257 // 7. Define the parallel vector finite element spaces representing the mesh
258 // deformation x_gf, the velocity v_gf, and the initial configuration,
259 // x_ref. Define also the elastic energy density, w_gf, which is in a
260 // discontinuous higher-order space. Since x and v are integrated in time
261 // as a system, we group them together in block vector vx, on the unique
262 // parallel degrees of freedom, with offsets given by array true_offset.
263 H1_FECollection fe_coll(order, dim);
264 ParFiniteElementSpace fespace(pmesh, &fe_coll, dim);
265
266 HYPRE_BigInt glob_size = fespace.GlobalTrueVSize();
267 if (myid == 0)
268 {
269 cout << "Number of velocity/deformation unknowns: " << glob_size << endl;
270 }
271 int true_size = fespace.TrueVSize();
272 Array<int> true_offset(3);
273 true_offset[0] = 0;
274 true_offset[1] = true_size;
275 true_offset[2] = 2*true_size;
276
277 BlockVector vx(true_offset);
278 ParGridFunction v_gf, x_gf;
279 v_gf.MakeTRef(&fespace, vx, true_offset[0]);
280 x_gf.MakeTRef(&fespace, vx, true_offset[1]);
281
282 ParGridFunction x_ref(&fespace);
283 pmesh->GetNodes(x_ref);
284
285 L2_FECollection w_fec(order + 1, dim);
286 ParFiniteElementSpace w_fespace(pmesh, &w_fec);
287 ParGridFunction w_gf(&w_fespace);
288
289 // 8. Set the initial conditions for v_gf, x_gf and vx, and define the
290 // boundary conditions on a beam-like mesh (see description above).
292 v_gf.ProjectCoefficient(velo);
293 v_gf.SetTrueVector();
295 x_gf.ProjectCoefficient(deform);
296 x_gf.SetTrueVector();
297
299
300 Array<int> ess_bdr(fespace.GetMesh()->bdr_attributes.Max());
301 ess_bdr = 0;
302 ess_bdr[0] = 1; // boundary attribute 1 (index 0) is fixed
303
304 // 9. Initialize the hyperelastic operator, the GLVis visualization and print
305 // the initial energies.
306 HyperelasticOperator oper(fespace, ess_bdr, visc, mu, K);
307
308 socketstream vis_v, vis_w;
309 if (visualization)
310 {
311 char vishost[] = "localhost";
312 int visport = 19916;
313 vis_v.open(vishost, visport);
314 vis_v.precision(8);
315 visualize(vis_v, pmesh, &x_gf, &v_gf, "Velocity", true);
316 // Make sure all ranks have sent their 'v' solution before initiating
317 // another set of GLVis connections (one from each rank):
318 MPI_Barrier(pmesh->GetComm());
319 vis_w.open(vishost, visport);
320 if (vis_w)
321 {
322 oper.GetElasticEnergyDensity(x_gf, w_gf);
323 vis_w.precision(8);
324 visualize(vis_w, pmesh, &x_gf, &w_gf, "Elastic energy density", true);
325 }
326 if (myid == 0)
327 {
328 cout << "GLVis visualization paused."
329 << " Press space (in the GLVis window) to resume it.\n";
330 }
331 }
332
333 real_t ee0 = oper.ElasticEnergy(x_gf);
334 real_t ke0 = oper.KineticEnergy(v_gf);
335 if (myid == 0)
336 {
337 cout << "initial elastic energy (EE) = " << ee0 << endl;
338 cout << "initial kinetic energy (KE) = " << ke0 << endl;
339 cout << "initial total energy (TE) = " << (ee0 + ke0) << endl;
340 }
341
342 real_t t = 0.0;
343 oper.SetTime(t);
344 ode_solver->Init(oper);
345
346 // 10. Perform time-integration
347 // (looping over the time iterations, ti, with a time-step dt).
348 bool last_step = false;
349 for (int ti = 1; !last_step; ti++)
350 {
351 real_t dt_real = min(dt, t_final - t);
352
353 ode_solver->Step(vx, t, dt_real);
354
355 last_step = (t >= t_final - 1e-8*dt);
356
357 if (last_step || (ti % vis_steps) == 0)
358 {
360
361 real_t ee = oper.ElasticEnergy(x_gf);
362 real_t ke = oper.KineticEnergy(v_gf);
363
364 if (myid == 0)
365 {
366 cout << "step " << ti << ", t = " << t << ", EE = " << ee
367 << ", KE = " << ke << ", ΔTE = " << (ee+ke)-(ee0+ke0) << endl;
368 }
369
370 if (visualization)
371 {
372 visualize(vis_v, pmesh, &x_gf, &v_gf);
373 if (vis_w)
374 {
375 oper.GetElasticEnergyDensity(x_gf, w_gf);
376 visualize(vis_w, pmesh, &x_gf, &w_gf);
377 }
378 }
379 }
380 }
381
382 // 11. Save the displaced mesh, the velocity and elastic energy.
383 {
385 GridFunction *nodes = &x_gf;
386 int owns_nodes = 0;
387 pmesh->SwapNodes(nodes, owns_nodes);
388
389 ostringstream mesh_name, velo_name, ee_name;
390 mesh_name << "deformed." << setfill('0') << setw(6) << myid;
391 velo_name << "velocity." << setfill('0') << setw(6) << myid;
392 ee_name << "elastic_energy." << setfill('0') << setw(6) << myid;
393
394 ofstream mesh_ofs(mesh_name.str().c_str());
395 mesh_ofs.precision(8);
396 pmesh->Print(mesh_ofs);
397 pmesh->SwapNodes(nodes, owns_nodes);
398 ofstream velo_ofs(velo_name.str().c_str());
399 velo_ofs.precision(8);
400 v_gf.Save(velo_ofs);
401 ofstream ee_ofs(ee_name.str().c_str());
402 ee_ofs.precision(8);
403 oper.GetElasticEnergyDensity(x_gf, w_gf);
404 w_gf.Save(ee_ofs);
405 }
406
407 // 12. Free the used memory.
408 delete pmesh;
409
410 return 0;
411}
412
413void visualize(ostream &os, ParMesh *mesh,
414 ParGridFunction *deformed_nodes,
415 ParGridFunction *field, const char *field_name, bool init_vis)
416{
417 if (!os)
418 {
419 return;
420 }
421
422 GridFunction *nodes = deformed_nodes;
423 int owns_nodes = 0;
424
425 mesh->SwapNodes(nodes, owns_nodes);
426
427 os << "parallel " << mesh->GetNRanks()
428 << " " << mesh->GetMyRank() << "\n";
429 os << "solution\n" << *mesh << *field;
430
431 mesh->SwapNodes(nodes, owns_nodes);
432
433 if (init_vis)
434 {
435 os << "window_size 800 800\n";
436 os << "window_title '" << field_name << "'\n";
437 if (mesh->SpaceDimension() == 2)
438 {
439 os << "view 0 0\n"; // view from top
440 os << "keys jl\n"; // turn off perspective and light
441 }
442 os << "keys cm\n"; // show colorbar and mesh
443 // update value-range; keep mesh-extents fixed
444 os << "autoscale value\n";
445 os << "pause\n";
446 }
447 os << flush;
448}
449
450
451ReducedSystemOperator::ReducedSystemOperator(
453 const Array<int> &ess_tdof_list_)
454 : Operator(M_->ParFESpace()->TrueVSize()), M(M_), S(S_), H(H_),
455 Jacobian(NULL), dt(0.0), v(NULL), x(NULL), w(height), z(height),
456 ess_tdof_list(ess_tdof_list_)
457{ }
458
459void ReducedSystemOperator::SetParameters(real_t dt_, const Vector *v_,
460 const Vector *x_)
461{
462 dt = dt_; v = v_; x = x_;
463}
464
465void ReducedSystemOperator::Mult(const Vector &k, Vector &y) const
466{
467 // compute: y = H(x + dt*(v + dt*k)) + M*k + S*(v + dt*k)
468 add(*v, dt, k, w);
469 add(*x, dt, w, z);
470 H->Mult(z, y);
471 M->TrueAddMult(k, y);
472 S->TrueAddMult(w, y);
473 y.SetSubVector(ess_tdof_list, 0.0);
474}
475
476Operator &ReducedSystemOperator::GetGradient(const Vector &k) const
477{
478 delete Jacobian;
479 SparseMatrix *localJ = Add(1.0, M->SpMat(), dt, S->SpMat());
480 add(*v, dt, k, w);
481 add(*x, dt, w, z);
482 localJ->Add(dt*dt, H->GetLocalGradient(z));
483 Jacobian = M->ParallelAssemble(localJ);
484 delete localJ;
485 HypreParMatrix *Je = Jacobian->EliminateRowsCols(ess_tdof_list);
486 delete Je;
487 return *Jacobian;
488}
489
490ReducedSystemOperator::~ReducedSystemOperator()
491{
492 delete Jacobian;
493}
494
495
496HyperelasticOperator::HyperelasticOperator(ParFiniteElementSpace &f,
497 Array<int> &ess_bdr, real_t visc,
498 real_t mu, real_t K)
499 : TimeDependentOperator(2*f.TrueVSize(), (real_t) 0.0), fespace(f),
500 M(&fespace), S(&fespace), H(&fespace),
501 viscosity(visc), M_solver(f.GetComm()), newton_solver(f.GetComm()),
502 z(height/2)
503{
504#if defined(MFEM_USE_DOUBLE)
505 const real_t rel_tol = 1e-8;
506 const real_t newton_abs_tol = 0.0;
507#elif defined(MFEM_USE_SINGLE)
508 const real_t rel_tol = 1e-3;
509 const real_t newton_abs_tol = 1e-4;
510#else
511#error "Only single and double precision are supported!"
512 const real_t rel_tol = real_t(1);
513 const real_t newton_abs_tol = real_t(0);
514#endif
515 const int skip_zero_entries = 0;
516
517 const real_t ref_density = 1.0; // density in the reference configuration
518 ConstantCoefficient rho0(ref_density);
519 M.AddDomainIntegrator(new VectorMassIntegrator(rho0));
520 M.Assemble(skip_zero_entries);
521 M.Finalize(skip_zero_entries);
522 Mmat = M.ParallelAssemble();
523 fespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list);
524 HypreParMatrix *Me = Mmat->EliminateRowsCols(ess_tdof_list);
525 delete Me;
526
527 M_solver.iterative_mode = false;
528 M_solver.SetRelTol(rel_tol);
529 M_solver.SetAbsTol(0.0);
530 M_solver.SetMaxIter(30);
531 M_solver.SetPrintLevel(0);
532 M_prec.SetType(HypreSmoother::Jacobi);
533 M_solver.SetPreconditioner(M_prec);
534 M_solver.SetOperator(*Mmat);
535
536 model = new NeoHookeanModel(mu, K);
537 H.AddDomainIntegrator(new HyperelasticNLFIntegrator(model));
538 H.SetEssentialTrueDofs(ess_tdof_list);
539
540 ConstantCoefficient visc_coeff(viscosity);
541 S.AddDomainIntegrator(new VectorDiffusionIntegrator(visc_coeff));
542 S.Assemble(skip_zero_entries);
543 S.Finalize(skip_zero_entries);
544
545 reduced_oper = new ReducedSystemOperator(&M, &S, &H, ess_tdof_list);
546
547 HypreSmoother *J_hypreSmoother = new HypreSmoother;
548 J_hypreSmoother->SetType(HypreSmoother::l1Jacobi);
549 J_hypreSmoother->SetPositiveDiagonal(true);
550 J_prec = J_hypreSmoother;
551
552 MINRESSolver *J_minres = new MINRESSolver(f.GetComm());
553 J_minres->SetRelTol(rel_tol);
554 J_minres->SetAbsTol(0.0);
555 J_minres->SetMaxIter(300);
556 J_minres->SetPrintLevel(-1);
557 J_minres->SetPreconditioner(*J_prec);
558 J_solver = J_minres;
559
560 newton_solver.iterative_mode = false;
561 newton_solver.SetSolver(*J_solver);
562 newton_solver.SetOperator(*reduced_oper);
563 newton_solver.SetPrintLevel(1); // print Newton iterations
564 newton_solver.SetRelTol(rel_tol);
565 newton_solver.SetAbsTol(newton_abs_tol);
566 newton_solver.SetAdaptiveLinRtol(2, 0.5, 0.9);
567 newton_solver.SetMaxIter(10);
568}
569
570void HyperelasticOperator::Mult(const Vector &vx, Vector &dvx_dt) const
571{
572 // Create views to the sub-vectors v, x of vx, and dv_dt, dx_dt of dvx_dt
573 int sc = height/2;
574 Vector v(vx.GetData() + 0, sc);
575 Vector x(vx.GetData() + sc, sc);
576 Vector dv_dt(dvx_dt.GetData() + 0, sc);
577 Vector dx_dt(dvx_dt.GetData() + sc, sc);
578
579 H.Mult(x, z);
580 if (viscosity != 0.0)
581 {
582 S.TrueAddMult(v, z);
583 z.SetSubVector(ess_tdof_list, 0.0);
584 }
585 z.Neg(); // z = -z
586 M_solver.Mult(z, dv_dt);
587
588 dx_dt = v;
589}
590
591void HyperelasticOperator::ImplicitSolve(const real_t dt,
592 const Vector &vx, Vector &dvx_dt)
593{
594 int sc = height/2;
595 Vector v(vx.GetData() + 0, sc);
596 Vector x(vx.GetData() + sc, sc);
597 Vector dv_dt(dvx_dt.GetData() + 0, sc);
598 Vector dx_dt(dvx_dt.GetData() + sc, sc);
599
600 // By eliminating kx from the coupled system:
601 // kv = -M^{-1}*[H(x + dt*kx) + S*(v + dt*kv)]
602 // kx = v + dt*kv
603 // we reduce it to a nonlinear equation for kv, represented by the
604 // reduced_oper. This equation is solved with the newton_solver
605 // object (using J_solver and J_prec internally).
606 reduced_oper->SetParameters(dt, &v, &x);
607 Vector zero; // empty vector is interpreted as zero r.h.s. by NewtonSolver
608 newton_solver.Mult(zero, dv_dt);
609 MFEM_VERIFY(newton_solver.GetConverged(), "Newton solver did not converge.");
610 add(v, dt, dv_dt, dx_dt);
611}
612
613real_t HyperelasticOperator::ElasticEnergy(const ParGridFunction &x) const
614{
615 return H.GetEnergy(x);
616}
617
618real_t HyperelasticOperator::KineticEnergy(const ParGridFunction &v) const
619{
620 real_t energy = 0.5*M.ParInnerProduct(v, v);
621 return energy;
622}
623
624void HyperelasticOperator::GetElasticEnergyDensity(
625 const ParGridFunction &x, ParGridFunction &w) const
626{
627 ElasticEnergyCoefficient w_coeff(*model, x);
628 w.ProjectCoefficient(w_coeff);
629}
630
631HyperelasticOperator::~HyperelasticOperator()
632{
633 delete J_solver;
634 delete J_prec;
635 delete reduced_oper;
636 delete model;
637 delete Mmat;
638}
639
640
641real_t ElasticEnergyCoefficient::Eval(ElementTransformation &T,
642 const IntegrationPoint &ip)
643{
644 model.SetTransformation(T);
645 x.GetVectorGradient(T, J);
646 // return model.EvalW(J); // in reference configuration
647 return model.EvalW(J)/J.Det(); // in deformed configuration
648}
649
650
652{
653 // set the initial configuration to be the same as the reference, stress
654 // free, configuration
655 y = x;
656}
657
658void InitialVelocity(const Vector &x, Vector &v)
659{
660 const int dim = x.Size();
661 const real_t s = 0.1/64.;
662
663 v = 0.0;
664 v(dim-1) = s*x(0)*x(0)*(8.0-x(0));
665 v(0) = -s*x(0)*x(0);
666}
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
Definition array.cpp:68
const SparseMatrix & SpMat() const
Returns a const reference to the sparse matrix: .
A class to handle Vectors in a block fashion.
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 dense matrix using column-major storage.
Definition densemat.hpp:24
real_t Det() const
Definition densemat.cpp:516
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
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
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_)
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:408
void EliminateRowsCols(const Array< int > &rows_cols, const HypreParVector &X, HypreParVector &B)
Definition hypre.cpp:2397
Parallel smoothers in hypre.
Definition hypre.hpp:1046
void SetPositiveDiagonal(bool pos=true)
After computing l1-norms, replace them with their absolute values.
Definition hypre.hpp:1162
void SetType(HypreSmoother::Type type, int relax_times=1)
Set the relaxation type and number of sweeps.
Definition hypre.cpp:3608
@ l1Jacobi
l1-scaled Jacobi
Definition hypre.hpp:1106
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
Definition hypre.cpp:33
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
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
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
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
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.
Class for parallel bilinear form.
Abstract parallel finite element space.
Definition pfespace.hpp:29
HYPRE_BigInt GlobalTrueVSize() const
Definition pfespace.hpp:346
int TrueVSize() const
Obsolete, kept for backward compatibility.
Definition pfespace.hpp:524
Class for parallel grid function.
Definition pgridfunc.hpp:50
void Save(std::ostream &out) const override
void ProjectCoefficient(Coefficient &coeff) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Class for parallel meshes.
Definition pmesh.hpp:34
MPI_Comm GetComm() const
Definition pmesh.hpp:402
int GetMyRank() const
Definition pmesh.hpp:404
int GetNRanks() const
Definition pmesh.hpp:403
void Print(std::ostream &out=mfem::out, const std::string &comments="") const override
Definition pmesh.cpp:4800
Parallel non-linear operator on the true dofs.
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
A general vector function coefficient.
Vector data type.
Definition vector.hpp:82
void Neg()
(*this) = -(*this)
Definition vector.cpp:375
void SetSubVector(const Array< int > &dofs, const real_t value)
Set the entries listed in dofs to the given value.
Definition vector.cpp:679
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, ParMesh *mesh, ParGridFunction *deformed_nodes, ParGridFunction *field, const char *field_name=NULL, bool init_vis=false)
Definition ex10p.cpp:413
void InitialDeformation(const Vector &x, Vector &y)
Definition ex10p.cpp:651
void InitialVelocity(const Vector &x, Vector &v)
Definition ex10p.cpp:658
int dim
Definition ex24.cpp:53
real_t mu
Definition ex25.cpp:140
int main()
HYPRE_Int HYPRE_BigInt
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