forked from j-fletcher/fusion-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
156 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: CI | ||
|
||
# We can specify which Github events will trigger a CI build | ||
on: push | ||
|
||
# now define a single job 'build' (but could define more) | ||
jobs: | ||
|
||
build: | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
python-version: ["3.9", "3.10"] | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
# a job is a seq of steps | ||
steps: | ||
|
||
# Next we need to checkout out repository, and set up Python | ||
# A 'name' is just an optional label shown in the log - helpful to clarify progress - and can be anything | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install Python dependencies | ||
run: | | ||
python3 -m pip install --upgrade pip | ||
pip3 install -r requirements.txt | ||
- name: Test with PyTest | ||
run: | | ||
python -m pytest --cov=fusion_toolbox tests/ | ||
- name: Check style with Pylint | ||
run: | | ||
python3 -m pylint --fail-under=0 --reports=y fusion_toolbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
matplotlib>=3.0.0 | ||
numpy>=1.0.0 | ||
pytest>=7.0.0 | ||
pytest-cov>=4.0.0 | ||
pylint>=2.0.0 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
def test_empty(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import numpy as np | ||
import numpy.testing as npt | ||
from math import pi | ||
from fusion_toolbox.Bfield import * | ||
import pytest | ||
|
||
MU_0 = 4*pi*1E-7 # T * m / A | ||
|
||
def generate_pf_coil_xyz(R, N = 100, z = 0): | ||
''' | ||
Get xyz coordinates of points along a pf coil | ||
R: radius [m] | ||
N: number of points | ||
z: pf coil height [m] | ||
Returns: xyz - np.ndarray [N,3] | ||
''' | ||
thetas = np.linspace(0, 2*pi, N) | ||
xyz = np.zeros((N,3)) | ||
xyz[:,0] = R * np.cos(thetas) | ||
xyz[:,1] = R * np.sin(thetas) | ||
xyz[:,2] = z | ||
return xyz | ||
|
||
def analytic_B_center_of_pf_coil(I, R): | ||
return np.array([0,0,MU_0 * I / (2 * R)]) | ||
|
||
@pytest.mark.parametrize( | ||
"I, R", | ||
[[1E3,0.3], [1E5, 0.02], [1E7, 0.004], [1E2, 1] | ||
]) | ||
def test_B_center_of_pf_circular_coil(I, R): | ||
''' | ||
I: current [A] | ||
R: coil radius [m] | ||
Checks the calculated field at the center of a circular coil against the analytic solution | ||
''' | ||
|
||
# Generate test coil and calculate the field at the center | ||
xyz = generate_pf_coil_xyz(R, N = int(1E4)) | ||
test_coil = Coil(xyz, I) | ||
B_center = test_coil.B([np.array([0,0,0])]) | ||
|
||
# Compare to analytic calculation | ||
B_analytic = [analytic_B_center_of_pf_coil(I,R)] | ||
npt.assert_almost_equal(B_center, B_analytic, decimal = 4) |