FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
pointstar_structure.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
8#include <kernel/util/math.hpp>
9#include <kernel/lafem/dense_vector.hpp>
10#include <kernel/lafem/sparse_matrix_banded.hpp>
11
12#include <stack>
13
14namespace FEAT
15{
16 namespace LAFEM
17 {
26 {
40 template<typename DataType_, typename IndexType_>
42 const std::vector<IndexType_> & num_of_subintervalls)
43 {
44 const IndexType_ * const pnos(num_of_subintervalls.data());
45
46 // get number of dimensions
47 const Index d(Index(num_of_subintervalls.size()));
48
49 // output of errors if wrong input
50 XASSERTM(d >= IndexType_(1), "You need at least 1 dimension");
51
52 for (IndexType_ i(0); i < d; ++i)
53 {
54 XASSERTM(pnos[i] >= IndexType_(3), "You need at least 3 subintervalls per dimension");
55 }
56
57 // calculate size of matrix and number of offsets
58 IndexType_ size(1);
59 Index noo(1);
60 if (fe_degree > Index(0))
61 {
62 for (Index i(0); i < d; ++i)
63 {
64 size *= pnos[i] * IndexType_(fe_degree) + 1;
65 noo *= 2 * fe_degree + 1;
66 }
67 }
68 else
69 {
70 for (Index i(0); i < d; ++i)
71 {
72 size *= pnos[i];
73 }
74 }
75
76 // allocate memory for vectors of matrix
78 DenseVector<DataType_, IndexType_> vec_val(noo * Index(size));
79
80 // fill offsets-vector
81 IndexType_ * const poffsets(vec_offsets.elements());
82 const Index h_off((noo - 1) / 2);
83
84 // save position of main-diagonal
85 poffsets[h_off] = size - IndexType_(1);
86
87 for (Index i(0), k(1), m(1); i < d; ++i, k *= 2 * fe_degree + 1, m *= pnos[i - 1] * fe_degree + 1)
88 {
89 Index k1((k - 1) / 2);
90
91 for (IndexType_ j(1); j <= fe_degree; ++j)
92 {
93 for (IndexType_ l(0); l < k; ++l)
94 {
95 poffsets[h_off - k1 + l + k * j] = poffsets[h_off - k1 + l] + IndexType_(j * m);
96 poffsets[h_off - k1 + l - k * j] = poffsets[h_off - k1 + l] - IndexType_(j * m);
97 }
98 }
99 }
100
101 // return the matrix
102 return SparseMatrixBanded<DataType_, IndexType_>(Index(size), Index(size), vec_val, vec_offsets);
103 }
104 }; // struct PointstarStructureFE
105
114 {
124 template<typename DataType_, typename IndexType_>
125 static SparseMatrixBanded<DataType_, IndexType_> value(const std::vector<IndexType_> & num_of_subintervalls)
126 {
127 const IndexType_ * const pnos(num_of_subintervalls.data());
128
129 const Index d(Index(num_of_subintervalls.size()) - 1);
130
131 // calculate dimension of the matrix
132 IndexType_ size(1);
133 for (Index i(1); i <= d; ++i)
134 {
135 size *= pnos[i] - 1;
136 }
137
138 // calculate number of offsets
139 const Index num_of_offsets(2 * d + 1);
140
141 // allocate memory for vectors of matrix
142 DenseVector<DataType_, IndexType_> vec_val(Index(size) * num_of_offsets);
143 DenseVector<IndexType_, IndexType_> vec_offsets(num_of_offsets);
144
145 // fill vec_offsets
146 IndexType_ * const poffsets(vec_offsets.elements());
147
148 poffsets[d] = IndexType_(size - 1);
149
150 Index tmp(1);
151 for (Index i(0); i < d; ++i)
152 {
153 tmp *= pnos[i] - 1;
154 poffsets[d - 1 - i] = size - IndexType_(1 + tmp);
155 poffsets[d + 1 + i] = size + IndexType_(tmp - 1);
156 }
157
158 // return the matrix
159 return SparseMatrixBanded<DataType_, IndexType_>(Index(size), Index(size), vec_val, vec_offsets);
160 }
161 }; // struct PointstarStructureFD
162
163 } // namespace LAFEM
164} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Dense data vector class template.
DT_ * elements()
Get a pointer to the data array.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.
empty Finite-Differences pointstar matrix creator.
static SparseMatrixBanded< DataType_, IndexType_ > value(const std::vector< IndexType_ > &num_of_subintervalls)
Generates an empty FD-style pointstar banded matrix.
empty Finite-Elements pointstar matrix creator.
static SparseMatrixBanded< DataType_, IndexType_ > value(const Index fe_degree, const std::vector< IndexType_ > &num_of_subintervalls)
Generates an empty FE-style pointstar banded matrix.