Debian Codegraph @

packages/seacas/applications/exodiff/Norm.h

raw
1 // Copyright(C) 1999-2020, 2022, 2023 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6 #pragma once
7
8 #include <cmath>
9 class Norm
10 {
11 public:
12 Norm() = default;
13
14 double diff(int order) const
15 {
16 if (order == 1) {
17 return l1_norm_d;
18 }
19 if (order == 2) {
20 return std::sqrt(l2_norm_d);
21 }
22 return 0.0;
23 }
24
25 double left(int order) const
26 {
27 if (order == 1) {
28 return l1_norm_1;
29 }
30 if (order == 2) {
31 return std::sqrt(l2_norm_1);
32 }
33 return 0.0;
34 }
35
36 double right(int order) const
37 {
38 if (order == 1) {
39 return l1_norm_2;
40 }
41 if (order == 2) {
42 return std::sqrt(l2_norm_2);
43 }
44 return 0.0;
45 }
46
47 double relative(int order) const
48 {
49 double l = left(order);
50 double r = right(order);
51 double lr_max = l > r ? l : r;
52 return diff(order) / lr_max;
53 }
54
55 void add_value(double val1, double val2)
56 {
57 l1_norm_d += std::fabs(val1 - val2);
58 l1_norm_1 += std::fabs(val1);
59 l1_norm_2 += std::fabs(val2);
60
61 l2_norm_d += (val1 - val2) * (val1 - val2);
62 l2_norm_1 += val1 * val1;
63 l2_norm_2 += val2 * val2;
64 }
65
66 double l1_norm_1{0.0};
67 double l1_norm_2{0.0};
68 double l1_norm_d{0.0};
69
70 double l2_norm_1{0.0};
71 double l2_norm_2{0.0};
72 double l2_norm_d{0.0};
73 };