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
72 
73  // default constructor needed by the RTS mechanism
75 
76  // constructor
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
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 
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
115  using CGPreconditioner::rhs;
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
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
virtual std::string description() const
Description of the preconditioner.
Definition: KPAPreconditioner.cpp:52
B-spline environment.
Definition: bspline.h:57
virtual void CG_mmul(int iblock, const cArrayView p, cArrayView q) const
Definition: CGPreconditioner.cpp:242
void unlock_kpa_access() const
Definition: KPAPreconditioner.cpp:215
virtual void precondition(BlockArray< Complex > const &r, BlockArray< Complex > &z) const
Precondition the equation.
Definition: CGPreconditioner.cpp:142
virtual void CG_prec(int iblock, const cArrayView r, cArrayView z) const
Definition: KPAPreconditioner.cpp:119
Angular basis.
Definition: ang.h:44
iArray refcount_proj_
Definition: KPAPreconditioner.h:137
virtual void update(Real E)
Update the preconditioner for the next energy.
Definition: NoPreconditioner.cpp:498
virtual void CG_constrain(cArrayView r) const
Definition: CGPreconditioner.cpp:438
void lock_kpa_access() const
Definition: KPAPreconditioner.cpp:208
Command line parameters.
Definition: io.h:57
int maxell
Definition: io.h:362
iArray refcount_atom_
Definition: KPAPreconditioner.h:137
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
virtual void CG_exit(int iblock) const
Definition: KPAPreconditioner.cpp:176
virtual void rhs(BlockArray< Complex > &chi, int ienergy, int instate) const
Calculate the right-hand side.
Definition: NoPreconditioner.cpp:821
cArrays workspace_
Definition: KPAPreconditioner.h:145
virtual void setup()
Initialize the preconditioner.
Definition: KPAPreconditioner.cpp:57
CG iteration-based preconditioner.
Definition: CGPreconditioner.h:48
Input parameters.
Definition: io.h:321
virtual ~KPACGPreconditioner()
Definition: KPAPreconditioner.h:103
MPI info.
Definition: parallel.h:50
KPA-preconditioned CG-preconditioner.
Definition: KPAPreconditioner.h:66
virtual void CG_init(int iblock) const
Definition: KPAPreconditioner.cpp:81
preconditionerRunTimeSelectionDefinitions(KPACGPreconditioner, "KPA") KPACGPreconditioner()
Definition: KPAPreconditioner.h:71
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
virtual void finish()
Clean up memory etc.
Definition: KPAPreconditioner.cpp:203
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