Beispiel #1
0
    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()

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

        self.ffdFile = os.path.join(baseDir, "../../input_files/mdo_tutorial_ffd.fmt")

        mesh_options = copy.copy(IDWarpDefOpts)
        mesh_options.update({"gridFile": options["gridfile"]})

        self.ap = copy.deepcopy(self.aero_prob)

        # Setup aeroproblem
        self.ap.evalFuncs = self.evalFuncs

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

        self.CFDSolver = ADFLOW_C(options=options, debug=True)

        self.CFDSolver.setMesh(USMesh_C(options=mesh_options))
        self.CFDSolver.setDVGeo(setDVGeo(self.ffdFile, cmplx=True))

        # propagates the values from the restart file throughout the code
        self.CFDSolver.getResidual(self.ap)
Beispiel #2
0
    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()

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

        self.ap = copy.deepcopy(self.aero_prob)

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

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

        self.CFDSolver = ADFLOW_C(options=options, debug=True)

        # propagates the values from the restart file throughout the code
        self.CFDSolver.getResidual(self.ap)
Beispiel #3
0
    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_C(options=options, debug=False)
Beispiel #4
0
class TestCmplxSolverCombos(reg_test_classes.CmplxRegTest):

    # TODO add a convergence test with a complex perturbed DV also

    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_C(options=options, debug=False)

    def cmplx_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)
Beispiel #5
0
class TestCmplxStep(reg_test_classes.CmplxRegTest):
    """
    Tests that sensitives calculated from solving an adjoint are correct.
    and jacobian vector products are accurate.

    based on old regression tests_cs 12, and 14
    """

    N_PROCS = 2

    h = 1e-40

    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()

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

        self.ffdFile = os.path.join(baseDir, "../../input_files/mdo_tutorial_ffd.fmt")

        mesh_options = copy.copy(IDWarpDefOpts)
        mesh_options.update({"gridFile": options["gridfile"]})

        self.ap = copy.deepcopy(self.aero_prob)

        # Setup aeroproblem
        self.ap.evalFuncs = self.evalFuncs

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

        self.CFDSolver = ADFLOW_C(options=options, debug=True)

        self.CFDSolver.setMesh(USMesh_C(options=mesh_options))
        self.CFDSolver.setDVGeo(setDVGeo(self.ffdFile, cmplx=True))

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

    def cmplx_test_aero_dvs(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

        for dv in ["alpha", "mach"]:  # defaultAeroDVs:

            funcsSens = defaultdict(lambda: {})
            setattr(self.ap, dv, getattr(self.ap, dv) + self.h * 1j)

            self.CFDSolver.resetFlow(self.ap)
            self.CFDSolver(self.ap, writeSolution=False)
            self.assert_solution_failure()

            funcs = {}
            self.CFDSolver.evalFunctions(self.ap, funcs)
            setattr(self.ap, dv, getattr(self.ap, dv) - self.h * 1j)

            for f in self.ap.evalFuncs:
                key = self.ap.name + "_" + f
                dv_key = dv + "_" + self.ap.name
                funcsSens[key][dv_key] = numpy.imag(funcs[key]) / self.h

        if MPI.COMM_WORLD.rank == 0:
            print("====================================")
            print(self.ap.alpha)
            print(self.ap.mach)
            print(self.name, funcsSens)
            print("====================================")

        self.handler.root_add_dict("Eval Functions Sens:", funcsSens, rtol=1e-8, atol=5e-10)

    def cmplx_test_geom_dvs(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

        # redo the setup for a cmplx test
        funcsSens = defaultdict(lambda: {})

        xRef = {"twist": [0.0] * 6, "span": [0.0], "shape": numpy.zeros(72, dtype="D")}

        for dv in ["span", "twist", "shape"]:

            xRef[dv][0] += self.h * 1j

            self.CFDSolver.resetFlow(self.ap)
            self.CFDSolver.DVGeo.setDesignVars(xRef)
            self.CFDSolver(self.ap, writeSolution=False)
            self.assert_solution_failure()

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

            xRef[dv][0] -= self.h * 1j

            for f in self.ap.evalFuncs:
                key = self.ap.name + "_" + f
                dv_key = dv
                funcsSens[key][dv_key] = numpy.imag(funcs[key]) / self.h

                err_msg = "Failed value for: {}".format(key + " " + dv_key)

                ref_val = self.handler.db["Eval Functions Sens:"][key][dv_key]
                ref_val = ref_val.flatten()[0]

                numpy.testing.assert_allclose(funcsSens[key][dv_key], ref_val, atol=5e-9, rtol=5e-9, err_msg=err_msg)

        if MPI.COMM_WORLD.rank == 0:
            print("====================================")
            print(self.name, funcsSens)
            print("====================================")
Beispiel #6
0
     'l2convergence':1e-15,
     'l2convergencecoarse':1e-2,
     'nkswitchtol':1e-2,
     'adjointl2convergence': 1e-15,
     'nkls':'non monotone',
     'blocksplitting': True
 }
)
h = 1e-40

# Setup aeroproblem, cfdsolver
ap = AeroProblem(name='mdo_tutorial', alpha=1.8, mach=0.80, R=287.87,
                 altitude=10000.0, areaRef=45.5, chordRef=3.25,
                 evalFuncs=['cl','cmz','drag'])

CFDSolver = ADFLOW(options=aeroOptions)
if 'complex' in sys.argv:
    DVGeo = DVGeometry('../inputFiles/mdo_tutorial_ffd.fmt', complex=True)
else:
    DVGeo = DVGeometry('../inputFiles/mdo_tutorial_ffd.fmt', complex=False)

nTwist = 2
DVGeo.addRefAxis('wing', pyspline.Curve(x=numpy.linspace(5.0/4.0, 1.5/4.0+7.5, nTwist),
                                        y=numpy.zeros(nTwist),
                                        z=numpy.linspace(0,14, nTwist), k=2))
def twist(val, geo):
    for i in range(nTwist):
        geo.rot_z['wing'].coef[i] = val[i]

def span(val, geo):
    # Span
Beispiel #7
0
    'timeIntervals':
    ntimeintervalsspectral,
    'qmode':
    True,
    'alphaFollowing':
    False,
    'TSStability':
    False,
    'usetsinterpolatedgridvelocity':
    False,
    'useblockettes':
    False,
}

if complex_flag:
    CFDSolver = ADFLOW_C(options=aeroOptions)
else:
    CFDSolver = ADFLOW(options=aeroOptions)

ap = AeroProblem(name=name, alpha=alpha, mach=mach, altitude=10000.0, areaRef=1.0, chordRef=1.0, evalFuncs=['cl','cd', 'cmz'],
    xRef=xRef,xRot=xRot,\
    degreePol=0,coefPol=[0.0],\
    degreeFourier=1,omegaFourier=omega,cosCoefFourier=[0.0,0.0],sinCoefFourier=[alpha_mag])

ap.addDV('mach', scale=1.0)
ap.addDV('alpha', scale=1.0)

funcs = {}
CFDSolver(ap)
CFDSolver.evalFunctions(ap, funcs)
Beispiel #8
0
    def setUp(self):

        super().setUp()

        self.options = {
            "gridfile": os.path.join(baseDir, "../../input_files/actuator_test_pipe.cgns"),
            # the restart file was ran with thrust = 600 N and heat = 1e5 W
            # "restartfile": os.path.join(baseDir, "../../input_files/actuator_test_pipe.cgns"),
            "writevolumesolution": False,
            "writesurfacesolution": False,
            "writetecplotsurfacesolution": False,
            "mgcycle": "sg",
            "ncycles": 1000,
            "useanksolver": True,
            "usenksolver": True,
            "ankswitchtol": 10.0,
            "anksecondordswitchtol": 1e-2,
            "ankinnerpreconits": 1,
            "monitorvariables": ["cpu", "resrho", "resrhoe"],
            "volumevariables": ["temp", "mach", "resrho"],
            "surfacevariables": ["temp", "vx", "vy", "vz", "p", "ptloss", "mach", "rho"],
            "equationType": "Euler",
            "l2convergence": 1e-13,
            "adjointl2convergence": 1e-13,
        }

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

        # CFDSolver = ADFLOW(options=options)
        CFDSolver = ADFLOW_C(options=options, debug=True)

        CFDSolver.addFunction("mdot", "inlet", name="mdot_in")
        CFDSolver.addFunction("mdot", "outlet", name="mdot_out")

        CFDSolver.addFunction("aavgptot", "outlet", name="aavgptot_out")
        CFDSolver.addFunction("aavgptot", "inlet", name="aavgptot_in")

        CFDSolver.addFunction("mavgttot", "outlet", name="mavgttot_out")
        CFDSolver.addFunction("mavgttot", "inlet", name="mavgttot_in")

        CFDSolver.addFunction("aavgps", "outlet", name="aavgps_out")
        CFDSolver.addFunction("aavgps", "inlet", name="aavgps_in")

        CFDSolver.addFunction("area", "inlet", name="area_in")
        CFDSolver.addFunction("area", "outlet", name="area_out")

        CFDSolver.addFunction("mavgvx", "inlet", name="mavgvx_in")
        CFDSolver.addFunction("mavgvx", "outlet", name="mavgvx_out")

        CFDSolver.addFunction("forcexpressure", "inlet", name="forcexpressure_in")
        CFDSolver.addFunction("forcexpressure", "outlet", name="forcexpressure_out")

        CFDSolver.addFunction("forcexmomentum", "inlet", name="forcexmomentum_in")
        CFDSolver.addFunction("forcexmomentum", "outlet", name="forcexmomentum_out")

        self.CFDSolver = CFDSolver

        # this is imported from reg_aeroproblems utility script
        self.ap = ap_actuator_pipe

        actuatorFile = os.path.join(baseDir, "../../input_files/actuator_test_disk.xyz")
        self.CFDSolver.addActuatorRegion(
            actuatorFile,
            np.array([0, 0, 0]),
            np.array([1, 0, 0]),
            "actuator_region",
            # we will set these individually in the tests below
            thrust=0.0,
            torque=0.0,
            heat=0.0,
        )

        # add thrust and heat as AP DVs
        self.ap.setBCVar("Thrust", 0.0, "actuator_region")
        self.ap.addDV("Thrust", family="actuator_region", units="N", name="thrust")

        self.ap.setBCVar("Heat", 0.0, "actuator_region")
        self.ap.addDV("Heat", family="actuator_region", units="J/s", name="heat")

        # also add flowpower as an AZ function
        CFDSolver.addFunction("flowpower", "actuator_region", name="flowpower_az")
Beispiel #9
0
    # 'alpha':0.25,
    # 'errTol':0.0001,
    # 'evalMode':'fast',
    # 'useRotations':True,
    # 'zeroCornerRotations':True,
    # 'cornerAngle':30.0,
    # 'bucketSize':8,
}

execfile('./setup_geometry.py')

DVList = {'shape': array0}
DVGeo.setDesignVars(DVList)

if complex_flag:
    CFDSolver = ADFLOW_C(options=aeroOptions)
else:
    CFDSolver = ADFLOW(options=aeroOptions)

CFDSolver.setDVGeo(DVGeo)

ap = AeroProblem(name=name, alpha=alpha, mach=mach, altitude=10000.0, areaRef=1.0, chordRef=1.0, evalFuncs=['cl','cd', 'cmz'],
    xRef=xRef,xRot=xRot,\
    degreePol=0,coefPol=[0.0],\
    degreeFourier=1,omegaFourier=omega,cosCoefFourier=[0.0,0.0],sinCoefFourier=[0.0])

ap.addDV('mach', scale=1.0)
ap.addDV('alpha', scale=1.0)

if complex_flag:
    mesh = USMesh_C(options=usoptions)
Beispiel #10
0
    'blocksplitting': True
})

# Setup aeroproblem, cfdsolver
ap = AeroProblem(name='mdo_tutorial',
                 alpha=1.8,
                 mach=0.80,
                 R=287.87,
                 altitude=10000.0,
                 areaRef=45.5,
                 chordRef=3.25,
                 evalFuncs=['cd', 'lift', 'cmz'])
ap.addDV('alpha')
ap.addDV('mach')
ap.addDV('altitude')
CFDSolver = ADFLOW(options=aeroOptions, debug=True)

if not 'complex' in sys.argv:
    # Solve system
    CFDSolver(ap, writeSolution=False)
    funcs = {}
    CFDSolver.evalFunctions(ap, funcs)
    # Solve sensitivities
    funcsSens = {}
    CFDSolver.evalFunctionsSens(ap, funcsSens)

    # Write values and derivatives out:
    if MPI.COMM_WORLD.rank == 0:
        for key in ['cd', 'cmz', 'lift']:
            print('funcs[%s]:' % key)
            reg_write(funcs['mdo_tutorial_%s' % key], 1e-10, 1e-10)
Beispiel #11
0
  # 'evalMode':'fast',
  # 'useRotations':True,
  # 'zeroCornerRotations':True,
  # 'cornerAngle':30.0,
  # 'bucketSize':8,
}

execfile('./utils/setup_geometry.py')


DVList={'shape':array0}
DVGeo.setDesignVars(DVList)


if complex_flag:
    CFDSolver = ADFLOW_C(options=aeroOptions)
else:
    CFDSolver = ADFLOW(options=aeroOptions)

CFDSolver.setDVGeo(DVGeo)

ap = AeroProblem(name=name, alpha=alpha, mach=mach, altitude=10000.0, areaRef=1.0, chordRef=1.0, evalFuncs=['cl','cd', 'cmz'],
    xRef=xRef,xRot=xRot,\
    degreePol=0,coefPol=[0.0],\
    degreeFourier=1,omegaFourier=omega,cosCoefFourier=[0.0,0.0],sinCoefFourier=[alpha_mag])


ap.addDV('mach',scale=1.0)
ap.addDV('alpha',scale=1.0)

Beispiel #12
0
class TestJacVecFwdCS(reg_test_classes.CmplxRegTest):
    """
    Tests jacobian vector products against CS.

    """

    N_PROCS = 2

    h = 1e-40

    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()

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

        self.ap = copy.deepcopy(self.aero_prob)

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

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

        self.CFDSolver = ADFLOW_C(options=options, debug=True)

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

    # ------------------- Derivative routine checks ----------------------------
    def cmplx_test_wDot(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

        # perturb each input and check that the outputs match the FD to with in reason
        wDot = self.CFDSolver.getStatePerturbation(314)

        resDot_CS, funcsDot_CS, fDot_CS = self.CFDSolver.computeJacobianVectorProductFwd(
            wDot=wDot,
            residualDeriv=True,
            funcDeriv=True,
            fDeriv=True,
            mode="CS",
            h=self.h)

        rtol, atol = getTol(tol=1e-9)

        self.handler.root_print("||dR/dw * wDot||")
        self.handler.par_add_norm("||dR/dw * wDot||",
                                  resDot_CS,
                                  rtol=rtol,
                                  atol=atol)

        self.handler.root_print("dFuncs/dw * wDot")
        self.handler.root_add_dict("dFuncs/dw * wDot",
                                   funcsDot_CS,
                                   rtol=rtol,
                                   atol=atol)

        self.handler.root_print("||dF/dw * wDot||")
        self.handler.par_add_norm("||dF/dw * wDot||",
                                  fDot_CS,
                                  rtol=rtol,
                                  atol=atol)

    def cmplx_test_xVDot(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

        # perturb each input and check that the outputs match the FD to with in reason
        xVDot = self.CFDSolver.getSpatialPerturbation(314)

        rtol, atol = getTol(tol=1e-10)

        resDot_cs, funcsDot_cs, fDot_cs = self.CFDSolver.computeJacobianVectorProductFwd(
            xVDot=xVDot,
            residualDeriv=True,
            funcDeriv=True,
            fDeriv=True,
            mode="CS",
            h=self.h)

        self.handler.root_print("||dR/dXv * xVDot||")
        self.handler.par_add_norm("||dR/dXv * xVDot||",
                                  resDot_cs,
                                  rtol=rtol,
                                  atol=atol)

        # These can be finiky sometimes so a bigger tolerance.
        self.handler.root_print("dFuncs/dXv * xVDot")
        self.handler.root_add_dict("dFuncs/dXv * xVDot",
                                   funcsDot_cs,
                                   rtol=rtol * 10,
                                   atol=atol * 10)

        self.handler.root_print("||dF/dXv * xVDot||")
        self.handler.par_add_norm("||dF/dXv * xVDot||",
                                  fDot_cs,
                                  rtol=rtol,
                                  atol=atol)

    def cmplx_test_xDvDot(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
        rtol, atol = getTol(tol=1e-10)

        # perturb each input and check that the outputs match the FD to with in reason
        for aeroDV in self.ap.DVs.values():
            key = aeroDV.key
            self.handler.root_print("  -> %s" % key)
            xDvDot = {key: 1.0}

            resDot_cs, funcsDot_cs, fDot_cs = self.CFDSolver.computeJacobianVectorProductFwd(
                xDvDot=xDvDot,
                residualDeriv=True,
                funcDeriv=True,
                fDeriv=True,
                mode="CS",
                h=self.h)

            self.handler.root_print("||dR/d%s||" % key)
            self.handler.par_add_norm("||dR/d%s||" % key,
                                      resDot_cs,
                                      rtol=rtol,
                                      atol=atol)

            self.handler.root_print("dFuncs/d%s" % key)
            self.handler.root_add_dict("dFuncs/d%s" % key,
                                       funcsDot_cs,
                                       rtol=rtol,
                                       atol=atol)

            self.handler.root_print("||dF/d%s||" % key)
            self.handler.par_add_norm("||dF/d%s||" % key,
                                      fDot_cs,
                                      rtol=rtol,
                                      atol=atol)