FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
norm_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_NORM_GENERIC_HPP
8#define KERNEL_LAFEM_ARCH_NORM_GENERIC_HPP 1
9
10#ifndef KERNEL_LAFEM_ARCH_NORM_HPP
11#error "Do not include this implementation-only header file directly!"
12#endif
13
14#include <kernel/util/math.hpp>
15#include <cmath>
16
17namespace FEAT
18{
19 namespace LAFEM
20 {
21 namespace Arch
22 {
23 template <typename DT_>
24 DT_ Norm2::value_generic(const DT_ * const x, const Index size)
25 {
26 DT_ r(0);
27 FEAT_PRAGMA_OMP(parallel for reduction(+:r))
28 for (Index i = 0 ; i < size ; ++i)
29 {
30 r += x[i] * x[i];
31 }
32
33 return (DT_)Math::sqrt(r);
34 }
35
36 template <typename ValueType_>
37 ValueType_ Norm2::value_blocked_generic(const ValueType_ * const x, const Index size)
38 {
39 ValueType_ r(0);
40 FEAT_PRAGMA_OMP(parallel for)
41 for(int j = 0; j<ValueType_::n; ++j)
42 {
43 for (Index i(0) ; i < size ; ++i)
44 {
45 r[j] += x[i][j] * x[i][j];
46 }
47 r[j] = Math::sqrt(r[j]);
48 }
49 return r;
50 }
51
52 template <typename ValueType_>
53 ValueType_ Norm2Sqr::value_blocked_generic(const ValueType_ * const x, const Index size)
54 {
55 ValueType_ r(0);
56 FEAT_PRAGMA_OMP(parallel for)
57 for(int j = 0; j<ValueType_::n; ++j)
58 {
59 for (Index i(0) ; i < size ; ++i)
60 {
61 r[j] += x[i][j] * x[i][j];
62 }
63 }
64 return r;
65 }
66 } // namespace Arch
67 } // namespace LAFEM
68} // namespace FEAT
69
70#endif // KERNEL_LAFEM_ARCH_NORM_GENERIC_HPP
T_ sqrt(T_ x)
Returns the square-root of a value.
Definition: math.hpp:300
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.