pyuff 2.6.0__tar.gz → 2.6.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyuff
3
- Version: 2.6.0
3
+ Version: 2.6.1
4
4
  Summary: UFF (Universal File Format) read/write.
5
5
  Project-URL: homepage, https://github.com/ladisk/pyuff
6
6
  Project-URL: documentation, https://pyuff.readthedocs.io/en/latest/
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pyuff"
7
- version = "2.6.0"
7
+ version = "2.6.1"
8
8
  authors = [{name = "Primož Čermelj, Janko Slavič", email = "janko.slavic@fs.uni-lj.si"}]
9
9
  maintainers = [{name = "Janko Slavič et al.", email = "janko.slavic@fs.uni-lj.si"}]
10
10
  license = "MIT"
@@ -668,12 +668,10 @@ def _write2414(fh, dset):
668
668
 
669
669
  # The data and structure of Record 14 and 15 depend on the 'dataset_location'
670
670
  if dset['dataset_location'] == 1:
671
- for index in range(dset['node_nums'].shape[0]):
672
- fh.write('%10i\n' % (dset['node_nums'][index]))
673
- for field in dset['data_at_node'][index]:
674
- # number of values unknown, so loop
675
- fh.write('%13.5e' % (field))
676
- fh.write('\n')
671
+ # the number of values may differ from node to node
672
+ lines = ['%10i\n' % node + '%13.5e' * len(values) % tuple(values) + '\n'
673
+ for node, values in zip(dset['node_nums'], dset['data_at_node'])]
674
+ fh.write(''.join(lines))
677
675
  fh.write('%6i\n' % (-1))
678
676
 
679
677
  elif dset['dataset_location'] == 2:
@@ -788,10 +786,9 @@ def _extract2414(block_data):
788
786
  split_data = split_data.splitlines()
789
787
  if dset['dataset_location'] == 1:
790
788
  # Data at nodes
791
- record14 = np.asarray([str.split() for str in split_data[0::2]], 'U')
792
789
  # record 15 not always same number of fields, so a list of ndarray
793
- record15 = [np.array([float(elem) for elem in item.split()], float) for item in split_data[1::2]]
794
- dset['node_nums'] = np.array(record14[:,0].copy(), dtype=int)
790
+ record15 = [np.array(line.split(), float) for line in split_data[1::2]]
791
+ dset['node_nums'] = np.array([line.split()[0] for line in split_data[0::2]], dtype=int)
795
792
  dset['data_at_node'] = record15
796
793
 
797
794
  elif dset['dataset_location'] == 2:
@@ -426,26 +426,21 @@ def _write55(fh, dset):
426
426
  dset['modal_b'].real, dset['modal_b'].imag))
427
427
  else:
428
428
  raise ValueError('Unsupported analysis type')
429
- n = len(dset['node_nums'])
429
+ # Records 14 and 15 of every node: node number, then its values
430
430
  if data_type == 2:
431
431
  # Real data
432
432
  if n_data_per_node == 3:
433
- for k in range(0, n):
434
- fh.write('%10i\n' % dset['node_nums'][k])
435
- fh.write('%13.5e%13.5e%13.5e\n' % (dset['r1'][k], dset['r2'][k], dset['r3'][k]))
433
+ rows = zip(dset['node_nums'], dset['r1'], dset['r2'], dset['r3'])
434
+ fh.write(''.join('%10i\n%13.5e%13.5e%13.5e\n' % row for row in rows))
436
435
  else:
437
- for k in range(0, n):
438
- fh.write('%10i\n' % dset['node_nums'][k])
439
- fh.write('%13.5e%13.5e%13.5e%13.5e%13.5e%13.5e\n' %
440
- (dset['r1'][k], dset['r2'][k], dset['r3'][k], dset['r4'][k], dset['r5'][k],
441
- dset['r6'][k]))
436
+ rows = zip(dset['node_nums'], dset['r1'], dset['r2'], dset['r3'], dset['r4'], dset['r5'], dset['r6'])
437
+ fh.write(''.join('%10i\n%13.5e%13.5e%13.5e%13.5e%13.5e%13.5e\n' % row for row in rows))
442
438
  elif data_type == 5:
443
439
  # Complex data; n_data_per_node is assumed being 3
444
- for k in range(0, n):
445
- fh.write('%10i\n' % dset['node_nums'][k])
446
- fh.write('%13.5e%13.5e%13.5e%13.5e%13.5e%13.5e\n' %
447
- (dset['r1'][k].real, dset['r1'][k].imag, dset['r2'][k].real, dset['r2'][k].imag,
448
- dset['r3'][k].real, dset['r3'][k].imag))
440
+ rows = zip(dset['node_nums'], dset['r1'], dset['r2'], dset['r3'])
441
+ fh.write(''.join('%10i\n%13.5e%13.5e%13.5e%13.5e%13.5e%13.5e\n' %
442
+ (node, r1.real, r1.imag, r2.real, r2.imag, r3.real, r3.imag)
443
+ for node, r1, r2, r3 in rows))
449
444
  else:
450
445
  raise ValueError('Unsupported data type')
451
446
  fh.write('%6i\n' % -1)
@@ -504,7 +499,9 @@ def _extract55(block_data):
504
499
  # Body
505
500
  split_data = ''.join(split_data[10:])
506
501
  node_nums = np.asarray([int(str) for str in split_data.splitlines(True)[::2]])
507
- node_vals = np.array([[str[i*13:(i+1)*13] for i in range(len(str)//13) ] for str in split_data.splitlines(True)[1::2]], 'd').flatten()
502
+ # values are in fields of 13 characters, which may touch each other
503
+ value_lines = split_data.splitlines()[1::2]
504
+ node_vals = np.array([line[i:i + 13] for line in value_lines for i in range(0, len(line) - 12, 13)], 'd')
508
505
  if dset['data_type'] == 2:
509
506
  # real data
510
507
  if dset['n_data_per_node'] == 3:
@@ -225,9 +225,11 @@ class UFF:
225
225
  si = self._block_ind[ii, 0]
226
226
  ei = self._block_ind[ii, 1]
227
227
  try:
228
- block_data = data[si:ei + 1].splitlines()
229
- self._set_types[ii] = int(block_data[1][0:6])
230
- if block_data[1][6].lower() == 'b':
228
+ # only the second line (data-set type, 'b' for binary) is
229
+ # needed; it follows the ' -1' line within 200 bytes
230
+ type_line = data[si:min(si + 200, ei + 1)].splitlines()[1]
231
+ self._set_types[ii] = int(type_line[0:6])
232
+ if type_line[6:7].lower() == b'b':
231
233
  self._set_formats[ii] = 1
232
234
  except:
233
235
  # Some non-valid blocks found; ignore the exception
@@ -257,6 +259,11 @@ class UFF:
257
259
  This usefull for large files.
258
260
  """
259
261
  dset = []
262
+ if not self.file_exists():
263
+ raise Exception('Cannot read from a non-existing file: ' + self._filename)
264
+ if not self._refreshed:
265
+ if not self.refresh():
266
+ raise Exception('Cannot read from the file: ' + self._filename)
260
267
  if setn is None:
261
268
  read_range = range(0, self._n_sets)
262
269
  else:
@@ -264,11 +271,6 @@ class UFF:
264
271
  read_range = [setn]
265
272
  else:
266
273
  read_range = setn
267
- if not self.file_exists():
268
- raise Exception('Cannot read from a non-existing file: ' + self._filename)
269
- if not self._refreshed:
270
- if not self.refresh():
271
- raise Exception('Cannot read from the file: ' + self._filename)
272
274
  try:
273
275
  for ii in read_range:
274
276
  dset.append(self._read_set(ii, header_only=header_only))
@@ -324,6 +326,7 @@ class UFF:
324
326
  self._write_set(dsets[ii], 'add', force_double=force_double)
325
327
  else:
326
328
  raise Exception('Unknown mode: ' + mode)
329
+ self.refresh()
327
330
 
328
331
  def _read_set(self, n, header_only=False):
329
332
  """
@@ -490,7 +493,9 @@ class UFF:
490
493
  raise # re-raise the last exception
491
494
  else:
492
495
  fh.close()
493
- self.refresh()
496
+ # the file has changed: its index of data-sets is rebuilt when it is
497
+ # needed next, not after every data-set (write_sets writes many)
498
+ self._refreshed = False
494
499
 
495
500
 
496
501
  if __name__ == '__main__':
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes