Skip to content

Commit

Permalink
Compatibility to examples in hangar:
Browse files Browse the repository at this point in the history
1. Adding "add_tag_to_patches" to all component types
2. Checking for underlying_surf.tag in Curved, Rotated , Offset and Mirrored patches
  • Loading branch information
amirmit committed Feb 8, 2024
1 parent a622830 commit 3a7090a
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 20 deletions.
26 changes: 11 additions & 15 deletions hypervehicle/components/component.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import enum

import meshio
import numpy as np
from stl import mesh
Expand All @@ -11,6 +9,7 @@
from gdtk.geom.sgrid import StructuredGrid
from hypervehicle.utilities import assign_tags_to_cell
from hypervehicle.utilities import parametricSurfce2stl, parametricSurfce2vtk
from hypervehicle.utilities import PatchTag
from hypervehicle.geometry import (
CurvedPatch,
RotatedPatch,
Expand All @@ -19,13 +18,6 @@
)


class PatchTag(enum.Enum):
FREE_STREAM = 1
INLET = 2
OUTLET = 3
NOZZLE = 4


class AbstractComponent:
componenttype = None

Expand Down Expand Up @@ -272,6 +264,8 @@ def wrapper(key: str, patch):
else:
res_r = res_s = int(stl_resolution / 4) * 4
flip = True if "1" in key else False
else:
res_r = res_s = res

surface = parametricSurfce2stl(
patch, res_r, res_s, flip_faces=flip, **self._clustering
Expand All @@ -281,14 +275,14 @@ def wrapper(key: str, patch):

# Initialise surfaces and pool
self.surfaces = {}
pool = mp.Pool()

# Submit tasks single (debug mode)
# for a in self.patches.items():
# result = wrapper(a[0], a[1])
# self.surfaces[result[0]] = result[1]

# Submit tasks multi
pool = mp.Pool()
for result in pool.starmap(wrapper, self.patches.items()):
self.surfaces[result[0]] = result[1]

Expand Down Expand Up @@ -318,6 +312,8 @@ def wrapper(key: str, patch):
else:
res_r = res_s = int(stl_resolution / 4) * 4
flip = True if "1" in key else False
else:
res_r = res_s = res

vertices, cell_ids = parametricSurfce2vtk(
patch, res_r, res_s, flip_faces=flip, **self._clustering
Expand All @@ -330,14 +326,14 @@ def wrapper(key: str, patch):

# Initialise cells and pool
self.cells = {}
pool = mp.Pool()

# Submit tasks single (debug mode)
# for a in self.patches.items():
# result = wrapper(a[0], a[1])
# self.cells[result[0]] = (result[1], result[2], result[3])

# Submit tasks multi
pool = mp.Pool()
for result in pool.starmap(wrapper, self.patches.items()):
self.cells[result[0]] = (result[1], result[2], result[3])

Expand Down Expand Up @@ -371,10 +367,10 @@ def to_vtk(self, outfile: str = None):
tags = np.empty(0, dtype=int)

# Combine all Cell data
for sss in self.cells.items():
cell_ids = np.concatenate([cell_ids, sss[1][1] + len(vertices)])
vertices = np.concatenate([vertices, sss[1][0]])
tags = np.concatenate([tags, sss[1][2]])
for cell in self.cells.items():
cell_ids = np.concatenate([cell_ids, cell[1][1] + len(vertices)])
vertices = np.concatenate([vertices, cell[1][0]])
tags = np.concatenate([tags, cell[1][2]])

# Generate mesh in VTK format
cell_ids = [("triangle", cell_ids)]
Expand Down
3 changes: 3 additions & 0 deletions hypervehicle/components/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,6 @@ def generate_patches(self):
merged[f"{key}_{ix}"] = patch

self.patches = merged

# Add tags to patches
self.add_tag_to_patches()
3 changes: 3 additions & 0 deletions hypervehicle/components/fin.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,6 @@ def generate_patches(self):

# Save patches
self.patches = fin_patch_dict

# Add tags to patches
self.add_tag_to_patches()
6 changes: 6 additions & 0 deletions hypervehicle/components/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def generate_patches(self):
for face in faces:
self.patches[face] = CubePatch(self.a, self.centre, face)

# Add tags to patches
self.add_tag_to_patches()


class Sphere(Component):
componenttype = SPHERE
Expand Down Expand Up @@ -60,3 +63,6 @@ def generate_patches(self):

for face in faces:
self.patches[face] = SpherePatch(self.r, self.centre, face)

# Add tags to patches
self.add_tag_to_patches()
3 changes: 3 additions & 0 deletions hypervehicle/components/revolved.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ def generate_patches(self):
self.patches[f"revolved_fuse_{i}"] = RevolvedPatch(
self.revolve_line, i * np.pi / 2, (i + 1) * np.pi / 2
)

# Add tags to patches
self.add_tag_to_patches()
3 changes: 3 additions & 0 deletions hypervehicle/components/wing.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ def generate_patches(self):
if "CLOSE_WING" in self.params and self.params["CLOSE_WING"]:
self._close_wing()

# Add tags to patches
self.add_tag_to_patches()

def _create_planform_patches(self):
if self.params["Line_B0TT_TYPE"].lower() == "bezier":
if self.verbosity > 1:
Expand Down
9 changes: 8 additions & 1 deletion hypervehicle/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class OffsetPatchFunction(ParametricSurface):
def __init__(self, underlying_surf, function):
self.underlying_surf = underlying_surf
self.function = function
if hasattr(underlying_surf, "tag"):
self.tag = underlying_surf.tag

def __repr__(self):
str = " + offset function"
Expand Down Expand Up @@ -484,6 +486,8 @@ def __init__(self, underlying_surf, direction=None, fun=None, fun_dash=None):
self.direction = direction
self.fun = fun
self.fun_dash = fun_dash
if hasattr(underlying_surf, "tag"):
self.tag = underlying_surf.tag

def __repr__(self):
return self.underlying_surf.__repr__() + " with added curvature"
Expand Down Expand Up @@ -794,7 +798,8 @@ def __init__(self, underlying_surf, angle, axis="x", point=Vector3(x=0, y=0, z=0
self.angle = angle
self.axis = axis.lower()
self.point = point
self.tag = underlying_surf.tag
if hasattr(underlying_surf, "tag"):
self.tag = underlying_surf.tag

def __repr__(self):
str = f" (rotated by {np.rad2deg(self.angle)} degrees)"
Expand Down Expand Up @@ -828,6 +833,8 @@ class MirroredPatch(ParametricSurface):
def __init__(self, underlying_surf, axis="x"):
self.underlying_surf = underlying_surf
self.axis = axis.lower()
if hasattr(underlying_surf, "tag"):
self.tag = underlying_surf.tag

def __repr__(self):
return self.underlying_surf.__repr__() + f" mirrored along {self.axis}-axis"
Expand Down
18 changes: 14 additions & 4 deletions hypervehicle/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import glob
import numpy as np
import pandas as pd
import enum
from stl import mesh
from tqdm import tqdm
import xml.etree.ElementTree as ET
Expand Down Expand Up @@ -117,8 +118,8 @@ def gen_points(lb, ub, steps, spacing=1.0):
############################################################
### Amir - adding ni != nj capability for tagging sub_patchs

# p00 = j * (ni + 1) + i # bottom left
# p10 = j * (ni + 1) + i + 1 # bottom right
# p00 = j * (nj + 1) + i # bottom left
# p10 = j * (nj + 1) + i + 1 # bottom right
# p01 = (j + 1) * (ni + 1) + i # top left
# p11 = (j + 1) * (ni + 1) + i + 1 # top right
#
Expand Down Expand Up @@ -152,7 +153,7 @@ def gen_points(lb, ub, steps, spacing=1.0):
def parametricSurfce2stl(
parametric_surface,
triangles_per_edge_r: int,
triangles_per_edge_s: int,
triangles_per_edge_s: int = None,
si: float = 1.0,
sj: float = 1.0,
mirror_y=False,
Expand All @@ -176,7 +177,7 @@ def parametricSurfce2stl(
triangles_per_edge_r : int
The resolution for the stl object in r direction.
triangles_per_edge_s : int
triangles_per_edge_s : int, optional
The resolution for the stl object in s direction.
mirror_y : bool, optional
Expand All @@ -188,6 +189,8 @@ def parametricSurfce2stl(
The numpy-stl mesh.
"""

if triangles_per_edge_s == None:
triangles_per_edge_s = triangles_per_edge_r
vertices, cell_ids = create_cells(
parametric_surface,
triangles_per_edge_r,
Expand Down Expand Up @@ -871,3 +874,10 @@ def assign_tags_to_cell(patch, length):
# Creates a tag vector for a given patch
tags = [patch.tag.value] * length
return tags


class PatchTag(enum.Enum):
FREE_STREAM = 1
INLET = 2
OUTLET = 3
NOZZLE = 4

0 comments on commit 3a7090a

Please sign in to comment.