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);
120int 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");
138#if !defined(LIBMESH_HAVE_EIGEN) || !defined(LIBMESH_HAVE_PETSC)
139 libmesh_example_requires
141 "--enable-eigen and --enable-petsc");
150 <<
"\t " << argv[0] <<
" -init_timestep 0 -n_timesteps 25 [-n_refinements 5]\n"
152 <<
"\t " << argv[0] <<
" -read_solution -init_timestep 26 -n_timesteps 25\n"
157 for (
int i=1; i<argc; i++)
175 const unsigned int init_timestep =
183 libmesh_error_msg(
"ERROR: Initial timestep not specified!");
187 const unsigned int n_timesteps =
192 libmesh_error_msg(
"ERROR: Number of timesteps not specified");
195 const unsigned int max_h_level =
199 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
231 const unsigned int n_refinements =
256 system.attach_init_function (
init_cd);
259 equation_systems.
init ();
271 equation_systems.
read(
"saved_solution.xda",
READ);
289 libMesh::out <<
"Initial H1 norm = " << H1norm << std::endl << std::endl;
295 equation_systems.
parameters.
set<
unsigned int>(
"linear solver maximum iterations") = 250;
299#ifdef LIBMESH_HAVE_EXODUS_API
331 const Real dt = 0.025;
332 system.time = init_timestep*dt;
335 const Real refine_fraction =
338 const Real coarsen_fraction =
343 for (
unsigned int t_step=init_timestep; t_step<(init_timestep+n_timesteps); t_step++)
357 std::ostringstream
out;
365 << std::setprecision(3)
379 *system.old_local_solution = *system.current_local_solution;
382 const unsigned int max_r_steps = 2;
385 for (
unsigned int r_step=0; r_step<max_r_steps; r_step++)
396 if (r_step+1 != max_r_steps)
445 equation_systems.
reinit ();
450 const unsigned int output_freq =
455 if ((t_step+1)%output_freq == 0)
459 std::ostringstream file_name;
461 file_name <<
"out.e."
468#ifdef LIBMESH_HAVE_EXODUS_API
480 libMesh::out <<
"Final H1 norm = " << H1norm << std::endl << std::endl;
483 equation_systems.
write(
"saved_solution.xda",
WRITE);
484#ifdef LIBMESH_HAVE_EXODUS_API
499 const std::string & libmesh_dbg_var(system_name))
503 libmesh_assert_equal_to (system_name,
"Convection-Diffusion");
521#ifdef LIBMESH_ENABLE_AMR
523 const std::string & libmesh_dbg_var(system_name))
527 libmesh_assert_equal_to (system_name,
"Convection-Diffusion");
541 if (system.has_static_condensation())
542 sc = &system.get_static_condensation();
546 FEType fe_type = system.variable_type(0);
561 fe->attach_quadrature_rule (&qrule);
562 fe_face->attach_quadrature_rule (&qface);
567 const std::vector<Real> & JxW = fe->get_JxW();
568 const std::vector<Real> & JxW_face = fe_face->get_JxW();
571 const std::vector<std::vector<Real>> & phi = fe->get_phi();
572 const std::vector<std::vector<Real>> & psi = fe_face->get_phi();
576 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
579 const std::vector<Point> & qface_points = fe_face->get_xyz();
585 const DofMap & dof_map = system.get_dof_map();
597 std::vector<dof_id_type> dof_indices;
604 const Real diffusivity =
617 for (
const auto & elem :
mesh.active_local_element_ptr_range())
631 const unsigned int n_dofs =
632 cast_int<unsigned int>(dof_indices.size());
633 libmesh_assert_equal_to (n_dofs, phi.size());
641 Ke.
resize (n_dofs, n_dofs);
651 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
658 for (
unsigned int l=0; l != n_dofs; l++)
660 u_old += phi[l][qp]*system.
old_solution (dof_indices[l]);
669 for (
unsigned int i=0; i != n_dofs; i++)
679 (grad_u_old*velocity)*phi[i][qp] +
682 diffusivity*(grad_u_old*dphi[i][qp]))
685 for (
unsigned int j=0; j != n_dofs; j++)
690 phi[i][qp]*phi[j][qp] +
693 (velocity*dphi[j][qp])*phi[i][qp] +
695 diffusivity*(dphi[i][qp]*dphi[j][qp]))
712 const Real penalty = 1.e10;
717 for (
auto s : elem->side_index_range())
718 if (elem->neighbor_ptr(s) ==
nullptr)
720 fe_face->reinit(elem, s);
722 libmesh_assert_equal_to (n_dofs, psi.size());
724 for (
unsigned int qp=0; qp<qface.
n_points(); qp++)
731 for (
unsigned int i=0; i != n_dofs; i++)
732 Fe(i) += penalty*JxW_face[qp]*
value*psi[i][qp];
735 for (
unsigned int i=0; i != n_dofs; i++)
736 for (
unsigned int j=0; j != n_dofs; j++)
737 Ke(i,j) += penalty*JxW_face[qp]*psi[i][qp]*psi[j][qp];
754 sc->set_current_elem(*elem);
760 matrix.add_matrix (Ke, dof_indices);
761 system.rhs->add_vector (Fe, dof_indices);
Number exact_value(const Point &p, const Parameters ¶meters, const std::string &, const std::string &)
void assemble_cd(EquationSystems &es, const std::string &system_name)
void init_cd(EquationSystems &es, const std::string &system_name)
Number(* exact_solution)(const Point &p, const Parameters &, const std::string &, const std::string &)
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 vector for use in Finite Element-type computations.
void resize(const unsigned int n)
Resize the vector.
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 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.
virtual void reinit()
Handle any mesh changes and reinitialize all the systems on the updated mesh.
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
void write(std::string_view name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
Write the systems to disk using the XDR data format.
void read(std::string_view name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
Read & initialize the systems from disk using the XDR data format.
const MeshBase & get_mesh() const
Parameters parameters
Data structure holding arbitrary parameters.
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 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...
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.
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
bool use_unweighted_quadrature_rules
This boolean flag allows you to use "unweighted" quadrature rules (sized to exactly integrate unweigh...
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...
This class implements the Kelly error indicator which is based on the flux jumps between elements.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
This is the MeshBase class.
unsigned int mesh_dimension() const
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.
virtual void write(const std::string &name) const =0
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.
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.
unsigned int & max_h_level()
The max_h_level is the greatest refinement level an element should reach.
bool refine_and_coarsen_elements()
Refines and coarsens user-requested elements.
Real & refine_fraction()
The refine_fraction sets either a desired target or a desired maximum number of elements to flag for ...
Real & coarsen_fraction()
The coarsen_fraction sets either a desired target or a desired maximum number of elements to flag for...
This class provides the ability to map between arbitrary, user-defined strings and several data types...
T & set(const std::string &)
const T & get(std::string_view) const
A Point defines a location in LIBMESH_DIM dimensional Real space.
unsigned int n_points() const
This class implements specific orders of Gauss quadrature.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a ...
Manages storage and variables for transient systems.
Number old_solution(const dof_id_type global_dof_number) const
LIBMESH_DEVICE_INLINE void add_scaled(const TypeVector< T2 > &, const T &)
Add a scaled value to this vector without creating a temporary.
The libMesh namespace provides an interface to certain functionality in the library.
SolverPackage default_solver_package()
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
static constexpr Real TOLERANCE
bool on_command_line(std::string arg)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real