libMesh
Loading...
Searching...
No Matches
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 509 of file systems_of_equations_ex7.C.

510{
511 LibMeshInit init (argc, argv);
512
513 // This example requires the PETSc nonlinear solvers
514 libmesh_example_requires(libMesh::default_solver_package() == PETSC_SOLVERS, "--enable-petsc");
515
516 // We use a 3D domain.
517 libmesh_example_requires(LIBMESH_DIM > 2, "--disable-1D-only --disable-2D-only");
518
519 // We use Dirichlet boundary conditions here
520#ifndef LIBMESH_ENABLE_DIRICHLET
521 libmesh_example_requires(false, "--enable-dirichlet");
522#endif
523
524 GetPot infile("systems_of_equations_ex7.in");
525
526 infile.parse_command_line(argc,argv);
527
528 const Real x_length = infile("x_length", 0.);
529 const Real y_length = infile("y_length", 0.);
530 const Real z_length = infile("z_length", 0.);
531 const int n_elem_x = infile("n_elem_x", 0);
532 const int n_elem_y = infile("n_elem_y", 0);
533 const int n_elem_z = infile("n_elem_z", 0);
534 const std::string approx_order = infile("approx_order", "FIRST");
535 const std::string fe_family = infile("fe_family", "LAGRANGE");
536
537 const Real young_modulus = infile("Young_modulus", 1.0);
538 const Real poisson_ratio = infile("poisson_ratio", 0.3);
539 const Real forcing_magnitude = infile("forcing_magnitude", 0.001);
540
541 const Real nonlinear_abs_tol = infile("nonlinear_abs_tol", 1.e-8);
542 const Real nonlinear_rel_tol = infile("nonlinear_rel_tol", 1.e-8);
543 const unsigned int nonlinear_max_its = infile("nonlinear_max_its", 50);
544
545 const unsigned int n_solves = infile("n_solves", 10);
546 const Real force_scaling = infile("force_scaling", 5.0);
547
548 Mesh mesh(init.comm());
549
551 n_elem_x,
552 n_elem_y,
553 n_elem_z,
554 0., x_length,
555 0., y_length,
556 0., z_length,
557 HEX27);
558
560
561 EquationSystems equation_systems (mesh);
562 LargeDeformationElasticity lde(equation_systems);
563
564 NonlinearImplicitSystem & system =
565 equation_systems.add_system<NonlinearImplicitSystem> ("NonlinearElasticity");
567
568 unsigned int u_var =
569 system.add_variable("u",
570 Utility::string_to_enum<Order> (approx_order),
571 Utility::string_to_enum<FEFamily>(fe_family));
572
573 unsigned int v_var =
574 system.add_variable("v",
575 Utility::string_to_enum<Order> (approx_order),
576 Utility::string_to_enum<FEFamily>(fe_family));
577
578 unsigned int w_var =
579 system.add_variable("w",
580 Utility::string_to_enum<Order> (approx_order),
581 Utility::string_to_enum<FEFamily>(fe_family));
582
583 // Also, initialize an ExplicitSystem to store stresses
584 ExplicitSystem & stress_system =
585 equation_systems.add_system<ExplicitSystem> ("StressSystem");
586 stress_system.add_variable("sigma_00", CONSTANT, MONOMIAL);
587 stress_system.add_variable("sigma_01", CONSTANT, MONOMIAL);
588 stress_system.add_variable("sigma_02", CONSTANT, MONOMIAL);
589 stress_system.add_variable("sigma_11", CONSTANT, MONOMIAL);
590 stress_system.add_variable("sigma_12", CONSTANT, MONOMIAL);
591 stress_system.add_variable("sigma_22", CONSTANT, MONOMIAL);
592
593 equation_systems.parameters.set<Real> ("nonlinear solver absolute residual tolerance") = nonlinear_abs_tol;
594 equation_systems.parameters.set<Real> ("nonlinear solver relative residual tolerance") = nonlinear_rel_tol;
595 equation_systems.parameters.set<unsigned int> ("nonlinear solver maximum iterations") = nonlinear_max_its;
596
597 system.nonlinear_solver->residual_object = &lde;
598 system.nonlinear_solver->jacobian_object = &lde;
599
600 equation_systems.parameters.set<Real>("young_modulus") = young_modulus;
601 equation_systems.parameters.set<Real>("poisson_ratio") = poisson_ratio;
602 equation_systems.parameters.set<Real>("forcing_magnitude") = forcing_magnitude;
603
604#ifdef LIBMESH_ENABLE_DIRICHLET
605 // Attach Dirichlet (Clamped) boundary conditions
607
608 // Most DirichletBoundary users will want to supply a "locally
609 // indexed" functor
611 (DirichletBoundary ({BOUNDARY_ID_MIN_X}, {u_var, v_var, w_var},
613#endif // LIBMESH_ENABLE_DIRICHLET
614 libmesh_ignore(u_var, v_var, w_var);
615
616 equation_systems.init();
617 equation_systems.print_info();
618
619 // Provide a loop here so that we can do a sequence of solves
620 // where solve n gives a good starting guess for solve n+1.
621 // This "continuation" approach is helpful for solving for
622 // large values of "forcing_magnitude".
623 // Set n_solves and force_scaling in nonlinear_elasticity.in.
624 for (unsigned int count=0; count<n_solves; count++)
625 {
626 Real previous_forcing_magnitude = equation_systems.parameters.get<Real>("forcing_magnitude");
627 equation_systems.parameters.set<Real>("forcing_magnitude") = previous_forcing_magnitude*force_scaling;
628
629 libMesh::out << "Performing solve "
630 << count
631 << ", forcing_magnitude: "
632 << equation_systems.parameters.get<Real>("forcing_magnitude")
633 << std::endl;
634
635 system.solve();
636
637 libMesh::out << "System solved at nonlinear iteration "
638 << system.n_nonlinear_iterations()
639 << " , final nonlinear residual norm: "
640 << system.final_nonlinear_residual()
641 << std::endl
642 << std::endl;
643
644 libMesh::out << "Computing stresses..." << std::endl;
645
646 lde.compute_stresses();
647
648#ifdef LIBMESH_HAVE_EXODUS_API
649 std::stringstream filename;
650 filename << "solution_" << count << ".exo";
651 ExodusII_IO (mesh).write_equation_systems(filename.str(), equation_systems);
652#endif
653 }
654
655 return 0;
656}
streamT * get()
Rather than implement every ostream/ios/ios_base function, we'll be lazy and make esoteric uses go th...
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
This is the EquationSystems class.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition exodusII_io.h:53
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition libmesh.h:92
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:1755
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
virtual void solve() override
Assembles & solves the nonlinear system R(x) = 0.
std::unique_ptr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system.
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:1344
void prefer_hash_table_matrix_assembly(bool preference)
Sets whether to use hash table matrix assembly if the matrix sub-classes support it.
Definition system.h:2667
const DofMap & get_dof_map() const
Definition system.h:2417
ConstFunction that simply returns 0.
MeshBase & mesh
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.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
void libmesh_ignore(const Args &...)
SolverPackage default_solver_package()
Definition libmesh.C:1064
OStreamProxy out
const Number zero
.
Definition libmesh.h:297
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

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::EquationSystems::init(), libMesh::libmesh_ignore(), libMesh::LOCAL_VARIABLE_ORDER, main(), mesh, libMesh::MONOMIAL, libMesh::NonlinearImplicitSystem::n_nonlinear_iterations(), libMesh::NonlinearImplicitSystem::nonlinear_solver, libMesh::out, libMesh::EquationSystems::parameters, libMesh::PETSC_SOLVERS, libMesh::System::prefer_hash_table_matrix_assembly(), libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::Real, libMesh::Parameters::set(), libMesh::NonlinearImplicitSystem::solve(), libMesh::ExodusII_IO::write_equation_systems(), and libMesh::zero.