Coverage for src / sdynpy / fileio / sdynpy_uff_datasets / sdynpy_uff_dataset_82.py: 36%

33 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-11 16:22 +0000

1# -*- coding: utf-8 -*- 

2""" 

3Tracelines 

4 

5This dataset defines tracelines, which are used to improve visibility of a 

6test geometry. 

7""" 

8""" 

9Copyright 2022 National Technology & Engineering Solutions of Sandia, 

10LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. 

11Government retains certain rights in this software. 

12 

13This program is free software: you can redistribute it and/or modify 

14it under the terms of the GNU General Public License as published by 

15the Free Software Foundation, either version 3 of the License, or 

16(at your option) any later version. 

17 

18This program is distributed in the hope that it will be useful, 

19but WITHOUT ANY WARRANTY; without even the implied warranty of 

20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

21GNU General Public License for more details. 

22 

23You should have received a copy of the GNU General Public License 

24along with this program. If not, see <https://www.gnu.org/licenses/>. 

25""" 

26 

27from ..sdynpy_uff import UFFReadError, parse_uff_line, parse_uff_lines, write_uff_line 

28import numpy as np 

29 

30 

31class Sdynpy_UFF_Dataset_82: 

32 def __init__(self, 

33 traceline_number=1, 

34 color=1, 

35 identification='', 

36 nodes=[1]): 

37 self.traceline_number = traceline_number 

38 self.color = color 

39 self.identification = identification 

40 self.nodes = nodes 

41 

42 @property 

43 def dataset_number(self): 

44 return 82 

45 

46 @classmethod 

47 def from_uff_data_array(cls, data): 

48 # Transform from binary to ascii 

49 data = [line.decode() for line in data] 

50# Record 1: FORMAT(3I10) 

51# Field 1 - trace line number 

52# Field 2 - number of nodes defining trace line 

53# (maximum of 250) 

54# Field 3 - color 

55 traceline_number, number_nodes, color = parse_uff_line(data[0], 3 * ['I10']) 

56# Record 2: FORMAT(80A1) 

57# Field 1 - Identification line 

58 identification, = parse_uff_line(data[1], ['A80']) 

59# Record 3: FORMAT(8I10) 

60# Field 1 - nodes defining trace line 

61# = > 0 draw line to node 

62# = 0 move to node (a move to the first 

63# node is implied) 

64 nodes, read_lines = parse_uff_lines(data[2:], 8 * ['I10'], number_nodes) 

65 # Make sure connectivities doesn't end up being 2D 

66 ds_82 = cls(traceline_number=traceline_number, 

67 nodes=nodes, 

68 color=color, 

69 identification=identification) 

70 return ds_82 

71 

72 def __repr__(self): 

73 return 'Sdynpy_UFF_Dataset_82<traceline {:}>'.format(self.traceline_number) 

74 

75 def write_string(self): 

76 return_string = '' 

77 return_string += write_uff_line([self.traceline_number, 

78 len(self.nodes), 

79 self.color], 3 * ['I10']) 

80 return_string += write_uff_line([self.identification], ['A80']) 

81 return_string += write_uff_line(self.nodes, 8 * ['I10']) 

82 return return_string 

83 

84 def __str__(self): 

85 lines = self.write_string().split('\n') 

86 if len(lines) > 8: 

87 return 'Dataset 82: Tracelines\n ' + '\n '.join(lines[0:5] + ['.', '.', '.']) 

88 else: 

89 return 'Dataset 82: Tracelines\n ' + '\n '.join(lines) 

90 

91 

92def read(data): 

93 return Sdynpy_UFF_Dataset_82.from_uff_data_array(data)