femagtools 1.7.8__py3-none-any.whl → 1.8.0__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.
Files changed (54) hide show
  1. femagtools/__init__.py +1 -1
  2. femagtools/amela.py +2 -2
  3. femagtools/dxfsl/area.py +142 -9
  4. femagtools/dxfsl/conv.py +2 -9
  5. femagtools/dxfsl/converter.py +33 -9
  6. femagtools/dxfsl/fslrenderer.py +13 -12
  7. femagtools/dxfsl/geom.py +39 -6
  8. femagtools/dxfsl/journal.py +2 -2
  9. femagtools/dxfsl/machine.py +14 -13
  10. femagtools/dxfsl/shape.py +3 -0
  11. femagtools/dxfsl/svgparser.py +31 -4
  12. femagtools/ecloss.py +381 -2
  13. femagtools/femag.py +55 -0
  14. femagtools/fsl.py +74 -47
  15. femagtools/isa7.py +41 -0
  16. femagtools/job.py +2 -2
  17. femagtools/machine/afpm.py +5 -1
  18. femagtools/machine/pm.py +1 -1
  19. femagtools/machine/sm.py +14 -0
  20. femagtools/machine/utils.py +4 -3
  21. femagtools/mcv.py +128 -124
  22. femagtools/me.py +13 -13
  23. femagtools/model.py +14 -1
  24. femagtools/moo/population.py +9 -7
  25. femagtools/nc.py +12 -0
  26. femagtools/plot/__init__.py +1 -1
  27. femagtools/plot/fieldlines.py +1 -1
  28. femagtools/plot/mcv.py +18 -0
  29. femagtools/plot/nc.py +22 -5
  30. femagtools/plot/wdg.py +40 -7
  31. femagtools/svgfsl/converter.py +6 -0
  32. femagtools/templates/gen_hairpin_winding.mako +36 -45
  33. femagtools/templates/gen_winding.mako +7 -0
  34. femagtools/templates/magnetIron.mako +30 -46
  35. femagtools/templates/magnetIron2.mako +39 -0
  36. femagtools/templates/magnetIron3.mako +39 -0
  37. femagtools/templates/magnetIron4.mako +39 -0
  38. femagtools/templates/magnetIron5.mako +39 -0
  39. femagtools/templates/magnetIronV.mako +34 -54
  40. femagtools/templates/magnetSector.mako +32 -47
  41. femagtools/templates/mesh-airgap.mako +12 -6
  42. femagtools/templates/prepare_thermal.mako +354 -0
  43. femagtools/templates/statorRotor3.mako +3 -22
  44. femagtools/windings.py +92 -59
  45. {femagtools-1.7.8.dist-info → femagtools-1.8.0.dist-info}/METADATA +20 -18
  46. {femagtools-1.7.8.dist-info → femagtools-1.8.0.dist-info}/RECORD +53 -53
  47. {femagtools-1.7.8.dist-info → femagtools-1.8.0.dist-info}/WHEEL +1 -1
  48. tests/test_fsl.py +1 -1
  49. tests/test_mcv.py +106 -1
  50. tests/test_windings.py +18 -2
  51. tests/test_mcvwriter.py +0 -96
  52. {femagtools-1.7.8.dist-info → femagtools-1.8.0.dist-info}/LICENSE +0 -0
  53. {femagtools-1.7.8.dist-info → femagtools-1.8.0.dist-info}/entry_points.txt +0 -0
  54. {femagtools-1.7.8.dist-info → femagtools-1.8.0.dist-info}/top_level.txt +0 -0
femagtools/mcv.py CHANGED
@@ -103,6 +103,54 @@ def norm_pfe(B, pfe):
103
103
  for x in Bv[:n]] + [None]*(len(Bv)-n))
104
104
  return Bv.tolist(), m
105
105
 
106
+ def extrapol(crv, jsat=0, bmax=3):
107
+ """extends BH curve into saturation range"""
108
+ curve = copy.deepcopy(crv)
109
+ dh = curve['hi'][-1]-curve['hi'][-2]
110
+ db = curve['bi'][-1]-curve['bi'][-2]
111
+ mue_d = db/dh
112
+ mue = curve['bi'][-1]/curve['hi'][-1]
113
+ db = 3e-2*curve['bi'][-1]
114
+ b2 = 1.5
115
+
116
+ curve['muer'] = [b/MUE0/h if h>0 else float('nan')
117
+ for b, h in zip(curve['bi'],
118
+ curve['hi'])]
119
+
120
+ # extend bh-curve into saturation
121
+ while mue_d > 1.01*MUE0 and mue > 1.5*MUE0:
122
+ mue_d = MUE0 + (mue_d-MUE0)/np.sqrt(b2)
123
+ curve['bi'].append(curve['bi'][-1]+db)
124
+ curve['hi'].append(curve['hi'][-1]+db/mue_d)
125
+ curve['muer'].append(curve['bi'][-1]/MUE0/curve['hi'][-1])
126
+ b2 += 2
127
+ mue = curve['bi'][-1]/curve['hi'][-1]
128
+
129
+ # Fröhlich-Kennelly coefficients
130
+ if jsat:
131
+ hx = curve['hi'][-1]
132
+ bx = curve['bi'][-1]
133
+ fkb = 1./jsat
134
+ fka = (hx/(bx - MUE0*hx) - hx/jsat)
135
+ else:
136
+ Js1 = curve['bi'][-1] - MUE0*curve['hi'][-1]
137
+ Js0 = curve['bi'][-2] - MUE0*curve['hi'][-2]
138
+ fkb = ((curve['hi'][-1]/Js1 - curve['hi'][-2]/Js0)
139
+ /(curve['hi'][-1] - curve['hi'][-2]))
140
+ fka = curve['hi'][-1]/Js1 - fkb*curve['hi'][-1]
141
+ logger.debug("B values %d Fröhlich-Kennelly coeffs: a %f b %f",
142
+ len(curve['bi']), fka, fkb)
143
+ bstep = 0.15
144
+ bx = np.arange(curve['bi'][-1] + bstep, bmax, bstep)
145
+ # Fröhlich-Kennelly approximation
146
+ b = fkb * bx - MUE0*fka - 1
147
+ a = fkb * bx
148
+ c = MUE0*fka
149
+ nuer = (b + np.sqrt(b*b + 4*a*c))/2/a
150
+ curve['bi'] += bx.tolist()
151
+ curve['hi'] += (nuer*bx/MUE0).tolist()
152
+ return curve
153
+
106
154
 
107
155
  def recalc_bsin(curve):
108
156
  """recalculates B-H curve (static problems) into effective
@@ -159,7 +207,7 @@ def recalc_hsin(curve):
159
207
  return ncurve
160
208
 
161
209
 
162
- def approx(db2, curve):
210
+ def approx(db2, curve, ctype):
163
211
  """return nuer, bi2, a, b approx for curve"""
164
212
  nuek0 = (curve['hi'][1] - curve['hi'][0]) / \
165
213
  (curve['bi'][1]-curve['bi'][0])
@@ -191,12 +239,22 @@ def approx(db2, curve):
191
239
  nuer.append(MUE0*nuek1)
192
240
  bi2.append(bk12)
193
241
 
194
- a.append(1.0)
195
- b.append(MUE0*curve['hi'][-1]-curve['bi'][-1])
242
+ if ctype in (DEMCRV, MAG_AC_CRV):
243
+ dhdbn = 0
244
+ k = len(bi2)-1
245
+ if curve['bi'][k] - curve['bi'][k-1] > 0:
246
+ dhdbn = ((curve['hi'][k] - curve['h'][k-1],KK)
247
+ /(curve['bi'][k] - curve['bi'][k-1]))
248
+ a.append(MUE0*dhdbn)
249
+ b.append(MUE0*curve['hi'][k] - dhdbn*curve['bi'][k])
250
+ else:
251
+ a.append(1.0)
252
+ b.append(MUE0*curve['hi'][-1]-curve['bi'][-1])
196
253
  return dict(nuer=nuer, a=a, b=b, bi2=bi2)
197
254
 
198
255
 
199
256
  def fe_sat_mag(curve):
257
+ """returns maximum polarization of all BH curves"""
200
258
  fesat = 0
201
259
  for c in curve:
202
260
  js2 = c['bi'][-1] - MUE0*c['hi'][-1]
@@ -219,7 +277,7 @@ def findNotNone(l):
219
277
 
220
278
 
221
279
  class Mcv(object):
222
- def __init__(self):
280
+ def __init__(self, data={}):
223
281
  # default values from file: mcv.par
224
282
  self.ACT_VERSION_MC_CURVE = 0
225
283
  self.ORIENTED_VERSION_MC_CURVE = 1
@@ -248,7 +306,6 @@ class Mcv(object):
248
306
  self.mc1_induction_factor = self.MC1_INDUCTION_FACTOR
249
307
  self.mc1_induction_beta_factor = self.MC1_INDUCTION_BETA_FACTOR
250
308
  self.mc1_fe_spez_weigth = self.MC1_FE_SPEZ_WEIGTH
251
- self.mc1_fe_sat_magnetization = self.MC1_FE_SAT_MAGNETIZATION
252
309
 
253
310
  self.mc1_title = ''
254
311
  self.version_mc_curve = self.ACT_VERSION_MC_CURVE
@@ -274,26 +331,18 @@ class Mcv(object):
274
331
 
275
332
  self.mc1_energy = [[0]*self.MCURVES_MAX]*self.MC1_NIMAX
276
333
 
277
- def rtrimValueList(self, vlist):
278
- """cut list at first 0"""
279
- le = len(vlist)
280
- for i in range(le-1, -1, -1):
281
- if vlist[i] != 0.:
282
- break
283
- return list(vlist[:i+1])
284
-
285
- def __getitem__(self, key):
286
- if key == 'ctype': # for compatibility purposes
287
- return self.mc1_type
288
- return getattr(self, key)
289
-
290
-
291
- class Writer(Mcv):
292
- def __init__(self, data=None):
293
- Mcv.__init__(self)
294
334
  if data:
295
335
  self.setData(data)
296
336
 
337
+ self.mc1_curves = len(self.curve)
338
+ if self.mc1_type == MAGCRV and self.mc1_curves > 1:
339
+ self.mc1_type = ORIENT_CRV
340
+ if self.mc1_type in (ORIENT_CRV, ORIENT_PM_CRV):
341
+ self.version_mc_curve = self.ORIENTED_VERSION_MC_CURVE
342
+ elif self.mc1_type == DEMCRV_BR:
343
+ self.version_mc_curve = self.PARAMETER_PM_CURVE
344
+
345
+
297
346
  def __setattr__(self, key, val):
298
347
  try:
299
348
  self.__dict__[key] = val
@@ -317,6 +366,24 @@ class Writer(Mcv):
317
366
  pass
318
367
  return
319
368
 
369
+ def rtrimValueList(self, vlist):
370
+ """cut list at first 0"""
371
+ le = len(vlist)
372
+ for i in range(le-1, -1, -1):
373
+ if vlist[i] != 0.:
374
+ break
375
+ return list(vlist[:i+1])
376
+
377
+ def __getitem__(self, key):
378
+ if key == 'ctype': # for compatibility purposes
379
+ return self.mc1_type
380
+ return getattr(self, key)
381
+
382
+
383
+ class Writer(Mcv):
384
+ def __init__(self, data=None):
385
+ Mcv.__init__(self, data)
386
+
320
387
  def getBlockLength(self, d):
321
388
  if isinstance(d, string_types) or isinstance(d, bytes):
322
389
  try:
@@ -374,11 +441,6 @@ class Writer(Mcv):
374
441
 
375
442
  def _prepare(self, fillfac, recsin):
376
443
  """prepare output format (internal use only)"""
377
- if self.mc1_type in (ORIENT_CRV, ORIENT_PM_CRV):
378
- self.version_mc_curve = self.ORIENTED_VERSION_MC_CURVE
379
- elif self.mc1_type == DEMCRV_BR:
380
- self.version_mc_curve = self.PARAMETER_PM_CURVE
381
-
382
444
  curve = copy.deepcopy(self.curve)
383
445
  if fillfac:
384
446
  alpha = fillfac/self.mc1_fillfac
@@ -392,17 +454,17 @@ class Writer(Mcv):
392
454
  if fillfac or recsin:
393
455
  if hasattr(self, 'mc1_fe_sat_magnetization'):
394
456
  self.mc1_fe_sat_magnetization = fe_sat_mag(curve)
395
- logger.info("%s Type: %d Num Curves %d",
457
+ logger.info("%s Type: %d (%s) Num Curves %d",
396
458
  self.name, self.version_mc_curve,
459
+ types[self.mc1_type],
397
460
  len(self.curve))
398
- self.mc1_curves = len(self.curve)
399
461
  self.mc1_ni = [min(len(c['hi']),
400
462
  len(c['bi']))
401
463
  for c in self.curve if 'hi' in c]
402
464
  self.mc1_db2 = [(c['bi'][-1]**2 - c['bi'][0]**2)/n
403
465
  for c, n in zip(curve, self.mc1_mi)]
404
466
  for db2, c in zip(self.mc1_db2, curve):
405
- c.update(approx(db2, c))
467
+ c.update(approx(db2, c, self.mc1_type))
406
468
  if not hasattr(self, 'mc1_fe_sat_magnetization'):
407
469
  self.mc1_fe_sat_magnetization = fe_sat_mag(curve)
408
470
  self.mc1_mi = [len(c['a'])
@@ -513,6 +575,7 @@ class Writer(Mcv):
513
575
  self.mc1_cw_factor = cw
514
576
  self.mc1_cw_freq_factor = beta
515
577
  self.mc1_induction_factor = gamma
578
+
516
579
  except AttributeError:
517
580
  pass
518
581
  self.writeBlock([float(self.mc1_base_frequency),
@@ -528,10 +591,10 @@ class Writer(Mcv):
528
591
  if not hasattr(self, 'losses') or not self.losses:
529
592
  # new variables: ce factor for bertotti losses
530
593
  # b_beta_coeff for modified steinmetz
531
- try:
532
- self.writeBlock([float(self.mc1_ce_factor),
594
+ try:
595
+ self.writeBlock([float(self.mc1_ce_factor),
533
596
  float(self.mc1_induction_beta_factor)])
534
- except:
597
+ except:
535
598
  pass
536
599
  return
537
600
 
@@ -599,7 +662,7 @@ class Writer(Mcv):
599
662
  logger.info('Losses n freq %d n ind %d', nfreq, nind)
600
663
  except Exception as e:
601
664
  logger.error("Exception %s", e, exc_info=True)
602
-
665
+
603
666
  def writeMcv(self, filename, fillfac=None, recsin=''):
604
667
  # windows needs this strip to remove '\r'
605
668
  filename = filename.strip()
@@ -612,7 +675,7 @@ class Writer(Mcv):
612
675
  else:
613
676
  binary = False
614
677
  self.fp = open(filename, "wb")
615
- logger.info("Write File %s, binary format %d", filename, binary)
678
+ logger.info("Write File %s, binary format", filename)
616
679
 
617
680
  self.writeBinaryFile(fillfac, recsin)
618
681
  self.fp.close()
@@ -737,8 +800,9 @@ class Reader(Mcv):
737
800
  if self.version_mc_curve == self.ORIENTED_VERSION_MC_CURVE or \
738
801
  self.version_mc_curve == self.PARAMETER_PM_CURVE:
739
802
  self.mc1_curves = int(line[4])
740
- logger.debug("MC file %s Version %s Curves %d",
741
- filename, self.version_mc_curve, self.mc1_curves)
803
+ logger.info("Read file %s %s Type: %d (%s) Num Curves %d",
804
+ filename, self.name, self.version_mc_curve,
805
+ types[self.mc1_type], self.mc1_curves)
742
806
  if self.mc1_type == DEMCRV_BR:
743
807
  self.mc1_angle[self.mc1_curves-1] = self.mc1_remz
744
808
 
@@ -873,7 +937,7 @@ class Reader(Mcv):
873
937
 
874
938
  self.ce = 0
875
939
  self.b_beta_coeff = 0
876
- try:
940
+ try:
877
941
  if not self.losses['f'][0]:
878
942
  self.fp.seek(-16, 1)
879
943
  res = self.readBlock([float]*2)
@@ -882,30 +946,33 @@ class Reader(Mcv):
882
946
  pass
883
947
 
884
948
  def get_results(self):
949
+ self.desc = self.mc1_title
950
+ self.fillfac = self.mc1_fillfac
951
+ #self.cversion = self.version_mc_curve
885
952
  result = {
886
- 'name': self.name,
887
- 'desc': self.mc1_title,
888
- 'cversion': self.version_mc_curve,
889
- 'ctype': self.mc1_type,
890
- 'recalc': self.mc1_recalc,
891
- 'remz': self.mc1_remz,
892
- 'bsat': self.mc1_bsat,
893
- 'bref': self.mc1_bref,
894
- 'fillfac': self.mc1_fillfac,
895
- 'fo': self.fo,
896
- 'Bo': self.Bo,
897
- 'ch': self.ch,
898
- 'ch_freq': self.ch_freq,
899
- 'cw': self.cw,
900
- 'ce': self.ce,
901
- 'b_beta_coeff': self.b_beta_coeff,
902
- 'cw_freq': self.cw_freq,
903
- 'b_coeff': self.b_coeff,
904
- 'rho': self.rho,
905
- 'fe_sat_mag': self.fe_sat_mag,
906
- 'curve': [{k: c[k] for k in ('hi', 'bi')}
907
- for c in self.curve]
908
- }
953
+ k: getattr(self, k) for k in (
954
+ 'name',
955
+ 'desc',
956
+ 'cversion',
957
+ 'ctype',
958
+ 'recalc',
959
+ 'remz',
960
+ 'bsat',
961
+ 'bref',
962
+ 'fillfac',
963
+ 'fo',
964
+ 'Bo',
965
+ 'ch',
966
+ 'ch_freq',
967
+ 'cw',
968
+ 'ce',
969
+ 'b_beta_coeff',
970
+ 'cw_freq',
971
+ 'b_coeff',
972
+ 'rho',
973
+ 'fe_sat_mag') if hasattr(self, k)}
974
+ result['curve'] = [{k: c[k] for k in ('hi', 'bi')}
975
+ for c in self.curve]
909
976
  try:
910
977
  if self.losses:
911
978
  result['losses'] = self.losses
@@ -1003,69 +1070,6 @@ class MagnetizingCurve(object):
1003
1070
  pass
1004
1071
  return None
1005
1072
 
1006
- def recalc(self):
1007
- for m in self.mcv:
1008
- curve = self.mcv[m]['curve'][0]
1009
- mi = MC1_MIMAX-2
1010
- dh = curve['hi'][-1]-curve['hi'][-2]
1011
- db = curve['bi'][-1]-curve['bi'][-2]
1012
- dmue_d = db/dh
1013
- dmue = curve['bi'][-1]/curve['hi'][-1]
1014
- db = 3e-2*curve['bi'][-1]
1015
- n3 = 1.5
1016
-
1017
- curve['muer'] = [b/MUE0/h
1018
- for b, h in zip(curve['bi'],
1019
- curve['hi'])]
1020
-
1021
- # extend bh-curve into saturation
1022
- while dmue_d > 1.01*MUE0 and dmue > 1.5*MUE0:
1023
- dmue_d = MUE0 + (dmue_d-MUE0)/np.sqrt(n3)
1024
- curve['bi'].append(curve['bi'][-1]+db)
1025
- curve['hi'].append(curve['hi'][-1]+db/dmue_d)
1026
- curve['muer'].append(curve['bi'][-1]/MUE0/curve['hi'][-1])
1027
- n3 += 0.2
1028
- dmue = curve['bi'][-1]/curve['hi'][-1]
1029
-
1030
- self.mcv[m]['db2'] = (curve['bi'][-1]**2 -
1031
- curve['bi'][0]**2)/(mi-1)
1032
- nuek0 = (curve['hi'][1] - curve['hi'][0]) / \
1033
- (curve['bi'][1]-curve['bi'][0])
1034
- for j1 in range(len(curve['bi'])):
1035
- bk02 = curve['bi'][j1]**2
1036
- if bk02 > 0:
1037
- break
1038
- curve['nuer'] = [MUE0*nuek0]
1039
- curve['bi2'] = [bk02]
1040
- curve['a'] = []
1041
- curve['b'] = []
1042
-
1043
- bk1 = 0.0
1044
- while bk1 <= curve['bi'][-1]:
1045
- bk12 = bk02 + self.mcv[m]['db2']
1046
- bk1 = np.sqrt(bk12)
1047
- j = 2
1048
- while j < len(curve['bi']) and bk1 <= curve['bi'][j]:
1049
- j += 1
1050
- j -= 1
1051
- bdel = curve['bi'][j] - curve['bi'][j1]
1052
- c1 = (curve['hi'][j] - curve['hi'][j1])/bdel
1053
- c2 = curve['hi'][j1] - c1*curve['bi'][j1]
1054
-
1055
- nuek1 = c1 + c2/bk1
1056
-
1057
- curve['a'].append(MUE0*(bk12*nuek0 -
1058
- bk02*nuek1)/self.mcv[m]['db2'])
1059
- curve['b'].append(MUE0*(nuek1 - nuek0)/self.mcv[m]['db2'])
1060
- nuek0 = nuek1
1061
- bk02 = bk12
1062
-
1063
- curve['nuer'].append(MUE0*nuek1)
1064
- curve['bi2'].append(bk12)
1065
-
1066
- curve['a'].append(1.0)
1067
- curve['b'].append(MUE0*curve['hi'][-1]-curve['bi'][-1])
1068
-
1069
1073
  def fix_name(self, name, fillfac=1.0):
1070
1074
  """return os compatible mcv name including fillfac"""
1071
1075
  if not self.find_by_name(name):
femagtools/me.py CHANGED
@@ -3,8 +3,8 @@ Postprocessing FEMAG-ME results
3
3
  """
4
4
  __author__ = 'dapu zhang'
5
5
 
6
- import re
7
- import numpy as np
6
+ import re
7
+ import numpy as np
8
8
  import matplotlib.pyplot as plt
9
9
  import logging
10
10
 
@@ -16,33 +16,33 @@ def get_eigenvectors(filelist, psfiles):
16
16
  eigenvecs = {}
17
17
  eigenfreq = []
18
18
  ps_data = []
19
- temp = []
19
+ temp = []
20
20
  temp_arr = []
21
21
  read_fig = False
22
22
 
23
23
  if len(psfiles) > 0: read_fig = True
24
24
  if len(filelist) == 0: return []
25
-
26
- for k, kk in zip(filelist, range(len(filelist))):
25
+
26
+ for k, kk in zip(filelist, range(len(filelist))):
27
27
  # read ps file
28
28
  if read_fig: ps_data.append(plt.imread(psfiles[kk]))
29
29
  eigenvecs[str(kk)] = {}
30
- with open(k, 'r') as f:
30
+ with open(k, 'r') as f:
31
31
  data = f.read().split('\n')
32
- eigenval = float(re.split('\s+', data[0].strip())[2])
32
+ eigenval = float(re.split(r'\s+', data[0].strip())[2])
33
33
  eigenfreq.append(eigenval/2/np.pi)
34
-
35
- for i in range(len(data[1:-1])):
36
- for j in data[2+i].strip().split(' '):
34
+
35
+ for i in range(len(data[1:-1])):
36
+ for j in data[2+i].strip().split(' '):
37
37
  if j != '':
38
38
  temp.append(float(j))
39
39
 
40
40
  temp_arr = np.array(temp).reshape(-1, 5)
41
41
  idx_collect = []
42
42
  # remove the index, at which the dof equals zero
43
- for c in range(temp_arr.shape[0]):
43
+ for c in range(temp_arr.shape[0]):
44
44
  if np.abs(temp_arr[c, 1]) < 1e-15 and \
45
- np.abs(temp_arr[c, 2]) < 1e-15:
45
+ np.abs(temp_arr[c, 2]) < 1e-15:
46
46
  idx_collect.append(c)
47
47
  # prepare the data from the further calculation
48
48
  temp_arr = np.delete(temp_arr, np.array(idx_collect), axis=0)
@@ -52,4 +52,4 @@ def get_eigenvectors(filelist, psfiles):
52
52
  # return node position
53
53
  if kk == 0: eigenvecs.update({'node_pos': temp_arr[:, 4::]})
54
54
 
55
- return [ps_data, eigenfreq, eigenvecs]
55
+ return [ps_data, eigenfreq, eigenvecs]
femagtools/model.py CHANGED
@@ -386,6 +386,13 @@ class MachineModel(Model):
386
386
  if mcv:
387
387
  logger.debug('shaft mcv %s', mcv)
388
388
  rotor['mcvkey_shaft'] = magcurves.fix_name(mcv)
389
+ mshaft = magcurves.find_by_name(mcv)
390
+ thkeys_shaft = ['thcond', 'thcap', 'rho']
391
+ if mshaft and set(thkeys_shaft).issubset(mshaft.keys()):
392
+ for k in thkeys_shaft:
393
+ rotor[k+'_shaft'] = mshaft[k]
394
+ rotor['spmaweight_shaft'] = rotor['rho_shaft']
395
+
389
396
  self.stator['mcvkey_shaft_name'] = mcv
390
397
  names.append((mcv, 1.0))
391
398
  else:
@@ -435,7 +442,7 @@ class MachineModel(Model):
435
442
 
436
443
  def is_complete(self):
437
444
  """check completeness of models"""
438
- if self.is_dxffile():
445
+ if self.is_dxffile() or self.is_svgfile():
439
446
  return True
440
447
  try:
441
448
  self.statortype()
@@ -453,6 +460,12 @@ class MachineModel(Model):
453
460
  return True
454
461
  return False
455
462
 
463
+ def is_svgfile(self):
464
+ if 'svgfile' in self.__dict__:
465
+ if isinstance(self.svgfile, dict):
466
+ return True
467
+ return False
468
+
456
469
  def has_magnet(self): # either rotor or magnet
457
470
  return hasattr(self, 'magnet')
458
471
 
@@ -198,21 +198,23 @@ class Population:
198
198
  self.update_pareto_information()
199
199
  retval = [[] for s in range(max(self.pareto_rank)+1)]
200
200
  for i, j in enumerate(self.individuals):
201
- retval[self.pareto_rank[i]].append(i)
201
+ retval[self.pareto_rank[i]].append(j)
202
202
  return retval
203
203
 
204
204
  def compute_ideal(self):
205
- return [min(x)
205
+ return [np.min(np.array(x)[np.isfinite(x)])
206
206
  for x in zip(*[i.cur_f
207
- for i in self.individuals if i.rank == 0])]
207
+ for i in self.individuals
208
+ if i.rank == 0])]
208
209
 
209
210
  def compute_nadir(self):
210
- return [max(x)
211
+ return [np.max(np.array(x)[np.isfinite(x)])
211
212
  for x in zip(*[i.cur_f
212
- for i in self.individuals if i.rank == 0])]
213
+ for i in self.individuals
214
+ if i.rank == 0])]
213
215
 
214
216
  def compute_worst(self):
215
- return [max(x)
217
+ return [np.max(np.array(x)[np.isfinite(x)])
216
218
  for x in zip(*[i.cur_f
217
219
  for i in self.individuals])]
218
220
 
@@ -252,7 +254,7 @@ class Population:
252
254
  raise ValueError(
253
255
  'Invalid components of the objective function selected for plot')
254
256
 
255
- p_dim = self.problem.f_dimension
257
+ p_dim = self.problem.f_dim
256
258
 
257
259
  if p_dim == 1:
258
260
  raise ValueError(
femagtools/nc.py CHANGED
@@ -23,6 +23,7 @@ class Reader(object):
23
23
 
24
24
  def __init__(self, filename):
25
25
  ds = netCDF4.Dataset(filename)
26
+ node_temperature = None
26
27
  self.POINT_ISA_POINT_REC_PT_CO_X = []
27
28
  self.POINT_ISA_POINT_REC_PT_CO_Y = []
28
29
  self.LINE_ISA_LINE_REC_LN_PNT_1 = []
@@ -54,6 +55,11 @@ class Reader(object):
54
55
  grp.variables[k][:-1]
55
56
  for k in ('bnd_cnd', 'bnd_cnd', 'per_nod',
56
57
  'co_1', 'co_2', 'co_rad', 'co_phi', 'vp_re', 'vp_im')]
58
+ try:
59
+ node_temperature = grp.variables['temperature'][:-1]
60
+ except:
61
+ pass
62
+
57
63
  logger.debug('Nodes: %d', len(self.NODE_ISA_NODE_REC_ND_CO_1))
58
64
 
59
65
  grp = ds.groups['node_elements']
@@ -198,9 +204,15 @@ class Reader(object):
198
204
  self.poles_sim = int(grp.variables['poles_sim'].getValue().data)
199
205
  self.slots = int(grp.variables['num_slots'].getValue().data)
200
206
  self.arm_length = float(grp.variables['arm_length'].getValue().data)
207
+ self.state_of_problem = int(grp.variables['state_of_problem'].getValue().data)
201
208
  except:
202
209
  pass
203
210
 
211
+ if hasattr(self, 'state_of_problem'):
212
+ if self.state_of_problem == 5:
213
+ # th simulation
214
+ if node_temperature is not None:
215
+ self.NODE_ISA_NODE_REC_ND_VP_IM = node_temperature
204
216
  self.MAGN_TEMPERATURE = 20
205
217
  self.BR_TEMP_COEF = 0
206
218
  try:
@@ -16,5 +16,5 @@ from .nc import spel, mesh, demag, demag_pos, \
16
16
  airgap_flux_density_pos, loss_density
17
17
  from .mcv import mcv_hbj, mcv_muer, felosses
18
18
  from .phasor import i1beta_phasor, iqd_phasor, phasor
19
- from .wdg import mmf, mmf_fft, zoneplan, winding_factors, winding
19
+ from .wdg import mmf, mmf_fft, zoneplan, winding_factors, winding, currdist
20
20
  from .fieldlines import fieldlines
@@ -4,7 +4,7 @@ import matplotlib.pyplot as plt
4
4
  import numpy as np
5
5
  import matplotlib.lines as mpl
6
6
 
7
- rgbpat = re.compile('rgb\((\d+),(\d+),(\d+)\)')
7
+ rgbpat = re.compile(r'rgb\((\d+),(\d+),(\d+)\)')
8
8
 
9
9
  def fieldlines(svgfilename, ax=0):
10
10
  """plot fieldlines from svg file"""
femagtools/plot/mcv.py CHANGED
@@ -37,10 +37,12 @@ def mcv_hbj(mcv, log=True, ax=0):
37
37
  label = 'Flux Density ({0}°)'.format(mcv.mc1_angle[k])
38
38
  if log:
39
39
  ax.semilogx(hi, bi, label=label)
40
+ ax.semilogx(hi, bi, 'k.')
40
41
  if ji:
41
42
  ax.semilogx(hi, ji, label='Polarisation')
42
43
  else:
43
44
  ax.plot(hi, bi, label=label)
45
+ ax.plot(hi, bi, 'k.')
44
46
  if ji:
45
47
  ax.plot(hi, ji, label='Polarisation')
46
48
  ax.set_xlabel('H / kA/m')
@@ -59,10 +61,26 @@ def mcv_muer(mcv, ax=0):
59
61
  if ax == 0:
60
62
  ax = plt.gca()
61
63
  ax.plot(bi, ur)
64
+ ax.plot(bi, ur, 'k.')
62
65
  ax.set_xlabel('B / T')
63
66
  ax.set_title('rel. Permeability')
64
67
  ax.grid()
65
68
 
69
+ def mcv_nuer(mcv, ax=0):
70
+ """plot rel. reluctivity vs. B of mcv dict"""
71
+ MUE0 = 4e-7*np.pi
72
+ bi, ur = zip(*[(bx, bx/hx/MUE0)
73
+ for bx, hx in zip(mcv['curve'][0]['bi'],
74
+ mcv['curve'][0]['hi']) if not hx == 0])
75
+ if ax == 0:
76
+ ax = plt.gca()
77
+ nuer = 1/np.array(ur)
78
+ ax.plot(bi, 1/np.array(ur))
79
+ ax.plot(bi, nuer, 'k.')
80
+ ax.set_xlabel('B / T')
81
+ ax.set_title('rel. Reluctivity')
82
+ ax.grid()
83
+
66
84
 
67
85
  def felosses(losses, coeffs, title='', log=True, ax=0):
68
86
  """plot iron losses with steinmetz or jordan approximation
femagtools/plot/nc.py CHANGED
@@ -35,19 +35,19 @@ def spel(isa, superelements=[], with_axis=False, ax=0):
35
35
  color=isa.color[se.color], lw=0))
36
36
  try:
37
37
  # draw wire direction
38
- if se.subregion:
39
- if se.subregion.curdir != 0:
38
+ if se.subregion:
39
+ if se.subregion.curdir != 0:
40
40
  wkey = se.subregion.winding.key
41
- if se.subregion.curdir < 0:
41
+ if se.subregion.curdir < 0:
42
42
  label = str(se.subregion.curdir*wkey)
43
- else:
43
+ else:
44
44
  label = '+'+str(se.subregion.curdir*wkey)
45
45
 
46
46
  xy = np.array([n.xy
47
47
  for nc in se.nodechains
48
48
  for n in nc.nodes])
49
49
  cx, cy = np.mean(np.unique(xy[:, 0])), np.mean(np.unique(xy[:, -1]))
50
- ax.text(cx, cy, label, rotation=np.arctan2(cy, cx)/np.pi*180-90,
50
+ ax.text(cx, cy, label, rotation=np.arctan2(cy, cx)/np.pi*180-90,
51
51
  horizontalalignment='center', verticalalignment='center')
52
52
  except:
53
53
  pass
@@ -296,3 +296,20 @@ def loss_density(isa, subreg=[], cmap=DEFAULT_CMAP, ax=0):
296
296
  elements = [e for e in __elements_of_subreg(isa, subreg)]
297
297
  lossd = np.array([e.loss_density*1e-3 for e in elements])
298
298
  _contour(ax, 'Loss Density kW/m³', elements, lossd, '', cmap)
299
+
300
+ def temperature_distribution(isa, ax=0, cmap='plasma'):
301
+ """plot temperature distribution of NC/I7/ISA7 model
302
+
303
+ Args:
304
+ isa: Isa7/NC object
305
+ """
306
+ temp = []
307
+ elements = [e for e in isa.elements]
308
+ for e in isa.elements:
309
+ tmp = 0
310
+ ctr = 1
311
+ for n in e.vertices:
312
+ tmp += n.vpot[-1]
313
+ ctr = ctr + 1
314
+ temp.append(tmp/ctr)
315
+ _contour(ax, 'Temperature in K', elements, temp, '', cmap)