14#ifndef ACCURACY_TESTS_LNORMS_HPP
15#define ACCURACY_TESTS_LNORMS_HPP
24#include "Vector/vector_dist.hpp"
25#include "Grid/grid_dist_id.hpp"
42template <
size_t PropNumeric,
size_t PropAnalytic,
size_t Error,
typename gr
idtype>
45 auto dom =
grid.getDomainIterator();
46 typedef typename std::remove_const_t<std::remove_reference_t<
decltype(
47 grid.template get<PropNumeric>(dom.get()))>> numeric_type;
48 typedef typename std::remove_const_t<std::remove_reference_t<
decltype(
49 grid.template get<PropAnalytic>(dom.get()))>> analytic_type;
51 if(!(std::is_same<numeric_type, analytic_type>::value))
53 std::cout <<
"Type of numerical and analytical solution must be the same! Aborting..." << std::endl;
58 grid.template getProp<Error> (key) = abs(
grid.template getProp<PropAnalytic> (key) - (
grid.template getProp<PropNumeric> (key)));
74template <
size_t PropNumeric,
size_t PropAnalytic,
size_t Error,
typename gr
idtype>
77 auto dom =
grid.getDomainIterator();
78 typedef typename std::remove_const_t<std::remove_reference_t<
decltype(
79 grid.template get<PropNumeric>(dom.get()))>> numeric_type;
80 typedef typename std::remove_const_t<std::remove_reference_t<
decltype(
81 grid.template get<PropAnalytic>(dom.get()))>> analytic_type;
83 if(!(std::is_same<numeric_type, analytic_type>::value))
85 std::cout <<
"Type of numerical and analytical solution must be the same! Aborting..." << std::endl;
92 grid.template getProp<Error> (key) =
93 abs((
grid.template getProp<PropNumeric> (key) -
grid.template getProp<PropAnalytic> (key)) /
94 (
grid.template getProp<PropAnalytic> (key) + std::numeric_limits<analytic_type>::epsilon()));
103template <
typename lnorm_type=
double>
123 template <
size_t Error,
typename gr
idtype>
126 auto dom =
grid.getDomainIterator();
127 typedef typename std::remove_const_t<std::remove_reference_t<
decltype(
128 grid.template get<Error>(dom.get()))>> error_type;
130 error_type maxError = 0;
131 error_type sumErrorSq = 0;
135 auto key = dom.get();
136 sumErrorSq +=
grid.template getProp<Error> (key) *
grid.template getProp<Error> (key);
137 if (
grid.template getProp<Error> (key) > maxError) maxError =
grid.template getProp<Error> (key);
140 auto &v_cl = create_vcluster();
141 v_cl.sum(sumErrorSq);
144 l2 = (lnorm_type) sqrt( sumErrorSq / (error_type)
grid.size());
145 linf = (lnorm_type) maxError;
154 template <
size_t Error,
typename vectortype>
157 auto dom = vd.getDomainIterator();
158 typedef typename std::remove_const_t<std::remove_reference_t<
decltype(
159 vd.template getProp<Error>(dom.get()))>> error_type;
161 error_type maxError = 0;
162 error_type sumErrorSq = 0;
163 int count_particles = 0;
166 auto key = dom.get();
167 sumErrorSq += vd.template getProp<Error> (key) * vd.template getProp<Error> (key);
168 if (vd.template getProp<Error> (key) > maxError) maxError = vd.template getProp<Error> (key);
172 auto &v_cl = create_vcluster();
173 v_cl.sum(sumErrorSq);
174 v_cl.sum(count_particles);
177 l2 = (lnorm_type) sqrt( sumErrorSq / (error_type)count_particles);
178 linf = (lnorm_type) maxError;
188 template <
size_t Error,
typename gr
id_type>
191 auto dom =
grid.getDomainIterator();
192 typedef typename std::remove_const_t<std::remove_reference_t<
decltype(
193 grid.template getProp<Error>(dom.get()))>> error_type;
195 error_type maxError = 0;
196 error_type sumErrorSq = 0;
197 int count_points = 0;
200 auto key = dom.get();
201 sumErrorSq +=
grid.template getProp<Error> (key) *
grid.template getProp<Error> (key);
202 if (
grid.template getProp<Error> (key) > maxError) maxError =
grid.template getProp<Error> (key);
206 auto &v_cl = create_vcluster();
207 v_cl.sum(sumErrorSq);
208 v_cl.sum(count_points);
211 l2 = (lnorm_type) sqrt( sumErrorSq / (error_type)count_points);
212 linf = (lnorm_type) maxError;
225 template <
typename T>
228 const std::string & filename,
229 const std::string & path_output)
231 auto &v_cl = create_vcluster();
232 if (v_cl.rank() == 0)
234 std::string path_output_lnorm = path_output +
"/" + filename +
".csv";
238 l_out.open(path_output_lnorm, std::ios_base::app);
239 l_out << std::to_string(col_0)
Header file containing small mathematical help-functions that are needed e.g. for the Sussman redista...
std::string to_string_with_precision(const T myValue, const size_t n=6)
Converts value into string maintaining a desired precision.
void get_absolute_error(gridtype &grid)
At each grid node, the absolute error is computed and stored in another property.
void get_relative_error(gridtype &grid)
At each grid node, the relative error is computed and stored in another property.
Header file containing functions for creating files and folders.
static void create_file_if_not_exist(std::string path)
Creates a file if not already existent.
Class for computing the l2/l_infinity norm for distributed grids and vectors based on given errors.
void get_l_norms_vector(vectortype &vd)
Computes the L_2 and L_infinity norm on the basis of the precomputed error on a particle vector.
void get_l_norms(grid_type &grid)
Computes the L_2 and L_infinity norm from the error stored in a property on sparse grids,...
void write_to_file(const T col_0, const int precision, const std::string &filename, const std::string &path_output)
Writes the N (number of grid points on a square grid) and L-norms as strings to a csv-file.
void get_l_norms_grid(gridtype &grid)
Computes the L_2 and L_infinity norm on the basis of the precomputed error on a grid.
This is a distributed grid.