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/lafem/dense_vector.hpp>
10#include <kernel/lafem/power_vector.hpp>
11#include <kernel/lafem/tuple_vector.hpp>
12#include <kernel/lafem/sparse_matrix_csr.hpp>
13#include <kernel/lafem/power_diag_matrix.hpp>
14#include <kernel/lafem/power_col_matrix.hpp>
15#include <kernel/lafem/power_row_matrix.hpp>
16#include <kernel/lafem/power_full_matrix.hpp>
17#include <kernel/lafem/saddle_point_matrix.hpp>
18#include <kernel/lafem/pointstar_factory.hpp>
19
20namespace FEAT
21{
22 namespace LAFEM
23 {
25 // Helper class: selects the matrix and vector types
26 template<typename DataType_, typename IndexType_>
27 struct MetaMatrixTestHelper
28 {
30 typedef DenseVector<DataType_, IndexType_> ScalarVector;
32 typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixA;
34 typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixB;
36 typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixD;
37 };
38
39// // CUDA specialization: There is no COO implementation, so we choose ELL for D matrices
40// template<typename DataType_, typename IndexType_>
41// struct MetaMatrixTestHelper<DataType_, IndexType_>
42// {
43// /// scalar vector type
44// typedef DenseVector<DataType_, IndexType_> ScalarVector;
45// /// scalar matrix type A
46// typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixA;
47// /// scalar matrix type B
48// typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixB;
49// /// scalar matrix type D
50// typedef SparseMatrixCSR<DataType_, IndexType_> ScalarMatrixD;
51// };
53
91 template<typename DataType_, typename IndexType_>
94 {
95 public:
96 typedef DataType_ DataType;
97 typedef IndexType_ IndexType;
98 typedef MetaMatrixTestHelper<DataType, IndexType> Helper;
99
101 typedef typename Helper::ScalarVector ScalarVector;
108
110 typedef typename Helper::ScalarMatrixA ScalarMatrixA;
112 typedef typename Helper::ScalarMatrixB ScalarMatrixB;
114 typedef typename Helper::ScalarMatrixD ScalarMatrixD;
115
124
128
129 explicit MetaMatrixTestBase(const String& id_in, const String datatype_name = "none", const String index_name = "none", PreferredBackend preferred_backend = PreferredBackend::generic)
130 : FEAT::TestSystem::UnitTest(id_in, datatype_name, index_name, preferred_backend)
131 {
132 }
133
135 static void gen_system(Index m, SystemDiagMatrix& mat_sys, SystemVector& vec_sol, SystemVector& vec_rhs)
136 {
140
144
145 // generate Q2-bubble and eigenvector
146 const DenseVector<DataType_, IndexType_> vec_eigen1(ps_fd.eigenvector_min());
147 const DenseVector<DataType_, IndexType_> vec_eigen2(ps_fd.eigenvector_min());
149
150 // set system matrix
151 mat_sys.template at<0,0>().template at<0,0>().convert(mat_fe);
152 mat_sys.template at<0,0>().template at<1,1>().convert(mat_fe);
153 mat_sys.template at<0,1>().template at<0,0>().convert(mat_fd);
154 mat_sys.template at<0,1>().template at<1,0>().convert(mat_fd);
155 mat_sys.template at<1,0>().template at<0,0>().convert(mat_fd);
156 mat_sys.template at<1,0>().template at<0,1>().convert(mat_fd);
157
158 // set solution vector
159 vec_sol.template at<0>().template at<0>().convert(vec_bubble); // u1
160 vec_sol.template at<0>().template at<1>().convert(vec_eigen1); // u2
161 vec_sol.template at<1>().convert(vec_eigen2); // p
162
163 // create vectors for rhs computation
164 DenseVector<DataType_, IndexType_> vec_rhs1(vec_bubble.size());
165 DenseVector<DataType_, IndexType_> vec_rhs2(vec_bubble.size());
166 DenseVector<DataType_, IndexType_> vec_rhs3(vec_bubble.size());
167
168 // compute rhs vector (by exploiting the eigenvector property)
169 mat_fe.apply(vec_rhs1, vec_bubble); // A11*u1
170 vec_rhs1.axpy(vec_eigen1, ps_fd.lambda_min()); // B1*p
171 vec_rhs2.scale(vec_eigen1, ps_fe.lambda_min() + ps_fd.lambda_min()); // A22*u2 + B2*p
172 mat_fd.apply(vec_rhs3, vec_bubble); // D1*u1
173 vec_rhs3.axpy(vec_eigen1, ps_fd.lambda_min()); // D2*u2
174
175 // set rhs vector
176 vec_rhs.template at<0>().template at<0>().convert(vec_rhs1);
177 vec_rhs.template at<0>().template at<1>().convert(vec_rhs2);
178 vec_rhs.template at<1>().convert(vec_rhs3);
179 }
180
182 static void gen_system(Index m, SystemFullMatrix& mat_sys, SystemVector& vec_sol, SystemVector& vec_rhs)
183 {
187
191
192 // generate Q2-bubble and eigenvector
193 const DenseVector<DataType_, IndexType_> vec_eigen1(ps_fd.eigenvector_min());
194 const DenseVector<DataType_, IndexType_> vec_eigen2(ps_fd.eigenvector_min());
196
197 // set system matrix
198 mat_sys.template at<0,0>().template at<0,0>().convert(mat_fe);
199 mat_sys.template at<0,0>().template at<1,1>().convert(mat_fe);
200 mat_sys.template at<0,0>().template at<0,1>().convert(mat_fd);
201 mat_sys.template at<0,0>().template at<1,0>().convert(mat_fd);
202 mat_sys.template at<0,1>().template at<0,0>().convert(mat_fd);
203 mat_sys.template at<0,1>().template at<1,0>().convert(mat_fd);
204 mat_sys.template at<1,0>().template at<0,0>().convert(mat_fd);
205 mat_sys.template at<1,0>().template at<0,1>().convert(mat_fd);
206
207 // set solution vector
208 vec_sol.template at<0>().template at<0>().convert(vec_bubble); // u1
209 vec_sol.template at<0>().template at<1>().convert(vec_eigen1); // u2
210 vec_sol.template at<1>().convert(vec_eigen2); // p
211
212 // create vectors for rhs computation
213 DenseVector<DataType_, IndexType_> vec_rhs1(vec_bubble.size());
214 DenseVector<DataType_, IndexType_> vec_rhs2(vec_bubble.size());
215 DenseVector<DataType_, IndexType_> vec_rhs3(vec_bubble.size());
216
217 // compute rhs vector (by exploiting the eigenvector property)
218 mat_fe.apply(vec_rhs1, vec_bubble); // A11*u1
219 mat_fd.apply(vec_rhs2, vec_bubble); // A21*u1
220 vec_rhs1.axpy(vec_eigen1, ps_fd.lambda_min() + ps_fd.lambda_min()); // A12*u2 + B1*p
221 vec_rhs2.axpy(vec_eigen1, ps_fe.lambda_min() + ps_fd.lambda_min()); // A22*u2 + B2*p
222 mat_fd.apply(vec_rhs3, vec_bubble); // D1*u1
223 vec_rhs3.axpy(vec_eigen1, ps_fd.lambda_min()); // D2*u2
224
225 // set rhs vector
226 vec_rhs.template at<0>().template at<0>().convert(vec_rhs1);
227 vec_rhs.template at<0>().template at<1>().convert(vec_rhs2);
228 vec_rhs.template at<1>().convert(vec_rhs3);
229 }
230 }; // MetaVectorTestBase
231 } // namespace LAFEM
232} // namespace FEAT
FEAT Kernel base header.
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 .
Index size() const
Returns the size of this vector, i.e. its number of entries.
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:47
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:18
std::uint64_t Index
Index data type.