MFEM  v3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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 3 -rs 2 -dt 3
7 // mpirun -np 4 ex10p -m ../data/beam-tri.mesh -s 3 -rs 2 -dt 3
8 // mpirun -np 4 ex10p -m ../data/beam-hex.mesh -s 2 -rs 1 -dt 3
9 // mpirun -np 4 ex10p -m ../data/beam-tet.mesh -s 2 -rs 1 -dt 3
10 // mpirun -np 4 ex10p -m ../data/beam-quad.mesh -s 14 -rs 2 -dt 0.03 -vs 20
11 // mpirun -np 4 ex10p -m ../data/beam-hex.mesh -s 14 -rs 1 -dt 0.05 -vs 20
12 //
13 // Description: This examples solves a time dependent nonlinear elasticity
14 // problem of the form dv/dt = H(x) + S v, dx/dt = v, where H is a
15 // hyperelastic model and S is a viscosity operator of Laplacian
16 // type. The geometry of the domain is assumed to be as follows:
17 //
18 // +---------------------+
19 // boundary --->| |
20 // attribute 1 | |
21 // (fixed) +---------------------+
22 //
23 // The example demonstrates the use of nonlinear operators (the
24 // class HyperelasticOperator defining H(x)), as well as their
25 // implicit time integration using a Newton method for solving an
26 // associated reduced backward-Euler type nonlinear equation
27 // (class BackwardEulerOperator). Each Newton step requires the
28 // inversion of a Jacobian matrix, which is done through a
29 // (preconditioned) inner solver. Note that implementing the
30 // method HyperelasticOperator::ImplicitSolve is the only
31 // requirement for high-order implicit (SDIRK) time integration.
32 //
33 // We recommend viewing examples 2 and 9 before viewing this
34 // example.
35 
36 
37 #include "mfem.hpp"
38 #include <memory>
39 #include <iostream>
40 #include <fstream>
41 
42 using namespace std;
43 using namespace mfem;
44 
45 class BackwardEulerOperator;
46 
57 class HyperelasticOperator : public TimeDependentOperator
58 {
59 protected:
60  ParFiniteElementSpace &fespace;
61 
62  ParBilinearForm M, S;
64  double viscosity;
65  HyperelasticModel *model;
66 
67  HypreParMatrix *Mmat; // Mass matrix from ParallelAssemble()
68  CGSolver M_solver; // Krylov solver for inverting the mass matrix M
69  HypreSmoother M_prec; // Preconditioner for the mass matrix M
70 
73  BackwardEulerOperator *backward_euler_oper;
75  NewtonSolver newton_solver;
77  Solver *J_solver;
79  Solver *J_prec;
80 
81  mutable Vector z; // auxiliary vector
82 
83 public:
84  HyperelasticOperator(ParFiniteElementSpace &f, Array<int> &ess_bdr,
85  double visc, double mu, double K);
86 
87  virtual void Mult(const Vector &vx, Vector &dvx_dt) const;
90  virtual void ImplicitSolve(const double dt, const Vector &x, Vector &k);
91 
92  double ElasticEnergy(ParGridFunction &x) const;
93  double KineticEnergy(ParGridFunction &v) const;
94  void GetElasticEnergyDensity(ParGridFunction &x, ParGridFunction &w) const;
95 
96  virtual ~HyperelasticOperator();
97 };
98 
99 // Nonlinear operator of the form:
100 // k --> (M + dt*S)*k + H(x + dt*v + dt^2*k) + S*v,
101 // where M and S are given BilinearForms, H is a given NonlinearForm, v and x
102 // are given vectors, and dt is a scalar.
103 class BackwardEulerOperator : public Operator
104 {
105 private:
106  ParBilinearForm *M, *S;
107  ParNonlinearForm *H;
108  mutable HypreParMatrix *Jacobian;
109  const Vector *v, *x;
110  double dt;
111  mutable Vector w, z;
112 
113 public:
114  BackwardEulerOperator(ParBilinearForm *M_, ParBilinearForm *S_,
115  ParNonlinearForm *H_);
116  void SetParameters(double dt_, const Vector *v_, const Vector *x_);
117  virtual void Mult(const Vector &k, Vector &y) const;
118  virtual Operator &GetGradient(const Vector &k) const;
119  virtual ~BackwardEulerOperator();
120 };
121 
124 class ElasticEnergyCoefficient : public Coefficient
125 {
126 private:
127  HyperelasticModel &model;
128  ParGridFunction &x;
129  DenseMatrix J;
130 
131 public:
132  ElasticEnergyCoefficient(HyperelasticModel &m, ParGridFunction &x_)
133  : model(m), x(x_) { }
134  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip);
135  virtual ~ElasticEnergyCoefficient() { }
136 };
137 
138 void InitialDeformation(const Vector &x, Vector &y);
139 
140 void InitialVelocity(const Vector &x, Vector &v);
141 
142 void visualize(ostream &out, ParMesh *mesh, ParGridFunction *deformed_nodes,
143  ParGridFunction *field, const char *field_name = NULL,
144  bool init_vis = false);
145 
146 
147 int main(int argc, char *argv[])
148 {
149  // 1. Initialize MPI.
150  int num_procs, myid;
151  MPI_Init(&argc, &argv);
152  MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
153  MPI_Comm_rank(MPI_COMM_WORLD, &myid);
154 
155  // 2. Parse command-line options.
156  const char *mesh_file = "../data/beam-quad.mesh";
157  int ser_ref_levels = 2;
158  int par_ref_levels = 0;
159  int order = 2;
160  int ode_solver_type = 3;
161  double t_final = 300.0;
162  double dt = 3.0;
163  double visc = 1e-2;
164  double mu = 0.25;
165  double K = 5.0;
166  bool visualization = true;
167  int vis_steps = 1;
168 
169  OptionsParser args(argc, argv);
170  args.AddOption(&mesh_file, "-m", "--mesh",
171  "Mesh file to use.");
172  args.AddOption(&ser_ref_levels, "-rs", "--refine-serial",
173  "Number of times to refine the mesh uniformly in serial.");
174  args.AddOption(&par_ref_levels, "-rp", "--refine-parallel",
175  "Number of times to refine the mesh uniformly in parallel.");
176  args.AddOption(&order, "-o", "--order",
177  "Order (degree) of the finite elements.");
178  args.AddOption(&ode_solver_type, "-s", "--ode-solver",
179  "ODE solver: 1 - Backward Euler, 2 - SDIRK2, 3 - SDIRK3,\n\t"
180  "\t 11 - Forward Euler, 12 - RK2, 13 - RK3 SSP, 14 - RK4.");
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  if (myid == 0)
200  {
201  args.PrintUsage(cout);
202  }
203  MPI_Finalize();
204  return 1;
205  }
206  if (myid == 0)
207  {
208  args.PrintOptions(cout);
209  }
210 
211  // 3. Read the serial mesh from the given mesh file on all processors. We can
212  // handle triangular, quadrilateral, tetrahedral and hexahedral meshes
213  // with the same code.
214  Mesh *mesh = new Mesh(mesh_file, 1, 1);
215  int dim = mesh->Dimension();
216 
217  // 4. Define the ODE solver used for time integration. Several implicit
218  // singly diagonal implicit Runge-Kutta (SDIRK) methods, as well as
219  // explicit Runge-Kutta methods are available.
220  ODESolver *ode_solver;
221  switch (ode_solver_type)
222  {
223  // Implicit L-stable methods
224  case 1: ode_solver = new BackwardEulerSolver; break;
225  case 2: ode_solver = new SDIRK23Solver(2); break;
226  case 3: ode_solver = new SDIRK33Solver; break;
227  // Explicit methods
228  case 11: ode_solver = new ForwardEulerSolver; break;
229  case 12: ode_solver = new RK2Solver(0.5); break; // midpoint method
230  case 13: ode_solver = new RK3SSPSolver; break;
231  case 14: ode_solver = new RK4Solver; break;
232  // Implicit A-stable methods (not L-stable)
233  case 22: ode_solver = new ImplicitMidpointSolver; break;
234  case 23: ode_solver = new SDIRK23Solver; break;
235  case 24: ode_solver = new SDIRK34Solver; break;
236  default:
237  if (myid == 0)
238  {
239  cout << "Unknown ODE solver type: " << ode_solver_type << '\n';
240  }
241  MPI_Finalize();
242  return 3;
243  }
244 
245  // 5. Refine the mesh in serial to increase the resolution. In this example
246  // we do 'ser_ref_levels' of uniform refinement, where 'ser_ref_levels' is
247  // a command-line parameter.
248  for (int lev = 0; lev < ser_ref_levels; lev++)
249  {
250  mesh->UniformRefinement();
251  }
252 
253  // 6. Define a parallel mesh by a partitioning of the serial mesh. Refine
254  // this mesh further in parallel to increase the resolution. Once the
255  // parallel mesh is defined, the serial mesh can be deleted.
256  ParMesh *pmesh = new ParMesh(MPI_COMM_WORLD, *mesh);
257  delete mesh;
258  for (int lev = 0; lev < par_ref_levels; lev++)
259  {
260  pmesh->UniformRefinement();
261  }
262 
263  // 7. Define the parallel vector finite element spaces representing the mesh
264  // deformation x_gf, the velocity v_gf, and the initial configuration,
265  // x_ref. Define also the elastic energy density, w_gf, which is in a
266  // discontinuous higher-order space. Since x and v are integrated in time
267  // as a system, we group them together in block vector vx, on the unique
268  // parallel degrees of freedom, with offsets given by array true_offset.
269  H1_FECollection fe_coll(order, dim);
270  ParFiniteElementSpace fespace(pmesh, &fe_coll, dim);
271 
272  HYPRE_Int glob_size = fespace.GlobalTrueVSize();
273  if (myid == 0)
274  {
275  cout << "Number of velocity/deformation unknowns: " << glob_size << endl;
276  }
277  int true_size = fespace.TrueVSize();
278  Array<int> true_offset(3);
279  true_offset[0] = 0;
280  true_offset[1] = true_size;
281  true_offset[2] = 2*true_size;
282 
283  BlockVector vx(true_offset);
284  ParGridFunction v_gf(&fespace), x_gf(&fespace);
285 
286  ParGridFunction x_ref(&fespace);
287  pmesh->GetNodes(x_ref);
288 
289  L2_FECollection w_fec(order + 1, dim);
290  ParFiniteElementSpace w_fespace(pmesh, &w_fec);
291  ParGridFunction w_gf(&w_fespace);
292 
293  // 8. Set the initial conditions for v_gf, x_gf and vx, and define the
294  // boundary conditions on a beam-like mesh (see description above).
296  v_gf.ProjectCoefficient(velo);
298  x_gf.ProjectCoefficient(deform);
299 
300  v_gf.GetTrueDofs(vx.GetBlock(0));
301  x_gf.GetTrueDofs(vx.GetBlock(1));
302 
303  Array<int> ess_bdr(fespace.GetMesh()->bdr_attributes.Max());
304  ess_bdr = 0;
305  ess_bdr[0] = 1; // boundary attribute 1 (index 0) is fixed
306 
307  // 9. Initialize the hyperelastic operator, the GLVis visualization and print
308  // the initial energies.
309  HyperelasticOperator oper(fespace, ess_bdr, visc, mu, K);
310 
311  socketstream vis_v, vis_w;
312  if (visualization)
313  {
314  char vishost[] = "localhost";
315  int visport = 19916;
316  vis_v.open(vishost, visport);
317  vis_v.precision(8);
318  visualize(vis_v, pmesh, &x_gf, &v_gf, "Velocity", true);
319  // Make sure all ranks have sent their 'v' solution before initiating
320  // another set of GLVis connections (one from each rank):
321  MPI_Barrier(pmesh->GetComm());
322  vis_w.open(vishost, visport);
323  if (vis_w)
324  {
325  oper.GetElasticEnergyDensity(x_gf, w_gf);
326  vis_w.precision(8);
327  visualize(vis_w, pmesh, &x_gf, &w_gf, "Elastic energy density", true);
328  }
329  }
330 
331  double ee0 = oper.ElasticEnergy(x_gf);
332  double ke0 = oper.KineticEnergy(v_gf);
333  if (myid == 0)
334  {
335  cout << "initial elastic energy (EE) = " << ee0 << endl;
336  cout << "initial kinetic energy (KE) = " << ke0 << endl;
337  cout << "initial total energy (TE) = " << (ee0 + ke0) << endl;
338  }
339 
340  // 10. Perform time-integration (looping over the time iterations, ti, with a
341  // time-step dt).
342  ode_solver->Init(oper);
343  double t = 0.0;
344 
345  bool last_step = false;
346  for (int ti = 1; !last_step; ti++)
347  {
348  if (t + dt >= t_final - dt/2)
349  {
350  last_step = true;
351  }
352 
353  ode_solver->Step(vx, t, dt);
354 
355  if (last_step || (ti % vis_steps) == 0)
356  {
357  v_gf.Distribute(vx.GetBlock(0));
358  x_gf.Distribute(vx.GetBlock(1));
359 
360  double ee = oper.ElasticEnergy(x_gf);
361  double ke = oper.KineticEnergy(v_gf);
362 
363  if (myid == 0)
364  cout << "step " << ti << ", t = " << t << ", EE = " << ee
365  << ", KE = " << ke << ", ΔTE = " << (ee+ke)-(ee0+ke0) << endl;
366 
367  if (visualization)
368  {
369  visualize(vis_v, pmesh, &x_gf, &v_gf);
370  if (vis_w)
371  {
372  oper.GetElasticEnergyDensity(x_gf, w_gf);
373  visualize(vis_w, pmesh, &x_gf, &w_gf);
374  }
375  }
376  }
377  }
378 
379  // 11. Save the displaced mesh, the velocity and elastic energy.
380  {
381  GridFunction *nodes = &x_gf;
382  int owns_nodes = 0;
383  pmesh->SwapNodes(nodes, owns_nodes);
384 
385  ostringstream mesh_name, velo_name, ee_name;
386  mesh_name << "deformed." << setfill('0') << setw(6) << myid;
387  velo_name << "velocity." << setfill('0') << setw(6) << myid;
388  ee_name << "elastic_energy." << setfill('0') << setw(6) << myid;
389 
390  ofstream mesh_ofs(mesh_name.str().c_str());
391  mesh_ofs.precision(8);
392  pmesh->Print(mesh_ofs);
393  pmesh->SwapNodes(nodes, owns_nodes);
394  ofstream velo_ofs(velo_name.str().c_str());
395  velo_ofs.precision(8);
396  v_gf.Save(velo_ofs);
397  ofstream ee_ofs(ee_name.str().c_str());
398  ee_ofs.precision(8);
399  oper.GetElasticEnergyDensity(x_gf, w_gf);
400  w_gf.Save(ee_ofs);
401  }
402 
403  // 12. Free the used memory.
404  delete ode_solver;
405  delete pmesh;
406 
407  MPI_Finalize();
408 
409  return 0;
410 }
411 
412 void visualize(ostream &out, ParMesh *mesh, ParGridFunction *deformed_nodes,
413  ParGridFunction *field, const char *field_name, bool init_vis)
414 {
415  if (!out)
416  {
417  return;
418  }
419 
420  GridFunction *nodes = deformed_nodes;
421  int owns_nodes = 0;
422 
423  mesh->SwapNodes(nodes, owns_nodes);
424 
425  out << "parallel " << mesh->GetNRanks() << " " << mesh->GetMyRank() << "\n";
426  out << "solution\n" << *mesh << *field;
427 
428  mesh->SwapNodes(nodes, owns_nodes);
429 
430  if (init_vis)
431  {
432  out << "window_size 800 800\n";
433  out << "window_title '" << field_name << "'\n";
434  if (mesh->SpaceDimension() == 2)
435  {
436  out << "view 0 0\n"; // view from top
437  out << "keys jl\n"; // turn off perspective and light
438  }
439  out << "keys cm\n"; // show colorbar and mesh
440  out << "autoscale value\n"; // update value-range; keep mesh-extents fixed
441  out << "pause\n";
442  }
443  out << flush;
444 }
445 
446 BackwardEulerOperator::BackwardEulerOperator(
448  : Operator(M_->ParFESpace()->TrueVSize()), M(M_), S(S_), H(H_),
449  Jacobian(NULL), v(NULL), x(NULL), dt(0.0), w(height), z(height)
450 { }
451 
452 void BackwardEulerOperator::SetParameters(double dt_, const Vector *v_,
453  const Vector *x_)
454 {
455  dt = dt_; v = v_; x = x_;
456 }
457 
458 void BackwardEulerOperator::Mult(const Vector &k, Vector &y) const
459 {
460  // compute: y = H(x + dt*(v + dt*k)) + M*k + S*(v + dt*k)
461  add(*v, dt, k, w);
462  add(*x, dt, w, z);
463  H->Mult(z, y);
464  M->TrueAddMult(k, y);
465  S->TrueAddMult(w, y);
466 }
467 
468 Operator &BackwardEulerOperator::GetGradient(const Vector &k) const
469 {
470  delete Jacobian;
471  SparseMatrix *localJ = Add(1.0, M->SpMat(), dt, S->SpMat());
472  add(*v, dt, k, w);
473  add(*x, dt, w, z);
474  localJ->Add(dt*dt, H->GetLocalGradient(z));
475  Jacobian = M->ParallelAssemble(localJ);
476  delete localJ;
477  return *Jacobian;
478 }
479 
480 BackwardEulerOperator::~BackwardEulerOperator()
481 {
482  delete Jacobian;
483 }
484 
485 
486 HyperelasticOperator::HyperelasticOperator(ParFiniteElementSpace &f,
487  Array<int> &ess_bdr, double visc,
488  double mu, double K)
489  : TimeDependentOperator(2*f.TrueVSize(), 0.0), fespace(f),
490  M(&fespace), S(&fespace), H(&fespace), M_solver(f.GetComm()),
491  newton_solver(f.GetComm()), z(height/2)
492 {
493  const double rel_tol = 1e-8;
494  const int skip_zero_entries = 0;
495 
496  const double ref_density = 1.0; // density in the reference configuration
497  ConstantCoefficient rho0(ref_density);
498  M.AddDomainIntegrator(new VectorMassIntegrator(rho0));
499  M.Assemble(skip_zero_entries);
500  M.EliminateEssentialBC(ess_bdr);
501  M.Finalize(skip_zero_entries);
502  Mmat = M.ParallelAssemble();
503 
504  M_solver.iterative_mode = false;
505  M_solver.SetRelTol(rel_tol);
506  M_solver.SetAbsTol(0.0);
507  M_solver.SetMaxIter(30);
508  M_solver.SetPrintLevel(0);
509  M_prec.SetType(HypreSmoother::Jacobi);
510  M_solver.SetPreconditioner(M_prec);
511  M_solver.SetOperator(*Mmat);
512 
513  model = new NeoHookeanModel(mu, K);
514  H.AddDomainIntegrator(new HyperelasticNLFIntegrator(model));
515  H.SetEssentialBC(ess_bdr);
516 
517  viscosity = visc;
518  ConstantCoefficient visc_coeff(viscosity);
519  S.AddDomainIntegrator(new VectorDiffusionIntegrator(visc_coeff));
520  S.Assemble(skip_zero_entries);
521  S.EliminateEssentialBC(ess_bdr);
522  S.Finalize(skip_zero_entries);
523 
524  backward_euler_oper = new BackwardEulerOperator(&M, &S, &H);
525 
526  HypreSmoother *J_hypreSmoother = new HypreSmoother;
527  J_hypreSmoother->SetType(HypreSmoother::l1Jacobi);
528  J_prec = J_hypreSmoother;
529 
530  MINRESSolver *J_minres = new MINRESSolver(f.GetComm());
531  J_minres->SetRelTol(rel_tol);
532  J_minres->SetAbsTol(0.0);
533  J_minres->SetMaxIter(300);
534  J_minres->SetPrintLevel(-1);
535  J_minres->SetPreconditioner(*J_prec);
536  J_solver = J_minres;
537 
538  newton_solver.iterative_mode = false;
539  newton_solver.SetSolver(*J_solver);
540  newton_solver.SetOperator(*backward_euler_oper);
541  newton_solver.SetPrintLevel(1); // print Newton iterations
542  newton_solver.SetRelTol(rel_tol);
543  newton_solver.SetAbsTol(0.0);
544  newton_solver.SetMaxIter(10);
545 }
546 
547 void HyperelasticOperator::Mult(const Vector &vx, Vector &dvx_dt) const
548 {
549  // Create views to the sub-vectors v, x of vx, and dv_dt, dx_dt of dvx_dt
550  int sc = height/2;
551  Vector v(vx.GetData() + 0, sc);
552  Vector x(vx.GetData() + sc, sc);
553  Vector dv_dt(dvx_dt.GetData() + 0, sc);
554  Vector dx_dt(dvx_dt.GetData() + sc, sc);
555 
556  H.Mult(x, z);
557  if (viscosity != 0.0)
558  {
559  S.TrueAddMult(v, z);
560  }
561  z.Neg(); // z = -z
562  M_solver.Mult(z, dv_dt);
563 
564  dx_dt = v;
565 }
566 
567 void HyperelasticOperator::ImplicitSolve(const double dt,
568  const Vector &vx, Vector &dvx_dt)
569 {
570  int sc = height/2;
571  Vector v(vx.GetData() + 0, sc);
572  Vector x(vx.GetData() + sc, sc);
573  Vector dv_dt(dvx_dt.GetData() + 0, sc);
574  Vector dx_dt(dvx_dt.GetData() + sc, sc);
575 
576  // By eliminating kx from the coupled system:
577  // kv = -M^{-1}*[H(x + dt*kx) + S*(v + dt*kv)]
578  // kx = v + dt*kv
579  // we reduce it to a nonlinear equation for kv, represented by the
580  // backward_euler_oper. This equation is solved with the newton_solver
581  // object (using J_solver and J_prec internally).
582  backward_euler_oper->SetParameters(dt, &v, &x);
583  Vector zero; // empty vector is interpreted as zero r.h.s. by NewtonSolver
584  newton_solver.Mult(zero, dv_dt);
585  add(v, dt, dv_dt, dx_dt);
586 
587  MFEM_VERIFY(newton_solver.GetConverged(), "Newton Solver did not converge.");
588 }
589 
590 double HyperelasticOperator::ElasticEnergy(ParGridFunction &x) const
591 {
592  return H.GetEnergy(x);
593 }
594 
595 double HyperelasticOperator::KineticEnergy(ParGridFunction &v) const
596 {
597  double loc_energy = 0.5*M.InnerProduct(v, v);
598  double energy;
599  MPI_Allreduce(&loc_energy, &energy, 1, MPI_DOUBLE, MPI_SUM,
600  fespace.GetComm());
601  return energy;
602 }
603 
604 void HyperelasticOperator::GetElasticEnergyDensity(
605  ParGridFunction &x, ParGridFunction &w) const
606 {
607  ElasticEnergyCoefficient w_coeff(*model, x);
608  w.ProjectCoefficient(w_coeff);
609 }
610 
611 HyperelasticOperator::~HyperelasticOperator()
612 {
613  delete model;
614  delete backward_euler_oper;
615  delete J_solver;
616  delete J_prec;
617  delete Mmat;
618 }
619 
620 
622  const IntegrationPoint &ip)
623 {
624  model.SetTransformation(T);
625  x.GetVectorGradient(T, J);
626  // return model.EvalW(J); // in reference configuration
627  return model.EvalW(J)/J.Det(); // in deformed configuration
628 }
629 
630 
631 void InitialDeformation(const Vector &x, Vector &y)
632 {
633  // set the initial configuration to be the same as the reference, stress
634  // free, configuration
635  y = x;
636 }
637 
638 void InitialVelocity(const Vector &x, Vector &v)
639 {
640  const int dim = x.Size();
641  const double s = 0.1/64.;
642 
643  v = 0.0;
644  v(dim-1) = s*x(0)*x(0)*(8.0-x(0));
645  v(0) = -s*x(0)*x(0);
646 }
void visualize(ostream &out, Mesh *mesh, GridFunction *deformed_nodes, GridFunction *field, const char *field_name=NULL, bool init_vis=false)
Definition: ex10.cpp:356
double Eval(ElementTransformation &T, const IntegrationPoint &ip, double t)
Definition: coefficient.hpp:45
void Add(const int i, const int j, const double a)
Definition: sparsemat.cpp:1816
void InitialDeformation(const Vector &x, Vector &y)
Definition: ex10.cpp:567
Conjugate gradient method.
Definition: solvers.hpp:110
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:27
Subclass constant coefficient.
Definition: coefficient.hpp:57
Base abstract class for time dependent operators: (x,t) -&gt; f(x,t)
Definition: operator.hpp:68
void SwapNodes(GridFunction *&nodes, int &own_nodes_)
Definition: mesh.cpp:5152
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
Definition: table.cpp:451
virtual void Step(Vector &x, double &t, double &dt)=0
Data type dense matrix using column-major storage.
Definition: densemat.hpp:22
int Size() const
Returns the size of the vector.
Definition: vector.hpp:86
Parallel non-linear operator on the true dofs.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
Definition: ode.hpp:22
virtual void Save(std::ostream &out) const
Definition: pgridfunc.cpp:312
Abstract parallel finite element space.
Definition: pfespace.hpp:28
void ProjectCoefficient(Coefficient &coeff)
Definition: pgridfunc.cpp:247
bool iterative_mode
If true, use the second argument of Mult as an initial guess.
Definition: operator.hpp:106
MINRES method.
Definition: solvers.hpp:219
virtual void Init(TimeDependentOperator &_f)
Definition: ode.hpp:30
Hyperelastic integrator for any given HyperelasticModel.
int main(int argc, char *argv[])
Backward Euler ODE solver. L-stable.
Definition: ode.hpp:150
double * GetData() const
Definition: vector.hpp:90
void add(const Vector &v1, const Vector &v2, Vector &v)
Definition: vector.cpp:259
int GetNRanks() const
Definition: pmesh.hpp:97
void InitialVelocity(const Vector &x, Vector &v)
Definition: ex10.cpp:574
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
Definition: densemat.cpp:2809
int dim
Definition: ex3.cpp:47
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
Definition: solvers.hpp:232
void SetPrintLevel(int print_lvl)
Definition: solvers.cpp:71
Data type sparse matrix.
Definition: sparsemat.hpp:38
Mesh * GetMesh() const
Returns the mesh.
Definition: fespace.hpp:136
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Definition: mesh.cpp:6402
void SetMaxIter(int max_it)
Definition: solvers.hpp:62
T Max() const
Definition: array.cpp:90
Parallel smoothers in hypre.
Definition: hypre.hpp:433
int Dimension() const
Definition: mesh.hpp:523
void PrintUsage(std::ostream &out) const
Definition: optparser.cpp:434
void GetTrueDofs(Vector &tv) const
Returns the true dofs in a Vector.
Definition: pgridfunc.cpp:95
int SpaceDimension() const
Definition: mesh.hpp:524
The classical explicit forth-order Runge-Kutta method, RK4.
Definition: ode.hpp:85
void SetAbsTol(double atol)
Definition: solvers.hpp:61
Array< int > bdr_attributes
Definition: mesh.hpp:141
int GetMyRank() const
Definition: pmesh.hpp:98
void SetRelTol(double rtol)
Definition: solvers.hpp:60
MPI_Comm GetComm() const
Definition: pmesh.hpp:96
Base class Coefficient that may optionally depend on time.
Definition: coefficient.hpp:31
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)
Definition: optparser.hpp:74
Third-order, strong stability preserving (SSP) Runge-Kutta method.
Definition: ode.hpp:72
void Distribute(const Vector *tv)
Definition: pgridfunc.cpp:85
Implicit midpoint method. A-stable, not L-stable.
Definition: ode.hpp:163
Class for integration point with weight.
Definition: intrules.hpp:25
void PrintOptions(std::ostream &out) const
Definition: optparser.cpp:304
Class for parallel bilinear form.
Abstract class for hyperelastic models.
Definition: nonlininteg.hpp:49
int open(const char hostname[], int port)
Vector data type.
Definition: vector.hpp:33
void GetNodes(Vector &node_coord) const
Definition: mesh.cpp:5114
Arbitrary order H1-conforming (continuous) finite elements.
Definition: fe_coll.hpp:77
Base class for solvers.
Definition: operator.hpp:102
Class for parallel grid function.
Definition: pgridfunc.hpp:31
The classical forward Euler method.
Definition: ode.hpp:39
Abstract operator.
Definition: operator.hpp:21
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:150
void GetVectorGradient(ElementTransformation &tr, DenseMatrix &grad)
Definition: gridfunc.cpp:942
Vector & GetBlock(int i)
Get the i-th vector in the block.
Class for parallel meshes.
Definition: pmesh.hpp:28
void SetType(HypreSmoother::Type type, int relax_times=1)
Set the relaxation type and number of sweeps.
Definition: hypre.cpp:1617
Arbitrary order &quot;L2-conforming&quot; discontinuous finite elements.
Definition: fe_coll.hpp:130
void Neg()
(*this) = -(*this)
Definition: vector.cpp:251
virtual void Print(std::ostream &out=std::cout) const
Definition: pmesh.cpp:2927
bool Good() const
Definition: optparser.hpp:120