Skip to content

Commit

Permalink
Bug Fixes for F2F-Shape-Driver Application Case (#242)
Browse files Browse the repository at this point in the history
* fix typo in test bdf utils callbacks

* fix f2f shape design vars file and struct pre analysis

* check whether output file exists before removal

* fix remote default names
  • Loading branch information
sean-engelstad authored Oct 19, 2023
1 parent 07f31c3 commit 63dbbd5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
28 changes: 25 additions & 3 deletions funtofem/driver/funtofem_shape_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class methods FuntofemShapeDriver.remesh and FuntofemShapeDriver.analysis which
import importlib.util, os, shutil, numpy as np
from funtofem.optimization.optimization_manager import OptimizationManager
from funtofem.interface import Remote
import time

caps_loader = importlib.util.find_spec("pyCAPS")
fun3d_loader = importlib.util.find_spec("fun3d")
Expand Down Expand Up @@ -286,12 +287,19 @@ def solve_forward(self):
Create new aero/struct geometries and run fully-coupled forward analysis.
"""
if self.aero_shape:
start_time_aero = time.time()
if self.comm.rank == 0:
print("F2F - building aero mesh..", flush=True)
if self.flow_aim.mesh_morph:
self.flow_aim.set_design_sensitivity(False, include_file=False)

# run the pre analysis to generate a new mesh
self.flow_aim.pre_analysis()

dt_aero = time.time() - start_time_aero
if self.comm.rank == 0:
print(f"F2F - built aero mesh in {dt_aero:.5e} sec", flush=True)

# for FUN3D mesh morphing now initialize body nodes
if not (self.is_paired) and self._first_forward:
if self.uses_fun3d:
Expand All @@ -306,13 +314,17 @@ def solve_forward(self):

if self.struct_shape:
# self._update_struct_design()
start_time_struct = time.time()
if self.comm.rank == 0:
print("F2F - Building struct mesh")
input_dict = {var.name: var.value for var in self.model.get_variables()}
self.model.structural.update_design(input_dict)
self.struct_aim.setup_aim()
self.struct_aim.pre_analysis()

# build the new structure geometry
self.struct_aim.pre_analysis()
dt_struct = time.time() - start_time_struct
if self.comm.rank == 0:
print(f"F2F - Built struct mesh in {dt_struct:.5e} sec", flush=True)

# move the bdf and dat file to the fun3d_dir
if self.is_remote:
Expand All @@ -335,6 +347,8 @@ def solve_forward(self):
self._update_struct_transfer()

if self.is_remote:
if self.comm.rank == 0:
print("F2F - writing design variables file", flush=True)
# write the funtofem design input file
self.model.write_design_variables_file(
self.comm,
Expand All @@ -343,13 +357,21 @@ def solve_forward(self):
)

# clear the output file
if self.root_proc:
if self.root_proc and os.path.exists(self.remote.output_file):
os.remove(self.remote.output_file)

start_time = time.time()
if self.comm.rank == 0:
print(f"Calling remote analysis..", flush=True)
# system call funtofem forward + adjoint analysis
os.system(
f"mpiexec_mpt -n {self.remote.nprocs} python {self.remote.analysis_file} 2>&1 > {self.remote.output_file}"
)
elapsed_time = time.time() - start_time
if self.comm.rank == 0:
print(
f"Done with remote analysis in {elapsed_time:2.5e} sec", flush=True
)

else:
if self.is_paired:
Expand Down
2 changes: 1 addition & 1 deletion funtofem/interface/utils/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
self.struct_name = struct_name

@classmethod
def paths(cls, main_dir, aero_name="fun3d", struct_name="struct"):
def paths(cls, main_dir, aero_name="fun3d", struct_name="tacs"):
return cls(
analysis_file=None,
main_dir=main_dir,
Expand Down
6 changes: 3 additions & 3 deletions funtofem/model/funtofem_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,8 @@ def read_design_variables_file(self, comm, filename, root=0):

# update the variable values on each processor
for var in self.get_variables():
if var.name in variables_dict:
var.value = variables_dict[var.name]
if var.full_name in variables_dict:
var.value = variables_dict[var.full_name]

return

Expand Down Expand Up @@ -812,7 +812,7 @@ def write_design_variables_file(self, comm, filename, root=0):
# write each variable from that discipline
for var in variables[discipline]:
# only real numbers written to this file
hdl.write(f"\tvar {var.name} {var.value.real}\n")
hdl.write(f"\tvar {var.full_name} {var.value.real}\n")

hdl.close()

Expand Down

0 comments on commit 63dbbd5

Please sign in to comment.