Skip to content

Commit efbc996

Browse files
authored
Fix for residual checking for uncoupled FUN3D (#350)
1 parent 7f64922 commit efbc996

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

funtofem/driver/oneway_aero_driver.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def _solve_steady_forward(self, scenario, bodies):
457457
self.solvers.flow.initialize(scenario, bodies)
458458
for step in range(1, scenario.steps + 1):
459459
self.solvers.flow.iterate(scenario, bodies, step=step)
460-
self.solvers.flow.post(scenario, bodies)
460+
self.solvers.flow.post(scenario, bodies, coupled_residuals=False)
461461

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

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

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

525525
# call get function gradients to store the gradients w.r.t. aero DVs from FUN3D
526526
self.solvers.flow.get_function_gradients(scenario, bodies)

funtofem/interface/fun3d_14_interface.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def iterate(self, scenario, bodies, step):
697697

698698
return 0
699699

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

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

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

11621168
# report warning if flow residual too large
11631169
resid = self.get_adjoint_residual(
1164-
step=self._last_adjoint_step, outer=True, all=True
1170+
step=self._last_adjoint_step, outer=coupled_residuals, all=True
11651171
)
11661172
if self.comm.rank == 0:
11671173
print(f"Adjoint residuals = {resid}")

0 commit comments

Comments
 (0)