111{
112
114
115
117
118
120
121
123
124
125
126 for (const auto & elem : range)
127 {
128
130
131
132
133 Patch patch(
mesh.processor_id());
134
135
136
137
139 continue;
140
141
142
143
146
147
148
149
150
151 std::vector<Real> new_error_per_cell(1, 0.);
153 new_error_per_cell.resize(patch.size(), 0.);
154
155
156
157 for (
unsigned int var=0; var<
n_vars; var++)
158 {
160#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
161#ifdef DEBUG
162 bool is_valid_norm_type =
169 norm_type ==
L_INF ||
173#endif
174#else
176 norm_type ==
L_INF ||
182#endif
183
184#ifdef DEBUG
185 if (var > 0)
186 {
187
188 bool is_valid_norm_combo =
201 ((norm_type ==
L_INF ||
208 }
209#endif
210
211
213
214
215 const FEType & fe_type = dof_map.variable_type (var);
216
217 const Order element_order = fe_type.order + elem->p_level();
218
219
221
222
223 std::unique_ptr<QBase> qrule =
225
226
227 fe->attach_quadrature_rule (qrule.get());
228
229
230 const std::vector<Real> & JxW = fe->get_JxW();
231 const std::vector<Point> & q_point = fe->get_xyz();
232
233
234
235
236
237 const std::vector<std::vector<Real>> * phi = nullptr;
238
239
240
241#ifdef NDEBUG
242 if (norm_type ==
L2 ||
244#endif
245 phi = &(fe->get_phi());
246
247 const std::vector<std::vector<RealGradient>> * dphi = nullptr;
253 dphi = &(fe->get_dphi());
254
255#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
256 const std::vector<std::vector<RealTensor>> * d2phi = nullptr;
259 d2phi = &(fe->get_d2phi());
260#endif
261
262
263 std::vector<dof_id_type> dof_indices;
264
265
266
267 unsigned int matsize = element_order + 1;
269 {
270 matsize *= (element_order + 2);
271 matsize /= 2;
272 }
274 {
275 matsize *= (element_order + 3);
276 matsize /= 3;
277 }
278
279 DenseMatrix<Number> Kp(matsize,matsize);
280 DenseVector<Number> F, Fx, Fy, Fz, Fxy, Fxz, Fyz;
281 DenseVector<Number> Pu_h, Pu_x_h, Pu_y_h, Pu_z_h, Pu_xy_h, Pu_xz_h, Pu_yz_h;
282 if (norm_type ==
L2 ||
284 {
285 F.resize(matsize); Pu_h.resize(matsize);
286 }
291 {
292 Fx.resize(matsize); Pu_x_h.resize(matsize);
293#if LIBMESH_DIM > 1
294 Fy.resize(matsize); Pu_y_h.resize(matsize);
295#endif
296#if LIBMESH_DIM > 2
297 Fz.resize(matsize); Pu_z_h.resize(matsize);
298#endif
299 }
301 {
302 Fx.resize(matsize); Pu_x_h.resize(matsize);
303 }
305 {
307 Fy.resize(matsize); Pu_y_h.resize(matsize);
308 }
310 {
312 Fz.resize(matsize); Pu_z_h.resize(matsize);
313 }
314
315#if LIBMESH_DIM > 1
318 {
319 Fxy.resize(matsize); Pu_xy_h.resize(matsize);
320#if LIBMESH_DIM > 2
321 Fxz.resize(matsize); Pu_xz_h.resize(matsize);
322 Fyz.resize(matsize); Pu_yz_h.resize(matsize);
323#endif
324 }
325#endif
326
327
328
329
330
331 for (const auto & e_p : patch)
332 {
333
334 fe->reinit (e_p);
335
336
337
338 dof_map.dof_indices (e_p, dof_indices, var);
340
341 const unsigned int n_dofs =
342 cast_int<unsigned int>(dof_indices.size());
343 const unsigned int n_qp = qrule->n_points();
344
345
346
347 for (unsigned int qp=0; qp<n_qp; qp++)
348 {
349
350 std::vector<Real> psi(
specpoly(
dim, element_order, q_point[qp], matsize));
351
352 const unsigned int psi_size = cast_int<unsigned int>(psi.size());
353
354
355 const unsigned int m = Kp.m(), n = Kp.n();
356 for (unsigned int i=0; i<m; i++)
357 for (unsigned int j=0; j<n; j++)
358 Kp(i,j) += JxW[qp]*psi[i]*psi[j];
359
360 if (norm_type ==
L2 ||
362 {
363
364
366
367 for (unsigned int i=0; i<n_dofs; i++)
369
370
371 for (unsigned int i=0; i != psi_size; i++)
372 F(i) = JxW[qp]*u_h*psi[i];
373
374 }
377 {
378
379
381
382 for (std::size_t i=0; i<n_dofs; i++)
385
386
387
388
389 for (unsigned int i=0; i != psi_size; i++)
390 {
391 Fx(i) += JxW[qp]*grad_u_h(0)*psi[i];
392#if LIBMESH_DIM > 1
393 Fy(i) += JxW[qp]*grad_u_h(1)*psi[i];
394#endif
395#if LIBMESH_DIM > 2
396 Fz(i) += JxW[qp]*grad_u_h(2)*psi[i];
397#endif
398 }
399 }
401 {
402
403
405
406 for (unsigned int i=0; i<n_dofs; i++)
409
410
411
412
413 for (unsigned int i=0; i != psi_size; i++)
414 {
415 Fx(i) += JxW[qp]*grad_u_h(0)*psi[i];
416 }
417 }
418#if LIBMESH_DIM > 1
420 {
421
422
424
425 for (unsigned int i=0; i<n_dofs; i++)
428
429
430
431
432 for (unsigned int i=0; i != psi_size; i++)
433 {
434 Fy(i) += JxW[qp]*grad_u_h(1)*psi[i];
435 }
436 }
437#endif
438#if LIBMESH_DIM > 2
440 {
441
442
444
445 for (unsigned int i=0; i<n_dofs; i++)
448
449
450
451
452 for (unsigned int i=0; i != psi_size; i++)
453 {
454 Fz(i) += JxW[qp]*grad_u_h(2)*psi[i];
455 }
456 }
457#endif
460 {
461#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
462
463
465
466 for (unsigned int i=0; i<n_dofs; i++)
469
470
471
472
473 for (unsigned int i=0; i != psi_size; i++)
474 {
475 Fx(i) += JxW[qp]*hess_u_h(0,0)*psi[i];
476#if LIBMESH_DIM > 1
477 Fy(i) += JxW[qp]*hess_u_h(1,1)*psi[i];
478 Fxy(i) += JxW[qp]*hess_u_h(0,1)*psi[i];
479#endif
480#if LIBMESH_DIM > 2
481 Fz(i) += JxW[qp]*hess_u_h(2,2)*psi[i];
482 Fxz(i) += JxW[qp]*hess_u_h(0,2)*psi[i];
483 Fyz(i) += JxW[qp]*hess_u_h(1,2)*psi[i];
484#endif
485 }
486#else
487 libmesh_error_msg("ERROR: --enable-second-derivatives is required \nfor _sobolev_order == 2!");
488#endif
489 }
490 else
492 }
493 }
494
495
496
497
498
499
500
501 if (norm_type ==
L2 ||
503 {
504 Kp.lu_solve(F, Pu_h);
505 }
510 {
511 Kp.lu_solve (Fx, Pu_x_h);
512#if LIBMESH_DIM > 1
513 Kp.lu_solve (Fy, Pu_y_h);
514#endif
515#if LIBMESH_DIM > 2
516 Kp.lu_solve (Fz, Pu_z_h);
517#endif
518 }
520 {
521 Kp.lu_solve (Fx, Pu_x_h);
522 }
524 {
525 Kp.lu_solve (Fy, Pu_y_h);
526 }
528 {
529 Kp.lu_solve (Fz, Pu_z_h);
530 }
531
532#if LIBMESH_DIM > 1
535 {
536 Kp.lu_solve(Fxy, Pu_xy_h);
537#if LIBMESH_DIM > 2
538 Kp.lu_solve(Fxz, Pu_xz_h);
539 Kp.lu_solve(Fyz, Pu_yz_h);
540#endif
541 }
542#endif
543
544
545
546
547
548 Patch::const_iterator patch_re_it;
549 Patch::const_iterator patch_re_end;
550
551
552 Patch patch_re(
mesh.processor_id());
553
555 {
556
557 patch_re_it = patch.begin();
558 patch_re_end = patch.end();
559 }
560 else
561 {
562
563
564 patch_re.build_around_element (elem, 0,
566
567
568 patch_re_it = patch_re.begin();
569 patch_re_end = patch_re.end();
570 }
571
572
573
574
575
576
577
578
579
580
581 FEMContext femcontext(
system,
nullptr,
582 false);
584
585
586 for (unsigned int e = 0 ; patch_re_it != patch_re_end; ++patch_re_it, ++e)
587 {
588
589
590
591 const Elem * e_p = *patch_re_it;
592
593
595
596
597 femcontext.pre_fe_reinit(
system, e_p);
598
599
600
601
602
603
605 continue;
606
607
608 fe->reinit (e_p);
609
610
611
612 dof_map.dof_indices (e_p, dof_indices, var);
614
615
616 const unsigned int n_dofs =
617 cast_int<unsigned int>(dof_indices.size());
618
619
620 Real element_error = 0;
621
622 const Order qorder = fe_type.order + e_p->p_level();
623
624
625 QGrid samprule (
dim, qorder);
626
629 fe->attach_quadrature_rule (&samprule);
630
631
632 const unsigned int n_sp =
633 cast_int<unsigned int>(JxW.size());
634
635
636 for (unsigned int sp=0; sp<n_sp; sp++)
637 {
638
639
640 std::vector<Number> temperr(6,0.0);
641
642 if (norm_type ==
L2 ||
644 {
645
647
648 for (unsigned int i=0; i<n_dofs; i++)
650
651
652 std::vector<Real> psi(
specpoly(
dim, element_order, q_point[sp], matsize));
653 for (unsigned int i=0; i<matsize; i++)
654 {
655 temperr[0] += psi[i]*Pu_h(i);
656 }
657
658 temperr[0] -= u_h;
659 }
662 {
663
665
666 for (unsigned int i=0; i<n_dofs; i++)
669
670
671 std::vector<Real> psi(
specpoly(
dim, element_order, q_point[sp], matsize));
672
673 for (unsigned int i=0; i<matsize; i++)
674 {
675 temperr[0] += psi[i]*Pu_x_h(i);
676#if LIBMESH_DIM > 1
677 temperr[1] += psi[i]*Pu_y_h(i);
678#endif
679#if LIBMESH_DIM > 2
680 temperr[2] += psi[i]*Pu_z_h(i);
681#endif
682 }
683 temperr[0] -= grad_u_h(0);
684#if LIBMESH_DIM > 1
685 temperr[1] -= grad_u_h(1);
686#endif
687#if LIBMESH_DIM > 2
688 temperr[2] -= grad_u_h(2);
689#endif
690 }
692 {
693
695
696 for (unsigned int i=0; i<n_dofs; i++)
699
700
701 std::vector<Real> psi(
specpoly(
dim, element_order, q_point[sp], matsize));
702 for (unsigned int i=0; i<matsize; i++)
703 {
704 temperr[0] += psi[i]*Pu_x_h(i);
705 }
706
707 temperr[0] -= grad_u_h(0);
708 }
709#if LIBMESH_DIM > 1
711 {
712
714
715 for (unsigned int i=0; i<n_dofs; i++)
718
719
720 std::vector<Real> psi(
specpoly(
dim, element_order, q_point[sp], matsize));
721 for (unsigned int i=0; i<matsize; i++)
722 {
723 temperr[1] += psi[i]*Pu_y_h(i);
724 }
725
726 temperr[1] -= grad_u_h(1);
727 }
728#endif
729#if LIBMESH_DIM > 2
731 {
732
734
735 for (unsigned int i=0; i<n_dofs; i++)
738
739
740 std::vector<Real> psi(
specpoly(
dim, element_order, q_point[sp], matsize));
741 for (unsigned int i=0; i<matsize; i++)
742 {
743 temperr[2] += psi[i]*Pu_z_h(i);
744 }
745
746 temperr[2] -= grad_u_h(2);
747 }
748#endif
751 {
752#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
753
755
756 for (unsigned int i=0; i<n_dofs; i++)
759
760
761 std::vector<Real> psi(
specpoly(
dim, element_order, q_point[sp], matsize));
762 for (unsigned int i=0; i<matsize; i++)
763 {
764 temperr[0] += psi[i]*Pu_x_h(i);
765#if LIBMESH_DIM > 1
766 temperr[1] += psi[i]*Pu_y_h(i);
767 temperr[3] += psi[i]*Pu_xy_h(i);
768#endif
769#if LIBMESH_DIM > 2
770 temperr[2] += psi[i]*Pu_z_h(i);
771 temperr[4] += psi[i]*Pu_xz_h(i);
772 temperr[5] += psi[i]*Pu_yz_h(i);
773#endif
774 }
775
776 temperr[0] -= hess_u_h(0,0);
777#if LIBMESH_DIM > 1
778 temperr[1] -= hess_u_h(1,1);
779 temperr[3] -= hess_u_h(0,1);
780#endif
781#if LIBMESH_DIM > 2
782 temperr[2] -= hess_u_h(2,2);
783 temperr[4] -= hess_u_h(0,2);
784 temperr[5] -= hess_u_h(1,2);
785#endif
786#else
787 libmesh_error_msg("ERROR: --enable-second-derivatives is required \nfor _sobolev_order == 2!");
788#endif
789 }
790
791
793
794
795
796
797
798 if (norm_type ==
L_INF)
799 element_error = std::max(element_error, std::abs(weight*temperr[0]));
801 for (unsigned int i=0; i != LIBMESH_DIM; ++i)
802 element_error = std::max(element_error, std::abs(weight*temperr[i]));
804 for (unsigned int i=0; i != 6; ++i)
805 element_error = std::max(element_error, std::abs(weight*temperr[i]));
806 else if (norm_type ==
L2)
809 for (unsigned int i=0; i != LIBMESH_DIM; ++i)
818 {
819 for (unsigned int i=0; i != LIBMESH_DIM; ++i)
821
822 for (unsigned int i=3; i != 6; ++i)
824 }
825
826 }
827
828 if (norm_type ==
L_INF ||
832 else if (norm_type ==
L2 ||
839 else
841 }
842
843 }
844
845
846
847
848
849
850
851 Patch::const_iterator patch_re_it;
852 Patch::const_iterator patch_re_end;
853
854
855 Patch current_elem_patch(
mesh.processor_id());
856
858 {
859
860 patch_re_it = patch.begin();
861 patch_re_end = patch.end();
862 }
863 else
864 {
865
866
867 current_elem_patch.build_around_element (elem, 0,
869
870
871 patch_re_it = current_elem_patch.begin();
872 patch_re_end = current_elem_patch.end();
873 }
874
875
876 for (unsigned int i = 0 ; patch_re_it != patch_re_end; ++patch_re_it, ++i)
877 {
878
879 const Elem * e_p = *patch_re_it;
880
881
883
884
891 {
895 (std::sqrt(new_error_per_cell[i]));
896 }
897 else
898 {
905 (new_error_per_cell[i]);
906 }
907
908 }
909
910
911 }
912
913}
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
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
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.
std::vector< FEMFunctionBase< Number > * > weight_functions
Vector of fem function base pointers, the user will fill this in with pointers to the appropriate wei...
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