Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new tests for two consecutive adjoint runs #362

Merged
merged 11 commits into from
Nov 13, 2024
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Adjoint States": 0.0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entry should be the only one changing in the .json files. There is no point changing the reference values for this PR, especially if the training is done on a local machine.

"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