airfoilranssolver 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- airfoilranssolver-0.1.0/LICENSE +21 -0
- airfoilranssolver-0.1.0/PKG-INFO +24 -0
- airfoilranssolver-0.1.0/README.md +2 -0
- airfoilranssolver-0.1.0/airfoilranssolver/__init__.py +0 -0
- airfoilranssolver-0.1.0/airfoilranssolver/launchers_no_coefficient_control.py +273 -0
- airfoilranssolver-0.1.0/airfoilranssolver/launchers_pimplefoam.py +400 -0
- airfoilranssolver-0.1.0/airfoilranssolver/launchers_rhopimplefoam.py +407 -0
- airfoilranssolver-0.1.0/airfoilranssolver/launchers_rhosimplefoam.py +549 -0
- airfoilranssolver-0.1.0/airfoilranssolver/launchers_simplefoam.py +408 -0
- airfoilranssolver-0.1.0/airfoilranssolver/utils.py +729 -0
- airfoilranssolver-0.1.0/airfoilranssolver.egg-info/PKG-INFO +24 -0
- airfoilranssolver-0.1.0/airfoilranssolver.egg-info/SOURCES.txt +15 -0
- airfoilranssolver-0.1.0/airfoilranssolver.egg-info/dependency_links.txt +1 -0
- airfoilranssolver-0.1.0/airfoilranssolver.egg-info/requires.txt +7 -0
- airfoilranssolver-0.1.0/airfoilranssolver.egg-info/top_level.txt +1 -0
- airfoilranssolver-0.1.0/pyproject.toml +36 -0
- airfoilranssolver-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Isaac.Robledo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: airfoilranssolver
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python tools for 2D airfoil Openfoam Simulation
|
|
5
|
+
Author-email: Isaac <isaac.robledo.martin@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ipatazas/AirfoilRANSSolver
|
|
8
|
+
Project-URL: Repository, https://github.com/ipatazas/AirfoilRANSSolver
|
|
9
|
+
Project-URL: Issues, https://github.com/ipatazas/AirfoilRANSSolver/issues
|
|
10
|
+
Keywords: airfoil,aerodynamics,cfd
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: matplotlib
|
|
16
|
+
Requires-Dist: airfoilgmesher
|
|
17
|
+
Requires-Dist: scipy
|
|
18
|
+
Requires-Dist: fluidfoam
|
|
19
|
+
Requires-Dist: pandas
|
|
20
|
+
Requires-Dist: gmsh
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# AirfoilRANSSolver
|
|
24
|
+
Repository to run RANS models on 2D airfoils
|
|
File without changes
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import shutil
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import time
|
|
6
|
+
import subprocess
|
|
7
|
+
import signal
|
|
8
|
+
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from fluidfoam.readof import readmesh, readscalar, readvector
|
|
12
|
+
from airfoilgmesher.mesher import meshing_pipeline
|
|
13
|
+
from airfoilgmesher.utils import plot_gmsh_mesh
|
|
14
|
+
|
|
15
|
+
from airfoilranssolver.utils import (
|
|
16
|
+
replace_foam_scalar_entry,
|
|
17
|
+
read_post_processing_file,
|
|
18
|
+
compute_sst_initial_properties_from_nut_ratio,
|
|
19
|
+
compute_compressible_freestream,
|
|
20
|
+
replace_foam_internal_field,
|
|
21
|
+
replace_dictionary_scalar,
|
|
22
|
+
replace_p_outlet_fieldInf,
|
|
23
|
+
patch_control_dict_time_settings,
|
|
24
|
+
estimate_min_edge_from_gmsh_msh,
|
|
25
|
+
compute_acoustic_cfl_delta_t,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def patch_transonic_case(output_path, props):
|
|
29
|
+
output_path = Path(output_path)
|
|
30
|
+
replace_foam_internal_field(output_path / "0" / "U", (props["U_inf"], 0.0, 0.0), is_vector=True)
|
|
31
|
+
replace_foam_internal_field(output_path / "0" / "p", props["p_inf"])
|
|
32
|
+
replace_foam_internal_field(output_path / "0" / "T", props["T_inf"])
|
|
33
|
+
replace_foam_internal_field(output_path / "0" / "k", props["k"])
|
|
34
|
+
replace_foam_internal_field(output_path / "0" / "omega", props["omega"])
|
|
35
|
+
replace_foam_internal_field(output_path / "0" / "nut", props["nut"])
|
|
36
|
+
replace_foam_internal_field(output_path / "0" / "alphat", props["alphat"])
|
|
37
|
+
replace_p_outlet_fieldInf(output_path / "0" / "p", props["p_inf"])
|
|
38
|
+
replace_dictionary_scalar(output_path / "system" / "forceCoeffs", "rhoInf", props["rho_inf"])
|
|
39
|
+
replace_dictionary_scalar(output_path / "system" / "forceCoeffs", "magUInf", props["U_inf"])
|
|
40
|
+
|
|
41
|
+
def launch_pimplefoam(output_path, Re, geometry_parameters, mesh_parameters, splitting_parameters=None, permutation_parameters=None,refinement_parameters=None, n_subdomains=48):
|
|
42
|
+
ref = time.time()
|
|
43
|
+
local_path = os.path.dirname(__file__)
|
|
44
|
+
|
|
45
|
+
nu = 1.0 / Re
|
|
46
|
+
|
|
47
|
+
if not os.path.isdir(output_path):
|
|
48
|
+
os.mkdir(output_path)
|
|
49
|
+
shutil.copytree(f'{local_path}/Templates/Template_pimplefoam', output_path, dirs_exist_ok=True)
|
|
50
|
+
shutil.copytree(f'{output_path}/0_org', f'{output_path}/0', dirs_exist_ok=True)
|
|
51
|
+
|
|
52
|
+
if Re <= 0:
|
|
53
|
+
raise ValueError("reynolds must be positive.")
|
|
54
|
+
|
|
55
|
+
if n_subdomains < 1:
|
|
56
|
+
raise ValueError("n_subdomains must be >= 1.")
|
|
57
|
+
|
|
58
|
+
props = compute_sst_initial_properties_from_nut_ratio(
|
|
59
|
+
Re=Re,
|
|
60
|
+
c=1.0,
|
|
61
|
+
u_inf=1.0,
|
|
62
|
+
rho=1.0,
|
|
63
|
+
I=0.005, # 0.5% turbulence intensity
|
|
64
|
+
nut_over_nu=10.0, # robust initial turbulent-viscosity ratio
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
replace_foam_scalar_entry(
|
|
68
|
+
Path(output_path) / "constant" / "transportProperties",
|
|
69
|
+
"nu",
|
|
70
|
+
props["nu"],
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
replace_foam_internal_field(
|
|
74
|
+
Path(output_path) / "0" / "k",
|
|
75
|
+
props["k"],
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
replace_foam_internal_field(
|
|
79
|
+
Path(output_path) / "0" / "omega",
|
|
80
|
+
props["omega"],
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
replace_foam_internal_field(
|
|
84
|
+
Path(output_path) / "0" / "nut",
|
|
85
|
+
props["nut"],
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
geo_path = Path(output_path) / "airfoil.geo"
|
|
89
|
+
|
|
90
|
+
meshing_pipeline(
|
|
91
|
+
str(geo_path),
|
|
92
|
+
geometry_parameters,
|
|
93
|
+
mesh_parameters,
|
|
94
|
+
splitting_parameters,
|
|
95
|
+
permutation_parameters,
|
|
96
|
+
refinement_parameters,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
msh_path = geo_path.with_suffix(".msh")
|
|
100
|
+
|
|
101
|
+
plot_gmsh_mesh(msh_path, output_path + "mesh.png")
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
env = os.environ.copy()
|
|
105
|
+
env.pop("DISPLAY", None)
|
|
106
|
+
env.pop("XAUTHORITY", None)
|
|
107
|
+
env["NP"] = str(int(n_subdomains))
|
|
108
|
+
result = subprocess.run(
|
|
109
|
+
["bash", "Allrun"],
|
|
110
|
+
cwd=output_path,
|
|
111
|
+
capture_output=True,
|
|
112
|
+
text=True,
|
|
113
|
+
env=env,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
if result.returncode != 0:
|
|
117
|
+
raise RuntimeError(
|
|
118
|
+
f"OpenFOAM failed with return code {result.returncode}\n"
|
|
119
|
+
f"STDOUT:\n{result.stdout[-4000:]}\n"
|
|
120
|
+
f"STDERR:\n{result.stderr[-4000:]}"
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
print(f'Processing time {(time.time()-ref)/60} mins')
|
|
124
|
+
# Read the mean pressure field (pMean) from the time folder
|
|
125
|
+
p_mean = readscalar(output_path, time_name="latestTime", name="pMean", boundary='airfoil')
|
|
126
|
+
tau_W = readvector(output_path, time_name="latestTime", name="wallShearStressMean", boundary='airfoil')
|
|
127
|
+
mag_tau_w = np.sqrt(np.power(tau_W[0,:],2)+np.power(tau_W[1,:],2))
|
|
128
|
+
x,y,_ = readmesh(output_path,boundary='airfoil')
|
|
129
|
+
# Since inco Cp = 2*(p-pinf) since uinf, rhoinf = 1
|
|
130
|
+
Cp = 2*(p_mean-0)
|
|
131
|
+
Cf = mag_tau_w*2
|
|
132
|
+
df_to = pd.DataFrame({'x':x,'y':y,'Cp':Cp,'Cf':Cf})
|
|
133
|
+
df_to.to_csv(f'{output_path}/Cp.csv')
|
|
134
|
+
|
|
135
|
+
filename = f'{output_path}/postProcessing/forces/0/coefficient.dat'
|
|
136
|
+
|
|
137
|
+
df = read_post_processing_file(filename)
|
|
138
|
+
|
|
139
|
+
n_tail = min(2000, df.shape[0])
|
|
140
|
+
Cd = df["Cd"].iloc[-n_tail:].mean()
|
|
141
|
+
Cl = df["Cl"].iloc[-n_tail:].mean()
|
|
142
|
+
|
|
143
|
+
np.savez(output_path + '/coefficients',Cd=Cd, Cl=Cl)
|
|
144
|
+
df.to_csv(output_path + '/outputs_processed.csv')
|
|
145
|
+
|
|
146
|
+
except:
|
|
147
|
+
raise Exception('Error in the computation')
|
|
148
|
+
|
|
149
|
+
def launch_rho_pimplefoam(
|
|
150
|
+
output_path,
|
|
151
|
+
Mach,
|
|
152
|
+
Re,
|
|
153
|
+
geometry_parameters,
|
|
154
|
+
mesh_parameters,
|
|
155
|
+
splitting_parameters=None,
|
|
156
|
+
permutation_parameters=None,
|
|
157
|
+
refinement_parameters=None,
|
|
158
|
+
n_subdomains=48,
|
|
159
|
+
c=1.0,
|
|
160
|
+
T_inf=288.15,
|
|
161
|
+
I=0.005,
|
|
162
|
+
nut_over_nu=10.0,
|
|
163
|
+
target_cfl=0.95,
|
|
164
|
+
n_iterations=100000,
|
|
165
|
+
write_every_iterations=1000,
|
|
166
|
+
dx_percentile=None, # None = absolute minimum edge; 1.0 = 1st percentile
|
|
167
|
+
):
|
|
168
|
+
ref = time.time()
|
|
169
|
+
local_path = os.path.dirname(__file__)
|
|
170
|
+
output_path = Path(output_path)
|
|
171
|
+
|
|
172
|
+
if Re <= 0:
|
|
173
|
+
raise ValueError("Re must be positive.")
|
|
174
|
+
if Mach <= 0:
|
|
175
|
+
raise ValueError("Mach must be positive.")
|
|
176
|
+
if n_subdomains < 1:
|
|
177
|
+
raise ValueError("n_subdomains must be >= 1.")
|
|
178
|
+
if target_cfl <= 0:
|
|
179
|
+
raise ValueError("target_cfl must be positive.")
|
|
180
|
+
if n_iterations < 1:
|
|
181
|
+
raise ValueError("n_iterations must be >= 1.")
|
|
182
|
+
if write_every_iterations < 1:
|
|
183
|
+
raise ValueError("write_every_iterations must be >= 1.")
|
|
184
|
+
|
|
185
|
+
output_path.mkdir(parents=True, exist_ok=True)
|
|
186
|
+
shutil.copytree(Path(local_path) / "Templates" / "Template_rhoPimpleFoam", output_path, dirs_exist_ok=True)
|
|
187
|
+
shutil.copytree(output_path / "0_org", output_path / "0", dirs_exist_ok=True)
|
|
188
|
+
|
|
189
|
+
props = compute_compressible_freestream(
|
|
190
|
+
Mach=Mach,
|
|
191
|
+
Re=Re,
|
|
192
|
+
c=c,
|
|
193
|
+
T_inf=T_inf,
|
|
194
|
+
I=I,
|
|
195
|
+
nut_over_nu=nut_over_nu,
|
|
196
|
+
)
|
|
197
|
+
patch_transonic_case(output_path, props)
|
|
198
|
+
|
|
199
|
+
geo_path = output_path / "airfoil.geo"
|
|
200
|
+
meshing_pipeline(
|
|
201
|
+
str(geo_path),
|
|
202
|
+
geometry_parameters,
|
|
203
|
+
splitting_parameters,
|
|
204
|
+
permutation_parameters,
|
|
205
|
+
mesh_parameters,
|
|
206
|
+
refinement_parameters,
|
|
207
|
+
)
|
|
208
|
+
msh_path = geo_path.with_suffix(".msh")
|
|
209
|
+
|
|
210
|
+
plot_gmsh_mesh(msh_path, output_path / "mesh.png")
|
|
211
|
+
|
|
212
|
+
dx_cfl = estimate_min_edge_from_gmsh_msh(
|
|
213
|
+
msh_path,
|
|
214
|
+
percentile=dx_percentile,
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
delta_t = compute_acoustic_cfl_delta_t(
|
|
218
|
+
props=props,
|
|
219
|
+
dx=dx_cfl,
|
|
220
|
+
cfl=target_cfl,
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
end_time = patch_control_dict_time_settings(
|
|
224
|
+
output_path,
|
|
225
|
+
delta_t=delta_t,
|
|
226
|
+
n_iterations=n_iterations,
|
|
227
|
+
write_every_iterations=write_every_iterations,
|
|
228
|
+
start_from="startTime",
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
env = os.environ.copy()
|
|
232
|
+
env.pop("DISPLAY", None)
|
|
233
|
+
env.pop("XAUTHORITY", None)
|
|
234
|
+
env["NP"] = str(int(n_subdomains))
|
|
235
|
+
|
|
236
|
+
result = subprocess.run(["bash", "Allrun"], cwd=output_path, capture_output=True, text=True, env=env)
|
|
237
|
+
if result.returncode != 0:
|
|
238
|
+
raise RuntimeError(
|
|
239
|
+
f"OpenFOAM failed with return code {result.returncode}\n"
|
|
240
|
+
f"STDOUT:\n{result.stdout[-6000:]}\n"
|
|
241
|
+
f"STDERR:\n{result.stderr[-6000:]}"
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
print(f'Processing time {(time.time()-ref)/60} mins')
|
|
245
|
+
# Read the mean pressure field (pMean) from the time folder
|
|
246
|
+
p_mean = readscalar(output_path, time_name="latestTime", name="pMean", boundary='airfoil')
|
|
247
|
+
tau_W = readvector(output_path, time_name="latestTime", name="wallShearStressMean", boundary='airfoil')
|
|
248
|
+
mag_tau_w = np.sqrt(np.power(tau_W[0,:],2)+np.power(tau_W[1,:],2))
|
|
249
|
+
x,y,_ = readmesh(str(output_path),boundary='airfoil')
|
|
250
|
+
# Since inco Cp = 2*(p-pinf) since uinf, rhoinf = 1
|
|
251
|
+
Cp = 2*(p_mean-0)
|
|
252
|
+
Cf = mag_tau_w*2
|
|
253
|
+
df_to = pd.DataFrame({'x':x,'y':y,'Cp':Cp,'Cf':Cf})
|
|
254
|
+
df_to.to_csv(f'{output_path}/Cp.csv')
|
|
255
|
+
|
|
256
|
+
coeff_file = output_path / "postProcessing" / "forces" / "0" / "coefficient.dat"
|
|
257
|
+
df = read_post_processing_file(str(coeff_file))
|
|
258
|
+
n_tail = min(2000, df.shape[0])
|
|
259
|
+
Cd = df["Cd"].iloc[-n_tail:].mean()
|
|
260
|
+
Cl = df["Cl"].iloc[-n_tail:].mean()
|
|
261
|
+
|
|
262
|
+
np.savez(
|
|
263
|
+
output_path / "coefficients.npz",
|
|
264
|
+
Cd=Cd,
|
|
265
|
+
Cl=Cl,
|
|
266
|
+
delta_t=delta_t,
|
|
267
|
+
dx_cfl=dx_cfl,
|
|
268
|
+
target_cfl=target_cfl,
|
|
269
|
+
n_iterations=n_iterations,
|
|
270
|
+
end_time=end_time,
|
|
271
|
+
**props,
|
|
272
|
+
)
|
|
273
|
+
df.to_csv(output_path / "outputs_processed.csv", index=False)
|