@@ -117,12 +117,12 @@ def getFTmagnet(sources, targets, eps=1e-5, anchor=None):
117
117
targets: Cuboid object or 1D list of Cuboid objects
118
118
Force and Torque acting on targets in the magnetic field generated by the sources
119
119
will be computed. A target must have a valid `meshing` parameter.
120
-
120
+
121
121
eps: float, default=1e-5
122
122
The magnetic field gradient is computed using finite differences (FD). eps is
123
123
the FD step size. A good value is 1e-5 * characteristic system size (magnet size,
124
124
distance between sources and targets, ...).
125
-
125
+
126
126
anchor: array_like, default=None
127
127
The Force adds to the Torque via the anchor point. For a freely floating magnet
128
128
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):
151
151
152
152
for i ,tgt in enumerate (targets ):
153
153
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 ]
155
155
MOM [insti [i ]:insti [i + 1 ]] = inst_mom
156
156
157
157
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
+
158
168
for j ,ev in enumerate (eps_vec ):
159
169
POSS [insti [i ]:insti [i + 1 ],j ] = mesh + ev + tgt .position
160
170
@@ -188,12 +198,12 @@ def getFTmagnet(sources, targets, eps=1e-5, anchor=None):
188
198
# targets: Cuboid object or 1D list of Cuboid objects
189
199
# Force and Torque acting on targets in the magnetic field generated by the sources
190
200
# will be computed. A target must have a valid `meshing` parameter.
191
-
201
+
192
202
# eps: float, default=1e-5
193
203
# The magnetic field gradient is computed using finite differences (FD). eps is
194
204
# the FD step size. A good value is 1e-5 * characteristic system size (magnet size,
195
205
# distance between sources and targets, ...).
196
-
206
+
197
207
# anchor: array_like, default=None
198
208
# The Force adds to the Torque via the anchor point. For a freely floating magnet
199
209
# 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):
292
302
CURR = np .zeros ((no_inst ,))
293
303
294
304
for i ,tgt in enumerate (targets ):
295
- verts = tgt .vertices
305
+ verts = tgt .orientation . apply ( tgt . vertices )
296
306
mesh = mesh_numbers [i ]
297
307
298
308
lvec = np .repeat (verts [1 :] - verts [:- 1 ], mesh , axis = 0 )/ mesh
299
309
LVEC [insti [i ]:insti [i + 1 ]] = lvec
300
310
301
311
CURR [insti [i ]:insti [i + 1 ]] = [tgt .current ]* mesh * seg_numbers [i ]
302
-
312
+
303
313
for j in range (seg_numbers [i ]):
304
314
poss = np .linspace (verts [j ]+ lvec [j * mesh ]/ 2 , verts [j + 1 ]- lvec [j * mesh ]/ 2 , mesh ) + tgt .position
305
315
POSS [insti [i ]+ mesh * j :insti [i ]+ mesh * (j + 1 )] = poss
0 commit comments