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 vec_val.format();
80
81 // fill offsets-vector
82 Memory::TypedView<IndexType_ > poffsets(vec_offsets.elements_view_w());
83 const Index h_off((noo - 1) / 2);
84
85 // save position of main-diagonal
86 poffsets[h_off] = size - IndexType_(1);
87
88 for (Index i(0), k(1), m(1); i < d; ++i, k *= 2 * fe_degree + 1, m *= pnos[i - 1] * fe_degree + 1)
89 {
90 Index k1((k - 1) / 2);
91
92 for (IndexType_ j(1); j <= fe_degree; ++j)
93 {
94 for (IndexType_ l(0); l < k; ++l)
95 {
96 poffsets[h_off - k1 + l + k * j] = poffsets[h_off - k1 + l] + IndexType_(j * m);
97 poffsets[h_off - k1 + l - k * j] = poffsets[h_off - k1 + l] - IndexType_(j * m);
98 }
99 }
100 }
101 poffsets.release();
102
103 // return the matrix
104 return SparseMatrixBanded<DataType_, IndexType_>(Index(size), Index(size), vec_val, vec_offsets);
105 }
106 }; // struct PointstarStructureFE
107
116 {
126 template<typename DataType_, typename IndexType_>
127 static SparseMatrixBanded<DataType_, IndexType_> value(const std::vector<IndexType_> & num_of_subintervalls)
128 {
129 const IndexType_ * const pnos(num_of_subintervalls.data());
130
131 const Index d(Index(num_of_subintervalls.size()) - 1);
132
133 // calculate dimension of the matrix
134 IndexType_ size(1);
135 for (Index i(1); i <= d; ++i)
136 {
137 size *= pnos[i] - 1;
138 }
139
140 // calculate number of offsets
141 const Index num_of_offsets(2 * d + 1);
142
143 // allocate memory for vectors of matrix
144 DenseVector<DataType_, IndexType_> vec_val(Index(size) * num_of_offsets);
145 DenseVector<IndexType_, IndexType_> vec_offsets(num_of_offsets);
146 vec_val.format();
147
148 // fill vec_offsets
149 {
150 Memory::TypedView<IndexType_> poffsets(vec_offsets.elements_view_w());
151
152 poffsets[d] = IndexType_(size - 1);
153
154 Index tmp(1);
155 for (Index i(0); i < d; ++i)
156 {
157 tmp *= pnos[i] - 1;
158 poffsets[d - 1 - i] = size - IndexType_(1 + tmp);
159 poffsets[d + 1 + i] = size + IndexType_(tmp - 1);
160 }
161 }
162
163 // return the matrix
164 return SparseMatrixBanded<DataType_, IndexType_>(Index(size), Index(size), vec_val, vec_offsets);
165 }
166 }; // struct PointstarStructureFD
167
168 } // namespace LAFEM
169} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
void format()
Reset all elements of the container to a given value or zero if missing.
Definition: container.hpp:831
Dense data vector class template.
Typed memory view class.
void release() const
Releases this view.
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.