DUNE PDELab (2.7)

geneobasis.hh
1#ifndef DUNE_PDELAB_BACKEND_ISTL_GENEO_GENEOBASIS_HH
2#define DUNE_PDELAB_BACKEND_ISTL_GENEO_GENEOBASIS_HH
3
4#include <algorithm>
5#include <functional>
6
7#include <dune/pdelab/backend/istl/geneo/subdomainbasis.hh>
8#include <dune/pdelab/backend/istl/geneo/arpackpp_geneo.hh>
9
10#if HAVE_ARPACKPP
11
12namespace Dune {
13 namespace PDELab {
14
21 template<class GFS, class M, class X, int dim>
22 class GenEOBasis : public SubdomainBasis<X>
23 {
24 typedef Dune::PDELab::Backend::Native<M> ISTLM;
25 typedef Dune::PDELab::Backend::Native<X> ISTLX;
26
27 public:
28
42 GenEOBasis(const GFS& gfs, const M& AF_exterior, const M& AF_ovlp, const double eigenvalue_threshold, X& part_unity,
43 int& nev, int nev_arpack = -1, double shift = 0.001, bool add_part_unity = false, int verbose = 0) {
44 using Dune::PDELab::Backend::native;
45
46 if (nev_arpack == -1)
47 nev_arpack = std::max(nev, 2);
48 if (nev_arpack < nev)
49 DUNE_THROW(Dune::Exception,"nev_arpack is less then nev!");
50
51 // X * A_0 * X
52 M ovlp_mat(AF_ovlp);
53 for (auto row_iter = native(ovlp_mat).begin(); row_iter != native(ovlp_mat).end(); row_iter++) {
54 for (auto col_iter = row_iter->begin(); col_iter != row_iter->end(); col_iter++) {
55 *col_iter *= native(part_unity)[row_iter.index()] * native(part_unity)[col_iter.index()];
56 }
57 }
58
59 // Setup Arpack for solving generalized eigenproblem
60 ArpackGeneo::ArPackPlusPlus_Algorithms<ISTLM, X> arpack(native(AF_exterior));
61 double eps = 0.0;
62
63 std::vector<double> eigenvalues(nev_arpack,0.0);
64 std::vector<X> eigenvectors(nev_arpack,X(gfs,0.0));
65
66 arpack.computeGenNonSymMinMagnitude(native(ovlp_mat), eps, eigenvectors, eigenvalues, shift);
67
68 // Count eigenvectors below threshold
69 int cnt = -1;
70 if (eigenvalue_threshold >= 0) {
71 for (int i = 0; i < nev; i++) {
72 if (eigenvalues[i] > eigenvalue_threshold) {
73 cnt = i;
74 break;
75 }
76 }
77 if (verbose > 0)
78 std::cout << "Process " << gfs.gridView().comm().rank() << " picked " << cnt << " eigenvectors" << std::endl;
79 if (cnt == -1)
80 DUNE_THROW(Dune::Exception,"No eigenvalue above threshold - not enough eigenvalues computed!");
81 } else {
82 cnt = nev;
83 }
84
85 // Write results to basis
86 this->local_basis.resize(cnt);
87 for (int base_id = 0; base_id < cnt; base_id++) {
88 this->local_basis[base_id] = std::make_shared<X>(part_unity);
89 // scale partition of unity with eigenvector
90 std::transform(
91 this->local_basis[base_id]->begin(),this->local_basis[base_id]->end(),
92 eigenvectors[base_id].begin(),
93 this->local_basis[base_id]->begin(),
94 std::multiplies<>()
95 );
96 }
97
98 // Normalize basis vectors
99 for (auto& v : this->local_basis) {
100 *v *= 1.0 / v->two_norm2();
101 }
102
103 // Optionally add partition of unity to eigenvectors
104 // Only if there is no near-zero eigenvalue (that usually already corresponds to a partition of unity!)
105 if (add_part_unity && eigenvalues[0] > 1E-10) {
106 this->local_basis.insert (this->local_basis.begin(), std::make_shared<X>(part_unity));
107 this->local_basis.pop_back();
108 }
109 }
110 };
111
112
113 }
114}
115
116#endif
117
118#endif //DUNE_PDELAB_BACKEND_ISTL_GENEO_GENEOBASIS_HH
Base class for Dune-Exceptions.
Definition: exceptions.hh:94
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
Dune namespace.
Definition: alignedallocator.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Sep 17, 22:29, 2024)