项目作者: julianyulu

项目描述 :
Magnetic field in 3D space generated by current in arbitrary wire shape
高级语言: C++
项目地址: git://github.com/julianyulu/WireMag.git
创建时间: 2018-08-11T23:15:51Z
项目社区:https://github.com/julianyulu/WireMag

开源协议:

下载


WireMag

WireMag is a C++ library for calculating the magnetic field in 3D space generated current in arbitrary wire shape.

Compile

This library uses CMake for compliation, by default using g++ (C11). To compile, make a new folder in the package directory:

  1. mkdir build
  2. cd build

Then call CMake to generate makefile:

  1. cmake ..

A ‘Makefile’ will then be generated in the ‘build’ directory. To compile, just:

  1. make

An executable ‘run’ will be generated under /build/bin, simply execute by:

  1. ./run

How it Works

To calculate the magnetic field at certain grid with certain wire shape, one has to create to first creat two object:

  1. 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

    1. Wire w1;
    2. w1.path = *w1.solenoidPath(5.1e-3, 0.405e-3, 4, 2, 20);
    3. w1.pathTranslate(0, 0, -2.5e-3);
    4. w1.unit_length = 2e-3;
    5. w1.pathDiscretize();
  2. 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:

    1. Mesh m;
    2. m.genMesh(0, -5e-3, -5e-3, 0, 5e-3, 5e-3, 0.1e-3);
    3. m.save();
  3. Calculate magnetic field based on Biot Savart Law. To do this pass the wire object and mesh object to class BiotSavartLaw initializer:

    1. BiotSavartLaw bst;
    2. bst.addWires(&w1);
    3. bst.addWires(&w2);
    4. bst.mesh = &m;
    5. bst.current = 500;
    6. bst.calculate();
    7. bst.saveWires();
  4. 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:

    1. bst.startAnalysis();
    2. //bst.sliceMeshX(0);
    3. bst.normField();
    4. bst.saveAsCSV();

Examples

Example of generated wire geometry:
wire-example

Example of generated slice meshgrid:
mesh-example

Result of calculated field:
field-example

Status

Under development

TODO

  • Make GUI window for user-firendly access
  • Add plotting module using python
  • Add unittest