@@ -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