1
1
"""
2
2
Force computation codes
3
3
"""
4
+ import warnings
4
5
5
6
import magpylib as magpy
6
7
import numpy as np
10
11
from magpylib ._src .obj_classes .class_magnet_Sphere import Sphere
11
12
from magpylib ._src .obj_classes .class_magnet_Cylinder import Cylinder
12
13
from magpylib ._src .obj_classes .class_magnet_CylinderSegment import CylinderSegment
14
+ from magpylib ._src .obj_classes .class_current_Circle import Circle
13
15
14
16
from magpylib_force .meshing import mesh_target
15
17
from magpylib_force .utility import check_input_anchor
@@ -63,8 +65,12 @@ def getFT(sources, targets, anchor=None, eps=1e-5, squeeze=True):
63
65
n = len (targets )
64
66
65
67
# split targets into lists of similar types
66
- TARGET_TYPES = [Cuboid , Polyline , Sphere , Cylinder , CylinderSegment ]
67
- getFT_FUNCS = [getFTmagnet , getFTcurrent , getFTmagnet , getFTmagnet , getFTmagnet ]
68
+ TARGET_TYPES = [
69
+ Cuboid , Polyline , Sphere , Cylinder , CylinderSegment , Circle
70
+ ]
71
+ getFT_FUNCS = [
72
+ getFTmagnet , getFTcurrent , getFTmagnet , getFTmagnet , getFTmagnet , getFTcurrent_circ
73
+ ]
68
74
objects = [[] for _ in TARGET_TYPES ]
69
75
orders = [[] for _ in TARGET_TYPES ]
70
76
@@ -192,6 +198,41 @@ def getFTmagnet(sources, targets, eps=1e-5, anchor=None):
192
198
193
199
return np .array ((F , - T ))
194
200
201
+
202
+ def getFTcurrent_circ (sources , targets , anchor = None , eps = None ):
203
+ """
204
+ The current force computation is designed for Polylines.
205
+ To make use of this, Circle objects are transformed into Polylines.
206
+ Its a dirty solution that should be fixed at some point
207
+ """
208
+ new_targets = []
209
+ for tgt in targets :
210
+ n = tgt .meshing
211
+ if n < 20 :
212
+ warnings .warn (
213
+ "Circle meshing parameter with low value detected. "
214
+ "This will give bad results. Please increase meshing. "
215
+ "Circle meshing defines the number of points on the circle."
216
+ )
217
+ r = tgt .diameter / 2
218
+ verts = np .zeros ((3 ,n ))
219
+ verts [2 ] = np .linspace (0 , 2 * np .pi , n )
220
+ verts [0 ] = r * np .cos (verts [2 ])
221
+ verts [1 ] = r * np .sin (verts [2 ])
222
+ verts [2 ] = 0
223
+
224
+ poly = magpy .current .Polyline (
225
+ vertices = verts .T ,
226
+ current = tgt .current ,
227
+ position = tgt .position ,
228
+ orientation = tgt .orientation ,
229
+ )
230
+ poly .meshing = 1
231
+ new_targets .append (poly )
232
+
233
+ return getFTcurrent (sources , new_targets , anchor , eps )
234
+
235
+
195
236
#pylint: disable=unused-argument
196
237
def getFTcurrent (sources , targets , anchor = None , eps = None ):
197
238
"""
@@ -203,7 +244,6 @@ def getFTcurrent(sources, targets, anchor=None, eps=None):
203
244
segements = linear segments within Polyline objects
204
245
instances = computation instances, each segment is split into `meshing` points
205
246
"""
206
-
207
247
# number of Polylines
208
248
tgt_number = len (targets )
209
249
0 commit comments