示例#1
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)
示例#2
0
ap = AeroProblem(name='wing',
    mach=0.75,
    altitude=5000,
    alpha=1.5,
    areaRef=45.5,
    chordRef=3.25,
    evalFuncs=['cl','cd']
)

# ==============================================================================
#       Solve for a specific CL
# ==============================================================================
W = 50000 * 9.81                # total aircraft weight in Newtons
n = 2.5                         # load factor for 2.5g maneuver
Sref = ap.areaRef * 2           # total reference wing area
CLstar = W * n / Sref / ap.q    # desired CL for load condition
if MPI.COMM_WORLD.rank == 0:
    print('\nSolving for CL={:.5f}\n'.format(CLstar))
CFDSolver.solveCL(ap, CLstar)

# ==============================================================================
#       Print functions and write force file
# ==============================================================================
funcs = {}
CFDSolver.evalFunctions(ap, funcs)
# Print the evaluated functions
if MPI.COMM_WORLD.rank == 0:
    print(funcs)

CFDSolver.writeForceFile('forces.txt')