Example #1
0
CFDSolver.addSlices("z", np.linspace(0.1, 14, 10))
# rst adflow (end)
# ======================================================================
#         Set up flow conditions with AeroProblem
# ======================================================================
# rst aeroproblem (beg)
ap = AeroProblem(name="wing",
                 alpha=1.5,
                 mach=0.8,
                 altitude=10000,
                 areaRef=45.5,
                 chordRef=3.25,
                 evalFuncs=["cl", "cd"])

# Add angle of attack variable
ap.addDV("alpha", value=1.5, lower=0, upper=10.0, scale=0.1)
# rst aeroproblem (end)
# ======================================================================
#         Geometric Design Variable Set-up
# ======================================================================
# rst dvgeo (beg)
# Create DVGeometry object
FFDFile = "ffd.xyz"
DVGeo = DVGeometry(FFDFile)

# Create reference axis
nRefAxPts = DVGeo.addRefAxis("wing", xFraction=0.25, alignIndex="k")
nTwist = nRefAxPts - 1


# Set up global design variables
Example #2
0
                     'aavgptot_up',
                     'aavgptot_down',
                     'aavgptot_plane',
                     'mavgttot_up',
                     'mavgttot_down',
                     'mavgttot_plane',
                     'mavgps_up',
                     'mavgps_down',
                     'mavgps_plane',
                     'aavgps_up',
                     'aavgps_down',
                     'aavgps_plane',
                 ])

ap.setBCVar('Pressure', 79326.7, 'downstream')
ap.addDV('Pressure', family='downstream')

ap.setBCVar('PressureStagnation', 100000.0, 'upstream')
ap.addDV('PressureStagnation', family='upstream')

ap.setBCVar('TemperatureStagnation', 500.0, 'upstream')
ap.addDV('TemperatureStagnation', family='upstream')


def setup_cb(comm):

    solver = ADFLOW(options=options, comm=comm, debug=True)

    solver.addIntegrationSurface('../inputFiles/integration_plane_viscous.fmt',
                                 'viscous_plane')
    solver.finalizeUserIntegrationSurfaces()
Example #3
0
    outFile = open(fName, 'w', buffering=0)
    redirectIO(outFile)

# ==============================================================================
# Set up case problems
# ==============================================================================
# Setup cruise problems
cruiseProblems = []
ap = AeroProblem(name='cruise',
                 mach=0.8,
                 altitude=10000,
                 areaRef=Sref,
                 alpha=2.0,
                 chordRef=chordRef,
                 evalFuncs=['lift', 'drag'])
ap.addDV('alpha', lower=0, upper=10.0, scale=0.1)
sp = StructProblem(ap.name, evalFuncs=['mass'])
cruiseProblems.append(AeroStructProblem(ap, sp))

# Setup maneuver problems
maneuverProblems = []  # List of maneuver AeroStruct problem objects
ap = AeroProblem(name='maneuver',
                 mach=0.75,
                 altitude=5000,
                 areaRef=Sref,
                 alpha=2.0,
                 chordRef=chordRef,
                 evalFuncs=['lift'])
ap.addDV('alpha', lower=0, upper=10.0, scale=0.1)
sp = StructProblem(ap.name, evalFuncs=['ks0', 'ks1', 'ks2'], loadFactor=2.5)
maneuverProblems.append(AeroStructProblem(ap, sp))
Example #4
0
    2,
    '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=['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:
Example #5
0
     'usenksolver':True,
     'l2convergence':1e-16,
     'l2convergencecoarse':1e-2,
     'nkswitchtol':1e-2,
     'adjointl2convergence': 1e-15,
     'nkls':'non monotone',
     'blocksplitting': True
 }
)


# Setup aeroproblem, cfdsolver
ap = AeroProblem(name='mdo_tutorial', alpha=1.8, mach=0.50, R=287.87,
                 reynolds=50000.0, reynoldsLength=3.25, T=293.15,
                 areaRef=45.5, chordRef=3.25, evalFuncs=['cd','cmz','lift'])
ap.addDV('alpha')
ap.addDV('mach')

CFDSolver = ADFLOW(options=aeroOptions)

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:
Example #6
0
#         Set up flow conditions with AeroProblem
# ======================================================================
# rst aeroproblem (beg)
aeroProblems = []
for i in range(nFlowCases):
    ap = AeroProblem(
        name="fc%d" % i,
        alpha=alpha[i],
        mach=mach[i],
        altitude=alt[i],
        areaRef=1.0,
        chordRef=1.0,
        evalFuncs=["cl", "cd"],
    )
    # Add angle of attack variable
    ap.addDV("alpha", value=alpha[i], lower=0, upper=10.0, scale=1.0)
    aeroProblems.append(ap)
# rst aeroproblem (end)
# ======================================================================
#         Geometric Design Variable Set-up
# ======================================================================
# rst dvgeo (beg)
# Create DVGeometry object
FFDFile = "ffd.xyz"

DVGeo = DVGeometry(FFDFile)  # DVGeo = DVGeometry_FFD(FFDFile)
DVGeo.addGeoDVLocal("shape", lower=-0.05, upper=0.05, axis="y", scale=1.0)

span = 1.0
pos = np.array([0.5]) * span
CFDSolver.addSlices("z", pos, sliceType="absolute")
Example #7
0
class ActuatorDerivTests(unittest.TestCase):

    def setUp(self):
        gridFile = os.path.join(baseDir, '../input_files/pipe.cgns')
        self.options = {'gridfile': gridFile,
                        'mgcycle':'sg',
                        'ncycles':1,
                        'useanksolver':True,
                        'usenksolver':False,
                        'volumevariables': ['temp', 'mach', 'resrho' ],
                        'surfacevariables':['temp', 'vx', 'vy', 'vz', 'p', 'ptloss', 'mach', 'rho'],
                        'equationType':'euler',
                        'l2convergence': 1e-13}
                        
        CFDSolver = ADFLOW(options=self.options)

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

        CFDSolver.addFunction('mavgptot', 'outlet', name="mavgptot_out")
        CFDSolver.addFunction('mavgptot', 'inlet', name="mavgptot_in")

        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('mavgps', 'outlet', name="mavgps_out")
        CFDSolver.addFunction('mavgps', 'inlet', name="mavgps_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="vx_in")
        CFDSolver.addFunction('mavgvx', 'outlet', name="vx_out")

        CFDSolver.addFunction('mavgps', 'inlet', name="ps_in")
        CFDSolver.addFunction('mavgps', 'outlet', name="ps_out")

        self.CFDSolver = CFDSolver
        
        self.ap = AeroProblem(name='actuator_in_pipe', alpha=00, mach=0.6, altitude=0,
                        areaRef=1.0, chordRef=1.0,
                    evalFuncs=['mdot_in', 'mdot_out', 
                               'mavgptot_in', 'mavgptot_out', 
                               'mavgttot_in', 'mavgttot_out', 
                               'mavgps_in', 'mavgps_out',
                               'area_in', 'area_out', 
                               'aavgps_in', 'aavgps_out',
                               'aavgptot_in', 'aavgptot_out',
                               'ps_in', 'ps_out',
                               'vx_in', 'vx_out'] )

        self.ap.setActuatorVar('Thrust',  599.0, 'actuator')
        self.ap.addDV('Thrust', familyGroup='actuator', name='actuator_thrust')
        self.ap.setActuatorVar('Torque',  599.0, 'actuator')
        self.ap.addDV('Torque', familyGroup='actuator', name='actuator_torque')
        
        actuatorFile = os.path.join(baseDir, '../input_files/actuator_disk.xyz')
        self.CFDSolver.addActuatorRegion(actuatorFile, np.array([0,0,0]),np.array([1,0,0]), 'actuator', thrust=600 )


    def test_fwd(self):
        self.CFDSolver(self.ap)
        for DV in self.ap.DVs:
            xDvDot = {DV:1}

            resDot_FD, funcsDot_FD, fDot_FD, hfDot_FD = self.CFDSolver.computeJacobianVectorProductFwd(
            xDvDot=xDvDot, residualDeriv=True, funcDeriv=True, fDeriv=True, hfDeriv=True, mode='FD', h=1e-3)

            resDot, funcsDot, fDot, hfDot = self.CFDSolver.computeJacobianVectorProductFwd(
            xDvDot=xDvDot, residualDeriv=True, funcDeriv=True, fDeriv=True, hfDeriv=True, mode='AD')


            np.testing.assert_allclose(resDot_FD,resDot, atol=1e-10)
            for func in funcsDot:
                np.testing.assert_allclose(funcsDot_FD[func],funcsDot[func], atol=1e-7)

            np.testing.assert_allclose(fDot_FD,fDot, atol=1e-7)
            np.testing.assert_allclose(hfDot_FD,hfDot, atol=1e-10)


    # def test_fwd_CS(self):
    #     # arch=self.arch['complex']
    #     import petsc4py
    #     petsc4py.init(arch='complex-debug')
    #     from petsc4py import PETSc
    #     from python.pyADflow_C import ADFLOW_C
        
    #     self.options['useanksolver'] = False
    #     CFDSolver = ADFLOW_C(options=self.options)

    #     CFDSolver.addFamilyGroup('upstream',['inlet'])
    #     CFDSolver.addFamilyGroup('downstream',['outlet'])
    #     CFDSolver.addFamilyGroup('all_flow',['inlet', 'outlet'])
    #     CFDSolver.addFamilyGroup('output_fam',['all_flow', 'allWalls'])

    #     CFDSolver.addFunction('mdot', 'upstream', name="mdot_up")
    #     CFDSolver.addFunction('mdot', 'downstream', name="mdot_down")

    #     CFDSolver.addFunction('mavgptot', 'downstream', name="mavgptot_down")
    #     CFDSolver.addFunction('mavgptot', 'upstream', name="mavgptot_up")

    #     CFDSolver.addFunction('aavgptot', 'downstream', name="aavgptot_down")
    #     CFDSolver.addFunction('aavgptot', 'upstream', name="aavgptot_up")

    #     CFDSolver.addFunction('mavgttot', 'downstream', name="mavgttot_down")
    #     CFDSolver.addFunction('mavgttot', 'upstream', name="mavgttot_up")

    #     CFDSolver.addFunction('mavgps', 'downstream', name="mavgps_down")
    #     CFDSolver.addFunction('mavgps', 'upstream', name="mavgps_up")

    #     CFDSolver.addFunction('aavgps', 'downstream', name="aavgps_down")
    #     CFDSolver.addFunction('aavgps', 'upstream', name="aavgps_up")
        
    #     actuatorFile = os.path.join(baseDir, '../input_files/actuator_disk.xyz')
    #     CFDSolver.addActuatorRegion(actuatorFile, np.array([0,0,0]),np.array([1,0,0]), 'actuator', thrust=600 )
    #     CFDSolver(self.ap, writeSolution=False)

    #     for DV in self.ap.DVs:
    #         xDvDot = {DV:1}

    #         resDot, funcsDot, fDot, hfDot = CFDSolver.computeJacobianVectorProductFwd(
    #         xDvDot=xDvDot, residualDeriv=True, funcDeriv=True, fDeriv=True, hfDeriv=True, mode='CS')
    #         print(np.real(resDot[resDot != 0 ]))
    #         print(np.real(np.sum(resDot)))

    #         # np.testing.assert_allclose(resDot_FD,resDot, rtol=1e-8)
    #         # for func in funcsDot:
    #         #     np.testing.assert_allclose(funcsDot_FD[func],funcsDot[func], rtol=1e-8)

    #         # np.testing.assert_allclose(fDot_FD,fDot, rtol=1e-8)
    #         # np.testing.assert_allclose(hfDot_FD,hfDot, rtol=1e-8)



    #     del(CFDSolver)
    #     del(ADFLOW_C)

    #     # print(resDot)
    #     # print(funcsDot)
    #     # print(fDot)
    #     # print(hfDot)


    def test_bwd(self):
        """ tests the bwd AD for actuator regions """
        self.CFDSolver(self.ap)

        for DV in self.ap.DVs:
            xDvDot = {DV:1}

            resDot, _, _, _ = self.CFDSolver.computeJacobianVectorProductFwd(
            xDvDot=xDvDot, residualDeriv=True, funcDeriv=True, fDeriv=True, hfDeriv=True)

            dwBar = self.CFDSolver.getStatePerturbation(123)
            _, _, xDvBar = self.CFDSolver.computeJacobianVectorProductBwd(
                resBar=dwBar, wDeriv=True, xVDeriv=True, xDvDerivAero=True)

            np.testing.assert_array_almost_equal(np.dot(xDvBar[DV],xDvDot[DV]),\
                                                    np.dot(resDot, dwBar), decimal=14)
Example #8
0
rho_inf = p_inf / (287 * temp_air)

ap = AeroProblem(name='fc_therm',
                 V=u_inf,
                 T=temp_air,
                 P=p_inf,
                 areaRef=1.0,
                 chordRef=1.0,
                 evalFuncs=['heatflux', 'cd', 'cl'],
                 alpha=0.0,
                 beta=0.00,
                 xRef=0.0,
                 yRef=0.0,
                 zRef=0.0)

ap.addDV('alpha', value=0.0, upper=10.0, lower=-10, scale=1e0)

# Create the solver
CFDSolver = ADFLOW(options=options, debug=False)
# CFDSolver.setMesh(USMesh(mesh_options))

# res = CFDSolver.getResidual(ap)
# totalR0 = CFDSolver.getFreeStreamResidual(ap)
# res /= totalR0
# print('Norm of residual')
# reducedSum = MPI.COMM_WORLD.reduce(numpy.sum(res**2))
# print(reducedSum)

# res = CFDSolver.getResidual(ap)

# CFDSolver.setAeroProblem(ap)
Example #9
0
    def regression_test(self, handler, solve=False):
        '''
        This is where the actual testing happens.
        '''
        # gridFile = 'input_files/conic_conv_nozzle.cgns'
        gridFile = '../python/inputFiles/conic_conv_nozzle.cgns'

        options = copy.copy(adflowDefOpts)
        options.update({
            # Common Parameters
            'gridfile':
            gridFile,
            # Physics Parameters
            'equationType':
            'euler',
            'smoother':
            'dadi',
            'nsubiter':
            3,
            'CFL':
            4.0,
            'CFLCoarse':
            1.25,
            'MGCycle':
            'sg',
            'MGStartLevel':
            -1,
            'nCyclesCoarse':
            250,
            'nCycles':
            1000,
            'nkcfl0':
            1e10,
            'monitorvariables': ['cpu', 'resrho', 'cl', 'cd'],
            'volumevariables': ['blank'],
            'surfacevariables': ['mach', 'cp', 'vx', 'vy', 'vz', 'blank'],
            'useNKSolver':
            True,
            'nkswitchtol':
            .01,
            'nkadpc':
            True,
            'nkjacobianlag':
            5,
            'nkouterpreconits':
            3,
            'nkinnerpreconits':
            2,
            # Convergence Parameters
            'L2Convergence':
            1e-10,
            'L2ConvergenceCoarse':
            1e-4,
            'adjointl2convergence':
            1e-6,
            'forcesAsTractions':
            True,
            'debugzipper':
            True,
            'nearwalldist':
            .001,
            'nkls':
            'none',
            'solutionprecision':
            'double',
            'adjointsubspacesize':
            200,
            'outerpreconits':
            3,
            'zipperSurfaceFamily':
            'output_fam',
            'flowtype':
            'internal',
        })

        if not solve:
            options['restartfile'] = gridFile

        # Setup aeroproblem
        ap = AeroProblem(
            name='nozzle',
            alpha=90.0,
            mach=0.5,
            altitude=0,
            areaRef=1.0,
            chordRef=1.0,
            R=287.87,
            evalFuncs=[
                'mdot_up',
                'mdot_down',  #'mdot_plane',
                'mavgptot_up',
                'mavgptot_down',  # 'mavgptot_plane',
                'aavgptot_up',
                'aavgptot_down',  # 'aavgptot_plane',
                'mavgttot_up',
                'mavgttot_down',  # 'mavgttot_plane',
                'mavgps_up',
                'mavgps_down',  #'mavgps_plane'
                'aavgps_up',
                'aavgps_down',  #'aavgps_plane'
            ])

        ap.setBCVar('Pressure', 79326.7, 'downstream')
        ap.addDV('Pressure', family='downstream')

        ap.setBCVar('PressureStagnation', 100000.0, 'upstream')
        ap.addDV('PressureStagnation', family='upstream')

        ap.setBCVar('TemperatureStagnation', 500.0, 'upstream')
        ap.addDV('TemperatureStagnation', family='upstream')

        # Create the solver
        CFDSolver = ADFLOW(options=options)

        CFDSolver.addFamilyGroup('upstream', ['inlet'])
        CFDSolver.addFamilyGroup('downstream', ['outlet'])
        CFDSolver.addFamilyGroup('all_flow', ['inlet', 'outlet'])
        CFDSolver.addFamilyGroup('output_fam', ['all_flow', 'allWalls'])

        CFDSolver.addFunction('mdot', 'upstream', name="mdot_up")
        CFDSolver.addFunction('mdot', 'downstream', name="mdot_down")

        CFDSolver.addFunction('mavgptot', 'downstream', name="mavgptot_down")
        CFDSolver.addFunction('mavgptot', 'upstream', name="mavgptot_up")

        CFDSolver.addFunction('aavgptot', 'downstream', name="aavgptot_down")
        CFDSolver.addFunction('aavgptot', 'upstream', name="aavgptot_up")

        CFDSolver.addFunction('mavgttot', 'downstream', name="mavgttot_down")
        CFDSolver.addFunction('mavgttot', 'upstream', name="mavgttot_up")

        CFDSolver.addFunction('mavgps', 'downstream', name="mavgps_down")
        CFDSolver.addFunction('mavgps', 'upstream', name="mavgps_up")

        CFDSolver.addFunction('aavgps', 'downstream', name="aavgps_down")
        CFDSolver.addFunction('aavgps', 'upstream', name="aavgps_up")

        CFDSolver.setOption('ncycles', 1000)

        # Run test
        # CFDSolver(ap)

        # Check the residual
        res = CFDSolver.getResidual(ap)
        handler.par_add_norm(res, 1e-10, 1e-10, msg='res')

        # Get and check the states
        handler.par_add_norm(CFDSolver.getStates(), 1e-10, 1e-10, msg='states')

        funcs = {}
        CFDSolver.evalFunctions(ap, funcs)
        handler.root_add_dict(funcs, 1e-10, 1e-10, msg='functions')
Example #10
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
Example #11
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