libMesh
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
libMesh::PatchRecoveryErrorEstimator::EstimateError Class Reference

Class to compute the error contribution for a range of elements. More...

Public Member Functions

 EstimateError (const System &sys, const PatchRecoveryErrorEstimator &ee, ErrorVector &epc)
 
void operator() (const ConstElemRange &range) const
 

Private Attributes

const System & system
 
const PatchRecoveryErrorEstimator & error_estimator
 
ErrorVector & error_per_cell
 

Detailed Description

Class to compute the error contribution for a range of elements.

May be executed in parallel on separate threads.

Definition at line 130 of file patch_recovery_error_estimator.h.

Constructor & Destructor Documentation

◆ EstimateError()

libMesh::PatchRecoveryErrorEstimator::EstimateError::EstimateError ( const System &  sys,
const PatchRecoveryErrorEstimator &  ee,
ErrorVector &  epc 
)
inline

Member Function Documentation

◆ operator()()

void libMesh::PatchRecoveryErrorEstimator::EstimateError::operator() ( const ConstElemRange &  range) const

Definition at line 209 of file patch_recovery_error_estimator.C.

210{
211 // The current mesh
212 const MeshBase & mesh = system.get_mesh();
213
214 // The dimensionality of the mesh
215 const unsigned int dim = mesh.mesh_dimension();
216
217 // The number of variables in the system
218 const unsigned int n_vars = system.n_vars();
219
220 // The DofMap for this system
221 const DofMap & dof_map = system.get_dof_map();
222
223 //------------------------------------------------------------
224 // Iterate over all the elements in the range.
225 for (const auto & elem : range)
226 {
227 // We'll need an index into the error vector
228 const dof_id_type e_id=elem->id();
229
230 // We are going to build a patch containing the current element
231 // and its neighbors on the local processor
232 Patch patch(mesh.processor_id());
233
234 // If we are reusing patches and the current element
235 // already has an estimate associated with it, move on the
236 // next element
237 if (this->error_estimator.patch_reuse && error_per_cell[e_id] != 0)
238 continue;
239
240 // If we are not reusing patches or haven't built one containing this element, we build one
241
242 // Use user specified patch size and growth strategy
243 patch.build_around_element (elem, error_estimator.target_patch_size,
245
246 // Declare a new_error_per_cell vector to hold error estimates
247 // from each element in this patch, or one estimate if we are
248 // not reusing patches since we will only be computing error for
249 // one cell
250 std::vector<Real> new_error_per_cell(1, 0.);
252 new_error_per_cell.resize(patch.size(), 0.);
253
254 //------------------------------------------------------------
255 // Process each variable in the system using the current patch
256 for (unsigned int var=0; var<n_vars; var++)
257 {
258 const auto norm_type = error_estimator.error_norm.type(var);
259#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
260#ifdef DEBUG
261 bool is_valid_norm_type =
262 norm_type == L2 ||
263 norm_type == H1_SEMINORM ||
264 norm_type == H2_SEMINORM ||
265 norm_type == H1_X_SEMINORM ||
266 norm_type == H1_Y_SEMINORM ||
267 norm_type == H1_Z_SEMINORM ||
268 norm_type == L_INF ||
269 norm_type == W1_INF_SEMINORM ||
270 norm_type == W2_INF_SEMINORM;
271 libmesh_assert (is_valid_norm_type);
272#endif // DEBUG
273#else
274 libmesh_assert (norm_type == L2 ||
275 norm_type == L_INF ||
276 norm_type == H1_SEMINORM ||
277 norm_type == H1_X_SEMINORM ||
278 norm_type == H1_Y_SEMINORM ||
279 norm_type == H1_Z_SEMINORM ||
280 norm_type == W1_INF_SEMINORM);
281#endif
282
283
284#ifdef DEBUG
285 if (var > 0)
286 {
287 // We can't mix L_inf and L_2 norms
288 bool is_valid_norm_combo =
289 ((norm_type == L2 ||
290 norm_type == H1_SEMINORM ||
291 norm_type == H1_X_SEMINORM ||
292 norm_type == H1_Y_SEMINORM ||
293 norm_type == H1_Z_SEMINORM ||
294 norm_type == H2_SEMINORM) &&
295 (error_estimator.error_norm.type(var-1) == L2 ||
301 ((norm_type == L_INF ||
302 norm_type == W1_INF_SEMINORM ||
303 norm_type == W2_INF_SEMINORM) &&
307 libmesh_assert (is_valid_norm_combo);
308 }
309#endif // DEBUG
310
311 // Possibly skip this variable
312 if (error_estimator.error_norm.weight(var) == 0.0) continue;
313
314 // The type of finite element to use for this variable
315 const FEType & fe_type = dof_map.variable_type (var);
316
317 const Order element_order = fe_type.order + elem->p_level();
318
319 // Finite element object for use in this patch
320 std::unique_ptr<FEBase> fe (FEBase::build (dim, fe_type));
321
322 // Build an appropriate Gaussian quadrature rule
323 std::unique_ptr<QBase> qrule (fe_type.default_quadrature_rule(dim, error_estimator._extra_order));
324
325 // Tell the finite element about the quadrature rule.
326 fe->attach_quadrature_rule (qrule.get());
327
328 // Get Jacobian values, etc..
329 const std::vector<Real> & JxW = fe->get_JxW();
330 const std::vector<Point> & q_point = fe->get_xyz();
331
332 // Get whatever phi/dphi/d2phi values we need. Avoid
333 // getting them unless the requested norm is actually going
334 // to use them.
335
336 const std::vector<std::vector<Real>> * phi = nullptr;
337 // If we're using phi to assert the correct dof_indices
338 // vector size later, then we'll need to get_phi whether we
339 // plan to use it or not.
340#ifdef NDEBUG
341 if (norm_type == L2 ||
342 norm_type == L_INF)
343#endif
344 phi = &(fe->get_phi());
345
346 const std::vector<std::vector<RealGradient>> * dphi = nullptr;
347 if (norm_type == H1_SEMINORM ||
348 norm_type == H1_X_SEMINORM ||
349 norm_type == H1_Y_SEMINORM ||
350 norm_type == H1_Z_SEMINORM ||
351 norm_type == W1_INF_SEMINORM)
352 dphi = &(fe->get_dphi());
353
354#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
355 const std::vector<std::vector<RealTensor>> * d2phi = nullptr;
356 if (norm_type == H2_SEMINORM ||
357 norm_type == W2_INF_SEMINORM)
358 d2phi = &(fe->get_d2phi());
359#endif
360
361 // global DOF indices
362 std::vector<dof_id_type> dof_indices;
363
364 // Compute the appropriate size for the patch projection matrices
365 // and vectors;
366 unsigned int matsize = element_order + 1;
367 if (dim > 1)
368 {
369 matsize *= (element_order + 2);
370 matsize /= 2;
371 }
372 if (dim > 2)
373 {
374 matsize *= (element_order + 3);
375 matsize /= 3;
376 }
377
378 DenseMatrix<Number> Kp(matsize,matsize);
379 DenseVector<Number> F, Fx, Fy, Fz, Fxy, Fxz, Fyz;
380 DenseVector<Number> Pu_h, Pu_x_h, Pu_y_h, Pu_z_h, Pu_xy_h, Pu_xz_h, Pu_yz_h;
381 if (norm_type == L2 ||
382 norm_type == L_INF)
383 {
384 F.resize(matsize); Pu_h.resize(matsize);
385 }
386 else if (norm_type == H1_SEMINORM ||
387 norm_type == W1_INF_SEMINORM ||
388 norm_type == H2_SEMINORM ||
389 norm_type == W2_INF_SEMINORM)
390 {
391 Fx.resize(matsize); Pu_x_h.resize(matsize); // stores xx in W2 cases
392#if LIBMESH_DIM > 1
393 Fy.resize(matsize); Pu_y_h.resize(matsize); // stores yy in W2 cases
394#endif
395#if LIBMESH_DIM > 2
396 Fz.resize(matsize); Pu_z_h.resize(matsize); // stores zz in W2 cases
397#endif
398 }
399 else if (norm_type == H1_X_SEMINORM)
400 {
401 Fx.resize(matsize); Pu_x_h.resize(matsize); // Only need to compute the x gradient for the x component seminorm
402 }
403 else if (norm_type == H1_Y_SEMINORM)
404 {
405 libmesh_assert_greater (LIBMESH_DIM, 1);
406 Fy.resize(matsize); Pu_y_h.resize(matsize); // Only need to compute the y gradient for the y component seminorm
407 }
408 else if (norm_type == H1_Z_SEMINORM)
409 {
410 libmesh_assert_greater (LIBMESH_DIM, 2);
411 Fz.resize(matsize); Pu_z_h.resize(matsize); // Only need to compute the z gradient for the z component seminorm
412 }
413
414#if LIBMESH_DIM > 1
415 if (norm_type == H2_SEMINORM ||
416 norm_type == W2_INF_SEMINORM)
417 {
418 Fxy.resize(matsize); Pu_xy_h.resize(matsize);
419#if LIBMESH_DIM > 2
420 Fxz.resize(matsize); Pu_xz_h.resize(matsize);
421 Fyz.resize(matsize); Pu_yz_h.resize(matsize);
422#endif
423 }
424#endif
425
426 //------------------------------------------------------
427 // Loop over each element in the patch and compute their
428 // contribution to the patch gradient projection.
429 for (const auto & e_p : patch)
430 {
431 // Reinitialize the finite element data for this element
432 fe->reinit (e_p);
433
434 // Get the global DOF indices for the current variable
435 // in the current element
436 dof_map.dof_indices (e_p, dof_indices, var);
437 libmesh_assert_equal_to (dof_indices.size(), phi->size());
438
439 const unsigned int n_dofs =
440 cast_int<unsigned int>(dof_indices.size());
441 const unsigned int n_qp = qrule->n_points();
442
443 // Compute the projection components from this cell.
444 // \int_{Omega_e} \psi_i \psi_j = \int_{Omega_e} du_h/dx_k \psi_i
445 for (unsigned int qp=0; qp<n_qp; qp++)
446 {
447 // Construct the shape function values for the patch projection
448 std::vector<Real> psi(specpoly(dim, element_order, q_point[qp], matsize));
449
450 const unsigned int psi_size = cast_int<unsigned int>(psi.size());
451
452 // Patch matrix contribution
453 const unsigned int m = Kp.m(), n = Kp.n();
454 for (unsigned int i=0; i<m; i++)
455 for (unsigned int j=0; j<n; j++)
456 Kp(i,j) += JxW[qp]*psi[i]*psi[j];
457
458 if (norm_type == L2 ||
459 norm_type == L_INF)
460 {
461 // Compute the solution on the current patch element
462 // the quadrature point
463 Number u_h = libMesh::zero;
464
465 for (unsigned int i=0; i<n_dofs; i++)
466 u_h += (*phi)[i][qp]*system.current_solution (dof_indices[i]);
467
468 // Patch RHS contributions
469 for (unsigned int i=0; i != psi_size; i++)
470 F(i) += JxW[qp]*u_h*psi[i];
471
472 }
473 else if (norm_type == H1_SEMINORM ||
474 norm_type == W1_INF_SEMINORM)
475 {
476 // Compute the gradient on the current patch element
477 // at the quadrature point
478 Gradient grad_u_h;
479
480 for (unsigned int i=0; i<n_dofs; i++)
481 grad_u_h.add_scaled ((*dphi)[i][qp],
482 system.current_solution(dof_indices[i]));
483
484 // Patch RHS contributions
485 for (unsigned int i=0; i != psi_size; i++)
486 {
487 Fx(i) += JxW[qp]*grad_u_h(0)*psi[i];
488#if LIBMESH_DIM > 1
489 Fy(i) += JxW[qp]*grad_u_h(1)*psi[i];
490#endif
491#if LIBMESH_DIM > 2
492 Fz(i) += JxW[qp]*grad_u_h(2)*psi[i];
493#endif
494 }
495 }
496 else if (norm_type == H1_X_SEMINORM)
497 {
498 // Compute the gradient on the current patch element
499 // at the quadrature point
500 Gradient grad_u_h;
501
502 for (unsigned int i=0; i<n_dofs; i++)
503 grad_u_h.add_scaled ((*dphi)[i][qp],
504 system.current_solution(dof_indices[i]));
505
506 // Patch RHS contributions
507 for (unsigned int i=0; i != psi_size; i++)
508 {
509 Fx(i) += JxW[qp]*grad_u_h(0)*psi[i];
510 }
511 }
512#if LIBMESH_DIM > 1
513 else if (norm_type == H1_Y_SEMINORM)
514 {
515 // Compute the gradient on the current patch element
516 // at the quadrature point
517 Gradient grad_u_h;
518
519 for (unsigned int i=0; i<n_dofs; i++)
520 grad_u_h.add_scaled ((*dphi)[i][qp],
521 system.current_solution(dof_indices[i]));
522
523 // Patch RHS contributions
524 for (unsigned int i=0; i != psi_size; i++)
525 {
526 Fy(i) += JxW[qp]*grad_u_h(1)*psi[i];
527 }
528 }
529#endif // LIBMESH_DIM > 1
530#if LIBMESH_DIM > 2
531 else if (norm_type == H1_Z_SEMINORM)
532 {
533 // Compute the gradient on the current patch element
534 // at the quadrature point
535 Gradient grad_u_h;
536
537 for (unsigned int i=0; i<n_dofs; i++)
538 grad_u_h.add_scaled ((*dphi)[i][qp],
539 system.current_solution(dof_indices[i]));
540
541 // Patch RHS contributions
542 for (unsigned int i=0; i != psi_size; i++)
543 {
544 Fz(i) += JxW[qp]*grad_u_h(2)*psi[i];
545 }
546 }
547#endif // LIBMESH_DIM > 2
548 else if (norm_type == H2_SEMINORM ||
549 norm_type == W2_INF_SEMINORM)
550 {
551#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
552 // Compute the hessian on the current patch element
553 // at the quadrature point
554 Tensor hess_u_h;
555
556 for (unsigned int i=0; i<n_dofs; i++)
557 hess_u_h.add_scaled ((*d2phi)[i][qp],
558 system.current_solution(dof_indices[i]));
559
560 // Patch RHS contributions
561 for (unsigned int i=0; i != psi_size; i++)
562 {
563 Fx(i) += JxW[qp]*hess_u_h(0,0)*psi[i];
564#if LIBMESH_DIM > 1
565 Fy(i) += JxW[qp]*hess_u_h(1,1)*psi[i];
566 Fxy(i) += JxW[qp]*hess_u_h(0,1)*psi[i];
567#endif
568#if LIBMESH_DIM > 2
569 Fz(i) += JxW[qp]*hess_u_h(2,2)*psi[i];
570 Fxz(i) += JxW[qp]*hess_u_h(0,2)*psi[i];
571 Fyz(i) += JxW[qp]*hess_u_h(1,2)*psi[i];
572#endif
573 }
574#else
575 libmesh_error_msg("ERROR: --enable-second-derivatives is required \nfor _sobolev_order == 2!");
576#endif
577 }
578 else
579 libmesh_error_msg("Unsupported error norm type == " << Utility::enum_to_string(norm_type));
580 } // end quadrature loop
581 } // end patch loop
582
583
584
585 //--------------------------------------------------
586 // Now we have fully assembled the projection system
587 // for this patch. Project the gradient components.
588 // MAY NEED TO USE PARTIAL PIVOTING!
589 if (norm_type == L2 ||
590 norm_type == L_INF)
591 {
592 Kp.lu_solve(F, Pu_h);
593 }
594 else if (norm_type == H1_SEMINORM ||
595 norm_type == W1_INF_SEMINORM ||
596 norm_type == H2_SEMINORM ||
597 norm_type == W2_INF_SEMINORM)
598 {
599 Kp.lu_solve (Fx, Pu_x_h);
600#if LIBMESH_DIM > 1
601 Kp.lu_solve (Fy, Pu_y_h);
602#endif
603#if LIBMESH_DIM > 2
604 Kp.lu_solve (Fz, Pu_z_h);
605#endif
606 }
607 else if (norm_type == H1_X_SEMINORM)
608 {
609 Kp.lu_solve (Fx, Pu_x_h);
610 }
611 else if (norm_type == H1_Y_SEMINORM)
612 {
613 Kp.lu_solve (Fy, Pu_y_h);
614 }
615 else if (norm_type == H1_Z_SEMINORM)
616 {
617 Kp.lu_solve (Fz, Pu_z_h);
618 }
619
620#if LIBMESH_DIM > 1
621 if (norm_type == H2_SEMINORM ||
622 norm_type == W2_INF_SEMINORM)
623 {
624 Kp.lu_solve(Fxy, Pu_xy_h);
625#if LIBMESH_DIM > 2
626 Kp.lu_solve(Fxz, Pu_xz_h);
627 Kp.lu_solve(Fyz, Pu_yz_h);
628#endif
629 }
630#endif
631
632 // If we are reusing patches, reuse the current patch to loop
633 // over all elements in the current patch, otherwise build a new
634 // patch containing just the current element and loop over it
635 // Note that C++ will not allow patch_re_end to be a const here
636 Patch::const_iterator patch_re_it;
637 Patch::const_iterator patch_re_end;
638
639 // Declare a new patch
640 Patch patch_re(mesh.processor_id());
641
643 {
644 // Just get the iterators from the current patch
645 patch_re_it = patch.begin();
646 patch_re_end = patch.end();
647 }
648 else
649 {
650 // Use a target patch size of just 0, this will contain
651 // just the current element
652 patch_re.build_around_element (elem, 0,
654
655 // Get the iterators from this newly constructed patch
656 patch_re_it = patch_re.begin();
657 patch_re_end = patch_re.end();
658 }
659
660 // If we are reusing patches, loop over all the elements
661 // in the current patch and develop an estimate
662 // for all the elements by computing ||P u_h - u_h|| or ||P grad_u_h - grad_u_h||
663 // or ||P hess_u_h - hess_u_h|| according to the requested
664 // seminorm, otherwise just compute it for the current element
665
666 // Loop over every element in the patch
667 for (unsigned int e = 0 ; patch_re_it != patch_re_end; ++patch_re_it, ++e)
668 {
669 // Build the Finite Element for the current element
670
671 // The pth element in the patch
672 const Elem * e_p = *patch_re_it;
673
674 // We'll need an index into the error vector for this element
675 const dof_id_type e_p_id = e_p->id();
676
677 // We will update the new_error_per_cell vector with element_error if the
678 // error_per_cell[e_p_id] entry is non-zero, otherwise update it
679 // with 0. i.e. leave it unchanged
680
681 // No need to compute the estimate if we are reusing patches and already have one
682 if (this->error_estimator.patch_reuse && error_per_cell[e_p_id] != 0.)
683 continue;
684
685 // Reinitialize the finite element data for this element
686 fe->reinit (e_p);
687
688 // Get the global DOF indices for the current variable
689 // in the current element
690 dof_map.dof_indices (e_p, dof_indices, var);
691 libmesh_assert_equal_to (dof_indices.size(), phi->size());
692
693 // The number of dofs for this variable on this element
694 const unsigned int n_dofs =
695 cast_int<unsigned int>(dof_indices.size());
696
697 // Variable to hold the error on the current element
698 Real element_error = 0;
699
700 const Order qorder = fe_type.order + e_p->p_level();
701
702 // A quadrature rule for this element
703 QGrid samprule (dim, qorder);
704
705 if (norm_type == W1_INF_SEMINORM ||
706 norm_type == W2_INF_SEMINORM)
707 fe->attach_quadrature_rule (&samprule);
708
709 // The number of points we will sample over
710 const unsigned int n_sp =
711 cast_int<unsigned int>(JxW.size());
712
713 // Loop over every sample point for the current element
714 for (unsigned int sp=0; sp<n_sp; sp++)
715 {
716 // Compute the solution at the current sample point
717
718 std::vector<Number> temperr(6,0.0); // x,y,z or xx,yy,zz,xy,xz,yz
719
720 if (norm_type == L2 ||
721 norm_type == L_INF)
722 {
723 // Compute the value at the current sample point
724 Number u_h = libMesh::zero;
725
726 for (unsigned int i=0; i<n_dofs; i++)
727 u_h += (*phi)[i][sp]*system.current_solution (dof_indices[i]);
728
729 // Compute the phi values at the current sample point
730 std::vector<Real> psi(specpoly(dim, element_order, q_point[sp], matsize));
731 for (unsigned int i=0; i<matsize; i++)
732 {
733 temperr[0] += psi[i]*Pu_h(i);
734 }
735
736 temperr[0] -= u_h;
737 }
738 else if (norm_type == H1_SEMINORM ||
739 norm_type == W1_INF_SEMINORM)
740 {
741 // Compute the gradient at the current sample point
742 Gradient grad_u_h;
743
744 for (unsigned int i=0; i<n_dofs; i++)
745 grad_u_h.add_scaled ((*dphi)[i][sp],
746 system.current_solution(dof_indices[i]));
747
748 // Compute the phi values at the current sample point
749 std::vector<Real> psi(specpoly(dim, element_order, q_point[sp], matsize));
750
751 for (unsigned int i=0; i<matsize; i++)
752 {
753 temperr[0] += psi[i]*Pu_x_h(i);
754#if LIBMESH_DIM > 1
755 temperr[1] += psi[i]*Pu_y_h(i);
756#endif
757#if LIBMESH_DIM > 2
758 temperr[2] += psi[i]*Pu_z_h(i);
759#endif
760 }
761 temperr[0] -= grad_u_h(0);
762#if LIBMESH_DIM > 1
763 temperr[1] -= grad_u_h(1);
764#endif
765#if LIBMESH_DIM > 2
766 temperr[2] -= grad_u_h(2);
767#endif
768 }
769 else if (norm_type == H1_X_SEMINORM)
770 {
771 // Compute the gradient at the current sample point
772 Gradient grad_u_h;
773
774 for (unsigned int i=0; i<n_dofs; i++)
775 grad_u_h.add_scaled ((*dphi)[i][sp],
776 system.current_solution(dof_indices[i]));
777
778 // Compute the phi values at the current sample point
779 std::vector<Real> psi(specpoly(dim, element_order, q_point[sp], matsize));
780 for (unsigned int i=0; i<matsize; i++)
781 {
782 temperr[0] += psi[i]*Pu_x_h(i);
783 }
784
785 temperr[0] -= grad_u_h(0);
786 }
787#if LIBMESH_DIM > 1
788 else if (norm_type == H1_Y_SEMINORM)
789 {
790 // Compute the gradient at the current sample point
791 Gradient grad_u_h;
792
793 for (unsigned int i=0; i<n_dofs; i++)
794 grad_u_h.add_scaled ((*dphi)[i][sp],
795 system.current_solution(dof_indices[i]));
796
797 // Compute the phi values at the current sample point
798 std::vector<Real> psi(specpoly(dim, element_order, q_point[sp], matsize));
799 for (unsigned int i=0; i<matsize; i++)
800 {
801 temperr[1] += psi[i]*Pu_y_h(i);
802 }
803
804 temperr[1] -= grad_u_h(1);
805 }
806#endif // LIBMESH_DIM > 1
807#if LIBMESH_DIM > 2
808 else if (norm_type == H1_Z_SEMINORM)
809 {
810 // Compute the gradient at the current sample point
811 Gradient grad_u_h;
812
813 for (unsigned int i=0; i<n_dofs; i++)
814 grad_u_h.add_scaled ((*dphi)[i][sp],
815 system.current_solution(dof_indices[i]));
816
817 // Compute the phi values at the current sample point
818 std::vector<Real> psi(specpoly(dim, element_order, q_point[sp], matsize));
819 for (unsigned int i=0; i<matsize; i++)
820 {
821 temperr[2] += psi[i]*Pu_z_h(i);
822 }
823
824 temperr[2] -= grad_u_h(2);
825 }
826#endif // LIBMESH_DIM > 2
827 else if (norm_type == H2_SEMINORM ||
828 norm_type == W2_INF_SEMINORM)
829 {
830#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
831 // Compute the Hessian at the current sample point
832 Tensor hess_u_h;
833
834 for (unsigned int i=0; i<n_dofs; i++)
835 hess_u_h.add_scaled ((*d2phi)[i][sp],
836 system.current_solution(dof_indices[i]));
837
838 // Compute the phi values at the current sample point
839 std::vector<Real> psi(specpoly(dim, element_order, q_point[sp], matsize));
840 for (unsigned int i=0; i<matsize; i++)
841 {
842 temperr[0] += psi[i]*Pu_x_h(i);
843#if LIBMESH_DIM > 1
844 temperr[1] += psi[i]*Pu_y_h(i);
845 temperr[3] += psi[i]*Pu_xy_h(i);
846#endif
847#if LIBMESH_DIM > 2
848 temperr[2] += psi[i]*Pu_z_h(i);
849 temperr[4] += psi[i]*Pu_xz_h(i);
850 temperr[5] += psi[i]*Pu_yz_h(i);
851#endif
852 }
853
854 temperr[0] -= hess_u_h(0,0);
855#if LIBMESH_DIM > 1
856 temperr[1] -= hess_u_h(1,1);
857 temperr[3] -= hess_u_h(0,1);
858#endif
859#if LIBMESH_DIM > 2
860 temperr[2] -= hess_u_h(2,2);
861 temperr[4] -= hess_u_h(0,2);
862 temperr[5] -= hess_u_h(1,2);
863#endif
864#else
865 libmesh_error_msg("ERROR: --enable-second-derivatives is required \nfor _sobolev_order == 2!");
866#endif
867 }
868 // Add up relevant terms. We can easily optimize the
869 // LIBMESH_DIM < 3 cases a little bit with the exception
870 // of the W2 cases
871
872 if (norm_type == L_INF)
873 element_error = std::max(element_error, std::abs(temperr[0]));
874 else if (norm_type == W1_INF_SEMINORM)
875 for (unsigned int i=0; i != LIBMESH_DIM; ++i)
876 element_error = std::max(element_error, std::abs(temperr[i]));
877 else if (norm_type == W2_INF_SEMINORM)
878 for (unsigned int i=0; i != 6; ++i)
879 element_error = std::max(element_error, std::abs(temperr[i]));
880 else if (norm_type == L2)
881 element_error += JxW[sp]*TensorTools::norm_sq(temperr[0]);
882 else if (norm_type == H1_SEMINORM)
883 for (unsigned int i=0; i != LIBMESH_DIM; ++i)
884 element_error += JxW[sp]*TensorTools::norm_sq(temperr[i]);
885 else if (norm_type == H1_X_SEMINORM)
886 element_error += JxW[sp]*TensorTools::norm_sq(temperr[0]);
887 else if (norm_type == H1_Y_SEMINORM)
888 element_error += JxW[sp]*TensorTools::norm_sq(temperr[1]);
889 else if (norm_type == H1_Z_SEMINORM)
890 element_error += JxW[sp]*TensorTools::norm_sq(temperr[2]);
891 else if (norm_type == H2_SEMINORM)
892 {
893 for (unsigned int i=0; i != LIBMESH_DIM; ++i)
894 element_error += JxW[sp]*TensorTools::norm_sq(temperr[i]);
895 // Off diagonal terms enter into the Hessian norm twice
896 for (unsigned int i=3; i != 6; ++i)
897 element_error += JxW[sp]*2*TensorTools::norm_sq(temperr[i]);
898 }
899
900 } // End loop over sample points
901
902 if (norm_type == L_INF ||
903 norm_type == W1_INF_SEMINORM ||
904 norm_type == W2_INF_SEMINORM)
905 new_error_per_cell[e] += error_estimator.error_norm.weight(var) * element_error;
906 else if (norm_type == L2 ||
907 norm_type == H1_SEMINORM ||
908 norm_type == H1_X_SEMINORM ||
909 norm_type == H1_Y_SEMINORM ||
910 norm_type == H1_Z_SEMINORM ||
911 norm_type == H2_SEMINORM)
912 new_error_per_cell[e] += error_estimator.error_norm.weight_sq(var) * element_error;
913 else
914 libmesh_error_msg("Unsupported error norm type == " << Utility::enum_to_string(norm_type));
915 } // End (re) loop over patch elements
916
917 } // end variables loop
918
919 // Now that we have the contributions from each variable,
920 // we have take square roots of the entries we
921 // added to error_per_cell to get an error norm
922 // If we are reusing patches, once again reuse the current patch to loop
923 // over all elements in the current patch, otherwise build a new
924 // patch containing just the current element and loop over it
925 Patch::const_iterator patch_re_it;
926 Patch::const_iterator patch_re_end;
927
928 // Build a new patch if necessary
929 Patch current_elem_patch(mesh.processor_id());
930
932 {
933 // Just get the iterators from the current patch
934 patch_re_it = patch.begin();
935 patch_re_end = patch.end();
936 }
937 else
938 {
939 // Use a target patch size of just 0, this will contain
940 // just the current element.
941 current_elem_patch.build_around_element (elem, 0,
943
944 // Get the iterators from this newly constructed patch
945 patch_re_it = current_elem_patch.begin();
946 patch_re_end = current_elem_patch.end();
947 }
948
949 // Loop over every element in the patch we just constructed
950 for (unsigned int i = 0 ; patch_re_it != patch_re_end; ++patch_re_it, ++i)
951 {
952 // The pth element in the patch
953 const Elem * e_p = *patch_re_it;
954
955 // We'll need an index into the error vector
956 const dof_id_type e_p_id = e_p->id();
957
958 // Update the error_per_cell vector for this element
959 if (error_estimator.error_norm.type(0) == L2 ||
965 {
966 Threads::spin_mutex::scoped_lock acquire(Threads::spin_mtx);
967 if (!error_per_cell[e_p_id])
968 error_per_cell[e_p_id] =
969 static_cast<ErrorVectorReal>(std::sqrt(new_error_per_cell[i]));
970 }
971 else
972 {
976 Threads::spin_mutex::scoped_lock acquire(Threads::spin_mtx);
977 if (!error_per_cell[e_p_id])
978 error_per_cell[e_p_id] =
979 static_cast<ErrorVectorReal>(new_error_per_cell[i]);
980 }
981
982 } // End loop over every element in patch
983
984 } // end element loop
985
986} // End () operator definition
unsigned int n_vars
unsigned int dim
SystemNorm error_norm
When estimating the error in a single system, the error_norm is used to control the scaling and norm ...
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
unsigned int mesh_dimension() const
Definition mesh_base.C:515
unsigned int target_patch_size
The PatchErrorEstimator will build patches of at least this many elements to perform estimates.
static std::vector< Real > specpoly(const unsigned int dim, const Order order, const Point p, const unsigned int matsize)
Patch::PMF patch_growth_strategy
The PatchErrorEstimator will use this pointer to a Patch member function when growing patches.
int _extra_order
Extra order to use for quadrature rule.
FEMNormType type(unsigned int var) const
Real weight(unsigned int var) const
Real weight_sq(unsigned int var) const
Number current_solution(const dof_id_type global_dof_number) const
Definition system.C:164
unsigned int n_vars() const
Definition system.C:2729
const DofMap & get_dof_map() const
Definition system.h:2448
const MeshBase & get_mesh() const
Definition system.h:2432
LIBMESH_DEVICE_INLINE void add_scaled(const TypeTensor< T2 > &, const T &)
Add a scaled tensor to this tensor without creating a temporary.
LIBMESH_DEVICE_INLINE void add_scaled(const TypeVector< T2 > &, const T &)
Add a scaled value to this vector without creating a temporary.
MeshBase & mesh
LIBMESH_DEVICE_INLINE auto norm_sq(const T &a)
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition threads.C:30
std::string enum_to_string(const T e)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
NumberVectorValue Gradient
libmesh_assert(ctx)
NumberTensorValue Tensor
const Number zero
.
Definition libmesh.h:297
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::PatchRecoveryErrorEstimator::_extra_order, libMesh::TypeTensor< T >::add_scaled(), libMesh::TypeVector< T >::add_scaled(), libMesh::FEGenericBase< OutputType >::build(), libMesh::Patch::build_around_element(), libMesh::System::current_solution(), libMesh::FEType::default_quadrature_rule(), dim, libMesh::DofMap::dof_indices(), libMesh::Utility::enum_to_string(), error_estimator, libMesh::ErrorEstimator::error_norm, error_per_cell, libMesh::ErrorVectorReal, libMesh::System::get_dof_map(), libMesh::System::get_mesh(), libMesh::H1_SEMINORM, libMesh::H1_X_SEMINORM, libMesh::H1_Y_SEMINORM, libMesh::H1_Z_SEMINORM, libMesh::H2_SEMINORM, libMesh::DofObject::id(), libMesh::L2, libMesh::L_INF, libMesh::libmesh_assert(), libMesh::DenseMatrix< T >::lu_solve(), libMesh::DenseMatrixBase< T >::m(), mesh, libMesh::MeshBase::mesh_dimension(), libMesh::DenseMatrixBase< T >::n(), n_vars, libMesh::System::n_vars(), libMesh::TensorTools::norm_sq(), libMesh::FEType::order, libMesh::Elem::p_level(), libMesh::PatchRecoveryErrorEstimator::patch_growth_strategy, libMesh::PatchRecoveryErrorEstimator::patch_reuse, libMesh::Real, libMesh::DenseVector< T >::resize(), libMesh::PatchRecoveryErrorEstimator::specpoly(), libMesh::Threads::spin_mtx, system, libMesh::PatchRecoveryErrorEstimator::target_patch_size, libMesh::SystemNorm::type(), libMesh::DofMap::variable_type(), libMesh::W1_INF_SEMINORM, libMesh::W2_INF_SEMINORM, libMesh::SystemNorm::weight(), libMesh::SystemNorm::weight_sq(), and libMesh::zero.

Member Data Documentation

◆ error_estimator

const PatchRecoveryErrorEstimator& libMesh::PatchRecoveryErrorEstimator::EstimateError::error_estimator
private

Definition at line 145 of file patch_recovery_error_estimator.h.

Referenced by operator()().

◆ error_per_cell

ErrorVector& libMesh::PatchRecoveryErrorEstimator::EstimateError::error_per_cell
private

Definition at line 146 of file patch_recovery_error_estimator.h.

Referenced by operator()().

◆ system

const System& libMesh::PatchRecoveryErrorEstimator::EstimateError::system
private

Definition at line 144 of file patch_recovery_error_estimator.h.

Referenced by operator()().


The documentation for this class was generated from the following files: