20
20
need an Abaqus installation to run.
21
21
"""
22
22
23
+ import sys
23
24
import os
24
25
import pytest
25
26
import json
27
+ import shutil
28
+ from pathlib import Path
26
29
27
30
import numpy as np
28
31
import pandas as pd
32
35
from odbclient .odbclient import OdbServerError
33
36
34
37
@pytest .fixture
35
- def client ():
36
- return odbclient .OdbClient ('tests/beam_3d_hex_quad.odb' )
38
+ def datapath ():
39
+ base = os .path .dirname (__file__ )
40
+
41
+ def join_path (filename ):
42
+ return os .path .join (base , filename )
43
+
44
+ return join_path
45
+
46
+
47
+ @pytest .fixture (params = ["2022" , "2023" , "2024" ])
48
+ def abaqus_version (request ):
49
+ return request .param
50
+
51
+
52
+ @pytest .fixture
53
+ def abaqus_bin (abaqus_version ):
54
+ if sys .platform == 'win32' :
55
+ return f"C:/Program Files/SIMULIA/{ abaqus_version } /EstProducts/win_b64/code/bin/SMALauncher.exe"
56
+ return shutil .which (f"abaqus{ abaqus_version } " )
57
+
58
+
59
+ @pytest .fixture
60
+ def client (datapath , abaqus_version , abaqus_bin ):
61
+ python_path = os .path .join (Path .home (), ".conda" , "envs" , f"odbserver-{ abaqus_version } " )
62
+ odb_file = datapath (f"beam_3d_hex_quad-{ abaqus_version } .odb" )
63
+ return odbclient .OdbClient (odb_file , abaqus_bin = abaqus_bin , python_env_path = python_path )
37
64
38
65
39
66
def test_not_existing_odbserver_env ():
@@ -54,8 +81,9 @@ def test_odbclient_invalid_instance(client):
54
81
with pytest .raises (KeyError ):
55
82
client .node_coordinates ("FOO-1-1" )
56
83
57
- def test_odbclient_node_coordinates (client ):
58
- expected = pd .read_csv ('tests/node_coordinates.csv' , index_col = 'node_id' )
84
+
85
+ def test_odbclient_node_coordinates (client , datapath ):
86
+ expected = pd .read_csv (datapath ('node_coordinates.csv' ), index_col = 'node_id' )
59
87
pd .testing .assert_frame_equal (client .node_coordinates ('PART-1-1' ), expected )
60
88
61
89
@@ -106,10 +134,8 @@ def test_odbclient_elset_names_invalid_instance_name(client):
106
134
client .elset_names ('nonexistent' )
107
135
108
136
109
- def test_element_connectivity (client ):
110
- expected = pd .read_json (
111
- 'tests/connectivity.json' , orient = "index"
112
- )
137
+ def test_element_connectivity (client , datapath ):
138
+ expected = pd .read_json (datapath ('connectivity.json' ), orient = "index" )
113
139
expected .index .names = ["element_id" ]
114
140
115
141
result = client .element_connectivity ('PART-1-1' )
@@ -141,8 +167,8 @@ def test_variable_names(client):
141
167
np .testing .assert_array_equal (result , expected )
142
168
143
169
144
- def test_variable_stress_element_nodal (client ):
145
- expected = pd .read_csv ('tests/ stress_element_nodal.csv' , index_col = ['node_id' , 'element_id' ])
170
+ def test_variable_stress_element_nodal (client , datapath ):
171
+ expected = pd .read_csv (datapath ( ' stress_element_nodal.csv') , index_col = ['node_id' , 'element_id' ])
146
172
result = client .variable ('S' , 'PART-1-1' , 'Load' , 1 )
147
173
148
174
pd .testing .assert_frame_equal (result , expected )
@@ -160,17 +186,20 @@ def test_variable_invalid_instance_name(client):
160
186
client .variable ('S' , 'nonexistent' , 'Load' , 1 )
161
187
162
188
163
- def test_variable_stress_integration_point (client ):
164
- expected = pd .read_csv ('tests/stress_integration_point.csv' ,
165
- index_col = ['element_id' , 'ipoint_id' ])
189
+ def test_variable_stress_integration_point (client , datapath ):
190
+ expected = pd .read_csv (
191
+ datapath ('stress_integration_point.csv' ), index_col = ['element_id' , 'ipoint_id' ]
192
+ )
166
193
result = client .variable ('S' , 'PART-1-1' , 'Load' , 1 , position = 'INTEGRATION POINTS' )
167
- result .to_csv ('tests/ stress_integration_point.csv' )
194
+ result .to_csv (datapath ( ' stress_integration_point.csv') )
168
195
pd .testing .assert_frame_equal (result , expected )
169
196
170
197
171
- @pytest .fixture
172
- def client_history ():
173
- return odbclient .OdbClient ('tests/history_output_test.odb' )
198
+ @pytest .fixture ()
199
+ def client_history (datapath , abaqus_version , abaqus_bin ):
200
+ python_path = os .path .join (Path .home (), ".conda" , "envs" , f"odbserver-{ abaqus_version } " )
201
+ odb_file = datapath (f"history_output_test-{ abaqus_version } .odb" )
202
+ return odbclient .OdbClient (odb_file , abaqus_bin = abaqus_bin , python_env_path = python_path )
174
203
175
204
176
205
def test_history_region_empty (client ):
@@ -202,19 +231,111 @@ def test_history_outputs(client_history):
202
231
'CUR3' ,
203
232
]
204
233
234
+
205
235
def test_history_output_values (client_history ):
206
236
assert client_history .history_output_values ("Step-1" , 'Element ASSEMBLY.1' , 'CTF1' ).array [1 ] == pytest .approx (0.09999854117631912 )
207
237
208
238
209
- def test_history_region_description (client_history ):
210
- assert (
211
- client_history .history_region_description ("Step-1" , 'Element ASSEMBLY.1' )
212
- == "Output at assembly ASSEMBLY instance ASSEMBLY element 1"
213
- )
214
-
215
-
216
- def test_history_info (client_history ):
217
- expected = json .loads ("""
218
- {"Output at assembly ASSEMBLY instance ASSEMBLY node 1 region RP-1": {"History Outputs": ["RF1", "RF2", "RF3", "RM1", "RM2", "RM3", "U1", "U2", "U3", "UR1", "UR2", "UR3"], "History Region": "Node ASSEMBLY.1", "Steps ": ["Step-1", "Step-2"]}, "Output at assembly ASSEMBLY instance ASSEMBLY element 1": {"History Outputs": ["CTF1", "CTF2", "CTF3", "CTM1", "CTM2", "CTM3", "CU1", "CU2", "CU3", "CUR1", "CUR2", "CUR3"], "History Region": "Element ASSEMBLY.1", "Steps ": ["Step-1", "Step-2"]}, "Output at assembly ASSEMBLY instance ASSEMBLY node 2 region SET-5": {"History Outputs": ["RF1", "RF2", "RF3", "RM1", "RM2", "RM3", "U1", "U2", "U3", "UR1", "UR2", "UR3"], "History Region": "Node ASSEMBLY.2", "Steps ": ["Step-1", "Step-2"]}, "Output at assembly ASSEMBLY": {"History Outputs": ["ALLAE", "ALLCCDW", "ALLCCE", "ALLCCEN", "ALLCCET", "ALLCCSD", "ALLCCSDN", "ALLCCSDT", "ALLCD", "ALLDMD", "ALLDTI", "ALLEE", "ALLFD", "ALLIE", "ALLJD", "ALLKE", "ALLKL", "ALLPD", "ALLQB", "ALLSD", "ALLSE", "ALLVD", "ALLWK", "ETOTAL"], "History Region": "Assembly ASSEMBLY", "Steps ": ["Step-1", "Step-2"]}}
219
- """ )
220
- assert client_history .history_info () == expected
239
+ def test_history_region_description (client_history , abaqus_version ):
240
+ result = client_history .history_region_description ("Step-1" , 'Element ASSEMBLY.1' )
241
+ expected = "Output at assembly ASSEMBLY instance ASSEMBLY element 1"
242
+ if abaqus_version == "2024" :
243
+ expected += " region _PICKEDSET21"
244
+ assert result == expected
245
+
246
+
247
+ def test_history_info (client_history , abaqus_version ):
248
+ expected = {
249
+ "Output at assembly ASSEMBLY" : {
250
+ "History Outputs" : [
251
+ "ALLAE" ,
252
+ "ALLCCDW" ,
253
+ "ALLCCE" ,
254
+ "ALLCCEN" ,
255
+ "ALLCCET" ,
256
+ "ALLCCSD" ,
257
+ "ALLCCSDN" ,
258
+ "ALLCCSDT" ,
259
+ "ALLCD" ,
260
+ "ALLDMD" ,
261
+ "ALLDTI" ,
262
+ "ALLEE" ,
263
+ "ALLFD" ,
264
+ "ALLIE" ,
265
+ "ALLJD" ,
266
+ "ALLKE" ,
267
+ "ALLKL" ,
268
+ "ALLPD" ,
269
+ "ALLQB" ,
270
+ "ALLSD" ,
271
+ "ALLSE" ,
272
+ "ALLVD" ,
273
+ "ALLWK" ,
274
+ "ETOTAL" ,
275
+ ],
276
+ "History Region" : "Assembly ASSEMBLY" ,
277
+ "Steps " : ["Step-1" , "Step-2" ],
278
+ },
279
+ "Output at assembly ASSEMBLY instance ASSEMBLY node 1 region RP-1" : {
280
+ "History Outputs" : [
281
+ "RF1" ,
282
+ "RF2" ,
283
+ "RF3" ,
284
+ "RM1" ,
285
+ "RM2" ,
286
+ "RM3" ,
287
+ "U1" ,
288
+ "U2" ,
289
+ "U3" ,
290
+ "UR1" ,
291
+ "UR2" ,
292
+ "UR3" ,
293
+ ],
294
+ "History Region" : "Node ASSEMBLY.1" ,
295
+ "Steps " : ["Step-1" , "Step-2" ],
296
+ },
297
+ "Output at assembly ASSEMBLY instance ASSEMBLY element 1" : {
298
+ "History Outputs" : [
299
+ "CTF1" ,
300
+ "CTF2" ,
301
+ "CTF3" ,
302
+ "CTM1" ,
303
+ "CTM2" ,
304
+ "CTM3" ,
305
+ "CU1" ,
306
+ "CU2" ,
307
+ "CU3" ,
308
+ "CUR1" ,
309
+ "CUR2" ,
310
+ "CUR3" ,
311
+ ],
312
+ "History Region" : "Element ASSEMBLY.1" ,
313
+ "Steps " : ["Step-1" , "Step-2" ],
314
+ },
315
+ "Output at assembly ASSEMBLY instance ASSEMBLY node 2 region SET-5" : {
316
+ "History Outputs" : [
317
+ "RF1" ,
318
+ "RF2" ,
319
+ "RF3" ,
320
+ "RM1" ,
321
+ "RM2" ,
322
+ "RM3" ,
323
+ "U1" ,
324
+ "U2" ,
325
+ "U3" ,
326
+ "UR1" ,
327
+ "UR2" ,
328
+ "UR3" ,
329
+ ],
330
+ "History Region" : "Node ASSEMBLY.2" ,
331
+ "Steps " : ["Step-1" , "Step-2" ],
332
+ },
333
+ }
334
+ if abaqus_version == "2024" :
335
+ expected ["Output at assembly ASSEMBLY region Whole Model" ] = expected .pop ("Output at assembly ASSEMBLY" )
336
+ element_1 = expected .pop ("Output at assembly ASSEMBLY instance ASSEMBLY element 1" )
337
+ expected ["Output at assembly ASSEMBLY instance ASSEMBLY element 1 region _PICKEDSET21" ] = element_1
338
+ expected ["Output at assembly ASSEMBLY instance ASSEMBLY element 1 region _PICKEDSET22" ] = element_1
339
+
340
+ result = client_history .history_info ()
341
+ assert result == expected
0 commit comments