Beispiel #1
0
    def run_compare(
        self,
        setup_cb,
        ap,
        gridFile,
        dvs=None,
        defaultFuncs=True,
    ):

        if dvs is None:
            for dv in defaultAeroDVs:
                ap.addDV(dv)
        else:
            for dv in dvs:
                ap.addDV(dv)

        evalFuncs = defaultFuncList
        if not defaultFuncs:
            evalFuncs = ap.evalFuncs

        ##########################################
        # Run the strait ADflow code
        ##########################################
        CFDSolver, _, _, _, = setup_cb(MPI.COMM_WORLD)

        solve = True
        if 'solve' not in sys.argv:
            CFDSolver.setOption('restartfile', gridFile)
            solve = False

        CFDSolver(ap)

        # Check the residual
        res = CFDSolver.getResidual(ap)

        funcs = {}
        CFDSolver.evalFunctions(ap, funcs, evalFuncs)

        # # Get and check the states
        states = CFDSolver.getStates()

        ##########################################
        # Run things through OpenMDAO
        ##########################################

        prob = Problem()
        prob.model = OM_ADFLOW(ap=ap,
                               setup_cb=setup_cb,
                               debug=False,
                               owns_indeps=True)

        prob.setup(mode='rev')
        if not solve:
            prob.model.solver.resetFlow(ap)
            prob.model.solver.setOption('restartfile', gridFile)
            prob.model.solver.adflow.inputiteration.mgstartlevel = 1
            prob.model.solver.adflow.initializeflow.initflowrestart()
            prob.model.solver.getResidual(
                ap)  # this does some kind of memory allocation that is needed

        prob.run_model()

        assert_rel_error(self,
                         res,
                         prob.model._residuals['states.states'],
                         tolerance=5e-7)
        assert_rel_error(self, states, prob['states.states'], tolerance=3e-10)

        assert_funcs_equal(self, ap, funcs, prob, tolerance=3e-10)
Beispiel #2
0
    def run_compare(self, setup_cb, ap, gridFile):

        CFDSolver, _, _, _ = setup_cb(MPI.COMM_WORLD)

        solve = True
        if 'solve' not in sys.argv:
            CFDSolver.setOption('restartfile', gridFile)
            solve = False

        for dv in defaultAeroDVs:
            ap.addDV(dv)

        ##########################################
        # Run the strait ADflow code
        ##########################################
        if solve:
            # We are told that we must first solve the problem, most likely
            # for a training run.
            CFDSolver(ap)

        # Check the residual
        res = CFDSolver.getResidual(ap)
        # res /= totalR0

        funcs = {}
        CFDSolver.evalFunctions(ap, funcs, defaultFuncList)

        # # Get and check the states
        states = CFDSolver.getStates()

        #force it to restart the flow
        if CFDSolver.getOption('restartFile') is not None:
            CFDSolver.adflow.inputiteration.mgstartlevel = 1
            CFDSolver.adflow.initializeflow.initflowrestart()

        ##########################################
        # Run things through OpenMDAO
        ##########################################
        prob = Problem()
        prob.model = OM_ADFLOW(ap=ap,
                               setup_cb=setup_cb,
                               debug=True,
                               owns_indeps=True)

        prob.setup(mode='rev')
        if not solve:
            prob.model.solver.resetFlow(ap)
            prob.model.solver.setOption('restartfile', gridFile)
            prob.model.solver.adflow.inputiteration.mgstartlevel = 1
            prob.model.solver.adflow.initializeflow.initflowrestart()
            prob.model.solver.getResidual(
                ap)  # this does some kind of memory allocation that is needed

        prob.model.states._do_solve = solve
        prob.model.functionals._do_solve = solve
        prob.final_setup()
        prob.run_model()

        assert_rel_error(self,
                         res,
                         prob.model._residuals['states.states'],
                         tolerance=1e-7)
        assert_rel_error(self, states, prob['states.states'], tolerance=1e-10)
        assert_funcs_equal(self, ap, funcs, prob, tolerance=1e-10)
    def run_compare(self, setup_cb, ap, gridFile, ffdFile):

        for dv in defaultAeroDVs:
            ap.addDV(dv)
        ap.addDV('alpha')
        ap.addDV('mach')

        # Create the solver
        CFDSolver, mesh, DVGeo, _ = setup_cb(MPI.COMM_WORLD)

        solve = True
        if 'solve' not in sys.argv:
            CFDSolver.setOption('restartfile', gridFile)
            solve = False

        if solve:
            # We are told that we must first solve the problem, most likely
            # for a training run.
            CFDSolver(ap)

        res = CFDSolver.getResidual(ap)

        funcsSens = {}
        CFDSolver.evalFunctionsSens(ap, funcsSens)

        ##########################################
        # Run things through OpenMDAO
        ##########################################
        prob = Problem()

        prob.model = OM_ADFLOW(ap=ap,
                               setup_cb=setup_cb,
                               debug=True,
                               owns_indeps=True)

        prob.setup(mode='rev')
        if not solve:
            prob.model.solver.resetFlow(ap)
            prob.model.solver.setOption('restartfile', gridFile)
            prob.model.solver.adflow.inputiteration.mgstartlevel = 1
            prob.model.solver.adflow.initializeflow.initflowrestart()
            prob.model.solver.getResidual(
                ap)  # this does some kind of memory allocation that is needed

        prob.model.states._do_solve = solve
        prob.model.functionals._do_solve = solve

        prob.final_setup()
        prob.run_model()

        dvs, _ = get_dvs_and_cons(ap=ap, geo=DVGeo)
        dv_names = [args[0] for args, kwargs in dvs]
        om_funcsSens = prob.compute_totals(
            of=['functionals.{}'.format(s) for s in ap.evalFuncs],
            wrt=dv_names,
            return_format='dict')

        # om_funcsSens = prob.compute_totals(of=['functionals.fx'],
        #                                   wrt=dv_names, return_format='dict')

        # print(om_funcsSens)
        # print()
        # print(funcsSens)

        assert_rel_error(self,
                         res,
                         prob.model._residuals['states.states'],
                         tolerance=1e-5)

        assert_funcsSens_equal(self,
                               ap,
                               funcsSens,
                               om_funcsSens,
                               tolerance=1e-9)