Volumetric and Surface#
This example demonstrates how to configure and retrieve volumetric and surface field data from a steady-state simulation using the Flow360 Python API. It details the setup for specifying desired output fields (like primitive variables, Mach number, Cp, Cf) for both the entire volume and specific surfaces. Furthermore, it shows the process of downloading and extracting these results after the simulation completion.
1import os
2import tarfile
3import tempfile
4
5import flow360 as fl
6from flow360.examples import OM6wing
7
8OM6wing.get_files()
9
10project = fl.Project.from_volume_mesh(
11 OM6wing.mesh_filename,
12 name="Volumetric and surface results from Python",
13)
14
15vm = project.volume_mesh
16
17with fl.SI_unit_system:
18 params = fl.SimulationParams(
19 reference_geometry=fl.ReferenceGeometry(
20 area=1.15315084119231,
21 moment_center=[0, 0, 0],
22 moment_length=[1.47602, 0.801672958512342, 1.47602],
23 ),
24 operating_condition=fl.operating_condition_from_mach_reynolds(
25 reynolds=14.6e6, mach=0.84, alpha=3.06 * fl.u.deg, project_length_unit=fl.u.m
26 ),
27 time_stepping=fl.Steady(
28 max_steps=500, CFL=fl.RampCFL(initial=5, final=200, ramp_steps=100)
29 ),
30 models=[
31 fl.Fluid(
32 navier_stokes_solver=fl.NavierStokesSolver(absolute_tolerance=1e-10),
33 turbulence_model_solver=fl.SpalartAllmaras(absolute_tolerance=1e-8),
34 ),
35 fl.Wall(surfaces=vm["1"]),
36 fl.SlipWall(surfaces=vm["2"]),
37 fl.Freestream(surfaces=vm["3"]),
38 ],
39 outputs=[
40 fl.VolumeOutput(output_fields=["primitiveVars", "Mach"]),
41 fl.SurfaceOutput(surfaces=vm["1"], output_fields=["primitiveVars", "Cp", "Cf"]),
42 fl.SliceOutput(
43 output_fields=["Cp"],
44 slices=[
45 fl.Slice(name="x0", normal=[1, 0, 0], origin=[0, 0, 0]),
46 fl.Slice(name="y1", normal=[0, 1, 0], origin=[2, 1, 0]),
47 ],
48 ),
49 ],
50 )
51
52case = project.run_case(params, "Volumetric and surface results case from Python")
53
54
55# wait until the case finishes execution
56case.wait()
57
58results = case.results
59
60with tempfile.TemporaryDirectory() as temp_dir:
61 # download slice and volume output files as tar.gz archives
62 results.slices.download(os.path.join(temp_dir, "slices.tar.gz"), overwrite=True)
63 results.volumes.download(os.path.join(temp_dir, "volumes.tar.gz"), overwrite=True)
64
65 # slices.tar.gz, volumes.tar.gz
66 print(os.listdir(temp_dir))
67
68 # extract slices file
69 file = tarfile.open(os.path.join(temp_dir, "slices.tar.gz"))
70 file.extractall(os.path.join(temp_dir, "slices"))
71 file.close()
72
73 # contains plots for all slices in the specified format (tecplot)
74 # slice_x1.szplt, slice_y1.szplt
75 print(os.listdir(os.path.join(temp_dir, "slices")))
76
77 # extract volumes file
78 file = tarfile.open(os.path.join(temp_dir, "volumes.tar.gz"))
79 file.extractall(os.path.join(temp_dir, "volumes"))
80 file.close()
81
82 # contains volume plots in the specified format (tecplot)
83 # volume.szplt
84 print(os.listdir(os.path.join(temp_dir, "volumes")))
Notes#
The
fl.VolumeOutput
andfl.SurfaceOutput
classes within theoutputs
list are used to specify the desired field data and target entities.Simulation results, including volumetric and surface data files, are accessed through the
case.results
object.The script uses standard Python libraries (
os
,tarfile
,tempfile
) to manage the download and extraction of the output archives.