public void WakeModelTypeAndSettings_Test()
        {
            Continuum thisInst = new Continuum("");
            string    fileName = "C:\\Users\\liz_w\\Desktop\\Continuum 3 GUI Testing\\SaveFolder\\OneMetTABAndGrossNet_1";

            thisInst.Open(fileName + ".cfm");
            thisInst.isTest = true;
            Wake_Model wakeModel = thisInst.wakeModelList.wakeModels[0];

            thisInst.wakeModelList.RemoveWakeModel(thisInst.turbineList, thisInst.mapList, wakeModel);
            thisInst.turbineList.ClearAllTurbines();

            string turbineFile = testingFolder + "\\Turbine sites\\Findlay\\Three rows.csv"; // 12 turbine sites, 3 rows

            thisInst.LoadTurbines(turbineFile);

            // Test wake model type and settings

            Gen_WakeModel thisWake   = new Gen_WakeModel(thisInst);
            double        horizExp   = 5;
            double        ambTI      = 10;
            double        DW_Spacing = 0;
            double        CW_Spacing = 0;
            double        ambRough   = 0;
            string        crvName    = thisInst.turbineList.powerCurves[0].name;

            TurbineCollection.PowerCurve crvObject = thisInst.turbineList.powerCurves[0];
            double wakeRecharge = 0;

            Turbine.Avg_Est thisEst = new Turbine.Avg_Est();

            string outputFile = testingFolder + "\\Calc WS.csv";

            double[] wakedEsts    = new double[0];
            int      wakeModelInd = 0;

            for (int modelInd = 0; modelInd < 3; modelInd++)
            {
                for (int comboInd = 0; comboInd < 5; comboInd++)
                {
                    for (int horizInd = 0; horizInd < 2; horizInd++)
                    {
                        if (horizInd == 0)
                        {
                            horizExp = 5;
                        }
                        else if (horizInd == 1)
                        {
                            horizExp = 6;
                        }

                        thisWake.cboWakeCombo.SelectedIndex = comboInd;
                        thisWake.cboWakeModel.SelectedIndex = modelInd;
                        thisWake.cboPowerCrvs.SelectedIndex = 0;
                        thisWake.txtHorizWakeExp.Text       = horizExp.ToString();
                        thisWake.txtAmbTI.Text = ambTI.ToString();

                        if (modelInd == 1) // Deep-array model
                        {
                            DW_Spacing = 5;
                            CW_Spacing = 2;
                            ambRough   = 0.005;
                            thisWake.txtDownSpace.Text  = DW_Spacing.ToString();
                            thisWake.txtCrossSpace.Text = CW_Spacing.ToString();
                            thisWake.txtAmbRough.Text   = ambRough.ToString();
                        }
                        else
                        {
                            DW_Spacing = 0;
                            CW_Spacing = 0;
                            ambRough   = 0;
                        }

                        thisWake.GenWakeModel();

                        while (thisInst.BW_worker.DoWorkDone == false && thisInst.BW_worker.WasReturned == false)
                        {
                            Thread.Sleep(100);
                        }

                        string comboName = thisWake.cboWakeCombo.SelectedItem.ToString();
                        wakeModel = thisInst.wakeModelList.GetWakeModel(modelInd, horizExp, ambTI, DW_Spacing, CW_Spacing, ambRough, crvName, comboName);
                        thisEst   = thisInst.turbineList.turbineEsts[10].GetAvgWS_Est(wakeModel);

                        for (int i = 0; i < wakeModelInd; i++)
                        {
                            Assert.AreNotEqual(thisEst.waked.WS, wakedEsts[i], "Same estimate calculated. ModelInd:" + modelInd + ", ComboInd:" + comboInd + ", HorizInd: " + horizInd);
                        }

                        wakeModelInd++;
                        Array.Resize(ref wakedEsts, wakeModelInd);
                        wakedEsts[wakeModelInd - 1] = thisEst.waked.WS;

                        thisInst.updateThe.AllTABs(thisInst);
                        thisInst.BW_worker.Close();
                    }
                }
            }


            thisInst.Close();
        }
Ejemplo n.º 2
0
        public void Maps_Waked()
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            Continuum thisInst = new Continuum("");

            string fileName = saveFolder + "\\Maps_Waked";

            if (File.Exists(fileName + ".cfm"))
            {
                File.Delete(fileName + ".cfm");
                File.Delete(fileName + ".mdf");
                File.Delete(fileName + "_log.ldf");
            }

            thisInst.savedParams.savedFileName       = fileName + ".cfm";
            thisInst.UTM_conversions.savedDatumIndex = 0;
            thisInst.UTM_conversions.UTMZoneNumber   = 16;
            thisInst.UTM_conversions.hemisphere      = "Northern";

            thisInst.modeledHeight = 80;
            thisInst.SaveFile(true);

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Load topo data
            string topoFile = testingFolder + "\\Topo & LC\\Findlay\\Findlay Topo.tif";

            BackgroundWork.Vars_for_BW Vars_for_BW = new BackgroundWork.Vars_for_BW();
            Vars_for_BW.thisInst = thisInst;
            Vars_for_BW.Filename = topoFile;
            thisInst.BW_worker   = new BackgroundWork();
            thisInst.BW_worker.Call_BW_TopoImport(Vars_for_BW);

            while (thisInst.BW_worker.DoWorkDone == false && thisInst.BW_worker.WasReturned == false) // RunWorkerCompleted isn't getting called (?) so killing BW_Worker once it reaches end of DoWork
            {
                Thread.Sleep(1000);
            }

            if (thisInst.BW_worker.WasReturned)
            {
                Assert.Fail();
            }

            // Called in BackgroundWorker RunWorkerCompleted
            thisInst.SaveFile(true);
            thisInst.updateThe.AllTABs(thisInst);
            thisInst.BW_worker.Close();

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Load one met TAB file
            thisInst.metList.isTimeSeries = false;
            thisInst.ofdMets.FileName     = testingFolder + "\\Met TAB files\\Findlay\\Paulding Findlay coords.TAB";
            thisInst.ImportMetsTAB();

            // The following are all called in btnMetTAB_Click
            thisInst.turbineList.ClearAllWSEsts();
            thisInst.updateThe.AllTABs(thisInst);

            if (thisInst.topo.gotTopo == true)
            {
                if (thisInst.chkUseSR.Checked == true && thisInst.topo.gotSR == true)
                {
                    thisInst.topo.useSR = true;
                }
                else
                {
                    thisInst.topo.useSR = false;
                }

                if (thisInst.chk_Use_Sep.Checked == true)
                {
                    thisInst.topo.useSepMod = true;
                }
                else
                {
                    thisInst.topo.useSepMod = false;
                }

                // Call background worker to run calculations
                // In background worker, performs exposure and grid stat calculations, finds path of nodes and does site calibration.
                thisInst.BW_worker = new BackgroundWork();
                BackgroundWork.Vars_for_BW metArgs = new BackgroundWork.Vars_for_BW();
                metArgs.thisInst = thisInst;

                thisInst.BW_worker.Call_BW_MetCalcs(metArgs);

                while (thisInst.BW_worker.DoWorkDone == false && thisInst.BW_worker.WasReturned == false) // RunWorkerCompleted isn't getting called (?) so killing BW_Worker once it reaches end of DoWork
                {
                    Thread.Sleep(1000);
                }

                if (thisInst.BW_worker.WasReturned)
                {
                    Assert.Fail();
                }

                thisInst.SaveFile(true);
                thisInst.updateThe.AllTABs(thisInst);
                thisInst.BW_worker.Close();
            }

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Load one turbine
            string turbineFile = testingFolder + "\\Turbine sites\\Findlay\\Ball 2 Turbines.csv";

            thisInst.LoadTurbines(turbineFile);

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Analyze mets
            thisInst.BW_worker = new BackgroundWork();
            BackgroundWork.Vars_for_BW theArgs = new BackgroundWork.Vars_for_BW();
            theArgs.thisInst = thisInst;
            thisInst.BW_worker.Call_BW_MetCalcs(theArgs);

            while (thisInst.BW_worker.DoWorkDone == false && thisInst.BW_worker.WasReturned == false)
            {
                Thread.Sleep(1000);
            }

            if (thisInst.BW_worker.WasReturned)
            {
                Assert.Fail();
            }

            thisInst.BW_worker.Close();

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Generate turbine wind speed and gross energy estimates

            // First check that a model has been created
            if (thisInst.modelList.ModelCount == 0)
            {
                thisInst.Analyze_Mets();

                while (thisInst.BW_worker.DoWorkDone == false && thisInst.BW_worker.WasReturned == false)
                {
                    Thread.Sleep(1000);
                }

                if (thisInst.BW_worker.WasReturned)
                {
                    Assert.Fail();
                }

                thisInst.BW_worker.Close();
            }


            BackgroundWork.Vars_for_TurbCalcs argsForBW = new BackgroundWork.Vars_for_TurbCalcs();

            argsForBW.thisInst      = thisInst;
            argsForBW.thisWakeModel = null;

            // Call background worker to run calculations
            thisInst.BW_worker   = new BackgroundWork();
            MCP_Method           = thisInst.Get_MCP_Method();
            argsForBW.MCP_Method = MCP_Method;
            thisInst.BW_worker.Call_BW_TurbCalcs(argsForBW);

            while (thisInst.BW_worker.DoWorkDone == false && thisInst.BW_worker.WasReturned == false)
            {
                Thread.Sleep(100);
            }

            if (thisInst.BW_worker.WasReturned == true)
            {
                Assert.Fail();
            }

            Assert.AreNotEqual(thisInst.turbineList.turbineEsts[0].avgWS_Est[0].freeStream.WS, 0, "Didn't calculate average WS");

            thisInst.updateThe.AllTABs(thisInst);
            thisInst.BW_worker.Close();

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Load a power curve
            string powerCurveFile = testingFolder + "\\Power Curves\\GE_1_85_CRV.csv";

            thisInst.ofdPowerCurve.FileName = powerCurveFile;
            thisInst.turbineList.ImportPowerCurve(thisInst, 87, 16);

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Do Exceedance calcs
            // Delete 10 of the curves to speed up calcs
            for (int i = 0; i < 10; i++)
            {
                thisInst.turbineList.exceed.Delete_Exceed(thisInst.lstDefinedLosses.Items[i].Text);
            }

            // Reduce the number simulations to 1000
            thisInst.turbineList.exceed.numSims = 1000;

            BackgroundWork.Vars_for_BW varsForBW = new BackgroundWork.Vars_for_BW();
            varsForBW.thisInst = thisInst;
            thisInst.BW_worker = new BackgroundWork();
            thisInst.BW_worker.Call_BW_Exceed(varsForBW);

            while (thisInst.BW_worker.DoWorkDone == false && thisInst.BW_worker.WasReturned == false)
            {
                Thread.Sleep(100);
            }

            if (thisInst.BW_worker.WasReturned == true)
            {
                Assert.Fail();
            }

            Assert.AreEqual(thisInst.turbineList.exceed.compositeLoss.isComplete, true, "Didn't do Monte Carlo model");

            thisInst.updateThe.AllTABs(thisInst);
            thisInst.BW_worker.Close();

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Create Eddy Viscosity Wake Model
            Gen_WakeModel thisWake = new Gen_WakeModel(thisInst);

            thisWake.cboWakeCombo.SelectedIndex = 0;

            thisWake.cboWakeModel.SelectedIndex = 0;
            thisWake.cboPowerCrvs.SelectedIndex = 0;
            thisWake.txtHorizWakeExp.Text       = "5";
            thisWake.txtAmbTI.Text = "10";


            thisWake.GenWakeModel();

            while (thisInst.BW_worker.DoWorkDone == false && thisInst.BW_worker.WasReturned == false)
            {
                Thread.Sleep(100);
            }

            Assert.AreEqual(thisInst.wakeModelList.NumWakeModels, 1, "Didn't create a wake model");

            thisInst.updateThe.AllTABs(thisInst);
            thisInst.BW_worker.Close();


            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Create wake map
            GenWakeMap wakeMap = new GenWakeMap(thisInst);

            numMaps = thisInst.wakeModelList.NumCompleteWakeGridMaps;
            wakeMap.cboWakeModels.Items.Clear();
            for (int i = 0; i <= thisInst.wakeModelList.NumWakeModels - 1; i++)
            {
                string Wake_String = thisInst.wakeModelList.CreateWakeModelString(thisInst.wakeModelList.wakeModels[i]);
                wakeMap.cboWakeModels.Items.Add(Wake_String);
            }

            wakeMap.cboWakeModels.SelectedIndex    = 0;
            wakeMap.cboUseTimeSeries.SelectedIndex = 0; // Use Avg Dist.
            wakeMap.gridReso = 250;
            wakeMap.UpdateLimits();
            wakeMap.GetCoordsAroundTurbs();
            wakeMap.GenerateWakeMap();

            while (thisInst.BW_worker.DoWorkDone == false)
            {
                Thread.Sleep(100);
            }

            thisInst.updateThe.AllTABs(thisInst);
            thisInst.BW_worker.Close();

            Assert.AreEqual(thisInst.wakeModelList.NumCompleteWakeGridMaps, numMaps + 1, "Didn't create waked map");

            thisInst.SaveFile(true);
            thisInst.Close();
        }