Mesh based vector field. More...
#include <meshvectorfield.hpp>
Public Member Functions | |
MeshVectorField () | |
Default constructor. | |
MeshVectorField (const Mesh &m, const bool fout[3]) | |
Constructor for vector field from m. | |
MeshVectorField (geom_mode_e geom_mode, const bool fout[3], Int3D size, Vec3D origo, double h) | |
Constructor for set geometry. | |
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. | |
MeshVectorField (geom_mode_e geom_mode, const bool fout[3], Int3D size, Vec3D origo, double h, const MeshVectorField &fin) | |
Conversion constructor. | |
MeshVectorField (const MeshVectorField &f) | |
Copy constructor. | |
MeshVectorField (std::istream &is) | |
Constructor for loading vector field from stream is. | |
virtual | ~MeshVectorField () |
Destructor. | |
void | set_extrapolation (const field_extrpl_e extrpl[6]) |
Set the behaviour of field interpolation outside mesh points (extrapolation). | |
void | reset_transformation (void) |
Set transformation to unity. | |
void | set_transformation (const Transformation &T) |
Set transformation as a copy of T. | |
void | translate (const Vec3D &dx) |
Translate field. | |
void | scale (const Vec3D &sx) |
Scale field. | |
void | rotate_x (double a) |
Rotate solid around x-axis. | |
void | rotate_y (double a) |
Rotate solid around y-axis. | |
void | rotate_z (double a) |
Rotate solid around z-axis. | |
void | clear () |
Clears the field. | |
void | reset (geom_mode_e geom_mode, const bool fout[3], Int3D size, Vec3D origo, double h) |
Resets the field geometry. | |
void | get_minmax (double &min, double &max) const |
Search minimum and maximum vector length values of vector field. | |
void | get_defined_components (bool fout[3]) const |
Get which field components are defined. | |
MeshVectorField & | operator= (const MeshVectorField &f) |
Copy operator. | |
MeshVectorField & | operator+= (const MeshVectorField &f) |
Accumulation operator. | |
MeshVectorField & | operator*= (double x) |
Scaling operator for field values. | |
MeshVectorField & | operator/= (double x) |
Inverse scaling operator. | |
const Vec3D | operator() (int32_t i) const |
Operator for getting elements of the field mesh. | |
const Vec3D | operator() (int32_t i, int32_t j) const |
Operator for getting elements of the field mesh. | |
const Vec3D | operator() (int32_t i, int32_t j, int32_t k) const |
Operator for getting elements of the field mesh. | |
void | set (int32_t i, const Vec3D &v) |
Operator for setting element (i) of the field mesh. | |
void | set (int32_t i, int32_t j, const Vec3D &v) |
Operator for setting element (i,j) of the field mesh. | |
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. | |
virtual const Vec3D | operator() (Vec3D x) const |
Operator for getting linearly interpolated field value at x. | |
void | save (const std::string &filename) const |
Saves data to a new file filename. | |
void | save (std::ostream &os) const |
Saves vector field data to stream os. | |
void | debug_print (std::ostream &os) const |
Print debugging information to stream os. | |
![]() | |
virtual | ~VectorField () |
Virtual destructor. | |
![]() | |
Mesh () | |
Default constructor for mesh definition. | |
Mesh (geom_mode_e geom_mode, Int3D size, Vec3D origo, double h) | |
Constructor for mesh definition. | |
Mesh (std::istream &is) | |
Constructoer for loading mesh from a stream is. | |
~Mesh () | |
Destructor. | |
void | reset (geom_mode_e geom_mode, Int3D size, Vec3D origo, double h) |
Reset mesh definition. | |
geom_mode_e | geom_mode (void) const |
Returns geometry mode. | |
int32_t | dim (void) const |
Returns number of dimensions in geometry. | |
Int3D | size (void) const |
Returns size array of geometry. | |
int32_t | size (int i) const |
Returns size of solid mesh in direction i. | |
int32_t | nodecount (void) const |
Returns number of nodes in the mesh. | |
Vec3D | origo (void) const |
Returns origo vector of geometry. | |
double | origo (int i) const |
Returns i-th component of vector origo. | |
Vec3D | max (void) const |
Returns vector pointing to the last mesh point opposite of origo. | |
double | max (int i) const |
Returns i-th component of vector pointing to the last mesh point opposite of origo. | |
double | h (void) const |
Returns mesh cell size. | |
double | div_h (void) const |
Returns reciprocal of mesh cell size (1/h). | |
bool | operator== (const Mesh &m) const |
Equality. | |
bool | operator!= (const Mesh &m) const |
Non-equality. |
Additional Inherited Members | |
![]() | |
geom_mode_e | _geom_mode |
Geometry mode | |
Int3D | _size |
Size of mesh. | |
Vec3D | _origo |
Location of mesh point (0,0,0) [m]. | |
Vec3D | _max |
Location of mesh point (size[0]-1,size[1]-1,size[2]-1) [m]. | |
double | _h |
Length of mesh step [m]. | |
double | _div_h |
Reciprocal of length of mesh step [1/m]. |
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 interpolation function uses linear extrapolation of field outside the defined mesh. This way it can be ensured that VectorField returns sensible values even close by to the edges of the geometry.
If the size of mesh is 1 in some direction, then the field is constant in that direction. Otherwise linear interpolation is used.
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::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::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::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::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
Conversion algorithm uses field evaluator ot the input field and therefore the extrapolation settings and the transformation in the field affect the created field.
MeshVectorField::MeshVectorField | ( | const MeshVectorField & | f | ) |
Copy constructor.
MeshVectorField::MeshVectorField | ( | std::istream & | is | ) |
Constructor for loading vector field from stream is.
|
virtual |
Destructor.
void MeshVectorField::clear | ( | ) |
Clears the field.
void MeshVectorField::debug_print | ( | std::ostream & | os | ) | const |
Print debugging information to stream os.
Reimplemented from Mesh.
void MeshVectorField::get_defined_components | ( | bool | fout[3] | ) | const |
Get which field components are defined.
void MeshVectorField::get_minmax | ( | double & | min, |
double & | max | ||
) | const |
Search minimum and maximum vector length values of vector field.
const Vec3D MeshVectorField::operator() | ( | int32_t | i | ) | const |
Operator for getting elements of the field mesh.
const Vec3D MeshVectorField::operator() | ( | int32_t | i, |
int32_t | j | ||
) | const |
Operator for getting elements of the field mesh.
const Vec3D MeshVectorField::operator() | ( | int32_t | i, |
int32_t | j, | ||
int32_t | k | ||
) | const |
Operator for getting elements of the field mesh.
Operator for getting linearly interpolated field value at x.
Implements VectorField.
MeshVectorField& MeshVectorField::operator*= | ( | double | x | ) |
Scaling operator for field values.
MeshVectorField& MeshVectorField::operator+= | ( | const MeshVectorField & | f | ) |
Accumulation operator.
MeshVectorField& MeshVectorField::operator/= | ( | double | x | ) |
Inverse scaling operator.
MeshVectorField& MeshVectorField::operator= | ( | const MeshVectorField & | f | ) |
Copy operator.
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.
void MeshVectorField::reset_transformation | ( | void | ) |
Set transformation to unity.
void MeshVectorField::rotate_x | ( | double | a | ) |
Rotate solid around x-axis.
Rotate around x-axis for a radians.
void MeshVectorField::rotate_y | ( | double | a | ) |
Rotate solid around y-axis.
Rotate around y-axis for \a a radians.
Rotate field in coordinate system around y-axis.
void MeshVectorField::rotate_z | ( | double | a | ) |
Rotate solid around z-axis.
Rotate around z-axis for a radians.
void MeshVectorField::save | ( | const std::string & | filename | ) | const |
Saves data to a new file filename.
void MeshVectorField::save | ( | std::ostream & | os | ) | const |
Saves vector field data to stream os.
Reimplemented from Mesh.
void MeshVectorField::scale | ( | const Vec3D & | sx | ) |
Scale field.
void MeshVectorField::set | ( | int32_t | i, |
const Vec3D & | v | ||
) |
Operator for setting element (i) of the field mesh.
void MeshVectorField::set | ( | int32_t | i, |
int32_t | j, | ||
const Vec3D & | v | ||
) |
Operator for setting element (i,j) of the field mesh.
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.
|
inline |
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 mesh boundary (FIELD_MIRROR), can return a zero field (FIELD_ZERO) or it can return a NaN (FIELD_NAN) outside the mesh
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 simulation box) the field evaluator will always return zero.
void MeshVectorField::set_transformation | ( | const Transformation & | T | ) |
Set transformation as a copy of T.
void MeshVectorField::translate | ( | const Vec3D & | dx | ) |
Translate field.