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

Redo: Remote subdir and Aero DV Sens File Mode #245

Merged
merged 1 commit into from
Oct 25, 2023
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
16 changes: 10 additions & 6 deletions funtofem/driver/funtofem_shape_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __init__(

if not self.is_remote:
assert solvers.flow is not None
assert solvers.structural is not None
assert solvers.structural is not None or model.structural is not None
self._first_forward = True

# initialize adjoint state variables to zero for writing sens files
Expand Down Expand Up @@ -352,7 +352,7 @@ def solve_forward(self):
# write the funtofem design input file
self.model.write_design_variables_file(
self.comm,
filename=Remote.paths(self.remote.main_dir).design_file,
filename=Remote.paths(self.comm, self.remote.main_dir).design_file,
root=0,
)

Expand All @@ -378,7 +378,7 @@ def solve_forward(self):
# read in the funtofem design input file
self.model.read_design_variables_file(
self.comm,
filename=Remote.paths(self.flow_dir).design_file,
filename=Remote.paths(self.comm, self.flow_dir).design_file,
root=0,
)

Expand All @@ -390,13 +390,14 @@ def solve_forward(self):
if not self.is_paired:
filepath = self.flow_aim.sens_file_path
else:
filepath = Remote.paths(self.flow_dir).aero_sens_file
filepath = Remote.paths(self.comm, self.flow_dir).aero_sens_file

# write the sensitivity file for the FUN3D AIM
self.model.write_sensitivity_file(
comm=self.comm,
filename=filepath,
discipline="aerodynamic",
write_dvs=False,
)

# post analysis for FUN3D mesh morphing
Expand Down Expand Up @@ -434,8 +435,10 @@ def solve_adjoint(self):
if self.is_paired:
write_struct = True
write_aero = True
struct_sensfile = Remote.paths(self.flow_dir).struct_sens_file
aero_sensfile = Remote.paths(self.flow_dir).aero_sens_file
struct_sensfile = Remote.paths(
self.comm, self.flow_dir
).struct_sens_file
aero_sensfile = Remote.paths(self.comm, self.flow_dir).aero_sens_file
else:
if self.struct_shape:
write_struct = True
Expand Down Expand Up @@ -463,6 +466,7 @@ def solve_adjoint(self):
comm=self.comm,
filename=aero_sensfile,
discipline="aerodynamic",
write_dvs=False,
)

if self.struct_shape: # either remote or regular
Expand Down
10 changes: 6 additions & 4 deletions funtofem/driver/oneway_aero_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def solve_forward(self):
# write the funtofem design input file
self.model.write_design_variables_file(
self.comm,
filename=Remote.paths(self.remote.main_dir).design_file,
filename=Remote.paths(self.comm, self.remote.main_dir).design_file,
root=0,
)

Expand All @@ -279,7 +279,7 @@ def solve_forward(self):
if self.is_paired:
self.model.read_design_variables_file(
self.comm,
filename=Remote.paths(self.flow_dir).design_file,
filename=Remote.paths(self.comm, self.flow_dir).design_file,
root=0,
)

Expand All @@ -299,13 +299,14 @@ def solve_forward(self):
if not self.is_paired:
filepath = self.flow_aim.sens_file_path
else:
filepath = Remote.paths(self.flow_dir).aero_sens_file
filepath = Remote.paths(self.comm, self.flow_dir).aero_sens_file

# write the sensitivity file for the FUN3D AIM
self.model.write_sensitivity_file(
comm=self.comm,
filename=filepath,
discipline="aerodynamic",
write_dvs=False,
)

# post analysis for FUN3D mesh morphing
Expand Down Expand Up @@ -359,13 +360,14 @@ def solve_adjoint(self):
if not self.is_paired:
filepath = self.flow_aim.sens_file_path
else:
filepath = Remote.paths(self.flow_dir).aero_sens_file
filepath = Remote.paths(self.comm, self.flow_dir).aero_sens_file

# write the sensitivity file for the FUN3D AIM
self.model.write_sensitivity_file(
comm=self.comm,
filename=filepath,
discipline="aerodynamic",
write_dvs=False,
)

# shape derivative section
Expand Down
2 changes: 1 addition & 1 deletion funtofem/driver/oneway_struct_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def uses_tacs(self) -> bool:
def analysis_sens_file(self):
"""write location of sens file when used in FuntofemShapeDriver for double oneway drivers (analysis version)"""
if self.fun3d_dir is None:
return Remote.paths(self.fun3d_dir).struct_sens_file
return Remote.paths(self.comm, self.fun3d_dir).struct_sens_file
else:
return None

Expand Down
11 changes: 9 additions & 2 deletions funtofem/interface/utils/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ def __init__(
self.struct_name = struct_name

@classmethod
def paths(cls, main_dir, aero_name="fun3d", struct_name="tacs"):
def paths(cls, comm, main_dir, aero_name="fun3d", struct_name="tacs"):
return cls(
analysis_file=None,
main_dir=main_dir,
main_dir=cls.remote_dir(comm, main_dir),
aero_name=aero_name,
struct_name=struct_name,
)

@classmethod
def remote_dir(cls, comm, main_dir):
_remote_dir = os.path.join(main_dir, "remote")
if comm.rank == 0 and not (os.path.exists(_remote_dir)):
os.mkdir(_remote_dir)
return _remote_dir

@classmethod
def fun3d_path(cls, main_dir, filename):
return os.path.join(main_dir, filename)
Expand Down
15 changes: 10 additions & 5 deletions funtofem/model/funtofem_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,9 @@ def read_aero_loads(self, comm, filename, root=0):
# return the loads data
return loads_data

def write_sensitivity_file(self, comm, filename, discipline="aerodynamic", root=0):
def write_sensitivity_file(
self, comm, filename, discipline="aerodynamic", root=0, write_dvs: bool = True
):
"""
Write the sensitivity file.

Expand All @@ -656,6 +658,8 @@ def write_sensitivity_file(self, comm, filename, discipline="aerodynamic", root=
The name of the discipline sensitivity data to be written
root: int
The rank of the processor that will write the file
write_dvs: bool
whether to write the design variables for this discipline
"""

funcs = self.get_functions()
Expand All @@ -674,10 +678,11 @@ def write_sensitivity_file(self, comm, filename, discipline="aerodynamic", root=
if comm.rank == root:
variables = self.get_variables()
discpline_vars = []
for var in variables:
# Write the variables whose analysis_type matches the discipline string.
if discipline == var.analysis_type:
discpline_vars.append(var)
if write_dvs: # flag for registering dvs that will later get written out
for var in variables:
# Write the variables whose analysis_type matches the discipline string.
if discipline == var.analysis_type:
discpline_vars.append(var)

# Write out the number of sets of discpline variables
num_dvs = len(discpline_vars)
Expand Down
Loading