Reference documentation for deal.II version 9.5.0
|
The ParsedConvergenceTable class. More...
#include <deal.II/base/parsed_convergence_table.h>
Public Member Functions | |
ParsedConvergenceTable (const std::vector< std::string > &component_names={"u"}, const std::vector< std::set< VectorTools::NormType > > &list_of_error_norms={ {VectorTools::H1_norm, VectorTools::L2_norm, VectorTools::Linfty_norm}}) | |
ParsedConvergenceTable (const std::vector< std::string > &component_names, const std::vector< std::set< VectorTools::NormType > > &list_of_error_norms, const double exponent, const std::set< std::string > &extra_columns, const std::string &rate_key, const std::string &rate_mode, const std::string &error_file_name, const unsigned int precision, const bool compute_error) | |
void | add_parameters (ParameterHandler &prm) |
template<int dim, int spacedim, typename VectorType > | |
void | error_from_exact (const DoFHandler< dim, spacedim > &vspace, const VectorType &solution, const Function< spacedim > &exact, const Function< spacedim > *weight=nullptr) |
template<int dim, int spacedim, typename VectorType > | |
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 | add_extra_column (const std::string &column_name, const std::function< double()> &custom_function, const bool compute_rate=true) |
template<int dim, int spacedim, typename VectorType > | |
void | difference (const DoFHandler< dim, spacedim > &, const VectorType &, const VectorType &, const Function< spacedim > *weight=nullptr) |
template<int dim, int spacedim, typename VectorType > | |
void | difference (const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &, const VectorType &, const VectorType &, const Function< spacedim > *weight=nullptr) |
void | output_table (std::ostream &out) |
void | output_table () |
Private Member Functions | |
void | prepare_table_for_output () |
Private Attributes | |
const std::vector< std::string > | component_names |
const std::vector< std::string > | unique_component_names |
const std::vector< ComponentMask > | unique_component_masks |
std::map< std::string, std::pair< std::function< double()>, bool > > | extra_column_functions |
std::vector< std::set< VectorTools::NormType > > | norms_per_unique_component |
double | exponent |
ConvergenceTable | table |
std::set< std::string > | extra_columns |
std::string | rate_key |
std::string | rate_mode |
unsigned int | precision |
std::string | error_file_name |
bool | compute_error |
The ParsedConvergenceTable class.
This class simplifies the construction of convergence tables, reading the options for the generation of the table from a parameter file. It provides a series of methods that can be used to compute the error given a reference exact solution, or the difference between two numerical solutions, or any other custom computation of the error, given via std::function objects.
An example usage of this class is given by
The above code constructs a ParsedConvergenceTable that works for scalar problems, and will produce an error table with H1_norm
, L2_norm
, and Linfty_norm
norms of the error.
Whenever a call to the methods error_from_exact() or difference() is made, the instance of this class inspects its parameters, computes all norms specified by the parameter given at construction time, possibly modified via a parameter file, computes all extra column entries specified using the method add_extra_column(), and writes one row of the convergence table.
Once you have finished with the computations, a call to output_table() will generate a formatted convergence table on the provided stream, and to the file (if any) specified in the parameter file.
With a small modification, the same code can be used to estimate the errors of mixed or multi-physics problems, e.g.:
The above code assumes that you are solving a Stokes problem with three components. Two components for the vector velocity field u
, and one component for the pressure field p
, and will produce an error table with H1
and L2
norm of the error in the velocity field (first two, components) and L2
error in the pressure field.
You may also call table.output_table()
without arguments, to write the table only to the file specified in the parameter file.
By calling the method add_parameters() passing a ParameterHandler object, the following options will be defined in the given ParameterHandler object (in the current level of the ParameterHandler object, i.e., whatever level you have entered with the ParameterHandler::enter_subsection() method), and can be modified at run time through a parameter file :
When using this class, please cite
Definition at line 136 of file parsed_convergence_table.h.
ParsedConvergenceTable::ParsedConvergenceTable | ( | const std::vector< std::string > & | component_names = {"u"} , |
const std::vector< std::set< VectorTools::NormType > > & | list_of_error_norms = { {VectorTools::H1_norm, VectorTools::L2_norm, VectorTools::Linfty_norm}} |
||
) |
Minimal constructor for ParsedConvergenceTable objects.
The number of components must match the number of components of the finite element space that is used to compute the errors. If a component name is repeated, than it is interpreted as a vector field, and the errors of the repeated components are grouped together.
The size of the vector list_of_error_norms
must match the number of unique component names, and may contain zero or more comma separated identifiers for the norm to compute for each component (see the documentation of VectorTools::NormType for the available options).
For example, the following constructor
would produce (if the parameter file is left untouched) a table similar to
See the other constructor for a documentation of all the parameters you can change.
component_names | Specify the names of the components; |
list_of_error_norms | Specify what error norms to compute for each unique component name. |
Definition at line 63 of file parsed_convergence_table.cc.
ParsedConvergenceTable::ParsedConvergenceTable | ( | const std::vector< std::string > & | component_names, |
const std::vector< std::set< VectorTools::NormType > > & | list_of_error_norms, | ||
const double | exponent, | ||
const std::set< std::string > & | extra_columns, | ||
const std::string & | rate_key, | ||
const std::string & | rate_mode, | ||
const std::string & | error_file_name, | ||
const unsigned int | precision, | ||
const bool | compute_error | ||
) |
Full constructor for ParsedConvergenceTable.
component_names | Names of the components. Repeated consecutive names are interpreted as components of a vector valued field; |
list_of_error_norms | Specify what error norms to compute for each unique component name; |
exponent | The exponent to use in p-norms; |
extra_columns | Extra columns to add. These may be "cells" or "dofs"; |
rate_key | Specify the extra column by which we will compute the error rates. This key can either be one of "cells" or "dofs", or, if you add extra columns to the table via the method add_extra_column(), it may be one of the extra columns you added; |
rate_mode | Specify the rate mode to use when computing error rates. This maybe either "reduction_rate", "reduction_rate_log2", or "none". See the documentation of ConvergenceTable::RateMode for an explanation of how each of this mode behaves; |
error_file_name | Name of error output file (with extension txt, gpl, tex, or org). If different from the empty string, than output_table() also writes in this file in the format deduced from its extension; |
precision | How many digits to use when writing the error; |
compute_error | Control whether the filling of the table is enabled or not. This flag may be used to disable at run time any error computation; |
The parameters you specify with this constructor can be written to a ParameterHandler object by calling the add_parameters() method. Once you call the add_parameters() method, the following options will be defined in the given ParameterHandler object, and the parameters of the instance of this class will follow the modification you make to the ParameterHandler object at run time:
Definition at line 79 of file parsed_convergence_table.cc.
void ParsedConvergenceTable::add_parameters | ( | ParameterHandler & | prm | ) |
Attach all the parameters in this class to entries of the parameter handler prm
. Whenever the content of prm
changes, the parameters of this class will be updated.
Definition at line 108 of file parsed_convergence_table.cc.
void ParsedConvergenceTable::error_from_exact | ( | const DoFHandler< dim, spacedim > & | vspace, |
const VectorType & | solution, | ||
const Function< spacedim > & | exact, | ||
const Function< spacedim > * | weight = nullptr |
||
) |
Add a row to the error table, containing the error between solution
and the exact
function, in the norm(s) specified in the parameter file.
If you specify a weight
function during this call, then this is used to compute weighted errors. The weight function can be either a scalar function (which will be used for all components), or a vector function. When it is a vector function, an assertion is triggered if the number of components does not coincide with the number of components of the underlying finite element space.
void ParsedConvergenceTable::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 |
||
) |
Same as above, with a different mapping.
void ParsedConvergenceTable::add_extra_column | ( | const std::string & | column_name, |
const std::function< double()> & | custom_function, | ||
const bool | compute_rate = true |
||
) |
Add an additional column (with name column_name
) to the table, by invoking the function custom_function
, when calling error_from_exact() or difference().
You can call this method as many times as you want. If column_name
was already used in a previous call, then calling this method with the same name will overwrite whatever function you had previously specified. If you use a lambda function for this call, make sure that the variables used internally in the lambda function remain valid until the call to error_from_exact() or difference().
Make sure you add all extra columns before the first call to error_from_exact() or difference(). Adding additional columns to the convergence table after you already started filling the table will trigger an exception.
This method may be used, for example, to compute the error w.r.t. to time step increments in time, for example:
will produce a table similar to
provided that you use the following parameter file (only non default entries are shown here):
column_name | Name of the column to add; |
custom_function | Function that will be called to fill the given entry. You need to make sure that the scope of this function is valid up to the call to error_from_exact() or difference(); |
compute_rate | If set to true, then this column will be included in the list of columns for which error rates are computed. You may want to set this to false if you want to compute error rates with respect to this column. In this case, you should also specify column_name as the rate key in the parameter file. |
Definition at line 263 of file parsed_convergence_table.cc.
void ParsedConvergenceTable::difference | ( | const DoFHandler< dim, spacedim > & | , |
const VectorType & | , | ||
const VectorType & | , | ||
const Function< spacedim > * | weight = nullptr |
||
) |
Difference between two solutions in the same vector space.
void ParsedConvergenceTable::difference | ( | const Mapping< dim, spacedim > & | mapping, |
const DoFHandler< dim, spacedim > & | , | ||
const VectorType & | , | ||
const VectorType & | , | ||
const Function< spacedim > * | weight = nullptr |
||
) |
Same as above, with a non default mapping.
void ParsedConvergenceTable::output_table | ( | std::ostream & | out | ) |
Write the error table to the out
stream (in text format), and (possibly) to the file stream specified in the parameters (with the format deduced from the file name extension).
Definition at line 216 of file parsed_convergence_table.cc.
void ParsedConvergenceTable::output_table | ( | ) |
Write the error table to the file stream specified in the parameters.
If the "Error file name" option in the parameter file is set to the empty string, no output is written.
Definition at line 229 of file parsed_convergence_table.cc.
|
private |
Add rates to the output table.
Definition at line 162 of file parsed_convergence_table.cc.
|
private |
Names of the solution components.
Definition at line 411 of file parsed_convergence_table.h.
|
private |
Same as above, but containing repeated component names only once.
Definition at line 416 of file parsed_convergence_table.h.
|
private |
Masks for each unique component name.
Definition at line 421 of file parsed_convergence_table.h.
|
private |
Additional methods to call when adding rows to the table.
Definition at line 427 of file parsed_convergence_table.h.
|
private |
Type of error to compute per components.
Definition at line 432 of file parsed_convergence_table.h.
|
private |
Exponent to use in p-norm types.
Definition at line 437 of file parsed_convergence_table.h.
|
private |
The actual table
Definition at line 442 of file parsed_convergence_table.h.
|
private |
Extra columns to add to the table.
Definition at line 447 of file parsed_convergence_table.h.
|
private |
The name of column with respect to which we compute convergence rates.
Definition at line 452 of file parsed_convergence_table.h.
|
private |
Reduction rate mode. See ConvergenceTable::RateMode for a documentation.
Definition at line 457 of file parsed_convergence_table.h.
|
private |
The precision used to output the table.
Definition at line 462 of file parsed_convergence_table.h.
|
private |
Filename to use when writing to file.
Definition at line 467 of file parsed_convergence_table.h.
|
private |
Compute the error. If this is false, all methods that perform the computation of the error are disabled and don't do anything.
Definition at line 473 of file parsed_convergence_table.h.