Magnetic field in 3D space generated by current in arbitrary wire shape
WireMag is a C++ library for calculating the magnetic field in 3D space generated current in arbitrary wire shape.
This library uses CMake for compliation, by default using g++ (C11). To compile, make a new folder in the package directory:
mkdir build
cd build
Then call CMake to generate makefile:
cmake ..
A ‘Makefile’ will then be generated in the ‘build’ directory. To compile, just:
make
An executable ‘run’ will be generated under /build/bin, simply execute by:
./run
To calculate the magnetic field at certain grid with certain wire shape, one has to create to first creat two object:
Object of class Wire: the shape of wire and it’s discritize resolution.
There are also supplements class method to help creat common wire shapes with flexiable configuration parameters
Wire w1;
w1.path = *w1.solenoidPath(5.1e-3, 0.405e-3, 4, 2, 20);
w1.pathTranslate(0, 0, -2.5e-3);
w1.unit_length = 2e-3;
w1.pathDiscretize();
Object of class Mesh: the mesh grid where the magnetic field will be calculated.
The mesh grid creator can be used to create rectangular meshgrid:
Mesh m;
m.genMesh(0, -5e-3, -5e-3, 0, 5e-3, 5e-3, 0.1e-3);
m.save();
Calculate magnetic field based on Biot Savart Law. To do this pass the wire object and mesh object to class BiotSavartLaw initializer:
BiotSavartLaw bst;
bst.addWires(&w1);
bst.addWires(&w2);
bst.mesh = &m;
bst.current = 500;
bst.calculate();
bst.saveWires();
After field data has been calculated, one can optionally choose to do post analysis, e.g. calculate the norm of the field or choose a slice for evaluation:
bst.startAnalysis();
//bst.sliceMeshX(0);
bst.normField();
bst.saveAsCSV();
Example of generated wire geometry:
Example of generated slice meshgrid:
Result of calculated field:
Under development