Go to the documentation of this file.
44 #include "libmesh/libmesh.h"
45 #include "libmesh/mesh.h"
46 #include "libmesh/mesh_refinement.h"
47 #include "libmesh/exodusII_io.h"
48 #include "libmesh/equation_systems.h"
49 #include "libmesh/fe.h"
50 #include "libmesh/quadrature_gauss.h"
51 #include "libmesh/dof_map.h"
52 #include "libmesh/sparse_matrix.h"
53 #include "libmesh/numeric_vector.h"
54 #include "libmesh/dense_matrix.h"
55 #include "libmesh/dense_vector.h"
56 #include "libmesh/elem.h"
57 #include "libmesh/string_to_enum.h"
58 #include "libmesh/getpot.h"
61 #include "libmesh/nonlinear_solver.h"
62 #include "libmesh/nonlinear_implicit_system.h"
65 #ifdef LIBMESH_HAVE_PETSC
67 #include "libmesh/petsc_macro.h"
119 bool & changed_search_direction,
120 bool & changed_new_soln,
134 int main (
int argc,
char ** argv)
140 #if !defined(LIBMESH_HAVE_PETSC) && (!defined(LIBMESH_TRILINOS_HAVE_NOX) || !defined(LIBMESH_TRILINOS_HAVE_EPETRA))
141 libmesh_example_requires(
false,
"--enable-petsc or --enable-trilinos");
146 libMesh::err <<
"This example requires a NonlinearSolver, and therefore does not "
147 <<
"support --use-eigen on the command line."
152 #ifndef LIBMESH_ENABLE_AMR
153 libmesh_example_requires(
false,
"--enable-amr");
157 GetPot command_line (argc, argv);
164 libmesh_error_msg(
"Usage:\n" <<
"\t " << argv[0] <<
" -r 2");
173 for (
int i=1; i<argc; i++)
182 if (command_line.search(1,
"-r"))
183 nr = command_line.next(nr);
186 std::string order =
"FIRST";
187 if (command_line.search(2,
"-Order",
"-o"))
188 order = command_line.next(order);
191 std::string family =
"LAGRANGE";
192 if (command_line.search(2,
"-FEFamily",
"-f"))
193 family = command_line.next(family);
196 if ((family ==
"MONOMIAL") || (family ==
"XYZ"))
197 libmesh_error_msg(
"This example requires a C^0 (or higher) FE basis.");
199 if (command_line.search(1,
"-pre"))
201 #ifdef LIBMESH_HAVE_PETSC
203 # if PETSC_VERSION_LESS_THAN(3,7,0)
204 PetscOptionsSetValue(
"-snes_mf_operator", PETSC_NULL);
206 PetscOptionsSetValue(PETSC_NULL,
"-snes_mf_operator", PETSC_NULL);
209 libMesh::err <<
"Must be using PETSc to use jacobian based preconditioning" << std::endl;
213 #endif //LIBMESH_HAVE_PETSC
217 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
225 if (order !=
"FIRST")
245 equation_systems.
parameters.
set<
unsigned int> (
"nonlinear solver maximum iterations") = 50;
251 Utility::string_to_enum<Order> (order),
252 Utility::string_to_enum<FEFamily>(family));
262 equation_systems.
init();
269 equation_systems.
get_system(
"Laplace-Young").solve();
274 libMesh::out <<
"Laplace-Young system solved at nonlinear iteration "
276 <<
" , final nonlinear residual norm: "
280 #ifdef LIBMESH_HAVE_EXODUS_API
284 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
285 #endif // #ifndef LIBMESH_ENABLE_AMR
305 libmesh_assert_equal_to (
dim, 2);
319 FEType fe_type = dof_map.variable_type(0);
331 fe->attach_quadrature_rule (&qrule);
344 fe_face->attach_quadrature_rule (&qface);
350 const std::vector<Real> & JxW = fe->get_JxW();
353 const std::vector<std::vector<Real>> & phi = fe->get_phi();
357 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
365 std::vector<dof_id_type> dof_indices;
378 dof_map.dof_indices (elem, dof_indices);
391 const unsigned int n_dofs =
392 cast_int<unsigned int>(dof_indices.size());
403 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
408 for (
unsigned int j=0; j<n_dofs; j++)
410 u += phi[j][qp]*soln(dof_indices[j]);
411 grad_u += dphi[j][qp]*soln(dof_indices[j]);
416 for (
unsigned int i=0; i<n_dofs; i++)
418 K*(dphi[i][qp]*grad_u) +
430 for (
auto side : elem->side_index_range())
431 if (elem->neighbor_ptr(side) ==
nullptr)
435 const std::vector<std::vector<Real>> & phi_face = fe_face->get_phi();
439 const std::vector<Real> & JxW_face = fe_face->get_JxW();
442 fe_face->reinit(elem, side);
445 for (
unsigned int qp=0; qp<qface.
n_points(); qp++)
449 for (
unsigned int i=0; i<n_dofs; i++)
450 Re(i) -= JxW_face[qp]*_sigma*phi_face[i][qp];
454 dof_map.constrain_element_vector (Re, dof_indices);
489 FEType fe_type = dof_map.variable_type(0);
501 fe->attach_quadrature_rule (&qrule);
507 const std::vector<Real> & JxW = fe->get_JxW();
510 const std::vector<std::vector<Real>> & phi = fe->get_phi();
514 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
524 std::vector<dof_id_type> dof_indices;
535 dof_map.dof_indices (elem, dof_indices);
549 const unsigned int n_dofs =
550 cast_int<unsigned int>(dof_indices.size());
551 Ke.
resize (n_dofs, n_dofs);
559 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
563 for (
unsigned int i=0; i<n_dofs; i++)
564 grad_u += dphi[i][qp]*soln(dof_indices[i]);
567 sa = 1. + grad_u*grad_u,
571 for (
unsigned int i=0; i<n_dofs; i++)
572 for (
unsigned int j=0; j<n_dofs; j++)
574 K * (dphi[i][qp]*dphi[j][qp]) +
575 dK * (grad_u*dphi[j][qp]) * (grad_u*dphi[i][qp]) +
576 _kappa * phi[i][qp] * phi[j][qp]
580 dof_map.constrain_element_matrix (Ke, dof_indices);
596 bool & changed_new_soln,
611 new_soln.
add(-_gamma, search_direction);
612 changed_new_soln =
true;
615 changed_new_soln =
false;
virtual void zero()=0
Set all entries to zero.
const EquationSystems & get_equation_systems() const
virtual void add(const numeric_index_type i, const T value)=0
Adds value to each entry of the vector.
Real final_nonlinear_residual() const
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
virtual void residual(const NumericVector< Number > &X, NumericVector< Number > &R, NonlinearImplicitSystem &S)
Function which computes the residual.
virtual System & add_system(const std::string &system_type, const std::string &name)
Add the system of type system_type named name to the systems array.
const MeshBase & get_mesh() const
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.
This class implements specific orders of Gauss quadrature.
virtual void postcheck(const NumericVector< Number > &old_soln, NumericVector< Number > &search_direction, NumericVector< Number > &new_soln, bool &changed_search_direction, bool &changed_new_soln, NonlinearImplicitSystem &S)
Function which performs a postcheck on the solution.
virtual void all_second_order(const bool full_ordered=true)=0
Converts a (conforming, non-refined) mesh with linear elements into a mesh with second-order elements...
virtual void jacobian(const NumericVector< Number > &X, SparseMatrix< Number > &J, NonlinearImplicitSystem &S)
Function which computes the jacobian.
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
unsigned int n_points() const
The libMesh namespace provides an interface to certain functionality in the library.
const T_sys & get_system(const std::string &name) const
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
unsigned int mesh_dimension() const
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 non-linear solv...
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
A class which provides the residual and jacobian assembly functions for the Laplace-Young system of e...
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
Implements (adaptive) mesh refinement algorithms for a MeshBase.
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].
This is the MeshBase class.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
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.
virtual void init()
Initialize all the systems.
unsigned int n_nonlinear_iterations() const
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
int main(int argc, char **argv)
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
This is the EquationSystems class.
T & set(const std::string &)
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 ...
std::unique_ptr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system.
void resize(const unsigned int n)
Resize the vector.
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.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
This class handles the numbering of degrees of freedom on a mesh.
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
Abstract base class to be used to calculate the Jacobian of a nonlinear system.
bool on_command_line(std::string arg)
const DofMap & get_dof_map() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.
Abstract base class to be used to calculate the residual of a nonlinear system.
Abstract base class to be used for applying user modifications to the solution vector and/or Newton u...
Parameters parameters
Data structure holding arbitrary parameters.