femagtools 1.6.2__py3-none-any.whl → 1.6.2a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
femagtools/__init__.py CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  """
4
4
  __title__ = 'femagtools'
5
- __version__ = '1.6.2'
5
+ __version__ = '1.6.2a1'
6
6
  __author__ = 'Ronald Tanner'
7
7
  __license__ = 'BSD'
8
8
  __copyright__ = 'Copyright 2016-2022 SEMAFOR Informatik & Energie AG'
femagtools/machine/pm.py CHANGED
@@ -154,10 +154,6 @@ class PmRelMachine(object):
154
154
  return torque - self.mtpa(i1)[2]
155
155
  i1 = so.fsolve(func, res.x[0])[0]
156
156
  return self.mtpa(i1)[:2]
157
- def func(iq):
158
- return torque - self.torque_iqd(iq, 0)
159
- return so.fsolve(func, 0)[0]
160
-
161
157
 
162
158
  def tqiq(iq):
163
159
  return torque - self.torque_iqd(float(iq), 0)
@@ -169,29 +165,36 @@ class PmRelMachine(object):
169
165
  if np.abs(torque) < 1e-2:
170
166
  return (0, 0)
171
167
  if np.isscalar(iqd0):
172
- i0 = self.io
168
+ tx = self.tmech_iqd(self.io[0], 0, n)
169
+ iq0 = min(0.9*self.i1range[1]/np.sqrt(2),
170
+ np.abs(torque)/tx*self.io[0])
171
+ if torque < 0:
172
+ i0 = (-iq0, 0)
173
+ else:
174
+ i0 = (iq0, 0)
175
+ logger.debug("initial guess i0 %f -> %s tx %f torque %f",
176
+ self.io[0], i0, tx, torque)
173
177
  else:
174
178
  i0 = iqd0
175
179
 
176
180
  if with_mtpa:
177
- res = so.minimize(
178
- lambda iqd: la.norm(iqd), i0, method='SLSQP',
179
- constraints=({'type': 'eq',
180
- 'fun': lambda iqd:
181
- self.tmech_iqd(*iqd, n) - torque}))
182
- if res.success:
183
- return res.x
184
-
185
- #logger.warning("n: %s, torque %s: %s %s",
186
- # 60*n, torque, res.message, i0)
187
- # try a different approach:
188
- #raise ValueError(
189
- # f'Torque {torque:.1f} speed {60*n:.1f} {res.message}')
190
- def func(i1):
191
- return torque - self.mtpa_tmech(i1, n)[2]
192
- i1 = so.fsolve(func, res.x[0])[0]
193
- return self.mtpa_tmech(i1, n)[:2]
194
-
181
+ k=0
182
+ while k < 5:
183
+ res = so.minimize(
184
+ lambda iqd: la.norm(iqd), i0, method='SLSQP',
185
+ constraints=({'type': 'eq',
186
+ 'fun': lambda iqd:
187
+ self.tmech_iqd(*iqd, n) - torque}))
188
+ if res.success:
189
+ return res.x
190
+ # make new initial guess:
191
+ tx = self.tmech_iqd(*i0, n)
192
+ logger.debug("k %d new guess i0 %s tx %f torque %f",
193
+ k, i0, tx, torque)
194
+ i0=(min(0.9*self.i1range[1]/np.sqrt(2), torque/tx*i0[0]), 0)
195
+ k += 1
196
+ raise ValueError(
197
+ f'Torque {torque} speed {n} {i0} {res.message}')
195
198
  def tqiq(iq):
196
199
  return torque - self.tmech_iqd(float(iq), 0, n)
197
200
  iq = so.fsolve(tqiq, (i0[0],))[0]
@@ -351,13 +354,13 @@ class PmRelMachine(object):
351
354
  beta)[0], i1)
352
355
 
353
356
  res = so.minimize(lambda iqd: np.linalg.norm(iqd), i0, method='SLSQP',
354
- constraints=(
355
- {'type': 'eq',
356
- 'fun': lambda iqd:
357
- self.tmech_iqd(*iqd, n) - torque},
358
- {'type': 'ineq',
359
- 'fun': lambda iqd:
360
- np.sqrt(2)*u1max - la.norm(self.uqd(w1, *iqd))}))
357
+ constraints=(
358
+ {'type': 'eq',
359
+ 'fun': lambda iqd:
360
+ self.tmech_iqd(*iqd, n) - torque},
361
+ {'type': 'ineq',
362
+ 'fun': lambda iqd:
363
+ np.sqrt(2)*u1max - la.norm(self.uqd(w1, *iqd))}))
361
364
  iq, id = res.x
362
365
  else:
363
366
  iq, id = i0
@@ -365,12 +368,15 @@ class PmRelMachine(object):
365
368
  try:
366
369
  log((iq,id))
367
370
  except:
368
- pass # logger is not correct
369
- logger.debug("iqd_tmech_umax w1=%f torque=%f %f iq=%f id=%f u1 u1 %f %f",
371
+ pass
372
+ logger.debug("iqd_tmech_umax w1=%f torque=%f %f iq=%f id=%f u1 %f %f",
370
373
  w1, torque, self.torque_iqd(iq, id), iq, id,
371
374
  u1max, np.linalg.norm(
372
375
  self.uqd(w1, iq, id))/np.sqrt(2))
373
- return iq, id, self.tmech_iqd(iq, id, n)
376
+ u1 = np.linalg.norm(
377
+ self.uqd(w1, iq, id))/np.sqrt(2)
378
+ tq = self.tmech_iqd(iq, id, n)
379
+ return iq, id, tq
374
380
 
375
381
  def iqd_torque_umax(self, torque, w1, u1max, log=0, with_mtpa=True):
376
382
  """return d-q current and torque at stator frequency and max voltage
@@ -681,17 +687,23 @@ class PmRelMachine(object):
681
687
  iq, id, T = self.mtpa(i1max)
682
688
  w1type = self.w1_umax(u1max, iq, id)
683
689
  Pmax = w1type/self.p*T
684
- w1max = 2*np.pi*speedmax*self.p
685
- # check max speed:
686
- if with_pmconst:
687
- iq, id, tq = self.iqd_pmech_imax_umax(
688
- speedmax, Pmax, i1max, u1max,
689
- with_mtpa, with_tmech)
690
- else:
691
- iq, id, tq = self.iqd_imax_umax(
692
- i1max, w1max, u1max,
693
- T, with_mtpv=False,
694
- with_tmech=with_tmech)
690
+ sp = speedmax
691
+ while sp > w1type/2/np.pi/self.p:
692
+ w1max = 2*np.pi*sp*self.p
693
+ try:
694
+ if with_pmconst:
695
+ iq, id, tq = self.iqd_pmech_imax_umax(
696
+ sp, Pmax, i1max, u1max,
697
+ with_mtpa, with_tmech)
698
+ else:
699
+ iq, id, tq = self.iqd_imax_umax(
700
+ i1max, w1max, u1max,
701
+ T, with_mtpv=False,
702
+ with_tmech=with_tmech)
703
+ break
704
+ except ValueError:
705
+ sp -= 5e-2*speedmax
706
+ speedmax = sp
695
707
  i1 = betai1(iq, id)[1]
696
708
  if (abs(i1max) >= i1
697
709
  and round(u1max, 1) >= round(np.linalg.norm(
@@ -922,6 +934,8 @@ class PmRelMachine(object):
922
934
 
923
935
  if speedrange[-1] < speedrange[-2]:
924
936
  speedrange = speedrange[:-1]
937
+ if speedrange[-1] < nmax:
938
+ logger.warning("adjusted nmax %f -> %f", nmax, speedrange[-1])
925
939
  logger.info("Speedrange T=%g Nm %s", Tf, speedrange)
926
940
  n3 = speedrange[-1]
927
941
  nstab = [int(nsamples*(x1-x2)/n3)
@@ -1135,7 +1149,11 @@ class PmRelMachineLdq(PmRelMachine):
1135
1149
  if np.any(beta[beta > np.pi]):
1136
1150
  beta[beta > np.pi] = beta - 2*np.pi
1137
1151
 
1138
- self.io = iqd((np.min(beta)+max(beta))/2, np.max(i1)/2)
1152
+ self.betarange = min(beta), max(beta)
1153
+ if min(beta) < -np.pi/2 and max(beta) > -np.pi/2:
1154
+ self.io = iqd(-np.pi/4, np.max(i1)/2)
1155
+ else:
1156
+ self.io = iqd((np.min(beta)+max(beta))/2, np.max(i1)/2)
1139
1157
  kx = ky = 3
1140
1158
  if len(i1) < 4:
1141
1159
  ky = len(i1)-1
@@ -1157,7 +1175,6 @@ class PmRelMachineLdq(PmRelMachine):
1157
1175
  logger.warning("loss map missing: %s", e)
1158
1176
  pass
1159
1177
  if 'psid' in kwargs:
1160
- self.betarange = min(beta), max(beta)
1161
1178
  self.i1range = (0, np.max(i1))
1162
1179
  self.psid = ip.RectBivariateSpline(
1163
1180
  beta, i1, np.sqrt(2)*np.asarray(kwargs['psid']),
@@ -1264,10 +1281,10 @@ class PmRelMachineLdq(PmRelMachine):
1264
1281
  r = self._losses['magnet'](beta, i1)*(f1/self.fo)**2
1265
1282
  try:
1266
1283
  idx = np.argwhere(r < 0)
1267
- if len(idx.squeeze()):
1284
+ if len(idx.squeeze()):
1268
1285
  r[idx.squeeze()] = 0.0
1269
- except:
1270
- pass
1286
+ except:
1287
+ pass
1271
1288
  return r
1272
1289
 
1273
1290
  def iqd_plmag(self, iq, id, f1):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: femagtools
3
- Version: 1.6.2
3
+ Version: 1.6.2a1
4
4
  Summary: Python API for FEMAG
5
5
  Author-email: Ronald Tanner <tar@semafor.ch>, Dapu Zhang <dzhang@gtisoft.com>, Beat Holm <hob@semafor.ch>, Günther Amsler <amg@semafor.ch>, Nicolas Mauchle <mau@semafor.ch>
6
6
  License: Copyright (c) 2016-2023, Semafor Informatik & Energie AG, Basel
@@ -1,4 +1,4 @@
1
- femagtools/__init__.py,sha256=UUpTqpPxTE9-KNmWFDhqdB2Sy56sR68HZdRSYl0X3BA,1615
1
+ femagtools/__init__.py,sha256=0Czmc00qOcerVrb_HqxErbf-Nydh8tEB0bNJ7clxtWI,1617
2
2
  femagtools/airgap.py,sha256=ZCIZTYf6BbuNYx68y9fUDBQo3taN8RuGl8q-jJ7ygiA,1577
3
3
  femagtools/amazon.py,sha256=O1ICuv21XDAJi1qK1Sigs2TdS6hDZP19OzvmE2t76wU,12069
4
4
  femagtools/amela.py,sha256=pHjfXzpANI-7oz8MtrqNcyDZ6PxVM91vCJuvYhHy1rk,13891
@@ -62,7 +62,7 @@ femagtools/machine/__init__.py,sha256=U8W65K7jr7jDdC1KnJh0WjYd8DFaLnIFVvlh-TKcV9
62
62
  femagtools/machine/afpm.py,sha256=hNyDFRLGmCuWRPZl_u1ztJ4pA-Y_mxLaVvg3UJkzRuE,24766
63
63
  femagtools/machine/effloss.py,sha256=I8s2Fog6klhgcRYw3448qfGvzaQ0AQUJXFdNoeDyhfE,13138
64
64
  femagtools/machine/im.py,sha256=ScIOLrlc4CPLYFNx2MmJqkpmbky_HXxFGZbMWUNGBrk,37881
65
- femagtools/machine/pm.py,sha256=R8RWzQrMI_fNaUU7ruHnQxg3-Lubh1vp-6EG6z5QbRk,56229
65
+ femagtools/machine/pm.py,sha256=lSZy5fQo2meI9ISRCoQGdHKoVTpreaoucZoTlQclQpI,57059
66
66
  femagtools/machine/sizing.py,sha256=aN_OahewjTTBHnpRNfLh1AGFhqnoeZVuMBeb_3MCIVI,23096
67
67
  femagtools/machine/sm.py,sha256=pkik913kU41PPiUpwDy_6BEKfCIhvY6FEp-fbU2Lqew,34320
68
68
  femagtools/machine/utils.py,sha256=g9q4j9KxUWdb_iUOUQDuaAwwJx8XM0kZMpgnwsNz8hU,18616
@@ -200,9 +200,9 @@ tests/moo/__init__.py,sha256=l8HD-AY8EwxOoo_VrG3HgEZb2MaHypvnhKCVSkR-DTA,808
200
200
  tests/moo/test_algorithm.py,sha256=Em8sFm2vzPmuIzRrBBnUQLU_TYuJHSf-kEeozw0XeX4,2563
201
201
  tests/moo/test_population.py,sha256=FvX9LRCxQx0_E2GxHQ5vKwOYFBQiNbT6Lmv5GmNWjTQ,5471
202
202
  tests/moo/test_problem.py,sha256=ALeP4u7g-dFhfwWL8vxivdrrYzVKPjHMCAXzzgyNZbs,467
203
- femagtools-1.6.2.dist-info/LICENSE,sha256=V5OED7AzEaOtvbfgNheKOSUeNtijvKQuo84FtSJNkJU,1316
204
- femagtools-1.6.2.dist-info/METADATA,sha256=_Fn2D61D0C-a96X_49iBhYauUSoeaM6AAR28-QDL1is,5685
205
- femagtools-1.6.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
206
- femagtools-1.6.2.dist-info/entry_points.txt,sha256=UXpu6KnrykN89sCUaFAIIzn_dYwuxizUS0GcPdoekro,195
207
- femagtools-1.6.2.dist-info/top_level.txt,sha256=Ri4YWtU8MZTzNje9IKyXhTakNbsrCynuWdon4Yq94Dc,17
208
- femagtools-1.6.2.dist-info/RECORD,,
203
+ femagtools-1.6.2a1.dist-info/LICENSE,sha256=V5OED7AzEaOtvbfgNheKOSUeNtijvKQuo84FtSJNkJU,1316
204
+ femagtools-1.6.2a1.dist-info/METADATA,sha256=oLG4odGgDU9q0mHzRwan00p1Ko9dtPy-1ReLG1-zxQI,5687
205
+ femagtools-1.6.2a1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
206
+ femagtools-1.6.2a1.dist-info/entry_points.txt,sha256=UXpu6KnrykN89sCUaFAIIzn_dYwuxizUS0GcPdoekro,195
207
+ femagtools-1.6.2a1.dist-info/top_level.txt,sha256=Ri4YWtU8MZTzNje9IKyXhTakNbsrCynuWdon4Yq94Dc,17
208
+ femagtools-1.6.2a1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5