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

Add external mesh morph flag to Fun3dInterface #290

Merged
Merged
Show file tree
Hide file tree
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
35 changes: 26 additions & 9 deletions funtofem/interface/fun3d_14_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(
auto_coords=True,
coord_test_override=False,
debug=False,
external_mesh_morph=False,
forward_tolerance=1e-6,
adjoint_tolerance=1e-6,
):
Expand Down Expand Up @@ -81,6 +82,8 @@ def __init__(
override the aero displacements in F2F to add fixed displacements for mesh morphing coordinate derivative tests
debug: bool
whether to print debug statements or not such as the real/imag norms of state vectors in FUN3D
external_mesh_morph: bool
override for AFRL to set mesh morph through constructor instead of caps2fun
"""

self.comm = comm
Expand Down Expand Up @@ -129,6 +132,8 @@ def __init__(
if self.comm.rank != 0:
self._debug = False

self.external_mesh_morph = external_mesh_morph

# Initialize the nodes associated with the bodies
self.auto_coords = auto_coords
if auto_coords:
Expand Down Expand Up @@ -269,6 +274,8 @@ def initialize(self, scenario, bodies):
# turn on mesh morphing with Fun3dAim if the Fun3dModel has it on
if self.model.flow is not None:
self.fun3d_flow.set_mesh_morph(self.model.flow.mesh_morph)
elif self.external_mesh_morph:
self.fun3d_flow.set_mesh_morph(True)

bcont = self.fun3d_flow.initialize_solution()
if bcont == 0:
Expand All @@ -277,18 +284,24 @@ def initialize(self, scenario, bodies):
return 1

# update FUNtoFEM xA0 coords from FUN3D if doing mesh morphing
_update_aero_coords = False
if self.model.flow is not None:
if self.model.flow.mesh_morph:
for ibody, body in enumerate(bodies, 1):
aero_X = body.get_aero_nodes()
aero_nnodes = body.get_num_aero_nodes()
_update_aero_coords = self.model.flow.mesh_morph
else:
_update_aero_coords = self.external_mesh_morph

if aero_nnodes > 0:
x, y, z = interface.extract_surface(aero_nnodes, body=ibody)
# update the aero coordinates in FUNtoFEM after mesh morphing
if _update_aero_coords:
for ibody, body in enumerate(bodies, 1):
aero_X = body.get_aero_nodes()
aero_nnodes = body.get_num_aero_nodes()

if aero_nnodes > 0:
x, y, z = interface.extract_surface(aero_nnodes, body=ibody)

aero_X[0::3] = x[:]
aero_X[1::3] = y[:]
aero_X[2::3] = z[:]
aero_X[0::3] = x[:]
aero_X[1::3] = y[:]
aero_X[2::3] = z[:]

return 0

Expand Down Expand Up @@ -750,6 +763,8 @@ def initialize_adjoint(self, scenario, bodies):
# turn on mesh morphing with Fun3dAim if the Fun3dModel has it on
if self.model.flow is not None:
self.fun3d_adjoint.set_mesh_morph(self.model.flow.mesh_morph)
elif self.external_mesh_morph:
self.fun3d_adjoint.set_mesh_morph(True)

# Deform the aero mesh before finishing FUN3D initialization
for ibody, body in enumerate(bodies, 1):
Expand Down Expand Up @@ -804,6 +819,8 @@ def initialize_adjoint(self, scenario, bodies):
# turn on mesh morphing with Fun3dAim if the Fun3dModel has it on
if self.model.flow is not None:
self.fun3d_adjoint.set_mesh_morph(self.model.flow.mesh_morph)
elif self.external_mesh_morph:
self.fun3d_adjoint.set_mesh_morph(True)

self.fun3d_adjoint.initialize_solution()

Expand Down
37 changes: 28 additions & 9 deletions funtofem/interface/fun3d_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(
auto_coords=True,
coord_test_override=False,
debug=False,
external_mesh_morph=False,
forward_tolerance=1e-6,
adjoint_tolerance=1e-6,
):
Expand Down Expand Up @@ -81,6 +82,8 @@ def __init__(
override the aero displacements in F2F to add fixed displacements for mesh morphing coordinate derivative tests
debug: bool
whether to print debug statements or not such as the real/imag norms of state vectors in FUN3D
external_mesh_morph: bool
override for AFRL to set mesh morph through constructor instead of caps2fun
"""

self.comm = comm
Expand Down Expand Up @@ -125,6 +128,8 @@ def __init__(
if self.comm.rank != 0:
self._debug = False

self.external_mesh_morph = external_mesh_morph

# Initialize the nodes associated with the bodies
self.auto_coords = auto_coords
if auto_coords:
Expand Down Expand Up @@ -220,6 +225,7 @@ def initialize(self, scenario, bodies):

# copy the *_body1.dat file for fun3d mesh morphing from the Fun3dAim folder to the scenario folder
# if mesh morphing is online
# if external_mesh_morph is True, the user is responsible for moving the mesh morphing data files to each scenario folder
if self.model.flow is not None:
morph_flag = self.model.flow.mesh_morph
if morph_flag and self.comm.rank == 0:
Expand Down Expand Up @@ -262,6 +268,8 @@ def initialize(self, scenario, bodies):
# turn on mesh morphing with Fun3dAim if the Fun3dModel has it on
if self.model.flow is not None:
self.fun3d_flow.set_mesh_morph(self.model.flow.mesh_morph)
elif self.external_mesh_morph:
self.fun3d_flow.set_mesh_morph(True)

bcont = self.fun3d_flow.initialize_solution()
if bcont == 0:
Expand All @@ -270,18 +278,24 @@ def initialize(self, scenario, bodies):
return 1

# update FUNtoFEM xA0 coords from FUN3D if doing mesh morphing
_update_aero_coords = False
if self.model.flow is not None:
if self.model.flow.mesh_morph:
for ibody, body in enumerate(bodies, 1):
aero_X = body.get_aero_nodes()
aero_nnodes = body.get_num_aero_nodes()
_update_aero_coords = self.model.flow.mesh_morph
else:
_update_aero_coords = self.external_mesh_morph

if aero_nnodes > 0:
x, y, z = interface.extract_surface(aero_nnodes, body=ibody)
# update the aero coordinates in FUNtoFEM after mesh morphing
if _update_aero_coords:
for ibody, body in enumerate(bodies, 1):
aero_X = body.get_aero_nodes()
aero_nnodes = body.get_num_aero_nodes()

if aero_nnodes > 0:
x, y, z = interface.extract_surface(aero_nnodes, body=ibody)

aero_X[0::3] = x[:]
aero_X[1::3] = y[:]
aero_X[2::3] = z[:]
aero_X[0::3] = x[:]
aero_X[1::3] = y[:]
aero_X[2::3] = z[:]

return 0

Expand Down Expand Up @@ -720,6 +734,7 @@ def initialize_adjoint(self, scenario, bodies):

# copy the *_body1.dat file for fun3d mesh morphing from the Fun3dAim folder to the scenario folder
# if mesh morphing is online
# if self.external_mesh_morph is True, the user needs to move the mesh morph .dat files to the appropriate folder
if self.model.flow is not None:
morph_flag = self.model.flow.mesh_morph
if morph_flag and self.comm.rank == 0:
Expand Down Expand Up @@ -759,6 +774,8 @@ def initialize_adjoint(self, scenario, bodies):
# turn on mesh morphing with Fun3dAim if the Fun3dModel has it on
if self.model.flow is not None:
self.fun3d_adjoint.set_mesh_morph(self.model.flow.mesh_morph)
elif self.external_mesh_morph:
self.fun3d_adjoint.set_mesh_morph(True)

# Deform the aero mesh before finishing FUN3D initialization
for ibody, body in enumerate(bodies, 1):
Expand Down Expand Up @@ -806,6 +823,8 @@ def initialize_adjoint(self, scenario, bodies):
# turn on mesh morphing with Fun3dAim if the Fun3dModel has it on
if self.model.flow is not None:
self.fun3d_adjoint.set_mesh_morph(self.model.flow.mesh_morph)
elif self.external_mesh_morph:
self.fun3d_adjoint.set_mesh_morph(True)

self.fun3d_adjoint.initialize_solution()

Expand Down
Loading