39 #ifdef LIBMESH_ENABLE_AMR 72 const unsigned int n_dofs =
80 const unsigned int n_coarse_dofs =
85 Ke.
resize(n_coarse_dofs, n_coarse_dofs);
95 for (
unsigned int qp=0; qp<
qrule->n_points(); qp++)
102 for (
unsigned int i=0; i != n_dofs; i++)
105 val += (*phi)[i][qp] *
114 for (
unsigned int i=0; i !=
Fe.
size(); ++i)
116 Fe(i) += (*JxW)[qp] *
117 (*phi_coarse)[i][qp]*val;
119 Fe(i) += (*JxW)[qp] *
120 (grad*(*dphi_coarse)[i][qp]);
122 Fe(i) += (*JxW)[qp] *
125 for (
unsigned int j=0; j !=
Fe.
size(); ++j)
127 Ke(i,j) += (*JxW)[qp] *
128 (*phi_coarse)[i][qp]*(*phi_coarse)[j][qp];
130 Ke(i,j) += (*JxW)[qp] *
131 (*dphi_coarse)[i][qp]*(*dphi_coarse)[j][qp];
133 Ke(i,j) += (*JxW)[qp] *
134 ((*d2phi_coarse)[i][qp].contract((*
d2phi_coarse)[j][qp]));
142 LOG_SCOPE(
"select_refinement()",
"HPCoarsenTest");
148 const unsigned int dim =
mesh.mesh_dimension();
157 const unsigned int sys_num = system.
number();
163 libmesh_error_msg(
"ERROR: component_scale is the wrong size:\n" \
164 <<
" component_scale.size()=" \
177 std::vector<ErrorVectorReal> h_error_per_cell(
mesh.max_elem_id(), 0.);
178 std::vector<ErrorVectorReal> p_error_per_cell(
mesh.max_elem_id(), 0.);
181 for (
unsigned int var=0; var<
n_vars; var++)
197 unsigned int cached_coarse_p_level = 0;
208 fe->attach_quadrature_rule (
qrule.get());
212 JxW = &(
fe->get_JxW());
216 phi = &(
fe->get_phi());
229 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 233 libmesh_error_msg(
"Minimization of H2 error without second derivatives is not possible.");
239 for (
const auto & elem :
mesh.active_local_element_ptr_range())
250 if (elem->parent() &&
252 cached_coarse_p_level != elem->
p_level()))
257 cached_coarse_p_level = elem->
p_level();
260 (
const_cast<Elem *
>(
coarse))->hack_p_level(elem->p_level());
264 (
const_cast<Elem *
>(
coarse))->hack_p_level(old_parent_level);
276 const unsigned int n_qp =
qrule->n_points();
279 const unsigned int n_dofs =
283 const unsigned int n_nodes = elem->n_nodes();
293 if (elem->p_level() == 0)
295 unsigned int n_vertices = 0;
296 for (
unsigned int n = 0; n !=
n_nodes; ++n)
297 if (elem->is_vertex(n))
300 const Node & node = elem->node_ref(n);
304 average_val /= n_vertices;
308 unsigned int old_elem_level = elem->p_level();
309 (
const_cast<Elem *
>(elem))->hack_p_level(old_elem_level - 1);
313 const unsigned int n_coarse_dofs =
316 (
const_cast<Elem *
>(elem))->hack_p_level(old_elem_level);
318 Ke.
resize(n_coarse_dofs, n_coarse_dofs);
324 for (
unsigned int qp=0; qp<
qrule->n_points(); qp++)
331 for (
unsigned int i=0; i != n_dofs; i++)
334 val += (*phi)[i][qp] *
343 for (
unsigned int i=0; i !=
Fe.
size(); ++i)
345 Fe(i) += (*JxW)[qp] *
346 (*phi_coarse)[i][qp]*val;
348 Fe(i) += (*JxW)[qp] *
349 grad * (*dphi_coarse)[i][qp];
351 Fe(i) += (*JxW)[qp] *
354 for (
unsigned int j=0; j !=
Fe.
size(); ++j)
356 Ke(i,j) += (*JxW)[qp] *
357 (*phi_coarse)[i][qp]*(*phi_coarse)[j][qp];
359 Ke(i,j) += (*JxW)[qp] *
360 (*dphi_coarse)[i][qp]*(*dphi_coarse)[j][qp];
362 Ke(i,j) += (*JxW)[qp] *
363 ((*d2phi_coarse)[i][qp].contract((*
d2phi_coarse)[j][qp]));
373 for (
unsigned int qp=0; qp<n_qp; qp++)
378 for (
unsigned int i=0; i<n_dofs; i++)
381 value_error += (*phi)[i][qp] *
388 if (elem->p_level() == 0)
390 value_error -= average_val;
394 for (
unsigned int i=0; i<
Up.
size(); i++)
396 value_error -= (*phi_coarse)[i][qp] *
Up(i);
410 (*JxW)[qp] * grad_error.
norm_sq());
414 (*JxW)[qp] * hessian_error.
norm_sq());
423 h_error_per_cell[e_id] =
432 (
const_cast<Elem *
>(
coarse))->hack_p_level(elem->p_level());
436 (
const_cast<Elem *
>(
coarse))->hack_p_level(old_parent_level);
439 unsigned int n_coarse_dofs =
443 for (
unsigned int qp=0; qp<n_qp; qp++)
450 for (
unsigned int i=0; i != n_dofs; ++i)
453 value_error += (*phi)[i][qp] *
461 for (
unsigned int i=0; i != n_coarse_dofs; ++i)
463 value_error -= (*phi_coarse)[i][qp] *
Uc(i);
476 (*JxW)[qp] * grad_error.
norm_sq());
480 (*JxW)[qp] * hessian_error.
norm_sq());
492 for (
auto & elem :
mesh.active_local_element_ptr_range())
501 unsigned int dofs_per_elem = 0, dofs_per_p_elem = 0;
504 for (
unsigned int var=0; var<
n_vars; var++)
511 FEType elem_fe_type = fe_type;
513 static_cast<Order>(fe_type.
order + elem->p_level());
518 static_cast<Order>(fe_type.
order + elem->p_level() + 1);
523 const unsigned int new_h_dofs = dofs_per_elem *
524 (elem->n_children() - 1);
526 const unsigned int new_p_dofs = dofs_per_p_elem -
538 std::sqrt(p_error_per_cell[e_id]) *
p_weight / new_p_dofs;
540 std::sqrt(h_error_per_cell[e_id]) /
541 static_cast<Real>(new_h_dofs);
542 if (p_value > h_value)
559 #endif // #ifdef LIBMESH_ENABLE_AMR Manages the family, order, etc. parameters for a given FE.
virtual unsigned int size() const override
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
const Elem * parent() const
std::vector< float > component_scale
void add_projection(const System &, const Elem *, unsigned int var)
A geometric point in (x,y,z) space associated with a DOF.
static unsigned int n_dofs(const unsigned int dim, const FEType &fe_t, const ElemType t)
virtual void select_refinement(System &system) override
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
void add_scaled(const TypeTensor< T2 > &, const T)
void add_scaled(const TypeVector< T2 > &, const T)
std::unique_ptr< FEBase > fe_coarse
const std::vector< std::vector< Real > > * phi_coarse
void resize(const unsigned int n)
const FEType & variable_type(const unsigned int c) const
The base class for all geometric element types.
const std::vector< std::vector< RealGradient > > * dphi_coarse
unsigned int p_level() const
const unsigned int n_vars
const std::vector< Point > * xyz_values
long double max(long double a, double b)
const MeshBase & get_mesh() const
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
SimpleRange< ChildRefIter > child_ref_range()
Number current_solution(const dof_id_type global_dof_number) const
const std::vector< Real > * JxW
Manages the degrees of freedom (DOFs) in a simulation.
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
Responsible for mesh refinement algorithms and data.
Manages consistently variables, degrees of freedom, and coefficient vectors.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
static Point inverse_map(const unsigned int dim, const FEType &fe_t, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true)
bool make_flags_parallel_consistent()
CompareTypes< T, T2 >::supertype contract(const TypeTensor< T2 > &) const
void subtract_scaled(const TypeVector< T2 > &, const T)
std::unique_ptr< FEBase > fe
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void zero() override
void resize(const unsigned int new_m, const unsigned int new_n)
unsigned int mesh_dimension() const
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)
const std::vector< std::vector< RealGradient > > * dphi
unsigned int n_vars() const
std::vector< dof_id_type > dof_indices
std::vector< Point > coarse_qpoints
const DofMap & get_dof_map() const
std::unique_ptr< QBase > qrule
void subtract_scaled(const TypeTensor< T2 > &, const T)
virtual void zero() override