42 #include "libmesh/libmesh.h" 43 #include "libmesh/replicated_mesh.h" 44 #include "libmesh/mesh_refinement.h" 45 #include "libmesh/exodusII_io.h" 46 #include "libmesh/equation_systems.h" 47 #include "libmesh/fe.h" 48 #include "libmesh/quadrature_gauss.h" 49 #include "libmesh/dof_map.h" 50 #include "libmesh/static_condensation.h" 51 #include "libmesh/sparse_matrix.h" 52 #include "libmesh/numeric_vector.h" 53 #include "libmesh/dense_matrix.h" 54 #include "libmesh/dense_vector.h" 55 #include "libmesh/getpot.h" 56 #include "libmesh/enum_solver_package.h" 57 #include "libmesh/enum_xdr_mode.h" 58 #include "libmesh/enum_norm_type.h" 62 #include "libmesh/transient_system.h" 63 #include "libmesh/linear_implicit_system.h" 64 #include "libmesh/vector_value.h" 68 #include "libmesh/error_vector.h" 69 #include "libmesh/kelly_error_estimator.h" 72 #include "libmesh/elem.h" 84 #ifdef LIBMESH_ENABLE_AMR 86 const std::string & system_name);
95 const std::string & system_name);
120 int main (
int argc,
char ** argv)
127 "--enable-petsc, --enable-trilinos, or --enable-eigen");
129 #ifndef LIBMESH_ENABLE_AMR 130 libmesh_example_requires(
false,
"--enable-amr");
143 <<
"\t " << argv[0] <<
" -init_timestep 0 -n_timesteps 25 [-n_refinements 5]\n" 145 <<
"\t " << argv[0] <<
" -read_solution -init_timestep 26 -n_timesteps 25\n" 150 for (
int i=1; i<argc; i++)
168 const unsigned int init_timestep =
176 libmesh_error_msg(
"ERROR: Initial timestep not specified!");
180 const unsigned int n_timesteps =
185 libmesh_error_msg(
"ERROR: Number of timesteps not specified");
188 const unsigned int max_h_level =
192 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
224 const unsigned int n_refinements =
249 system.attach_init_function (
init_cd);
252 equation_systems.init ();
264 equation_systems.read(
"saved_solution.xda",
READ);
282 libMesh::out <<
"Initial H1 norm = " << H1norm << std::endl << std::endl;
286 equation_systems.print_info();
288 equation_systems.parameters.set<
unsigned int>(
"linear solver maximum iterations") = 250;
289 equation_systems.parameters.set<
Real>(
"linear solver tolerance") =
TOLERANCE;
292 #ifdef LIBMESH_HAVE_EXODUS_API 299 #endif // LIBMESH_HAVE_EXODUS_API 310 equation_systems.parameters.set<
Real>(
"diffusivity") = 0.01;
324 const Real dt = 0.025;
325 system.time = init_timestep*dt;
328 const Real refine_fraction =
331 const Real coarsen_fraction =
336 for (
unsigned int t_step=init_timestep; t_step<(init_timestep+n_timesteps); t_step++)
342 equation_systems.parameters.set<
Real> (
"time") = system.time;
343 equation_systems.parameters.set<
Real> (
"dt") = dt;
350 std::ostringstream
out;
358 << std::setprecision(3)
372 *system.old_local_solution = *system.current_local_solution;
375 const unsigned int max_r_steps = 2;
378 for (
unsigned int r_step=0; r_step<max_r_steps; r_step++)
389 if (r_step+1 != max_r_steps)
438 equation_systems.reinit ();
443 const unsigned int output_freq =
448 if ((t_step+1)%output_freq == 0)
450 equation_systems.print_info();
452 std::ostringstream file_name;
454 file_name <<
"out.e." 461 #ifdef LIBMESH_HAVE_EXODUS_API 464 #endif // LIBMESH_HAVE_EXODUS_API 473 libMesh::out <<
"Final H1 norm = " << H1norm << std::endl << std::endl;
476 equation_systems.write(
"saved_solution.xda",
WRITE);
477 #ifdef LIBMESH_HAVE_EXODUS_API 480 #endif // LIBMESH_HAVE_EXODUS_API 482 #endif // #ifndef LIBMESH_ENABLE_AMR 492 const std::string & libmesh_dbg_var(system_name))
496 libmesh_assert_equal_to (system_name,
"Convection-Diffusion");
514 #ifdef LIBMESH_ENABLE_AMR 516 const std::string & libmesh_dbg_var(system_name))
520 libmesh_assert_equal_to (system_name,
"Convection-Diffusion");
534 if (system.has_static_condensation())
535 sc = &system.get_static_condensation();
539 FEType fe_type = system.variable_type(0);
554 fe->attach_quadrature_rule (&qrule);
555 fe_face->attach_quadrature_rule (&qface);
560 const std::vector<Real> & JxW = fe->get_JxW();
561 const std::vector<Real> & JxW_face = fe_face->get_JxW();
564 const std::vector<std::vector<Real>> & phi = fe->get_phi();
565 const std::vector<std::vector<Real>> & psi = fe_face->get_phi();
569 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
572 const std::vector<Point> & qface_points = fe_face->get_xyz();
578 const DofMap & dof_map = system.get_dof_map();
590 std::vector<dof_id_type> dof_indices;
597 const Real diffusivity =
610 for (
const auto & elem :
mesh.active_local_element_ptr_range())
624 const unsigned int n_dofs =
625 cast_int<unsigned int>(dof_indices.size());
626 libmesh_assert_equal_to (n_dofs, phi.size());
634 Ke.
resize (n_dofs, n_dofs);
644 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
651 for (
unsigned int l=0; l != n_dofs; l++)
653 u_old += phi[l][qp]*system.
old_solution (dof_indices[l]);
662 for (
unsigned int i=0; i != n_dofs; i++)
672 (grad_u_old*velocity)*phi[i][qp] +
675 diffusivity*(grad_u_old*dphi[i][qp]))
678 for (
unsigned int j=0; j != n_dofs; j++)
683 phi[i][qp]*phi[j][qp] +
686 (velocity*dphi[j][qp])*phi[i][qp] +
688 diffusivity*(dphi[i][qp]*dphi[j][qp]))
705 const Real penalty = 1.e10;
710 for (
auto s : elem->side_index_range())
711 if (elem->neighbor_ptr(s) ==
nullptr)
713 fe_face->reinit(elem, s);
715 libmesh_assert_equal_to (n_dofs, psi.size());
717 for (
unsigned int qp=0; qp<qface.n_points(); qp++)
724 for (
unsigned int i=0; i != n_dofs; i++)
725 Fe(i) += penalty*JxW_face[qp]*
value*psi[i][qp];
728 for (
unsigned int i=0; i != n_dofs; i++)
729 for (
unsigned int j=0; j != n_dofs; j++)
730 Ke(i,j) += penalty*JxW_face[qp]*psi[i][qp]*psi[j][qp];
747 sc->set_current_elem(*elem);
753 matrix.add_matrix (Ke, dof_indices);
754 system.rhs->add_vector (Fe, dof_indices);
759 #endif // #ifdef LIBMESH_ENABLE_AMR class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line...
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
void add_scaled(const TypeVector< T2 > &, const T &)
Add a scaled value to this vector without creating a temporary.
Order
defines an enum for polynomial orders.
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
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.
This class provides the ability to map between arbitrary, user-defined strings and several data types...
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
static constexpr Real TOLERANCE
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
void resize(const unsigned int n)
Resize the vector.
Real & coarsen_fraction()
The coarsen_fraction sets either a desired target or a desired maximum number of elements to flag for...
Manages storage and variables for transient systems.
Order default_quadrature_order() const
Real & refine_fraction()
The refine_fraction sets either a desired target or a desired maximum number of elements to flag for ...
This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a ...
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
const T_sys & get_system(std::string_view name) const
unsigned int & max_h_level()
The max_h_level is the greatest refinement level an element should reach.
Number exact_value(const Point &p, const Parameters ¶meters, const std::string &, const std::string &)
This is the MeshBase class.
SolverPackage default_solver_package()
This class handles the numbering of degrees of freedom on a mesh.
const T & get(std::string_view) const
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void assemble_cd(EquationSystems &es, const std::string &system_name)
Real exact_solution(const Real x, const Real y, const Real t)
This is the exact solution that we are trying to obtain.
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.
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.
Number old_solution(const dof_id_type global_dof_number) const
virtual void write(const std::string &name) const =0
This class implements the Kelly error indicator which is based on the flux jumps between elements...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
int main(int argc, char **argv)
void init_cd(EquationSystems &es, const std::string &system_name)
T & set(const std::string &)
bool refine_and_coarsen_elements()
Refines and coarsens user-requested elements.
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().
bool use_unweighted_quadrature_rules
This boolean flag allows you to use "unweighted" quadrature rules (sized to exactly integrate unweigh...
void all_second_order(const bool full_ordered=true)
Calls the range-based version of this function with a range consisting of all elements in the mesh...
This class implements specific orders of Gauss quadrature.
unsigned int mesh_dimension() const
Parameters parameters
Data structure holding arbitrary parameters.
void flag_elements_by_error_fraction(const ErrorVector &error_per_cell, const Real refine_fraction=0.3, const Real coarsen_fraction=0.0, const unsigned int max_level=libMesh::invalid_uint)
Flags elements for coarsening and refinement based on the computed error passed in error_per_cell...
virtual void estimate_error(const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector=nullptr, bool estimate_parent_error=false) override
This function uses the derived class's jump error estimate formula to estimate the error on each cell...
bool on_command_line(std::string arg)
A Point defines a location in LIBMESH_DIM dimensional Real space.
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.