FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
max_rel_diff_generic.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7#ifndef KERNEL_LAFEM_ARCH_MAX_REL_DIFF_GENERIC_HPP
8#define KERNEL_LAFEM_ARCH_MAX_REL_DIFF_GENERIC_HPP 1
9
10#ifndef KERNEL_LAFEM_ARCH_MAX_REL_DIFF_HPP
11#error "Do not include this implementation-only header file directly!"
12#endif
13
14#include <kernel/util/math.hpp>
15
16namespace FEAT
17{
18 namespace LAFEM
19 {
20 namespace Arch
21 {
22 template <typename DT_>
23 DT_ MaxRelDiff::value_generic(const DT_ * const x, const DT_ * const y, const Index size)
24 {
25 DT_ max(0);
26 static DT_ eps = Math::eps<DT_>();
27 DT_ tmp;
28
29 for (Index i(0) ; i < size ; ++i)
30 {
31 // |x_i-y_i|/max(|x_i|+|y_i|, eps)
32 tmp = Math::abs(x[i] - y[i]) / Math::max(Math::abs(x[i]) + Math::abs(y[i]), eps);
33 if (tmp > max)
34 {
35 max = tmp;
36 }
37 }
38 return max;
39 }
40
41 } // namespace Arch
42 } // namespace LAFEM
43} // namespace FEAT
44
45#endif // KERNEL_LAFEM_ARCH_MAX_REL_DIFF_GENERIC_HPP
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Definition: math.hpp:137
T_ eps()
Returns the machine precision constant for a floating-point data type.
Definition: math.hpp:787
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.