MicroModelicaCCompiler  4.5.3
node_selector.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  This file is part of QSS Solver.
4 
5  QSS Solver is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  QSS Solver is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
17 
18  ******************************************************************************/
19 
20 #include "node_selector.hpp"
21 
22 #include <deps/sbg_graph/build_from_exps.hpp>
23 
24 namespace MicroModelica {
25 using namespace IR;
26 
27 namespace Deps {
28 
29 EQSelector::EQSelector(EquationTable eqs) : _eqs(eqs), _select_states(false), _lhs_states(false){};
30 
31 IR::EquationTable EQSelector::getNodes() const { return _eqs; };
32 
33 IR::Equation EQSelector::getNode(int id)
34 {
35  Option<Equation> eq = _eqs[id];
36  assert(eq);
37  return eq.get();
38 }
39 
40 IR::Equation EQSelector::setUsage(Index ifr_idx, Equation eq, Option<Range> range)
41 {
42  Equation der = eq;
43  der.setUsage(ifr_idx);
44  if (range && der.hasRange()) {
45  der.setRange(range);
46  }
47  return der;
48 }
49 
51 {
52  Equation use_eq = eq;
53  if ((range.size() == 1) && exp.isScalar() && eq.hasRange()) {
54  use_eq.applyUsage(ifr_idx);
55  }
56  return use_eq;
57 }
58 
59 bool EQSelector::isAlgebraic(SB::Deps::SetVertex vertex)
60 {
61  Equation eq = getEquation(vertex, _eqs);
62  return eq.type() == EQUATION::Algebraic;
63 }
64 
65 int EQSelector::id(SB::Deps::SetVertex vertex) { return getEquation(vertex, _eqs).id(); };
66 
68 
69 bool EQSelector::multipleNodes() const { return false; }
70 
71 bool EQSelector::lhsStates() { return _lhs_states; }
72 
73 std::string EQSelector::nodeName(int id) { return getNode(id).LHSVariable()->name(); }
74 
75 bool EQSelector::validVariable(Util::Variable var)
76 {
77  if (_select_states) {
78  return var.isState();
79  }
80  return (var.name().find("_event_") != std::string::npos);
81 }
82 
83 SB::PWLMap EQSelector::mapU() { return _map_u; }
84 
85 SB::PWLMap EQSelector::mapF() { return _map_f; }
86 
87 void EQSelector::setMapU(SB::PWLMap map_u) { _map_u = map_u; }
88 
89 void EQSelector::setMapF(SB::PWLMap map_f) { _map_f = map_f; }
90 
91 EVSelector::EVSelector(IR::EventTable evs) : _evs(evs) {}
92 
93 IR::EventTable EVSelector::getNodes() const { return _evs; }
94 
96 {
97  Option<Event> ev = _evs[id];
98  assert(ev);
99  return ev.get();
100 }
101 
103 
104 IR::Event EVSelector::getScalarUsage(SB::Set range, IR::Expression exp, IR::Event ev, IR::Index ifr_idx) { return ev; }
105 
106 bool EVSelector::isAlgebraic(SB::Deps::SetVertex vertex)
107 {
108  if (vertex.desc().type() == SB::Deps::VERTEX::Equation) {
109  Equation eq = getEquation(vertex);
110  return eq.type() == EQUATION::Algebraic;
111  }
112  return false;
113 }
114 
115 int EVSelector::id(SB::Deps::SetVertex vertex) { return getEvent(vertex).id(); };
116 
118 
119 bool EVSelector::multipleNodes() const { return true; }
120 
121 bool EVSelector::lhsStates() { return false; }
122 
123 std::string EVSelector::nodeName(int id) { return getNode(id).zeroCrossing().LHSVariable()->name(); }
124 
125 bool EVSelector::validVariable(Util::Variable var) { return (var.name().find("_event_") != std::string::npos); }
126 
127 SB::PWLMap EVSelector::mapU() { return _map_u; }
128 
129 SB::PWLMap EVSelector::mapF() { return _map_f; }
130 
131 void EVSelector::setMapU(SB::PWLMap map_u) { _map_u = map_u; }
132 
133 void EVSelector::setMapF(SB::PWLMap map_f) { _map_f = map_f; }
134 
135 } // namespace Deps
136 } // namespace MicroModelica
MicroModelica::Deps::EQSelector::lhsStates
bool lhsStates()
Definition: node_selector.cpp:88
ModelTable< int, Event >
MicroModelica::Deps::EVSelector::mapU
SB::PWLMap mapU()
Definition: node_selector.cpp:144
MicroModelica::Deps::EVSelector::setMapU
void setMapU(SB::PWLMap map_u)
Definition: node_selector.cpp:148
MicroModelica::Deps::EVSelector::exp
IR::Expression exp(IR::Event ev)
Definition: node_selector.cpp:134
MicroModelica::Util::Variable
Definition: symbol_table.hpp:75
MicroModelica::Deps::EVSelector::lhsStates
bool lhsStates()
Definition: node_selector.cpp:138
MicroModelica::Deps::EVSelector::nodeName
std::string nodeName(int id)
Definition: node_selector.cpp:140
MicroModelica::Deps::EQSelector::getScalarUsage
IR::Equation getScalarUsage(SB::Set range, IR::Expression exp, IR::Equation eq, IR::Index ifr_idx)
Definition: node_selector.cpp:67
MicroModelica::Deps::EVSelector::getNode
IR::Event getNode(int id)
Definition: node_selector.cpp:112
MicroModelica::IR::Equation::LHSVariable
Option< Util::Variable > LHSVariable() const
Definition: equation.cpp:165
MicroModelica::Deps::EVSelector::id
int id(SB::Deps::SetVertex vertex)
Definition: node_selector.cpp:132
MicroModelica::IR::EquationTable
ModelTable< int, Equation > EquationTable
Definition: equation.hpp:169
MicroModelica::Deps::EQSelector::getNode
IR::Equation getNode(int id)
Definition: node_selector.cpp:50
Option
Definition: util_types.hpp:32
MicroModelica::Util::Variable::name
string name() const
Definition: symbol_table.hpp:127
MicroModelica::Deps::EQSelector::getNodes
IR::EquationTable getNodes() const
Definition: node_selector.cpp:48
MicroModelica::Deps::EQSelector::id
int id(SB::Deps::SetVertex vertex)
Definition: node_selector.cpp:82
MicroModelica::Deps::EVSelector::validVariable
bool validVariable(Util::Variable var)
Definition: node_selector.cpp:142
MicroModelica::Deps::EVSelector::EVSelector
EVSelector()
Definition: node_selector.hpp:98
MicroModelica::Deps::EQSelector::isAlgebraic
bool isAlgebraic(SB::Deps::SetVertex vertex)
Definition: node_selector.cpp:76
MicroModelica::Deps::EVSelector::_evs
IR::EventTable _evs
Definition: node_selector.hpp:118
MicroModelica::Deps::EVSelector::getNodes
IR::EventTable getNodes() const
Definition: node_selector.cpp:110
MicroModelica::IR::Expression
Definition: expression.hpp:64
node_selector.hpp
MicroModelica::IR::Equation::lhs
Expression lhs() const
Definition: equation.hpp:78
MicroModelica::Deps::EQSelector::setUsage
IR::Equation setUsage(IR::Index ifr_idx, IR::Equation eq, Option< IR::Range > range)
Definition: node_selector.cpp:57
MicroModelica::Deps::EVSelector::setMapF
void setMapF(SB::PWLMap map_f)
Definition: node_selector.cpp:150
MicroModelica::IR::Equation
Definition: equation.hpp:67
MicroModelica::IR::Event
Definition: event.hpp:84
MicroModelica::Deps::EVSelector::setUsage
IR::Event setUsage(IR::Index ifr_idx, IR::Event ev, Option< IR::Range > range)
Definition: node_selector.cpp:119
MicroModelica::Deps::EVSelector::isAlgebraic
bool isAlgebraic(SB::Deps::SetVertex vertex)
Definition: node_selector.cpp:123
MicroModelica::IR::Equation::setUsage
void setUsage(Index usage)
Definition: equation.hpp:103
MicroModelica::IR::Index
Definition: index.hpp:92
MicroModelica::Deps::EVSelector::getScalarUsage
IR::Event getScalarUsage(SB::Set range, IR::Expression exp, IR::Event ev, IR::Index ifr_idx)
Definition: node_selector.cpp:121
MicroModelica::Generator::MODEL_INSTANCE::Component::Deps
@ Deps
MicroModelica::IR::Equation::applyUsage
void applyUsage(Index usage)
Definition: equation.cpp:215
MicroModelica::IR::Expression::isScalar
bool isScalar() const
Definition: expression.cpp:73
MicroModelica
Definition: files.cpp:45
MicroModelica::Deps::EQSelector::EQSelector
EQSelector()
Definition: node_selector.hpp:85
MicroModelica::Deps::EQSelector::nodeName
std::string nodeName(int id)
Definition: node_selector.cpp:90
MicroModelica::Deps::EVSelector::multipleNodes
bool multipleNodes() const
Definition: node_selector.cpp:136
MicroModelica::Deps::EQSelector::setMapU
void setMapU(SB::PWLMap map_u)
Definition: node_selector.cpp:104
MicroModelica::IR::Equation::index
Index index() const
Definition: equation.cpp:191
MicroModelica::IR::Equation::hasRange
bool hasRange() const
Definition: equation.hpp:77
MicroModelica::Deps::EVSelector::_map_u
SB::PWLMap _map_u
Definition: node_selector.hpp:119
MicroModelica::Deps::EVSelector::_map_f
SB::PWLMap _map_f
Definition: node_selector.hpp:120
MicroModelica::IR::EQUATION::Algebraic
@ Algebraic
Definition: equation.hpp:50
MicroModelica::Deps::EQSelector::validVariable
bool validVariable(Util::Variable var)
Definition: node_selector.cpp:92
MicroModelica::IR::Index::expression
Expression expression() const
Definition: index.cpp:126
MicroModelica::Deps::EQSelector::exp
IR::Expression exp(IR::Equation eq)
Definition: node_selector.cpp:84
MicroModelica::Deps::EVSelector::mapF
SB::PWLMap mapF()
Definition: node_selector.cpp:146
MicroModelica::Deps::EQSelector::setMapF
void setMapF(SB::PWLMap map_f)
Definition: node_selector.cpp:106
MicroModelica::Deps::EQSelector::multipleNodes
bool multipleNodes() const
Definition: node_selector.cpp:86
MicroModelica::Deps::EQSelector::mapF
SB::PWLMap mapF()
Definition: node_selector.cpp:102
MicroModelica::Deps::EQSelector::mapU
SB::PWLMap mapU()
Definition: node_selector.cpp:100
MicroModelica::IR::Equation::type
EQUATION::Type type() const
Definition: equation.hpp:89
MicroModelica::IR::Event::zeroCrossing
Equation zeroCrossing()
Definition: event.hpp:90