Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delinted magnetic field test file #2

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d59e3a8
added blablabla to description
RemDelaporteMathurin Sep 20, 2023
37aba0d
Merge pull request #1 from RemDelaporteMathurin/feature-branch
j-fletcher Sep 20, 2023
2dbd085
adding CI
seflapod Sep 21, 2023
79425d2
Merge branch 'j-fletcher:main' into main
seflapod Sep 21, 2023
8cc26f3
adding requirements.txt file
seflapod Sep 21, 2023
2d36025
cleaned up requirements.txt
seflapod Sep 21, 2023
9938468
added pytest-cov package to requirements.txt
seflapod Sep 21, 2023
8717b99
renamed test folder to tests
seflapod Sep 21, 2023
53eabea
Delete test directory
seflapod Sep 21, 2023
ca94520
removing --cov on pytest for now
seflapod Sep 21, 2023
a459cf4
added empty test
seflapod Sep 21, 2023
7f8d649
added pylint package and added --cov back to testing
seflapod Sep 21, 2023
c65e689
fixed typo in main.yaml
seflapod Sep 21, 2023
e4edd94
Merge pull request #5 from seflapod/main
RemDelaporteMathurin Sep 21, 2023
500ca18
Added Coil class to represent 1D filamentous coils, which can calcula…
DeIonizedPlasma Sep 21, 2023
5edf4f7
newline linting?
DeIonizedPlasma Sep 21, 2023
b2c0a28
Packages requirements documented
AudreySaltzman Sep 21, 2023
ec6074a
generate pf coil xyz for testing
AudreySaltzman Sep 21, 2023
c89f1c0
Minor formatting fixes and removing unused variables
DeIonizedPlasma Sep 21, 2023
e791365
Renamed variable for clarity and agreement with commented formula
DeIonizedPlasma Sep 21, 2023
01ab9dd
debug stuff added in comment lines
DeIonizedPlasma Sep 21, 2023
eaec2e9
Test magnetic field at the center of ciruclar poloidal field coil
AudreySaltzman Sep 21, 2023
7fd542d
Parameterize testing
AudreySaltzman Sep 21, 2023
cb82e1f
magnetic tests automatically run
AudreySaltzman Sep 21, 2023
40f39cf
Remove IPython dependence
AudreySaltzman Sep 21, 2023
601f491
Merge branch 'main' of github.com:DeIonizedPlasma/fusion-toolbox into…
AudreySaltzman Sep 21, 2023
3fc1a43
Merge branch 'DeIonizedPlasma-main' into develop
AudreySaltzman Sep 21, 2023
3577d7d
Merge pull request #3 from DeIonizedPlasma/main
AudreySaltzman Sep 21, 2023
e72c9cd
Linting
AudreySaltzman Sep 21, 2023
4e9c8a9
Merge branch 'develop' of https://github.com/AudreySaltzman/fusion-to…
AudreySaltzman Sep 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/main.yaml
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
2 changes: 1 addition & 1 deletion fusion_toolbox/shot_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def smooth(data):
"""Smooth the data to remove noise

Args:
data (_type_): _description_
data (_type_): blablabla
"""
pass

Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
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.
53 changes: 53 additions & 0 deletions tests/test_Bfield.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
''' Module to test Bfield.py calculations'''
from math import pi
import numpy as np
import numpy.testing as npt
import pytest
from fusion_toolbox.Bfield import Coil


MU_0 = 4*pi*1E-7 # T * m / A

def generate_pf_coil_xyz(coil_radius, num_coil_pts = 100, coil_height = 0):
'''
Get xyz coordinates of points along a pf coil
coil radius: [m]
num_coil_points: Number of points used to define the coil (int)
coil_height: pf coil height [m]
Returns: xyz - np.ndarray [N,3]
'''
thetas = np.linspace(0, 2*pi, num_coil_pts)
xyz = np.zeros((num_coil_pts,3))
xyz[:,0] = coil_radius * np.cos(thetas)
xyz[:,1] = coil_radius * np.sin(thetas)
xyz[:,2] = coil_height
return xyz

def analytic_B_center_of_pf_coil(current, coil_radius):
'''
Analytic calculation of magnetic field at the center of a circular pf coil
current: [A]
coil radius: [m]
returns: B-field [T]
'''
return np.array([0,0,MU_0 * current / (2 * coil_radius)])

@pytest.mark.parametrize(
"current, coil_radius",
[[1E3,0.3], [1E5, 0.02], [1E7, 0.004], [1E2, 1]
])
def test_B_center_of_pf_circular_coil(current, coil_radius):
'''
current: [A]
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(coil_radius, num_coil_pts= int(1E4))
test_coil = Coil(xyz, current)
B_center = test_coil.B([np.array([0,0,0])])

# Compare to analytic calculation
B_analytic = [analytic_B_center_of_pf_coil(current,coil_radius)]
npt.assert_almost_equal(B_center, B_analytic, decimal = 4)
4 changes: 4 additions & 0 deletions tests/test_empty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


def test_empty():
pass