34
34
import os
35
35
36
36
import numpy as np
37
- import pytest
38
37
import pyvista as pv
39
38
import quaternion
40
39
50
49
from .utils import (
51
50
compare_test_result_pytest ,
52
51
compare_vtk_pytest ,
53
- get_pytest_test_name ,
54
- testing_input ,
55
- testing_temp ,
56
52
)
57
53
58
54
59
- def load_cosserat_curve_from_file ():
55
+ def load_cosserat_curve_from_file (reference_file_directory ):
60
56
"""Load the centerline coordinates from the reference files and create the
61
57
Cosserat curve."""
62
58
coordinates = np .loadtxt (
63
- os .path .join (testing_input , "test_cosserat_curve_centerline.txt" ),
59
+ os .path .join (reference_file_directory , "test_cosserat_curve_centerline.txt" ),
64
60
comments = "#" ,
65
61
delimiter = "," ,
66
62
unpack = False ,
67
63
)
68
64
return CosseratCurve (coordinates )
69
65
70
66
71
- def create_beam_solid_input_file ():
67
+ def create_beam_solid_input_file (reference_file_directory ):
72
68
"""Create a beam and solid input file for testing purposes."""
73
69
74
70
mpy .import_mesh_full = True
75
71
mesh = InputFile (
76
- dat_file = os .path .join (testing_input , "test_cosserat_curve_mesh.dat" )
72
+ dat_file = os .path .join (reference_file_directory , "test_cosserat_curve_mesh.dat" )
77
73
)
78
74
create_beam_mesh_helix (
79
75
mesh ,
@@ -89,10 +85,12 @@ def create_beam_solid_input_file():
89
85
return mesh
90
86
91
87
92
- def test_cosserat_curve_translate_and_rotate ():
88
+ def test_cosserat_curve_translate_and_rotate (
89
+ reference_file_directory , current_test_name
90
+ ):
93
91
"""Test that a curve can be loaded, rotated and transformed."""
94
92
95
- curve = load_cosserat_curve_from_file ()
93
+ curve = load_cosserat_curve_from_file (reference_file_directory )
96
94
97
95
# Translate the curve so that the start is at the origin
98
96
curve .translate (- curve .centerline_interpolation (5.0 ))
@@ -113,7 +111,7 @@ def test_cosserat_curve_translate_and_rotate():
113
111
def load_compare (name ):
114
112
"""Load the compare files and return a numpy array."""
115
113
return np .loadtxt (
116
- os .path .join (testing_input , f"{ get_pytest_test_name () } _{ name } .txt" )
114
+ os .path .join (reference_file_directory , f"{ current_test_name } _{ name } .txt" )
117
115
)
118
116
119
117
assert np .allclose (sol_half_pos , load_compare ("pos_half_ref" ), rtol = 1e-14 )
@@ -127,25 +125,27 @@ def load_compare(name):
127
125
)
128
126
129
127
130
- def test_cosserat_curve_vtk_representation ():
128
+ def test_cosserat_curve_vtk_representation (
129
+ tmp_path , reference_file_directory , current_test_name
130
+ ):
131
131
"""Test the vtk representation of the Cosserat curve."""
132
132
133
- result_name = os .path .join (testing_temp , get_pytest_test_name () + ".vtu" )
134
- curve = load_cosserat_curve_from_file ()
133
+ result_name = os .path .join (tmp_path , current_test_name + ".vtu" )
134
+ curve = load_cosserat_curve_from_file (reference_file_directory )
135
135
pv .UnstructuredGrid (curve .get_pyvista_polyline ()).save (result_name )
136
136
compare_vtk_pytest (
137
- os .path .join (testing_input , get_pytest_test_name () + ".vtu" ),
137
+ os .path .join (reference_file_directory , current_test_name + ".vtu" ),
138
138
result_name ,
139
139
rtol = 1e-8 ,
140
140
atol = 1e-8 ,
141
141
)
142
142
143
143
144
- def test_cosserat_curve_project_point ():
144
+ def test_cosserat_curve_project_point (reference_file_directory ):
145
145
"""Test that the project point function works as expected."""
146
146
147
147
# Load the curve
148
- curve = load_cosserat_curve_from_file ()
148
+ curve = load_cosserat_curve_from_file (reference_file_directory )
149
149
150
150
# Translate the curve so that the start is at the origin
151
151
curve .translate (- curve .centerline_interpolation (0.0 ))
@@ -158,16 +158,16 @@ def test_cosserat_curve_project_point():
158
158
assert np .allclose (t_ref , curve .project_point ([- 5 , 1 , 1 ], t0 = 4.0 ), rtol = rtol )
159
159
160
160
161
- def test_cosserat_mesh_transformation ():
161
+ def test_cosserat_mesh_transformation (reference_file_directory , current_test_name ):
162
162
"""Test that the get_mesh_transformation function works as expected."""
163
163
164
- curve = load_cosserat_curve_from_file ()
164
+ curve = load_cosserat_curve_from_file (reference_file_directory )
165
165
pos , rot = curve .get_centerline_position_and_rotation (0 )
166
166
rot = Rotation .from_quaternion (quaternion .as_float_array (rot ))
167
167
curve .translate (- pos )
168
168
curve .translate ([1 , 2 , 3 ])
169
169
170
- mesh = create_beam_solid_input_file ()
170
+ mesh = create_beam_solid_input_file (reference_file_directory )
171
171
pos , rot = get_mesh_transformation (
172
172
curve ,
173
173
mesh .nodes ,
@@ -184,7 +184,8 @@ def test_cosserat_mesh_transformation():
184
184
185
185
def load_result (name ):
186
186
with open (
187
- os .path .join (testing_input , f"{ get_pytest_test_name ()} _{ name } .json" ), "r"
187
+ os .path .join (reference_file_directory , f"{ current_test_name } _{ name } .json" ),
188
+ "r" ,
188
189
) as f :
189
190
return np .array (json .load (f ))
190
191
@@ -198,19 +199,19 @@ def load_result(name):
198
199
assert np .allclose (rot_ref , rot_np , rtol = 1e-14 )
199
200
200
201
201
- def test_cosserat_curve_mesh_warp ():
202
+ def test_cosserat_curve_mesh_warp (reference_file_directory ):
202
203
"""Warp a balloon along a centerline."""
203
204
204
205
# Load the curve
205
- curve = load_cosserat_curve_from_file ()
206
+ curve = load_cosserat_curve_from_file (reference_file_directory )
206
207
pos , rot = curve .get_centerline_position_and_rotation (0 )
207
208
rot = Rotation .from_quaternion (quaternion .as_float_array (rot ))
208
209
curve .translate (- pos )
209
210
curve .translate ([1 , 2 , 3 ])
210
211
211
212
# Warp the mesh. The reference coordinate system is rotated such that z axis is the longitudinal direction,
212
213
# and x and y are the first and second cross-section basis vectors respectively.
213
- mesh = create_beam_solid_input_file ()
214
+ mesh = create_beam_solid_input_file (reference_file_directory )
214
215
warp_mesh_along_curve (
215
216
mesh ,
216
217
curve ,
@@ -226,18 +227,20 @@ def test_cosserat_curve_mesh_warp():
226
227
)
227
228
228
229
229
- def test_cosserat_curve_mesh_warp_transform_boundary_conditions ():
230
+ def test_cosserat_curve_mesh_warp_transform_boundary_conditions (
231
+ reference_file_directory ,
232
+ ):
230
233
"""Test the transform boundary creation function."""
231
234
232
235
# Load the curve
233
- curve = load_cosserat_curve_from_file ()
236
+ curve = load_cosserat_curve_from_file (reference_file_directory )
234
237
pos , rot = curve .get_centerline_position_and_rotation (0 )
235
238
rot = Rotation .from_quaternion (quaternion .as_float_array (rot ))
236
239
curve .translate (- pos )
237
240
curve .translate ([1 , 2 , 3 ])
238
241
239
242
# Load the mesh
240
- mesh = create_beam_solid_input_file ()
243
+ mesh = create_beam_solid_input_file (reference_file_directory )
241
244
242
245
# Apply the transform boundary conditions
243
246
create_transform_boundary_conditions (
0 commit comments