Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
epot_matrixsolver.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2011,2012,2017,2021 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 
44 #ifndef EPOT_MATRIXSOLVER_HPP
45 #define EPOT_MATRIXSOLVER_HPP 1
46 
47 
48 #include "epot_solver.hpp"
49 #include "crowmatrix.hpp"
50 #include "mvector.hpp"
51 
52 
53 #define N2D_TYPE_MASK 0x80000000 // 100...
54 #define N2D_TYPE_FIXED 0x80000000 // 100...
55 #define N2D_TYPE_FREE 0x00000000 // 000...
56 
57 #define N2D_INDEX_MASK 0x7FFFFFFF // 011...
58 
59 
62 class EpotMatrixSolver : public EpotSolver {
63 
64 protected:
65 
75  class Node2DoF {
76  Int3D _size;
77  uint32_t *_n2d;
79  public:
80 
81  Node2DoF();
82  Node2DoF( Int3D size );
83  ~Node2DoF();
84  void clear( void );
85  void resize( Int3D size );
86 
87  uint32_t &operator()( int i )
88  { return( _n2d[i] ); }
89  uint32_t &operator()( int i, int j )
90  { return( _n2d[i+j*_size[0]] ); }
91  uint32_t &operator()( int i, int j, int k )
92  { return( _n2d[i+j*_size[0]+k*_size[0]*_size[1]] ); }
93 
94  const uint32_t &operator()( int i ) const
95  { return( _n2d[i] ); }
96  const uint32_t &operator()( int i, int j ) const
97  { return( _n2d[i+j*_size[0]] ); }
98  const uint32_t &operator()( int i, int j, int k ) const
99  { return( _n2d[i+j*_size[0]+k*_size[0]*_size[1]] ); }
100 
103  void debug_print( std::ostream &os ) const;
104  };
105 
106  uint32_t _dof;
111  const Vector *_sol;
113  MeshScalarField *_epot;
114  const MeshScalarField *_scharge;
115 
116 
119  EpotMatrixSolver( Geometry &geom );
120 
123  EpotMatrixSolver( Geometry &geom, std::istream &s );
124 
128  void get_vecmat( const CRowMatrix **A, const Vector **B );
129 
133  void get_resjac( const CRowMatrix **J, const Vector **R, const Vector &X );
134 
137  //bool linear( void ) const;
138 
141  void set_initial_guess( const MeshScalarField &epot, Vector &X ) const;
142 
147  void set_solution( MeshScalarField &epot, const Vector &X ) const;
148 
154  void preprocess( MeshScalarField &epot, const MeshScalarField &scharge );
155 
161  void postprocess( void );
162 
165  void reset_matrix( void );
166 
167 private:
168 
171  void build_mat_vec( void );
172 
173  void set_link( uint32_t a, uint32_t b, double val );
174  void add_vacuum_node( uint32_t i, uint32_t j, uint32_t k, const Vec3D &x );
175  void add_near_solid_node_1d( uint32_t i, const Vec3D &x );
176  void add_near_solid_node_2d( uint32_t i, uint32_t j, const Vec3D &x );
177  void add_near_solid_node_cyl( uint32_t i, uint32_t j, const Vec3D &x );
178  void add_near_solid_node_3d( uint32_t i, uint32_t j, uint32_t k, const Vec3D &x );
179  void add_near_solid_node( uint32_t i, uint32_t j, uint32_t k, const Vec3D &x );
180  void add_neumann_node_1d( uint32_t i, const Vec3D &x );
181  void add_neumann_node_2d( uint32_t i, uint32_t j, const Vec3D &x );
182  void add_neumann_node_cyl( uint32_t i, uint32_t j, const Vec3D &x );
183  void add_neumann_node_3d( uint32_t i, uint32_t j, uint32_t k, const Vec3D &x );
184  void add_neumann_node( uint32_t i, uint32_t j, uint32_t k, const Vec3D &x );
185 
186 public:
187 
190  virtual ~EpotMatrixSolver();
191 
194  virtual void debug_print( std::ostream &os ) const;
195 
198  virtual void save( std::ostream &s ) const;
199 };
200 
201 
202 #endif
Compressed row sparse matrix class.
Definition: crowmatrix.hpp:76
Class nodes to degrees of freedom mapping.
Definition: epot_matrixsolver.hpp:75
void debug_print(std::ostream &os) const
Print debugging information to os.
Definition: epot_matrixsolver.cpp:88
Parent class for Matrix-based solvers for Electric potential problem.
Definition: epot_matrixsolver.hpp:62
void get_resjac(const CRowMatrix **J, const Vector **R, const Vector &X)
Return const pointers to jacobian matrix and residual vector of the problem to J and R at X.
Definition: epot_matrixsolver.cpp:905
void set_solution(MeshScalarField &epot, const Vector &X) const
Load electric potential from solution vector.
Definition: epot_matrixsolver.cpp:798
const Vector * _sol
Current solution vector.
Definition: epot_matrixsolver.hpp:111
CRowMatrix * _fd_mat
Finite Difference matrix.
Definition: epot_matrixsolver.hpp:108
virtual void save(std::ostream &s) const
Saves problem data to stream.
Definition: epot_matrixsolver.cpp:960
virtual void debug_print(std::ostream &os) const
Print debugging information to os.
Definition: epot_matrixsolver.cpp:943
Vector * _d_vec
Derivative vector for nonlinear solution.
Definition: epot_matrixsolver.hpp:110
void get_vecmat(const CRowMatrix **A, const Vector **B)
Return const pointers to the matrix A and vector B of the linear problem.
Definition: epot_matrixsolver.cpp:897
Node2DoF _n2d
Nodes to degrees of freedom map.
Definition: epot_matrixsolver.hpp:107
virtual ~EpotMatrixSolver()
Destructor.
Definition: epot_matrixsolver.cpp:128
void reset_matrix(void)
Reset matrix representation.
Definition: epot_matrixsolver.cpp:771
EpotMatrixSolver(Geometry &geom)
Constructor.
Definition: epot_matrixsolver.cpp:114
void preprocess(MeshScalarField &epot, const MeshScalarField &scharge)
Preprocess.
Definition: epot_matrixsolver.cpp:811
Vector * _fd_vec
Finite Difference vector.
Definition: epot_matrixsolver.hpp:109
void set_initial_guess(const MeshScalarField &epot, Vector &X) const
Return true if problem is linear.
Definition: epot_matrixsolver.cpp:785
uint32_t _dof
Degrees of freedom.
Definition: epot_matrixsolver.hpp:106
void postprocess(void)
Postprocess.
Definition: epot_matrixsolver.cpp:890
Class for constructing the linear/nonlinear problem for the solver.
Definition: epot_solver.hpp:210
Geometry defining class.
Definition: geometry.hpp:180
3D Integer vector class.
Definition: vec3d.hpp:320
Scalar field class.
Definition: meshscalarfield.hpp:70
Three dimensional vector.
Definition: vec3d.hpp:58
Dense math vector class.
Definition: mvector.hpp:71
Compressed row sparse matrix algebra.
Poisson equation problem for solving electric potential.
N-dimensional vector.


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.