FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
max_abs_index_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_ABS_INDEX_GENERIC_HPP
8#define KERNEL_LAFEM_ARCH_MAX_ABS_INDEX_GENERIC_HPP 1
9
10#ifndef KERNEL_LAFEM_ARCH_MAX_ABS_INDEX_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 Index MaxAbsIndex::value_generic(const DT_ * const x, const Index size)
24 {
25 DT_ max(0);
26 Index max_i(0);
27
28 for (Index i(0) ; i < size ; ++i)
29 {
30 if (Math::abs(x[i]) > max)
31 {
32 max = Math::abs(x[i]);
33 max_i = i;
34 }
35 }
36 return max_i;
37 }
38
39 template <typename ValueType_>
40 ValueType_ MaxAbsIndex::value_blocked_generic(const ValueType_ * const x, const Index size)
41 {
42 ValueType_ max(0);
43
44 if(size > 0)
45 {
46 for(int j(0); j < ValueType_::n; ++j)
47 {
48 max[j] = Math::abs(x[0][j]);
49 }
50 }
51
52 for (Index i(0) ; i < size ; ++i)
53 {
54 for(int j(0); j < ValueType_::n; ++j)
55 {
56 if(Math::abs(x[i][j]) > Math::abs(max[j]))
57 {
58 max[j] = Math::abs(x[i][j]);
59 }
60 }
61 }
62 return max;
63 }
64
65 } // namespace Arch
66 } // namespace LAFEM
67} // namespace FEAT
68
69#endif // KERNEL_LAFEM_ARCH_MAX_ABS_INDEX_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
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.