11"""
22Force computation codes
33"""
4+ import warnings
45
56import magpylib as magpy
67import numpy as np
1011from magpylib ._src .obj_classes .class_magnet_Sphere import Sphere
1112from magpylib ._src .obj_classes .class_magnet_Cylinder import Cylinder
1213from magpylib ._src .obj_classes .class_magnet_CylinderSegment import CylinderSegment
14+ from magpylib ._src .obj_classes .class_current_Circle import Circle
1315
1416from magpylib_force .meshing import mesh_target
1517from magpylib_force .utility import check_input_anchor
@@ -63,8 +65,12 @@ def getFT(sources, targets, anchor=None, eps=1e-5, squeeze=True):
6365 n = len (targets )
6466
6567 # 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+ ]
6874 objects = [[] for _ in TARGET_TYPES ]
6975 orders = [[] for _ in TARGET_TYPES ]
7076
@@ -192,6 +198,41 @@ def getFTmagnet(sources, targets, eps=1e-5, anchor=None):
192198
193199 return np .array ((F , - T ))
194200
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+
195236#pylint: disable=unused-argument
196237def getFTcurrent (sources , targets , anchor = None , eps = None ):
197238 """
@@ -203,7 +244,6 @@ def getFTcurrent(sources, targets, anchor=None, eps=None):
203244 segements = linear segments within Polyline objects
204245 instances = computation instances, each segment is split into `meshing` points
205246 """
206-
207247 # number of Polylines
208248 tgt_number = len (targets )
209249
0 commit comments