Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to convert set 2412 to set 82 #55

Merged
merged 3 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
253 changes: 253 additions & 0 deletions data/mesh_set2412_to_convert.uff
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
-1
18
1 0 0 1 1
CS1
0.00000E+00 0.00000E+00 0.00000E+00 1.00000E+00 0.00000E+00 0.00000E+00
0.00000E+00 0.00000E+00 1.00000E+00
-1
-1
15
7 1 0 1 -5.16190E+01 5.16190E+01 5.00000E+01
6 1 0 1 -3.65000E+01 6.32200E+01 5.00000E+01
5 1 0 1 -1.88940E+01 7.05130E+01 5.00000E+01
4 1 0 1 5.09760E-15 8.32500E+01 5.00000E+01
3 1 0 1 1.88940E+01 7.05130E+01 5.00000E+01
2 1 0 1 3.65000E+01 6.32200E+01 5.00000E+01
1 1 0 1 5.16190E+01 5.16190E+01 5.00000E+01
24 1 0 1 6.32200E+01 3.65000E+01 5.00000E+01
23 1 0 1 7.05130E+01 1.88940E+01 5.00000E+01
22 1 0 1 8.32500E+01 0.00000E+00 5.00000E+01
21 1 0 1 7.05130E+01 -1.88940E+01 5.00000E+01
20 1 0 1 6.32200E+01 -3.65000E+01 5.00000E+01
19 1 0 1 5.16190E+01 -5.16190E+01 5.00000E+01
18 1 0 1 3.65000E+01 -6.32200E+01 5.00000E+01
17 1 0 1 1.88940E+01 -7.05130E+01 5.00000E+01
16 1 0 1 5.09760E-15 -8.32500E+01 5.00000E+01
15 1 0 1 -1.88940E+01 -7.05130E+01 5.00000E+01
14 1 0 1 -3.65000E+01 -6.32200E+01 5.00000E+01
13 1 0 1 -5.16190E+01 -5.16190E+01 5.00000E+01
12 1 0 1 -6.32200E+01 -3.65000E+01 5.00000E+01
11 1 0 1 -7.05130E+01 -1.88940E+01 5.00000E+01
10 1 0 1 -8.32500E+01 -1.01950E-14 5.00000E+01
9 1 0 1 -7.05130E+01 1.88940E+01 5.00000E+01
8 1 0 1 -6.32200E+01 3.65000E+01 5.00000E+01
31 1 0 1 -5.16190E+01 5.16190E+01 1.70000E+01
30 1 0 1 -3.65000E+01 6.32200E+01 1.70000E+01
29 1 0 1 -1.88940E+01 7.05130E+01 1.70000E+01
28 1 0 1 5.09760E-15 8.32500E+01 1.70000E+01
27 1 0 1 1.88940E+01 7.05130E+01 1.70000E+01
26 1 0 1 3.65000E+01 6.32200E+01 1.70000E+01
25 1 0 1 5.16190E+01 5.16190E+01 1.70000E+01
48 1 0 1 6.32200E+01 3.65000E+01 1.70000E+01
47 1 0 1 7.05130E+01 1.88940E+01 1.70000E+01
46 1 0 1 8.32500E+01 0.00000E+00 1.70000E+01
45 1 0 1 7.05130E+01 -1.88940E+01 1.70000E+01
44 1 0 1 6.32200E+01 -3.65000E+01 1.70000E+01
43 1 0 1 5.16190E+01 -5.16190E+01 1.70000E+01
42 1 0 1 3.65000E+01 -6.32200E+01 1.70000E+01
41 1 0 1 1.88940E+01 -7.05130E+01 1.70000E+01
40 1 0 1 5.09760E-15 -8.32500E+01 1.70000E+01
39 1 0 1 -1.88940E+01 -7.05130E+01 1.70000E+01
38 1 0 1 -3.65000E+01 -6.32200E+01 1.70000E+01
37 1 0 1 -5.16190E+01 -5.16190E+01 1.70000E+01
36 1 0 1 -6.32200E+01 -3.65000E+01 1.70000E+01
35 1 0 1 -7.05130E+01 -1.88940E+01 1.70000E+01
34 1 0 1 -8.32500E+01 -1.01950E-14 1.70000E+01
33 1 0 1 -7.05130E+01 1.88940E+01 1.70000E+01
32 1 0 1 -6.32200E+01 3.65000E+01 1.70000E+01
55 1 0 1 -5.16190E+01 5.16190E+01 -1.70000E+01
54 1 0 1 -3.65000E+01 6.32200E+01 -1.70000E+01
53 1 0 1 -1.88940E+01 7.05130E+01 -1.70000E+01
52 1 0 1 5.09760E-15 8.32500E+01 -1.70000E+01
51 1 0 1 1.88940E+01 7.05130E+01 -1.70000E+01
50 1 0 1 3.65000E+01 6.32200E+01 -1.70000E+01
49 1 0 1 5.16190E+01 5.16190E+01 -1.70000E+01
72 1 0 1 6.32200E+01 3.65000E+01 -1.70000E+01
71 1 0 1 7.05130E+01 1.88940E+01 -1.70000E+01
70 1 0 1 8.32500E+01 0.00000E+00 -1.70000E+01
69 1 0 1 7.05130E+01 -1.88940E+01 -1.70000E+01
68 1 0 1 6.32200E+01 -3.65000E+01 -1.70000E+01
67 1 0 1 5.16190E+01 -5.16190E+01 -1.70000E+01
66 1 0 1 3.65000E+01 -6.32200E+01 -1.70000E+01
65 1 0 1 1.88940E+01 -7.05130E+01 -1.70000E+01
64 1 0 1 5.09760E-15 -8.32500E+01 -1.70000E+01
63 1 0 1 -1.88940E+01 -7.05130E+01 -1.70000E+01
62 1 0 1 -3.65000E+01 -6.32200E+01 -1.70000E+01
61 1 0 1 -5.16190E+01 -5.16190E+01 -1.70000E+01
60 1 0 1 -6.32200E+01 -3.65000E+01 -1.70000E+01
59 1 0 1 -7.05130E+01 -1.88940E+01 -1.70000E+01
58 1 0 1 -8.32500E+01 -1.01950E-14 -1.70000E+01
57 1 0 1 -7.05130E+01 1.88940E+01 -1.70000E+01
56 1 0 1 -6.32200E+01 3.65000E+01 -1.70000E+01
79 1 0 1 -5.16190E+01 5.16190E+01 -5.00000E+01
78 1 0 1 -3.65000E+01 6.32200E+01 -5.00000E+01
77 1 0 1 -1.88940E+01 7.05130E+01 -5.00000E+01
76 1 0 1 5.09760E-15 8.32500E+01 -5.00000E+01
75 1 0 1 1.88940E+01 7.05130E+01 -5.00000E+01
74 1 0 1 3.65000E+01 6.32200E+01 -5.00000E+01
73 1 0 1 5.16190E+01 5.16190E+01 -5.00000E+01
96 1 0 1 6.32200E+01 3.65000E+01 -5.00000E+01
95 1 0 1 7.05130E+01 1.88940E+01 -5.00000E+01
94 1 0 1 8.32500E+01 0.00000E+00 -5.00000E+01
93 1 0 1 7.05130E+01 -1.88940E+01 -5.00000E+01
92 1 0 1 6.32200E+01 -3.65000E+01 -5.00000E+01
91 1 0 1 5.16190E+01 -5.16190E+01 -5.00000E+01
90 1 0 1 3.65000E+01 -6.32200E+01 -5.00000E+01
89 1 0 1 1.88940E+01 -7.05130E+01 -5.00000E+01
88 1 0 1 5.09760E-15 -8.32500E+01 -5.00000E+01
87 1 0 1 -1.88940E+01 -7.05130E+01 -5.00000E+01
86 1 0 1 -3.65000E+01 -6.32200E+01 -5.00000E+01
85 1 0 1 -5.16190E+01 -5.16190E+01 -5.00000E+01
84 1 0 1 -6.32200E+01 -3.65000E+01 -5.00000E+01
83 1 0 1 -7.05130E+01 -1.88940E+01 -5.00000E+01
82 1 0 1 -8.32500E+01 -1.01950E-14 -5.00000E+01
81 1 0 1 -7.05130E+01 1.88940E+01 -5.00000E+01
80 1 0 1 -6.32200E+01 3.65000E+01 -5.00000E+01
-1
-1
2412
1 44 0 0 1 4
1 25 48 24
2 44 0 0 1 4
25 49 72 48
3 44 0 0 1 4
49 73 96 72
4 44 0 0 1 4
24 48 47 23
5 44 0 0 1 4
48 72 71 47
6 44 0 0 1 4
72 96 95 71
7 44 0 0 1 4
23 47 46 22
8 44 0 0 1 4
47 71 70 46
9 44 0 0 1 4
71 95 94 70
10 44 0 0 1 4
22 46 45 21
11 44 0 0 1 4
46 70 69 45
12 44 0 0 1 4
70 94 93 69
13 44 0 0 1 4
21 45 44 20
14 44 0 0 1 4
45 69 68 44
15 44 0 0 1 4
69 93 92 68
16 44 0 0 1 4
20 44 43 19
17 44 0 0 1 4
44 68 67 43
18 44 0 0 1 4
68 92 91 67
19 44 0 0 1 4
19 43 42 18
20 44 0 0 1 4
43 67 66 42
21 44 0 0 1 4
67 91 90 66
22 44 0 0 1 4
18 42 41 17
23 44 0 0 1 4
42 66 65 41
24 44 0 0 1 4
66 90 89 65
25 44 0 0 1 4
17 41 40 16
26 44 0 0 1 4
41 65 64 40
27 44 0 0 1 4
65 89 88 64
28 44 0 0 1 4
16 40 39 15
29 44 0 0 1 4
40 64 63 39
30 44 0 0 1 4
64 88 87 63
31 44 0 0 1 4
15 39 38 14
32 44 0 0 1 4
39 63 62 38
33 44 0 0 1 4
63 87 86 62
34 44 0 0 1 4
14 38 37 13
35 44 0 0 1 4
38 62 61 37
36 44 0 0 1 4
62 86 85 61
37 44 0 0 1 4
13 37 36 12
38 44 0 0 1 4
37 61 60 36
39 44 0 0 1 4
61 85 84 60
40 44 0 0 1 4
12 36 35 11
41 44 0 0 1 4
36 60 59 35
42 44 0 0 1 4
60 84 83 59
43 44 0 0 1 4
11 35 34 10
44 44 0 0 1 4
35 59 58 34
45 44 0 0 1 4
59 83 82 58
46 44 0 0 1 4
10 34 33 9
47 44 0 0 1 4
34 58 57 33
48 44 0 0 1 4
58 82 81 57
49 44 0 0 1 4
9 33 32 8
50 44 0 0 1 4
33 57 56 32
51 44 0 0 1 4
57 81 80 56
52 44 0 0 1 4
8 32 31 7
53 44 0 0 1 4
32 56 55 31
54 44 0 0 1 4
56 80 79 55
55 44 0 0 1 4
7 31 30 6
56 44 0 0 1 4
31 55 54 30
57 44 0 0 1 4
55 79 78 54
58 44 0 0 1 4
6 30 29 5
59 44 0 0 1 4
30 54 53 29
60 44 0 0 1 4
54 78 77 53
61 44 0 0 1 4
5 29 28 4
62 44 0 0 1 4
29 53 52 28
63 44 0 0 1 4
53 77 76 52
64 44 0 0 1 4
4 28 27 3
65 44 0 0 1 4
28 52 51 27
66 44 0 0 1 4
52 76 75 51
67 44 0 0 1 4
3 27 26 2
68 44 0 0 1 4
27 51 50 26
69 44 0 0 1 4
51 75 74 50
70 44 0 0 1 4
2 26 25 1
71 44 0 0 1 4
26 50 49 25
72 44 0 0 1 4
50 74 73 49
-1
34 changes: 34 additions & 0 deletions pyuff/tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pyuff
import numpy as np

def _opt_fields(dict, fields_dict):
"""Sets the optional fields of the dict dictionary.
Expand Down Expand Up @@ -125,3 +127,35 @@ def check_dict_for_none(dataset):
return dataset1


def convert_dataset_2412_to_82(datasets):
"""Converts the dataset 2412 to dataset 82"""

datasets_82 = []
nodes = list()
for i in range(0, len(datasets)):
if (datasets[i]["type"] == 2412) and ("quad" in datasets[i].keys()):
for j in range(len(datasets[i]["quad"]["nodes_nums"])):
nodes.append(datasets[i]["quad"]["nodes_nums"][j][0])
nodes.append(datasets[i]["quad"]["nodes_nums"][j][1])
nodes.append(0)
nodes.append(datasets[i]["quad"]["nodes_nums"][j][1])
nodes.append(datasets[i]["quad"]["nodes_nums"][j][2])
nodes.append(0)
nodes.append(datasets[i]["quad"]["nodes_nums"][j][2])
nodes.append(datasets[i]["quad"]["nodes_nums"][j][3])
nodes.append(0)
nodes.append(datasets[i]["quad"]["nodes_nums"][j][3])
nodes.append(datasets[i]["quad"]["nodes_nums"][j][0])
nodes.append(0)
nodes = np.array(nodes)
dataset_82 = pyuff.prepare_82(
trace_num=i,
n_nodes=len(nodes),
nodes=nodes,
color=0,
id="",
return_full_dict=True,
)
datasets_82.append(dataset_82)

return datasets_82
21 changes: 21 additions & 0 deletions tests/test_convert_2412_to_82.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import sys, os

my_path = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, my_path + "/../")

import pyuff
from pyuff import tools

geom_exp_path = "./data/mesh_set2412_to_convert.uff"
file_geom = pyuff.UFF(geom_exp_path)
sets_old = file_geom.read_sets()
sets_new = tools.convert_dataset_2412_to_82(sets_old)

#check manually few values; better testing required
np.testing.assert_equal(sets_new[0]['type'], 82)
np.testing.assert_equal(sets_new[0]['trace_num'], 2)
np.testing.assert_equal(sets_new[0]['n_nodes'], 864)
np.testing.assert_equal(sets_new[0]['nodes'][:4], np.array([1,25,0,25]))