summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Project/ControlEditor.cpp12
-rw-r--r--Project/ControlElement.cpp6
-rw-r--r--Project/ControlElement.h6
-rw-r--r--Project/Exponential.cpp6
-rw-r--r--Project/Exponential.h2
-rw-r--r--Project/Gain.cpp6
-rw-r--r--Project/Gain.h2
-rw-r--r--Project/Multiplier.cpp39
-rw-r--r--Project/Multiplier.h4
-rw-r--r--Project/Project.mk2
10 files changed, 73 insertions, 12 deletions
diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp
index b4976ad..ad2db78 100644
--- a/Project/ControlEditor.cpp
+++ b/Project/ControlEditor.cpp
@@ -623,29 +623,37 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event)
double integrationError = 1e-5;
double simTime = 10.0;
double printStep = 1e-2;
+
+ double pulsePer = 1.0;
ControlElementSolver solver(this, timeStep, integrationError, true, 0.0);
double currentTime = 0.0;
double printTime = 0.0;
+ double pulseTime = 0.0;
std::vector<double> time;
std::vector<double> solution;
+ std::vector<double> inputV;
while(currentTime <= simTime) {
double input = 0.0;
- if(currentTime >= 1.0) input = 1.0;
+ if(pulseTime >= pulsePer * 2.0) pulseTime = 0.0;
+ if(pulseTime >= pulsePer) input = 1.0;
solver.SolveNextStep(input);
if(printTime >= printStep) {
time.push_back(currentTime);
solution.push_back(solver.GetLastSolution());
+ inputV.push_back(input);
printTime = 0.0;
}
printTime += timeStep;
currentTime += timeStep;
+ pulseTime += timeStep;
}
std::vector<ElementPlotData> epdList;
ElementPlotData curve1Data(_("TESTES"), ElementPlotData::CT_BUS);
- curve1Data.AddData(solution, _("teste 1"));
+ curve1Data.AddData(inputV, _("Entrada"));
+ curve1Data.AddData(solution, _("Saida"));
epdList.push_back(curve1Data);
ChartView* cView = new ChartView(this, epdList, time);
diff --git a/Project/ControlElement.cpp b/Project/ControlElement.cpp
index d75c606..e5c7a23 100644
--- a/Project/ControlElement.cpp
+++ b/Project/ControlElement.cpp
@@ -118,3 +118,9 @@ void ControlElement::Move(wxPoint2DDouble position)
m_nodeList[i]->Move(position);
}
}
+
+bool ControlElement::Solve(double input)
+{
+ m_output = input;
+ return true;
+}
diff --git a/Project/ControlElement.h b/Project/ControlElement.h
index 3744c6f..cce739a 100644
--- a/Project/ControlElement.h
+++ b/Project/ControlElement.h
@@ -65,11 +65,7 @@ class ControlElement : public Element
virtual bool IsSolved() const { return m_solved; }
virtual void SetSolved(bool solved = true) { m_solved = solved; }
- virtual bool Solve(double input)
- {
- m_output = input * 2.0;
- return true;
- }
+ virtual bool Solve(double input);
virtual double GetOutput() const { return m_output; }
virtual void SetOutput(double output) { m_output = output; }
protected:
diff --git a/Project/Exponential.cpp b/Project/Exponential.cpp
index 7c4f1fe..a197b93 100644
--- a/Project/Exponential.cpp
+++ b/Project/Exponential.cpp
@@ -111,3 +111,9 @@ void Exponential::SetValues(double aValue, double bValue)
m_aValue = aValue;
m_bValue = bValue;
}
+
+bool Exponential::Solve(double input)
+{
+ m_output = m_aValue * std::exp(m_bValue * input);
+ return true;
+}
diff --git a/Project/Exponential.h b/Project/Exponential.h
index 8260d66..deb5772 100644
--- a/Project/Exponential.h
+++ b/Project/Exponential.h
@@ -22,6 +22,8 @@ public:
virtual void GetValues(double& aValue, double &bValue);
virtual void SetValues(double aValue, double bValue);
+ virtual bool Solve(double input);
+
protected:
double m_aValue = 0.001;
double m_bValue = 5.0;
diff --git a/Project/Gain.cpp b/Project/Gain.cpp
index faea89c..5f65c0c 100644
--- a/Project/Gain.cpp
+++ b/Project/Gain.cpp
@@ -167,3 +167,9 @@ void Gain::Move(wxPoint2DDouble position)
SetPosition(m_movePos + position - m_moveStartPt);
UpdatePoints();
}
+
+bool Gain::Solve(double input)
+{
+ m_output = input * m_value;
+ return true;
+}
diff --git a/Project/Gain.h b/Project/Gain.h
index 8844372..b2552fc 100644
--- a/Project/Gain.h
+++ b/Project/Gain.h
@@ -24,6 +24,8 @@ class Gain : public ControlElement
virtual void SetValue(double value);
virtual double GetValue() const { return m_value; }
virtual void UpdatePoints();
+
+ virtual bool Solve(double input);
protected:
double m_value = 1.0;
diff --git a/Project/Multiplier.cpp b/Project/Multiplier.cpp
index ee644ed..14efa8c 100644
--- a/Project/Multiplier.cpp
+++ b/Project/Multiplier.cpp
@@ -1,12 +1,12 @@
#include "Multiplier.h"
+#include "ConnectionLine.h"
Multiplier::Multiplier(int id) : ControlElement(id)
{
m_width = m_height = 36.0;
Node* nodeIn1 = new Node(m_position + wxPoint2DDouble(-18, -9), Node::NODE_IN, m_borderSize);
nodeIn1->StartMove(m_position);
- Node* nodeIn2 =
- new Node(m_position + wxPoint2DDouble(-18, 9), Node::NODE_IN, m_borderSize);
+ Node* nodeIn2 = new Node(m_position + wxPoint2DDouble(-18, 9), Node::NODE_IN, m_borderSize);
nodeIn2->StartMove(m_position);
Node* nodeOut = new Node(m_position + wxPoint2DDouble(18, 0), Node::NODE_OUT, m_borderSize);
nodeOut->SetAngle(180.0);
@@ -17,7 +17,6 @@ Multiplier::Multiplier(int id) : ControlElement(id)
}
Multiplier::~Multiplier() {}
-
void Multiplier::Draw(wxPoint2DDouble translation, double scale) const
{
glLineWidth(1.0);
@@ -30,7 +29,7 @@ void Multiplier::Draw(wxPoint2DDouble translation, double scale) const
DrawRectangle(m_position, m_width, m_height);
glColor4d(0.0, 0.0, 0.0, 1.0);
DrawRectangle(m_position, m_width, m_height, GL_LINE_LOOP);
-
+
// Plot x.
glLineWidth(2.0);
std::vector<wxPoint2DDouble> xSymbol;
@@ -84,3 +83,35 @@ void Multiplier::UpdatePoints()
m_nodeList[2]->SetPosition(m_position + wxPoint2DDouble(0, -18));
}
}
+
+bool Multiplier::Solve(double input)
+{
+ std::vector<double> inputVector;
+ for(auto itN = m_nodeList.begin(), itNEnd = m_nodeList.end(); itN != itNEnd; ++itN) {
+ Node* node = *itN;
+ if(node->GetNodeType() != Node::NODE_OUT) {
+ if(!node->IsConnected()) {
+ inputVector.push_back(1.0);
+ } else {
+ for(auto itC = m_childList.begin(), itCEnd = m_childList.end(); itC != itCEnd; ++itC) {
+ ConnectionLine* cLine = static_cast<ConnectionLine*>(*itC);
+ auto nodeList = cLine->GetNodeList();
+ for(auto itCN = nodeList.begin(), itCNEnd = nodeList.end(); itCN != itCNEnd; ++itCN) {
+ Node* childNode = *itCN;
+ if(childNode == node) {
+ inputVector.push_back(cLine->GetValue());
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ m_output = 1.0;
+ for(unsigned int i = 0; i < inputVector.size(); ++i) {
+ m_output *= inputVector[i];
+ }
+
+ return true;
+}
diff --git a/Project/Multiplier.h b/Project/Multiplier.h
index 8a25b23..57efe39 100644
--- a/Project/Multiplier.h
+++ b/Project/Multiplier.h
@@ -3,6 +3,8 @@
#include "ControlElement.h"
+class ConnectionLine;
+
class Multiplier : public ControlElement
{
public:
@@ -16,6 +18,8 @@ class Multiplier : public ControlElement
virtual void Rotate(bool clockwise = true);
virtual void UpdatePoints();
+
+ virtual bool Solve(double input);
};
#endif // MULTIPLIER_H
diff --git a/Project/Project.mk b/Project/Project.mk
index 215c533..caab0f7 100644
--- a/Project/Project.mk
+++ b/Project/Project.mk
@@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=NDSE-69
-Date :=08/05/2017
+Date :=09/05/2017
CodeLitePath :="C:/Program Files/CodeLite"
LinkerName :=C:/TDM-GCC-64/bin/g++.exe
SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC