Esempio n. 1
0
def test6():
    # ****************************************************************************
    printHeader('MDO tutorial RANS Geometric Variables')
    # ****************************************************************************
    aeroOptions = copy.deepcopy(defOpts)

    # Now set the options that need to be overwritten for this example:
    aeroOptions.update(
        {'gridfile': '../inputFiles/mdo_tutorial_rans.cgns',
         'mgcycle':'2w',
         'equationtype':'RANS',
         'smoother':'dadi',
         'nsubiterturb':3,
         'nsubiter':3,
         'cfl':1.5,
         'cflcoarse':1.25,
         'ncyclescoarse':250,
         'ncycles':750,
         'monitorvariables':['resrho','resturb','cl','cd','cmz','yplus','totalr'],
         'usenksolver':True,
         'l2convergence':1e-17,
         'l2convergencecoarse':1e-2,
         'nkswitchtol':1e-4,
         'adjointl2convergence': 1e-16,
         'nkls': 'non monotone',
         'frozenturbulence':False,
         'nkjacobianlag':2,
     }
    )

    # Setup aeroproblem, cfdsolver
    ap = AeroProblem(name='mdo_tutorial', alpha=1.8, mach=0.80, 
                     altitude=10000.0, areaRef=45.5, chordRef=3.25, evalFuncs=['cl','cmz','drag'])
    
    ap.addDV('alpha')
    ap.addDV('mach')
    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 xrange(nTwist):
            geo.rot_z['wing'].coef[i] = val[i]

    def span(val, geo):
        # Span
        C = geo.extractCoef('wing')
        s = geo.extractS('wing')
        for i in xrange(len(C)-1):
            C[-1, 2] = C[-1, 2] + val[0]
        geo.restoreCoef(C, 'wing')

    DVGeo.addGeoDVGlobal('twist', [0]*nTwist, twist, lower=-10, upper=10, scale=1.0)
    DVGeo.addGeoDVGlobal('span', [0], span, lower=-10, upper=10, scale=1.0)
    DVGeo.addGeoDVLocal('shape', lower=-0.5, upper=0.5, axis='y', scale=10.0)
    mesh = MBMesh(options={'gridFile':'../inputFiles/mdo_tutorial_rans.cgns'})
    CFDSolver.setMesh(mesh)
    CFDSolver.setDVGeo(DVGeo)
    #Aeroproblem must be set before we can call DVGeo.setDesignVars
    CFDSolver.setAeroProblem(ap)
    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 ['cl','cmz','drag']:
                print 'funcs[%s]:'%key
                reg_write(funcs['mdo_tutorial_%s'%key],1e-10,1e-10)
            # Now write the derivatives in the same order the CS will do them:
            print ('Twist[0] Derivatives:')
            reg_write(funcsSens['mdo_tutorial_cl']['twist'][0][0], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_cmz']['twist'][0][0], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_drag']['twist'][0][0], 1e-10,1e-10)

            print ('Span Derivatives:')
            reg_write(funcsSens['mdo_tutorial_cl']['span'][0], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_cmz']['span'][0], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_drag']['span'][0], 1e-10,1e-10)

            print ('shape[13] Derivatives:')
            reg_write(funcsSens['mdo_tutorial_cl']['shape'][0][13], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_cmz']['shape'][0][13], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_drag']['shape'][0][13], 1e-10,1e-10)

            print ('mach Derivatives:')
            reg_write(funcsSens['mdo_tutorial_cl']['mach_mdo_tutorial'], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_cmz']['mach_mdo_tutorial'], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_drag']['mach_mdo_tutorial'], 1e-10,1e-10)

    else:
        # For the complex....we just do successive perturbation
        for ii in range(4):
            xRef = {'twist':[0.0, 0.0], 'span':[0.0], 'shape':numpy.zeros(72, dtype='D'), 'mach_mdo_tutorial':0.8}
            if ii == 0:
                xRef['twist'][0] += h*1j
            elif ii == 1:      
                xRef['span'][0] += h*1j
            elif ii == 2:
                xRef['shape'][13] += h*1j
            else:
                xRef['mach_mdo_tutorial']+=h*1j

            ap.setDesignVars(xRef)
            CFDSolver.resetFlow(ap)
            DVGeo.setDesignVars(xRef)
            CFDSolver(ap, writeSolution=False)
            funcs = {}
            CFDSolver.evalFunctions(ap, funcs)

            if MPI.COMM_WORLD.rank == 0:
                if ii == 0:
                    for key in ['cl','cmz','drag']:
                        print 'funcs[%s]:'%key
                        reg_write(numpy.real(funcs['mdo_tutorial_%s'%key]),1e-10,1e-10)

                if ii == 0:
                    print ('Twist[0] Derivatives:')
                elif ii == 1:
                    print ('Span Derivatives:')
                elif ii == 2:
                    print ('shape[13] Derivatives:')
                elif ii == 3:
                    print ('mach Derivatives:')

                for key in ['cl','cmz','drag']:
                    deriv = numpy.imag(funcs['mdo_tutorial_%s'%key])/h
                    reg_write(deriv,1e-10,1e-10)

    del CFDSolver
    del mesh
Esempio n. 2
0
                 areaRef=45.5,
                 chordRef=3.25,
                 evalFuncs=['cd', 'cmz', 'lift'])
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)
        # Now write the derivatives in the same order the CS will do them:
        print('Alpha Derivatives:')
        reg_write(funcsSens['mdo_tutorial_cd']['alpha_mdo_tutorial'], 1e-10,
                  1e-10)
        reg_write(funcsSens['mdo_tutorial_cmz']['alpha_mdo_tutorial'], 1e-10,
                  1e-10)
        reg_write(funcsSens['mdo_tutorial_lift']['alpha_mdo_tutorial'], 1e-10,
                  1e-10)
Esempio n. 3
0
def test5():
    # ****************************************************************************
    printHeader('MDO tutorial RANS Aerodynamic Variables')
    # ****************************************************************************
    aeroOptions = copy.deepcopy(defOpts)

    # Now set the options that need to be overwritten for this example:
    aeroOptions.update(
        {'gridfile': '../inputFiles/mdo_tutorial_rans.cgns',
         'mgcycle':'2w',
         'equationtype':'RANS',
         'smoother':'dadi',
         'nsubiterturb':3,
         'nsubiter':3,
         'cfl':1.5,
         'cflcoarse':1.25,
         'ncyclescoarse':250,
         'ncycles':750,
         'monitorvariables':['resrho','resturb','cl','cd','cmz','yplus','totalr'],
         'usenksolver':True,
         'l2convergence':1e-17,
         'l2convergencecoarse':1e-2,
         'nkswitchtol':1e-4,
         'adjointl2convergence': 1e-16,
         'nkls': 'non monotone',
         'frozenturbulence':False,
         'nkjacobianlag':2,
     }
    )

    # Setup aeroproblem, cfdsolver
    ap = AeroProblem(name='mdo_tutorial', alpha=1.8, mach=0.80, 
                     altitude=10000.0, areaRef=45.5, chordRef=3.25, evalFuncs=['cd','cmz','lift'])
    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)
            # Now write the derivatives in the same order the CS will do them:
            print ('Alpha Derivatives:')
            reg_write(funcsSens['mdo_tutorial_cd']['alpha_mdo_tutorial'], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_cmz']['alpha_mdo_tutorial'], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_lift']['alpha_mdo_tutorial'], 1e-10,1e-10)

            print ('Mach Derivatives:')
            reg_write(funcsSens['mdo_tutorial_cd']['mach_mdo_tutorial'], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_cmz']['mach_mdo_tutorial'], 1e-10,1e-10)
            reg_write(funcsSens['mdo_tutorial_lift']['mach_mdo_tutorial'], 1e-10,1e-10)

            print ('Altitude Derivatives:')
            reg_write(funcsSens['mdo_tutorial_cd']['altitude_mdo_tutorial'], 1e-8,1e-8)
            reg_write(funcsSens['mdo_tutorial_cmz']['altitude_mdo_tutorial'], 1e-8,1e-8)
            reg_write(funcsSens['mdo_tutorial_lift']['altitude_mdo_tutorial'], 1e-8,1e-8)

    else:
        # For the complex....we just do successive perturbation
        for ii in range(3):
            ap.alpha = 1.8
            ap.mach = 0.80
            ap.altitude = 10000.0
            if ii == 0:
                ap.alpha += h*1j
            elif ii == 1:
                ap.mach += h*1j
            else:
                ap.altitude += h*1j

            CFDSolver.resetFlow(ap)
            CFDSolver(ap, writeSolution=False)
            funcs = {}
            CFDSolver.evalFunctions(ap, funcs)

            if MPI.COMM_WORLD.rank == 0:
                if ii == 0:
                    for key in ['cd','cmz','lift']:
                        print 'funcs[%s]:'%key
                        reg_write(numpy.real(funcs['mdo_tutorial_%s'%key]),1e-10,1e-10)

                if ii == 0:
                    print ('Alpha Derivatives:')
                    for key in ['cd','cmz','lift']:
                        deriv = numpy.imag(funcs['mdo_tutorial_%s'%key])/h
                        reg_write(deriv,1e-10,1e-10)

                elif ii == 1:
                    print ('Mach Derivatives:')
                    for key in ['cd','cmz','lift']:
                        deriv = numpy.imag(funcs['mdo_tutorial_%s'%key])/h
                        reg_write(deriv,1e-10,1e-10)

                else:
                    print ('AltitudeDerivatives:')
                    for key in ['cd','cmz','lift']:
                        deriv = numpy.imag(funcs['mdo_tutorial_%s'%key])/h
                        reg_write(deriv,1e-10,1e-10)


    del CFDSolver