Ejemplo n.º 1
0
                  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']:
Ejemplo n.º 2
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