libMesh
systems_of_equations_ex6.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // <h1> Systems Example 6 - 3D Linear Elastic Cantilever </h1>
21 // \author David Knezevic
22 // \date 2012
23 //
24 // This is a 3D version of systems_of_equations_ex4. The weak form PDE for
25 // equilibrium elasticity is:
26 //
27 // \int_\Omega Sigma_ij v_i,j = \int_\Omega f_i v_i + \int_\Gamma g_i v_i ds,
28 //
29 // for all admissible test functions v, where:
30 // * Sigma is the stress tensor, which for linear elasticity is
31 // given by Sigma_ij = C_ijkl u_k,l.
32 // * f is a body load.
33 // * g is a surface traction on the surface \Gamma.
34 
35 
36 // C++ include files that we need
37 #include <iostream>
38 #include <algorithm>
39 #include <math.h>
40 
41 // libMesh includes
42 #include "libmesh/libmesh_config.h"
43 #include "libmesh/libmesh.h"
44 #include "libmesh/mesh.h"
45 #include "libmesh/mesh_generation.h"
46 #include "libmesh/exodusII_io.h"
47 #include "libmesh/gnuplot_io.h"
48 #include "libmesh/linear_implicit_system.h"
49 #include "libmesh/equation_systems.h"
50 #include "libmesh/fe.h"
51 #include "libmesh/quadrature_gauss.h"
52 #include "libmesh/dof_map.h"
53 #include "libmesh/sparse_matrix.h"
54 #include "libmesh/numeric_vector.h"
55 #include "libmesh/dense_matrix.h"
56 #include "libmesh/dense_submatrix.h"
57 #include "libmesh/dense_vector.h"
58 #include "libmesh/dense_subvector.h"
59 #include "libmesh/perf_log.h"
60 #include "libmesh/elem.h"
61 #include "libmesh/boundary_info.h"
62 #include "libmesh/zero_function.h"
63 #include "libmesh/dirichlet_boundaries.h"
64 #include "libmesh/string_to_enum.h"
65 #include "libmesh/getpot.h"
66 #include "libmesh/solver_configuration.h"
67 #include "libmesh/petsc_linear_solver.h"
68 #include "libmesh/petsc_macro.h"
69 #include "libmesh/enum_solver_package.h"
70 
71 #define x_scaling 1.3
72 
73 // boundary IDs
74 #define BOUNDARY_ID_MIN_Z 0
75 #define BOUNDARY_ID_MIN_Y 1
76 #define BOUNDARY_ID_MAX_X 2
77 #define BOUNDARY_ID_MAX_Y 3
78 #define BOUNDARY_ID_MIN_X 4
79 #define BOUNDARY_ID_MAX_Z 5
80 #define NODE_BOUNDARY_ID 10
81 #define EDGE_BOUNDARY_ID 20
82 
83 // Bring in everything from the libMesh namespace
84 using namespace libMesh;
85 
86 #ifdef LIBMESH_HAVE_PETSC
87 // This class allows us to set the solver and preconditioner
88 // to be appropriate for linear elasticity.
90 {
91 public:
92 
94  _petsc_linear_solver(petsc_linear_solver)
95  {
96  }
97 
98  virtual void configure_solver()
99  {
100  PetscErrorCode ierr = 0;
101  ierr = KSPSetType (_petsc_linear_solver.ksp(), const_cast<KSPType>(KSPCG));
102  CHKERRABORT(_petsc_linear_solver.comm().get(), ierr);
103 
104  ierr = PCSetType (_petsc_linear_solver.pc(), const_cast<PCType>(PCBJACOBI));
105  CHKERRABORT(_petsc_linear_solver.comm().get(), ierr);
106  }
107 
108  // The linear solver object that we are configuring
110 
111 };
112 #endif
113 
115 {
116 private:
118 
119 public:
120 
122  es(es_in)
123  {}
124 
128  Real kronecker_delta(unsigned int i,
129  unsigned int j)
130  {
131  return i == j ? 1. : 0.;
132  }
133 
137  Real elasticity_tensor(unsigned int i,
138  unsigned int j,
139  unsigned int k,
140  unsigned int l)
141  {
142  // Hard code material parameters for the sake of simplicity
143  const Real poisson_ratio = 0.3;
144  const Real young_modulus = 1.;
145 
146  // Define the Lame constants
147  const Real lambda_1 = (young_modulus*poisson_ratio)/((1.+poisson_ratio)*(1.-2.*poisson_ratio));
148  const Real lambda_2 = young_modulus/(2.*(1.+poisson_ratio));
149 
150  return lambda_1 * kronecker_delta(i, j) * kronecker_delta(k, l) +
151  lambda_2 * (kronecker_delta(i, k) * kronecker_delta(j, l) + kronecker_delta(i, l) * kronecker_delta(j, k));
152  }
153 
157  void assemble()
158  {
159  const MeshBase & mesh = es.get_mesh();
160 
161  const unsigned int dim = mesh.mesh_dimension();
162 
163  LinearImplicitSystem & system = es.get_system<LinearImplicitSystem>("Elasticity");
164 
165  const unsigned int u_var = system.variable_number ("u");
166 
167  const DofMap & dof_map = system.get_dof_map();
168  FEType fe_type = dof_map.variable_type(u_var);
169  std::unique_ptr<FEBase> fe (FEBase::build(dim, fe_type));
170  QGauss qrule (dim, fe_type.default_quadrature_order());
171  fe->attach_quadrature_rule (&qrule);
172 
173  std::unique_ptr<FEBase> fe_face (FEBase::build(dim, fe_type));
174  QGauss qface(dim-1, fe_type.default_quadrature_order());
175  fe_face->attach_quadrature_rule (&qface);
176 
177  const std::vector<Real> & JxW = fe->get_JxW();
178  const std::vector<std::vector<Real>> & phi = fe->get_phi();
179  const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
180 
182  DenseSubMatrix<Number> Ke_var[3][3] =
183  {
187  };
188 
190 
191  DenseSubVector<Number> Fe_var[3] =
195 
196  std::vector<dof_id_type> dof_indices;
197  std::vector<std::vector<dof_id_type>> dof_indices_var(3);
198 
199  for (const auto & elem : mesh.active_local_element_ptr_range())
200  {
201  dof_map.dof_indices (elem, dof_indices);
202  for (unsigned int var=0; var<3; var++)
203  dof_map.dof_indices (elem, dof_indices_var[var], var);
204 
205  const unsigned int n_dofs = dof_indices.size();
206  const unsigned int n_var_dofs = dof_indices_var[0].size();
207 
208  fe->reinit (elem);
209 
210  Ke.resize (n_dofs, n_dofs);
211  for (unsigned int var_i=0; var_i<3; var_i++)
212  for (unsigned int var_j=0; var_j<3; var_j++)
213  Ke_var[var_i][var_j].reposition (var_i*n_var_dofs, var_j*n_var_dofs, n_var_dofs, n_var_dofs);
214 
215  Fe.resize (n_dofs);
216  for (unsigned int var=0; var<3; var++)
217  Fe_var[var].reposition (var*n_var_dofs, n_var_dofs);
218 
219  for (unsigned int qp=0; qp<qrule.n_points(); qp++)
220  {
221  // assemble \int_Omega C_ijkl u_k,l v_i,j \dx
222  for (unsigned int dof_i=0; dof_i<n_var_dofs; dof_i++)
223  for (unsigned int dof_j=0; dof_j<n_var_dofs; dof_j++)
224  for (unsigned int i=0; i<3; i++)
225  for (unsigned int j=0; j<3; j++)
226  for (unsigned int k=0; k<3; k++)
227  for (unsigned int l=0; l<3; l++)
228  Ke_var[i][k](dof_i,dof_j) +=
229  JxW[qp] * elasticity_tensor(i,j,k,l) * dphi[dof_j][qp](l) * dphi[dof_i][qp](j);
230 
231  // assemble \int_Omega f_i v_i \dx
232  DenseVector<Number> f_vec(3);
233  f_vec(0) = 0.;
234  f_vec(1) = 0.;
235  f_vec(2) = -1.;
236  for (unsigned int dof_i=0; dof_i<n_var_dofs; dof_i++)
237  for (unsigned int i=0; i<3; i++)
238  Fe_var[i](dof_i) += JxW[qp] * (f_vec(i) * phi[dof_i][qp]);
239  }
240 
241  // assemble \int_\Gamma g_i v_i \ds
242  DenseVector<Number> g_vec(3);
243  g_vec(0) = 0.;
244  g_vec(1) = 0.;
245  g_vec(2) = -1.;
246  {
247  for (auto side : elem->side_index_range())
248  if (elem->neighbor_ptr(side) == nullptr)
249  {
250  const std::vector<std::vector<Real>> & phi_face = fe_face->get_phi();
251  const std::vector<Real> & JxW_face = fe_face->get_JxW();
252 
253  fe_face->reinit(elem, side);
254 
255  // Apply a traction
256  for (unsigned int qp=0; qp<qface.n_points(); qp++)
257  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_X))
258  for (unsigned int dof_i=0; dof_i<n_var_dofs; dof_i++)
259  for (unsigned int i=0; i<3; i++)
260  Fe_var[i](dof_i) += JxW_face[qp] * (g_vec(i) * phi_face[dof_i][qp]);
261  }
262  }
263 
264  dof_map.constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
265 
266  system.matrix->add_matrix (Ke, dof_indices);
267  system.rhs->add_vector (Fe, dof_indices);
268  }
269  }
270 
271  // Post-process the solution to compute stresses
273  {
274  const MeshBase & mesh = es.get_mesh();
275  const unsigned int dim = mesh.mesh_dimension();
276 
277  LinearImplicitSystem & system = es.get_system<LinearImplicitSystem>("Elasticity");
278 
279  unsigned int displacement_vars[3];
280  displacement_vars[0] = system.variable_number ("u");
281  displacement_vars[1] = system.variable_number ("v");
282  displacement_vars[2] = system.variable_number ("w");
283  const unsigned int u_var = system.variable_number ("u");
284 
285  const DofMap & dof_map = system.get_dof_map();
286  FEType fe_type = dof_map.variable_type(u_var);
287  std::unique_ptr<FEBase> fe (FEBase::build(dim, fe_type));
288  QGauss qrule (dim, fe_type.default_quadrature_order());
289  fe->attach_quadrature_rule (&qrule);
290 
291  const std::vector<Real> & JxW = fe->get_JxW();
292  const std::vector<std::vector<Real>> & phi = fe->get_phi();
293  const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
294 
295  // Also, get a reference to the ExplicitSystem
296  ExplicitSystem & stress_system = es.get_system<ExplicitSystem>("StressSystem");
297  const DofMap & stress_dof_map = stress_system.get_dof_map();
298  unsigned int sigma_vars[6];
299  sigma_vars[0] = stress_system.variable_number ("sigma_00");
300  sigma_vars[1] = stress_system.variable_number ("sigma_01");
301  sigma_vars[2] = stress_system.variable_number ("sigma_02");
302  sigma_vars[3] = stress_system.variable_number ("sigma_11");
303  sigma_vars[4] = stress_system.variable_number ("sigma_12");
304  sigma_vars[5] = stress_system.variable_number ("sigma_22");
305  unsigned int vonMises_var = stress_system.variable_number ("vonMises");
306 
307  // Storage for the stress dof indices on each element
308  std::vector<std::vector<dof_id_type>> dof_indices_var(system.n_vars());
309  std::vector<dof_id_type> stress_dof_indices_var;
310  std::vector<dof_id_type> vonmises_dof_indices_var;
311 
312  for (const auto & elem : mesh.active_local_element_ptr_range())
313  {
314  for (unsigned int var=0; var<3; var++)
315  dof_map.dof_indices (elem, dof_indices_var[var], displacement_vars[var]);
316 
317  const unsigned int n_var_dofs = dof_indices_var[0].size();
318 
319  fe->reinit (elem);
320 
321  std::vector<DenseMatrix<Number>> stress_tensor_qp(qrule.n_points());
322  for (unsigned int qp=0; qp<qrule.n_points(); qp++)
323  {
324  stress_tensor_qp[qp].resize(3,3);
325 
326  // Row is variable u1, u2, or u3, column is x, y, or z
327  DenseMatrix<Number> grad_u(3,3);
328  for (unsigned int var_i=0; var_i<3; var_i++)
329  for (unsigned int var_j=0; var_j<3; var_j++)
330  for (unsigned int j=0; j<n_var_dofs; j++)
331  grad_u(var_i,var_j) += dphi[j][qp](var_j) * system.current_solution(dof_indices_var[var_i][j]);
332 
333  for (unsigned int var_i=0; var_i<3; var_i++)
334  for (unsigned int var_j=0; var_j<3; var_j++)
335  for (unsigned int k=0; k<3; k++)
336  for (unsigned int l=0; l<3; l++)
337  stress_tensor_qp[qp](var_i,var_j) += elasticity_tensor(var_i,var_j,k,l) * grad_u(k,l);
338  }
339 
340  stress_dof_map.dof_indices (elem, vonmises_dof_indices_var, vonMises_var);
341  std::vector<DenseMatrix<Number>> elem_sigma_vec(vonmises_dof_indices_var.size());
342  for (std::size_t index=0; index<elem_sigma_vec.size(); index++)
343  elem_sigma_vec[index].resize(3,3);
344 
345  // Below we project each component of the stress tensor onto a L2_LAGRANGE discretization.
346  // Note that this gives a discontinuous stress plot on element boundaries, which is
347  // appropriate. We then also get the von Mises stress from the projected stress tensor.
348  unsigned int stress_var_index = 0;
349  for (unsigned int var_i=0; var_i<3; var_i++)
350  for (unsigned int var_j=var_i; var_j<3; var_j++)
351  {
352  stress_dof_map.dof_indices (elem, stress_dof_indices_var, sigma_vars[stress_var_index]);
353 
354  const unsigned int n_proj_dofs = stress_dof_indices_var.size();
355 
356  DenseMatrix<Real> Me(n_proj_dofs, n_proj_dofs);
357  for (unsigned int qp=0; qp<qrule.n_points(); qp++)
358  {
359  for(unsigned int i=0; i<n_proj_dofs; i++)
360  for(unsigned int j=0; j<n_proj_dofs; j++)
361  {
362  Me(i,j) += JxW[qp]*(phi[i][qp]*phi[j][qp]);
363  }
364  }
365 
366  DenseVector<Number> Fe(n_proj_dofs);
367  for (unsigned int qp=0; qp<qrule.n_points(); qp++)
368  for(unsigned int i=0; i<n_proj_dofs; i++)
369  {
370  Fe(i) += JxW[qp] * stress_tensor_qp[qp](var_i,var_j) * phi[i][qp];
371  }
372 
373  DenseVector<Number> projected_data;
374  Me.cholesky_solve(Fe, projected_data);
375 
376  for(unsigned int index=0; index<n_proj_dofs; index++)
377  {
378  dof_id_type dof_index = stress_dof_indices_var[index];
379  if ((stress_system.solution->first_local_index() <= dof_index) &&
380  (dof_index < stress_system.solution->last_local_index()))
381  stress_system.solution->set(dof_index, projected_data(index));
382 
383  elem_sigma_vec[index](var_i,var_j) = projected_data(index);
384  }
385 
386  stress_var_index++;
387  }
388 
389  for (std::size_t index=0; index<elem_sigma_vec.size(); index++)
390  {
391  elem_sigma_vec[index](1,0) = elem_sigma_vec[index](0,1);
392  elem_sigma_vec[index](2,0) = elem_sigma_vec[index](0,2);
393  elem_sigma_vec[index](2,1) = elem_sigma_vec[index](1,2);
394 
395  // Get the von Mises stress from the projected stress tensor
396  Number vonMises_value = std::sqrt(0.5*(pow(elem_sigma_vec[index](0,0) - elem_sigma_vec[index](1,1), 2.) +
397  pow(elem_sigma_vec[index](1,1) - elem_sigma_vec[index](2,2), 2.) +
398  pow(elem_sigma_vec[index](2,2) - elem_sigma_vec[index](0,0), 2.) +
399  6.*(pow(elem_sigma_vec[index](0,1), 2.) +
400  pow(elem_sigma_vec[index](1,2), 2.) +
401  pow(elem_sigma_vec[index](2,0), 2.))));
402 
403  dof_id_type dof_index = vonmises_dof_indices_var[index];
404 
405  if ((stress_system.solution->first_local_index() <= dof_index) &&
406  (dof_index < stress_system.solution->last_local_index()))
407  stress_system.solution->set(dof_index, vonMises_value);
408  }
409  }
410 
411  // Should call close and update when we set vector entries directly
412  stress_system.solution->close();
413  stress_system.update();
414  }
415 };
416 
417 
418 // Begin the main program.
419 int main (int argc, char ** argv)
420 {
421  // Initialize libMesh and any dependent libraries
422  LibMeshInit init (argc, argv);
423 
424  // This example requires a linear solver package.
425  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
426  "--enable-petsc, --enable-trilinos, or --enable-eigen");
427 
428  // Initialize the cantilever mesh
429  const unsigned int dim = 3;
430 
431  // Make sure libMesh was compiled for 3D
432  libmesh_example_requires(dim == LIBMESH_DIM, "3D support");
433 
434  // We use Dirichlet boundary conditions here
435 #ifndef LIBMESH_ENABLE_DIRICHLET
436  libmesh_example_requires(false, "--enable-dirichlet");
437 #endif
438 
439  // Create a 3D mesh distributed across the default MPI communicator.
440  Mesh mesh(init.comm(), dim);
442  32,
443  8,
444  4,
445  0., 1.*x_scaling,
446  0., 0.3,
447  0., 0.1,
448  HEX8);
449 
450  // Print information about the mesh to the screen.
451  mesh.print_info();
452 
453  // Let's add some node and edge boundary conditions
454  // Each processor should know about each boundary condition it can
455  // see, so we loop over all elements, not just local elements.
456  for (const auto & elem : mesh.element_ptr_range())
457  {
458  unsigned int
459  side_max_x = 0, side_min_y = 0,
460  side_max_y = 0, side_max_z = 0;
461 
462  bool
463  found_side_max_x = false, found_side_max_y = false,
464  found_side_min_y = false, found_side_max_z = false;
465 
466  for (auto side : elem->side_index_range())
467  {
468  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_X))
469  {
470  side_max_x = side;
471  found_side_max_x = true;
472  }
473 
474  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MIN_Y))
475  {
476  side_min_y = side;
477  found_side_min_y = true;
478  }
479 
480  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Y))
481  {
482  side_max_y = side;
483  found_side_max_y = true;
484  }
485 
486  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Z))
487  {
488  side_max_z = side;
489  found_side_max_z = true;
490  }
491  }
492 
493  // If elem has sides on boundaries
494  // BOUNDARY_ID_MAX_X, BOUNDARY_ID_MAX_Y, BOUNDARY_ID_MAX_Z
495  // then let's set a node boundary condition
496  if (found_side_max_x && found_side_max_y && found_side_max_z)
497  for (auto n : elem->node_index_range())
498  if (elem->is_node_on_side(n, side_max_x) &&
499  elem->is_node_on_side(n, side_max_y) &&
500  elem->is_node_on_side(n, side_max_z))
501  mesh.get_boundary_info().add_node(elem->node_ptr(n), NODE_BOUNDARY_ID);
502 
503 
504  // If elem has sides on boundaries
505  // BOUNDARY_ID_MAX_X and BOUNDARY_ID_MIN_Y
506  // then let's set an edge boundary condition
507  if (found_side_max_x && found_side_min_y)
508  for (auto e : elem->edge_index_range())
509  if (elem->is_edge_on_side(e, side_max_x) &&
510  elem->is_edge_on_side(e, side_min_y))
511  mesh.get_boundary_info().add_edge(elem, e, EDGE_BOUNDARY_ID);
512  }
513 
514  // Create an equation systems object.
515  EquationSystems equation_systems (mesh);
516 
517  // Declare the system and its variables.
518  // Create a system named "Elasticity"
519  LinearImplicitSystem & system =
520  equation_systems.add_system<LinearImplicitSystem> ("Elasticity");
521 
522 #ifdef LIBMESH_HAVE_PETSC
523  // Attach a SolverConfiguration object to system.linear_solver
524  PetscLinearSolver<Number> * petsc_linear_solver =
525  cast_ptr<PetscLinearSolver<Number>*>(system.get_linear_solver());
526  libmesh_assert(petsc_linear_solver);
527  PetscSolverConfiguration petsc_solver_config(*petsc_linear_solver);
528  petsc_linear_solver->set_solver_configuration(petsc_solver_config);
529 #endif
530 
531  LinearElasticity le(equation_systems);
532  system.attach_assemble_object(le);
533 
534 #ifdef LIBMESH_ENABLE_DIRICHLET
535  // Add three displacement variables, u and v, to the system
536  unsigned int u_var = system.add_variable("u", FIRST, LAGRANGE);
537  unsigned int v_var = system.add_variable("v", FIRST, LAGRANGE);
538  unsigned int w_var = system.add_variable("w", FIRST, LAGRANGE);
539 
540  std::set<boundary_id_type> boundary_ids;
541  boundary_ids.insert(BOUNDARY_ID_MIN_X);
542  boundary_ids.insert(NODE_BOUNDARY_ID);
543  boundary_ids.insert(EDGE_BOUNDARY_ID);
544 
545  // Create a vector storing the variable numbers which the BC applies to
546  std::vector<unsigned int> variables;
547  variables.push_back(u_var);
548  variables.push_back(v_var);
549  variables.push_back(w_var);
550 
551  // Create a ZeroFunction to initialize dirichlet_bc
552  ZeroFunction<> zf;
553 
554  // Most DirichletBoundary users will want to supply a "locally
555  // indexed" functor
556  DirichletBoundary dirichlet_bc(boundary_ids, variables, zf,
558 
559  // We must add the Dirichlet boundary condition _before_
560  // we call equation_systems.init()
561  system.get_dof_map().add_dirichlet_boundary(dirichlet_bc);
562 #endif // LIBMESH_ENABLE_DIRICHLET
563 
564  // Also, initialize an ExplicitSystem to store stresses
565  ExplicitSystem & stress_system =
566  equation_systems.add_system<ExplicitSystem> ("StressSystem");
567 
568  stress_system.add_variable("sigma_00", FIRST, L2_LAGRANGE);
569  stress_system.add_variable("sigma_01", FIRST, L2_LAGRANGE);
570  stress_system.add_variable("sigma_02", FIRST, L2_LAGRANGE);
571  stress_system.add_variable("sigma_11", FIRST, L2_LAGRANGE);
572  stress_system.add_variable("sigma_12", FIRST, L2_LAGRANGE);
573  stress_system.add_variable("sigma_22", FIRST, L2_LAGRANGE);
574  stress_system.add_variable("vonMises", FIRST, L2_LAGRANGE);
575 
576  // Initialize the data structures for the equation system.
577  equation_systems.init();
578 
579  // Print information about the system to the screen.
580  equation_systems.print_info();
581 
582  // Solve the system
583  system.solve();
584 
585  // Post-process the solution to compute the stresses
586  le.compute_stresses();
587 
588  // Plot the solution
589 #ifdef LIBMESH_HAVE_EXODUS_API
590 
591  // Use single precision in this case (reduces the size of the exodus file)
592  ExodusII_IO exo_io(mesh, /*single_precision=*/true);
593  exo_io.write_discontinuous_exodusII("displacement_and_stress.exo", equation_systems);
594 
595 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
596 
597  // All done.
598  return 0;
599 }
elasticity_tensor
Real elasticity_tensor(unsigned int i, unsigned int j, unsigned int k, unsigned int l)
Definition: assembly.C:40
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::System::n_vars
unsigned int n_vars() const
Definition: system.h:2155
PetscSolverConfiguration::_petsc_linear_solver
PetscLinearSolver< Number > & _petsc_linear_solver
Definition: systems_of_equations_ex6.C:109
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::EquationSystems::add_system
virtual System & add_system(const std::string &system_type, const std::string &name)
Add the system of type system_type named name to the systems array.
Definition: equation_systems.C:345
libMesh::EquationSystems::get_mesh
const MeshBase & get_mesh() const
Definition: equation_systems.h:637
main
int main(int argc, char **argv)
Definition: systems_of_equations_ex6.C:419
libMesh::MeshBase::get_boundary_info
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:132
libMesh::ExplicitSystem::rhs
NumericVector< Number > * rhs
The system matrix.
Definition: explicit_system.h:114
libMesh::QGauss
This class implements specific orders of Gauss quadrature.
Definition: quadrature_gauss.h:39
libMesh::DofMap::dof_indices
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
Definition: dof_map.C:1967
libMesh::DofMap::add_dirichlet_boundary
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
Definition: dof_map_constraints.C:4390
libMesh::HEX8
Definition: enum_elem_type.h:47
libMesh::BoundaryInfo::add_node
void add_node(const Node *node, const boundary_id_type id)
Add Node node with boundary id id to the boundary information data structures.
Definition: boundary_info.C:636
LinearElasticity
Definition: systems_of_equations_ex6.C:114
libMesh::MeshBase::active_local_element_ptr_range
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
libMesh::DenseSubMatrix
Defines a dense submatrix for use in Finite Element-type computations.
Definition: dense_submatrix.h:45
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::EquationSystems::get_system
const T_sys & get_system(const std::string &name) const
Definition: equation_systems.h:757
kronecker_delta
Real kronecker_delta(unsigned int i, unsigned int j)
Definition: assembly.C:34
libMesh::MeshTools::Generation::build_cube
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
Definition: mesh_generation.C:298
std::sqrt
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::DenseMatrix< Number >
libMesh::LinearImplicitSystem::solve
virtual void solve() override
Assembles & solves the linear system A*x=b.
Definition: linear_implicit_system.C:108
libMesh::default_solver_package
SolverPackage default_solver_package()
Definition: libmesh.C:993
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshBase::mesh_dimension
unsigned int mesh_dimension() const
Definition: mesh_base.C:135
LinearElasticity::elasticity_tensor
Real elasticity_tensor(unsigned int i, unsigned int j, unsigned int k, unsigned int l)
Evaluate the fourth order tensor (C_ijkl) that relates stress to strain.
Definition: systems_of_equations_ex6.C:137
libMesh::ExodusII_IO
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:51
libMesh::ierr
ierr
Definition: petsc_dm_wrapper.C:72
PetscSolverConfiguration
Definition: systems_of_equations_ex6.C:89
dim
unsigned int dim
Definition: adaptivity_ex3.C:113
libMesh::ExodusII_IO::write_discontinuous_exodusII
void write_discontinuous_exodusII(const std::string &name, const EquationSystems &es, const std::set< std::string > *system_names=nullptr)
Writes a exodusII file with discontinuous data.
Definition: exodusII_io.C:93
libMesh::DenseMatrix::resize
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
Definition: dense_matrix.h:822
libMesh::System::current_solution
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:194
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
libMesh::MeshBase::element_ptr_range
virtual SimpleRange< element_iterator > element_ptr_range()=0
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::LOCAL_VARIABLE_ORDER
Definition: dirichlet_boundaries.h:62
libMesh::NumericVector::add_vector
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i].
Definition: numeric_vector.C:363
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::LinearImplicitSystem::get_linear_solver
virtual LinearSolver< Number > * get_linear_solver() const override
Definition: linear_implicit_system.C:353
LinearElasticity::assemble
void assemble()
Assemble the system matrix and right-hand side vector.
Definition: systems_of_equations_ex6.C:157
libMesh::INVALID_SOLVER_PACKAGE
Definition: enum_solver_package.h:43
libMesh::FEGenericBase::build
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
libMesh::System::add_variable
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1069
libMesh::PetscLinearSolver< Number >
LinearElasticity::LinearElasticity
LinearElasticity(EquationSystems &es_in)
Definition: systems_of_equations_ex6.C:121
libMesh::EquationSystems::init
virtual void init()
Initialize all the systems.
Definition: equation_systems.C:96
libMesh::ImplicitSystem::matrix
SparseMatrix< Number > * matrix
The system matrix.
Definition: implicit_system.h:393
std::pow
double pow(double a, int b)
Definition: libmesh_augment_std_namespace.h:58
libMesh::DofMap::variable_type
const FEType & variable_type(const unsigned int c) const
Definition: dof_map.h:1924
libMesh::LibMeshInit
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:83
LinearElasticity::compute_stresses
void compute_stresses()
Definition: systems_of_equations_ex6.C:272
libMesh::ZeroFunction
ConstFunction that simply returns 0.
Definition: zero_function.h:36
libMesh::System::Assembly
Abstract base class to be used for system assembly.
Definition: system.h:143
libMesh::EquationSystems::print_info
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
Definition: equation_systems.C:1314
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::DofMap::constrain_element_matrix_and_vector
void constrain_element_matrix_and_vector(DenseMatrix< Number > &matrix, DenseVector< Number > &rhs, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true) const
Constrains the element matrix and vector.
Definition: dof_map.h:2034
libMesh::DenseSubVector< Number >
libMesh::DenseMatrix::cholesky_solve
void cholesky_solve(const DenseVector< T2 > &b, DenseVector< T2 > &x)
For symmetric positive definite (SPD) matrices.
Definition: dense_matrix_impl.h:947
libMesh::ExplicitSystem
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
Definition: explicit_system.h:48
libMesh::DenseVector::resize
void resize(const unsigned int n)
Resize the vector.
Definition: dense_vector.h:355
libMesh::System::solution
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1539
libMesh::SparseMatrix::add_matrix
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
Add the full matrix dm to the SparseMatrix.
libMesh::FEType
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:178
PetscSolverConfiguration::PetscSolverConfiguration
PetscSolverConfiguration(PetscLinearSolver< Number > &petsc_linear_solver)
Definition: systems_of_equations_ex6.C:93
libMesh::DofMap
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:176
libMesh::MeshBase::print_info
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
Definition: mesh_base.C:585
libMesh::BoundaryInfo::add_edge
void add_edge(const dof_id_type elem, const unsigned short int edge, const boundary_id_type id)
Add edge edge of element number elem with boundary id id to the boundary information data structure.
Definition: boundary_info.C:707
libMesh::DirichletBoundary
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
Definition: dirichlet_boundaries.h:88
libMesh::System::variable_number
unsigned short int variable_number(const std::string &var) const
Definition: system.C:1232
libMesh::SolverConfiguration
This class stores solver configuration data, e.g.
Definition: solver_configuration.h:39
LinearElasticity::es
EquationSystems & es
Definition: systems_of_equations_ex6.C:117
libMesh::L2_LAGRANGE
Definition: enum_fe_family.h:41
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::System::attach_assemble_object
void attach_assemble_object(Assembly &assemble)
Register a user object to use in assembling the system matrix and RHS.
Definition: system.C:1774
libMesh::LAGRANGE
Definition: enum_fe_family.h:36
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::FEType::default_quadrature_order
Order default_quadrature_order() const
Definition: fe_type.h:353
libMesh::LinearImplicitSystem
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
Definition: linear_implicit_system.h:55
libMesh::BoundaryInfo::has_boundary_id
bool has_boundary_id(const Node *const node, const boundary_id_type id) const
Definition: boundary_info.C:972
libMesh::System::update
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:408
libMesh::FIRST
Definition: enum_order.h:42
LinearElasticity::kronecker_delta
Real kronecker_delta(unsigned int i, unsigned int j)
Kronecker delta function.
Definition: systems_of_equations_ex6.C:128
PetscSolverConfiguration::configure_solver
virtual void configure_solver()
Apply solver options to a particular solver.
Definition: systems_of_equations_ex6.C:98
libMesh::DenseVector< Number >