Generate loft from a parameter config file#
Load configs
[1]:
from cfdmod.use_cases.loft.parameters import LoftCaseConfig
import pathlib
cfg_file = pathlib.Path("./fixtures/tests/loft/loft_params.yaml")
cfg = LoftCaseConfig.from_file(cfg_file)
cfg
[1]:
LoftCaseConfig(reference_direction=[-1, 0, 0], cases={'default': LoftParams(loft_length=1200.0, mesh_element_size=25.0, wind_source_angles=[0.0, 45.0, 135.0, 90.0], upwind_elevation=780.0), 'longer_loft': LoftParams(loft_length=1500.0, mesh_element_size=25.0, wind_source_angles=[180.0, 270.0, 225.0], upwind_elevation=780.0)})
Load surface mesh
[2]:
from cfdmod.api.geometry.STL import read_stl
mesh_path = pathlib.Path("./fixtures/tests/loft/terrain.stl")
triangles, normals = read_stl(mesh_path)
triangles, normals
[2]:
(array([[[ 622.19226 , 7.6139417, 774.35693 ],
[ 620.78424 , 7.970398 , 773.9987 ],
[ 614.316 , 4.6423063, 773.50385 ]],
[[ 645.47797 , -15.484023 , 767.435 ],
[ 643.78357 , -16.447126 , 766.5187 ],
[ 645.73376 , -16.655039 , 766.02747 ]],
[[ 642.06805 , -12.476355 , 767.9776 ],
[ 632.3187 , -4.6019497, 770.26587 ],
[ 642.0133 , -14.797253 , 767.05884 ]],
...,
[[ 605.6187 , -651.87646 , 757.34576 ],
[ 615.6246 , -675.4446 , 757.1043 ],
[ 627.32086 , -659.3153 , 760.9082 ]],
[[ 605.6187 , -651.87646 , 757.34576 ],
[ 591.1564 , -671.6936 , 755.1523 ],
[ 615.6246 , -675.4446 , 757.1043 ]],
[[ 610.7315 , 9.4921 , 780.0834 ],
[ 620.91907 , 9.256538 , 790.40234 ],
[ 585.0646 , 9.5950575, 791.08875 ]]], dtype=float32),
array([[-0.18731488, 0.22175997, 0.95694077],
[ 0.08185904, -0.7587941 , 0.6461661 ],
[-0.07739674, -0.36539087, 0.92763096],
...,
[-0.19173947, -0.09141431, 0.9771793 ],
[-0.08658855, -0.04695639, 0.995137 ],
[-0.00969394, -0.9998652 , -0.01325442]], dtype=float32))
Generate loft
[4]:
from cfdmod.use_cases.loft.functions import (
generate_loft_surface,
apply_remeshing,
rotate_vector_around_z,
)
import numpy as np
from cfdmod.api.geometry.STL import export_stl
from cfdmod.logger import logger
output_path = pathlib.Path("./output/loft")
for case_lbl, loft_params in cfg.cases.items():
logger.info(f"Generating loft for {case_lbl}/{loft_params.wind_source_angle}...")
wind_source_direction = rotate_vector_around_z(
np.array(cfg.reference_direction, dtype=np.float32), loft_params.wind_source_angle
)
loft_directions = {
"upwind": -np.array(wind_source_direction),
"downwind": np.array(wind_source_direction),
}
for side, direction in loft_directions.items():
loft_tri, loft_normals = generate_loft_surface(
triangle_vertices=triangles,
projection_diretion=direction,
loft_length=loft_params.loft_length,
loft_z_pos=loft_params.upwind_elevation,
)
export_stl(
output_path / f"{case_lbl}" / f"{loft_params.wind_source_angle}" / f"{side}_loft.stl",
loft_tri,
loft_normals,
)
apply_remeshing(
element_size=loft_params.mesh_element_size,
mesh_path=output_path
/ f"{case_lbl}"
/ f"{loft_params.wind_source_angle}"
/ f"{side}_loft.stl",
output_path=output_path
/ f"{case_lbl}"
/ f"{loft_params.wind_source_angle}"
/ f"{side}_loft_remeshed.stl",
)
export_stl(
output_path / f"{case_lbl}" / f"{loft_params.wind_source_angle}" / "terrain.stl",
triangles,
normals,
)
apply_remeshing(
element_size=loft_params.mesh_element_size,
mesh_path=output_path / f"{case_lbl}" / f"{loft_params.wind_source_angle}" / "terrain.stl",
output_path=output_path
/ f"{case_lbl}"
/ f"{loft_params.wind_source_angle}"
/ "terrain_remeshed.stl",
)
[2024-11-14 13:06:27,872] [INFO] - cfdmod - Generating loft for default/0.0... (1613004650.py:13)
[2024-11-14 13:06:34,808] [INFO] - cfdmod - Generating loft for longer_loft/270.0... (1613004650.py:13)
[2024-11-14 13:06:42,053] [INFO] - cfdmod - Generating loft for inherit_loft/0.0... (1613004650.py:13)
[2024-11-14 13:06:50,913] [INFO] - cfdmod - Generating loft for inherit_element_size/270.0... (1613004650.py:13)