Hex: src/preconditioners/CGPreconditioner.h Source File

| Hex 2.2 Hydrogen-electron collision solver

CGPreconditioner.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_CGPRECONDITIONER_H
33 #define HEX_CGPRECONDITIONER_H
34
35 // --------------------------------------------------------------------------------- //
36
37 #include "NoPreconditioner.h"
38
39 // --------------------------------------------------------------------------------- //
40
48 class CGPreconditioner : public NoPreconditioner
49 {
50 public:
51
52 // run-time selection mechanism
53 preconditionerRunTimeSelectionDefinitions(CGPreconditioner, "cg")
54
55 // default constructor needed by the RTS mechanism
56 CGPreconditioner () {}
57
58 // constructor
59 CGPreconditioner
60 (
61 CommandLine const & cmd,
62 InputFile const & inp,
63 Parallel const & par,
64 AngularBasis const & ang,
65 Bspline const & bspline_inner,
66 Bspline const & bspline_full,
67 Bspline const & bspline_panel_x,
68 Bspline const & bspline_panel_y
69 ) : NoPreconditioner
70 (
71 cmd, inp, par, ang,
72 bspline_inner,
73 bspline_full,
74 bspline_panel_x,
75 bspline_panel_y
76 ),
77 n_(ang.states().size(), -1) {}
78
79 // description of the preconditioner
80 virtual std::string description () const;
81
82 // reuse parent definitions
83 using NoPreconditioner::setup;
84 using NoPreconditioner::update;
85 using NoPreconditioner::rhs;
86 using NoPreconditioner::multiply;
87
88 // declare own definitions
89 virtual void precondition (BlockArray<Complex> const & r, BlockArray<Complex> & z) const;
90 virtual void finish ();
91
92 // solve diagonal block
93 int solve_block (int ill, const cArrayView r, cArrayView z) const;
94
95 // inner CG driver
96 virtual void CG_init (int iblock) const;
97 virtual void CG_mmul (int iblock, const cArrayView p, cArrayView q) const;
98 virtual void CG_prec (int iblock, const cArrayView r, cArrayView z) const;
99 virtual void CG_exit (int iblock) const;
100
101 // inner CG callback routines
102 virtual Real CG_compute_norm (const cArrayView a) const;
103 virtual Complex CG_scalar_product (const cArrayView a, const cArrayView b) const;
104 virtual void CG_axby_operation (Complex a, cArrayView x, Complex b, const cArrayView y) const;
105 virtual void CG_constrain (cArrayView r) const;
106
107 protected:
108
109 // last iterations
110 mutable iArray n_;
111
112 // timing
113 mutable std::size_t us_axby_, us_mmul_, us_norm_, us_prec_, us_spro_;
114 };
115
116 // --------------------------------------------------------------------------------- //
117
118 #endif
CGPreconditioner::description
virtual std::string description() const
Description of the preconditioner.
Definition: CGPreconditioner.cpp:48
CGPreconditioner::preconditionerRunTimeSelectionDefinitions
preconditionerRunTimeSelectionDefinitions(CGPreconditioner, "cg") CGPreconditioner()
Definition: CGPreconditioner.h:53
NoPreconditioner
Solution driver without actual preconditioner.
Definition: NoPreconditioner.h:55
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
CGPreconditioner::precondition
virtual void precondition(BlockArray< Complex > const &r, BlockArray< Complex > &z) const
Precondition the equation.
Definition: CGPreconditioner.cpp:142
AngularBasis
Angular basis.
Definition: ang.h:44
NoPreconditioner::update
virtual void update(Real E)
Update the preconditioner for the next energy.
Definition: NoPreconditioner.cpp:498
CGPreconditioner::us_spro_
std::size_t us_spro_
Definition: CGPreconditioner.h:113
CGPreconditioner::CG_constrain
virtual void CG_constrain(cArrayView r) const
Definition: CGPreconditioner.cpp:438
CGPreconditioner::CG_compute_norm
virtual Real CG_compute_norm(const cArrayView a) const
Definition: CGPreconditioner.cpp:360
CommandLine
Command line parameters.
Definition: io.h:57
CGPreconditioner::us_axby_
std::size_t us_axby_
Definition: CGPreconditioner.h:113
CGPreconditioner::CG_exit
virtual void CG_exit(int iblock) const
Definition: CGPreconditioner.cpp:350
CGPreconditioner::n_
iArray n_
Definition: CGPreconditioner.h:110
NoPreconditioner::rhs
virtual void rhs(BlockArray< Complex > &chi, int ienergy, int instate) const
Calculate the right-hand side.
Definition: NoPreconditioner.cpp:821
CGPreconditioner::us_mmul_
std::size_t us_mmul_
Definition: CGPreconditioner.h:113
AngularBasis::states
std::vector< std::pair< int, int > > const & states() const
List of coupled angular states.
Definition: ang.h:55
CGPreconditioner::CG_init
virtual void CG_init(int iblock) const
Definition: CGPreconditioner.cpp:238
CGPreconditioner
CG iteration-based preconditioner.
Definition: CGPreconditioner.h:48
InputFile
Input parameters.
Definition: io.h:321
CGPreconditioner::CG_scalar_product
virtual Complex CG_scalar_product(const cArrayView a, const cArrayView b) const
Definition: CGPreconditioner.cpp:377
Parallel
MPI info.
Definition: parallel.h:50
CGPreconditioner::us_norm_
std::size_t us_norm_
Definition: CGPreconditioner.h:113
CGPreconditioner::finish
virtual void finish()
Clean up memory etc.
Definition: CGPreconditioner.cpp:354
NoPreconditioner::NoPreconditioner
NoPreconditioner(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: NoPreconditioner.cpp:56
CGPreconditioner::CG_prec
virtual void CG_prec(int iblock, const cArrayView r, cArrayView z) const
Definition: CGPreconditioner.cpp:345
CGPreconditioner::us_prec_
std::size_t us_prec_
Definition: CGPreconditioner.h:113
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
CGPreconditioner::CG_axby_operation
virtual void CG_axby_operation(Complex a, cArrayView x, Complex b, const cArrayView y) const
Definition: CGPreconditioner.cpp:396
NoPreconditioner::setup
virtual void setup()
Initialize the preconditioner.
Definition: NoPreconditioner.cpp:101
CGPreconditioner::solve_block
int solve_block(int ill, const cArrayView r, cArrayView z) const
Definition: CGPreconditioner.cpp:53
NoPreconditioner.h
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