Skip to content

Commit

Permalink
Addition of the Internal Resistance Parameter
Browse files Browse the repository at this point in the history
Added the option of adding an internal resistance to both voltage sources,
ac and dc, which would equal a resistor in series with them.
The same applies to Iprobe. The default values for these components are 0 Ohms.
In the voltmeter, another series resistance is applied, but the default value is 1e12, I can change this if another value is prefered. The Wattmeter also has internal resistance, both for the voltage and the current part, the same principals were applied, as they were to their Probes.
Regarding the current sources, the internal resistor will result in a paralel with the component, and the default value was set to 1e12ohms as well.
I will add some working examples in a pdf.
Thanks to andresmmera for all his help and patience on this topic.
Edit:Fixed the default values of some components
Edit2:Added message, an Ri of 0 disables the parameter
  • Loading branch information
gildias committed May 12, 2017
1 parent 3ab825e commit 28edf66
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 11 deletions.
11 changes: 11 additions & 0 deletions qucs-core/src/components/iac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ void iac::initAC (void) {
nr_complex_t i = qucs::polar (a, deg2rad (p));
allocMatrixMNA ();
setI (NODE_1, +i); setI (NODE_2, -i);
nr_double_t r = getScaledProperty ("Ri");
// Setting the internal resistance
if (r != 0.0) {
nr_double_t g = 1.0 / r;
setVoltageSources (0);
setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
}

// The internal resistance can't be zero
}

void iac::calcTR (nr_double_t t) {
Expand All @@ -76,6 +86,7 @@ PROP_OPT [] = {
{ "Phase", PROP_REAL, { 0, PROP_NO_STR }, PROP_RNGII (-360, 360) },
{ "Theta", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
{ "f", PROP_REAL, { 1e9, PROP_NO_STR }, PROP_POS_RANGE },
{ "Ri", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
PROP_NO_PROP };
struct define_t iac::cirdef =
{ "Iac", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
12 changes: 11 additions & 1 deletion qucs-core/src/components/idc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ void idc::initDC (void) {
nr_double_t i = getPropertyDouble ("I");
allocMatrixMNA ();
setI (NODE_1, +i); setI (NODE_2, -i);
nr_double_t r = getScaledProperty ("Ri");
// Setting the internal resistance
if (r != 0.0) {
nr_double_t g = 1.0 / r;
setVoltageSources (0);
setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
}
// The internal resistance can't be zero
}

void idc::calcDC (void) {
Expand All @@ -68,7 +77,8 @@ void idc::initTR (void) {
// properties
PROP_REQ [] = {
{ "I", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
PROP_OPT [] = {
PROP_OPT [] = {
{ "Ri", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
PROP_NO_PROP };
struct define_t idc::cirdef =
{ "Idc", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
4 changes: 3 additions & 1 deletion qucs-core/src/components/iprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ void iprobe::initTR (void) {

// properties
PROP_REQ [] = { PROP_NO_PROP };
PROP_OPT [] = { PROP_NO_PROP };
PROP_OPT [] = {
{ "Ri", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
PROP_NO_PROP };
struct define_t iprobe::cirdef =
{ "IProbe", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
1 change: 1 addition & 0 deletions qucs-core/src/components/vac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ PROP_OPT [] = {
{ "Phase", PROP_REAL, { 0, PROP_NO_STR }, PROP_RNGII (-360, 360) },
{ "Theta", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
{ "f", PROP_REAL, { 1e9, PROP_NO_STR }, PROP_POS_RANGE },
{ "Ri", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
PROP_NO_PROP };
struct define_t vac::cirdef =
{ "Vac", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
1 change: 1 addition & 0 deletions qucs-core/src/components/vdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void vdc::calcHB (nr_double_t frequency) {
PROP_REQ [] = {
{ "U", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
PROP_OPT [] = {
{ "Ri", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
PROP_NO_PROP };
struct define_t vdc::cirdef =
{ "Vdc", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
13 changes: 12 additions & 1 deletion qucs-core/src/components/vprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ void vprobe::initSP (void) {

void vprobe::initDC (void) {
allocMatrixMNA ();
nr_double_t r = getScaledProperty ("Ri");
// Setting the internal resistance
if (r != 0.0) {
nr_double_t g = 1.0 / r;
setVoltageSources (0);
setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
}
// The internal resistance can't be zero
}

void vprobe::saveOperatingPoints (void) {
Expand All @@ -65,6 +74,8 @@ void vprobe::initTR (void) {

// properties
PROP_REQ [] = { PROP_NO_PROP };
PROP_OPT [] = { PROP_NO_PROP };
PROP_OPT [] = {
{ "Ri", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
PROP_NO_PROP };
struct define_t vprobe::cirdef =
{ "VProbe", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
12 changes: 11 additions & 1 deletion qucs-core/src/components/wprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ wprobe::wprobe () : circuit (4) {
void wprobe::initDC (void) {
allocMatrixMNA ();
voltageSource (VSRC_1, NODE_1, NODE_2);
nr_double_t r = getScaledProperty ("Riv");
// Setting the internal resistance
if (r != 0.0) {
nr_double_t g = 1.0 / r;
setY (NODE_3, NODE_3, +g); setY (NODE_4, NODE_4, +g);
setY (NODE_3, NODE_4, -g); setY (NODE_4, NODE_3, -g);
}
}

void wprobe::initAC (void) {
Expand Down Expand Up @@ -85,6 +92,9 @@ void wprobe::initTR (void) {

//properties
PROP_REQ [] = { PROP_NO_PROP };
PROP_OPT [] = { PROP_NO_PROP };
PROP_OPT [] = {
{ "Riv", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
{ "Rii", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
PROP_NO_PROP };
struct define_t wprobe::cirdef =
{ "WProbe", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
2 changes: 2 additions & 0 deletions qucs/qucs/components/ampere_ac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Ampere_ac::Ampere_ac()
QObject::tr("initial phase in degrees")));
Props.append(new Property("Theta", "0", false,
QObject::tr("damping factor (transient simulation only)")));
Props.append(new Property("Ri", "0 Ohm", false,
QObject::tr("Internal resistance, (0 : disable), ideal behavior")));

rotate(); // fix historical flaw
}
Expand Down
2 changes: 2 additions & 0 deletions qucs/qucs/components/ampere_dc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Ampere_dc::Ampere_dc()

Props.append(new Property("I", "1 mA", true,
QObject::tr("current in Ampere")));
Props.append(new Property("Ri", "0 Ohm", false,
QObject::tr("Internal resistance, (0 : disable), ideal behavior")));

rotate(); // fix historical flaw
}
Expand Down
68 changes: 61 additions & 7 deletions qucs/qucs/components/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,17 +615,71 @@ void Component::mirrorY()
QString Component::netlist()
{
QString s = Model+":"+Name;

int i=-1;
// output all node names
foreach(Port *p1, Ports)
s += " "+p1->Connection->Name; // node names
// This only works in cases where the resistor would be a series
// with the component, as for the other components, they're accounted
// as a resistor as well, and the changes were made to their .cpp
foreach(Port *p1, Ports){
i++;

if ((Model == "Vdc" || Model == "Vac") && i==0) { // node 0 is +
s += " " + p1->Connection->Name + "_TEMP_" + Name; // node names
}
else if ((Model == "IProbe") && i==1) { // node 1 is +
s += " " + p1->Connection->Name + "_TEMP_" + Name; // node names
}
else if (Model == "WProbe" && (i==1)) { // node 1 is +
s += " " + p1->Connection->Name + "_TEMP_" + Name + "1"; // node names
}
else {
s += " " + p1->Connection->Name; // node names
}
}

// output all properties
for(Property *p2 = Props.first(); p2 != 0; p2 = Props.next())
if(p2->Name != "Symbol")
s += " "+p2->Name+"=\""+p2->Value+"\"";
for (Property *p2 = Props.first(); p2 != 0; p2 = Props.next())
if (p2->Name != "Symbol")
s += " " + p2->Name + "=\"" + p2->Value + "\"";

s += '\n';

if (Model == "Vdc" || Model == "Vac") {
// output all node names
Port *p1 = Ports.at(0);
s += "R:_R_" + p1->Connection->Name + "_TEMP_" + Name;
s += " " + p1->Connection->Name + "_TEMP_" + Name; // node names
s += " " + p1->Connection->Name; // node names
// output all properties
for (Property *p2 = Props.first(); p2 != 0; p2 = Props.next())
if (p2->Name == "Ri") s += " R=\"" + p2->Value + "\"";
s += " Temp = \"26.85\" Tc1 = \"0.0\" Tc2 = \"0.0\" Tnom = \"26.85\"";
}
else if (Model == "IProbe") {
Port *p1 = Ports.at(1);
s += "R:_R_" + p1->Connection->Name + "_TEMP_" + Name;
s += " " + p1->Connection->Name + "_TEMP_" + Name; // node names
s += " " + p1->Connection->Name; // node names
// output all properties
for (Property *p2 = Props.first(); p2 != 0; p2 = Props.next())
if (p2->Name == "Ri") s += " R=\"" + p2->Value + "\"";
s += " Temp = \"26.85\" Tc1 = \"0.0\" Tc2 = \"0.0\" Tnom = \"26.85\"";
}

else if (Model == "WProbe") {
Port *p1 = Ports.at(1);
s += "R:_R_" + p1->Connection->Name + "_TEMP_" + Name + "1";
s += " " + p1->Connection->Name + "_TEMP_" + Name + "1"; // node names
s += " " + p1->Connection->Name; // node names
// output all properties
for (Property *p2 = Props.first(); p2 != 0; p2 = Props.next())
if (p2->Name == "Rii") s += " R=\"" + p2->Value + "\"";
s += " Temp = \"26.85\" Tc1 = \"0.0\" Tc2 = \"0.0\" Tnom = \"26.85\"";
}

s += '\n';

return s + '\n';
return s;
}

// -------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions qucs/qucs/components/iprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ iProbe::iProbe()
{
Description = QObject::tr("current probe");

Props.append(new Property("Ri", "0 Ohm", false,
QObject::tr("Internal resistance, (0 : disable), ideal behavior")));

Lines.append(new Line(-30, 0,-20, 0,QPen(Qt::darkBlue,2)));
Lines.append(new Line( 30, 0, 20, 0,QPen(Qt::darkBlue,2)));
Lines.append(new Line(-20, 0, 20, 0,QPen(Qt::darkBlue,3)));
Expand Down
3 changes: 3 additions & 0 deletions qucs/qucs/components/volt_ac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Volt_ac::Volt_ac()
QObject::tr("initial phase in degrees")));
Props.append(new Property("Theta", "0", false,
QObject::tr("damping factor (transient simulation only)")));
Props.append(new Property("Ri", "0 Ohm", false,
QObject::tr("Internal resistance, (0 : disable), ideal behavior")));


rotate(); // fix historical flaw
}
Expand Down
2 changes: 2 additions & 0 deletions qucs/qucs/components/volt_dc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Volt_dc::Volt_dc()

Props.append(new Property("U", "1 V", true,
QObject::tr("voltage in Volts")));
Props.append(new Property("Ri", "0 Ohm", false,
QObject::tr("Internal resistance, (0 : disable), ideal behavior")));

rotate(); // fix historical flaw
}
Expand Down
2 changes: 2 additions & 0 deletions qucs/qucs/components/vprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
vProbe::vProbe()
{
Description = QObject::tr("voltage probe");
Props.append(new Property("Ri", "0 Ohm", false,
QObject::tr("Internal resistance, (0 : disable), ideal behavior")));

Lines.append(new Line(-20,-31, 20,-31,QPen(Qt::darkBlue,2)));
Lines.append(new Line(-20, 9, 20, 9,QPen(Qt::darkBlue,2)));
Expand Down
5 changes: 5 additions & 0 deletions qucs/qucs/components/wprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ wProbe::wProbe()
{
Description = QObject::tr("power probe");

Props.append(new Property("Riv", "0 Ohm", false,
QObject::tr("Internal resistance, (0 : disable), ideal behavior")));
Props.append(new Property("Rii", "0 Ohm", false,
QObject::tr("Internal resistance, (0 : disable), ideal behavior")));

//Large box
Lines.append(new Line(-20,-33, 20,-33,QPen(Qt::darkBlue,2)));
Lines.append(new Line(-20, 14, 20, 14,QPen(Qt::darkBlue,2)));
Expand Down

0 comments on commit 28edf66

Please sign in to comment.