static public void TestCircuitModel() { Stream StdoutStream = Console.OpenStandardOutput(); StreamWriter Stdout = new StreamWriter(StdoutStream); Stdout.WriteLine("\tTest circuit model"); CircuitModelAC model = new CircuitModelAC(); int v = model.AddVoltageSource("a1", "a2", 10.0f, 0.0f, 50.0f); model.AddTransformer("a1", "a2", "a3", "a4", 2.0f); int r = model.AddResistor("a3", "a4", 2.0f); model.AddGround("a1"); model.AddGround("a3"); model.AddVoltageOutput("a1", "a2"); model.AddVoltageOutput("a3", "a4"); model.AddCurrentOutput(v); model.AddCurrentOutput(r); /*model.addVoltageSource("a2", "a1", 10.0f, 60.0f, 50.0f); * model.addVoltageSource("a1", "a3", 10.0f, 0.0f, 50.0f); * model.addCapacitor("a1", "a3", 0.1f); * model.addResistor("a1", "a4", 15.0f); * model.addResistor("a4", "a2", 4.0f); * model.addInductor("a4", "a3", 5.0f); * model.addGround("a2"); * model.addVoltageOutput("a2","a3"); * model.addVoltageOutput("a2", "a4"); * model.addVoltageOutput("a2", "a1");*/ Stdout.WriteLine(model.TestEquationGeneration()); try { List <string> solution = model.Solve(); foreach (var s in solution) { Stdout.WriteLine(s); } } catch (CompilerException exc) { Stdout.WriteLine(exc.Message); var errors = exc.Errors; foreach (var error in errors) { Stdout.WriteLine(error.Message + " Line: " + error.Line + " Position: " + error.Position); } } catch (Exception exc) { Stdout.WriteLine(exc.Message); } Stdout.WriteLine(""); Stdout.Flush(); Stdout.Close(); }
static public void TestCircuitEquationGeneration() { Stream StdoutStream = Console.OpenStandardOutput(); StreamWriter Stdout = new StreamWriter(StdoutStream); Stdout.WriteLine("\t Test circuit equation generation"); try { CircuitModelAC model = new CircuitModelAC(); model.AddVoltageSource("a2", "a1", 10.0f, 50.0f, 10.0f); model.AddVoltageSource("a1", "a3", 10.0f, 50.0f, 0.5f); model.AddResistor("a1", "a3", 5.0f); model.AddResistor("a1", "a4", 15.0f); model.AddResistor("a4", "a2", 4.0f); model.AddGround("a2"); Stdout.WriteLine("Equations: "); string equations = model.TestEquationGeneration(); Stdout.WriteLine(equations); } catch (CompilerException exc) { Stdout.WriteLine(exc.Message); var errors = exc.Errors; foreach (var error in errors) { Stdout.WriteLine(error.Message + " Line: " + error.Line + " Position: " + error.Position); } } catch (Exception exc) { Stdout.WriteLine(exc.Message); } Stdout.WriteLine(""); Stdout.Flush(); Stdout.Close(); //Environment.NewLine }
static public void TestCircuitModel2() { Stream StdoutStream = Console.OpenStandardOutput(); StreamWriter Stdout = new StreamWriter(StdoutStream); Stdout.WriteLine("\tTest circuit model 2"); CircuitModelAC model = new CircuitModelAC(); int v1 = model.AddVoltageSource("g", "0", 20412.41f, 0.0f, 60.0f); int r1 = model.AddResistor("0", "1", 600.0f); int r2 = model.AddInductor("1", "2", 20.0f); int r3 = model.AddResistor("2", "3", 300.0f); int rg = model.AddInductor("3", "g", 6.0f); model.AddGround("g"); model.AddVoltageOutput("g", "2"); model.AddCurrentOutput(v1); model.AddCurrentOutput(r1); model.AddCurrentOutput(r2); model.AddCurrentOutput(r3); model.AddCurrentOutput(rg); //Stdout.WriteLine(model.TestEquationGeneration(true)); try { List <string> solution = model.Solve(); foreach (var s in solution) { Stdout.WriteLine(s); } } catch (CompilerException exc) { Stdout.WriteLine(exc.Message); var errors = exc.Errors; foreach (var error in errors) { Stdout.WriteLine(error.Message + " Line: " + error.Line + " Position: " + error.Position); } } catch (Exception exc) { Stdout.WriteLine(exc.Message); } Stdout.WriteLine(""); Stdout.Flush(); Stdout.Close(); }