@@ -117,12 +117,12 @@ def getFTmagnet(sources, targets, eps=1e-5, anchor=None):
117117 targets: Cuboid object or 1D list of Cuboid objects
118118 Force and Torque acting on targets in the magnetic field generated by the sources
119119 will be computed. A target must have a valid `meshing` parameter.
120-
120+
121121 eps: float, default=1e-5
122122 The magnetic field gradient is computed using finite differences (FD). eps is
123123 the FD step size. A good value is 1e-5 * characteristic system size (magnet size,
124124 distance between sources and targets, ...).
125-
125+
126126 anchor: array_like, default=None
127127 The Force adds to the Torque via the anchor point. For a freely floating magnet
128128 this would be the barycenter. If `anchor=None`, this part of the Torque computation
@@ -151,10 +151,20 @@ def getFTmagnet(sources, targets, eps=1e-5, anchor=None):
151151
152152 for i ,tgt in enumerate (targets ):
153153 tgt_vol = volume (tgt )
154- inst_mom = tgt .magnetization * tgt_vol / inst_numbers [i ]
154+ inst_mom = tgt .orientation . apply ( tgt . magnetization ) * tgt_vol / inst_numbers [i ]
155155 MOM [insti [i ]:insti [i + 1 ]] = inst_mom
156156
157157 mesh = mesh_target (tgt )
158+ #import matplotlib.pyplot as plt
159+ #ax = plt.figure().add_subplot(projection='3d')
160+ #ax.plot(mesh[:,0], mesh[:,1], mesh[:,2], ls='', marker='.')
161+
162+ mesh = tgt .orientation .apply (mesh )
163+ #ax.plot(mesh[:,0], mesh[:,1], mesh[:,2], ls='', marker='.', color='r')
164+ #plt.show()
165+ #import sys
166+ #sys.exit()
167+
158168 for j ,ev in enumerate (eps_vec ):
159169 POSS [insti [i ]:insti [i + 1 ],j ] = mesh + ev + tgt .position
160170
@@ -188,12 +198,12 @@ def getFTmagnet(sources, targets, eps=1e-5, anchor=None):
188198# targets: Cuboid object or 1D list of Cuboid objects
189199# Force and Torque acting on targets in the magnetic field generated by the sources
190200# will be computed. A target must have a valid `meshing` parameter.
191-
201+
192202# eps: float, default=1e-5
193203# The magnetic field gradient is computed using finite differences (FD). eps is
194204# the FD step size. A good value is 1e-5 * characteristic system size (magnet size,
195205# distance between sources and targets, ...).
196-
206+
197207# anchor: array_like, default=None
198208# The Force adds to the Torque via the anchor point. For a freely floating magnet
199209# this would be the barycenter. If `anchor=None`, this part of the Torque computation
@@ -292,14 +302,14 @@ def getFTcurrent(sources, targets, anchor=None, eps=None):
292302 CURR = np .zeros ((no_inst ,))
293303
294304 for i ,tgt in enumerate (targets ):
295- verts = tgt .vertices
305+ verts = tgt .orientation . apply ( tgt . vertices )
296306 mesh = mesh_numbers [i ]
297307
298308 lvec = np .repeat (verts [1 :] - verts [:- 1 ], mesh , axis = 0 )/ mesh
299309 LVEC [insti [i ]:insti [i + 1 ]] = lvec
300310
301311 CURR [insti [i ]:insti [i + 1 ]] = [tgt .current ]* mesh * seg_numbers [i ]
302-
312+
303313 for j in range (seg_numbers [i ]):
304314 poss = np .linspace (verts [j ]+ lvec [j * mesh ]/ 2 , verts [j + 1 ]- lvec [j * mesh ]/ 2 , mesh ) + tgt .position
305315 POSS [insti [i ]+ mesh * j :insti [i ]+ mesh * (j + 1 )] = poss
0 commit comments