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(); }
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()); }
public InductorElm(Point pos) : base(pos) { mInd = new Inductor(mCir); Inductance = 0.001; ReferenceName = "L"; mInd.Setup(Inductance, mCurrent, mFlags); }
public void CalculateZTest(double frequency) { Inductor inductor = new Inductor("I", 50); double expected = 2 * Math.PI * frequency * 50; Assert.AreEqual(expected, inductor.CalculateZ(frequency).Imaginary, 0.001); }
/// <summary> /// Вводит данные о новом индуктивном элементе /// </summary> /// <returns></returns> private Inductor GetNewInductor() { var newInductor = new Inductor(); var actions = new List <Action>() { new Action(() => { ReadingAndParsing.ReadAndParse( PassiveElementParameter1_textBox.Text, TranslateParameter(NamesOfPassiveElementParameters. Frecuency.ToString()), out double frecuency); newInductor.Frecuency = frecuency; }), new Action(() => { ReadingAndParsing.ReadAndParse( PassiveElementParameter2_textBox.Text, TranslateParameter(NamesOfPassiveElementParameters. Inductance.ToString()), out double inductance); newInductor.Inductance = inductance; }) }; actions.ForEach(SetValue); return(newInductor); }
/// <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); }
/// <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); }
/// <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); }
public void GetImpedanceTest(double resultReal, double resulrImaginary, double angularFrequency, double value) { var inductor = new Inductor(value); var impedance = inductor.GetImpedance(angularFrequency); Assert.AreEqual(resultReal, impedance.Real); Assert.AreEqual(resulrImaginary, impedance.Imaginary); }
public void inductorImpedanceTest(double _value, double _freq) { IElement impInductor = new Inductor(); impInductor.Value = _value; Complex impComplex = new Complex(0.0, -20 * Math.PI); Assert.AreEqual(impInductor.GetImpedance(_freq), impComplex); }
public InductorElm(Point p1, Point p2, int f, StringTokenizer st) : base(p1, p2, f) { mInd = new Inductor(mCir); try { Inductance = st.nextTokenDouble(); mCurrent = st.nextTokenDouble(); ReferenceName = st.nextToken(); } catch { } mInd.Setup(Inductance, mCurrent, mFlags); }
public void EventHandlerTest() { Inductor inductor = new Inductor("I", 40); bool test = false; inductor.ValueChanged += (sender, argument) => { test = true; }; inductor.Value = 50; Assert.AreEqual(true, test); }
/// <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); }
public List <Inductor> GetDatasFromAccess_Inductor(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 <Inductor> lstCapacitor = new List <Inductor>(); for (int i = 0; i < count; i++) { Inductor obj = new Inductor(); //从第2行开始为第一个数据 obj.PartNumber = GetValue(worksheet.Cells[string.Format("A{0}", i + 2)].Value); obj.PartType = GetValue(worksheet.Cells[string.Format("B{0}", i + 2)].Value); obj.Value = GetValue(worksheet.Cells[string.Format("C{0}", i + 2)].Value); obj.Description = GetValue(worksheet.Cells[string.Format("D{0}", i + 2)].Value); obj.Rating = GetValue(worksheet.Cells[string.Format("E{0}", i + 2)].Value); obj.Tolerance = GetValue(worksheet.Cells[string.Format("F{0}", i + 2)].Value); obj.SchematicPart = GetValue(worksheet.Cells[string.Format("G{0}", i + 2)].Value); obj.LayoutPCBFootprint = GetValue(worksheet.Cells[string.Format("H{0}", i + 2)].Value); obj.AllegroPCBFootprint = GetValue(worksheet.Cells[string.Format("I{0}", i + 2)].Value); obj.PSpice = GetValue(worksheet.Cells[string.Format("J{0}", i + 2)].Value); obj.ManufacturerPartNumber = GetValue(worksheet.Cells[string.Format("K{0}", i + 2)].Value); obj.Manufacturer = GetValue(worksheet.Cells[string.Format("L{0}", i + 2)].Value); obj.DistributorPartNumber = GetValue(worksheet.Cells[string.Format("M{0}", i + 2)].Value); obj.Distributor = GetValue(worksheet.Cells[string.Format("N{0}", i + 2)].Value); 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 = GetValue(worksheet.Cells[string.Format("P{0}", i + 2)].Value); 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; } }
/// <summary> /// Generates a new inductor. /// </summary> /// <param name="name">Name of inductor to generate.</param> /// <param name="parameters">Parameters and pins for inductor.</param> /// <param name="context">Reading context.</param> /// <returns> /// A new instance of inductor. /// </returns> protected SpiceSharp.Components.Component GenerateInd(string name, ParameterCollection parameters, ICircuitContext context) { if (parameters.Count != 3) { context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader, ValidationEntryLevel.Warning, $"Inductor expects 3 parameters/pins", parameters.LineInfo)); return(null); } var inductor = new Inductor(name); context.CreateNodes(inductor, parameters); context.SetParameter(inductor, "inductance", parameters.Get(2)); return(inductor); }
/// <summary> /// Generate an inductor /// </summary> /// <param name="name">Name</param> /// <param name="parameters">Parameters</param> /// <param name="netlist">Netlist</param> /// <returns></returns> protected ICircuitObject GenerateInd(CircuitIdentifier name, List <Token> parameters, Netlist netlist) { Inductor ind = new Inductor(name); ind.ReadNodes(netlist.Path, parameters); // Read the value if (parameters.Count < 3) { throw new ParseException(parameters[1], "Inductance expected", false); } ind.INDinduct.Set(netlist.ParseDouble(parameters[2])); // Read initial conditions netlist.ReadParameters(ind, parameters, 3); return(ind); }
// void constraintsSaveFunction() { // if(transform.parent.name.Contains("capacitor")) { // constraintsSelectedValue = selectCapacitorValuePanel.getConstraintsSelected(transform.parent.name); // } else if(transform.parent.name.Contains("resistor")) { // constraintsSelectedValue = setResistorValuePanel.getConstraintsSelected(transform.parent.name); // } // } public void setInductorValueWindow() { Inductor inductor = (Inductor)getComponentDataObject(); //Debug.Log("deleteOptionWindow " + transform.parent.name); selectInductorValuePanel.Choice(inductorSaveAction, inductorCancelAction, resetAllStateAction); selectInductorValuePanel.setTitle("SelectValuePanelTitle", transform.parent.name); selectInductorValuePanel.setPosition(new Vector3(0, 210, 250)); selectInductorValuePanel.setComponent("inductor"); selectInductorValuePanel.setOptionValues(inductor.optionValues); //Debug.Log("cc = " + (int)componentValue); selectInductorValuePanel.setSelectedToggle(inductorToggleValue); selectInductorValuePanel.setSelectedIndexValue(inductorToggleValue); selectInductorValuePanel.setDropdownActive(false); // if(selectCapacitorValuePanel.getSumOfSelectedValue() == 0) // selectCapacitorValuePanel.resetToggles(); //Debug.Log("x = " + transform.position.x + " y = " + transform.position.y + " z = " + transform.position.z); }
/// <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); } }
/// <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); }
public void PositiveValue(double value) { var indValue = new Inductor(); indValue.Value = value; }
public void InductorCreate(InductorVM inductorVM) { Inductor inductor = new Inductor(); }
public PartialViewResult Inductor() { CDTEntities db = new CDTEntities(); Inductor inductor = new Inductor(); return PartialView("_InductorPartial", inductor); }
/// <summary> /// Инициализировать цепь. /// </summary> /// <param name="circuit">Цепь.</param> /// <param name="initialTemplateCircuitType">Тип шаблона.</param> public static void Initialize(Circuit circuit, InitialTemplateCircuitType initialTemplateCircuitType) { if (circuit == null) { circuit = new Circuit(); } circuit.Clear(); switch (initialTemplateCircuitType) { case InitialTemplateCircuitType.A: { Inductor inductor1 = new Inductor("L1", 20); Resistor resistor2 = new Resistor("R2", 20); Resistor resistor3 = new Resistor("R3", 20); Inductor inductor4 = new Inductor("L4", 20); SeriesSubcircuit seriesSubcircuit1 = new SeriesSubcircuit(); seriesSubcircuit1.Nodes.Add(inductor1); inductor1.Parent = seriesSubcircuit1; seriesSubcircuit1.Nodes.Add(resistor2); resistor2.Parent = seriesSubcircuit1; ParallelSubcircuit parallelSubcircuit1 = new ParallelSubcircuit(); seriesSubcircuit1.Nodes.Add(parallelSubcircuit1); parallelSubcircuit1.Parent = seriesSubcircuit1; parallelSubcircuit1.Nodes.Add(resistor3); resistor3.Parent = parallelSubcircuit1; parallelSubcircuit1.Nodes.Add(inductor4); inductor4.Parent = parallelSubcircuit1; circuit.AddAfter(null, seriesSubcircuit1); break; } case InitialTemplateCircuitType.B: { Capacitor capacitor1 = new Capacitor("C1", 20); Inductor inductor2 = new Inductor("L2", 20); Resistor resistor3 = new Resistor("R3", 20); Inductor inductor4 = new Inductor("L4", 20); ParallelSubcircuit parallelSubcircuit1 = new ParallelSubcircuit(); parallelSubcircuit1.Nodes.Add(capacitor1); capacitor1.Parent = parallelSubcircuit1; SeriesSubcircuit seriesSubcircuit1 = new SeriesSubcircuit(); parallelSubcircuit1.Nodes.Add(seriesSubcircuit1); seriesSubcircuit1.Parent = parallelSubcircuit1; seriesSubcircuit1.Nodes.Add(inductor2); inductor2.Parent = seriesSubcircuit1; ParallelSubcircuit parallelSubcircuit2 = new ParallelSubcircuit(); parallelSubcircuit2.Nodes.Add(resistor3); resistor3.Parent = parallelSubcircuit2; parallelSubcircuit2.Nodes.Add(inductor4); inductor4.Parent = parallelSubcircuit2; seriesSubcircuit1.Nodes.Add(parallelSubcircuit2); parallelSubcircuit2.Parent = seriesSubcircuit1; circuit.AddAfter(null, parallelSubcircuit1); break; } case InitialTemplateCircuitType.C: { Resistor resistor1 = new Resistor("R1", 20); Inductor inductor2 = new Inductor("L2", 20); Inductor inductor3 = new Inductor("L3", 20); Inductor inductor4 = new Inductor("L4", 20); Resistor resistor5 = new Resistor("R5", 20); Resistor resistor6 = new Resistor("R6", 20); Inductor inductor7 = new Inductor("L7", 20); ParallelSubcircuit parallelSubcircuit1 = new ParallelSubcircuit(); SeriesSubcircuit seriesSubcircuit1 = new SeriesSubcircuit(); SeriesSubcircuit seriesSubcircuit2 = new SeriesSubcircuit(); parallelSubcircuit1.Nodes.Add(seriesSubcircuit1); seriesSubcircuit1.Parent = parallelSubcircuit1; parallelSubcircuit1.Nodes.Add(seriesSubcircuit2); seriesSubcircuit2.Parent = parallelSubcircuit1; ParallelSubcircuit parallelSubcircuit2 = new ParallelSubcircuit(); ParallelSubcircuit parallelSubcircuit3 = new ParallelSubcircuit(); seriesSubcircuit1.Nodes.Add(inductor3); inductor3.Parent = seriesSubcircuit1; seriesSubcircuit1.Nodes.Add(parallelSubcircuit2); parallelSubcircuit2.Parent = seriesSubcircuit1; parallelSubcircuit2.Nodes.Add(resistor1); resistor1.Parent = parallelSubcircuit2; parallelSubcircuit2.Nodes.Add(inductor4); inductor4.Parent = parallelSubcircuit2; seriesSubcircuit2.Nodes.Add(inductor2); inductor2.Parent = seriesSubcircuit2; seriesSubcircuit2.Nodes.Add(resistor5); resistor5.Parent = seriesSubcircuit2; seriesSubcircuit2.Nodes.Add(parallelSubcircuit3); parallelSubcircuit3.Parent = seriesSubcircuit2; parallelSubcircuit3.Nodes.Add(resistor6); resistor6.Parent = parallelSubcircuit3; parallelSubcircuit3.Nodes.Add(inductor7); inductor7.Parent = parallelSubcircuit3; circuit.AddAfter(null, parallelSubcircuit1); break; } case InitialTemplateCircuitType.D: { Resistor resistor1 = new Resistor("R1", 1); Capacitor capacitor2 = new Capacitor("C2", 20); Resistor resistor3 = new Resistor("R3", 20); Inductor inductor4 = new Inductor("L4", 20); Resistor resistor5 = new Resistor("R5", 20); Inductor inductor6 = new Inductor("L6", 20); SeriesSubcircuit seriesSubcircuit1 = new SeriesSubcircuit(); ParallelSubcircuit parallelSubcircuit1 = new ParallelSubcircuit(); ParallelSubcircuit parallelSubcircuit2 = new ParallelSubcircuit(); seriesSubcircuit1.Nodes.Add(parallelSubcircuit1); parallelSubcircuit1.Parent = seriesSubcircuit1; seriesSubcircuit1.Nodes.Add(parallelSubcircuit2); parallelSubcircuit2.Parent = seriesSubcircuit1; seriesSubcircuit1.Nodes.Add(resistor3); resistor3.Parent = seriesSubcircuit1; parallelSubcircuit1.Nodes.Add(resistor1); resistor1.Parent = parallelSubcircuit1; parallelSubcircuit1.Nodes.Add(inductor4); inductor4.Parent = parallelSubcircuit1; parallelSubcircuit2.Nodes.Add(capacitor2); capacitor2.Parent = parallelSubcircuit2; parallelSubcircuit2.Nodes.Add(resistor5); resistor5.Parent = parallelSubcircuit2; parallelSubcircuit2.Nodes.Add(inductor6); inductor6.Parent = parallelSubcircuit2; circuit.AddAfter(null, seriesSubcircuit1); break; } case InitialTemplateCircuitType.E: { Resistor resistor1 = new Resistor("R1", 20); Capacitor capacitor2 = new Capacitor("C2", 20); Resistor resistor3 = new Resistor("R3", 20); Inductor inductor4 = new Inductor("L4", 20); Resistor resistor5 = new Resistor("R5", 20); Inductor inductor6 = new Inductor("L6", 20); Resistor resistor7 = new Resistor("R7", 20); Inductor inductor8 = new Inductor("L8", 20); SeriesSubcircuit seriesSubcircuit1 = new SeriesSubcircuit(); SeriesSubcircuit seriesSubcircuit2 = new SeriesSubcircuit(); ParallelSubcircuit parallelSubcircuit1 = new ParallelSubcircuit(); ParallelSubcircuit parallelSubcircuit2 = new ParallelSubcircuit(); ParallelSubcircuit parallelSubcircuit3 = new ParallelSubcircuit(); seriesSubcircuit1.Nodes.Add(parallelSubcircuit1); parallelSubcircuit1.Parent = seriesSubcircuit1; parallelSubcircuit1.Nodes.Add(resistor1); resistor1.Parent = parallelSubcircuit1; parallelSubcircuit1.Nodes.Add(inductor4); inductor4.Parent = parallelSubcircuit1; seriesSubcircuit1.Nodes.Add(parallelSubcircuit2); parallelSubcircuit2.Parent = seriesSubcircuit1; parallelSubcircuit2.Nodes.Add(capacitor2); capacitor2.Parent = parallelSubcircuit2; parallelSubcircuit2.Nodes.Add(seriesSubcircuit2); seriesSubcircuit2.Parent = parallelSubcircuit2; seriesSubcircuit2.Nodes.Add(parallelSubcircuit3); parallelSubcircuit3.Parent = seriesSubcircuit2; seriesSubcircuit2.Nodes.Add(resistor7); resistor7.Parent = seriesSubcircuit2; parallelSubcircuit3.Nodes.Add(resistor5); resistor5.Parent = parallelSubcircuit3; parallelSubcircuit3.Nodes.Add(inductor8); inductor8.Parent = parallelSubcircuit3; parallelSubcircuit2.Nodes.Add(inductor6); inductor6.Parent = parallelSubcircuit2; seriesSubcircuit1.Nodes.Add(resistor3); resistor3.Parent = seriesSubcircuit1; circuit.AddAfter(null, seriesSubcircuit1); break; } } }
public void NegativeValue(double value, Type expectedException) { var capValue = new Inductor(); Assert.Throws(expectedException, () => capValue.Value = value); }
public void NanValue(double value, Type expectedException) { var indValue = new Inductor(); Assert.Throws(expectedException, () => indValue.Value = value); }