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