コード例 #1
0
ファイル: test_bcdata.py プロジェクト: joanibal/adflow
    def test_setBCData(self):
        "Test if bcdata is correctly set to data arrays"
        
        


        CFDSolver = ADFLOW(options=self.options)
        CFDSolver.addFamilyGroup('upstream',['inlet'])
        CFDSolver.addFamilyGroup('downstream',['outlet'])
        bc_data = CFDSolver.getBCData(groupNames=self.set_dvs.keys())
        
        for patch in bc_data:
            if patch.fam in self.set_dvs: 
                for arr in patch:
                    if arr.name in self.set_dvs[patch.fam]:
                        arr.data = self.set_dvs[patch.fam][arr.name]
        
        CFDSolver.setBCData(bc_data)
        # CFDSolver.setAeroProblem(self.ap)

        new_bc_data = CFDSolver.getBCData(groupNames=self.set_dvs.keys())

        ## check that the mesh bc match 
        for patch in new_bc_data:
            for arr in patch:
                np.testing.assert_array_equal(arr.data,
                 np.array(self.set_dvs[patch.fam][arr.name])
                 , err_msg=arr.name)
コード例 #2
0
ファイル: test_bcdata.py プロジェクト: joanibal/adflow
    def test_ap_bcvar_nodal_array(self):
        gridFile = os.path.join(baseDir, '../input_files/conic_conv_nozzle_mb_L4_array.cgns')
        options = copy.deepcopy(self.options)
        options['gridfile'] =  gridFile
        CFDSolver = ADFLOW(options=options)
        CFDSolver.addFamilyGroup('upstream',['inlet'])
        CFDSolver.addFamilyGroup('downstream',['outlet'])

  
        ap = self.ap
        group = 'outlet'
        BCVar = 'Pressure'
        # ap.bc_data = bc_data

        ap.setBCVar(BCVar,  70000.0, group)
        ap.addDV(BCVar,  name='outlet_pressure',  familyGroup=group,)
        
        # DVs = {'outlet_pressure':123000.0}
        DVs = {'outlet_pressure':np.arange(1,5*9+1)*10**5}

        ap.setDesignVars(DVs)
        assert (ap.getBCData()[group][BCVar] == DVs['outlet_pressure']).all()

        CFDSolver.setAeroProblem(ap)
        bc_data = CFDSolver.getBCData(groupNames=[group])
        for ii, d in enumerate(bc_data.getBCArraysFlatData(BCVar, familyGroup=group)):
            assert d == DVs['outlet_pressure'][ii]
コード例 #3
0
ファイル: test_basics.py プロジェクト: joanibal/adflow
class BasicTests(unittest.TestCase):
    N_PROCS = 1

    def setUp(self):
        gridFile = 'input_files/mdo_tutorial_euler.cgns'
        options = {'gridfile': gridFile}
        self.CFDSolver = ADFLOW(options=options)

    def test_import(self):
        "Tests if mesh was read properly"
        nStates = self.CFDSolver.getStateSize()
        assert (nStates == 60480)
コード例 #4
0
ファイル: test_bcdata.py プロジェクト: joanibal/adflow
    def test_setBCData_array(self):
        gridFile = os.path.join(baseDir, '../input_files/conic_conv_nozzle_mb_L4_array.cgns')
        options = copy.deepcopy(self.options)
        options['gridfile'] =  gridFile
        CFDSolver = ADFLOW(options=options)
        CFDSolver.addFamilyGroup('upstream',['inlet'])
        CFDSolver.addFamilyGroup('downstream',['outlet'])

        bc_data = CFDSolver.getBCData(groupNames=self.set_dvs.keys())
        for patch in bc_data:
            if patch.fam in self.set_dvs: 
                for arr in patch:
                    if arr.name in self.set_dvs[patch.fam]:
                        arr.data = self.set_dvs[patch.fam][arr.name]*np.ones(arr.size)
        
        CFDSolver.setBCData(bc_data)
        bc_data = CFDSolver.getBCData(groupNames=self.set_dvs.keys())

        for patch in bc_data:
            for arr in patch:
                np.testing.assert_array_equal(arr.data, np.ones(arr.size)*
                                                self.set_dvs[patch.fam][arr.name])
コード例 #5
0
ファイル: test_bcdata.py プロジェクト: joanibal/adflow
    def test_getBCData(self):
        "Tests if mesh was read properly"
        CFDSolver = ADFLOW(options=self.options)
        CFDSolver.addFamilyGroup('upstream',['inlet'])
        CFDSolver.addFamilyGroup('downstream',['outlet'])

        bc_data = CFDSolver.getBCData(groupNames=self.initial_dvs.keys())

        ## check that the mesh bc match 
        for patch in bc_data:
            for arr in patch:
                np.testing.assert_array_equal(arr.data, np.array(self.initial_dvs[patch.fam][arr.name]))
コード例 #6
0
ファイル: test_bcdata.py プロジェクト: joanibal/adflow
    def test_ap_bcvar_array(self):
        CFDSolver = ADFLOW(options=self.options)
        CFDSolver.addFamilyGroup('upstream',['inlet'])
        CFDSolver.addFamilyGroup('downstream',['outlet'])

        ap = self.ap
        group = 'outlet'
        BCVar = 'Pressure'
        # ap.bc_data = bc_data

        ap.setBCVar(BCVar,  70000.0, group)
        ap.addDV(BCVar,  name='outlet_pressure',  familyGroup=group,)
        
        # DVs = {'outlet_pressure':123000.0}
        DVs = {'outlet_pressure':np.arange(1,6)*10**5}

        ap.setDesignVars(DVs)
        print(ap.getBCData()[group][BCVar] == DVs['outlet_pressure'])
        assert (ap.getBCData()[group][BCVar] == DVs['outlet_pressure']).all()

        CFDSolver.setAeroProblem(ap)
        bc_data = CFDSolver.getBCData(groupNames=[group])
        for ii, d in enumerate(bc_data.getBCArraysFlatData(BCVar, familyGroup=group)):
            assert d == DVs['outlet_pressure'][ii]
コード例 #7
0
ファイル: test_bcdata.py プロジェクト: joanibal/adflow
    def test_ap_bcvar_scalar(self):
        CFDSolver = ADFLOW(options=self.options)
        CFDSolver.addFamilyGroup('upstream',['inlet'])
        CFDSolver.addFamilyGroup('downstream',['outlet'])

        ap = self.ap
        group = 'outlet'
        BCVar = 'Pressure'
        # ap.bc_data = bc_data

        ap.setBCVar(BCVar,  70000.0, group)
        ap.addDV(BCVar,  name='outlet_pressure',  familyGroup=group,)
        
        DVs = {'outlet_pressure':123000.0}

        ap.setDesignVars(DVs)

        assert ap.getBCData()[group][BCVar] == DVs['outlet_pressure']

        CFDSolver.setAeroProblem(ap)
        bc_data = CFDSolver.getBCData(groupNames=[group])
        
        for d in bc_data.getBCArraysFlatData(BCVar, familyGroup=group):
            assert d == DVs['outlet_pressure']
コード例 #8
0
    def setUp(self):
        gridFile = os.path.join(baseDir, '../input_files/pipe.cgns')
        self.options = {'gridfile': gridFile,
                        'mgcycle':'sg',
                        'ncycles':1000,
                        'useanksolver':True,
                        'usenksolver':True,
                        '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.force = 600
        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=self.force )
コード例 #9
0
ファイル: test18.py プロジェクト: joanibal/adflow
    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')
コード例 #10
0
ファイル: test16.py プロジェクト: joanibal/adflow
    def regression_test(self, handler):
        '''
        This is where the actual testing happens.
        '''
        gridFile = 'input_files/euler_conv_nozzle.cgns'

        options = copy.copy(adflowDefOpts)
        options.update({
            'gridfile': gridFile,
            'equationType': 'euler',
            'smoother': 'dadi',
            'liftIndex': 2,
            'CFL': 3.,
            'CFLCoarse': 1.5,
            'MGCycle': 'sg',
            'MGStartLevel': 1,
            'nCyclesCoarse': 500,
            'nCycles': 2500,
            'monitorvariables': ['resrho', 'cl', 'cd', 'yplus'],
            'nsubiterturb': 3,
            'useNKSolver': True,
            'NKSubSpaceSize': 60,
            'L2Convergence': 1e-14,
            'L2ConvergenceCoarse': 1e-2,
            'NKSwitchTol': 1e-2,
            'nkadpc': False,
            'vis4': 0.006,
            'vis2': 0.0,
            'blocksplitting': True,
            'solutionPrecision': 'double',
            'flowtype': 'internal',
            'useblockettes': False
        })

        # Setup aeroproblem
        ap = AeroProblem(
            name='conv_nozzle',
            alpha=00.0,
            mach=0.25,
            T=500,
            P=79326.7,
            areaRef=1.,
            chordRef=2.,
            R=287.87,
            evalFuncs=[
                'mdot', 'mdot_up', 'mdot_down', 'mavgptot_up', 'mavgptot_down',
                'aavgptot_up', 'aavgptot_down', 'mavgttot_up', 'mavgttot_down',
                'mavgps_up', 'mavgps_down', 'aavgps_up', 'aavgps_down',
                'mavgmn_up', 'mavgmn_down', 'thrust', 'thrust_pressure',
                'thrust_viscous', 'thrust_momentum'
            ])

        # Create the solver
        CFDSolver = ADFLOW(options=options)
        CFDSolver.addFamilyGroup('upstream', ['INFLOW'])
        CFDSolver.addFamilyGroup('downstream', ['OUTFLOW'])
        CFDSolver.addFamilyGroup('all_flow', ['INFLOW', 'OUTFLOW'])

        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.addFunction('mavgmn', 'downstream', name="mavgmn_down")
        CFDSolver.addFunction('mavgmn', 'upstream', name="mavgmn_up")

        CFDSolver.addFunction(
            'drag', 'all_flow',
            name="thrust")  # this naming makes it seem like wishful thinking

        CFDSolver.addFunction('dragpressure',
                              'all_flow',
                              name="thrust_pressure")
        CFDSolver.addFunction('dragviscous', 'all_flow', name="thrust_viscous")
        CFDSolver.addFunction('dragmomentum',
                              'all_flow',
                              name="thrust_momentum")

        # Run test
        # CFDSolver.getResidual(ap)
        CFDSolver(ap)
        # Check the residual
        res = CFDSolver.getResidual(ap)
        totalR0, totalRStart, totalRFinal = CFDSolver.getResNorms()
        res /= totalR0

        handler.par_add_norm(res, 1e-10, 1e-10)

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

        funcs = {}
        CFDSolver.evalFunctions(ap, funcs)
        handler.root_add_dict(funcs, 1e-10, 1e-10)
コード例 #11
0
ファイル: test_basics.py プロジェクト: joanibal/adflow
 def setUp(self):
     gridFile = 'input_files/mdo_tutorial_euler.cgns'
     options = {'gridfile': gridFile}
     self.CFDSolver = ADFLOW(options=options)
コード例 #12
0
ファイル: test_bcdata.py プロジェクト: joanibal/adflow
    def setUp(self):
        # import petsc4py
        # petsc4py.init(arch='real-debug-gfortran-3.7.7')
        # from petsc4py import PETSc

        gridFile = os.path.join(baseDir, '../input_files/conic_conv_nozzle_mb_L4_array.cgns')
        intSurfFile = os.path.join(baseDir, '../input_files/integration_plane_viscous.fmt')

        self.options = {'gridfile': gridFile}

        self.options['mgstartlevel'] = 1
        self.options['mgstartlevel'] = 1
        self.options['mgcycle'] = 'sg'
        self.options['ncycles'] = 1
        self.options['useanksolver'] = False
        self.options['l2convergence'] = 1e-12
        ap = AeroProblem(name='nozzle_flow', alpha=90, 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',
                                'mavgttot_up', 'mavgttot_down', 'mavgttot_plane',
                                'mavgps_up', 'mavgps_down', 'mavgps_plane',
                                ])

        self.ap = ap 

        CFDSolver = ADFLOW(options=self.options)
        CFDSolver.addIntegrationSurface(intSurfFile, 'viscous_plane')
        CFDSolver.finalizeUserIntegrationSurfaces()

        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('mdot', 'viscous_plane', name="mdot_plane")

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

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

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

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

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

        self.CFDSolver= CFDSolver

        self.comm = MPI.COMM_WORLD