diff --git a/funtofem/driver/funtofem_shape_driver.py b/funtofem/driver/funtofem_shape_driver.py index e36b2577..16b5cd3b 100644 --- a/funtofem/driver/funtofem_shape_driver.py +++ b/funtofem/driver/funtofem_shape_driver.py @@ -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 @@ -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, ) @@ -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, ) @@ -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 @@ -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 @@ -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 diff --git a/funtofem/driver/oneway_aero_driver.py b/funtofem/driver/oneway_aero_driver.py index af239de0..ace29507 100644 --- a/funtofem/driver/oneway_aero_driver.py +++ b/funtofem/driver/oneway_aero_driver.py @@ -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, ) @@ -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, ) @@ -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 @@ -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 diff --git a/funtofem/driver/oneway_struct_driver.py b/funtofem/driver/oneway_struct_driver.py index 399b0eed..a7d62870 100644 --- a/funtofem/driver/oneway_struct_driver.py +++ b/funtofem/driver/oneway_struct_driver.py @@ -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 diff --git a/funtofem/interface/utils/remote.py b/funtofem/interface/utils/remote.py index 08beb7b7..e6b6c8db 100644 --- a/funtofem/interface/utils/remote.py +++ b/funtofem/interface/utils/remote.py @@ -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) diff --git a/funtofem/model/funtofem_model.py b/funtofem/model/funtofem_model.py index 961066b5..afee76ca 100644 --- a/funtofem/model/funtofem_model.py +++ b/funtofem/model/funtofem_model.py @@ -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. @@ -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() @@ -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)