Exemple #1
0
class TestSolverCombos(reg_test_classes.RegTest):
    N_PROCS = 2
    ref_file = "test_solver_combos.json"

    def setUp(self):
        if not hasattr(self, "name"):
            # return immediately when the setup method is being called on the based class and NOT the
            # classes created using parametrized
            # this will happen when training, but will hopefully be fixed down the line
            return

        super().setUp()

        # start with the default options dictionary
        options = copy.copy(adflowDefOpts)

        # set the output directory
        options["outputdirectory"] = os.path.join(baseDir,
                                                  options["outputdirectory"])

        # these are the modified options common to these tests
        options.update(commonTestOptions)

        # finally, bring in the specific options for each parameterized test
        options.update(self.options)

        self.ap = copy.deepcopy(ap_simple_cart_cube)

        # Create the solver
        self.CFDSolver = ADFLOW(options=options, debug=False)

    def test_convergence(self):
        if not hasattr(self, "name"):
            # return immediately when the setup method is being called on the based class and NOT the
            # classes created using parametrized
            # this will happen when training, but will hopefully be fixed down the line
            return

        # do the solve
        self.CFDSolver(self.ap)

        self.assert_solution_failure()

        # get residual norms
        r0, _, rfinal = self.CFDSolver.getResNorms()

        # get the target
        l2conv = self.CFDSolver.getOption("L2Convergence")

        # we should get 12 orders of magnitude relative convergence
        numpy.testing.assert_array_less(rfinal / r0, l2conv)
Exemple #2
0
class TestFunctionals(reg_test_classes.RegTest):
    """
    Tests that given a flow state the residuals, function, forces/tractions,
    and jacobian vector products are accurate.

    """

    N_PROCS = 2

    def setUp(self):
        if not hasattr(self, "name"):
            # return immediately when the setup method is being called on the based class and NOT the
            # classes created using parametrized
            # this will happen when testing, but will hopefully be fixed down the line
            return

        super().setUp()

        options = copy.copy(adflowDefOpts)
        options["outputdirectory"] = os.path.join(baseDir,
                                                  options["outputdirectory"])
        options.update(self.options)

        # Create the solver
        self.CFDSolver = ADFLOW(options=copy.deepcopy(options), debug=True)

        self.ap = copy.deepcopy(self.aero_prob)
        # add the default dvs to the problem
        for dv in defaultAeroDVs:
            self.ap.addDV(dv)

        # propagates the values from the restart file throughout the code
        self.CFDSolver.getResidual(self.ap)

    def test_restart_read(self):
        utils.assert_problem_size_equal(self.handler,
                                        self.CFDSolver,
                                        tol=1e-10)
        utils.assert_states_allclose(self.handler, self.CFDSolver, tol=1e-10)

    def test_residuals(self):
        utils.assert_residuals_allclose(self.handler,
                                        self.CFDSolver,
                                        self.ap,
                                        tol=1e-10)

    def test_functions(self):
        utils.assert_functions_allclose(self.handler,
                                        self.CFDSolver,
                                        self.ap,
                                        tol=1e-9)

    def test_forces_and_tractions(self):
        utils.assert_forces_allclose(self.handler, self.CFDSolver, tol=1e-10)
        utils.assert_tractions_allclose(self.handler,
                                        self.CFDSolver,
                                        tol=1e-10)

        # Reset the option
        self.CFDSolver.setOption("forcesAsTractions", True)

        # Make sure we can write the force file.
        forces_file = os.path.join(self.CFDSolver.getOption("outputdirectory"),
                                   "forces.txt")
        self.CFDSolver.writeForceFile(forces_file)

    # ------------------- Derivative routine checks ----------------------------
    def test_jac_vec_prod_fwd(self):
        utils.assert_fwd_mode_allclose(self.handler,
                                       self.CFDSolver,
                                       self.ap,
                                       tol=5e-9)

    def test_jac_vec_prod_bwd(self):
        utils.assert_bwd_mode_allclose(self.handler,
                                       self.CFDSolver,
                                       self.ap,
                                       tol=1e-10)

    def test_dot_products(self):
        utils.assert_dot_products_allclose(self.handler,
                                           self.CFDSolver,
                                           tol=1e-10)