forked from KVSlab/turtleFSI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_turtleFSI.py
127 lines (100 loc) · 4.57 KB
/
test_turtleFSI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File under GNU GPL (v3) licence, see LICENSE file for details.
# This software is distributed WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.
import pytest
import numpy as np
from os import system
from pathlib import Path
def compare(one, two):
if one < 1e-7 or two < 1e-7:
return '{:0.5e}'.format(one) == '{:0.5e}'.format(two)
else:
return '{:0.6e}'.format(one) == '{:0.6e}'.format(two)
def test_cfd():
cmd = ("turtleFSI --problem TF_cfd -dt 0.01 -T 0.05 --verbose True" +
" --folder tmp --sub-folder 1")
d = system(cmd)
drag = np.loadtxt(Path.cwd().joinpath("tmp/1/Drag.txt"))[-1]
lift = np.loadtxt(Path.cwd().joinpath("tmp/1/Lift.txt"))[-1]
drag_reference = 4.503203576965564
lift_reference = -0.03790359084395478
assert compare(drag, drag_reference)
assert compare(lift, lift_reference)
def test_csm():
cmd = ("turtleFSI --problem TF_csm -dt 0.01 -T 0.05 --verbose True" +
" --folder tmp --sub-folder 2")
d = system(cmd)
distance_x = np.loadtxt("tmp/2/dis_x.txt")[-1]
distance_y = np.loadtxt("tmp/2/dis_y.txt")[-1]
distance_x_reference = -3.312418050495862e-05
distance_y_reference = -0.003738529237136441
assert compare(distance_x, distance_x_reference)
assert compare(distance_y, distance_y_reference)
def test_fsi():
cmd = ("turtleFSI --problem TF_fsi -dt 0.01 -T 0.05 --verbose True --theta 0.51" +
" --folder tmp --sub-folder 3")
d = system(cmd)
drag = np.loadtxt("tmp/3/Drag.txt")[-1]
lift = np.loadtxt("tmp/3/Lift.txt")[-1]
distance_x = np.loadtxt("tmp/3/dis_x.txt")[-1]
distance_y = np.loadtxt("tmp/3/dis_y.txt")[-1]
distance_x_reference = -6.896013956339182e-06
distance_y_reference = 1.876355330341896e-09
drag_reference = 4.407481239804155
lift_reference = -0.005404703556977697
assert compare(distance_x, distance_x_reference)
assert compare(distance_y, distance_y_reference)
assert compare(drag, drag_reference)
assert compare(lift, lift_reference)
@pytest.mark.parametrize("extrapolation_sub_type", ["volume", "volume_change",
"constant", "small_constant"])
def test_laplace(extrapolation_sub_type):
cmd = ("turtleFSI --problem TF_fsi -dt 0.01 -T 0.05 --verbose True --theta 0.51" +
" --folder tmp --sub-folder 4")
d = system(cmd)
drag = np.loadtxt("tmp/4/Drag.txt")[-1]
lift = np.loadtxt("tmp/4/Lift.txt")[-1]
distance_x = np.loadtxt("tmp/4/dis_x.txt")[-1]
distance_y = np.loadtxt("tmp/4/dis_y.txt")[-1]
distance_x_reference = -6.896013956339182e-06
distance_y_reference = 1.876355330341896e-09
drag_reference = 4.407481239804155
lift_reference = -0.005404703556977697
assert compare(distance_x, distance_x_reference)
assert compare(distance_y, distance_y_reference)
assert compare(drag, drag_reference)
assert compare(lift, lift_reference)
@pytest.mark.parametrize("extrapolation_sub_type", ["constrained_disp", "constrained_disp_vel"])
def test_biharmonic(extrapolation_sub_type):
cmd = ("turtleFSI --problem TF_fsi -dt 0.01 -T 0.05 --verbose True --theta 0.51" +
" --extrapolation biharmonic --folder tmp --sub-folder 5")
d = system(cmd)
drag = np.loadtxt("tmp/5/Drag.txt")[-1]
lift = np.loadtxt("tmp/5/Lift.txt")[-1]
distance_x = np.loadtxt("tmp/5/dis_x.txt")[-1]
distance_y = np.loadtxt("tmp/5/dis_y.txt")[-1]
distance_x_reference = -6.896013956339182e-06
distance_y_reference = 1.876355330341896e-09
drag_reference = 4.407481239804155
lift_reference = -0.005404703556977697
assert compare(distance_x, distance_x_reference)
assert compare(distance_y, distance_y_reference)
assert compare(drag, drag_reference)
assert compare(lift, lift_reference)
def test_elastic():
cmd = ("turtleFSI --problem TF_fsi -dt 0.01 -T 0.05 --verbose True --theta 0.51" +
" -e elastic -et constant --folder tmp --sub-folder 6")
d = system(cmd)
drag = np.loadtxt("tmp/6/Drag.txt")[-1]
lift = np.loadtxt("tmp/6/Lift.txt")[-1]
distance_x = np.loadtxt("tmp/6/dis_x.txt")[-1]
distance_y = np.loadtxt("tmp/6/dis_y.txt")[-1]
distance_x_reference = -6.896144755254494e-06
distance_y_reference = 1.868651990487361e-09
drag_reference = 4.407488867909029
lift_reference = -0.005404616050528832
assert compare(distance_x, distance_x_reference)
assert compare(distance_y, distance_y_reference)
assert compare(drag, drag_reference)
assert compare(lift, lift_reference)