deal.II version GIT relicensing-7058-gb35ee29762 2026-11-11 09:30: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
28#include <deal.II/grid/tria.h>
29
30#include <deal.II/lac/vector.h>
31
33
34#include <set>
35#include <string>
36#include <vector>
37
38
40
41#ifndef DOXYGEN
43#endif
44
128{
129public:
167 const std::vector<std::string> &component_names = {"u"},
168 const std::vector<std::set<VectorTools::NormType>> &list_of_error_norms = {
170
236 const std::vector<std::string> &component_names,
237 const std::vector<std::set<VectorTools::NormType>> &list_of_error_norms,
238 const double exponent,
239 const std::set<std::string> &extra_columns,
240 const std::string &rate_key,
241 const std::string &rate_mode,
242 const std::string &error_file_name,
243 const unsigned int precision,
244 const bool compute_error);
245
251 void
253
265 template <int dim, int spacedim, typename VectorType>
266 void
268 const VectorType &solution,
269 const Function<spacedim> &exact,
270 const Function<spacedim> *weight = nullptr);
271
275 template <int dim, int spacedim, typename VectorType>
276 void
278 const DoFHandler<dim, spacedim> &vspace,
279 const VectorType &solution,
280 const Function<spacedim> &exact,
281 const Function<spacedim> *weight = nullptr);
282
349 void
350 add_extra_column(const std::string &column_name,
351 const std::function<double()> &custom_function,
352 const bool compute_rate = true);
353
357 template <int dim, int spacedim, typename VectorType>
358 void
360 const VectorType &,
361 const VectorType &,
362 const Function<spacedim> *weight = nullptr);
363
367 template <int dim, int spacedim, typename VectorType>
368 void
371 const VectorType &,
372 const VectorType &,
373 const Function<spacedim> *weight = nullptr);
374
380 void
381 output_table(std::ostream &out);
382
389 void
390 output_table();
391
392private:
396 void
398
402 const std::vector<std::string> component_names;
403
407 const std::vector<std::string> unique_component_names;
408
412 const std::vector<ComponentMask> unique_component_masks;
413
417 std::map<std::string, std::pair<std::function<double()>, bool>>
419
423 std::vector<std::set<VectorTools::NormType>> norms_per_unique_component;
424
428 double exponent;
429
434
438 std::set<std::string> extra_columns;
439
443 std::string rate_key;
444
448 std::string rate_mode;
449
453 unsigned int precision;
454
458 std::string error_file_name;
459
465};
466
467
468
469#ifndef DOXYGEN
470// ============================================================
471// Template functions
472// ============================================================
473template <int dim, int spacedim, typename VectorType>
474void
476 const VectorType &solution1,
477 const VectorType &solution2,
478 const Function<spacedim> *weight)
479{
480 AssertThrow(solution1.size() == solution2.size(),
481 ExcDimensionMismatch(solution1.size(), solution2.size()));
482 VectorType solution(solution1);
483 solution -= solution2;
485 dh,
486 solution,
488 weight);
489}
490
491
492
493template <int dim, int spacedim, typename VectorType>
494void
497 const VectorType &solution1,
498 const VectorType &solution2,
499 const Function<spacedim> *weight)
500{
501 AssertThrow(solution1.size() == solution2.size(),
502 ExcDimensionMismatch(solution1.size(), solution2.size()));
503 VectorType solution(solution1);
504 solution -= solution2;
506 mapping,
507 dh,
508 solution,
510 weight);
511}
512
513
514
515template <int dim, int spacedim, typename VectorType>
516void
518 const VectorType &solution,
519 const Function<spacedim> &exact,
520 const Function<spacedim> *weight)
521{
523 dh,
524 solution,
525 exact,
526 weight);
527}
528
529
530
531template <int dim, int spacedim, typename VectorType>
532void
535 const VectorType &solution,
536 const Function<spacedim> &exact,
537 const Function<spacedim> *weight)
538{
539 const auto n_components = component_names.size();
540
541 if (compute_error)
542 {
543 AssertDimension(exact.n_components, n_components);
544 AssertDimension(dh.get_fe().n_components(), n_components);
545
548 const types::global_dof_index n_dofs = dh.n_dofs();
549
550 for (const auto &col : extra_columns)
551 if (col == "cells")
552 {
553 table.add_value("cells", n_active_cells);
554 table.set_tex_caption("cells", "\\# cells");
555 table.set_tex_format("cells", "r");
556 }
557 else if (col == "dofs")
558 {
559 table.add_value("dofs", n_dofs);
560 table.set_tex_caption("dofs", "\\# dofs");
561 table.set_tex_format("dofs", "r");
562 }
563
564 // A vector of zero std::functions with n_components components
565 const std::vector<std::function<double(const Point<spacedim> &)>>
566 zero_components(n_components,
567 [](const Point<spacedim> &) { return 0.0; });
568
569 // The default weight function, with n_components components
570 std::vector<std::function<double(const Point<spacedim> &)>>
571 weight_components(n_components,
572 [](const Point<spacedim> &) { return 1.0; });
573
574 if (weight != nullptr)
575 {
576 if (weight->n_components == 1)
577 {
578 for (auto &f : weight_components)
579 f = [&](const Point<spacedim> &p) { return weight->value(p); };
580 }
581 else
582 {
583 AssertDimension(weight->n_components, n_components);
584 for (unsigned int i = 0; i < n_components; ++i)
585 weight_components[i] = [&](const Point<spacedim> &p) {
586 return weight->value(p, i);
587 };
588 }
589 }
590
591 for (unsigned int i = 0; i < norms_per_unique_component.size(); ++i)
592 {
593 std::map<VectorTools::NormType, double> errors;
594
595 const auto &norms = norms_per_unique_component[i];
596 const auto &mask = unique_component_masks[i];
597
598 // Simple case first
599 if (norms.empty())
600 continue;
601
602 auto components_expr = zero_components;
603 for (unsigned int j = 0; j < n_components; ++j)
604 if (mask[j] == true)
605 components_expr[j] = weight_components[j];
606
608 components_expr);
609
610 Vector<float> difference_per_cell(
612
613 const auto q_gauss =
614 dh.get_fe().reference_cell().get_gauss_type_quadrature(
615 (dh.get_fe().degree + 1) * 2);
616
617 for (const auto &norm : norms)
618 {
619 difference_per_cell = 0;
621 dh,
622 solution,
623 exact,
624 difference_per_cell,
625 q_gauss,
626 norm,
627 &select_component,
628 exponent);
629
631 dh.get_triangulation(), difference_per_cell, norm, exponent);
632
633 std::string name = unique_component_names[i] + "_" +
635 std::string latex_name = "@f$\\| " + unique_component_names[i] +
636 " - " + unique_component_names[i] +
637 "_h \\|_{" +
638 Patterns::Tools::to_string(norm) + "}@f$";
639
640 table.add_value(name, errors[norm]);
642 table.set_scientific(name, true);
643 table.set_tex_caption(name, latex_name);
644 }
645 }
646
647 for (const auto &extra_col : extra_column_functions)
648 {
649 const double custom_error = extra_col.second.first();
650
651 std::string name = extra_col.first;
652 table.add_value(name, custom_error);
654 table.set_scientific(name, true);
655 }
656 }
657}
658
659#endif
660
662
663#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
ReferenceCell< dim > reference_cell() 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:15834