8#include <kernel/util/math.hpp>
9#include <kernel/lafem/dense_vector.hpp>
10#include <kernel/lafem/sparse_matrix_csr.hpp>
11#include <kernel/lafem/sparse_matrix_banded.hpp>
12#include <kernel/lafem/pointstar_structure.hpp>
25 template<
typename DataType_,
typename IndexType_>
37 XASSERTM(m >=
Index(3),
"You need at least 3 inner nodes per dimension");
99 const DataType_ xsf = DataType_(Math::pi<DataType_>()) / DataType_(
_m+1);
103 for(
Index i(0); i < neq; ++i)
105 for(
Index quo(1); quo < neq; quo *=
_m)
136 const DataType_ xsf = DataType_(1) / DataType_(
_m+1);
140 for(
Index i(0); i < neq; ++i)
142 for(
Index quo(1); quo < neq; quo *=
_m)
145 DataType_ x(xsf * DataType_(((i / quo) %
_m) +
Index(1)));
146 v[i] *= DataType_(4) * x * (DataType_(1) - x);
169 template<
typename DataType_,
typename IndexType_>
199 Index i,j,k,l,n,neq,nnze,bpl,rpb,rps,b;
200 IndexType_ *epr,*dor,*ior,*col_idx;
207 for(i = 1; i < d; ++i)
210 nnze += 2*(m-1) * neq;
223 data = data_view.
get_w();
227 epr = epr_view.
get_w();
231 dor = dor_view.
get_w();
235 ior = row_ptr_view.
get_w();
239 col_idx = col_idx_view.
get_w();
256 for(l = 0; l < d; ++l)
262 for(b = 0; b < bpl; ++b)
268 for(j = 0; j < rps; ++j)
272 for(i = 1; i < m - 1; ++i)
276 for(j = 0; j < rps; ++j)
285 for(j = 0; j < rps; ++j)
301 for(i = 0; i < neq; ++i)
303 ior[i+1] = ior[i] + epr[i];
308 const DataType_ v1 = DataType_(2*d);
309 const DataType_ v2 = DataType_(-1);
310 for(i = 0; i < neq; ++i)
313 for(j = ior[i]; j < dor[i]; ++j)
320 for(j = dor[i]+1; j < ior[i+1]; ++j)
329 for(i = 0; i < neq; ++i)
331 epr[i] = ior[i+1] - dor[i] - 1;
332 col_idx[dor[i]] = IndexType_(i);
351 for(l = 0; l < d; ++l)
357 for(b = 0; b < bpl; ++b)
363 for(i = 0; i < rpb - rps; ++i)
366 col_idx[dor[k+i]+epr[k+i]] = IndexType_(k + i + rps);
367 col_idx[dor[neq-k-i-1]-epr[k+i]] = IndexType_(neq - k - i - rps - 1);
370 for(i = 0; i < rpb - rps; ++i)
404 return DataType_(2) * DataType_(this->
_d) *
405 (DataType_(1) -
Math::cos(Math::pi<DataType_>() / DataType_(this->
_m+1)));
421 return DataType_(2) * DataType_(this->
_d) *
422 (DataType_(1) +
Math::cos(Math::pi<DataType_>() / DataType_(this->
_m+1)));
438 template<
typename DataType_,
typename IndexType_>
467 Index i,j,k,l,n,neq,nnze,bpl,rpb,rps,b;
468 IndexType_ *epr,*dor,*ior,*col_idx;
475 for(i = 1; i < d; i++)
490 data = data_view.
get_w();
494 epr = epr_view.
get_w();
498 dor = dor_view.
get_w();
502 ior = row_ptr_view.
get_w();
506 col_idx = col_idx_view.
get_w();
523 for(l = 0; l < d; ++l)
529 for(b = 0; b < bpl; ++b)
535 for(j = 0; j < rps; ++j)
539 for(i = 1; i < m - 1; ++i)
543 for(j = 0; j < rps; ++j)
545 dor[n+j] += epr[n+j];
552 for(j = 0; j < rps; ++j)
554 dor[n+j] += epr[n+j];
569 for(i = 0; i < neq; ++i)
571 ior[i+1] = ior[i] + epr[i];
577 for(i = 1; i < d; ++i)
579 const DataType_ v1 = DataType_(j -
Index(1));
580 const DataType_ v2 = DataType_(-1);
582 for(i = 0; i < neq; ++i)
585 for(j = ior[i]; j < dor[i]; ++j)
592 for(j = dor[i]+1; j < ior[i+1]; ++j)
599 for(i = 0; i < neq; ++i)
602 for(j = ior[i]; j < ior[i+1]; ++j)
603 col_idx[j] = IndexType_(neq+i);
613 for(l = d; l > 0; --l)
619 for(b = 0; b < bpl; ++b)
625 for(i = 0; i < rps; ++i)
627 for(n = 0; 2*n*epr[k+i] < ior[k+i+1]-ior[k+i]; ++n)
629 for(j = 0; j < epr[k+i]; ++j)
631 col_idx[ior[k+i]+2*n*epr[k+i]+j+epr[k+i]] += IndexType_(rps);
632 col_idx[ior[neq-k-i]-2*n*epr[k+i]-j-epr[k+i]-1] -= IndexType_(rps);
640 for(i = rps; i < rpb - rps; ++i)
642 for(n = 0; 3*n*epr[k+i] < ior[k+i+1]-ior[k+i]; ++n)
644 for(j = 0; j < epr[k+i]; ++j)
646 col_idx[ior[k+i]+3*n*epr[k+i]+j+2*epr[k+i]] += IndexType_(rps);
647 col_idx[ior[neq-k-i]-3*n*epr[k+i]-j-2*epr[k+i]-1] -= IndexType_(rps);
662 for(i = 0; i < nnze; ++i)
663 col_idx[i] -= IndexType_(neq);
690 const IndexType_ m = IndexType_(this->
_m);
699 const IndexType_ row = 0;
700 for(IndexType_ k(row_ptr[row]); k < row_ptr[row + 1]; ++k)
702 const IndexType_ col = col_idx[k];
704 val[k] = DataType_(4);
705 else if(col == row+1)
706 val[k] = DataType_(-1);
707 else if(col == row+m)
708 val[k] = DataType_(-1);
709 else if(col == row+m+1)
710 val[k] = DataType_(-2);
717 for(IndexType_ jj(1); jj + 1 < m; ++jj)
720 const IndexType_ row = jj;
721 for(IndexType_ k(row_ptr[row]); k < row_ptr[row + 1]; ++k)
723 const IndexType_ col = col_idx[k];
725 val[k] = DataType_(8);
726 else if(col+1 == row)
727 val[k] = DataType_(-1);
728 else if(col == row+1)
729 val[k] = DataType_(-1);
731 val[k] = DataType_(-2);
737 const IndexType_ row = m - 1;
738 for(IndexType_ k(row_ptr[row]); k < row_ptr[row + 1]; ++k)
740 const IndexType_ col = col_idx[k];
742 val[k] = DataType_(4);
743 else if(col+1 == row)
744 val[k] = DataType_(-1);
745 else if(col == row+m)
746 val[k] = DataType_(-1);
747 else if(col+1 == row+m)
748 val[k] = DataType_(-2);
756 for(IndexType_ ii(1); ii + 1 < m; ++ii)
760 const IndexType_ row = ii*m;
761 for(IndexType_ k(row_ptr[row]); k < row_ptr[row + 1]; ++k)
763 const IndexType_ col = col_idx[k];
765 val[k] = DataType_(8);
766 else if(col+m == row)
767 val[k] = DataType_(-1);
768 else if(col == row+m)
769 val[k] = DataType_(-1);
771 val[k] = DataType_(-2);
776 for(IndexType_ jj(1); jj + 1 < m; ++jj)
779 const IndexType_ row = ii*m + jj;
780 for(IndexType_ k(row_ptr[row]); k < row_ptr[row+1]; ++k)
781 val[k] = DataType_(col_idx[k] == row ? 16 : -2);
786 const IndexType_ row = ii*m + m - 1;
787 for(IndexType_ k(row_ptr[row]); k < row_ptr[row + 1]; ++k)
789 const IndexType_ col = col_idx[k];
791 val[k] = DataType_(8);
792 else if(col+m == row)
793 val[k] = DataType_(-1);
794 else if(col == row+m)
795 val[k] = DataType_(-1);
797 val[k] = DataType_(-2);
807 const IndexType_ row = (m-1)*m;
808 for(IndexType_ k(row_ptr[row]); k < row_ptr[row + 1]; ++k)
810 const IndexType_ col = col_idx[k];
812 val[k] = DataType_(4);
813 else if(col == row+1)
814 val[k] = DataType_(-1);
815 else if(col+m == row)
816 val[k] = DataType_(-1);
817 else if(col+m == row+1)
818 val[k] = DataType_(-2);
825 for(IndexType_ jj(1); jj + 1 < m; ++jj)
828 const IndexType_ row = (m-1)*m + jj;
829 for(IndexType_ k(row_ptr[row]); k < row_ptr[row + 1]; ++k)
831 const IndexType_ col = col_idx[k];
833 val[k] = DataType_(8);
834 else if(col+1 == row)
835 val[k] = DataType_(-1);
836 else if(col == row+1)
837 val[k] = DataType_(-1);
839 val[k] = DataType_(-2);
845 const IndexType_ row = (m-1)*m + m - 1;
846 for(IndexType_ k(row_ptr[row]); k < row_ptr[row + 1]; ++k)
848 const IndexType_ col = col_idx[k];
850 val[k] = DataType_(4);
851 else if(col+1 == row)
852 val[k] = DataType_(-1);
853 else if(col+m == row)
854 val[k] = DataType_(-1);
855 else if(col+m+1 == row)
856 val[k] = DataType_(-2);
873 const DataType_ c(
Math::cos(Math::pi<DataType_>() / DataType_(this->
_m+1)));
879 for(
Index i(0); i < this->
_d; ++i)
885 DataType_ y = DataType_(v);
886 for(
Index k(1); k < this->
_d; ++k)
888 (y *= c) += DataType_((v *= this->_d - k +
Index(1)) /= (
Index(2) * k));
891 return DataType_(a -
Index(1)) - c*y;
899 return DataType_(8) + DataType_(4)*
Math::sqr(
Math::cos(Math::pi<DataType_>() / DataType_(this->
_m+1)));
909 template<
typename DataType_,
typename IndexType_>
921 const std::vector<DataType_> & dimensions) :
1006 template<
typename DataType_,
typename IndexType_>
1020 const std::vector<DataType_> & dimensions) :
1035 const IndexType_ d(IndexType_(this->
_d));
1037 const DataType_ *
const pdim(this->
_dimensions.data());
1043 const IndexType_ neq(IndexType_(matrix.
num_rows()));
1050 DataType_ diagonal_entry(0);
1051 for (IndexType_ i(0); i < d; ++i)
1053 diagonal_entry += DataType_(2.0) *
Math::sqr(pdim[i] / DataType_(pnos[i + 1]));
1057 for (IndexType_ i(0); i < neq; ++i)
1059 pval[neq * d + i] = diagonal_entry;
1063 for (IndexType_ i(0), k(pnos[0] - 1); i < d; ++i, k *= pnos[i] - 1)
1065 const DataType_ subdiagonal_entry(-
Math::sqr(pdim[i] / DataType_(pnos[i + 1])));
1067 for (IndexType_ j(0); j < neq / k / (pnos[i + 1] - 1); ++j)
1069 const IndexType_ k1(neq * d + k * (pnos[i + 1] - 1) * j);
1070 const IndexType_ k2(neq * (i + 1));
1074 for (IndexType_ l(pnos[i] - 1); l > 0; --l)
1076 pval[k1 + k2 - l] = DataType_(0);
1077 pval[k1 - k2 - l + k] = DataType_(0);
1081 for (IndexType_ l(0); l < k * (pnos[i + 1] - 2); ++l)
1083 pval[k1 + l + k2] = subdiagonal_entry;
1084 pval[k1 + l - k2 + k] = subdiagonal_entry;
1107 DataType_ x(DataType_(0.0));
1109 const DataType_ *
const pdim(this->
_dimensions.data());
1111 for (
Index i(0); i < this->
_d; ++i)
1113 const DataType_ h(pdim[i] / DataType_(pnos[i + 1]));
1114 x +=
Math::sqr(h) * (DataType_(1.0) -
Math::cos(Math::pi<DataType_>() * h / pdim[i]));
1117 return DataType_(2) * x;
1132 DataType_ x(DataType_(0.0));
1134 const DataType_ *
const pdim(this->
_dimensions.data());
1136 for (
Index i(0); i < this->
_d; ++i)
1138 const DataType_ h(pdim[i] / DataType_(pnos[i + 1]));
1139 x +=
Math::sqr(h) * (DataType_(1.0) +
Math::cos(Math::pi<DataType_>() * h / pdim[i]));
1142 return DataType_(2) * x;
1152 for (
Index i(1); i <= d; ++i)
1154 size *= pnos[i] - 1;
1161 for(
Index i(0); i < size; ++i)
1163 for(
Index j(0), quo(1); j < d; ++j, quo *= pnos[j] - 1)
1166 const DataType_ xsf(Math::pi<DataType_>() / DataType_(pnos[j + 1]));
1167 v[i] *=
Math::sin(xsf * DataType_(((i / quo) % (pnos[j + 1] - 1)) +
Index(1)));
1189 const DataType_ *
const pdim(this->
_dimensions.data());
1193 for (
Index i(1); i <= d; ++i)
1195 size *= pnos[i] - 1;
1202 for(
Index i(0); i < size; ++i)
1204 for(
Index j(0), quo(1); j < d; ++j, quo *= pnos[j] - 1)
1207 const DataType_ xsf(pdim[j] / DataType_(pnos[j + 1]));
1210 DataType_ x(xsf * DataType_(((i / quo) % (pnos[j + 1] - 1)) +
Index(1)));
1212 v[i] *= DataType_(4) * x * (DataType_(1) - x);
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Dense data vector class template.
Pointstar factory base class.
virtual DenseVector< DataType_, IndexType_ > eigenvector_min() const =0
Computes the eigenvector of the smallest eigenvalue.
virtual DataType_ lambda_min() const =0
Computes the smallest eigenvalue of the pointstar matrix.
virtual DenseVector< DataType_, IndexType_ > vector_q2_bubble() const =0
Computes a Q2-bubble vector.
const std::vector< DataType_ > & _dimensions
vector with lengths of the n-dimensional hypercube
virtual DataType_ lambda_max() const =0
Computes the largest eigenvalue of the pointstar matrix.
virtual DataType_ spectral_cond() const
Computes the spectral condition number of the pointstar matrix.
const Index _d
number of dimensions
const std::vector< IndexType_ > & _num_of_subintervalls
vector with number of subintervalls per dimension (plus a leading 2).
virtual SparseMatrixBanded< DataType_, IndexType_ > matrix_banded() const =0
Computes the pointstar matrix in banded format.
Pointstar factory base class.
virtual DataType_ lambda_max() const =0
Computes the largest eigenvalue of the pointstar matrix.
Index _m
number of inner nodes per dimension
Index _d
number of dimensions
virtual SparseMatrixCSR< DataType_, IndexType_ > matrix_csr() const =0
Computes the pointstar matrix in CSR format.
DenseVector< DataType_, IndexType_ > vector_q2_bubble() const
Computes a Q2-bubble vector.
virtual DataType_ spectral_cond() const
Computes the spectral condition number of the pointstar matrix.
virtual DenseVector< DataType_, IndexType_ > eigenvector_min() const
Computes the eigenvector of the smallest eigenvalue.
virtual DataType_ lambda_min() const =0
Computes the smallest eigenvalue of the pointstar matrix.
Finite-Differences pointstar matrix factory.
DenseVector< DataType_, IndexType_ > vector_q2_bubble() const override
Computes a Q2-bubble vector.
virtual DataType_ lambda_min() const override
Computes the smallest eigenvalue of the FD-style matrix.
virtual SparseMatrixBanded< DataType_, IndexType_ > matrix_banded() const override
Generates a FD-style pointstar banded matrix.
virtual DataType_ lambda_max() const override
Computes the largest eigenvalue of the FD-style matrix.
virtual DenseVector< DataType_, IndexType_ > eigenvector_min() const override
Computes the eigenvector of the smallest eigenvalue.
PointstarFactoryFD2(const std::vector< IndexType_ > &num_of_subintervalls, const std::vector< DataType_ > &dimensions)
Creates the pointstar factory.
Finite-Differences pointstar matrix factory.
virtual DataType_ lambda_max() const override
Computes the largest eigenvalue of the FD-style matrix.
PointstarFactoryFD(Index m, Index d=Index(2))
Creates the pointstar 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.
PointstarFactoryFE(Index m)
Creates the pointstar factory.
virtual SparseMatrixCSR< DataType_, IndexType_ > matrix_csr_neumann() const
Generates a FE-style pointstar CSR matrix with Neumann boundaries.
virtual SparseMatrixCSR< DataType_, IndexType_ > matrix_csr() const override
Generates a FE-style pointstar CSR matrix.
virtual DataType_ lambda_max() const override
Computes the largest eigenvalue of the FE-style matrix.
Index num_rows() const
Retrieve matrix row count.
T_ * get_w()
Returns a typed pointer to the array that grants write (and read) access.
void release() const
Releases this view.
T_ sin(T_ x)
Returns the sine of a value.
T_ sqr(T_ x)
Returns the square of a value.
T_ cos(T_ x)
Returns the cosine of a value.
std::uint64_t Index
Index data type.