示例#1
0
        /// <summary>
        /// Тестовая схема №5.
        /// </summary>
        /// <returns></returns
        private IComponent _circuit5()
        {
            var R1       = new Resistor("R1", 100);
            var R2       = new Resistor("R2", 100);
            var C1       = new Capacitor("C1", 0.005);
            var C2       = new Capacitor("C2", 0.005);
            var C3       = new Capacitor("C3", 0.005);
            var L1       = new Inductor("L1", 0.5);
            var L2       = new Inductor("L2", 0.5);
            var circuit1 = new SerialCircuit("circuit1");
            var circuit2 = new ParallelCircuit("circuit2");
            var circuit3 = new SerialCircuit("circuit3");
            var circuit4 = new SerialCircuit("circuit4");
            var circuit5 = new ParallelCircuit("circuit5");

            circuit5.Circuit.Add(C3);
            circuit5.Circuit.Add(R1);
            circuit4.Circuit.Add(R2);
            circuit4.Circuit.Add(L2);
            circuit3.Circuit.Add(L1);
            circuit3.Circuit.Add(circuit5);
            circuit2.Circuit.Add(C2);
            circuit2.Circuit.Add(circuit3);
            circuit2.Circuit.Add(circuit4);
            circuit1.Circuit.Add(C1);
            circuit1.Circuit.Add(circuit2);
            return(circuit1);
        }
示例#2
0
        /// <summary>
        /// Кнопка рандомного элемента
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void randomelement_Click(object sender, EventArgs e)
        {
            ICircuit randomCircuit;
            var      random      = new Random();
            var      elementType = random.Next(3);

            if (elementType == 0)
            {
                randomCircuit = new Resistor()
                {
                    Resistance = random.Next(500)
                };
            }
            else if (elementType == 1)
            {
                randomCircuit = new Capacitor()
                {
                    Capacitance = random.Next(9000000)
                };
            }
            else
            {
                randomCircuit = new Induct()
                {
                    Inductance = random.Next(9000000)
                };
            }
            listCircuit.Add(randomCircuit);
            var row = _datatable.NewRow();

            row[0] = randomCircuit.Name;
            row[1] = Convert.ToString(randomCircuit.CalculateValue(Convert.ToDouble(FrequencyTextBox.Text)));
            _datatable.Rows.Add(row); //Добавление строки
            dataGridView1.Update();   //Обновление таблицы
        }
示例#3
0
        /// <summary>
        ///     Получить элемент
        /// </summary>
        /// <param name="nodeType">Тип узла</param>
        /// <param name="name">Имя</param>
        /// <param name="value">Номинал</param>
        /// <returns>Элемент</returns>
        public static ElementBase GetInstance(NodeType nodeType, string name,
                                              double value)
        {
            ElementBase newElement;

            switch (nodeType)
            {
            case NodeType.Resistor:
                newElement = new Resistor(name, value);

                break;

            case NodeType.Inductor:
                newElement = new Inductor(name, value);

                break;

            case NodeType.Capacitor:
                newElement = new Capacitor(name, value);

                break;

            default:
                throw new ArgumentException("Некорректный тип узла.");
            }

            return(newElement);
        }
示例#4
0
        static void Main(string[] args)
        {
            IElement resistor = new Resistor();

            resistor.Value = 15.0;
            resistor.Name  = "R1";
            var impedanceR = resistor.GetImpedance(1.0);

            Console.WriteLine(impedanceR.ToString());

            IElement inductor = new Inductor();

            inductor.Value = 25.0;
            inductor.Name  = "L1";
            var impedanceI = inductor.GetImpedance(33);

            Console.WriteLine(impedanceI.ToString());

            IElement capacitor = new Capacitor();

            capacitor.Value = 32.2;
            capacitor.Name  = "C1";
            var impendanceC = capacitor.GetImpedance(22);

            Console.WriteLine(impendanceC.ToString());
        }
示例#5
0
        static void Main(string[] args)
        {
            bool f           = false;
            var  ElementList = new List <IElement>();

            while (f != true)
            {
                try
                {
                    var r1 = new Resistor(Convert.ToDouble(Console.ReadLine()));
                    var i1 = new Inductor(Convert.ToDouble(Console.ReadLine()));
                    var c1 = new Capacitor(Convert.ToDouble(Console.ReadLine()));
                    ElementList.Add(r1);
                    ElementList.Add(i1);
                    ElementList.Add(c1);
                    f = true;
                }

                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }


            Complex sum;

            sum = ElementList[0].GetImpedance(2e9 * 2 * Math.PI) + ElementList[1].GetImpedance(2e9 * 2 * Math.PI);

            Console.WriteLine("\n" + ElementList[0].GetImpedance(3e9 * 2 * Math.PI) + " + " + ElementList[1].GetImpedance(3e9 * 2 * Math.PI) + " = " + sum);

            Console.ReadKey();
        }
示例#6
0
        public override void Initialize()
        {
            base.Initialize();

            MicroWorld.Logics.CircuitManager.RegisterReUpdatingComponent(this);
            par = parent as Capacitor;
        }
        /// <summary>
        /// Вводит данные о новом конденсаторе
        /// </summary>
        /// <returns></returns>
        private Capacitor GetNewCapacitor()
        {
            var newCapacitor = new Capacitor();
            var actions      = new List <Action>()
            {
                new Action(() =>
                {
                    ReadingAndParsing.ReadAndParse(
                        PassiveElementParameter1_textBox.Text,
                        TranslateParameter(NamesOfPassiveElementParameters.
                                           Frecuency.ToString()),
                        out double frecuency);
                    newCapacitor.Frecuency = frecuency;
                }),
                new Action(() =>
                {
                    ReadingAndParsing.ReadAndParse(
                        PassiveElementParameter2_textBox.Text,
                        TranslateParameter(NamesOfPassiveElementParameters.
                                           Capacity.ToString()),
                        out double capacity);
                    newCapacitor.Сapacity = capacity;
                })
            };

            actions.ForEach(SetValue);
            return(newCapacitor);
        }
示例#8
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="converter">所属变换器</param>
        public ThreeLevelBoost(DCDCConverter converter)
        {
            //获取设计规格
            this.converter = converter;
            math_Pfull     = converter.Math_Psys / converter.Number;
            math_fs        = converter.Math_fs;
            math_Vin_min   = converter.Math_Vin_min;
            math_Vin_max   = converter.Math_Vin_max;
            math_Vo        = converter.Math_Vo;

            //初始化元器件
            dualModule = new DualModule(2, false)
            {
                Name      = "开关器件",
                Name_Up   = "二极管",
                Name_Down = "开关管"
            };
            inductor = new DCInductor(1)
            {
                Name = "滤波电感"
            };
            capacitor = new FilteringCapacitor(2)
            {
                Name = "滤波电容"
            };
            components         = new Component[] { dualModule, inductor, capacitor };
            componentGroups    = new Component[1][];
            componentGroups[0] = new Component[] { dualModule, inductor, capacitor };
        }
        /// <summary>
        /// Генерация случайного элемента
        /// </summary>
        /// <returns></returns>
        static public IElement CreateRandomElement()
        {
            Random rand = new Random();
            int    n    = rand.Next(0, 3);

            switch (n)
            {
            case 0:
            {
                var r = new Resistor();
                r.Value = rand.Next(0, 200);
                r.Name  = "R";
                return(r);
            }

            case 1:
            {
                var c = new Capacitor();
                c.Value = rand.Next(0, 200);
                c.Name  = "C";
                return(c);
            }

            case 2:
            {
                var i = new Inductor();
                i.Value = rand.Next(0, 200);
                i.Name  = "I";
                return(i);
            }
            }
            return(null);
        }
示例#10
0
        public void CalculateZTest(double frequency)
        {
            Capacitor capacitor = new Capacitor("C", 50);
            double    expected  = 1 / (2 * Math.PI * frequency * 50);


            Assert.AreEqual(expected, capacitor.CalculateZ(frequency).Imaginary, 0.001);
        }
示例#11
0
 public override void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc)
 {
     base.GetBlockInfo(forPlayer, dsc);
     dsc.AppendLine("On:" + isOn.ToString());
     dsc.AppendLine("Volts:" + MaxVolts.ToString() + "V" + " Amps:" + maxAmps.ToString());
     dsc.AppendLine("Power:" + Capacitor.ToString() + "/" + Capacitance.ToString());
     dsc.AppendLine("IN:" + inputConnections.Count.ToString() + " OUT:" + outputConnections.Count.ToString());
 }
示例#12
0
        public void GetImpedanceTest(double resultReal, double resulrImaginary, double angularFrequency, double value)
        {
            var capacitor = new Capacitor(value);
            var impedance = capacitor.GetImpedance(angularFrequency);

            Assert.AreEqual(resultReal, impedance.Real);
            Assert.AreEqual(resulrImaginary, impedance.Imaginary);
        }
示例#13
0
文件: LLC.cs 项目: yufeijie/learngit
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="converter">所属变换器</param>
        public LLC(IsolatedDCDCConverter converter)
        {
            //获取设计规格
            this.converter = converter;
            math_Pfull     = converter.Math_Psys / converter.PhaseNum / converter.Number;
            math_Vin       = converter.Math_Vin;
            math_Vo        = converter.Math_Vo;
            math_No        = converter.Math_No;
            math_fs        = converter.Math_fs;
            math_Q         = converter.Math_Q;
            math_k         = converter.Math_k;
            math_Tdead     = math_fs < Configuration.SIC_SELECTION_FREQUENCY ? Configuration.IGBT_DEAD_TIME : Configuration.MOSFET_DEAD_TIME;

            //初始化元器件
            primaryDualModule = new DualModule(2)
            {
                Name            = "原边开关管",
                VoltageVariable = false
            };
            secondaryDualDiodeModule = new DualDiodeModule(2 * math_No)
            {
                Name            = "副边二极管",
                VoltageVariable = false
            };
            resonantInductor = new ACInductor(1)
            {
                Name            = "谐振电感",
                VoltageVariable = false
            };
            transformer = new Transformer(1)
            {
                Name            = "变压器",
                VoltageVariable = false
            };
            resonantCapacitor = new ResonantCapacitor(1)
            {
                Name            = "谐振电容",
                VoltageVariable = false,
            };
            filteringCapacitor = new FilteringCapacitor(math_No)
            {
                Name            = "滤波电容",
                VoltageVariable = false,
            };

            componentGroups = new Component[1][];
            if (Configuration.IS_RESONANT_INDUCTOR_INTEGRATED)
            {
                components         = new Component[] { primaryDualModule, secondaryDualDiodeModule, transformer, resonantCapacitor, filteringCapacitor };
                componentGroups[0] = new Component[] { primaryDualModule, secondaryDualDiodeModule, transformer, resonantCapacitor, filteringCapacitor };
            }
            else
            {
                components         = new Component[] { primaryDualModule, secondaryDualDiodeModule, resonantInductor, transformer, resonantCapacitor, filteringCapacitor };
                componentGroups[0] = new Component[] { primaryDualModule, secondaryDualDiodeModule, resonantInductor, transformer, resonantCapacitor, filteringCapacitor };
            }
        }
示例#14
0
        public void capacitorImpedanceTest(double _value, double _freq)
        {
            IElement impCapacitor = new Capacitor();

            impCapacitor.Value = _value;
            Complex capComplex = new Complex(0.0, 100 * Math.PI);

            Assert.AreEqual(impCapacitor.GetImpedance(_freq), capComplex);
        }
    public override void OnContact(Capacitor other)
    {
        int desiredEndOtherCharge = other.currentCharge + this.currentCharge;

        int actualEndOtherCharge = Mathf.Clamp(desiredEndOtherCharge, -other.capacity, other.capacity);

        this.currentCharge += other.currentCharge - actualEndOtherCharge;
        other.currentCharge = actualEndOtherCharge;
    }
示例#16
0
    public override void GenerateCurrentDots()
    {
        Device[] devices = Device.GetDevices();
        foreach (Device device in devices)
        {
            List <Vector3> pointsList = new List <Vector3>();
            switch (device.DeviceType)
            {
            case Device.TypeEnum.Capacitor:
                Capacitor tempCapacitor = device as Capacitor;
                pointsList.Add(tempCapacitor.NegativeNode.ConnectedNode.transform.position);
                pointsList.Add(tempCapacitor.NegativeNode.transform.position);
                pointsList.Add(tempCapacitor.PositiveNode.transform.position);
                pointsList.Add(tempCapacitor.PositiveNode.ConnectedNode.transform.position);
                //print("There is a capacitor");
                break;

            case Device.TypeEnum.Ground:
                break;

            case Device.TypeEnum.Resistor:
                Resistor tempResistor = device as Resistor;
                pointsList.Add(tempResistor.NegativeNode.ConnectedNode.transform.position);
                pointsList.Add(tempResistor.NegativeNode.transform.position);
                pointsList.Add(tempResistor.PositiveNode.transform.position);
                pointsList.Add(tempResistor.PositiveNode.ConnectedNode.transform.position);
                break;

            case Device.TypeEnum.PulseVoltageSource:
                PulseVoltageSource tempPulseVoltageSource = device as PulseVoltageSource;
                pointsList.Add(tempPulseVoltageSource.NegativeNode.ConnectedNode.transform.position);
                pointsList.Add(tempPulseVoltageSource.NegativeNode.transform.position);
                pointsList.Add(tempPulseVoltageSource.PositiveNode.transform.position);
                pointsList.Add(tempPulseVoltageSource.PositiveNode.ConnectedNode.transform.position);
                break;
            }
            for (int i = 0; i < pointsList.Count - 1; i++)
            {
                if (pointsList[i] != pointsList[i + 1])
                {
                    GameObject currentDotGo =
                        (GameObject)Instantiate(Container.CircuitElements.CurrentDot, pointsList[i],
                                                Quaternion.identity);
                    CurrentDot currentDot = currentDotGo.GetComponent <CurrentDot>();
                    currentDot.AttachedDevice = device;
                    currentDot.StartPos       = pointsList[i];
                    currentDot.EndPos         = pointsList[i + 1];
                    print(pointsList[i]);
                }
            }
        }
    }
示例#17
0
 public void OnChargeChange(Capacitor capa)
 {
     if ((targetCharge > 0 &&
          capa.currentCharge >= targetCharge) ||
         (targetCharge <= 0 &&
          capa.currentCharge <= targetCharge))
     {
         StartCoroutine(Move(openHeight));
     }
     else
     {
         StartCoroutine(Move(closedHeight));
     }
 }
示例#18
0
文件: ExcelHelper.cs 项目: wwwK/2016
        public List <Capacitor> GetDatasFromAccess_Capacitor(string path, string sheetName = "Sheet1")
        {
            try
            {
                workbook  = Factory.GetWorkbook(path);
                worksheet = workbook.Worksheets[sheetName];
                if (worksheet == null)
                {
                    throw new Exception("worksheet为空");
                }
                int count = worksheet.UsedRange.RowCount - 1;
                List <Capacitor> lstCapacitor = new List <Capacitor>();
                for (int i = 0; i < count; i++)
                {
                    Capacitor obj = new Capacitor();
                    //从第2行开始为第一个数据
                    obj.PartNumber                = worksheet.Cells[string.Format("A{0}", i + 2)].Value.ToString();
                    obj.PartType                  = worksheet.Cells[string.Format("B{0}", i + 2)].Value.ToString();
                    obj.Value                     = worksheet.Cells[string.Format("C{0}", i + 2)].Value == null?null:worksheet.Cells[string.Format("C{0}", i + 2)].Value.ToString();
                    obj.Description               = worksheet.Cells[string.Format("D{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("D{0}", i + 2)].Value.ToString();
                    obj.RatedVoltage              = worksheet.Cells[string.Format("E{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("E{0}", i + 2)].Value.ToString();
                    obj.Tolerance                 = worksheet.Cells[string.Format("F{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("F{0}", i + 2)].Value.ToString();
                    obj.SchematicPart             = worksheet.Cells[string.Format("G{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("G{0}", i + 2)].Value.ToString();
                    obj.LayoutPCBFootprint        = worksheet.Cells[string.Format("H{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("H{0}", i + 2)].Value.ToString();
                    obj.AllegroPCBFootprint       = worksheet.Cells[string.Format("I{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("I{0}", i + 2)].Value.ToString();
                    obj.PSpice                    = worksheet.Cells[string.Format("J{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("J{0}", i + 2)].Value.ToString();
                    obj.ManufacturerPartNumber    = worksheet.Cells[string.Format("K{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("K{0}", i + 2)].Value.ToString();
                    obj.Manufacturer              = worksheet.Cells[string.Format("L{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("L{0}", i + 2)].Value.ToString();
                    obj.DistributorPartNumber     = worksheet.Cells[string.Format("M{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("M{0}", i + 2)].Value.ToString();
                    obj.Distributor               = worksheet.Cells[string.Format("N{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("N{0}", i + 2)].Value.ToString();
                    obj.Price                     = worksheet.Cells[string.Format("O{0}", i + 2)].Value == null ? 0 : Convert.ToDouble(worksheet.Cells[string.Format("O{0}", i + 2)].Value.ToString());
                    obj.Availability              = worksheet.Cells[string.Format("P{0}", i + 2)].Value == null ? null : worksheet.Cells[string.Format("P{0}", i + 2)].Value.ToString();
                    obj.Datasheet                 = GetValue(worksheet.Cells[string.Format("Q{0}", i + 2)].Value);
                    obj.ActivepartsID             = GetValue(worksheet.Cells[string.Format("R{0}", i + 2)].Value);
                    obj.OperatingTemperatureRange = GetValue(worksheet.Cells[string.Format("S{0}", i + 2)].Value);
                    obj.StorageTemperatureRange   = GetValue(worksheet.Cells[string.Format("T{0}", i + 2)].Value);
                    lstCapacitor.Add(obj);
                }

                workbook.Close();
                return(lstCapacitor);
            }
            catch (Exception e)
            {
                workbook.Close();
                string exPath = "exception.txt";
                System.IO.File.AppendAllText(exPath, e.Message);
                throw e;
            }
        }
示例#19
0
        /// <summary>
        /// Тестовая схема №2.
        /// </summary>
        /// <returns></returns
        private IComponent _circuit2()
        {
            var R1       = new Resistor("R1", 100);
            var C1       = new Capacitor("C1", 0.005);
            var L1       = new Inductor("L1", 0.5);
            var circuit1 = new SerialCircuit("circuit1");
            var circuit2 = new ParallelCircuit("circuit2");

            circuit2.Circuit.Add(R1);
            circuit2.Circuit.Add(C1);
            circuit1.Circuit.Add(circuit2);
            circuit1.Circuit.Add(L1);
            return(circuit1);
        }
示例#20
0
        /// <summary>
        /// Generate a capacitor
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="parameters">Parameters</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        protected ICircuitObject GenerateCap(CircuitIdentifier name, List <Token> parameters, Netlist netlist)
        {
            Capacitor cap = new Capacitor(name);

            cap.ReadNodes(netlist.Path, parameters);

            // Search for a parameter IC, which is common for both types of capacitors
            for (int i = 3; i < parameters.Count; i++)
            {
                if (parameters[i].kind == ASSIGNMENT)
                {
                    AssignmentToken at = parameters[i] as AssignmentToken;
                    if (at.Name.image.ToLower() == "ic")
                    {
                        double ic = netlist.ParseDouble(at.Value);
                        cap.CAPinitCond.Set(ic);
                        parameters.RemoveAt(i);
                        break;
                    }
                }
            }

            // The rest is just dependent on the number of parameters
            if (parameters.Count == 3)
            {
                cap.CAPcapac.Set(netlist.ParseDouble(parameters[2]));
            }
            else
            {
                cap.SetModel(netlist.FindModel <CapacitorModel>(parameters[2]));
                switch (parameters[2].kind)
                {
                case WORD:
                case IDENTIFIER:
                    cap.SetModel(netlist.Path.FindModel <CapacitorModel>(netlist.Circuit.Objects, new CircuitIdentifier(parameters[2].image)));
                    break;

                default:
                    throw new ParseException(parameters[2], "Model name expected");
                }
                netlist.ReadParameters(cap, parameters, 2);
                if (!cap.CAPlength.Given)
                {
                    throw new ParseException(parameters[1], "L needs to be specified", false);
                }
            }

            return(cap);
        }
示例#21
0
        public void When_IsTemperatureDependent_Expect_Reference()
        {
            /*
             * A test for a lowpass RC circuit (DC voltage, resistor, capacitor)
             * The initial voltage on capacitor is 0V. The result should be an exponential converging to dcVoltage.
             * TC1 and TC2 of capacitor is 0.
             * Temperature is 30 degrees.
             */
            double dcVoltage                   = 10;
            var    resistorResistance          = 10e3; // 10000;
            double factor                      = (1.0 + 3.0 * 1.1 + 3.0 * 3.0 * 2.1);
            var    capacitance                 = 1e-6;
            var    capacitanceAfterTemperature = capacitance * factor;

            var tau = resistorResistance * capacitanceAfterTemperature;

            var capacitor = new Capacitor("C1", "OUT", "0", capacitance);
            var model     = new CapacitorModel("model C1");

            model.Parameters.TemperatureCoefficient1 = 1.1;
            model.Parameters.TemperatureCoefficient2 = 2.1;
            capacitor.Model = model.Name;

            // Build circuit
            var ckt = new Circuit(
                model,
                capacitor,
                new Resistor("R1", "IN", "OUT", resistorResistance),
                new VoltageSource("V1", "IN", "0", dcVoltage));

            // Create simulation, exports and references
            var tran = new Transient("tran", 1e-8, 10e-6);

            tran.TimeParameters.InitialConditions["OUT"] = 0.0;

            tran.BeforeTemperature += (sender, args) =>
            {
                var state = tran.GetState <ITemperatureSimulationState>();
                ((TemperatureSimulationState)state).Temperature = Constants.CelsiusKelvin + 30.0;
            };

            IExport <double>[]      exports    = { new RealPropertyExport(tran, "C1", "v") };
            Func <double, double>[] references = { t => dcVoltage * (1.0 - Math.Exp(-t / tau)) };

            // Run
            AnalyzeTransient(tran, ckt, exports, references);
            DestroyExports(exports);
        }
    public override void OnContact(Capacitor other)
    {
        // Adapt charge (steal from other)
        int desiredEndCharge = this.currentCharge + other.currentCharge;

        int actualEndCharge = Mathf.Clamp(desiredEndCharge, -capacity, capacity);

        other.currentCharge += this.currentCharge - actualEndCharge;
        this.currentCharge   = actualEndCharge;

        // Notify connected trigger if any
        if (connected != null)
        {
            connected.GetComponent <ITriggerable>().OnChargeChange(this);
        }
    }
示例#23
0
        public void ResetForPool()
        {
            spriteRenderer.sprite = null;

            attackSound = null;
            jumpSound   = null;
            runSound    = null;

            hp = null;
            ap = null;

            move = 0;
            jump = 0;

            size = UnitSize.small;
        }
示例#24
0
        public void LoadRecipe(MapUnitRecipe recipe)
        {
            spriteRenderer.sprite = recipe.sprite;

            attackSound = recipe.attackSound;
            jumpSound   = recipe.jumpSound;
            runSound    = recipe.runSound;

            hp = new Capacitor(recipe.maxHp);
            ap = new Capacitor(recipe.maxAp);

            move = recipe.move;
            jump = recipe.jump;

            size = recipe.size;
        }
示例#25
0
    private void Start()
    {
        startScale = transform.localScale;

        oldPosition   = transform.position;
        oldLocalScale = transform.localScale;

        capacitor = GetComponentInParent <Capacitor>();

        resizeWidthObject1  = CreateResizeObject(Vector3.right, maxWidthSize);
        resizeWidthObject2  = CreateResizeObject(Vector3.right, maxWidthSize);
        resizeHeightObject1 = CreateResizeObject(Vector3.up, maxHeightSize);
        resizeHeightObject2 = CreateResizeObject(Vector3.up, maxHeightSize);

        EnableResizeObjects(false);

        disableWhenIdle = false;
    }
示例#26
0
        public void When_CapacitorIsTemperatureInvariant_Expect_Reference()
        {
            /*
             * A test for a lowpass RC circuit (DC voltage, resistor, capacitor)
             * The initial voltage on capacitor is 0V. The result should be an exponential converging to dcVoltage.
             * TC1 and TC2 of capacitor is 0.
             * Temperature is 30 degrees.
             */
            double dcVoltage          = 10;
            var    resistorResistance = 10e3; // 10000;
            var    capacitance        = 1e-6; // 0.000001;
            var    tau = resistorResistance * capacitance;

            var capacitor = new Capacitor("C1", "OUT", "0", capacitance);
            var model     = new CapacitorModel("model C1");

            model.ParameterSets.Get <ModelBaseParameters>().TemperatureCoefficient1.Value = 0.0;
            model.ParameterSets.Get <ModelBaseParameters>().TemperatureCoefficient2.Value = 0.0;
            capacitor.Model = model.Name;

            // Build circuit
            var ckt = new Circuit(
                model,
                capacitor,
                new Resistor("R1", "IN", "OUT", resistorResistance),
                new VoltageSource("V1", "IN", "0", dcVoltage));

            // Create simulation, exports and references
            var tran = new Transient("tran", 1e-8, 10e-6);

            tran.Configurations.Get <TimeConfiguration>().InitialConditions["OUT"] = 0.0;

            tran.BeforeTemperature += (sender, args) =>
            {
                ((BaseSimulationState)args.State).Temperature = Constants.CelsiusKelvin + 30.0;
            };

            Export <double>[]       exports    = { new RealPropertyExport(tran, "C1", "v") };
            Func <double, double>[] references = { t => dcVoltage * (1.0 - Math.Exp(-t / tau)) };

            // Run
            AnalyzeTransient(tran, ckt, exports, references);
            DestroyExports(exports);
        }
示例#27
0
 /// <summary>
 /// Метод возвращающий номинал элемента
 /// </summary>
 /// <returns></returns>
 public IComponent.IComponent CalculateImpedance()
 {
     if (ElementComboBox.Text == "Resistor")
     {
         if (ResistorTextBox.Text == "" || ResistorTextBox.Text[0].ToString() == ",")
         {
             throw new ArgumentException("Value Error!");
         }
         else
         {
             var resistor = new Resistor(Convert.ToDouble(ResistorTextBox.Text));
             return(resistor);
         }
     }
     else if (ElementComboBox.Text == "Capacitor")
     {
         if (CapacitorTextBox.Text == "" || CapacitorTextBox.Text[0].ToString() == ",")
         {
             throw new ArgumentException("Value Error!");
         }
         else
         {
             var capacitor = new Capacitor(Convert.ToDouble(CapacitorTextBox.Text));
             return(capacitor);
         }
     }
     else if (ElementComboBox.Text == "Inductor")
     {
         if (InductorTextBox.Text == "" || InductorTextBox.Text[0].ToString() == ",")
         {
             throw new ArgumentException("Value Error!");
         }
         else
         {
             var inductor = new Inductor(Convert.ToDouble(InductorTextBox.Text));
             return(inductor);
         }
     }
     else
     {
         return(null);
     }
 }
示例#28
0
        /// <summary>
        /// Создание случайной пассивного элемента
        /// </summary>
        /// <returns>Ексемпляр пассивного элемента</returns>
        public static PassiveElementBase GetRandomPassiveElement()
        {
            PassiveElementBase passiveElement = new Capacitor();

            int typePassiveElement = _random.Next(0, 3);

            if (typePassiveElement == 0)
            {
                passiveElement = new Capacitor();

                (passiveElement as Capacitor).Сapacity =
                    Convert.ToDouble(_random.Next(0, 10000));

                (passiveElement as Capacitor).Frecuency =
                    Convert.ToDouble(_random.Next(0, 10000));
            }

            if (typePassiveElement == 1)
            {
                passiveElement = new Resistor();

                (passiveElement as Resistor).Resistance =
                    Convert.ToDouble(_random.Next(0, 10000));
            }

            if (typePassiveElement == 2)
            {
                passiveElement = new Inductor();

                (passiveElement as Inductor).Inductance =
                    Convert.ToDouble(_random.Next(0, 10000));

                (passiveElement as Inductor).Frecuency =
                    Convert.ToDouble(_random.Next(0, 10000));
            }

            return(passiveElement);
        }
示例#29
0
    private void AddElectricalElement(Slot slot, Circuit ckt)
    {
        string componentName  = "S" + slot.slotID;
        string componentStart = "C" + GetSlotColumn(slot.slotID);
        string componentEnd   = "C" + GetSlotColumn(slot.slotPair.GetComponent <Slot>().slotID);

        if (slot.slotType == Globals.SlotType.BananaPlugSlot)
        {
            componentStart = "B" + slot.slotID;
        }

        float value = GetComponentValue(slot);

        switch (slot.itemPlaced.itemName)
        {
        case (Globals.AvailableItems.Wire):
            Resistor wire = new Resistor(componentName, componentStart, componentEnd, wireResistance);
            Debug.Log("Adding Wire: " + componentName + " " + componentStart + " " + componentEnd + " " + wireResistance);
            ckt.Add(wire);
            break;

        case (Globals.AvailableItems.Resistor):
            Resistor resistor = new Resistor(componentName, componentStart, componentEnd, value);
            Debug.Log("Adding Resistor: " + componentName + " " + componentStart + " " + componentEnd + " " + value);
            ckt.Add(resistor);
            break;

        case (Globals.AvailableItems.Capacitor):
            Capacitor capacitor = new Capacitor(componentName, componentStart, componentEnd, value);
            Debug.Log("Adding Capacitor: " + componentName + " " + componentStart + " " + componentEnd + " " + value);
            ckt.Add(capacitor);
            break;

        default:
            Debug.Log("Nothing found");
            break;
        }
    }
示例#30
0
    // public void awgPlusFunction(){

    // }

    // public void awgMinusFunction(){

    // }

    public void setCapacitorValueWindow()
    {
        Capacitor capacitor = (Capacitor)getComponentDataObject();

        constraintsComponentList = new List <string> {
            "--------------"
        };
        //Debug.Log("constraintsHandle.getBoardId() = " + constraintsHandle.getBoardId());
        if (constraintsHandle.getBoardId() == "101")  // resistor 8
        //constraintsComponentList = new List<string> {"Resistor0", "Resistor1", "Resistor2", "Resistor3", "Resistor4", "Resistor5", "Resistor6", "Resistor7"};
        {
            constraintsComponentList.Add("resistor0");
            constraintsComponentList.Add("resistor1");
            constraintsComponentList.Add("resistor2");
            constraintsComponentList.Add("resistor3");
            constraintsComponentList.Add("resistor4");
            constraintsComponentList.Add("resistor5");
            constraintsComponentList.Add("resistor6");
            constraintsComponentList.Add("resistor7");
            constraintsComponentList.Remove(transform.parent.name);
        }
        else if (constraintsHandle.getBoardId() == "102")
        {
            //constraintsComponentList = new List<string> {"Resistor0", "Resistor1", "Capacitor2", "Capacitor3", "Voltmeter"};
            constraintsComponentList.Add("resistor0");
            constraintsComponentList.Add("resistor1");
            constraintsComponentList.Remove(transform.parent.name);
        }

        //Debug.Log("deleteOptionWindow " + transform.parent.name);
        selectCapacitorValuePanel.Choice(capacitorSaveAction, capacitorCancelAction, resetAllStateAction, constraintsComponentList, transform.parent.name);
        selectCapacitorValuePanel.setTitle("SelectValuePanelTitle", transform.parent.name);
        selectCapacitorValuePanel.setPosition(new Vector3(0, 210, 250));
        selectCapacitorValuePanel.setComponent("capacitor");
        selectCapacitorValuePanel.setOptionValues(capacitor.optionValues);
        //Debug.Log("cc = " + (int)componentValue);
        selectCapacitorValuePanel.setSelectedToggle(capacitorToggleValue);
        selectCapacitorValuePanel.setSelectedIndexValue(capacitorToggleValue);

        if (constraintsSelectedValue == 0)
        {
            for (int i = 0; i < constraintsComponentList.Count; i++)
            {
                if (constraintsComponentList[i] == constraintsHandle.getConstrainSource(transform.parent.name))
                {
                    constraintsSelectedValue = i;
                }
            }
        }
        else if (!constraintsHandle.containsConstrainSource(transform.parent.name) && !constraintsHandle.containsConstrainTarget(transform.parent.name))
        {
            constraintsSelectedValue = 0;
        }

        //Debug.Log("constraintsSelectedValue = " + constraintsSelectedValue);

        if (constraintsSelectedValue > 0)
        {
            setFrequencyInfoDisplay(true, "SelectValuePanel");
        }
        else
        {
            setFrequencyInfoDisplay(false, "SelectValuePanel");
        }

        selectCapacitorValuePanel.setConstraintsSelected(constraintsSelectedValue);
        // if(selectCapacitorValuePanel.getSumOfSelectedValue() == 0)
        //     selectCapacitorValuePanel.resetToggles();
        //Debug.Log("x = " + transform.position.x + " y = " + transform.position.y + " z = " + transform.position.z);
    }
示例#31
0
        public override void Initialize()
        {
            base.Initialize();

            MicroWorld.Logics.CircuitManager.RegisterReUpdatingComponent(this);
            par = parent as Capacitor;
        }