37#include "libmesh/libmesh_config.h"
38#include "libmesh/libmesh.h"
39#include "libmesh/mesh.h"
40#include "libmesh/mesh_generation.h"
41#include "libmesh/exodusII_io.h"
42#include "libmesh/gnuplot_io.h"
43#include "libmesh/linear_implicit_system.h"
44#include "libmesh/equation_systems.h"
45#include "libmesh/fe.h"
46#include "libmesh/quadrature_gauss.h"
47#include "libmesh/dof_map.h"
48#include "libmesh/sparse_matrix.h"
49#include "libmesh/numeric_vector.h"
50#include "libmesh/dense_matrix.h"
51#include "libmesh/dense_submatrix.h"
52#include "libmesh/dense_vector.h"
53#include "libmesh/dense_subvector.h"
54#include "libmesh/perf_log.h"
55#include "libmesh/elem.h"
56#include "libmesh/boundary_info.h"
57#include "libmesh/zero_function.h"
58#include "libmesh/dirichlet_boundaries.h"
59#include "libmesh/string_to_enum.h"
60#include "libmesh/getpot.h"
61#include "libmesh/mesh_refinement.h"
62#include "libmesh/solver_configuration.h"
63#include "libmesh/petsc_linear_solver.h"
64#include "libmesh/petsc_macro.h"
65#include "libmesh/periodic_boundaries.h"
66#include "libmesh/periodic_boundary.h"
67#include "libmesh/enum_solver_package.h"
68#include "libmesh/tensor_value.h"
69#include "libmesh/vector_value.h"
74#ifdef LIBMESH_ENABLE_PERIODIC
148 (cost + u_x*u_x*(1.0 - cost), u_x*u_y*(1.0 - cost) - u_z*sint, u_x*u_z*(1.0 - cost) + u_y*sint,
149 u_y*u_x*(1.0 - cost) + u_z*sint, cost + u_y*u_y*(1.0 - cost), u_y*u_z*(1.0 - cost) - u_x*sint,
150 u_z*u_x*(1.0 - cost) - u_y*sint, u_z*u_y*(1.0 - cost) + u_x*sint, cost + u_z*u_z*(1.0 - cost));
155 (
DenseMatrix<Real> (3, 3, {
_R(0,0),
_R(0,1),
_R(0,2),
_R(1,0),
_R(1,1),
_R(1,2),
_R(2,0),
_R(2,1),
_R(2,2)}));
178 return std::make_unique<AzimuthalPeriodicBoundary>(*
this, t);
211 return i == j ? 1. : 0.;
223 const Real poisson_ratio = 0.3;
224 const Real young_modulus = 1.;
227 const Real lambda_1 = (young_modulus*poisson_ratio)/((1.+poisson_ratio)*(1.-2.*poisson_ratio));
228 const Real lambda_2 = young_modulus/(2.*(1.+poisson_ratio));
251 fe->attach_quadrature_rule (&qrule);
255 fe_face->attach_quadrature_rule (&qface);
257 const std::vector<Real> & JxW = fe->get_JxW();
258 const std::vector<std::vector<Real>> & phi = fe->get_phi();
259 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
276 std::vector<dof_id_type> dof_indices;
277 std::vector<std::vector<dof_id_type>> dof_indices_var(3);
281 for (
const auto & elem :
mesh.active_local_element_ptr_range())
284 for (
unsigned int var=0; var<3; var++)
285 dof_map.
dof_indices (elem, dof_indices_var[var], var);
287 const unsigned int n_dofs = dof_indices.size();
288 const unsigned int n_var_dofs = dof_indices_var[0].size();
292 Ke.
resize (n_dofs, n_dofs);
293 for (
unsigned int var_i=0; var_i<3; var_i++)
294 for (
unsigned int var_j=0; var_j<3; var_j++)
295 Ke_var[var_i][var_j].reposition (var_i*n_var_dofs, var_j*n_var_dofs, n_var_dofs, n_var_dofs);
298 for (
unsigned int var=0; var<3; var++)
299 Fe_var[var].reposition (var*n_var_dofs, n_var_dofs);
301 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
304 for (
unsigned int dof_i=0; dof_i<n_var_dofs; dof_i++)
305 for (
unsigned int dof_j=0; dof_j<n_var_dofs; dof_j++)
306 for (
unsigned int i=0; i<3; i++)
307 for (
unsigned int j=0; j<3; j++)
308 for (
unsigned int k=0; k<3; k++)
309 for (
unsigned int l=0; l<3; l++)
310 Ke_var[i][k](dof_i,dof_j) +=
316 auto f_vec = (elem->subdomain_id() == 101 ?
320 for (
unsigned int dof_i=0; dof_i<n_var_dofs; dof_i++)
321 for (
unsigned int i=0; i<3; i++)
322 Fe_var[i](dof_i) += JxW[qp] * (f_vec(i) * phi[dof_i][qp]);
335int main (
int argc,
char ** argv)
342 "--enable-petsc, --enable-trilinos, or --enable-eigen");
344#ifndef LIBMESH_HAVE_EXODUS_API
346 libmesh_example_requires(
false,
"--enable-exodus");
350#ifndef LIBMESH_ENABLE_DIRICHLET
351 libmesh_example_requires(
false,
"--enable-dirichlet");
353#ifndef LIBMESH_ENABLE_PERIODIC
354 libmesh_example_requires(
false,
"--enable-periodic");
358 const unsigned int dim = 3;
361 libmesh_example_requires(
dim == LIBMESH_DIM,
"3D support");
364 libmesh_example_requires(
sizeof(
boundary_id_type) > 1,
"boundary_id_size > 1");
366#if LIBMESH_BOUNDARY_ID_BYTES > 1
378#ifdef LIBMESH_ENABLE_PERIODIC
390 Point center(0., 0., 0.);
391 Point axis(0., 0., 1.);
399 Point center(0., 0., 0.);
400 Point axis(0., 0., 1.);
409 mesh.
read(
"systems_of_equations_ex9.exo");
411 GetPot input(argc, argv);
412 const unsigned int n_refinements = input(
"n_refinements", 0);
414#ifndef LIBMESH_ENABLE_AMR
415 libmesh_example_requires(n_refinements==0,
"--enable-amr");
434#ifdef LIBMESH_ENABLE_DIRICHLET
440 equation_systems.
init();
449#ifdef LIBMESH_HAVE_EXODUS_API
virtual ~AzimuthalPeriodicBoundary()=default
Destructor.
AzimuthalPeriodicBoundary(Point center, Point axis, Real angle)
Constructor.
virtual std::unique_ptr< PeriodicBoundaryBase > clone(TransformationType t=FORWARD) const override
If we want the DofMap to be able to make copies of references and store them in the underlying map,...
void set_up_rotation_matrix()
Computes and stores the rotation matrix for this transformation, and then calls the base class API to...
AzimuthalPeriodicBoundary(const AzimuthalPeriodicBoundary &o, TransformationType t=FORWARD)
Copy constructor, with option for the copy to represent an inverse transformation.
virtual Point get_corresponding_pos(const Point &pt) const override
This function should be overridden by derived classes to define how one finds corresponding nodes on ...
LinearElasticity(EquationSystems &es_in)
void assemble()
Assemble the system matrix and right-hand side vector.
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.
Real kronecker_delta(unsigned int i, unsigned int j)
Kronecker delta function.
Defines a dense matrix for use in Finite Element-type computations.
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
Defines a dense submatrix for use in Finite Element-type computations.
Defines a dense subvector for use in finite element computations.
Defines a dense vector for use in Finite Element-type computations.
void resize(const unsigned int n)
Resize the vector.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
This class handles the numbering of degrees of freedom on a mesh.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
const FEType & variable_type(const unsigned int i) const
void add_periodic_boundary(const PeriodicBoundaryBase &periodic_boundary)
Adds a copy of the specified periodic boundary to the system.
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.
This is the EquationSystems class.
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
const MeshBase & get_mesh() const
virtual void init()
Initialize all the systems.
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.
const T_sys & get_system(std::string_view name) const
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
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.
NumericVector< Number > * rhs
The system matrix.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Order default_quadrature_order() const
const SparseMatrix< Number > & get_system_matrix() const
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
virtual void solve() override
Assembles & solves the linear system A*x=b.
This is the MeshBase class.
unsigned int mesh_dimension() const
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.
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
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].
The base class for defining periodic boundaries.
boundary_id_type myboundary
The boundary ID of this boundary and its counterpart.
void set_variable(unsigned int var)
void set_transformation_matrix(const DenseMatrix< Real > &matrix)
Set the transformation matrix.
boundary_id_type pairedboundary
A Point defines a location in LIBMESH_DIM dimensional Real space.
unsigned int n_points() const
This class implements specific orders of Gauss quadrature.
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.
Abstract base class to be used for system assembly.
void attach_assemble_object(Assembly &assemble)
Register a user object to use in assembling the system matrix and RHS.
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.
unsigned int variable_number(std::string_view var) const
const DofMap & get_dof_map() const
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
TypeVector< typename CompareTypes< T, T2 >::supertype > left_multiply(const TypeVector< T2 > &p) const
Left-multiply this tensor by a vector, i.e.
TypeVector< T > unit() const
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
ConstFunction that simply returns 0.
The libMesh namespace provides an interface to certain functionality in the library.
TensorValue< Real > RealTensorValue
Useful typedefs to allow transparent switching between Real and Complex data types.
SolverPackage default_solver_package()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real