Skip to content

Commit

Permalink
Addition of the Wattmeter Module
Browse files Browse the repository at this point in the history
Hoping this is staying on my end for now so not describing in depth, if it
goes through to a developer, hopefully i can edit it later. Sorry.
  • Loading branch information
gildias committed Apr 20, 2017
1 parent 9d4b134 commit 7842a29
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 7 deletions.
4 changes: 2 additions & 2 deletions qucs-core/src/components/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ libcomponent_la_SOURCES = attenuator.cpp dcblock.cpp open.cpp vccs.cpp \
biastee.cpp circulator.cpp dcfeed.cpp pac.cpp vcvs.cpp capacitor.cpp \
ground.cpp resistor.cpp cccs.cpp cross.cpp trafo.cpp inductor.cpp \
tee.cpp ccvs.cpp isolator.cpp itrafo.cpp strafo.cpp vdc.cpp idc.cpp \
vac.cpp phaseshifter.cpp gyrator.cpp tline.cpp iprobe.cpp iac.cpp \
vac.cpp phaseshifter.cpp gyrator.cpp tline.cpp iprobe.cpp wprobe.cpp iac.cpp \
spfile.cpp vnoise.cpp inoise.cpp vpulse.cpp ipulse.cpp vrect.cpp \
irect.cpp amplifier.cpp opamp.cpp iinoise.cpp mutual.cpp mutual2.cpp \
vvnoise.cpp ivnoise.cpp coupler.cpp coaxline.cpp vprobe.cpp vam.cpp \
Expand All @@ -46,7 +46,7 @@ noinst_HEADERS = attenuator.h dcblock.h open.h vccs.h biastee.h circulator.h \
dcfeed.h pac.h vcvs.h capacitor.h ground.h resistor.h cccs.h cross.h \
trafo.h inductor.h tee.h ccvs.h isolator.h component.h itrafo.h \
strafo.h vdc.h idc.h vac.h component_id.h phaseshifter.h gyrator.h \
tline.h iprobe.h iac.h spfile.h vnoise.h inoise.h vpulse.h ipulse.h \
tline.h iprobe.h wprobe.h iac.h spfile.h vnoise.h inoise.h vpulse.h ipulse.h \
vrect.h irect.h amplifier.h opamp.h iinoise.h mutual.h mutual2.h \
vvnoise.h ivnoise.h coupler.h coaxline.h vprobe.h vam.h vpm.h \
tswitch.h relais.h short.h twistedpair.h tline4p.h vexp.h iexp.h \
Expand Down
1 change: 1 addition & 0 deletions qucs-core/src/components/component_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ enum circuit_type {
CIR_TLINE4P,
CIR_RLCG,
CIR_IPROBE,
CIR_WPROBE,
CIR_VPROBE,
CIR_SPFILE,
CIR_VPULSE,
Expand Down
1 change: 1 addition & 0 deletions qucs-core/src/components/components.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "tline4p.h"
#include "rlcg.h"
#include "iprobe.h"
#include "wprobe.h"
#include "vprobe.h"
#include "spfile.h"
#include "vpulse.h"
Expand Down
89 changes: 89 additions & 0 deletions qucs-core/src/components/wprobe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* wprobe.cpp - AC/DC and transient watt probe class implementation
*
* Copyright (C) 2015, Pedro Macedo
* 2017, Alberto Silva, 1120196@isep.ipp.pt
*
* This file is part of Qucs
*
* Qucs is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Qucs. If not, see <http://www.gnu.org/licenses/>.
*
*/

//Taking iprobe as basis

#if HAVE_CONFIG_H
# include <config.h>
#endif

#include "component.h"
#include "wprobe.h"

using namespace qucs;

wprobe::wprobe () : circuit (4) {
type = CIR_WPROBE;
setProbe (true);
setVSource (true);
setVoltageSources (1);
}

// NODE 1 --> I+
// NODE 2 --> I-
// NODE 3 --> V+
// NODE 4 --> V-

void wprobe::initDC (void) {
allocMatrixMNA ();
voltageSource (VSRC_1, NODE_1, NODE_2);
}

void wprobe::initAC (void) {
initDC ();
}

void wprobe::saveOperatingPoints (void) {
nr_double_t Vr = real (getV (NODE_3) - getV (NODE_4));
nr_double_t Vi = imag (getV (NODE_3) - getV (NODE_4));
setOperatingPoint ("Vr", Vr);
setOperatingPoint ("Vi", Vi); //This section works just like a voltmeter
}

void wprobe::calcOperatingPoints (void) {
//Reading the current and voltage values to calculate potency values
nr_double_t VAr = real (getV (NODE_3) * getJ (NODE_1));
nr_double_t VAi = -imag (getV (NODE_3) * getJ (NODE_1));
setOperatingPoint ("VAr", VAr);
setOperatingPoint ("VAi", VAi);

nr_double_t Wr = VAr;
setOperatingPoint ("W", Wr);

nr_double_t var = VAi;
setOperatingPoint ("var", var);
//necessary calculations for Potency Factor
nr_double_t alpha = std::atan(VAi/VAr);
nr_double_t S1 = VAr/std::cos(alpha);
setOperatingPoint ("FP", VAr/S1);
}

void wprobe::initTR (void) {
initDC ();
}

// properties
PROP_REQ [] = { PROP_NO_PROP };
PROP_OPT [] = { PROP_NO_PROP };
struct define_t wprobe::cirdef =
{ "WProbe", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };
40 changes: 40 additions & 0 deletions qucs-core/src/components/wprobe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* wprobe.h - AC/DC and transient watt probe class definitions
*
* Copyright (C) 2015, Pedro Macedo
* 2017, Alberto Silva, 1120196@isep.ipp.pt
*
* This file is part of Qucs
*
* Qucs is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Qucs. If not, see <http://www.gnu.org/licenses/>.
*
*/

//Taking vprobe as a basis

#ifndef __WPROBE_H__
#define __WPROBE_H__

class wprobe : public qucs::circuit
{
public:
CREATOR (wprobe);
void initDC (void);
void initAC (void);
void initTR (void);
void saveOperatingPoints (void);
void calcOperatingPoints (void);
};

#endif /* __WPROBE_H__ */
1 change: 1 addition & 0 deletions qucs-core/src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ void module::registerModules (void) {
REGISTER_CIRCUIT (cpwgap);
REGISTER_CIRCUIT (cpwstep);
REGISTER_CIRCUIT (iprobe);
REGISTER_CIRCUIT (wprobe);
REGISTER_CIRCUIT (vprobe);
REGISTER_CIRCUIT (jfet);
REGISTER_CIRCUIT (bjt);
Expand Down
27 changes: 25 additions & 2 deletions qucs-core/src/nasolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,10 +1356,33 @@ void nasolver<nr_type_t>::saveResults (const std::string &volts, const std::stri
if (!c->isProbe ()) continue;
if (!c->getSubcircuit().empty() && !(saveOPs & SAVE_ALL)) continue;
if (volts != "vn")
c->saveOperatingPoints ();
c->saveOperatingPoints ();
std::string n = createOP (c->getName (), volts);
saveVariable (n, nr_complex_t (c->getOperatingPoint ("Vr"),
c->getOperatingPoint ("Vi")), f);
c->getOperatingPoint ("Vi")), f);

//add watt probe data
c->calcOperatingPoints ();
for (auto ops: c->getOperatingPoints ())
{
//It will only get values if none of the strings are 0
//Once again most of this is adapted from Vprobe and Iprobe
operatingpoint &p = ops.second;
if (strcmp(p.getName(), "Vi") == 0) continue;
if (strcmp(p.getName(), "VAi") == 0) continue;
if (strcmp(p.getName(), "Vr") == 0) continue;
if (strcmp(p.getName(), "VAr") == 0)
{
std::string n = createOP(c->getName(), "VA");
saveVariable (n, nr_complex_t (c->getOperatingPoint ("VAr"),
c->getOperatingPoint ("VAi")), f);
continue;
}

std::string n = createOP(c->getName(), p.getName());
saveVariable(n, p.getValue(), f);
}

}
}

Expand Down
Binary file added qucs/qucs/bitmaps/wprobe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion qucs/qucs/components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cpwstep.cpp jkff_SR.cpp pad4bit.cpp volt_noise.cpp
ctline.cpp libcomp.cpp param_sweep.cpp vprobe.cpp
d_flipflop.cpp log_amp.cpp phaseshifter.cpp vpulse.cpp
dc_sim.cpp logic_0.cpp photodiode.cpp vrect.cpp
dcblock.cpp logic_1.cpp phototransistor.cpp
dcblock.cpp logic_1.cpp phototransistor.cpp wprobe.cpp
dcfeed.cpp logical_and.cpp pm_modulator.cpp
vcresistor.cpp
vacomponent.cpp
Expand Down Expand Up @@ -127,6 +127,7 @@ iexp.h
ifile.h
inductor.h
iprobe.h
wprobe.h
ipulse.h
irect.h
isolator.h
Expand Down
4 changes: 2 additions & 2 deletions qucs/qucs/components/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ libcomponents_a_SOURCES = phaseshifter.cpp gyrator.cpp componentdialog.cpp \
source_ac.cpp isolator.cpp equation.cpp circulator.cpp attenuator.cpp \
ampere_dc.cpp transformer.cpp symtrafo.cpp subcirport.cpp ground.cpp \
dcfeed.cpp dcblock.cpp biast.cpp inductor.cpp capacitor.cpp vhdlfile.cpp \
component.cpp resistor.cpp iprobe.cpp volt_noise.cpp ampere_noise.cpp \
component.cpp resistor.cpp iprobe.cpp wprobe.cpp volt_noise.cpp ampere_noise.cpp \
msmbend.cpp msopen.cpp ampere_ac.cpp bjt.cpp jfet.cpp mosfet.cpp \
msgap.cpp bjtsub.cpp mosfet_sub.cpp vpulse.cpp ipulse.cpp vrect.cpp \
irect.cpp msvia.cpp amplifier.cpp opamp.cpp spicefile.cpp cpwopen.cpp \
Expand Down Expand Up @@ -71,7 +71,7 @@ noinst_HEADERS = $(MOCHEADERS) resistor.h components.h capacitor.h vccs.h \
ccvs.h coplanar.h dc_sim.h diode.h hb_sim.h mscorner.h mscoupled.h mslange.h \
mscross.h msline.h msstep.h mstee.h param_sweep.h sp_sim.h substrate.h \
tline.h tr_sim.h component.h vcvs.h gyrator.h phaseshifter.h vhdlfile.h \
iprobe.h volt_noise.h ampere_noise.h msmbend.h msopen.h ampere_ac.h bjt.h \
iprobe.h wprobe.h volt_noise.h ampere_noise.h msmbend.h msopen.h ampere_ac.h bjt.h \
jfet.h mosfet.h msgap.h bjtsub.h mosfet_sub.h vpulse.h ipulse.h vrect.h \
irect.h msvia.h amplifier.h opamp.h spicefile.h cpwopen.h cpwshort.h \
cpwgap.h cpwstep.h libcomp.h mutual.h mutual2.h noise_ii.h noise_iv.h \
Expand Down
1 change: 1 addition & 0 deletions qucs/qucs/components/components.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
#include "opt_sim.h"
#include "param_sweep.h"
#include "iprobe.h"
#include "wprobe.h"
#include "vprobe.h"
#include "volt_noise.h"
#include "ampere_noise.h"
Expand Down
105 changes: 105 additions & 0 deletions qucs/qucs/components/wprobe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* wprobe.cpp - Construction of the Wattmeter Probe
*
* Copyright (C) 2015, Pedro Macedo
* 2017, Alberto Silva, 1120196@isep.ipp.pt
*
* This file is part of Qucs
*
* Qucs is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Qucs. If not, see <http://www.gnu.org/licenses/>.
*
*/

//Taking vprobe as a basis
#include "wprobe.h"

wProbe::wProbe()
{
Description = QObject::tr("power probe");

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

//Small box
Lines.append(new Line(-16,-28, 16,-28,QPen(Qt::darkYellow,2)));
Lines.append(new Line(-16, -10, 16, -10,QPen(Qt::darkYellow,2)));
Lines.append(new Line(-16,-28,-16, -10,QPen(Qt::darkYellow,2)));
Lines.append(new Line( 16,-28, 16, -10,QPen(Qt::darkYellow,2)));

//Letter W
Lines.append(new Line(-9,-22, -2, -11,QPen(Qt::darkGreen,3)));
Lines.append(new Line(0, -17, -2, -11,QPen(Qt::darkGreen,3)));
Lines.append(new Line(0, -17, 2, -11,QPen(Qt::darkGreen,3)));
Lines.append(new Line(9,-22, 2, -11,QPen(Qt::darkGreen,3)));

//+ and - signs
Lines.append(new Line(-12, 5,-12, 11,QPen(Qt::red,2)));
Lines.append(new Line(-15, 8, -9, 8,QPen(Qt::red,2)));
Lines.append(new Line( 9, 8, 15, 8,QPen(Qt::black,2)));

//Current Entries
Ports.append(new Port(-30, 0));
Ports.append(new Port( 30, 0));

//Voltage Entries
Lines.append(new Line(-10, 14,-10, 20,QPen(Qt::darkBlue,2)));
Lines.append(new Line( 10, 14, 10, 20,QPen(Qt::darkBlue,2)));
Ports.append(new Port(-10, 20));
Ports.append(new Port( 10, 20));

//Letter V
Lines.append(new Line(-3, 7 ,0, 13,QPen(Qt::darkGreen,2)));
Lines.append(new Line( 0, 13, 3, 7,QPen(Qt::darkGreen,2)));

//Letter A
Lines.append(new Line( 11, -9, 15,0,QPen(Qt::darkGreen,2)));
Lines.append(new Line( 7, 0, 11, -9,QPen(Qt::darkGreen,2)));
Lines.append(new Line( 14, -3, 8, -3,QPen(Qt::darkGreen,2)));

//Arrow
Lines.append(new Line(-30, 0,-20, 0,QPen(Qt::darkBlue,1)));
Lines.append(new Line( 30, 0, 20, 0,QPen(Qt::darkBlue,1)));
Lines.append(new Line(-20, 0, 20, 0,QPen(Qt::darkBlue,2)));
Lines.append(new Line( 4, 0, -4, -3,QPen(Qt::darkBlue,2)));
Lines.append(new Line( 4, 0, -4, 4,QPen(Qt::darkBlue,2)));

x1 = -24; y1 = -35;
x2 = 24; y2 = 20;

tx = x2+4;
ty = y1+4;
Model = "WProbe";
Name = "Pr";
}

wProbe::~wProbe()
{
}

Component* wProbe::newOne()
{
return new wProbe();
}

Element* wProbe::info(QString& Name, char* &BitmapFile, bool getNewOne)
{
Name = QObject::tr("Power Probe");
BitmapFile = (char *) "wprobe";

if(getNewOne) return new wProbe();
return 0;
}
38 changes: 38 additions & 0 deletions qucs/qucs/components/wprobe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* wprobe.h - Header file for Wattmeter Probe
*
* Copyright (C) 2015, Pedro Macedo
* 2017, Alberto Silva, 1120196@isep.ipp.pt
*
* This file is part of Qucs
*
* Qucs is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Qucs. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef WPROBE_H
#define WPROBE_H

#include "component.h"

//Following vprobe as basis
class wProbe : public Component {
public:
wProbe();
~wProbe();
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
};

#endif
Loading

0 comments on commit 7842a29

Please sign in to comment.