Hex: src/preconditioners/KPAPreconditioner.h Source File

| Hex 2.2 Hydrogen-electron collision solver

KPAPreconditioner.h
Go to the documentation of this file.
1 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2 // //
3 // / / / / __ \ \ / / //
4 // / /__ / / / _ \ \ \/ / //
5 // / ___ / | |/_/ / /\ \ //
6 // / / / / \_\ / / \ \ //
7 // //
8 // //
9 // Copyright (c) 2016, Jakub Benda, Charles University in Prague //
10 // //
11 // MIT License: //
12 // //
13 // Permission is hereby granted, free of charge, to any person obtaining a //
14 // copy of this software and associated documentation files (the "Software"), //
15 // to deal in the Software without restriction, including without limitation //
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense, //
17 // and/or sell copies of the Software, and to permit persons to whom the //
18 // Software is furnished to do so, subject to the following conditions: //
19 // //
20 // The above copyright notice and this permission notice shall be included //
21 // in all copies or substantial portions of the Software. //
22 // //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, //
27 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF //
28 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
29 // //
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31
32 #ifndef HEX_KPAPRECONDITIONER_H
33 #define HEX_KPAPRECONDITIONER_H
34
35 // --------------------------------------------------------------------------------- //
36
37 #include <deque>
38 #include <set>
39 #include <string>
40 #include <vector>
41
42 // --------------------------------------------------------------------------------- //
43
44 #include "hex-arrays.h"
45 #include "hex-matrix.h"
46
47 // --------------------------------------------------------------------------------- //
48
49 #include "CGPreconditioner.h"
50
51 // --------------------------------------------------------------------------------- //
52
66 class KPACGPreconditioner : public virtual CGPreconditioner
67 {
68 public:
69
70 // run-time selection mechanism
71 preconditionerRunTimeSelectionDefinitions(KPACGPreconditioner, "KPA")
72
73 // default constructor needed by the RTS mechanism
74 KPACGPreconditioner () {}
75
76 // constructor
77 KPACGPreconditioner
78 (
79 CommandLine const & cmd,
80 InputFile const & inp,
81 Parallel const & par,
82 AngularBasis const & ang,
83 Bspline const & bspline_inner,
84 Bspline const & bspline_full,
85 Bspline const & bspline_panel_x,
86 Bspline const & bspline_panel_y
87 ) : CGPreconditioner
88 (
89 cmd, inp, par, ang,
90 bspline_inner,
91 bspline_full,
92 bspline_panel_x,
93 bspline_panel_y
94 ),
95 refcount_atom_(inp.maxell + 1),
96 refcount_proj_(inp.maxell + 1)
97 {
98 #ifdef _OPENMP
99 omp_init_lock(&lck_);
100 #endif
101 }
102
103 virtual ~KPACGPreconditioner ()
104 {
105 #ifdef _OPENMP
106 omp_destroy_lock(&lck_);
107 #endif
108 }
109
110 // preconditioner description
111 virtual std::string description () const;
112
113 // reuse parent definitions
114 using CGPreconditioner::update;
115 using CGPreconditioner::rhs;
116 using CGPreconditioner::multiply;
117 using CGPreconditioner::precondition;
118 using CGPreconditioner::CG_mmul;
119 using CGPreconditioner::CG_constrain;
120
121 // declare own definitions
122 virtual void setup ();
123 virtual void finish ();
124
125 // inner CG callback (needed by parent)
126 virtual void CG_init (int iblock) const;
127 virtual void CG_prec (int iblock, const cArrayView r, cArrayView z) const;
128 virtual void CG_exit (int iblock) const;
129
130 protected:
131
132 // internal concurrent access lock
133 void lock_kpa_access () const;
134 void unlock_kpa_access () const;
135
136 // preconditioner data
137 mutable iArray refcount_atom_, refcount_proj_;
138
139 // memory access lock
140 #ifdef _OPENMP
141 mutable omp_lock_t lck_;
142 #endif
143
144 // workspace
145 mutable cArrays workspace_;
146 };
147
148 // --------------------------------------------------------------------------------- //
149
150 #endif
KPACGPreconditioner::description
virtual std::string description() const
Description of the preconditioner.
Definition: KPAPreconditioner.cpp:52
Bspline
B-spline environment.
Definition: bspline.h:57
CGPreconditioner::CG_mmul
virtual void CG_mmul(int iblock, const cArrayView p, cArrayView q) const
Definition: CGPreconditioner.cpp:242
KPACGPreconditioner::unlock_kpa_access
void unlock_kpa_access() const
Definition: KPAPreconditioner.cpp:215
CGPreconditioner::precondition
virtual void precondition(BlockArray< Complex > const &r, BlockArray< Complex > &z) const
Precondition the equation.
Definition: CGPreconditioner.cpp:142
KPACGPreconditioner::CG_prec
virtual void CG_prec(int iblock, const cArrayView r, cArrayView z) const
Definition: KPAPreconditioner.cpp:119
AngularBasis
Angular basis.
Definition: ang.h:44
KPACGPreconditioner::refcount_proj_
iArray refcount_proj_
Definition: KPAPreconditioner.h:137
NoPreconditioner::update
virtual void update(Real E)
Update the preconditioner for the next energy.
Definition: NoPreconditioner.cpp:498
CGPreconditioner.h
CGPreconditioner::CG_constrain
virtual void CG_constrain(cArrayView r) const
Definition: CGPreconditioner.cpp:438
KPACGPreconditioner::lock_kpa_access
void lock_kpa_access() const
Definition: KPAPreconditioner.cpp:208
CommandLine
Command line parameters.
Definition: io.h:57
InputFile::maxell
int maxell
Definition: io.h:362
KPACGPreconditioner::refcount_atom_
iArray refcount_atom_
Definition: KPAPreconditioner.h:137
KPACGPreconditioner::KPACGPreconditioner
KPACGPreconditioner(CommandLine const &cmd, InputFile const &inp, Parallel const &par, AngularBasis const &ang, Bspline const &bspline_inner, Bspline const &bspline_full, Bspline const &bspline_panel_x, Bspline const &bspline_panel_y)
Definition: KPAPreconditioner.h:78
KPACGPreconditioner::CG_exit
virtual void CG_exit(int iblock) const
Definition: KPAPreconditioner.cpp:176
NoPreconditioner::rhs
virtual void rhs(BlockArray< Complex > &chi, int ienergy, int instate) const
Calculate the right-hand side.
Definition: NoPreconditioner.cpp:821
KPACGPreconditioner::workspace_
cArrays workspace_
Definition: KPAPreconditioner.h:145
KPACGPreconditioner::setup
virtual void setup()
Initialize the preconditioner.
Definition: KPAPreconditioner.cpp:57
CGPreconditioner
CG iteration-based preconditioner.
Definition: CGPreconditioner.h:48
InputFile
Input parameters.
Definition: io.h:321
KPACGPreconditioner::~KPACGPreconditioner
virtual ~KPACGPreconditioner()
Definition: KPAPreconditioner.h:103
Parallel
MPI info.
Definition: parallel.h:50
KPACGPreconditioner
KPA-preconditioned CG-preconditioner.
Definition: KPAPreconditioner.h:66
KPACGPreconditioner::CG_init
virtual void CG_init(int iblock) const
Definition: KPAPreconditioner.cpp:81
KPACGPreconditioner::preconditionerRunTimeSelectionDefinitions
preconditionerRunTimeSelectionDefinitions(KPACGPreconditioner, "KPA") KPACGPreconditioner()
Definition: KPAPreconditioner.h:71
NoPreconditioner::multiply
virtual void multiply(BlockArray< Complex > const &p, BlockArray< Complex > &q, MatrixSelection::Selection tri=MatrixSelection::Both) const
Multiply by the matrix equation.
Definition: NoPreconditioner.cpp:1233
KPACGPreconditioner::finish
virtual void finish()
Clean up memory etc.
Definition: KPAPreconditioner.cpp:203
CGPreconditioner::CGPreconditioner
CGPreconditioner(CommandLine const &cmd, InputFile const &inp, Parallel const &par, AngularBasis const &ang, Bspline const &bspline_inner, Bspline const &bspline_full, Bspline const &bspline_panel_x, Bspline const &bspline_panel_y)
Definition: CGPreconditioner.h:60