diff --git a/model/PandE2019_RLC_example.mdl b/model/PandE2019_RLC_example.mdl index 4807aec..0153ca1 100644 --- a/model/PandE2019_RLC_example.mdl +++ b/model/PandE2019_RLC_example.mdl @@ -12,21 +12,16 @@ // //------------------------------------------------------------------------------------------------- -// create and ACsource -class ACSource extends Element{ - ElectricOutputPort EP_O; - ElectricInputPort EP_I1, EP_I2; -} - real defaultFrequency = 60.; -ACSource ACS{ - void postexecute(){ - EP_O.frequency = 60.; - EP_O.setIVRMS( 0,0, 120, 0 ); - EP_I1.setIVRMS( 0, 0, 0, 0 ); - EP_I2.setIVRMS( 0, 0, 0, 0 ); - } +Source ACS { + EP_O.setOption("ElectricPowerType", "AC1"); + Vrms = 120; // [volts] + Vphase = 0; + Ireal = 0.150796; + Iimag = 0.263894; + frequency = defaultFrequency; + effDes = 1; // [100 %] } Capacitor C1{ @@ -45,24 +40,33 @@ Element Resistor R1{ R = 500; } +Element Enode n1{ + ElectricInputPort EP_I; + ElectricOutputPort EP_O1, EP_O2; + //initial guess + Vreal = 120-70; + Vimag = 40; +} + +Element Enode n2{ + ElectricInputPort EP_I1, EP_I2; + real Iout_r = 1; + real Iout_j = 1; + dep_Ireal.eq_rhs = "Iout_r"; + dep_Iimag.eq_rhs = "Iout_j"; +} + //-------------------------------------------------------- // link it up //-------------------------------------------------------- -linkEports( "ACS.EP_O", "C1.EP_I", "PORT" ); -linkEports("C1.EP_O", "n1" ,"NODE"); -linkEports( "L1.EP_I", "n1", "NODE" ); -linkEports( "L1.EP_O", "n2", "NODE" ); -linkEports( "C2.EP_I", "n2", "NODE" ); -linkEports( "C2.EP_O", "ACS.EP_I1", "PORT" ); -linkEports( "R1.EP_I", "n1", "NODE" ); -linkEports( "R1.EP_O", "ACS.EP_I2", "PORT" ); +linkPortI( "ACS.EP_O", "C1.EP_I"); +linkPortI("C1.EP_O", "n1.EP_I"); +linkPortI( "n1.EP_O1", "L1.EP_I"); +linkPortI( "L1.EP_O", "C2.EP_I"); +linkPortI( "C2.EP_O", "n2.EP_I1"); +linkPortI( "n1.EP_O2","R1.EP_I"); +linkPortI( "R1.EP_O", "n2.EP_I2"); -n1{ - VrealRMS = 120-70; //guess value - VimagRMS = 40; //guess value -} +Independent ind_Iout_r { varName = "n2.Iout_r";} +Independent ind_Iout_j { varName = "n2.Iout_j";} -n2{ - VrealRMS = 120-70+8; //guess value - VimagRMS = 40+6.98; //guess value -} diff --git a/model/R_dc_example.mdl b/model/R_dc_example.mdl index 7727fcf..2c70aff 100644 --- a/model/R_dc_example.mdl +++ b/model/R_dc_example.mdl @@ -15,17 +15,7 @@ ------------------------------------------------------------------------------- ***/ -// class DCSource extends Element{ -// ElectricOutputPort EP_O; -// } - -// real defaultFrequency = 0.; - -// DCSource DCS{ -// void calculate(){ -// EP_O.setIVRMS( 0, 0., 10., 0.); -// } -// } +real defaultFrequency = 0.; Source DCS { EP_O.setOption("ElectricPowerType", "DC"); @@ -34,7 +24,6 @@ Source DCS { effDes = 1; // [100 %] } - Element Resistor R1{ R = 1.; } @@ -47,20 +36,19 @@ Element Resistor R3{ R = 2.; } - //-------------------------------------------------------- // link it up //-------------------------------------------------------- Element Enode n1{ ElectricInputPort EP_I; - ElectricOutputPort EP_O1, EP_O2; - // VrealRMS = 10; //guess value - // VimagRMS = 0.; //guess value + ElectricOutputPort EP_O1, EP_O2; } Element Enode n2 { ElectricInputPort EP_I1, EP_I2; + real Iout = 1; + dep_Ireal.eq_rhs = "Iout"; } linkPortI("DCS.EP_O", "R1.EP_I"); @@ -70,24 +58,7 @@ linkPortI("R2.EP_O", "n2.EP_I1"); linkPortI("n1.EP_O2","R3.EP_I"); linkPortI("R3.EP_O", "n2.EP_I2"); - -// linkEports( "DCS.EP_O", "R1.EP_I", "PORT" ); -// linkEports("R1.EP_O", "n1" ,"NODE"); -// linkEports("R2.EP_I", "n1" ,"NODE"); -// linkEports("R2.EP_O", "DCS.EP_I1" ,"PORT"); -// linkEports("R3.EP_I", "n1" ,"NODE"); -// linkEports("R3.EP_O", "DCS.EP_I2" ,"PORT"); - -// n1{ -// VrealRMS = 10; //guess value -// VimagRMS = 0.; //guess value -// } - -// linkEports( "DCS.EP_O", "R1.EP_I","PORT"); -// linkEports("R1.EP_O", "n1.EP_I1","NODE"); -// linkEports("n1.EP_O1", "R2.EP_I","NODE"); -// linkEports("R2.EP_O", "DCS.EP_I1","PORT"); -// linkEports("n1.EP_O2", "R3.EP_I","NODE"); -// linkEports("R3.EP_O", "DCS.EP_I2","PORT"); +Independent ind_Iout { varName = "n2.Iout";} +Dependent dep_Vgrnd { eq_rhs="DCS.Ireal"; eq_lhs="n2.Iout"; } setOption( "ElectricPowerType", "DC" ); diff --git a/run/run_RLC_example.run b/run/run_RLC_example.run index 1ba334f..4ea6703 100644 --- a/run/run_RLC_example.run +++ b/run/run_RLC_example.run @@ -36,18 +36,30 @@ MODELNAME = "RLC Circuit"; // select model #include "PandE2019_RLC_example.mdl" +solverSequence = { + "ACS","C1","n1","L1","C2","R1","n2" +}; + +setOption( "ElectricPowerType", "AC1" ); autoSolverSetup(); -//--------------------------------------------------------- -// just like a rocket engine, volumes last -//--------------------------------------------------------- +solver.addIndependent( "ind_Iout_r" ); +solver.addIndependent( "ind_Iout_j" ); + +solver.removeIndependent( "n2.ind_Vreal" ); +solver.removeIndependent( "n2.ind_Vimag" ); +n2.Vreal = 0; +n2.Vimag = 0; + solver.debugLevel = "ITERATION_DETAILS"; solver.diagnosticFile = "output/Solver.bad"; +// solver.solutionMode = "ONE_PASS"; solver.maxIterations = 5000; solver.maxJacobians = 1000; -setOption( "ElectricPowerType", "AC1" ); - + +cout << endl << solver.dependentNames << endl << solver.independentNames << endl; + run(); page.display(); // output data to out file @@ -57,6 +69,7 @@ page_runtime.display(); // output data to cmd window // print out certain components to the command line //--------------------------------------------------------- cerr << "\n Voltages \n"; +cerr << "ACS: " << ACS.EP_O.V.rRMS << " + " << ACS.EP_O.V.jRMS << "j"<< endl; cerr << "C1: " << C1.EP_O.V.rRMS << " + " << C1.EP_O.V.jRMS << "j"<< endl; cerr << "L1: " << L1.EP_O.V.rRMS << " + " << L1.EP_O.V.jRMS << "j"<< endl; @@ -82,8 +95,4 @@ cerr << "C2(out): " << C2.EP_O.S.rRMS << " + " << C2.EP_O.S.jRMS << "j"<< endl; cerr << " R1(in): " << R1.EP_I.S.rRMS << " + " << R1.EP_I.S.jRMS << "j"<< endl; cerr << "R1(out): " << R1.EP_O.S.rRMS << " + " << R1.EP_O.S.jRMS << "j"<< endl; - - - - cerr << "\n" << endl; diff --git a/run/run_R_dc_example.run b/run/run_R_dc_example.run index 92f6776..62a8819 100644 --- a/run/run_R_dc_example.run +++ b/run/run_R_dc_example.run @@ -34,24 +34,21 @@ MODELNAME = "Resistive Circuit"; // select model #include "R_dc_example.mdl" -//string var[] = propagateEpsSolverListAndPowerTypes(); -//solverSequence = var; solverSequence = { "DCS","R1","n1","R2","R3","n2" }; +cout << solverSequence << endl; autoSolverSetup(); -cout << solverSequence << endl; + +solver.addIndependent( "ind_Iout" ); +solver.removeIndependent( "n2.ind_Vreal" ); +n2.Vreal = 0; cout << endl << solver.dependentNames << endl << solver.independentNames << endl; -//--------------------------------------------------------- -// just like a rocket engine, volumes last -//--------------------------------------------------------- -//solverSequence = { "Bat", "R1", "C1", "L1", "C2","E1","E2" } -//solverSequence = { "Bat", "R1", "C1", "L1", "C2" } + solver.debugLevel = "ITERATION_DETAILS"; solver.diagnosticFile = "output/Solver.bad"; - solver.maxIterations = 5000; solver.maxJacobians = 1000; diff --git a/src/Capacitor.int b/src/Capacitor.int index 81d660d..2ec62fb 100644 --- a/src/Capacitor.int +++ b/src/Capacitor.int @@ -65,8 +65,8 @@ no sizing logic included in this component."; real C; ComplexNumber dV; + ComplexNumber Vo; ComplexNumber Z; - ComplexNumber I; //---------------------------------------------------------- // ****** SETUP PORTS, FLOW STATIONS, SOCKETS, TABLES ****** @@ -81,19 +81,20 @@ no sizing logic included in this component."; } void calculate() { + Z.setrj(0., -1. / (2*PI*EP_I.frequency*C)); - // calculate the current - dV.copy("EP_I.V"); - dV.minus("EP_O.V"); - Z.setrj(0., -1. / (2*PI*EP_I.frequency*C)); - I.copy("dV"); - I.div("Z"); + // calculate the current + dV.copy( "EP_I.I" ); + dV.times( "Z" ); + Vo.copy( "EP_I.V" ); + Vo.minus( "dV" ); // set the conditions in the ports - EP_O.setIVRMS(I.rRMS, I.jRMS, EP_O.V.rRMS, EP_O.V.jRMS); - EP_I.setIVRMS(I.rRMS, I.jRMS, EP_I.V.rRMS, EP_I.V.jRMS); - EP_O.frequency = EP_I.frequency; + EP_O.frequency = EP_I.frequency; + EP_O.setIVRMS( EP_I.I.rRMS, EP_I.I.jRMS, Vo.rRMS, Vo.jRMS ); + // EP_I.setIVRMS(I.rRMS, I.jRMS, EP_I.V.rRMS, EP_I.V.jRMS); + } } #endif diff --git a/src/Enode.int b/src/Enode.int index fedfd41..43efc3c 100644 --- a/src/Enode.int +++ b/src/Enode.int @@ -170,6 +170,8 @@ approach taken in fluid networks within NPSS rocket models."; int i; string Iname; + updatePortQuantities(); + for (i = 0; i < ElectricInputPorts.entries(); i++) { Iname = ElectricInputPorts[i] + ".I"; Inet.plus(Iname); @@ -179,7 +181,7 @@ approach taken in fluid networks within NPSS rocket models."; Iname = ElectricOutputPorts[i] + ".I"; Inet.minus(Iname); } - updatePortQuantities(); + } //------------------------------- diff --git a/src/Inductor.int b/src/Inductor.int index b692fc3..2de6c3c 100644 --- a/src/Inductor.int +++ b/src/Inductor.int @@ -65,9 +65,9 @@ no sizing logic included in this component."; //------------------------------ real L; - ComplexNumber Z; ComplexNumber dV; - ComplexNumber I; + ComplexNumber Vo; + ComplexNumber Z; //---------------------------------------------------------- // ****** SETUP PORTS, FLOW STATIONS, SOCKETS, TABLES ****** @@ -83,18 +83,19 @@ no sizing logic included in this component."; string EPortRef; void calculate() { - - // calculate current from voltage drop - dV.copy( "EP_I.V" ); - dV.minus( "EP_O.V" ); Z.setrj( 0., 2.*PI*EP_I.frequency*L ); - I.copy( "dV" ); - I.div( "Z" ); + + // calculate current from voltage drop + dV.copy( "EP_I.I" ); + dV.times( "Z" ); + Vo.copy( "EP_I.V" ); + Vo.minus( "dV" ); // set the conditions in the ports - EP_O.setIVRMS( I.rRMS, I.jRMS, EP_O.V.rRMS, EP_O.V.jRMS ); - EP_I.setIVRMS( I.rRMS, I.jRMS, EP_I.V.rRMS, EP_I.V.jRMS ); - EP_O.frequency=EP_I.frequency; + EP_O.frequency=EP_I.frequency; + EP_O.setIVRMS( EP_I.I.rRMS, EP_I.I.jRMS, Vo.rRMS, Vo.jRMS ); + //EP_I.setIVRMS( I.rRMS, I.jRMS, EP_I.V.rRMS, EP_I.V.jRMS ); + } } #endif diff --git a/src/Resistor.int b/src/Resistor.int index 17a6314..f309863 100644 --- a/src/Resistor.int +++ b/src/Resistor.int @@ -64,6 +64,7 @@ no sizing logic included in this component."; real R; ComplexNumber dV; ComplexNumber Vo; + ComplexNumber Z; //---------------------------------------------------------- // ****** SETUP PORTS, FLOW STATIONS, SOCKETS, TABLES ****** @@ -80,17 +81,18 @@ no sizing logic included in this component."; } void calculate() { - + Z.setrj(R, 0); // calculate current from voltage drop dV.copy( "EP_I.I" ); - dV.scale( R ); + dV.times( "Z" ); Vo.copy( "EP_I.V" ); Vo.minus( "dV" ); // set the conditions in the port + EP_O.frequency=EP_I.frequency; EP_O.setIVRMS( EP_I.I.rRMS, EP_I.I.jRMS, Vo.rRMS, Vo.jRMS ); //EP_I.setIVRMS( I.rRMS, I.jRMS, EP_I.V.rRMS, EP_I.V.jRMS ); - EP_O.frequency=EP_I.frequency; + } } #endif