diff options
author | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2017-12-20 20:45:35 -0200 |
---|---|---|
committer | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2017-12-20 20:45:35 -0200 |
commit | c6d815b6b11504be68d7a97df63cfef749624418 (patch) | |
tree | 750161c22282c781ab9c62fec84c8de50dfb230f /Project/ControlElementSolver.cpp | |
parent | 54bb80251432ff49c967115f8401e7dafc5c57d6 (diff) | |
download | PSP.git-c6d815b6b11504be68d7a97df63cfef749624418.tar.gz PSP.git-c6d815b6b11504be68d7a97df63cfef749624418.tar.xz PSP.git-c6d815b6b11504be68d7a97df63cfef749624418.zip |
Math expr GUI implemented
Diffstat (limited to 'Project/ControlElementSolver.cpp')
-rw-r--r-- | Project/ControlElementSolver.cpp | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/Project/ControlElementSolver.cpp b/Project/ControlElementSolver.cpp index 3534023..c14dd54 100644 --- a/Project/ControlElementSolver.cpp +++ b/Project/ControlElementSolver.cpp @@ -17,10 +17,10 @@ #include "ControlElementSolver.h" -#include "ControlElementContainer.h" -#include "ControlEditor.h" #include "ConnectionLine.h" #include "Constant.h" +#include "ControlEditor.h" +#include "ControlElementContainer.h" #include "Exponential.h" #include "Gain.h" #include "IOControl.h" @@ -119,6 +119,11 @@ bool ControlElementSolver::InitializeValues(bool startAllZero) cLine->SetSolved(false); cLine->SetValue(0.0); } + auto mathExprList = m_ctrlContainer->GetMathExprList(); + for(auto it = mathExprList.begin(), itEnd = mathExprList.end(); it != itEnd; ++it) { + MathExpression* mathExpr = *it; + if(!mathExpr->Initialize()) return false; + } if(!startAllZero) { double origTimeStep = m_timeStep; @@ -141,13 +146,9 @@ bool ControlElementSolver::InitializeValues(bool startAllZero) numIt++; error = std::abs(prevSol - currentSol); if(std::abs(error - prevError) < 1e-1) { - if(m_timeStep < maxStep) { - m_timeStep *= 1.5; - } + if(m_timeStep < maxStep) { m_timeStep *= 1.5; } } else if(std::abs(error - prevError) > 10) { - if(m_timeStep > minStep) { - m_timeStep /= 1.5; - } + if(m_timeStep > minStep) { m_timeStep /= 1.5; } } if(numIt >= maxIteration) { m_failMessage = _("It was not possible to initialize the control system."); @@ -177,10 +178,6 @@ void ControlElementSolver::SolveNextStep() // Get first node connection ConnectionLine* firstConn = static_cast<ConnectionLine*>(m_inputControl->GetChildList()[0]); - /*m_inputControl->SetSolved(); - firstConn->SetValue(1); - firstConn->SetSolved(); - FillAllConnectedChildren(firstConn);*/ // Set value to the connected lines in constants auto constantList = m_ctrlContainer->GetConstantList(); @@ -246,9 +243,7 @@ void ControlElementSolver::SolveNextStep() } ConnectionLine* currentLine = firstConn; - while(currentLine) { - currentLine = SolveNextElement(currentLine); - } + while(currentLine) { currentLine = SolveNextElement(currentLine); } bool haveUnsolvedElement = true; while(haveUnsolvedElement) { @@ -264,9 +259,7 @@ void ControlElementSolver::SolveNextStep() haveUnsolvedElement = true; // Solve secondary branch. currentLine = cLine; - while(currentLine) { - currentLine = SolveNextElement(currentLine); - } + while(currentLine) { currentLine = SolveNextElement(currentLine); } break; } } @@ -276,11 +269,6 @@ void ControlElementSolver::SolveNextStep() } // Set the control system output. - /*if(m_outputControl->GetChildList().size() == 1) { - ConnectionLine* cLine = static_cast<ConnectionLine*>(m_outputControl->GetChildList()[0]); - m_solutions.push_back(cLine->GetValue()); - } else - m_solutions.push_back(0.0);*/ for(auto it = ioList.begin(), itEnd = ioList.end(); it != itEnd; ++it) { IOControl* io = *it; if(io->GetChildList().size() == 1) { @@ -320,7 +308,7 @@ ConnectionLine* ControlElementSolver::SolveNextElement(ConnectionLine* currentLi ControlElement* element = static_cast<ControlElement*>(*it); // Solve the unsolved parent. if(!element->IsSolved()) { - if(!element->Solve(currentLine->GetValue(), m_timeStep)) return NULL; + if(!element->Solve(currentLine->GetValue(), m_timeStep, m_currentTime)) return NULL; element->SetSolved(); // Get the output node (must have one or will result NULL). |