Skip to content

Commit

Permalink
some cleanup and removal of use of separate yaml readers
Browse files Browse the repository at this point in the history
  • Loading branch information
wr1 committed Oct 11, 2024
1 parent 56c6b11 commit e709c3b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 31 deletions.
9 changes: 4 additions & 5 deletions b3p/add_te_solids.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,11 @@ def get_bondline_material(d):


def add_bondline(bladedict):
wd = os.path.join(
bladedict["general"]["workdir"] + "_portable"
if "_portable" not in bladedict["general"]["workdir"]
else bladedict["general"]["workdir"]
# wd = prefix
prefix = os.path.join(
bladedict["general"]["workdir"], bladedict["general"]["prefix"]
)
vtu = glob.glob(os.path.join(wd, "*joined.vtu"))
vtu = glob.glob(prefix + "*joined.vtu")
bondline_material_id, bondline_width = get_bondline_material(bladedict)
add_bondline_to_vtu(
vtu[0], bondline_width=bondline_width, bondline_material_id=bondline_material_id
Expand Down
11 changes: 9 additions & 2 deletions b3p/anba4_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pyvista as pv
import argparse
import multiprocessing
import os


def conv3d_2d(mesh):
Expand All @@ -20,16 +21,22 @@ def conv3d_2d(mesh):
def vtp2xdmf(vtp):
"""convert a vtp file to xdmf format and translate to 2D"""
assert vtp.endswith(".vtp")
xd = vtp.replace(".vtp", ".xdmf")
if os.path.exists(xd):
print(f"\t** ANBA mesh {xd} already exists - skipping")
return

mesh = pv.read(vtp)
tri = mesh.triangulate() # fenics doesn't do mixed element types
tri.points[:, 2] = 0
xd = vtp.replace(".vtp", ".xdmf")
pv.save_meshio(xd, tri, data_format="XML")
conv3d_2d(xd)
print(f"converted {vtp} to {xd}")
print(f"\t**converted {vtp} to {xd}")


def anba4_prep(section_meshes):
"""convert a list of section meshes to xdmf format"""
print("** converting section meshes to XDMF")
p = multiprocessing.Pool()
p.map(vtp2xdmf, section_meshes)
p.close()
Expand Down
23 changes: 14 additions & 9 deletions b3p/b3p_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,35 @@
)
import os
import pickle
import numpy as np

# import numpy as np
import shutil
import glob
import multiprocessing
from ruamel import yaml
import os

# from ruamel import yaml


class cli:
"""Fire command line interface for b3p"""

def __init__(self, yml):
self.dct = yml_portable.yaml_make_portable(yml, True)
self.dct = yml_portable.yaml_make_portable(yml)
self.plybookname = "__plybook.pck"
self.prefix = os.path.join(
self.dct["general"]["workdir"], self.dct["general"]["prefix"]
self.dct["general"]["workdir"],
self.dct["general"]["prefix"],
)

def clean(self):
"""Clean up workdir"""
if os.path.isdir(self.dct["general"]["workdir"]):
shutil.rmtree(self.dct["general"]["workdir"])
print(f"** Removing workdir {self.dct['general']['workdir']}")
wd = self.dct["general"]["workdir"]
if os.path.isdir(wd):
shutil.rmtree(wd)
print(f"** Removing workdir {wd}")
else:
print(f"** Workdir {self.dct['general']['workdir']} does not exist")
print(f"** Workdir {wd} does not exist")
return self

def __str__(self):
Expand Down Expand Up @@ -136,7 +141,7 @@ def ccxprep(
if not bondline or available_meshes == []:
available_meshes = glob.glob(f"{self.prefix}*_joined.vtu")

print("available_meshes", available_meshes)
# print("\tavailable_meshes", available_meshes)

output_files = mesh2ccx.mesh2ccx(
available_meshes[-1],
Expand Down
11 changes: 6 additions & 5 deletions b3p/build_blade_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np


def build_blade_geometry(config, verbose=False, xfoil=True):
def build_blade_geometry(config, xfoil=True):
"""
Perform blade 3d model generation based on b3p dictionary.
Expand All @@ -28,19 +28,20 @@ def build_blade_geometry(config, verbose=False, xfoil=True):
chordwise_sampling=b3p.loft_utils.optspace(config["planform"]["npchord"]),
np_spanwise=config["planform"]["npspan"],
)
wd = config["general"]["workdir"]

wdp = os.path.join(config["general"]["workdir"], config["general"]["prefix"])
wdp = os.path.join(wd, config["general"]["prefix"])

if not os.path.isdir(config["general"]["workdir"]):
os.makedirs(config["general"]["workdir"])
if not os.path.isdir(wd):
os.makedirs(wd)

blade.mesh(f"{wdp}.vtp")
blade.dump(f"{wdp}.pck", z_rotation=0)
blade.export_variables(f"{wdp}.var")
if xfoil:
blade.export_xfoil(
prefix=os.path.join(
config["general"]["workdir"],
wd,
"airfoil_out",
f'xs_{config["general"]["prefix"]}',
)
Expand Down
2 changes: 0 additions & 2 deletions b3p/build_plybook.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ def lamplan2plies(blade, outputfile="__plybook.pck"):

datums = blade["laminates"]["datums"] if "datums" in blade["laminates"] else {}

# print(datums)

allstacks = []

# use a multiple of lamplan length as radius grid to interpolate geometric variables to
Expand Down
4 changes: 2 additions & 2 deletions b3p/drape_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_slab_cover(inp):
# create a boolean array with n_cell rows and n_ply columns presenting true where the ply covers the cell in the chordwise direction
name, cover, numbering, rr, stack, df = inp

print(name, cover)
# print(name, cover)
one = np.ones_like(rr)

names = ["ply_%.8i_%s" % (i, name) for i in numbering]
Expand All @@ -45,7 +45,7 @@ def get_slab_cover(inp):
cov = np.ones_like(df.radius, dtype=bool)
for i in cover:
start, end, __ = cover[i]
print(i, cover[i])
# print(i, cover[i])
over_start = np.interp(df.radius, rr, one * start) <= df[i].values
under_end = np.interp(df.radius, rr, one * end) >= df[i].values
cov = cov & over_start & under_end
Expand Down
14 changes: 10 additions & 4 deletions b3p/mesh_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ def cut_blade(r, vtu, if_bondline=True, rotz=0, var=None, is2d=False, verbose=Fa
var = {}
print("# creating cross section mesh from %s at r=%.3f" % (vtu, r))
workdir = os.path.dirname(vtu)

output_file = os.path.join(workdir, "msec_%i.vtp" % (1e3 * r))

if os.path.exists(output_file):
print(f"\t** 2d mesh {output_file} already exists - skipping ")
return output_file

# read in the mesh
rd = pv.read(vtu)

Expand Down Expand Up @@ -592,17 +599,16 @@ def cut_blade(r, vtu, if_bondline=True, rotz=0, var=None, is2d=False, verbose=Fa

align_normals(out)

of = os.path.join(workdir, "msec_%i.vtp" % (1e3 * r))
wrt = vtk.vtkXMLPolyDataWriter()
wrt.SetInputData(out)
wrt.SetFileName(of)
wrt.SetFileName(output_file)
wrt.Write()
print(f"# written vtk to {of}")
print(f"# written vtk to {output_file}")
table_out.to_csv(
os.path.join(workdir, "section_location_%i.csv" % (1e3 * r)), index=False
)

return of
return output_file


def cut_blade_parallel(
Expand Down
5 changes: 3 additions & 2 deletions b3p/yml_portable.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def load_airfoils(afs, prefix=""):
return dct


def yaml_make_portable(yaml_file, safe=False):
def yaml_make_portable(yaml_file):
"""Import a yaml file and all linked files, and write to a _portable version of itself.
:param yaml_file: path to yaml file
Expand All @@ -50,7 +50,8 @@ def yaml_make_portable(yaml_file, safe=False):
print(f"** Loading yaml file {yaml_file} and loading linked files")
prefix = os.path.dirname(yaml_file)

yaml = YAML() # typ="safe")
yaml = YAML()
# typ="safe")
# typ="safe") # YAML(typ="safe") if safe else YAML(typ="rt")
d = yaml.load(open(yaml_file, "r"))
# yaml.load(open(yaml_file, "r"), Loader=yaml.CLoader)
Expand Down

0 comments on commit e709c3b

Please sign in to comment.