26 #include <util/visitors/convert_output_range.hpp>
32 template <
typename Config,
typename N>
37 template <
typename Config,
typename N>
46 template <
typename Config,
typename N>
50 string component = _matrix_config.component[0];
51 bool use_component = _matrix_config.use_component[mode];
53 component = _matrix_config.component[1];
55 if (!component.empty() && use_component) {
56 buffer <<
"." << component;
61 template <
typename Config,
typename N>
65 AST_Expression_ComponentReference comp_ref = exp->getAsComponentReference();
66 string comp_ref_name = comp_ref->name();
74 string event_var_name;
75 for (
Event ev = events.
begin(ev_it); !events.
end(ev_it); ev = events.
next(ev_it)) {
76 if (ev.compareEventID(comp_ref_name)) {
77 event_var_name = ev.zeroCrossing().LHSVariable()->name();
81 if (event_var_name.empty()) {
84 if (comp_ref->hasIndexes()) {
85 AST_ExpressionList indexes = comp_ref->firstIndex();
86 AST_ExpressionListIterator exp_it;
88 foreach (exp_it, indexes) {
98 template <
typename Config,
typename N>
101 string matrix = _matrix_config.names[method + mode];
102 string access = _matrix_config.access[mode];
104 for (
auto entry_def : _matrix_config.user_def) {
105 int entry_id = entry_def.first;
106 AST_ExpressionList entry_infs = entry_def.second;
107 AST_ExpressionListIterator exp_it;
108 foreach (exp_it, entry_infs) {
110 N node = _matrix_config.selector.getNode(entry_id);
114 if (exp->expressionType() ==
EXPOUTPUT) {
115 AST_Expression_Output matrix_exps = exp->getAsOutput();
116 AST_ExpressionList matrix_entry = matrix_exps->expressionList();
117 AST_ExpressionListIterator matrix_entry_it;
118 if (matrix_entry->size() != 2) {
121 bool first_exp =
true;
122 ConvertOutputRange convert;
123 AST_Expression matrix_exp =
nullptr;
124 foreach (matrix_entry_it, matrix_entry) {
130 AST_Expression_Bracket range_def =
current_element(matrix_entry_it)->getAsBracket();
131 AST_ExpressionList ranges = range_def->ranges();
132 AST_ExpressionListIterator range_it;
133 foreach (range_it, ranges) {
136 range = convert.range();
139 ife_idx = Index(Expression(transformExp(matrix_exp)));
140 ife_idx = ife_idx.replace(range);
141 }
else if (exp->expressionType() ==
EXPCOMPREF) {
142 AST_Expression_ComponentReference comp_ref = exp->getAsComponentReference();
143 ife_idx = Index(Expression(transformExp(comp_ref)));
144 range = node.range();
146 range->replace(ife_idx);
151 ifr_idx = Index(_matrix_config.selector.exp(node));
152 ifr_idx = ifr_idx.replace();
153 ife_idx = ife_idx.replace();
156 const bool GENERATE_RANGE_INDEX =
false;
157 const bool C_INDEX =
false;
158 const bool CONVERT_PARAMS =
true;
159 code << range->print(GENERATE_RANGE_INDEX, C_INDEX, CONVERT_PARAMS);
160 code << range->block();
163 code << _matrix_config.container << matrix <<
"[" << ifr_idx <<
"]" << component(
MATRIX::Alloc, mode) <<
"++;" << endl;
165 code << _matrix_config.container << matrix <<
"[" << ifr_idx <<
"]" << component(
MATRIX::Init, mode) <<
"[" << access <<
"["
166 << ifr_idx <<
"]++] = " << ife_idx <<
";" << endl;
169 code << range->end() << endl;
174 _model_matrix_def.alloc[mode] = code.str();
176 _model_matrix_def.init[mode] = code.str();
180 template <
typename Config,
typename N>
183 return _model_matrix_def;
186 template <
typename Config,
typename N>
189 return _access_vector;
192 template class UserDefMatrix<MATRIX::EQMatrixConfig, Equation>;
194 template class UserDefMatrix<MATRIX::EVMatrixConfig, Event>;