예제 #1
0
    def test_opt_bug1(self):
        # Due to a new feature, there is a TypeError when you optimize a model without a constraint.
        optProb = Optimization("Paraboloid", objfunc_no_con)

        # Design Variables
        optProb.addVarGroup("x", 1, varType="c", lower=-50.0, upper=50.0, value=0.0)
        optProb.addVarGroup("y", 1, varType="c", lower=-50.0, upper=50.0, value=0.0)

        # Objective
        optProb.addObj("obj")

        test_name = "bugfix_SNOPT_bug1"
        optOptions = {
            "Major feasibility tolerance": 1e-1,
            "Print file": f"{test_name}.out",
            "Summary file": f"{test_name}_summary.out",
        }

        # Optimizer
        try:
            opt = SNOPT(options=optOptions)
        except Error as e:
            if "There was an error importing" in e.message:
                raise unittest.SkipTest("Optimizer not available: SNOPT")
            raise e

        opt(optProb, sens=sens)
    def test_sens(self):
        termcomp = TerminateComp(max_sens=3)
        optProb = Optimization("Paraboloid", termcomp.objfunc)

        optProb.addVarGroup("x", 1, type="c", lower=-50.0, upper=50.0, value=0.0)
        optProb.addVarGroup("y", 1, type="c", lower=-50.0, upper=50.0, value=0.0)
        optProb.finalizeDesignVariables()

        optProb.addObj("obj")

        optProb.addConGroup("con", 1, lower=-15.0, upper=-15.0, wrt=["x", "y"], linear=True, jac=con_jac)

        test_name = "SNOPT_user_termination_sens"
        optOptions = {
            "Print file": "{}.out".format(test_name),
            "Summary file": "{}_summary.out".format(test_name),
        }
        try:
            opt = SNOPT(options=optOptions)
        except Error:
            raise unittest.SkipTest("Optimizer not available: SNOPT")

        sol = opt(optProb, sens=termcomp.sens)

        self.assertEqual(termcomp.sens_count, 4)

        # Exit code for user requested termination.
        self.assertEqual(sol.optInform["value"], 71)
예제 #3
0
    def test_opt(self):
        # Optimization Object
        optProb = Optimization("Paraboloid", objfunc)

        # Design Variables
        optProb.addVarGroup("x", 1, varType="c", lower=-50.0, upper=50.0, value=0.0)
        optProb.addVarGroup("y", 1, varType="c", lower=-50.0, upper=50.0, value=0.0)

        # Objective
        optProb.addObj("obj")

        # Equality Constraint
        optProb.addConGroup("con", 1, lower=-15.0, upper=-15.0, wrt=["x", "y"], linear=True, jac=con_jac)

        # Check optimization problem:
        print(optProb)
        test_name = "bugfix_SNOPT_test_opt"
        optOptions = {
            "Major feasibility tolerance": 1e-1,
            "Print file": "{}.out".format(test_name),
            "Summary file": "{}_summary.out".format(test_name),
        }

        # Optimizer
        try:
            opt = SNOPT(options=optOptions)
        except Error:
            raise unittest.SkipTest("Optimizer not available: SNOPT")

        sol = opt(optProb, sens=sens)

        # Check Solution 7.166667, -7.833334
        tol = 1e-6
        assert_allclose(sol.variables["x"][0].value, 7.166667, atol=tol, rtol=tol)
        assert_allclose(sol.variables["y"][0].value, -7.833333, atol=tol, rtol=tol)
예제 #4
0
    def test_opt(self):
        # Optimization Object
        optProb = Optimization('Paraboloid', objfunc)

        # Design Variables
        optProb.addVarGroup('x', 1, type='c', lower=-50.0, upper=50.0, value=0.0)
        optProb.addVarGroup('y', 1, type='c', lower=-50.0, upper=50.0, value=0.0)
        optProb.finalizeDesignVariables()

        # Objective
        optProb.addObj('obj')

        # Equality Constraint
        optProb.addConGroup('con', 1, lower=-15.0, upper=-15.0, wrt=['x', 'y'], linear=True, jac=con_jac)

        # Check optimization problem:
        print(optProb)


        # Optimizer
        try:
            opt = SNOPT(optOptions = {'Major feasibility tolerance' : 1e-1})
        except:
            raise unittest.SkipTest('Optimizer not available: SNOPT')

        sol = opt(optProb, sens=sens)

        # Check Solution 7.166667, -7.833334
        self.assertAlmostEqual(sol.variables['x'][0].value, 7.166667, places=6)
        self.assertAlmostEqual(sol.variables['y'][0].value, -7.833333, places=6)
    def test_obj(self):
        termcomp = TerminateComp(max_obj=2)
        optProb = Optimization("Paraboloid", termcomp.objfunc)

        optProb.addVarGroup("x",
                            1,
                            varType="c",
                            lower=-50.0,
                            upper=50.0,
                            value=0.0)
        optProb.addVarGroup("y",
                            1,
                            varType="c",
                            lower=-50.0,
                            upper=50.0,
                            value=0.0)

        optProb.addObj("obj")

        optProb.addConGroup("con",
                            1,
                            lower=-15.0,
                            upper=-15.0,
                            wrt=["x", "y"],
                            linear=True,
                            jac=con_jac)

        test_name = "SNOPT_user_termination_obj"
        optOptions = {
            "Print file": f"{test_name}.out",
            "Summary file": f"{test_name}_summary.out",
        }
        try:
            opt = SNOPT(options=optOptions)
        except Error as e:
            if "There was an error importing" in e.message:
                raise unittest.SkipTest("Optimizer not available: SNOPT")
            raise e

        sol = opt(optProb, sens=termcomp.sens)

        self.assertEqual(termcomp.obj_count, 3)

        # Exit code for user requested termination.
        self.assertEqual(sol.optInform["value"], 71)
예제 #6
0
    def test_opt_bug_print_2con(self):
        # Optimization Object
        optProb = Optimization("Paraboloid", objfunc_2con)

        # Design Variables
        optProb.addVarGroup("x", 1, varType="c", lower=-50.0, upper=50.0, value=0.0)
        optProb.addVarGroup("y", 1, varType="c", lower=-50.0, upper=50.0, value=0.0)

        # Objective
        optProb.addObj("obj")

        con_jac2 = {}
        con_jac2["x"] = -np.ones((2, 1))
        con_jac2["y"] = np.ones((2, 1))

        con_jac3 = {}
        con_jac3["x"] = -np.ones((3, 1))
        con_jac3["y"] = np.ones((3, 1))

        # Equality Constraint
        optProb.addConGroup("con", 2, lower=-15.0, upper=-15.0, wrt=["x", "y"], linear=True, jac=con_jac2)
        optProb.addConGroup("con2", 3, lower=-15.0, upper=-15.0, wrt=["x", "y"], linear=True, jac=con_jac3)

        # Check optimization problem:
        print(optProb)

        test_name = "bugfix_SNOPT_bug_print_2con"
        optOptions = {
            "Major feasibility tolerance": 1e-1,
            "Print file": f"{test_name}.out",
            "Summary file": f"{test_name}_summary.out",
        }

        # Optimizer
        try:
            opt = SNOPT(options=optOptions)
        except Error as e:
            if "There was an error importing" in e.message:
                raise unittest.SkipTest("Optimizer not available: SNOPT")
            raise e

        sol = opt(optProb, sens=sens)

        print(sol)
예제 #7
0
    def test_opt_bug1(self):
        # Due to a new feature, there is a TypeError when you optimize a model without a constraint.
        optProb = Optimization('Paraboloid', objfunc_no_con)

        # Design Variables
        optProb.addVarGroup('x', 1, type='c', lower=-50.0, upper=50.0, value=0.0)
        optProb.addVarGroup('y', 1, type='c', lower=-50.0, upper=50.0, value=0.0)
        optProb.finalizeDesignVariables()

        # Objective
        optProb.addObj('obj')

        # Optimizer
        try:
            opt = SNOPT(optOptions = {'Major feasibility tolerance' : 1e-1})
        except:
            raise unittest.SkipTest('Optimizer not available: SNOPT')

        sol = opt(optProb, sens=sens)
예제 #8
0
    def test_obj(self):
        termcomp = TerminateComp(max_obj=2)
        optProb = Optimization('Paraboloid', termcomp.objfunc)

        optProb.addVarGroup('x',
                            1,
                            type='c',
                            lower=-50.0,
                            upper=50.0,
                            value=0.0)
        optProb.addVarGroup('y',
                            1,
                            type='c',
                            lower=-50.0,
                            upper=50.0,
                            value=0.0)
        optProb.finalizeDesignVariables()

        optProb.addObj('obj')

        optProb.addConGroup('con',
                            1,
                            lower=-15.0,
                            upper=-15.0,
                            wrt=['x', 'y'],
                            linear=True,
                            jac=con_jac)

        try:
            opt = SNOPT()
        except:
            raise unittest.SkipTest('Optimizer not available: SNOPT')

        sol = opt(optProb, sens=termcomp.sens)

        self.assertEqual(termcomp.obj_count, 3)

        # Exit code for user requested termination.
        self.assertEqual(sol.optInform['value'][0], 71)
예제 #9
0
    def test_opt_bug_print_2con(self):
        # Optimization Object
        optProb = Optimization('Paraboloid', objfunc_2con)

        # Design Variables
        optProb.addVarGroup('x', 1, type='c', lower=-50.0, upper=50.0, value=0.0)
        optProb.addVarGroup('y', 1, type='c', lower=-50.0, upper=50.0, value=0.0)
        optProb.finalizeDesignVariables()

        # Objective
        optProb.addObj('obj')

        con_jac2 = {}
        con_jac2['x'] = -np.ones((2, 1))
        con_jac2['y'] = np.ones((2, 1))

        con_jac3 = {}
        con_jac3['x'] = -np.ones((3, 1))
        con_jac3['y'] = np.ones((3, 1))

        # Equality Constraint
        optProb.addConGroup('con', 2, lower=-15.0, upper=-15.0, wrt=['x', 'y'], linear=True, jac=con_jac2)
        optProb.addConGroup('con2', 3, lower=-15.0, upper=-15.0, wrt=['x', 'y'], linear=True, jac=con_jac3)

        # Check optimization problem:
        print(optProb)

        # Optimizer
        try:
            opt = SNOPT(optOptions = {'Major feasibility tolerance' : 1e-1})
        except:
            raise unittest.SkipTest('Optimizer not available: SNOPT')

        sol = opt(optProb, sens=sens)

        print(sol)
def fit(s,t,length,plot,comp,read_data,opt_print):
    global posdn
    global poslt
    global velod
    
    t2 = t+'.0'

    wfit = s+'_'+t2
    wfit2 = s+'_'+t2
    wfit3 = s+'_'+t2
    wfit4 = s+'_'+t2
    wfit5 = s+'_'+t2
    wfit6 = s+'_'+t2

    length2 = length
    length3 = length
    length4 = length
    length5 = length
    length6 = length
    wind = 15.
    wind2 = 14.
    wind3 = 12.
    wind4 = 16.

    rad = 3.
    dia = rad*2.
    tsr = float(wfit[3]+'.'+wfit[4]+wfit[5])
    rot = tsr*wind/rad
    rot2 = tsr*wind2/rad
    rot3 = tsr*wind3/rad
    rot4 = tsr*wind4/rad
    rot5 = 17.
    rot6 = 18.
    wind5 = rot5*rad/tsr
    wind6 = rot6*rad/tsr

    if comp == 'mac':
        # fdata = '/Users/ning1/Documents/Flow Lab/STAR-CCM+/NACA0021/MoveForward/test.csv'
        fdata = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/Velocity Sections/'+wfit+'.csv'
        fdata2 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel14/Velocity/'+wfit2+'.csv'
        fdata3 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel12/Velocity/'+wfit3+'.csv'
        fdata4 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel16/Velocity/'+wfit4+'.csv'
        fdata5 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot17/Velocity/'+wfit5+'.csv'
        fdata6 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot18/Velocity/'+wfit6+'.csv'
    elif comp == 'fsl':
        fdata = '/fslhome/ebtingey/compute/moveForward/Velocity/'+wfit+'.csv'
        fdata2 = '/fslhome/ebtingey/compute/moveForward/vel14/Velocity/'+wfit2+'.csv'
        fdata3 = '/fslhome/ebtingey/compute/moveForward/vel12/Velocity/'+wfit3+'.csv'
        fdata4 = '/fslhome/ebtingey/compute/moveForward/vel16/Velocity/'+wfit4+'.csv'
        fdata5 = '/fslhome/ebtingey/compute/moveForward/rot17/Velocity/'+wfit5+'.csv'
        fdata6 = '/fslhome/ebtingey/compute/moveForward/rot18/Velocity/'+wfit6+'.csv'
    elif comp == 'win':
        fdata = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//Velocity Sections//'+wfit+'.csv'
        fdata2 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel14//Velocity//'+wfit2+'.csv'
        fdata3 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel12//Velocity//'+wfit3+'.csv'
        fdata4 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel16//Velocity//'+wfit4+'.csv'
        fdata5 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//rot17//Velocity//'+wfit5+'.csv'
        fdata6 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//rot18//Velocity//'+wfit6+'.csv'



    if read_data ==1:
        posdn,poslt,velod = starccm_read(np.array([fdata]),dia,np.array([wind]),length,opt_print)
    if read_data ==2:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2]),dia,np.array([wind,wind2]),length,opt_print)
    if read_data ==3:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3]),dia,np.array([wind,wind2,wind3]),length,opt_print)
    if read_data ==4:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3,fdata4]),dia,np.array([wind,wind2,wind3,wind4]),length,opt_print)
    if read_data ==5:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3,fdata4,fdata5]),dia,np.array([wind,wind2,wind3,wind4,wind5]),length,opt_print)
    if read_data ==6:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3,fdata4,fdata5,fdata6]),dia,np.array([wind,wind2,wind3,wind4,wind5,wind6]),length,opt_print)

    if plot == True:
        if read_data ==1:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata]),dia,np.array([wind]),opt_print)
        if read_data ==2:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2]),dia,np.array([wind,wind2]),opt_print)
        if read_data ==3:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3]),dia,np.array([wind,wind2,wind3]),opt_print)
        if read_data ==4:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3,fdata4]),dia,np.array([wind,wind2,wind3,wind4]),opt_print)
        if read_data ==5:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3,fdata4,fdata5]),dia,np.array([wind,wind2,wind3,wind4,wind5]),opt_print)
        if read_data ==6:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3,fdata4,fdata5,fdata6]),dia,np.array([wind,wind2,wind3,wind4,wind5,wind6]),opt_print)

        start = length/30.
        xd = np.linspace(start,length,30)/dia



## Optimization
    optProb = Optimization('VAWTWake_Velo', obj_func)
    optProb.addObj('obj')

    spr10 = 10.0
    pow10 = 5.0
    pow20 = 0.5
    pow30 = 1.0
    spr20 = 2.0
    skw0 = 0.0
    odr0 = 2.0
    scl10 = 0.5
    scl20 = 0.1
    scl30 = 20.0

    # spr10 = 213.8593169
    # pow10 = 10.39210953
    # pow20 = 2.086951239
    # pow30 = 0.035659319
    # spr20 = 0.007589688
    # skw0 = 10.63462155
    # odr0 = 2.0
    # scl10 = 0.537566448
    # scl20 = 0.041077603
    # scl30 = 56.74689143

    param0 = np.array([spr10,pow10,pow20,pow30,spr20,skw0,odr0,scl10,scl20,scl30])

    param_l = np.array([0.,0.,0.,0.,0.,None,0.,0.,0.,0.])
    param_u = np.array([None,None,None,None,None,None,None,1.,1.,None])

    nparam = np.size(param0)
    optProb.addVarGroup('param', nparam, 'c', lower=param_l, upper=param_u, value=param0)
    
    opt = SNOPT()
    opt.setOption('Scale option',2)
    if comp == 'mac':
        opt.setOption('Print file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_summary'+s+'_'+t+'.out')
    elif comp == 'fsl':
        opt.setOption('Print file','/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_summary'+s+'_'+t+'.out')
    elif comp == 'win':
        opt.setOption('Print file','C://Users//TingeyPC//Documents//FLOW Lab//VAWTWakeModel//wake_model//data//optVel//SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','C://Users//TingeyPC//Documents//FLOW Lab//VAWTWakeModel//wake_model//data//OptVel//SNOPT_summary'+s+'_'+t+'.out')
    res = opt(optProb, sens=None)
    if opt_print == True:
        print res
    
    pow = res.fStar
    paramf = res.xStar['param']
    if opt_print == True:
        print paramf[0]
        print paramf[1]
        print paramf[2]
        print paramf[3]
        print paramf[4]
        print paramf[5]
        print paramf[6]
        print paramf[7]
        print paramf[8]
        print paramf[9]


    spr1 = paramf[0]
    pow1 = paramf[1]
    pow2 = paramf[2]
    pow3 = paramf[3]
    spr2 = paramf[4]
    skw = paramf[5]
    odr = paramf[6]
    scl1 = paramf[7]
    scl2 = paramf[8]
    scl3 = paramf[9]

    paper = False

    if plot == True:
        if paper == True:
            for i in range(30):
                name = str(i+1)
                ind = str(i)
                plt.figure(1)
                ax1 = plt.subplot(5,6,i+1)
                color = 'bo'
                color2 = 'r-'
                fs = 15
                lab = 'CFD'
                lab2 = 'Trend'
                tex = '$x/D$ = '+str("{0:.2f}".format(x[i]/dia))
                exec('xfit = np.linspace(min(pos'+name+'/dia)-1.,max(pos'+name+'/dia)+1.,500)')
                if i == 5:
                    exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                    exec('plt.plot(velo'+name+'d,pos'+name+'d,color,label=lab)')
                    skw_v,spr_v,scl_v,rat_v,spr_v = paramfit(xd[i],skw,spr,scl,rat,spr)
                    plt.plot(veldist(xfit,skw_v,spr_v,scl_v,rat_v,spr_v),xfit,'r-',linewidth=2,label=lab2)
                    plt.xlim(0.,1.5)
                    # plt.ylim(-4.,4.)
                    plt.legend(loc="upper left", bbox_to_anchor=(1,1),fontsize=fs)
                else:
                    exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                    exec('plt.plot(velo'+name+'d,pos'+name+'d,color)')
                    skw_v,spr_v,scl_v,rat_v,spr_v = paramfit(xd[i],skw,spr,scl,rat,spr)
                    plt.plot(veldist(xfit,skw_v,spr_v,scl_v,rat_v,spr_v),xfit,'r-',linewidth=2)
                    plt.xlim(0.,1.5)
                    # plt.ylim(-4.,4.)
                plt.text(0.3,0.8,tex,fontsize=fs)
                if i <= 23:
                    plt.setp(ax1.get_xticklabels(), visible=False)
                else:
                    plt.xlabel('$y/D$',fontsize=fs)
                    plt.xticks(fontsize=fs)
                if i == 0 or i == 6 or i == 12 or i == 18 or i ==24:
                    plt.ylabel(r'$u/U_\infty$',fontsize=fs)
                    plt.yticks(fontsize=fs)
                else:
                    plt.setp(ax1.get_yticklabels(), visible=False)


        elif paper == False:
            for i in range(30):
                name = str(i+1)
                plt.figure(1)
                plt.subplot(5,6,i+1)
                color = 'bo'
                exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                exec('plt.plot(velo'+name+'d,pos'+name+'d,color)')
                plt.plot(veldist(xd[i],xfit,spr1,pow1,pow2,pow3,spr2,skw,odr,scl1,scl2,scl3),xfit,'r-',linewidth=2)
                plt.xlim(0.,1.5)
                # plt.ylim(-4.,4.)
                # plt.legend(loc=1)
                plt.xlabel('Normalized Velocity')
                plt.ylabel('$y/D$')
    
    return spr1,pow1,pow2,pow3,spr2,skw,odr,scl1,scl2,scl3
예제 #11
0
optProb.addConGroup("con", len(lower), lower=lower, upper=upper)

# And the 2 linear constriants
if USE_LINEAR:
    jac = np.zeros((1, 9))
    jac[0, 3] = 1.0
    jac[0, 2] = -1.0
    optProb.addConGroup("lin_con", 1, lower=-0.55, upper=0.55, wrt=["xvars"], jac={"xvars": jac}, linear=True)

# Objective
optProb.addObj("obj")

# Check optimization problem:
print(optProb)
optProb.printSparsity()

# Global Optimizer: ALPSO
opt1 = ALPSO()

# Get first Solution
sol1 = opt1(optProb)
print(sol1)

# Now run the previous solution with SNOPT
opt2 = SNOPT()
sol2 = opt2(sol1)

# Check Solution
print(sol2)
예제 #12
0
    optProb.addVarGroup('sdv1s', ords, 'c', lower=None, upper=None, value=sdv1s0)
    optProb.addVarGroup('sdv2s', ords, 'c', lower=None, upper=None, value=sdv2s0)
    optProb.addVarGroup('sdv3s', ords, 'c', lower=None, upper=None, value=sdv3s0)
    optProb.addVarGroup('sdv4s', ords, 'c', lower=None, upper=None, value=sdv4s0)
    optProb.addVarGroup('rats', ords, 'c', lower=None, upper=None, value=rats0)
    optProb.addVarGroup('tnss', ords, 'c', lower=None, upper=None, value=tnss0)
    optProb.addVarGroup('spr1s', ords, 'c', lower=None, upper=None, value=spr1s0)
    optProb.addVarGroup('spr2s', ords, 'c', lower=None, upper=None, value=spr2s0)
    optProb.addVarGroup('spr3s', ords, 'c', lower=None, upper=None, value=spr3s0)
    optProb.addVarGroup('spr4s', ords, 'c', lower=None, upper=None, value=spr4s0)
    optProb.addVarGroup('scl1s', ords, 'c', lower=None, upper=None, value=scl1s0)
    optProb.addVarGroup('scl2s', ords, 'c', lower=None, upper=None, value=scl2s0)
    optProb.addVarGroup('scl3s', ords, 'c', lower=None, upper=None, value=scl3s0)


    opt = SNOPT()
    opt.setOption('Scale option',0)
    if comp == 'mac':
        opt.setOption('Print file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptSheet/cv_cvx_SNOPT_print.out')
        opt.setOption('Summary file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptSheet/cv_cvx_SNOPT_summary.out')
    elif comp == 'fsl':
        opt.setOption('Print file','/fslhome/ebtingey/compute/VAWTWakeModel/OptSheet/cv_cvx_'+argv[1]+argv[2]+argv[3]+argv[4]+'_SNOPT_OptSheet_print.out')
        opt.setOption('Summary file','/fslhome/ebtingey/compute/VAWTWakeModel/OptSheet/cv_cvx_'+argv[1]+argv[2]+argv[3]+argv[4]+'_SNOPT_OptSheet_summary.out')
    res = opt(optProb, sens=None)
    if opt_print == True:
        print res

    error = res.fStar

    mentf = res.xStar['ment']
    sdv1tf = res.xStar['sdv1t']
    # mlab = Matlab('/Applications/MATLAB_R2014b.app/bin/matlab')
    # mlab.start()
    #
    # res = mlab.lsqcurvefit(sheet,param,posdntr,velodtr)
    # print res
    #
    # mlab.stop


    if fit_opt == 'snopt':
        optProb = Optimization('VAWTWake_Velo', obj_func)
        optProb.addObj('obj')

        optProb.addVarGroup('param', 90, 'c', lower=None, upper=None, value=param0)

        opt = SNOPT()
        opt.setOption('Scale option',2)
        if comp == 'mac':
            opt.setOption('Print file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptSheet/SNOPT_print'+str(argv[1])+str(argv[2])+str(argv[3])+'ORD'+str(argv[4])+str(argv[5])+str(argv[6])+str(argv[7])+str(argv[8])+str(argv[9])+str(argv[10])+str(argv[11])+str(argv[12])+'.out')
            opt.setOption('Summary file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptSheet/SNOPT_summary'+str(argv[1])+str(argv[2])+str(argv[3])+'ORD'+str(argv[4])+str(argv[5])+str(argv[6])+str(argv[7])+str(argv[8])+str(argv[9])+str(argv[10])+str(argv[11])+str(argv[12])+'.out')
        elif comp == 'fsl':
            opt.setOption('Print file','/fslhome/ebtingey/compute/VAWTWakeModel/CrossVal/SNOPT_Files/SNOPT_print'+str(argv[1])+str(argv[2])+str(argv[3])+'ORD'+str(argv[4])+str(argv[5])+str(argv[6])+str(argv[7])+str(argv[8])+str(argv[9])+str(argv[10])+str(argv[11])+str(argv[12])+'.out')
            opt.setOption('Summary file','/fslhome/ebtingey/compute/VAWTWakeModel/CrossVal/SNOPT_Files/SNOPT_summary'+str(argv[1])+str(argv[2])+str(argv[3])+'ORD'+str(argv[4])+str(argv[5])+str(argv[6])+str(argv[7])+str(argv[8])+str(argv[9])+str(argv[10])+str(argv[11])+str(argv[12])+'.out')
        result = opt(optProb, sens=None)

        res = result.xStar['param']

    elif fit_opt == 'scipy':
        res,_ = curve_fit(sheet,posdntr,velodtr,p0=param0,maxfev=2820000)

예제 #14
0
    omega_r = 1500  # rpm
    R_rotor = 0.705  # m
    fuel_cap = 1.0  # kg
    theta_hover = 20  # deg
    x0 = scale(
        [eng_displace, fuel_rate, omega_r, R_rotor, fuel_cap, theta_hover])
    # x0 = [ 4.3441622,   0.16620041,  0.10885692,  2.78460696,  6.76453586, 0.85782237]
    x0 = [4.61280557, 0.17376677, 0.08200489, 1.5, 7.32432873, 0.86800068]

    lb = [0, 0, 0, 0, 0, 0]
    ub = scale([1200.0, 1.0, 7500.0, 3.0, 12.0, 30.0])
    setPayload(5.0)

    #    print obj_func_print(x0)

    optimizer = SNOPT()
    # optimizer = NSGA2()
    # optimizer.setOption('maxGen', 200)

    xopt, fopt, info = optimize(obj_func, x0, lb, ub, optimizer)
    print 'SNOPT:', xopt, fopt, info

    out = obj_func_print(xopt)

    # Create the pareto frunt

    steps = 20
    payloads = np.linspace(0.0, 10.0, num=steps)
    flight_times = np.zeros(steps)
    engine_size = np.zeros(steps)
    for i in range(steps):
    optProb = Optimization('Wind_Farm_APP', obj_func)
    optProb.addObj('obj')

    # Design Variables (scaled to 1)
    nrpm = nturb*nwind
    optProb.addVarGroup('xvars', nturb, 'c', lower=xlow/100., upper=xupp/100., value=turbineX/100.) # x positions
    optProb.addVarGroup('yvars', nturb, 'c', lower=ylow/100., upper=yupp/100., value=turbineY/100.) # y positions
    optProb.addVarGroup('rpm', nrpm, 'c', lower=rpmlow/10., upper=rpmupp/10., value=rpm/10.) # rpm values

    # Constraints (scaled to 1)
    num_cons_sep = (nturb-1)*nturb/2
    optProb.addConGroup('sep', num_cons_sep, lower=0., upper=None) # separation between turbines
    num_cons_spl = nwind*nobs
    optProb.addConGroup('SPL', num_cons_spl, lower=0., upper=SPLlim/10.) # SPL limit

    opt = SNOPT()
    opt.setOption('Scale option',0)
    opt.setOption('Iterations limit',1000000)
    res = opt(optProb)
    # Printing optimization results (SNOPT format)
    print res

    # Final results (scaled back to original values)
    pow = np.array(-1*res.fStar)*1e4
    xf = res.xStar['xvars']*100.
    yf = res.xStar['yvars']*100.
    rpmf = res.xStar['rpm']*10.
    rpmfw = np.zeros((nwind,nturb))
    k = 0
    for i in range(nwind):
        for j in range(nturb):
예제 #16
0
        optProb.addVarGroup('me',
                            2,
                            lower=np.array([-1.0, 0.0]),
                            upper=np.array([0.0, 0.9]),
                            value=np.array([-0.5, 0.3]))  # , scalar=1E-1)
        optProb.addVarGroup('MU',
                            2,
                            lower=np.array([0.0, 1.5]),
                            upper=np.array([1.0, 20.0]),
                            value=np.array([0.5, 5.5]))  # , scalar=1E-1)
        optProb.addVarGroup('aU', 1, lower=0.0, upper=20.0,
                            value=5.0)  # , scalar=1E-1)
        optProb.addVarGroup('bU', 1, lower=0.0, upper=5.0,
                            value=1.66)  # , scalar=1E-1)
        optProb.addVarGroup('cos_spread', 1, lower=0.0, upper=10.0,
                            value=2.0)  # , scalar=1E-1)

    # add objective
    optProb.addObj('obj', scale=1E0)

    # initialize optimizer
    snopt = SNOPT(options={'Print file': 'SNOPT_print_tune_all.out'})

    # run optimizer
    sol = snopt(optProb, sens=None)

    # print solution
    print sol

    # plot fit
    tuning_obj_function(xdict=sol.xStar, plot=True)
def fit(s,t,length,plot,comp,read_data,opt_print):
    global posdntr
    global poslttr
    global velodtr
    
    t2 = t+'.0'

    wfit = s+'_'+t2
    wfit2 = s+'_'+t2
    wfit3 = s+'_'+t2
    wfit4 = s+'_'+t2
    wfit5 = s+'_'+t2
    wfit6 = s+'_'+t2

    length2 = length
    length3 = length
    length4 = length
    length5 = length
    length6 = length
    wind = 15.
    wind2 = 14.
    wind3 = 12.
    wind4 = 16.

    rad = 3.
    dia = rad*2.
    tsr = float(wfit[3]+'.'+wfit[4]+wfit[5])
    rot = tsr*wind/rad
    rot2 = tsr*wind2/rad
    rot3 = tsr*wind3/rad
    rot4 = tsr*wind4/rad
    rot5 = 17.
    rot6 = 18.
    wind5 = rot5*rad/tsr
    wind6 = rot6*rad/tsr

    if comp == 'mac':
        # fdata = '/Users/ning1/Documents/Flow Lab/STAR-CCM+/NACA0021/MoveForward/test.csv'
        fdata = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/Velocity Sections/'+wfit+'.csv'
        fdata2 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel14/Velocity/'+wfit2+'.csv'
        fdata3 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel12/Velocity/'+wfit3+'.csv'
        fdata4 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel16/Velocity/'+wfit4+'.csv'
        fdata5 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot17/Velocity/'+wfit5+'.csv'
        fdata6 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot18/Velocity/'+wfit6+'.csv'
    elif comp == 'fsl':
        fdata = '/fslhome/ebtingey/compute/moveForward/Velocity/'+wfit+'.csv'
        fdata2 = '/fslhome/ebtingey/compute/moveForward/vel14/Velocity/'+wfit2+'.csv'
        fdata3 = '/fslhome/ebtingey/compute/moveForward/vel12/Velocity/'+wfit3+'.csv'
        fdata4 = '/fslhome/ebtingey/compute/moveForward/vel16/Velocity/'+wfit4+'.csv'
        fdata5 = '/fslhome/ebtingey/compute/moveForward/rot17/Velocity/'+wfit5+'.csv'
        fdata6 = '/fslhome/ebtingey/compute/moveForward/rot18/Velocity/'+wfit6+'.csv'



    if read_data ==1:
        posdn,poslt,velod = starccm_read(np.array([fdata]),dia,np.array([wind]),length,opt_print)
    if read_data ==2:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2]),dia,np.array([wind,wind2]),length,opt_print)
    if read_data ==3:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3]),dia,np.array([wind,wind2,wind3]),length,opt_print)
    if read_data ==4:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3,fdata4]),dia,np.array([wind,wind2,wind3,wind4]),length,opt_print)
    if read_data ==5:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3,fdata4,fdata5]),dia,np.array([wind,wind2,wind3,wind4,wind5]),length,opt_print)
    if read_data ==6:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3,fdata4,fdata5,fdata6]),dia,np.array([wind,wind2,wind3,wind4,wind5,wind6]),length,opt_print)

    if plot == True:
        if read_data ==1:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata]),dia,np.array([wind]),opt_print)
        if read_data ==2:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2]),dia,np.array([wind,wind2]),opt_print)
        if read_data ==3:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3]),dia,np.array([wind,wind2,wind3]),opt_print)
        if read_data ==4:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3,fdata4]),dia,np.array([wind,wind2,wind3,wind4]),opt_print)
        if read_data ==5:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3,fdata4,fdata5]),dia,np.array([wind,wind2,wind3,wind4,wind5]),opt_print)
        if read_data ==6:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3,fdata4,fdata5,fdata6]),dia,np.array([wind,wind2,wind3,wind4,wind5,wind6]),opt_print)

        start = length/30.
        xd = np.linspace(start,length,30)/dia

    cvtest = 0.3
    posdntr,posdnts,poslttr,posltts,velodtr,velodts = train_test_split(posdn,poslt,velod,test_size=cvtest)

## Optimization
    optProb = Optimization('VAWTWake_Velo', obj_func)
    optProb.addObj('obj')

    men0 = 0.
    sdv10 = 0.5
    sdv20 = 0.1
    sdv30 = 10.
    sdv40 = 0.5
    rat0 = 10.
    spr0 = 10.
    bow1 = 0.5
    bow2 = 0.1
    bow3 = 20.
    bow4 = 1.
    # bow1 = -1.
    # bow2 = 1.
    # bow3 = 1.
    # bow4 = 1.
    
    param0 = np.array([men0,sdv10,sdv20,sdv30,sdv40,rat0,bow4,spr0,bow1,bow2,bow3,0.5,0.1,20.])

    param_l = np.array([None,0.,0.,0.,0.,None,0.,None,0.,0.,0.,0.])
    param_u = np.array([None,None,None,None,None,0.,None,0.,None,1.,1.,50.])

    param_l = np.array([None,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.])
    param_u = np.array([None,10.,1.,50.,None,None,None,None,1.,1.,50.,1.,1.,None])

    # param_l = np.array([None,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.])
    # param_u = np.array([None,None,None,None,None,None,None,None,None,None,None,1.,1.,None])

    # param_l = np.array([None,0.,0.,0.,0.,0.,None,0.,None,None,None,0.,0.,0.])
    # param_u = np.array([None,1.,1.,50.,None,None,None,None,None,None,None,1.,1.,50.])
    
    nparam = np.size(param0)
    optProb.addVarGroup('param', nparam, 'c', lower=param_l, upper=param_u, value=param0)
    
    opt = SNOPT()
    opt.setOption('Scale option',2)
    if comp == 'mac':
        opt.setOption('Print file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_summary'+s+'_'+t+'.out')
    elif comp == 'fsl':
        opt.setOption('Print file','/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_summary'+s+'_'+t+'.out')
    res = opt(optProb, sens=None)
    if opt_print == True:
        print res
    
    pow = res.fStar
    paramf = res.xStar['param']
    if opt_print == True:
        print paramf[0]
        print paramf[1]
        print paramf[2]
        print paramf[3]
        print paramf[4]
        print paramf[5]
        print paramf[6]
        print paramf[7]
        print paramf[8]
        print paramf[9]
        print paramf[10]
        print paramf[11]
        print paramf[12]
        print paramf[13]

    men = paramf[0]
    sdv1 = paramf[1]
    sdv2 = paramf[2]
    sdv3 = paramf[3]
    sdv4 = paramf[4]
    rat1 = paramf[5]
    rat2 = paramf[6]
    spr1 = paramf[7]
    spr2 = paramf[8]
    spr3 = paramf[9]
    spr4 = paramf[10]
    scl1 = paramf[11]
    scl2 = paramf[12]
    scl3 = paramf[13]

    cv_error = 0.
    for i in range(np.size(posdnts)):
        if posdnts[i] > 0.58:
            vel = veldist(posdnts[i],posltts[i],men,sdv1,sdv2,sdv3,sdv4,rat1,rat2,spr1,spr2,spr3,spr4,scl1,scl2,scl3)
            cv_error = cv_error + (vel-velodts[i])**2
    
    # men = np.array([paramf[0],paramf[1],paramf[2]])
    # spr = np.array([paramf[3],paramf[4],paramf[5],paramf[6]])
    # scl = np.array([paramf[7],paramf[8],paramf[9]])
    # rat = np.array([paramf[10],paramf[11]])
    # spr = np.array([paramf[12],paramf[13]])
    #
    paper = False

    if plot == True:
        if paper == True:
            for i in range(30):
                name = str(i+1)
                ind = str(i)
                plt.figure(1)
                ax1 = plt.subplot(5,6,i+1)
                color = 'bo'
                color2 = 'r-'
                fs = 15
                lab = 'CFD'
                lab2 = 'Trend'
                tex = '$x/D$ = '+str("{0:.2f}".format(x[i]/dia))
                exec('xfit = np.linspace(min(pos'+name+'/dia)-1.,max(pos'+name+'/dia)+1.,500)')
                if i == 5:
                    exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                    exec('plt.plot(velo'+name+'d,pos'+name+'d,color,label=lab)')
                    men_v,spr_v,scl_v,rat_v,spr_v = paramfit(xd[i],men,spr,scl,rat,spr)
                    plt.plot(veldist(xfit,men_v,spr_v,scl_v,rat_v,spr_v),xfit,'r-',linewidth=2,label=lab2)
                    plt.xlim(0.,1.5)
                    # plt.ylim(-4.,4.)
                    plt.legend(loc="upper left", bbox_to_anchor=(1,1),fontsize=fs)
                else:
                    exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                    exec('plt.plot(velo'+name+'d,pos'+name+'d,color)')
                    men_v,spr_v,scl_v,rat_v,spr_v = paramfit(xd[i],men,spr,scl,rat,spr)
                    plt.plot(veldist(xfit,men_v,spr_v,scl_v,rat_v,spr_v),xfit,'r-',linewidth=2)
                    plt.xlim(0.,1.5)
                    # plt.ylim(-4.,4.)
                plt.text(0.3,0.8,tex,fontsize=fs)
                if i <= 23:
                    plt.setp(ax1.get_xticklabels(), visible=False)
                else:
                    plt.xlabel('$y/D$',fontsize=fs)
                    plt.xticks(fontsize=fs)
                if i == 0 or i == 6 or i == 12 or i == 18 or i ==24:
                    plt.ylabel(r'$u/U_\infty$',fontsize=fs)
                    plt.yticks(fontsize=fs)
                else:
                    plt.setp(ax1.get_yticklabels(), visible=False)


        elif paper == False:
            for i in range(30):
                name = str(i+1)
                plt.figure(1)
                plt.subplot(5,6,i+1)
                color = 'bo'
                exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                exec('plt.plot(velo'+name+'d,pos'+name+'d,color)')
                plt.plot(veldist(xd[i],xfit,men,sdv1,sdv2,sdv3,sdv4,rat1,rat2,spr1,spr2,spr3,spr4,scl1,scl2,scl3),xfit,'r-',linewidth=2)
                plt.xlim(0.,1.5)
                # plt.ylim(-4.,4.)
                # plt.legend(loc=1)
                plt.xlabel('Normalized Velocity')
                plt.ylabel('$y/D$')
    
    return men,sdv1,sdv2,sdv3,sdv4,rat1,rat2,spr1,spr2,spr3,spr4,scl1,scl2,scl3,cv_error
 input = {'dx':dx,'dy':dy,'offset':offset,'rotate':rotate}
 funcs,_ = obj_func_grid(input)
 AEPstart = funcs['obj']
 print AEPstart
 nCalls = 0
 """Optimization"""
 optProb = Optimization('Wind_Farm_AEP', obj_func_grid)
 optProb.addObj('obj')
 optProb.addVar('dx', type='c', lower=0., upper=None, value=dx)
 optProb.addVar('dy', type='c', lower=0., upper=None, value=dy)
 optProb.addVar('offset', type='c', lower=None, upper=None, value=offset)
 optProb.addVar('rotate', type='c', lower=None, upper=None, value=rotate)
 num_cons_sep = (nTurbs-1)*nTurbs/2
 optProb.addConGroup('sep', num_cons_sep, lower=0., upper=None)
 optProb.addConGroup('bound', nTurbs, lower=0., upper=None)
 opt = SNOPT()
 opt.setOption('Scale option',0)
 opt.setOption('Iterations limit',1000000)
 opt.setOption('Summary file','summary_grid.out')
 opt.setOption('Major optimality tolerance',1.e-5)
 opt.setOption('Major feasibility tolerance',1.e-6)
 res = opt(optProb)
 dx_f = res.xStar['dx']
 dy_f = res.xStar['dy']
 o_f = res.xStar['offset']
 r_f = res.xStar['rotate']
 # print 'dx_f: ', dx_f
 # print 'dy_f: ', dy_f
 # print 'offset_f: ', o_f
 # print 'rotate_f: ', r_f
 print nCalls
def fit(s,t,length,plot,comp,read_data,opt_print):
    global xd
    
    global pos1d
    global pos2d
    global pos3d
    global pos4d
    global pos5d
    global pos6d
    global pos7d
    global pos8d
    global pos9d
    global pos10d
    global pos11d
    global pos12d
    global pos13d
    global pos14d
    global pos15d
    global pos16d
    global pos17d
    global pos18d
    global pos19d
    global pos20d
    global pos21d
    global pos22d
    global pos23d
    global pos24d
    global pos25d
    global pos26d
    global pos27d
    global pos28d
    global pos29d
    global pos30d
    
    global velo1d
    global velo2d
    global velo3d
    global velo4d
    global velo5d
    global velo6d
    global velo7d
    global velo8d
    global velo9d
    global velo10d
    global velo11d
    global velo12d
    global velo13d
    global velo14d
    global velo15d
    global velo16d
    global velo17d
    global velo18d
    global velo19d
    global velo20d
    global velo21d
    global velo22d
    global velo23d
    global velo24d
    global velo25d
    global velo26d
    global velo27d
    global velo28d
    global velo29d
    global velo30d
    
    t2 = t+'.0'

    wfit = s+'_'+t2
    wfit2 = s+'_'+t2
    wfit3 = s+'_'+t2
    wfit4 = s+'_'+t2
    wfit5 = s+'_'+t2
    wfit6 = s+'_'+t2

    length2 = length
    length3 = length
    length4 = length
    length5 = length
    length6 = length
    wind = 15.
    wind2 = 14.
    wind3 = 12.
    wind4 = 16.

    rad = 3.
    dia = rad*2.
    tsr = float(wfit[3]+'.'+wfit[4]+wfit[5])
    rot = tsr*wind/rad
    rot2 = tsr*wind2/rad
    rot3 = tsr*wind3/rad
    rot4 = tsr*wind4/rad
    rot5 = 17.
    rot6 = 18.
    wind5 = rot5*rad/tsr
    wind6 = rot6*rad/tsr

    if comp == 'mac':
        # fdata = '/Users/ning1/Documents/Flow Lab/STAR-CCM+/NACA0021/MoveForward/test.csv'
        fdata = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/Velocity Sections/'+wfit+'.csv'
        fdata2 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel14/Velocity/'+wfit2+'.csv'
        fdata3 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel12/Velocity/'+wfit3+'.csv'
        fdata4 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel16/Velocity/'+wfit4+'.csv'
        fdata5 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot17/Velocity/'+wfit5+'.csv'
        fdata6 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot18/Velocity/'+wfit6+'.csv'
    elif comp == 'fsl':
        fdata = '/fslhome/ebtingey/compute/moveForward/Velocity/'+wfit+'.csv'
        fdata2 = '/fslhome/ebtingey/compute/moveForward/vel14/Velocity/'+wfit2+'.csv'
        fdata3 = '/fslhome/ebtingey/compute/moveForward/vel12/Velocity/'+wfit3+'.csv'
        fdata4 = '/fslhome/ebtingey/compute/moveForward/vel16/Velocity/'+wfit4+'.csv'
        fdata5 = '/fslhome/ebtingey/compute/moveForward/rot17/Velocity/'+wfit5+'.csv'
        fdata6 = '/fslhome/ebtingey/compute/moveForward/rot18/Velocity/'+wfit6+'.csv'
    elif comp == 'win':
        fdata = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//Velocity Sections//'+wfit+'.csv'
        fdata2 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel14//Velocity//'+wfit2+'.csv'
        fdata3 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel12//Velocity//'+wfit3+'.csv'
        fdata4 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel16//Velocity//'+wfit4+'.csv'
        fdata5 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//rot17//Velocity//'+wfit5+'.csv'
        fdata6 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//rot18//Velocity//'+wfit6+'.csv'



    if read_data ==1:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata]),dia,np.array([wind]),opt_print)
    if read_data ==2:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata,fdata2]),dia,np.array([wind,wind2]),opt_print)
    if read_data ==3:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata,fdata2,fdata3]),dia,np.array([wind,wind2,wind3]),opt_print)
    if read_data ==4:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata,fdata2,fdata3,fdata4]),dia,np.array([wind,wind2,wind3,wind4]),opt_print)
    if read_data ==5:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata,fdata2,fdata3,fdata4,fdata5]),dia,np.array([wind,wind2,wind3,wind4,wind5]),opt_print)
    if read_data ==6:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata,fdata2,fdata3,fdata4,fdata5,fdata6]),dia,np.array([wind,wind2,wind3,wind4,wind5,wind6]),opt_print)
    
    start = length/30.
    xd = np.linspace(start,length,30)/dia
    
    
    
## Optimization
    optProb = Optimization('VAWTWake_Velo', obj_func)
    optProb.addObj('obj')
    
    param0 = np.array([2.91638655e-04,  -1.70286993e-03 ,  2.38051673e-02 , 7.65610623e-01,6.40509205e-02  , 6.99046413e-01,   7.83484187e-01  , 4.55408268e-01, 1.18716383e-01  , 2.05484572e+01 , -2.67741935e+00  , 4.43022575e+01,-2.10925147e+00  , 3.30400554e+01])
    
    # param0 = np.array([-0.000168794,0.005413905,-0.151372907,0.194333896,-29.52514866,-5.555943879,0.350540531,106.116331,0.000304188,17.4218187,30.06169144,47.3929253,32.97190468,33.4188042])
    # param0 = np.array([-0.430957043,0.202977737,0.20361798,-0.818862214,-1.568705068,0.753568492,0.255557818,0.162385094,3.7137047,19.67995783,31.32756058,77.24259087,13.72492175,48.22628446])
    
    # param0 = np.array([-0.0002347,0.0094285,-0.2262108,0.0847296,0.7634520,5.0331194,0.3964091,6.0135974,0.0052853,19.9466507,-2.0322239,47.3381111,-1.1426171,27.5907093])
    param_l = np.array([-1.,-1,-1.,-1.,-1,-1.,0.,0.,0.,None,0.,None,0.]) 
    param_u = np.array([1.,1.,1.,1.,1.,1.,None,None,None,0.,None,0.,None])
    param_l = np.array([None,None,None,0.,0.,0.,0.,0.,0.,0.,None,0.,None,0.])
    param_u = np.array([None,None,None,None,None,None,None,None,None,None,0.,None,0.,None])
    
    nparam = np.size(param0)
    optProb.addVarGroup('param', nparam, 'c', lower=param_l, upper=param_u, value=param0)
    
    opt = SNOPT()
    opt.setOption('Scale option',2)
    if comp == 'mac':
        opt.setOption('Print file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_summary'+s+'_'+t+'.out')
    elif comp == 'fsl':
        opt.setOption('Print file','/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_summary'+s+'_'+t+'.out')
    elif comp == 'win':
        opt.setOption('Print file','C://Users//TingeyPC//Documents//FLOW Lab//VAWTWakeModel//wake_model//data//optVel//SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','C://Users//TingeyPC//Documents//FLOW Lab//VAWTWakeModel//wake_model//data//OptVel//SNOPT_summary'+s+'_'+t+'.out')
    res = opt(optProb, sens=None)
    if opt_print == True:
        print res
    
    pow = res.fStar
    paramf = res.xStar['param']
    if opt_print == True:
        print paramf[0]
        print paramf[1]
        print paramf[2]
        print paramf[3]
        print paramf[4]
        print paramf[5]
        print paramf[6]
        print paramf[7]
        print paramf[8]
        print paramf[9]
        print paramf[10]
        print paramf[11]
        print paramf[12]
        print paramf[13]
    
    men = np.array([paramf[0],paramf[1],paramf[2]])
    spr = np.array([paramf[3],paramf[4],paramf[5],paramf[6]])
    scl = np.array([paramf[7],paramf[8],paramf[9]])
    rat = np.array([paramf[10],paramf[11]])
    tns = np.array([paramf[12],paramf[13]])
    
    paper = False
    
    if plot == True:
        if paper == True:
            for i in range(30):
                name = str(i+1)
                ind = str(i)
                plt.figure(1)
                ax1 = plt.subplot(5,6,i+1)
                color = 'bo'
                color2 = 'r-'
                fs = 15
                lab = 'CFD'
                lab2 = 'Trend'
                tex = '$x/D$ = '+str("{0:.2f}".format(x[i]/dia))
                exec('xfit = np.linspace(min(pos'+name+'/dia)-1.,max(pos'+name+'/dia)+1.,500)')
                if i == 5:
                    exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                    exec('plt.plot(velo'+name+'d,pos'+name+'d,color,label=lab)')
                    men_v,spr_v,scl_v,rat_v,tns_v = paramfit(xd[i],men,spr,scl,rat,tns)
                    plt.plot(veldist(xfit,men_v,spr_v,scl_v,rat_v,tns_v),xfit,'r-',linewidth=2,label=lab2)
                    plt.xlim(0.,1.5)
                    # plt.ylim(-4.,4.)
                    plt.legend(loc="upper left", bbox_to_anchor=(1,1),fontsize=fs)
                else:
                    exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                    exec('plt.plot(velo'+name+'d,pos'+name+'d,color)')
                    men_v,spr_v,scl_v,rat_v,tns_v = paramfit(xd[i],men,spr,scl,rat,tns)
                    plt.plot(veldist(xfit,men_v,spr_v,scl_v,rat_v,tns_v),xfit,'r-',linewidth=2)
                    plt.xlim(0.,1.5)
                    # plt.ylim(-4.,4.)
                plt.text(0.3,0.8,tex,fontsize=fs)
                if i <= 23:
                    plt.setp(ax1.get_xticklabels(), visible=False)
                else:
                    plt.xlabel('$y/D$',fontsize=fs)
                    plt.xticks(fontsize=fs)
                if i == 0 or i == 6 or i == 12 or i == 18 or i ==24:
                    plt.ylabel(r'$u/U_\infty$',fontsize=fs)
                    plt.yticks(fontsize=fs)
                else:
                    plt.setp(ax1.get_yticklabels(), visible=False)


        elif paper == False:
            for i in range(30):
                name = str(i+1)
                plt.figure(1)
                plt.subplot(5,6,i+1)
                color = 'bo'
                exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                exec('plt.plot(velo'+name+'d,pos'+name+'d,color)')
                men_v,spr_v,scl_v,rat_v,tns_v = paramfit(xd[i],men,spr,scl,rat,tns)
                plt.plot(veldist(xfit,men_v,spr_v,scl_v,rat_v,tns_v),xfit,'r-',linewidth=2)
                plt.xlim(0.,1.5)
                # plt.ylim(-4.,4.)
                # plt.legend(loc=1)
                plt.xlabel('Normalized Velocity')
                plt.ylabel('$y/D$')
    
    return men,spr,scl,rat,tns
예제 #20
0
    prob['model_params:n_std_dev'] = 4.
    # prob['model_params:m'] = 0.33
    # prob['model_params:Dw0'] = 1.3

    tuning_obj_function(plot=True)

    # initialize optimization problem
    optProb = Optimization('Tuning Gaussian Model to SOWFA', tuning_obj_function)
    optProb.addVarGroup('ke', 1, lower=0.0, upper=1.0, value=0.152, scalar=1)
    # optProb.addVarGroup('spread_angle', 1, lower=0.0, upper=30.0, value=3.0, scalar=1)
    optProb.addVarGroup('rotation_offset_angle', 1, lower=0.0, upper=5.0, value=1.5, scalar=1)
    # optProb.addVarGroup('ky', 1, lower=0.0, upper=20.0, value=0.1, scalar=1E-4)
    # optProb.addVarGroup('Dw0', 3, lower=np.zeros(3), upper=np.ones(3)*20., value=np.array([1.3, 1.3, 1.3]))#, scalar=1E-2)
    # optProb.addVarGroup('m', 1, lower=0.1, upper=20.0, value=0.33, scalar=1E-3)

    # add objective
    optProb.addObj('obj', scale=1E-3)

    # initialize optimizer
    snopt = SNOPT()

    # run optimizer
    sol = snopt(optProb, sens='FD')

    print sol

    # tuning_obj_function(xdict={'ke': sol.xStar['ke'], 'spread_angle': sol.xStar['spread_angle'],
    #                            'rotation_offset_angle': sol.xStar['rotation_offset_angle'],
    #                            'ky': sol.xStar['ky']}, plot=True)

    tuning_obj_function(xdict=sol.xStar, plot=True)
예제 #21
0
 xlow = points[0]-spacing*area
 xupp = points[-1]+spacing*area
 ylow = points[0]-spacing*area
 yupp = points[-1]+spacing*area
 
 optProb = Optimization('VAWT_Power', obj_func)
 optProb.addObj('obj')
 
 n = np.size(x0)
 optProb.addVarGroup('xvars', n, 'c', lower=xlow, upper=xupp, value=x0)
 optProb.addVarGroup('yvars', n, 'c', lower=ylow, upper=yupp, value=y0)
 
 num_cons_sep = (n-1)*n/2
 optProb.addConGroup('sep', num_cons_sep, lower=0, upper=None)
 
 opt = SNOPT()
 opt.setOption('Scale option',0)
 res = opt(optProb, sens=None)
 print res
 
 pow = np.array(-1*res.fStar)
 xf = res.xStar['xvars']
 yf = res.xStar['yvars']
 power_turb = funcs['power_turb']
 veleff = funcs['veleff']
 
 print 'The power is:',pow,'kJ'
 print 'The isolated power is:',power_iso*np.size(xt),'kJ'
 print 'The x-locations:',xf
 print 'The y-locations:',yf
 print 'The effective wind speeds:',veleff
def fit(s, t, length, plot, comp, read_data, opt_print):
    global posdn
    global poslt
    global velod

    t2 = t + ".0"

    wfit = s + "_" + t2
    wfit2 = s + "_" + t2
    wfit3 = s + "_" + t2
    wfit4 = s + "_" + t2
    wfit5 = s + "_" + t2
    wfit6 = s + "_" + t2

    length2 = length
    length3 = length
    length4 = length
    length5 = length
    length6 = length
    wind = 15.0
    wind2 = 14.0
    wind3 = 12.0
    wind4 = 16.0

    rad = 3.0
    dia = rad * 2.0
    tsr = float(wfit[3] + "." + wfit[4] + wfit[5])
    rot = tsr * wind / rad
    rot2 = tsr * wind2 / rad
    rot3 = tsr * wind3 / rad
    rot4 = tsr * wind4 / rad
    rot5 = 17.0
    rot6 = 18.0
    wind5 = rot5 * rad / tsr
    wind6 = rot6 * rad / tsr

    if comp == "mac":
        # fdata = '/Users/ning1/Documents/Flow Lab/STAR-CCM+/NACA0021/MoveForward/test.csv'
        fdata = "/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/Velocity Sections/" + wfit + ".csv"
        fdata2 = (
            "/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel14/Velocity/"
            + wfit2
            + ".csv"
        )
        fdata3 = (
            "/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel12/Velocity/"
            + wfit3
            + ".csv"
        )
        fdata4 = (
            "/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel16/Velocity/"
            + wfit4
            + ".csv"
        )
        fdata5 = (
            "/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot17/Velocity/"
            + wfit5
            + ".csv"
        )
        fdata6 = (
            "/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot18/Velocity/"
            + wfit6
            + ".csv"
        )
    elif comp == "fsl":
        fdata = "/fslhome/ebtingey/compute/moveForward/Velocity/" + wfit + ".csv"
        fdata2 = "/fslhome/ebtingey/compute/moveForward/vel14/Velocity/" + wfit2 + ".csv"
        fdata3 = "/fslhome/ebtingey/compute/moveForward/vel12/Velocity/" + wfit3 + ".csv"
        fdata4 = "/fslhome/ebtingey/compute/moveForward/vel16/Velocity/" + wfit4 + ".csv"
        fdata5 = "/fslhome/ebtingey/compute/moveForward/rot17/Velocity/" + wfit5 + ".csv"
        fdata6 = "/fslhome/ebtingey/compute/moveForward/rot18/Velocity/" + wfit6 + ".csv"
    elif comp == "win":
        fdata = (
            "C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//Velocity Sections//"
            + wfit
            + ".csv"
        )
        fdata2 = (
            "C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel14//Velocity//"
            + wfit2
            + ".csv"
        )
        fdata3 = (
            "C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel12//Velocity//"
            + wfit3
            + ".csv"
        )
        fdata4 = (
            "C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel16//Velocity//"
            + wfit4
            + ".csv"
        )
        fdata5 = (
            "C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//rot17//Velocity//"
            + wfit5
            + ".csv"
        )
        fdata6 = (
            "C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//rot18//Velocity//"
            + wfit6
            + ".csv"
        )

    if read_data == 1:
        posdn, poslt, velod = starccm_read(np.array([fdata]), dia, np.array([wind]), length, opt_print)
    if read_data == 2:
        posdn, poslt, velod = starccm_read(np.array([fdata, fdata2]), dia, np.array([wind, wind2]), length, opt_print)
    if read_data == 3:
        posdn, poslt, velod = starccm_read(
            np.array([fdata, fdata2, fdata3]), dia, np.array([wind, wind2, wind3]), length, opt_print
        )
    if read_data == 4:
        posdn, poslt, velod = starccm_read(
            np.array([fdata, fdata2, fdata3, fdata4]), dia, np.array([wind, wind2, wind3, wind4]), length, opt_print
        )
    if read_data == 5:
        posdn, poslt, velod = starccm_read(
            np.array([fdata, fdata2, fdata3, fdata4, fdata5]),
            dia,
            np.array([wind, wind2, wind3, wind4, wind5]),
            length,
            opt_print,
        )
    if read_data == 6:
        posdn, poslt, velod = starccm_read(
            np.array([fdata, fdata2, fdata3, fdata4, fdata5, fdata6]),
            dia,
            np.array([wind, wind2, wind3, wind4, wind5, wind6]),
            length,
            opt_print,
        )

    if plot == True:
        if read_data == 1:
            pos1d, pos2d, pos3d, pos4d, pos5d, pos6d, pos7d, pos8d, pos9d, pos10d, pos11d, pos12d, pos13d, pos14d, pos15d, pos16d, pos17d, pos18d, pos19d, pos20d, pos21d, pos22d, pos23d, pos24d, pos25d, pos26d, pos27d, pos28d, pos29d, pos30d, velo1d, velo2d, velo3d, velo4d, velo5d, velo6d, velo7d, velo8d, velo9d, velo10d, velo11d, velo12d, velo13d, velo14d, velo15d, velo16d, velo17d, velo18d, velo19d, velo20d, velo21d, velo22d, velo23d, velo24d, velo25d, velo26d, velo27d, velo28d, velo29d, velo30d = starccm_read2(
                np.array([fdata]), dia, np.array([wind]), opt_print
            )
        if read_data == 2:
            pos1d, pos2d, pos3d, pos4d, pos5d, pos6d, pos7d, pos8d, pos9d, pos10d, pos11d, pos12d, pos13d, pos14d, pos15d, pos16d, pos17d, pos18d, pos19d, pos20d, pos21d, pos22d, pos23d, pos24d, pos25d, pos26d, pos27d, pos28d, pos29d, pos30d, velo1d, velo2d, velo3d, velo4d, velo5d, velo6d, velo7d, velo8d, velo9d, velo10d, velo11d, velo12d, velo13d, velo14d, velo15d, velo16d, velo17d, velo18d, velo19d, velo20d, velo21d, velo22d, velo23d, velo24d, velo25d, velo26d, velo27d, velo28d, velo29d, velo30d = starccm_read2(
                np.array([fdata, fdata2]), dia, np.array([wind, wind2]), opt_print
            )
        if read_data == 3:
            pos1d, pos2d, pos3d, pos4d, pos5d, pos6d, pos7d, pos8d, pos9d, pos10d, pos11d, pos12d, pos13d, pos14d, pos15d, pos16d, pos17d, pos18d, pos19d, pos20d, pos21d, pos22d, pos23d, pos24d, pos25d, pos26d, pos27d, pos28d, pos29d, pos30d, velo1d, velo2d, velo3d, velo4d, velo5d, velo6d, velo7d, velo8d, velo9d, velo10d, velo11d, velo12d, velo13d, velo14d, velo15d, velo16d, velo17d, velo18d, velo19d, velo20d, velo21d, velo22d, velo23d, velo24d, velo25d, velo26d, velo27d, velo28d, velo29d, velo30d = starccm_read2(
                np.array([fdata, fdata2, fdata3]), dia, np.array([wind, wind2, wind3]), opt_print
            )
        if read_data == 4:
            pos1d, pos2d, pos3d, pos4d, pos5d, pos6d, pos7d, pos8d, pos9d, pos10d, pos11d, pos12d, pos13d, pos14d, pos15d, pos16d, pos17d, pos18d, pos19d, pos20d, pos21d, pos22d, pos23d, pos24d, pos25d, pos26d, pos27d, pos28d, pos29d, pos30d, velo1d, velo2d, velo3d, velo4d, velo5d, velo6d, velo7d, velo8d, velo9d, velo10d, velo11d, velo12d, velo13d, velo14d, velo15d, velo16d, velo17d, velo18d, velo19d, velo20d, velo21d, velo22d, velo23d, velo24d, velo25d, velo26d, velo27d, velo28d, velo29d, velo30d = starccm_read2(
                np.array([fdata, fdata2, fdata3, fdata4]), dia, np.array([wind, wind2, wind3, wind4]), opt_print
            )
        if read_data == 5:
            pos1d, pos2d, pos3d, pos4d, pos5d, pos6d, pos7d, pos8d, pos9d, pos10d, pos11d, pos12d, pos13d, pos14d, pos15d, pos16d, pos17d, pos18d, pos19d, pos20d, pos21d, pos22d, pos23d, pos24d, pos25d, pos26d, pos27d, pos28d, pos29d, pos30d, velo1d, velo2d, velo3d, velo4d, velo5d, velo6d, velo7d, velo8d, velo9d, velo10d, velo11d, velo12d, velo13d, velo14d, velo15d, velo16d, velo17d, velo18d, velo19d, velo20d, velo21d, velo22d, velo23d, velo24d, velo25d, velo26d, velo27d, velo28d, velo29d, velo30d = starccm_read2(
                np.array([fdata, fdata2, fdata3, fdata4, fdata5]),
                dia,
                np.array([wind, wind2, wind3, wind4, wind5]),
                opt_print,
            )
        if read_data == 6:
            pos1d, pos2d, pos3d, pos4d, pos5d, pos6d, pos7d, pos8d, pos9d, pos10d, pos11d, pos12d, pos13d, pos14d, pos15d, pos16d, pos17d, pos18d, pos19d, pos20d, pos21d, pos22d, pos23d, pos24d, pos25d, pos26d, pos27d, pos28d, pos29d, pos30d, velo1d, velo2d, velo3d, velo4d, velo5d, velo6d, velo7d, velo8d, velo9d, velo10d, velo11d, velo12d, velo13d, velo14d, velo15d, velo16d, velo17d, velo18d, velo19d, velo20d, velo21d, velo22d, velo23d, velo24d, velo25d, velo26d, velo27d, velo28d, velo29d, velo30d = starccm_read2(
                np.array([fdata, fdata2, fdata3, fdata4, fdata5, fdata6]),
                dia,
                np.array([wind, wind2, wind3, wind4, wind5, wind6]),
                opt_print,
            )

        start = length / 30.0
        xd = np.linspace(start, length, 30) / dia

    ## Optimization
    optProb = Optimization("VAWTWake_Velo", obj_func)
    optProb.addObj("obj")

    spr10 = 10.0
    pow10 = 10.0
    pow20 = 0.5
    pow30 = 1.0
    spr20 = 2.0
    skw0 = 0.0
    scl10 = 0.5
    scl20 = 0.1
    scl30 = 10.0

    spr10 = 10.0
    pow10 = 5.0
    pow20 = 0.5
    pow30 = 1.0
    spr20 = 2.0
    skw0 = 0.0
    scl10 = 0.5
    scl20 = 0.1
    scl30 = 20.0

    spr10 = 213.8593169
    pow10 = 10.39210953
    pow20 = 2.086951239
    pow30 = 0.035659319
    spr20 = 0.007589688
    skw0 = 10.63462155
    scl10 = 0.537566448
    scl20 = 0.041077603
    scl30 = 56.74689143

    spr10 = 100.0
    pow10 = 10.0
    pow20 = 0.5
    pow30 = 0.0  # 1.0
    spr20 = 20.0
    skw0 = 0.0
    scl10 = 0.5
    scl20 = 0.1
    scl30 = 10.0

    param0 = np.array([spr10, pow10, pow20, pow30, spr20, skw0, scl10, scl20, scl30])

    param_l = np.array([0.0, 0.0, 0.0, 0.0, 0.0, None, 0.0, 0.0, 0.0])
    param_u = np.array([None, None, None, None, None, None, 1.0, 1.0, None])

    nparam = np.size(param0)
    optProb.addVarGroup("param", nparam, "c", lower=param_l, upper=param_u, value=param0)

    opt = SNOPT()
    opt.setOption("Scale option", 2)
    if comp == "mac":
        opt.setOption(
            "Print file",
            "/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_print" + s + "_" + t + ".out",
        )
        opt.setOption(
            "Summary file",
            "/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_summary" + s + "_" + t + ".out",
        )
    elif comp == "fsl":
        opt.setOption("Print file", "/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_print" + s + "_" + t + ".out")
        opt.setOption(
            "Summary file", "/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_summary" + s + "_" + t + ".out"
        )
    elif comp == "win":
        opt.setOption(
            "Print file",
            "C://Users//TingeyPC//Documents//FLOW Lab//VAWTWakeModel//wake_model//data//optVel//SNOPT_print"
            + s
            + "_"
            + t
            + ".out",
        )
        opt.setOption(
            "Summary file",
            "C://Users//TingeyPC//Documents//FLOW Lab//VAWTWakeModel//wake_model//data//OptVel//SNOPT_summary"
            + s
            + "_"
            + t
            + ".out",
        )
    res = opt(optProb, sens=None)
    if opt_print == True:
        print res

    pow = res.fStar
    paramf = res.xStar["param"]
    if opt_print == True:
        print paramf[0]
        print paramf[1]
        print paramf[2]
        print paramf[3]
        print paramf[4]
        print paramf[5]
        print paramf[6]
        print paramf[7]
        print paramf[8]

    spr1 = paramf[0]
    pow1 = paramf[1]
    pow2 = paramf[2]
    pow3 = paramf[3]
    spr2 = paramf[4]
    skw = paramf[5]
    scl1 = paramf[6]
    scl2 = paramf[7]
    scl3 = paramf[8]

    paper = False

    if plot == True:
        if paper == True:
            for i in range(30):
                name = str(i + 1)
                ind = str(i)
                plt.figure(1)
                ax1 = plt.subplot(5, 6, i + 1)
                color = "bo"
                color2 = "r-"
                fs = 15
                lab = "CFD"
                lab2 = "Trend"
                tex = "$x/D$ = " + str("{0:.2f}".format(x[i] / dia))
                exec ("xfit = np.linspace(min(pos" + name + "/dia)-1.,max(pos" + name + "/dia)+1.,500)")
                if i == 5:
                    exec ("xfit = np.linspace(min(pos" + name + "d)-1.,max(pos" + name + "d)+1.,500)")
                    exec ("plt.plot(velo" + name + "d,pos" + name + "d,color,label=lab)")
                    skw_v, spr_v, scl_v, rat_v, spr_v = paramfit(xd[i], skw, spr, scl, rat, spr)
                    plt.plot(veldist(xfit, skw_v, spr_v, scl_v, rat_v, spr_v), xfit, "r-", linewidth=2, label=lab2)
                    plt.xlim(0.0, 1.5)
                    # plt.ylim(-4.,4.)
                    plt.legend(loc="upper left", bbox_to_anchor=(1, 1), fontsize=fs)
                else:
                    exec ("xfit = np.linspace(min(pos" + name + "d)-1.,max(pos" + name + "d)+1.,500)")
                    exec ("plt.plot(velo" + name + "d,pos" + name + "d,color)")
                    skw_v, spr_v, scl_v, rat_v, spr_v = paramfit(xd[i], skw, spr, scl, rat, spr)
                    plt.plot(veldist(xfit, skw_v, spr_v, scl_v, rat_v, spr_v), xfit, "r-", linewidth=2)
                    plt.xlim(0.0, 1.5)
                    # plt.ylim(-4.,4.)
                plt.text(0.3, 0.8, tex, fontsize=fs)
                if i <= 23:
                    plt.setp(ax1.get_xticklabels(), visible=False)
                else:
                    plt.xlabel("$y/D$", fontsize=fs)
                    plt.xticks(fontsize=fs)
                if i == 0 or i == 6 or i == 12 or i == 18 or i == 24:
                    plt.ylabel(r"$u/U_\infty$", fontsize=fs)
                    plt.yticks(fontsize=fs)
                else:
                    plt.setp(ax1.get_yticklabels(), visible=False)

        elif paper == False:
            for i in range(30):
                name = str(i + 1)
                plt.figure(1)
                plt.subplot(5, 6, i + 1)
                color = "bo"
                exec ("xfit = np.linspace(min(pos" + name + "d)-1.,max(pos" + name + "d)+1.,500)")
                exec ("plt.plot(velo" + name + "d,pos" + name + "d,color)")
                plt.plot(
                    veldist(xd[i], xfit, spr1, pow1, pow2, pow3, spr2, skw, scl1, scl2, scl3), xfit, "r-", linewidth=2
                )
                plt.xlim(0.0, 1.5)
                # plt.ylim(-4.,4.)
                # plt.legend(loc=1)
                plt.xlabel("Normalized Velocity")
                plt.ylabel("$y/D$")

    return spr1, pow1, pow2, pow3, spr2, skw, scl1, scl2, scl3
예제 #23
0
    jdist = cp.MvNormal(initial_seed, std_dev)
    collocation = StochasticCollocation(3, "Normal")
    collocation_grad = StochasticCollocation(3,
                                             "Normal",
                                             QoI_dimensions=rv_systemsize)
    threshold_factor = 0.9
    dominant_space = DimensionReduction(threshold_factor,
                                        n_arnoldi_sample=3,
                                        exact_Hessian=False)
    dominant_space.getDominantDirections(QoI, jdist)

    # Setup the problem
    optProb = Optimization('Paraboloid', objfunc)
    lower_bound = -20 * np.ones(rv_systemsize)
    upper_bound = 20 * np.ones(rv_systemsize)
    optProb.addVarGroup('xvars',
                        rv_systemsize,
                        'c',
                        lower=lower_bound,
                        upper=upper_bound,
                        value=10 * np.ones(rv_systemsize))
    optProb.addObj('obj')
    # Optimizer
    opt = SNOPT(optOptions={'Major feasibility tolerance': 1e-6})
    sol = opt(optProb, sens=sens)

    # Check Solution
    import inspect
    print(sol.fStar)
    print(sol.getDVs()['xvars'])
예제 #24
0
# Optimization Object
optProb = Optimization("Paraboloid", objfunc)

# Design Variables
optProb.addVarGroup("x", 1, type="c", lower=-50.0, upper=50.0, value=0.0)
optProb.addVarGroup("y", 1, type="c", lower=-50.0, upper=50.0, value=0.0)
optProb.finalizeDesignVariables()

# Objective
optProb.addObj("obj")

# Equality Constraint
optProb.addConGroup("con",
                    1,
                    lower=-15.0,
                    upper=-15.0,
                    wrt=["x", "y"],
                    linear=True,
                    jac=con_jac)

# Check optimization problem:
print(optProb)

# Optimizer
opt = SNOPT(optOptions={"Major feasibility tolerance": 1e-1})
sol = opt(optProb, sens=sens)

# Check Solution
print(sol)
print("Solution shoud be (x, y) = (7.166667, -7.833334)\n")
def fit(s,t,length,plot,comp,read_data,opt_print):
    global posdn
    global poslt
    global velod

    t2 = t+'.0'

    wfit = s+'_'+t2
    wfit2 = s+'_'+t2
    wfit3 = s+'_'+t2
    wfit4 = s+'_'+t2
    wfit5 = s+'_'+t2
    wfit6 = s+'_'+t2

    length2 = length
    length3 = length
    length4 = length
    length5 = length
    length6 = length
    wind = 15.
    wind2 = 14.
    wind3 = 12.
    wind4 = 16.

    rad = 3.
    dia = rad*2.
    tsr = float(wfit[3]+'.'+wfit[4]+wfit[5])
    rot = tsr*wind/rad
    rot2 = tsr*wind2/rad
    rot3 = tsr*wind3/rad
    rot4 = tsr*wind4/rad
    rot5 = 17.
    rot6 = 18.
    wind5 = rot5*rad/tsr
    wind6 = rot6*rad/tsr

    if comp == 'mac':
        # fdata = '/Users/ning1/Documents/Flow Lab/STAR-CCM+/NACA0021/MoveForward/test.csv'
        fdata = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/Velocity Sections/'+wfit+'.csv'
        fdata2 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel14/Velocity/'+wfit2+'.csv'
        fdata3 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel12/Velocity/'+wfit3+'.csv'
        fdata4 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel16/Velocity/'+wfit4+'.csv'
        fdata5 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot17/Velocity/'+wfit5+'.csv'
        fdata6 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot18/Velocity/'+wfit6+'.csv'
    elif comp == 'fsl':
        fdata = '/fslhome/ebtingey/compute/moveForward/Velocity/'+wfit+'.csv'
        fdata2 = '/fslhome/ebtingey/compute/moveForward/vel14/Velocity/'+wfit2+'.csv'
        fdata3 = '/fslhome/ebtingey/compute/moveForward/vel12/Velocity/'+wfit3+'.csv'
        fdata4 = '/fslhome/ebtingey/compute/moveForward/vel16/Velocity/'+wfit4+'.csv'
        fdata5 = '/fslhome/ebtingey/compute/moveForward/rot17/Velocity/'+wfit5+'.csv'
        fdata6 = '/fslhome/ebtingey/compute/moveForward/rot18/Velocity/'+wfit6+'.csv'
    elif comp == 'win':
        fdata = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//Velocity Sections//'+wfit+'.csv'
        fdata2 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel14//Velocity//'+wfit2+'.csv'
        fdata3 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel12//Velocity//'+wfit3+'.csv'
        fdata4 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//vel16//Velocity//'+wfit4+'.csv'
        fdata5 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//rot17//Velocity//'+wfit5+'.csv'
        fdata6 = 'C://Users//TingeyPC//Documents//zStar-CCM//STAR-CCM//NACA0021//MoveForward//CrossValidate//rot18//Velocity//'+wfit6+'.csv'



    if read_data ==1:
        posdn,poslt,velod = starccm_read(np.array([fdata]),dia,np.array([wind]),length,opt_print)
    if read_data ==2:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2]),dia,np.array([wind,wind2]),length,opt_print)
    if read_data ==3:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3]),dia,np.array([wind,wind2,wind3]),length,opt_print)
    if read_data ==4:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3,fdata4]),dia,np.array([wind,wind2,wind3,wind4]),length,opt_print)
    if read_data ==5:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3,fdata4,fdata5]),dia,np.array([wind,wind2,wind3,wind4,wind5]),length,opt_print)
    if read_data ==6:
        posdn,poslt,velod = starccm_read(np.array([fdata,fdata2,fdata3,fdata4,fdata5,fdata6]),dia,np.array([wind,wind2,wind3,wind4,wind5,wind6]),length,opt_print)

    if plot == True:
        if read_data ==1:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata]),dia,np.array([wind]),opt_print)
        if read_data ==2:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2]),dia,np.array([wind,wind2]),opt_print)
        if read_data ==3:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3]),dia,np.array([wind,wind2,wind3]),opt_print)
        if read_data ==4:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3,fdata4]),dia,np.array([wind,wind2,wind3,wind4]),opt_print)
        if read_data ==5:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3,fdata4,fdata5]),dia,np.array([wind,wind2,wind3,wind4,wind5]),opt_print)
        if read_data ==6:
            pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read2(np.array([fdata,fdata2,fdata3,fdata4,fdata5,fdata6]),dia,np.array([wind,wind2,wind3,wind4,wind5,wind6]),opt_print)

        start = length/30.
        xd = np.linspace(start,length,30)/dia



## Optimization
    optProb = Optimization('VAWTWake_Velo', obj_func)
    optProb.addObj('obj')

    men0 = 0.
    sdv10 = 0.5
    sdv20 = 0.1
    sdv30 = 10.
    sdv40 = 0.5
    rat0 = 10.
    wdt0 = 10.
    spr10 = 0.5
    spr20 = 0.1
    spr30 = 20.
    spr40 = 1.
    scl10 = 0.5
    scl20 = 0.1
    scl30 = 40.


    # men0 = 0.107980482
    # sdv10 = 5.09E-01
    # sdv20 = 0.056288195
    # sdv30 = 50
    # sdv40 = 0.5
    # rat0 = 13.19127977
    # wdt0 = 14.20436344
    # spr10 = 1
    # spr20 = 0.010825
    # spr30 = 132.4282087
    # spr40 = 1
    # scl10 = 0.365635251
    # scl20 = 0.082475724
    # scl30 = 37.61946447

    men0 = -0.0138439642406
    sdv10 = 0.0
    sdv20 = 0.17803796067
    sdv30 = 9.69044107271
    sdv40 = 0.50982003115
    rat0 = 0.0
    wdt0 = 10.0
    spr10 = 0.998862596849
    spr20 = 1.47011550439e-05
    spr30 = 22.5386579407
    spr40 = 1.0
    scl10 = 0.380051328623
    scl20 = 0.134712758388
    scl30 = 45.7788575653

    men0 = -0.0384248691061
    sdv10 = 0.0
    sdv20 = 0.17803796067
    sdv30 = 9.69044107271
    sdv40 = 0.81447171018
    rat0 = 0.0
    wdt0 = 10.0
    spr10 = 0.0232236137751
    spr20 = 0.0
    spr30 = 12.6315271162
    spr40 = 9.75322269238
    scl10 = 0.357152390403
    scl20 = 0.135756021609
    scl30 = 33.8432403717




    param0 = np.array([men0,sdv10,sdv20,sdv30,sdv40,rat0,wdt0,spr10,spr20,spr30,spr40,scl10,scl20,scl30])

    param_l = np.array([None,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.])
    param_u = np.array([None,10.,1.,50.,None,None,None,1.,1.,50.,None,1.,1.,None])

    # param_l = np.array([None,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.])
    # param_u = np.array([None,10.,1.,None,None,None,None,None,None,None,None,1.,1.,None])

    # param_l = np.array([None,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.])
    # param_u = np.array([None,None,None,None,None,None,None,None,None,None,None,1.,1.,None])

    nparam = np.size(param0)
    optProb.addVarGroup('param', nparam, 'c', lower=param_l, upper=param_u, value=param0)

    opt = SNOPT()
    opt.setOption('Scale option',2)
    if comp == 'mac':
        opt.setOption('Print file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_summary'+s+'_'+t+'.out')
    elif comp == 'fsl':
        opt.setOption('Print file','/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_summary'+s+'_'+t+'.out')
    elif comp == 'win':
        opt.setOption('Print file','C://Users//TingeyPC//Documents//FLOW Lab//VAWTWakeModel//wake_model//data//optVel//SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','C://Users//TingeyPC//Documents//FLOW Lab//VAWTWakeModel//wake_model//data//OptVel//SNOPT_summary'+s+'_'+t+'.out')
    res = opt(optProb, sens=None)
    if opt_print == True:
        print res

    pow = res.fStar
    paramf = res.xStar['param']
    if opt_print == True:
        print paramf[0]
        print paramf[1]
        print paramf[2]
        print paramf[3]
        print paramf[4]
        print paramf[5]
        print paramf[6]
        print paramf[7]
        print paramf[8]
        print paramf[9]
        print paramf[10]
        print paramf[11]
        print paramf[12]
        print paramf[13]

    men = paramf[0]
    sdv1 = paramf[1]
    sdv2 = paramf[2]
    sdv3 = paramf[3]
    sdv4 = paramf[4]
    rat = paramf[5]
    wdt = paramf[6]
    spr1 = paramf[7]
    spr2 = paramf[8]
    spr3 = paramf[9]
    spr4 = paramf[10]
    scl1 = paramf[11]
    scl2 = paramf[12]
    scl3 = paramf[13]

    paper = False

    if plot == True:
        if paper == True:
            for i in range(30):
                name = str(i+1)
                ind = str(i)
                plt.figure(1)
                ax1 = plt.subplot(5,6,i+1)
                color = 'bo'
                color2 = 'r-'
                fs = 15
                lab = 'CFD'
                lab2 = 'Trend'
                tex = '$x/D$ = '+str("{0:.2f}".format(x[i]/dia))
                exec('xfit = np.linspace(min(pos'+name+'/dia)-1.,max(pos'+name+'/dia)+1.,500)')
                if i == 5:
                    exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                    exec('plt.plot(velo'+name+'d,pos'+name+'d,color,label=lab)')
                    men_v,spr_v,scl_v,rat_v,spr_v = paramfit(xd[i],men,spr,scl,rat,spr)
                    plt.plot(veldist(xfit,men_v,spr_v,scl_v,rat_v,spr_v),xfit,'r-',linewidth=2,label=lab2)
                    plt.xlim(0.,1.5)
                    # plt.ylim(-4.,4.)
                    plt.legend(loc="upper left", bbox_to_anchor=(1,1),fontsize=fs)
                else:
                    exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                    exec('plt.plot(velo'+name+'d,pos'+name+'d,color)')
                    men_v,spr_v,scl_v,rat_v,spr_v = paramfit(xd[i],men,spr,scl,rat,spr)
                    plt.plot(veldist(xfit,men_v,spr_v,scl_v,rat_v,spr_v),xfit,'r-',linewidth=2)
                    plt.xlim(0.,1.5)
                    # plt.ylim(-4.,4.)
                plt.text(0.3,0.8,tex,fontsize=fs)
                if i <= 23:
                    plt.setp(ax1.get_xticklabels(), visible=False)
                else:
                    plt.xlabel('$y/D$',fontsize=fs)
                    plt.xticks(fontsize=fs)
                if i == 0 or i == 6 or i == 12 or i == 18 or i ==24:
                    plt.ylabel(r'$u/U_\infty$',fontsize=fs)
                    plt.yticks(fontsize=fs)
                else:
                    plt.setp(ax1.get_yticklabels(), visible=False)


        elif paper == False:
            for i in range(30):
                name = str(i+1)
                plt.figure(1)
                plt.subplot(5,6,i+1)
                color = 'bo'
                exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
                exec('plt.plot(velo'+name+'d,pos'+name+'d,color)')
                plt.plot(veldist(xd[i],xfit,men,sdv1,sdv2,sdv3,sdv4,rat,wdt,spr1,spr2,spr3,spr4,scl1,scl2,scl3),xfit,'r-',linewidth=2)
                plt.xlim(0.,1.5)
                # plt.ylim(-4.,4.)
                # plt.legend(loc=1)
                plt.xlabel('Normalized Velocity')
                plt.ylabel('$y/D$')

    return men,sdv1,sdv2,sdv3,sdv4,rat,wdt,spr1,spr2,spr3,spr4,scl1,scl2,scl3
예제 #26
0
    def optimize(self,
                 sparse=True,
                 tol=None,
                 optOptions={},
                 storeHistory=False):
        # set N
        if sparse:
            self.N = 50000
        else:
            self.N = 500
        # Optimization Object
        optProb = Optimization("large and sparse", self.objfunc)

        # Design Variables
        optProb.addVar("x", lower=-100, upper=150, value=0)
        optProb.addVarGroup("y",
                            self.N,
                            lower=-10 - np.arange(self.N),
                            upper=np.arange(self.N),
                            value=0)
        optProb.addVarGroup("z",
                            2 * self.N,
                            upper=np.arange(2 * self.N),
                            lower=-100 - np.arange(2 * self.N),
                            value=0)

        # Constraints
        optProb.addCon("con1", upper=100, wrt=["x"])
        optProb.addCon("con2", upper=100)
        optProb.addCon("con3", lower=4, wrt=["x", "z"])
        xJac = np.ones((self.N, 1))
        if sparse:
            yJac = scipy.sparse.spdiags(np.ones(self.N), 0, self.N, self.N)
        else:
            yJac = np.eye(self.N)
        optProb.addConGroup(
            "lincon",
            self.N,
            lower=2 - 3 * np.arange(self.N),
            linear=True,
            wrt=["x", "y"],
            jac={
                "x": xJac,
                "y": yJac
            },
        )
        optProb.addObj("obj")

        # Optimizer
        try:
            opt = SNOPT(options=optOptions)
        except Error:
            raise unittest.SkipTest("Optimizer not available: SNOPT")

        sol = opt(optProb, sens=self.sens)

        # Check Solution
        if tol is not None:
            if opt.version != "7.7.7":
                assert_allclose(sol.objectives["obj"].value,
                                10.0,
                                atol=tol,
                                rtol=tol)
            else:
                assert_allclose(sol.fStar, 10.0, atol=tol, rtol=tol)
            assert_allclose(sol.variables["x"][0].value,
                            2.0,
                            atol=tol,
                            rtol=tol)
        return sol
예제 #27
0
    if optimize == True:
        # optimization setup
        optProb = Optimization('VAWT_Power', obj_func)
        optProb.addObj('obj')

        n = np.size(x0)
        optProb.addVarGroup('xvars', n, 'c', lower=xlow, upper=xupp, value=x0)
        optProb.addVarGroup('yvars', n, 'c', lower=ylow, upper=yupp, value=y0)

        num_cons_sep = (n - 1) * n / 2
        optProb.addConGroup('sep', num_cons_sep, lower=0, upper=None)
        num_cons_obs = nobs * nwind
        optProb.addConGroup('SPL', num_cons_obs, lower=0, upper=SPLlim / 10.)

        opt = SNOPT()
        opt.setOption('Scale option', 0)
        if rotdir_spec == 'cn':
            opt.setOption(
                'Print file',
                basepath + path.sep + 'optimization_results/SNOPT_print_SPL' +
                str(SPLlim) + '_turb' + str(n) + '_counterrot.out')
            opt.setOption(
                'Summary file', basepath + path.sep +
                'optimization_results/SNOPT_summary_SPL' + str(SPLlim) +
                '_turb' + str(n) + '_counterrot.out')
        elif rotdir_spec == 'co':
            opt.setOption(
                'Print file',
                basepath + path.sep + 'optimization_results/SNOPT_print_SPL' +
                str(SPLlim) + '_turb' + str(n) + '_corot.out')
def fit(s,t,length,plot,comp,read_data,opt_print):
    global xd
    
    global pos1tr
    global pos2tr
    global pos3tr
    global pos4tr
    global pos5tr
    global pos6tr
    global pos7tr
    global pos8tr
    global pos9tr
    global pos10tr
    global pos11tr
    global pos12tr
    global pos13tr
    global pos14tr
    global pos15tr
    global pos16tr
    global pos17tr
    global pos18tr
    global pos19tr
    global pos20tr
    global pos21tr
    global pos22tr
    global pos23tr
    global pos24tr
    global pos25tr
    global pos26tr
    global pos27tr
    global pos28tr
    global pos29tr
    global pos30tr
    
    global velo1tr
    global velo2tr
    global velo3tr
    global velo4tr
    global velo5tr
    global velo6tr
    global velo7tr
    global velo8tr
    global velo9tr
    global velo10tr
    global velo11tr
    global velo12tr
    global velo13tr
    global velo14tr
    global velo15tr
    global velo16tr
    global velo17tr
    global velo18tr
    global velo19tr
    global velo20tr
    global velo21tr
    global velo22tr
    global velo23tr
    global velo24tr
    global velo25tr
    global velo26tr
    global velo27tr
    global velo28tr
    global velo29tr
    global velo30tr
    
    t2 = t+'.0'

    wfit = s+'_'+t2
    wfit2 = s+'_'+t2
    wfit3 = s+'_'+t2
    wfit4 = s+'_'+t2
    wfit5 = s+'_'+t2
    wfit6 = s+'_'+t2

    length2 = length
    length3 = length
    length4 = length
    length5 = length
    length6 = length
    wind = 15.
    wind2 = 14.
    wind3 = 12.
    wind4 = 16.

    rad = 3.
    dia = rad*2.
    tsr = float(wfit[3]+'.'+wfit[4]+wfit[5])
    rot = tsr*wind/rad
    rot2 = tsr*wind2/rad
    rot3 = tsr*wind3/rad
    rot4 = tsr*wind4/rad
    rot5 = 17.
    rot6 = 18.
    wind5 = rot5*rad/tsr
    wind6 = rot6*rad/tsr
    
    if comp == 'mac':
        # fdata = '/Users/ning1/Documents/Flow Lab/STAR-CCM+/NACA0021/MoveForward/test.csv'
        fdata = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/Velocity Sections/'+wfit+'.csv'
        fdata2 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel14/Velocity/'+wfit2+'.csv'
        fdata3 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel12/Velocity/'+wfit3+'.csv'
        fdata4 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/vel16/Velocity/'+wfit4+'.csv'
        fdata5 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot17/Velocity/'+wfit5+'.csv'
        fdata6 = '/Users/ning1/Documents/FLOW Lab/STAR-CCM+/NACA0021/MoveForward/CrossValidate/rot18/Velocity/'+wfit6+'.csv'
    elif comp == 'fsl':
        fdata = '/fslhome/ebtingey/compute/moveForward/Velocity/'+wfit+'.csv'
        fdata2 = '/fslhome/ebtingey/compute/moveForward/vel14/Velocity/'+wfit2+'.csv'
        fdata3 = '/fslhome/ebtingey/compute/moveForward/vel12/Velocity/'+wfit3+'.csv'
        fdata4 = '/fslhome/ebtingey/compute/moveForward/vel16/Velocity/'+wfit4+'.csv'
        fdata5 = '/fslhome/ebtingey/compute/moveForward/rot17/Velocity/'+wfit5+'.csv'
        fdata6 = '/fslhome/ebtingey/compute/moveForward/rot18/Velocity/'+wfit6+'.csv'


    if read_data ==1:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata]),dia,np.array([wind]),opt_print)
    if read_data ==2:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata,fdata2]),dia,np.array([wind,wind2]),opt_print)
    if read_data ==3:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata,fdata2,fdata3]),dia,np.array([wind,wind2,wind3]),opt_print)
    if read_data ==4:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata,fdata2,fdata3,fdata4]),dia,np.array([wind,wind2,wind3,wind4]),opt_print)
    if read_data ==5:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata,fdata2,fdata3,fdata4,fdata5]),dia,np.array([wind,wind2,wind3,wind4,wind5]),opt_print)
    if read_data ==6:
        pos1d,pos2d,pos3d,pos4d,pos5d,pos6d,pos7d,pos8d,pos9d,pos10d,pos11d,pos12d,pos13d,pos14d,pos15d,pos16d,pos17d,pos18d,pos19d,pos20d,pos21d,pos22d,pos23d,pos24d,pos25d,pos26d,pos27d,pos28d,pos29d,pos30d,velo1d,velo2d,velo3d,velo4d,velo5d,velo6d,velo7d,velo8d,velo9d,velo10d,velo11d,velo12d,velo13d,velo14d,velo15d,velo16d,velo17d,velo18d,velo19d,velo20d,velo21d,velo22d,velo23d,velo24d,velo25d,velo26d,velo27d,velo28d,velo29d,velo30d = starccm_read(np.array([fdata,fdata2,fdata3,fdata4,fdata5,fdata6]),dia,np.array([wind,wind2,wind3,wind4,wind5,wind6]),opt_print)
    
    start = length/30.
    xd = np.linspace(start,length,30)/dia
    
    
    cvtest = 0.3
    pos1tr,pos1ts,velo1tr,velo1ts = train_test_split(pos1d,velo1d,test_size=cvtest)
    pos2tr,pos2ts,velo2tr,velo2ts = train_test_split(pos2d,velo2d,test_size=cvtest)
    pos3tr,pos3ts,velo3tr,velo3ts = train_test_split(pos3d,velo3d,test_size=cvtest)
    pos4tr,pos4ts,velo4tr,velo4ts = train_test_split(pos4d,velo4d,test_size=cvtest)
    pos5tr,pos5ts,velo5tr,velo5ts = train_test_split(pos5d,velo5d,test_size=cvtest)
    pos6tr,pos6ts,velo6tr,velo6ts = train_test_split(pos6d,velo6d,test_size=cvtest)
    pos7tr,pos7ts,velo7tr,velo7ts = train_test_split(pos7d,velo7d,test_size=cvtest)
    pos8tr,pos8ts,velo8tr,velo8ts = train_test_split(pos8d,velo8d,test_size=cvtest)
    pos9tr,pos9ts,velo9tr,velo9ts = train_test_split(pos9d,velo9d,test_size=cvtest)
    pos10tr,pos10ts,velo10tr,velo10ts = train_test_split(pos10d,velo10d,test_size=cvtest)
    pos11tr,pos11ts,velo11tr,velo11ts = train_test_split(pos11d,velo11d,test_size=cvtest)
    pos12tr,pos12ts,velo12tr,velo12ts = train_test_split(pos12d,velo12d,test_size=cvtest)
    pos13tr,pos13ts,velo13tr,velo13ts = train_test_split(pos13d,velo13d,test_size=cvtest)
    pos14tr,pos14ts,velo14tr,velo14ts = train_test_split(pos14d,velo14d,test_size=cvtest)
    pos15tr,pos15ts,velo15tr,velo15ts = train_test_split(pos15d,velo15d,test_size=cvtest)
    pos16tr,pos16ts,velo16tr,velo16ts = train_test_split(pos16d,velo16d,test_size=cvtest)
    pos17tr,pos17ts,velo17tr,velo17ts = train_test_split(pos17d,velo17d,test_size=cvtest)
    pos18tr,pos18ts,velo18tr,velo18ts = train_test_split(pos18d,velo18d,test_size=cvtest)
    pos19tr,pos19ts,velo19tr,velo19ts = train_test_split(pos19d,velo19d,test_size=cvtest)
    pos20tr,pos20ts,velo20tr,velo20ts = train_test_split(pos20d,velo20d,test_size=cvtest)
    pos21tr,pos21ts,velo21tr,velo21ts = train_test_split(pos21d,velo21d,test_size=cvtest)
    pos22tr,pos22ts,velo22tr,velo22ts = train_test_split(pos22d,velo22d,test_size=cvtest)
    pos23tr,pos23ts,velo23tr,velo23ts = train_test_split(pos23d,velo23d,test_size=cvtest)
    pos24tr,pos24ts,velo24tr,velo24ts = train_test_split(pos24d,velo24d,test_size=cvtest)
    pos25tr,pos25ts,velo25tr,velo25ts = train_test_split(pos25d,velo25d,test_size=cvtest)
    pos26tr,pos26ts,velo26tr,velo26ts = train_test_split(pos26d,velo26d,test_size=cvtest)
    pos27tr,pos27ts,velo27tr,velo27ts = train_test_split(pos27d,velo27d,test_size=cvtest)
    pos28tr,pos28ts,velo28tr,velo28ts = train_test_split(pos28d,velo28d,test_size=cvtest)
    pos29tr,pos29ts,velo29tr,velo29ts = train_test_split(pos29d,velo29d,test_size=cvtest)
    pos30tr,pos30ts,velo30tr,velo30ts = train_test_split(pos30d,velo30d,test_size=cvtest)
    
    
    
## Optimization
    optProb = Optimization('VAWTWake_Velo', obj_func)
    optProb.addObj('obj')
    
    param0 = np.array([2.91638655e-04,  -1.70286993e-03 ,  2.38051673e-02 , -7.65610623e-01,6.40509205e-02  , 6.99046413e-01,   7.83484187e-01  , 4.55408268e-01, 1.18716383e-01  , 2.05484572e+01 , -2.67741935e+00  , 4.43022575e+01,-2.10925147e+00  , 3.30400554e+01])
    param_l = np.array([-1.,-1,-1.,-1.,-1,-1.,0.,0.,0.,None,0.,None,0.]) 
    param_u = np.array([1.,1.,1.,1.,1.,1.,None,None,None,0.,None,0.,None])
    
    nparam = np.size(param0)
    optProb.addVarGroup('param', nparam, 'c', lower=None, upper=None, value=param0)
    
    opt = SNOPT()
    opt.setOption('Scale option',2)
    if comp == 'mac':
        opt.setOption('Print file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','/Users/ning1/Documents/FLOW Lab/VAWTWakeModel/wake_model/data/OptVel/SNOPT_summary'+s+'_'+t+'.out')
    elif comp == 'fsl':
        opt.setOption('Print file','/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_print'+s+'_'+t+'.out')
        opt.setOption('Summary file','/fslhome/ebtingey/compute/VAWTWakeModel/OptVel/SNOPT_summary'+s+'_'+t+'.out')
    res = opt(optProb, sens=None)
    if opt_print == True:
        print res
    
    pow = res.fStar
    paramf = res.xStar['param']
    if opt_print == True:
        print paramf
    
    men = np.array([paramf[0],paramf[1],paramf[2]])
    spr = np.array([paramf[3],paramf[4],paramf[5],paramf[6]])
    scl = np.array([paramf[7],paramf[8],paramf[9]])
    rat = np.array([paramf[10],paramf[11]])
    tns = np.array([paramf[12],paramf[13]])
    
    cv_error = 0.
    for i in range(30):
        name = str(i+1)
        ind = str(i)
        exec('if xd['+ind+'] > 0.58:\n\tmen_v,spr_v,scl_v,rat_v,tns_v = paramfit(xd['+ind+'],men,spr,scl,rat,tns)\n\tfor j in range(np.size(pos'+name+'ts)):\n\t\tvel = (-scl_v/(spr_v*sqrt(2.*pi))*exp(-(pos'+name+'ts[j]+men_v)**2/(2.*spr_v**2)))*(1./(1. + exp(rat_v*fabs(pos'+name+'ts[j])-tns_v))) + 1.\n\t\tcv_error = cv_error + (vel-velo'+name+'ts[j])**2')
        
    
    if plot == True:
        for i in range(30):
            name = str(i+1)
            plt.figure(1)
            plt.subplot(5,6,i+1)
            color = 'bo'
            exec('xfit = np.linspace(min(pos'+name+'d)-1.,max(pos'+name+'d)+1.,500)')
            exec('plt.plot(velo'+name+'d,pos'+name+'d,color)')
            men_v,spr_v,scl_v,rat_v,tns_v = paramfit(xd[i],men,spr,scl,rat,tns)
            plt.plot(veldist(xfit,men_v,spr_v,scl_v,rat_v,tns_v),xfit,'r-',linewidth=2)
            plt.xlim(0.,1.5)
            # plt.ylim(-4.,4.)
            # plt.legend(loc=1)
            plt.xlabel('Normalized Velocity')
            plt.ylabel('$y/D$')
    
    return men,spr,scl,rat,tns,cv_error
예제 #29
0
        """Optimization"""
        optProb = Optimization('Wind_Farm_AEP', obj_func_no_damage)
        optProb.addObj('AEP')
        # optProb.addObj('damage')

        optProb.addVarGroup('turbineX', nTurbs, type='c', lower=min(xBounds), upper=max(xBounds), value=turbineX)
        optProb.addVarGroup('turbineY', nTurbs, type='c', lower=min(yBounds), upper=max(yBounds), value=turbineY)

        num_cons_sep = (nTurbs-1)*nTurbs/2
        optProb.addConGroup('sep', num_cons_sep, lower=0., upper=None)
        optProb.addConGroup('bound', nTurbs, lower=0., upper=None)
        # optProb.addConGroup('damage', nTurbs, lower=None, upper=damage_lim)
        # optProb.addCon('damage', lower=aep_lim, upper=None)

        opt = SNOPT()
        opt.setOption('Scale option',0)
        opt.setOption('Iterations limit',1000000)

        opt.setOption('Summary file','%s/summary.out'%folder)
        opt.setOption('Major optimality tolerance',1.e-4)
        opt.setOption('Major feasibility tolerance',1.e-6)

        res = opt(optProb)

        x1 = res.xStar['turbineX']
        y1 = res.xStar['turbineY']

        input = {'turbineX':x1,'turbineY':y1}
        funcs,_ = obj_func_damage(input)
	
	for i in range(2, 3):
		print "----------------- Part: ", part[i], " -------------------"
		for j in range(0, 6):
			ub = 5.0*np.ones(len(x))
			lb = -5.0*np.ones(len(x))
			#Somthing is wrong with NSGA2 that returns segmentation fault (core dumped) when run multiple times
			#...so I did it outside the loop..
			#if part[i] == "a":
			#	optimizer = NSGA2()
			#	optimizer.setOption('maxGen', 500)
			#	optimizer.setOption('PopSize', len(x)*10)				
			#	func, _ = mul_dim_rosen(x, part[i])
			if part[i] == "b":
				func, _ = mul_dim_rosen(x, part[i])
				optimizer = SNOPT()
			elif part[i] == "c":
				optimizer = SNOPT()
				func, _, _, _ = mul_dim_rosen(x, part[i])
				
			xopt, fopt, info = optimize(mul_dim_rosen, x, lb, ub, optimizer, args = [part[i]])
			print "n: ", len(x)
			print "x_in: ", x
			print "f_in: ", func
			print "xopt: ", xopt
			print "fopt: ", fopt
			print "function calls: ", function_calls
			print "info: ", info, "\n\n"
			function_calls_array = np.append(function_calls_array, function_calls)
			x = np.append(x, x)
			function_calls = 0