24 #include "libmesh/hp_coarsentest.h" 25 #include "libmesh/dense_matrix.h" 26 #include "libmesh/dense_vector.h" 27 #include "libmesh/dof_map.h" 28 #include "libmesh/fe_base.h" 29 #include "libmesh/fe_interface.h" 30 #include "libmesh/libmesh_logging.h" 31 #include "libmesh/elem.h" 32 #include "libmesh/error_vector.h" 33 #include "libmesh/mesh_base.h" 34 #include "libmesh/mesh_refinement.h" 35 #include "libmesh/quadrature.h" 36 #include "libmesh/system.h" 37 #include "libmesh/tensor_value.h" 39 #ifdef LIBMESH_ENABLE_AMR 69 const unsigned int n_dofs =
77 const unsigned int n_coarse_dofs =
82 Ke.
resize(n_coarse_dofs, n_coarse_dofs);
99 for (
unsigned int i=0; i != n_dofs; i++)
102 val += (*phi)[i][qp] *
113 Fe(i) += (*JxW)[qp] *
114 (*phi_coarse)[i][qp]*val;
116 Fe(i) += (*JxW)[qp] *
117 (grad*(*dphi_coarse)[i][qp]);
119 Fe(i) += (*JxW)[qp] *
124 Ke(i,j) += (*JxW)[qp] *
125 (*phi_coarse)[i][qp]*(*phi_coarse)[j][qp];
127 Ke(i,j) += (*JxW)[qp] *
128 (*dphi_coarse)[i][qp]*(*dphi_coarse)[j][qp];
130 Ke(i,j) += (*JxW)[qp] *
131 ((*d2phi_coarse)[i][qp].contract((*
d2phi_coarse)[j][qp]));
139 LOG_SCOPE(
"select_refinement()",
"HPCoarsenTest");
145 const unsigned int dim =
mesh.mesh_dimension();
154 const unsigned int sys_num = system.
number();
160 "ERROR: component_scale is the wrong size:\n" 161 <<
" component_scale.size()=" 174 std::vector<ErrorVectorReal> h_error_per_cell(
mesh.max_elem_id(), 0.);
175 std::vector<ErrorVectorReal> p_error_per_cell(
mesh.max_elem_id(), 0.);
178 for (
unsigned int var=0; var<
n_vars; var++)
194 unsigned int cached_coarse_p_level = 0;
205 fe->attach_quadrature_rule (
qrule.get());
209 JxW = &(
fe->get_JxW());
213 phi = &(
fe->get_phi());
226 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 230 libmesh_error_msg(
"Minimization of H2 error without second derivatives is not possible.");
236 for (
auto & elem :
mesh.active_local_element_ptr_range())
247 if (elem->parent() &&
249 cached_coarse_p_level != elem->
p_level()))
254 cached_coarse_p_level = elem->
p_level();
273 const unsigned int n_qp =
qrule->n_points();
276 const unsigned int n_dofs =
280 const unsigned int n_nodes = elem->n_nodes();
290 if (elem->p_level() == 0)
292 unsigned int n_vertices = 0;
293 for (
unsigned int n = 0; n !=
n_nodes; ++n)
294 if (elem->is_vertex(n))
297 const Node & node = elem->node_ref(n);
301 average_val /= n_vertices;
305 unsigned int old_elem_level = elem->p_level();
306 elem->hack_p_level(old_elem_level - 1);
310 const unsigned int n_coarse_dofs =
313 elem->hack_p_level(old_elem_level);
315 Ke.
resize(n_coarse_dofs, n_coarse_dofs);
328 for (
unsigned int i=0; i != n_dofs; i++)
331 val += (*phi)[i][qp] *
342 Fe(i) += (*JxW)[qp] *
343 (*phi_coarse)[i][qp]*val;
345 Fe(i) += (*JxW)[qp] *
346 grad * (*dphi_coarse)[i][qp];
348 Fe(i) += (*JxW)[qp] *
353 Ke(i,j) += (*JxW)[qp] *
354 (*phi_coarse)[i][qp]*(*phi_coarse)[j][qp];
356 Ke(i,j) += (*JxW)[qp] *
357 (*dphi_coarse)[i][qp]*(*dphi_coarse)[j][qp];
359 Ke(i,j) += (*JxW)[qp] *
360 ((*d2phi_coarse)[i][qp].contract((*
d2phi_coarse)[j][qp]));
370 for (
unsigned int qp=0; qp<n_qp; qp++)
375 for (
unsigned int i=0; i<n_dofs; i++)
378 value_error += (*phi)[i][qp] *
385 if (elem->p_level() == 0)
387 value_error -= average_val;
393 value_error -= (*phi_coarse)[i][qp] *
Up(i);
407 (*JxW)[qp] * grad_error.
norm_sq());
411 (*JxW)[qp] * hessian_error.
norm_sq());
420 h_error_per_cell[e_id] =
421 std::numeric_limits<ErrorVectorReal>::max() / 2;
436 unsigned int n_coarse_dofs =
440 for (
unsigned int qp=0; qp<n_qp; qp++)
447 for (
unsigned int i=0; i != n_dofs; ++i)
450 value_error += (*phi)[i][qp] *
458 for (
unsigned int i=0; i != n_coarse_dofs; ++i)
460 value_error -= (*phi_coarse)[i][qp] *
Uc(i);
473 (*JxW)[qp] * grad_error.
norm_sq());
477 (*JxW)[qp] * hessian_error.
norm_sq());
489 for (
auto & elem :
mesh.active_local_element_ptr_range())
498 unsigned int dofs_per_elem = 0, dofs_per_p_elem = 0;
501 for (
unsigned int var=0; var<
n_vars; var++)
518 const unsigned int new_h_dofs = dofs_per_elem *
519 (elem->n_children() - 1);
521 const unsigned int new_p_dofs = dofs_per_p_elem -
533 std::sqrt(p_error_per_cell[e_id]) *
p_weight / new_p_dofs;
535 std::sqrt(h_error_per_cell[e_id]) /
536 static_cast<Real>(new_h_dofs);
537 if (p_value > h_value)
554 #endif // #ifdef LIBMESH_ENABLE_AMR class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
const std::vector< std::vector< Real > > * phi
The shape functions and their derivatives.
const Elem * parent() const
void add_scaled(const TypeVector< T2 > &, const T &)
Add a scaled value to this vector without creating a temporary.
std::vector< float > component_scale
This vector can be used to "scale" certain variables in a system.
void add_projection(const System &, const Elem *, unsigned int var)
The helper function which adds individual fine element data to the coarse element projection...
A Node is like a Point, but with more information.
static unsigned int n_dofs(const unsigned int dim, const FEType &fe_t, const ElemType t)
virtual void zero() override final
Set every element in the vector to 0.
void subtract_scaled(const TypeVector< T2 > &, const T &)
Subtract a scaled value from this vector without creating a temporary.
virtual void select_refinement(System &system) override
This pure virtual function must be redefined in derived classes to take a mesh flagged for h refineme...
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
virtual void zero() override final
Sets all elements of the matrix to 0 and resets any decomposition flag which may have been previously...
static Point inverse_map(const unsigned int dim, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true, const bool extra_checks=true)
std::unique_ptr< FEBase > fe_coarse
const std::vector< std::vector< Real > > * phi_coarse
int _extra_order
Extra order to use for quadrature rule.
void resize(const unsigned int n)
Resize the vector.
const FEType & variable_type(const unsigned int c) const
This is the base class from which all geometric element types are derived.
auto norm_sq() const -> decltype(std::norm(T()))
const std::vector< std::vector< RealGradient > > * dphi_coarse
unsigned int p_level() const
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The libMesh namespace provides an interface to certain functionality in the library.
const std::vector< Point > * xyz_values
Quadrature locations.
const MeshBase & get_mesh() const
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
DenseVector< Number > Uc
Coefficients for projected coarse and projected p-derefined solutions.
This is the MeshBase class.
SimpleRange< ChildRefIter > child_ref_range()
Returns a range with all children of a parent element, usable in range-based for loops.
Number current_solution(const dof_id_type global_dof_number) const
const std::vector< Real > * JxW
Mapping jacobians.
This class handles the numbering of degrees of freedom on a mesh.
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
const dof_id_type n_nodes
unsigned int number() const
auto norm_sq() const -> decltype(std::norm(T()))
void subtract_scaled(const TypeTensor< T2 > &, const T &)
Subtract a scaled value from this tensor without creating a temporary.
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Manages consistently variables, degrees of freedom, and coefficient vectors.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
bool make_flags_parallel_consistent()
Copy refinement flags on ghost elements from their local processors.
void add_scaled(const TypeTensor< T2 > &, const T &)
Add a scaled tensor to this tensor without creating a temporary.
CompareTypes< T, T2 >::supertype contract(const TypeTensor< T2 > &) const
Multiply 2 tensors together to return a scalar, i.e.
std::unique_ptr< FEBase > fe
The finite element objects for fine and coarse elements.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
FEContinuity
defines an enum for finite element types to libmesh_assert a certain level (or type? Hcurl?) of continuity.
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
unsigned int mesh_dimension() const
virtual unsigned int size() const override final
const std::vector< std::vector< RealTensor > > * d2phi_coarse
const std::vector< std::vector< RealTensor > > * d2phi
void cholesky_solve(const DenseVector< T2 > &b, DenseVector< T2 > &x)
For symmetric positive definite (SPD) matrices.
const std::vector< std::vector< RealGradient > > * dphi
unsigned int n_vars() const
std::vector< dof_id_type > dof_indices
Global DOF indices for fine elements.
Real p_weight
Because the coarsening test seems to always choose p refinement, we're providing an option to make h ...
std::vector< Point > coarse_qpoints
void hack_p_level(const unsigned int p)
Sets the value of the p-refinement level for the element without altering the p-level of its ancestor...
const DofMap & get_dof_map() const
Elem * coarse
The coarse element on which a solution projection is cached.
std::unique_ptr< QBase > qrule
The quadrature rule for the fine element.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
DenseMatrix< Number > Ke
Linear system for projections.