Loading [MathJax]/extensions/TeX/newcommand.js
 deal.II version GIT relicensing-2850-g1646a780ac 2025-03-17 15:10:00+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\}}
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
convergence_table.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 1999 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
18
19#include <cmath>
20
22
23void
25 const std::string &data_column_key,
26 const std::string &reference_column_key,
27 const RateMode rate_mode,
28 const unsigned int dim)
29{
30 Assert(columns.count(data_column_key), ExcColumnNotExistent(data_column_key));
31 Assert(columns.count(reference_column_key),
32 ExcColumnNotExistent(reference_column_key));
33
34 if (rate_mode == none)
35 return;
36
37 // reset the auto fill mode flag since we are going to fill columns from
38 // the top that don't yet exist
39 set_auto_fill_mode(false);
40
41 const std::vector<internal::TableEntry> &entries =
42 columns[data_column_key].entries;
43 const std::vector<internal::TableEntry> &ref_entries =
44 columns[reference_column_key].entries;
45 std::string rate_key = data_column_key + "...";
46
47 const unsigned int n = entries.size();
48 const unsigned int n_ref = ref_entries.size();
49 Assert(n == n_ref, ExcDimensionMismatch(n, n_ref));
50
51 std::vector<double> values(n);
52 std::vector<double> ref_values(n_ref);
53
54 for (unsigned int i = 0; i < n; ++i)
55 {
56 values[i] = entries[i].get_numeric_value();
57 ref_values[i] = ref_entries[i].get_numeric_value();
58 }
59
60 unsigned int no_rate_entries = 0;
61
62 switch (rate_mode)
63 {
64 // case none: already considered above
65 case reduction_rate:
66 rate_key += "red.rate";
67 no_rate_entries = columns[rate_key].entries.size();
68 // Calculate all missing rate values:
69 for (unsigned int i = no_rate_entries; i < n; ++i)
70 {
71 if (i == 0)
72 {
73 // no value available for the first row
74 add_value(rate_key, "-");
75 }
76 else
77 {
78 add_value(rate_key,
79 values[i - 1] / values[i] * ref_values[i] /
80 ref_values[i - 1]);
81 }
82 }
83 break;
85 rate_key += "red.rate.log2";
86 no_rate_entries = columns[rate_key].entries.size();
87 // Calculate all missing rate values:
88 for (unsigned int i = no_rate_entries; i < n; ++i)
89 {
90 if (i == 0)
91 {
92 // no value available for the first row
93 add_value(rate_key, "-");
94 }
95 else
96 {
97 add_value(rate_key,
98 dim * std::log(std::fabs(values[i - 1] / values[i])) /
100 std::fabs(ref_values[i] / ref_values[i - 1])));
101 }
102 }
103 break;
104 default:
106 }
107
108 Assert(columns.count(rate_key), ExcInternalError());
109 columns[rate_key].flag = 1;
110 set_precision(rate_key, 2);
111
112 const std::string &superkey = data_column_key;
113 if (supercolumns.count(superkey) == 0u)
114 {
115 add_column_to_supercolumn(data_column_key, superkey);
116 set_tex_supercaption(superkey, columns[data_column_key].tex_caption);
117 }
118
119 // only add rate_key to the supercolumn once
120 if (no_rate_entries == 0)
121 {
122 add_column_to_supercolumn(rate_key, superkey);
123 }
124}
125
126
127
128void
129ConvergenceTable::evaluate_convergence_rates(const std::string &data_column_key,
130 const RateMode rate_mode)
131{
132 Assert(columns.count(data_column_key), ExcColumnNotExistent(data_column_key));
133
134 // reset the auto fill mode flag since we are going to fill columns from
135 // the top that don't yet exist
136 set_auto_fill_mode(false);
137
138 const std::vector<internal::TableEntry> &entries =
139 columns[data_column_key].entries;
140 std::string rate_key = data_column_key + "...";
141
142 const unsigned int n = entries.size();
143
144 std::vector<double> values(n);
145 for (unsigned int i = 0; i < n; ++i)
146 values[i] = entries[i].get_numeric_value();
147
148 unsigned int no_rate_entries = 0;
149
150 switch (rate_mode)
151 {
152 case none:
153 break;
154
155 case reduction_rate:
156 rate_key += "red.rate";
157 no_rate_entries = columns[rate_key].entries.size();
158 // Calculate all missing rate values:
159 for (unsigned int i = no_rate_entries; i < n; ++i)
160 {
161 if (i == 0)
162 {
163 // no value available for the first row
164 add_value(rate_key, "-");
165 }
166 else
167 {
168 add_value(rate_key, values[i - 1] / values[i]);
169 }
170 }
171 break;
172
174 rate_key += "red.rate.log2";
175 no_rate_entries = columns[rate_key].entries.size();
176 // Calculate all missing rate values:
177 for (unsigned int i = no_rate_entries; i < n; ++i)
178 {
179 if (i == 0)
180 {
181 // no value available for the first row
182 add_value(rate_key, "-");
183 }
184 else
185 {
186 add_value(rate_key,
187 std::log(std::fabs(values[i - 1] / values[i])) /
188 std::log(2.0));
189 }
190 }
191 break;
192
193 default:
195 }
196
197 Assert(columns.count(rate_key), ExcInternalError());
198 columns[rate_key].flag = 1;
199 set_precision(rate_key, 2);
200
201 // set the superkey equal to the key
202 const std::string &superkey = data_column_key;
203 // and set the tex caption of the supercolumn to the tex caption of the
204 // data_column.
205 if (supercolumns.count(superkey) == 0u)
206 {
207 add_column_to_supercolumn(data_column_key, superkey);
208 set_tex_supercaption(superkey, columns[data_column_key].tex_caption);
209 }
210
211 // only add rate_key to the supercolumn once
212 if (no_rate_entries == 0)
213 {
214 add_column_to_supercolumn(rate_key, superkey);
215 }
216}
217
218
219
220void
222 const std::string &key)
223{
224 Assert(columns.count(key), ExcColumnNotExistent(key));
225
226 const std::map<std::string, Column>::iterator col_iter = columns.find(key);
227 col_iter->second.flag = 1;
228}
229
230
231
232void
234 const std::string &reference_column_key,
235 const RateMode rate_mode)
236{
237 for (std::map<std::string, Column>::const_iterator col_iter = columns.begin();
238 col_iter != columns.end();
239 ++col_iter)
240 if (col_iter->second.flag == 0u)
241 evaluate_convergence_rates(col_iter->first,
242 reference_column_key,
243 rate_mode);
244}
245
246
247
248void
250{
251 for (std::map<std::string, Column>::const_iterator col_iter = columns.begin();
252 col_iter != columns.end();
253 ++col_iter)
254 if (col_iter->second.flag == 0u)
255 evaluate_convergence_rates(col_iter->first, rate_mode);
256}
257
void evaluate_all_convergence_rates(const std::string &reference_column_key, const RateMode rate_mode)
void evaluate_convergence_rates(const std::string &data_column_key, const std::string &reference_column_key, const RateMode rate_mode, const unsigned int dim=2)
void omit_column_from_convergence_rate_evaluation(const std::string &key)
void set_tex_supercaption(const std::string &superkey, const std::string &tex_supercaption)
void set_auto_fill_mode(const bool state)
void add_value(const std::string &key, const T value)
std::map< std::string, std::vector< std::string > > supercolumns
void add_column_to_supercolumn(const std::string &key, const std::string &superkey)
void set_precision(const std::string &key, const unsigned int precision)
std::map< std::string, Column > columns
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:40
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41
static ::ExceptionBase & ExcColumnNotExistent(std::string arg1)
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define AssertThrow(cond, exc)
::VectorizedArray< Number, width > log(const ::VectorizedArray< Number, width > &)