epot_problem.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2011 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 #ifndef EPOT_PROBLEM_HPP
44 #define EPOT_PROBLEM_HPP 1
45 
46 
47 #include <iostream>
48 #include <stdint.h>
49 #include "problem.hpp"
50 #include "solver.hpp"
51 #include "scalarfield.hpp"
52 #include "geometry.hpp"
53 #include "vec3d.hpp"
54 
55 
70 
71 #define PLASMA_INITIAL PLASMA_PEXP_INITIAL
72 
142 class EpotProblem : public Problem {
143 
153  class Node2DoF {
154  Int3D _size;
155  int32_t *_n2d;
157  public:
158 
159  Node2DoF() : _size(0), _n2d(0) {}
160  Node2DoF( Int3D size ) : _size(size) {
161  _n2d = new int32_t[_size[0]*_size[1]*_size[2]];
162  }
163  ~Node2DoF() { delete _n2d; }
164 
165  void resize( Int3D size ) {
166  _size = size;
167  if( _n2d )
168  delete _n2d;
169  _n2d = new int32_t[_size[0]*_size[1]*_size[2]];
170  }
171 
172  int32_t &operator()( int i )
173  { return( _n2d[i] ); }
174  int32_t &operator()( int i, int j )
175  { return( _n2d[i+j*_size[0]] ); }
176  int32_t &operator()( int i, int j, int k )
177  { return( _n2d[i+j*_size[0]+k*_size[0]*_size[1]] ); }
178 
179  const int32_t &operator()( int i ) const
180  { return( _n2d[i] ); }
181  const int32_t &operator()( int i, int j ) const
182  { return( _n2d[i+j*_size[0]] ); }
183  const int32_t &operator()( int i, int j, int k ) const
184  { return( _n2d[i+j*_size[0]+k*_size[0]*_size[1]] ); }
185 
188  void debug_print( std::ostream &os ) const;
189  };
190 
191  int32_t _nodecount;
192  int32_t _dof;
193  Node2DoF _n2d;
194  CRowMatrix *_fd_mat;
195  Vector *_fd_vec;
197  const Geometry *_g;
198  mutable CRowMatrix *_fd_mat2;
199  mutable Vector *_fd_vec2;
200  mutable Vector *_fd_vec3;
202  int32_t _neumann_order;
203  bool _smooth_solid;
205  plasma_mode_e _plasma;
207  double _rhoe;
208  double _Te;
209  double _Up;
211  std::vector<double> _rhoi;
213  std::vector<double> _Ei;
216  double _force_pot;
218  bool (*_force_pot_func)(double,double,double);
219  bool (*_init_plasma_func)(double,double,double);
221  Solver *_solver;
224  void set_link( CRowMatrix &A, Vector &B,
225  int32_t a, int32_t b, double val );
226 
227  void add_initial_plasma( int32_t i, int32_t j, int32_t k,
228  CRowMatrix &A, Vector &B, Node2DoF &n2d );
229 
230  void add_forced_pot( int32_t i, int32_t j, int32_t k,
231  CRowMatrix &A, Vector &B, Node2DoF &n2d );
232 
233  void add_vacuum_node( int32_t i, int32_t j, int32_t k,
234  CRowMatrix &A, Vector &B, Node2DoF &n2d );
235 
236  void add_neumann_node( signed char a, int32_t i, int32_t j, int32_t k,
237  CRowMatrix &A, Vector &B, Node2DoF &n2d );
238 
239  void add_solid_edge_node( signed char a, int32_t i, int32_t j, int32_t k,
240  CRowMatrix &A, Vector &B, Node2DoF &n2d );
241 
242  void clear_problem( void );
243 
244 public:
245 
246 /* ************************************** *
247  * Constructors and destructor *
248  * ************************************** */
249 
252  EpotProblem();
253 
256  EpotProblem( std::istream &s );
257 
260  ~EpotProblem();
261 
262 /* ************************************** *
263  * Problem constructing and solving *
264  * ************************************** */
265 
270  void set_neumann_order( int32_t order );
271 
276  void enable_smooth_solids( bool enable );
277 
285  void set_forced_potential_volume( double force_pot,
286  bool (*force_pot_func)(double,double,double) );
287 
292  void set_initial_plasma( double Up,
293  bool (*plasma_func)(double,double,double) );
294 
301  void set_pexp_plasma( double rhoe, double Te, double Up );
302 
308  void set_nsimp_initial_plasma( bool (*plasma_func)(double,double,double) );
309 
323  void set_nsimp_plasma( double rhop, double Ep,
324  std::vector<double> rhoi, std::vector<double> Ei );
325 
330  void construct( const Geometry &g );
331 
334  void set_solver( Solver &s );
335 
343  void solve( ScalarField &epot, const ScalarField &scharge ) const;
344 
345 /* ************************************** *
346  * Solver interface *
347  * ************************************** */
348 
356  void get_vecmat( const Matrix **A, const Vector **B ) const;
357 
365  void get_resjac( const Matrix **J, const Vector **R, const Vector &X ) const;
366 
369  bool linear( void ) const;
370 
371 /* ************************************** *
372  * Misc *
373  * ************************************** */
374 
377  int get_dof( void ) const { return( _dof ); }
378 
381  void debug_print( std::ostream &os ) const;
382 
385  void save( std::ostream &s ) const;
386 };
387 
388 
389 #endif
390 
391 
392 
393 
394 
395 
396 
397 
398 
399 
400 
401 
402 
403 
404 
405 
406 
407 
408 
409 
Definition: epot_problem.hpp:68
void enable_smooth_solids(bool enable)
Enable smooth solid edges.
void solve(ScalarField &epot, const ScalarField &scharge) const
Solve the problem.
Base for solvers.
Geometry definition
Compressed row sparse matrix class.
Definition: crowmatrix.hpp:76
Scalar fields.
void debug_print(std::ostream &os) const
Print debugging information to os.
Base for problems.
Dense math vector class.
Definition: mvector.hpp:68
Abstract base class for linear/non-linear problem, which can be described by a non-linear system of e...
Definition: problem.hpp:54
Definition: epot_problem.hpp:69
void set_initial_plasma(double Up, bool(*plasma_func)(double, double, double))
Define initial plasma to the problem.
Class for constructing the linear/nonlinear problem for the solver.
Definition: epot_problem.hpp:142
Three dimensional vectors.
~EpotProblem()
Destructor for problem.
void set_nsimp_plasma(double rhop, double Ep, std::vector< double > rhoi, std::vector< double > Ei)
Enable plasma model for negative ion extraction problem.
Geometry defining class.
Definition: geometry.hpp:131
void get_vecmat(const Matrix **A, const Vector **B) const
Return const pointers to the matrix A and vector B of the linear problem.
void set_pexp_plasma(double rhoe, double Te, double Up)
Enable plasma model for positive ion extraction problem.
void set_nsimp_initial_plasma(bool(*plasma_func)(double, double, double))
Define initial plasma boundary location to negative ion extraction problem.
int get_dof(void) const
Get degrees of freedom.
Definition: epot_problem.hpp:377
void set_neumann_order(int32_t order)
Set Neumann boundary order.
Base matrix class.
Definition: matrix.hpp:76
bool linear(void) const
Return true if problem is linear.
3D Integer vector class.
Definition: vec3d.hpp:289
void set_solver(Solver &s)
Set solver to be used for the problem.
Abstract base class for solving linear and nonlinear problems. Different implementation may exist...
Definition: solver.hpp:57
void save(std::ostream &s) const
Saves problem data to stream.
void get_resjac(const Matrix **J, const Vector **R, const Vector &X) const
Return const pointers to jacobian matrix and residual vector of the problem to J and R at X...
EpotProblem()
Default constructor.
Definition: epot_problem.hpp:68
void construct(const Geometry &g)
Construct matrix form of the problem.
plasma_mode_e
Plasma modes.
Definition: epot_problem.hpp:68
Scalar field class.
Definition: scalarfield.hpp:70
void set_forced_potential_volume(double force_pot, bool(*force_pot_func)(double, double, double))
Define forced potential volume.
Definition: epot_problem.hpp:68
Definition: epot_problem.hpp:69