//VoltVarController vc;


        #endregion

        #region [ Private Methods ]

        #region [ Read the InputData ]

        private void ReadSubAlarm(VoltVarController vc, string SubAlarmPathName)
        {
            CsvAdapter csvRead = new CsvAdapter();

            csvRead.ReadCSV(SubAlarmPathName);

            vc.SubstationAlarmDevice.Host         = csvRead.Frame[1, 0];
            vc.SubstationAlarmDevice.SwSchedId    = csvRead.Frame[1, 1];
            vc.SubstationAlarmDevice.SwSchedField = csvRead.Frame[1, 2];
            vc.SubstationAlarmDevice.SwSchedClear = csvRead.Frame[1, 3];
            vc.SubstationAlarmDevice.LtcDevice    = csvRead.Frame[1, 4];
            vc.SubstationAlarmDevice.ContFail     = csvRead.Frame[1, 5];
            vc.SubstationAlarmDevice.LtcLimit     = csvRead.Frame[1, 6];
            vc.SubstationAlarmDevice.OutService   = csvRead.Frame[1, 7];
            vc.SubstationAlarmDevice.VoltsOut     = csvRead.Frame[1, 8];
            vc.SubstationAlarmDevice.LtcProgram   = csvRead.Frame[1, 9];
            vc.SubstationAlarmDevice.ZNTX         = Convert.ToInt32(csvRead.Frame[1, 10]);
            vc.SubstationAlarmDevice.ZNCP         = Convert.ToInt32(csvRead.Frame[1, 11]);
            vc.SubstationAlarmDevice.ZVLO         = Convert.ToDouble(csvRead.Frame[1, 12]);
            vc.SubstationAlarmDevice.VLLIM        = Convert.ToDouble(csvRead.Frame[1, 13]);
            vc.SubstationAlarmDevice.VHLIM        = Convert.ToDouble(csvRead.Frame[1, 14]);
            vc.SubstationAlarmDevice.ZVHI         = Convert.ToDouble(csvRead.Frame[1, 15]);
            vc.SubstationAlarmDevice.ZHITAP       = Convert.ToInt32(csvRead.Frame[1, 16]);
            vc.SubstationAlarmDevice.ZLOTAP       = Convert.ToInt32(csvRead.Frame[1, 17]);
            vc.SubstationAlarmDevice.ZTCONS       = Convert.ToInt32(csvRead.Frame[1, 18]);
            vc.SubstationAlarmDevice.ZBAL         = Convert.ToDouble(csvRead.Frame[1, 19]);
            vc.SubstationAlarmDevice.ZLOWV        = Convert.ToDouble(csvRead.Frame[1, 20]);
            vc.SubstationAlarmDevice.ZDIFTAP      = Convert.ToDouble(csvRead.Frame[1, 21]);
        }
        private void CreateDictionary(VoltVarController vc)
        {
            vc.RawkeyValuePairs = new Dictionary <string, dynamic>();


            // Add Transformers
            foreach (VcTransformer vcTransformer in vc.ControlTransformers)
            {
                vc.RawkeyValuePairs.Add(vcTransformer.HighSideId, vcTransformer.HighSideV);
                vc.RawkeyValuePairs.Add(vcTransformer.LowSideId, vcTransformer.LowSideV);
                vc.RawkeyValuePairs.Add(vcTransformer.LocRemId, vcTransformer.LocRemV);
                vc.RawkeyValuePairs.Add(vcTransformer.MvrId, vcTransformer.MvrV);
                vc.RawkeyValuePairs.Add(vcTransformer.MwId, vcTransformer.MwV);
                vc.RawkeyValuePairs.Add(vcTransformer.ScadaSw, vcTransformer.ScadaSwV);
                vc.RawkeyValuePairs.Add(vcTransformer.TapId, vcTransformer.TapV);
                vc.RawkeyValuePairs.Add(vcTransformer.VoltsId, vcTransformer.VoltsV);
            }

            foreach (VcCapacitorBank vcCapacitorbank in vc.ControlCapacitorBanks)
            {
                vc.RawkeyValuePairs.Add(vcCapacitorbank.OpCapId, vcCapacitorbank.OpCapV);
                vc.RawkeyValuePairs.Add(vcCapacitorbank.ScadaSwId, vcCapacitorbank.ScadaSwV);
                vc.RawkeyValuePairs.Add(vcCapacitorbank.MiscId, vcCapacitorbank.MiscV);
                vc.RawkeyValuePairs.Add(vcCapacitorbank.AutoManId, vcCapacitorbank.AutoManV);
                vc.RawkeyValuePairs.Add(vcCapacitorbank.BusBkrId, vcCapacitorbank.BusBkrV);
                vc.RawkeyValuePairs.Add(vcCapacitorbank.LockvId, vcCapacitorbank.LockvV);
                vc.RawkeyValuePairs.Add(vcCapacitorbank.CapBkrId, vcCapacitorbank.CapBkrV);
            }

            // Add Generators
            vc.RawkeyValuePairs.Add(vc.SubstationInformation.G1MwId, vc.SubstationInformation.G1Mw);
            vc.RawkeyValuePairs.Add(vc.SubstationInformation.G1MvrId, vc.SubstationInformation.G1Mvr);
            vc.RawkeyValuePairs.Add(vc.SubstationInformation.G2MwId, vc.SubstationInformation.G2Mw);
            vc.RawkeyValuePairs.Add(vc.SubstationInformation.G2MvrId, vc.SubstationInformation.G2Mvr);
        }
Пример #3
0
        private VoltVarController ConTap(int i, string Control, string Description, VoltVarController vc)
        {
            vc.LtcStatus.Cfail = 0;
            //set_clear_alarm;
            if (i == -1)
            {
                m_messageInput += string.Format("CON TAP Control Deselected No control |");
            }
            else
            {
                m_messageInput += string.Format("Control Decision {0} {1} {2} |", vc.ControlTransformers[i].DeviceId,
                                                vc.ControlTransformers[i].LtcCtlId, Control);


                switch (Control)
                {
                case "RAISE":
                    vc.ControlTransformers[i].TapV += 1;
                    break;

                case "LOWER":
                    vc.ControlTransformers[i].TapV += -1;
                    break;
                }

                vc.ControlTransformers[i].PrevCtl = Control;
                vc.ControlTransformers[i].CtlDone = 1;

                vc.SubstationInformation.Ntdel     = 0; // Once the tap is operated, the delay counting is reset.
                vc.SubstationInformation.ConsecTap = 0;
            }
            // select undef, undef, undef, 1.00 delay fraction of second
            return(vc);
        }
Пример #4
0
        public VoltVarController CheckPreviousControlResults(VoltVarController vc)
        {
            // If we did any controls last time, check they had the expected results
            //  we did the controls, CLEAR CONTROL-DONE FLAG
            for (int i = 0; i < vc.SubstationAlarmDevice.ZNTX; i++)
            {
                if (vc.ControlTransformers[i].CtlDone != 0) // if Control Was Done
                {
                    double tapmove = Math.Abs(vc.ControlTransformers[i].StTapV - vc.ControlTransformers[i].TapV);
                    double mvrmove = Math.Abs(vc.ControlTransformers[i].StMvrV - vc.ControlTransformers[i].MvrV);
                    if (tapmove < 0.2 && mvrmove < 0.2)
                    {
                        m_messageInput += string.Format("Control Failed {0} {1} {2} {3} |", vc.ControlTransformers[i].DeviceId, vc.ControlTransformers[i].LtcCtlId, vc.ControlTransformers[i].PrevCtl, vc.ControlTransformers[i].TapV);
                        vc.LtcStatus.Cfail++;
                    }

                    vc.ControlTransformers[i].CtlDone = 0;
                }
            }

            if (vc.LtcStatus.Cfail > 0)
            {
                //clear control alarm
            }
            else
            {
                //clear control alarm
            }

            if (vc.LtcStatus.Nins == 1)
            {
                vc.LtcStatus.BalMvr = 0;
                vc.LtcStatus.DifTap = 0;
            }
            else if (vc.LtcStatus.Nins > 1)
            {
                vc.LtcStatus.Avv = vc.LtcStatus.Avv / vc.LtcStatus.Nins;

                // set clear alarm //

                vc.LtcStatus.BalMvr = vc.LtcStatus.MaxVar - vc.LtcStatus.MinVar;
                vc.LtcStatus.DifTap = vc.LtcStatus.MaxTap - vc.LtcStatus.MinTap;
            }
            else
            {
                // if more than one transoformer is out of service, quit and set out of service alarm
                vc.SubstationInformation.ConsecTap = 0;
                //save before exit.
            }

            if (vc.LtcStatus.Avv < vc.SubstationAlarmDevice.ZVLO || vc.LtcStatus.Avv > vc.SubstationAlarmDevice.ZVHI)
            {
                m_messageInput += string.Format("KVs are out of range = {0} must exit |", vc.LtcStatus.Avv);
                //save before exist
            }

            return(vc);
        }
        private void ReadLtcStatus(VoltVarController vc, string LtcStatusPath)
        {
            CsvAdapter csvRead = new CsvAdapter();

            csvRead.ReadCSV(LtcStatusPath);
            vc.LtcStatus.MinVar = Convert.ToDouble(csvRead.Frame[1, 0]);
            vc.LtcStatus.MaxVar = Convert.ToDouble(csvRead.Frame[1, 1]);
            vc.LtcStatus.MinTap = Convert.ToInt32(csvRead.Frame[1, 2]);
            vc.LtcStatus.MaxTap = Convert.ToInt32(csvRead.Frame[1, 3]);
            vc.LtcStatus.Nins   = Convert.ToInt32(csvRead.Frame[1, 4]);
            vc.LtcStatus.Avv    = Convert.ToInt32(csvRead.Frame[1, 5]);
            vc.LtcStatus.DifTap = Convert.ToInt32(csvRead.Frame[1, 6]);
            vc.LtcStatus.Cfail  = Convert.ToInt32(csvRead.Frame[1, 7]);
            vc.LtcStatus.RTX    = Convert.ToInt32(csvRead.Frame[1, 8]);
            vc.LtcStatus.LTX    = Convert.ToInt32(csvRead.Frame[1, 9]);
        }
Пример #6
0
        public static Output Execute(Input inputData, _InputMeta inputMeta)
        {
            Output output = new Output();

            try
            {
                // Output Testing Message in openECA Client MainWindow
                string _message = String.Format("\n=============== MainWindowTempLog_{0:yyyy-MM-dd_hh:mm:ss.fff} ===============\n", DateTime.UtcNow);
                foreach (VcTransformer Transformer in vca.InputFrame.ControlTransformers)
                {
                    _message += String.Format("\n\t- ControlTransformers_{0}_{1}\t| TapV: {2:00} \t VoltsV: {3}", Transformer.DeviceId, Transformer.LtcCtlId, Transformer.TapV, Transformer.VoltsV);
                }

                foreach (VcCapacitorBank CapBank in vca.InputFrame.ControlCapacitorBanks)
                {
                    _message += String.Format("\n\t- ControlCapBanks_{0}\t| CapBkrV: {1} \t VoltsV: {2}  Clov:{3} Chiv:{4}", CapBank.CapBkrId, CapBank.CapBkrV, CapBank.LockvV, CapBank.Clov, CapBank.Chiv);
                }

                MainWindow.WriteMessage(_message);


                // Extract inputData from openECA then Call SubRoutine
                vca.GetData(inputData, inputMeta, PreviousFrame);
                MainWindow.WriteMessage("%%\t" + vca.LogMessage.Replace("|", "\n = "));
                //System.Threading.Thread.Sleep(800);     //Threading: Suspends the current thread for MainWindow Output.

                // Append to tempLog File
                //string tempLogPath = (@"C:\Users\Chetan\Documents\openECA Projects\Zhijie\LVC20170203\CtrlDecisionLog_170206_test1.txt");
                //File.AppendAllText(tempLogPath, _message + "\n%%\t" + vca.LogMessage.Replace("|", "\n = "));

                // Logging control decision to *.xml files
                string   logsfolder   = (@"C:\Users\Chetan\Documents\openECA Projects\Zhijie\LVC20170203\Logs\\");
                string[] logsfilestr  = Directory.GetFiles(logsfolder, "CtrlDecisionLog_*.xml");
                string   logsFileName = logsfolder + "CtrlDecisionLog" + String.Format("_{0:000}_{1:yyyyMMdd_hhmmssfff}", (logsfilestr.Length + 1), DateTime.UtcNow) + ".xml";
                vca.SerializeToXml(logsFileName);

                // Store Current vca.InputFrame to previous.InputFrame for the next InputFrame
                PreviousFrame = vca.InputFrame;
            }
            catch (Exception ex)
            {
                // Display exceptions to the main window
                MainWindow.WriteError(new InvalidOperationException($"Algorithm exception: {ex.Message}", ex));
            }

            return(output);
        }
        private void ReadSubInformation(VoltVarController vc, string SubInformationPath, int rowNumber)
        {
            CsvAdapter csvRead = new CsvAdapter();

            csvRead.ReadCSV(SubInformationPath);

            vc.SubstationInformation.SubDevId  = csvRead.Frame[rowNumber, 0];
            vc.SubstationInformation.TieId     = csvRead.Frame[rowNumber, 1];
            vc.SubstationInformation.TieV      = Convert.ToInt32(csvRead.Frame[rowNumber, 2]);
            vc.SubstationInformation.CloverDev = csvRead.Frame[rowNumber, 3];
            vc.SubstationInformation.G1MwId    = csvRead.Frame[rowNumber, 4];
            vc.SubstationInformation.G1MvrId   = csvRead.Frame[rowNumber, 5];
            vc.SubstationInformation.G2MwId    = csvRead.Frame[rowNumber, 6];
            vc.SubstationInformation.G2MvrId   = csvRead.Frame[rowNumber, 7];
            vc.SubstationInformation.G1Mw      = Convert.ToDouble(csvRead.Frame[rowNumber, 8]);
            vc.SubstationInformation.G1Mvr     = Convert.ToDouble(csvRead.Frame[rowNumber, 9]);
            vc.SubstationInformation.G2Mw      = Convert.ToDouble(csvRead.Frame[rowNumber, 10]);
            vc.SubstationInformation.G2Mvr     = Convert.ToDouble(csvRead.Frame[rowNumber, 11]);

            vc.SubstationInformation.ConsecTap = Convert.ToInt32(csvRead.Frame[rowNumber, 12]);
            vc.SubstationInformation.ConsecCap = Convert.ToInt32(csvRead.Frame[rowNumber, 13]);
            vc.SubstationInformation.Ncdel     = Convert.ToInt32(csvRead.Frame[rowNumber, 14]);
            vc.SubstationInformation.Ntdel     = Convert.ToInt32(csvRead.Frame[rowNumber, 15]);
            vc.SubstationInformation.OldDay    = Convert.ToInt32(csvRead.Frame[rowNumber, 16]);
            vc.SubstationInformation.Zcdel     = Convert.ToInt32(csvRead.Frame[rowNumber, 17]);
            vc.SubstationInformation.Zdel      = Convert.ToInt32(csvRead.Frame[rowNumber, 18]);
            vc.SubstationInformation.Zmaxtrip  = Convert.ToInt32(csvRead.Frame[rowNumber, 19]);
            vc.SubstationInformation.Zmaxclose = Convert.ToInt32(csvRead.Frame[rowNumber, 20]);
            vc.SubstationInformation.Zccons    = Convert.ToInt32(csvRead.Frame[rowNumber, 21]);
            vc.SubstationInformation.Zclmvr    = Convert.ToDouble(csvRead.Frame[rowNumber, 22]);
            vc.SubstationInformation.Ztrmvr    = Convert.ToDouble(csvRead.Frame[rowNumber, 23]);
            vc.SubstationInformation.Alarm     = csvRead.Frame[rowNumber, 24];
            vc.SubstationInformation.Normal    = csvRead.Frame[rowNumber, 25];
            vc.SubstationInformation.Raise     = csvRead.Frame[rowNumber, 26];
            vc.SubstationInformation.Lower     = csvRead.Frame[rowNumber, 27];
            vc.SubstationInformation.ON        = csvRead.Frame[rowNumber, 28];
            vc.SubstationInformation.OFF       = csvRead.Frame[rowNumber, 29];
            vc.SubstationInformation.Close     = csvRead.Frame[rowNumber, 30];
            vc.SubstationInformation.Trip      = csvRead.Frame[rowNumber, 31];
            vc.SubstationInformation.Remote    = csvRead.Frame[rowNumber, 32];
            vc.SubstationInformation.Local     = csvRead.Frame[rowNumber, 33];
            vc.SubstationInformation.Auto      = csvRead.Frame[rowNumber, 34];
            vc.SubstationInformation.Manual    = csvRead.Frame[rowNumber, 35];
            vc.SubstationInformation.Dashes    = csvRead.Frame[rowNumber, 36];
        }
Пример #8
0
        static Algorithm()
        {
            string configurationPathName = (@"C:\Users\Chetan\Documents\openECA Projects\Zhijie\LVC20170203\Data\Configurations_test1.xml");

            vca = new VoltVarControllerAdapter();
            vca.ConfigurationPathName = configurationPathName;
            vca.Initialize();
            PreviousFrame = new VoltVarController();
            PreviousFrame = VoltVarController.DeserializeFromXml(configurationPathName);

            /*
             * Testing Files Configurations
             * test1.xml    -   Verify if the controller can RAISE both transformers' taps when voltages on both buses are lower than the limit (VLLIM = 114.5kV)
             * test2.xml    -   Verify if the controller is still able to operate (VLLIM = 114.5kV), when the other transformer's tap has reached the highest tap position (16)
             * test3.xml    -   Verify if the controller can switch ON the capacitor bank when the voltage in Pamplin substation reach the lower limit (Clov = 113.5kV)
             * test4.xml    -   Verify if the controller can switch OFF the capacitor bank when the voltage in Crewe substation reach the higher limit (Chiv = 119.7kV)
             */
        }
        private void ReadCapBanks(VoltVarController vc, string datafolder, int rowNumber)
        {
            for (int i = 0; i < vc.SubstationAlarmDevice.ZNCP; i++)
            {
                int k = i + 1;

                CsvAdapter csvRead = new CsvAdapter();
                csvRead.ReadCSV(string.Format(datafolder + "CapBank{0}.csv", k));
                vc.ControlCapacitorBanks[i].OpCapDev  = csvRead.Frame[rowNumber, 0];
                vc.ControlCapacitorBanks[i].OpCapId   = csvRead.Frame[rowNumber, 1];
                vc.ControlCapacitorBanks[i].OpCapV    = csvRead.Frame[rowNumber, 2];
                vc.ControlCapacitorBanks[i].ScadaSwId = csvRead.Frame[rowNumber, 3];
                vc.ControlCapacitorBanks[i].ScadaSwV  = csvRead.Frame[rowNumber, 4];
                vc.ControlCapacitorBanks[i].LocRemId  = csvRead.Frame[rowNumber, 5];
                vc.ControlCapacitorBanks[i].LocRemV   = csvRead.Frame[rowNumber, 6];
                vc.ControlCapacitorBanks[i].AutoManId = csvRead.Frame[rowNumber, 7];
                vc.ControlCapacitorBanks[i].AutoManV  = vc.SubstationInformation.Manual;
                vc.ControlCapacitorBanks[i].MiscId    = csvRead.Frame[rowNumber, 9];
                vc.ControlCapacitorBanks[i].MiscV     = csvRead.Frame[rowNumber, 10];
                vc.ControlCapacitorBanks[i].BusBkrId  = csvRead.Frame[rowNumber, 11];
                vc.ControlCapacitorBanks[i].BusBkrV   = csvRead.Frame[rowNumber, 12];
                vc.ControlCapacitorBanks[i].CapBkrId  = csvRead.Frame[rowNumber, 13];
                vc.ControlCapacitorBanks[i].CapBkrV   = csvRead.Frame[rowNumber, 14];
                vc.ControlCapacitorBanks[i].Clov      = Convert.ToDouble(csvRead.Frame[rowNumber, 15]);
                vc.ControlCapacitorBanks[i].Chiv      = Convert.ToDouble(csvRead.Frame[rowNumber, 16]);
                vc.ControlCapacitorBanks[i].Alovc     = Convert.ToDouble(csvRead.Frame[rowNumber, 17]);
                vc.ControlCapacitorBanks[i].Ahivt     = Convert.ToDouble(csvRead.Frame[rowNumber, 18]);
                vc.ControlCapacitorBanks[i].LockvDev  = csvRead.Frame[rowNumber, 19];
                vc.ControlCapacitorBanks[i].LockvId   = csvRead.Frame[rowNumber, 20];
                vc.ControlCapacitorBanks[i].LockvV    = Convert.ToDouble(csvRead.Frame[rowNumber, 21]);
                vc.ControlCapacitorBanks[i].CapCtlDev = csvRead.Frame[rowNumber, 22];
                vc.ControlCapacitorBanks[i].CapCtlId  = csvRead.Frame[rowNumber, 23];
                vc.ControlCapacitorBanks[i].Rtu       = Convert.ToInt32(csvRead.Frame[rowNumber, 24]);
                vc.ControlCapacitorBanks[i].CtlDone   = Convert.ToInt32(csvRead.Frame[rowNumber, 25]);
                vc.ControlCapacitorBanks[i].InSvc     = Convert.ToInt32(csvRead.Frame[rowNumber, 26]);
                vc.ControlCapacitorBanks[i].PrevCtl   = csvRead.Frame[rowNumber, 27];
                vc.ControlCapacitorBanks[i].NcTrip    = Convert.ToInt32(csvRead.Frame[rowNumber, 28]);
                vc.ControlCapacitorBanks[i].NcClose   = Convert.ToInt32(csvRead.Frame[rowNumber, 29]);
                vc.ControlCapacitorBanks[i].TripEx    = Convert.ToInt32(csvRead.Frame[rowNumber, 30]);
                vc.ControlCapacitorBanks[i].CloseEx   = Convert.ToInt32(csvRead.Frame[rowNumber, 31]);
            }
        }
Пример #10
0
        private VoltVarController CapStat(int i, VoltVarController vc)
        {
            if (vc.ControlCapacitorBanks[i].ScadaSwV == vc.SubstationInformation.OFF)
            {
                vc.ControlCapacitorBanks[i].InSvc = 0;
            }

            if (vc.ControlCapacitorBanks[i].MiscV == vc.SubstationInformation.Alarm || vc.ControlCapacitorBanks[i].MiscV == vc.SubstationInformation.OFF)
            {
                vc.ControlCapacitorBanks[i].InSvc = 0;
            }

            if (vc.ControlCapacitorBanks[i].BusBkrV == null)
            {
                m_messageInput += string.Format("CAP I = {0} Undefed bits set {1} {2} |", i, vc.SubstationInformation.SubDevId, vc.ControlCapacitorBanks[i].BusBkrId);
                vc.ControlCapacitorBanks[i].InSvc = 0;
            }

            if (vc.ControlCapacitorBanks[i].BusBkrV != 1)
            {
                vc.ControlCapacitorBanks[i].InSvc = 0;
            }

            if (vc.ControlCapacitorBanks[i].CapBkrV == null)
            {
                m_messageInput += string.Format("CAP I = {0} Undefed bits set {1} {2} |", i, vc.SubstationInformation.SubDevId, vc.ControlCapacitorBanks[i].CapBkrV);
                vc.ControlCapacitorBanks[i].InSvc = 0;
            }



            if (vc.ControlCapacitorBanks[i].LockvV <vc.SubstationAlarmDevice.ZVLO || vc.ControlCapacitorBanks[i].LockvV> vc.SubstationAlarmDevice.ZVHI)
            {
                vc.ControlCapacitorBanks[i].InSvc = 0;
            }

            return(vc);
        }
Пример #11
0
 private VoltVarController ConCap(int i, string CNAME, VoltVarController vc)
 {
     if (CNAME == vc.SubstationInformation.Close)
     {
         if (vc.ControlCapacitorBanks[i].CloseEx == 0)
         {
             m_messageInput += string.Format("Exceeded MAX Control Count {0} {1} {2} {3}|", CNAME, i, vc.ControlCapacitorBanks[i].CapCtlDev, vc.ControlCapacitorBanks[i].CapCtlId);
             vc.ControlCapacitorBanks[i].CloseEx = 1;
         }
         else
         {
             vc.ControlCapacitorBanks[i].NcClose = vc.ControlCapacitorBanks[i].NcClose + 1;
             // ret = &sw_db::write_point($CP[$i]{ cap_ctl_dev}, $CP[$i]{ cap_ctl_id} , $CNAME);
             vc.SubstationInformation.Ncdel      = 0;
             vc.ControlCapacitorBanks[i].CapBkrV = 1;
             m_messageInput += string.Format("CapControl {0} {1} {2} {3}|", vc.ControlCapacitorBanks[i].CapCtlDev, vc.ControlCapacitorBanks[i].CapCtlId, CNAME, vc.ControlCapacitorBanks[i].LockvV);
         }
     }
     else if (CNAME == vc.SubstationInformation.Trip)
     {
         if (vc.ControlCapacitorBanks[i].NcTrip >= vc.SubstationInformation.Zmaxtrip)
         {
             if (vc.ControlCapacitorBanks[i].TripEx == 0)
             {
                 m_messageInput += string.Format("Exceeded MAX Control Count {0} {1} {2}|", i, vc.ControlCapacitorBanks[i].CapCtlDev, vc.ControlCapacitorBanks[i].CapCtlId);
                 vc.ControlCapacitorBanks[i].TripEx = 1;
             }
         }
         else
         {
             vc.ControlCapacitorBanks[i].NcTrip  = vc.ControlCapacitorBanks[i].NcTrip + 1;
             vc.SubstationInformation.Ncdel      = 0;
             vc.ControlCapacitorBanks[i].CapBkrV = 0;
             m_messageInput += string.Format("CapControl {0} {1} {2} {3}|", vc.ControlCapacitorBanks[i].CapCtlDev, vc.ControlCapacitorBanks[i].CapCtlId, CNAME, vc.ControlCapacitorBanks[i].LockvV);
         }
     }
     return(vc);
 }
        private void CheckIfControlDoneLastCycle(int i)
        {
            VoltVarController      VC        = new VoltVarController();
            VcSubstationInfomation VcSubInfo = new VcSubstationInfomation();
            ProgLogMessage         PM        = new ProgLogMessage();
            BellyUps       BU  = new BellyUps();
            LtcLogMessages LM  = new LtcLogMessages();
            VcLtcStatus    LTC = new VcLtcStatus();

            if (VC.ControlTransformers[i].CtlDone != 0)
            {
                double TapMove = Math.Abs(VC.ControlTransformers[i].StTapV - VC.ControlTransformers[i].TapV);
                double MvrMove = Math.Abs(VC.ControlTransformers[i].StMvrV - VC.ControlTransformers[i].MvrV);
                if (TapMove < 0.2 && MvrMove < 0.2)
                {
                    LM.LtcLogMessage(string.Format("Control Failed {0} {1} {2} {3}",
                                                   VC.ControlTransformers[i].DeviceId, VC.ControlTransformers[i].LtcCtlId, VC.ControlTransformers[i].PrevCtl, VC.ControlTransformers[i].TapV));

                    LTC.Cfail++;
                }
                VC.ControlTransformers[i].CtlDone = 0;
            }
        }
        public VoltVarController ReadFrame(string inputdatafolder, string fileName, int rowNumber)
        {
            ReadInputAdapter  ReadIn = new ReadInputAdapter();
            VoltVarController vc     = new VoltVarController();

            string SubAlarmPath       = "SubAlarm.csv";
            string SubInformationPath = "SubInformation.csv";
            string LtcStatusPath      = "LtcStatus.csv";

            ReadIn.ReadSubAlarm(vc, inputdatafolder + SubAlarmPath);
            ReadIn.ReadSubInformation(vc, inputdatafolder + SubInformationPath, rowNumber);
            ReadIn.ReadLtcStatus(vc, inputdatafolder + LtcStatusPath);

            vc.LinkNetworkComponents(vc.SubstationAlarmDevice.ZNTX, vc.SubstationAlarmDevice.ZNCP);

            ReadIn.ReadTransformer(vc, inputdatafolder, rowNumber);
            ReadIn.ReadCapBanks(vc, inputdatafolder, rowNumber);

            ReadIn.CreateDictionary(vc);

            //vc.SerializeToXml(fileName);

            return(vc);
        }
 private void ReadTransformer(VoltVarController vc, string datafolder, int rowNumber)
 {
     for (int i = 0; i < vc.SubstationAlarmDevice.ZNTX; i++)
     {
         int        k       = i + 1;
         CsvAdapter csvRead = new CsvAdapter();
         csvRead.ReadCSV(string.Format(datafolder + "Transformer{0}.csv", k));
         vc.ControlTransformers[i].DeviceId   = csvRead.Frame[rowNumber, 0];
         vc.ControlTransformers[i].LocRemId   = csvRead.Frame[rowNumber, 1];
         vc.ControlTransformers[i].LocRemV    = csvRead.Frame[rowNumber, 2];
         vc.ControlTransformers[i].ScadaSw    = csvRead.Frame[rowNumber, 3];
         vc.ControlTransformers[i].ScadaSwV   = csvRead.Frame[rowNumber, 4];
         vc.ControlTransformers[i].HighSideId = csvRead.Frame[rowNumber, 5];
         vc.ControlTransformers[i].HighSideV  = Convert.ToInt32(csvRead.Frame[rowNumber, 6]);
         vc.ControlTransformers[i].LowSideId  = csvRead.Frame[rowNumber, 7];
         vc.ControlTransformers[i].LowSideV   = Convert.ToInt32(csvRead.Frame[rowNumber, 8]);
         vc.ControlTransformers[i].TapId      = csvRead.Frame[rowNumber, 9];
         vc.ControlTransformers[i].TapV       = Convert.ToInt32(csvRead.Frame[rowNumber, 10]);
         vc.ControlTransformers[i].StTapV     = Convert.ToInt32(csvRead.Frame[rowNumber, 11]);
         vc.ControlTransformers[i].MwId       = csvRead.Frame[rowNumber, 12];
         vc.ControlTransformers[i].MwV        = Convert.ToDouble(csvRead.Frame[rowNumber, 13]);
         vc.ControlTransformers[i].MvrId      = csvRead.Frame[rowNumber, 14];
         vc.ControlTransformers[i].MvrV       = Convert.ToDouble(csvRead.Frame[rowNumber, 15]);
         vc.ControlTransformers[i].StMvrV     = Convert.ToInt32(csvRead.Frame[rowNumber, 16]);
         vc.ControlTransformers[i].VoltsId    = csvRead.Frame[rowNumber, 17];
         vc.ControlTransformers[i].VoltsV     = Convert.ToDouble(csvRead.Frame[rowNumber, 18]);
         vc.ControlTransformers[i].VoltsTime  = Convert.ToInt32(csvRead.Frame[rowNumber, 19]);
         vc.ControlTransformers[i].LtcCtlId   = csvRead.Frame[rowNumber, 20];
         vc.ControlTransformers[i].TapTime    = Convert.ToInt32(csvRead.Frame[rowNumber, 21]);
         vc.ControlTransformers[i].CtlDone    = Convert.ToInt32(csvRead.Frame[rowNumber, 22]);
         vc.ControlTransformers[i].InSvc      = Convert.ToInt32(csvRead.Frame[rowNumber, 23]);
         vc.ControlTransformers[i].PrevCtl    = csvRead.Frame[rowNumber, 24];
         vc.ControlTransformers[i].MvrBal     = Convert.ToInt32(csvRead.Frame[rowNumber, 25]);
         vc.ControlTransformers[i].IRange     = csvRead.Frame[rowNumber, 26];
     }
 }
Пример #15
0
        internal static Output Execute(Inputs inputData, _InputsMeta inputMeta)
        {
            Output   output  = Output.CreateNew();
            DateTime runTime = DateTime.UtcNow;

            try
            {
                // TODO: Implement your algorithm here...
                // You can also write messages to the main window:

                #region [ Message Output ]

                bool EnableVoltageControlsMessageOutput = true;

                #endregion

                #region [ Environment Settings ]
                string MainFolderPath          = (@"C:\Users\niezj\Documents\dom\LVC118\");
                string DataFolderPath          = Path.Combine(MainFolderPath, @"Data");
                string LogFolderPath           = Path.Combine(MainFolderPath, @"Log");
                string ActionChannelFolderPath = Path.Combine(MainFolderPath, @"ActionChannel");

                string[] LogFileNameList = Directory.GetFiles(LogFolderPath, "CtrlDecisionLog_*.xml");
                string   LogFileName     = $"CtrlDecisionLog_{LogFileNameList.Length + 1:000}_{DateTime.UtcNow:yyyyMMdd_HHmmssfff}.xml";

                string LogFilePath = Path.Combine(LogFolderPath, LogFileName);

                #endregion


                VoltVarControllerAdapter vca;
                VoltVarController        PreviousFrame;

                /*
                 * Testing Files Configurations
                 * test1.xml    -   Verify if the controller can RAISE both transformers' taps when voltages on both buses are lower than the limit (VLLIM = 114.5kV)
                 * test2.xml    -   Verify if the controller is still able to operate (VLLIM = 114.5kV), when the other transformer's tap has reached the highest tap position (16)
                 * test3.xml    -   Verify if the controller can switch ON the capacitor bank when the voltage in Pamplin substation reach the lower limit (Clov = 113.5kV)
                 * test4.xml    -   Verify if the controller can switch OFF the capacitor bank when the voltage in Crewe substation reach the higher limit (Chiv = 119.7kV)
                 */
                string configurationPathName = (@"C:\Users\niezj\Documents\dom\ShadowSys118\ShadowSysConfiguration\prev_SysConfigFrame.xml");
                vca = new VoltVarControllerAdapter()
                {
                    ConfigurationPathName = configurationPathName
                };

                vca.Initialize();
                PreviousFrame = new VoltVarController();
                PreviousFrame = VoltVarController.DeserializeFromXml(configurationPathName);


                // Extract inputData from openECA then Call SubRoutine
                vca.GetData(inputData, inputMeta, PreviousFrame);

                // Logging control decision to *.xml files
                vca.SerializeToXml(LogFilePath);

                // Store Current vca.InputFrame to previous.InputFrame for the next InputFrame
                //PreviousFrame = vca.InputFrame;
                //PreviousFrame.SerializeToXml(@"C:\Users\niezj\Documents\dom\ShadowSys118\ShadowSysConfiguration\ctrl_SysConfigFrame.xml");

                #region [ Mimic an ActionChannel ]

                ActionsAdapter actChannel = new ActionsAdapter();

                bool actFlag = false;

                if (vca.InputFrame.ControlTransformers[0].TapV != PreviousFrame.ControlTransformers[0].TapV)
                {
                    actFlag = true;
                    if (vca.InputFrame.ControlTransformers[0].TapV > PreviousFrame.ControlTransformers[0].TapV)
                    {
                        actChannel.ActTxRaise = 1;
                    }
                    else
                    {
                        actChannel.ActTxLower = 1;
                    }
                }

                if (vca.InputFrame.ControlCapacitorBanks[0].CapBkrV != PreviousFrame.ControlCapacitorBanks[0].CapBkrV)
                {
                    actFlag = true;
                    switch (vca.InputFrame.ControlCapacitorBanks[0].CapBkrV)
                    {
                    case 1:
                        actChannel.ActSn1Close = 1;
                        break;

                    case 0:
                        actChannel.ActSn1Trip = 1;
                        break;

                    default:
                        break;
                    }
                }

                if (vca.InputFrame.ControlCapacitorBanks[1].CapBkrV != PreviousFrame.ControlCapacitorBanks[1].CapBkrV)
                {
                    actFlag = true;
                    switch (vca.InputFrame.ControlCapacitorBanks[1].CapBkrV)
                    {
                    case 1:
                        actChannel.ActSn2Close = 1;
                        break;

                    case 0:
                        actChannel.ActSn2Trip = 1;
                        break;

                    default:
                        break;
                    }
                }

                if (actFlag)
                {
                    actChannel.SerializeToXml(Path.Combine(ActionChannelFolderPath, "act.xml"));                    // Local
                    //actChannel.SerializeToXml(@"C:\Users\niezj\Documents\dom\ShadowSys118\ActionChannel\act.xml");   // External
                }

                #endregion

                #region [ Update Timestamps for Control Signals ]

                output.OutputData.ActTxRaise  = actChannel.ActTxRaise;
                output.OutputData.ActTxLower  = actChannel.ActTxLower;
                output.OutputData.ActSn1Close = actChannel.ActSn1Close;
                output.OutputData.ActSn1Trip  = actChannel.ActSn1Trip;
                output.OutputData.ActSn2Close = actChannel.ActSn2Close;
                output.OutputData.ActSn2Trip  = actChannel.ActSn2Trip;

                output.OutputMeta.ActTxRaise  = UpdateTime(output.OutputMeta.ActTxRaise);
                output.OutputMeta.ActTxLower  = UpdateTime(output.OutputMeta.ActTxLower);
                output.OutputMeta.ActSn1Close = UpdateTime(output.OutputMeta.ActSn1Close);
                output.OutputMeta.ActSn1Trip  = UpdateTime(output.OutputMeta.ActSn1Trip);
                output.OutputMeta.ActSn2Close = UpdateTime(output.OutputMeta.ActSn2Close);
                output.OutputMeta.ActSn2Trip  = UpdateTime(output.OutputMeta.ActSn2Trip);

                #endregion

                #region [ Write openECA Client Windows Message]
                if (EnableVoltageControlsMessageOutput)
                {
                    StringBuilder _message = new StringBuilder();
                    _message.AppendLine($" ================= LVC118 Analytics ================== ");
                    _message.AppendLine($"                 Run Time:  {runTime:yyyy-MM-dd HH:mm:ss.fff}");
                    _message.AppendLine($"          Completion Time:  {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss.fff}");
                    _message.AppendLine($"      InputData Timestamp:  {inputMeta.MeasGn1MvrV.Timestamp:yyyy-MM-dd HH:mm:ss.fff}");
                    _message.AppendLine($"     OutputData Timestamp:  {output.OutputMeta.ActTxRaise.Timestamp:yyyy-MM-dd HH:mm:ss.fff}");
                    //_message.AppendLine($" ------------------ CsvInputAdapter ------------------ ");
                    _message.AppendLine($" ------------------- ActionChannel ------------------- ");
                    _message.AppendLine($"       ActTxRaise:  {output.OutputData.ActTxRaise}");
                    _message.AppendLine($"       ActTxLower:  {output.OutputData.ActTxLower}");
                    _message.AppendLine($"      ActSn1Close:  {output.OutputData.ActSn1Close}");
                    _message.AppendLine($"       ActSn1Trip:  {output.OutputData.ActSn1Trip}");
                    _message.AppendLine($"      ActSn2Close:  {output.OutputData.ActSn2Close}");
                    _message.AppendLine($"       ActSn2Trip:  {output.OutputData.ActSn2Trip}");
                    _message.AppendLine($" ---------------- MeasurementChannel ----------------- ");
                    _message.AppendLine($"      MeasTxVoltV:  {inputData.MeasTxVoltV:0.000} Volts");
                    _message.AppendLine($"     MeasSn1VoltV:  {inputData.MeasSn1VoltV:0.000} Volts");
                    _message.AppendLine($"     MeasSn2VoltV:  {inputData.MeasSn2VoltV:0.000} Volts");
                    _message.AppendLine($"        MeasTxMwV:  {inputData.MeasTxMwV:0.000} MW");
                    _message.AppendLine($"       MeasTxMvrV:  {inputData.MeasTxMvrV:0.000} MVar");
                    _message.AppendLine($"       MeasGn1MwV:  {inputData.MeasGn1MwV:0.000} MW");
                    _message.AppendLine($"      MeasGn1MvrV:  {inputData.MeasGn1MvrV:0.000} MVar");
                    _message.AppendLine($"       MeasGn2MwV:  {inputData.MeasGn2MwV:0.000} MW");
                    _message.AppendLine($"      MeasGn2MvrV:  {inputData.MeasGn2MvrV:0.000} MVar");
                    _message.AppendLine($" ------------------- StateChannel -------------------- ");
                    _message.AppendLine($"      StateTxTapV:  {inputData.StateTxTapV}");
                    _message.AppendLine($"  StateSn1CapBkrV:  {inputData.StateSn1CapBkrV}");
                    _message.AppendLine($"  StateSn2CapBkrV:  {inputData.StateSn2CapBkrV}");
                    _message.AppendLine($"  StateSn1BusBkrV:  {inputData.StateSn1BusBkrV}");
                    _message.AppendLine($"  StateSn2BusBkrV:  {inputData.StateSn2BusBkrV}");
                    _message.AppendLine($" -------------- Control Decision Message ------------- ");
                    _message.AppendLine($" {vca.LogMessage}");
                    _message.AppendLine($" ===================================================== ");

                    MainWindow.WriteMessage(_message.ToString());
                }

                #endregion
            }
            catch (Exception ex)
            {
                // Display exceptions to the main window
                MainWindow.WriteError(new InvalidOperationException($"Algorithm exception: {ex.Message}", ex));
            }

            return(output);
        }
Пример #16
0
        internal static Output Execute(Inputs inputData, _InputsMeta inputMeta)
        {
            Output   output  = Output.CreateNew();
            DateTime runTime = DateTime.UtcNow;

            #region [ Message Output ]

            const bool EnableXmlFileLog = false;
            const bool EnableMainWindowMessageDisplay = true;

            #endregion

            #region [ Environment Settings ]

            string MainFolderPath          = (@"C:\Users\niezj\Documents\dom\ShadowSys118\");
            string ActionChannelFolderPath = Path.Combine(MainFolderPath, @"ActionChannel");
            string DataFolderPath          = Path.Combine(MainFolderPath, @"Data");
            string LogFolderPath           = Path.Combine(MainFolderPath, @"Log");
            string ConfigurationFolderPath = Path.Combine(MainFolderPath, @"ShadowSysConfiguration");
            string ProjFolderPath          = Path.Combine(MainFolderPath, @"ShadowSysLibrary");
            string PythonCodeFolderPath    = Path.Combine(MainFolderPath, @"PythonCode");

            string CaseFileName               = "IEEE_118_Bus.sav";
            string CsvOutputsFileName         = "Outputs.csv";
            string ConfigurationFileName      = "Configurations.xml";
            string InitSysConfigFrameFileName = "init_SysConfigFrame.xml";
            string PrevSysConfigFrameFileName = "prev_SysConfigFrame.xml";

            string CaseFilePath               = Path.Combine(PythonCodeFolderPath, CaseFileName);
            string CsvOutputsFilePath         = Path.Combine(LogFolderPath, CsvOutputsFileName);
            string ConfigurationFilePath      = Path.Combine(ConfigurationFolderPath, ConfigurationFileName);
            string InitSysConfigFrameFilePath = Path.Combine(ConfigurationFolderPath, InitSysConfigFrameFileName);
            string PrevSysConfigFrameFilePath = Path.Combine(ConfigurationFolderPath, PrevSysConfigFrameFileName);
            #endregion

            #region [ Update Configurations of Controlled Devices ]

            VoltVarController frame = new VoltVarController();

            // Read System Initial Configuration from XML file
            if (inputData.ResetSignal != 0)
            {
                MainWindow.WriteMessage($"Initialized Local Voltage Controller Test #{inputData.ResetSignal}");
                InitSysConfigFrameFileName = $"init_SysConfigFrame_test{inputData.ResetSignal}.xml";
                InitSysConfigFrameFilePath = Path.Combine(ConfigurationFolderPath, InitSysConfigFrameFileName);
                frame = VoltVarController.DeserializeFromXml(InitSysConfigFrameFilePath);
                File.Delete(PrevSysConfigFrameFilePath);

                ActionsAdapter initAction = new ActionsAdapter();
                frame.ExecuteControl(initAction);
            }
            else
            {
                if (File.Exists(PrevSysConfigFrameFilePath))
                {
                    frame = VoltVarController.DeserializeFromXml(PrevSysConfigFrameFilePath);
                }
                else
                {
                    frame = VoltVarController.DeserializeFromXml(InitSysConfigFrameFilePath);
                }
            }

            #endregion

            ActionsAdapter action = new ActionsAdapter();

            frame.SubstationInformation.ConsecCap += 1;
            frame.SubstationInformation.ConsecTap += 1;
            frame.SubstationInformation.Ncdel     += 1;
            frame.SubstationInformation.Ntdel     += 1;

            #region [ Receive Control Decision from LVC ]

            action.ReadFromEcaInputData(inputData);

            frame.ExecuteControl(action);

            #endregion

            #region [ Pending: Avoid logic conflict before execute control ]

            #endregion

            #region [ Run Power Flow Calculation using PSS/E ]
            // Call Python script to run power flow calculation
            PythonScripts Python          = new PythonScripts();
            List <string> outputFrameList = new List <string>();
            outputFrameList = Python.RunPythonCmd(Path.Combine(PythonCodeFolderPath, "CalculatePowerFlow.py"),
                                                  MainFolderPath,
                                                  CaseFileName,
                                                  CsvOutputsFileName,
                                                  inputData.LoadIncrementPercentage,
                                                  frame.ControlTransformers[0].TapV,
                                                  frame.ControlCapacitorBanks[0].CapBkrV,
                                                  frame.ControlCapacitorBanks[1].CapBkrV,
                                                  frame.ControlCapacitorBanks[0].BusBkrV,
                                                  frame.ControlCapacitorBanks[1].BusBkrV,
                                                  0,                                       // RegionalLoadIncrementPercentage
                                                  frame.ControlCapacitorBanks[0].CapBkrV,  // SnB34
                                                  frame.ControlCapacitorBanks[2].CapBkrV,  // SnB44
                                                  frame.ControlCapacitorBanks[3].CapBkrV,  // SnB45
                                                  frame.ControlCapacitorBanks[4].CapBkrV,  // SnB48
                                                  frame.ControlCapacitorBanks[5].CapBkrV,  // SnB74
                                                  frame.ControlCapacitorBanks[6].CapBkrV   // SnB105
                                                  );

            frame.SerializeToXml(PrevSysConfigFrameFilePath);

            #endregion

            #region [ Convert Calculated Values to OutputData ]

            // Read LVC Measurement Values from python outputs
            output.OutputData.StateTxTapV     = Convert.ToInt16(outputFrameList[0]);
            output.OutputData.StateSn1CapBkrV = Convert.ToInt16(outputFrameList[1]);
            output.OutputData.StateSn2CapBkrV = Convert.ToInt16(outputFrameList[2]);
            output.OutputData.StateSn1BusBkrV = Convert.ToInt16(outputFrameList[3]);
            output.OutputData.StateSn2BusBkrV = Convert.ToInt16(outputFrameList[4]);
            output.OutputData.MeasTxVoltV     = Convert.ToDouble(outputFrameList[5]);
            output.OutputData.MeasSn1VoltV    = Convert.ToDouble(outputFrameList[6]);
            output.OutputData.MeasSn2VoltV    = Convert.ToDouble(outputFrameList[7]);
            output.OutputData.MeasTxMwV       = Convert.ToDouble(outputFrameList[8]);
            output.OutputData.MeasTxMvrV      = Convert.ToDouble(outputFrameList[9]);
            output.OutputData.MeasGn1MwV      = Convert.ToDouble(outputFrameList[10]);
            output.OutputData.MeasGn1MvrV     = Convert.ToDouble(outputFrameList[11]);
            output.OutputData.MeasGn2MwV      = Convert.ToDouble(outputFrameList[12]);
            output.OutputData.MeasGn2MvrV     = Convert.ToDouble(outputFrameList[13]);

            // Read RVC Measurement Values from python outputs
            output.OutputData.StateSnB34CapBkrV  = Convert.ToInt16(outputFrameList[14]);
            output.OutputData.StateSnB44CapBkrV  = Convert.ToInt16(outputFrameList[15]);
            output.OutputData.StateSnB45CapBkrV  = Convert.ToInt16(outputFrameList[16]);
            output.OutputData.StateSnB48CapBkrV  = Convert.ToInt16(outputFrameList[17]);
            output.OutputData.StateSnB74CapBkrV  = Convert.ToInt16(outputFrameList[18]);
            output.OutputData.StateSnB105CapBkrV = Convert.ToInt16(outputFrameList[19]);
            output.OutputData.MeasB1VoltV        = Convert.ToDouble(outputFrameList[20]);
            output.OutputData.MeasB2VoltV        = Convert.ToDouble(outputFrameList[21]);
            output.OutputData.MeasB3VoltV        = Convert.ToDouble(outputFrameList[22]);
            output.OutputData.MeasB4VoltV        = Convert.ToDouble(outputFrameList[23]);
            output.OutputData.MeasB5VoltV        = Convert.ToDouble(outputFrameList[24]);
            output.OutputData.MeasB6VoltV        = Convert.ToDouble(outputFrameList[25]);
            output.OutputData.MeasB7VoltV        = Convert.ToDouble(outputFrameList[26]);
            output.OutputData.MeasB8VoltV        = Convert.ToDouble(outputFrameList[27]);
            output.OutputData.MeasB9VoltV        = Convert.ToDouble(outputFrameList[28]);
            output.OutputData.MeasB10VoltV       = Convert.ToDouble(outputFrameList[29]);
            output.OutputData.MeasB11VoltV       = Convert.ToDouble(outputFrameList[30]);
            output.OutputData.MeasB12VoltV       = Convert.ToDouble(outputFrameList[31]);
            output.OutputData.MeasB13VoltV       = Convert.ToDouble(outputFrameList[32]);
            output.OutputData.MeasB14VoltV       = Convert.ToDouble(outputFrameList[33]);
            output.OutputData.MeasB15VoltV       = Convert.ToDouble(outputFrameList[34]);
            output.OutputData.MeasB16VoltV       = Convert.ToDouble(outputFrameList[35]);
            output.OutputData.MeasB17VoltV       = Convert.ToDouble(outputFrameList[36]);
            output.OutputData.MeasB18VoltV       = Convert.ToDouble(outputFrameList[37]);
            output.OutputData.MeasB19VoltV       = Convert.ToDouble(outputFrameList[38]);
            output.OutputData.MeasB20VoltV       = Convert.ToDouble(outputFrameList[39]);
            output.OutputData.MeasB21VoltV       = Convert.ToDouble(outputFrameList[40]);
            output.OutputData.MeasB22VoltV       = Convert.ToDouble(outputFrameList[41]);
            output.OutputData.MeasB23VoltV       = Convert.ToDouble(outputFrameList[42]);
            output.OutputData.MeasB24VoltV       = Convert.ToDouble(outputFrameList[43]);
            output.OutputData.MeasB25VoltV       = Convert.ToDouble(outputFrameList[44]);
            output.OutputData.MeasB26VoltV       = Convert.ToDouble(outputFrameList[45]);
            output.OutputData.MeasB27VoltV       = Convert.ToDouble(outputFrameList[46]);
            output.OutputData.MeasB28VoltV       = Convert.ToDouble(outputFrameList[47]);
            output.OutputData.MeasB29VoltV       = Convert.ToDouble(outputFrameList[48]);
            output.OutputData.MeasB30VoltV       = Convert.ToDouble(outputFrameList[49]);
            output.OutputData.MeasB31VoltV       = Convert.ToDouble(outputFrameList[50]);
            output.OutputData.MeasB32VoltV       = Convert.ToDouble(outputFrameList[51]);
            output.OutputData.MeasB33VoltV       = Convert.ToDouble(outputFrameList[52]);
            output.OutputData.MeasB34VoltV       = Convert.ToDouble(outputFrameList[53]);
            output.OutputData.MeasB35VoltV       = Convert.ToDouble(outputFrameList[54]);
            output.OutputData.MeasB36VoltV       = Convert.ToDouble(outputFrameList[55]);
            output.OutputData.MeasB37VoltV       = Convert.ToDouble(outputFrameList[56]);
            output.OutputData.MeasB38VoltV       = Convert.ToDouble(outputFrameList[57]);
            output.OutputData.MeasB39VoltV       = Convert.ToDouble(outputFrameList[58]);
            output.OutputData.MeasB40VoltV       = Convert.ToDouble(outputFrameList[59]);
            output.OutputData.MeasB41VoltV       = Convert.ToDouble(outputFrameList[60]);
            output.OutputData.MeasB42VoltV       = Convert.ToDouble(outputFrameList[61]);
            output.OutputData.MeasB43VoltV       = Convert.ToDouble(outputFrameList[62]);
            output.OutputData.MeasB44VoltV       = Convert.ToDouble(outputFrameList[63]);
            output.OutputData.MeasB45VoltV       = Convert.ToDouble(outputFrameList[64]);
            output.OutputData.MeasB46VoltV       = Convert.ToDouble(outputFrameList[65]);
            output.OutputData.MeasB47VoltV       = Convert.ToDouble(outputFrameList[66]);
            output.OutputData.MeasB48VoltV       = Convert.ToDouble(outputFrameList[67]);
            output.OutputData.MeasB49VoltV       = Convert.ToDouble(outputFrameList[68]);
            output.OutputData.MeasB50VoltV       = Convert.ToDouble(outputFrameList[69]);
            output.OutputData.MeasB51VoltV       = Convert.ToDouble(outputFrameList[70]);
            output.OutputData.MeasB52VoltV       = Convert.ToDouble(outputFrameList[71]);
            output.OutputData.MeasB53VoltV       = Convert.ToDouble(outputFrameList[72]);
            output.OutputData.MeasB54VoltV       = Convert.ToDouble(outputFrameList[73]);
            output.OutputData.MeasB55VoltV       = Convert.ToDouble(outputFrameList[74]);
            output.OutputData.MeasB56VoltV       = Convert.ToDouble(outputFrameList[75]);
            output.OutputData.MeasB57VoltV       = Convert.ToDouble(outputFrameList[76]);
            output.OutputData.MeasB58VoltV       = Convert.ToDouble(outputFrameList[77]);
            output.OutputData.MeasB59VoltV       = Convert.ToDouble(outputFrameList[78]);
            output.OutputData.MeasB60VoltV       = Convert.ToDouble(outputFrameList[79]);
            output.OutputData.MeasB61VoltV       = Convert.ToDouble(outputFrameList[80]);
            output.OutputData.MeasB62VoltV       = Convert.ToDouble(outputFrameList[81]);
            output.OutputData.MeasB63VoltV       = Convert.ToDouble(outputFrameList[82]);
            output.OutputData.MeasB64VoltV       = Convert.ToDouble(outputFrameList[83]);
            output.OutputData.MeasB65VoltV       = Convert.ToDouble(outputFrameList[84]);
            output.OutputData.MeasB66VoltV       = Convert.ToDouble(outputFrameList[85]);
            output.OutputData.MeasB67VoltV       = Convert.ToDouble(outputFrameList[86]);
            output.OutputData.MeasB68VoltV       = Convert.ToDouble(outputFrameList[87]);
            output.OutputData.MeasB69VoltV       = Convert.ToDouble(outputFrameList[88]);
            output.OutputData.MeasB70VoltV       = Convert.ToDouble(outputFrameList[89]);
            output.OutputData.MeasB71VoltV       = Convert.ToDouble(outputFrameList[90]);
            output.OutputData.MeasB72VoltV       = Convert.ToDouble(outputFrameList[91]);
            output.OutputData.MeasB73VoltV       = Convert.ToDouble(outputFrameList[92]);
            output.OutputData.MeasB74VoltV       = Convert.ToDouble(outputFrameList[93]);
            output.OutputData.MeasB75VoltV       = Convert.ToDouble(outputFrameList[94]);
            output.OutputData.MeasB76VoltV       = Convert.ToDouble(outputFrameList[95]);
            output.OutputData.MeasB77VoltV       = Convert.ToDouble(outputFrameList[96]);
            output.OutputData.MeasB78VoltV       = Convert.ToDouble(outputFrameList[97]);
            output.OutputData.MeasB79VoltV       = Convert.ToDouble(outputFrameList[98]);
            output.OutputData.MeasB80VoltV       = Convert.ToDouble(outputFrameList[99]);
            output.OutputData.MeasB81VoltV       = Convert.ToDouble(outputFrameList[100]);
            output.OutputData.MeasB82VoltV       = Convert.ToDouble(outputFrameList[101]);
            output.OutputData.MeasB83VoltV       = Convert.ToDouble(outputFrameList[102]);
            output.OutputData.MeasB84VoltV       = Convert.ToDouble(outputFrameList[103]);
            output.OutputData.MeasB85VoltV       = Convert.ToDouble(outputFrameList[104]);
            output.OutputData.MeasB86VoltV       = Convert.ToDouble(outputFrameList[105]);
            output.OutputData.MeasB87VoltV       = Convert.ToDouble(outputFrameList[106]);
            output.OutputData.MeasB88VoltV       = Convert.ToDouble(outputFrameList[107]);
            output.OutputData.MeasB89VoltV       = Convert.ToDouble(outputFrameList[108]);
            output.OutputData.MeasB90VoltV       = Convert.ToDouble(outputFrameList[109]);
            output.OutputData.MeasB91VoltV       = Convert.ToDouble(outputFrameList[110]);
            output.OutputData.MeasB92VoltV       = Convert.ToDouble(outputFrameList[111]);
            output.OutputData.MeasB93VoltV       = Convert.ToDouble(outputFrameList[112]);
            output.OutputData.MeasB94VoltV       = Convert.ToDouble(outputFrameList[113]);
            output.OutputData.MeasB95VoltV       = Convert.ToDouble(outputFrameList[114]);
            output.OutputData.MeasB96VoltV       = Convert.ToDouble(outputFrameList[115]);
            output.OutputData.MeasB97VoltV       = Convert.ToDouble(outputFrameList[116]);
            output.OutputData.MeasB98VoltV       = Convert.ToDouble(outputFrameList[117]);
            output.OutputData.MeasB99VoltV       = Convert.ToDouble(outputFrameList[118]);
            output.OutputData.MeasB100VoltV      = Convert.ToDouble(outputFrameList[119]);
            output.OutputData.MeasB101VoltV      = Convert.ToDouble(outputFrameList[120]);
            output.OutputData.MeasB102VoltV      = Convert.ToDouble(outputFrameList[121]);
            output.OutputData.MeasB103VoltV      = Convert.ToDouble(outputFrameList[122]);
            output.OutputData.MeasB104VoltV      = Convert.ToDouble(outputFrameList[123]);
            output.OutputData.MeasB105VoltV      = Convert.ToDouble(outputFrameList[124]);
            output.OutputData.MeasB106VoltV      = Convert.ToDouble(outputFrameList[125]);
            output.OutputData.MeasB107VoltV      = Convert.ToDouble(outputFrameList[126]);
            output.OutputData.MeasB108VoltV      = Convert.ToDouble(outputFrameList[127]);
            output.OutputData.MeasB109VoltV      = Convert.ToDouble(outputFrameList[128]);
            output.OutputData.MeasB110VoltV      = Convert.ToDouble(outputFrameList[129]);
            output.OutputData.MeasB111VoltV      = Convert.ToDouble(outputFrameList[130]);
            output.OutputData.MeasB112VoltV      = Convert.ToDouble(outputFrameList[131]);
            output.OutputData.MeasB113VoltV      = Convert.ToDouble(outputFrameList[132]);
            output.OutputData.MeasB114VoltV      = Convert.ToDouble(outputFrameList[133]);
            output.OutputData.MeasB115VoltV      = Convert.ToDouble(outputFrameList[134]);
            output.OutputData.MeasB116VoltV      = Convert.ToDouble(outputFrameList[135]);
            output.OutputData.MeasB117VoltV      = Convert.ToDouble(outputFrameList[136]);
            output.OutputData.MeasB118VoltV      = Convert.ToDouble(outputFrameList[137]);

            output.OutputData.StateLoad = Convert.ToDouble(inputData.LoadIncrementPercentage);


            #endregion

            try
            {
                // TODO: Implement your algorithm here...
                // You can also write messages to the main window:

                #region [ Write Xml Log File ]
                if (EnableXmlFileLog)
                {
                    string ConfigFrameXMLLogFileName = $"Log_SysConfigFrame_{DateTime.UtcNow:yyMMdd_HHmmss}.xml";
                    string ConfigFrameXMLLogFilePath = Path.Combine(LogFolderPath, ConfigFrameXMLLogFileName);
                    frame.SerializeToXml(ConfigFrameXMLLogFilePath);
                }
                #endregion

                #region [ Write openECA Client Windows Message ]
                if (EnableMainWindowMessageDisplay)
                {
                    StringBuilder _message = new StringBuilder();
                    _message.AppendLine($" ================ ShadowSys Analytics ================");
                    _message.AppendLine($"                 Run Time:  {runTime:yyyy-MM-dd HH:mm:ss.fff}");
                    _message.AppendLine($"          Completion Time:  {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss.fff}");
                    _message.AppendLine($"      InputData Timestamp:  {inputMeta.LoadIncrementPercentage.Timestamp:yyyy-MM-dd HH:mm:ss.fff}");
                    //_message.AppendLine($" ------------------ CsvInputAdapter ------------------ ");
                    //_message.AppendLine($"  LoadIncrementPercentage:  {inputData.LoadIncrementPercentage:0.0000} %");
                    //_message.AppendLine($" ------------------- ActionChannel ------------------- ");
                    //_message.AppendLine($"               ActTxRaise:  {inputData.ActTxRaise}");
                    //_message.AppendLine($"               ActTxLower:  {inputData.ActTxLower}");
                    //_message.AppendLine($"              ActSn1Close:  {inputData.ActSn1Close}");
                    //_message.AppendLine($"               ActSn1Trip:  {inputData.ActSn1Trip}");
                    //_message.AppendLine($"              ActSn2Close:  {inputData.ActSn2Close}");
                    //_message.AppendLine($"               ActSn2Trip:  {inputData.ActSn2Trip}");
                    //_message.AppendLine($" ---------------- MeasurementChannel ----------------- ");
                    //_message.AppendLine($"              MeasTxVoltV:  {output.OutputData.MeasTxVoltV:0.000} Volts");
                    //_message.AppendLine($"             MeasSn1VoltV:  {output.OutputData.MeasSn1VoltV:0.000} Volts");
                    //_message.AppendLine($"             MeasSn2VoltV:  {output.OutputData.MeasSn2VoltV:0.000} Volts");
                    //_message.AppendLine($"                MeasTxMwV:  {output.OutputData.MeasTxMwV:0.000} MW");
                    //_message.AppendLine($"               MeasTxMvrV:  {output.OutputData.MeasTxMvrV:0.000} MVar");
                    //_message.AppendLine($"               MeasGn1MwV:  {output.OutputData.MeasGn1MwV:0.000} MW");
                    //_message.AppendLine($"              MeasGn1MvrV:  {output.OutputData.MeasGn1MvrV:0.000} MVar");
                    //_message.AppendLine($"               MeasGn2MwV:  {output.OutputData.MeasGn2MwV:0.000} MW");
                    //_message.AppendLine($"              MeasGn2MvrV:  {output.OutputData.MeasGn2MvrV:0.000} MVar");
                    //_message.AppendLine($" ------------------- StateChannel -------------------- ");
                    _message.AppendLine($"                  StateLoad:  {output.OutputData.StateLoad} ");
                    //_message.AppendLine($"              StateTxTapV:  {output.OutputData.StateTxTapV}");
                    //_message.AppendLine($"          StateSn1CapBkrV:  {output.OutputData.StateSn1CapBkrV}");
                    //_message.AppendLine($"          StateSn2CapBkrV:  {output.OutputData.StateSn2CapBkrV}");
                    //_message.AppendLine($"          StateSn1BusBkrV:  {output.OutputData.StateSn1BusBkrV}");
                    //_message.AppendLine($"          StateSn2BusBkrV:  {output.OutputData.StateSn2BusBkrV}");
                    //_message.AppendLine($"          StateSnB34CapBkrV:  {output.OutputData.StateSnB34CapBkrV}");
                    //_message.AppendLine($"          StateSnB44CapBkrV:  {output.OutputData.StateSnB44CapBkrV}");
                    //_message.AppendLine($"          StateSnB45CapBkrV:  {output.OutputData.StateSnB45CapBkrV}");
                    //_message.AppendLine($"          StateSnB48CapBkrV:  {output.OutputData.StateSnB48CapBkrV}");
                    //_message.AppendLine($"          StateSnB74CapBkrV:  {output.OutputData.StateSnB74CapBkrV}");
                    //_message.AppendLine($"         StateSnB105CapBkrV:  {output.OutputData.StateSnB105CapBkrV}");
                    _message.AppendLine($" ------------------ RVCActionChannel ----------------- ");
                    _message.AppendLine($"                * :  | 34 | 44 | 45 | 48 | 74 | 105 |");
                    _message.AppendLine($"      ActSnB*Close:  |  {inputData.ActSnB34Close} |  {inputData.ActSnB44Close} |  {inputData.ActSnB45Close} |  {inputData.ActSnB48Close} |  {inputData.ActSnB74Close} |   {inputData.ActSnB105Close} |");
                    _message.AppendLine($"       ActSnB*Trip:  |  {inputData.ActSnB34Trip} |  {inputData.ActSnB44Trip} |  {inputData.ActSnB45Trip} |  {inputData.ActSnB48Trip} |  {inputData.ActSnB74Trip} |   {inputData.ActSnB105Trip} |");
                    _message.AppendLine($"  StateSnB*CapBkrV:  |  {output.OutputData.StateSnB34CapBkrV} |  {output.OutputData.StateSnB44CapBkrV} |  {output.OutputData.StateSnB45CapBkrV} |  {output.OutputData.StateSnB48CapBkrV} |  {output.OutputData.StateSnB74CapBkrV} |   {output.OutputData.StateSnB105CapBkrV} |");
                    _message.AppendLine($" =====================================================");
                    MainWindow.WriteMessage(_message.ToString());
                }

                #endregion
            }
            catch (Exception ex)
            {
                // Display exceptions to the main window
                MainWindow.WriteError(new InvalidOperationException($"Algorithm exception: {ex.Message}", ex));
            }

            return(output);
        }
        public void GetData(Input inputData, _InputMeta inputMeta, VoltVarController PreviousFrame)
        {
            #region [ openECA inputData Extraction ]
            // Extract inputData from openECA
            //m_inputFrame.ControlTransformers[0].TapV = inputData.TapVTx4;
            m_inputFrame.ControlTransformers[0].MwV    = inputData.MwVTx4;
            m_inputFrame.ControlTransformers[0].MvrV   = inputData.MvrVTx4;
            m_inputFrame.ControlTransformers[0].VoltsV = inputData.VoltsVTx4;

            //m_inputFrame.ControlTransformers[1].TapV = inputData.TapVTx5;
            m_inputFrame.ControlTransformers[1].MwV    = inputData.MwVTx5;
            m_inputFrame.ControlTransformers[1].MvrV   = inputData.MvrVTx5;
            m_inputFrame.ControlTransformers[1].VoltsV = inputData.VoltsVTx5;

            m_inputFrame.ControlCapacitorBanks[0].BusBkrV = inputData.BusBkrVCap1;
            //m_inputFrame.ControlCapacitorBanks[0].CapBkrV = inputData.CapBkrVCap1;
            m_inputFrame.ControlCapacitorBanks[0].LockvV = inputData.LocKvVCap1;

            m_inputFrame.ControlCapacitorBanks[1].BusBkrV = inputData.BusBkrVCap2;
            //m_inputFrame.ControlCapacitorBanks[1].CapBkrV = inputData.CapBkrVCap2;
            m_inputFrame.ControlCapacitorBanks[1].LockvV = inputData.LocKvVCap2;

            m_inputFrame.SubstationInformation.G1Mw  = inputData.G1Mw;
            m_inputFrame.SubstationInformation.G1Mvr = inputData.G1Mvr;
            m_inputFrame.SubstationInformation.G2Mw  = inputData.G2Mw;
            m_inputFrame.SubstationInformation.G2Mvr = inputData.G2Mvr;

            #endregion

            SubRoutine         sub            = new SubRoutine();
            ReadCurrentControl ReadCurrentCon = new ReadCurrentControl();

            VoltVarController Frame = new VoltVarController();

            #region [ Measurements Mapping ]

            m_inputFrame.OnNewMeasurements();

            #endregion

            #region [ Read The Previous Run ]

            m_inputFrame.ReadPreviousRun(PreviousFrame);

            #endregion

            #region [ Verify Program Controls ]

            ReadCurrentCon.VerifyProgramControl(m_inputFrame.SubstationAlarmDevice.LtcProgram);

            #endregion

            #region [ Adjust Control Delay Counters ]

            //#-----------------------------------------------------------------------#
            //# adjust the cap bank control delay counter, which is used to ensure:	#
            //# a. we don't do two cap bank control within 30 minutes of each other.	#
            //# b. we don't do a tap control within a minute of a cap bank control.	#
            //#-----------------------------------------------------------------------#

            if (m_inputFrame.SubstationInformation.Ncdel < m_inputFrame.SubstationInformation.Zcdel)
            {
                m_inputFrame.SubstationInformation.Ncdel = m_inputFrame.SubstationInformation.Ncdel + 1;
            }


            //#-----------------------------------------------------------------------#
            //# Adjust the tap control delay counter, which is used to ensure we	#
            //# don't do a cap bank control within a minute of a tap control.		#
            //#-----------------------------------------------------------------------#


            if (m_inputFrame.SubstationInformation.Ntdel < m_inputFrame.SubstationInformation.Zdel)
            {
                m_inputFrame.SubstationInformation.Ntdel = m_inputFrame.SubstationInformation.Ntdel + 1;
            }


            #endregion

            #region [ Read Curren Tx Values and Voltages ]

            m_inputFrame = ReadCurrentCon.ReadCurrentTransformerValuesAndVoltages(m_inputFrame);

            #endregion

            #region [ Check if the Previous Control Reults can Meet Our Expectation ]

            m_inputFrame = ReadCurrentCon.CheckPreviousControlResults(m_inputFrame);

            #endregion

            #region [ Call Sub Taps ]

            m_inputFrame = sub.Taps(m_inputFrame);

            #endregion

            #region [CapBank]

            m_inputFrame = sub.CapBank(m_inputFrame);

            #endregion

            #region [ Save before Exit ]

            m_logMessage  = ReadCurrentCon.MessageInput;
            m_logMessage += sub.MessageInput;
            m_inputFrame.LtcStatus.Avv    = 0;
            m_inputFrame.LtcStatus.Nins   = 0;
            m_inputFrame.LtcStatus.MinVar = 99999;
            m_inputFrame.LtcStatus.MaxVar = -99999;

            #endregion
        }
 public void Initialize()
 {
     m_inputFrame = VoltVarController.DeserializeFromXml(m_configurationPathName);
     m_logMessage = null;
 }
 private void InitializeInputFrame()
 {
     m_inputFrame = new VoltVarController();
 }
Пример #20
0
        public VoltVarController Taps(VoltVarController vc)
        {
            #region [ check if LTC Taps are too far apart to continue]

            if (vc.LtcStatus.DifTap > vc.SubstationAlarmDevice.ZDIFTAP)
            {
                //set clear alarm
                m_messageInput += string.Format("LTCs are too far apart must EXIT {0} {1} |", vc.LtcStatus.DifTap, vc.SubstationAlarmDevice.ZDIFTAP);
            }
            else
            {
                //set clear alarm
            }

            #endregion

            #region [ Check TimeStamps. Make Sure the Last Voltage TimeStamp is more recent than the last TimeStamp ]

            //for (int i = 0; i < vc.SubstationAlarmDevice.ZNTX; i++)
            //{
            //    if (vc.ControlTransformers[i].VoltsTime > vc.ControlTransformers[i].TapTime)
            //    {
            //        m_messageInput += string.Format("TS last volts time = {0} > TS last control = {1} no Contrl ", vc.ControlTransformers[i].VoltsTime, vc.ControlTransformers[i].TapTime);
            //        //save before exit
            //    }

            //    if (vc.LtcStatus.Avv >= vc.SubstationAlarmDevice.VLLIM && vc.LtcStatus.Avv < vc.SubstationAlarmDevice.VHLIM)
            //    {
            //        if (vc.LtcStatus.BalMvr <= vc.SubstationAlarmDevice.ZBAL)
            //        {
            //            m_messageInput += string.Format("Normal Exit KV= {0} OK & MVRs= {1} balanced ", vc.LtcStatus.Avv, vc.LtcStatus.BalMvr);

            //        }
            //    }

            //}

            #endregion

            #region [ Check for ZCONS consecutive trigers, or the use by the operators of the command which forces us to take action immediately ]

            if (vc.SubstationInformation.ConsecTap < vc.SubstationAlarmDevice.ZTCONS)
            {
                vc.SubstationInformation.ConsecTap = vc.SubstationInformation.ConsecTap + 1;

                m_messageInput += string.Format("Not enough Counts yet = {0} < {1} |", vc.SubstationInformation.ConsecTap, vc.SubstationAlarmDevice.ZTCONS);

                return(vc);
            }
            #endregion

            else
            {
                #region [ Decide which Transformer we would prefer to use ]

                //-----------------------------------------------------------------------#
                // If the megavars are unbalanced, we are only going to tap-change on    #
                // one transformer. Decide which transformer we would prefer to use.	#
                //                                   #
                // If we are here because the voltage is out of range:	            #
                //                                   #
                // For a raise, we consider only transformers which are in		#
                // service and not already on the highest tap. We select the one	#
                // with the lowest megavars.					#
                //                                   #
                // For a lower, we consider only transformers which are in		#
                // service and not already on the lowest tap. We select the one	#
                // with the highest megavars.					#
                //                                   #
                // If the voltage is in range, and we are here only because the	#
                // megavars are unbalanced:					#
                //                                   #
                // For a raise, we consider only transformers which are in		#
                // service. We select the one with the lowest megavars. If it is	#
                // already on the highest tap, we give up.				#
                //                                   #
                // For a lower, we consider only transformers which are in		#
                // service. We select the one with the highest megavars. If it is	#
                // already on the lowest tap, we give up.				#
                //---------------------------------------------------------------------- #

                //------------------------------------------------------------#
                // Set up megavar unbalance , initial low and high MVRs,      #
                // Set up MIN and MAX MVRs and save , Check to make sure      #
                // not on lowest or highest tap, if they are deselect tap     #
                //------------------------------------------------------------#

                if (vc.LtcStatus.BalMvr > vc.SubstationAlarmDevice.ZBAL)
                {
                    for (int i = 0; i < vc.SubstationAlarmDevice.ZNTX; i++)
                    {
                        if (vc.ControlTransformers[i].InSvc != 0)
                        {
                            if (vc.ControlTransformers[i].TapV >= vc.SubstationAlarmDevice.ZHITAP && vc.ControlTransformers[i].MvrV == vc.LtcStatus.MinVar)
                            {
                                vc.LtcStatus.RTX = -1; // RTX on Highest Tap, we give up
                            }
                            else if (vc.ControlTransformers[i].TapV <= vc.SubstationAlarmDevice.ZLOTAP && vc.ControlTransformers[i].MvrV == vc.LtcStatus.MaxVar)
                            {
                                vc.LtcStatus.LTX = -1; // RTX on Lowest Tap, we give up
                            }
                        }
                    }
                }

                // Start the Control!
                if (vc.LtcStatus.Avv < vc.SubstationAlarmDevice.VLLIM)
                {
                    if (vc.LtcStatus.BalMvr > vc.SubstationAlarmDevice.ZBAL) // if the balance is out of range, we control the Tx with lowest megavars
                    {
                        vc = ConTap(vc.LtcStatus.RTX, vc.SubstationInformation.Raise, "KV =", vc);
                    }
                    else
                    {
                        for (int i = 0; i < vc.SubstationAlarmDevice.ZNTX; i++) // if the balance is within the range, we control both Tx.
                        {
                            if (vc.ControlTransformers[i].InSvc != 0)
                            {
                                if (vc.ControlTransformers[i].TapV < vc.SubstationAlarmDevice.ZHITAP)
                                {
                                    vc = ConTap(i, vc.SubstationInformation.Raise, "KV=", vc);
                                }
                                else
                                {
                                    vc = ConTap(-1, vc.SubstationInformation.Raise, "KV=", vc); // if it reaches the highest tap, we give up.
                                }
                            }
                        }
                    }
                }
                else if (vc.LtcStatus.Avv >= vc.SubstationAlarmDevice.VHLIM)
                {
                    if (vc.LtcStatus.BalMvr > vc.SubstationAlarmDevice.ZBAL)
                    {
                        ConTap(vc.LtcStatus.LTX, vc.SubstationInformation.Lower, "KV = ", vc);
                    }
                    else
                    {
                        for (int i = 0; i < vc.SubstationAlarmDevice.ZNTX; i++)
                        {
                            if (vc.ControlTransformers[i].InSvc != 0)
                            {
                                if (vc.ControlTransformers[i].TapV > vc.SubstationAlarmDevice.ZLOTAP)
                                {
                                    vc = ConTap(i, vc.SubstationInformation.Lower, "KV = ", vc);
                                }
                                else
                                {
                                    vc = ConTap(-1, vc.SubstationInformation.Lower, "KV = ", vc);
                                }
                            }
                        }
                    }
                }
                else if (vc.LtcStatus.BalMvr > vc.SubstationAlarmDevice.ZBAL)
                {
                    if (vc.LtcStatus.Avv > (vc.SubstationAlarmDevice.VLLIM + vc.SubstationAlarmDevice.VHLIM) / 2.0)
                    {
                        vc = ConTap(vc.LtcStatus.LTX, vc.SubstationInformation.Lower, "MVR SPREAD = ", vc);
                    }
                    else
                    {
                        vc = ConTap(vc.LtcStatus.RTX, vc.SubstationInformation.Raise, "MVR SPREAD = ", vc);
                    }
                }
                else
                {
                    m_messageInput += string.Format("Sub Taps No Conrtols Needed this Cycle |");
                }



                #endregion
                return(vc);
            }
        }
Пример #21
0
        public VoltVarController CapBank(VoltVarController vc)
        {
            //--------------------------------------------------------- #
            //---- Order of Cap bank operation -----
            //1. First  Close 1   SC242
            //2. Second Close 2   SC242
            //3. First  Trip  2   SC242
            //4. Second Trip  1   SC242
            //--------------------------------------------------------- #

            int    co    = 3; // 3 means no capbanks require control
            string cName = null;
            double GtMvr = vc.SubstationInformation.G1Mvr + vc.SubstationInformation.G2Mvr;

            for (int i = 0; i < vc.SubstationAlarmDevice.ZNCP; i++)
            {
                if (vc.ControlCapacitorBanks[i].OpCapV != null)
                {
                    if (vc.ControlCapacitorBanks[i].OpCapV != "ON")
                    {
                        vc.ControlCapacitorBanks[i].InSvc = 0;
                        m_messageInput += string.Format("op Cap Bank Control {0} {1} {2} |", i, vc.ControlCapacitorBanks[i].OpCapDev, vc.ControlCapacitorBanks[i].OpCapId);
                    }
                    else
                    {
                        vc.ControlCapacitorBanks[i].InSvc = 1;

                        // --------------------------------------------------------------------- #
                        // Check status availability. If any statuses are unavailable (i.e.,	#
                        // telemetry is failed on the digital word), just set the field status	#
                        // for this capacitor to bad. We perform this two-step process so that	#
                        // we will be able to perform our voltage out-of-range checks even if	#
                        // one capacitor has telemetry failure.					#
                        // --------------------------------------------------------------------- #
                        // ---  Get the statuses of the cap banks for later checking --- #

                        CapStat(i, vc);
                    }
                }
                else
                {
                    m_messageInput += string.Format("Cap Bank Control {0} {1} {2} Undefed bits set |", i, vc.ControlCapacitorBanks[i].CapCtlDev, vc.ControlCapacitorBanks[i].OpCapId);
                    vc.ControlCapacitorBanks[i].InSvc = 0;
                }
            }

            for (int i = 0; i < vc.SubstationAlarmDevice.ZNCP; i++)
            {
                if (vc.ControlCapacitorBanks[i].InSvc != 0)
                {
                    m_messageInput += string.Format("{0} {1} {2} {3} {4} < {5} or gtvr = {6} |", i, vc.ControlCapacitorBanks[i].CapCtlDev, vc.ControlCapacitorBanks[i].CapCtlId, vc.ControlCapacitorBanks[i].CapBkrV, vc.ControlCapacitorBanks[i].LockvV, vc.ControlCapacitorBanks[i].Clov, GtMvr);
                    if (vc.ControlCapacitorBanks[i].LockvV < vc.ControlCapacitorBanks[i].Clov || ((GtMvr > vc.SubstationInformation.Zclmvr) && (vc.ControlCapacitorBanks[i].LockvV < vc.ControlCapacitorBanks[i].Alovc)))
                    {
                        if (vc.ControlCapacitorBanks[i].CapBkrV != vc.SubstationInformation.Close)
                        {
                            co    = i;
                            cName = vc.SubstationInformation.Close;
                        }
                    }
                    else if (vc.ControlCapacitorBanks[i].LockvV > vc.ControlCapacitorBanks[i].Chiv || ((GtMvr < vc.SubstationInformation.Ztrmvr) && (vc.ControlCapacitorBanks[i].LockvV > vc.ControlCapacitorBanks[i].Ahivt)))
                    {
                        if (vc.ControlCapacitorBanks[i].CapBkrV != vc.SubstationInformation.Trip)
                        {
                            co    = i;
                            cName = vc.SubstationInformation.Trip;
                        }
                    }
                }
            }


            if (vc.SubstationInformation.ConsecCap < vc.SubstationInformation.Zccons || vc.SubstationInformation.Ncdel < vc.SubstationInformation.Zcdel || vc.SubstationInformation.Ntdel < vc.SubstationInformation.Zdel)
            {
                vc.SubstationInformation.ConsecCap = vc.SubstationInformation.ConsecCap + 1;
                m_messageInput += string.Format("Not enough CAPBANK Counts {0} < {1} {2} < {3}  {4} < {5}|", vc.SubstationInformation.ConsecCap, vc.SubstationInformation.Zccons, vc.SubstationInformation.Ncdel, vc.SubstationInformation.Zcdel, vc.SubstationInformation.Ntdel, vc.SubstationInformation.Zdel);
                co              = 3;
            }

            if (co != 3)
            {
                vc = ConCap(co, cName, vc);
                vc.SubstationInformation.ConsecCap = 0;
            }

            return(vc);
        }
        public void PublishFrame(VoltVarController Frame, string inputdatafolder, VoltVarController PreviousFrame)
        {
            SubRoutine         sub            = new SubRoutine();
            ReadCurrentControl ReadCurrentCon = new ReadCurrentControl();

            #region [ Read the Input Value Key Pairs]

            foreach (KeyValuePair <string, object> kvp in Frame.RawkeyValuePairs)
            {
                m_inputFrame.RawkeyValuePairs.Add(kvp.Key, kvp.Value);
            }

            #endregion

            #region [ Measurements Mapping ]

            m_inputFrame.OnNewMeasurements();

            #endregion

            #region [ Read The Previous Run ]

            m_inputFrame.ReadPreviousRun(PreviousFrame);

            #endregion

            #region [ Verify Program Controls ]

            ReadCurrentCon.VerifyProgramControl(m_inputFrame.SubstationAlarmDevice.LtcProgram);

            #endregion

            #region [ Adjust Control Delay Counters ]

            //#-----------------------------------------------------------------------#
            //# adjust the cap bank control delay counter, which is used to ensure:	#
            //# a. we don't do two cap bank control within 30 minutes of each other.	#
            //# b. we don't do a tap control within a minute of a cap bank control.	#
            //#-----------------------------------------------------------------------#

            if (m_inputFrame.SubstationInformation.Ncdel < m_inputFrame.SubstationInformation.Zcdel)
            {
                m_inputFrame.SubstationInformation.Ncdel = m_inputFrame.SubstationInformation.Ncdel + 1;
            }


            //#-----------------------------------------------------------------------#
            //# Adjust the tap control delay counter, which is used to ensure we	#
            //# don't do a cap bank control within a minute of a tap control.		#
            //#-----------------------------------------------------------------------#


            if (m_inputFrame.SubstationInformation.Ntdel < m_inputFrame.SubstationInformation.Zdel)
            {
                m_inputFrame.SubstationInformation.Ntdel = m_inputFrame.SubstationInformation.Ntdel + 1;
            }


            #endregion

            #region [ Read Curren Tx Values and Voltages ]

            m_inputFrame = ReadCurrentCon.ReadCurrentTransformerValuesAndVoltages(m_inputFrame);

            #endregion

            #region [ Check if the Previous Control Reults can Meet Our Expectation ]

            m_inputFrame = ReadCurrentCon.CheckPreviousControlResults(m_inputFrame);

            #endregion

            #region [ Call Sub Taps ]

            m_inputFrame = sub.Taps(m_inputFrame);

            #endregion

            #region [CapBank]

            m_inputFrame = sub.CapBank(m_inputFrame);

            #endregion

            #region [ Save before Exit ]

            m_logMessage  = ReadCurrentCon.MessageInput;
            m_logMessage += sub.MessageInput;
            m_inputFrame.RawkeyValuePairs.Clear();
            m_inputFrame.LtcStatus.Avv    = 0;
            m_inputFrame.LtcStatus.Nins   = 0;
            m_inputFrame.LtcStatus.MinVar = 99999;
            m_inputFrame.LtcStatus.MaxVar = -9999;

            #endregion
        }
        public static void Main()
        {
            // set the  directory
            string testCase        = (@"C:\Users\Duotong\Desktop\2019SUM\LocalVoltageControl\Test1\\");
            string inputdatafolder = (@"C:\Users\Duotong\Desktop\2019SUM\LocalVoltageControl\Test1\Data\\");
            string logsfolder      = (@"C:\Users\Duotong\Desktop\2019SUM\LocalVoltageControl\Test1\Logs\\");
            string pythonCmdPath   = (@"C:\Users\Duotong\Desktop\2019SUM\LocalVoltageControl\Test1\pythonCode\\");

            // Set the Path for BenchMark Model and Configuration
            string caseName              = testCase + "2019SUM_2013Series_Updated_forLocalVoltageControl_BenchMark.sav";
            string testCaseName          = testCase + "2019SUM_2013Series_Updated_forLocalVoltageControl_BenchMark_test.sav";
            string configurationPathName = inputdatafolder + "Configurations.xml";

            VoltVarControllerAdapter VCAdapter     = new VoltVarControllerAdapter();
            ReadInputAdapter         ReadIn        = new ReadInputAdapter();
            VoltVarController        Frame         = new VoltVarController();
            PythonScripts            Python        = new PythonScripts();
            VoltVarController        PreviousFrame = new VoltVarController();

            #region [ Initialization ]

            Python.CleanCmd(pythonCmdPath + "CleanData.py", inputdatafolder, logsfolder, pythonCmdPath, caseName, testCaseName); // clean the inputd data, delete the logs, and copy the benchmark model

            VCAdapter.ConfigurationPathName = configurationPathName;
            VCAdapter.Initialize();
            PreviousFrame = VoltVarController.DeserializeFromXml(configurationPathName);

            #endregion

            #region [ Execute Program for Each Frame ]
            for (int i = 0; i < 30; i++)
            {
                int rowNumber = i + 1;

                string inputFileName = inputdatafolder + String.Format("{0:yyyy-MM-dd  hh-mm-ss}_{1}", DateTime.UtcNow, rowNumber) + ".xml";
                string logsFileName  = logsfolder + String.Format("{0:yyyy-MM-dd  hh-mm-ss}_{1}", DateTime.UtcNow, rowNumber) + " Logs.xml";

                Frame = ReadIn.ReadFrame(inputdatafolder, inputFileName, rowNumber);

                VCAdapter.PublishFrame(Frame, inputdatafolder, PreviousFrame);

                PreviousFrame = VCAdapter.InputFrame;

                VCAdapter.InputFrame.SerializeToXml(inputFileName);

                VCAdapter.SerializeToXml(logsFileName);



                #region [ Control PSSE ]

                try
                {
                    Python.RunCmd(pythonCmdPath + "DVPScaleLoad.py", VCAdapter.LogMessage, inputdatafolder, VCAdapter.InputFrame.SubstationInformation, testCaseName, VCAdapter.InputFrame.ControlCapacitorBanks[0], VCAdapter.InputFrame.ControlCapacitorBanks[1]);
                    //Console.ReadLine();
                    //if (i == 0)
                    //{
                    //    Console.ReadLine();
                    //}
                }
                catch
                {
                    Console.ReadLine();
                }

                #endregion
            }

            #endregion
        }
Пример #24
0
 internal VoltVarController ReadPreviousFrame(VoltVarController frame, ReadPreviousRun previousFrame)
 {
     throw new NotImplementedException();
 }
Пример #25
0
        public VoltVarController ReadCurrentTransformerValuesAndVoltages(VoltVarController vc)
        {
            for (int i = 0; i < vc.SubstationAlarmDevice.ZNTX; i++)
            {
                #region [ check Transformer Local/Remote Switch ]
                if (vc.ControlTransformers[i].LocRemV != vc.SubstationInformation.Remote)
                {
                    vc.ControlTransformers[i].InSvc = 0;
                    m_messageInput += string.Format("loc_Rem not in service {0} {1} {2} = {3} |", i, vc.ControlTransformers[i].DeviceId, vc.ControlTransformers[i].LocRemId, vc.ControlTransformers[i].LocRemV);
                }
                else
                {
                    vc.ControlTransformers[i].InSvc = 1;
                }

                #endregion

                #region [ Check Scada Control Switch ]

                if (vc.ControlTransformers[i].ScadaSwV != vc.SubstationInformation.ON)
                {
                    vc.ControlTransformers[i].InSvc = 0;
                    m_messageInput += string.Format("ScadaSw {0} SCADA SW OUT of Service =  {1} |", i, vc.ControlTransformers[i].ScadaSwV);
                }

                #endregion

                #region [ Check Transformer High Side Breaker ]
                if (Convert.ToString(vc.ControlTransformers[i].HighSideV) == vc.SubstationInformation.Trip)
                {
                    vc.ControlTransformers[i].InSvc = 0;
                    m_messageInput += string.Format("high side breaker open = {0} {1} {2} |", vc.ControlTransformers[i].DeviceId, vc.ControlTransformers[i].HighSideId, vc.ControlTransformers[i].HighSideV);
                }

                #endregion

                #region [ Check Transformer Low Side Breaker ]
                if (Convert.ToString(vc.ControlTransformers[i].LowSideV) == vc.SubstationInformation.Trip)
                {
                    vc.ControlTransformers[i].InSvc = 0;
                    m_messageInput = string.Format("Low side breaker open = {0} {1} {2} |", vc.ControlTransformers[i].DeviceId, vc.ControlTransformers[i].LowSideId, vc.ControlTransformers[i].LowSideV);
                }

                #endregion

                #region [ Check Transfromer Bus Voltage ]
                if (vc.ControlTransformers[i].VoltsV <vc.SubstationAlarmDevice.ZVLO || vc.ControlTransformers[i].VoltsV> vc.SubstationAlarmDevice.ZVHI)
                {
                    vc.ControlTransformers[i].InSvc = 0;
                    m_messageInput = string.Format("Volts out of range {0},{1} = {2}  set alarm |", vc.ControlTransformers[i].DeviceId, vc.ControlTransformers[i].VoltsId, vc.ControlTransformers[i].VoltsV);
                }

                #endregion

                #region [ Check Transformer Watts and Vars ]

                vc.ControlTransformers[i].StMvrV = vc.ControlTransformers[i].MvrV;
                if (Math.Abs(vc.ControlTransformers[i].MwV) < vc.SubstationAlarmDevice.ZLOWV && Math.Abs(vc.ControlTransformers[i].MvrV) < vc.SubstationAlarmDevice.ZLOWV)
                {
                    vc.ControlTransformers[i].InSvc = 0;
                    m_messageInput = string.Format("TX watts-vars {0} {1} {2} |", vc.ControlTransformers[i].DeviceId, vc.ControlTransformers[i].MwId, vc.ControlTransformers[i].MvrId);
                }

                #endregion

                #region [ Check Transformer LTC Tap Position ]
                if (vc.ControlTransformers[i].TapV <vc.SubstationAlarmDevice.ZLOTAP || vc.ControlTransformers[i].TapV> vc.SubstationAlarmDevice.ZHITAP)
                {
                    vc.ControlTransformers[i].InSvc = 0;
                    m_messageInput += string.Format("LTC Tap Position Unreasonable {0} {1} {2} ", vc.ControlTransformers[i].DeviceId, vc.ControlTransformers[i].TapId, vc.ControlTransformers[i].TapV);
                }

                #endregion

                #region [ For all Tx's that are in Service ]

                if (vc.ControlTransformers[i].InSvc != 0)
                {
                    vc.LtcStatus.Nins++;
                    vc.LtcStatus.Avv = vc.LtcStatus.Avv + vc.ControlTransformers[i].VoltsV;

                    if (vc.ControlTransformers[i].MvrV < vc.LtcStatus.MinVar)
                    {
                        vc.LtcStatus.RTX    = i;
                        vc.LtcStatus.MinVar = vc.ControlTransformers[i].MvrV;
                    }

                    if (vc.ControlTransformers[i].MvrV > vc.LtcStatus.MaxVar)
                    {
                        vc.LtcStatus.LTX    = i;
                        vc.LtcStatus.MaxVar = vc.ControlTransformers[i].MvrV;
                    }

                    if (vc.ControlTransformers[i].TapV < vc.LtcStatus.MinTap)
                    {
                        vc.LtcStatus.MinTap = vc.ControlTransformers[i].TapV;
                    }

                    if (vc.ControlTransformers[i].TapV > vc.LtcStatus.MaxTap)
                    {
                        vc.LtcStatus.MaxTap = vc.ControlTransformers[i].TapV;
                    }
                }
                else
                {
                    m_messageInput += string.Format("{0} {1} Transformer{2} is NOT service = {3}", vc.ControlTransformers[i].DeviceId, vc.ControlTransformers[i].LtcCtlId, i, vc.ControlTransformers[i].InSvc);
                }

                #endregion
            }

            return(vc);
        }
Пример #26
0
 private void Initialize()
 {
     m_previousFrame = new VoltVarController();
 }
Пример #27
0
        public VoltVarController ReadPreviousFrame(VoltVarController CurrentFrame, VoltVarController PreviousFrame)
        {
            PreviousFrame = CurrentFrame;
            //VcSubstationInfomation VcSubInfo = new VcSubstationInfomation();
            //VcTransformer VcTx = new VcTransformer();
            //VcCapacitorBank VcCap = new VcCapacitorBank();
            //VcSubstationAlarmDevice VcSubAlarm = new VcSubstationAlarmDevice();
            //ProgLogMessage ProgLogMsg = new ProgLogMessage();

            //if (infoline != null)
            //{
            //    // ltc_log_message(string.Format("Get Read info = {0}", infoline));
            //    char[] delimiterchars = { '|' };
            //    string[] arr = infoline.Split(delimiterchars);

            //    Hashtable Hashtable_temp = new Hashtable();

            //    char[] delimiterchars1 = { '~' };
            //    for (int i = 0; i < arr.Length; i++)
            //    {
            //        string[] splitedarr;
            //        splitedarr = arr[i].Split(delimiterchars1);
            //        string name = splitedarr[0];
            //        string val = splitedarr[1];
            //        Hashtable_temp[name] = val;
            //    }


            //    VcSubInfo.ConsecTap = (int)Hashtable_temp["ConsecTap"];
            //    VcSubInfo.ConsecCap = (int)Hashtable_temp["ConsecCap"];
            //    VcSubInfo.Ntdel = (int)Hashtable_temp["Ntdel"];
            //    VcSubInfo.Ncdel = (int)Hashtable_temp["Ncdel"];
            //    VcSubInfo.OldDay = (int)Hashtable_temp["OldDay"];

            //    VcSubAlarm.ZNTX = 2;
            //    VcSubAlarm.ZNCP = 2;

            //    for (int i = 0; i < VcSubAlarm.ZNTX; i++)
            //    {
            //        string prefix = "tx" + Convert.ToString(i);
            //        VcTx.CtlDone = Convert.ToInt32(Hashtable_temp[prefix + "CltDone"]);
            //        VcTx.TapV = (int)Hashtable_temp[prefix + "TapV"];
            //        VcTx.MvrV = (int)Hashtable_temp[prefix + "MvrV"];
            //        VcTx.PrevCtl = (string)Hashtable_temp[prefix + "PrevCtl"];

            //    }

            //    // two hashtables are indexed by a list
            //    for (int i = 0; i < VcSubAlarm.ZNCP; i++)
            //    {
            //        string prefix1 = "CP" + Convert.ToString(i);
            //        VcCap.CtlDone = Convert.ToInt32(Hashtable_temp[prefix1 + "CtlDone"]);
            //        VcCap.PrevCtl = (string)Hashtable_temp[prefix1 + "PrevCtl"];
            //        VcCap.NcTrip = Convert.ToInt32(Hashtable_temp[prefix1 + "NcTrip"]);
            //        VcCap.NcClose = Convert.ToInt32(Hashtable_temp[prefix1 + "NcClose"]);
            //        VcCap.TripEx = Convert.ToInt32(Hashtable_temp[prefix1 + "TripEx"]);
            //        VcCap.CloseEx = Convert.ToInt32(Hashtable_temp[prefix1 + "CloseEx"]);
            //    }
            //}
            //else
            //{
            //    ProgLogMsg.PrintProgLogMessage(string.Format("Nothing saved on previous run"));
            //    VcSubInfo.ConsecTap = 0;
            //}

            return(CurrentFrame);
        }