MicroModelicaCCompiler  4.5.3
model_matrix.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 "model_matrix.hpp"
21 
22 #include <sstream>
23 
24 #include <deps/builders/eq_graph_builder.hpp>
25 #include <ir/user_def_matrix.hpp>
26 #include <util/model_config.hpp>
27 
28 namespace MicroModelica {
29 using namespace Deps;
30 using namespace SB;
31 using namespace Util;
32 namespace IR {
33 
34 template <typename GraphBuilder, typename MatrixBuilder, typename Config, typename T, typename N>
36 {
37 }
38 
39 template <typename GraphBuilder, typename MatrixBuilder, typename Config, typename T, typename N>
40 void ModelMatrix<GraphBuilder, MatrixBuilder, Config, T, N>::build(Config config)
41 {
42  EquationTable algebraics = ModelConfig::instance().algebraics();
43  VarSymbolTable symbols = ModelConfig::instance().symbols();
44  MatrixBuilder model_matrix;
45  IndexShiftBuilder index_shifts(algebraics);
46  T nodes = config.selector.getNodes();
47  GraphBuilder SBGraph(nodes, algebraics, config.search);
48  model_matrix.setup(config);
49  model_matrix.compute(SBGraph.build(), index_shifts.build());
50  _model_matrix_def = model_matrix.def();
51  _access[0] = model_matrix.config().access[0];
52  _access[1] = model_matrix.config().access[1];
53  // Add any user definition entry if any.
54  UserDefMatrix<Config, N> user_def(config);
55  user_def.compute();
56  append(user_def.def());
57 }
58 
59 template <typename GraphBuilder, typename MatrixBuilder, typename Config, typename T, typename N>
61 {
62  return _model_matrix_def.alloc[_mode];
63 }
64 
65 template <typename GraphBuilder, typename MatrixBuilder, typename Config, typename T, typename N>
67 {
68  return _model_matrix_def.init[_mode];
69 }
70 
71 template <typename GraphBuilder, typename MatrixBuilder, typename Config, typename T, typename N>
72 string ModelMatrix<GraphBuilder, MatrixBuilder, Config, T, N>::accessVector() const
73 {
74  return _access[_mode];
75 }
76 
77 template <typename GraphBuilder, typename MatrixBuilder, typename Config, typename T, typename N>
79 {
80  return _model_matrix_def.alloc[MATRIX::Normal].empty();
81 }
82 
83 template <typename GraphBuilder, typename MatrixBuilder, typename Config, typename T, typename N>
85 {
86  _mode = mode;
87 }
88 
89 template <typename GraphBuilder, typename MatrixBuilder, typename Config, typename T, typename N>
91 {
92  return _model_matrix_def;
93 }
94 
95 template <typename GraphBuilder, typename MatrixBuilder, typename Config, typename T, typename N>
97 {
98  _model_matrix_def.alloc[MATRIX::Normal].append(def.alloc[MATRIX::Normal]);
99  _model_matrix_def.init[MATRIX::Normal].append(def.init[MATRIX::Normal]);
100  _model_matrix_def.alloc[MATRIX::Transpose].append(def.alloc[MATRIX::Transpose]);
101  _model_matrix_def.init[MATRIX::Transpose].append(def.init[MATRIX::Transpose]);
102 }
103 
105 
107 
109 
111 
113 
115 
117 
119 
121 
123 
125 
126 } // namespace IR
127 } // namespace MicroModelica
MicroModelica::IR::MATRIX::Normal
@ Normal
Definition: model_matrix_gen.hpp:103
MicroModelica::IR::ModelMatrix
Definition: model_matrix.hpp:68
model_matrix.hpp
MicroModelica::IR::ModelMatrixDef::init
std::string init[2]
Definition: model_matrix_gen.hpp:108
MicroModelica::IR::ModelMatrix::alloc
std::string alloc()
Definition: model_matrix.cpp:77
MicroModelica::IR::EquationTable
ModelTable< int, Equation > EquationTable
Definition: equation.hpp:169
MicroModelica::IR::UserDefMatrix
Definition: user_def_matrix.hpp:64
model_config.hpp
MicroModelica::IR::ModelMatrix::ModelMatrix
ModelMatrix()
Definition: model_matrix.cpp:52
MicroModelica::IR::ModelMatrixDef
Definition: model_matrix_gen.hpp:106
MicroModelica::IR::MATRIX::Transpose
@ Transpose
Definition: model_matrix_gen.hpp:103
MicroModelica::IR::ModelMatrix::init
std::string init()
Definition: model_matrix.cpp:83
user_def_matrix.hpp
MicroModelica::IR::MATRIX::Mode
Mode
Definition: model_matrix_gen.hpp:86
MicroModelica::IR::ModelMatrixDef::alloc
std::string alloc[2]
Definition: model_matrix_gen.hpp:107
MicroModelica::Generator::MODEL_INSTANCE::Component::Deps
@ Deps
MicroModelica
Definition: files.cpp:45
T
#define T(s)
Definition: type_check.cpp:30