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

336{
337 // Initialize libMesh and any dependent libraries
338 LibMeshInit init (argc, argv);
339
340 // This example requires a linear solver package.
341 libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
342 "--enable-petsc, --enable-trilinos, or --enable-eigen");
343
344#ifndef LIBMESH_HAVE_EXODUS_API
345 // example requires ExodusII to load the mesh
346 libmesh_example_requires(false, "--enable-exodus");
347#endif
348
349 // We use Dirichlet and Periodic boundary conditions here
350#ifndef LIBMESH_ENABLE_DIRICHLET
351 libmesh_example_requires(false, "--enable-dirichlet");
352#endif
353#ifndef LIBMESH_ENABLE_PERIODIC
354 libmesh_example_requires(false, "--enable-periodic");
355#endif
356
357 // Initialize the cantilever mesh
358 const unsigned int dim = 3;
359
360 // Make sure libMesh was compiled for 3D
361 libmesh_example_requires(dim == LIBMESH_DIM, "3D support");
362
363 // Make sure libMesh has normal boundary id sizes
364 libmesh_example_requires(sizeof(boundary_id_type) > 1, "boundary_id_size > 1");
365
366#if LIBMESH_BOUNDARY_ID_BYTES > 1
367 // Create a 3D mesh distributed across the default MPI communicator.
368 Mesh mesh(init.comm());
369
370 // Create an equation systems object.
371 EquationSystems equation_systems (mesh);
372
373 // Declare the system and its variables.
374 // Create a system named "Elasticity"
375 LinearImplicitSystem & system =
376 equation_systems.add_system<LinearImplicitSystem> ("Elasticity");
377
378#ifdef LIBMESH_ENABLE_PERIODIC
379 // Add two azimuthal periodic boundaries on two adjacent domains.
380 // We do this to show that the periodic boundary condition that
381 // we impose leads to a continuous solution across adjacent domains.
382 //
383 // We add the periodic boundaries *before* reading the Mesh, so
384 // that periodic neighbors will be retained when a DistributedMesh
385 // is distributed.
386 //
387 // The angle specified below defines the mapping
388 // from "pairedboundary" to "myboundary".
389 {
390 Point center(0., 0., 0.);
391 Point axis(0., 0., 1.);
392 Real angle = 2*libMesh::pi/12.0;
393 AzimuthalPeriodicBoundary periodic_bc(center, axis, angle);
394 periodic_bc.myboundary = 301;
395 periodic_bc.pairedboundary = 302;
396 system.get_dof_map().add_periodic_boundary(periodic_bc);
397 }
398 {
399 Point center(0., 0., 0.);
400 Point axis(0., 0., 1.);
401 Real angle = 2*libMesh::pi/12.0;
402 AzimuthalPeriodicBoundary periodic_bc(center, axis, angle);
403 periodic_bc.myboundary = 401;
404 periodic_bc.pairedboundary = 402;
405 system.get_dof_map().add_periodic_boundary(periodic_bc);
406 }
407#endif // LIBMESH_ENABLE_PERIODIC
408
409 mesh.read("systems_of_equations_ex9.exo");
410
411 GetPot input(argc, argv);
412 const unsigned int n_refinements = input("n_refinements", 0);
413 // Skip adaptive runs on a non-adaptive libMesh build
414#ifndef LIBMESH_ENABLE_AMR
415 libmesh_example_requires(n_refinements==0, "--enable-amr");
416#else
417 MeshRefinement mesh_refinement(mesh);
418 mesh_refinement.uniformly_refine(n_refinements);
419#endif
420
421 // Print information about the mesh to the screen.
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
433
434#ifdef LIBMESH_ENABLE_DIRICHLET
435 DirichletBoundary clamped_bc({300,400}, {u_var,v_var,w_var}, zf);
436 system.get_dof_map().add_dirichlet_boundary(clamped_bc);
437#endif
438
439 // Initialize the data structures for the equation system.
440 equation_systems.init();
441
442 // Print information about the system to the screen.
443 equation_systems.print_info();
444
445 // Solve the system
446 system.solve();
447
448 // Plot the solution
449#ifdef LIBMESH_HAVE_EXODUS_API
450
451 ExodusII_IO (mesh).write_equation_systems("solution.exo",
452 equation_systems);
453
454#endif // #ifdef LIBMESH_HAVE_EXODUS_API
455#endif // #if LIBMESH_BOUNDARY_ID_BYTES > 1
456
457 // All done.
458 return 0;
459}
unsigned int dim
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.
void add_periodic_boundary(const PeriodicBoundaryBase &periodic_boundary)
Adds a copy of the specified periodic 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.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition libmesh.h:92
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
virtual void solve() override
Assembles & solves the linear system A*x=b.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false)=0
Interfaces for reading/writing a mesh to/from a file.
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
Implements (adaptive) mesh refinement algorithms for a MeshBase.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
void attach_assemble_object(Assembly &assemble)
Register a user object to use in assembling the system matrix and RHS.
Definition system.C:1976
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
const DofMap & get_dof_map() const
Definition system.h:2417
ConstFunction that simply returns 0.
MeshBase & mesh
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
int8_t boundary_id_type
Definition id_types.h:51
SolverPackage default_solver_package()
Definition libmesh.C:1064
const Real pi
.
Definition libmesh.h:292
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::DofMap::add_dirichlet_boundary(), libMesh::DofMap::add_periodic_boundary(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::System::attach_assemble_object(), libMesh::default_solver_package(), dim, libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::INVALID_SOLVER_PACKAGE, libMesh::LAGRANGE, main(), mesh, libMesh::PeriodicBoundaryBase::myboundary, libMesh::PeriodicBoundaryBase::pairedboundary, libMesh::pi, libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::MeshBase::read(), libMesh::Real, libMesh::LinearImplicitSystem::solve(), libMesh::MeshRefinement::uniformly_refine(), and libMesh::ExodusII_IO::write_equation_systems().