Go to the documentation of this file.
   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         libmesh_error_msg(
"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);
 
  401               p_error_per_cell[e_id] += static_cast<ErrorVectorReal>
 
  405                 p_error_per_cell[e_id] += static_cast<ErrorVectorReal>
 
  409                 p_error_per_cell[e_id] += static_cast<ErrorVectorReal>
 
  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);
 
  467                   h_error_per_cell[e_id] += static_cast<ErrorVectorReal>
 
  471                     h_error_per_cell[e_id] += static_cast<ErrorVectorReal>
 
  475                     h_error_per_cell[e_id] += static_cast<ErrorVectorReal>
 
  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++)
 
  508           FEType elem_fe_type = fe_type;
 
  510             static_cast<Order>(fe_type.
order + elem->p_level());
 
  515             static_cast<Order>(fe_type.
order + elem->p_level() + 1);
 
  520       const unsigned int new_h_dofs = dofs_per_elem *
 
  521         (elem->n_children() - 1);
 
  523       const unsigned int new_p_dofs = dofs_per_p_elem -
 
  538         static_cast<Real>(new_h_dofs);
 
  539       if (p_value > h_value)
 
  556 #endif // #ifdef LIBMESH_ENABLE_AMR 
  
Manages consistently variables, degrees of freedom, and coefficient vectors.
 
unsigned int n_vars() const
 
void subtract_scaled(const TypeVector< T2 > &, const T &)
Subtract a scaled value from this vector without creating a temporary.
 
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
 
SimpleRange< ChildRefIter > child_ref_range()
Returns a range with all children of a parent element, usable in range-based for loops.
 
std::unique_ptr< FEBase > fe_coarse
 
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
 
The libMesh namespace provides an interface to certain functionality in the library.
 
virtual void zero() override
Set every element in the vector to 0.
 
bool make_flags_parallel_consistent()
Copy refinement flags on ghost elements from their local processors.
 
const std::vector< Real > * JxW
Mapping jacobians.
 
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
 
unsigned int p_level() const
 
unsigned int number() const
 
unsigned int mesh_dimension() const
 
const std::vector< Point > * xyz_values
Quadrature locations.
 
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
 
Number current_solution(const dof_id_type global_dof_number) const
 
Implements (adaptive) mesh refinement algorithms for a MeshBase.
 
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
 
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
 
This is the MeshBase class.
 
std::unique_ptr< QBase > qrule
The quadrature rule for the fine element.
 
DenseMatrix< Number > Ke
Linear system for projections.
 
static Point inverse_map(const unsigned int dim, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true)
 
auto norm_sq() const -> decltype(std::norm(T()))
 
auto norm_sq() const -> decltype(std::norm(T()))
 
Elem * coarse
The coarse element on which a solution projection is cached.
 
const MeshBase & get_mesh() const
 
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
 
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
 
void add_scaled(const TypeVector< T2 > &, const T &)
Add a scaled value to this vector without creating a temporary.
 
CompareTypes< T, T2 >::supertype contract(const TypeTensor< T2 > &) const
Multiply 2 tensors together to return a scalar, i.e.
 
A Node is like a Point, but with more information.
 
void add_scaled(const TypeTensor< T2 > &, const T &)
Add a scaled tensor to this tensor without creating a temporary.
 
static unsigned int n_dofs(const unsigned int dim, const FEType &fe_t, const ElemType t)
 
std::vector< float > component_scale
This vector can be used to "scale" certain variables in a system.
 
const FEType & variable_type(const unsigned int c) const
 
DenseVector< Number > Uc
Coefficients for projected coarse and projected p-derefined solutions.
 
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
 
const dof_id_type n_nodes
 
virtual unsigned int size() const override
 
void add_projection(const System &, const Elem *, unsigned int var)
The helper function which adds individual fine element data to the coarse element projection.
 
virtual void zero() override
Set every element in the matrix to 0.
 
std::unique_ptr< FEBase > fe
The finite element objects for fine and coarse elements.
 
const Elem * parent() const
 
void cholesky_solve(const DenseVector< T2 > &b, DenseVector< T2 > &x)
For symmetric positive definite (SPD) matrices.
 
std::vector< dof_id_type > dof_indices
Global DOF indices for fine elements.
 
void resize(const unsigned int n)
Resize the vector.
 
const std::vector< std::vector< RealTensor > > * d2phi
 
Real p_weight
Because the coarsening test seems to always choose p refinement, we're providing an option to make h ...
 
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
 
const std::vector< std::vector< Real > > * phi_coarse
 
OrderWrapper order
The approximation order of the element.
 
This class handles the numbering of degrees of freedom on a mesh.
 
This is the base class from which all geometric element types are derived.
 
const std::vector< std::vector< RealGradient > > * dphi
 
const std::vector< std::vector< Real > > * phi
The shape functions and their derivatives.
 
const std::vector< std::vector< RealGradient > > * dphi_coarse
 
const DofMap & get_dof_map() const
 
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
 
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...
 
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...
 
void subtract_scaled(const TypeTensor< T2 > &, const T &)
Subtract a scaled value from this tensor without creating a temporary.
 
const std::vector< std::vector< RealTensor > > * d2phi_coarse