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
convergence_table.cc
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) 1999 - 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#include <deal.II/base/config.h>
14
19
20#include <Kokkos_Macros.hpp>
21
22#include <cmath>
23#include <map>
24#include <string>
25#include <utility>
26#include <vector>
27
29
30void
32 const std::string &data_column_key,
33 const std::string &reference_column_key,
34 const RateMode rate_mode,
35 const unsigned int dim)
36{
37 Assert(columns.count(data_column_key), ExcColumnNotExistent(data_column_key));
38 Assert(columns.count(reference_column_key),
39 ExcColumnNotExistent(reference_column_key));
40
41 if (rate_mode == none)
42 return;
43
44 // reset the auto fill mode flag since we are going to fill columns from
45 // the top that don't yet exist
46 set_auto_fill_mode(false);
47
48 const std::vector<internal::TableEntry> &entries =
49 columns[data_column_key].entries;
50 const std::vector<internal::TableEntry> &ref_entries =
51 columns[reference_column_key].entries;
52 std::string rate_key = data_column_key + "...";
53
54 const unsigned int n = entries.size();
55 const unsigned int n_ref = ref_entries.size();
56 Assert(n == n_ref, ExcDimensionMismatch(n, n_ref));
57
58 std::vector<double> values(n);
59 std::vector<double> ref_values(n_ref);
60
61 for (unsigned int i = 0; i < n; ++i)
62 {
63 values[i] = entries[i].get_numeric_value();
64 ref_values[i] = ref_entries[i].get_numeric_value();
65 }
66
67 unsigned int no_rate_entries = 0;
68
69 switch (rate_mode)
70 {
71 // case none: already considered above
72 case reduction_rate:
73 rate_key += "red.rate";
74 no_rate_entries = columns[rate_key].entries.size();
75 // Calculate all missing rate values:
76 for (unsigned int i = no_rate_entries; i < n; ++i)
77 {
78 if (i == 0)
79 {
80 // no value available for the first row
81 add_value(rate_key, "-");
82 }
83 else
84 {
85 add_value(rate_key,
86 values[i - 1] / values[i] * ref_values[i] /
87 ref_values[i - 1]);
88 }
89 }
90 break;
92 rate_key += "red.rate.log2";
93 no_rate_entries = columns[rate_key].entries.size();
94 // Calculate all missing rate values:
95 for (unsigned int i = no_rate_entries; i < n; ++i)
96 {
97 if (i == 0)
98 {
99 // no value available for the first row
100 add_value(rate_key, "-");
101 }
102 else
103 {
104 add_value(rate_key,
105 dim * std::log(std::fabs(values[i - 1] / values[i])) /
106 std::log(
107 std::fabs(ref_values[i] / ref_values[i - 1])));
108 }
109 }
110 break;
111 default:
113 }
114
115 Assert(columns.count(rate_key), ExcInternalError());
116 columns[rate_key].flag = 1;
117 set_precision(rate_key, 2);
118
119 const std::string &superkey = data_column_key;
120 if (supercolumns.count(superkey) == 0u)
121 {
122 add_column_to_supercolumn(data_column_key, superkey);
123 set_tex_supercaption(superkey, columns[data_column_key].tex_caption);
124 }
125
126 // only add rate_key to the supercolumn once
127 if (no_rate_entries == 0)
128 {
129 add_column_to_supercolumn(rate_key, superkey);
130 }
131}
132
133
134
135void
136ConvergenceTable::evaluate_convergence_rates(const std::string &data_column_key,
137 const RateMode rate_mode)
138{
139 Assert(columns.count(data_column_key), ExcColumnNotExistent(data_column_key));
140
141 // reset the auto fill mode flag since we are going to fill columns from
142 // the top that don't yet exist
143 set_auto_fill_mode(false);
144
145 const std::vector<internal::TableEntry> &entries =
146 columns[data_column_key].entries;
147 std::string rate_key = data_column_key + "...";
148
149 const unsigned int n = entries.size();
150
151 std::vector<double> values(n);
152 for (unsigned int i = 0; i < n; ++i)
153 values[i] = entries[i].get_numeric_value();
154
155 unsigned int no_rate_entries = 0;
156
157 switch (rate_mode)
158 {
159 case none:
160 break;
161
162 case reduction_rate:
163 rate_key += "red.rate";
164 no_rate_entries = columns[rate_key].entries.size();
165 // Calculate all missing rate values:
166 for (unsigned int i = no_rate_entries; i < n; ++i)
167 {
168 if (i == 0)
169 {
170 // no value available for the first row
171 add_value(rate_key, "-");
172 }
173 else
174 {
175 add_value(rate_key, values[i - 1] / values[i]);
176 }
177 }
178 break;
179
181 rate_key += "red.rate.log2";
182 no_rate_entries = columns[rate_key].entries.size();
183 // Calculate all missing rate values:
184 for (unsigned int i = no_rate_entries; i < n; ++i)
185 {
186 if (i == 0)
187 {
188 // no value available for the first row
189 add_value(rate_key, "-");
190 }
191 else
192 {
193 add_value(rate_key,
194 std::log(std::fabs(values[i - 1] / values[i])) /
195 std::log(2.0));
196 }
197 }
198 break;
199
200 default:
202 }
203
204 Assert(columns.count(rate_key), ExcInternalError());
205 columns[rate_key].flag = 1;
206 set_precision(rate_key, 2);
207
208 // set the superkey equal to the key
209 const std::string &superkey = data_column_key;
210 // and set the tex caption of the supercolumn to the tex caption of the
211 // data_column.
212 if (supercolumns.count(superkey) == 0u)
213 {
214 add_column_to_supercolumn(data_column_key, superkey);
215 set_tex_supercaption(superkey, columns[data_column_key].tex_caption);
216 }
217
218 // only add rate_key to the supercolumn once
219 if (no_rate_entries == 0)
220 {
221 add_column_to_supercolumn(rate_key, superkey);
222 }
223}
224
225
226
227void
229 const std::string &key)
230{
231 Assert(columns.count(key), ExcColumnNotExistent(key));
232
233 const std::map<std::string, Column>::iterator col_iter = columns.find(key);
234 col_iter->second.flag = 1;
235}
236
237
238
239void
241 const std::string &reference_column_key,
242 const RateMode rate_mode)
243{
244 for (std::map<std::string, Column>::const_iterator col_iter = columns.begin();
245 col_iter != columns.end();
246 ++col_iter)
247 if (col_iter->second.flag == 0u)
248 evaluate_convergence_rates(col_iter->first,
249 reference_column_key,
250 rate_mode);
251}
252
253
254
255void
257{
258 for (std::map<std::string, Column>::const_iterator col_iter = columns.begin();
259 col_iter != columns.end();
260 ++col_iter)
261 if (col_iter->second.flag == 0u)
262 evaluate_convergence_rates(col_iter->first, rate_mode);
263}
264
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:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
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 > &)