Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d9369fa

Browse files
committedDec 31, 2019
test bugfix LineV, small dokufix
1 parent f14cc02 commit d9369fa

File tree

5 files changed

+27
-43
lines changed

5 files changed

+27
-43
lines changed
 

‎CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ All notable changes to magpylib are documented here.
99
## [2.2.0b] - 2019-12-27
1010

1111
### Changed
12-
- Improved performance of getB for diametral magnetized Cylinders by 20%
13-
- IMPORTANT: position arguments of `getBv` functions have been flipped! First comes the source position POSm THEN the observer position POSo!
12+
- Improved performance of getB for diametral magnetized Cylinders by 20%.
13+
- GetB of Line current now uses vectorized code which leads to massive performance enhancement.
14+
- **IMPORTANT:** position arguments of `getBv` functions have been flipped! First comes the source position POSm THEN the observer position POSo!
1415

1516
### Added
1617
- completed the library vector functionality adding magnet Cylinder, moment Dipole, current Circular and Line. This includes adding several private vectorized functions (e.g. ellipticV) to mathLib_vector, adding respective tests and docu examples.

‎docs/_pages/1_how2install.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ Installation
55
*************************
66

77
.. warning::
8-
Magpylib works only with Python 3.6 or later !
8+
magpylib works only with Python 3.6 or later !
9+
10+
**Dependencies:**
11+
- numpy
12+
- matplotlib
13+
The latest versions will be installed automatically with magpylib.
914

1015

1116
Content

‎docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ What is magpylib ?
99
- Free Python package for calculating magnetic fields of magnets, currents and moments (sources).
1010
- Provides convenient methods to create, geometrically manipulate, group and visualize assemblies of sources.
1111
- The magnetic fields are determined from underlying (semi-analytical) solutions which results in fast computation times and requires little computation power.
12+
- For high performance computation (e.g. for multivariate parameter space analysis) all functions are also available in vectorized form.
1213

1314
.. image:: _static/images/index/sourceFundamentals.png
1415
:align: center

‎setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
_SphinxVersion = "1.8.2"
2222
_name = "magpylib"
23-
_description = "A simple Python 3 toolbox for calculating magnetic fields from permanent magnets and current distributions."
23+
_description = "Free Python3 package to compute magnetic fields."
2424
_author_email = "magpylib@gmail.com"
2525
_author = "Michael Ortner"
2626
_projectUrl = "https://github.com/magpylib/magpylib"

‎tests/test_fields/test_CurrentLine.py

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from magpylib._lib.fields.Current_Line import Bfield_CurrentLine
1+
from magpylib._lib.fields.Current_Line_vector import Bfield_CurrentLineV
22
from numpy import array
33
import pytest
4-
4+
import numpy as np
55

66
# -------------------------------------------------------------------------------
77
def test_Bfield_Zero_Length_segment():
@@ -13,12 +13,13 @@ def test_Bfield_Zero_Length_segment():
1313
pos = [0,0,0]
1414

1515
vertices = array([[-1,0,0],[1,0,5],[1,0,5]])
16-
with pytest.warns(RuntimeWarning):
17-
results=Bfield_CurrentLine(pos,vertices,current)
18-
rounding = 4
16+
17+
results=Bfield_CurrentLineV(vertices,current,pos)
18+
rounding = 4
1919

20-
for i in range(0,3):
21-
assert round(mockResult[i],rounding)==round(results[i],rounding), errMsg
20+
for i in range(0,3):
21+
assert round(mockResult[i],rounding)==round(results[i],rounding), errMsg
22+
2223

2324
# -------------------------------------------------------------------------------
2425
def test_Bfield_CurrentLine_outside():
@@ -44,48 +45,24 @@ def test_Bfield_CurrentLine_outside():
4445
vertices = array([ [-4,-4,-3],[3.5,-3.5,-2],[3,3,-1],
4546
[-2.5,2.5,0],[-2,-2,1],[1.5,-1.5,2],[1,1,3]])
4647

47-
results=[Bfield_CurrentLine(pos,vertices,current) for pos in testPosOut]
48+
results=[Bfield_CurrentLineV(vertices,current,pos) for pos in testPosOut]
4849
rounding = 4
4950
for i in range(0,len(mockResults)):
5051
for j in range(0,3):
5152
assert round(mockResults[i][j],rounding)==round(results[i][j],rounding), errMsg
5253

53-
# -------------------------------------------------------------------------------
54-
def test_Bfield_singularity():
55-
# Test the result fo field sampleS on the line current
56-
# Each origin vertix, collinear center point
57-
# Expected: [nan,nan,nan]
58-
from magpylib import source,Collection
59-
from numpy import array, isnan
60-
vertices = [array([1,2,2]),array([1,2,30])]
61-
current = 5
62-
63-
origin1 = vertices[0]
64-
origin2 = vertices[1]
65-
middle = ((vertices[0]) + (vertices[1])) / 2
66-
67-
testPos = [origin1,origin2,middle]
68-
with pytest.warns(RuntimeWarning):
69-
results = [Bfield_CurrentLine(pos,vertices,current) for pos in testPos]
70-
assert all(all(isnan(val) for val in result) for result in results), "Results from getB is not NaN"
71-
7254
# -------------------------------------------------------------------------------
7355
def test_Bfield_onLine():
7456
# Check if points that are on the line but
7557
# not on the segment still return valid results
7658
# Expected for collinear points: [0,0,0]
77-
errMsg = "Points on Line (not on segment) are not being calculated"
78-
from magpylib import source,Collection
79-
from numpy import array
80-
vertices = [array([1,2,2]),array([1,2,30])]
81-
current = 5
82-
mockResults = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
8359

84-
points = [vertices[0] + [0,0,-3], vertices[1] + [0,0,3]]
60+
vertices = np.array([[1,2,2],[1,2,30]])
61+
current = 5
62+
mockResults = np.zeros((2,3))
8563

64+
points = [vertices[0] + array([0,0,-3]), vertices[1] + array([0,0,3])] #on line
8665

87-
results = [Bfield_CurrentLine(point,vertices,current) for point in points]
88-
rounding = 4
89-
for i in range(0,len(mockResults)):
90-
for j in range(0,3):
91-
assert round(mockResults[i][j],rounding)==round(results[i][j],rounding), errMsg
66+
results = array([Bfield_CurrentLineV(vertices,current,point) for point in points])
67+
68+
assert np.all((results==mockResults).ravel())

0 commit comments

Comments
 (0)
Please sign in to comment.