Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update map_aero_model.py #807

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 57 additions & 7 deletions pyNastran/bdf/mesh_utils/map_aero_model.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
import os
#import os
from typing import cast
from itertools import count
import numpy as np

from pyNastran.utils import PathLike
from pyNastran.bdf.bdf import read_bdf, BDF, SPLINE1, SET1
from pyNastran.bdf.mesh_utils.find_closest_nodes import find_closest_nodes

NEW_CARDS = [
NEW_CARDS_OLD = [
'GRID',
'CORD2R', 'CORD2C', 'CORD2S',
'CORD1R', 'CORD1C', 'CORD1S',
'CAERO1', 'PAERO1', 'SET1', 'SET3',
'CAERO2', 'PAERO2',
'CAERO2', 'PAERO2', 'SPLINE1', 'SPLINE2',
'AERO', 'AEROS',
]
OLD_CARDS = [
'GRID',
'CORD2R', 'CORD2C', 'CORD2S',
'CORD1R', 'CORD1C', 'CORD1S',
#'CAERO1', 'PAERO1', 'SET1', 'SET3',
#'CAERO2', 'PAERO2',
'CAERO1', 'PAERO1', 'SET1', 'SET3',
'CAERO2', 'PAERO2', 'SPLINE1', 'SPLINE2',
'FLUTTER', 'MKAERO1', 'MKAERO2', 'AEFACT',
'FLFACT',
'AERO', 'AEROS',
]
NEW_CARDS = OLD_CARDS

def map_aero_model(model_old: PathLike | BDF,
model_new: PathLike | BDF,
bdf_filename_out: PathLike,
remove_new_aero_cards: bool=False) -> None:
remove_new_aero_cards: bool=False,
include_mapped_grids: bool=False) -> None:
"""
Parameters
----------
Expand All @@ -47,10 +52,19 @@ def map_aero_model(model_old: PathLike | BDF,
if not isinstance(model_new, BDF):
model_new: BDF = read_bdf(model_new, read_cards=NEW_CARDS)

model_old.log.debug('-'*80)
model_old.log.debug('Old Model:')
model_old.log.debug(model_old.get_bdf_stats())
model_old.log.debug('-'*80)
model_new.log.debug('New Model:')
model_new.log.debug(model_new.get_bdf_stats())
model_old.log.debug('-'*80)

spline_nids = get_spline_node_ids(model_old)
xyz_cid0_old = get_xyz_cid0(model_old, spline_nids)

if remove_new_aero_cards:
model_new.log.debug('removing aero cards from new model...')
model_new.caeros = {}
model_new.splines = {}
model_new.paeros = {}
Expand All @@ -63,18 +77,29 @@ def map_aero_model(model_old: PathLike | BDF,
model_new.aesurf = model_old.aesurf
model_new.aesurfs = model_old.aesurfs
model_new.aestats = model_old.aestats
add_methods = model_new._add_methods
#print('npaero =', len(model_new.paeros))
for paero_id, paero in model_old.paeros.items():
paero.uncross_reference()
model_new.paeros[paero_id] = paero
add_methods._add_paero_object(paero)
for caero_id, caero in model_old.caeros.items():
caero.uncross_reference()
model_new.caeros[caero_id] = caero
add_methods._add_caero_object(caero)
for spline_id, spline in model_old.splines.items():
spline.uncross_reference()
model_new.splines[spline_id] = spline
add_methods._add_spline_object(spline)
for set_id, set1 in model_old.sets.items():
set1.uncross_reference()
model_new.sets[set_id] = set1
add_methods._add_set_object(set1)
#print(set1.rstrip())

coord_ids_list = []
for caero in model_new.caeros.values():
coord_ids_list.append(caero.cp)

nids_new = np.unique(list(model_new.nodes))
xyz_cid0_new = get_xyz_cid0(model_new, nids_new)
Expand All @@ -83,24 +108,48 @@ def map_aero_model(model_old: PathLike | BDF,
xyz_cid0_old)
assert len(spline_nids_new) == len(spline_nids)

inid_out = np.searchsorted(nids_new, spline_nids_new)
xyz_cid0_new_out = xyz_cid0_new[inid_out, :]
for inid, spline_id_old, spline_id_new in zip(count(), spline_nids, spline_nids_new):
xyz_oldi = xyz_cid0_old[inid, :]
xyz_newi = xyz_cid0_new_out[inid, :]
print(f'{inid}: {spline_id_old} -> {spline_id_new}')
print(f' {xyz_oldi} -> {xyz_newi}')
#aaa
for spline_id, spline_old in model_old.splines.items():
spline_new = model_new.splines[spline_id]
set1_old_id = spline_old.setg
set1_new_id = spline_new.setg
assert set1_old_id == set1_new_id
set1_old: SET1 = model_old.sets[set1_old_id]
set1_new: SET1 = model_new.sets[set1_new_id]

inids = np.searchsorted(spline_nids, set1_old.ids)
nids_newi = spline_nids_new[inids]
set1_new.ids = nids_newi
set1_new.ids = nids_newi.tolist()

model_new.log.debug('Out Model:')
model_new.log.debug(model_new.get_bdf_stats())
coord_ids = np.unique(coord_ids_list)
with open(bdf_filename_out, 'w') as bdf_file:
model_new._write_aero(bdf_file)
model_new._write_aero_control(bdf_file)
model_new._write_static_aero(bdf_file)
model_new._write_flutter(bdf_file)
model_new._write_gust(bdf_file)
model_new._write_sets(bdf_file)

if include_mapped_grids:
cid = 0
mass = 1.0
for nid in spline_nids_new:
node = model_new.nodes[nid]
bdf_file.write(str(node))
eid = nid
bdf_file.write(f'CONM2, {eid}, {nid}, {cid}, {mass}\n')
for cid in coord_ids:
coord = model_old.coords[cid]
bdf_file.write(str(coord))

#find_closest_nodes(nodes_xyz: NDArray3float, nids: NDArrayNint,
# xyz_compare: NDArray3float,
Expand All @@ -113,6 +162,7 @@ def get_spline_node_ids(model: BDF) -> np.ndarray:
for spline in model.splines.values():
spline = cast(SPLINE1, spline)
set1: SET1 = spline.setg_ref
#print(set1.get_stats())
nids = set1.ids
all_nids_list.extend(nids)
all_nids = np.unique(all_nids_list)
Expand Down
Loading