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 for(Index i(0); i < n00; ++i)
92 r00(i, fx00(i));
93 for(Index i(0); i < n01; ++i)
94 r01(i, fx01(i));
95 for(Index i(0); i < n1; ++i)
96 r1(i, fx1(i));
97
98 // construct data vector
99 MetaVector x;
100 x.template at<0>().template at<0>().convert(r00);
101 x.template at<0>().template at<1>().convert(r01);
102 x.template at<1>().convert(r1);
103 return x;
104 }
105
106 // generate test-vector y
107 static MetaVector gen_vector_y(Index n00, Index n01, Index n1)
108 {
109 DenseVector<DataType, IndexType> r00(n00), r01(n01), r1(n1);
110
111 // fill vectors
112 for(Index i(0); i < n00; ++i)
113 r00(i, fy00(i));
114 for(Index i(0); i < n01; ++i)
115 r01(i, fy01(i));
116 for(Index i(0); i < n1; ++i)
117 r1(i, fy1(i));
118
119 // construct data vector
120 MetaVector y;
121 y.template at<0>().template at<0>().convert(r00);
122 y.template at<0>().template at<1>().convert(r01);
123 y.template at<1>().convert(r1);
124 return y;
125 }
126
127 // Generate test-vector z. It is crucial that z_i != 0
128 static MetaVector gen_vector_z(Index n00, Index n01, Index n1)
129 {
130 DenseVector<DataType, IndexType> r00(n00), r01(n01), r1(n1);
131
132 // fill vectors
133 for(Index i(0); i < n00; ++i)
134 r00(i, fz00(i));
135 for(Index i(0); i < n01; ++i)
136 r01(i, fz01(i));
137 for(Index i(0); i < n1; ++i)
138 r1(i, fz1(i));
139
140 // construct data vector
141 MetaVector z;
142 z.template at<0>().template at<0>().convert(r00);
143 z.template at<0>().template at<1>().convert(r01);
144 z.template at<1>().convert(r1);
145 return z;
146 }
147
148 // generate null vector
149 static MetaVector gen_vector_null(Index n00, Index n01, Index n1)
150 {
151 MetaVector x;
152 x.template at<0>().template at<0>() = ScalarVector(n00, DataType(0));
153 x.template at<0>().template at<1>() = ScalarVector(n01, DataType(0));
154 x.template at<1>() = ScalarVector(n1, DataType(0));
155 return x;
156 }
157 }; // MetaVectorTestBase
158 } // namespace LAFEM
159} // 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.
String class implementation.
Definition: string.hpp:46
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:124
std::uint64_t Index
Index data type.