From d81cc9968a9e4e76de391345feae8b09b9f2cfec Mon Sep 17 00:00:00 2001 From: sean-engelstad Date: Tue, 31 Oct 2023 17:30:45 -0400 Subject: [PATCH] allow full fun3d residuals list to be extracted --- funtofem/driver/oneway_aero_driver.py | 13 ++++++++ funtofem/interface/fun3d_interface.py | 43 +++++++++++++++++---------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/funtofem/driver/oneway_aero_driver.py b/funtofem/driver/oneway_aero_driver.py index 926f7c56..b40177e4 100644 --- a/funtofem/driver/oneway_aero_driver.py +++ b/funtofem/driver/oneway_aero_driver.py @@ -532,6 +532,19 @@ def _setup_grid_filepaths(self): grid_filepaths.append(filepath) # set the grid filepaths into the fun3d aim self.flow_aim.grid_filepaths = grid_filepaths + + # also setup the mapbc files + mapbc_filepaths = [] + for scenario in self.model.scenarios: + filepath = os.path.join( + fun3d_dir, + scenario.name, + "Flow", + f"{scenario.fun3d_project_name}.mapbc", + ) + mapbc_filepaths.append(filepath) + # set the mapbc filepaths into the fun3d aim + self.flow_aim.mapbc_filepaths = mapbc_filepaths return @property diff --git a/funtofem/interface/fun3d_interface.py b/funtofem/interface/fun3d_interface.py index 4143ecc8..84b7444b 100644 --- a/funtofem/interface/fun3d_interface.py +++ b/funtofem/interface/fun3d_interface.py @@ -629,13 +629,15 @@ def post(self, scenario, bodies): """ # report warning if flow residual too large - resid = self.get_forward_residual(step=scenario.steps) # step=scenario.steps + resid = self.get_forward_residual(step=scenario.steps, all=True) # step=scenario.steps + if self.comm.rank == 0: + print(f"Forward residuals = {resid}") self._forward_done = True self._forward_resid = resid - if abs(resid.real) > 1.0e-10: + if abs(np.linalg.norm(resid).real) > self.forward_tolerance: if self.comm.rank == 0: print( - f"Warning: fun3d forward flow residual = {resid} > 1.0e-10, is rather large..." + f"\tWarning: fun3d forward flow residual = {resid} > {self.forward_tolerance:.2e}, is rather large..." ) self.fun3d_flow.post() @@ -964,13 +966,15 @@ def post_adjoint(self, scenario, bodies): """ # report warning if flow residual too large - resid = self.get_adjoint_residual(step=scenario.steps) + resid = self.get_adjoint_residual(step=scenario.steps, all=True) + if self.comm.rank == 0: + print(f"Adjoint residuals = {resid}") self._adjoint_done = True self._adjoint_resid = resid - if abs(resid.real) > 1.0e-10: + if abs(np.linalg.norm(resid).real) > self.adjoint_tolerance: if self.comm.rank == 0: print( - f"Warning fun3d adjoint residual = {resid} > 1.0e-10, is rather large..." + f"\tWarning fun3d adjoint residual = {resid} > {self.adjoint_tolerance:.2e}, is rather large..." ) # solve the initial condition adjoint @@ -978,7 +982,7 @@ def post_adjoint(self, scenario, bodies): os.chdir(self.root_dir) return - def get_forward_residual(self, step=0): + def get_forward_residual(self, step=0, all=False): """ Returns L2 norm of scalar residual norms for each flow state L2norm([R1,...,R6]) @@ -987,16 +991,20 @@ def get_forward_residual(self, step=0): ---------- step: int the time step number + all: bool + whether to return a list of all residuals or just a scalar """ if not self._forward_done: residuals = self.fun3d_flow.get_flow_rms_residual(step) - if self.comm.rank == 0: - print(f"Forward residuals = {residuals}") - return np.linalg.norm(residuals) else: - return self._forward_resid + residuals = self._forward_resid + + if all: + return residuals + else: + return np.linalg.norm(residuals) - def get_adjoint_residual(self, step=0): + def get_adjoint_residual(self, step=0, all=False): """ Returns L2 norm of list of scalar adjoint residuals L2norm([R1,...,R6]) @@ -1004,14 +1012,19 @@ def get_adjoint_residual(self, step=0): ---------- step: int the time step number + all: bool + whether to return a list of all residuals or a scalar """ if not self._adjoint_done: residuals = self.fun3d_adjoint.get_flow_rms_residual(step) - if self.comm.rank == 0: - print(f"Adjoint residuals = {residuals}") return np.linalg.norm(residuals) else: - return self._adjoint_resid + residuals = self._adjoint_resid + + if all: + return residuals + else: + return np.linalg.norm(residuals) def set_states(self, scenario, bodies, step): """