Hex  2.2
Hydrogen-electron collision solver
solver.h
Go to the documentation of this file.
1 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2 // //
3 // / / / / __ \ \ / / //
4 // / /__ / / / _ \ \ \/ / //
5 // / ___ / | |/_/ / /\ \ //
6 // / / / / \_\ / / \ \ //
7 // //
8 // //
9 // Copyright (c) 2017, 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_ECS_SOLVER_H
33 #define HEX_ECS_SOLVER_H
34 
35 // --------------------------------------------------------------------------------- //
36 
37 #include <vector>
38 
39 // --------------------------------------------------------------------------------- //
40 
41 #include "hex-itersolve.h"
42 
43 // --------------------------------------------------------------------------------- //
44 
45 #include "ang.h"
46 #include "bspline.h"
47 #include "io.h"
48 #include "parallel.h"
49 #include "preconditioners.h"
50 
51 // --------------------------------------------------------------------------------- //
52 
53 class Solver
54 {
55  public:
56 
58  Solver
59  (
60  CommandLine & cmd,
61  InputFile const & inp,
62  Parallel const & par,
63  AngularBasis const & ang,
64  Bspline const & bspline_inner,
65  Bspline const & bspline_full
66  );
67 
69  void choose_preconditioner ();
70 
72  void setup_preconditioner ();
73 
75  void solve ();
76 
78  void finish ();
79 
80  protected:
81 
82  // CG preconditioner callback
83  void apply_preconditioner_ (BlockArray<Complex> const & r, BlockArray<Complex> & z) const;
84 
85  // CG matrix multiplication callback
86  void matrix_multiply_ (BlockArray<Complex> const & p, BlockArray<Complex> & q) const;
87 
88  // CG scalar product function callback
89  Complex scalar_product_ (BlockArray<Complex> const & x, BlockArray<Complex> const & y) const;
90 
91  // CG norm function that broadcasts master's result to all nodes
92  Real compute_norm_ (BlockArray<Complex> const & r) const;
93 
94  // CG linear combination
95  void axby_operation_ (Complex a, BlockArray<Complex> & x, Complex b, BlockArray<Complex> const & y) const;
96 
97  // CG new array
98  BlockArray<Complex> new_array_ (std::size_t N, std::string name) const;
99 
100  // CG optional write current solution
101  void process_solution_ (unsigned iteration, BlockArray<Complex> const & x) const;
102 
103  // concatenate previous-panel full solution and new single-panel solution
104  void concatenate_panels_ (cArray & psi, cArray const & psip) const;
105 
106  private:
107 
109  CommandLine & cmd_;
110 
112  InputFile const & inp_;
113 
115  Parallel const & par_;
116 
118  AngularBasis ang_;
119 
121  Bspline const & bspline_inner_;
122  Bspline const & bspline_full_;
123 
125  PreconditionerBase * prec_;
126 
128  ConjugateGradients <Complex, cBlockArray, cBlockArray&> CG_;
129 
131  int ni_, li_, mi_;
132  Real E_;
133 
135  std::vector<std::pair<iArray,iArray>> bstates_;
136 
138  std::vector<std::pair<int,int>> channels_;
139 };
140 
141 // --------------------------------------------------------------------------------- //
142 
143 #endif // HEX_ECS_SOLVER_H
Real compute_norm_(BlockArray< Complex > const &r) const
Definition: solver.cpp:402
B-spline environment.
Definition: bspline.h:57
void matrix_multiply_(BlockArray< Complex > const &p, BlockArray< Complex > &q) const
Definition: solver.cpp:361
void solve()
Find solution of the scattering equations on chosen panel.
Definition: solver.cpp:88
Angular basis.
Definition: ang.h:44
void process_solution_(unsigned iteration, BlockArray< Complex > const &x) const
Definition: solver.cpp:512
Command line parameters.
Definition: io.h:57
void concatenate_panels_(cArray &psi, cArray const &psip) const
BlockArray< Complex > new_array_(std::size_t N, std::string name) const
Definition: solver.cpp:472
Input parameters.
Definition: io.h:321
void axby_operation_(Complex a, BlockArray< Complex > &x, Complex b, BlockArray< Complex > const &y) const
Definition: solver.cpp:435
void finish()
Release resources.
Definition: solver.cpp:538
MPI info.
Definition: parallel.h:50
Solver(CommandLine &cmd, InputFile const &inp, Parallel const &par, AngularBasis const &ang, Bspline const &bspline_inner, Bspline const &bspline_full)
Constructor.
Definition: solver.cpp:43
Definition: solver.h:53
void setup_preconditioner()
Precompute (or load) the radial data.
Definition: solver.cpp:76
Preconditioner template.
Definition: preconditioners.h:62
void choose_preconditioner()
Pick preconditioner for a given panel.
Definition: solver.cpp:58
void apply_preconditioner_(BlockArray< Complex > const &r, BlockArray< Complex > &z) const
Definition: solver.cpp:352
Complex scalar_product_(BlockArray< Complex > const &x, BlockArray< Complex > const &y) const
Definition: solver.cpp:367