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
MeshVectorField Class Reference

Mesh based vector field. More...

#include <meshvectorfield.hpp>

Inheritance diagram for MeshVectorField:
VectorField Mesh Field

Public Member Functions

 MeshVectorField ()
 Default constructor. More...
 
 MeshVectorField (const Mesh &m, const bool fout[3])
 Constructor for vector field from m. More...
 
 MeshVectorField (geom_mode_e geom_mode, const bool fout[3], Int3D size, Vec3D origo, double h)
 Constructor for set geometry. More...
 
 MeshVectorField (geom_mode_e geom_mode, const bool fout[3], double xscale, double fscale, const std::string &filename)
 Constructor for vector field from ascii file. More...
 
 MeshVectorField (geom_mode_e geom_mode, const bool fout[3], Int3D size, Vec3D origo, double h, const MeshVectorField &fin)
 Conversion constructor. More...
 
 MeshVectorField (const MeshVectorField &f)
 Copy constructor. More...
 
 MeshVectorField (std::istream &is)
 Constructor for loading vector field from stream is. More...
 
virtual ~MeshVectorField ()
 Destructor. More...
 
void set_extrapolation (const field_extrpl_e extrpl[6])
 Set the behaviour of field interpolation outside mesh points (extrapolation). More...
 
void reset_transformation (void)
 Set transformation to unity. More...
 
void set_transformation (const Transformation &T)
 Set transformation as a copy of T. More...
 
void translate (const Vec3D &dx)
 Translate field. More...
 
void scale (const Vec3D &sx)
 Scale field. More...
 
void rotate_x (double a)
 Rotate field in coordinate system around y-axis for a radians. More...
 
void rotate_y (double a)
 Rotate field in coordinate system around y-axis for a radians. More...
 
void rotate_z (double a)
 Rotate field in coordinate system around y-axis for a radians. More...
 
void clear ()
 Clears the field. More...
 
void reset (geom_mode_e geom_mode, const bool fout[3], Int3D size, Vec3D origo, double h)
 Resets the field geometry. More...
 
void get_minmax (double &min, double &max) const
 Search minimum and maximum vector length values of vector field. More...
 
void get_minmax (Vec3D &min, Vec3D &max) const
 Search minimum and maximum for each vector component. More...
 
void get_defined_components (bool fout[3]) const
 Get which field components are defined. More...
 
MeshVectorFieldoperator= (const MeshVectorField &f)
 Copy operator. More...
 
MeshVectorFieldoperator+= (const MeshVectorField &f)
 Accumulation operator. More...
 
MeshVectorFieldoperator*= (double x)
 Scaling operator for field values. More...
 
MeshVectorFieldoperator/= (double x)
 Inverse scaling operator. More...
 
const Vec3D operator() (int32_t i) const
 Operator for getting elements of the field mesh. More...
 
const Vec3D operator() (int32_t i, int32_t j) const
 Operator for getting elements of the field mesh. More...
 
const Vec3D operator() (int32_t i, int32_t j, int32_t k) const
 Operator for getting elements of the field mesh. More...
 
void set (int32_t i, const Vec3D &v)
 Operator for setting element (i) of the field mesh. More...
 
void set (int32_t i, int32_t j, const Vec3D &v)
 Operator for setting element (i,j) of the field mesh. More...
 
void set (int32_t i, int32_t j, int32_t k, const Vec3D &v)
 Operator for setting element (i,j,k) of the field mesh. More...
 
virtual const Vec3D operator() (const Vec3D &x) const
 Operator for getting linearly interpolated field value at x. More...
 
void save (const std::string &filename) const
 Saves data to a new file filename. More...
 
void save (std::ostream &os) const
 Saves vector field data to stream os. More...
 
void debug_print (std::ostream &os) const
 Print debugging information to stream os. More...
 
- Public Member Functions inherited from VectorField
virtual ~VectorField ()
 Virtual destructor. More...
 
void get_minmax (const Mesh &mesh, double &min, double &max) const
 Search minimum and maximum vector length values of vector field at mesh nodes. More...
 
void get_minmax (const Mesh &mesh, Vec3D &min, Vec3D &max) const
 Search minimum and maximum for each vector component at mesh nodes. More...
 
- Public Member Functions inherited from Field
virtual ~Field ()
 Virtual destructor. More...
 
- Public Member Functions inherited from Mesh
 Mesh ()
 Default constructor for mesh definition. More...
 
 Mesh (geom_mode_e geom_mode, Int3D size, Vec3D origo, double h)
 Constructor for mesh definition. More...
 
 Mesh (std::istream &is)
 Constructoer for loading mesh from a stream is. More...
 
 ~Mesh ()
 Destructor. More...
 
void reset (geom_mode_e geom_mode, Int3D size, Vec3D origo, double h)
 Reset mesh definition. More...
 
geom_mode_e geom_mode (void) const
 Returns geometry mode. More...
 
uint32_t dim (void) const
 Returns number of dimensions in geometry. More...
 
Int3D size (void) const
 Returns size array of geometry. More...
 
uint32_t size (int i) const
 Returns size of solid mesh in direction i. More...
 
uint32_t nodecount (void) const
 Returns number of nodes in the mesh. More...
 
Vec3D origo (void) const
 Returns origo vector of geometry. More...
 
double origo (int i) const
 Returns i-th component of vector origo. More...
 
Vec3D max (void) const
 Returns vector pointing to the last mesh point opposite of origo. More...
 
double max (int i) const
 Returns i-th component of vector pointing to the last mesh point opposite of origo. More...
 
double h (void) const
 Returns mesh cell size. More...
 
double div_h (void) const
 Returns reciprocal of mesh cell size (1/h). More...
 
Int3D closest_node (Vec3D x) const
 Returns node closest to location x. More...
 
Int3D mesh_number (Vec3D x) const
 Returns node, which contains x. More...
 
Vec3D coord_of_node (Int3D n) const
 Returns coordinates of node i. More...
 
void save (std::ostream &os) const
 Saves geometry data to stream os. More...
 
bool operator== (const Mesh &m) const
 Equality. More...
 
bool operator!= (const Mesh &m) const
 Non-equality. More...
 
void debug_print (std::ostream &os) const
 Print debugging information to stream os. More...
 

Additional Inherited Members

- Protected Attributes inherited from Mesh
geom_mode_e _geom_mode
 Geometry mode More...
 
Int3D _size
 Size of mesh. More...
 
Vec3D _origo
 Location of mesh point (0,0,0) [m]. More...
 
Vec3D _max
 Location of mesh point (size[0]-1,size[1]-1,size[2]-1) [m]. More...
 
double _h
 Length of mesh step [m]. More...
 
double _div_h
 Reciprocal of length of mesh step [1/m]. More...
 

Detailed Description

Mesh based vector field.

The mesh based vector field is a vector field implementation storing vector data in a even, rectangular mesh. The IBSimu Package uses vector fields for electric and magnetic fields. The vector field class provides a subset of vector operations to copy, sum and scale vector fields. The class also includes operators for indexed access to mesh elements and interpolation functions for linearly interpolated smooth field data. The behaviour of the interpolation function can be selected outside the defined mesh. The default behaviour is to use linear extrapolation. This way it can be ensured that VectorField returns sensible values even close by to the edges of the mesh.

If the size of mesh is 1 in some direction, then the field is constant in that direction. Otherwise linear interpolation is used.

The mesh of the magnetic field can be selected independently of the electric field in ParticleDataBase. This allows minimization of the memory use in the case where electric field needs high resolution, but magnetic field is relatively smooth.

The mesh based bector field can be rotated, scaled and translated. This is implemented by storing the active transformation in the MeshVectorField. Each time the field value is queried at a point, the coordinates are transformed to the local coordinate system of the MeshVectorField using the active transformation.

Constructor & Destructor Documentation

◆ MeshVectorField() [1/7]

MeshVectorField::MeshVectorField ( )

Default constructor.

The field made with the default constructor sets geometry mode to MODE3D, mesh cell size h to 1, mesh size size to (0,0,0) and origo origo to (0,0,0). The field evaluator returns always zero.

◆ MeshVectorField() [2/7]

MeshVectorField::MeshVectorField ( const Mesh m,
const bool  fout[3] 
)

Constructor for vector field from m.

Returns a new vector field with geometry parameters (including mesh size) set from m. The field is set to zero in all locations.

◆ MeshVectorField() [3/7]

MeshVectorField::MeshVectorField ( geom_mode_e  geom_mode,
const bool  fout[3],
Int3D  size,
Vec3D  origo,
double  h 
)

Constructor for set geometry.

Returns a new vector field with geometry set according to parameters: geom_mode is the geometry mode, size is the size of the mesh, origo is the location of mesh point (0,0,0) and h is the mesh cell size. The vector field components marked true in array fout are to be defined in the vector field. Components marked false are always zero. The field is initially set to zero in all locations.

◆ MeshVectorField() [4/7]

MeshVectorField::MeshVectorField ( geom_mode_e  geom_mode,
const bool  fout[3],
double  xscale,
double  fscale,
const std::string &  filename 
)

Constructor for vector field from ascii file.

The vector field for geometry mode geom_mode is read in from file filename. The lines starting with # are skipped. After that the data is read in line-by-line with one data point per line. The data columns are separated by white space. The coordinate data are (x, y) in 2D, (x, r) in Cyl and (x, y, z) in 3D. The field data to be read are enabled by user with fout. The enabled field data components are read in after the coordinate data from the data line.

The data points are expected to appear in coordinate sorted order because the mesh step h is determined from the spatial difference of first two data points. Spatial coordinates are multiplied with xscale and field components with fscale while read in.

For magnetic fields the particle iterator assumes vector field in the following formats: In 2D: (x, y, Bz) In Cyl: (x, r, Bx, Br, Btheta) In 3D: (x, y, z, Bx, By, Bz)

◆ MeshVectorField() [5/7]

MeshVectorField::MeshVectorField ( geom_mode_e  geom_mode,
const bool  fout[3],
Int3D  size,
Vec3D  origo,
double  h,
const MeshVectorField fin 
)

Conversion constructor.

Returns a new vector field with geometry set according to parameters: geom_mode is the geometry mode, size is the size of the mesh, origo is the location of mesh point (0,0,0) and h is the mesh cell size. The vector field components marked true in array fout are to be defined in the vector field. Components marked false are always zero. The field content is copied from another mesh based vector field fin.

Currently supports

  1. Conversion from cylindrical (x,r,Bx,Br,Btheta) to 3d (x,y,z,Bx,By,Bz), where x -> z and r -> (x,y).
  2. Conversion from 3d to 3d. Allows change of mesh density and size of field, change of extrapolation effect, etc.

Conversion algorithm uses field evaluator of the input field and therefore the extrapolation settings and the transformation in the field affect the newly created field.

◆ MeshVectorField() [6/7]

MeshVectorField::MeshVectorField ( const MeshVectorField f)

Copy constructor.

◆ MeshVectorField() [7/7]

MeshVectorField::MeshVectorField ( std::istream &  is)

Constructor for loading vector field from stream is.

◆ ~MeshVectorField()

MeshVectorField::~MeshVectorField ( )
virtual

Destructor.

Member Function Documentation

◆ clear()

void MeshVectorField::clear ( void  )

Clears the field.

◆ debug_print()

void MeshVectorField::debug_print ( std::ostream &  os) const

Print debugging information to stream os.

◆ get_defined_components()

void MeshVectorField::get_defined_components ( bool  fout[3]) const

Get which field components are defined.

◆ get_minmax() [1/2]

void MeshVectorField::get_minmax ( double &  min,
double &  max 
) const

Search minimum and maximum vector length values of vector field.

◆ get_minmax() [2/2]

void MeshVectorField::get_minmax ( Vec3D min,
Vec3D max 
) const

Search minimum and maximum for each vector component.

Return vector min with minimum components found and vector max with maximum components found.

◆ operator()() [1/4]

const Vec3D MeshVectorField::operator() ( const Vec3D x) const
virtual

Operator for getting linearly interpolated field value at x.

Implements VectorField.

◆ operator()() [2/4]

const Vec3D MeshVectorField::operator() ( int32_t  i) const

Operator for getting elements of the field mesh.

◆ operator()() [3/4]

const Vec3D MeshVectorField::operator() ( int32_t  i,
int32_t  j 
) const

Operator for getting elements of the field mesh.

◆ operator()() [4/4]

const Vec3D MeshVectorField::operator() ( int32_t  i,
int32_t  j,
int32_t  k 
) const

Operator for getting elements of the field mesh.

◆ operator*=()

MeshVectorField & MeshVectorField::operator*= ( double  x)

Scaling operator for field values.

◆ operator+=()

MeshVectorField & MeshVectorField::operator+= ( const MeshVectorField f)

Accumulation operator.

This operator is only capable of accumulating fields with matching meshes and tranformations.

◆ operator/=()

MeshVectorField & MeshVectorField::operator/= ( double  x)

Inverse scaling operator.

◆ operator=()

MeshVectorField & MeshVectorField::operator= ( const MeshVectorField f)

Copy operator.

◆ reset()

void MeshVectorField::reset ( geom_mode_e  geom_mode,
const bool  fout[3],
Int3D  size,
Vec3D  origo,
double  h 
)

Resets the field geometry.

Sets the field mesh geometry according to the parameters, clears the field to zero in all locations and resets the transformation.

◆ reset_transformation()

void MeshVectorField::reset_transformation ( void  )

Set transformation to unity.

◆ rotate_x()

void MeshVectorField::rotate_x ( double  a)

Rotate field in coordinate system around y-axis for a radians.

◆ rotate_y()

void MeshVectorField::rotate_y ( double  a)

Rotate field in coordinate system around y-axis for a radians.

◆ rotate_z()

void MeshVectorField::rotate_z ( double  a)

Rotate field in coordinate system around y-axis for a radians.

◆ save() [1/2]

void MeshVectorField::save ( const std::string &  filename) const

Saves data to a new file filename.

◆ save() [2/2]

void MeshVectorField::save ( std::ostream &  os) const

Saves vector field data to stream os.

◆ scale()

void MeshVectorField::scale ( const Vec3D sx)

Scale field.

◆ set() [1/3]

void MeshVectorField::set ( int32_t  i,
const Vec3D v 
)

Operator for setting element (i) of the field mesh.

◆ set() [2/3]

void MeshVectorField::set ( int32_t  i,
int32_t  j,
const Vec3D v 
)

Operator for setting element (i,j) of the field mesh.

◆ set() [3/3]

void MeshVectorField::set ( int32_t  i,
int32_t  j,
int32_t  k,
const Vec3D v 
)

Operator for setting element (i,j,k) of the field mesh.

◆ set_extrapolation()

void MeshVectorField::set_extrapolation ( const field_extrpl_e  extrpl[6])

Set the behaviour of field interpolation outside mesh points (extrapolation).

The interpolation function behaviour can be set separately for each boundary. This is done by setting the desired properties to the extrpl array. The interpolation function can use an extrapolation of the last two field values (FIELD_EXTRAPOLATE) or it can return the mirror of the field across the boundary as if the boundary was a perfect magnetic conductor, i.e. the field lines are perpendicular to the boundary (FIELD_MIRROR). It can also return the mirror of the field across the mesh boundary as if the boundary was a magnetic insulator, i.e. the field lines are parallel to the boundary (FIELD_ANTIMIRROR) or it can return a zero field (FIELD_ZERO) NaN (FIELD_NAN) outside the mesh. The FIELD_EXTRAPOLATE is the default behaviour.

The FIELD_MIRROR extrapolation mirrors the field for a boundary x=0 as

B_x(-x,y,z) =  B_x(x,y,z),
B_y(-x,y,z) = -B_y(x,y,z),
B_z(-x,y,z) = -B_z(x,y,z)

The FIELD_ANTIMIRROR extrapolation mirrors the field for a boundary x=0 as

B_x(-x,y,z) = -B_x(x,y,z),  
B_y(-x,y,z) =  B_y(x,y,z),  
B_z(-x,y,z) =  B_z(x,y,z)

The use of FIELD_MIRROR in case of symmetric cases, where beam is traversing next to the geometry boundary, is necessary to get physical results.

Very far (double the size of the mesh volume) the field evaluator will always return zero.

◆ set_transformation()

void MeshVectorField::set_transformation ( const Transformation T)

Set transformation as a copy of T.

◆ translate()

void MeshVectorField::translate ( const Vec3D dx)

Translate field.


The documentation for this class was generated from the following files:


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