Skip to content

Commit

Permalink
Fix for residual checking for uncoupled FUN3D (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
bburke38 authored Oct 24, 2024
1 parent 7f64922 commit efbc996
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions funtofem/driver/oneway_aero_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def _solve_steady_forward(self, scenario, bodies):
self.solvers.flow.initialize(scenario, bodies)
for step in range(1, scenario.steps + 1):
self.solvers.flow.iterate(scenario, bodies, step=step)
self.solvers.flow.post(scenario, bodies)
self.solvers.flow.post(scenario, bodies, coupled_residuals=False)

# get functions to store the function values into the model
self.solvers.flow.get_functions(scenario, bodies)
Expand All @@ -472,7 +472,7 @@ def _solve_unsteady_forward(self, scenario, bodies):
self.solvers.flow.initialize(scenario, bodies)
for step in range(1, scenario.steps + 1):
self.solvers.flow.iterate(scenario, bodies, step=step)
self.solvers.flow.post(scenario, bodies)
self.solvers.flow.post(scenario, bodies, coupled_residuals=False)

# get functions to store the function values into the model
self.solvers.flow.get_functions(scenario, bodies)
Expand All @@ -498,7 +498,7 @@ def _solve_steady_adjoint(self, scenario, bodies):
for step in range(1, steps + 2):
self.solvers.flow.iterate_adjoint(scenario, bodies, step=step)
self._extract_coordinate_derivatives(scenario, bodies, step=0)
self.solvers.flow.post_adjoint(scenario, bodies)
self.solvers.flow.post_adjoint(scenario, bodies, coupled_residuals=False)

# call get function gradients to store the gradients w.r.t. aero DVs from FUN3D
self.solvers.flow.get_function_gradients(scenario, bodies)
Expand All @@ -520,7 +520,7 @@ def _solve_unsteady_adjoint(self, scenario, bodies):
step = scenario.steps + 1 - rstep
self.solvers.flow.iterate_adjoint(scenario, bodies, step=step)
self._extract_coordinate_derivatives(scenario, bodies, step=step)
self.solvers.flow.post_adjoint(scenario, bodies)
self.solvers.flow.post_adjoint(scenario, bodies, coupled_residuals=False)

# call get function gradients to store the gradients w.r.t. aero DVs from FUN3D
self.solvers.flow.get_function_gradients(scenario, bodies)
Expand Down
18 changes: 12 additions & 6 deletions funtofem/interface/fun3d_14_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def iterate(self, scenario, bodies, step):

return 0

def post(self, scenario, bodies):
def post(self, scenario, bodies, coupled_residuals=True):
"""
Calls FUN3D post to save history files, deallocate memory etc.
Then moves back to the problem's root directory
Expand All @@ -708,13 +708,15 @@ def post(self, scenario, bodies):
The scenario
bodies: :class:`~body.Body`
list of FUNtoFEM bodies.
first_pass: bool
Set to true during instantiation
coupled_residuals: bool
Whether FUN3D is coupled or oneway. If coupled, then the residual
check is performed over the maximum of the flow residuals since
the last coupled iteration.
"""

# report warning if flow residual too large
resid = self.get_forward_residual(
step=self._last_forward_step, all=True, outer=True
step=self._last_forward_step, all=True, outer=coupled_residuals
) # step=scenario.steps
if self.comm.rank == 0:
print(f"Forward residuals = {resid}")
Expand Down Expand Up @@ -1146,7 +1148,7 @@ def iterate_adjoint(self, scenario, bodies, step):
print(f"complete f2f adjoint iteration step {rstep}", flush=True)
return fail

def post_adjoint(self, scenario, bodies):
def post_adjoint(self, scenario, bodies, coupled_residuals=True):
"""
Calls post fo the adjoint solver in FUN3D.
Then moves back to the problem's root directory
Expand All @@ -1157,11 +1159,15 @@ def post_adjoint(self, scenario, bodies):
The scenario
bodies: :class:`~body.Body`
list of FUNtoFEM bodies.
coupled_residuals: bool
Whether FUN3D is coupled or oneway. If coupled, then the residual
check is performed over the maximum of the flow residuals since
the last coupled iteration.
"""

# report warning if flow residual too large
resid = self.get_adjoint_residual(
step=self._last_adjoint_step, outer=True, all=True
step=self._last_adjoint_step, outer=coupled_residuals, all=True
)
if self.comm.rank == 0:
print(f"Adjoint residuals = {resid}")
Expand Down

0 comments on commit efbc996

Please sign in to comment.