Example #1
0
    public static void RemoveSupply(PowerSupplyControlInheritance Supply, PowerTypeCategory category)
    {
        ElectricalSynchronisationStorage QuickAdd = new ElectricalSynchronisationStorage();

        QuickAdd.device   = Supply;
        QuickAdd.category = category;
        ToRemove.Enqueue(QuickAdd);
    }
Example #2
0
 public static void AddSupply(PowerSupplyControlInheritance Supply, PowerTypeCategory category)
 {
     if (!(AliveSupplies.ContainsKey(category)))
     {
         AliveSupplies[category] = new HashSet <PowerSupplyControlInheritance>();
     }
     AliveSupplies[category].Add(Supply);
     TotalSupplies.Add(Supply);
 }
Example #3
0
    public static void TurnOffEverything(PowerSupplyControlInheritance Battery)      //For turn off
    {
        Battery.ChargingWatts         = 0;
        Battery.ChargingMultiplier    = 0.1f;
        Battery.Resistance            = 0;
        Battery.ChargLastDeductedTime = 0;

        Battery.PullingWatts         = 0;
        Battery.current              = 0;
        Battery.PullLastDeductedTime = 0;
        //Battery.PassChangeToOff = false;
    }
Example #4
0
    //This should be the split up into different functions depending on what stage you want
    //This will give you back if you give it the right data, how it modifies resistance, and then How it modifies current
    public static Tuple <float, float> TransformerCalculate(PowerSupplyControlInheritance TransformInformation, float ResistanceToModify = 0, float Voltage = 0, float ResistanceModified = 0, float ActualCurrent = 0)
    {
        if (!(ResistanceToModify == 0))
        {
            //float R2 = ResistanceToModify;
            //float I2 = 1/ResistanceToModify;
            //float V2 = 1;

            //float Turn_ratio = TransformInformation.TurnRatio;

            //float V1 = (V2*Turn_ratio);
            //float I1 = (V2/V1)*I2;
            //float R1 = V1/I1;
            Tuple <float, float> returns = new Tuple <float, float>(
                (float)Math.Pow(TransformInformation.TurnRatio, 2.0) * (ResistanceToModify),
                0
                );
            return(returns);
        }
        if (!(Voltage == 0))
        {
            float offcut = 0;

            float V2 = Voltage / TransformInformation.TurnRatio;
            float R2 = V2 / ((Voltage / V2) * (Voltage / ResistanceModified));
            if (!(TransformInformation.VoltageLimiting == 0))              //if Total Voltage greater than that then  Push some of it to ground  to == VoltageLimitedTo And then everything after it to ground/

            {
                float SUBV2 = (ActualCurrent * ResistanceModified) / TransformInformation.TurnRatio;

                if ((V2 + SUBV2) > TransformInformation.VoltageLimiting)
                {
                    offcut = ((V2 + SUBV2) - TransformInformation.VoltageLimitedTo) / R2;
                    V2     = TransformInformation.VoltageLimitedTo - SUBV2;
                    if (V2 < 0)
                    {
                        V2 = 0;
                    }
                }
            }
            float I2 = V2 / R2;
            Tuple <float, float> returns = new Tuple <float, float>(
                I2,
                offcut
                );
            return(returns);
        }
        Tuple <float, float> returnsE = new Tuple <float, float>(0.0f, 0);

        return(returnsE);
    }
Example #5
0
 public static void PowerUpdateCurrentChange(PowerSupplyControlInheritance Battery)
 {
     if (Battery.Cansupport)           //Denotes capacity to Provide current
     {
         if (Battery.ToggleCansupport) //Denotes Whether at the current time it is allowed to provide current
         {
             if (Battery.ActualVoltage < Battery.MinimumSupportVoltage)
             {
                 if (Battery.CurrentCapacity > 0)
                 {
                     float NeedToPushVoltage = Battery.StandardSupplyingVoltage - Battery.ActualVoltage;
                     Battery.current = NeedToPushVoltage / Battery.CircuitResistance;
                     if (Battery.current > Battery.MaximumCurrentSupport)                           //Limits the maximum current
                     {
                         Battery.current = Battery.MaximumCurrentSupport;
                     }
                     Battery.PullingWatts = Battery.current * Battery.StandardSupplyingVoltage;                         // Should be the same as NeedToPushVoltage + powerSupply.ActualVoltage
                 }
             }
             else
             {
                 if (Battery.PullingWatts > 0)                       //Cleaning up values if it can't supply
                 {
                     Battery.PullingWatts         = 0;
                     Battery.current              = 0;
                     Battery.PullLastDeductedTime = 0;
                     //Logger.Log ("Turning off support due to voltage levels being suitable", Category.Electrical);
                 }
             }
         }
         else
         {
             if (Battery.PullingWatts > 0)                   //Cleaning up values if it can't supply
             {
                 Battery.PullingWatts         = 0;
                 Battery.current              = 0;
                 Battery.PullLastDeductedTime = 0;
                 //Logger.Log ("Supply was turned off due to termination a support", Category.Electrical);
             }
         }
     }
 }
Example #6
0
    public static void PowerNetworkUpdate(PowerSupplyControlInheritance Battery)
    {
        if (Battery.isOnForInterface)           //Checks if the battery is actually on This is not needed in PowerUpdateCurrentChange Since having those updates Would mean it would be on
        {
            if (Battery.CanCharge)              //Ability to charge
            {
                if (Battery.ToggleCanCharge)    //Is available for charging
                {
                    if (Battery.Resistance > 0)
                    {
                        if (Battery.ChargLastDeductedTime == 0)                           //so it's based on time
                        {
                            Battery.ChargLastDeductedTime = Time.time;
                        }
                        //Logger.Log (Battery.ActualVoltage.ToString () + " < ActualVoltage " + Battery.Resistance.ToString () + " < Resistance ", Category.Electrical);
                        Battery.ChargingWatts         = (Battery.ActualVoltage / Battery.Resistance) * Battery.ActualVoltage;
                        Battery.CurrentCapacity       = Battery.CurrentCapacity + (Battery.ChargingWatts * (Time.time - Battery.ChargLastDeductedTime));
                        Battery.ChargLastDeductedTime = Time.time;

                        if (Battery.ActualVoltage > Battery.IncreasedChargeVoltage)                           //Increasing the current charge by
                        {
                            if (!(Battery.ChargingMultiplier >= Battery.MaxChargingMultiplier))
                            {
                                Battery.ChargingMultiplier = Battery.ChargingMultiplier + Battery.ChargeSteps;
                                Battery.Resistance         = (1000 / ((Battery.StandardChargeNumber * Battery.ChargingMultiplier)));
                            }
                        }
                        else if (Battery.ActualVoltage < Battery.ExtraChargeCutOff)
                        {
                            if (!(0.1 >= Battery.ChargingMultiplier))
                            {
                                Battery.ChargingMultiplier = Battery.ChargingMultiplier - Battery.ChargeSteps;
                                Battery.Resistance         = (1000 / ((Battery.StandardChargeNumber * Battery.ChargingMultiplier)));
                            }
                            else                                 //Turning off charge if it pulls too much
                            {
                                Battery.ChargingWatts         = 0;
                                Battery.ChargingMultiplier    = 0.1f;
                                Battery.Resistance            = 0;
                                Battery.ChargLastDeductedTime = 0;
                            }
                        }


                        if (Battery.CurrentCapacity >= Battery.CapacityMax)                           //Making sure it doesn't go over Max capacity
                        {
                            Battery.CurrentCapacity       = Battery.CapacityMax;
                            Battery.ChargingWatts         = 0;
                            Battery.ChargingMultiplier    = 0.1f;
                            Battery.Resistance            = 0;
                            Battery.ChargLastDeductedTime = 0;
                            //Logger.Log ("Turn off charging battery full", Category.Electrical);
                        }
                    }
                    else if ((Battery.ActualVoltage > Battery.IncreasedChargeVoltage) && (!(Battery.CurrentCapacity >= Battery.CapacityMax)))
                    {
                        Battery.Resistance            = (1000 / ((Battery.StandardChargeNumber * Battery.ChargingMultiplier)));
                        Battery.ChargLastDeductedTime = Time.time;
                        //Logger.Log ("Charging turning back on from line voltage checks\n", Category.Electrical);
                    }
                }
                else
                {
                    if (Battery.Resistance > 0)
                    {
                        Battery.ChargingWatts         = 0;
                        Battery.ChargingMultiplier    = 0.1f;
                        Battery.Resistance            = 0;
                        Battery.ChargLastDeductedTime = 0;
                        //Logger.Log (" Turning off Charging because support was terminated for charging", Category.Electrical);
                    }
                }
            }

            if (Battery.Cansupport)
            {
                if (Battery.ToggleCansupport)
                {
                    if (Battery.PullingWatts > 0)
                    {
                        if (Battery.PullLastDeductedTime == 0)
                        {
                            Battery.PullLastDeductedTime = Time.time;
                        }
                        Battery.CurrentCapacity      = Battery.CurrentCapacity - (Battery.PullingWatts * (Time.time - Battery.PullLastDeductedTime));
                        Battery.PullLastDeductedTime = Time.time;
                        if (Battery.CurrentCapacity < 0)
                        {
                            Battery.CurrentCapacity      = 0;
                            Battery.ToggleCansupport     = false;
                            Battery.PullingWatts         = 0;
                            Battery.current              = 0;
                            Battery.PullLastDeductedTime = 0;
                            //Battery.PassChangeToOff = false;
                            //Logger.Log ("Turning off supply from loss of capacity", Category.Electrical);
                        }
                    }
                    else
                    {
                        if (Battery.ActualVoltage < Battery.MinimumSupportVoltage)
                        {
                            if (Battery.CurrentCapacity > 0)
                            {
                                float NeedToPushVoltage = Battery.StandardSupplyingVoltage - Battery.ActualVoltage;
                                Battery.current = NeedToPushVoltage / Battery.CircuitResistance;
                                if (Battery.current > Battery.MaximumCurrentSupport)
                                {
                                    Battery.current = Battery.MaximumCurrentSupport;
                                }
                                Battery.PullingWatts = Battery.current * Battery.StandardSupplyingVoltage;
                            }
                        }
                    }
                }
                else
                {
                    if (Battery.PullingWatts > 0)
                    {
                        //Battery.CurrentCapacity = 0;
                        //Battery.ToggleCansupport = false;
                        Battery.PullingWatts         = 0;
                        Battery.current              = 0;
                        Battery.PullLastDeductedTime = 0;
                    }
                }
            }
        }
    }
Example #7
0
    /// <summary>
    /// Clear currents and Calculate the currents And voltage
    /// </summary>
    private static void PowerUpdateCurrentChange()
    {
        for (int i = 0; i < UnconditionalSupplies.Count; i++)
        {
            foreach (PowerSupplyControlInheritance TheSupply in AliveSupplies[OrderList[i]])
            {
                if (NUCurrentChange.Contains(TheSupply) && !(NUStructureChangeReact.Contains(TheSupply)) && !(NUResistanceChange.Contains(TheSupply)))
                {
                    TheSupply.PowerUpdateCurrentChange();
                    NUCurrentChange.Remove(TheSupply);
                }
            }
        }
        HashSet <PowerSupplyControlInheritance> DoneSupplies   = new HashSet <PowerSupplyControlInheritance>();
        PowerSupplyControlInheritance           LowestReactive = null;
        int LowestReactiveint = 9999;
        List <PowerSupplyControlInheritance> QToRemove = new List <PowerSupplyControlInheritance>();

        while (NumberOfReactiveSupplies_f() > 0)
        {
            //Logger.Log("NUCurrentChange.Count > 0");
            foreach (PowerSupplyControlInheritance TheSupply in NUCurrentChange)
            {
                if (!DoneSupplies.Contains(TheSupply))
                {
                    if (TotalSupplies.Contains(TheSupply))
                    {
                        if (ReactiveSuppliesSet.Contains(TheSupply._IElectricityIO.InData.Categorytype))
                        {
                            if (NUCurrentChange.Contains(TheSupply) && !(NUStructureChangeReact.Contains(TheSupply)) && !(NUResistanceChange.Contains(TheSupply)))
                            {
                                if (LowestReactive == null)
                                {
                                    LowestReactive    = TheSupply;
                                    LowestReactiveint = NumberOfReactiveSupplies(TheSupply._IElectricityIO);
                                }
                                else if (LowestReactiveint > NumberOfReactiveSupplies(TheSupply._IElectricityIO))
                                {
                                    LowestReactive    = TheSupply;
                                    LowestReactiveint = NumberOfReactiveSupplies(TheSupply._IElectricityIO);
                                }
                                //TheSupply.GameObject().GetComponent<ElectricalOIinheritance>().Data.ResistanceToConnectedDevices
                            }
                            else
                            {
                                QToRemove.Add(TheSupply);
                            }
                        }
                    }
                    else
                    {
                        QToRemove.Add(TheSupply);
                    }
                }
                else
                {
                    QToRemove.Add(TheSupply);
                }
            }
            if (LowestReactive != null)
            {
                LowestReactive.PowerUpdateCurrentChange();
                NUCurrentChange.Remove(LowestReactive);
                DoneSupplies.Add(LowestReactive);
            }

            LowestReactive    = null;
            LowestReactiveint = 9999;
            foreach (PowerSupplyControlInheritance re in QToRemove)
            {
                NUCurrentChange.Remove(re);
            }
            QToRemove = new List <PowerSupplyControlInheritance>();
        }
    }