libMesh
Classes | Functions
systems_of_equations_ex7.C File Reference

Go to the source code of this file.

Classes

class  LargeDeformationElasticity
 

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 524 of file systems_of_equations_ex7.C.

525 {
526  LibMeshInit init (argc, argv);
527 
528  // This example requires the PETSc nonlinear solvers
529  libmesh_example_requires(libMesh::default_solver_package() == PETSC_SOLVERS, "--enable-petsc");
530 
531  // We use a 3D domain.
532  libmesh_example_requires(LIBMESH_DIM > 2, "--disable-1D-only --disable-2D-only");
533 
534  // We use Dirichlet boundary conditions here
535 #ifndef LIBMESH_ENABLE_DIRICHLET
536  libmesh_example_requires(false, "--enable-dirichlet");
537 #endif
538 
539  GetPot infile("systems_of_equations_ex7.in");
540  const Real x_length = infile("x_length", 0.);
541  const Real y_length = infile("y_length", 0.);
542  const Real z_length = infile("z_length", 0.);
543  const int n_elem_x = infile("n_elem_x", 0);
544  const int n_elem_y = infile("n_elem_y", 0);
545  const int n_elem_z = infile("n_elem_z", 0);
546  const std::string approx_order = infile("approx_order", "FIRST");
547  const std::string fe_family = infile("fe_family", "LAGRANGE");
548 
549  const Real young_modulus = infile("Young_modulus", 1.0);
550  const Real poisson_ratio = infile("poisson_ratio", 0.3);
551  const Real forcing_magnitude = infile("forcing_magnitude", 0.001);
552 
553  const Real nonlinear_abs_tol = infile("nonlinear_abs_tol", 1.e-8);
554  const Real nonlinear_rel_tol = infile("nonlinear_rel_tol", 1.e-8);
555  const unsigned int nonlinear_max_its = infile("nonlinear_max_its", 50);
556 
557  const unsigned int n_solves = infile("n_solves", 10);
558  const Real force_scaling = infile("force_scaling", 5.0);
559 
560  Mesh mesh(init.comm());
561 
563  n_elem_x,
564  n_elem_y,
565  n_elem_z,
566  0., x_length,
567  0., y_length,
568  0., z_length,
569  HEX27);
570 
571  mesh.print_info();
572 
573  EquationSystems equation_systems (mesh);
574  LargeDeformationElasticity lde(equation_systems);
575 
576  NonlinearImplicitSystem & system =
577  equation_systems.add_system<NonlinearImplicitSystem> ("NonlinearElasticity");
578 
579  unsigned int u_var =
580  system.add_variable("u",
581  Utility::string_to_enum<Order> (approx_order),
582  Utility::string_to_enum<FEFamily>(fe_family));
583 
584  unsigned int v_var =
585  system.add_variable("v",
586  Utility::string_to_enum<Order> (approx_order),
587  Utility::string_to_enum<FEFamily>(fe_family));
588 
589  unsigned int w_var =
590  system.add_variable("w",
591  Utility::string_to_enum<Order> (approx_order),
592  Utility::string_to_enum<FEFamily>(fe_family));
593 
594  // Also, initialize an ExplicitSystem to store stresses
595  ExplicitSystem & stress_system =
596  equation_systems.add_system<ExplicitSystem> ("StressSystem");
597  stress_system.add_variable("sigma_00", CONSTANT, MONOMIAL);
598  stress_system.add_variable("sigma_01", CONSTANT, MONOMIAL);
599  stress_system.add_variable("sigma_02", CONSTANT, MONOMIAL);
600  stress_system.add_variable("sigma_11", CONSTANT, MONOMIAL);
601  stress_system.add_variable("sigma_12", CONSTANT, MONOMIAL);
602  stress_system.add_variable("sigma_22", CONSTANT, MONOMIAL);
603 
604  equation_systems.parameters.set<Real> ("nonlinear solver absolute residual tolerance") = nonlinear_abs_tol;
605  equation_systems.parameters.set<Real> ("nonlinear solver relative residual tolerance") = nonlinear_rel_tol;
606  equation_systems.parameters.set<unsigned int> ("nonlinear solver maximum iterations") = nonlinear_max_its;
607 
608  system.nonlinear_solver->residual_object = &lde;
609  system.nonlinear_solver->jacobian_object = &lde;
610 
611  equation_systems.parameters.set<Real>("young_modulus") = young_modulus;
612  equation_systems.parameters.set<Real>("poisson_ratio") = poisson_ratio;
613  equation_systems.parameters.set<Real>("forcing_magnitude") = forcing_magnitude;
614 
615 #ifdef LIBMESH_ENABLE_DIRICHLET
616  // Attach Dirichlet boundary conditions
617  std::set<boundary_id_type> clamped_boundaries;
618  clamped_boundaries.insert(BOUNDARY_ID_MIN_X);
619 
620  std::vector<unsigned int> uvw;
621  uvw.push_back(u_var);
622  uvw.push_back(v_var);
623  uvw.push_back(w_var);
624 
626 
627  // Most DirichletBoundary users will want to supply a "locally
628  // indexed" functor
630  (DirichletBoundary (clamped_boundaries, uvw, zero,
632 #else
633  libmesh_ignore(u_var, v_var, w_var);
634 #endif // LIBMESH_ENABLE_DIRICHLET
635 
636  equation_systems.init();
637  equation_systems.print_info();
638 
639  // Provide a loop here so that we can do a sequence of solves
640  // where solve n gives a good starting guess for solve n+1.
641  // This "continuation" approach is helpful for solving for
642  // large values of "forcing_magnitude".
643  // Set n_solves and force_scaling in nonlinear_elasticity.in.
644  for (unsigned int count=0; count<n_solves; count++)
645  {
646  Real previous_forcing_magnitude = equation_systems.parameters.get<Real>("forcing_magnitude");
647  equation_systems.parameters.set<Real>("forcing_magnitude") = previous_forcing_magnitude*force_scaling;
648 
649  libMesh::out << "Performing solve "
650  << count
651  << ", forcing_magnitude: "
652  << equation_systems.parameters.get<Real>("forcing_magnitude")
653  << std::endl;
654 
655  system.solve();
656 
657  libMesh::out << "System solved at nonlinear iteration "
658  << system.n_nonlinear_iterations()
659  << " , final nonlinear residual norm: "
660  << system.final_nonlinear_residual()
661  << std::endl
662  << std::endl;
663 
664  libMesh::out << "Computing stresses..." << std::endl;
665 
666  lde.compute_stresses();
667 
668 #ifdef LIBMESH_HAVE_EXODUS_API
669  std::stringstream filename;
670  filename << "solution_" << count << ".exo";
671  ExodusII_IO (mesh).write_equation_systems(filename.str(), equation_systems);
672 #endif
673  }
674 
675  return 0;
676 }

References libMesh::DofMap::add_dirichlet_boundary(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshTools::Generation::build_cube(), LargeDeformationElasticity::compute_stresses(), libMesh::CONSTANT, libMesh::default_solver_package(), libMesh::NonlinearImplicitSystem::final_nonlinear_residual(), libMesh::Parameters::get(), libMesh::System::get_dof_map(), libMesh::HEX27, libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), libMesh::libmesh_ignore(), libMesh::LOCAL_VARIABLE_ORDER, mesh, libMesh::MONOMIAL, libMesh::NonlinearImplicitSystem::n_nonlinear_iterations(), libMesh::NonlinearImplicitSystem::nonlinear_solver, libMesh::out, libMesh::EquationSystems::parameters, libMesh::PETSC_SOLVERS, libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::Real, libMesh::Parameters::set(), libMesh::NonlinearImplicitSystem::solve(), libMesh::MeshOutput< MT >::write_equation_systems(), and libMesh::zero.

libMesh::NonlinearImplicitSystem::final_nonlinear_residual
Real final_nonlinear_residual() const
Definition: nonlinear_implicit_system.h:278
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::PETSC_SOLVERS
Definition: enum_solver_package.h:36
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::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
libMesh::default_solver_package
SolverPackage default_solver_package()
Definition: libmesh.C:993
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
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::NonlinearImplicitSystem
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
Definition: nonlinear_implicit_system.h:54
libMesh::NonlinearImplicitSystem::solve
virtual void solve() override
Assembles & solves the nonlinear system R(x) = 0.
Definition: nonlinear_implicit_system.C:161
libMesh::zero
const Number zero
.
Definition: libmesh.h:243
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
libMesh::LOCAL_VARIABLE_ORDER
Definition: dirichlet_boundaries.h:62
libMesh::HEX27
Definition: enum_elem_type.h:49
libMesh::BasicOStreamProxy::get
streamT * get()
Rather than implement every ostream/ios/ios_base function, we'll be lazy and make esoteric uses go th...
Definition: ostream_proxy.h:213
libMesh::libmesh_ignore
void libmesh_ignore(const Args &...)
Definition: libmesh_common.h:526
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::NonlinearImplicitSystem::n_nonlinear_iterations
unsigned int n_nonlinear_iterations() const
Definition: nonlinear_implicit_system.h:273
LargeDeformationElasticity
Definition: systems_of_equations_ex7.C:85
libMesh::CONSTANT
Definition: enum_order.h:41
libMesh::LibMeshInit
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:83
libMesh::ZeroFunction
ConstFunction that simply returns 0.
Definition: zero_function.h:36
libMesh::MONOMIAL
Definition: enum_fe_family.h:39
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::MeshOutput::write_equation_systems
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
Definition: mesh_output.C:31
libMesh::NonlinearImplicitSystem::nonlinear_solver
std::unique_ptr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system.
Definition: nonlinear_implicit_system.h:261
libMesh::ExplicitSystem
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
Definition: explicit_system.h:48
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::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::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::out
OStreamProxy out