Skip to content

Commit ab09147

Browse files
committed
Slightly refactor power probe
to avoid using calcOperatingPoints(), which should be reserved for non-linear circuits.
1 parent d18bd68 commit ab09147

3 files changed

Lines changed: 13 additions & 18 deletions

File tree

qucs-core/src/components/wprobe.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,19 @@ void wprobe::saveOperatingPoints (void) {
6060
nr_double_t Vi = imag (getV (NODE_1) - getV (NODE_2));
6161
// operating points as for the vprobe
6262
setOperatingPoint ("Vr", Vr);
63-
setOperatingPoint ("Vi", Vi); //This section works just like a voltmeter
64-
}
65-
66-
//For specific information regarding The Power triangle and Power factor:
67-
//https://en.wikipedia.org/wiki/Power_factor#Definition_and_calculation
63+
setOperatingPoint ("Vi", Vi);
6864

69-
void wprobe::calcOperatingPoints (void) {
70-
//Reading the current and voltage values to calculate power values
65+
// read current and voltage values to calculate power values
7166
nr_complex_t Vw = getV (NODE_1) - getV (NODE_2);
7267
nr_complex_t Iw = getJ (VSRC_1);
7368
nr_complex_t Sw = Vw * conj (Iw);
74-
nr_double_t VAr = real (Sw);
75-
nr_double_t VAi = imag (Sw);
76-
setOperatingPoint ("VAr", VAr);
77-
setOperatingPoint ("VAi", VAi);
78-
79-
nr_double_t P = VAr;
69+
// save P and Q instead of just S since operating points cannot hold complex values
70+
nr_double_t P = real (Sw);
71+
nr_double_t Q = imag (Sw);
8072
setOperatingPoint ("P", P);
81-
82-
nr_double_t Q = VAi;
8373
setOperatingPoint ("Q", Q);
8474
//Power Factor calculation
85-
setOperatingPoint ("PF", P/std::sqrt(P*P+VAi*VAi));
75+
setOperatingPoint ("PF", P/std::sqrt(P*P+Q*Q));
8676
}
8777

8878
void wprobe::initTR (void) {

qucs-core/src/components/wprobe.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class wprobe : public qucs::circuit
3434
void initAC (void);
3535
void initTR (void);
3636
void saveOperatingPoints (void);
37-
void calcOperatingPoints (void);
3837
};
3938

4039
#endif /* __WPROBE_H__ */

qucs-core/src/nasolver.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,16 +1355,22 @@ void nasolver<nr_type_t>::saveResults (const std::string &volts, const std::stri
13551355
circuit * root = subnet->getRoot ();
13561356
for (circuit * c = root; c != NULL; c = (circuit *) c->getNext ())
13571357
{
1358+
// FIXME: operating points are (ab)used in probes to hold probes data
1359+
// should be handled differently
1360+
// skip if not a probe
13581361
if (!c->isProbe ()) continue;
1362+
// skip if saving subcircuit components data is not requested
13591363
if (!c->getSubcircuit().empty() && !(saveOPs & SAVE_ALL)) continue;
1364+
// update probe internal values, if it's not a noise simulation
1365+
// values for noise simulation are in acsolver::saveNoiseResults()
13601366
if (volts != "vn")
13611367
c->saveOperatingPoints ();
13621368
std::string n = createOP (c->getName (), volts);
13631369
saveVariable (n, nr_complex_t (c->getOperatingPoint ("Vr"),
13641370
c->getOperatingPoint ("Vi")), f);
13651371

13661372
//add watt probe data
1367-
c->calcOperatingPoints ();
1373+
// this is a big hack due to (ab)using the operating points
13681374
for (auto ops: c->getOperatingPoints ())
13691375
{
13701376
//It will only get values if none of the strings are 0

0 commit comments

Comments
 (0)