Coverage for src / sdynpy / fileio / sdynpy_uff_datasets / sdynpy_uff_dataset_2411.py: 31%
39 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-11 16:22 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-11 16:22 +0000
1# -*- coding: utf-8 -*-
2"""
3Nodes
5This dataset defines the node positions, colors, and coordinate systems in a
6geometry.
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.
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.
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.
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"""
27from ..sdynpy_uff import UFFReadError, parse_uff_line, parse_uff_lines, write_uff_line
28import numpy as np
31class Sdynpy_UFF_Dataset_2411:
32 def __init__(self, node_labels=np.array((1,)), export_coordinate_systems=np.array((1,)),
33 displacement_coordinate_systems=np.array((1,)), colors=np.array((1,)),
34 coordinates=np.array([(0, 0, 0)])):
35 self.node_labels = node_labels
36 self.export_coordinate_systems = export_coordinate_systems
37 self.displacement_coordinate_systems = displacement_coordinate_systems
38 self.colors = colors
39 self.coordinates = coordinates
41 @property
42 def dataset_number(self):
43 return 2411
45 @classmethod
46 def from_uff_data_array(cls, data):
47 # Transform from binary to ascii
48 data = [line.decode() for line in data]
49 nnodes = len(data) // 2
50 node_labels = np.empty(nnodes, dtype=int)
51 export_coordinate_systems = np.empty(nnodes, dtype=int)
52 displacement_coordinate_systems = np.empty(nnodes, dtype=int)
53 coordinates = np.empty((nnodes, 3), dtype=float)
54 colors = np.empty(nnodes, dtype=int)
55 for i in range(nnodes):
56 # Record 1: FORMAT(4I10)
57 # Field 1 -- node label
58 # Field 2 -- export coordinate system number
59 # Field 3 -- displacement coordinate system number
60 # Field 4 -- color
61 node_labels[i], export_coordinate_systems[i], displacement_coordinate_systems[i], colors[i] = (
62 parse_uff_line(data[2 * i], 4 * ['I10']))
63# Record 2: FORMAT(1P3D25.16)
64# Fields 1-3 -- node coordinates in the part coordinate
65# system
66 coordinates[i, :] = parse_uff_line(data[2 * i + 1], 3 * ['D25.16'])
67 # Make sure coordinates don't end up being 2D
68 ds_2411 = cls(node_labels, export_coordinate_systems, displacement_coordinate_systems,
69 colors, coordinates)
70 return ds_2411
72 def __repr__(self):
73 return 'Sdynpy_UFF_Dataset_2411<{} node(s)>'.format(len(self.node_labels))
75 def write_string(self):
76 return_string = ''
77 for node_label, export_coordinate_system, displacement_coordinate_system, color, coordinates in zip(
78 self.node_labels, self.export_coordinate_systems, self.displacement_coordinate_systems, self.colors, self.coordinates):
79 return_string += write_uff_line([node_label, export_coordinate_system, displacement_coordinate_system,
80 color] + coordinates.tolist(), 4 * ['I10'] + ['\n'] + 3 * ['D25.16'])
81 return return_string
83 def __str__(self):
84 lines = self.write_string().split('\n')
85 if len(lines) > 8:
86 return 'Dataset 2411: Nodes\n ' + '\n '.join(lines[0:5] + ['.', '.', '.'])
87 else:
88 return 'Dataset 2411: Nodes\n ' + '\n '.join(lines)
91def read(data):
92 return Sdynpy_UFF_Dataset_2411.from_uff_data_array(data)