42 #include "libmesh/libmesh.h" 43 #include "libmesh/replicated_mesh.h" 44 #include "libmesh/mesh_refinement.h" 45 #include "libmesh/gmv_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/sparse_matrix.h" 51 #include "libmesh/numeric_vector.h" 52 #include "libmesh/dense_matrix.h" 53 #include "libmesh/dense_vector.h" 54 #include "libmesh/getpot.h" 55 #include "libmesh/enum_solver_package.h" 56 #include "libmesh/enum_xdr_mode.h" 57 #include "libmesh/enum_norm_type.h" 61 #include "libmesh/transient_system.h" 62 #include "libmesh/linear_implicit_system.h" 63 #include "libmesh/vector_value.h" 67 #include "libmesh/error_vector.h" 68 #include "libmesh/kelly_error_estimator.h" 71 #include "libmesh/elem.h" 83 #ifdef LIBMESH_ENABLE_AMR 85 const std::string & system_name);
94 const std::string & system_name);
119 int main (
int argc,
char ** argv)
126 "--enable-petsc, --enable-trilinos, or --enable-eigen");
128 #ifndef LIBMESH_ENABLE_AMR 129 libmesh_example_requires(
false,
"--enable-amr");
142 <<
"\t " << argv[0] <<
" -init_timestep 0 -n_timesteps 25 [-n_refinements 5]\n" 144 <<
"\t " << argv[0] <<
" -read_solution -init_timestep 26 -n_timesteps 25\n" 149 for (
int i=1; i<argc; i++)
167 const unsigned int init_timestep =
175 libmesh_error_msg(
"ERROR: Initial timestep not specified!");
179 const unsigned int n_timesteps =
184 libmesh_error_msg(
"ERROR: Number of timesteps not specified");
187 const unsigned int max_h_level =
191 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
209 const unsigned int n_refinements = 5;
227 system.add_variable (
"u",
FIRST);
232 system.attach_init_function (
init_cd);
235 equation_systems.init ();
247 equation_systems.read(
"saved_solution.xda",
READ);
265 libMesh::out <<
"Initial H1 norm = " << H1norm << std::endl << std::endl;
269 equation_systems.print_info();
271 equation_systems.parameters.set<
unsigned int>(
"linear solver maximum iterations") = 250;
272 equation_systems.parameters.set<
Real>(
"linear solver tolerance") =
TOLERANCE;
290 equation_systems.parameters.set<
Real>(
"diffusivity") = 0.01;
304 const Real dt = 0.025;
305 system.time = init_timestep*dt;
309 for (
unsigned int t_step=init_timestep; t_step<(init_timestep+n_timesteps); t_step++)
315 equation_systems.parameters.set<
Real> (
"time") = system.time;
316 equation_systems.parameters.set<
Real> (
"dt") = dt;
323 std::ostringstream
out;
331 << std::setprecision(3)
345 *system.old_local_solution = *system.current_local_solution;
348 const unsigned int max_r_steps = 2;
351 for (
unsigned int r_step=0; r_step<max_r_steps; r_step++)
362 if (r_step+1 != max_r_steps)
411 equation_systems.reinit ();
416 const unsigned int output_freq =
420 if ((t_step+1)%output_freq == 0)
422 std::ostringstream file_name;
424 file_name <<
"out.gmv." 440 libMesh::out <<
"Final H1 norm = " << H1norm << std::endl << std::endl;
443 equation_systems.write(
"saved_solution.xda",
WRITE);
447 #endif // #ifndef LIBMESH_ENABLE_AMR 457 const std::string & libmesh_dbg_var(system_name))
461 libmesh_assert_equal_to (system_name,
"Convection-Diffusion");
479 #ifdef LIBMESH_ENABLE_AMR 481 const std::string & libmesh_dbg_var(system_name))
485 libmesh_assert_equal_to (system_name,
"Convection-Diffusion");
499 FEType fe_type = system.variable_type(0);
510 QGauss qrule (
dim, fe_type.default_quadrature_order());
511 QGauss qface (
dim-1, fe_type.default_quadrature_order());
514 fe->attach_quadrature_rule (&qrule);
515 fe_face->attach_quadrature_rule (&qface);
520 const std::vector<Real> & JxW = fe->get_JxW();
521 const std::vector<Real> & JxW_face = fe_face->get_JxW();
524 const std::vector<std::vector<Real>> & phi = fe->get_phi();
525 const std::vector<std::vector<Real>> & psi = fe_face->get_phi();
529 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
532 const std::vector<Point> & qface_points = fe_face->get_xyz();
538 const DofMap & dof_map = system.get_dof_map();
550 std::vector<dof_id_type> dof_indices;
557 const Real diffusivity =
570 for (
const auto & elem :
mesh.active_local_element_ptr_range())
584 const unsigned int n_dofs =
585 cast_int<unsigned int>(dof_indices.size());
586 libmesh_assert_equal_to (n_dofs, phi.size());
594 Ke.
resize (n_dofs, n_dofs);
604 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
611 for (
unsigned int l=0; l != n_dofs; l++)
613 u_old += phi[l][qp]*system.
old_solution (dof_indices[l]);
622 for (
unsigned int i=0; i != n_dofs; i++)
632 (grad_u_old*velocity)*phi[i][qp] +
635 diffusivity*(grad_u_old*dphi[i][qp]))
638 for (
unsigned int j=0; j != n_dofs; j++)
643 phi[i][qp]*phi[j][qp] +
646 (velocity*dphi[j][qp])*phi[i][qp] +
648 diffusivity*(dphi[i][qp]*dphi[j][qp]))
665 const Real penalty = 1.e10;
670 for (
auto s : elem->side_index_range())
671 if (elem->neighbor_ptr(s) ==
nullptr)
673 fe_face->reinit(elem, s);
675 libmesh_assert_equal_to (n_dofs, psi.size());
677 for (
unsigned int qp=0; qp<qface.n_points(); qp++)
684 for (
unsigned int i=0; i != n_dofs; i++)
685 Fe(i) += penalty*JxW_face[qp]*
value*psi[i][qp];
688 for (
unsigned int i=0; i != n_dofs; i++)
689 for (
unsigned int j=0; j != n_dofs; j++)
690 Ke(i,j) += penalty*JxW_face[qp]*psi[i][qp]*psi[j][qp];
710 matrix.add_matrix (Ke, dof_indices);
711 system.rhs->add_vector (Fe, dof_indices);
716 #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.
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.
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.
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
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.
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 ...
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...
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.
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.
This class implements writing meshes in the GMV format.
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.
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...
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.