26 #include "integrator_impl.hpp"
27 #include "casadi_misc.hpp"
33 case DYN_T:
return "t";
34 case DYN_X:
return "x";
35 case DYN_Z:
return "z";
36 case DYN_P:
return "p";
37 case DYN_U:
return "u";
136 return integrator(name, solver, dae, 0.0, std::vector<double>{1.0}, opts);
141 return integrator(name, solver, dae, 0.0, std::vector<double>{1.0}, opts);
146 return integrator(name, solver, dae, 0.0, std::vector<double>{1.0}, opts);
150 const SXDict& dae,
double t0,
const std::vector<double>& tout,
const Dict& opts) {
155 const MXDict& dae,
double t0,
const std::vector<double>& tout,
const Dict& opts) {
160 const Function& dae,
double t0,
const std::vector<double>& tout,
const Dict& opts) {
163 casadi_error(
"Cannot create '" + name +
"' since " +
str(dae.
get_free()) +
" are free.");
170 const SXDict& dae,
double t0,
double tf,
const Dict& opts) {
171 return integrator(name, solver, dae, t0, std::vector<double>{tf}, opts);
175 const MXDict& dae,
double t0,
double tf,
const Dict& opts) {
176 return integrator(name, solver, dae, t0, std::vector<double>{tf}, opts);
180 const Function& dae,
double t0,
double tf,
const Dict& opts) {
181 return integrator(name, solver, dae, t0, std::vector<double>{tf}, opts);
207 return std::string();
221 return std::string();
233 return enum_names<DynIn>();
237 return enum_names<DynOut>();
257 return enum_names<EventIn>();
261 return enum_names<EventOut>();
265 double t0,
const std::vector<double>& tout)
358 casadi_int* iw,
double* w,
void* mem)
const {
381 setup(m, arg, res, iw, w);
393 bool first_call =
true;
399 casadi_int k_stop = -1;
402 m->reset_solver =
false;
405 for (m->k = 0; m->k <
nt(); ++m->k) {
409 m->t_next_out =
tout_[m->k];
411 m->t_next = m->t_next_out;
418 m->t_stop = m->t_step =
tout_[k_stop];
420 m->reset_solver =
true;
423 std::fill_n(m->event_triggered,
ne_, 0);
427 if (m->reset_solver) {
428 reset(m, first_call);
429 m->reset_solver =
false;
434 casadi_message(
"Interval " +
str(m->k) +
": Integrating forward from "
435 +
str(m->t) +
" to " +
str(m->t_next) +
", t_stop = " +
str(m->t_stop));
439 if (m->event_index >= 0) {
441 std::fill_n(m->event_triggered,
ne_, 0);
443 while (m->event_index >= 0) {
447 m->reset_solver =
true;
451 m->t_stop = m->t_step;
452 m->t_next = m->t_next_out;
454 }
while (m->t != m->t_next);
468 if (adj_xf) adj_xf +=
nrx_ *
nt();
469 if (rz0) rz0 +=
nrz_ *
nt();
470 if (rp) rp +=
nrp_ *
nt();
471 if (adj_u) adj_u +=
nuq_ *
nt();
477 bool any_impulse =
false;
479 for (m->k =
nt(); m->k-- > 0; ) {
482 if (adj_xf) adj_xf -=
nrx_;
483 if (rz0) rz0 -=
nrz_;
485 if (adj_u) adj_u -=
nuq_;
488 if (
verbose_) casadi_message(
"Impulse from adjoint seeds at output time " +
str(m->k));
493 casadi_int k_next = m->k - 1;
494 m->t_next = k_next < 0 ?
t0_ :
tout_[k_next];
496 if (k_next < k_stop) k_stop =
next_stopB(m->k, u);
497 m->t_stop = k_stop < 0 ?
t0_ :
tout_[k_stop];
500 if (
verbose_) casadi_message(
"Integrating backward from output time " +
str(m->k)
501 +
": t_next = " +
str(m->t_next) +
", t_stop = " +
str(m->t_stop));
503 retreat(m, u,
nullptr,
nullptr, adj_u);
505 retreat(m, u, adj_x, adj_p, adj_u);
508 if (
verbose_) casadi_message(
"No adjoint seeds from output time " +
str(m->k)
509 +
": t_next = " +
str(m->t_next) +
", t_stop = " +
str(m->t_stop));
519 for (m->k = 0; m->k <
nt() - 1; ++m->k) {
559 for (casadi_int i = 0; i <
ne_; ++i) {
565 double t_zero = m->
t - m->
e[i] / m->
edot[i];
567 if (t_zero <= m->t_start || (m->
e[i] < 0 && m->
edot[i] >= 0)) {
571 if (t_zero < m->t_next) {
581 double t_diff = std::fabs(m->
t_next - m->
t);
584 if (
verbose_) casadi_message(
"Event iteration converged, |dt| == " +
str(t_diff));
591 casadi_error(
"Maximum number of event iterations reached without convergence");
593 if (
verbose_) casadi_message(
"Max event iterations, |dt| == " +
str(t_diff));
608 "Print out statistics after integration"}},
611 "Number of forward sensitivities to be calculated [0]"}},
614 "Number of adjoint sensitivities to be calculated [0]"}},
617 "[DEPRECATED] Beginning of the time horizon"}},
620 "[DEPRECATED] End of the time horizon"}},
623 "[DEPRECATED] Time grid"}},
624 {
"augmented_options",
626 "Options to be passed down to the augmented integrator, if one is constructed"}},
629 "Function to be called a zero-crossing events"}},
632 "Maximum number of iterations to zero in on a single event"}},
635 "Maximum total number of events"}},
638 "Termination tolerance for the event iteration"}},
641 "[DEPRECATED] Output the state at the initial time"}}
647 double t0 = 0, tf = 1;
648 bool output_t0 =
false;
649 std::vector<double> grid;
650 bool uses_legacy_options =
false;
653 for (
auto&& op : opts) {
654 if (op.first==
"output_t0") {
655 output_t0 = op.second;
656 uses_legacy_options =
true;
657 }
else if (op.first==
"print_stats") {
659 }
else if (op.first==
"nfwd") {
661 }
else if (op.first==
"nadj") {
663 }
else if (op.first==
"grid") {
665 uses_legacy_options =
true;
666 }
else if (op.first==
"augmented_options") {
668 }
else if (op.first==
"transition") {
670 }
else if (op.first==
"max_event_iter") {
672 }
else if (op.first==
"max_events") {
674 }
else if (op.first==
"event_tol") {
676 }
else if (op.first==
"event_acceptable_tol") {
678 }
else if (op.first==
"t0") {
680 uses_legacy_options =
true;
681 }
else if (op.first==
"tf") {
683 uses_legacy_options =
true;
691 if (uses_legacy_options) {
692 static bool first_encounter =
true;
693 if (first_encounter) {
695 casadi_warning(
"The options 't0', 'tf', 'grid' and 'output_t0' have been deprecated.\n"
696 "The same functionality is provided by providing additional input arguments to "
697 "the 'integrator' function, in particular:\n"
698 " * Call integrator(..., t0, tf, options) for a single output time, or\n"
699 " * Call integrator(..., t0, grid, options) for multiple grid points.\n"
700 "The legacy 'output_t0' option can be emulated by including or excluding 't0' in 'grid'.\n"
701 "Backwards compatibility is provided in this release only.");
702 first_encounter =
false;
706 if (grid.empty()) grid = {t0, tf};
715 casadi_assert(
nfwd_ >= 0,
"Number of forward sensitivities must be non-negative");
716 casadi_assert(
nadj_ >= 0,
"Number of adjoint sensitivities must be non-negative");
726 casadi_assert(sp.
is_empty() || sp.
is_scalar(),
"DAE time variable must be empty or scalar. "
727 "Got dimension " +
str(sp.
size()));
729 casadi_assert(sp.
is_vector(),
"DAE inputs must be vectors. "
732 casadi_assert(sp.
is_dense(),
"DAE inputs must be dense . "
733 +
dyn_in(i) +
" is sparse.");
739 casadi_assert(sp.
is_vector(),
"DAE outputs must be vectors. "
741 casadi_assert(sp.
is_dense(),
"DAE outputs must be dense . "
755 casadi_warning(
"Event support is experimental");
759 casadi_assert(
nx1_ > 0,
"Ill-posed ODE - no state");
855 "Jacobian of the forward problem is structurally rank-deficient. "
860 "Jacobian of the backward problem is structurally rank-deficient. "
887 casadi_int*& iw,
double*& w)
const {
900 m->edot = w; w +=
ne_;
901 m->old_e = w; w +=
ne_;
902 m->xdot = w; w +=
nx_;
903 m->zdot = w; w +=
nz_;
904 m->event_triggered = iw; iw +=
ne_;
906 m->adj_x = w; w +=
nrx_;
907 m->adj_z = w; w +=
nrz_;
908 m->adj_p = w; w +=
nrq_;
909 m->adj_q = w; w +=
nrp_;
911 m->tmp1 = w; w +=
ntmp_;
912 m->tmp2 = w; w +=
ntmp_;
934 ret = get_forward_dae<SX>(aug_name);
936 ret = get_forward_dae<MX>(aug_name);
938 }
catch (std::exception& e) {
939 casadi_error(
"Failed to generate augmented DAE for " +
name_ +
":\n" + e.what());
946 template<
typename MatType>
951 casadi_assert(
ne_ == 0,
"Event support not implemented for Integrator::augmented_dae");
954 std::vector<MatType> arg = MatType::get_input(
oracle_);
955 std::vector<MatType> res =
oracle_(arg);
958 std::vector<std::vector<MatType>> aug_in(
DYN_NUM_IN);
959 for (casadi_int i = 0; i <
DYN_NUM_IN; ++i) aug_in[i].push_back(arg.at(i));
960 std::vector<std::vector<MatType>> aug_out(
DYN_NUM_OUT);
961 for (casadi_int i = 0; i <
DYN_NUM_OUT; ++i) aug_out[i].push_back(res.at(i));
967 std::vector<std::vector<MatType>> seed(
nfwd_, std::vector<MatType>(
DYN_NUM_IN));
968 for (casadi_int d = 0; d <
nfwd_; ++d) {
970 std::string pref =
"aug" +
str(d) +
"_";
980 if (i !=
DYN_T) aug_in[i].push_back(seed[d][i]);
985 std::vector<std::vector<MatType>> sens;
990 casadi_assert_dev(sens.size() ==
nfwd_);
991 for (casadi_int d = 0; d <
nfwd_; ++d) {
999 for (casadi_int i = 0; i <
DYN_NUM_IN; ++i) arg.at(i) = vertcat(aug_in[i]);
1000 for (casadi_int i = 0; i <
DYN_NUM_OUT; ++i) res.at(i) = vertcat(aug_out[i]);
1018 for (casadi_int i = 0; i <
nfwd_; ++i) {
1044 for (casadi_int i = 0; i <
nfwd_; ++i) {
1078 for (casadi_int i = 0; i <
nfwd_; ++i) {
1125 for (casadi_int i = 0; i <
nfwd_; ++i) {
1152 casadi_int* iw,
bvec_t* w,
void* mem)
const {
1196 std::copy_n(x0,
nx_, x);
1198 std::fill_n(x,
nx_, 0);
1202 for (casadi_int k = 0; k <
nt(); ++k) {
1205 for (casadi_int i = 0; i <
nx_; ++i) tmp1[i] |= x[i];
1208 std::copy_n(tmp1,
nx_ +
nz_, w);
1209 std::fill_n(tmp1,
nx_ +
nz_, 0);
1213 if (xf) std::copy_n(tmp1,
nx_, xf);
1214 if (zf) std::copy_n(tmp1 +
nx_,
nz_, zf);
1217 if (
nq_ > 0 && qf) {
1222 std::copy_n(tmp1,
nx_, x);
1231 std::fill_n(tmp2,
nrx_, 0);
1232 if (adj_p0) std::fill_n(adj_p0,
nrq_, 0);
1235 if (adj_xf) adj_xf +=
nrx_ *
nt();
1236 if (adj_qf) adj_qf +=
nrp_ *
nt();
1237 if (adj_u) adj_u +=
nuq_ *
nt();
1240 for (casadi_int k =
nt(); k-- > 0; ) {
1242 if (adj_xf) adj_xf -=
nrx_;
1243 if (adj_qf) adj_qf -=
nrp_;
1244 if (adj_u) adj_u -=
nuq_;
1249 for (casadi_int i = 0; i <
nrx_; ++i) tmp2[i] |= adj_xf[i];
1253 if (
bdae_sp_forward(&m, tmp1, tmp1 +
nx_, p, u, tmp2, adj_qf, adj_x, adj_z))
return 1;
1254 for (casadi_int i = 0; i <
nrx_; ++i) adj_x[i] |= tmp2[i];
1257 std::copy_n(adj_x,
nrx_ +
nrz_, w);
1258 std::fill_n(adj_x,
nrx_ +
nrz_, 0);
1262 if ((
nrq_ > 0 && adj_p0) || (
nuq_ > 0 && adj_u)) {
1267 for (casadi_int i = 0; i <
nrq_; ++i) adj_p0[i] |= adj_p[i];
1272 std::copy_n(adj_x,
nrx_, tmp2);
1276 if (adj_x0) std::copy_n(adj_x,
nrx_, adj_x0);
1290 for (casadi_int i = 0; i <
nfwd_; ++i) {
1318 for (casadi_int i = 0; i <
nfwd_; ++i) {
1352 for (casadi_int i = 0; i <
nfwd_; ++i) {
1399 for (casadi_int i = 0; i <
nfwd_; ++i) {
1430 casadi_int* iw,
bvec_t* w,
void* mem)
const {
1473 std::fill_n(tmp1,
nx_ +
nz_, 0);
1478 std::copy_n(adj_x0,
nrx_, adj_x);
1479 std::fill_n(adj_x0,
nrx_, 0);
1481 std::fill_n(adj_x,
nrx_, 0);
1484 std::fill_n(adj_z,
nrz_, 0);
1487 if (adj_p0) std::copy_n(adj_p0,
nrq_, adj_p);
1490 for (casadi_int k = 0; k <
nt(); ++k) {
1492 if (adj_p0) std::copy_n(adj_p,
nrq_, adj_p0);
1496 for (casadi_int i = 0; i <
nrx_; ++i) adj_x[i] |= adj_xf[i];
1497 std::fill_n(adj_xf,
nrx_, 0);
1501 if ((
nrq_ > 0 && adj_p0) || (
nuq_ > 0 && adj_u)) {
1509 std::copy_n(w,
nrx_ +
nrz_, adj_x);
1512 std::copy_n(adj_x,
nrx_, tmp2);
1515 if (
bdae_sp_reverse(&m, tmp1, tmp1 +
nx_, p, u, tmp2, adj_qf, adj_x, adj_z))
return 1;
1518 std::copy_n(tmp2,
nrx_, adj_x);
1519 std::fill_n(adj_z,
nrz_, 0);
1522 if (adj_xf) adj_xf +=
nrx_;
1523 if (adj_qf) adj_qf +=
nrp_;
1524 if (adj_u) adj_u +=
nuq_;
1529 if (u) u +=
nu_ *
nt();
1533 if (xf) xf +=
nx_ *
nt();
1534 if (zf) zf +=
nz_ *
nt();
1535 if (qf) qf +=
nq_ *
nt();
1538 for (casadi_int k =
nt(); k-- > 0; ) {
1547 for (casadi_int i = 0; i <
nx_; ++i) tmp1[i] |= xf[i];
1548 std::fill_n(xf,
nx_, 0);
1551 for (casadi_int i = 0; i <
nz_; ++i) tmp1[
nx_ + i] |= zf[i];
1552 std::fill_n(zf,
nz_, 0);
1556 if (
nq_ > 0 && qf) {
1561 std::fill_n(w,
nx_ +
nz_, 0);
1563 std::copy_n(w,
nx_ +
nz_, tmp1);
1566 std::copy_n(tmp1,
nx_, x);
1572 std::copy_n(x,
nx_, tmp1);
1573 std::fill_n(tmp1 +
nx_,
nz_, 0);
1578 for (casadi_int i = 0; i <
nx_; ++i) x0[i] |= x[i];
1585 const std::vector<std::string>& inames,
1586 const std::vector<std::string>& onames,
1587 const Dict& opts)
const {
1593 aug_opts[i.first] = i.second;
1600 std::string aug_prefix =
"fsens" +
str(nfwd) +
"_";
1601 aug_opts[
"derivative_of"] =
self();
1602 aug_opts[
"nfwd"] = nfwd;
1603 aug_opts[
"nadj"] =
nadj_;
1608 std::vector<MX> ret_in;
1623 std::vector<MX> v(nfwd);
1625 for (casadi_int d = 0; d < nfwd; ++d) {
1627 aug_in[i].push_back(v[d]);
1629 ret_in.push_back(horzcat(v));
1636 if (
size1_in(i) > 0 && n_grid > 1) {
1638 std::vector<MX> ret_in_split = horzsplit_n(ret_in[i], n_grid);
1640 std::vector<std::vector<MX>> aug_in_split(nfwd);
1641 for (casadi_int d = 0; d < nfwd; ++d) {
1642 aug_in_split[d] = horzsplit_n(aug_in[i][d], n_grid);
1646 for (casadi_int k = 0; k < n_grid; ++k) {
1647 v.push_back(ret_in_split.at(k));
1648 for (casadi_int d = 0; d < nfwd; ++d) {
1649 v.push_back(aug_in_split[d].at(k));
1655 v.insert(v.begin(), ret_in[i]);
1658 for (
MX& e : v) e = vec(e);
1664 std::vector<MX> ret_out;
1669 std::vector<casadi_int> offset = {0};
1670 for (casadi_int k = 0; k < n_grid; ++k) {
1671 for (casadi_int d = 0; d <= nfwd; ++d) {
1672 offset.push_back(offset.back() +
size2_out(i) / n_grid);
1675 std::vector<MX> integrator_out_split = horzsplit(
1678 std::vector<MX> ret_out_split;
1679 ret_out_split.reserve(n_grid * nfwd);
1680 for (casadi_int d = 0; d < nfwd; ++d) {
1681 for (casadi_int k = 0; k < n_grid; ++k) {
1682 ret_out_split.push_back(integrator_out_split.at((nfwd + 1) * k + d + 1));
1685 ret_out.push_back(horzcat(ret_out_split));
1688 Dict options = opts;
1689 options[
"allow_duplicate_io_names"] =
true;
1691 options[
"jit"] =
false;
1694 return Function(name, ret_in, ret_out, inames, onames, options);
1698 const std::vector<std::string>& inames,
1699 const std::vector<std::string>& onames,
1700 const Dict& opts)
const {
1704 casadi_assert(
has_reverse(nadj),
"Event support not implemented for Integrator::get_reverse");
1709 aug_opts[i.first] = i.second;
1718 casadi_assert(na == 1 ||
nfwd_ == 0,
"Reverse mode of forward sensitivities of an integrator "
1719 "with several adjoint directions is not implemented");
1722 std::string aug_prefix =
"asens" +
str(nadj) +
"_";
1723 aug_opts[
"derivative_of"] =
self();
1726 aug_opts[
"nadj"] = nadj;
1727 aug_opts[
"nfwd"] = 0;
1730 aug_opts[
"nfwd"] = nadj * na;
1731 aug_opts[
"nadj"] =
nadj_;
1737 std::vector<MX> ret_in;
1752 std::vector<MX> v(nadj);
1754 for (casadi_int d=0; d<nadj; ++d) {
1756 aug_in[i].push_back(v[d]);
1758 ret_in.push_back(horzcat(v));
1769 std::vector<MX> ret_in_split;
1770 std::vector<std::vector<MX>> aug_in_split(nadj);
1774 ret_in_split = ret_in[i].size2() > 0 ? horzsplit_n(ret_in[i], n_grid)
1775 : std::vector<MX>(n_grid,
MX(
size1_in(i), 0));
1777 for (casadi_int d = 0; d < nadj; ++d) {
1778 aug_in_split[d] = horzsplit_n(aug_in[j][d], n_grid);
1782 ret_in_split = {ret_in[i]};
1783 for (casadi_int d = 0; d < nadj; ++d) aug_in_split[d] = {aug_in[j][d]};
1787 for (
auto&& e : ret_in_split) e = vec(e);
1788 for (
auto&& e1 : aug_in_split) {
1789 for (
auto&& e2 : e1) e2 = vec(e2);
1793 for (casadi_int k = 0; k < ret_in_split.size(); ++k) {
1794 v.push_back(ret_in_split.at(k));
1795 for (casadi_int d = 0; d < nadj; ++d) {
1797 v.push_back(aug_in_split[d].at(k));
1800 for (
const MX& e : vertsplit_n(aug_in_split[d].at(k), na)) v.push_back(e);
1803 casadi_int n =
numel_in(i) / n_grid, n_seed = aug_in_split[d].at(k).numel();
1804 v.push_back(vertcat(aug_in_split[d].at(k),
MX(n - n_seed, 1)));
1805 for (casadi_int a = 1; a < na; ++a) v.push_back(
MX(n, 1));
1814 std::vector<MX> ret_out;
1820 casadi_int n_dir = nadj * na, n_block = (na == 1 ?
numel_in(i) :
numel_out(j)) / n_grid;
1821 std::vector<casadi_int> offset = {0};
1822 for (casadi_int k = 0; k < n_grid; ++k) {
1823 offset.push_back(offset.back() +
numel_out(j) / n_grid);
1824 for (casadi_int d = 0; d < n_dir; ++d) {
1825 offset.push_back(offset.back() + n_block);
1828 std::vector<MX> integrator_out_split = vertsplit(vec(
integrator_out[j]), offset);
1830 std::vector<MX> ret_out_split;
1831 ret_out_split.reserve(n_grid * nadj);
1832 for (casadi_int d = 0; d < nadj; ++d) {
1833 for (casadi_int k = 0; k < n_grid; ++k) {
1835 auto block = [&](casadi_int a) ->
MX {
1836 return integrator_out_split.at((n_dir + 1) * k + d * na + a + 1);
1844 for (casadi_int a = 0; a < na; ++a) s += vertsplit_n(block(a), na).at(a);
1847 std::vector<MX> parts;
1848 for (casadi_int a = 0; a < na; ++a) parts.push_back(block(a));
1854 ret_out.push_back(horzcat(ret_out_split));
1857 Dict options = opts;
1858 options[
"allow_duplicate_io_names"] =
true;
1860 options[
"jit"] =
false;
1863 return Function(name, ret_in, ret_out, inames, onames, options);
1879 return blockcat(J, J12, J21, J22);
1900 return blockcat(J_xx, J_xz, J_zx, J_zz);
1920 return blockcat(J_xx, J_xz, J_zx, J_zz);
1925 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
1926 std::mutex Integrator::mutex_solvers_;
1932 double t0,
const std::vector<double>& tout) :
Integrator(name, dae, t0, tout) {
1944 {{
"number_of_finite_elements",
1946 "Target number of finite elements. "
1947 "The actual number may be higher to accommodate all output times"}},
1950 "Implement as MX Function (codegeneratable/serializable) default: false"}},
1951 {
"simplify_options",
1953 "Any options to pass to simplified form Function constructor"}}
1963 auto it = opts.find(
"simplify");
1964 if (it != opts.end())
simplify = it->second;
1973 std::vector<MX> F_in = F.
mx_in();
1984 double h = (
tout_.back() -
t0_)/
static_cast<double>(
disc_.back());
1991 std::vector<MX> F_out;
1993 for (casadi_int k=0; k<
disc_.back(); ++k) {
2012 auto it = opts.find(
"simplify_options");
2013 if (it!=opts.end())
update_dict(sopts, it->second);
2026 for (
auto&& op : opts) {
2027 if (op.first==
"number_of_finite_elements") {
2033 casadi_assert(
nk_target_ > 0,
"Number of finite elements must be strictly positive");
2042 for (
double t_next :
tout_) {
2043 disc_.push_back(
disc_.back() + std::ceil((t_next - t_cur) / h_target));
2076 casadi_int*& iw,
double*& w)
const {
2084 m->v_prev = w; w +=
nv_;
2085 m->q_prev = w; w +=
nq_;
2088 m->rv = w; w +=
nrv_;
2089 m->adj_u = w; w +=
nuq_;
2090 m->adj_p_prev = w; w +=
nrq_;
2091 m->adj_u_prev = w; w +=
nuq_;
2095 m->x_tape = w; w += (
disc_.back() + 1) *
nx_;
2096 m->v_tape = w; w +=
disc_.back() *
nv_;
2111 double* x_prev = m->
tmp1;
2114 casadi_int nj =
disc_[m->k + 1] -
disc_[m->k];
2115 double h = (m->t_next - m->t) / nj;
2118 for (casadi_int j = 0; j < nj; ++j) {
2120 double t = m->t + j * h;
2128 stepF(m, t, h, x_prev, m->v_prev, m->x, m->v, m->q);
2133 casadi_int tapeind =
disc_[m->k] + j;
2140 for (casadi_int d = 0; d <=
nfwd_; ++d) {
2148 double* adj_x,
double* adj_p,
double* adj_u)
const {
2155 casadi_int nj =
disc_[m->k + 1] -
disc_[m->k];
2156 double h = (m->t - m->t_next) / nj;
2159 for (casadi_int j = nj; j-- > 0; ) {
2161 double t = m->t_next + j * h;
2169 casadi_int tapeind =
disc_[m->k] + j;
2171 m->x_tape +
nx_ * tapeind, m->x_tape +
nx_ * (tapeind + 1),
2172 m->v_tape +
nv_ * tapeind,
2173 m->tmp1, m->rv, m->adj_x, m->adj_p, m->adj_u);
2186 const double* x0,
const double* v0,
double* xf,
double* vf,
double* qf)
const {
2219 const double* x0,
const double* xf,
const double* vf,
2220 const double* adj_xf,
const double* rv0,
2221 double* adj_x0,
double* adj_p,
double* adj_u)
const {
2296 casadi_fill(m->v,
nv_, std::numeric_limits<double>::quiet_NaN());
2321 const double* adj_x,
const double* adj_z,
const double* adj_q)
const {
2333 for (casadi_int d = 0; d <=
nfwd_; ++d) {
2334 casadi_axpy(nrz_per_block, 1., adj_z + d * nrz_per_block,
2335 m->rv + (d + 1) *
nrv1_ - nrz_per_block);
2340 const std::string& name,
const Function& dae,
double t0,
const std::vector<double>& tout)
2351 "An implicit function solver"}},
2352 {
"rootfinder_options",
2354 "Options to be passed to the NLP Solver"}}
2363 std::string implicit_function_name =
"newton";
2367 for (
auto&& op : opts) {
2368 if (op.first==
"rootfinder") {
2369 implicit_function_name = op.second.to_string();
2370 }
else if (op.first==
"rootfinder_options") {
2395 template<
typename XType>
2397 const std::map<std::string, XType>& d) {
2399 for (
auto&& i : d) {
2401 de_in[
DYN_T]=i.second;
2402 }
else if (i.first==
"x") {
2403 de_in[
DYN_X]=i.second;
2404 }
else if (i.first==
"z") {
2405 de_in[
DYN_Z]=i.second;
2406 }
else if (i.first==
"p") {
2407 de_in[
DYN_P]=i.second;
2408 }
else if (i.first==
"u") {
2409 de_in[
DYN_U]=i.second;
2410 }
else if (i.first==
"ode") {
2412 }
else if (i.first==
"alg") {
2414 }
else if (i.first==
"quad") {
2416 }
else if (i.first==
"zero") {
2419 casadi_error(
"No such field: " + i.first);
2424 for (casadi_int i = 0; i <
DYN_NUM_IN; ++i) {
2425 const Sparsity& sp = de_in[i].sparsity();
2427 casadi_assert(sp.
is_empty() || sp.
is_scalar(),
"DAE time variable must be empty or scalar. "
2428 "Got dimension " +
str(sp.
size()));
2430 casadi_assert(sp.
is_empty() || sp.
is_vector(),
"DAE inputs must be empty or vectors. "
2433 casadi_assert(sp.
is_dense(),
"DAE inputs must be dense . "
2434 +
dyn_in(i) +
" is sparse.");
2436 de_in[i] = vec(de_in[i]);
2441 const Sparsity& sp = de_out[i].sparsity();
2442 casadi_assert(sp.
is_empty() || sp.
is_vector(),
"DAE outputs must be empty or vectors. "
2445 de_out[i] = vec(densify(de_out[i]));
2459 s.
pack(
"Integrator::t0",
t0_);
2465 s.
pack(
"Integrator::nx",
nx_);
2466 s.
pack(
"Integrator::nz",
nz_);
2467 s.
pack(
"Integrator::nq",
nq_);
2481 s.
pack(
"Integrator::np",
np_);
2486 s.
pack(
"Integrator::nu",
nu_);
2489 s.
pack(
"Integrator::ne",
ne_);
2570 s.
version(
"FixedStepIntegrator", 3);
2572 s.
pack(
"FixedStepIntegrator::disc",
disc_);
2573 s.
pack(
"FixedStepIntegrator::nv",
nv_);
2574 s.
pack(
"FixedStepIntegrator::nv1",
nv1_);
2575 s.
pack(
"FixedStepIntegrator::nrv",
nrv_);
2576 s.
pack(
"FixedStepIntegrator::nrv1",
nrv1_);
2580 s.
version(
"FixedStepIntegrator", 3);
2583 s.
unpack(
"FixedStepIntegrator::nv",
nv_);
2592 s.
version(
"ImplicitFixedStepIntegrator", 2);
2597 s.
version(
"ImplicitFixedStepIntegrator", 2);
2634 if (
nu_ == 0 || u ==
nullptr)
return nt() - 1;
2636 for (; k + 1 <
nt(); ++k) {
2638 const double *u_next = u +
nu_;
2640 for (casadi_int i = 0; i <
nu_; ++i) {
2642 if (u[i] != u_next[i])
return k;
2686 double t_event = m->
t_stop;
2687 casadi_int event_index = -1;
2693 for (casadi_int i = 0; i <
ne_; ++i) {
2696 if (m->
e[i] > 0 && m->
edot[i] < 0) {
2698 double t = m->
t - m->
e[i] / m->
edot[i];
2708 if (event_index >= 0) {
2710 if (
verbose_) casadi_message(
"Projected zero crossing for index " +
str(event_index)
2711 +
" at t = " +
str(t_event));
2722 casadi_error(
"At t = " +
str(m->
t) +
": Too many event iterations during interval "
2726 if (*ind < 0 || m->event_triggered[*ind])
return 1;
2730 if (
verbose_) casadi_message(
"Zero crossing for index " +
str(*ind) +
" at t = " +
str(m->
t));
2754 for (casadi_int i = 0; i <
nfwd_; ++i) {
2758 for (casadi_int i = 0; i <
nfwd_; ++i) {
2765 double index = *ind;
2796 for (casadi_int i = 0; i <
nfwd_; ++i) {
2806 if (
nu_ == 0 || u ==
nullptr)
return -1;
2810 const double *u_next = u -
nu_;
2812 for (casadi_int i = 0; i <
nu_; ++i) {
2814 if (u[i] != u_next[i])
return k;
2825 if (v ==
nullptr || n == 0)
return true;
2827 for (casadi_int i = 0; i < n; ++i) {
2828 if (v[i] != 0.)
return false;
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
void version(const std::string &name, int v)
~FixedStepIntegrator() override
Destructor.
std::vector< casadi_int > disc_
static const Options options_
Options.
void init(const Dict &opts) override
Initialize stage.
void stepB(FixedStepMemory *m, double t, double h, const double *x0, const double *xf, const double *vf, const double *adj_xf, const double *rv0, double *adj_x0, double *adj_p, double *adj_u) const
Take integrator step backward.
int init_mem(void *mem) const override
Initalize memory block.
void stepF(FixedStepMemory *m, double t, double h, const double *x0, const double *v0, double *xf, double *vf, double *qf) const
Take integrator step forward.
void impulseB(IntegratorMemory *mem, const double *adj_x, const double *adj_z, const double *adj_q) const override
Introduce an impulse into the backwards integration at the current time.
void retreat(IntegratorMemory *mem, const double *u, double *adj_x, double *adj_p, double *adj_u) const override
Retreat solution in time.
void reset(IntegratorMemory *mem, bool first_call) const override
Reset the forward solver at the start or after an event.
casadi_int nv_
Number of dependent variables in the discrete time integration.
int advance_noevent(IntegratorMemory *mem) const override
Advance solution in time.
FixedStepIntegrator(const std::string &name, const Function &dae, double t0, const std::vector< double > &tout)
Constructor.
void resetB(IntegratorMemory *mem) const override
Reset the backward problem and take time to tf.
Function create_advanced(const Dict &opts) override
virtual void setup_step()=0
Setup step functions.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
casadi_int size1_in(casadi_int ind) const
Input/output dimensions.
void alloc_iw(size_t sz_iw, bool persistent=false)
Ensure required length of iw field.
virtual void call_forward(const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens, bool always_inline, bool never_inline) const
Forward mode AD, virtual functions overloaded in derived classes.
static std::string forward_name(const std::string &fcn, casadi_int nfwd)
Helper function: Get name of forward derivative function.
casadi_int numel_out() const
Number of input/output elements.
const Sparsity & sparsity_in(casadi_int ind) const
Input/output sparsity.
virtual void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const
Set the (persistent) work vectors.
casadi_int numel_in() const
Number of input/output elements.
size_t n_in_
Number of inputs and outputs.
casadi_int size2_out(casadi_int ind) const
Input/output dimensions.
casadi_int size1_out(casadi_int ind) const
Input/output dimensions.
std::pair< casadi_int, casadi_int > size_out(casadi_int ind) const
Input/output dimensions.
virtual int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
Propagate sparsity forward.
void serialize_type(SerializingStream &s) const override
Serialize type information.
const Sparsity & sparsity_out(casadi_int ind) const
Input/output sparsity.
virtual int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
Propagate sparsity backwards.
void alloc_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
void setup(void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
Set the (persistent and temporary) work vectors.
std::vector< bool > is_diff_in_
Are inputs and outputs differentiable?
static std::string reverse_name(const std::string &fcn, casadi_int nadj)
Helper function: Get name of adjoint derivative function.
casadi_int size2_in(casadi_int ind) const
Input/output dimensions.
casadi_int numel_in() const
Get the number of elements (rows times columns) of one input, or of all.
Function forward(casadi_int nfwd) const
Get a function computing nfwd forward directional derivatives.
casadi_int nnz_out() const
Get the number of structural nonzeros of one output, or of all outputs.
const MX mx_in(casadi_int ind) const
Create fresh symbols with the names and sparsity patterns of the inputs.
const Sparsity & sparsity_out(casadi_int ind) const
Get the sparsity pattern of an output, by index or name.
const std::string & name() const
Get the name given at construction ("null" for a null object)
casadi_int numel_out() const
Get the number of elements (rows times columns) of one output, or of all.
Function reverse(casadi_int nadj) const
Get a function computing nadj reverse (adjoint) directional derivatives.
static Function create(FunctionInternal *node)
Create from node.
std::vector< double > nominal_in(casadi_int ind) const
Get the nominal value of each nonzero of input ind.
const Sparsity & sparsity_in(casadi_int ind) const
Get the sparsity pattern of an input, by index or name.
casadi_int n_out() const
Get the number of function outputs.
casadi_int n_in() const
Get the number of function inputs.
std::vector< std::string > get_free() const
Get the names of the free variables; empty when there are none.
bool is_a(const std::string &type, bool recursive=true) const
Check whether the function is of a given class.
bool has_free() const
Check whether the outputs contain symbols that are not inputs.
std::pair< casadi_int, casadi_int > size_in(casadi_int ind) const
Get the shape of an input: rows, columns or both.
const std::vector< Sparsity > & jac_sparsity(bool compact=false) const
Get the sparsity patterns of all Jacobian blocks.
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
bool is_null() const
Is a null pointer?
~ImplicitFixedStepIntegrator() override
Destructor.
void init(const Dict &opts) override
Initialize stage.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
static const Options options_
Options.
ImplicitFixedStepIntegrator(const std::string &name, const Function &dae, double t0, const std::vector< double > &tout)
Constructor.
Internal storage for integrator related data.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
casadi_int nfwd_
Number of sensitivities.
void init(const Dict &opts) override
Initialize.
virtual void reset(IntegratorMemory *mem, bool first_call) const
Reset the forward solver at the start or after an event.
int eval(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const override
evaluate
static const Options options_
Options.
casadi_int n_grid_out(casadi_int i) const
Number of grid points for which an output is repeated.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
void set_z(IntegratorMemory *m, const double *z) const
virtual void resetB(IntegratorMemory *mem) const =0
Reset the backward problem.
void get_z(IntegratorMemory *m, double *z) const
~Integrator() override=0
Destructor.
void set_x(IntegratorMemory *m, const double *x) const
void serialize_type(SerializingStream &s) const override
Serialize type information.
casadi_int next_stopB(casadi_int k, const double *u) const
Find next stop time.
int advance(IntegratorMemory *m) const
Advance solution in time, with events handling.
Sparsity sp_jac_aug(const Sparsity &J, const Sparsity &J1) const
Helper function, get augmented system Jacobian.
static Function map2oracle(const std::string &name, const std::map< std::string, XType > &d)
Convert dictionary to Problem.
std::vector< double > nom_x_
Function rdae_
Backwards DAE function.
Integrator(const std::string &name, const Function &oracle, double t0, const std::vector< double > &tout)
Constructor.
Dict augmented_options_
Augmented user option.
Sparsity get_sparsity_in(casadi_int i) override
Sparsities of function inputs and outputs.
casadi_int nrx_
Number of states for the backward integration.
casadi_int max_events_
Maximum total number of events during the simulation.
Sparsity sp_jac_dae_
Sparsity pattern of the extended Jacobians.
void get_q(IntegratorMemory *m, double *q) const
int init_mem(void *mem) const override
Initalize memory block.
int predict_events(IntegratorMemory *m) const
Predict next event time.
casadi_int next_stop(casadi_int k, const double *u) const
Find next stop time.
int fdae_sp_reverse(SpReverseMem *m, bvec_t *x, bvec_t *p, bvec_t *u, bvec_t *ode, bvec_t *alg) const
Reverse sparsity pattern propagation through DAE, forward problem.
virtual MX algebraic_state_output(const MX &Z) const
bool has_reverse(casadi_int nadj) const override
Generate a function that calculates nadj adjoint derivatives.
int fquad_sp_forward(SpForwardMem *m, const bvec_t *x, const bvec_t *z, const bvec_t *p, const bvec_t *u, bvec_t *quad) const
Forward sparsity pattern propagation through quadratures, forward problem.
virtual void retreat(IntegratorMemory *mem, const double *u, double *adj_x, double *adj_p, double *adj_u) const =0
Retreat solution in time.
casadi_int np_
Number of forward and backward parameters.
casadi_int nt() const
Number of output times.
void set_u(IntegratorMemory *m, const double *u) const
bool print_stats_
Options.
casadi_int ntmp_
Length of the tmp1, tmp2 vectors.
virtual void impulseB(IntegratorMemory *mem, const double *adj_x, const double *adj_z, const double *adj_q) const =0
Introduce an impulse into the backwards integration at the current time.
int bquad_sp_reverse(SpReverseMem *m, bvec_t *x, bvec_t *z, bvec_t *p, bvec_t *u, bvec_t *adj_ode, bvec_t *adj_alg, bvec_t *adj_quad, bvec_t *adj_p, bvec_t *adj_u) const
Reverse sparsity pattern propagation through quadratures, backward problem.
std::vector< double > nom_z_
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const override
Propagate sparsity forward.
int bdae_sp_reverse(SpReverseMem *m, bvec_t *x, bvec_t *z, bvec_t *p, bvec_t *u, bvec_t *adj_ode, bvec_t *adj_quad, bvec_t *adj_x, bvec_t *adj_z) const
Reverse sparsity pattern propagation through DAE, backward problem.
static std::vector< std::string > quad_out()
IO conventions for continuous time dynamics.
Function get_forward(casadi_int nfwd, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const override
Generate a function that calculates nfwd forward derivatives.
virtual MX algebraic_state_init(const MX &x0, const MX &z0) const
void get_x(IntegratorMemory *m, double *x) const
virtual void print_stats(IntegratorMemory *mem) const
Print solver statistics.
virtual Function create_advanced(const Dict &opts)
Sparsity get_sparsity_out(casadi_int i) override
Sparsities of function inputs and outputs.
static std::vector< std::string > bquad_out()
IO conventions for continuous time dynamics.
Function augmented_dae() const
Generate the augmented DAE system.
int trigger_event(IntegratorMemory *m, casadi_int *ind) const
Trigger an event.
Dict opts_
Copy of the options.
static std::map< std::string, Plugin > solvers_
Collection of solvers.
static std::vector< std::string > bdyn_in()
IO conventions for continuous time dynamics.
int bquad_sp_forward(SpForwardMem *m, const bvec_t *x, const bvec_t *z, const bvec_t *p, const bvec_t *u, const bvec_t *adj_ode, const bvec_t *adj_alg, const bvec_t *adj_quad, bvec_t *adj_p, bvec_t *adj_u) const
Forward sparsity pattern propagation through quadratures, backward problem.
static bool all_zero(const double *v, casadi_int n)
Helper function: Vector has only zeros?
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
int fquad_sp_reverse(SpReverseMem *m, bvec_t *x, bvec_t *z, bvec_t *p, bvec_t *u, bvec_t *quad) const
Reverse sparsity pattern propagation through quadratures, forward problem.
std::vector< double > tout_
Output time grid.
double event_tol_
Termination tolerance for the event iteration.
void set_q(IntegratorMemory *m, const double *q) const
static std::vector< std::string > dae_out()
IO conventions for continuous time dynamics.
int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const override
Propagate sparsity backwards.
double event_acceptable_tol_
Acceptable tolerance for the event iteration.
virtual Dict getDerivativeOptions(bool fwd) const
Set solver specific options to generated augmented integrators.
virtual int advance_noevent(IntegratorMemory *mem) const =0
Advance solution in time, without events handling.
Function get_reverse(casadi_int nadj, const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const override
Generate a function that calculates nadj adjoint derivatives.
Function transition_
Function to be called at state events.
static std::vector< std::string > bdae_out()
IO conventions for continuous time dynamics.
Sparsity sp_jac_rdae()
Create sparsity pattern of the extended Jacobian (backward problem)
casadi_int max_event_iter_
Maximum number of event iterations for a single event.
Function get_forward_dae(const std::string &name) const
Generate the augmented DAE system.
static const std::string infix_
Infix.
casadi_int nu_
Number of controls.
casadi_int nx_
Number of states for the forward integration.
Sparsity sp_jac_dae()
Create sparsity pattern of the extended Jacobian (forward problem)
casadi_int n_grid_in(casadi_int i) const
Number of grid points for which an input is repeated: output times or columns of u.
int calc_edot(IntegratorMemory *m) const
Linearize the zero crossing function.
static std::vector< std::string > bdyn_out()
IO conventions for continuous time dynamics.
int fdae_sp_forward(SpForwardMem *m, const bvec_t *x, const bvec_t *p, const bvec_t *u, bvec_t *ode, bvec_t *alg) const
Forward sparsity pattern propagation through DAE, forward problem.
int bdae_sp_forward(SpForwardMem *m, const bvec_t *x, const bvec_t *z, const bvec_t *p, const bvec_t *u, const bvec_t *adj_ode, const bvec_t *adj_quad, bvec_t *adj_x, bvec_t *adj_z) const
Forward sparsity pattern propagation through DAE, backward problem.
casadi_int ne_
Number of of zero-crossing functions.
void set_p(IntegratorMemory *m, const double *p) const
static casadi_int adjmap_out(casadi_int i)
Which output is used to calculate a given input in adjoint sensitivity analysis.
Base class for functions that perform calculation with an oracle.
void set_function(const Function &fcn, const std::string &fname, bool jit=false)
Function oracle_
Oracle: Used to generate other functions.
int calc_sp_forward(const std::string &fcn, const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
Function create_function(const Function &oracle, const std::string &fname, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux=Function::AuxOut(), const Dict &opts=Dict())
void join_results(OracleMemory *m) const
Combine results from different threads.
void init(const Dict &opts) override
Function create_forward(const std::string &fname, casadi_int nfwd)
int init_mem(void *mem) const override
Initalize memory block.
int calc_function(OracleMemory *m, const std::string &fcn, const double *const *arg=nullptr, int thread_id=0) const
std::vector< std::string > get_function() const override
Get list of dependency functions.
bool has_function(const std::string &fname) const override
static const Options options_
Options.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
int calc_sp_reverse(const std::string &fcn, bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
static bool has_plugin(const std::string &pname, bool verbose=false)
Check if a plugin is available or can be loaded.
void serialize_type(SerializingStream &s) const
Serialize type information.
static Plugin & getPlugin(const std::string &pname)
Load and get the creator function.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
virtual const char * plugin_name() const=0
static Plugin load_plugin(const std::string &pname, bool register_plugin=true, bool needs_lock=true)
Load a plugin dynamically.
Base class for FunctionInternal and LinsolInternal.
bool verbose_
Verbose printout.
void clear_mem()
Clear all memory (called from destructor)
Helper class for Serialization.
void version(const std::string &name, int v)
void pack(const Sparsity &e)
Serializes an object to the output stream.
bool is_vector() const
Check whether the pattern is a row or a column vector.
casadi_int size1() const
Number of rows.
static Sparsity diag(casadi_int nrow)
Create a diagonal sparsity pattern.
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern.
void spsolve(bvec_t *X, bvec_t *B, bool tr) const
Propagate sparsity through a linear solve.
bool is_scalar(bool scalar_and_dense=false) const
Check whether the pattern is 1-by-1.
casadi_int size2() const
Number of columns.
std::pair< casadi_int, casadi_int > size() const
Shape as a pair (number of rows, number of columns)
bool is_empty(bool both=false) const
Check whether the pattern has a zero dimension.
bool is_singular() const
Check whether a square pattern is structurally singular.
bool is_dense() const
Check whether every entry is a structural nonzero, i.e. nnz() == numel()
std::vector< std::string > dyn_out()
Get the output scheme of a DAE function.
std::vector< std::string > event_in()
Get the input scheme of an event transition function.
bool has_integrator(const std::string &name)
Check if an integrator plugin is available.
std::vector< std::string > dyn_in()
Get the input scheme of a DAE function.
casadi_int integrator_n_out()
Get the number of integrator outputs.
casadi_int dyn_n_in()
Get the number of inputs of a DAE function.
std::vector< std::string > integrator_out()
Get the output scheme of integrators.
std::vector< std::string > event_out()
Get the output scheme of an event transition function.
void load_integrator(const std::string &name)
Explicitly load an integrator plugin.
casadi_int integrator_n_in()
Get the number of integrator inputs.
std::vector< std::string > integrator_in()
Get the input scheme of integrators.
Function integrator(const std::string &name, const std::string &solver, const SXDict &dae, const Dict &opts)
std::string doc_integrator(const std::string &name)
Get the documentation string of an integrator plugin.
casadi_int dyn_n_out()
Get the number of outputs of a DAE function.
std::vector< std::string > rootfinder_options(const std::string &name)
Get all options of a rootfinder plugin.
Function rootfinder(const std::string &name, const std::string &solver, const SXDict &rfp, const Dict &opts)
std::map< std::string, MX > MXDict
@ STEP_NUM_IN
Number of arguments.
@ STEP_V0
Dependent variables.
IntegratorOutput
Output arguments of an integrator.
@ INTEGRATOR_ADJ_U
Adjoint sensitivities corresponding to the control vector.
@ INTEGRATOR_ADJ_Z0
Adjoint sensitivities corresponding to the algebraic variable guess.
@ INTEGRATOR_QF
Quadrature state at all output times.
@ INTEGRATOR_ADJ_P
Adjoint sensitivities corresponding to the parameter vector.
@ INTEGRATOR_ZF
Algebraic variable at all output times.
@ INTEGRATOR_XF
Differential state at all output times.
@ INTEGRATOR_NUM_OUT
Number of output arguments of an integrator.
@ INTEGRATOR_ADJ_X0
Adjoint sensitivities corresponding to the initial state.
IntegratorInput
Input arguments of an integrator.
@ INTEGRATOR_U
Piecewise constant control, a new control interval starts at each output time.
@ INTEGRATOR_ADJ_QF
Adjoint seeds corresponding to the quadratures at the output times.
@ INTEGRATOR_ADJ_ZF
Adjoint seeds corresponding to the algebraic variables at the output times.
@ INTEGRATOR_P
Parameters.
@ INTEGRATOR_ADJ_XF
Adjoint seeds corresponding to the states at the output times.
@ INTEGRATOR_Z0
Initial guess for the algebraic variable at the initial time.
@ INTEGRATOR_NUM_IN
Number of input arguments of an integrator.
@ INTEGRATOR_X0
Differential state at the initial time.
unsigned long long bvec_t
@ STEP_XF
State vector at next time.
@ STEP_QF
Quadrature state contribution.
@ STEP_VF
Dependent variables at next time.
@ STEP_NUM_OUT
Number of arguments.
EventIn
Inputs of an event transition function.
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.
DynIn
Inputs of the symbolic representation of the DAE.
EventOut
Outputs of an event transition function.
void casadi_fill(T1 *x, casadi_int n, T1 alpha)
FILL: x <- alpha.
std::map< std::string, SX > SXDict
std::string str(const T &v)
String representation, any type.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
DynOut
Outputs of the symbolic representation of the DAE.
void update_dict(Dict &target, const Dict &source, bool recurse)
Update the target dictionary in place with source elements.
std::string to_string(TypeFmi2 v)
void casadi_axpy(casadi_int n, T1 alpha, const T1 *x, T1 *y)
AXPY: y <- a*x + y.
void casadi_clear(T1 *x, casadi_int n)
CLEAR: x <- 0.
double simplify(double x)
casadi_int * event_triggered
Options metadata for a class.
Memory struct, forward sparsity pattern propagation.
Memory struct, backward sparsity pattern propagation.