FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
meta_matrix_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#include <kernel/lafem/sparse_matrix_csr.hpp>
14#include <kernel/lafem/power_diag_matrix.hpp>
15#include <kernel/lafem/power_col_matrix.hpp>
16#include <kernel/lafem/power_row_matrix.hpp>
17#include <kernel/lafem/power_full_matrix.hpp>
18#include <kernel/lafem/saddle_point_matrix.hpp>
19#include <kernel/lafem/pointstar_factory.hpp>
20
21namespace FEAT
22{
23 namespace LAFEM
24 {
26 // Helper class: selects the matrix and vector types
27 template<typename DataType_, typename IndexType_>
28 struct MetaMatrixTestHelper
29 {
31 typedef DenseVector<DataType_, IndexType_> ScalarVector;
33 typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixA;
35 typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixB;
37 typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixD;
38 };
39
40// // CUDA specialization: There is no COO implementation, so we choose ELL for D matrices
41// template<typename DataType_, typename IndexType_>
42// struct MetaMatrixTestHelper<DataType_, IndexType_>
43// {
44// /// scalar vector type
45// typedef DenseVector<DataType_, IndexType_> ScalarVector;
46// /// scalar matrix type A
47// typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixA;
48// /// scalar matrix type B
49// typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixB;
50// /// scalar matrix type D
51// typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixD;
52// };
54
92 template<typename DataType_, typename IndexType_>
95 {
96 public:
97 typedef DataType_ DataType;
98 typedef IndexType_ IndexType;
99 typedef MetaMatrixTestHelper<DataType, IndexType> Helper;
100
102 typedef typename Helper::ScalarVector ScalarVector;
109
111 typedef typename Helper::ScalarMatrixA ScalarMatrixA;
113 typedef typename Helper::ScalarMatrixB ScalarMatrixB;
115 typedef typename Helper::ScalarMatrixD ScalarMatrixD;
116
125
129
130 explicit MetaMatrixTestBase(const String& id_in, const String datatype_name = "none", const String index_name = "none", PreferredBackend preferred_backend = PreferredBackend::generic)
131 : FEAT::TestSystem::UnitTest(id_in, datatype_name, index_name, preferred_backend)
132 {
133 }
134
136 static void gen_system(Index m, SystemDiagMatrix& mat_sys, SystemVector& vec_sol, SystemVector& vec_rhs)
137 {
141
145
146 // generate Q2-bubble and eigenvector
147 const DenseVector<DataType_, IndexType_> vec_eigen1(ps_fd.eigenvector_min());
148 const DenseVector<DataType_, IndexType_> vec_eigen2(ps_fd.eigenvector_min());
150
151 // set system matrix
152 mat_sys.template at<0,0>().template at<0,0>().convert(mat_fe);
153 mat_sys.template at<0,0>().template at<1,1>().convert(mat_fe);
154 mat_sys.template at<0,1>().template at<0,0>().convert(mat_fd);
155 mat_sys.template at<0,1>().template at<1,0>().convert(mat_fd);
156 mat_sys.template at<1,0>().template at<0,0>().convert(mat_fd);
157 mat_sys.template at<1,0>().template at<0,1>().convert(mat_fd);
158
159 // set solution vector
160 vec_sol.template at<0>().template at<0>().convert(vec_bubble); // u1
161 vec_sol.template at<0>().template at<1>().convert(vec_eigen1); // u2
162 vec_sol.template at<1>().convert(vec_eigen2); // p
163
164 // create vectors for rhs computation
165 DenseVector<DataType_, IndexType_> vec_rhs1(vec_bubble.size());
166 DenseVector<DataType_, IndexType_> vec_rhs2(vec_bubble.size());
167 DenseVector<DataType_, IndexType_> vec_rhs3(vec_bubble.size());
168
169 // compute rhs vector (by exploiting the eigenvector property)
170 mat_fe.apply(vec_rhs1, vec_bubble); // A11*u1
171 vec_rhs1.axpy(vec_eigen1, ps_fd.lambda_min()); // B1*p
172 vec_rhs2.scale(vec_eigen1, ps_fe.lambda_min() + ps_fd.lambda_min()); // A22*u2 + B2*p
173 mat_fd.apply(vec_rhs3, vec_bubble); // D1*u1
174 vec_rhs3.axpy(vec_eigen1, ps_fd.lambda_min()); // D2*u2
175
176 // set rhs vector
177 vec_rhs.template at<0>().template at<0>().convert(vec_rhs1);
178 vec_rhs.template at<0>().template at<1>().convert(vec_rhs2);
179 vec_rhs.template at<1>().convert(vec_rhs3);
180 }
181
183 static void gen_system(Index m, SystemFullMatrix& mat_sys, SystemVector& vec_sol, SystemVector& vec_rhs)
184 {
188
192
193 // generate Q2-bubble and eigenvector
194 const DenseVector<DataType_, IndexType_> vec_eigen1(ps_fd.eigenvector_min());
195 const DenseVector<DataType_, IndexType_> vec_eigen2(ps_fd.eigenvector_min());
197
198 // set system matrix
199 mat_sys.template at<0,0>().template at<0,0>().convert(mat_fe);
200 mat_sys.template at<0,0>().template at<1,1>().convert(mat_fe);
201 mat_sys.template at<0,0>().template at<0,1>().convert(mat_fd);
202 mat_sys.template at<0,0>().template at<1,0>().convert(mat_fd);
203 mat_sys.template at<0,1>().template at<0,0>().convert(mat_fd);
204 mat_sys.template at<0,1>().template at<1,0>().convert(mat_fd);
205 mat_sys.template at<1,0>().template at<0,0>().convert(mat_fd);
206 mat_sys.template at<1,0>().template at<0,1>().convert(mat_fd);
207
208 // set solution vector
209 vec_sol.template at<0>().template at<0>().convert(vec_bubble); // u1
210 vec_sol.template at<0>().template at<1>().convert(vec_eigen1); // u2
211 vec_sol.template at<1>().convert(vec_eigen2); // p
212
213 // create vectors for rhs computation
214 DenseVector<DataType_, IndexType_> vec_rhs1(vec_bubble.size());
215 DenseVector<DataType_, IndexType_> vec_rhs2(vec_bubble.size());
216 DenseVector<DataType_, IndexType_> vec_rhs3(vec_bubble.size());
217
218 // compute rhs vector (by exploiting the eigenvector property)
219 mat_fe.apply(vec_rhs1, vec_bubble); // A11*u1
220 mat_fd.apply(vec_rhs2, vec_bubble); // A21*u1
221 vec_rhs1.axpy(vec_eigen1, ps_fd.lambda_min() + ps_fd.lambda_min()); // A12*u2 + B1*p
222 vec_rhs2.axpy(vec_eigen1, ps_fe.lambda_min() + ps_fd.lambda_min()); // A22*u2 + B2*p
223 mat_fd.apply(vec_rhs3, vec_bubble); // D1*u1
224 vec_rhs3.axpy(vec_eigen1, ps_fd.lambda_min()); // D2*u2
225
226 // set rhs vector
227 vec_rhs.template at<0>().template at<0>().convert(vec_rhs1);
228 vec_rhs.template at<0>().template at<1>().convert(vec_rhs2);
229 vec_rhs.template at<1>().convert(vec_rhs3);
230 }
231 }; // MetaVectorTestBase
232 } // namespace LAFEM
233} // namespace FEAT
FEAT Kernel base header.
Index size() const
Returns the containers size.
Definition: container.hpp:1136
Dense data vector class template.
void scale(const DenseVector &x, const DT_ alpha)
Calculate .
void axpy(const DenseVector &x, const DT_ alpha=DT_(1))
Calculate .
Abstract base class for meta-matrix tests.
PowerFullMatrix< ScalarMatrixA, 2, 2 > VeloFullMatrix
velocity matrix type (full)
PowerRowMatrix< ScalarMatrixD, 2 > DiveMatrix
divergence matrix type
PowerVector< ScalarVector, 2 > VeloVector
velocity vector type
SaddlePointMatrix< VeloDiagMatrix, GradMatrix, DiveMatrix > SystemDiagMatrix
system matrix type
Helper::ScalarMatrixA ScalarMatrixA
scalar matrix type A
static void gen_system(Index m, SystemFullMatrix &mat_sys, SystemVector &vec_sol, SystemVector &vec_rhs)
generate test matrix with full velocity blocks
static void gen_system(Index m, SystemDiagMatrix &mat_sys, SystemVector &vec_sol, SystemVector &vec_rhs)
generate test matrix with diagonal velocity blocks
ScalarVector PresVector
pressure vector type
Helper::ScalarMatrixB ScalarMatrixB
scalar matrix type B
Helper::ScalarVector ScalarVector
scalar vector type
PowerDiagMatrix< ScalarMatrixA, 2 > VeloDiagMatrix
velocity matrix type (diagonal)
PowerColMatrix< ScalarMatrixB, 2 > GradMatrix
gradient matrix type
TupleVector< VeloVector, PresVector > SystemVector
system vector type
Helper::ScalarMatrixD ScalarMatrixD
scalar matrix type D
DenseVector< DataType_, IndexType_ > vector_q2_bubble() const
Computes a Q2-bubble vector.
virtual DenseVector< DataType_, IndexType_ > eigenvector_min() const
Computes the eigenvector of the smallest eigenvalue.
Finite-Differences pointstar matrix factory.
virtual DataType_ lambda_min() const override
Computes the smallest eigenvalue of the FD-style matrix.
virtual SparseMatrixCSR< DataType_, IndexType_ > matrix_csr() const override
Generates a FD-style pointstar CSR matrix.
Finite-Element pointstar matrix factory.
virtual DataType_ lambda_min() const override
Computes the smallest eigenvalue of the FE-style matrix.
virtual SparseMatrixCSR< DataType_, IndexType_ > matrix_csr() const override
Generates a FE-style pointstar CSR matrix.
Power-Col-Matrix meta class template.
Power-Diag-Matrix meta class template.
Power-Full-Matrix meta class template.
Power-Row-Matrix meta class template.
Power-Vector meta class template.
Saddle-Point matrix meta class template.
void convert(const SaddlePointMatrix< MatrixA2_, MatrixB2_, MatrixD2_ > &other)
Conversion method.
CSR based sparse matrix.
void apply(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
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
UnitTest(const String &id_in, const String &datatype_name="none", const String &index_name="none", PreferredBackend preferred_backend=PreferredBackend::generic)
CTOR.
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.