libMesh
Classes | Functions
systems_of_equations_ex9.C File Reference

Go to the source code of this file.

Classes

class  AzimuthalPeriodicBoundary
 
class  LinearElasticity
 

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 345 of file systems_of_equations_ex9.C.

346 {
347  // Initialize libMesh and any dependent libraries
348  LibMeshInit init (argc, argv);
349 
350  // This example requires a linear solver package.
351  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
352  "--enable-petsc, --enable-trilinos, or --enable-eigen");
353 
354 #ifndef LIBMESH_HAVE_EXODUS_API
355  // example requires ExodusII to load the mesh
356  libmesh_example_requires(false, "--enable-exodus");
357 #endif
358 
359  // We use Dirichlet and Periodic boundary conditions here
360 #ifndef LIBMESH_ENABLE_DIRICHLET
361  libmesh_example_requires(false, "--enable-dirichlet");
362 #endif
363 #ifndef LIBMESH_ENABLE_PERIODIC
364  libmesh_example_requires(false, "--enable-periodic");
365 #endif
366 
367  // Initialize the cantilever mesh
368  const unsigned int dim = 3;
369 
370  // Make sure libMesh was compiled for 3D
371  libmesh_example_requires(dim == LIBMESH_DIM, "3D support");
372 
373  // Make sure libMesh has normal boundary id sizes
374  libmesh_example_requires(sizeof(boundary_id_type) > 1, "boundary_id_size > 1");
375 
376 #if LIBMESH_BOUNDARY_ID_BYTES > 1
377  // Create a 3D mesh distributed across the default MPI communicator.
378  Mesh mesh(init.comm());
379 
380  // Create an equation systems object.
381  EquationSystems equation_systems (mesh);
382 
383  // Declare the system and its variables.
384  // Create a system named "Elasticity"
385  LinearImplicitSystem & system =
386  equation_systems.add_system<LinearImplicitSystem> ("Elasticity");
387 
388 #ifdef LIBMESH_ENABLE_PERIODIC
389  // Add two azimuthal periodic boundaries on two adjacent domains.
390  // We do this to show that the periodic boundary condition that
391  // we impose leads to a continuous solution across adjacent domains.
392  //
393  // We add the periodic boundaries *before* reading the Mesh, so
394  // that periodic neighbors will be retained when a DistributedMesh
395  // is distributed.
396  //
397  // The angle specified below defines the mapping
398  // from "pairedboundary" to "myboundary".
399  {
400  Point center(0., 0., 0.);
401  Point axis(0., 0., 1.);
402  Real angle = 2*libMesh::pi/12.0;
403  AzimuthalPeriodicBoundary periodic_bc(center, axis, angle);
404  periodic_bc.myboundary = 301;
405  periodic_bc.pairedboundary = 302;
406  system.get_dof_map().add_periodic_boundary(periodic_bc);
407  }
408  {
409  Point center(0., 0., 0.);
410  Point axis(0., 0., 1.);
411  Real angle = 2*libMesh::pi/12.0;
412  AzimuthalPeriodicBoundary periodic_bc(center, axis, angle);
413  periodic_bc.myboundary = 401;
414  periodic_bc.pairedboundary = 402;
415  system.get_dof_map().add_periodic_boundary(periodic_bc);
416  }
417 #endif // LIBMESH_ENABLE_PERIODIC
418 
419  mesh.read("systems_of_equations_ex9.exo");
420 
421  // Print information about the mesh to the screen.
422  mesh.print_info();
423 
424  // Add three displacement variables, u and v, to the system
425  unsigned int u_var = system.add_variable("u", FIRST, LAGRANGE);
426  unsigned int v_var = system.add_variable("v", FIRST, LAGRANGE);
427  unsigned int w_var = system.add_variable("w", FIRST, LAGRANGE);
428 
429  LinearElasticity le(equation_systems);
430  system.attach_assemble_object(le);
431 
432  std::vector<unsigned int> variables;
433  variables.push_back(u_var);
434  variables.push_back(v_var);
435  variables.push_back(w_var);
436  ZeroFunction<> zf;
437  std::set<boundary_id_type> clamped_boundary_ids;
438  clamped_boundary_ids.insert(300);
439  clamped_boundary_ids.insert(400);
440 
441 #ifdef LIBMESH_ENABLE_DIRICHLET
442  DirichletBoundary clamped_bc(clamped_boundary_ids, variables, zf);
443  system.get_dof_map().add_dirichlet_boundary(clamped_bc);
444 #endif
445 
446  // Initialize the data structures for the equation system.
447  equation_systems.init();
448 
449  // Print information about the system to the screen.
450  equation_systems.print_info();
451 
452  // Solve the system
453  system.solve();
454 
455  // Plot the solution
456 #ifdef LIBMESH_HAVE_EXODUS_API
457 
458  ExodusII_IO (mesh).write_equation_systems("solution.exo",
459  equation_systems);
460 
461 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
462 #endif // #if LIBMESH_BOUNDARY_ID_BYTES > 1
463 
464  // All done.
465  return 0;
466 }

References libMesh::DofMap::add_dirichlet_boundary(), libMesh::DofMap::add_periodic_boundary(), libMesh::System::add_variable(), libMesh::System::attach_assemble_object(), libMesh::default_solver_package(), dim, libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::TriangleWrapper::init(), libMesh::INVALID_SOLVER_PACKAGE, libMesh::LAGRANGE, mesh, libMesh::PeriodicBoundaryBase::myboundary, libMesh::PeriodicBoundaryBase::pairedboundary, libMesh::pi, libMesh::MeshBase::print_info(), libMesh::MeshBase::read(), libMesh::Real, libMesh::LinearImplicitSystem::solve(), and libMesh::MeshOutput< MT >::write_equation_systems().

libMesh::pi
const Real pi
.
Definition: libmesh.h:237
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::MeshBase::read
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
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
LinearElasticity
Definition: systems_of_equations_ex6.C:114
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::ExodusII_IO
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:51
libMesh::boundary_id_type
int8_t boundary_id_type
Definition: id_types.h:51
dim
unsigned int dim
Definition: adaptivity_ex3.C:113
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
libMesh::INVALID_SOLVER_PACKAGE
Definition: enum_solver_package.h:43
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::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
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::DofMap::add_periodic_boundary
void add_periodic_boundary(const PeriodicBoundaryBase &periodic_boundary)
Adds a copy of the specified periodic boundary to the system.
Definition: dof_map_constraints.C:4510
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
AzimuthalPeriodicBoundary
Definition: systems_of_equations_ex9.C:75
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::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::LinearImplicitSystem
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
Definition: linear_implicit_system.h:55
libMesh::FIRST
Definition: enum_order.h:42