Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions model/PandE2019_RLC_example.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
41 changes: 6 additions & 35 deletions model/R_dc_example.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -34,7 +24,6 @@ Source DCS {
effDes = 1; // [100 %]
}


Element Resistor R1{
R = 1.;
}
Expand All @@ -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");
Expand All @@ -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" );
27 changes: 18 additions & 9 deletions run/run_RLC_example.run
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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;
15 changes: 6 additions & 9 deletions run/run_R_dc_example.run
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
21 changes: 11 additions & 10 deletions src/Capacitor.int
Original file line number Diff line number Diff line change
Expand Up @@ -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 ******
Expand All @@ -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
4 changes: 3 additions & 1 deletion src/Enode.int
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -179,7 +181,7 @@ approach taken in fluid networks within NPSS rocket models.";
Iname = ElectricOutputPorts[i] + ".I";
Inet.minus(Iname);
}
updatePortQuantities();

}

//-------------------------------
Expand Down
23 changes: 12 additions & 11 deletions src/Inductor.int
Original file line number Diff line number Diff line change
Expand Up @@ -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 ******
Expand All @@ -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
8 changes: 5 additions & 3 deletions src/Resistor.int
Original file line number Diff line number Diff line change
Expand Up @@ -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 ******
Expand All @@ -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