FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
meta_vector_test_base.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
9// #include <kernel/archs.hpp>
10#include <kernel/lafem/dense_vector.hpp>
11#include <kernel/lafem/power_vector.hpp>
12#include <kernel/lafem/tuple_vector.hpp>
13
14namespace FEAT
15{
16 namespace LAFEM
17 {
23 template<typename DataType_, typename IndexType_>
26 {
27 public:
28 typedef DataType_ DataType;
29 typedef IndexType_ IndexType;
30
34
35 explicit MetaVectorTestBase(const String& id_in, const String datatype_name = "none", const String index_name = "none", PreferredBackend preferred_backend = PreferredBackend::generic)
36 : FEAT::TestSystem::UnitTest(id_in, datatype_name, index_name, preferred_backend)
37 {
38 }
39
40 static DataType fx00(Index i)
41 {
42 return DataType(0.2) * DataType(i);
43 }
44
45 static DataType fx01(Index i)
46 {
47 return DataType(2) - DataType(i);
48 }
49
50 static DataType fx1(Index i)
51 {
52 return DataType(0.01) * Math::sqr(DataType(i+1));
53 }
54
55 static DataType fy00(Index i)
56 {
57 return -DataType(3) + DataType(2*i);
58 }
59
60 static DataType fy01(Index i)
61 {
62 return DataType(1) + Math::sqrt(DataType(i+1));
63 }
64
65 static DataType fy1(Index i)
66 {
67 return DataType(1) + DataType(7) / DataType(i+1);
68 }
69
70 static DataType fz00(Index i)
71 {
72 return Math::sqr(DataType(i+1));
73 }
74
75 static DataType fz01(Index i)
76 {
77 return -DataType(5) - Math::sqrt(DataType(i+1));
78 }
79
80 static DataType fz1(Index i)
81 {
82 return - DataType(7) / DataType(i+1);
83 }
84
85 // generate test-vector x
86 static MetaVector gen_vector_x(Index n00, Index n01, Index n1)
87 {
88 DenseVector<DataType, IndexType> r00(n00), r01(n01), r1(n1);
89
90 // fill vectors
91 {
92 Memory::TypedView<DataType> vr00(r00.elements_view_w());
93 Memory::TypedView<DataType> vr01(r01.elements_view_w());
94 Memory::TypedView<DataType> vr1(r1.elements_view_w());
95 for(Index i(0); i < n00; ++i)
96 vr00[i] = fx00(i);
97 for(Index i(0); i < n01; ++i)
98 vr01[i] = fx01(i);
99 for(Index i(0); i < n1; ++i)
100 vr1[i] = fx1(i);
101 }
102
103 // construct data vector
104 MetaVector x;
105 x.template at<0>().template at<0>().convert(r00);
106 x.template at<0>().template at<1>().convert(r01);
107 x.template at<1>().convert(r1);
108 return x;
109 }
110
111 // generate test-vector y
112 static MetaVector gen_vector_y(Index n00, Index n01, Index n1)
113 {
114 DenseVector<DataType, IndexType> r00(n00), r01(n01), r1(n1);
115
116 // fill vectors
117 {
118 Memory::TypedView<DataType> vr00(r00.elements_view_w());
119 Memory::TypedView<DataType> vr01(r01.elements_view_w());
120 Memory::TypedView<DataType> vr1(r1.elements_view_w());
121 for(Index i(0); i < n00; ++i)
122 vr00[i] = fy00(i);
123 for(Index i(0); i < n01; ++i)
124 vr01[i] = fy01(i);
125 for(Index i(0); i < n1; ++i)
126 vr1[i] = fy1(i);
127 }
128
129
130 // construct data vector
131 MetaVector y;
132 y.template at<0>().template at<0>().convert(r00);
133 y.template at<0>().template at<1>().convert(r01);
134 y.template at<1>().convert(r1);
135 return y;
136 }
137
138 // Generate test-vector z. It is crucial that z_i != 0
139 static MetaVector gen_vector_z(Index n00, Index n01, Index n1)
140 {
141 DenseVector<DataType, IndexType> r00(n00), r01(n01), r1(n1);
142
143 // fill vectors
144 {
145 Memory::TypedView<DataType> vr00(r00.elements_view_w());
146 Memory::TypedView<DataType> vr01(r01.elements_view_w());
147 Memory::TypedView<DataType> vr1(r1.elements_view_w());
148 for(Index i(0); i < n00; ++i)
149 vr00[i] = fz00(i);
150 for(Index i(0); i < n01; ++i)
151 vr01[i] = fz01(i);
152 for(Index i(0); i < n1; ++i)
153 vr1[i] = fz1(i);
154 }
155
156 // construct data vector
157 MetaVector z;
158 z.template at<0>().template at<0>().convert(r00);
159 z.template at<0>().template at<1>().convert(r01);
160 z.template at<1>().convert(r1);
161 return z;
162 }
163
164 // generate null vector
165 static MetaVector gen_vector_null(Index n00, Index n01, Index n1)
166 {
167 MetaVector x;
168 x.template at<0>().template at<0>() = ScalarVector(n00, DataType(0));
169 x.template at<0>().template at<1>() = ScalarVector(n01, DataType(0));
170 x.template at<1>() = ScalarVector(n1, DataType(0));
171 return x;
172 }
173 }; // MetaVectorTestBase
174 } // namespace LAFEM
175} // namespace FEAT
FEAT Kernel base header.
Dense data vector class template.
Abstract base class for meta-vector tests.
Power-Vector meta class template.
Variadic TupleVector class template.
void convert(const TupleVector< First2_, Rest2_... > &other)
Conversion method.
Typed memory view class.
String class implementation.
Definition: string.hpp:47
base class for all Tests
T_ sqrt(T_ x)
Returns the square-root of a value.
Definition: math.hpp:300
T_ sqr(T_ x)
Returns the square of a value.
Definition: math.hpp:95
FEAT namespace.
Definition: adjactor.hpp:12
PreferredBackend
The backend that shall be used in all compute heavy calculations.
Definition: backend.hpp:18
std::uint64_t Index
Index data type.