femagtools 1.8.7__py3-none-any.whl → 1.8.8__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.
@@ -11,6 +11,10 @@ from .. import model
11
11
  from .. import utils
12
12
  from .. import windings
13
13
  from .. import femag
14
+ from .. import ecloss
15
+ from .. import nc
16
+ from .. import bch
17
+
14
18
  from scipy.interpolate import make_interp_spline, RegularGridInterpolator, RectBivariateSpline
15
19
  from scipy.integrate import quad
16
20
  import copy
@@ -27,6 +31,49 @@ AFM_TYPES = (
27
31
  "S2R1_all" # 2 stator, 1 rotor, all simulated
28
32
  )
29
33
 
34
+ def stator_template_name(machine):
35
+ for k in machine['stator']:
36
+ if type(machine['stator'][k]) == dict:
37
+ return k
38
+ return ''
39
+
40
+ def magnet_template_name(machine):
41
+ for k in machine['magnet']:
42
+ if type(machine['magnet'][k]) == dict:
43
+ return k
44
+ return ''
45
+
46
+ def jsonify(v):
47
+ vtype = type(v)
48
+ if vtype == np.float32:
49
+ return float(v)
50
+ if vtype == np.ndarray:
51
+ return v.tolist()
52
+ if vtype == dict:
53
+ for k in v:
54
+ v[k] = jsonify(v[k])
55
+ return v
56
+
57
+
58
+ def get_magdata(task):
59
+ basedir = Path(task.directory)
60
+ bchfile_list = sorted(basedir.glob(
61
+ '*_[0-9][0-9][0-9].B*CH'))
62
+ if bchfile_list:
63
+ result = bch.Reader()
64
+ with open(bchfile_list[-1]) as f:
65
+ logger.debug("Reading %s",
66
+ bchfile_list[-1])
67
+ result.read(f)
68
+ fnc = list(basedir.glob('*.nc'))[0]
69
+ ibeta = len(result.linearForce)-1
70
+ ncmod = nc.read(fnc)
71
+ result.losses[0]['magnet_data'] = [jsonify(pm)
72
+ for pm in ncmod.get_magnet_data(
73
+ ibeta=ibeta)]
74
+ return result
75
+
76
+
30
77
  def num_agnodes(Q, p, pw, ag):
31
78
  """return total number of nodes in airgap per pole
32
79
  Args:
@@ -51,6 +98,7 @@ def num_agnodes(Q, p, pw, ag):
51
98
  # TODO nodedist 0.5, 2, 4, 6
52
99
  return nag
53
100
 
101
+
54
102
  def _integrate(radius, pos, val):
55
103
  interp = RegularGridInterpolator((radius, pos), val)
56
104
  def func(x, y):
@@ -66,6 +114,7 @@ def _integrate1d(radius, val):
66
114
  return interp((x))
67
115
  return quad(func, radius[0], radius[-1], limit=100)[0]
68
116
 
117
+
69
118
  def ld_interpol(i1, beta, v):
70
119
  '''interpolate Ld at beta angle 0°, -180°'''
71
120
  # ld
@@ -86,8 +135,9 @@ def ld_interpol(i1, beta, v):
86
135
  bp = beta[0:-1] + \
87
136
  [[dbeta for i in range(len(np.unique(i1)))]]
88
137
 
89
- return RectBivariateSpline(np.unique(bp), np.unique(cur), \
90
- np.array(v)).ev(*[betad, i1]).tolist()
138
+ return RectBivariateSpline(np.unique(bp), np.unique(cur),
139
+ np.array(v)).ev(*[betad, i1]).tolist()
140
+
91
141
 
92
142
  def lq_interpol(i1, beta, v):
93
143
  '''interpolate Lq at beta -90°'''
@@ -111,6 +161,7 @@ def lq_interpol(i1, beta, v):
111
161
  return RectBivariateSpline(np.unique(bp), np.unique(cur), \
112
162
  np.array(v)).ev(*[betad, i1]).tolist()
113
163
 
164
+
114
165
  def parident(workdir, engine, temp, machine,
115
166
  magnetizingCurves, magnetMat=[], condMat=[],
116
167
  **kwargs):
@@ -142,7 +193,7 @@ def parident(workdir, engine, temp, machine,
142
193
 
143
194
  di = machine['inner_diam']
144
195
  Q1 = machine['stator']['num_slots']
145
- slotmodel = 'afm_stator'
196
+ slotmodel = stator_template_name(machine)
146
197
  hs = machine['stator'][slotmodel]['slot_height']
147
198
  wdgk = 'windings' if 'windings' in machine else 'winding'
148
199
  N = machine[wdgk]['num_wires']
@@ -154,17 +205,19 @@ def parident(workdir, engine, temp, machine,
154
205
  machine[wdgk].get('num_par_wdgs', 1))
155
206
 
156
207
  p = machine['poles']
157
- if np.isscalar(machine['magnet']['afm_rotor']['rel_magn_width']):
208
+ slotmodel = magnet_template_name(machine)
209
+ if np.isscalar(machine['magnet'][slotmodel]['rel_magn_width']):
158
210
  num_slices = kwargs.get('num_slices', 3)
159
- rmagw = num_slices*[machine['magnet']['afm_rotor']['rel_magn_width']]
211
+ rmagw = num_slices*[machine['magnet'][slotmodel]['rel_magn_width']]
160
212
  else:
161
- rmagw = machine['magnet']['afm_rotor']['rel_magn_width']
213
+ rmagw = machine['magnet'][slotmodel]['rel_magn_width']
162
214
  if len(rmagw) == 1:
163
215
  num_slices = kwargs.get('num_slices', 3)
164
216
  rmagw = num_slices*list(rmagw)
165
217
  else:
166
218
  num_slices = len(rmagw)
167
219
 
220
+ logger.info("num_slices %d rmagw %s", num_slices, rmagw)
168
221
  lfe = get_arm_lengths(machine['outer_diam'],
169
222
  machine['inner_diam'],
170
223
  num_slices)
@@ -185,7 +238,7 @@ def parident(workdir, engine, temp, machine,
185
238
  {"values": pole_width,
186
239
  "name": "pole_width"},
187
240
  {"values": rmagw,
188
- "name": "magnet.afm_rotor.rel_magn_width"},
241
+ "name": f"magnet.{slotmodel}.rel_magn_width"},
189
242
  {"values": lfe,
190
243
  "name": "lfe"},
191
244
  {"values": linspeed, "name": "speed"}
@@ -234,7 +287,7 @@ def parident(workdir, engine, temp, machine,
234
287
  for pw, le, sp, rmw in zip(pole_width, lfe, linspeed, rmagw):
235
288
  nlmachine = {k: machine[k] for k in machine}
236
289
  nlmachine['pole_width'] = pw
237
- nlmachine['magnet']['afm_rotor']['rel_magn_width'] = rmw
290
+ nlmachine['magnet'][slotmodel]['rel_magn_width'] = rmw
238
291
  nlmachine['lfe'] = le
239
292
  nlcalc.update({"speed": sp})
240
293
  nlsubdir = f'{workdir}/{i}'
@@ -242,9 +295,10 @@ def parident(workdir, engine, temp, machine,
242
295
  if nlworkdir.exists():
243
296
  shutil.rmtree(nlworkdir)
244
297
  nlworkdir.mkdir(exist_ok=True)
245
- noloadsim = femag.Femag(nlworkdir, condMat=condMat, magnets=magnetMat,
246
- magnetizingCurves=magnetizingCurves,
247
- cmd=kwargs.get('cmd', None))
298
+ noloadsim = femag.Femag(
299
+ nlworkdir, condMat=condMat, magnets=magnetMat,
300
+ magnetizingCurves=magnetizingCurves,
301
+ cmd=kwargs.get('cmd', None))
248
302
  r = noloadsim(nlmachine, nlcalc)
249
303
  nlresults['f'].append({k: v for k, v in r.items()})
250
304
  i = i + 1
@@ -254,10 +308,10 @@ def parident(workdir, engine, temp, machine,
254
308
  results = []
255
309
  i = 0
256
310
  for l, pw, rmw in zip(lfe, pole_width, rmagw):
257
- mpart = {k: machine[k] for k in machine if k != 'afm_rotor'}
311
+ mpart = {k: machine[k] for k in machine if k != slotmodel}
258
312
  mpart['pole_width'] = pw
259
313
  mpart['lfe'] = l
260
- mpart['magnet']['afm_rotor']['rel_magn_width'] = rmw
314
+ mpart['magnet'][slotmodel]['rel_magn_width'] = rmw
261
315
  subdir = f"{workdir}/{i}"
262
316
 
263
317
  simulation = dict(
@@ -265,8 +319,8 @@ def parident(workdir, engine, temp, machine,
265
319
  wind_temp=20.0,
266
320
  magn_temp=magtemp,
267
321
  angl_i_up=0.0,
268
- magn_height=machine['magnet']['afm_rotor']['magn_height'],
269
- yoke_height=machine['magnet']['afm_rotor'].get(
322
+ magn_height=machine['magnet'][slotmodel]['magn_height'],
323
+ yoke_height=machine['magnet'][slotmodel].get(
270
324
  'yoke_height', 0),
271
325
  current=1,
272
326
  poc=poc.Poc(999,
@@ -278,9 +332,10 @@ def parident(workdir, engine, temp, machine,
278
332
 
279
333
  if kwargs.get('use_multiprocessing', True):
280
334
  gpstudy = parstudy.Grid(
281
- subdir, condMat=condMat, magnets=magnetMat,
282
- magnetizingCurves=magnetizingCurves,
283
- cmd=kwargs.get('cmd', None))
335
+ subdir, condMat=condMat, magnets=magnetMat,
336
+ magnetizingCurves=magnetizingCurves,
337
+ cmd=kwargs.get('cmd', None),
338
+ result_func=get_magdata)
284
339
  lresults = gpstudy(parvardef, mpart, simulation, engine)
285
340
 
286
341
  else:
@@ -299,9 +354,10 @@ def parident(workdir, engine, temp, machine,
299
354
  if lworkdir.exists():
300
355
  shutil.rmtree(lworkdir)
301
356
  lworkdir.mkdir(exist_ok=True)
302
- loadsim = femag.Femag(lworkdir, condMat=condMat, magnets=magnetMat,
303
- magnetizingCurves=magnetizingCurves,
304
- cmd=kwargs.get('cmd', None))
357
+ loadsim = femag.Femag(
358
+ lworkdir, condMat=condMat, magnets=magnetMat,
359
+ magnetizingCurves=magnetizingCurves,
360
+ cmd=kwargs.get('cmd', None))
305
361
  r = loadsim(mpart, simulation)
306
362
  lresults['f'].append({k: v for k, v in r.items()})
307
363
 
@@ -371,7 +427,7 @@ def parident(workdir, engine, temp, machine,
371
427
  losses.update({'speed': speed,
372
428
  'hf': postp[0]['lossPar']['hf'],
373
429
  'ef': postp[0]['lossPar']['ef'],
374
- 'magnet':np.flip(
430
+ 'magnet': np.flip(
375
431
  np.reshape([r['plmag'] for r in postp],
376
432
  (-1, num_beta_steps)),
377
433
  axis=1).T.tolist()})
@@ -416,8 +472,8 @@ def process(lfe, pole_width, machine, bch):
416
472
  slots_gen = mmod.stator['num_slots_gen']
417
473
  scale_factor = _get_scale_factor(model_type, num_slots, slots_gen)
418
474
  endpos = [2*pw*1e3 for pw in pole_width]
419
- displ = [[d for d in r['linearForce'][0]['displ']
420
- if d < e*(1+1/len(r['linearForce'][0]['displ']))]
475
+ displ = [[d for d in r['linearForce'][-1]['displ']
476
+ if d < e*(1+1/len(r['linearForce'][-1]['displ']))]
421
477
  for e, r in zip(endpos, bch)]
422
478
  radius = [pw*machine['poles']/2/np.pi for pw in pole_width]
423
479
  rotpos = [np.array(d)/r/1000 for r, d in zip(radius, displ)]
@@ -430,20 +486,20 @@ def process(lfe, pole_width, machine, bch):
430
486
  if np.diff([len(d) for d in displ]).any():
431
487
  raise ValueError(
432
488
  f"inhomogenous number of steps: {[len(d) for d in displ]}")
433
- lfx = [r['linearForce'][0]['force_x'] for r in bch]
489
+ lfx = [r['linearForce'][-1]['force_x'] for r in bch]
434
490
  torque = _integrate(radius, rotpos[0], np.array(
435
491
  [r*scale_factor*np.array(fx[:-1])/l
436
492
  for l, r, fx in zip(lfe, radius, lfx)]))
437
493
 
438
494
  voltage = {k: [scale_factor * np.array(ux[:-1])/l
439
- for l, ux in zip(lfe, [r['flux'][k][0]['voltage_dpsi']
495
+ for l, ux in zip(lfe, [r['flux'][k][-1]['voltage_dpsi']
440
496
  for r in bch])]
441
497
  for k in bch[0]['flux']}
442
498
  emf = [_integrate(radius, rotpos[0], np.array(voltage[k]))
443
499
  for k in voltage]
444
500
 
445
501
  fluxxy = {k: [scale_factor * np.array(flx[:-1])/l
446
- for l, flx in zip(lfe, [r['flux'][k][0]['flux_k']
502
+ for l, flx in zip(lfe, [r['flux'][k][-1]['flux_k']
447
503
  for r in bch])]
448
504
  for k in bch[0]['flux']}
449
505
  flux = [_integrate(radius, rotpos[0], np.array(fluxxy[k]))
@@ -451,57 +507,67 @@ def process(lfe, pole_width, machine, bch):
451
507
  else:
452
508
  r = radius[0]
453
509
  torque = [r*scale_factor*fx
454
- for fx in bch[0]['linearForce'][0]['force_x'][:-1]]
510
+ for fx in bch[0]['linearForce'][-1]['force_x'][:-1]]
455
511
  voltage = {k: [scale_factor * ux
456
- for ux in bch[0]['flux'][k][0]['voltage_dpsi'][:-1]]
512
+ for ux in bch[0]['flux'][k][-1]['voltage_dpsi'][:-1]]
457
513
  for k in bch[0]['flux']}
458
514
  emf = [voltage[k][:n] for k in voltage]
459
515
  fluxxy = {k: [scale_factor * np.array(flx)
460
- for flx in bch[0]['flux'][k][0]['flux_k']]
516
+ for flx in bch[0]['flux'][k][-1]['flux_k']]
461
517
  for k in bch[0]['flux']}
462
518
  flux = [fluxxy[k][:n] for k in fluxxy]
463
519
 
464
520
  pos = (rotpos[0]/np.pi*180)
465
521
  emffft = utils.fft(pos, emf[0])
466
522
 
523
+ scale_factor = 1 if model_type == 'S1R1' else 2
467
524
  styoke = {}
468
- stteeth = {'hyst':0, 'eddy':0}
525
+ stteeth = {'hyst': 0, 'eddy': 0}
469
526
  rotor = {}
470
527
  for k in ('hyst', 'eddy'):
471
528
  if len(pole_width) > 1:
472
529
  styoke[k] = _integrate1d(radius, scale_factor*np.array(
473
- [sum(b['losses'][0]['stator']['stfe'][k])/l
530
+ [sum(b['losses'][-1]['stator']['stfe'][k])/l
474
531
  for l, b in zip(lfe, bch)]))
475
532
  rotor[k] = _integrate1d(radius, scale_factor*np.array(
476
- [sum(b['losses'][0]['rotor']['----'][k])/l
533
+ [sum(b['losses'][-1]['rotor']['----'][k])/l
477
534
  for l, b in zip(lfe, bch)]))
478
535
  else:
479
536
  styoke[k] = scale_factor*sum(
480
- bch[0]['losses'][0]['stator']['stfe'][k])
537
+ bch[0]['losses'][-1]['stator']['stfe'][k])
481
538
  rotor[k] = scale_factor*sum(
482
- bch[0]['losses'][0]['rotor']['----'][k])
539
+ bch[0]['losses'][-1]['rotor']['----'][k])
483
540
 
484
- if 'magnetH' in bch[0]['losses'][0]:
541
+ if 'magnet_data' in bch[0]['losses'][0]:
485
542
  k = 'magnetH'
543
+ nsegx = machine['magnet'].get('num_segments', 1)
544
+ if type(nsegx) == int:
545
+ nsegx = [nsegx]*len(bch)
546
+ for nx, b in zip(nsegx, bch):
547
+ pm = b['losses'][0]['magnet_data']
548
+ magloss = ecloss.MagnLoss(magnet_data=[pm])
549
+ ml = magloss.calc_losses_ialh2(nsegx=nx)
550
+ b['losses'][-1][k] = ml[0]
486
551
  else:
487
552
  k = 'magnetJ'
488
553
  if len(pole_width) > 1:
489
554
  maglosses = _integrate1d(radius, scale_factor*np.array(
490
- [b['losses'][0][k]/l for l, b in zip(lfe, bch)]))
555
+ [b['losses'][-1][k]/lz
556
+ for lz, b in zip(lfe, bch)]))
491
557
  else:
492
- maglosses = scale_factor*bch[0]['losses'][0][k]
558
+ maglosses = scale_factor*bch[0]['losses'][-1][k]
493
559
 
494
- freq = bch[0]['losses'][0]['stator']['stfe']['freq'][0]
560
+ freq = bch[0]['losses'][-1]['stator']['stfe']['freq'][0]
495
561
 
496
562
  wdg = windings.Winding(
497
563
  dict(Q=mmod.stator['num_slots'],
498
564
  p=mmod.poles//2,
499
565
  m=mmod.winding['num_phases'],
500
566
  l=mmod.winding['num_layers']))
501
-
567
+ slotmodel = stator_template_name(machine)
502
568
  cufill = mmod.winding.get('cufilfact', 0.4)
503
- aw = (mmod.stator['afm_stator']['slot_width']*
504
- mmod.stator['afm_stator']['slot_height']*
569
+ aw = (mmod.stator[slotmodel]['slot_width']*
570
+ mmod.stator[slotmodel]['slot_height']*
505
571
  cufill/mmod.winding['num_wires']/mmod.winding['num_layers'])
506
572
  r1 = wdg_resistance(wdg, mmod.winding['num_wires'],
507
573
  mmod.winding['num_par_wdgs'],
@@ -954,15 +1020,15 @@ class AFPM:
954
1020
  raise ValueError(f"invalid afm type {machine['afmtype']}")
955
1021
  except KeyError:
956
1022
  raise ValueError("missing key afmtype")
957
-
958
- if np.isscalar(machine['magnet']['afm_rotor']['rel_magn_width']):
959
- rmagw = num_slices*[machine['magnet']['afm_rotor']['rel_magn_width']]
1023
+ slotmodel = magnet_template_name(machine)
1024
+ logger.info("num_slices %d rmagw %s", num_slices,
1025
+ machine['magnet'][slotmodel]['rel_magn_width'])
1026
+ if np.isscalar(machine['magnet'][slotmodel]['rel_magn_width']):
1027
+ rmagw = num_slices*[machine['magnet'][slotmodel]['rel_magn_width']]
960
1028
  else:
961
- rmagw = machine['magnet']['afm_rotor']['rel_magn_width']
962
- if len(rmagw) == 1:
963
- rmagw = num_slices*list(rmagw)
964
- elif num_slices != len(rmagw):
965
- num_slices = len(rmagw)
1029
+ rmagw = machine['magnet'][slotmodel]['rel_magn_width']
1030
+ num_slices = len(rmagw)
1031
+
966
1032
  lfe = get_arm_lengths(machine['outer_diam'],
967
1033
  machine['inner_diam'],
968
1034
  num_slices)
@@ -987,7 +1053,7 @@ class AFPM:
987
1053
  {"values": lfe,
988
1054
  "name": "lfe"},
989
1055
  {"values": rmagw,
990
- "name": "magnet.afm_rotor.rel_magn_width"},
1056
+ "name": f"magnet.{slotmodel}.rel_magn_width"},
991
1057
  {"values": linspeed, "name": "speed"}
992
1058
  ]
993
1059
  }
@@ -995,15 +1061,15 @@ class AFPM:
995
1061
  machine['pole_width'] = np.pi * machine['inner_diam']/machine['poles']
996
1062
  machine['lfe'] = machine['outer_diam'] - machine['inner_diam']
997
1063
  try:
998
- machine['magnet']['afm_rotor']['rel_magn_width'] = max(
999
- machine['magnet']['afm_rotor']['rel_magn_width'])
1064
+ machine['magnet'][slotmodel]['rel_magn_width'] = max(
1065
+ machine['magnet'][slotmodel]['rel_magn_width'])
1000
1066
  except TypeError:
1001
1067
  pass
1002
1068
 
1003
1069
  simulation['skew_displ'] = (simulation.get('skew_angle', 0)/180 * np.pi
1004
1070
  * machine['inner_diam'])
1005
1071
  nlresults = {}
1006
- if (simulation['calculationMode'] != 'cogg_calc'
1072
+ if (simulation['calculationMode'] == 'torq_calc'
1007
1073
  and 'poc' not in simulation):
1008
1074
  nlcalc = dict(
1009
1075
  calculationMode="cogg_calc",
@@ -1026,10 +1092,13 @@ class AFPM:
1026
1092
  parameters={
1027
1093
  'phi_voltage_winding': current_angles})
1028
1094
  logger.info("Current angles: %s", current_angles)
1029
- elif (simulation['calculationMode'] == 'cogg_calc'
1030
- and 'poc' not in simulation):
1095
+ simulation['calc_noload'] = 0
1096
+
1097
+ if 'poc' not in simulation:
1031
1098
  simulation['poc'] = poc.Poc(machine['pole_width'])
1032
1099
 
1100
+ self.parstudy.result_func = get_magdata
1101
+ logger.info("Simulation %s", simulation['calculationMode'])
1033
1102
  lresults = self.parstudy(
1034
1103
  parvardef, machine, simulation, engine)
1035
1104
  if lresults['status'].count('C') != len(lresults['status']):
@@ -327,11 +327,19 @@ def efficiency_losses_map(eecpars, u1, T, temp, n, npoints=(60, 40),
327
327
  plcu1 = m.iqd_plcu1(iqd[0], iqd[1], 2*np.pi*f1)
328
328
  plcu2 = m.iqd_plcu2(*iqd)
329
329
  tfric = m.tfric
330
+ try:
331
+ plcu1_dc = m.iqd_plcu1(iqd[0], iqd[1],
332
+ np.array([0.0 for i in f1])).tolist()
333
+ plcu1_ac = [i-j for i, j in zip(plcu1.tolist(), plcu1_dc)]
334
+ except:
335
+ plcu1_dc, plcu1_ac = [], []
330
336
  elif isinstance(m, SynchronousMachine):
331
337
  plfe1 = m.kpfe*m.iqd_plfe1(*iqd, f1)
332
338
  plfe2 = m.kpfe*m.iqd_plfe2(*iqd, f1)
333
339
  plmag = np.zeros_like(plfe2)
334
340
  plcu1 = m.iqd_plcu1(iqd[0], iqd[1], 2*np.pi*f1)
341
+ plcu1_dc = [] # reserved for winding (dc, ac) losses
342
+ plcu1_ac = []
335
343
  plcu2 = m.iqd_plcu2(*iqd)
336
344
  tfric = m.tfric
337
345
  logger.info("Iex %f %f",
@@ -342,6 +350,8 @@ def efficiency_losses_map(eecpars, u1, T, temp, n, npoints=(60, 40),
342
350
  plmag = np.zeros(ntmesh.shape[1])
343
351
  plcu1 = np.array(r['plcu1'])
344
352
  plcu2 = np.array(r['plcu2'])
353
+ plcu1_dc = [] # reserved for winding (dc, ac) losses
354
+ plcu1_ac = []
345
355
  iqd = np.zeros(ntmesh.shape)
346
356
  u1 = np.array(r['u1'])
347
357
  i1 = np.array(r['i1'])
@@ -387,4 +397,6 @@ def efficiency_losses_map(eecpars, u1, T, temp, n, npoints=(60, 40),
387
397
  plcu1=plcu1.tolist(),
388
398
  plcu2=plcu2.tolist(),
389
399
  plfric=plfric.tolist(),
390
- losses=ploss.tolist())
400
+ losses=ploss.tolist(),
401
+ plcu1_dc=plcu1_dc,
402
+ plcu1_ac=plcu1_ac)
femagtools/mcv.py CHANGED
@@ -99,7 +99,8 @@ def norm_pfe(B, pfe):
99
99
  b = list(b)
100
100
  b[-1] = Bv[n]
101
101
  n += 1
102
- pfunc = make_interp_spline(b, pfe[i])
102
+ k = 3 if len(pfe[i]) > 3 else 2
103
+ pfunc = make_interp_spline(b, pfe[i], k=k)
103
104
  m.append([float(pfunc(x))
104
105
  for x in Bv[:n]] + [None]*(len(Bv)-n))
105
106
  return Bv.tolist(), m
@@ -597,7 +598,8 @@ class Writer(Mcv):
597
598
  self.writeBlock([self.mc1_angle[K], self.mc1_db2[K]])
598
599
 
599
600
  try:
600
- if not (self.mc1_ch_factor or self.mc1_cw_factor) and self.losses and write_losses:
601
+ if (not (self.mc1_ch_factor or self.mc1_cw_factor)
602
+ and self.losses and write_losses):
601
603
  # fit loss parameters
602
604
  pfe = self.losses['pfe']
603
605
  f = self.losses['f']
@@ -630,15 +632,16 @@ class Writer(Mcv):
630
632
  float(self.mc1_fe_spez_weigth),
631
633
  float(self.mc1_fe_sat_magnetization)])
632
634
 
633
- logger.info(f"fo = {float(self.mc1_base_frequency)}")
634
- logger.info(f"Bo = {float(self.mc1_base_induction)}")
635
- logger.info(f"ch = {float(self.mc1_ch_factor)}")
636
- logger.info(f"cw = {float(self.mc1_cw_factor)}")
637
- logger.info(f"ch_freq = {float(self.mc1_ch_freq_factor)}")
638
- logger.info(f"cw_freq = {float(self.mc1_cw_freq_factor)}")
639
- logger.info(f"b_coeff = {float(self.mc1_induction_factor)}")
640
- logger.info(f"fr_spez_weight = {float(self.mc1_fe_spez_weigth)}")
641
- logger.info(f"fe_sat_magnetization = {float(self.mc1_fe_sat_magnetization)}")
635
+ logger.info("MCV coeffs %s",
636
+ {"fo": float(self.mc1_base_frequency),
637
+ "Bo": float(self.mc1_base_induction),
638
+ "ch": float(self.mc1_ch_factor),
639
+ "cw": float(self.mc1_cw_factor),
640
+ "ch_freq": float(self.mc1_ch_freq_factor),
641
+ "cw_freq": float(self.mc1_cw_freq_factor),
642
+ "b_coeff": float(self.mc1_induction_factor),
643
+ "fr_spez_weight": float(self.mc1_fe_spez_weigth),
644
+ "fe_sat_magnetization": float(self.mc1_fe_sat_magnetization)})
642
645
 
643
646
  if not hasattr(self, 'losses') or not self.losses:
644
647
  # new variables: ce factor for bertotti losses
@@ -646,8 +649,8 @@ class Writer(Mcv):
646
649
  try:
647
650
  self.writeBlock([float(self.mc1_ce_factor),
648
651
  float(self.mc1_induction_beta_factor)])
649
- logger.info(f"ce = {float(self.mc1_ce_factor)}")
650
- logger.info(f"b_beta_coeff = {float(self.mc1_induction_beta_factor)}")
652
+ #logger.info(f"ce = {float(self.mc1_ce_factor)}")
653
+ #logger.info(f"b_beta_coeff = {float(self.mc1_induction_beta_factor)}")
651
654
  except:
652
655
  pass
653
656
  return
@@ -710,6 +713,8 @@ class Writer(Mcv):
710
713
  nrec += 1
711
714
 
712
715
  if write_losses:
716
+ logger.info("Append empty blocks %d x %d",
717
+ M_LOSS_FREQ - nrec, M_LOSS_INDUCT)
713
718
  for m in range(M_LOSS_FREQ - nrec):
714
719
  self.writeBlock([0.0]*M_LOSS_INDUCT)
715
720
  self.writeBlock(0.0)
@@ -717,9 +722,13 @@ class Writer(Mcv):
717
722
  self.writeBlock([self.losses['cw'], self.losses['cw_freq'],
718
723
  self.losses['b_coeff'], self.losses['fo'],
719
724
  self.losses['Bo']])
720
- logger.info("losses_cw = %f, losses_cw_freq = %f, losses_b_coeff = %f, losses_fo = %f, losses_Bo = %f",
721
- self.losses['cw'], self.losses['cw_freq'],
722
- self.losses['b_coeff'], self.losses['fo'], self.losses['Bo'])
725
+ logger.info("loss coeff %s",
726
+ {"cw": float(self.losses['cw']),
727
+ "cw_freq": float(self.losses['cw_freq']),
728
+ "b_coeff": float(self.losses['b_coeff']),
729
+ "fo": float(self.losses['fo']),
730
+ "Bo": float(self.losses['Bo'])})
731
+
723
732
  self.writeBlock([1])
724
733
  logger.info('Losses n freq %d n ind %d', nfreq, nind)
725
734
  except Exception as e:
@@ -1149,7 +1158,7 @@ class MagnetizingCurve(object):
1149
1158
  repls.items(), name)
1150
1159
 
1151
1160
  def writefile(self, name, directory='.',
1152
- fillfac=None, recsin='', feloss='jordan'):
1161
+ fillfac=None, recsin='', feloss=''):
1153
1162
  """find magnetic curve by name or id and write binary file
1154
1163
  Arguments:
1155
1164
  name: key of mcv dict (name or id)
femagtools/nc.py CHANGED
@@ -192,21 +192,23 @@ class Reader(object):
192
192
  for k in ('sr_key', 'nxt_sr_pntr')]
193
193
  except:
194
194
  pass
195
- try:
196
- grp = ds.groups['machine']
195
+
196
+ grp = ds.groups['machine']
197
+ if 'speed' in grp.variables:
197
198
  self.speed = float(grp.variables['speed'].getValue().data)
199
+ if 'fc_radius' in grp.variables:
198
200
  self.FC_RADIUS = float(grp.variables['fc_radius'].getValue().data)
199
- self.pole_pairs = int(grp.variables['pole_pairs'].getValue().data)
201
+ self.delta_node_angle = float( # rad
202
+ grp.variables['delta_node_angle'].getValue().data)
203
+ self.arm_length = float(grp.variables['arm_length'].getValue().data)
204
+ for attr in ('pole_pairs', 'poles_sim', 'coil_span',
205
+ 'state_of_problem', 'move_action'):
206
+ if attr in grp.variables:
207
+ setattr(self, attr, int(grp.variables[attr].getValue().data))
208
+ if 'num_layers' in grp.variables:
200
209
  self.layers = int(grp.variables['num_layers'].getValue().data)
201
- self.coil_span = int(grp.variables['coil_span'].getValue().data)
202
- self.delta_node_angle = float( # rad
203
- grp.variables['delta_node_angle'].getValue().data)
204
- self.poles_sim = int(grp.variables['poles_sim'].getValue().data)
210
+ if 'num_slots' in grp.variables:
205
211
  self.slots = int(grp.variables['num_slots'].getValue().data)
206
- self.arm_length = float(grp.variables['arm_length'].getValue().data)
207
- self.state_of_problem = int(grp.variables['state_of_problem'].getValue().data)
208
- except:
209
- pass
210
212
 
211
213
  if hasattr(self, 'state_of_problem'):
212
214
  if self.state_of_problem == 5:
@@ -236,18 +238,18 @@ class Reader(object):
236
238
  except KeyError:
237
239
  pass
238
240
 
239
- try:
241
+ if 'el_induction' in ds.groups:
240
242
  grp = ds.groups['el_induction']
241
243
  (self.pos_el_fe_induction,
242
244
  self.el_fe_induction_1,
243
245
  self.el_fe_induction_2,
244
- self.eddy_cu_vpot) = [grp.variables[k][:]
246
+ self.eddy_cu_vpot) = [grp.variables[k][:] if k in grp.variables else []
245
247
  for k in ('position',
246
248
  'fe_induction_1',
247
249
  'fe_induction_2',
248
250
  'eddy_cu_vpot')]
249
251
  logger.debug('el_fe_induction %d', len(self.pos_el_fe_induction))
250
- except KeyError:
252
+ else:
251
253
  self.pos_el_fe_induction = []
252
254
  self.el_fe_induction_1 = []
253
255
  self.el_fe_induction_2 = []