210{
211
213
214
216
217
219
220
222
223
224
225 for (const auto & elem : range)
226 {
227
229
230
231
232 Patch patch(
mesh.processor_id());
233
234
235
236
238 continue;
239
240
241
242
245
246
247
248
249
250 std::vector<Real> new_error_per_cell(1, 0.);
252 new_error_per_cell.resize(patch.size(), 0.);
253
254
255
256 for (
unsigned int var=0; var<
n_vars; var++)
257 {
259#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
260#ifdef DEBUG
261 bool is_valid_norm_type =
268 norm_type ==
L_INF ||
272#endif
273#else
275 norm_type ==
L_INF ||
281#endif
282
283
284#ifdef DEBUG
285 if (var > 0)
286 {
287
288 bool is_valid_norm_combo =
301 ((norm_type ==
L_INF ||
308 }
309#endif
310
311
313
314
315 const FEType & fe_type = dof_map.variable_type (var);
316
317 const Order element_order = fe_type.order + elem->p_level();
318
319
321
322
324
325
326 fe->attach_quadrature_rule (qrule.get());
327
328
329 const std::vector<Real> & JxW = fe->get_JxW();
330 const std::vector<Point> & q_point = fe->get_xyz();
331
332
333
334
335
336 const std::vector<std::vector<Real>> * phi = nullptr;
337
338
339
340#ifdef NDEBUG
341 if (norm_type ==
L2 ||
343#endif
344 phi = &(fe->get_phi());
345
346 const std::vector<std::vector<RealGradient>> * dphi = nullptr;
352 dphi = &(fe->get_dphi());
353
354#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
355 const std::vector<std::vector<RealTensor>> * d2phi = nullptr;
358 d2phi = &(fe->get_d2phi());
359#endif
360
361
362 std::vector<dof_id_type> dof_indices;
363
364
365
366 unsigned int matsize = element_order + 1;
368 {
369 matsize *= (element_order + 2);
370 matsize /= 2;
371 }
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 ||
383 {
384 F.resize(matsize); Pu_h.resize(matsize);
385 }
390 {
391 Fx.resize(matsize); Pu_x_h.resize(matsize);
392#if LIBMESH_DIM > 1
393 Fy.resize(matsize); Pu_y_h.resize(matsize);
394#endif
395#if LIBMESH_DIM > 2
396 Fz.resize(matsize); Pu_z_h.resize(matsize);
397#endif
398 }
400 {
401 Fx.resize(matsize); Pu_x_h.resize(matsize);
402 }
404 {
405 libmesh_assert_greater (LIBMESH_DIM, 1);
406 Fy.resize(matsize); Pu_y_h.resize(matsize);
407 }
409 {
410 libmesh_assert_greater (LIBMESH_DIM, 2);
411 Fz.resize(matsize); Pu_z_h.resize(matsize);
412 }
413
414#if LIBMESH_DIM > 1
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
428
429 for (const auto & e_p : patch)
430 {
431
432 fe->reinit (e_p);
433
434
435
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
444
445 for (unsigned int qp=0; qp<n_qp; qp++)
446 {
447
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
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 ||
460 {
461
462
464
465 for (unsigned int i=0; i<n_dofs; i++)
467
468
469 for (unsigned int i=0; i != psi_size; i++)
470 F(i) += JxW[qp]*u_h*psi[i];
471
472 }
475 {
476
477
479
480 for (unsigned int i=0; i<n_dofs; i++)
483
484
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 }
497 {
498
499
501
502 for (unsigned int i=0; i<n_dofs; i++)
505
506
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
514 {
515
516
518
519 for (unsigned int i=0; i<n_dofs; i++)
522
523
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
530#if LIBMESH_DIM > 2
532 {
533
534
536
537 for (unsigned int i=0; i<n_dofs; i++)
540
541
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
550 {
551#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
552
553
555
556 for (unsigned int i=0; i<n_dofs; i++)
559
560
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
580 }
581 }
582
583
584
585
586
587
588
589 if (norm_type ==
L2 ||
591 {
592 Kp.lu_solve(F, Pu_h);
593 }
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 }
608 {
609 Kp.lu_solve (Fx, Pu_x_h);
610 }
612 {
613 Kp.lu_solve (Fy, Pu_y_h);
614 }
616 {
617 Kp.lu_solve (Fz, Pu_z_h);
618 }
619
620#if LIBMESH_DIM > 1
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
633
634
635
636 Patch::const_iterator patch_re_it;
637 Patch::const_iterator patch_re_end;
638
639
640 Patch patch_re(
mesh.processor_id());
641
643 {
644
645 patch_re_it = patch.begin();
646 patch_re_end = patch.end();
647 }
648 else
649 {
650
651
652 patch_re.build_around_element (elem, 0,
654
655
656 patch_re_it = patch_re.begin();
657 patch_re_end = patch_re.end();
658 }
659
660
661
662
663
664
665
666
667 for (unsigned int e = 0 ; patch_re_it != patch_re_end; ++patch_re_it, ++e)
668 {
669
670
671
672 const Elem * e_p = *patch_re_it;
673
674
676
677
678
679
680
681
683 continue;
684
685
686 fe->reinit (e_p);
687
688
689
690 dof_map.dof_indices (e_p, dof_indices, var);
691 libmesh_assert_equal_to (dof_indices.size(), phi->size());
692
693
694 const unsigned int n_dofs =
695 cast_int<unsigned int>(dof_indices.size());
696
697
698 Real element_error = 0;
699
700 const Order qorder = fe_type.order + e_p->p_level();
701
702
703 QGrid samprule (
dim, qorder);
704
707 fe->attach_quadrature_rule (&samprule);
708
709
710 const unsigned int n_sp =
711 cast_int<unsigned int>(JxW.size());
712
713
714 for (unsigned int sp=0; sp<n_sp; sp++)
715 {
716
717
718 std::vector<Number> temperr(6,0.0);
719
720 if (norm_type ==
L2 ||
722 {
723
725
726 for (unsigned int i=0; i<n_dofs; i++)
728
729
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 }
740 {
741
743
744 for (unsigned int i=0; i<n_dofs; i++)
747
748
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 }
770 {
771
773
774 for (unsigned int i=0; i<n_dofs; i++)
777
778
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
789 {
790
792
793 for (unsigned int i=0; i<n_dofs; i++)
796
797
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
807#if LIBMESH_DIM > 2
809 {
810
812
813 for (unsigned int i=0; i<n_dofs; i++)
816
817
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
829 {
830#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
831
833
834 for (unsigned int i=0; i<n_dofs; i++)
837
838
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
869
870
871
872 if (norm_type ==
L_INF)
873 element_error = std::max(element_error, std::abs(temperr[0]));
875 for (unsigned int i=0; i != LIBMESH_DIM; ++i)
876 element_error = std::max(element_error, std::abs(temperr[i]));
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)
883 for (unsigned int i=0; i != LIBMESH_DIM; ++i)
892 {
893 for (unsigned int i=0; i != LIBMESH_DIM; ++i)
895
896 for (unsigned int i=3; i != 6; ++i)
898 }
899
900 }
901
902 if (norm_type ==
L_INF ||
906 else if (norm_type ==
L2 ||
913 else
915 }
916
917 }
918
919
920
921
922
923
924
925 Patch::const_iterator patch_re_it;
926 Patch::const_iterator patch_re_end;
927
928
929 Patch current_elem_patch(
mesh.processor_id());
930
932 {
933
934 patch_re_it = patch.begin();
935 patch_re_end = patch.end();
936 }
937 else
938 {
939
940
941 current_elem_patch.build_around_element (elem, 0,
943
944
945 patch_re_it = current_elem_patch.begin();
946 patch_re_end = current_elem_patch.end();
947 }
948
949
950 for (unsigned int i = 0 ; patch_re_it != patch_re_end; ++patch_re_it, ++i)
951 {
952
953 const Elem * e_p = *patch_re_it;
954
955
957
958
965 {
970 }
971 else
972 {
980 }
981
982 }
983
984 }
985
986}
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
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
unsigned int n_vars() const
const DofMap & get_dof_map() const
const MeshBase & get_mesh() const
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.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
std::string enum_to_string(const T e)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
NumberVectorValue Gradient
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real