deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
parsed_convergence_table.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2019 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_base_parsed_convergence_table_h
14#define dealii_base_parsed_convergence_table_h
15
16#include <deal.II/base/config.h>
17
22
24
25#include <deal.II/fe/mapping.h>
26
27#include <deal.II/grid/tria.h>
28
29#include <deal.II/lac/vector.h>
30
32
33#include <set>
34#include <string>
35#include <vector>
36
37
39
40#ifndef DOXYGEN
42#endif
43
127{
128public:
166 const std::vector<std::string> &component_names = {"u"},
167 const std::vector<std::set<VectorTools::NormType>> &list_of_error_norms = {
169
235 const std::vector<std::string> &component_names,
236 const std::vector<std::set<VectorTools::NormType>> &list_of_error_norms,
237 const double exponent,
238 const std::set<std::string> &extra_columns,
239 const std::string &rate_key,
240 const std::string &rate_mode,
241 const std::string &error_file_name,
242 const unsigned int precision,
243 const bool compute_error);
244
250 void
252
264 template <int dim, int spacedim, typename VectorType>
265 void
267 const VectorType &solution,
268 const Function<spacedim> &exact,
269 const Function<spacedim> *weight = nullptr);
270
274 template <int dim, int spacedim, typename VectorType>
275 void
277 const DoFHandler<dim, spacedim> &vspace,
278 const VectorType &solution,
279 const Function<spacedim> &exact,
280 const Function<spacedim> *weight = nullptr);
281
348 void
349 add_extra_column(const std::string &column_name,
350 const std::function<double()> &custom_function,
351 const bool compute_rate = true);
352
356 template <int dim, int spacedim, typename VectorType>
357 void
359 const VectorType &,
360 const VectorType &,
361 const Function<spacedim> *weight = nullptr);
362
366 template <int dim, int spacedim, typename VectorType>
367 void
370 const VectorType &,
371 const VectorType &,
372 const Function<spacedim> *weight = nullptr);
373
379 void
380 output_table(std::ostream &out);
381
388 void
389 output_table();
390
391private:
395 void
397
401 const std::vector<std::string> component_names;
402
406 const std::vector<std::string> unique_component_names;
407
411 const std::vector<ComponentMask> unique_component_masks;
412
416 std::map<std::string, std::pair<std::function<double()>, bool>>
418
422 std::vector<std::set<VectorTools::NormType>> norms_per_unique_component;
423
427 double exponent;
428
433
437 std::set<std::string> extra_columns;
438
442 std::string rate_key;
443
447 std::string rate_mode;
448
452 unsigned int precision;
453
457 std::string error_file_name;
458
464};
465
466
467
468#ifndef DOXYGEN
469// ============================================================
470// Template functions
471// ============================================================
472template <int dim, int spacedim, typename VectorType>
473void
475 const VectorType &solution1,
476 const VectorType &solution2,
477 const Function<spacedim> *weight)
478{
479 AssertThrow(solution1.size() == solution2.size(),
480 ExcDimensionMismatch(solution1.size(), solution2.size()));
481 VectorType solution(solution1);
482 solution -= solution2;
484 dh,
485 solution,
487 weight);
488}
489
490
491
492template <int dim, int spacedim, typename VectorType>
493void
496 const VectorType &solution1,
497 const VectorType &solution2,
498 const Function<spacedim> *weight)
499{
500 AssertThrow(solution1.size() == solution2.size(),
501 ExcDimensionMismatch(solution1.size(), solution2.size()));
502 VectorType solution(solution1);
503 solution -= solution2;
505 mapping,
506 dh,
507 solution,
509 weight);
510}
511
512
513
514template <int dim, int spacedim, typename VectorType>
515void
517 const VectorType &solution,
518 const Function<spacedim> &exact,
519 const Function<spacedim> *weight)
520{
522 dh,
523 solution,
524 exact,
525 weight);
526}
527
528
529
530template <int dim, int spacedim, typename VectorType>
531void
534 const VectorType &solution,
535 const Function<spacedim> &exact,
536 const Function<spacedim> *weight)
537{
538 const auto n_components = component_names.size();
539
540 if (compute_error)
541 {
542 AssertDimension(exact.n_components, n_components);
543 AssertDimension(dh.get_fe().n_components(), n_components);
544
547 const types::global_dof_index n_dofs = dh.n_dofs();
548
549 for (const auto &col : extra_columns)
550 if (col == "cells")
551 {
552 table.add_value("cells", n_active_cells);
553 table.set_tex_caption("cells", "\\# cells");
554 table.set_tex_format("cells", "r");
555 }
556 else if (col == "dofs")
557 {
558 table.add_value("dofs", n_dofs);
559 table.set_tex_caption("dofs", "\\# dofs");
560 table.set_tex_format("dofs", "r");
561 }
562
563 // A vector of zero std::functions with n_components components
564 const std::vector<std::function<double(const Point<spacedim> &)>>
565 zero_components(n_components,
566 [](const Point<spacedim> &) { return 0.0; });
567
568 // The default weight function, with n_components components
569 std::vector<std::function<double(const Point<spacedim> &)>>
570 weight_components(n_components,
571 [](const Point<spacedim> &) { return 1.0; });
572
573 if (weight != nullptr)
574 {
575 if (weight->n_components == 1)
576 {
577 for (auto &f : weight_components)
578 f = [&](const Point<spacedim> &p) { return weight->value(p); };
579 }
580 else
581 {
582 AssertDimension(weight->n_components, n_components);
583 for (unsigned int i = 0; i < n_components; ++i)
584 weight_components[i] = [&](const Point<spacedim> &p) {
585 return weight->value(p, i);
586 };
587 }
588 }
589
590 for (unsigned int i = 0; i < norms_per_unique_component.size(); ++i)
591 {
592 std::map<VectorTools::NormType, double> errors;
593
594 const auto &norms = norms_per_unique_component[i];
595 const auto &mask = unique_component_masks[i];
596
597 // Simple case first
598 if (norms.empty())
599 continue;
600
601 auto components_expr = zero_components;
602 for (unsigned int j = 0; j < n_components; ++j)
603 if (mask[j] == true)
604 components_expr[j] = weight_components[j];
605
607 components_expr);
608
609 Vector<float> difference_per_cell(
611
612 QGauss<dim> q_gauss((dh.get_fe().degree + 1) * 2);
613
614 for (const auto &norm : norms)
615 {
616 difference_per_cell = 0;
618 dh,
619 solution,
620 exact,
621 difference_per_cell,
622 q_gauss,
623 norm,
624 &select_component,
625 exponent);
626
628 dh.get_triangulation(), difference_per_cell, norm, exponent);
629
630 std::string name = unique_component_names[i] + "_" +
632 std::string latex_name = "@f$\\| " + unique_component_names[i] +
633 " - " + unique_component_names[i] +
634 "_h \\|_{" +
635 Patterns::Tools::to_string(norm) + "}@f$";
636
637 table.add_value(name, errors[norm]);
639 table.set_scientific(name, true);
640 table.set_tex_caption(name, latex_name);
641 }
642 }
643
644 for (const auto &extra_col : extra_column_functions)
645 {
646 const double custom_error = extra_col.second.first();
647
648 std::string name = extra_col.first;
649 table.add_value(name, custom_error);
651 table.set_scientific(name, true);
652 }
653 }
654}
655
656#endif
657
659
660#endif
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
const Triangulation< dim, spacedim > & get_triangulation() const
types::global_dof_index n_dofs() const
const unsigned int degree
Definition fe_data.h:450
unsigned int n_components() const
const unsigned int n_components
Definition function.h:162
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
Abstract base class for mapping classes.
Definition mapping.h:318
The ParsedConvergenceTable class.
void add_extra_column(const std::string &column_name, const std::function< double()> &custom_function, const bool compute_rate=true)
void difference(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &, const VectorType &, const VectorType &, const Function< spacedim > *weight=nullptr)
void difference(const DoFHandler< dim, spacedim > &, const VectorType &, const VectorType &, const Function< spacedim > *weight=nullptr)
void add_parameters(ParameterHandler &prm)
void error_from_exact(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &vspace, const VectorType &solution, const Function< spacedim > &exact, const Function< spacedim > *weight=nullptr)
void error_from_exact(const DoFHandler< dim, spacedim > &vspace, const VectorType &solution, const Function< spacedim > &exact, const Function< spacedim > *weight=nullptr)
const std::vector< std::string > component_names
std::set< std::string > extra_columns
const std::vector< std::string > unique_component_names
std::vector< std::set< VectorTools::NormType > > norms_per_unique_component
const std::vector< ComponentMask > unique_component_masks
std::map< std::string, std::pair< std::function< double()>, bool > > extra_column_functions
Definition point.h:111
void set_tex_format(const std::string &key, const std::string &format="c")
void add_value(const std::string &key, const T value)
void set_tex_caption(const std::string &key, const std::string &tex_caption)
void set_scientific(const std::string &key, const bool scientific)
void set_precision(const std::string &key, const unsigned int precision)
virtual types::global_cell_index n_global_active_cells() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define AssertThrow(cond, exc)
const Mapping< dim, spacedim > & get_default_linear_mapping(const Triangulation< dim, spacedim > &triangulation)
Definition mapping.cc:314
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
double norm(const FEValuesBase< dim > &fe, const ArrayView< const std::vector< Tensor< 1, dim > > > &Du)
Definition divergence.h:469
std::string to_string(const T &t)
Definition patterns.h:2450
*  *  if(update_pressure &update_flags) *  compute_pressure(constitutive_request
*  *  *  *  std::vector< Number > ThermoPlasticMaterial< dim, ViscoplasticYieldLaw, Number >::get_state_parameters   const
double compute_global_error(const Triangulation< dim, spacedim > &tria, const InVector &cellwise_error, const NormType &norm, const double exponent=2.)
void integrate_difference(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const ReadVector< Number > &fe_function, const Function< spacedim, Number > &exact_solution, OutVector &difference, const Quadrature< dim > &q, const NormType &norm, const Function< spacedim, double > *weight=nullptr, const double exponent=2.)
unsigned int n_active_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
Definition tria.cc:15815