Skip to content

Commit 4d03a2b

Browse files
committed
Move some power probe calculations
1 parent ab09147 commit 4d03a2b

2 files changed

Lines changed: 19 additions & 23 deletions

File tree

qucs-core/src/components/wprobe.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ void wprobe::saveOperatingPoints (void) {
7171
nr_double_t Q = imag (Sw);
7272
setOperatingPoint ("P", P);
7373
setOperatingPoint ("Q", Q);
74-
//Power Factor calculation
75-
setOperatingPoint ("PF", P/std::sqrt(P*P+Q*Q));
7674
}
7775

7876
void wprobe::initTR (void) {

qucs-core/src/nasolver.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,28 +1369,26 @@ void nasolver<nr_type_t>::saveResults (const std::string &volts, const std::stri
13691369
saveVariable (n, nr_complex_t (c->getOperatingPoint ("Vr"),
13701370
c->getOperatingPoint ("Vi")), f);
13711371

1372-
//add watt probe data
1372+
// add watt probe data
13731373
// this is a big hack due to (ab)using the operating points
1374-
for (auto ops: c->getOperatingPoints ())
1375-
{
1376-
//It will only get values if none of the strings are 0
1377-
//Once again most of this is adapted from Vprobe and Iprobe
1378-
operatingpoint &p = ops.second;
1379-
if (strcmp(p.getName(), "Vi") == 0) continue;
1380-
if (strcmp(p.getName(), "VAi") == 0) continue;
1381-
if (strcmp(p.getName(), "Vr") == 0) continue;
1382-
if (strcmp(p.getName(), "VAr") == 0)
1383-
{
1384-
std::string n = createOP(c->getName(), "S");
1385-
saveVariable (n, nr_complex_t (c->getOperatingPoint ("VAr"),
1386-
c->getOperatingPoint ("VAi")), f);
1387-
continue;
1388-
}
1389-
1390-
std::string n = createOP(c->getName(), p.getName());
1391-
saveVariable(n, p.getValue(), f);
1392-
}
1393-
1374+
// for specific information regarding The Power triangle and Power factor:
1375+
// https://en.wikipedia.org/wiki/Power_factor#Definition_and_calculation
1376+
if (c->hasOperatingPoint("P") && c->hasOperatingPoint("Q")) {
1377+
nr_double_t P = c->getOperatingPoint ("P");
1378+
nr_double_t Q = c->getOperatingPoint ("Q");
1379+
// save complex power
1380+
std::string n = createOP(c->getName(), "S");
1381+
saveVariable (n, nr_complex_t (P, Q), f);
1382+
// save active power
1383+
n = createOP(c->getName(), "P");
1384+
saveVariable(n, P, f);
1385+
// save reactive power
1386+
n = createOP(c->getName(), "Q");
1387+
saveVariable(n, Q, f);
1388+
// save power factor
1389+
n = createOP(c->getName(), "PF");
1390+
saveVariable(n, P / std::sqrt(P*P + Q*Q), f);
1391+
}
13941392
}
13951393
}
13961394

0 commit comments

Comments
 (0)