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 97 set_up_rotation_matrix();
112 std::swap(myboundary, pairedboundary);
119 set_up_rotation_matrix();
145 Real cost = std::cos(_theta);
146 Real sint = std::sin(_theta);
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));
154 this->set_transformation_matrix
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)}));
168 return _R.left_multiply(pt - _center) + _center;
178 return std::make_unique<AzimuthalPeriodicBoundary>(*
this, t);
192 #endif // LIBMESH_ENABLE_PERIODIC 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]);
335 int 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.);
407 #endif // LIBMESH_ENABLE_PERIODIC 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();
443 equation_systems.print_info();
449 #ifdef LIBMESH_HAVE_EXODUS_API 454 #endif // #ifdef LIBMESH_HAVE_EXODUS_API 455 #endif // #if LIBMESH_BOUNDARY_ID_BYTES > 1 class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
This is the EquationSystems class.
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.
Real elasticity_tensor(unsigned int i, unsigned int j, unsigned int k, unsigned int l)
void add_periodic_boundary(const PeriodicBoundaryBase &periodic_boundary)
Adds a copy of the specified periodic boundary to the system.
ConstFunction that simply returns 0.
void assemble()
Assemble the system matrix and right-hand side vector.
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 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.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Real kronecker_delta(unsigned int i, unsigned int j)
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
AzimuthalPeriodicBoundary(Point center, Point axis, Real angle)
Constructor.
void resize(const unsigned int n)
Resize the vector.
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]...
const FEType & variable_type(const unsigned int c) const
LinearElasticity(EquationSystems &es_in)
boundary_id_type pairedboundary
NumericVector< Number > * rhs
The system matrix.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
Order default_quadrature_order() const
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
Abstract base class to be used for system assembly.
virtual void solve() override
Assembles & solves the linear system A*x=b.
const T_sys & get_system(std::string_view name) const
This is the MeshBase class.
unsigned int variable_number(std::string_view var) const
Defines a dense subvector for use in finite element computations.
SolverPackage default_solver_package()
This class handles the numbering of degrees of freedom on a mesh.
TensorValue< Real > RealTensorValue
Useful typedefs to allow transparent switching between Real and Complex data types.
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 ...
TypeVector< T > unit() const
boundary_id_type myboundary
The boundary ID of this boundary and its counterpart.
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.
Implements (adaptive) mesh refinement algorithms for a MeshBase.
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.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
Defines a dense submatrix for use in Finite Element-type computations.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
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.
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.
void attach_assemble_object(Assembly &assemble)
Register a user object to use in assembling the system matrix and RHS.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const MeshBase & get_mesh() const
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
AzimuthalPeriodicBoundary(const AzimuthalPeriodicBoundary &o, TransformationType t=FORWARD)
Copy constructor, with option for the copy to represent an inverse transformation.
This class implements specific orders of Gauss quadrature.
unsigned int mesh_dimension() const
int main(int argc, char **argv)
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
The base class for defining periodic boundaries.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Real kronecker_delta(unsigned int i, unsigned int j)
Kronecker delta function.
const DofMap & get_dof_map() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
const SparseMatrix< Number > & get_system_matrix() const
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
void set_up_rotation_matrix()
Computes and stores the rotation matrix for this transformation, and then calls the base class API to...
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.