Skip to content

Commit

Permalink
Added new tests for two consecutive adjoint runs (#362)
Browse files Browse the repository at this point in the history
* Added tests for running adjoints back to back

* clean-up formatting

* Double adjoint test now tests against single adjoint results. Black and Flake8 fixes.

* Reran tests on docker

* Remove extra files

* Black formatting fixes

* Fixed reference for 1 test

* Update remaining references

* Black formatting fixes

---------

Co-authored-by: Andrew Lamkin <[email protected]>
  • Loading branch information
sabakhshi and lamkina authored Nov 13, 2024
1 parent 4be4ccb commit cd21478
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Adjoint States": 0.0,
"Eval Functions Sens:": {
"mdo_tutorial_cd": {
"P_mdo_tutorial": 6.776263578034403e-21,
Expand Down
1 change: 1 addition & 0 deletions tests/reg_tests/refs/adjoint_laminar_tut_wing.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Adjoint States": 0.0,
"Eval Functions Sens:": {
"mdo_tutorial_cd": {
"P_mdo_tutorial": 1.5227077123299861e-05,
Expand Down
1 change: 1 addition & 0 deletions tests/reg_tests/refs/adjoint_rans_rotating.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Adjoint States": 0.0,
"Eval Functions Sens:": {
"mdo_tutorial_fy": {
"T_mdo_tutorial": 0.0009508864923091359,
Expand Down
1 change: 1 addition & 0 deletions tests/reg_tests/refs/adjoint_rans_tut_wing.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Adjoint States": 0.0,
"Eval Functions Sens:": {
"mdo_tutorial_cavitation": {
"P_mdo_tutorial": -3.3530531445605923e-10,
Expand Down
21 changes: 21 additions & 0 deletions tests/reg_tests/reg_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ def assert_adjoint_sens_allclose(handler, CFDSolver, ap, evalFuncs=None, **kwarg
handler.root_add_dict("Eval Functions Sens:", funcsSens, rtol=rtol, atol=atol)


def assert_adjoint2_sens_allclose(handler, CFDSolver, ap, evalFuncs=None, **kwargs):
rtol, atol = getTol(**kwargs)
funcsSens = {}
CFDSolver.evalFunctionsSens(ap, funcsSens, evalFuncs=None)
CFDSolver.evalFunctionsSens(ap, funcsSens, evalFuncs=None)
handler.root_print("Eval Functions Sens:")
handler.root_add_dict("Eval Functions Sens:", funcsSens, rtol=rtol, atol=atol)


def assert_adjoint_states_allclose(handler, CFDSolver, ap, evalFuncs=None, **kwargs):
rtol, atol = getTol(**kwargs)
funcsSens = {}
CFDSolver.evalFunctionsSens(ap, funcsSens, evalFuncs=None)
states1 = CFDSolver.getStates()
CFDSolver.evalFunctionsSens(ap, funcsSens, evalFuncs=None)
states2 = CFDSolver.getStates()
resNorm = numpy.sqrt((1 / CFDSolver.getStateSize()) * numpy.sum((states1 - states2) ** 2))
handler.root_print("Adjoint States")
handler.par_add_norm("Adjoint States", resNorm, rtol=rtol, atol=atol)


def assert_problem_size_equal(handler, CFDSolver, **kwargs):
rtol, atol = getTol(**kwargs)
# Now a few simple checks
Expand Down
8 changes: 8 additions & 0 deletions tests/reg_tests/test_adjoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ def test_adjoint(self):
utils.assert_adjoint_sens_allclose(self.handler, self.CFDSolver, self.ap, tol=1e-10)
self.assert_adjoint_failure()

def test_adjoint2(self):
utils.assert_adjoint2_sens_allclose(self.handler, self.CFDSolver, self.ap, tol=1e-10)
self.assert_adjoint_failure()

def test_adjoint_states(self):
utils.assert_adjoint_states_allclose(self.handler, self.CFDSolver, self.ap, tol=1e-10)
self.assert_adjoint_failure()


@parameterized_class(test_params)
class TestCmplxStep(reg_test_classes.CmplxRegTest):
Expand Down

0 comments on commit cd21478

Please sign in to comment.