libMesh
systems_of_equations_ex6.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 #include "libmesh/tensor_value.h"
71 #include "libmesh/vector_value.h"
72 #include "libmesh/utility.h"
73 
74 #define x_scaling 1.3
75 
76 // boundary IDs
77 #define BOUNDARY_ID_MIN_Z 0
78 #define BOUNDARY_ID_MIN_Y 1
79 #define BOUNDARY_ID_MAX_X 2
80 #define BOUNDARY_ID_MAX_Y 3
81 #define BOUNDARY_ID_MIN_X 4
82 #define BOUNDARY_ID_MAX_Z 5
83 #define NODE_BOUNDARY_ID 10
84 #define EDGE_BOUNDARY_ID 20
85 
86 // Bring in everything from the libMesh namespace
87 using namespace libMesh;
88 
89 #ifdef LIBMESH_HAVE_PETSC
90 // This class allows us to set the solver and preconditioner
91 // to be appropriate for linear elasticity.
93 {
94 public:
95 
97  _petsc_linear_solver(petsc_linear_solver)
98  {
99  }
100 
101  virtual void configure_solver()
102  {
103  LibmeshPetscCall2(_petsc_linear_solver.comm(), KSPSetType(_petsc_linear_solver.ksp(), const_cast<KSPType>(KSPCG)));
104  LibmeshPetscCall2(_petsc_linear_solver.comm(), PCSetType(_petsc_linear_solver.pc(), const_cast<PCType>(PCBJACOBI)));
105  }
106 
107  // The linear solver object that we are configuring
109 
110 };
111 #endif
112 
114 {
115 private:
117 
118 public:
119 
121  es(es_in)
122  {}
123 
127  Real kronecker_delta(unsigned int i,
128  unsigned int j)
129  {
130  return i == j ? 1. : 0.;
131  }
132 
136  Real elasticity_tensor(unsigned int i,
137  unsigned int j,
138  unsigned int k,
139  unsigned int l)
140  {
141  // Hard code material parameters for the sake of simplicity
142  const Real poisson_ratio = 0.3;
143  const Real young_modulus = 1.;
144 
145  // Define the Lame constants
146  const Real lambda_1 = (young_modulus*poisson_ratio)/((1.+poisson_ratio)*(1.-2.*poisson_ratio));
147  const Real lambda_2 = young_modulus/(2.*(1.+poisson_ratio));
148 
149  return lambda_1 * kronecker_delta(i, j) * kronecker_delta(k, l) +
150  lambda_2 * (kronecker_delta(i, k) * kronecker_delta(j, l) + kronecker_delta(i, l) * kronecker_delta(j, k));
151  }
152 
156  void assemble()
157  {
158  const MeshBase & mesh = es.get_mesh();
159 
160  const unsigned int dim = mesh.mesh_dimension();
161 
162  LinearImplicitSystem & system = es.get_system<LinearImplicitSystem>("Elasticity");
163 
164  const unsigned int u_var = system.variable_number ("u");
165 
166  const DofMap & dof_map = system.get_dof_map();
167  FEType fe_type = dof_map.variable_type(u_var);
168  std::unique_ptr<FEBase> fe (FEBase::build(dim, fe_type));
169  QGauss qrule (dim, fe_type.default_quadrature_order());
170  fe->attach_quadrature_rule (&qrule);
171 
172  std::unique_ptr<FEBase> fe_face (FEBase::build(dim, fe_type));
173  QGauss qface(dim-1, fe_type.default_quadrature_order());
174  fe_face->attach_quadrature_rule (&qface);
175 
176  const std::vector<Real> & JxW = fe->get_JxW();
177  const std::vector<std::vector<Real>> & phi = fe->get_phi();
178  const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
179 
181  DenseSubMatrix<Number> Ke_var[3][3] =
182  {
186  };
187 
189 
190  DenseSubVector<Number> Fe_var[3] =
194 
195  std::vector<dof_id_type> dof_indices;
196  std::vector<std::vector<dof_id_type>> dof_indices_var(3);
197 
198  SparseMatrix<Number> & matrix = system.get_system_matrix();
199 
200  for (const auto & elem : mesh.active_local_element_ptr_range())
201  {
202  dof_map.dof_indices (elem, dof_indices);
203  for (unsigned int var=0; var<3; var++)
204  dof_map.dof_indices (elem, dof_indices_var[var], var);
205 
206  const unsigned int n_dofs = dof_indices.size();
207  const unsigned int n_var_dofs = dof_indices_var[0].size();
208 
209  fe->reinit (elem);
210 
211  Ke.resize (n_dofs, n_dofs);
212  for (unsigned int var_i=0; var_i<3; var_i++)
213  for (unsigned int var_j=0; var_j<3; var_j++)
214  Ke_var[var_i][var_j].reposition (var_i*n_var_dofs, var_j*n_var_dofs, n_var_dofs, n_var_dofs);
215 
216  Fe.resize (n_dofs);
217  for (unsigned int var=0; var<3; var++)
218  Fe_var[var].reposition (var*n_var_dofs, n_var_dofs);
219 
220  for (unsigned int qp=0; qp<qrule.n_points(); qp++)
221  {
222  // assemble \int_Omega C_ijkl u_k,l v_i,j \dx
223  for (unsigned int dof_i=0; dof_i<n_var_dofs; dof_i++)
224  for (unsigned int dof_j=0; dof_j<n_var_dofs; dof_j++)
225  for (unsigned int i=0; i<3; i++)
226  for (unsigned int j=0; j<3; j++)
227  for (unsigned int k=0; k<3; k++)
228  for (unsigned int l=0; l<3; l++)
229  Ke_var[i][k](dof_i,dof_j) +=
230  JxW[qp] * elasticity_tensor(i,j,k,l) * dphi[dof_j][qp](l) * dphi[dof_i][qp](j);
231 
232  // assemble \int_Omega f_i v_i \dx
233  VectorValue<Number> f_vec(0., 0., -1.);
234  for (unsigned int dof_i=0; dof_i<n_var_dofs; dof_i++)
235  for (unsigned int i=0; i<3; i++)
236  Fe_var[i](dof_i) += JxW[qp] * (f_vec(i) * phi[dof_i][qp]);
237  }
238 
239  // assemble \int_\Gamma g_i v_i \ds
240  VectorValue<Number> g_vec(0., 0., -1.);
241  {
242  for (auto side : elem->side_index_range())
243  if (elem->neighbor_ptr(side) == nullptr)
244  {
245  const std::vector<std::vector<Real>> & phi_face = fe_face->get_phi();
246  const std::vector<Real> & JxW_face = fe_face->get_JxW();
247 
248  fe_face->reinit(elem, side);
249 
250  // Apply a traction
251  for (unsigned int qp=0; qp<qface.n_points(); qp++)
252  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_X))
253  for (unsigned int dof_i=0; dof_i<n_var_dofs; dof_i++)
254  for (unsigned int i=0; i<3; i++)
255  Fe_var[i](dof_i) += JxW_face[qp] * (g_vec(i) * phi_face[dof_i][qp]);
256  }
257  }
258 
259  dof_map.constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
260 
261  matrix.add_matrix (Ke, dof_indices);
262  system.rhs->add_vector (Fe, dof_indices);
263  }
264  }
265 
266  // Post-process the solution to compute stresses
268  {
269  const MeshBase & mesh = es.get_mesh();
270  const unsigned int dim = mesh.mesh_dimension();
271 
272  LinearImplicitSystem & system = es.get_system<LinearImplicitSystem>("Elasticity");
273 
274  unsigned int displacement_vars[3];
275  displacement_vars[0] = system.variable_number ("u");
276  displacement_vars[1] = system.variable_number ("v");
277  displacement_vars[2] = system.variable_number ("w");
278  const unsigned int u_var = system.variable_number ("u");
279 
280  const DofMap & dof_map = system.get_dof_map();
281  FEType fe_type = dof_map.variable_type(u_var);
282  std::unique_ptr<FEBase> fe (FEBase::build(dim, fe_type));
283  QGauss qrule (dim, fe_type.default_quadrature_order());
284  fe->attach_quadrature_rule (&qrule);
285 
286  const std::vector<Real> & JxW = fe->get_JxW();
287  const std::vector<std::vector<Real>> & phi = fe->get_phi();
288  const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
289 
290  // Also, get a reference to the ExplicitSystem
291  ExplicitSystem & stress_system = es.get_system<ExplicitSystem>("StressSystem");
292  const DofMap & stress_dof_map = stress_system.get_dof_map();
293  unsigned int sigma_vars[6];
294  sigma_vars[0] = stress_system.variable_number ("sigma_00");
295  sigma_vars[1] = stress_system.variable_number ("sigma_01");
296  sigma_vars[2] = stress_system.variable_number ("sigma_02");
297  sigma_vars[3] = stress_system.variable_number ("sigma_11");
298  sigma_vars[4] = stress_system.variable_number ("sigma_12");
299  sigma_vars[5] = stress_system.variable_number ("sigma_22");
300  unsigned int vonMises_var = stress_system.variable_number ("vonMises");
301 
302  // Storage for the stress dof indices on each element
303  std::vector<std::vector<dof_id_type>> dof_indices_var(system.n_vars());
304  std::vector<dof_id_type> stress_dof_indices_var;
305  std::vector<dof_id_type> vonmises_dof_indices_var;
306 
307  for (const auto & elem : mesh.active_local_element_ptr_range())
308  {
309  for (unsigned int var=0; var<3; var++)
310  dof_map.dof_indices (elem, dof_indices_var[var], displacement_vars[var]);
311 
312  const unsigned int n_var_dofs = dof_indices_var[0].size();
313 
314  fe->reinit (elem);
315 
316  std::vector<TensorValue<Number>> stress_tensor_qp(qrule.n_points());
317  for (unsigned int qp=0; qp<qrule.n_points(); qp++)
318  {
319  // Row is variable u1, u2, or u3, column is x, y, or z
320  TensorValue<Number> grad_u;
321  for (unsigned int var_i=0; var_i<3; var_i++)
322  for (unsigned int var_j=0; var_j<3; var_j++)
323  for (unsigned int j=0; j<n_var_dofs; j++)
324  grad_u(var_i,var_j) += dphi[j][qp](var_j) * system.current_solution(dof_indices_var[var_i][j]);
325 
326  for (unsigned int var_i=0; var_i<3; var_i++)
327  for (unsigned int var_j=0; var_j<3; var_j++)
328  for (unsigned int k=0; k<3; k++)
329  for (unsigned int l=0; l<3; l++)
330  stress_tensor_qp[qp](var_i,var_j) += elasticity_tensor(var_i,var_j,k,l) * grad_u(k,l);
331  }
332 
333  stress_dof_map.dof_indices (elem, vonmises_dof_indices_var, vonMises_var);
334  std::vector<TensorValue<Number>> elem_sigma_vec(vonmises_dof_indices_var.size());
335 
336  // Below we project each component of the stress tensor onto a L2_LAGRANGE discretization.
337  // Note that this gives a discontinuous stress plot on element boundaries, which is
338  // appropriate. We then also get the von Mises stress from the projected stress tensor.
339  unsigned int stress_var_index = 0;
340  for (unsigned int var_i=0; var_i<3; var_i++)
341  for (unsigned int var_j=var_i; var_j<3; var_j++)
342  {
343  stress_dof_map.dof_indices (elem, stress_dof_indices_var, sigma_vars[stress_var_index]);
344 
345  const unsigned int n_proj_dofs = stress_dof_indices_var.size();
346 
347  DenseMatrix<Real> Me(n_proj_dofs, n_proj_dofs);
348  for (unsigned int qp=0; qp<qrule.n_points(); qp++)
349  {
350  for(unsigned int i=0; i<n_proj_dofs; i++)
351  for(unsigned int j=0; j<n_proj_dofs; j++)
352  {
353  Me(i,j) += JxW[qp]*(phi[i][qp]*phi[j][qp]);
354  }
355  }
356 
357  DenseVector<Number> Fe(n_proj_dofs);
358  for (unsigned int qp=0; qp<qrule.n_points(); qp++)
359  for(unsigned int i=0; i<n_proj_dofs; i++)
360  {
361  Fe(i) += JxW[qp] * stress_tensor_qp[qp](var_i,var_j) * phi[i][qp];
362  }
363 
364  DenseVector<Number> projected_data;
365  Me.cholesky_solve(Fe, projected_data);
366 
367  for(unsigned int index=0; index<n_proj_dofs; index++)
368  {
369  dof_id_type dof_index = stress_dof_indices_var[index];
370  if ((stress_system.solution->first_local_index() <= dof_index) &&
371  (dof_index < stress_system.solution->last_local_index()))
372  stress_system.solution->set(dof_index, projected_data(index));
373 
374  elem_sigma_vec[index](var_i,var_j) = projected_data(index);
375  }
376 
377  stress_var_index++;
378  }
379 
380  for (std::size_t index=0; index<elem_sigma_vec.size(); index++)
381  {
382  elem_sigma_vec[index](1,0) = elem_sigma_vec[index](0,1);
383  elem_sigma_vec[index](2,0) = elem_sigma_vec[index](0,2);
384  elem_sigma_vec[index](2,1) = elem_sigma_vec[index](1,2);
385 
386  // Get the von Mises stress from the projected stress tensor
387  Number vonMises_value = std::sqrt(0.5*(Utility::pow<2>(elem_sigma_vec[index](0,0) - elem_sigma_vec[index](1,1)) +
388  Utility::pow<2>(elem_sigma_vec[index](1,1) - elem_sigma_vec[index](2,2)) +
389  Utility::pow<2>(elem_sigma_vec[index](2,2) - elem_sigma_vec[index](0,0)) +
390  6.*(Utility::pow<2>(elem_sigma_vec[index](0,1)) +
391  Utility::pow<2>(elem_sigma_vec[index](1,2)) +
392  Utility::pow<2>(elem_sigma_vec[index](2,0)))));
393 
394  dof_id_type dof_index = vonmises_dof_indices_var[index];
395 
396  if ((stress_system.solution->first_local_index() <= dof_index) &&
397  (dof_index < stress_system.solution->last_local_index()))
398  stress_system.solution->set(dof_index, vonMises_value);
399  }
400  }
401 
402  // Should call close and update when we set vector entries directly
403  stress_system.solution->close();
404  stress_system.update();
405  }
406 };
407 
408 
409 // Begin the main program.
410 int main (int argc, char ** argv)
411 {
412  // Initialize libMesh and any dependent libraries
413  LibMeshInit init (argc, argv);
414 
415  // This example requires a linear solver package.
416  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
417  "--enable-petsc, --enable-trilinos, or --enable-eigen");
418 
419  // Initialize the cantilever mesh
420  const unsigned int dim = 3;
421 
422  // Make sure libMesh was compiled for 3D
423  libmesh_example_requires(dim == LIBMESH_DIM, "3D support");
424 
425  // We use Dirichlet boundary conditions here
426 #ifndef LIBMESH_ENABLE_DIRICHLET
427  libmesh_example_requires(false, "--enable-dirichlet");
428 #endif
429 
430  // Get the mesh size from the command line.
431  const int nx = libMesh::command_line_next("-nx", 32),
432  ny = libMesh::command_line_next("-ny", 8),
433  nz = libMesh::command_line_next("-nz", 4);
434 
435  // Create a 3D mesh distributed across the default MPI communicator.
436  Mesh mesh(init.comm(), dim);
438  nx,
439  ny,
440  nz,
441  0., 1.*x_scaling,
442  0., 0.3,
443  0., 0.1,
444  HEX8);
445 
446  // Print information about the mesh to the screen.
447  mesh.print_info();
448 
449  // Let's add some node and edge boundary conditions
450  // Each processor should know about each boundary condition it can
451  // see, so we loop over all elements, not just local elements.
452  for (const auto & elem : mesh.element_ptr_range())
453  {
454  unsigned int
455  side_max_x = 0, side_min_y = 0,
456  side_max_y = 0, side_max_z = 0;
457 
458  bool
459  found_side_max_x = false, found_side_max_y = false,
460  found_side_min_y = false, found_side_max_z = false;
461 
462  for (auto side : elem->side_index_range())
463  {
464  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_X))
465  {
466  side_max_x = side;
467  found_side_max_x = true;
468  }
469 
470  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MIN_Y))
471  {
472  side_min_y = side;
473  found_side_min_y = true;
474  }
475 
476  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Y))
477  {
478  side_max_y = side;
479  found_side_max_y = true;
480  }
481 
482  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Z))
483  {
484  side_max_z = side;
485  found_side_max_z = true;
486  }
487  }
488 
489  // If elem has sides on boundaries
490  // BOUNDARY_ID_MAX_X, BOUNDARY_ID_MAX_Y, BOUNDARY_ID_MAX_Z
491  // then let's set a node boundary condition
492  if (found_side_max_x && found_side_max_y && found_side_max_z)
493  for (auto n : elem->node_index_range())
494  if (elem->is_node_on_side(n, side_max_x) &&
495  elem->is_node_on_side(n, side_max_y) &&
496  elem->is_node_on_side(n, side_max_z))
497  mesh.get_boundary_info().add_node(elem->node_ptr(n), NODE_BOUNDARY_ID);
498 
499 
500  // If elem has sides on boundaries
501  // BOUNDARY_ID_MAX_X and BOUNDARY_ID_MIN_Y
502  // then let's set an edge boundary condition
503  if (found_side_max_x && found_side_min_y)
504  for (auto e : elem->edge_index_range())
505  if (elem->is_edge_on_side(e, side_max_x) &&
506  elem->is_edge_on_side(e, side_min_y))
507  mesh.get_boundary_info().add_edge(elem, e, EDGE_BOUNDARY_ID);
508  }
509 
510  // Create an equation systems object.
511  EquationSystems equation_systems (mesh);
512 
513  // Declare the system and its variables.
514  // Create a system named "Elasticity"
515  LinearImplicitSystem & system =
516  equation_systems.add_system<LinearImplicitSystem> ("Elasticity");
517 
518 #ifdef LIBMESH_HAVE_PETSC
519  // Attach a SolverConfiguration object to system.linear_solver
520  PetscLinearSolver<Number> * petsc_linear_solver =
521  cast_ptr<PetscLinearSolver<Number>*>(system.get_linear_solver());
522  libmesh_assert(petsc_linear_solver);
523  PetscSolverConfiguration petsc_solver_config(*petsc_linear_solver);
524  petsc_linear_solver->set_solver_configuration(petsc_solver_config);
525 #endif
526 
527  LinearElasticity le(equation_systems);
528  system.attach_assemble_object(le);
529 
530 #ifdef LIBMESH_ENABLE_DIRICHLET
531  // Add three displacement variables, u and v, to the system
532  unsigned int u_var = system.add_variable("u", FIRST, LAGRANGE);
533  unsigned int v_var = system.add_variable("v", FIRST, LAGRANGE);
534  unsigned int w_var = system.add_variable("w", FIRST, LAGRANGE);
535 
536  // Create a ZeroFunction to initialize dirichlet_bc
537  ZeroFunction<> zf;
538 
539  // Most DirichletBoundary users will want to supply a "locally
540  // indexed" functor
541  DirichletBoundary dirichlet_bc({BOUNDARY_ID_MIN_X, NODE_BOUNDARY_ID,
542  EDGE_BOUNDARY_ID},
543  {u_var, v_var, w_var}, zf,
545 
546  // We must add the Dirichlet boundary condition _before_
547  // we call equation_systems.init()
548  system.get_dof_map().add_dirichlet_boundary(dirichlet_bc);
549 #endif // LIBMESH_ENABLE_DIRICHLET
550 
551  // Also, initialize an ExplicitSystem to store stresses
552  ExplicitSystem & stress_system =
553  equation_systems.add_system<ExplicitSystem> ("StressSystem");
554 
555  stress_system.add_variable("sigma_00", FIRST, L2_LAGRANGE);
556  stress_system.add_variable("sigma_01", FIRST, L2_LAGRANGE);
557  stress_system.add_variable("sigma_02", FIRST, L2_LAGRANGE);
558  stress_system.add_variable("sigma_11", FIRST, L2_LAGRANGE);
559  stress_system.add_variable("sigma_12", FIRST, L2_LAGRANGE);
560  stress_system.add_variable("sigma_22", FIRST, L2_LAGRANGE);
561  stress_system.add_variable("vonMises", FIRST, L2_LAGRANGE);
562 
563  // Initialize the data structures for the equation system.
564  equation_systems.init();
565 
566  // Print information about the system to the screen.
567  equation_systems.print_info();
568 
569  // Solve the system
570  system.solve();
571 
572  // Post-process the solution to compute the stresses
573  le.compute_stresses();
574 
575  // Plot the solution
576 #ifdef LIBMESH_HAVE_EXODUS_API
577 
578  // Use single precision in this case (reduces the size of the exodus file)
579  ExodusII_IO exo_io(mesh, /*single_precision=*/true);
580  exo_io.write_discontinuous_exodusII("displacement_and_stress.exo", equation_systems);
581 
582 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
583 
584  // All done.
585  return 0;
586 }
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:196
virtual void configure_solver()
Apply solver options to a particular solver.
T command_line_next(std::string name, T default_value)
Use GetPot&#39;s search()/next() functions to get following arguments from the command line...
Definition: libmesh.C:1078
This is the EquationSystems class.
bool has_boundary_id(const Node *const node, const boundary_id_type id) const
Real elasticity_tensor(unsigned int i, unsigned int j, unsigned int k, unsigned int l)
Definition: assembly.C:43
ConstFunction that simply returns 0.
Definition: zero_function.h:38
void assemble()
Assemble the system matrix and right-hand side 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:2330
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition: dof_map.C:2164
Real kronecker_delta(unsigned int i, unsigned int j)
Definition: assembly.C:37
unsigned int dim
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:52
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
void resize(const unsigned int n)
Resize the vector.
Definition: dense_vector.h:396
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]...
const FEType & variable_type(const unsigned int c) const
Definition: dof_map.h:2220
LinearElasticity(EquationSystems &es_in)
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
MeshBase & mesh
NumericVector< Number > * rhs
The system matrix.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
Order default_quadrature_order() const
Definition: fe_type.h:371
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
virtual LinearSolver< Number > * get_linear_solver() const override
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:90
The libMesh namespace provides an interface to certain functionality in the library.
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:165
Abstract base class to be used for system assembly.
Definition: system.h:155
virtual void solve() override
Assembles & solves the linear system A*x=b.
const T_sys & get_system(std::string_view name) const
int main(int argc, char **argv)
This is the MeshBase class.
Definition: mesh_base.h:75
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:165
unsigned int variable_number(std::string_view var) const
Definition: system.C:1609
Defines a dense subvector for use in finite element computations.
SolverPackage default_solver_package()
Definition: libmesh.C:1117
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:179
void add_node(const Node *node, const boundary_id_type id)
Add Node node with boundary id id to the boundary information data structures.
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.
PetscSolverConfiguration(PetscLinearSolver< Number > &petsc_linear_solver)
PetscLinearSolver< Number > & _petsc_linear_solver
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
Definition: mesh_base.C:1562
Defines a dense submatrix for use in Finite Element-type computations.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1593
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
libmesh_assert(ctx)
This class stores solver configuration data, e.g.
unsigned int add_variable(std::string_view 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:1357
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.
void attach_assemble_object(Assembly &assemble)
Register a user object to use in assembling the system matrix and RHS.
Definition: system.C:2178
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition: system.C:510
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:193
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const MeshBase & get_mesh() const
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
Definition: dense_matrix.h:895
This class implements specific orders of Gauss quadrature.
unsigned int mesh_dimension() const
Definition: mesh_base.C:372
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
void cholesky_solve(const DenseVector< T2 > &b, DenseVector< T2 > &x)
For symmetric positive definite (SPD) matrices.
virtual void init()
Initialize all the systems.
unsigned int n_vars() const
Definition: system.h:2430
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
Real kronecker_delta(unsigned int i, unsigned int j)
Kronecker delta function.
const DofMap & get_dof_map() const
Definition: system.h:2374
const SparseMatrix< Number > & get_system_matrix() const
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.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
uint8_t dof_id_type
Definition: id_types.h:67
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...