24 #include <ast/parser/parse.hpp>
25 #include <deps/builders/eq_graph_builder.hpp>
26 #include <deps/sbg_graph/build_from_exps.hpp>
27 #include <deps/sb_dependencies.hpp>
45 int size = vertex.range().size();
46 int id = vertex.index() - 1;
49 code <<
"// Assign Jacobian Matrix values for equation: " <<
id << endl;
50 code << tab <<
"for (row = 0; row < " << size <<
"; row++) {" << endl;
51 code << tab <<
" for (col = 0; col < dvdx->df_dx[" <<
id <<
"]->size[row]; col++) {" << endl;
52 code << tab <<
" row_t = dvdx->df_dx[" <<
id <<
"]->index[row][col];" << endl;
53 code << tab <<
" _assign_jac(row_t, dvdx->df_dx[" <<
id <<
"]->value[row][col]);" << endl;
54 code << tab <<
" }" << endl;
55 code << tab <<
"}" << endl;
64 code <<
"for(row = 1; row <= " << vertex.range().size() <<
"; row++) {" << endl;
65 code <<
TAB <<
"c_row = _c_index(row);" << endl;
79 if (map.constantExp()) {
82 Range range(dom, offset);
90 return range.
in(exps);
97 SB::Deps::LMapExp map = var_dep.nMap();
98 Range range(var_dep.variables(), var_dep.varOffset());
99 if (var_dep.isRecursive() && eq.
hasRange()) {
101 code << tabs << eq.
range().get();
104 vector<string> exps = eq.
range()->getIndexes();
110 if (!map.constantExp()) {
111 code << tabs <<
"if(" << range.
in(exps);
112 if (!
guard.empty()) {
113 code <<
" && " <<
guard;
115 code <<
") {" << endl;
116 }
else if (!
guard.empty()) {
117 code << tabs <<
" if(" <<
guard <<
") {" << endl;
121 if (!map.constantExp() || !
guard.empty()) {
125 code << tabs <<
"x_ind = " << x_ind <<
";" << endl;
132 if (!var_dep.nMap().constantExp() || !var_dep.mMap().constantExp()) {
136 if (var_dep.isRecursive() && eq.hasRange()) {
137 code << eq.range()->end();
146 string type_str =
"df_dx";
147 code << tab << col <<
" = pos(dvdx->";
151 code << type_str <<
"[" <<
id <<
"]->index[" << row <<
"], ";
152 code <<
"dvdx->" << type_str <<
"[" <<
id <<
"]->size[" << row <<
"], x_ind);" << endl;
161 code << tab <<
"dvdx->" << mat <<
"[" <<
id <<
"]->value[c_row][col] += aux;" << endl;
170 code << tab <<
"dvdx->" << mat <<
"[" << v_id <<
"]->value[c_row][col] += ";
171 code <<
"aux * dvdx->dg_dx[" << g_id <<
"]->value[c_row_g][col_g];" << endl;
181 code << tab <<
"_apply_usage" << eq.
applyId() <<
"(" << args <<
");" << endl;
193 void JacGenerator::visitF(SB::Deps::SetVertex vertex, SB::Deps::VariableDep var_dep, SB::Deps::SetVertex gen_vertex)
195 Equation eq = getEquation(gen_vertex);
214 void JacGenerator::visitG(SB::Deps::SetVertex v_vertex, SB::Deps::SetVertex g_vertex, SB::Deps::VariableDep var_dep,
int index_shift)
217 const bool REC_DEPS = var_dep.isRecursive();
218 Equation v_eq = getEquation(v_vertex);
219 Equation g_eq = getEquation(g_vertex);
221 SB::Deps::LMapExp map_m = var_dep.mMap();
222 SB::Deps::LMapExp n_map = var_dep.nMap();
223 string dom_guard =
guard(var_dep.equations(), var_dep.eqOffset(), var_dep.var().name(), map_m, v_eq);
226 vector<string> variables;
228 static const bool USE_RANGE_IDXS =
true;
231 exps = map_m.apply(v_eq.
range()->getDimensionVars(USE_RANGE_IDXS));
235 if (REC_DEPS || g_lhs->isArray()) {
236 Range range(var_dep.variables(), var_dep.varOffset());
238 }
else if (v_lhs->isArray()) {
241 exps.push_back(exp.print());
247 code << tab <<
"c_row_g = " << a_ind <<
" - ";
250 eq_shift += index_shift;
252 code << eq_shift <<
";" << endl;
260 void JacGenerator::visitG(SB::Deps::SetVertex v_vertex, SB::Deps::SetVertex g_vertex, SB::PWLMap use_map, SB::Deps::LMapExp use_map_exp,
261 Expression use_exp, SB::PWLMap def_map, SB::Deps::LMapExp def_map_exp, SB::Set intersection)
269 Equation eq = getEquation(vertex);
285 IndexShiftBuilder index_shifts(algebraics);
286 jac.setup(algebraics);
287 SDSBGraphBuilder SDSBGraph = SDSBGraphBuilder(derivatives, algebraics);
289 jac.compute(SDSBGraph.build(), index_shifts.build());