dune-composites (2.5.1)

geneobasis.hh
1#ifndef DUNE_GENEO_GENEOBASIS_HH
2#define DUNE_GENEO_GENEOBASIS_HH
3
4#include "subdomainbasis.hh"
5#include "arpackpp_fork.hh"
6
7namespace Dune{
8 namespace Geneo{
9
10 template<class GFS, class M, class X, class Y, class SI, int dim>
11 class GenEOBasis : public SubdomainBasis<X>
12 {
13 typedef Dune::PDELab::Backend::Native<M> ISTLM;
14 typedef Dune::PDELab::Backend::Native<X> ISTLX;
15
16 public:
17 GenEOBasis(const GFS& gfs, const M& AF_neumann, const M& AF_ovlp, const double eigenvalue_threshold, X& part_unity, SI& solver_info){//, SubdomainBasis<X>& localbasis2){
18 using Dune::PDELab::Backend::native;
19 M ovlp_mat(AF_ovlp);
20 // X * A_0 * X
21 for (auto row_iter = native(ovlp_mat).begin(); row_iter != native(ovlp_mat).end(); row_iter++) {
22 for (auto col_iter = row_iter->begin(); col_iter != row_iter->end(); col_iter++) {
23 *col_iter *= native(part_unity)[row_iter.index()] * native(part_unity)[col_iter.index()];
24 }
25 }
26
27 ArpackFork::ArPackPlusPlus_Algorithms<ISTLM, ISTLX> arpack(native(AF_neumann));
28 double eps = 0.0001;
29
30 if (solver_info.nev_arpack < solver_info.nev)
31 DUNE_THROW(Dune::ISTLError,"eigenvectors_compute is less then eigenvectors or not specified!");
32
33 std::vector<double> eigenvalues;
34 std::vector<ISTLX> eigenvectors;
35 eigenvectors.resize(solver_info.nev_arpack);
36 for (int i = 0; i < solver_info.nev_arpack; i++) {
37 eigenvectors[i] = native(X(gfs,0.0));
38 }
39
40 if (configuration.get<bool>("EigenvectorVTK",false)) {
41 for (int i = 0; i < solver_info.nev; i++) {
42 auto gv = gfs.gridView();
43 typedef typename GFS::Traits::GridView GV;
44 Dune::SubsamplingVTKWriter<GV> vtkwriter(gv,0);
45 X eigenvector(gfs, eigenvectors[i]);
46 Dune::PDELab::addSolutionToVTKWriter(vtkwriter,gfs,eigenvector);
47 vtkwriter.write("eigenvector"+std::to_string(i),Dune::VTK::appendedraw);
48 }
49 }
50
51 arpack.computeGenNonSymMinMagnitude(native(ovlp_mat), eps, solver_info.nev_arpack, eigenvectors, eigenvalues, solver_info.eigen_shift);
52
53 // Count eigenvectors below threshold
54 int cnt = -1; //int cnt2 = -1;
55 if (eigenvalue_threshold != 0) {
56 /*for (int i = 0; i < nev; i++) {
57 if (eigenvalues[i] > eigenvalue_threshold/configuration.get<double>("prec_threshhold",2)) {
58 cnt2 = i;
59 break;
60 }
61 }*/
62 for (int i = 0; i < solver_info.nev; i++) {
63 if (eigenvalues[i] > eigenvalue_threshold) {
64 cnt = i;
65 break;
66 }
67 }
68 std::cout << "Process " << gfs.gridView().comm().rank() << " picked " << cnt << " eigenvectors" << std::endl;
69
70 if (cnt == -1){
71 std:: cout << "No eigenvalue above threshold - not enough eigenvalue solves!" << std::endl;
72 cnt = solver_info.nev;
73 }
74 /*if (cnt2 == -1){
75 cnt2 = nev/configuration.get<double>("prec_threshhold",2);
76 }*/
77 }
78 else {
79 cnt = solver_info.nev;
80 //cnt2 = nev;
81 }
82
83 /*X numEV(gfs,cnt);
84 auto gv = gfs.gridView();
85 typedef typename GFS::Traits::GridView GV;
86 Dune::SubsamplingVTKWriter<GV> vtkwriter(gv,0);
87 Dune::PDELab::addSolutionToVTKWriter(vtkwriter,gfs,numEV);
88 vtkwriter.write("numEV",Dune::VTK::appendedraw);*/
89
90
91 this->local_basis.resize(cnt);
92 //localbasis2.local_basis.resize(cnt2);
93
94 for (int base_id = 0; base_id < cnt; base_id++) {
95 this->local_basis[base_id] = std::make_shared<X>(part_unity);
96 //if(base_id < cnt2) localbasis2.local_basis[base_id] = std::make_shared<X>(part_unity);
97 for (unsigned int it = 0; it < native(eigenvectors[base_id]).N(); it++) {
98 for(int j = 0; j < dim; j++){
99 native(*this->local_basis[base_id])[it][j] *= eigenvectors[base_id][it][j];
100 //if(base_id < cnt2) native(*localbasis2.local_basis[base_id])[it][j] *= eigenvectors[base_id][it][j];
101 }
102 }
103 }
104
105 if (configuration.get<bool>("AddPartUnityToEigenvectors",false) && eigenvalues[0] > 1E-10) {
106 auto part_unity_basis = std::make_shared<X>(gfs,0.0);
107 *part_unity_basis = part_unity;
108 this->local_basis.insert (this->local_basis.begin(), part_unity_basis);
109 this->local_basis.pop_back();
110 //localbasis2.local_basis.insert (localbasis2.local_basis.begin(), part_unity_basis);
111 //localbasis2.local_basis.pop_back();
112 }
113 }
114
115 };
116
117 }
118}
119
120#endif //DUNE_GENEO_GENEOBASIS_HH
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 5, 22:35, 2025)