List of all members | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes
casadi::CvodesInterface Class Reference

'cvodes' plugin for Integrator More...

#include <cvodes_interface.hpp>

Detailed Description

Interface to CVodes from the Sundials suite.

A call to evaluate will integrate to the end.

You can retrieve the entire state trajectory as follows, after the evaluate call: Call reset. Then call integrate(t_i) and getOuput for a series of times t_i.

Extra doc: https://github.com/casadi/casadi/wiki/L_228


List of available options
IdTypeDescription
abstolOT_DOUBLEAbsolute tolerence for the IVP solution
always_recalculate_jacobianOT_BOOLRecalculate Jacobian before factorizations, even if Jacobian is current [default: true]
disable_internal_warningsOT_BOOLDisable SUNDIALS internal warning messages
fsens_all_at_onceOT_BOOLCalculate all right hand sides of the sensitivity equations at once
fsens_err_conOT_BOOLinclude the forward sensitivities in all error controls
interpolation_typeOT_STRINGType of interpolation for the adjoint sensitivities
linear_multistep_methodOT_STRINGIntegrator scheme: BDF|adams
linear_solverOT_STRINGA custom linear solver creator function [default: qr]
linear_solver_optionsOT_DICTOptions to be passed to the linear solver
max_krylovOT_INTMaximum Krylov subspace size
max_multistep_orderOT_INTMaximum order for the (variable-order) multistep method
max_num_stepsOT_INTMaximum number of integrator steps
max_orderOT_DOUBLEMaximum order
max_step_sizeOT_DOUBLEMax step size [default: 0/inf]
min_step_sizeOT_DOUBLEMin step size [default: 0/0.0]
newton_schemeOT_STRINGLinear solver scheme in the Newton method: DIRECT|gmres|bcgstab|tfqmr
nonlin_conv_coeffOT_DOUBLECoefficient in the nonlinear convergence test
nonlinear_solver_iterationOT_STRINGNonlinear solver type: NEWTON|functional
quad_err_conOT_BOOLShould the quadratures affect the step size control
reltolOT_DOUBLERelative tolerence for the IVP solution
scale_abstolOT_BOOLScale absolute tolerance by nominal value
second_order_correctionOT_BOOLSecond order correction in the augmented system Jacobian [true]
sensitivity_methodOT_STRINGSensitivity method: SIMULTANEOUS|staggered
step0OT_DOUBLEinitial step size [default: 0/estimated]
steps_per_checkpointOT_INTNumber of steps between two consecutive checkpoints
stop_at_endOT_BOOL[DEPRECATED] Stop the integrator at the end of the interval
use_preconditionerOT_BOOLPrecondition the iterative solver [default: true]


Input scheme: casadi::IntegratorInput (INTEGRATOR_NUM_IN = 7)
Full nameShortDescription
INTEGRATOR_X0x0Differential state at the initial time.
INTEGRATOR_Z0z0Initial guess for the algebraic variable at the initial time.
INTEGRATOR_PpParameters.
INTEGRATOR_UuPiecewise constant control, a new control interval starts at each output time.
INTEGRATOR_ADJ_XFadj_xfAdjoint seeds corresponding to the states at the output times.
INTEGRATOR_ADJ_ZFadj_zfAdjoint seeds corresponding to the algebraic variables at the output times.
INTEGRATOR_ADJ_QFadj_qfAdjoint seeds corresponding to the quadratures at the output times.

Output scheme: casadi::IntegratorOutput (INTEGRATOR_NUM_OUT = 7)
Full nameShortDescription
INTEGRATOR_XFxfDifferential state at all output times.
INTEGRATOR_ZFzfAlgebraic variable at all output times.
INTEGRATOR_QFqfQuadrature state at all output times.
INTEGRATOR_ADJ_X0adj_x0Adjoint sensitivities corresponding to the initial state.
INTEGRATOR_ADJ_Z0adj_z0Adjoint sensitivities corresponding to the algebraic variable guess.
INTEGRATOR_ADJ_Padj_pAdjoint sensitivities corresponding to the parameter vector.
INTEGRATOR_ADJ_Uadj_uAdjoint sensitivities corresponding to the control vector.


List of available options
IdTypeDescriptionUsed in
abstolOT_DOUBLEAbsolute tolerence for the IVP solutioncasadi::SundialsInterface
ad_weightOT_DOUBLEWeighting factor for derivative calculation.When there is an option of either using forward or reverse mode directional derivatives, the condition ad_weight*nf<=(1-ad_weight)*na is used where nf and na are estimates of the number of forward/reverse mode directional derivatives needed. By default, ad_weight is calculated automatically, but this can be overridden by setting this option. In particular, 0 means forcing forward mode and 1 forcing reverse mode. Leave unset for (class specific) heuristics.casadi::FunctionInternal
ad_weight_spOT_DOUBLEWeighting factor for sparsity pattern calculation calculation.Overrides default behavior. Set to 0 and 1 to force forward and reverse mode respectively. Cf. option "ad_weight". When set to -1, sparsity is completely ignored and dense matrices are used.casadi::FunctionInternal
always_inlineOT_BOOLForce inlining.casadi::FunctionInternal
always_recalculate_jacobianOT_BOOLRecalculate Jacobian before factorizations, even if Jacobian is current [default: true]casadi::CvodesInterface
augmented_optionsOT_DICTOptions to be passed down to the augmented integrator, if one is constructedcasadi::Integrator
cacheOT_DICTPrepopulate the function cache. Default: emptycasadi::FunctionInternal
common_optionsOT_DICTOptions for auto-generated functionscasadi::OracleFunction
compilerOT_STRINGJust-in-time compiler plugin to be used.casadi::FunctionInternal
custom_jacobianOT_FUNCTIONOverride CasADi's AD. Use together with 'jac_penalty': 0. Note: Highly experimental. Syntax may break often.casadi::FunctionInternal
der_optionsOT_DICTDefault options to be used to populate forward_options, reverse_options, and jacobian_options before those options are merged in.casadi::FunctionInternal
derivative_ofOT_FUNCTIONThe function is a derivative of another function. The type of derivative (directional derivative, Jacobian) is inferred from the function name.casadi::FunctionInternal
disable_internal_warningsOT_BOOLDisable SUNDIALS internal warning messagescasadi::SundialsInterface
dumpOT_BOOLDump function to file upon first evaluation. [false]casadi::FunctionInternal
dump_dirOT_STRINGDirectory to dump inputs/outputs to. Make sure the directory exists [.]casadi::FunctionInternal
dump_formatOT_STRINGChoose file format to dump matrices. See DM.from_file [mtx]casadi::FunctionInternal
dump_inOT_BOOLDump numerical values of inputs to file (readable with DM.from_file) [default: false] A counter is used to generate unique names. The counter may be reset using reset_dump_count.casadi::FunctionInternal
dump_outOT_BOOLDump numerical values of outputs to file (readable with DM.from_file) [default: false] A counter is used to generate unique names. The counter may be reset using reset_dump_count.casadi::FunctionInternal
enable_fdOT_BOOLEnable derivative calculation by finite differencing. [default: false]]casadi::FunctionInternal
enable_forwardOT_BOOLEnable derivative calculation using generated functions for Jacobian-times-vector products - typically using forward mode AD - if available. [default: true]casadi::FunctionInternal
enable_jacobianOT_BOOLEnable derivative calculation using generated functions for Jacobians of all differentiable outputs with respect to all differentiable inputs - if available. [default: true]casadi::FunctionInternal
enable_reverseOT_BOOLEnable derivative calculation using generated functions for transposed Jacobian-times-vector products - typically using reverse mode AD - if available. [default: true]casadi::FunctionInternal
error_on_failOT_BOOLThrow exceptions when function evaluation fails (default true).casadi::ProtoFunction
event_tolOT_DOUBLETermination tolerance for the event iterationcasadi::Integrator
expandOT_BOOLReplace MX with SX expressions in problem formulation [false] This happens before creating derivatives unless indicated by postpone_expandcasadi::OracleFunction
external_transformOT_VECTORVECTORList of external_transform instruction arguments. Default: emptycasadi::FunctionInternal
fd_methodOT_STRINGMethod for finite differencing [default 'central']casadi::FunctionInternal
fd_optionsOT_DICTOptions to be passed to the finite difference instancecasadi::FunctionInternal
forward_optionsOT_DICTOptions to be passed to a forward mode constructorcasadi::FunctionInternal
fsens_all_at_onceOT_BOOLCalculate all right hand sides of the sensitivity equations at oncecasadi::CvodesInterface
fsens_err_conOT_BOOLinclude the forward sensitivities in all error controlscasadi::SundialsInterface
gather_statsOT_BOOLDeprecated option (ignored): Statistics are now always collected.casadi::FunctionInternal
gridOT_DOUBLEVECTOR[DEPRECATED] Time gridcasadi::Integrator
inputs_checkOT_BOOLThrow exceptions when the numerical values of the inputs don't make sensecasadi::FunctionInternal
interpolation_typeOT_STRINGType of interpolation for the adjoint sensitivitiescasadi::SundialsInterface
is_diff_inOT_BOOLVECTORIndicate for each input if it should be differentiable.casadi::FunctionInternal
is_diff_outOT_BOOLVECTORIndicate for each output if it should be differentiable.casadi::FunctionInternal
jac_penaltyOT_DOUBLEWhen requested for a number of forward/reverse directions, it may be cheaper to compute first the full jacobian and then multiply with seeds, rather than obtain the requested directions in a straightforward manner. Casadi uses a heuristic to decide which is cheaper. A high value of 'jac_penalty' makes it less likely for the heurstic to chose the full Jacobian strategy. The special value -1 indicates never to use the full Jacobian strategycasadi::FunctionInternal
jacobian_optionsOT_DICTOptions to be passed to a Jacobian constructorcasadi::FunctionInternal
jitOT_BOOLUse just-in-time compiler to speed up the evaluationcasadi::FunctionInternal
jit_cleanupOT_BOOLCleanup up the temporary source file that jit creates. Default: truecasadi::FunctionInternal
jit_nameOT_STRINGThe file name used to write out code. The actual file names used depend on 'jit_temp_suffix' and include extensions. Default: 'jit_tmp'casadi::FunctionInternal
jit_optionsOT_DICTOptions to be passed to the jit compiler.casadi::FunctionInternal
jit_serializeOT_STRINGSpecify behaviour when serializing a jitted function: SOURCE|link|embed.casadi::FunctionInternal
jit_temp_suffixOT_BOOLUse a temporary (seemingly random) filename suffix for generated code and libraries. This is desired for thread-safety. This behaviour may defeat caching compiler wrappers. Default: truecasadi::FunctionInternal
linear_multistep_methodOT_STRINGIntegrator scheme: BDF|adamscasadi::CvodesInterface
linear_solverOT_STRINGA custom linear solver creator function [default: qr]casadi::SundialsInterface
linear_solver_optionsOT_DICTOptions to be passed to the linear solvercasadi::SundialsInterface
max_event_iterOT_INTMaximum number of iterations to zero in on a single eventcasadi::Integrator
max_eventsOT_INTMaximum total number of eventscasadi::Integrator
max_ioOT_INTAcceptable number of inputs and outputs. Warn if exceeded.casadi::FunctionInternal
max_krylovOT_INTMaximum Krylov subspace sizecasadi::SundialsInterface
max_multistep_orderOT_INTMaximum order for the (variable-order) multistep methodcasadi::SundialsInterface
max_num_dirOT_INTSpecify the maximum number of directions for derivative functions. Overrules the builtin optimized_num_dir.casadi::FunctionInternal
max_num_stepsOT_INTMaximum number of integrator stepscasadi::SundialsInterface
max_orderOT_DOUBLEMaximum ordercasadi::SundialsInterface
max_step_sizeOT_DOUBLEMax step size [default: 0/inf]casadi::SundialsInterface
min_step_sizeOT_DOUBLEMin step size [default: 0/0.0]casadi::CvodesInterface
monitorOT_STRINGVECTORSet of user problem functions to be monitoredcasadi::OracleFunction
nadjOT_INTNumber of adjoint sensitivities to be calculated [0]casadi::Integrator
never_inlineOT_BOOLForbid inlining.casadi::FunctionInternal
newton_schemeOT_STRINGLinear solver scheme in the Newton method: DIRECT|gmres|bcgstab|tfqmrcasadi::SundialsInterface
nfwdOT_INTNumber of forward sensitivities to be calculated [0]casadi::Integrator
nonlin_conv_coeffOT_DOUBLECoefficient in the nonlinear convergence testcasadi::SundialsInterface
nonlinear_solver_iterationOT_STRINGNonlinear solver type: NEWTON|functionalcasadi::CvodesInterface
number_of_finite_elementsOT_INTTarget number of finite elements. The actual number may be higher to accommodate all output timescasadi::Integrator
output_t0OT_BOOL[DEPRECATED] Output the state at the initial timecasadi::Integrator
post_expandOT_BOOLAfter construction, expand this Function. Default: Falsecasadi::FunctionInternal
post_expand_optionsOT_DICTOptions to be passed to post-construction expansion. Default: emptycasadi::FunctionInternal
postpone_expandOT_BOOLWhen expand is active, postpone it until after creation of derivatives. Default: Falsecasadi::OracleFunction
print_canonicalOT_BOOLWhen printing numerical matrices, use a format that is exact and reproducible in generated C code.casadi::FunctionInternal
print_inOT_BOOLPrint numerical values of inputs [default: false]casadi::FunctionInternal
print_outOT_BOOLPrint numerical values of outputs [default: false]casadi::FunctionInternal
print_statsOT_BOOLPrint out statistics after integrationcasadi::Integrator
print_timeOT_BOOLprint information about execution time. Implies record_time.casadi::ProtoFunction
quad_err_conOT_BOOLShould the quadratures affect the step size controlcasadi::SundialsInterface
record_timeOT_BOOLrecord information about execution time, for retrieval with stats().casadi::ProtoFunction
regularity_checkOT_BOOLThrow exceptions when NaN or Inf appears during evaluationcasadi::ProtoFunction
reltolOT_DOUBLERelative tolerence for the IVP solutioncasadi::SundialsInterface
reverse_optionsOT_DICTOptions to be passed to a reverse mode constructorcasadi::FunctionInternal
rootfinderOT_STRINGAn implicit function solvercasadi::Integrator
rootfinder_optionsOT_DICTOptions to be passed to the NLP Solvercasadi::Integrator
scale_abstolOT_BOOLScale absolute tolerance by nominal valuecasadi::SundialsInterface
second_order_correctionOT_BOOLSecond order correction in the augmented system Jacobian [true]casadi::SundialsInterface
sensitivity_methodOT_STRINGSensitivity method: SIMULTANEOUS|staggeredcasadi::SundialsInterface
show_eval_warningsOT_BOOLShow warnings generated from function evaluations [true]casadi::OracleFunction
simplifyOT_BOOLImplement as MX Function (codegeneratable/serializable) default: falsecasadi::Integrator
simplify_optionsOT_DICTAny options to pass to simplified form Function constructorcasadi::Integrator
specific_optionsOT_DICTOptions for specific auto-generated functions, overwriting the defaults from common_options. Nested dictionary.casadi::OracleFunction
step0OT_DOUBLEinitial step size [default: 0/estimated]casadi::SundialsInterface
steps_per_checkpointOT_INTNumber of steps between two consecutive checkpointscasadi::SundialsInterface
stop_at_endOT_BOOL[DEPRECATED] Stop the integrator at the end of the intervalcasadi::SundialsInterface
t0OT_DOUBLE[DEPRECATED] Beginning of the time horizoncasadi::Integrator
tfOT_DOUBLE[DEPRECATED] End of the time horizoncasadi::Integrator
transitionOT_FUNCTIONFunction to be called a zero-crossing eventscasadi::Integrator
use_preconditionerOT_BOOLPrecondition the iterative solver [default: true]casadi::SundialsInterface
user_dataOT_VOIDPTRA user-defined field that can be used to identify the function or pass additional informationcasadi::FunctionInternal
verboseOT_BOOLVerbose evaluation – for debuggingcasadi::ProtoFunction

Definition at line 87 of file cvodes_interface.hpp.

Inheritance diagram for casadi::CvodesInterface:
Inheritance graph
[legend]
Collaboration diagram for casadi::CvodesInterface:
Collaboration graph
[legend]

Public Types

enum  NewtonScheme { SD_DIRECT , SD_GMRES , SD_BCGSTAB , SD_TFQMR }
 Supported iterative solvers in Sundials. More...
 
enum  InterpType { SD_POLYNOMIAL , SD_HERMITE }
 
typedef Integrator *(* Creator) (const std::string &name, const Function &oracle, double t0, const std::vector< double > &tout)
 
using weak_ref_type = WeakRefInternal
 
typedef int(* RegFcn) (Plugin *plugin)
 
enum  JtimesFIn {
  JTIMESF_T , JTIMESF_X , JTIMESF_Z , JTIMESF_P ,
  JTIMESF_U , JTIMESF_FWD_X , JTIMESF_FWD_Z , JTIMESF_NUM_IN
}
 IO conventions for continuous time dynamics. More...
 
enum  JtimesFOut { JTIMESF_FWD_ODE , JTIMESF_FWD_ALG , JTIMESF_NUM_OUT }
 IO conventions for continuous time dynamics. More...
 
enum  JacFOut {
  JACF_ODE_X , JACF_ALG_X , JACF_ODE_Z , JACF_ALG_Z ,
  JACF_NUM_OUT
}
 IO conventions for continuous time dynamics. More...
 

Public Member Functions

 CvodesInterface (const std::string &name, const Function &dae, double t0, const std::vector< double > &tout)
 Constructor. More...
 
 ~CvodesInterface () override
 Destructor. More...
 
const char * plugin_name () const override
 
std::string class_name () const override
 Readable name of the internal class. More...
 
void init (const Dict &opts) override
 Initialize stage. More...
 
void * alloc_mem () const override
 Create memory block. More...
 
int init_mem (void *mem) const override
 Initalize memory block. More...
 
void free_mem (void *mem) const override
 Free memory block. More...
 
void reset (IntegratorMemory *mem, bool first_call) const override
 Reset the forward solver at the start or after an event. More...
 
int advance_noevent (IntegratorMemory *mem) const override
 Advance solution in time. More...
 
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. More...
 
void retreat (IntegratorMemory *mem, const double *u, double *adj_x, double *adj_p, double *adj_u) const override
 Retreat solution in time. More...
 
void serialize_body (SerializingStream &s) const override
 Serialize an object without type information. More...
 
void set_work (void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
 Set the (persistent) work vectors. More...
 
double get_reltol () const override
 Get relative tolerance. More...
 
double get_abstol () const override
 Get absolute tolerance. More...
 
int calc_daeF (SundialsMemory *m, double t, const double *x, const double *z, double *ode, double *alg) const
 
int calc_daeB (SundialsMemory *m, double t, const double *x, const double *z, const double *adj_ode, const double *adj_alg, const double *adj_quad, double *adj_x, double *adj_z) const
 
int calc_quadF (SundialsMemory *m, double t, const double *x, const double *z, double *quad) const
 
int calc_quadB (SundialsMemory *m, double t, const double *x, const double *z, const double *adj_ode, const double *adj_alg, double *adj_p, double *adj_u) const
 
int calc_jtimesF (SundialsMemory *m, double t, const double *x, const double *z, const double *fwd_x, const double *fwd_z, double *fwd_ode, double *fwd_alg) const
 
int calc_jacF (SundialsMemory *m, double t, const double *x, const double *z, double *jac_ode_x, double *jac_alg_x, double *jac_ode_z, double *jac_alg_z) const
 
Dict get_stats (void *mem) const override
 Get all statistics. More...
 
void print_stats (IntegratorMemory *mem) const override
 Print solver statistics. More...
 
void resetB (IntegratorMemory *mem) const override
 Reset the backward problem and take time to tf. More...
 
void reset_stats (SundialsMemory *m) const
 Reset stats. More...
 
void save_offsets (SundialsMemory *m) const
 Save stats offsets before reset. More...
 
void add_offsets (SundialsMemory *m) const
 Add stats offsets to stats. More...
 
virtual Function create_advanced (const Dict &opts)
 
virtual MX algebraic_state_init (const MX &x0, const MX &z0) const
 
virtual MX algebraic_state_output (const MX &Z) const
 
void set_q (IntegratorMemory *m, const double *q) const
 
void set_x (IntegratorMemory *m, const double *x) const
 
void set_z (IntegratorMemory *m, const double *z) const
 
void set_p (IntegratorMemory *m, const double *p) const
 
void set_u (IntegratorMemory *m, const double *u) const
 
void get_q (IntegratorMemory *m, double *q) const
 
void get_x (IntegratorMemory *m, double *x) const
 
void get_z (IntegratorMemory *m, double *z) const
 
casadi_int next_stop (casadi_int k, const double *u) const
 Find next stop time. More...
 
int calc_edot (IntegratorMemory *m) const
 Linearize the zero crossing function. More...
 
int predict_events (IntegratorMemory *m) const
 Predict next event time. More...
 
int trigger_event (IntegratorMemory *m, casadi_int *ind) const
 Trigger an event. More...
 
int advance (IntegratorMemory *m) const
 Advance solution in time, with events handling. More...
 
casadi_int next_stopB (casadi_int k, const double *u) const
 Find next stop time. More...
 
int eval (const double **arg, double **res, casadi_int *iw, double *w, void *mem) const override
 evaluate More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int sp_forward (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const override
 Propagate sparsity forward. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int sp_reverse (bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const override
 Propagate sparsity backwards. More...
 
virtual Dict getDerivativeOptions (bool fwd) const
 Set solver specific options to generated augmented integrators. More...
 
Sparsity sp_jac_aug (const Sparsity &J, const Sparsity &J1) const
 Helper function, get augmented system Jacobian. More...
 
Sparsity sp_jac_dae ()
 Create sparsity pattern of the extended Jacobian (forward problem) More...
 
Sparsity sp_jac_rdae ()
 Create sparsity pattern of the extended Jacobian (backward problem) More...
 
casadi_int nt () const
 Number of output times. More...
 
void serialize_type (SerializingStream &s) const override
 Serialize type information. More...
 
std::string serialize_base_function () const override
 String used to identify the immediate FunctionInternal subclass. More...
 
void finalize () override
 Finalize initialization. More...
 
void join_results (OracleMemory *m) const
 Combine results from different threads. More...
 
const Functionoracle () const override
 Get oracle. More...
 
void expand ()
 
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())
 
Function create_function (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())
 
Function create_function (const std::string &fname, const std::vector< MX > &e_in, const std::vector< MX > &e_out, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Dict &opts=Dict())
 
Function create_forward (const std::string &fname, casadi_int nfwd)
 
void set_function (const Function &fcn, const std::string &fname, bool jit=false)
 
void set_function (const Function &fcn)
 
int calc_function (OracleMemory *m, const std::string &fcn, const double *const *arg=nullptr, int thread_id=0) const
 
int calc_sp_forward (const std::string &fcn, const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
 
int calc_sp_reverse (const std::string &fcn, bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
 
std::vector< std::string > get_function () const override
 Get list of dependency functions. More...
 
const Functionget_function (const std::string &name) const override
 
void find (std::map< FunctionInternal *, std::pair< Function, size_t > > &all_fun, casadi_int max_depth) const override
 
virtual bool monitored (const std::string &name) const
 
bool has_function (const std::string &fname) const override
 
std::string generate_dependencies (const std::string &fname, const Dict &opts) const override
 Export / Generate C code for the generated functions. More...
 
void jit_dependencies (const std::string &fname) override
 JIT for dependencies. More...
 
int local_init_mem (void *mem) const
 Initalize memory block. More...
 
void set_temp (void *mem, const double **arg, double **res, casadi_int *iw, double *w) const override
 Set the work vectors. More...
 
virtual void codegen_body_enter (CodeGenerator &g) const
 Generate code for the function body. More...
 
virtual void codegen_body_exit (CodeGenerator &g) const
 Generate code for the function body. More...
 
virtual std::string getAdaptorSolverName () const
 Obtain solver name from Adaptor. More...
 
Dict generate_options (const std::string &target) const override
 Reconstruct options dict. More...
 
void change_option (const std::string &option_name, const GenericType &option_value) override
 Change option after object creation for debugging. More...
 
void reset_dump_count ()
 Reset the counter used to name dump files. More...
 
Function self () const
 Get a public class instance. More...
 
virtual Function factory (const std::string &name, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux, const Dict &opts) const
 
void add_embedded (std::map< FunctionInternal *, std::pair< Function, size_t > > &all_fun, const Function &dep, casadi_int max_depth) const
 
virtual std::vector< bool > which_depends (const std::string &s_in, const std::vector< std::string > &s_out, casadi_int order, bool tr=false) const
 Which variables enter with some order. More...
 
virtual Function simplify_passes (const std::vector< std::pair< std::string, casadi_int > > &tasks) const
 Apply an ordered list of simplify passes (used by transform) More...
 
virtual int eval_sx (const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate with symbolic scalars. More...
 
virtual void eval_mx (const MXVector &arg, MXVector &res, bool always_inline, bool never_inline) const
 Evaluate with symbolic matrices. More...
 
template<typename M >
void call (const std::vector< M > &arg, std::vector< M > &res, bool always_inline, bool never_inline) const
 Call a function, templated. More...
 
template<typename M >
bool matching_arg (const std::vector< M > &arg, casadi_int &npar) const
 Check if input arguments that needs to be replaced. More...
 
template<typename M >
bool matching_res (const std::vector< M > &arg, casadi_int &npar) const
 Check if output arguments that needs to be replaced. More...
 
template<typename M >
std::vector< M > replace_arg (const std::vector< M > &arg, casadi_int npar) const
 Replace 0-by-0 inputs. More...
 
template<typename M >
std::vector< M > project_arg (const std::vector< M > &arg, casadi_int npar) const
 Project sparsities. More...
 
template<typename M >
std::vector< M > project_res (const std::vector< M > &arg, casadi_int npar) const
 Project sparsities. More...
 
template<typename M >
std::vector< M > replace_res (const std::vector< M > &res, casadi_int npar) const
 Replace 0-by-0 outputs. More...
 
template<typename M >
std::vector< std::vector< M > > replace_fseed (const std::vector< std::vector< M >> &fseed, casadi_int npar) const
 Replace 0-by-0 forward seeds. More...
 
template<typename M >
std::vector< std::vector< M > > replace_fseed (const std::vector< std::vector< M > > &fseed, casadi_int npar) const
 
template<typename M >
std::vector< std::vector< M > > replace_aseed (const std::vector< std::vector< M >> &aseed, casadi_int npar) const
 Replace 0-by-0 reverse seeds. More...
 
template<typename M >
std::vector< std::vector< M > > replace_aseed (const std::vector< std::vector< M > > &aseed, casadi_int npar) const
 
std::vector< MXmapsum_mx (const std::vector< MX > &arg, const std::string &parallelization)
 Parallel evaluation. More...
 
virtual bool uses_output () const
 Do the derivative functions need nondifferentiated outputs? More...
 
std::string diff_prefix (const std::string &prefix) const
 Determine prefix for differentiated functions. More...
 
virtual Function slice (const std::string &name, const std::vector< casadi_int > &order_in, const std::vector< casadi_int > &order_out, const Dict &opts) const
 returns a new function with a selection of inputs/outputs of the original More...
 
bool has_derivative () const
 Can derivatives be calculated in any way? More...
 
virtual double ad_weight () const
 Weighting factor for chosing forward/reverse mode. More...
 
virtual double sp_weight () const
 Weighting factor for chosing forward/reverse mode,. More...
 
virtual std::vector< MXfree_mx () const
 Get free variables (MX) More...
 
virtual std::vector< SXfree_sx () const
 Get free variables (SX) More...
 
virtual bool has_free () const
 Does the function have free variables. More...
 
virtual void generate_lifted (Function &vdef_fcn, Function &vinit_fcn) const
 Extract the functions needed for the Lifted Newton method. More...
 
virtual casadi_int n_instructions () const
 Get the number of atomic operations. More...
 
virtual casadi_int instruction_id (casadi_int k) const
 Get an atomic operation operator index. More...
 
virtual std::vector< casadi_int > instruction_input (casadi_int k) const
 Get the (integer) input arguments of an atomic operation. More...
 
virtual double instruction_constant (casadi_int k) const
 Get the floating point output argument of an atomic operation. More...
 
virtual std::vector< casadi_int > instruction_output (casadi_int k) const
 Get the (integer) output argument of an atomic operation. More...
 
virtual casadi_int n_nodes () const
 Number of nodes in the algorithm. More...
 
virtual MX instruction_MX (casadi_int k) const
 get MX expression associated with instruction More...
 
virtual SX instructions_sx () const
 get SX expression associated with instructions More...
 
Dict cache () const
 Get all functions in the cache. More...
 
bool incache (const std::string &fname, Function &f, const std::string &suffix="") const
 Get function in cache. More...
 
void tocache (const Function &f, const std::string &suffix="") const
 Save function to cache. More...
 
void tocache_if_missing (Function &f, const std::string &suffix="") const
 Save function to cache, only if missing. More...
 
void codegen (CodeGenerator &g, const std::string &fname) const
 Generate code the function. More...
 
void codegen_meta (CodeGenerator &g) const
 Generate meta-information allowing a user to evaluate a generated function. More...
 
void codegen_sparsities (CodeGenerator &g) const
 Codegen sparsities. More...
 
virtual std::string codegen_name (const CodeGenerator &g, bool ns=true) const
 Get name in codegen. More...
 
std::string codegen_mem (CodeGenerator &g, const std::string &index="mem") const
 Get thread-local memory object. More...
 
virtual void codegen_incref (CodeGenerator &g) const
 Codegen incref for dependencies. More...
 
virtual void codegen_decref (CodeGenerator &g) const
 Codegen decref for dependencies. More...
 
virtual void codegen_alloc_mem (CodeGenerator &g) const
 Codegen decref for alloc_mem. More...
 
virtual void codegen_init_mem (CodeGenerator &g) const
 Codegen decref for init_mem. More...
 
virtual void codegen_free_mem (CodeGenerator &g) const
 Codegen for free_mem. More...
 
virtual void codegen_checkout (CodeGenerator &g) const
 Codegen for checkout. More...
 
virtual void codegen_release (CodeGenerator &g) const
 Codegen for release. More...
 
std::string signature (const std::string &fname) const
 Code generate the function. More...
 
std::string signature_unrolled (const std::string &fname) const
 Code generate the function. More...
 
virtual void codegen_declarations (CodeGenerator &g) const
 Generate code for the declarations of the C function. More...
 
virtual void codegen_body (CodeGenerator &g) const
 Generate code for the function body. More...
 
virtual std::string codegen_mem_type () const
 Thread-local memory object type. More...
 
virtual bool codegen_needs_mem () const
 Is thread-local memory object needed? More...
 
virtual bool codegen_mem_is_opaque () const
 Is thread-local memory object managed by checkout/release. More...
 
virtual bool has_codegen () const
 Is codegen supported? More...
 
virtual void export_code (const std::string &lang, std::ostream &stream, const Dict &options) const
 Export function in a specific language. More...
 
void disp (std::ostream &stream, bool more) const override
 Display object. More...
 
virtual void disp_more (std::ostream &stream) const
 Print more. More...
 
std::string definition () const
 Get function signature: name:(inputs)->(outputs) More...
 
void print_dimensions (std::ostream &stream) const
 Print dimensions of inputs and outputs. More...
 
virtual std::vector< std::string > get_free () const
 Print free variables. More...
 
void get_partition (casadi_int iind, casadi_int oind, Sparsity &D1, Sparsity &D2, bool compact, bool symmetric, bool allow_forward, bool allow_reverse) const
 Get the unidirectional or bidirectional partition. More...
 
virtual double get_default_in (casadi_int ind) const
 Get default input value. More...
 
virtual double get_max_in (casadi_int ind) const
 Get largest input value. More...
 
virtual double get_min_in (casadi_int ind) const
 Get smallest input value. More...
 
virtual std::vector< double > get_nominal_in (casadi_int ind) const
 
virtual std::vector< double > get_nominal_out (casadi_int ind) const
 
virtual bool get_diff_in (casadi_int i)
 Which inputs are differentiable. More...
 
virtual bool get_diff_out (casadi_int i)
 Which outputs are differentiable. More...
 
casadi_int index_in (const std::string &name) const
 Get input scheme index by name. More...
 
casadi_int index_out (const std::string &name) const
 Get output scheme index by name. More...
 
virtual int eval_activity (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
 Propagate signal activity forward. More...
 
virtual int sp_forward_block (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem, casadi_int oind, casadi_int iind) const
 Propagate sparsity forward, specific block. More...
 
void sz_work (size_t &sz_arg, size_t &sz_res, size_t &sz_iw, size_t &sz_w) const
 Get number of temporary variables needed. More...
 
size_t sz_arg () const
 Get required length of arg field. More...
 
size_t sz_res () const
 Get required length of res field. More...
 
size_t sz_iw () const
 Get required length of iw field. More...
 
size_t sz_w () const
 Get required length of w field. More...
 
void alloc_arg (size_t sz_arg, bool persistent=false)
 Ensure required length of arg field. More...
 
void alloc_res (size_t sz_res, bool persistent=false)
 Ensure required length of res field. More...
 
void alloc_iw (size_t sz_iw, bool persistent=false)
 Ensure required length of iw field. More...
 
void alloc_w (size_t sz_w, bool persistent=false)
 Ensure required length of w field. More...
 
void alloc (const Function &f, bool persistent=false, int num_threads=1)
 Ensure work vectors long enough to evaluate function. More...
 
void setup (void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
 Set the (persistent and temporary) work vectors. More...
 
virtual Dict info () const
 
Function map (casadi_int n, const std::string &parallelization) const
 Generate/retrieve cached serial map. More...
 
void generate_in (const std::string &fname, const double **arg) const
 Export an input file that can be passed to generate C code with a main. More...
 
void generate_out (const std::string &fname, double **res) const
 
virtual bool is_a (const std::string &type, bool recursive) const
 Check if the function is of a particular type. More...
 
virtual void merge (const std::vector< MX > &arg, std::vector< MX > &subs_from, std::vector< MX > &subs_to) const
 List merge opportunitities. More...
 
template<typename MatType >
std::vector< std::vector< MatType > > fwd_seed (casadi_int nfwd) const
 Symbolic expressions for the forward seeds. More...
 
template<typename MatType >
std::vector< std::vector< MatType > > symbolicAdjSeed (casadi_int nadj, const std::vector< MatType > &v) const
 Symbolic expressions for the adjoint seeds. More...
 
void print_in (std::ostream &stream, const double **arg, bool truncate) const
 Print inputs. More...
 
void print_out (std::ostream &stream, double **res, bool truncate) const
 Print outputs. More...
 
void construct (const Dict &opts)
 Construct. More...
 
void print_options (std::ostream &stream) const
 Print list of options. More...
 
void print_option (const std::string &name, std::ostream &stream) const
 Print all information there is to know about a certain option. More...
 
bool has_option (const std::string &option_name) const
 Does a particular option exist. More...
 
int checkout () const
 Checkout a memory object. More...
 
void release (int mem) const
 Release a memory object. More...
 
void * memory (int ind) const
 Memory objects. More...
 
bool has_memory (int ind) const
 Check for existance of memory object. More...
 
virtual void check_mem_count (casadi_int n) const
 Check for validatity of memory object count. More...
 
void clear_mem ()
 Clear all memory (called from destructor) More...
 
void print (const char *fmt,...) const
 C-style formatted printing during evaluation. More...
 
void sprint (char *buf, size_t buf_sz, const char *fmt,...) const
 C-style formatted printing to string. More...
 
void format_time (char *buffer, double time) const
 Format time in a fixed width 8 format. More...
 
void print_time (const std::map< std::string, FStats > &fstats) const
 Print timing statistics. More...
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
casadi_int getCount () const
 Get the reference count. More...
 
std::string debug_repr (const SharedObjectInternal *) const
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 
virtual void deps_version_check (const std::string &stage) const
 
size_t get_n_in () override
 Number of function inputs and outputs. More...
 
size_t get_n_out () override
 Number of function inputs and outputs. More...
 
Sparsity get_sparsity_in (casadi_int i) override
 Sparsities of function inputs and outputs. More...
 
Sparsity get_sparsity_out (casadi_int i) override
 Sparsities of function inputs and outputs. More...
 
std::string get_name_in (casadi_int i) override
 Names of function input and outputs. More...
 
std::string get_name_out (casadi_int i) override
 Names of function input and outputs. More...
 
bool has_spfwd () const override
 
bool has_sprev () const override
 
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. More...
 
bool has_forward (casadi_int nfwd) const override
 Generate a function that calculates nfwd forward derivatives. More...
 
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. More...
 
bool has_reverse (casadi_int nadj) const override
 Generate a function that calculates nadj adjoint derivatives. More...
 
template<typename MatType >
Function get_forward_dae (const std::string &name) const
 Generate the augmented DAE system. More...
 
Function augmented_dae () const
 Generate the augmented DAE system. More...
 
int eval_gen (const double **arg, double **res, casadi_int *iw, double *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate numerically. More...
 
int eval_gen (const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate a function, overloaded. More...
 
int eval_gen (const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem, bool always_inline, bool never_inline) const
 Evaluate a function, overloaded. More...
 
virtual std::vector< DMeval_dm (const std::vector< DM > &arg) const
 Evaluate with DM matrices. More...
 
virtual bool has_eval_dm () const
 Evaluate with DM matrices. More...
 
void call_gen (const MXVector &arg, MXVector &res, casadi_int npar, bool always_inline, bool never_inline) const
 Call a function, overloaded. More...
 
template<typename D >
void call_gen (const std::vector< Matrix< D > > &arg, std::vector< Matrix< D > > &res, casadi_int npar, bool always_inline, bool never_inline) const
 Call a function, overloaded. More...
 
template<typename M >
void check_arg (const std::vector< M > &arg, casadi_int &npar) const
 Check if input arguments have correct length and dimensions. More...
 
template<typename M >
void check_res (const std::vector< M > &res, casadi_int &npar) const
 Check if output arguments have correct length and dimensions. More...
 
template<typename M >
std::map< std::string, M > convert_arg (const std::vector< M > &arg) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::vector< M > convert_arg (const std::map< std::string, M > &arg) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::map< std::string, M > convert_res (const std::vector< M > &res) const
 Convert from/to input/output lists/map. More...
 
template<typename M >
std::vector< M > convert_res (const std::map< std::string, M > &res) const
 Convert from/to input/output lists/map. More...
 
std::vector< double > nz_in (const std::vector< DM > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< DMnz_in (const std::vector< double > &arg) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< double > nz_out (const std::vector< DM > &res) const
 Convert from/to flat vector of input/output nonzeros. More...
 
std::vector< DMnz_out (const std::vector< double > &res) const
 Convert from/to flat vector of input/output nonzeros. More...
 
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. More...
 
virtual void call_forward (const std::vector< SX > &arg, const std::vector< SX > &res, const std::vector< std::vector< SX > > &fseed, std::vector< std::vector< SX > > &fsens, bool always_inline, bool never_inline) const
 Forward mode AD, virtual functions overloaded in derived classes. More...
 
virtual void call_reverse (const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens, bool always_inline, bool never_inline) const
 Reverse mode, virtual functions overloaded in derived classes. More...
 
virtual void call_reverse (const std::vector< SX > &arg, const std::vector< SX > &res, const std::vector< std::vector< SX > > &aseed, std::vector< std::vector< SX > > &asens, bool always_inline, bool never_inline) const
 Reverse mode, virtual functions overloaded in derived classes. More...
 
Function jacobian () const
 Return Jacobian of all input elements with respect to all output elements. More...
 
virtual bool has_jacobian () const
 Return Jacobian of all input elements with respect to all output elements. More...
 
virtual Function get_jacobian (const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const
 Return Jacobian of all input elements with respect to all output elements. More...
 
Sparsityjac_sparsity (casadi_int oind, casadi_int iind, bool compact, bool symmetric) const
 Get Jacobian sparsity. More...
 
virtual bool has_jac_sparsity (casadi_int oind, casadi_int iind) const
 Get Jacobian sparsity. More...
 
virtual Sparsity get_jac_sparsity (casadi_int oind, casadi_int iind, bool symmetric) const
 Get Jacobian sparsity. More...
 
Function forward (casadi_int nfwd) const
 Return function that calculates forward derivatives. More...
 
Function reverse (casadi_int nadj) const
 Return function that calculates adjoint derivatives. More...
 
virtual const SX sx_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< SXsx_in () const
 Get function input(s) and output(s) More...
 
virtual const SX sx_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< SXsx_out () const
 Get function input(s) and output(s) More...
 
virtual const MX mx_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< MXmx_in () const
 Get function input(s) and output(s) More...
 
virtual const MX mx_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
virtual const std::vector< MXmx_out () const
 Get function input(s) and output(s) More...
 
const DM dm_in (casadi_int ind) const
 Get function input(s) and output(s) More...
 
const std::vector< DMdm_in () const
 Get function input(s) and output(s) More...
 
const DM dm_out (casadi_int ind) const
 Get function input(s) and output(s) More...
 
const std::vector< DMdm_out () const
 Get function input(s) and output(s) More...
 
Function wrap (const std::string &name) const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap () const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap_as_needed (const std::string &name, const Dict &opts) const
 Wrap in an Function instance consisting of only one MX call. More...
 
Function wrap_as_needed (const Dict &opts) const
 Wrap in an Function instance consisting of only one MX call. More...
 
casadi_int nnz_in () const
 Number of input/output nonzeros. More...
 
casadi_int nnz_in (casadi_int ind) const
 Number of input/output nonzeros. More...
 
casadi_int nnz_out () const
 Number of input/output nonzeros. More...
 
casadi_int nnz_out (casadi_int ind) const
 Number of input/output nonzeros. More...
 
casadi_int numel_in () const
 Number of input/output elements. More...
 
casadi_int numel_in (casadi_int ind) const
 Number of input/output elements. More...
 
casadi_int numel_out (casadi_int ind) const
 Number of input/output elements. More...
 
casadi_int numel_out () const
 Number of input/output elements. More...
 
casadi_int size1_in (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size2_in (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size1_out (casadi_int ind) const
 Input/output dimensions. More...
 
casadi_int size2_out (casadi_int ind) const
 Input/output dimensions. More...
 
std::pair< casadi_int, casadi_int > size_in (casadi_int ind) const
 Input/output dimensions. More...
 
std::pair< casadi_int, casadi_int > size_out (casadi_int ind) const
 Input/output dimensions. More...
 
const Sparsitysparsity_in (casadi_int ind) const
 Input/output sparsity. More...
 
const Sparsitysparsity_out (casadi_int ind) const
 Input/output sparsity. More...
 
bool all_scalar () const
 Are all inputs and outputs scalar. More...
 
virtual bool jac_is_symm (casadi_int oind, casadi_int iind) const
 Is a Jacobian block known to be symmetric a priori? More...
 
Sparsity to_compact (casadi_int oind, casadi_int iind, const Sparsity &sp) const
 Convert to compact Jacobian sparsity pattern. More...
 
Sparsity from_compact (casadi_int oind, casadi_int iind, const Sparsity &sp) const
 Convert from compact Jacobian sparsity pattern. More...
 
template<bool fwd>
Sparsity get_jac_sparsity_gen (casadi_int oind, casadi_int iind) const
 Get the sparsity pattern via sparsity seed propagation. More...
 
Sparsity get_jac_sparsity_hierarchical (casadi_int oind, casadi_int iind) const
 A flavor of get_jac_sparsity_gen that does hierarchical block structure recognition. More...
 
Sparsity get_jac_sparsity_hierarchical_symm (casadi_int oind, casadi_int iind) const
 
virtual std::vector< MXsymbolic_output (const std::vector< MX > &arg) const
 Get a vector of symbolic variables corresponding to the outputs. More...
 
virtual size_t codegen_sz_arg (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual size_t codegen_sz_res (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual size_t codegen_sz_iw (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual size_t codegen_sz_w (const CodeGenerator &g) const
 Get required lengths, for codegen. More...
 
virtual bool fwdViaJac (casadi_int nfwd) const
 Calculate derivatives by multiplying the full Jacobian and multiplying. More...
 
virtual bool adjViaJac (casadi_int nadj) const
 Calculate derivatives by multiplying the full Jacobian and multiplying. More...
 

Static Public Member Functions

static Integratorcreator (const std::string &name, const Function &dae, double t0, const std::vector< double > &tout)
 Create a new integrator. More...
 
static CvodesMemoryto_mem (void *mem)
 Cast to memory object. More...
 
static ProtoFunctiondeserialize (DeserializingStream &s)
 Deserialize into MX. More...
 
static void printvar (const std::string &id, double v)
 
static void printvar (const std::string &id, N_Vector v)
 
static bool all_zero (const double *v, casadi_int n)
 Helper function: Vector has only zeros? More...
 
template<typename XType >
static Function map2oracle (const std::string &name, const std::map< std::string, XType > &d)
 Convert dictionary to Problem. More...
 
static bool grid_in (casadi_int i)
 Is an input repeated for each grid point? More...
 
static bool grid_out (casadi_int i)
 Is an output repeated for each grid point? More...
 
static casadi_int adjmap_out (casadi_int i)
 Which output is used to calculate a given input in adjoint sensitivity analysis. More...
 
static std::string forward_name (const std::string &fcn, casadi_int nfwd)
 Helper function: Get name of forward derivative function. More...
 
static std::string reverse_name (const std::string &fcn, casadi_int nadj)
 Helper function: Get name of adjoint derivative function. More...
 
template<typename MatType >
static MatType ensure_stacked (const MatType &v, const Sparsity &sp, casadi_int n)
 Ensure that a matrix's sparsity is a horizontal multiple of another, or empty. More...
 
static std::string get_jit_directory (const Dict &jit_options)
 Get JIT directory from options. More...
 
template<typename MatType >
static bool purgable (const std::vector< MatType > &seed)
 Can a derivative direction be skipped. More...
 
static std::string string_from_UnifiedReturnStatus (UnifiedReturnStatus status)
 
static void print_canonical (std::ostream &stream, const Sparsity &sp, const double *nz)
 Print canonical representation of a numeric matrix. More...
 
static void print_canonical (std::ostream &stream, casadi_int sz, const double *nz)
 Print canonical representation of a numeric vector. More...
 
static void print_canonical (std::ostream &stream, double a)
 Print canonical representation of a number. More...
 
static bool has_plugin (const std::string &pname, bool verbose=false)
 Check if a plugin is available or can be loaded. More...
 
static const Optionsplugin_options (const std::string &pname)
 Get the plugin options. More...
 
static Deserialize plugin_deserialize (const std::string &pname)
 Get the plugin deserialize_map. More...
 
static Plugin pluginFromRegFcn (RegFcn regfcn)
 Instantiate a Plugin struct from a factory function. More...
 
static Plugin load_plugin (const std::string &pname, bool register_plugin=true, bool needs_lock=true)
 Load a plugin dynamically. More...
 
static handle_t load_library (const std::string &libname, std::string &resultpath, bool global)
 Load a library dynamically. More...
 
static void registerPlugin (const Plugin &plugin, bool needs_lock=true)
 Register an integrator in the factory. More...
 
static void registerPlugin (RegFcn regfcn, bool needs_lock=true)
 Register an integrator in the factory. More...
 
static Plugin & getPlugin (const std::string &pname)
 Load and get the creator function. More...
 
static Integratorinstantiate (const std::string &fname, const std::string &pname, Problem problem)
 
static bool check_mat (const Sparsity &arg, const Sparsity &inp, casadi_int &npar)
 

Public Attributes

Linsol linsolF_
 Linear solver. More...
 
enum casadi::SundialsInterface::NewtonScheme newton_scheme_
 
enum casadi::SundialsInterface::InterpType interp_
 
Sparsity sp_jac_dae_
 Sparsity pattern of the extended Jacobians. More...
 
Sparsity sp_jac_rdae_
 
double t0_
 Initial time. More...
 
std::vector< double > tout_
 Output time grid. More...
 
casadi_int nfwd_
 Number of sensitivities. More...
 
casadi_int nadj_
 
Function rdae_
 Backwards DAE function. More...
 
casadi_int nx_
 Number of states for the forward integration. More...
 
casadi_int nz_
 
casadi_int nq_
 
casadi_int nx1_
 
casadi_int nz1_
 
casadi_int nq1_
 
casadi_int nrx_
 Number of states for the backward integration. More...
 
casadi_int nrz_
 
casadi_int nrq_
 
casadi_int nuq_
 
casadi_int nrx1_
 
casadi_int nrz1_
 
casadi_int nrq1_
 
casadi_int nuq1_
 
casadi_int np_
 Number of forward and backward parameters. More...
 
casadi_int nrp_
 
casadi_int np1_
 
casadi_int nrp1_
 
casadi_int nu_
 Number of controls. More...
 
casadi_int nu1_
 
casadi_int ne_
 Number of of zero-crossing functions. More...
 
casadi_int ntmp_
 Length of the tmp1, tmp2 vectors. More...
 
std::vector< double > nom_x_
 
std::vector< double > nom_z_
 
Dict augmented_options_
 Augmented user option. More...
 
Dict opts_
 Copy of the options. More...
 
bool print_stats_
 Options. More...
 
Function transition_
 Function to be called at state events. More...
 
casadi_int max_event_iter_
 Maximum number of event iterations for a single event. More...
 
casadi_int max_events_
 Maximum total number of events during the simulation. More...
 
double event_tol_
 Termination tolerance for the event iteration. More...
 
double event_acceptable_tol_
 Acceptable tolerance for the event iteration. More...
 
bool always_inline_
 
bool never_inline_
 
size_t n_in_
 Number of inputs and outputs. More...
 
size_t n_out_
 
std::vector< bool > is_diff_in_
 Are inputs and outputs differentiable? More...
 
std::vector< bool > is_diff_out_
 
std::vector< Sparsitysparsity_in_
 Input and output sparsity. More...
 
std::vector< Sparsitysparsity_out_
 
std::vector< std::string > name_in_
 Input and output scheme. More...
 
std::vector< std::string > name_out_
 
bool jit_
 Use just-in-time compiler. More...
 
bool jit_cleanup_
 Cleanup jit source file. More...
 
std::string jit_serialize_
 Serialize behaviour. More...
 
std::string jit_name_
 Name if jit source file. More...
 
std::string jit_directory_
 
std::string jit_base_name_
 
bool jit_temp_suffix_
 Use a temporary name. More...
 
eval_t eval_
 Numerical evaluation redirected to a C function. More...
 
casadi_checkout_t checkout_
 Checkout redirected to a C function. More...
 
casadi_release_t release_
 Release redirected to a C function. More...
 
signal_t incref_
 Incref/decref redirected to C functions. More...
 
signal_t decref_
 
Dict stats_
 Dict of statistics (resulting from evaluate) More...
 
bool has_refcount_
 Reference counting in codegen? More...
 
bool has_refcount_in_deps_
 Reference counting in dependent functions. More...
 
Dict cache_init_
 Values to prepopulate the function cache with. More...
 
WeakCache< std::string, Functioncache_
 Function cache. More...
 
std::vector< Sparsityjac_sparsity_ [2]
 Cache for sparsities of the Jacobian blocks. More...
 
Function derivative_of_
 If the function is the derivative of another function. More...
 
void * user_data_
 User-set field. More...
 
std::string compiler_plugin_
 Just-in-time compiler. More...
 
Importer compiler_
 
Dict jit_options_
 
double jac_penalty_
 Penalty factor for using a complete Jacobian to calculate directional derivatives. More...
 
bool enable_forward_
 
bool enable_reverse_
 
bool enable_jacobian_
 
bool enable_fd_
 
bool enable_forward_op_
 
bool enable_reverse_op_
 
bool enable_jacobian_op_
 
bool enable_fd_op_
 
double ad_weight_
 Weighting factor for derivative calculation and sparsity pattern calculation. More...
 
double ad_weight_sp_
 
casadi_int max_num_dir_
 Maximum number of sensitivity directions. More...
 
bool inputs_check_
 Errors are thrown if numerical values of inputs look bad. More...
 
Dict fd_options_
 
double fd_step_
 
std::string fd_method_
 
bool print_in_
 
bool print_out_
 
bool print_canonical_
 
casadi_int max_io_
 
bool dump_in_
 
bool dump_out_
 
bool dump_
 
std::string dump_dir_
 
std::string dump_format_
 
Dict forward_options_
 
Dict reverse_options_
 
Dict jacobian_options_
 
Dict der_options_
 
Function custom_jacobian_
 
std::vector< Functionregistered_functions_
 
casadi_int dump_count_
 
std::string name_
 Name. More...
 
bool verbose_
 Verbose printout. More...
 
bool print_time_
 
bool record_time_
 
bool regularity_check_
 Errors are thrown when NaN is produced. More...
 
bool error_on_fail_
 Throw an exception on failure? More...
 
double abstol_
 
double reltol_
 
casadi_int max_num_steps_
 
bool stop_at_end_
 
bool quad_err_con_
 
casadi_int steps_per_checkpoint_
 
bool disable_internal_warnings_
 
casadi_int max_multistep_order_
 
std::string linear_solver_
 
Dict linear_solver_options_
 
casadi_int max_krylov_
 
bool use_precon_
 
bool second_order_correction_
 
double step0_
 
double max_step_size_
 
double nonlin_conv_coeff_
 
casadi_int max_order_
 
bool scale_abstol_
 

Static Public Attributes

static const std::string meta_doc
 A documentation string. More...
 
static std::map< std::string, Plugin > solvers_
 Collection of solvers. More...
 
static const std::string infix_ = "integrator"
 Infix. More...
 
static std::map< std::string, ProtoFunction *(*)(DeserializingStream &)> deserialize_map
 

Protected Member Functions

 CvodesInterface (DeserializingStream &s)
 Deserializing constructor. More...
 
void set_jac_sparsity (casadi_int oind, casadi_int iind, const Sparsity &sp)
 Populate jac_sparsity_ and jac_sparsity_compact_ during initialization. More...
 
void initSingleton ()
 
void destroySingleton ()
 
shared_from_this ()
 Get a shared object from the current internal object. More...
 
const B shared_from_this () const
 Get a shared object from the current internal object. More...
 

Static Protected Member Functions

static void ehfun (int error_code, const char *module, const char *function, char *msg, void *user_data)
 
static int rhsF (double t, N_Vector x, N_Vector xdot, void *user_data)
 
static int rhsB (double t, N_Vector x, N_Vector xB, N_Vector xdotB, void *user_data)
 
static int rhsQF (double t, N_Vector x, N_Vector qdot, void *user_data)
 
static int rhsQB (double t, N_Vector x, N_Vector rx, N_Vector ruqdot, void *user_data)
 
static int jtimesF (N_Vector v, N_Vector Jv, double t, N_Vector x, N_Vector xdot, void *user_data, N_Vector tmp)
 
static int jtimesB (N_Vector vB, N_Vector JvB, double t, N_Vector x, N_Vector xB, N_Vector xdotB, void *user_data, N_Vector tmpB)
 
static int psolveF (double t, N_Vector x, N_Vector xdot, N_Vector r, N_Vector z, double gamma, double delta, int lr, void *user_data, N_Vector tmp)
 
static int psolveB (double t, N_Vector x, N_Vector xB, N_Vector xdotB, N_Vector rvecB, N_Vector zvecB, double gammaB, double deltaB, int lr, void *user_data, N_Vector tmpB)
 
static int psetupF (double t, N_Vector x, N_Vector xdot, booleantype jok, booleantype *jcurPtr, double gamma, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
 
static int psetupB (double t, N_Vector x, N_Vector xB, N_Vector xdotB, booleantype jokB, booleantype *jcurPtrB, double gammaB, void *user_data, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B)
 
static int lsetupF (CVodeMem cv_mem, int convfail, N_Vector x, N_Vector xdot, booleantype *jcurPtr, N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3)
 
static int lsolveF (CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector x, N_Vector xdot)
 
static int lsetupB (CVodeMem cv_mem, int convfail, N_Vector x, N_Vector xdot, booleantype *jcurPtr, N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3)
 
static int lsolveB (CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector x, N_Vector xdot)
 
static void cvodes_error (const char *module, int flag)
 

Protected Attributes

casadi_int lmm_
 
casadi_int iter_
 
Function oracle_
 Oracle: Used to generate other functions. More...
 
Dict common_options_
 Options for creating functions. More...
 
Dict specific_options_
 
bool show_eval_warnings_
 Show evaluation warnings. More...
 
int max_num_threads_
 
std::map< std::string, RegFunall_functions_
 
std::vector< std::string > monitor_
 
size_t stride_arg_
 
size_t stride_res_
 
size_t stride_iw_
 
size_t stride_w_
 
bool post_expand_
 
static const Options options_
 Options. More...
 
double min_step_size_
 Options. More...
 
bool always_recalculate_jacobian_
 Options. More...
 
const Optionsget_options () const override
 Options. More...
 
static std::vector< std::string > dae_out ()
 IO conventions for continuous time dynamics. More...
 
static std::vector< std::string > quad_out ()
 IO conventions for continuous time dynamics. More...
 
static std::string bdyn_in (casadi_int i)
 IO conventions for continuous time dynamics. More...
 
static std::vector< std::string > bdyn_in ()
 IO conventions for continuous time dynamics. More...
 
static std::string bdyn_out (casadi_int i)
 IO conventions for continuous time dynamics. More...
 
static std::vector< std::string > bdyn_out ()
 IO conventions for continuous time dynamics. More...
 
static std::vector< std::string > bdae_out ()
 IO conventions for continuous time dynamics. More...
 
static std::vector< std::string > bquad_out ()
 IO conventions for continuous time dynamics. More...
 
enum  DaeOut { DAE_ODE , DAE_ALG , DAE_NUM_OUT }
 IO conventions for continuous time dynamics. More...
 
enum  QuadOut { QUAD_QUAD , QUAD_NUM_OUT }
 IO conventions for continuous time dynamics. More...
 
enum  BDynIn {
  BDYN_T , BDYN_X , BDYN_Z , BDYN_P ,
  BDYN_U , BDYN_OUT_ODE , BDYN_OUT_ALG , BDYN_OUT_QUAD ,
  BDYN_OUT_ZERO , BDYN_ADJ_ODE , BDYN_ADJ_ALG , BDYN_ADJ_QUAD ,
  BDYN_ADJ_ZERO , BDYN_NUM_IN
}
 IO conventions for continuous time dynamics. More...
 
enum  BDynOut {
  BDYN_ADJ_T , BDYN_ADJ_X , BDYN_ADJ_Z , BDYN_ADJ_P ,
  BDYN_ADJ_U , BDYN_NUM_OUT
}
 IO conventions for continuous time dynamics. More...
 
enum  DAEBOut { BDAE_ADJ_X , BDAE_ADJ_Z , BDAE_NUM_OUT }
 IO conventions for continuous time dynamics. More...
 
enum  QuadBOut { BQUAD_ADJ_P , BQUAD_ADJ_U , BQUAD_NUM_OUT }
 IO conventions for continuous time dynamics. More...
 

Member Typedef Documentation

◆ Creator

typedef Integrator*(* casadi::Integrator::Creator) (const std::string &name, const Function &oracle, double t0, const std::vector< double > &tout)
inherited

Definition at line 442 of file integrator_impl.hpp.

◆ RegFcn

typedef int(* casadi::PluginInterface< Integrator >::RegFcn) (Plugin *plugin)
inherited

Definition at line 73 of file plugin_interface.hpp.

◆ weak_ref_type

Definition at line 152 of file shared_object.hpp.

Member Enumeration Documentation

◆ BDynIn

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Enumerator
BDYN_T 
BDYN_X 
BDYN_Z 
BDYN_P 
BDYN_U 
BDYN_OUT_ODE 
BDYN_OUT_ALG 
BDYN_OUT_QUAD 
BDYN_OUT_ZERO 
BDYN_ADJ_ODE 
BDYN_ADJ_ALG 
BDYN_ADJ_QUAD 
BDYN_ADJ_ZERO 
BDYN_NUM_IN 

Definition at line 370 of file integrator_impl.hpp.

◆ BDynOut

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Enumerator
BDYN_ADJ_T 
BDYN_ADJ_X 
BDYN_ADJ_Z 
BDYN_ADJ_P 
BDYN_ADJ_U 
BDYN_NUM_OUT 

Definition at line 375 of file integrator_impl.hpp.

◆ DAEBOut

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Enumerator
BDAE_ADJ_X 
BDAE_ADJ_Z 
BDAE_NUM_OUT 

Definition at line 378 of file integrator_impl.hpp.

◆ DaeOut

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Enumerator
DAE_ODE 
DAE_ALG 
DAE_NUM_OUT 

Definition at line 366 of file integrator_impl.hpp.

◆ InterpType

Enumerator
SD_POLYNOMIAL 
SD_HERMITE 

Definition at line 215 of file sundials_interface.hpp.

◆ JacFOut

◆ JtimesFIn

◆ JtimesFOut

Enumerator
JTIMESF_FWD_ODE 
JTIMESF_FWD_ALG 
JTIMESF_NUM_OUT 

Definition at line 183 of file sundials_interface.hpp.

◆ NewtonScheme

Enumerator
SD_DIRECT 
SD_GMRES 
SD_BCGSTAB 
SD_TFQMR 

Definition at line 212 of file sundials_interface.hpp.

◆ QuadBOut

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Enumerator
BQUAD_ADJ_P 
BQUAD_ADJ_U 
BQUAD_NUM_OUT 

Definition at line 380 of file integrator_impl.hpp.

◆ QuadOut

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Enumerator
QUAD_QUAD 
QUAD_NUM_OUT 

Definition at line 368 of file integrator_impl.hpp.

Constructor & Destructor Documentation

◆ CvodesInterface() [1/2]

casadi::CvodesInterface::CvodesInterface ( const std::string &  name,
const Function dae,
double  t0,
const std::vector< double > &  tout 
)

Definition at line 51 of file cvodes_interface.cpp.

52  : SundialsInterface(name, dae, t0, tout) {
53 }
SundialsInterface(const std::string &name, const Function &dae, double t0, const std::vector< double > &tout)
Constructor.

◆ ~CvodesInterface()

casadi::CvodesInterface::~CvodesInterface ( )
override

Definition at line 55 of file cvodes_interface.cpp.

55  {
56  clear_mem();
57 }
void clear_mem()
Clear all memory (called from destructor)

References casadi::ProtoFunction::clear_mem().

◆ CvodesInterface() [2/2]

casadi::CvodesInterface::CvodesInterface ( DeserializingStream s)
explicitprotected

Definition at line 759 of file cvodes_interface.cpp.

759  : SundialsInterface(s) {
760  int version = s.version("CvodesInterface", 1, 3);
761  s.unpack("CvodesInterface::lmm", lmm_);
762  s.unpack("CvodesInterface::iter", iter_);
763 
764  if (version>=2) {
765  s.unpack("CvodesInterface::min_step_size", min_step_size_);
766  } else {
767  min_step_size_ = 0;
768  }
769 
770  if (version >= 3) {
771  s.unpack("CvodesInterface::always_recalculate_jacobian", always_recalculate_jacobian_);
772  }
773 }
bool always_recalculate_jacobian_
Options.

References always_recalculate_jacobian_, iter_, lmm_, min_step_size_, casadi::DeserializingStream::unpack(), and casadi::DeserializingStream::version().

Member Function Documentation

◆ ad_weight()

double casadi::FunctionInternal::ad_weight ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l5

Definition at line 3464 of file function_internal.cpp.

3464  {
3465  // If reverse mode derivatives unavailable, use forward
3466  if (!enable_reverse_) return 0;
3467 
3468  // If forward mode derivatives unavailable, use reverse
3469  if (!enable_forward_ && !enable_fd_) return 1;
3470 
3471  // Use the (potentially user set) option
3472  return ad_weight_;
3473  }
double ad_weight_
Weighting factor for derivative calculation and sparsity pattern calculation.

References casadi::FunctionInternal::ad_weight_, casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, and casadi::FunctionInternal::enable_reverse_.

Referenced by casadi::FunctionInternal::adjViaJac(), casadi::FunctionInternal::fwdViaJac(), casadi::FunctionInternal::get_partition(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ add_embedded()

void casadi::FunctionInternal::add_embedded ( std::map< FunctionInternal *, std::pair< Function, size_t > > &  all_fun,
const Function dep,
casadi_int  max_depth 
) const
inherited

Definition at line 3906 of file function_internal.cpp.

3908  {
3909  // Add, if not already in graph and not null
3910  if (!dep.is_null() && all_fun.find(dep.get()) == all_fun.end()) {
3911  // Add to map
3912  all_fun[dep.get()] = std::make_pair(dep, all_fun.size());
3913  // Also add its dependencies
3914  if (max_depth > 0) dep->find(all_fun, max_depth - 1);
3915  }
3916  }

References casadi::FunctionInternal::find(), casadi::Function::get(), and casadi::GenericShared< Shared, Internal >::is_null().

Referenced by casadi::FunctionInternal::find(), casadi::Map::find(), casadi::MapSum::find(), casadi::MXFunction::find(), casadi::OracleFunction::find(), casadi::Switch::find(), casadi::SXFunction::find(), and casadi::BSplineInterpolant::find().

◆ add_offsets()

void casadi::SundialsInterface::add_offsets ( SundialsMemory m) const
inherited

Definition at line 374 of file sundials_interface.cpp.

374  {
375  // Add stats offsets, backward problem
376  m->nstepsB += m->nstepsB_off;
377  m->nfevalsB += m->nfevalsB_off;
378  m->nlinsetupsB += m->nlinsetupsB_off;
379  m->netfailsB += m->netfailsB_off;
380  m->nnitersB += m->nnitersB_off;
381  m->nncfailsB += m->nncfailsB_off;
382 
383 }

References casadi::SundialsMemory::netfailsB, casadi::SundialsMemory::netfailsB_off, casadi::SundialsMemory::nfevalsB, casadi::SundialsMemory::nfevalsB_off, casadi::SundialsMemory::nlinsetupsB, casadi::SundialsMemory::nlinsetupsB_off, casadi::SundialsMemory::nncfailsB, casadi::SundialsMemory::nncfailsB_off, casadi::SundialsMemory::nnitersB, casadi::SundialsMemory::nnitersB_off, casadi::SundialsMemory::nstepsB, and casadi::SundialsMemory::nstepsB_off.

Referenced by retreat(), and casadi::IdasInterface::retreat().

◆ adjmap_out()

casadi_int casadi::Integrator::adjmap_out ( casadi_int  i)
staticinherited

Definition at line 336 of file integrator.cpp.

336  {
337  switch (static_cast<IntegratorInput>(i)) {
338  case INTEGRATOR_X0: return INTEGRATOR_ADJ_X0;
339  case INTEGRATOR_Z0: return INTEGRATOR_ADJ_Z0;
340  case INTEGRATOR_P: return INTEGRATOR_ADJ_P;
341  case INTEGRATOR_U: return INTEGRATOR_ADJ_U;
342  case INTEGRATOR_ADJ_XF: return INTEGRATOR_XF;
343  case INTEGRATOR_ADJ_ZF: return INTEGRATOR_ZF;
344  case INTEGRATOR_ADJ_QF: return INTEGRATOR_QF;
345  default: break;
346  }
347  return -1;
348 }
@ INTEGRATOR_ADJ_U
Adjoint sensitivities corresponding to the control vector.
Definition: integrator.hpp:257
@ INTEGRATOR_ADJ_Z0
Adjoint sensitivities corresponding to the algebraic variable guess.
Definition: integrator.hpp:253
@ INTEGRATOR_QF
Quadrature state at all output times.
Definition: integrator.hpp:249
@ INTEGRATOR_ADJ_P
Adjoint sensitivities corresponding to the parameter vector.
Definition: integrator.hpp:255
@ INTEGRATOR_ZF
Algebraic variable at all output times.
Definition: integrator.hpp:247
@ INTEGRATOR_XF
Differential state at all output times.
Definition: integrator.hpp:245
@ INTEGRATOR_ADJ_X0
Adjoint sensitivities corresponding to the initial state.
Definition: integrator.hpp:251
IntegratorInput
Input arguments of an integrator.
Definition: integrator.hpp:223
@ INTEGRATOR_U
Piecewise constant control, a new control interval starts at each output time.
Definition: integrator.hpp:231
@ INTEGRATOR_ADJ_QF
Adjoint seeds corresponding to the quadratures at the output times.
Definition: integrator.hpp:237
@ INTEGRATOR_ADJ_ZF
Adjoint seeds corresponding to the algebraic variables at the output times.
Definition: integrator.hpp:235
@ INTEGRATOR_P
Parameters.
Definition: integrator.hpp:229
@ INTEGRATOR_ADJ_XF
Adjoint seeds corresponding to the states at the output times.
Definition: integrator.hpp:233
@ INTEGRATOR_Z0
Initial guess for the algebraic variable at the initial time.
Definition: integrator.hpp:227
@ INTEGRATOR_X0
Differential state at the initial time.
Definition: integrator.hpp:225

References casadi::INTEGRATOR_ADJ_P, casadi::INTEGRATOR_ADJ_QF, casadi::INTEGRATOR_ADJ_U, casadi::INTEGRATOR_ADJ_X0, casadi::INTEGRATOR_ADJ_XF, casadi::INTEGRATOR_ADJ_Z0, casadi::INTEGRATOR_ADJ_ZF, casadi::INTEGRATOR_P, casadi::INTEGRATOR_QF, casadi::INTEGRATOR_U, casadi::INTEGRATOR_X0, casadi::INTEGRATOR_XF, casadi::INTEGRATOR_Z0, and casadi::INTEGRATOR_ZF.

Referenced by casadi::Integrator::get_reverse().

◆ adjViaJac()

bool casadi::FunctionInternal::adjViaJac ( casadi_int  nadj) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nc

Definition at line 3197 of file function_internal.cpp.

3197  {
3198  if (!enable_reverse_) return true;
3199  if (jac_penalty_==-1) return false;
3200 
3201  // Heuristic 1: Jac calculated via reverse mode likely cheaper
3202  if (jac_penalty_*static_cast<double>(nnz_out())<nadj) return true;
3203 
3204  // Heuristic 2: Jac calculated via forward mode likely cheaper
3205  double w = ad_weight();
3206  if ((enable_forward_ || enable_fd_) &&
3207  jac_penalty_*w*static_cast<double>(nnz_in())<(1-w)*static_cast<double>(nadj))
3208  return true; // NOLINT
3209 
3210  return false;
3211  }
double jac_penalty_
Penalty factor for using a complete Jacobian to calculate directional derivatives.
virtual double ad_weight() const
Weighting factor for chosing forward/reverse mode.
casadi_int nnz_in() const
Number of input/output nonzeros.
casadi_int nnz_out() const
Number of input/output nonzeros.

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::jac_penalty_, casadi::FunctionInternal::nnz_in(), and casadi::FunctionInternal::nnz_out().

Referenced by casadi::FunctionInternal::call_reverse().

◆ advance()

int casadi::Integrator::advance ( IntegratorMemory m) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29r

Definition at line 532 of file integrator.cpp.

532  {
533  // Predict next event
534  if (ne_ > 0 && m->t_next_out != m->t_start) {
535  if (predict_events(m)) return 1;
536  }
537  // Event iterations
538  m->event_iter = 0;
539  while (true) {
540  // Start a new event iteration
541  m->event_iter++;
542  // No event triggered
543  m->event_index = -1;
544  // Advance solution in time
545  if (advance_noevent(m)) return 1;
546  // Update current time
547  m->t = m->t_next;
548  m->t_next = m->t_next_out;
549  // If no events or no interval, done
550  if (ne_ == 0 || m->t_next_out == m->t_start) break;
551  // Recalculate m->e and m->edot
552  if (calc_edot(m)) return 1;
553  // By default, let integrator continue to the next input step change
554  m->t_stop = m->t_step;
555  // Detect events
556  for (casadi_int i = 0; i < ne_; ++i) {
557  // Make sure that event was not already triggered
558  if (m->event_triggered[i] || m->old_e[i] <= 0) continue;
559  // Check if event was triggered or is projected to be triggered before next output time
560  if (m->e[i] < 0 || (m->edot[i] < 0 && m->e[i] + (m->t_next_out - m->t) * m->edot[i] < 0)) {
561  // Projected zero-crossing time
562  double t_zero = m->t - m->e[i] / m->edot[i];
563  // If t_zero is too small or m->edot[i] has the wrong sign, fall back to bisection
564  if (t_zero <= m->t_start || (m->e[i] < 0 && m->edot[i] >= 0)) {
565  t_zero = 0.5 * (m->t_start + m->t);
566  }
567  // Update t_next if earliest event so far
568  if (t_zero < m->t_next) {
569  m->event_index = i;
570  m->t_next = t_zero;
571  m->t_stop = std::max(m->t, m->t_next);
572  }
573  }
574  }
575  // If no events, done
576  if (m->event_index < 0) break;
577  // Distance to new time step
578  double t_diff = std::fabs(m->t_next - m->t);
579  // Check if converged
580  if (t_diff < event_tol_) {
581  if (verbose_) casadi_message("Event iteration converged, |dt| == " + str(t_diff));
582  break;
583  }
584  // Maximum number of iterations reached?
585  if (m->event_iter == max_event_iter_) {
586  // Throw error?
587  if (t_diff >= event_acceptable_tol_) {
588  casadi_error("Maximum number of event iterations reached without convergence");
589  }
590  if (verbose_) casadi_message("Max event iterations, |dt| == " + str(t_diff));
591  break;
592  }
593  // More iterations needed
594  if (verbose_) casadi_message("Event iteration " + str(m->event_iter) + ", |dt| == "
595  + str(t_diff));
596  }
597  // Successful return
598  return 0;
599 }
int predict_events(IntegratorMemory *m) const
Predict next event time.
double event_tol_
Termination tolerance for the event iteration.
double event_acceptable_tol_
Acceptable tolerance for the event iteration.
virtual int advance_noevent(IntegratorMemory *mem) const =0
Advance solution in time, without events handling.
casadi_int max_event_iter_
Maximum number of event iterations for a single event.
int calc_edot(IntegratorMemory *m) const
Linearize the zero crossing function.
casadi_int ne_
Number of of zero-crossing functions.
bool verbose_
Verbose printout.
std::string str(const T &v)
String representation, any type.

References casadi::Integrator::advance_noevent(), casadi::Integrator::calc_edot(), casadi::IntegratorMemory::e, casadi::IntegratorMemory::edot, casadi::Integrator::event_acceptable_tol_, casadi::IntegratorMemory::event_index, casadi::IntegratorMemory::event_iter, casadi::Integrator::event_tol_, casadi::IntegratorMemory::event_triggered, casadi::Integrator::max_event_iter_, casadi::Integrator::ne_, casadi::IntegratorMemory::old_e, casadi::Integrator::predict_events(), casadi::str(), casadi::IntegratorMemory::t, casadi::IntegratorMemory::t_next, casadi::IntegratorMemory::t_next_out, casadi::IntegratorMemory::t_start, casadi::IntegratorMemory::t_step, casadi::IntegratorMemory::t_stop, and casadi::ProtoFunction::verbose_.

Referenced by casadi::Integrator::eval().

◆ advance_noevent()

int casadi::CvodesInterface::advance_noevent ( IntegratorMemory mem) const
overridevirtual

Implements casadi::Integrator.

Definition at line 259 of file cvodes_interface.cpp.

259  {
260  auto m = to_mem(mem);
261 
262  // Do not integrate past change in input signals or past the end
263  // The event handling may cause the stop time to become smaller than internal time reached,
264  // in which case the stop time cannot be enforced
265  if (m->t_stop >= m->tcur) {
266  THROWING(CVodeSetStopTime, m->mem, m->t_stop);
267  }
268 
269  // Integrate, unless already at desired time
270  const double ttol = 1e-9;
271  if (fabs(m->t - m->t_next) >= ttol) {
272  // Integrate forward ...
273  double tret = m->t;
274  if (nrx_>0) {
275  // ... with taping
276  THROWING(CVodeF, m->mem, m->t_next, m->v_xz, &tret, CV_NORMAL, &m->ncheck);
277  } else {
278  // ... without taping
279  THROWING(CVode, m->mem, m->t_next, m->v_xz, &tret, CV_NORMAL);
280  }
281 
282  // Get quadratures
283  if (nq_ > 0) {
284  THROWING(CVodeGetQuad, m->mem, &tret, m->v_q);
285  }
286  }
287 
288  // Set function outputs
289  casadi_copy(NV_DATA_S(m->v_xz), nx_, m->x);
290  casadi_copy(NV_DATA_S(m->v_q), nq_, m->q);
291 
292  // Get stats
293  THROWING(CVodeGetIntegratorStats, m->mem, &m->nsteps, &m->nfevals, &m->nlinsetups,
294  &m->netfails, &m->qlast, &m->qcur, &m->hinused,
295  &m->hlast, &m->hcur, &m->tcur);
296  THROWING(CVodeGetNonlinSolvStats, m->mem, &m->nniters, &m->nncfails);
297 
298  return 0;
299 }
static CvodesMemory * to_mem(void *mem)
Cast to memory object.
casadi_int nrx_
Number of states for the backward integration.
casadi_int nx_
Number of states for the forward integration.
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.

References casadi::casadi_copy(), casadi::Integrator::nq_, casadi::Integrator::nrx_, casadi::Integrator::nx_, and to_mem().

◆ algebraic_state_init()

virtual MX casadi::Integrator::algebraic_state_init ( const MX x0,
const MX z0 
) const
inlinevirtualinherited

Reimplemented in casadi::Collocation.

Definition at line 162 of file integrator_impl.hpp.

162 { return z0; }

Referenced by casadi::FixedStepIntegrator::create_advanced().

◆ algebraic_state_output()

virtual MX casadi::Integrator::algebraic_state_output ( const MX Z) const
inlinevirtualinherited

Reimplemented in casadi::Collocation.

Definition at line 163 of file integrator_impl.hpp.

163 { return Z; }

References casadi::Z.

Referenced by casadi::FixedStepIntegrator::create_advanced().

◆ all_scalar()

bool casadi::FunctionInternal::all_scalar ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mi

Definition at line 3951 of file function_internal.cpp.

3951  {
3952  // Check inputs
3953  for (casadi_int i=0; i<n_in_; ++i) {
3954  if (!sparsity_in_[i].is_scalar()) return false;
3955  }
3956  // Check outputs
3957  for (casadi_int i=0; i<n_out_; ++i) {
3958  if (!sparsity_out_[i].is_scalar()) return false;
3959  }
3960  // All are scalar
3961  return true;
3962  }
std::vector< Sparsity > sparsity_in_
Input and output sparsity.
size_t n_in_
Number of inputs and outputs.
std::vector< Sparsity > sparsity_out_

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::sparsity_in_, and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::FunctionInternal::call().

◆ all_zero()

bool casadi::Integrator::all_zero ( const double *  v,
casadi_int  n 
)
staticinherited

Definition at line 2757 of file integrator.cpp.

2757  {
2758  // Quick return if trivially zero
2759  if (v == nullptr || n == 0) return true;
2760  // Loop over entries
2761  for (casadi_int i = 0; i < n; ++i) {
2762  if (v[i] != 0.) return false;
2763  }
2764  // All zero if reached here
2765  return true;
2766 }

Referenced by casadi::Integrator::eval(), and casadi::IdasInterface::z_impulseB().

◆ alloc()

void casadi::FunctionInternal::alloc ( const Function f,
bool  persistent = false,
int  num_threads = 1 
)
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_n8

Definition at line 3145 of file function_internal.cpp.

3145  {
3146  if (f.is_null()) return;
3147  size_t sz_arg, sz_res, sz_iw, sz_w;
3148  f.sz_work(sz_arg, sz_res, sz_iw, sz_w);
3149  alloc_arg(sz_arg*num_threads, persistent);
3150  alloc_res(sz_res*num_threads, persistent);
3151  alloc_iw(sz_iw*num_threads, persistent);
3152  alloc_w(sz_w*num_threads, persistent);
3153  registered_functions_.push_back(f);
3154  }
void alloc_iw(size_t sz_iw, bool persistent=false)
Ensure required length of iw field.
void alloc_res(size_t sz_res, bool persistent=false)
Ensure required length of res field.
void alloc_arg(size_t sz_arg, bool persistent=false)
Ensure required length of arg field.
std::vector< Function > registered_functions_
size_t sz_res() const
Get required length of res field.
size_t sz_w() const
Get required length of w field.
void alloc_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
size_t sz_arg() const
Get required length of arg field.
size_t sz_iw() const
Get required length of iw field.

References casadi::FunctionInternal::alloc_arg(), casadi::FunctionInternal::alloc_iw(), casadi::FunctionInternal::alloc_res(), casadi::FunctionInternal::alloc_w(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::registered_functions_, casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), and casadi::Function::sz_work().

Referenced by casadi::OracleFunction::finalize(), casadi::KinsolInterface::get_jtimes(), casadi::FiniteDiff::init(), casadi::Nlpsol::init(), casadi::Rootfinder::init(), casadi::Switch::init(), casadi::Feasiblesqpmethod::init(), casadi::ImplicitToNlp::init(), casadi::QpToNlp::init(), casadi::Qrsqp::init(), casadi::Scpgen::init(), and casadi::Sqpmethod::init().

◆ alloc_arg()

void casadi::FunctionInternal::alloc_arg ( size_t  sz_arg,
bool  persistent = false 
)
inherited

◆ alloc_iw()

void casadi::FunctionInternal::alloc_iw ( size_t  sz_iw,
bool  persistent = false 
)
inherited

◆ alloc_mem()

void* casadi::CvodesInterface::alloc_mem ( ) const
inlineoverridevirtual

Reimplemented from casadi::OracleFunction.

Definition at line 121 of file cvodes_interface.hpp.

121 { return new CvodesMemory(*this);}

◆ alloc_res()

void casadi::FunctionInternal::alloc_res ( size_t  sz_res,
bool  persistent = false 
)
inherited

◆ alloc_w()

void casadi::FunctionInternal::alloc_w ( size_t  sz_w,
bool  persistent = false 
)
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_n7

Definition at line 3137 of file function_internal.cpp.

3137  {
3138  if (persistent) {
3139  sz_w_per_ += sz_w;
3140  } else {
3141  sz_w_tmp_ = std::max(sz_w_tmp_, sz_w);
3142  }
3143  }

References casadi::FunctionInternal::sz_w().

Referenced by casadi::FunctionInternal::alloc(), casadi::BlazingSplineFunction::init(), casadi::External::init(), casadi::FiniteDiff::init(), casadi::FmuFunction::init(), casadi::Integrator::init(), casadi::FixedStepIntegrator::init(), casadi::Interpolant::init(), casadi::JitFunction::init(), casadi::Map::init(), casadi::OmpMap::init(), casadi::ThreadMap::init(), casadi::MapSum::init(), casadi::MXFunction::init(), casadi::Nlpsol::init(), casadi::Rootfinder::init(), casadi::Switch::init(), casadi::SXFunction::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::CbcInterface::init(), casadi::MadmpecInterface::init(), casadi::ClarabelInterface::init(), casadi::ClpInterface::init(), casadi::CplexInterface::init(), casadi::DaqpInterface::init(), casadi::FatropConicInterface::init(), casadi::FatropInterface::init(), casadi::GurobiInterface::init(), casadi::HighsInterface::init(), casadi::HpipmInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), casadi::MadnlpInterface::init(), casadi::MosekInterface::init(), casadi::OoqpInterface::init(), casadi::OsqpInterface::init(), casadi::PiqpInterface::init(), casadi::ProxqpInterface::init(), casadi::QpoasesInterface::init(), casadi::SLEQPInterface::init(), casadi::SlicotDple::init(), casadi::SlicotExpm::init(), casadi::SnoptInterface::init(), init(), casadi::IdasInterface::init(), casadi::KinsolInterface::init(), casadi::SundialsInterface::init(), casadi::SuperscsInterface::init(), casadi::WorhpInterface::init(), casadi::XpressInterface::init(), casadi::BSplineInterpolant::init(), casadi::FastNewton::init(), casadi::Feasiblesqpmethod::init(), casadi::ImplicitToNlp::init(), casadi::Ipqp::init(), casadi::LinearInterpolant::init(), casadi::LinearInterpolantJac::init(), casadi::Newton::init(), casadi::QpToNlp::init(), casadi::Qrqp::init(), casadi::Qrsqp::init(), casadi::Scpgen::init(), and casadi::Sqpmethod::init().

◆ augmented_dae()

Function casadi::Integrator::augmented_dae ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_261

Definition at line 919 of file integrator.cpp.

919  {
920  // If no sensitivities, augmented oracle is the oracle itself
921  if (nfwd_ == 0) return oracle_;
922  // Name of augmented DAE
923  std::string aug_name = "fsens" + str(nfwd_) + "_" + oracle_.name();
924  // Use function in cache, if available
925  Function ret;
926  // if (incache(aug_name, ret)) return ret; // caching disabled while implementing #3047
927  // Create new augmented oracle
928  try {
929  if (oracle_.is_a("SXFunction")) {
930  ret = get_forward_dae<SX>(aug_name);
931  } else {
932  ret = get_forward_dae<MX>(aug_name);
933  }
934  } catch (std::exception& e) {
935  casadi_error("Failed to generate augmented DAE for " + name_ + ":\n" + e.what());
936  }
937  // Save to Function cache and return
938  // tocache(ret); // caching disabled while implementing #3047
939  return ret;
940 }
const std::string & name() const
Name of the function.
Definition: function.cpp:1504
bool is_a(const std::string &type, bool recursive=true) const
Check if the function is of a particular type.
Definition: function.cpp:1861
casadi_int nfwd_
Number of sensitivities.
Function oracle_
Oracle: Used to generate other functions.

References casadi::Function::is_a(), casadi::Function::name(), casadi::ProtoFunction::name_, casadi::Integrator::nfwd_, casadi::OracleFunction::oracle_, and casadi::str().

Referenced by casadi::Integrator::get_forward(), and casadi::Integrator::get_reverse().

◆ bdae_out()

static std::vector<std::string> casadi::Integrator::bdae_out ( )
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Definition at line 379 of file integrator_impl.hpp.

379 { return {"adj_x", "adj_z"}; }

Referenced by casadi::Integrator::init().

◆ bdae_sp_forward()

int casadi::Integrator::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
inherited

Definition at line 1053 of file integrator.cpp.

1055  {
1056  // Evaluate nondifferentiated
1057  m->arg[BDYN_T] = nullptr; // t
1058  m->arg[BDYN_X] = x; // x
1059  m->arg[BDYN_Z] = z; // z
1060  m->arg[BDYN_P] = p; // p
1061  m->arg[BDYN_U] = u; // u
1062  m->arg[BDYN_OUT_ODE] = nullptr; // out_ode
1063  m->arg[BDYN_OUT_ALG] = nullptr; // out_alg
1064  m->arg[BDYN_OUT_QUAD] = nullptr; // out_quad
1065  m->arg[BDYN_OUT_ZERO] = nullptr; // out_zero
1066  m->arg[BDYN_ADJ_ODE] = adj_ode; // adj_ode
1067  m->arg[BDYN_ADJ_ALG] = nullptr; // adj_alg
1068  m->arg[BDYN_ADJ_QUAD] = adj_quad; // adj_quad
1069  m->arg[BDYN_ADJ_ZERO] = nullptr; // adj_zero
1070  m->res[BDAE_ADJ_X] = adj_x; // adj_x
1071  m->res[BDAE_ADJ_Z] = adj_z; // adj_z
1072  if (calc_sp_forward("daeB", m->arg, m->res, m->iw, m->w)) return 1;
1073  // Evaluate sensitivities
1074  for (casadi_int i = 0; i < nfwd_; ++i) {
1075  m->arg[BDYN_NUM_IN + BDAE_ADJ_X] = adj_x; // out:adj_x
1076  m->arg[BDYN_NUM_IN + BDAE_ADJ_Z] = adj_z; // out:adj_z
1077  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_T] = nullptr; // fwd:t
1078  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_X] = x + (i + 1) * nx1_; // fwd:x
1079  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_Z] = z + (i + 1) * nz1_; // fwd:z
1080  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_P] = p + (i + 1) * np1_; // fwd:p
1081  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_U] = u + (i + 1) * nu1_; // fwd:u
1082  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_ODE] = nullptr; // fwd:out_ode
1083  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_ALG] = nullptr; // fwd:out_alg
1084  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_QUAD] = nullptr; // fwd:out_quad
1085  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_ZERO] = nullptr; // fwd:out_zero
1087  = adj_ode + (i + 1) * nrx1_ * nadj_; // fwd:adj_ode
1088  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_ADJ_ALG] = nullptr; // fwd:adj_alg
1090  = adj_quad + (i + 1) * nrz1_ * nadj_; // fwd:adj_quad
1091  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_ADJ_ZERO] = nullptr; // fwd:adj_zero
1092  m->res[BDAE_ADJ_X] = adj_x + (i + 1) * nrx1_ * nadj_; // fwd:adj_x
1093  m->res[BDAE_ADJ_Z] = adj_z + (i + 1) * nrz1_ * nadj_; // fwd:adj_z
1094  if (calc_sp_forward(forward_name("daeB", 1), m->arg, m->res, m->iw, m->w)) return 1;
1095  }
1096  return 0;
1097 }
static std::string forward_name(const std::string &fcn, casadi_int nfwd)
Helper function: Get name of forward derivative function.
int calc_sp_forward(const std::string &fcn, const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const

References casadi::SpForwardMem::arg, casadi::Integrator::BDAE_ADJ_X, casadi::Integrator::BDAE_ADJ_Z, casadi::Integrator::BDAE_NUM_OUT, casadi::Integrator::BDYN_ADJ_ALG, casadi::Integrator::BDYN_ADJ_ODE, casadi::Integrator::BDYN_ADJ_QUAD, casadi::Integrator::BDYN_ADJ_ZERO, casadi::Integrator::BDYN_NUM_IN, casadi::Integrator::BDYN_OUT_ALG, casadi::Integrator::BDYN_OUT_ODE, casadi::Integrator::BDYN_OUT_QUAD, casadi::Integrator::BDYN_OUT_ZERO, casadi::Integrator::BDYN_P, casadi::Integrator::BDYN_T, casadi::Integrator::BDYN_U, casadi::Integrator::BDYN_X, casadi::Integrator::BDYN_Z, casadi::OracleFunction::calc_sp_forward(), casadi::FunctionInternal::forward_name(), casadi::SpForwardMem::iw, casadi::Integrator::nadj_, casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nrx1_, casadi::Integrator::nrz1_, casadi::Integrator::nu1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::SpForwardMem::res, and casadi::SpForwardMem::w.

Referenced by casadi::Integrator::sp_forward().

◆ bdae_sp_reverse()

int casadi::Integrator::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
inherited

Definition at line 1317 of file integrator.cpp.

1319  {
1320  // Nondifferentiated inputs
1321  m->arg[BDYN_T] = nullptr; // t
1322  m->arg[BDYN_X] = x; // x
1323  m->arg[BDYN_Z] = z; // z
1324  m->arg[BDYN_P] = p; // p
1325  m->arg[BDYN_U] = u; // u
1326  m->arg[BDYN_OUT_ODE] = nullptr; // out_ode
1327  m->arg[BDYN_OUT_ALG] = nullptr; // out_alg
1328  m->arg[BDYN_OUT_QUAD] = nullptr; // out_quad
1329  m->arg[BDYN_OUT_ZERO] = nullptr; // out_zero
1330  m->arg[BDYN_ADJ_ODE] = adj_ode; // adj_ode
1331  m->arg[BDYN_ADJ_ALG] = nullptr; // adj_alg
1332  m->arg[BDYN_ADJ_QUAD] = adj_quad; // adj_quad
1333  m->arg[BDYN_ADJ_ZERO] = nullptr; // adj_zero
1334  // Propagate through sensitivities
1335  for (casadi_int i = 0; i < nfwd_; ++i) {
1336  m->res[BDAE_ADJ_X] = adj_x + (i + 1) * nrx1_ * nadj_; // fwd:adj_x
1337  m->res[BDAE_ADJ_Z] = adj_z + (i + 1) * nrz1_ * nadj_; // fwd:adj_z
1338  m->arg[BDYN_NUM_IN + BDAE_ADJ_X] = adj_x; // out:adj_x
1339  m->arg[BDYN_NUM_IN + BDAE_ADJ_Z] = adj_z; // out:adj_z
1340  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_T] = nullptr; // fwd:t
1341  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_X] = x + (i + 1) * nx1_; // fwd:x
1342  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_Z] = z + (i + 1) * nz1_; // fwd:z
1343  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_P] = p + (i + 1) * np1_; // fwd:p
1344  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_U] = u + (i + 1) * nu1_; // fwd:u
1345  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_ODE] = nullptr; // fwd:out_ode
1346  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_ALG] = nullptr; // fwd:out_alg
1347  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_QUAD] = nullptr; // fwd:out_quad
1348  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_ZERO] = nullptr; // fwd:out_zero
1349  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_ADJ_ODE] =
1350  adj_ode + (i + 1) * nrx1_ * nadj_; // fwd:adj_ode
1351  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_ADJ_ALG] = nullptr; // fwd:adj_alg
1352  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_ADJ_QUAD] =
1353  adj_quad + (i + 1) * nrz1_ * nadj_; // fwd:adj_quad
1354  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_ADJ_ZERO] = nullptr; // fwd:adj_zero
1355  if (calc_sp_reverse(forward_name("daeB", 1), m->arg, m->res, m->iw, m->w)) return 1;
1356  }
1357  // Propagate through nondifferentiated
1358  m->res[BDAE_ADJ_X] = adj_x; // adj_x
1359  m->res[BDAE_ADJ_Z] = adj_z; // adj_z
1360  if (calc_sp_reverse("daeB", m->arg, m->res, m->iw, m->w)) return 1;
1361  return 0;
1362 }
int calc_sp_reverse(const std::string &fcn, bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const

References casadi::SpReverseMem::arg, casadi::Integrator::BDAE_ADJ_X, casadi::Integrator::BDAE_ADJ_Z, casadi::Integrator::BDAE_NUM_OUT, casadi::Integrator::BDYN_ADJ_ALG, casadi::Integrator::BDYN_ADJ_ODE, casadi::Integrator::BDYN_ADJ_QUAD, casadi::Integrator::BDYN_ADJ_ZERO, casadi::Integrator::BDYN_NUM_IN, casadi::Integrator::BDYN_OUT_ALG, casadi::Integrator::BDYN_OUT_ODE, casadi::Integrator::BDYN_OUT_QUAD, casadi::Integrator::BDYN_OUT_ZERO, casadi::Integrator::BDYN_P, casadi::Integrator::BDYN_T, casadi::Integrator::BDYN_U, casadi::Integrator::BDYN_X, casadi::Integrator::BDYN_Z, casadi::OracleFunction::calc_sp_reverse(), casadi::FunctionInternal::forward_name(), casadi::SpReverseMem::iw, casadi::Integrator::nadj_, casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nrx1_, casadi::Integrator::nrz1_, casadi::Integrator::nu1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::SpReverseMem::res, and casadi::SpReverseMem::w.

Referenced by casadi::Integrator::sp_reverse().

◆ bdyn_in() [1/2]

std::vector< std::string > casadi::Integrator::bdyn_in ( )
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Definition at line 96 of file integrator.cpp.

96  {
97  std::vector<std::string> ret(BDYN_NUM_IN);
98  for (casadi_int i = 0; i < BDYN_NUM_IN; ++i)
99  ret[i] = bdyn_in(i);
100  return ret;
101 }
static std::vector< std::string > bdyn_in()
IO conventions for continuous time dynamics.
Definition: integrator.cpp:96

References casadi::Integrator::BDYN_NUM_IN.

Referenced by casadi::Integrator::init().

◆ bdyn_in() [2/2]

std::string casadi::Integrator::bdyn_in ( casadi_int  i)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Definition at line 76 of file integrator.cpp.

76  {
77  switch (i) {
78  case BDYN_T: return "t";
79  case BDYN_X: return "x";
80  case BDYN_Z: return "z";
81  case BDYN_P: return "p";
82  case BDYN_U: return "u";
83  case BDYN_OUT_ODE: return "out_ode";
84  case BDYN_OUT_ALG: return "out_alg";
85  case BDYN_OUT_QUAD: return "out_quad";
86  case BDYN_OUT_ZERO: return "out_zero";
87  case BDYN_ADJ_ODE: return "adj_ode";
88  case BDYN_ADJ_ALG: return "adj_alg";
89  case BDYN_ADJ_QUAD: return "adj_quad";
90  case BDYN_ADJ_ZERO: return "adj_zero";
91  default: break;
92  }
93  return "";
94 }

References casadi::Integrator::BDYN_ADJ_ALG, casadi::Integrator::BDYN_ADJ_ODE, casadi::Integrator::BDYN_ADJ_QUAD, casadi::Integrator::BDYN_ADJ_ZERO, casadi::Integrator::BDYN_OUT_ALG, casadi::Integrator::BDYN_OUT_ODE, casadi::Integrator::BDYN_OUT_QUAD, casadi::Integrator::BDYN_OUT_ZERO, casadi::Integrator::BDYN_P, casadi::Integrator::BDYN_T, casadi::Integrator::BDYN_U, casadi::Integrator::BDYN_X, and casadi::Integrator::BDYN_Z.

◆ bdyn_out() [1/2]

std::vector< std::string > casadi::Integrator::bdyn_out ( )
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Definition at line 115 of file integrator.cpp.

115  {
116  std::vector<std::string> ret(BDYN_NUM_OUT);
117  for (casadi_int i = 0; i < BDYN_NUM_OUT; ++i)
118  ret[i] = bdyn_out(i);
119  return ret;
120 }
static std::vector< std::string > bdyn_out()
IO conventions for continuous time dynamics.
Definition: integrator.cpp:115

References casadi::Integrator::BDYN_NUM_OUT.

◆ bdyn_out() [2/2]

std::string casadi::Integrator::bdyn_out ( casadi_int  i)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Definition at line 103 of file integrator.cpp.

103  {
104  switch (i) {
105  case BDYN_ADJ_T: return "adj_t";
106  case BDYN_ADJ_X: return "adj_x";
107  case BDYN_ADJ_Z: return "adj_z";
108  case BDYN_ADJ_P: return "adj_p";
109  case BDYN_ADJ_U: return "adj_u";
110  default: break;
111  }
112  return "";
113 }

References casadi::Integrator::BDYN_ADJ_P, casadi::Integrator::BDYN_ADJ_T, casadi::Integrator::BDYN_ADJ_U, casadi::Integrator::BDYN_ADJ_X, and casadi::Integrator::BDYN_ADJ_Z.

◆ bquad_out()

static std::vector<std::string> casadi::Integrator::bquad_out ( )
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Definition at line 381 of file integrator_impl.hpp.

381 { return {"adj_p", "adj_u"}; }

Referenced by casadi::Integrator::init().

◆ bquad_sp_forward()

int casadi::Integrator::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
inherited

Definition at line 1099 of file integrator.cpp.

1102  {
1103  // Evaluate nondifferentiated
1104  m->arg[BDYN_T] = nullptr; // t
1105  m->arg[BDYN_X] = x; // x
1106  m->arg[BDYN_Z] = z; // z
1107  m->arg[BDYN_P] = p; // p
1108  m->arg[BDYN_U] = u; // u
1109  m->arg[BDYN_OUT_ODE] = nullptr; // out_ode
1110  m->arg[BDYN_OUT_ALG] = nullptr; // out_alg
1111  m->arg[BDYN_OUT_QUAD] = nullptr; // out_quad
1112  m->arg[BDYN_OUT_ZERO] = nullptr; // out_zero
1113  m->arg[BDYN_ADJ_ODE] = adj_ode; // adj_ode
1114  m->arg[BDYN_ADJ_ALG] = adj_alg; // adj_alg
1115  m->arg[BDYN_ADJ_QUAD] = adj_quad; // adj_quad
1116  m->arg[BDYN_ADJ_ZERO] = nullptr; // adj_zero
1117  m->res[BQUAD_ADJ_P] = adj_p; // adj_p
1118  m->res[BQUAD_ADJ_U] = adj_u; // adj_u
1119  if (calc_sp_forward("quadB", m->arg, m->res, m->iw, m->w)) return 1;
1120  // Evaluate sensitivities
1121  for (casadi_int i = 0; i < nfwd_; ++i) {
1122  m->arg[BDYN_NUM_IN + BQUAD_ADJ_P] = adj_p; // out:adj_p
1123  m->arg[BDYN_NUM_IN + BQUAD_ADJ_U] = adj_u; // out:adj_u
1124  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_T] = nullptr; // fwd:t
1125  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_X] = x + (i + 1) * nx1_; // fwd:x
1126  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_Z] = z + (i + 1) * nz1_; // fwd:z
1127  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_P] = p + (i + 1) * np1_; // fwd:p
1128  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_U] = u + (i + 1) * nu1_; // fwd:u
1129  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_ODE] = nullptr; // fwd:out_ode
1130  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_ALG] = nullptr; // fwd:out_alg
1131  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_QUAD] = nullptr; // fwd:out_quad
1132  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_ZERO] = nullptr; // fwd:out_zero
1133  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_ADJ_ODE] =
1134  adj_ode + (i + 1) * nrx1_ * nadj_; // fwd:adj_ode
1135  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_ADJ_ALG] =
1136  adj_alg + (i + 1) * nrz1_ * nadj_; // fwd:adj_alg
1138  adj_quad + (i + 1) * nrp1_ * nadj_; // fwd:adj_quad
1139  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_ADJ_ZERO] = nullptr; // fwd:adj_zero
1140  m->res[BQUAD_ADJ_P] = adj_p ? adj_p + (i + 1) * nrq1_ * nadj_ : nullptr; // fwd:adj_p
1141  m->res[BQUAD_ADJ_U] = adj_u ? adj_u + (i + 1) * nuq1_ * nadj_: nullptr; // fwd:adj_u
1142  if (calc_sp_forward(forward_name("quadB", 1), m->arg, m->res, m->iw, m->w)) return 1;
1143  }
1144  return 0;
1145 }

References casadi::SpForwardMem::arg, casadi::Integrator::BDYN_ADJ_ALG, casadi::Integrator::BDYN_ADJ_ODE, casadi::Integrator::BDYN_ADJ_QUAD, casadi::Integrator::BDYN_ADJ_ZERO, casadi::Integrator::BDYN_NUM_IN, casadi::Integrator::BDYN_OUT_ALG, casadi::Integrator::BDYN_OUT_ODE, casadi::Integrator::BDYN_OUT_QUAD, casadi::Integrator::BDYN_OUT_ZERO, casadi::Integrator::BDYN_P, casadi::Integrator::BDYN_T, casadi::Integrator::BDYN_U, casadi::Integrator::BDYN_X, casadi::Integrator::BDYN_Z, casadi::Integrator::BQUAD_ADJ_P, casadi::Integrator::BQUAD_ADJ_U, casadi::Integrator::BQUAD_NUM_OUT, casadi::OracleFunction::calc_sp_forward(), casadi::FunctionInternal::forward_name(), casadi::SpForwardMem::iw, casadi::Integrator::nadj_, casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nrp1_, casadi::Integrator::nrq1_, casadi::Integrator::nrx1_, casadi::Integrator::nrz1_, casadi::Integrator::nu1_, casadi::Integrator::nuq1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::SpForwardMem::res, and casadi::SpForwardMem::w.

Referenced by casadi::Integrator::sp_forward().

◆ bquad_sp_reverse()

int casadi::Integrator::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
inherited

Definition at line 1364 of file integrator.cpp.

1366  {
1367  // Nondifferentiated inputs
1368  m->arg[BDYN_T] = nullptr; // t
1369  m->arg[BDYN_X] = x; // x
1370  m->arg[BDYN_Z] = z; // z
1371  m->arg[BDYN_P] = p; // p
1372  m->arg[BDYN_U] = u; // u
1373  m->arg[BDYN_OUT_ODE] = adj_ode; // out_ode
1374  m->arg[BDYN_OUT_ALG] = adj_alg; // out_alg
1375  m->arg[BDYN_OUT_QUAD] = adj_quad; // out_quad
1376  m->arg[BDYN_OUT_ZERO] = nullptr; // out_zero
1377  m->arg[BDYN_ADJ_ODE] = adj_ode; // adj_ode
1378  m->arg[BDYN_ADJ_ALG] = adj_alg; // adj_alg
1379  m->arg[BDYN_ADJ_QUAD] = adj_quad; // adj_quad
1380  m->arg[BDYN_ADJ_ZERO] = nullptr; // adj_zero
1381  // Propagate through sensitivities
1382  for (casadi_int i = 0; i < nfwd_; ++i) {
1383  m->res[BQUAD_ADJ_P] = adj_p ? adj_p + (i + 1) * nrq1_ * nadj_ : nullptr; // fwd:adj_p
1384  m->res[BQUAD_ADJ_U] = adj_u ? adj_u + (i + 1) * nuq1_ * nadj_ : nullptr; // fwd:adj_u
1385  m->arg[BDYN_NUM_IN + BQUAD_ADJ_P] = adj_p; // out:adj_p
1386  m->arg[BDYN_NUM_IN + BQUAD_ADJ_U] = adj_u; // out:adj_u
1387  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_T] = nullptr; // fwd:t
1388  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_X] = x + (i + 1) * nx1_; // fwd:x
1389  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_Z] = z + (i + 1) * nz1_; // fwd:z
1390  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_P] = p + (i + 1) * np1_; // fwd:p
1391  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_U] = u + (i + 1) * nu1_; // fwd:u
1392  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_ODE] = nullptr; // fwd:out_ode
1393  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_ALG] = nullptr; // fwd:out_alg
1394  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_QUAD] = nullptr; // fwd:out_quad
1395  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_ZERO] = nullptr; // fwd:out_zero
1396  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_ADJ_ODE] =
1397  adj_ode + (i + 1) * nrx1_ * nadj_; // fwd:adj_ode
1398  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_ADJ_ALG] =
1399  adj_alg + (i + 1) * nrz1_ * nadj_; // fwd:adj_alg
1401  adj_quad + (i + 1) * nrp1_ * nadj_; // fwd:adj_quad
1402  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_ADJ_ZERO] = nullptr; // fwd:adj_zero
1403  if (calc_sp_reverse(forward_name("quadB", 1), m->arg, m->res, m->iw, m->w)) return 1;
1404  }
1405  // Propagate through nondifferentiated
1406  m->res[BQUAD_ADJ_P] = adj_p; // adj_p
1407  m->res[BQUAD_ADJ_U] = adj_u; // adj_u
1408  if (calc_sp_reverse("quadB", m->arg, m->res, m->iw, m->w)) return 1;
1409  return 0;
1410 }

References casadi::SpReverseMem::arg, casadi::Integrator::BDYN_ADJ_ALG, casadi::Integrator::BDYN_ADJ_ODE, casadi::Integrator::BDYN_ADJ_QUAD, casadi::Integrator::BDYN_ADJ_ZERO, casadi::Integrator::BDYN_NUM_IN, casadi::Integrator::BDYN_OUT_ALG, casadi::Integrator::BDYN_OUT_ODE, casadi::Integrator::BDYN_OUT_QUAD, casadi::Integrator::BDYN_OUT_ZERO, casadi::Integrator::BDYN_P, casadi::Integrator::BDYN_T, casadi::Integrator::BDYN_U, casadi::Integrator::BDYN_X, casadi::Integrator::BDYN_Z, casadi::Integrator::BQUAD_ADJ_P, casadi::Integrator::BQUAD_ADJ_U, casadi::Integrator::BQUAD_NUM_OUT, casadi::OracleFunction::calc_sp_reverse(), casadi::FunctionInternal::forward_name(), casadi::SpReverseMem::iw, casadi::Integrator::nadj_, casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nrp1_, casadi::Integrator::nrq1_, casadi::Integrator::nrx1_, casadi::Integrator::nrz1_, casadi::Integrator::nu1_, casadi::Integrator::nuq1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::SpReverseMem::res, and casadi::SpReverseMem::w.

Referenced by casadi::Integrator::sp_reverse().

◆ cache()

Dict casadi::FunctionInternal::cache ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_26g

Definition at line 1105 of file function_internal.cpp.

1105  {
1106  // Return value
1107  Dict ret;
1108 
1109  // Retrieve all Function instances that haven't been deleted
1110  std::vector<std::string> keys;
1111  std::vector<Function> entries;
1112  cache_.cache(keys, entries);
1113 
1114  for (size_t i=0; i<keys.size(); ++i) {
1115  // Get the name of the key
1116  std::string s = keys[i];
1117  casadi_assert_dev(s.size() > 0);
1118  // Replace ':' with '_'
1119  std::replace(s.begin(), s.end(), ':', '_');
1120  // Remove trailing underscore, if any
1121  if (s.back() == '_') s.resize(s.size() - 1);
1122  // Add entry to function return
1123  ret[s] = entries[i];
1124  }
1125 
1126  return ret;
1127  }
WeakCache< std::string, Function > cache_
Function cache.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.

References casadi::FunctionInternal::cache_.

◆ calc_daeB()

int casadi::SundialsInterface::calc_daeB ( SundialsMemory m,
double  t,
const double *  x,
const double *  z,
const double *  adj_ode,
const double *  adj_alg,
const double *  adj_quad,
double *  adj_x,
double *  adj_z 
) const
inherited

Definition at line 595 of file sundials_interface.cpp.

597  {
598  // Evaluate nondifferentiated
599  m->arg[BDYN_T] = &t; // t
600  m->arg[BDYN_X] = x; // x
601  m->arg[BDYN_Z] = z; // z
602  m->arg[BDYN_P] = m->p; // p
603  m->arg[BDYN_U] = m->u; // u
604  m->arg[BDYN_OUT_ODE] = nullptr; // out_ode
605  m->arg[BDYN_OUT_ALG] = nullptr; // out_alg
606  m->arg[BDYN_OUT_QUAD] = nullptr; // out_quad
607  m->arg[BDYN_OUT_ZERO] = nullptr; // out_zero
608  m->arg[BDYN_ADJ_ODE] = adj_ode; // adj_ode
609  m->arg[BDYN_ADJ_ALG] = adj_alg; // adj_alg
610  m->arg[BDYN_ADJ_QUAD] = adj_quad; // adj_quad
611  m->arg[BDYN_ADJ_ZERO] = nullptr; // adj_zero
612  m->res[BDAE_ADJ_X] = adj_x; // adj_x
613  m->res[BDAE_ADJ_Z] = adj_z; // adj_z
614  // Issue #3353: zero-init when adj_* output is structurally empty
615  const Function& daeB = get_function("daeB");
616  if (adj_x && !daeB.nnz_out(BDAE_ADJ_X)) casadi_clear(adj_x, nrx1_ * nadj_);
617  if (adj_z && !daeB.nnz_out(BDAE_ADJ_Z)) casadi_clear(adj_z, nrz1_ * nadj_);
618  if (calc_function(m, "daeB")) return 1;
619  // Evaluate sensitivities
620  if (nfwd_ > 0) {
621  m->arg[BDYN_NUM_IN + BDAE_ADJ_X] = adj_x; // out:adj_x
622  m->arg[BDYN_NUM_IN + BDAE_ADJ_Z] = adj_z; // out:adj_z
623  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_T] = 0; // fwd:t
624  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_X] = x ? x + nx1_ : x; // fwd:x
625  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_Z] = z ? z + nz1_ : z; // fwd:z
626  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_P] = m->p + np1_; // fwd:p
627  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_U] = m->u + nu1_; // fwd:u
628  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_ODE] = nullptr; // fwd:out_ode
629  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_ALG] = nullptr; // fwd:out_alg
630  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_QUAD] = nullptr; // fwd:out_quad
631  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_OUT_ZERO] = nullptr; // fwd:out_zero
633  adj_ode ? adj_ode + nrx1_ * nadj_ : 0; // fwd:adj_ode
635  adj_alg ? adj_alg + nrz1_ * nadj_ : 0; // fwd:adj_alg
637  adj_quad ? adj_quad + nrp1_ * nadj_ : 0; // fwd:adj_quad
638  m->arg[BDYN_NUM_IN + BDAE_NUM_OUT + BDYN_ADJ_ZERO] = nullptr; // fwd:adj_zero
639  m->res[BDAE_ADJ_X] = adj_x ? adj_x + nrx1_ * nadj_ : 0; // fwd:adj_x
640  m->res[BDAE_ADJ_Z] = adj_z ? adj_z + nrz1_ * nadj_ : 0; // fwd:adj_z
641  const Function& fwd_daeB = get_function(forward_name("daeB", nfwd_));
642  if (adj_x && !fwd_daeB.nnz_out(BDAE_ADJ_X))
643  casadi_clear(adj_x + nrx1_ * nadj_, nrx1_ * nadj_ * nfwd_);
644  if (adj_z && !fwd_daeB.nnz_out(BDAE_ADJ_Z))
645  casadi_clear(adj_z + nrz1_ * nadj_, nrz1_ * nadj_ * nfwd_);
646  if (calc_function(m, forward_name("daeB", nfwd_))) return 1;
647  }
648  return 0;
649 }
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.
void casadi_clear(T1 *x, casadi_int n)
CLEAR: x <- 0.

References casadi::OracleMemory::arg, casadi::Integrator::BDAE_ADJ_X, casadi::Integrator::BDAE_ADJ_Z, casadi::Integrator::BDAE_NUM_OUT, casadi::Integrator::BDYN_ADJ_ALG, casadi::Integrator::BDYN_ADJ_ODE, casadi::Integrator::BDYN_ADJ_QUAD, casadi::Integrator::BDYN_ADJ_ZERO, casadi::Integrator::BDYN_NUM_IN, casadi::Integrator::BDYN_OUT_ALG, casadi::Integrator::BDYN_OUT_ODE, casadi::Integrator::BDYN_OUT_QUAD, casadi::Integrator::BDYN_OUT_ZERO, casadi::Integrator::BDYN_P, casadi::Integrator::BDYN_T, casadi::Integrator::BDYN_U, casadi::Integrator::BDYN_X, casadi::Integrator::BDYN_Z, casadi::OracleFunction::calc_function(), casadi::casadi_clear(), casadi::FunctionInternal::forward_name(), casadi::OracleFunction::get_function(), casadi::Integrator::nadj_, casadi::Integrator::nfwd_, casadi::Function::nnz_out(), casadi::Integrator::np1_, casadi::Integrator::nrp1_, casadi::Integrator::nrx1_, casadi::Integrator::nrz1_, casadi::Integrator::nu1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::IntegratorMemory::p, casadi::OracleMemory::res, and casadi::IntegratorMemory::u.

Referenced by casadi::IdasInterface::solve_transposed(), and casadi::IdasInterface::z_impulseB().

◆ calc_daeF()

int casadi::SundialsInterface::calc_daeF ( SundialsMemory m,
double  t,
const double *  x,
const double *  z,
double *  ode,
double *  alg 
) const
inherited

Definition at line 568 of file sundials_interface.cpp.

569  {
570  // Evaluate nondifferentiated
571  m->arg[DYN_T] = &t; // t
572  m->arg[DYN_X] = x; // x
573  m->arg[DYN_Z] = z; // z
574  m->arg[DYN_P] = m->p; // p
575  m->arg[DYN_U] = m->u; // u
576  m->res[DAE_ODE] = ode; // ode
577  m->res[DAE_ALG] = alg; // alg
578  if (calc_function(m, "daeF")) return 1;
579  // Evaluate sensitivities
580  if (nfwd_ > 0) {
581  m->arg[DYN_NUM_IN + DAE_ODE] = ode; // out:ode
582  m->arg[DYN_NUM_IN + DAE_ALG] = alg; // out:alg
583  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_T] = 0; // fwd:t
584  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_X] = x + nx1_; // fwd:x
585  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_Z] = z ? z + nz1_ : 0; // fwd:z
586  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_P] = m->p + np1_; // fwd:p
587  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_U] = m->u + nu1_; // fwd:u
588  m->res[DAE_ODE] = ode ? ode + nx1_ : 0; // fwd:ode
589  m->res[DAE_ALG] = alg ? alg + nz1_ : 0; // fwd:alg
590  if (calc_function(m, forward_name("daeF", nfwd_))) return 1;
591  }
592  return 0;
593 }
@ DYN_NUM_IN
Definition: integrator.hpp:196

References casadi::OracleMemory::arg, casadi::OracleFunction::calc_function(), casadi::Integrator::DAE_ALG, casadi::Integrator::DAE_NUM_OUT, casadi::Integrator::DAE_ODE, casadi::DYN_NUM_IN, casadi::DYN_P, casadi::DYN_T, casadi::DYN_U, casadi::DYN_X, casadi::DYN_Z, casadi::FunctionInternal::forward_name(), casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nu1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::IntegratorMemory::p, casadi::OracleMemory::res, and casadi::IntegratorMemory::u.

◆ calc_edot()

int casadi::Integrator::calc_edot ( IntegratorMemory m) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29o

Definition at line 2585 of file integrator.cpp.

2585  {
2586  // Evaluate the DAE and zero crossing function
2587  m->arg[DYN_T] = &m->t; // t
2588  m->arg[DYN_X] = m->x; // x
2589  m->arg[DYN_Z] = m->z; // z
2590  m->arg[DYN_P] = m->p; // p
2591  m->arg[DYN_U] = m->u; // u
2592  m->res[DYN_ODE] = m->xdot; // ode
2593  m->res[DYN_ALG] = m->tmp1 + nx_; // alg
2594  m->res[DYN_QUAD] = nullptr; // quad
2595  m->res[DYN_ZERO] = m->e; // zero
2596  if (calc_function(m, "dae")) return 1;
2597  // Calculate de_dt using by forward mode AD applied to zero crossing function
2598  // Note: Currently ignoring dependency propagation via algebraic equations
2599  double dt_dt = 1;
2600  m->arg[DYN_NUM_IN + DYN_ODE] = m->xdot; // out:ode
2601  m->arg[DYN_NUM_IN + DYN_ALG] = m->tmp1 + nx_; // out:alg
2602  m->arg[DYN_NUM_IN + DYN_QUAD] = nullptr; // out:quad
2603  m->arg[DYN_NUM_IN + DYN_ZERO] = m->e; // out:zero
2604  m->arg[DYN_NUM_IN + DYN_NUM_OUT + DYN_T] = &dt_dt; // fwd:t
2605  m->arg[DYN_NUM_IN + DYN_NUM_OUT + DYN_X] = m->xdot; // fwd:x
2606  m->arg[DYN_NUM_IN + DYN_NUM_OUT + DYN_Z] = nullptr; // fwd:z
2607  m->arg[DYN_NUM_IN + DYN_NUM_OUT + DYN_P] = nullptr; // fwd:p
2608  m->arg[DYN_NUM_IN + DYN_NUM_OUT + DYN_U] = nullptr; // fwd:u
2609  m->res[DYN_ODE] = nullptr; // fwd:ode
2610  m->res[DYN_ALG] = nullptr; // fwd:alg
2611  m->res[DYN_QUAD] = nullptr; // fwd:quad
2612  m->res[DYN_ZERO] = m->edot; // fwd:zero
2613  if (calc_function(m, forward_name("dae", 1))) return 1;
2614  // Success
2615  return 0;
2616 }
@ DYN_NUM_OUT
Definition: integrator.hpp:204

References casadi::OracleMemory::arg, casadi::OracleFunction::calc_function(), casadi::DYN_ALG, casadi::DYN_NUM_IN, casadi::DYN_NUM_OUT, casadi::DYN_ODE, casadi::DYN_P, casadi::DYN_QUAD, casadi::DYN_T, casadi::DYN_U, casadi::DYN_X, casadi::DYN_Z, casadi::DYN_ZERO, casadi::IntegratorMemory::e, casadi::IntegratorMemory::edot, casadi::FunctionInternal::forward_name(), casadi::Integrator::nx_, casadi::IntegratorMemory::p, casadi::OracleMemory::res, casadi::IntegratorMemory::t, casadi::IntegratorMemory::tmp1, casadi::IntegratorMemory::u, casadi::IntegratorMemory::x, casadi::IntegratorMemory::xdot, and casadi::IntegratorMemory::z.

Referenced by casadi::Integrator::advance(), casadi::Integrator::predict_events(), and casadi::Integrator::trigger_event().

◆ calc_function()

int casadi::OracleFunction::calc_function ( OracleMemory m,
const std::string &  fcn,
const double *const *  arg = nullptr,
int  thread_id = 0 
) const
inherited

Definition at line 302 of file oracle_function.cpp.

304  {
305  auto *ml = m->thread_local_mem.at(thread_id);
306  // Is the function monitored?
307  bool monitored = this->monitored(fcn);
308 
309  // Print progress
310  if (monitored) casadi_message("Calling \"" + fcn + "\"");
311 
312  // Respond to a possible Crl+C signals
313  // Python interrupt checker needs the GIL.
314  // We may not have access to it in a multi-threaded context
315  // See issue #2955
317 
318  // Get function
319  const Function& f = get_function(fcn);
320 
321  // Get statistics structure
322  FStats& fstats = ml->fstats.at(fcn);
323 
324  // Number of inputs and outputs
325  casadi_int n_in = f.n_in(), n_out = f.n_out();
326 
327  // Prepare stats, start timer
328  ScopedTiming tic(fstats);
329 
330  // Input buffers
331  if (arg) {
332  std::fill_n(ml->arg, n_in, nullptr);
333  for (casadi_int i=0; i<n_in; ++i) ml->arg[i] = *arg++;
334  }
335 
336  // Print inputs nonzeros
337  if (monitored) {
338  std::stringstream s;
339  s << fcn << " input nonzeros:\n";
340  for (casadi_int i=0; i<n_in; ++i) {
341  s << " " << i << " (" << f.name_in(i) << "): ";
342  if (ml->arg[i]) {
343  // Print nonzeros
344  s << "[";
345  for (casadi_int k=0; k<f.nnz_in(i); ++k) {
346  if (k!=0) s << ", ";
347  DM::print_scalar(s, ml->arg[i][k]);
348  }
349  s << "]\n";
350  } else {
351  // All zero input
352  s << "0\n";
353  }
354  }
355  casadi_message(s.str());
356  }
357 
358  // Evaluate memory-less
359  try {
360  if (f(ml->arg, ml->res, ml->iw, ml->w)) {
361  // Recoverable error
362  if (monitored) casadi_message(name_ + ":" + fcn + " failed");
363  return 1;
364  }
365  } catch(std::exception& ex) {
366  // Fatal error: Generate stack trace
367  casadi_error("Error in " + name_ + ":" + fcn + ":" + std::string(ex.what()));
368  }
369 
370  // Print output nonzeros
371  if (monitored) {
372  std::stringstream s;
373  s << fcn << " output nonzeros:\n";
374  for (casadi_int i=0; i<n_out; ++i) {
375  s << " " << i << " (" << f.name_out(i) << "): ";
376  if (ml->res[i]) {
377  // Print nonzeros
378  s << "[";
379  for (casadi_int k=0; k<f.nnz_out(i); ++k) {
380  if (k!=0) s << ", ";
381  DM::print_scalar(s, ml->res[i][k]);
382  }
383  s << "]\n";
384  } else {
385  // Ignored output
386  s << " N/A\n";
387  }
388  }
389  casadi_message(s.str());
390  }
391 
392  // Make sure not NaN or Inf
393  for (casadi_int i=0; i<n_out; ++i) {
394  if (!ml->res[i]) continue;
395  if (!std::all_of(ml->res[i], ml->res[i]+f.nnz_out(i), [](double v) { return isfinite(v);})) {
396  std::stringstream ss;
397 
398  auto *it = std::find_if(ml->res[i], ml->res[i] + f.nnz_out(i),
399  [](double v) { return !isfinite(v);});
400  casadi_int k = std::distance(ml->res[i], it);
401  bool is_nan = isnan(ml->res[i][k]);
402  ss << name_ << ":" << fcn << " failed: " << (is_nan? "NaN" : "Inf") <<
403  " detected for output " << f.name_out(i) << ", at " << f.sparsity_out(i).repr_el(k) << ".";
404 
405  if (regularity_check_) {
406  casadi_error(ss.str());
407  } else {
408  if (show_eval_warnings_) casadi_warning(ss.str());
409  }
410  return -1;
411  }
412  }
413 
414  // Success
415  return 0;
416 }
static void check()
Raises an error if an interrupt was captured.
void print_scalar(std::ostream &stream) const
Print scalar.
virtual bool monitored(const std::string &name) const
bool show_eval_warnings_
Show evaluation warnings.
bool regularity_check_
Errors are thrown when NaN is produced.

References casadi::InterruptHandler::check(), casadi::OracleFunction::get_function(), casadi::OracleFunction::max_num_threads_, casadi::OracleFunction::monitored(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::ProtoFunction::name_, casadi::Function::name_in(), casadi::Function::name_out(), casadi::Function::nnz_in(), casadi::Function::nnz_out(), casadi::Matrix< double >::print_scalar(), casadi::ProtoFunction::regularity_check_, casadi::Sparsity::repr_el(), casadi::OracleFunction::show_eval_warnings_, casadi::Function::sparsity_out(), and casadi::OracleMemory::thread_local_mem.

Referenced by casadi::KinsolInterface::bjac(), casadi::SundialsInterface::calc_daeB(), casadi::SundialsInterface::calc_daeF(), casadi::Integrator::calc_edot(), casadi::calc_function(), casadi::SundialsInterface::calc_jacF(), casadi::SundialsInterface::calc_jtimesF(), casadi::SundialsInterface::calc_quadB(), casadi::SundialsInterface::calc_quadF(), casadi::casadi_func_cons_jac(), casadi::casadi_func_cons_val(), casadi::casadi_func_hess_prod(), casadi::casadi_func_obj_grad(), casadi::casadi_func_obj_val(), casadi::KinsolInterface::djac(), casadi::Nlpsol::eval(), casadi::AlpaqaProblem::eval_f(), casadi::BonminUserClass::eval_f(), casadi::IpoptUserClass::eval_f(), casadi::AlpaqaProblem::eval_f_grad_f(), casadi::AlpaqaProblem::eval_g(), casadi::BonminUserClass::eval_g(), casadi::IpoptUserClass::eval_g(), casadi::BonminUserClass::eval_grad_f(), casadi::IpoptUserClass::eval_grad_f(), casadi::AlpaqaProblem::eval_grad_L(), casadi::BonminUserClass::eval_h(), casadi::IpoptUserClass::eval_h(), casadi::AlpaqaProblem::eval_hess_L(), casadi::AlpaqaProblem::eval_hess_L_prod(), casadi::AlpaqaProblem::eval_hess_ψ(), casadi::AlpaqaProblem::eval_hess_ψ_prod(), casadi::AlpaqaProblem::eval_jac_g(), casadi::BonminUserClass::eval_jac_g(), casadi::IpoptUserClass::eval_jac_g(), casadi::AlpaqaProblem::eval_ψ(), casadi::AlpaqaProblem::eval_ψ_grad_ψ(), casadi::Blocksqp::evaluate(), casadi::Feasiblesqpmethod::feasibility_iterations(), casadi::KinsolInterface::psetup(), casadi::KnitroInterface::solve(), casadi::SnoptInterface::solve(), casadi::WorhpInterface::solve(), casadi::Feasiblesqpmethod::solve(), casadi::Newton::solve(), casadi::Qrsqp::solve(), casadi::Sqpmethod::solve(), casadi::FixedStepIntegrator::stepB(), casadi::FixedStepIntegrator::stepF(), casadi::Integrator::trigger_event(), and casadi::SnoptInterface::userfun().

◆ calc_jacF()

int casadi::SundialsInterface::calc_jacF ( SundialsMemory m,
double  t,
const double *  x,
const double *  z,
double *  jac_ode_x,
double *  jac_alg_x,
double *  jac_ode_z,
double *  jac_alg_z 
) const
inherited

Definition at line 760 of file sundials_interface.cpp.

761  {
762  // Calculate Jacobian
763  m->arg[DYN_T] = &t;
764  m->arg[DYN_X] = x;
765  m->arg[DYN_Z] = z;
766  m->arg[DYN_P] = m->p;
767  m->arg[DYN_U] = m->u;
768  m->res[JACF_ODE_X] = jac_ode_x;
769  m->res[JACF_ALG_X] = jac_alg_x;
770  m->res[JACF_ODE_Z] = jac_ode_z;
771  m->res[JACF_ALG_Z] = jac_alg_z;
772  return calc_function(m, "jacF");
773 }

References casadi::OracleMemory::arg, casadi::OracleFunction::calc_function(), casadi::DYN_P, casadi::DYN_T, casadi::DYN_U, casadi::DYN_X, casadi::DYN_Z, casadi::SundialsInterface::JACF_ALG_X, casadi::SundialsInterface::JACF_ALG_Z, casadi::SundialsInterface::JACF_ODE_X, casadi::SundialsInterface::JACF_ODE_Z, casadi::IntegratorMemory::p, casadi::OracleMemory::res, and casadi::IntegratorMemory::u.

◆ calc_jtimesF()

int casadi::SundialsInterface::calc_jtimesF ( SundialsMemory m,
double  t,
const double *  x,
const double *  z,
const double *  fwd_x,
const double *  fwd_z,
double *  fwd_ode,
double *  fwd_alg 
) const
inherited

Definition at line 728 of file sundials_interface.cpp.

729  {
730  // Evaluate nondifferentiated
731  m->arg[JTIMESF_T] = &t; // t
732  m->arg[JTIMESF_X] = x; // x
733  m->arg[JTIMESF_Z] = z; // z
734  m->arg[JTIMESF_P] = m->p; // p
735  m->arg[JTIMESF_U] = m->u; // u
736  m->arg[JTIMESF_FWD_X] = fwd_x; // fwd:x
737  m->arg[JTIMESF_FWD_Z] = fwd_z; // fwd:z
738  m->res[JTIMESF_FWD_ODE] = fwd_ode; // fwd:ode
739  m->res[JTIMESF_FWD_ALG] = fwd_alg; // fwd:alg
740  if (calc_function(m, "jtimesF")) return 1;
741  // Evaluate sensitivities
742  if (nfwd_ > 0) {
743  m->arg[JTIMESF_NUM_IN + JTIMESF_FWD_ODE] = fwd_ode; // out:fwd:ode
744  m->arg[JTIMESF_NUM_IN + JTIMESF_FWD_ALG] = fwd_alg; // out:fwd:alg
745  m->arg[JTIMESF_NUM_IN + JTIMESF_NUM_OUT + JTIMESF_T] = 0; // fwd:t
746  m->arg[JTIMESF_NUM_IN + JTIMESF_NUM_OUT + JTIMESF_X] = x + nx1_; // fwd:x
747  m->arg[JTIMESF_NUM_IN + JTIMESF_NUM_OUT + JTIMESF_Z] = z + nz1_; // fwd:z
748  m->arg[JTIMESF_NUM_IN + JTIMESF_NUM_OUT + JTIMESF_P] = m->p + np1_; // fwd:p
749  m->arg[JTIMESF_NUM_IN + JTIMESF_NUM_OUT + JTIMESF_U] = m->u + nu1_; // fwd:u
750  m->arg[JTIMESF_NUM_IN + JTIMESF_NUM_OUT + JTIMESF_FWD_X] = fwd_x + nx1_; // fwd:fwd:x
751  m->arg[JTIMESF_NUM_IN + JTIMESF_NUM_OUT + JTIMESF_FWD_Z] = fwd_z + nz1_; // fwd:fwd:z
752  m->res[JTIMESF_FWD_ODE] = fwd_ode + nx1_; // fwd:fwd:ode
753  m->res[JTIMESF_FWD_ALG] = fwd_alg + nz1_; // fwd:fwd:alg
754  if (calc_function(m, forward_name("jtimesF", nfwd_))) return 1;
755  }
756  // Successful return
757  return 0;
758 }

References casadi::OracleMemory::arg, casadi::OracleFunction::calc_function(), casadi::FunctionInternal::forward_name(), casadi::SundialsInterface::JTIMESF_FWD_ALG, casadi::SundialsInterface::JTIMESF_FWD_ODE, casadi::SundialsInterface::JTIMESF_FWD_X, casadi::SundialsInterface::JTIMESF_FWD_Z, casadi::SundialsInterface::JTIMESF_NUM_IN, casadi::SundialsInterface::JTIMESF_NUM_OUT, casadi::SundialsInterface::JTIMESF_P, casadi::SundialsInterface::JTIMESF_T, casadi::SundialsInterface::JTIMESF_U, casadi::SundialsInterface::JTIMESF_X, casadi::SundialsInterface::JTIMESF_Z, casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nu1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::IntegratorMemory::p, casadi::OracleMemory::res, and casadi::IntegratorMemory::u.

◆ calc_quadB()

int casadi::SundialsInterface::calc_quadB ( SundialsMemory m,
double  t,
const double *  x,
const double *  z,
const double *  adj_ode,
const double *  adj_alg,
double *  adj_p,
double *  adj_u 
) const
inherited

Definition at line 674 of file sundials_interface.cpp.

675  {
676  // Evaluate nondifferentiated
677  m->arg[BDYN_T] = &t; // t
678  m->arg[BDYN_X] = x; // x
679  m->arg[BDYN_Z] = z; // z
680  m->arg[BDYN_P] = m->p; // p
681  m->arg[BDYN_U] = m->u; // u
682  m->arg[BDYN_OUT_ODE] = nullptr; // out_ode
683  m->arg[BDYN_OUT_ALG] = nullptr; // out_alg
684  m->arg[BDYN_OUT_QUAD] = nullptr; // out_quad
685  m->arg[BDYN_OUT_ZERO] = nullptr; // out_zero
686  m->arg[BDYN_ADJ_ODE] = adj_ode; // adj_ode
687  m->arg[BDYN_ADJ_ALG] = adj_alg; // adj_alg
688  m->arg[BDYN_ADJ_QUAD] = m->adj_q; // adj_quad
689  m->arg[BDYN_ADJ_ZERO] = nullptr; // adj_zero
690  m->res[BQUAD_ADJ_P] = adj_p; // adj_p
691  m->res[BQUAD_ADJ_U] = adj_u; // adj_u
692  // Issue #3353: zero-init when adj_* output is structurally empty
693  const Function& quadB = get_function("quadB");
694  if (adj_p && !quadB.nnz_out(BQUAD_ADJ_P)) casadi_clear(adj_p, nrq1_ * nadj_);
695  if (adj_u && !quadB.nnz_out(BQUAD_ADJ_U)) casadi_clear(adj_u, nuq1_ * nadj_);
696  if (calc_function(m, "quadB")) return 1;
697  // Evaluate sensitivities
698  if (nfwd_ > 0) {
699  m->arg[BDYN_NUM_IN + BQUAD_ADJ_P] = adj_p; // out:adj_p
700  m->arg[BDYN_NUM_IN + BQUAD_ADJ_U] = adj_u; // out:adj_u
701  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_T] = 0; // fwd:t
702  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_X] = x ? x + nx1_ : 0; // fwd:x
703  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_Z] = z ? z + nz1_ : 0; // fwd:z
704  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_P] = m->p + np1_; // fwd:p
705  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_U] = m->u + nu1_; // fwd:u
706  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_ODE] = nullptr; // fwd:out_ode
707  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_ALG] = nullptr; // fwd:out_alg
708  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_QUAD] = nullptr; // fwd:out_quad
709  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_OUT_ZERO] = nullptr; // fwd:out_zero
711  adj_ode ? adj_ode + nrx1_ * nadj_ : 0; // fwd:adj_ode
713  adj_alg ? adj_alg + nrz1_ * nadj_ : 0; // fwd:adj_alg
714  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_ADJ_QUAD] = m->adj_q + nrp1_ * nadj_; // fwd:adj_quad
715  m->arg[BDYN_NUM_IN + BQUAD_NUM_OUT + BDYN_ADJ_ZERO] = nullptr; // fwd:adj_zero
716  m->res[BQUAD_ADJ_P] = adj_p + nrq1_ * nadj_; // fwd:adj_p
717  m->res[BQUAD_ADJ_U] = adj_u + nuq1_ * nadj_; // fwd:adj_u
718  const Function& fwd_quadB = get_function(forward_name("quadB", nfwd_));
719  if (adj_p && !fwd_quadB.nnz_out(BQUAD_ADJ_P))
720  casadi_clear(adj_p + nrq1_ * nadj_, nrq1_ * nadj_ * nfwd_);
721  if (adj_u && !fwd_quadB.nnz_out(BQUAD_ADJ_U))
722  casadi_clear(adj_u + nuq1_ * nadj_, nuq1_ * nadj_ * nfwd_);
723  if (calc_function(m, forward_name("quadB", nfwd_))) return 1;
724  }
725  return 0;
726 }

References casadi::IntegratorMemory::adj_q, casadi::OracleMemory::arg, casadi::Integrator::BDYN_ADJ_ALG, casadi::Integrator::BDYN_ADJ_ODE, casadi::Integrator::BDYN_ADJ_QUAD, casadi::Integrator::BDYN_ADJ_ZERO, casadi::Integrator::BDYN_NUM_IN, casadi::Integrator::BDYN_OUT_ALG, casadi::Integrator::BDYN_OUT_ODE, casadi::Integrator::BDYN_OUT_QUAD, casadi::Integrator::BDYN_OUT_ZERO, casadi::Integrator::BDYN_P, casadi::Integrator::BDYN_T, casadi::Integrator::BDYN_U, casadi::Integrator::BDYN_X, casadi::Integrator::BDYN_Z, casadi::Integrator::BQUAD_ADJ_P, casadi::Integrator::BQUAD_ADJ_U, casadi::Integrator::BQUAD_NUM_OUT, casadi::OracleFunction::calc_function(), casadi::casadi_clear(), casadi::FunctionInternal::forward_name(), casadi::OracleFunction::get_function(), casadi::Integrator::nadj_, casadi::Integrator::nfwd_, casadi::Function::nnz_out(), casadi::Integrator::np1_, casadi::Integrator::nrp1_, casadi::Integrator::nrq1_, casadi::Integrator::nrx1_, casadi::Integrator::nrz1_, casadi::Integrator::nu1_, casadi::Integrator::nuq1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::IntegratorMemory::p, casadi::OracleMemory::res, and casadi::IntegratorMemory::u.

◆ calc_quadF()

int casadi::SundialsInterface::calc_quadF ( SundialsMemory m,
double  t,
const double *  x,
const double *  z,
double *  quad 
) const
inherited

Definition at line 651 of file sundials_interface.cpp.

652  {
653  m->arg[DYN_T] = &t; // t
654  m->arg[DYN_X] = x; // x
655  m->arg[DYN_Z] = z; // z
656  m->arg[DYN_P] = m->p; // p
657  m->arg[DYN_U] = m->u; // u
658  m->res[QUAD_QUAD] = quad; // quad
659  if (calc_function(m, "quadF")) return 1;
660  // Evaluate sensitivities
661  if (nfwd_ > 0) {
662  m->arg[DYN_NUM_IN + QUAD_QUAD] = quad; // out:quad
663  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_T] = 0; // fwd:t
664  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_X] = x + nx1_; // fwd:x
665  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_Z] = z ? z + nz1_ : 0; // fwd:z
666  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_P] = m->p + np1_; // fwd:p
667  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_U] = m->u + nu1_; // fwd:u
668  m->res[QUAD_QUAD] = quad ? quad + nq1_ : 0; // fwd:quad
669  if (calc_function(m, forward_name("quadF", nfwd_))) return 1;
670  }
671  return 0;
672 }

References casadi::OracleMemory::arg, casadi::OracleFunction::calc_function(), casadi::DYN_NUM_IN, casadi::DYN_P, casadi::DYN_T, casadi::DYN_U, casadi::DYN_X, casadi::DYN_Z, casadi::FunctionInternal::forward_name(), casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nq1_, casadi::Integrator::nu1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::IntegratorMemory::p, casadi::Integrator::QUAD_NUM_OUT, casadi::Integrator::QUAD_QUAD, casadi::OracleMemory::res, and casadi::IntegratorMemory::u.

◆ calc_sp_forward()

int casadi::OracleFunction::calc_sp_forward ( const std::string &  fcn,
const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w 
) const
inherited

◆ calc_sp_reverse()

int casadi::OracleFunction::calc_sp_reverse ( const std::string &  fcn,
bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w 
) const
inherited

◆ call()

template<typename M >
void casadi::FunctionInternal::call ( const std::vector< M > &  arg,
std::vector< M > &  res,
bool  always_inline,
bool  never_inline 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kh

Definition at line 1615 of file function_internal.hpp.

1616  {
1617  // If all inputs are scalar ...
1618  if (all_scalar()) {
1619  // ... and some arguments are matrix-valued with matching dimensions ...
1620  bool matrix_call = false;
1621  std::pair<casadi_int, casadi_int> sz;
1622  for (auto&& a : arg) {
1623  if (!a.is_scalar() && !a.is_empty()) {
1624  if (!matrix_call) {
1625  // Matrix call
1626  matrix_call = true;
1627  sz = a.size();
1628  } else if (a.size()!=sz) {
1629  // Not same dimensions
1630  matrix_call = false;
1631  break;
1632  }
1633  }
1634  }
1635 
1636  // ... then, call multiple times
1637  if (matrix_call) {
1638  // Start with zeros
1639  res.resize(n_out_);
1640  M z = M::zeros(sz);
1641  for (auto&& a : res) a = z;
1642  // Call multiple times
1643  std::vector<M> arg1 = arg, res1;
1644  for (casadi_int c=0; c<sz.second; ++c) {
1645  for (casadi_int r=0; r<sz.first; ++r) {
1646  // Get scalar arguments
1647  for (casadi_int i=0; i<arg.size(); ++i) {
1648  if (arg[i].size()==sz) arg1[i] = arg[i](r, c);
1649  }
1650  // Call recursively with scalar arguments
1651  call(arg1, res1, always_inline, never_inline);
1652  // Get results
1653  casadi_assert_dev(res.size() == res1.size());
1654  for (casadi_int i=0; i<res.size(); ++i) res[i](r, c) = res1[i];
1655  }
1656  }
1657  // All elements assigned
1658  return;
1659  }
1660  }
1661 
1662  // Check if inputs need to be replaced
1663  casadi_int npar = 1;
1664  if (!matching_arg(arg, npar)) {
1665  return call(replace_arg(arg, npar), res, always_inline, never_inline);
1666  }
1667 
1668  // Call the type-specific method
1669  call_gen(arg, res, npar, always_inline, never_inline);
1670  }
void call_gen(const MXVector &arg, MXVector &res, casadi_int npar, bool always_inline, bool never_inline) const
Call a function, overloaded.
std::vector< M > replace_arg(const std::vector< M > &arg, casadi_int npar) const
Replace 0-by-0 inputs.
bool matching_arg(const std::vector< M > &arg, casadi_int &npar) const
Check if input arguments that needs to be replaced.
void call(const std::vector< M > &arg, std::vector< M > &res, bool always_inline, bool never_inline) const
Call a function, templated.
bool all_scalar() const
Are all inputs and outputs scalar.

References casadi::FunctionInternal::all_scalar(), casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::replace_arg().

◆ call_forward() [1/2]

void casadi::FunctionInternal::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
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ku

Definition at line 3217 of file function_internal.cpp.

3221  {
3222  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3223  casadi_assert(!always_inline, "Class " + class_name() +
3224  " cannot be inlined in an MX expression");
3225 
3226  // Derivative information must be available
3227  casadi_assert(has_derivative(),
3228  "Derivatives cannot be calculated for " + name_);
3229 
3230  // Number of directional derivatives
3231  casadi_int nfwd = fseed.size();
3232  fsens.resize(nfwd);
3233 
3234  // Quick return if no seeds
3235  if (nfwd==0) return;
3236 
3237  // Check if seeds need to have dimensions corrected
3238  casadi_int npar = 1;
3239  for (auto&& r : fseed) {
3240  if (!matching_arg(r, npar)) {
3241  FunctionInternal::call_forward(arg, res, replace_fseed(fseed, npar),
3242  fsens, always_inline, never_inline);
3243  return;
3244  }
3245  }
3246 
3247  // Calculating full Jacobian and then multiplying
3248  if (fwdViaJac(nfwd)) {
3249  // Multiply the Jacobian from the right
3250  std::vector<MX> darg = arg;
3251  darg.insert(darg.end(), res.begin(), res.end());
3252  std::vector<MX> J = jacobian()(darg);
3253  // Join forward seeds
3254  std::vector<MX> v(nfwd), all_fseed(n_in_);
3255  for (size_t i = 0; i < n_in_; ++i) {
3256  for (size_t d = 0; d < nfwd; ++d) v[d] = vec(fseed.at(d).at(i));
3257  all_fseed[i] = horzcat(v);
3258  }
3259  // Calculate forward sensitivities
3260  std::vector<MX> all_fsens(n_out_);
3261  std::vector<MX>::const_iterator J_it = J.begin();
3262  for (size_t oind = 0; oind < n_out_; ++oind) {
3263  for (size_t iind = 0; iind < n_in_; ++iind) {
3264  // Add contribution
3265  MX a = mtimes(*J_it++, all_fseed[iind]);
3266  all_fsens[oind] = all_fsens[oind].is_empty(true) ? a : all_fsens[oind] + a;
3267  }
3268  }
3269  // Split forward sensitivities
3270  for (size_t d = 0; d < nfwd; ++d) fsens[d].resize(n_out_);
3271  for (size_t i = 0; i < n_out_; ++i) {
3272  v = horzsplit(all_fsens[i]);
3273  casadi_assert_dev(v.size() == nfwd);
3274  for (size_t d = 0; d < nfwd; ++d) fsens[d][i] = reshape(v[d], size_out(i));
3275  }
3276  } else {
3277  // Evaluate in batches
3278  casadi_assert_dev(enable_forward_ || enable_fd_);
3279  casadi_int max_nfwd = max_num_dir_;
3280  if (!enable_fd_) {
3281  while (!has_forward(max_nfwd)) max_nfwd/=2;
3282  }
3283  casadi_int offset = 0;
3284  while (offset<nfwd) {
3285  // Number of derivatives, in this batch
3286  casadi_int nfwd_batch = std::min(nfwd-offset, max_nfwd);
3287 
3288  // All inputs and seeds
3289  std::vector<MX> darg;
3290  darg.reserve(n_in_ + n_out_ + n_in_);
3291  darg.insert(darg.end(), arg.begin(), arg.end());
3292  darg.insert(darg.end(), res.begin(), res.end());
3293  std::vector<MX> v(nfwd_batch);
3294  for (casadi_int i=0; i<n_in_; ++i) {
3295  for (casadi_int d=0; d<nfwd_batch; ++d) v[d] = fseed[offset+d][i];
3296  darg.push_back(horzcat(v));
3297  }
3298 
3299  // Create the evaluation node
3300  Function dfcn = self().forward(nfwd_batch);
3301  std::vector<MX> x = dfcn(darg);
3302 
3303  casadi_assert_dev(x.size()==n_out_);
3304 
3305  // Retrieve sensitivities
3306  for (casadi_int d=0; d<nfwd_batch; ++d) fsens[offset+d].resize(n_out_);
3307  for (casadi_int i=0; i<n_out_; ++i) {
3308  if (size2_out(i)>0) {
3309  v = horzsplit(x[i], size2_out(i));
3310  casadi_assert_dev(v.size()==nfwd_batch);
3311  } else {
3312  v = std::vector<MX>(nfwd_batch, MX(size_out(i)));
3313  }
3314  for (casadi_int d=0; d<nfwd_batch; ++d) fsens[offset+d][i] = v[d];
3315  }
3316 
3317  // Update offset
3318  offset += nfwd_batch;
3319  }
3320  }
3321  }
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.
Function forward(casadi_int nfwd) const
Return function that calculates forward derivatives.
virtual bool has_forward(casadi_int nfwd) const
Return function that calculates forward derivatives.
std::vector< std::vector< M > > replace_fseed(const std::vector< std::vector< M >> &fseed, casadi_int npar) const
Replace 0-by-0 forward seeds.
bool has_derivative() const
Can derivatives be calculated in any way?
casadi_int size2_out(casadi_int ind) const
Input/output dimensions.
std::pair< casadi_int, casadi_int > size_out(casadi_int ind) const
Input/output dimensions.
casadi_int max_num_dir_
Maximum number of sensitivity directions.
virtual bool fwdViaJac(casadi_int nfwd) const
Calculate derivatives by multiplying the full Jacobian and multiplying.
Function jacobian() const
Return Jacobian of all input elements with respect to all output elements.
virtual std::string class_name() const =0
Readable name of the internal class.

References casadi::SharedObjectInternal::class_name(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::forward(), casadi::FunctionInternal::fwdViaJac(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::has_forward(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::replace_fseed(), casadi::FunctionInternal::size2_out(), and casadi::FunctionInternal::size_out().

Referenced by casadi::Rootfinder::ad_forward(), casadi::Call::ad_forward(), casadi::MXFunction::ad_forward(), casadi::XFunction< DerivedType, MatType, NodeType >::call_forward(), casadi::MX::forward(), casadi::Integrator::get_forward_dae(), and casadi::Scpgen::init().

◆ call_forward() [2/2]

void casadi::FunctionInternal::call_forward ( const std::vector< SX > &  arg,
const std::vector< SX > &  res,
const std::vector< std::vector< SX > > &  fseed,
std::vector< std::vector< SX > > &  fsens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ku

Definition at line 3438 of file function_internal.cpp.

3442  {
3443  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3444  if (fseed.empty()) { // Quick return if no seeds
3445  fsens.clear();
3446  return;
3447  }
3448  casadi_error("'forward' (SX) not defined for " + class_name());
3449  }

References casadi::SharedObjectInternal::class_name().

◆ call_gen() [1/2]

void casadi::FunctionInternal::call_gen ( const MXVector arg,
MXVector res,
casadi_int  npar,
bool  always_inline,
bool  never_inline 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kg

Definition at line 4125 of file function_internal.cpp.

4127  {
4128  if (npar==1) {
4129  eval_mx(arg, res, always_inline, never_inline);
4130  } else {
4131  // Split it up arguments
4132  std::vector<std::vector<MX>> v(npar, arg);
4133  std::vector<MX> t;
4134  for (int i=0; i<n_in_; ++i) {
4135  if (arg[i].size2()!=size2_in(i)) {
4136  t = horzsplit(arg[i], size2_in(i));
4137  casadi_assert_dev(t.size()==npar);
4138  for (int p=0; p<npar; ++p) v[p][i] = t[p];
4139  }
4140  }
4141  // Unroll the loop
4142  for (int p=0; p<npar; ++p) {
4143  eval_mx(v[p], t, always_inline, never_inline);
4144  v[p] = t;
4145  }
4146  // Concatenate results
4147  t.resize(npar);
4148  res.resize(n_out_);
4149  for (int i=0; i<n_out_; ++i) {
4150  for (int p=0; p<npar; ++p) t[p] = v[p][i];
4151  res[i] = horzcat(t);
4152  }
4153  }
4154  }
virtual void eval_mx(const MXVector &arg, MXVector &res, bool always_inline, bool never_inline) const
Evaluate with symbolic matrices.
casadi_int size2_in(casadi_int ind) const
Input/output dimensions.

References casadi::FunctionInternal::eval_mx(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::size2_in().

Referenced by casadi::FunctionInternal::call().

◆ call_gen() [2/2]

template<typename D >
void casadi::FunctionInternal::call_gen ( const std::vector< Matrix< D > > &  arg,
std::vector< Matrix< D > > &  res,
casadi_int  npar,
bool  always_inline,
bool  never_inline 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kg

Definition at line 1719 of file function_internal.hpp.

1721  {
1722  std::vector< Matrix<D> > arg2 = project_arg(arg, npar);
1723 
1724  // Which arguments require mapped evaluation
1725  std::vector<bool> mapped(n_in_);
1726  for (casadi_int i=0; i<n_in_; ++i) {
1727  mapped[i] = arg[i].size2()!=size2_in(i);
1728  }
1729 
1730  // Allocate results
1731  res.resize(n_out_);
1732  for (casadi_int i=0; i<n_out_; ++i) {
1733  if (!res[i].sparsity().is_stacked(sparsity_out(i), npar)) {
1734  res[i] = Matrix<D>::zeros(repmat(sparsity_out(i), 1, npar));
1735  }
1736  }
1737 
1738  // Allocate temporary memory if needed
1739  std::vector<casadi_int> iw_tmp(sz_iw());
1740  std::vector<D> w_tmp(sz_w());
1741 
1742  // Get pointers to input arguments
1743  std::vector<const D*> argp(sz_arg());
1744  for (casadi_int i=0; i<n_in_; ++i) argp[i]=get_ptr(arg2[i]);
1745 
1746  // Get pointers to output arguments
1747  std::vector<D*> resp(sz_res());
1748  for (casadi_int i=0; i<n_out_; ++i) resp[i]=get_ptr(res[i]);
1749 
1750  // For all parallel calls
1751  for (casadi_int p=0; p<npar; ++p) {
1752  // Call memory-less
1753  if (eval_gen(get_ptr(argp), get_ptr(resp),
1754  get_ptr(iw_tmp), get_ptr(w_tmp), memory(0),
1755  always_inline, never_inline)) {
1756  if (error_on_fail_) casadi_error("Evaluation failed");
1757  }
1758  // Update offsets
1759  if (p==npar-1) break;
1760  for (casadi_int i=0; i<n_in_; ++i) if (mapped[i]) argp[i] += nnz_in(i);
1761  for (casadi_int i=0; i<n_out_; ++i) resp[i] += nnz_out(i);
1762  }
1763  }
std::vector< M > project_arg(const std::vector< M > &arg, casadi_int npar) const
Project sparsities.
const Sparsity & sparsity_out(casadi_int ind) const
Input/output sparsity.
int eval_gen(const double **arg, double **res, casadi_int *iw, double *w, void *mem, bool always_inline, bool never_inline) const
Evaluate numerically.
static Matrix< Scalar > zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
bool error_on_fail_
Throw an exception on failure?
void * memory(int ind) const
Memory objects.
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.

References casadi::ProtoFunction::error_on_fail_, casadi::FunctionInternal::eval_gen(), casadi::get_ptr(), casadi::ProtoFunction::memory(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::project_arg(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::sparsity_out(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), and casadi::GenericMatrix< Matrix< Scalar > >::zeros().

◆ call_reverse() [1/2]

void casadi::FunctionInternal::call_reverse ( const std::vector< MX > &  arg,
const std::vector< MX > &  res,
const std::vector< std::vector< MX > > &  aseed,
std::vector< std::vector< MX > > &  asens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kv

Definition at line 3323 of file function_internal.cpp.

3327  {
3328  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3329  casadi_assert(!always_inline, "Class " + class_name() +
3330  " cannot be inlined in an MX expression");
3331 
3332  // Derivative information must be available
3333  casadi_assert(has_derivative(),
3334  "Derivatives cannot be calculated for " + name_);
3335 
3336  // Number of directional derivatives
3337  casadi_int nadj = aseed.size();
3338  asens.resize(nadj);
3339 
3340  // Quick return if no seeds
3341  if (nadj==0) return;
3342 
3343  // Check if seeds need to have dimensions corrected
3344  casadi_int npar = 1;
3345  for (auto&& r : aseed) {
3346  if (!matching_res(r, npar)) {
3347  FunctionInternal::call_reverse(arg, res, replace_aseed(aseed, npar),
3348  asens, always_inline, never_inline);
3349  return;
3350  }
3351  }
3352 
3353  // Calculating full Jacobian and then multiplying likely cheaper
3354  if (adjViaJac(nadj)) {
3355  // Multiply the transposed Jacobian from the right
3356  std::vector<MX> darg = arg;
3357  darg.insert(darg.end(), res.begin(), res.end());
3358  std::vector<MX> J = jacobian()(darg);
3359  // Join adjoint seeds
3360  std::vector<MX> v(nadj), all_aseed(n_out_);
3361  for (size_t i = 0; i < n_out_; ++i) {
3362  for (size_t d = 0; d < nadj; ++d) v[d] = vec(aseed.at(d).at(i));
3363  all_aseed[i] = horzcat(v);
3364  }
3365  // Calculate adjoint sensitivities
3366  std::vector<MX> all_asens(n_in_);
3367  std::vector<MX>::const_iterator J_it = J.begin();
3368  for (size_t oind = 0; oind < n_out_; ++oind) {
3369  for (size_t iind = 0; iind < n_in_; ++iind) {
3370  // Add contribution
3371  MX a = mtimes((*J_it++).T(), all_aseed[oind]);
3372  all_asens[iind] = all_asens[iind].is_empty(true) ? a : all_asens[iind] + a;
3373  }
3374  }
3375  // Split adjoint sensitivities
3376  for (size_t d = 0; d < nadj; ++d) asens[d].resize(n_in_);
3377  for (size_t i = 0; i < n_in_; ++i) {
3378  v = horzsplit(all_asens[i]);
3379  casadi_assert_dev(v.size() == nadj);
3380  for (size_t d = 0; d < nadj; ++d) {
3381  if (asens[d][i].is_empty(true)) {
3382  asens[d][i] = reshape(v[d], size_in(i));
3383  } else {
3384  asens[d][i] += reshape(v[d], size_in(i));
3385  }
3386  }
3387  }
3388  } else {
3389  // Evaluate in batches
3390  casadi_assert_dev(enable_reverse_);
3391  casadi_int max_nadj = max_num_dir_;
3392 
3393  while (!has_reverse(max_nadj)) max_nadj/=2;
3394  casadi_int offset = 0;
3395  while (offset<nadj) {
3396  // Number of derivatives, in this batch
3397  casadi_int nadj_batch = std::min(nadj-offset, max_nadj);
3398 
3399  // All inputs and seeds
3400  std::vector<MX> darg;
3401  darg.reserve(n_in_ + n_out_ + n_out_);
3402  darg.insert(darg.end(), arg.begin(), arg.end());
3403  darg.insert(darg.end(), res.begin(), res.end());
3404  std::vector<MX> v(nadj_batch);
3405  for (casadi_int i=0; i<n_out_; ++i) {
3406  for (casadi_int d=0; d<nadj_batch; ++d) v[d] = aseed[offset+d][i];
3407  darg.push_back(horzcat(v));
3408  }
3409 
3410  // Create the evaluation node
3411  Function dfcn = self().reverse(nadj_batch);
3412  std::vector<MX> x = dfcn(darg);
3413  casadi_assert_dev(x.size()==n_in_);
3414 
3415  // Retrieve sensitivities
3416  for (casadi_int d=0; d<nadj_batch; ++d) asens[offset+d].resize(n_in_);
3417  for (casadi_int i=0; i<n_in_; ++i) {
3418  if (size2_in(i)>0) {
3419  v = horzsplit(x[i], size2_in(i));
3420  casadi_assert_dev(v.size()==nadj_batch);
3421  } else {
3422  v = std::vector<MX>(nadj_batch, MX(size_in(i)));
3423  }
3424  for (casadi_int d=0; d<nadj_batch; ++d) {
3425  if (asens[offset+d][i].is_empty(true)) {
3426  asens[offset+d][i] = v[d];
3427  } else {
3428  asens[offset+d][i] += v[d];
3429  }
3430  }
3431  }
3432  // Update offset
3433  offset += nadj_batch;
3434  }
3435  }
3436  }
virtual bool adjViaJac(casadi_int nadj) const
Calculate derivatives by multiplying the full Jacobian and multiplying.
std::pair< casadi_int, casadi_int > size_in(casadi_int ind) const
Input/output dimensions.
virtual void call_reverse(const std::vector< MX > &arg, const std::vector< MX > &res, const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens, bool always_inline, bool never_inline) const
Reverse mode, virtual functions overloaded in derived classes.
Function reverse(casadi_int nadj) const
Return function that calculates adjoint derivatives.
bool matching_res(const std::vector< M > &arg, casadi_int &npar) const
Check if output arguments that needs to be replaced.
virtual bool has_reverse(casadi_int nadj) const
Return function that calculates adjoint derivatives.
std::vector< std::vector< M > > replace_aseed(const std::vector< std::vector< M >> &aseed, casadi_int npar) const
Replace 0-by-0 reverse seeds.

References casadi::FunctionInternal::adjViaJac(), casadi::SharedObjectInternal::class_name(), casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::has_reverse(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::matching_res(), casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::replace_aseed(), casadi::FunctionInternal::reverse(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::size_in(), and casadi::T.

Referenced by casadi::Rootfinder::ad_reverse(), casadi::MXFunction::ad_reverse(), casadi::Call::ad_reverse(), casadi::XFunction< DerivedType, MatType, NodeType >::call_reverse(), casadi::Scpgen::init(), and casadi::MX::reverse().

◆ call_reverse() [2/2]

void casadi::FunctionInternal::call_reverse ( const std::vector< SX > &  arg,
const std::vector< SX > &  res,
const std::vector< std::vector< SX > > &  aseed,
std::vector< std::vector< SX > > &  asens,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kv

Definition at line 3451 of file function_internal.cpp.

3455  {
3456  casadi_assert(!(always_inline && never_inline), "Inconsistent options");
3457  if (aseed.empty()) { // Quick return if no seeds
3458  asens.clear();
3459  return;
3460  }
3461  casadi_error("'reverse' (SX) not defined for " + class_name());
3462  }

References casadi::SharedObjectInternal::class_name().

◆ change_option()

void casadi::FunctionInternal::change_option ( const std::string &  option_name,
const GenericType option_value 
)
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_k5

Reimplemented from casadi::ProtoFunction.

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 443 of file function_internal.cpp.

444  {
445  if (option_name == "print_in") {
446  print_in_ = option_value;
447  } else if (option_name == "print_out") {
448  print_out_ = option_value;
449  } else if (option_name == "print_canonical") {
450  print_canonical_ = option_value;
451  } else if (option_name=="ad_weight") {
452  ad_weight_ = option_value;
453  } else if (option_name=="ad_weight_sp") {
454  ad_weight_sp_ = option_value;
455  } else if (option_name=="dump") {
456  dump_ = option_value;
457  } else if (option_name=="dump_in") {
458  dump_in_ = option_value;
459  } else if (option_name=="dump_out") {
460  dump_out_ = option_value;
461  } else if (option_name=="dump_dir") {
462  dump_dir_ = option_value.to_string();
463  } else if (option_name=="dump_format") {
464  dump_format_ = option_value.to_string();
465  } else {
466  // Option not found - continue to base classes
467  ProtoFunction::change_option(option_name, option_value);
468  }
469  }
virtual void change_option(const std::string &option_name, const GenericType &option_value)
Change option after object creation for debugging.

References casadi::FunctionInternal::ad_weight_, casadi::FunctionInternal::ad_weight_sp_, casadi::ProtoFunction::change_option(), casadi::FunctionInternal::dump_, casadi::FunctionInternal::dump_dir_, casadi::FunctionInternal::dump_format_, casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::FunctionInternal::print_canonical_, casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out_, and casadi::GenericType::to_string().

Referenced by casadi::FmuFunction::change_option(), casadi::MXFunction::change_option(), and casadi::SXFunction::change_option().

◆ check_arg()

template<typename M >
void casadi::FunctionInternal::check_arg ( const std::vector< M > &  arg,
casadi_int &  npar 
) const
inherited

Raises errors.

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

Extra doc: https://github.com/casadi/casadi/wiki/L_ki

Definition at line 1766 of file function_internal.hpp.

1766  {
1767  casadi_assert(arg.size()==n_in_, "Incorrect number of inputs: Expected "
1768  + str(n_in_) + ", got " + str(arg.size()));
1769  for (casadi_int i=0; i<n_in_; ++i) {
1770  if (!check_mat(arg[i].sparsity(), sparsity_in(i), npar)) {
1771  // Dimensions
1772  std::string d_arg = str(arg[i].size1()) + "-by-" + str(arg[i].size2());
1773  std::string d_in = str(size1_in(i)) + "-by-" + str(size2_in(i));
1774  std::string e = "Input " + str(i) + " (" + name_in_[i] + ") has mismatching shape. "
1775  "Got " + d_arg + ". Allowed dimensions, in general, are:\n"
1776  " - The input dimension N-by-M (here " + d_in + ")\n"
1777  " - A scalar, i.e. 1-by-1\n"
1778  " - M-by-N if N=1 or M=1 (i.e. a transposed vector)\n"
1779  " - N-by-M1 if K*M1=M for some K (argument repeated horizontally)\n";
1780  if (npar!=-1) {
1781  e += " - N-by-P*M, indicating evaluation with multiple arguments (P must be a "
1782  "multiple of " + str(npar) + " for consistency with previous inputs)";
1783  }
1784  casadi_error(e);
1785  }
1786  }
1787  }
casadi_int size1_in(casadi_int ind) const
Input/output dimensions.
const Sparsity & sparsity_in(casadi_int ind) const
Input/output sparsity.
static bool check_mat(const Sparsity &arg, const Sparsity &inp, casadi_int &npar)
std::vector< std::string > name_in_
Input and output scheme.

References casadi::FunctionInternal::check_mat(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::sparsity_in(), and casadi::str().

Referenced by casadi::FunctionInternal::mapsum_mx(), and casadi::FunctionInternal::matching_arg().

◆ check_mat()

bool casadi::FunctionInternal::check_mat ( const Sparsity arg,
const Sparsity inp,
casadi_int &  npar 
)
staticinherited

Helper function

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
npar[out]required number of parallel calls (or -1)

Definition at line 3649 of file function_internal.cpp.

3649  {
3650  // Matching dimensions
3651  if (arg.size()==inp.size()) return true;
3652  // Calling with a scalar - set all
3653  if (arg.is_scalar()) return true;
3654  // Vectors that are transposes of each other
3655  if (arg.is_vector() && inp.size()==std::make_pair(arg.size2(), arg.size1())) return true;
3656  // Horizontal repmat
3657  if (arg.size1()==inp.size1() && arg.size2()>0 && inp.size2()>0
3658  && inp.size2()%arg.size2()==0) return true;
3659  // Evaluate with multiple arguments
3660  if (npar!=-1 && arg.size1()==inp.size1() && arg.size2()>0 && inp.size2()>0
3661  && arg.size2()%(npar*inp.size2())==0) {
3662  npar *= arg.size2()/(npar*inp.size2());
3663  return true;
3664  }
3665  // Calling with empty matrix - set all to zero (after the structured branches above,
3666  // so that a 0-by-N argument can still be recognised as a parallel/repmat call)
3667  if (arg.is_empty()) return true;
3668  // No match
3669  return false;
3670  }

References casadi::Sparsity::is_empty(), casadi::Sparsity::is_scalar(), casadi::Sparsity::is_vector(), casadi::Sparsity::size(), casadi::Sparsity::size1(), and casadi::Sparsity::size2().

Referenced by casadi::FunctionInternal::check_arg(), casadi::FunctionInternal::check_res(), and casadi::FunctionInternal::mapsum_mx().

◆ check_mem_count()

virtual void casadi::ProtoFunction::check_mem_count ( casadi_int  n) const
inlinevirtualinherited

Purpose if to allow more helpful error messages

Extra doc: https://github.com/casadi/casadi/wiki/L_2b7

Reimplemented in casadi::FmuFunction.

Definition at line 179 of file function_internal.hpp.

179 { }

Referenced by casadi::ProtoFunction::checkout().

◆ check_res()

template<typename M >
void casadi::FunctionInternal::check_res ( const std::vector< M > &  res,
casadi_int &  npar 
) const
inherited

Raises errors.

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

Extra doc: https://github.com/casadi/casadi/wiki/L_kj

Definition at line 1790 of file function_internal.hpp.

1790  {
1791  casadi_assert(res.size()==n_out_, "Incorrect number of outputs: Expected "
1792  + str(n_out_) + ", got " + str(res.size()));
1793  for (casadi_int i=0; i<n_out_; ++i) {
1794  casadi_assert(check_mat(res[i].sparsity(), sparsity_out(i), npar),
1795  "Output " + str(i) + " (" + name_out_[i] + ") has mismatching shape. "
1796  "Expected " + str(size_out(i)) + ", got " + str(res[i].size()));
1797  }
1798  }
std::vector< std::string > name_out_

References casadi::FunctionInternal::check_mat(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::size_out(), casadi::FunctionInternal::sparsity_out(), and casadi::str().

Referenced by casadi::FunctionInternal::matching_res().

◆ checkout()

int casadi::ProtoFunction::checkout ( ) const
inherited

Definition at line 3858 of file function_internal.cpp.

3858  {
3859 #ifdef CASADI_WITH_THREAD
3860  std::lock_guard<std::mutex> lock(mtx_);
3861 #endif //CASADI_WITH_THREAD
3862  if (unused_.empty()) {
3863  check_mem_count(mem_.size()+1);
3864  // Allocate a new memory object
3865  void* m = alloc_mem();
3866  mem_.push_back(m);
3867  if (init_mem(m)) {
3868  casadi_error("Failed to create or initialize memory object");
3869  }
3870  return static_cast<int>(mem_.size()) - 1;
3871  } else {
3872  // Use an unused memory object
3873  int m = unused_.top();
3874  unused_.pop();
3875  return m;
3876  }
3877  }
virtual int init_mem(void *mem) const
Initalize memory block.
virtual void * alloc_mem() const
Create memory block.
virtual void check_mem_count(casadi_int n) const
Check for validatity of memory object count.

References casadi::ProtoFunction::alloc_mem(), casadi::ProtoFunction::check_mem_count(), and casadi::ProtoFunction::init_mem().

Referenced by casadi::FunctionInternal::codegen_meta(), casadi::ProtoFunction::finalize(), and casadi::Sqpmethod::init_mem().

◆ class_name()

std::string casadi::CvodesInterface::class_name ( ) const
inlineoverridevirtual

Implements casadi::SharedObjectInternal.

Definition at line 106 of file cvodes_interface.hpp.

106 { return "CvodesInterface";}

◆ clear_mem()

void casadi::ProtoFunction::clear_mem ( )
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jq

Definition at line 3746 of file function_internal.cpp.

3746  {
3747  for (auto&& i : mem_) {
3748  if (i!=nullptr) free_mem(i);
3749  }
3750  mem_.clear();
3751  }
virtual void free_mem(void *mem) const
Free memory block.

References casadi::ProtoFunction::free_mem().

Referenced by casadi::AlpaqaInterface::~AlpaqaInterface(), casadi::AmplInterface::~AmplInterface(), casadi::BlazingSplineFunction::~BlazingSplineFunction(), casadi::Blocksqp::~Blocksqp(), casadi::BonminInterface::~BonminInterface(), casadi::BSplineInterpolant::~BSplineInterpolant(), casadi::CallbackInternal::~CallbackInternal(), casadi::CbcInterface::~CbcInterface(), casadi::ClarabelInterface::~ClarabelInterface(), casadi::ClpInterface::~ClpInterface(), casadi::CplexInterface::~CplexInterface(), casadi::CsparseInterface::~CsparseInterface(), ~CvodesInterface(), casadi::DaqpInterface::~DaqpInterface(), casadi::External::~External(), casadi::FastNewton::~FastNewton(), casadi::FatropConicInterface::~FatropConicInterface(), casadi::FatropInterface::~FatropInterface(), casadi::Feasiblesqpmethod::~Feasiblesqpmethod(), casadi::FiniteDiff::~FiniteDiff(), casadi::FixedStepIntegrator::~FixedStepIntegrator(), casadi::FmuFunction::~FmuFunction(), casadi::GurobiInterface::~GurobiInterface(), casadi::HighsInterface::~HighsInterface(), casadi::HpipmInterface::~HpipmInterface(), casadi::HpmpcInterface::~HpmpcInterface(), casadi::IdasInterface::~IdasInterface(), casadi::ImplicitToNlp::~ImplicitToNlp(), casadi::IpoptInterface::~IpoptInterface(), casadi::Ipqp::~Ipqp(), casadi::JitFunction::~JitFunction(), casadi::KinsolInterface::~KinsolInterface(), casadi::KnitroInterface::~KnitroInterface(), casadi::LapackLu::~LapackLu(), casadi::LapackQr::~LapackQr(), casadi::LinearInterpolant::~LinearInterpolant(), casadi::LinearInterpolantJac::~LinearInterpolantJac(), casadi::LinsolLdl::~LinsolLdl(), casadi::LinsolQr::~LinsolQr(), casadi::LinsolTridiag::~LinsolTridiag(), casadi::Lsqr::~Lsqr(), casadi::Ma27Interface::~Ma27Interface(), casadi::MadmpecInterface::~MadmpecInterface(), casadi::MadnlpInterface::~MadnlpInterface(), casadi::Map::~Map(), casadi::MapSum::~MapSum(), casadi::MosekInterface::~MosekInterface(), casadi::MumpsInterface::~MumpsInterface(), casadi::MXFunction::~MXFunction(), casadi::Newton::~Newton(), casadi::Nlpsol::~Nlpsol(), casadi::OmpMap::~OmpMap(), casadi::OnnxFunction::~OnnxFunction(), casadi::OnnxRuntimeInterface::~OnnxRuntimeInterface(), casadi::OoqpInterface::~OoqpInterface(), casadi::OsqpInterface::~OsqpInterface(), casadi::PiqpInterface::~PiqpInterface(), casadi::ProxqpInterface::~ProxqpInterface(), casadi::QpoasesInterface::~QpoasesInterface(), casadi::QpToNlp::~QpToNlp(), casadi::Qrqp::~Qrqp(), casadi::Qrsqp::~Qrsqp(), casadi::Scpgen::~Scpgen(), casadi::SLEQPInterface::~SLEQPInterface(), casadi::SlicotDple::~SlicotDple(), casadi::SlicotExpm::~SlicotExpm(), casadi::SnoptInterface::~SnoptInterface(), casadi::Sqpmethod::~Sqpmethod(), casadi::SuperscsInterface::~SuperscsInterface(), casadi::Switch::~Switch(), casadi::SXFunction::~SXFunction(), casadi::SymbolicQr::~SymbolicQr(), casadi::ThreadMap::~ThreadMap(), casadi::UnoInterface::~UnoInterface(), casadi::WorhpInterface::~WorhpInterface(), and casadi::XpressInterface::~XpressInterface().

◆ codegen()

void casadi::FunctionInternal::codegen ( CodeGenerator g,
const std::string &  fname 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lm

Definition at line 2452 of file function_internal.cpp.

2452  {
2453  // Define function
2454  g << "/* " << definition() << " */\n";
2455  g << "static " << signature(fname) << " {\n";
2456 
2457  // Reset local variables, flush buffer
2458  g.flush(g.body);
2459 
2460  g.scope_enter();
2461 
2462  if (dump_in_ || dump_out_) {
2463  Function F = shared_from_this<Function>();
2464  std::string cg_name = codegen_name(g, false);
2465  std::string dump_counter = g.shorthand(cg_name + "_dump_counter");
2466  g.auxiliaries << "static int " << dump_counter << " = 0;\n";
2467  if (g.thread_safe()) {
2468  g.define_local_mutex(F, cg_name + "_dump_mutex");
2469  std::string dump_mutex = g.local_mutex(F, cg_name + "_dump_mutex");
2470  g << "CASADI_MUTEX_LOCK(&" << dump_mutex << ");\n";
2471  g << "int dump_id_local = " << dump_counter << "++;\n";
2472  g << "CASADI_MUTEX_UNLOCK(&" << dump_mutex << ");\n";
2473  } else {
2474  g << "int dump_id_local = " << dump_counter << "++;\n";
2475  }
2476  }
2477 
2478  if (dump_in_) g.generate_dump(shared_from_this<Function>(), "arg", true);
2479  if (print_in_) g.generate_print(shared_from_this<Function>(), "arg", true);
2480 
2481  // Generate function body (to buffer)
2482  codegen_body(g);
2483 
2484  if (dump_out_) g.generate_dump(shared_from_this<Function>(), "res", false);
2485  if (print_out_) g.generate_print(shared_from_this<Function>(), "res", false);
2486 
2487  g.scope_exit();
2488 
2489  // Finalize the function
2490  g << "return 0;\n";
2491  g << "}\n\n";
2492 
2493  // Flush to function body
2494  g.flush(g.body);
2495  }
std::string definition() const
Get function signature: name:(inputs)->(outputs)
virtual std::string codegen_name(const CodeGenerator &g, bool ns=true) const
Get name in codegen.
virtual void codegen_body(CodeGenerator &g) const
Generate code for the function body.
std::string signature(const std::string &fname) const
Code generate the function.

References casadi::CodeGenerator::auxiliaries, casadi::CodeGenerator::body, casadi::FunctionInternal::codegen_body(), casadi::FunctionInternal::codegen_name(), casadi::CodeGenerator::define_local_mutex(), casadi::FunctionInternal::definition(), casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::CodeGenerator::flush(), casadi::CodeGenerator::generate_dump(), casadi::CodeGenerator::generate_print(), casadi::CodeGenerator::local_mutex(), casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out_, casadi::CodeGenerator::scope_enter(), casadi::CodeGenerator::scope_exit(), casadi::CodeGenerator::shorthand(), casadi::FunctionInternal::signature(), and casadi::CodeGenerator::thread_safe().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_alloc_mem()

void casadi::FunctionInternal::codegen_alloc_mem ( CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lt

Reimplemented in casadi::External.

Definition at line 2596 of file function_internal.cpp.

2596  {
2597  bool needs_mem = codegen_needs_mem();
2598  if (needs_mem) {
2599  std::string name = codegen_name(g, false);
2600  std::string mem_counter = g.shorthand(name + "_mem_counter");
2601  g << "return " + mem_counter + "++;\n";
2602  }
2603  }
virtual bool codegen_needs_mem() const
Is thread-local memory object needed?

References casadi::FunctionInternal::codegen_name(), casadi::FunctionInternal::codegen_needs_mem(), and casadi::CodeGenerator::shorthand().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_body()

void casadi::FunctionInternal::codegen_body ( CodeGenerator g) const
virtualinherited

◆ codegen_body_enter()

void casadi::OracleFunction::codegen_body_enter ( CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_27q

Reimplemented in casadi::Nlpsol.

Definition at line 295 of file oracle_function.cpp.

295  {
296  g.local("d_oracle", "struct casadi_oracle_data");
297  }

References casadi::CodeGenerator::local().

Referenced by casadi::Nlpsol::codegen_body_enter().

◆ codegen_body_exit()

void casadi::OracleFunction::codegen_body_exit ( CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_27r

Reimplemented in casadi::Nlpsol.

Definition at line 299 of file oracle_function.cpp.

299  {
300  }

Referenced by casadi::Nlpsol::codegen_body_exit().

◆ codegen_checkout()

void casadi::FunctionInternal::codegen_checkout ( CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lw

Reimplemented in casadi::External.

Definition at line 2605 of file function_internal.cpp.

2605  {
2606  std::string name = codegen_name(g, false);
2607  std::string stack_counter = g.shorthand(name + "_unused_stack_counter");
2608  std::string stack = g.shorthand(name + "_unused_stack");
2609  std::string mem_counter = g.shorthand(name + "_mem_counter");
2610  std::string mem_array = g.shorthand(name + "_mem");
2611  std::string alloc_mem = g.shorthand(name + "_alloc_mem");
2612  std::string init_mem = g.shorthand(name + "_init_mem");
2613 
2614 
2615  g.auxiliaries << "static int " << mem_counter << " = 0;\n";
2616  g.auxiliaries << "static int " << stack_counter << " = -1;\n";
2617  g.auxiliaries << "static int " << stack << "[CASADI_MAX_NUM_THREADS];\n";
2618  g.auxiliaries << "static " << codegen_mem_type() <<
2619  " " << mem_array << "[CASADI_MAX_NUM_THREADS];\n\n";
2620 
2621  if (g.thread_safe()) {
2622  Function F = shared_from_this<Function>();
2623  g.define_local_mutex(F, name + "_mem_mutex");
2624  std::string mem_mutex = g.local_mutex(F, name + "_mem_mutex");
2625  g << "CASADI_MUTEX_LOCK(&" << mem_mutex << ");\n";
2626  g.scope_add_cleanup("CASADI_MUTEX_UNLOCK(&" + mem_mutex + ");\n");
2627  }
2628 
2629  g.local("mid", "int");
2630 
2631  g << "if (" << stack_counter << ">=0) {\n";
2632  g.scope_return(stack + "[" + stack_counter + "--]");
2633  g << "} else {\n";
2634  g << "if (" << mem_counter << "==CASADI_MAX_NUM_THREADS) {\n";
2635  g.scope_return("-1");
2636  g << "}\n";
2637  g << "mid = " << alloc_mem << "();\n";
2638  g << "if (mid<0) {\n";
2639  g.scope_return("-1");
2640  g << "}\n";
2641  g << "if (" << init_mem << "(mid)) {\n";
2642  g.scope_return("-1");
2643  g << "}\n";
2644  g.scope_return("mid");
2645  g << "}\n";
2646  }
virtual std::string codegen_mem_type() const
Thread-local memory object type.
void * alloc_mem() const override
Create memory block.

References casadi::FunctionInternal::alloc_mem(), casadi::CodeGenerator::auxiliaries, casadi::FunctionInternal::codegen_mem_type(), casadi::FunctionInternal::codegen_name(), casadi::CodeGenerator::define_local_mutex(), casadi::ProtoFunction::init_mem(), casadi::CodeGenerator::local(), casadi::CodeGenerator::local_mutex(), casadi::CodeGenerator::scope_add_cleanup(), casadi::CodeGenerator::scope_return(), casadi::CodeGenerator::shorthand(), and casadi::CodeGenerator::thread_safe().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_declarations()

void casadi::FunctionInternal::codegen_declarations ( CodeGenerator g) const
virtualinherited

◆ codegen_decref()

void casadi::FunctionInternal::codegen_decref ( CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ls

Reimplemented in casadi::MXFunction, and casadi::External.

Definition at line 2551 of file function_internal.cpp.

2551  {
2552 
2553  // Treat dependent functions
2554  std::set<void*> added;
2555  Function F = shared_from_this<Function>();
2556  for (const Function& f : F.find_functions(0)) {
2557  if (f->has_refcount_in_deps_) {
2558  std::string cg_name = f->codegen_name(g, false);
2559  auto i = added.insert(f.get());
2560  if (i.second) { // prevent duplicate calls
2561  std::string decref = g.shorthand(cg_name + "_decref");
2562  g << decref << "();\n";
2563  }
2564  }
2565  }
2566 
2567  if (has_refcount_) {
2568  std::string name = codegen_name(g, false);
2569  std::string ref_counter = g.shorthand(name + "_ref_counter");
2570  std::string mem_counter = g.shorthand(name + "_mem_counter");
2571  std::string free_mem = g.shorthand(name + "_free_mem");
2572  g << ref_counter << "--;\n";
2573  g << "if (" << ref_counter << "==0) {\n";
2574  if (codegen_needs_mem()) {
2575  g << "while (" << mem_counter << ">0) {\n";
2576  g << free_mem << "(--" << mem_counter << ");\n";
2577  g << "}\n";
2578  }
2579  if (g.thread_safe()) {
2580  Function F = shared_from_this<Function>();
2581  for (const auto& m : g.local_mutexes(F)) {
2582  std::string mtx = g.local_mutex(F, m);
2583  g << "#if CASADI_MUTEX_USE_STATIC_INIT == 0\n";
2584  g << "CASADI_MUTEX_DESTROY(&" << mtx << ");\n";
2585  g << "#endif\n";
2586  }
2587  }
2588  g << "}\n";
2589  }
2590  }
bool has_refcount_
Reference counting in codegen?
void free_mem(void *mem) const override
Free memory block.

References casadi::FunctionInternal::codegen_name(), casadi::FunctionInternal::codegen_needs_mem(), casadi::Function::find_functions(), casadi::FunctionInternal::free_mem(), casadi::FunctionInternal::has_refcount_, casadi::CodeGenerator::local_mutex(), casadi::CodeGenerator::local_mutexes(), casadi::CodeGenerator::shorthand(), and casadi::CodeGenerator::thread_safe().

Referenced by casadi::CodeGenerator::add_dependency(), and casadi::MXFunction::codegen_decref().

◆ codegen_free_mem()

virtual void casadi::FunctionInternal::codegen_free_mem ( CodeGenerator g) const
inlinevirtualinherited

◆ codegen_incref()

void casadi::FunctionInternal::codegen_incref ( CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lr

Reimplemented in casadi::MXFunction, and casadi::External.

Definition at line 2518 of file function_internal.cpp.

2518  {
2519  if (has_refcount_) {
2520  std::string name = codegen_name(g, false);
2521  std::string ref_counter = g.shorthand(name + "_ref_counter");
2522  g.auxiliaries << "static int " << ref_counter << " = 0;\n";
2523 
2524  Function F = shared_from_this<Function>();
2525  if (g.thread_safe()) {
2526  for (const auto& m : g.local_mutexes(F)) {
2527  std::string mtx = g.local_mutex(F, m);
2528  g << "#if CASADI_MUTEX_USE_STATIC_INIT == 0\n";
2529  g << "if (" << ref_counter << "==0) CASADI_MUTEX_INIT(&" << mtx << ");\n";
2530  g << "#endif\n";
2531  }
2532  }
2533  g << ref_counter << "++;\n";
2534  }
2535 
2536  // Treat dependent functions
2537  std::set<void*> added;
2538  Function F = shared_from_this<Function>();
2539  for (const Function& f : F.find_functions(0)) {
2540  if (f->has_refcount_in_deps_) {
2541  std::string cg_name = f->codegen_name(g, false);
2542  auto i = added.insert(f.get());
2543  if (i.second) { // prevent duplicate calls
2544  std::string incref = g.shorthand(cg_name + "_incref");
2545  g << incref << "();\n";
2546  }
2547  }
2548  }
2549  }

References casadi::CodeGenerator::auxiliaries, casadi::FunctionInternal::codegen_name(), casadi::Function::find_functions(), casadi::FunctionInternal::has_refcount_, casadi::CodeGenerator::local_mutex(), casadi::CodeGenerator::local_mutexes(), casadi::CodeGenerator::shorthand(), and casadi::CodeGenerator::thread_safe().

Referenced by casadi::CodeGenerator::add_dependency(), and casadi::MXFunction::codegen_incref().

◆ codegen_init_mem()

void casadi::FunctionInternal::codegen_init_mem ( CodeGenerator g) const
virtualinherited

◆ codegen_mem()

std::string casadi::FunctionInternal::codegen_mem ( CodeGenerator g,
const std::string &  index = "mem" 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lq

Definition at line 2993 of file function_internal.cpp.

2993  {
2994  std::string name = codegen_name(g, false);
2995  std::string mem_array = g.shorthand(name + "_mem");
2996  return mem_array+"[" + index + "]";
2997  }

References casadi::FunctionInternal::codegen_name(), and casadi::CodeGenerator::shorthand().

Referenced by casadi::MadmpecInterface::codegen_body(), casadi::ClarabelInterface::codegen_body(), casadi::DaqpInterface::codegen_body(), casadi::FatropInterface::codegen_body(), casadi::HighsInterface::codegen_body(), casadi::IpoptInterface::codegen_body(), casadi::MadnlpInterface::codegen_body(), casadi::MosekInterface::codegen_body(), casadi::OsqpInterface::codegen_body(), casadi::UnoInterface::codegen_body(), casadi::XpressInterface::codegen_body(), casadi::Sqpmethod::codegen_body(), casadi::MadmpecInterface::codegen_free_mem(), casadi::ClarabelInterface::codegen_free_mem(), casadi::DaqpInterface::codegen_free_mem(), casadi::FatropInterface::codegen_free_mem(), casadi::HighsInterface::codegen_free_mem(), casadi::IpoptInterface::codegen_free_mem(), casadi::MadnlpInterface::codegen_free_mem(), casadi::MosekInterface::codegen_free_mem(), casadi::OsqpInterface::codegen_free_mem(), casadi::UnoInterface::codegen_free_mem(), casadi::XpressInterface::codegen_free_mem(), casadi::MadmpecInterface::codegen_init_mem(), casadi::ClarabelInterface::codegen_init_mem(), casadi::DaqpInterface::codegen_init_mem(), casadi::FatropInterface::codegen_init_mem(), casadi::HighsInterface::codegen_init_mem(), casadi::IpoptInterface::codegen_init_mem(), casadi::MadnlpInterface::codegen_init_mem(), casadi::MosekInterface::codegen_init_mem(), casadi::OsqpInterface::codegen_init_mem(), casadi::UnoInterface::codegen_init_mem(), casadi::XpressInterface::codegen_init_mem(), and casadi::MadmpecInterface::codegen_options().

◆ codegen_mem_is_opaque()

virtual bool casadi::FunctionInternal::codegen_mem_is_opaque ( ) const
inlinevirtualinherited

without a need for alloc_mem, init_mem, free_mem?

Extra doc: https://github.com/casadi/casadi/wiki/L_2ey

Reimplemented in casadi::External.

Definition at line 932 of file function_internal.hpp.

932 { return false; }

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_mem_type()

virtual std::string casadi::FunctionInternal::codegen_mem_type ( ) const
inlinevirtualinherited

◆ codegen_meta()

void casadi::FunctionInternal::codegen_meta ( CodeGenerator g) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ln

Definition at line 2668 of file function_internal.cpp.

2668  {
2669  bool needs_mem = codegen_needs_mem();
2670  std::string name = codegen_name(g, false);
2671 
2672  // Checkout/release routines
2673  g << g.declare("int " + name_ + "_checkout(void)") << " {\n";
2674  if (needs_mem) {
2675  std::string checkout = g.shorthand(name + "_checkout");
2676  g << "return " << checkout << "();\n";
2677  } else {
2678  g << "return 0;\n";
2679  }
2680  g << "}\n\n";
2681 
2682  if (needs_mem) {
2683  g << g.declare("void " + name_ + "_release(int mem)") << " {\n";
2684  std::string release = g.shorthand(name + "_release");
2685  g << release << "(mem);\n";
2686  } else {
2687  g << g.declare("void " + name_ + "_release(int mem)") << " {\n";
2688  }
2689  g << "}\n\n";
2690 
2691  // Reference counter routines
2692  g << g.declare("void " + name_ + "_incref(void)") << " {\n";
2693  if (has_refcount_in_deps_) {
2694  std::string incref = g.shorthand(name + "_incref");
2695  g << incref << "();\n";
2696  }
2697  g << "}\n\n"
2698  << g.declare("void " + name_ + "_decref(void)") << " {\n";
2699  if (has_refcount_in_deps_) {
2700  std::string decref = g.shorthand(name + "_decref");
2701  g << decref << "();\n";
2702  }
2703  g << "}\n\n";
2704 
2705  // Number of inputs and outptus
2706  g << g.declare("casadi_int " + name_ + "_n_in(void)")
2707  << " { return " << n_in_ << ";}\n\n"
2708  << g.declare("casadi_int " + name_ + "_n_out(void)")
2709  << " { return " << n_out_ << ";}\n\n";
2710 
2711  // Default inputs
2712  g << g.declare("casadi_real " + name_ + "_default_in(casadi_int i)") << " {\n"
2713  << "switch (i) {\n";
2714  for (casadi_int i=0; i<n_in_; ++i) {
2715  double def = get_default_in(i);
2716  if (def!=0) g << "case " << i << ": return " << g.constant(def) << ";\n";
2717  }
2718  g << "default: return 0;\n}\n"
2719  << "}\n\n";
2720 
2721  // Input names
2722  g << g.declare("const char* " + name_ + "_name_in(casadi_int i)") << " {\n"
2723  << "switch (i) {\n";
2724  for (casadi_int i=0; i<n_in_; ++i) {
2725  g << "case " << i << ": return \"" << name_in_[i] << "\";\n";
2726  }
2727  g << "default: return 0;\n}\n"
2728  << "}\n\n";
2729 
2730  // Output names
2731  g << g.declare("const char* " + name_ + "_name_out(casadi_int i)") << " {\n"
2732  << "switch (i) {\n";
2733  for (casadi_int i=0; i<n_out_; ++i) {
2734  g << "case " << i << ": return \"" << name_out_[i] << "\";\n";
2735  }
2736  g << "default: return 0;\n}\n"
2737  << "}\n\n";
2738 
2739  // Codegen sparsities
2740  codegen_sparsities(g);
2741 
2742  // Function that returns work vector lengths
2743  g << g.declare(
2744  "int " + name_ + "_work(casadi_int *sz_arg, casadi_int* sz_res, "
2745  "casadi_int *sz_iw, casadi_int *sz_w)")
2746  << " {\n"
2747  << "if (sz_arg) *sz_arg = " << codegen_sz_arg(g) << ";\n"
2748  << "if (sz_res) *sz_res = " << codegen_sz_res(g) << ";\n"
2749  << "if (sz_iw) *sz_iw = " << codegen_sz_iw(g) << ";\n"
2750  << "if (sz_w) *sz_w = " << codegen_sz_w(g) << ";\n"
2751  << "return 0;\n"
2752  << "}\n\n";
2753 
2754  // Function that returns work vector lengths in bytes
2755  g << g.declare(
2756  "int " + name_ + "_work_bytes(casadi_int *sz_arg, casadi_int* sz_res, "
2757  "casadi_int *sz_iw, casadi_int *sz_w)")
2758  << " {\n"
2759  << "if (sz_arg) *sz_arg = " << codegen_sz_arg(g) << "*sizeof(const casadi_real*);\n"
2760  << "if (sz_res) *sz_res = " << codegen_sz_res(g) << "*sizeof(casadi_real*);\n"
2761  << "if (sz_iw) *sz_iw = " << codegen_sz_iw(g) << "*sizeof(casadi_int);\n"
2762  << "if (sz_w) *sz_w = " << codegen_sz_w(g) << "*sizeof(casadi_real);\n"
2763  << "return 0;\n"
2764  << "}\n\n";
2765 
2766  // Also add to header file to allow getting
2767  if (g.with_header) {
2768  g.header
2769  << "#define " << name_ << "_SZ_ARG " << codegen_sz_arg(g) << "\n"
2770  << "#define " << name_ << "_SZ_RES " << codegen_sz_res(g) << "\n"
2771  << "#define " << name_ << "_SZ_IW " << codegen_sz_iw(g) << "\n"
2772  << "#define " << name_ << "_SZ_W " << codegen_sz_w(g) << "\n";
2773  }
2774 
2775  // Which inputs are differentiable
2776  if (!all(is_diff_in_)) {
2777  g << g.declare("int " + name_ + "_diff_in(casadi_int i)") << " {\n"
2778  << "switch (i) {\n";
2779  for (casadi_int i=0; i<n_in_; ++i) {
2780  g << "case " << i << ": return " << is_diff_in_[i] << ";\n";
2781  }
2782  g << "default: return -1;\n}\n"
2783  << "}\n\n";
2784  }
2785 
2786  // Which outputs are differentiable
2787  if (!all(is_diff_out_)) {
2788  g << g.declare("int " + name_ + "_diff_out(casadi_int i)") << " {\n"
2789  << "switch (i) {\n";
2790  for (casadi_int i=0; i<n_out_; ++i) {
2791  g << "case " << i << ": return " << is_diff_out_[i] << ";\n";
2792  }
2793  g << "default: return -1;\n}\n"
2794  << "}\n\n";
2795  }
2796 
2797  // Generate mex gateway for the function
2798  if (g.mex) {
2799  // Begin conditional compilation
2800  g << "#ifdef MATLAB_MEX_FILE\n";
2801 
2802  // Declare wrapper
2803  g << "void mex_" << name_
2804  << "(int resc, mxArray *resv[], int argc, const mxArray *argv[]) {\n"
2805  << "casadi_int i;\n";
2806  g << "int mem;\n";
2807  // Work vectors, including input and output buffers
2808  casadi_int i_nnz = nnz_in(), o_nnz = nnz_out();
2809  size_t sz_w = this->sz_w();
2810  for (casadi_int i=0; i<n_in_; ++i) {
2811  const Sparsity& s = sparsity_in_[i];
2812  sz_w = std::max(sz_w, static_cast<size_t>(s.size1())); // To be able to copy a column
2813  sz_w = std::max(sz_w, static_cast<size_t>(s.size2())); // To be able to copy a row
2814  }
2815  sz_w += i_nnz + o_nnz;
2816  g << CodeGenerator::array("casadi_real", "w", sz_w);
2817  g << CodeGenerator::array("casadi_int", "iw", sz_iw());
2818  std::string fw = "w+" + str(i_nnz + o_nnz);
2819 
2820  // Copy inputs to buffers
2821  casadi_int offset=0;
2822  g << CodeGenerator::array("const casadi_real*", "arg", sz_arg(), "{0}");
2823 
2824  // Allocate output buffers
2825  g << "casadi_real* res[" << sz_res() << "] = {0};\n";
2826 
2827  // Check arguments
2828  g << "if (argc>" << n_in_ << ") mexErrMsgIdAndTxt(\"Casadi:RuntimeError\","
2829  << "\"Evaluation of \\\"" << name_ << "\\\" failed. Too many input arguments "
2830  << "(%d, max " << n_in_ << ")\", argc);\n";
2831 
2832  g << "if (resc>" << n_out_ << ") mexErrMsgIdAndTxt(\"Casadi:RuntimeError\","
2833  << "\"Evaluation of \\\"" << name_ << "\\\" failed. "
2834  << "Too many output arguments (%d, max " << n_out_ << ")\", resc);\n";
2835 
2836  for (casadi_int i=0; i<n_in_; ++i) {
2837  std::string p = "argv[" + str(i) + "]";
2838  g << "if (--argc>=0) arg[" << i << "] = "
2839  << g.from_mex(p, "w", offset, sparsity_in_[i], fw) << "\n";
2840  offset += nnz_in(i);
2841  }
2842 
2843  for (casadi_int i=0; i<n_out_; ++i) {
2844  if (i==0) {
2845  // if i==0, always store output (possibly ans output)
2846  g << "--resc;\n";
2847  } else {
2848  // Store output, if it exists
2849  g << "if (--resc>=0) ";
2850  }
2851  // Create and get pointer
2852  g << g.res(i) << " = w+" << str(offset) << ";\n";
2853  offset += nnz_out(i);
2854  }
2855  g << name_ << "_incref();\n";
2856  g << "mem = " << name_ << "_checkout();\n";
2857 
2858  // Call the function
2859  g << "i = " << name_ << "(arg, res, iw, " << fw << ", mem);\n"
2860  << "if (i) mexErrMsgIdAndTxt(\"Casadi:RuntimeError\",\"Evaluation of \\\"" << name_
2861  << "\\\" failed.\");\n";
2862  g << name_ << "_release(mem);\n";
2863  g << name_ << "_decref();\n";
2864 
2865  // Save results
2866  for (casadi_int i=0; i<n_out_; ++i) {
2867  g << "if (" << g.res(i) << ") resv[" << i << "] = "
2868  << g.to_mex(sparsity_out_[i], g.res(i)) << "\n";
2869  }
2870 
2871  // End conditional compilation and function
2872  g << "}\n"
2873  << "#endif\n\n";
2874  }
2875 
2876  if (g.main) {
2877  // Declare wrapper
2878  g << "casadi_int main_" << name_ << "(casadi_int argc, char* argv[]) {\n";
2879 
2880  g << "casadi_int j;\n";
2881  g << "casadi_real* a;\n";
2882  g << "const casadi_real* r;\n";
2883  g << "casadi_int flag;\n";
2884  if (needs_mem) g << "int mem;\n";
2885 
2886 
2887 
2888  // Work vectors and input and output buffers
2889  size_t nr = sz_w() + nnz_in() + nnz_out();
2890  g << CodeGenerator::array("casadi_int", "iw", sz_iw())
2891  << CodeGenerator::array("casadi_real", "w", nr);
2892 
2893  // Input buffers
2894  g << "const casadi_real* arg[" << sz_arg() << "];\n";
2895 
2896  // Output buffers
2897  g << "casadi_real* res[" << sz_res() << "];\n";
2898 
2899  casadi_int off=0;
2900  for (casadi_int i=0; i<n_in_; ++i) {
2901  g << "arg[" << i << "] = w+" << off << ";\n";
2902  off += nnz_in(i);
2903  }
2904  for (casadi_int i=0; i<n_out_; ++i) {
2905  g << "res[" << i << "] = w+" << off << ";\n";
2906  off += nnz_out(i);
2907  }
2908 
2909  // TODO(@jaeandersson): Read inputs from file. For now; read from stdin
2910  g << "a = w;\n"
2911  << "for (j=0; j<" << nnz_in() << "; ++j) "
2912  << "if (scanf(\"%lg\", a++)<=0) return 2;\n";
2913 
2914  if (has_refcount_in_deps_) {
2915  g << name_ << "_incref();\n";
2916  }
2917 
2918  if (needs_mem) {
2919  g << "mem = " << name_ << "_checkout();\n";
2920  }
2921 
2922  // Call the function
2923  g << "flag = " << name_ << "(arg, res, iw, w+" << off << ", ";
2924  if (needs_mem) {
2925  g << "mem";
2926  } else {
2927  g << "0";
2928  }
2929  g << ");\n";
2930  if (needs_mem) {
2931  g << name_ << "_release(mem);\n";
2932  }
2933 
2934  if (has_refcount_in_deps_) {
2935  g << name_ << "_decref();\n";
2936  }
2937 
2938  g << "if (flag) return flag;\n";
2939 
2940  // TODO(@jaeandersson): Write outputs to file. For now: print to stdout
2941  g << "r = w+" << nnz_in() << ";\n"
2942  << "for (j=0; j<" << nnz_out() << "; ++j) "
2943  << g.printf("%.16e ", "*r++") << "\n";
2944 
2945  // End with newline
2946  g << g.printf("\\n") << "\n";
2947 
2948  // Finalize function
2949  g << "return 0;\n"
2950  << "}\n\n";
2951  }
2952 
2953  if (g.with_mem) {
2954  // Allocate memory
2955  g << g.declare("casadi_functions* " + name_ + "_functions(void)") << " {\n"
2956  << "static casadi_functions fun = {\n"
2957  << name_ << "_incref,\n"
2958  << name_ << "_decref,\n"
2959  << name_ << "_checkout,\n"
2960  << name_ << "_release,\n"
2961  << name_ << "_default_in,\n"
2962  << name_ << "_n_in,\n"
2963  << name_ << "_n_out,\n"
2964  << name_ << "_name_in,\n"
2965  << name_ << "_name_out,\n"
2966  << name_ << "_sparsity_in,\n"
2967  << name_ << "_sparsity_out,\n"
2968  << name_ << "_work,\n"
2969  << name_ << "\n"
2970  << "};\n"
2971  << "return &fun;\n"
2972  << "}\n";
2973  }
2974  // Flush
2975  g.flush(g.body);
2976  }
static std::string array(const std::string &type, const std::string &name, casadi_int len, const std::string &def=std::string())
virtual size_t codegen_sz_res(const CodeGenerator &g) const
Get required lengths, for codegen.
virtual size_t codegen_sz_arg(const CodeGenerator &g) const
Get required lengths, for codegen.
std::vector< bool > is_diff_out_
virtual size_t codegen_sz_iw(const CodeGenerator &g) const
Get required lengths, for codegen.
virtual size_t codegen_sz_w(const CodeGenerator &g) const
Get required lengths, for codegen.
bool has_refcount_in_deps_
Reference counting in dependent functions.
std::vector< bool > is_diff_in_
Are inputs and outputs differentiable?
void codegen_sparsities(CodeGenerator &g) const
Codegen sparsities.
virtual double get_default_in(casadi_int ind) const
Get default input value.
int checkout() const
Checkout a memory object.
void release(int mem) const
Release a memory object.
bool all(const std::vector< bool > &v)
Check if all arguments are true.
Definition: casadi_misc.cpp:81

References casadi::all(), casadi::CodeGenerator::array(), casadi::CodeGenerator::body, casadi::ProtoFunction::checkout(), casadi::FunctionInternal::codegen_name(), casadi::FunctionInternal::codegen_needs_mem(), casadi::FunctionInternal::codegen_sparsities(), casadi::FunctionInternal::codegen_sz_arg(), casadi::FunctionInternal::codegen_sz_iw(), casadi::FunctionInternal::codegen_sz_res(), casadi::FunctionInternal::codegen_sz_w(), casadi::CodeGenerator::constant(), casadi::CodeGenerator::declare(), casadi::CodeGenerator::flush(), casadi::CodeGenerator::from_mex(), casadi::FunctionInternal::get_default_in(), casadi::FunctionInternal::has_refcount_in_deps_, casadi::CodeGenerator::header, casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::CodeGenerator::main, casadi::CodeGenerator::mex, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::CodeGenerator::printf(), casadi::ProtoFunction::release(), casadi::CodeGenerator::res(), casadi::CodeGenerator::shorthand(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::FunctionInternal::sparsity_in_, casadi::FunctionInternal::sparsity_out_, casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::CodeGenerator::to_mex(), casadi::CodeGenerator::with_header, and casadi::CodeGenerator::with_mem.

Referenced by casadi::CodeGenerator::add().

◆ codegen_name()

std::string casadi::FunctionInternal::codegen_name ( const CodeGenerator g,
bool  ns = true 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lp

Definition at line 2978 of file function_internal.cpp.

2978  {
2979  if (ns) {
2980  // Get the index of the function
2981  for (auto&& e : g.added_functions_) {
2982  if (e.f.get()==this) return e.codegen_name;
2983  }
2984  } else {
2985  for (casadi_int i=0;i<g.added_functions_.size();++i) {
2986  const auto & e = g.added_functions_[i];
2987  if (e.f.get()==this) return "f" + str(i);
2988  }
2989  }
2990  casadi_error("Function '" + name_ + "' not found");
2991  }

References casadi::CodeGenerator::added_functions_, casadi::ProtoFunction::name_, and casadi::str().

Referenced by casadi::FunctionInternal::codegen(), casadi::FunctionInternal::codegen_alloc_mem(), casadi::FatropInterface::codegen_body(), casadi::FunctionInternal::codegen_checkout(), casadi::FunctionInternal::codegen_decref(), casadi::FunctionInternal::codegen_incref(), casadi::FunctionInternal::codegen_mem(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::codegen_release(), casadi::CodeGenerator::mem(), and casadi::CodeGenerator::operator()().

◆ codegen_needs_mem()

virtual bool casadi::FunctionInternal::codegen_needs_mem ( ) const
inlinevirtualinherited

◆ codegen_release()

void casadi::FunctionInternal::codegen_release ( CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lx

Reimplemented in casadi::External.

Definition at line 2648 of file function_internal.cpp.

2648  {
2649  std::string name = codegen_name(g, false);
2650  std::string stack_counter = g.shorthand(name + "_unused_stack_counter");
2651  std::string stack = g.shorthand(name + "_unused_stack");
2652 
2653  if (g.thread_safe()) {
2654  Function F = shared_from_this<Function>();
2655  std::string mem_mutex = g.local_mutex(F, name + "_mem_mutex");
2656  g << "CASADI_MUTEX_LOCK(&" << mem_mutex << ");\n";
2657  g.scope_add_cleanup("CASADI_MUTEX_UNLOCK(&" + mem_mutex + ");\n");
2658  }
2659 
2660  g << stack << "[++" << stack_counter << "] = mem;\n";
2661  g.scope_return();
2662  }

References casadi::FunctionInternal::codegen_name(), casadi::CodeGenerator::local_mutex(), casadi::CodeGenerator::scope_add_cleanup(), casadi::CodeGenerator::scope_return(), casadi::CodeGenerator::shorthand(), and casadi::CodeGenerator::thread_safe().

Referenced by casadi::CodeGenerator::add_dependency().

◆ codegen_sparsities()

void casadi::FunctionInternal::codegen_sparsities ( CodeGenerator g) const
inherited

◆ codegen_sz_arg()

size_t casadi::FunctionInternal::codegen_sz_arg ( const CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29g

Definition at line 3100 of file function_internal.cpp.

3100  {
3101  return sz_arg();
3102  }

References casadi::FunctionInternal::sz_arg().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ codegen_sz_iw()

size_t casadi::FunctionInternal::codegen_sz_iw ( const CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29g

Definition at line 3106 of file function_internal.cpp.

3106  {
3107  return sz_iw();
3108  }

References casadi::FunctionInternal::sz_iw().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ codegen_sz_res()

size_t casadi::FunctionInternal::codegen_sz_res ( const CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29g

Definition at line 3103 of file function_internal.cpp.

3103  {
3104  return sz_res();
3105  }

References casadi::FunctionInternal::sz_res().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ codegen_sz_w()

size_t casadi::FunctionInternal::codegen_sz_w ( const CodeGenerator g) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29g

Reimplemented in casadi::SXFunction.

Definition at line 3109 of file function_internal.cpp.

3109  {
3110  return sz_w();
3111  }

References casadi::FunctionInternal::sz_w().

Referenced by casadi::FunctionInternal::codegen_meta().

◆ construct()

void casadi::ProtoFunction::construct ( const Dict opts)
inherited

Prepares the function for evaluation

Extra doc: https://github.com/casadi/casadi/wiki/L_jf

Definition at line 141 of file function_internal.cpp.

141  {
142  // Sanitize dictionary is needed
143  if (!Options::is_sane(opts)) {
144  // Call recursively
146  return;
147  }
148 
149  // Make sure all options exist
150  get_options().check(opts);
151 
152  // Initialize the class hierarchy
153  try {
154  init(opts);
155  } catch(std::exception& e) {
156  casadi_error("Error calling " + class_name() + "::init for '" + name_ + "':\n"
157  + std::string(e.what()));
158  }
159 
160  // Revisit class hierarchy in reverse order
161  try {
162  finalize();
163  } catch(std::exception& e) {
164  casadi_error("Error calling " + class_name() + "::finalize for '" + name_ + "':\n"
165  + std::string(e.what()));
166  }
167  }
void construct(const Dict &opts)
Construct.
virtual const Options & get_options() const
Options.
virtual void init(const Dict &opts)
Initialize.
virtual void finalize()
Finalize the object creation.
static bool is_sane(const Dict &opts)
Is the dictionary sane.
Definition: options.cpp:169
static Dict sanitize(const Dict &opts, bool top_level=true)
Sanitize a options dictionary.
Definition: options.cpp:173
void check(const Dict &opts) const
Check if options exist.
Definition: options.cpp:240

References casadi::Options::check(), casadi::SharedObjectInternal::class_name(), casadi::ProtoFunction::finalize(), casadi::ProtoFunction::get_options(), casadi::ProtoFunction::init(), casadi::Options::is_sane(), casadi::ProtoFunction::name_, and casadi::Options::sanitize().

Referenced by casadi::Function::create(), casadi::FmuFunction::factory(), casadi::FmuFunction::get_forward(), casadi::FmuFunction::get_jacobian(), casadi::LinearInterpolant::get_jacobian(), and casadi::FmuFunction::get_reverse().

◆ convert_arg() [1/2]

template<typename M >
std::vector< M > casadi::FunctionInternal::convert_arg ( const std::map< std::string, M > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ks

Definition at line 1892 of file function_internal.hpp.

1893  {
1894  // Get default inputs
1895  std::vector<M> arg_v(n_in_);
1896  for (casadi_int i=0; i<arg_v.size(); ++i) {
1897  arg_v[i] = get_default_in(i);
1898  }
1899 
1900  // Assign provided inputs
1901  for (auto&& e : arg) {
1902  arg_v.at(index_in(e.first)) = e.second;
1903  }
1904 
1905  return arg_v;
1906  }
casadi_int index_in(const std::string &name) const
Get input scheme index by name.

References casadi::FunctionInternal::get_default_in(), casadi::FunctionInternal::index_in(), and casadi::FunctionInternal::n_in_.

◆ convert_arg() [2/2]

template<typename M >
std::map< std::string, M > casadi::FunctionInternal::convert_arg ( const std::vector< M > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ks

Definition at line 1880 of file function_internal.hpp.

1881  {
1882  casadi_assert(arg.size()==n_in_, "Incorrect number of inputs: Expected "
1883  + str(n_in_) + ", got " + str(arg.size()));
1884  std::map<std::string, M> ret;
1885  for (casadi_int i=0;i<n_in_;++i) {
1886  ret[name_in_[i]] = arg[i];
1887  }
1888  return ret;
1889  }

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::name_in_, and casadi::str().

◆ convert_res() [1/2]

template<typename M >
std::vector< M > casadi::FunctionInternal::convert_res ( const std::map< std::string, M > &  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ks

Definition at line 1921 of file function_internal.hpp.

1922  {
1923  // Get default inputs
1924  std::vector<M> res_v(n_out_);
1925  for (casadi_int i=0; i<res_v.size(); ++i) {
1926  res_v[i] = std::numeric_limits<double>::quiet_NaN();
1927  }
1928 
1929  // Assign provided inputs
1930  for (auto&& e : res) {
1931  M a = e.second;
1932  res_v.at(index_out(e.first)) = a;
1933  }
1934  return res_v;
1935  }
casadi_int index_out(const std::string &name) const
Get output scheme index by name.

References casadi::FunctionInternal::index_out(), and casadi::FunctionInternal::n_out_.

◆ convert_res() [2/2]

template<typename M >
std::map< std::string, M > casadi::FunctionInternal::convert_res ( const std::vector< M > &  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ks

Definition at line 1909 of file function_internal.hpp.

1910  {
1911  casadi_assert(res.size()==n_out_, "Incorrect number of outputs: Expected "
1912  + str(n_out_) + ", got " + str(res.size()));
1913  std::map<std::string, M> ret;
1914  for (casadi_int i=0;i<n_out_;++i) {
1915  ret[name_out_[i]] = res[i];
1916  }
1917  return ret;
1918  }

References casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_out_, and casadi::str().

◆ create_advanced()

Function casadi::Integrator::create_advanced ( const Dict opts)
virtualinherited

Helper for a more powerful 'integrator' factory

Reimplemented in casadi::FixedStepIntegrator.

Definition at line 350 of file integrator.cpp.

350  {
351  return Function::create(this, opts);
352 }
static Function create(FunctionInternal *node)
Create from node.
Definition: function.cpp:488

References casadi::Function::create().

Referenced by casadi::integrator().

◆ create_forward()

Function casadi::OracleFunction::create_forward ( const std::string &  fname,
casadi_int  nfwd 
)
inherited

Create an oracle function as a forward derivative of a different function

Definition at line 278 of file oracle_function.cpp.

278  {
279  // Create derivative
280  Function ret = get_function(fname).forward(nfwd);
281  std::string fwd_name = forward_name(fname, nfwd); // may be different from ret.name()
282  if (!has_function(fwd_name)) set_function(ret, fwd_name, true);
283  return ret;
284 }
void set_function(const Function &fcn, const std::string &fname, bool jit=false)
bool has_function(const std::string &fname) const override

References casadi::FunctionInternal::forward_name(), casadi::OracleFunction::get_function(), casadi::OracleFunction::has_function(), and casadi::OracleFunction::set_function().

Referenced by casadi::Integrator::init(), casadi::ImplicitFixedStepIntegrator::init(), casadi::SLEQPInterface::init(), casadi::SundialsInterface::init(), casadi::UnoInterface::init(), and casadi::RungeKutta::setup_step().

◆ create_function() [1/3]

Function casadi::OracleFunction::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() 
)
inherited

Create an oracle function, using a different oracle function Temporary addition to allow transition from one oracle formulation to another.

Definition at line 235 of file oracle_function.cpp.

239  {
240  // Print progress
241  if (verbose_) {
242  casadi_message(name_ + "::create_function " + fname + ":" + str(s_in) + "->" + str(s_out));
243  }
244 
245  // Check if function is already in cache
246  Function ret;
247  if (incache(fname, ret)) {
248  // Consistency checks
249  casadi_assert(ret.n_in() == s_in.size(), fname + " has wrong number of inputs");
250  casadi_assert(ret.n_out() == s_out.size(), fname + " has wrong number of outputs");
251  } else {
252  // Retrieve specific set of options if available
253  Dict specific_options;
254  auto it = specific_options_.find(fname);
255  if (it!=specific_options_.end()) specific_options = it->second;
256 
257  // Combine specific and common options
258  Dict opt = combine(specific_options, common_options_);
259  opt = combine(opts, opt);
260 
261  // Generate the function
262  ret = oracle.factory(fname, s_in, s_out, aux, opt);
263 
264  // Make sure that it's sound
265  if (ret.has_free()) {
266  casadi_error("Cannot create '" + fname + "' since " + str(ret.get_free()) + " are free.");
267  }
268 
269  // Add to cache
270  tocache_if_missing(ret);
271  }
272 
273  // Save and return
274  set_function(ret, fname, true);
275  return ret;
276 }
void tocache_if_missing(Function &f, const std::string &suffix="") const
Save function to cache, only if missing.
bool incache(const std::string &fname, Function &f, const std::string &suffix="") const
Get function in cache.
Function factory(const std::string &name, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const AuxOut &aux=AuxOut(), const Dict &opts=Dict()) const
Definition: function.cpp:2009
Dict common_options_
Options for creating functions.
const Function & oracle() const override
Get oracle.
Dict combine(const Dict &first, const Dict &second, bool recurse)
Combine two dicts. First has priority.

References casadi::combine(), casadi::OracleFunction::common_options_, casadi::Function::factory(), casadi::Function::get_free(), casadi::Function::has_free(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::ProtoFunction::name_, casadi::OracleFunction::oracle(), casadi::OracleFunction::set_function(), casadi::OracleFunction::specific_options_, casadi::str(), casadi::FunctionInternal::tocache_if_missing(), and casadi::ProtoFunction::verbose_.

Referenced by casadi::OracleFunction::create_function(), casadi::Integrator::init(), casadi::Nlpsol::init(), casadi::AlpaqaInterface::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::MadmpecInterface::init(), casadi::FatropInterface::init(), casadi::IpoptInterface::init(), casadi::KnitroInterface::init(), casadi::MadnlpInterface::init(), casadi::SLEQPInterface::init(), casadi::SnoptInterface::init(), casadi::SundialsInterface::init(), casadi::UnoInterface::init(), casadi::WorhpInterface::init(), casadi::Feasiblesqpmethod::init(), casadi::Qrsqp::init(), and casadi::Sqpmethod::init().

◆ create_function() [2/3]

Function casadi::OracleFunction::create_function ( const std::string &  fname,
const std::vector< MX > &  e_in,
const std::vector< MX > &  e_out,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const Dict opts = Dict() 
)
inherited

Create an oracle function from MX

Definition at line 187 of file oracle_function.cpp.

192  {
193 
194  // Print progress
195  if (verbose_) {
196  casadi_message(name_ + "::create_function " + fname + ":" + str(s_in) + "->" + str(s_out));
197  }
198 
199  // Check if function is already in cache
200  Function ret;
201  if (incache(fname, ret)) {
202  // Consistency checks
203  casadi_assert(ret.n_in() == s_in.size(), fname + " has wrong number of inputs");
204  casadi_assert(ret.n_out() == s_out.size(), fname + " has wrong number of outputs");
205  } else {
206  // Retrieve specific set of options if available
207  Dict specific_options;
208  auto it = specific_options_.find(fname);
209  if (it!=specific_options_.end()) specific_options = it->second;
210 
211  // Combine specific and common options
212  Dict opt = combine(specific_options, common_options_);
213  opt = combine(opts, opt);
214 
215  // Generate the function
216  ret = Function(fname, e_in, e_out, s_in, s_out, opt);
217 
218  // Make sure that it's sound
219  if (ret.has_free()) {
220  casadi_error("Cannot create '" + fname + "' since " + str(ret.get_free()) + " are free.");
221  }
222 
223  // TODO(jgillis) Conditionally convert to SX
224 
225  // Add to cache
226  tocache_if_missing(ret);
227  }
228 
229  // Save and return
230  set_function(ret, fname, true);
231  return ret;
232 
233 }

References casadi::combine(), casadi::OracleFunction::common_options_, casadi::FunctionInternal::Function, casadi::Function::get_free(), casadi::Function::has_free(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::ProtoFunction::name_, casadi::OracleFunction::set_function(), casadi::OracleFunction::specific_options_, casadi::str(), casadi::FunctionInternal::tocache_if_missing(), and casadi::ProtoFunction::verbose_.

◆ create_function() [3/3]

Function casadi::OracleFunction::create_function ( 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() 
)
inherited

Create an oracle function

Definition at line 179 of file oracle_function.cpp.

183  {
184  return create_function(oracle_, fname, s_in, s_out, aux, opts);
185 }
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())

References casadi::OracleFunction::create_function(), and casadi::OracleFunction::oracle_.

◆ creator()

static Integrator* casadi::CvodesInterface::creator ( const std::string &  name,
const Function dae,
double  t0,
const std::vector< double > &  tout 
)
inlinestatic

Definition at line 94 of file cvodes_interface.hpp.

95  {
96  return new CvodesInterface(name, dae, t0, tout);
97  }
CvodesInterface(const std::string &name, const Function &dae, double t0, const std::vector< double > &tout)
Constructor.

Referenced by casadi::casadi_register_integrator_cvodes().

◆ cvodes_error()

void casadi::CvodesInterface::cvodes_error ( const char *  module,
int  flag 
)
staticprotected

Definition at line 391 of file cvodes_interface.cpp.

391  {
392  // Successfull return or warning
393  if (flag>=CV_SUCCESS) return;
394  // Construct error message
395  char* flagname = CVodeGetReturnFlagName(flag);
396  std::stringstream ss;
397  ss << module << " returned \"" << flagname << "\". Consult CVODES documentation.";
398  free(flagname); // NOLINT
399  casadi_error(ss.str());
400 }

◆ dae_out()

static std::vector<std::string> casadi::Integrator::dae_out ( )
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Definition at line 367 of file integrator_impl.hpp.

367 { return {"ode", "alg"}; }

Referenced by casadi::Integrator::init().

◆ debug_repr()

std::string casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::debug_repr ( const Internal *  i) const
inherited

Definition at line 62 of file generic_shared_internal.hpp.

175  {
176  // Note: i != this because of something something multiple inheritance
177  return str( (casadi_int)(i)) + "/" + static_cast<const Internal*>(this)->class_name();
178  }

◆ definition()

std::string casadi::FunctionInternal::definition ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ma

Definition at line 1076 of file function_internal.cpp.

1076  {
1077  std::stringstream s;
1078 
1079  // Print name
1080  s << name_ << ":(";
1081  // Print input arguments
1082  for (casadi_int i=0; i<n_in_; ++i) {
1083  if (!is_diff_in_.empty() && !is_diff_in_[i]) s << "#";
1084  s << name_in_[i] << sparsity_in_[i].postfix_dim() << (i==n_in_-1 ? "" : ",");
1085  }
1086  s << ")->(";
1087  // Print output arguments
1088  for (casadi_int i=0; i<n_out_; ++i) {
1089  if (!is_diff_out_.empty() && !is_diff_out_[i]) s << "#";
1090  s << name_out_[i] << sparsity_out_[i].postfix_dim() << (i==n_out_-1 ? "" : ",");
1091  }
1092  s << ")";
1093 
1094  return s.str();
1095  }

References casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::sparsity_in_, and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::FunctionInternal::codegen(), casadi::FunctionInternal::disp(), casadi::MXFunction::should_inline(), and casadi::SXFunction::should_inline().

◆ deps_version_check()

virtual void casadi::PluginInterface< Integrator >::deps_version_check ( const std::string &  stage) const
inlinevirtualinherited

Definition at line 112 of file plugin_interface.hpp.

112 {}

◆ deserialize()

static ProtoFunction* casadi::CvodesInterface::deserialize ( DeserializingStream s)
inlinestatic

Definition at line 196 of file cvodes_interface.hpp.

196 { return new CvodesInterface(s); }

Referenced by casadi::casadi_register_integrator_cvodes().

◆ destroySingleton()

void casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::destroySingleton ( )
inlineprotectedinherited

Called in the destructor of singletons

Definition at line 77 of file generic_shared_internal.hpp.

77  {
78  static_cast<Internal*>(this)->count--;
79  }

◆ diff_prefix()

std::string casadi::FunctionInternal::diff_prefix ( const std::string &  prefix) const
inherited

Definition at line 2184 of file function_internal.cpp.

2184  {
2185  // Highest index found in current inputs and outputs
2186  casadi_int highest_index = 0;
2187  // Loop over both input names and output names
2188  for (const std::vector<std::string>& name_io : {name_in_, name_out_}) {
2189  for (const std::string& n : name_io) {
2190  // Find end of prefix, skip if no prefix
2191  size_t end = n.find('_');
2192  if (end >= n.size()) continue;
2193  // Skip if too short
2194  if (end < prefix.size()) continue;
2195  // Skip if wrong prefix
2196  if (n.compare(0, prefix.size(), prefix) != 0) continue;
2197  // Beginning of index
2198  size_t begin = prefix.size();
2199  // Check if any index
2200  casadi_int this_index;
2201  if (begin == end) {
2202  // No prefix, implicitly 1
2203  this_index = 1;
2204  } else {
2205  // Read index from string
2206  this_index = std::stoi(n.substr(begin, end - begin));
2207  }
2208  // Find the highest index
2209  if (this_index > highest_index) highest_index = this_index;
2210  }
2211  }
2212  // Return one higher index
2213  if (highest_index == 0) {
2214  return prefix + "_";
2215  } else {
2216  return prefix + std::to_string(highest_index + 1) + "_";
2217  }
2218  }

References casadi::FunctionInternal::name_in_, and casadi::FunctionInternal::name_out_.

Referenced by casadi::FunctionInternal::forward(), casadi::OnnxFunction::has_forward(), casadi::OnnxFunction::has_reverse(), and casadi::FunctionInternal::reverse().

◆ disp()

void casadi::FunctionInternal::disp ( std::ostream &  stream,
bool  more 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_m8

Implements casadi::SharedObjectInternal.

Definition at line 1097 of file function_internal.cpp.

1097  {
1098  stream << definition() << " " << class_name();
1099  if (more) {
1100  stream << std::endl;
1101  disp_more(stream);
1102  }
1103  }
virtual void disp_more(std::ostream &stream) const
Print more.

References casadi::SharedObjectInternal::class_name(), casadi::FunctionInternal::definition(), and casadi::FunctionInternal::disp_more().

Referenced by casadi::MXFunction::eval(), and casadi::SXFunction::eval().

◆ disp_more()

virtual void casadi::FunctionInternal::disp_more ( std::ostream &  stream) const
inlinevirtualinherited

◆ dm_in() [1/2]

const std::vector< DM > casadi::FunctionInternal::dm_in ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Definition at line 3518 of file function_internal.cpp.

3518  {
3519  std::vector<DM> ret(n_in_);
3520  for (casadi_int i=0; i<ret.size(); ++i) {
3521  ret[i] = dm_in(i);
3522  }
3523  return ret;
3524  }
const std::vector< DM > dm_in() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_in_.

Referenced by casadi::FunctionInternal::nz_in().

◆ dm_in() [2/2]

const DM casadi::FunctionInternal::dm_in ( casadi_int  ind) const
inherited

◆ dm_out() [1/2]

const std::vector< DM > casadi::FunctionInternal::dm_out ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Definition at line 3526 of file function_internal.cpp.

3526  {
3527  std::vector<DM> ret(n_out_);
3528  for (casadi_int i=0; i<ret.size(); ++i) {
3529  ret[i] = dm_out(i);
3530  }
3531  return ret;
3532  }
const std::vector< DM > dm_out() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_out_.

Referenced by casadi::FunctionInternal::nz_out().

◆ dm_out() [2/2]

const DM casadi::FunctionInternal::dm_out ( casadi_int  ind) const
inherited

◆ ehfun()

void casadi::CvodesInterface::ehfun ( int  error_code,
const char *  module,
const char *  function,
char *  msg,
void *  user_data 
)
staticprotected

Definition at line 402 of file cvodes_interface.cpp.

403  {
404  try {
405  casadi_assert_dev(user_data);
406  auto m = to_mem(user_data);
407  auto& s = m->self;
408  if (!s.disable_internal_warnings_) {
409  uerr() << msg << std::endl;
410  }
411  } catch(std::exception& e) {
412  uerr() << "ehfun failed: " << e.what() << std::endl;
413  }
414 }
std::ostream & uerr()

References to_mem(), and casadi::uerr().

Referenced by init_mem().

◆ ensure_stacked()

template<typename MatType >
MatType casadi::FunctionInternal::ensure_stacked ( const MatType &  v,
const Sparsity sp,
casadi_int  n 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_26j

Definition at line 1938 of file function_internal.hpp.

1938  {
1939  // Check dimensions
1940  if (v.size1() == sp.size1() && v.size2() == n * sp.size2()) {
1941  // Ensure that sparsity is a horizontal multiple of original input, or has no entries
1942  if (v.nnz() != 0 && !v.sparsity().is_stacked(sp, n)) {
1943  return project(v, repmat(sp, 1, n));
1944  }
1945  } else {
1946  // Correct empty sparsity
1947  casadi_assert_dev(v.is_empty());
1948  return MatType(sp.size1(), sp.size2() * n);
1949  }
1950  // No correction needed
1951  return v;
1952  }

References casadi::Sparsity::size1(), and casadi::Sparsity::size2().

◆ eval()

int casadi::Integrator::eval ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w,
void *  mem 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1m3

Reimplemented from casadi::FunctionInternal.

Definition at line 354 of file integrator.cpp.

355  {
356  auto *m = static_cast<IntegratorMemory*>(mem);
357 
358  // Read inputs
359  const double* x0 = arg[INTEGRATOR_X0];
360  const double* z0 = arg[INTEGRATOR_Z0];
361  const double* p = arg[INTEGRATOR_P];
362  const double* u = arg[INTEGRATOR_U];
363  const double* adj_xf = arg[INTEGRATOR_ADJ_XF];
364  const double* rz0 = arg[INTEGRATOR_ADJ_ZF];
365  const double* rp = arg[INTEGRATOR_ADJ_QF];
366  arg += INTEGRATOR_NUM_IN;
367 
368  // Read outputs
369  double* x = res[INTEGRATOR_XF];
370  double* z = res[INTEGRATOR_ZF];
371  double* q = res[INTEGRATOR_QF];
372  double* adj_x = res[INTEGRATOR_ADJ_X0];
373  double* adj_p = res[INTEGRATOR_ADJ_P];
374  double* adj_u = res[INTEGRATOR_ADJ_U];
375  res += INTEGRATOR_NUM_OUT;
376 
377  // Setup memory object
378  setup(m, arg, res, iw, w);
379 
380  // Pass initial state, parameters
381  set_q(m, nullptr);
382  set_x(m, x0);
383  set_z(m, z0);
384  set_p(m, p);
385 
386  // Reset number of events
387  m->num_events = 0;
388 
389  // Is this the first call to reset?
390  bool first_call = true;
391 
392  // Take time to t0
393  m->t = t0_;
394 
395  // Ensure that control is updated at the first iteration
396  casadi_int k_stop = -1;
397 
398  // Do we need to reset the solver?
399  m->reset_solver = false;
400 
401  // Integrate forward
402  for (m->k = 0; m->k < nt(); ++m->k) {
403  // Start of the current interval
404  m->t_start = m->t;
405  // Next output time
406  m->t_next_out = tout_[m->k];
407  // By default, integrate until the next output time
408  m->t_next = m->t_next_out;
409  // Handle changes in control input
410  if (m->k > k_stop) {
411  // Pass new controls
412  set_u(m, u);
413  // Detect next stopping time
414  k_stop = next_stop(m->k, u);
415  m->t_stop = m->t_step = tout_[k_stop];
416  // Need to reset solver
417  m->reset_solver = true;
418  }
419  // Mark all events as not triggered
420  std::fill_n(m->event_triggered, ne_, 0);
421  // Keep integrating until we reach the next output time
422  do {
423  // Reset the solver
424  if (m->reset_solver) {
425  reset(m, first_call);
426  m->reset_solver = false;
427  first_call = false;
428  }
429  // Advance solution
430  if (verbose_) {
431  casadi_message("Interval " + str(m->k) + ": Integrating forward from "
432  + str(m->t) + " to " + str(m->t_next) + ", t_stop = " + str(m->t_stop));
433  }
434  if (advance(m)) return 1;
435  // Trigger all event, if any
436  if (m->event_index >= 0) {
437  // Clear list of triggered events
438  std::fill_n(m->event_triggered, ne_, 0);
439  // Trigger the specific event and any chained events
440  while (m->event_index >= 0) {
441  // Trigger event, get any chained event
442  if (trigger_event(m, &m->event_index)) return 1;
443  // Solver needs to be reset
444  m->reset_solver = true;
445  }
446  // Move past event
447  m->t_start = m->t;
448  m->t_stop = m->t_step;
449  m->t_next = m->t_next_out;
450  }
451  } while (m->t != m->t_next);
452  // Get solution
453  get_x(m, x);
454  get_z(m, z);
455  get_q(m, q);
456  if (x) x += nx_;
457  if (z) z += nz_;
458  if (q) q += nq_;
459  if (u) u += nu_;
460  }
461 
462  // Backwards integration, if needed
463  if (nrx_ > 0) {
464  // Take adj_xf, rz0, rp past the last grid point
465  if (adj_xf) adj_xf += nrx_ * nt();
466  if (rz0) rz0 += nrz_ * nt();
467  if (rp) rp += nrp_ * nt();
468  if (adj_u) adj_u += nuq_ * nt();
469  // Next stop time due to step change in input
470  k_stop = nt();
471  // Reset the solver
472  resetB(m);
473  // Any adjoint seed so far?
474  bool any_impulse = false;
475  // Integrate backward
476  for (m->k = nt(); m->k-- > 0; ) {
477  m->t = tout_[m->k];
478  // Add impulse to backwards integration
479  if (adj_xf) adj_xf -= nrx_;
480  if (rz0) rz0 -= nrz_;
481  if (rp) rp -= nrp_;
482  if (adj_u) adj_u -= nuq_;
483  if (u) u -= nu_;
484  if (!all_zero(adj_xf, nrx_) || !all_zero(rz0, nrz_) || !all_zero(rp, nrp_)) {
485  if (verbose_) casadi_message("Impulse from adjoint seeds at output time " + str(m->k));
486  impulseB(m, adj_xf, rz0, rp);
487  any_impulse = true;
488  }
489  // Next output time, or beginning
490  casadi_int k_next = m->k - 1;
491  m->t_next = k_next < 0 ? t0_ : tout_[k_next];
492  // Update integrator stopping time
493  if (k_next < k_stop) k_stop = next_stopB(m->k, u);
494  m->t_stop = k_stop < 0 ? t0_ : tout_[k_stop];
495  // Proceed to the previous time point or t0
496  if (any_impulse) {
497  if (verbose_) casadi_message("Integrating backward from output time " + str(m->k)
498  + ": t_next = " + str(m->t_next) + ", t_stop = " + str(m->t_stop));
499  if (m->k > 0) {
500  retreat(m, u, nullptr, nullptr, adj_u);
501  } else {
502  retreat(m, u, adj_x, adj_p, adj_u);
503  }
504  } else {
505  if (verbose_) casadi_message("No adjoint seeds from output time " + str(m->k)
506  + ": t_next = " + str(m->t_next) + ", t_stop = " + str(m->t_stop));
507  casadi_clear(adj_u, nuq_);
508  if (m->k == 0) {
509  casadi_clear(adj_x, nrx_);
510  casadi_clear(adj_p, nrq_);
511  }
512  }
513  }
514  // adj_u should contain the contribution from the grid point, not cumulative
515  if (adj_u) {
516  for (m->k = 0; m->k < nt() - 1; ++m->k) {
517  casadi_axpy(nuq_, -1., adj_u + nuq_, adj_u);
518  adj_u += nuq_;
519  }
520  }
521  }
522 
523  // Collect oracle statistics
524  join_results(m);
525 
526  // Print integrator statistics
527  if (print_stats_) print_stats(m);
528 
529  return 0;
530 }
void setup(void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
Set the (persistent and temporary) work vectors.
virtual void reset(IntegratorMemory *mem, bool first_call) const
Reset the forward solver at the start or after an event.
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
void set_x(IntegratorMemory *m, const double *x) const
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.
Definition: integrator.cpp:532
void get_q(IntegratorMemory *m, double *q) const
casadi_int next_stop(casadi_int k, const double *u) const
Find next stop time.
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 nt() const
Number of output times.
void set_u(IntegratorMemory *m, const double *u) const
bool print_stats_
Options.
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.
void get_x(IntegratorMemory *m, double *x) const
virtual void print_stats(IntegratorMemory *mem) const
Print solver statistics.
int trigger_event(IntegratorMemory *m, casadi_int *ind) const
Trigger an event.
static bool all_zero(const double *v, casadi_int n)
Helper function: Vector has only zeros?
std::vector< double > tout_
Output time grid.
void set_q(IntegratorMemory *m, const double *q) const
double t0_
Initial time.
casadi_int nu_
Number of controls.
void set_p(IntegratorMemory *m, const double *p) const
void join_results(OracleMemory *m) const
Combine results from different threads.
@ INTEGRATOR_NUM_OUT
Number of output arguments of an integrator.
Definition: integrator.hpp:259
@ INTEGRATOR_NUM_IN
Number of input arguments of an integrator.
Definition: integrator.hpp:239
void casadi_axpy(casadi_int n, T1 alpha, const T1 *x, T1 *y)
AXPY: y <- a*x + y.

References casadi::Integrator::advance(), casadi::Integrator::all_zero(), casadi::casadi_axpy(), casadi::casadi_clear(), casadi::Integrator::get_q(), casadi::Integrator::get_x(), casadi::Integrator::get_z(), casadi::Integrator::impulseB(), casadi::INTEGRATOR_ADJ_P, casadi::INTEGRATOR_ADJ_QF, casadi::INTEGRATOR_ADJ_U, casadi::INTEGRATOR_ADJ_X0, casadi::INTEGRATOR_ADJ_XF, casadi::INTEGRATOR_ADJ_ZF, casadi::INTEGRATOR_NUM_IN, casadi::INTEGRATOR_NUM_OUT, casadi::INTEGRATOR_P, casadi::INTEGRATOR_QF, casadi::INTEGRATOR_U, casadi::INTEGRATOR_X0, casadi::INTEGRATOR_XF, casadi::INTEGRATOR_Z0, casadi::INTEGRATOR_ZF, casadi::OracleFunction::join_results(), casadi::Integrator::ne_, casadi::Integrator::next_stop(), casadi::Integrator::next_stopB(), casadi::Integrator::nq_, casadi::Integrator::nrp_, casadi::Integrator::nrq_, casadi::Integrator::nrx_, casadi::Integrator::nrz_, casadi::Integrator::nt(), casadi::Integrator::nu_, casadi::Integrator::nuq_, casadi::Integrator::nx_, casadi::Integrator::nz_, casadi::Integrator::print_stats(), casadi::Integrator::print_stats_, casadi::Integrator::reset(), casadi::Integrator::resetB(), casadi::Integrator::retreat(), casadi::Integrator::set_p(), casadi::Integrator::set_q(), casadi::Integrator::set_u(), casadi::Integrator::set_x(), casadi::Integrator::set_z(), casadi::FunctionInternal::setup(), casadi::str(), casadi::Integrator::t0_, casadi::Integrator::tout_, casadi::Integrator::trigger_event(), and casadi::ProtoFunction::verbose_.

◆ eval_activity()

int casadi::FunctionInternal::eval_activity ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
void *  mem 
) const
virtualinherited

bvec bit set = active (possibly nonzero), clear = inactive (definitely zero). Unlike sp_forward (a dependency analysis), this respects multiplicative annihilation and nonzero constants. Default is the sound fallback: all active.

Extra doc: https://github.com/casadi/casadi/wiki/L_2iy

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3015 of file function_internal.cpp.

3016  {
3017  // Sound fallback: we cannot prove any output zero, so mark everything active
3018  for (casadi_int oind=0; oind<n_out_; ++oind) {
3019  if (res[oind]==nullptr) continue;
3020  std::fill_n(res[oind], nnz_out(oind), ~static_cast<bvec_t>(0));
3021  }
3022  return 0;
3023  }
unsigned long long bvec_t

References casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::nnz_out().

◆ eval_dm()

std::vector< DM > casadi::FunctionInternal::eval_dm ( const std::vector< DM > &  arg) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ke

Reimplemented in casadi::CallbackInternal.

Definition at line 2167 of file function_internal.cpp.

2167  {
2168  casadi_error("'eval_dm' not defined for " + class_name());
2169  }

References casadi::SharedObjectInternal::class_name().

Referenced by casadi::FunctionInternal::eval().

◆ eval_gen() [1/3]

int casadi::FunctionInternal::eval_gen ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kf

Definition at line 445 of file function_internal.hpp.

446  {
447  return sp_forward(arg, res, iw, w, mem);
448  }
virtual int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, void *mem) const
Propagate sparsity forward.

◆ eval_gen() [2/3]

int casadi::FunctionInternal::eval_gen ( const double **  arg,
double **  res,
casadi_int *  iw,
double *  w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kb

Definition at line 965 of file function_internal.cpp.

967  {
968  casadi_int dump_id = (dump_in_ || dump_out_ || dump_) ? get_dump_id() : 0;
969  if (dump_in_) dump_in(dump_id, arg);
970  if (dump_ && dump_id==0) dump();
971  if (print_in_) print_in(uout(), arg, false);
972  auto *m = static_cast<ProtoFunctionMemory*>(mem);
973 
974  // Avoid memory corruption
975  for (casadi_int i=0;i<n_in_;++i) {
976  casadi_assert(arg[i]==nullptr || arg[i]+nnz_in(i)<=w || arg[i]>=w+sz_w(),
977  "Memory corruption detected for input " + name_in_[i] + ".\n"+
978  "arg[" + str(i) + "] " + str(arg[i]) + "-" + str(arg[i]+nnz_in(i)) +
979  " intersects with w " + str(w)+"-"+str(w+sz_w())+".");
980  }
981  for (casadi_int i=0;i<n_out_;++i) {
982  casadi_assert(res[i]==nullptr || res[i]+nnz_out(i)<=w || res[i]>=w+sz_w(),
983  "Memory corruption detected for output " + name_out_[i]);
984  }
985  // Reset statistics
986  for (auto&& s : m->fstats) s.second.reset();
987  if (m->t_total) m->t_total->tic();
988  int ret;
989  if (eval_) {
990  auto *m = static_cast<FunctionMemory*>(mem);
991  m->stats_available = true;
992  int mem_ = 0;
993  if (checkout_) {
994 #ifdef CASADI_WITH_THREAD
995  std::lock_guard<std::mutex> lock(mtx_);
996 #endif //CASADI_WITH_THREAD
997  mem_ = checkout_();
998  }
999  ret = eval_(arg, res, iw, w, mem_);
1000  if (release_) {
1001 #ifdef CASADI_WITH_THREAD
1002  std::lock_guard<std::mutex> lock(mtx_);
1003 #endif //CASADI_WITH_THREAD
1004  release_(mem_);
1005  }
1006  } else {
1007  ret = eval(arg, res, iw, w, mem);
1008  }
1009  if (m->t_total) m->t_total->toc();
1010  // Show statistics
1011  print_time(m->fstats);
1012 
1013  if (dump_out_) dump_out(dump_id, res);
1014  if (print_out_) print_out(uout(), res, false);
1015  // Check all outputs for NaNs
1016  if (regularity_check_) {
1017  for (casadi_int i = 0; i < n_out_; ++i) {
1018  // Skip of not calculated
1019  if (!res[i]) continue;
1020  // Loop over nonzeros
1021  casadi_int nnz = this->nnz_out(i);
1022  for (casadi_int nz = 0; nz < nnz; ++nz) {
1023  if (isnan(res[i][nz]) || isinf(res[i][nz])) {
1024  // Throw readable error message
1025  casadi_error(str(res[i][nz]) + " detected for output " + name_out_[i] + " at "
1026  + sparsity_out(i).repr_el(nz));
1027  }
1028  }
1029  }
1030  }
1031  return ret;
1032  }
void print_in(std::ostream &stream, const double **arg, bool truncate) const
Print inputs.
casadi_release_t release_
Release redirected to a C function.
virtual int eval(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const
Evaluate numerically.
eval_t eval_
Numerical evaluation redirected to a C function.
casadi_checkout_t checkout_
Checkout redirected to a C function.
void print_out(std::ostream &stream, double **res, bool truncate) const
Print outputs.
void print_time(const std::map< std::string, FStats > &fstats) const
Print timing statistics.
std::ostream & uout()

References casadi::FunctionInternal::checkout_, casadi::FunctionInternal::dump_, casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::FunctionInternal::eval(), casadi::FunctionInternal::eval_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out(), casadi::FunctionInternal::print_out_, casadi::ProtoFunction::print_time(), casadi::ProtoFunction::regularity_check_, casadi::FunctionInternal::release_, casadi::FunctionInternal::sparsity_out(), casadi::FunctionMemory::stats_available, casadi::str(), casadi::FunctionInternal::sz_w(), and casadi::uout().

Referenced by casadi::FunctionInternal::call_gen().

◆ eval_gen() [3/3]

int casadi::FunctionInternal::eval_gen ( const SXElem **  arg,
SXElem **  res,
casadi_int *  iw,
SXElem w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kf

Definition at line 441 of file function_internal.hpp.

442  {
443  return eval_sx(arg, res, iw, w, mem, always_inline, never_inline);
444  }
virtual int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, void *mem, bool always_inline, bool never_inline) const
Evaluate with symbolic scalars.

◆ eval_mx()

void casadi::FunctionInternal::eval_mx ( const MXVector arg,
MXVector res,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kd

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 2386 of file function_internal.cpp.

2387  {
2388 
2389  always_inline = always_inline || always_inline_;
2390  never_inline = never_inline || never_inline_;
2391 
2392  // The code below creates a call node, to inline, wrap in an MXFunction
2393  if (always_inline) {
2394  casadi_assert(!never_inline, "Inconsistent options for " + str(name_));
2395  wrap().call(arg, res, true);
2396  return;
2397  }
2398 
2399  // Create a call-node
2400  res = Call::create(self(), arg);
2401  }
static std::vector< MX > create(const Function &fcn, const std::vector< MX > &arg)
Create function call node.
Function wrap() const
Wrap in an Function instance consisting of only one MX call.
void call(const std::vector< DM > &arg, std::vector< DM > &res, bool always_inline=false, bool never_inline=false) const
Evaluate the function symbolically or numerically.
Definition: function.cpp:509

References casadi::FunctionInternal::always_inline_, casadi::Function::call(), casadi::Call::create(), casadi::ProtoFunction::name_, casadi::FunctionInternal::never_inline_, casadi::str(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_gen(), casadi::MXFunction::eval_mx(), and casadi::SXFunction::eval_mx().

◆ eval_sx()

int casadi::FunctionInternal::eval_sx ( const SXElem **  arg,
SXElem **  res,
casadi_int *  iw,
SXElem w,
void *  mem,
bool  always_inline,
bool  never_inline 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kc

Reimplemented in casadi::SXFunction, casadi::Switch, casadi::MXFunction, casadi::MapSum, and casadi::Map.

Definition at line 2171 of file function_internal.cpp.

2173  {
2174 
2175  always_inline = always_inline || always_inline_;
2176  never_inline = never_inline || never_inline_;
2177 
2178  casadi_assert(!always_inline, "'eval_sx' not defined for " + class_name() +
2179  " in combination with always_inline true");
2180 
2181  return CallSX::eval_sx(self(), arg, res);
2182  }
static int eval_sx(const Function &f, const SXElem **arg, SXElem **res)
Definition: call_sx.hpp:63

References casadi::FunctionInternal::always_inline_, casadi::SharedObjectInternal::class_name(), casadi::CallSX::eval_sx(), and casadi::FunctionInternal::never_inline_.

Referenced by casadi::MXFunction::eval_sx(), and casadi::SXFunction::eval_sx().

◆ expand()

void casadi::OracleFunction::expand ( )
inherited

Definition at line 455 of file oracle_function.cpp.

455  {
456  oracle_ = oracle_.expand();
457 }
Function expand() const
Expand a function to SX.
Definition: function.cpp:312

References casadi::Function::expand(), and casadi::OracleFunction::oracle_.

Referenced by casadi::Nlpsol::init(), and casadi::OracleFunction::init().

◆ export_code()

void casadi::FunctionInternal::export_code ( const std::string &  lang,
std::ostream &  stream,
const Dict options 
) const
virtualinherited

◆ factory()

Function casadi::FunctionInternal::factory ( const std::string &  name,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out,
const Function::AuxOut aux,
const Dict opts 
) const
virtualinherited

◆ fdae_sp_forward()

int casadi::Integrator::fdae_sp_forward ( SpForwardMem m,
const bvec_t x,
const bvec_t p,
const bvec_t u,
bvec_t ode,
bvec_t alg 
) const
inherited

Definition at line 1002 of file integrator.cpp.

1003  {
1004  // Evaluate nondifferentiated
1005  m->arg[DYN_T] = nullptr; // t
1006  m->arg[DYN_X] = x; // x
1007  m->arg[DYN_Z] = nullptr; // z
1008  m->arg[DYN_P] = p; // p
1009  m->arg[DYN_U] = u; // u
1010  m->res[DAE_ODE] = ode; // ode
1011  m->res[DAE_ALG] = alg; // alg
1012  if (calc_sp_forward("daeF", m->arg, m->res, m->iw, m->w)) return 1;
1013  // Evaluate sensitivities
1014  for (casadi_int i = 0; i < nfwd_; ++i) {
1015  m->arg[DYN_NUM_IN + DAE_ODE] = ode; // out:ode
1016  m->arg[DYN_NUM_IN + DAE_ALG] = alg; // out:alg
1017  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_T] = nullptr; // fwd:t
1018  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_X] = x + (i + 1) * nx1_; // fwd:x
1019  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_Z] = nullptr; // fwd:z
1020  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_P] = p + (i + 1) * np1_; // fwd:p
1021  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_U] = u + (i + 1) * nu1_; // fwd:u
1022  m->res[DAE_ODE] = ode + (i + 1) * nx1_; // fwd:ode
1023  m->res[DAE_ALG] = alg + (i + 1) * nz1_; // fwd:alg
1024  if (calc_sp_forward(forward_name("daeF", 1), m->arg, m->res, m->iw, m->w)) return 1;
1025  }
1026  return 0;
1027 }

References casadi::SpForwardMem::arg, casadi::OracleFunction::calc_sp_forward(), casadi::Integrator::DAE_ALG, casadi::Integrator::DAE_NUM_OUT, casadi::Integrator::DAE_ODE, casadi::DYN_NUM_IN, casadi::DYN_P, casadi::DYN_T, casadi::DYN_U, casadi::DYN_X, casadi::DYN_Z, casadi::FunctionInternal::forward_name(), casadi::SpForwardMem::iw, casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nu1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::SpForwardMem::res, and casadi::SpForwardMem::w.

Referenced by casadi::Integrator::sp_forward().

◆ fdae_sp_reverse()

int casadi::Integrator::fdae_sp_reverse ( SpReverseMem m,
bvec_t x,
bvec_t p,
bvec_t u,
bvec_t ode,
bvec_t alg 
) const
inherited

Definition at line 1264 of file integrator.cpp.

1265  {
1266  // Nondifferentiated inputs
1267  m->arg[DYN_T] = nullptr; // t
1268  m->arg[DYN_X] = x; // x
1269  m->arg[DYN_Z] = nullptr; // z
1270  m->arg[DYN_P] = p; // p
1271  m->arg[DYN_U] = u; // u
1272  // Propagate through sensitivities
1273  for (casadi_int i = 0; i < nfwd_; ++i) {
1274  m->res[DAE_ODE] = ode + (i + 1) * nx1_; // fwd:ode
1275  m->res[DAE_ALG] = alg + (i + 1) * nz1_; // fwd:alg
1276  m->arg[DYN_NUM_IN + DAE_ODE] = ode; // out:ode
1277  m->arg[DYN_NUM_IN + DAE_ALG] = alg; // out:alg
1278  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_T] = nullptr; // fwd:t
1279  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_X] = x + (i + 1) * nx1_; // fwd:x
1280  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_Z] = nullptr; // fwd:z
1281  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_P] = p + (i + 1) * np1_; // fwd:p
1282  m->arg[DYN_NUM_IN + DAE_NUM_OUT + DYN_U] = u + (i + 1) * nu1_; // fwd:u
1283  if (calc_sp_reverse(forward_name("daeF", 1), m->arg, m->res, m->iw, m->w)) return 1;
1284  }
1285  // Propagate through nondifferentiated
1286  m->res[DAE_ODE] = ode; // ode
1287  m->res[DAE_ALG] = alg; // alg
1288  if (calc_sp_reverse("daeF", m->arg, m->res, m->iw, m->w)) return 1;
1289  return 0;
1290 }

References casadi::SpReverseMem::arg, casadi::OracleFunction::calc_sp_reverse(), casadi::Integrator::DAE_ALG, casadi::Integrator::DAE_NUM_OUT, casadi::Integrator::DAE_ODE, casadi::DYN_NUM_IN, casadi::DYN_P, casadi::DYN_T, casadi::DYN_U, casadi::DYN_X, casadi::DYN_Z, casadi::FunctionInternal::forward_name(), casadi::SpReverseMem::iw, casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nu1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::SpReverseMem::res, and casadi::SpReverseMem::w.

Referenced by casadi::Integrator::sp_reverse().

◆ finalize()

void casadi::OracleFunction::finalize ( )
overridevirtualinherited

Reimplemented from casadi::FunctionInternal.

Definition at line 122 of file oracle_function.cpp.

122  {
123  if (post_expand_) {
124  for (auto&& e : all_functions_) {
125  Function& fcn = e.second.f;
126  fcn = fcn.expand();
127  }
128  }
129 
130  // Allocate space for (parallel) evaluations
131  // Lifted from set_function as max_num_threads_ is not known yet in that method
132  for (auto&& e : all_functions_) {
133  Function& fcn = e.second.f;
134  // Compute strides for multi threading
135  size_t sz_arg, sz_res, sz_iw, sz_w;
136  fcn.sz_work(sz_arg, sz_res, sz_iw, sz_w);
137  stride_arg_ = std::max(stride_arg_, sz_arg);
138  stride_res_ = std::max(stride_res_, sz_res);
139  stride_iw_ = std::max(stride_iw_, sz_iw);
140  stride_w_ = std::max(stride_w_, sz_w);
141  bool persistent = false;
142  alloc(fcn, persistent, max_num_threads_);
143  }
144 
145  // Set corresponding monitors
146  for (const std::string& fname : monitor_) {
147  auto it = all_functions_.find(fname);
148  if (it==all_functions_.end()) {
149  casadi_warning("Ignoring monitor '" + fname + "'."
150  " Available functions: " + join(get_function()) + ".");
151  } else {
152  if (it->second.monitored) casadi_warning("Duplicate monitor " + fname);
153  it->second.monitored = true;
154  }
155  }
156 
157  // Check specific options
158  for (auto&& i : specific_options_) {
159  if (all_functions_.find(i.first)==all_functions_.end())
160  casadi_warning("Ignoring specific_options entry '" + i.first+"'."
161  " Available functions: " + join(get_function()) + ".");
162  }
163 
164  // Recursive call
166 }
void finalize() override
Finalize the object creation.
void alloc(const Function &f, bool persistent=false, int num_threads=1)
Ensure work vectors long enough to evaluate function.
std::map< std::string, RegFun > all_functions_
std::vector< std::string > monitor_
std::string join(const std::vector< std::string > &l, const std::string &delim)

References casadi::OracleFunction::all_functions_, casadi::FunctionInternal::alloc(), casadi::Function::expand(), casadi::FunctionInternal::finalize(), casadi::OracleFunction::get_function(), casadi::join(), casadi::OracleFunction::max_num_threads_, casadi::OracleFunction::monitor_, casadi::OracleFunction::post_expand_, casadi::OracleFunction::specific_options_, casadi::OracleFunction::stride_arg_, casadi::OracleFunction::stride_iw_, casadi::OracleFunction::stride_res_, casadi::OracleFunction::stride_w_, casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), and casadi::Function::sz_work().

◆ find()

void casadi::OracleFunction::find ( std::map< FunctionInternal *, std::pair< Function, size_t > > &  all_fun,
casadi_int  max_depth 
) const
overridevirtualinherited

Reimplemented from casadi::FunctionInternal.

Definition at line 548 of file oracle_function.cpp.

549  {
550  // Call to base class
551  FunctionInternal::find(all_fun, max_depth);
552  for (auto&& e : all_functions_) {
553  add_embedded(all_fun, e.second.f, max_depth);
554  }
555 }
void add_embedded(std::map< FunctionInternal *, std::pair< Function, size_t > > &all_fun, const Function &dep, casadi_int max_depth) const
virtual void find(std::map< FunctionInternal *, std::pair< Function, size_t > > &all_fun, casadi_int max_depth) const

References casadi::FunctionInternal::add_embedded(), casadi::OracleFunction::all_functions_, and casadi::FunctionInternal::find().

◆ format_time()

void casadi::ProtoFunction::format_time ( char *  buffer,
double  time 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jt

Definition at line 4059 of file function_internal.cpp.

4059  {
4060  // Always of width 8
4061  casadi_assert_dev(time>=0);
4062  double log_time = log10(time);
4063  int magn = static_cast<int>(floor(log_time));
4064  int iprefix = static_cast<int>(floor(log_time/3));
4065  if (iprefix<-4) {
4066  sprint(buffer, 10, " 0");
4067  return;
4068  }
4069  if (iprefix>=5) {
4070  sprint(buffer, 10, " inf");
4071  return;
4072  }
4073  char prefixes[] = "TGMk munp";
4074  char prefix = prefixes[4-iprefix];
4075 
4076  int rem = magn-3*iprefix;
4077  double time_normalized = time/pow(10, 3*iprefix);
4078 
4079  if (rem==0) {
4080  sprint(buffer, 10, " %1.2f%cs", time_normalized, prefix);
4081  } else if (rem==1) {
4082  sprint(buffer, 10, " %2.2f%cs", time_normalized, prefix);
4083  } else {
4084  sprint(buffer, 10, "%3.2f%cs", time_normalized, prefix);
4085  }
4086  }
void sprint(char *buf, size_t buf_sz, const char *fmt,...) const
C-style formatted printing to string.

References casadi::ProtoFunction::sprint().

Referenced by casadi::ProtoFunction::print_time().

◆ forward()

Function casadi::FunctionInternal::forward ( casadi_int  nfwd) const
inherited

forward(nfwd) returns a cached instance if available, and calls Function get_forward(casadi_int nfwd) if no cached version is available.

Extra doc: https://github.com/casadi/casadi/wiki/L_l0

Definition at line 2220 of file function_internal.cpp.

2220  {
2221  casadi_assert_dev(nfwd>=0);
2222  // Used wrapped function if forward not available
2223  if (!enable_forward_ && !enable_fd_) {
2224  // Derivative information must be available
2225  casadi_assert(has_derivative(), "Derivatives cannot be calculated for " + name_);
2226  return wrap().forward(nfwd);
2227  }
2228  // Retrieve/generate cached
2229  Function f;
2230  std::string fname = forward_name(name_, nfwd);
2231  if (!incache(fname, f)) {
2232  casadi_int i;
2233  // Prefix to be used for forward seeds, sensitivities
2234  std::string pref = diff_prefix("fwd");
2235  // Names of inputs
2236  std::vector<std::string> inames;
2237  for (i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2238  for (i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2239  for (i=0; i<n_in_; ++i) inames.push_back(pref + name_in_[i]);
2240  // Names of outputs
2241  std::vector<std::string> onames;
2242  for (i=0; i<n_out_; ++i) onames.push_back(pref + name_out_[i]);
2243  // Options
2245  if (enable_forward_) {
2246  opts = combine(opts, generate_options("forward"));
2247  } else {
2248  opts = combine(opts, FunctionInternal::generate_options("forward"));
2249  }
2250  opts["derivative_of"] = self();
2251  // Generate derivative function
2252  casadi_assert_dev(enable_forward_ || enable_fd_);
2253  if (enable_forward_) {
2254  f = get_forward(nfwd, fname, inames, onames, opts);
2255  } else {
2256  opts = combine(opts, fd_options_);
2257  // Get FD method
2258  if (fd_method_.empty() || fd_method_=="central") {
2259  f = Function::create(new CentralDiff(fname, nfwd), opts);
2260  } else if (fd_method_=="forward") {
2261  f = Function::create(new ForwardDiff(fname, nfwd), opts);
2262  } else if (fd_method_=="backward") {
2263  f = Function::create(new BackwardDiff(fname, nfwd), opts);
2264  } else if (fd_method_=="smoothing") {
2265  f = Function::create(new Smoothing(fname, nfwd), opts);
2266  } else {
2267  casadi_error("Unknown 'fd_method': " + fd_method_);
2268  }
2269  }
2270  // Consistency check for inputs
2271  casadi_assert_dev(f.n_in()==n_in_ + n_out_ + n_in_);
2272  casadi_int ind=0;
2273  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), size2_in(i));
2274  for (i=0; i<n_out_; ++i) f.assert_size_in(ind++, size1_out(i), size2_out(i));
2275  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), nfwd*size2_in(i));
2276  // Consistency check for outputs
2277  casadi_assert_dev(f.n_out()==n_out_);
2278  for (i=0; i<n_out_; ++i) f.assert_sparsity_out(i, sparsity_out(i), nfwd);
2279  // Save to cache
2280  tocache_if_missing(f);
2281  }
2282  return f;
2283  }
std::string diff_prefix(const std::string &prefix) const
Determine prefix for differentiated functions.
casadi_int size1_out(casadi_int ind) const
Input/output dimensions.
Dict generate_options(const std::string &target) const override
Reconstruct options dict.
virtual 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
Return function that calculates forward derivatives.
Function forward(casadi_int nfwd) const
Get a function that calculates nfwd forward derivatives.
Definition: function.cpp:1324

References casadi::Function::assert_size_in(), casadi::Function::assert_sparsity_out(), casadi::combine(), casadi::Function::create(), casadi::FunctionInternal::der_options_, casadi::FunctionInternal::diff_prefix(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::fd_method_, casadi::FunctionInternal::fd_options_, casadi::Function::forward(), casadi::FunctionInternal::forward_name(), casadi::FunctionInternal::forward_options_, casadi::FunctionInternal::generate_options(), casadi::FunctionInternal::get_forward(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::FunctionInternal::n_in_, casadi::Function::n_out(), casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size1_out(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::size2_out(), casadi::FunctionInternal::sparsity_out(), casadi::FunctionInternal::tocache_if_missing(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_forward(), and casadi::Function::forward().

◆ forward_name()

static std::string casadi::FunctionInternal::forward_name ( const std::string &  fcn,
casadi_int  nfwd 
)
inlinestaticinherited

◆ fquad_sp_forward()

int casadi::Integrator::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
inherited

Definition at line 1029 of file integrator.cpp.

1030  {
1031  // Evaluate nondifferentiated
1032  m->arg[DYN_T] = nullptr; // t
1033  m->arg[DYN_X] = x; // x
1034  m->arg[DYN_Z] = z; // z
1035  m->arg[DYN_P] = p; // p
1036  m->arg[DYN_U] = u; // u
1037  m->res[QUAD_QUAD] = quad; // quad
1038  if (calc_sp_forward("quadF", m->arg, m->res, m->iw, m->w)) return 1;
1039  // Evaluate sensitivities
1040  for (casadi_int i = 0; i < nfwd_; ++i) {
1041  m->arg[DYN_NUM_IN + QUAD_QUAD] = quad; // out:quad
1042  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_T] = nullptr; // fwd:t
1043  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_X] = x + (i + 1) * nx1_; // fwd:x
1044  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_Z] = z + (i + 1) * nz1_; // fwd:z
1045  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_P] = p + (i + 1) * np1_; // fwd:p
1046  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_U] = u + (i + 1) * nu1_; // fwd:u
1047  m->res[QUAD_QUAD] = quad + (i + 1) * nq1_; // fwd:quad
1048  if (calc_sp_forward(forward_name("quadF", 1), m->arg, m->res, m->iw, m->w)) return 1;
1049  }
1050  return 0;
1051 }

References casadi::SpForwardMem::arg, casadi::OracleFunction::calc_sp_forward(), casadi::DYN_NUM_IN, casadi::DYN_P, casadi::DYN_T, casadi::DYN_U, casadi::DYN_X, casadi::DYN_Z, casadi::FunctionInternal::forward_name(), casadi::SpForwardMem::iw, casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nq1_, casadi::Integrator::nu1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::Integrator::QUAD_NUM_OUT, casadi::Integrator::QUAD_QUAD, casadi::SpForwardMem::res, and casadi::SpForwardMem::w.

Referenced by casadi::Integrator::sp_forward().

◆ fquad_sp_reverse()

int casadi::Integrator::fquad_sp_reverse ( SpReverseMem m,
bvec_t x,
bvec_t z,
bvec_t p,
bvec_t u,
bvec_t quad 
) const
inherited

Definition at line 1292 of file integrator.cpp.

1293  {
1294  // Nondifferentiated inputs
1295  m->arg[DYN_T] = nullptr; // t
1296  m->arg[DYN_X] = x; // x
1297  m->arg[DYN_Z] = z; // z
1298  m->arg[DYN_P] = p; // p
1299  m->arg[DYN_U] = u; // u
1300  // Propagate through sensitivities
1301  for (casadi_int i = 0; i < nfwd_; ++i) {
1302  m->res[QUAD_QUAD] = quad + (i + 1) * nq1_; // fwd:quad
1303  m->arg[DYN_NUM_IN + QUAD_QUAD] = quad; // out:quad
1304  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_T] = nullptr; // fwd:t
1305  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_X] = x + (i + 1) * nx1_; // fwd:x
1306  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_Z] = z + (i + 1) * nz1_; // fwd:z
1307  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_P] = p + (i + 1) * np1_; // fwd:p
1308  m->arg[DYN_NUM_IN + QUAD_NUM_OUT + DYN_U] = u + (i + 1) * nu1_; // fwd:u
1309  if (calc_sp_reverse(forward_name("quadF", 1), m->arg, m->res, m->iw, m->w)) return 1;
1310  }
1311  // Propagate through nondifferentiated
1312  m->res[QUAD_QUAD] = quad; // quad
1313  if (calc_sp_reverse("quadF", m->arg, m->res, m->iw, m->w)) return 1;
1314  return 0;
1315 }

References casadi::SpReverseMem::arg, casadi::OracleFunction::calc_sp_reverse(), casadi::DYN_NUM_IN, casadi::DYN_P, casadi::DYN_T, casadi::DYN_U, casadi::DYN_X, casadi::DYN_Z, casadi::FunctionInternal::forward_name(), casadi::SpReverseMem::iw, casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nq1_, casadi::Integrator::nu1_, casadi::Integrator::nx1_, casadi::Integrator::nz1_, casadi::Integrator::QUAD_NUM_OUT, casadi::Integrator::QUAD_QUAD, casadi::SpReverseMem::res, and casadi::SpReverseMem::w.

Referenced by casadi::Integrator::sp_reverse().

◆ free_mem()

void casadi::CvodesInterface::free_mem ( void *  mem) const
inlineoverridevirtual

Reimplemented from casadi::OracleFunction.

Definition at line 127 of file cvodes_interface.hpp.

127 { delete static_cast<CvodesMemory*>(mem);}

◆ free_mx()

std::vector< MX > casadi::FunctionInternal::free_mx ( ) const
virtualinherited

Reimplemented in casadi::MXFunction.

Definition at line 3566 of file function_internal.cpp.

3566  {
3567  casadi_error("'free_mx' only defined for 'MXFunction'");
3568  }

◆ free_sx()

std::vector< SX > casadi::FunctionInternal::free_sx ( ) const
virtualinherited

Reimplemented in casadi::SXFunction.

Definition at line 3570 of file function_internal.cpp.

3570  {
3571  casadi_error("'free_sx' only defined for 'SXFunction'");
3572  }

◆ from_compact()

Sparsity casadi::FunctionInternal::from_compact ( casadi_int  oind,
casadi_int  iind,
const Sparsity sp 
) const
inherited

Definition at line 1985 of file function_internal.cpp.

1986  {
1987  // Return value
1988  Sparsity r = sp;
1989  // Insert rows if sparse output
1990  if (numel_out(oind) != r.size1()) {
1991  casadi_assert_dev(r.size1() == nnz_out(oind));
1992  r.enlargeRows(numel_out(oind), sparsity_out(oind).find());
1993  }
1994  // Insert columns if sparse input
1995  if (numel_in(iind) != r.size2()) {
1996  casadi_assert_dev(r.size2() == nnz_in(iind));
1997  r.enlargeColumns(numel_in(iind), sparsity_in(iind).find());
1998  }
1999  // Return non-compact pattern
2000  return r;
2001  }
casadi_int numel_out() const
Number of input/output elements.
casadi_int numel_in() const
Number of input/output elements.

References casadi::Sparsity::enlargeColumns(), casadi::Sparsity::enlargeRows(), casadi::FunctionInternal::find(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::numel_in(), casadi::FunctionInternal::numel_out(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::FunctionInternal::sparsity_in(), and casadi::FunctionInternal::sparsity_out().

Referenced by casadi::FunctionInternal::jac_sparsity().

◆ fwd_seed()

template<typename MatType >
std::vector< std::vector< MatType > > casadi::FunctionInternal::fwd_seed ( casadi_int  nfwd) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nr

Definition at line 1575 of file function_internal.hpp.

1576  {
1577  std::vector<std::vector<MatType>> fseed(nfwd);
1578  for (casadi_int dir=0; dir<nfwd; ++dir) {
1579  fseed[dir].resize(n_in_);
1580  for (casadi_int iind=0; iind<n_in_; ++iind) {
1581  std::string n = "f" + str(dir) + "_" + name_in_[iind];
1582  Sparsity sp = is_diff_in_[iind] ? sparsity_in(iind) : Sparsity(size_in(iind));
1583  fseed[dir][iind] = MatType::sym(n, sp);
1584  }
1585  }
1586  return fseed;
1587  }

References casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::size_in(), casadi::FunctionInternal::sparsity_in(), and casadi::str().

◆ fwdViaJac()

bool casadi::FunctionInternal::fwdViaJac ( casadi_int  nfwd) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nc

Definition at line 3181 of file function_internal.cpp.

3181  {
3182  if (!enable_forward_ && !enable_fd_) return true;
3183  if (jac_penalty_==-1) return false;
3184 
3185  // Heuristic 1: Jac calculated via forward mode likely cheaper
3186  if (jac_penalty_*static_cast<double>(nnz_in())<nfwd) return true;
3187 
3188  // Heuristic 2: Jac calculated via reverse mode likely cheaper
3189  double w = ad_weight();
3190  if (enable_reverse_ &&
3191  jac_penalty_*(1-w)*static_cast<double>(nnz_out())<w*static_cast<double>(nfwd))
3192  return true; // NOLINT
3193 
3194  return false;
3195  }

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::jac_penalty_, casadi::FunctionInternal::nnz_in(), and casadi::FunctionInternal::nnz_out().

Referenced by casadi::FunctionInternal::call_forward().

◆ generate_dependencies()

std::string casadi::OracleFunction::generate_dependencies ( const std::string &  fname,
const Dict opts 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_j

Reimplemented from casadi::FunctionInternal.

Definition at line 428 of file oracle_function.cpp.

429  {
430  CodeGenerator gen(fname, opts);
431  gen.add(oracle_);
432  for (auto&& e : all_functions_) {
433  if (e.second.jit) gen.add(e.second.f);
434  }
435  return gen.generate();
436 }

References casadi::CodeGenerator::add(), casadi::OracleFunction::all_functions_, casadi::CodeGenerator::generate(), and casadi::OracleFunction::oracle_.

Referenced by casadi::OracleFunction::jit_dependencies().

◆ generate_in()

void casadi::FunctionInternal::generate_in ( const std::string &  fname,
const double **  arg 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ne

Definition at line 794 of file function_internal.cpp.

794  {
795  // Set up output stream
796  auto of_ptr = Filesystem::ofstream_ptr(fname);
797  std::ostream& of = *of_ptr;
798  normalized_setup(of);
799 
800  // Encode each input
801  for (casadi_int i=0; i<n_in_; ++i) {
802  const double* v = arg[i];
803  for (casadi_int k=0;k<nnz_in(i);++k) {
804  normalized_out(of, v ? v[k] : 0);
805  of << std::endl;
806  }
807  }
808  }
static std::unique_ptr< std::ostream > ofstream_ptr(const std::string &path, std::ios_base::openmode mode=std::ios_base::out)
Definition: filesystem.cpp:115
void normalized_setup(std::istream &stream)
void normalized_out(std::ostream &stream, double val)

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::nnz_in(), casadi::normalized_out(), casadi::normalized_setup(), and casadi::Filesystem::ofstream_ptr().

◆ generate_lifted()

void casadi::FunctionInternal::generate_lifted ( Function vdef_fcn,
Function vinit_fcn 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l9

Reimplemented in casadi::MXFunction.

Definition at line 3574 of file function_internal.cpp.

3575  {
3576  casadi_error("'generate_lifted' only defined for 'MXFunction'");
3577  }

◆ generate_options()

Dict casadi::FunctionInternal::generate_options ( const std::string &  target) const
overridevirtualinherited

Reimplemented from casadi::ProtoFunction.

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 389 of file function_internal.cpp.

389  {
390  Dict opts = ProtoFunction::generate_options(target);
391  opts["jac_penalty"] = jac_penalty_;
392  opts["user_data"] = user_data_;
393  opts["inputs_check"] = inputs_check_;
394  if (target!="tmp") opts["jit"] = jit_;
395  opts["jit_cleanup"] = jit_cleanup_;
396  opts["jit_serialize"] = jit_serialize_;
397  opts["compiler"] = compiler_plugin_;
398  opts["jit_options"] = jit_options_;
399  opts["jit_name"] = jit_base_name_;
400  opts["jit_temp_suffix"] = jit_temp_suffix_;
401  opts["ad_weight"] = ad_weight_;
402  opts["ad_weight_sp"] = ad_weight_sp_;
403  opts["always_inline"] = always_inline_;
404  opts["never_inline"] = never_inline_;
405  opts["max_num_dir"] = max_num_dir_;
406  if (target=="clone" || target=="tmp") {
407  opts["enable_forward"] = enable_forward_op_;
408  opts["enable_reverse"] = enable_reverse_op_;
409  opts["enable_jacobian"] = enable_jacobian_op_;
410  opts["enable_fd"] = enable_fd_op_;
411  opts["reverse_options"] = reverse_options_;
412  opts["forward_options"] = forward_options_;
413  opts["jacobian_options"] = jacobian_options_;
414  opts["der_options"] = der_options_;
415  opts["derivative_of"] = derivative_of_;
416  }
417  opts["fd_options"] = fd_options_;
418  opts["fd_method"] = fd_method_;
419  opts["print_in"] = print_in_;
420  opts["print_out"] = print_out_;
421  opts["print_canonical"] = print_canonical_;
422  opts["max_io"] = max_io_;
423  opts["dump_in"] = dump_in_;
424  opts["dump_out"] = dump_out_;
425  opts["dump_dir"] = dump_dir_;
426  opts["dump_format"] = dump_format_;
427  opts["dump"] = dump_;
428  if (target=="clone") {
429  opts["is_diff_in"] = is_diff_in_;
430  opts["is_diff_out"] = is_diff_out_;
431  }
432  if (target=="forward") {
433  opts["is_diff_in"] = join(is_diff_in_, is_diff_out_, is_diff_in_);
434  opts["is_diff_out"] = is_diff_out_;
435  }
436  if (target=="reverse") {
437  opts["is_diff_in"] = join(is_diff_in_, is_diff_out_, is_diff_out_);
438  opts["is_diff_out"] = is_diff_in_;
439  }
440  return opts;
441  }
std::string jit_serialize_
Serialize behaviour.
std::string compiler_plugin_
Just-in-time compiler.
void * user_data_
User-set field.
bool inputs_check_
Errors are thrown if numerical values of inputs look bad.
bool jit_
Use just-in-time compiler.
bool jit_temp_suffix_
Use a temporary name.
bool jit_cleanup_
Cleanup jit source file.
Function derivative_of_
If the function is the derivative of another function.
virtual Dict generate_options(const std::string &target) const
Reconstruct options dict.

References casadi::FunctionInternal::ad_weight_, casadi::FunctionInternal::ad_weight_sp_, casadi::FunctionInternal::always_inline_, casadi::FunctionInternal::compiler_plugin_, casadi::FunctionInternal::der_options_, casadi::FunctionInternal::derivative_of_, casadi::FunctionInternal::dump_, casadi::FunctionInternal::dump_dir_, casadi::FunctionInternal::dump_format_, casadi::FunctionInternal::dump_in_, casadi::FunctionInternal::dump_out_, casadi::FunctionInternal::enable_fd_op_, casadi::FunctionInternal::enable_forward_op_, casadi::FunctionInternal::enable_jacobian_op_, casadi::FunctionInternal::enable_reverse_op_, casadi::FunctionInternal::fd_method_, casadi::FunctionInternal::fd_options_, casadi::FunctionInternal::forward_options_, casadi::ProtoFunction::generate_options(), casadi::FunctionInternal::inputs_check_, casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::FunctionInternal::jac_penalty_, casadi::FunctionInternal::jacobian_options_, casadi::FunctionInternal::jit_, casadi::FunctionInternal::jit_base_name_, casadi::FunctionInternal::jit_cleanup_, casadi::FunctionInternal::jit_options_, casadi::FunctionInternal::jit_serialize_, casadi::FunctionInternal::jit_temp_suffix_, casadi::join(), casadi::FunctionInternal::max_io_, casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::never_inline_, casadi::FunctionInternal::print_canonical_, casadi::FunctionInternal::print_in_, casadi::FunctionInternal::print_out_, casadi::FunctionInternal::reverse_options_, and casadi::FunctionInternal::user_data_.

Referenced by casadi::Function::expand(), casadi::FunctionInternal::forward(), casadi::MXFunction::generate_options(), casadi::SXFunction::generate_options(), casadi::BlazingSplineFunction::get_jacobian(), and casadi::FunctionInternal::reverse().

◆ generate_out()

void casadi::FunctionInternal::generate_out ( const std::string &  fname,
double **  res 
) const
inherited

Definition at line 810 of file function_internal.cpp.

810  {
811  // Set up output stream
812  auto of_ptr = Filesystem::ofstream_ptr(fname);
813  std::ostream& of = *of_ptr;
814  normalized_setup(of);
815 
816  // Encode each input
817  for (casadi_int i=0; i<n_out_; ++i) {
818  const double* v = res[i];
819  for (casadi_int k=0;k<nnz_out(i);++k) {
820  normalized_out(of, v ? v[k] : std::numeric_limits<double>::quiet_NaN());
821  of << std::endl;
822  }
823  }
824  }

References casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_out(), casadi::normalized_out(), casadi::normalized_setup(), and casadi::Filesystem::ofstream_ptr().

◆ get_abstol()

double casadi::SundialsInterface::get_abstol ( ) const
inlineoverridevirtualinherited

Reimplemented from casadi::FunctionInternal.

Definition at line 120 of file sundials_interface.hpp.

120 { return abstol_;}

◆ get_default_in()

virtual double casadi::FunctionInternal::get_default_in ( casadi_int  ind) const
inlinevirtualinherited

◆ get_diff_in()

virtual bool casadi::FunctionInternal::get_diff_in ( casadi_int  i)
inlinevirtualinherited

◆ get_diff_out()

virtual bool casadi::FunctionInternal::get_diff_out ( casadi_int  i)
inlinevirtualinherited

◆ get_forward()

Function casadi::Integrator::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
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1m7

Reimplemented from casadi::FunctionInternal.

Definition at line 1558 of file integrator.cpp.

1561  {
1562  if (verbose_) casadi_message(name_ + "::get_forward");
1563 
1564  // Integrator options
1565  Dict aug_opts = getDerivativeOptions(true);
1566  for (auto&& i : augmented_options_) {
1567  aug_opts[i.first] = i.second;
1568  }
1569 
1570  // Get current DAE, with any existing sensitivity equations augmented
1571  Function this_dae = augmented_dae();
1572 
1573  // Create integrator for augmented DAE
1574  std::string aug_prefix = "fsens" + str(nfwd) + "_";
1575  aug_opts["derivative_of"] = self();
1576  aug_opts["nfwd"] = nfwd;
1577  aug_opts["nadj"] = nadj_;
1578  Function aug_int = integrator(aug_prefix + name_, plugin_name(),
1579  this_dae, t0_, tout_, aug_opts);
1580 
1581  // All inputs of the return function
1582  std::vector<MX> ret_in;
1584 
1585  // Add nondifferentiated inputs to ret_in
1586  for (casadi_int i = 0; i < INTEGRATOR_NUM_IN; ++i) {
1587  ret_in.push_back(MX::sym(integrator_in(i), sparsity_in(i)));
1588  }
1589 
1590  // Add nondifferentiated outputs (unused) to ret_in
1591  for (casadi_int i = 0; i < INTEGRATOR_NUM_OUT; ++i) {
1592  ret_in.push_back(MX::sym("out_" + integrator_out(i), Sparsity(size_out(i))));
1593  }
1594 
1595  // Create symbolic expressions for augmented problem, add forward seeds to ret_in
1596  std::vector<std::vector<MX>> aug_in(INTEGRATOR_NUM_IN);
1597  std::vector<MX> v(nfwd);
1598  for (casadi_int i = 0; i < INTEGRATOR_NUM_IN; ++i) {
1599  for (casadi_int d = 0; d < nfwd; ++d) {
1600  v[d] = MX::sym("fwd" + str(d) + "_" + integrator_in(i), sparsity_in(i));
1601  aug_in[i].push_back(v[d]);
1602  }
1603  ret_in.push_back(horzcat(v));
1604  }
1605 
1606  // Call the augmented integrator
1607  std::vector<MX> integrator_in(INTEGRATOR_NUM_IN);
1608  for (casadi_int i = 0; i < INTEGRATOR_NUM_IN; ++i) {
1609  if (size1_in(i) > 0 && grid_in(i) && nt() > 1) {
1610  // Split nondifferentiated input by grid point
1611  std::vector<MX> ret_in_split = horzsplit_n(ret_in[i], nt());
1612  // Split augmented input by grid point
1613  std::vector<std::vector<MX>> aug_in_split(nfwd);
1614  for (casadi_int d = 0; d < nfwd; ++d) {
1615  aug_in_split[d] = horzsplit_n(aug_in[i][d], nt());
1616  }
1617  // Reorder columns
1618  v.clear();
1619  for (casadi_int k = 0; k < nt(); ++k) {
1620  v.push_back(ret_in_split.at(k));
1621  for (casadi_int d = 0; d < nfwd; ++d) {
1622  v.push_back(aug_in_split[d].at(k));
1623  }
1624  }
1625  } else {
1626  // No reordering necessary
1627  v = aug_in[i];
1628  v.insert(v.begin(), ret_in[i]);
1629  }
1630  // Flatten all elements
1631  for (MX& e : v) e = vec(e);
1632  integrator_in[i] = horzcat(v);
1633  }
1634  std::vector<MX> integrator_out = aug_int(integrator_in);
1635 
1636  // Collect forward sensitivites
1637  std::vector<MX> ret_out;
1638  ret_out.reserve(INTEGRATOR_NUM_OUT);
1639  for (casadi_int i = 0; i < INTEGRATOR_NUM_OUT; ++i) {
1640  // Split return by grid points and sensitivities
1641  casadi_int n_grid = grid_out(i) ? nt() : 1;
1642  std::vector<casadi_int> offset = {0};
1643  for (casadi_int k = 0; k < n_grid; ++k) {
1644  for (casadi_int d = 0; d <= nfwd; ++d) {
1645  offset.push_back(offset.back() + size2_out(i) / n_grid);
1646  }
1647  }
1648  std::vector<MX> integrator_out_split = horzsplit(
1649  reshape(integrator_out[i], size1_out(i), offset.back()), offset);
1650  // Collect sensitivity blocks in the right order
1651  std::vector<MX> ret_out_split;
1652  ret_out_split.reserve(n_grid * nfwd);
1653  for (casadi_int d = 0; d < nfwd; ++d) {
1654  for (casadi_int k = 0; k < n_grid; ++k) {
1655  ret_out_split.push_back(integrator_out_split.at((nfwd + 1) * k + d + 1));
1656  }
1657  }
1658  ret_out.push_back(horzcat(ret_out_split));
1659  }
1660 
1661  Dict options = opts;
1662  options["allow_duplicate_io_names"] = true;
1663 
1664  // Create derivative function and return
1665  return Function(name, ret_in, ret_out, inames, onames, options);
1666 }
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
Dict augmented_options_
Augmented user option.
static bool grid_out(casadi_int i)
Is an output repeated for each grid point?
Definition: integrator.cpp:324
static bool grid_in(casadi_int i)
Is an input repeated for each grid point?
Definition: integrator.cpp:312
Function augmented_dae() const
Generate the augmented DAE system.
Definition: integrator.cpp:919
virtual Dict getDerivativeOptions(bool fwd) const
Set solver specific options to generated augmented integrators.
virtual const char * plugin_name() const=0
std::vector< std::string > integrator_out()
Get integrator output scheme of integrators.
Definition: integrator.cpp:190
std::vector< std::string > integrator_in()
Get input scheme of integrators.
Definition: integrator.cpp:184
Function integrator(const std::string &name, const std::string &solver, const SXDict &dae, const Dict &opts)
Definition: integrator.cpp:134

References casadi::Integrator::augmented_dae(), casadi::Integrator::augmented_options_, casadi::FunctionInternal::Function, casadi::Integrator::getDerivativeOptions(), casadi::Integrator::grid_in(), casadi::Integrator::grid_out(), casadi::integrator(), casadi::integrator_in(), casadi::INTEGRATOR_NUM_IN, casadi::INTEGRATOR_NUM_OUT, casadi::integrator_out(), casadi::Integrator::nadj_, casadi::ProtoFunction::name_, casadi::Integrator::nt(), casadi::PluginInterface< Integrator >::plugin_name(), casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size1_out(), casadi::FunctionInternal::size2_out(), casadi::FunctionInternal::size_out(), casadi::FunctionInternal::sparsity_in(), casadi::str(), casadi::GenericMatrix< MX >::sym(), casadi::Integrator::t0_, casadi::Integrator::tout_, and casadi::ProtoFunction::verbose_.

◆ get_forward_dae()

template<typename MatType >
Function casadi::Integrator::get_forward_dae ( const std::string &  name) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_261

Definition at line 943 of file integrator.cpp.

943  {
944  if (verbose_) casadi_message(name_ + "::get_forward_dae");
945 
946  // Events not implemented
947  casadi_assert(ne_ == 0, "Event support not implemented for Integrator::augmented_dae");
948 
949  // Get input and output expressions
950  std::vector<MatType> arg = MatType::get_input(oracle_);
951  std::vector<MatType> res = oracle_(arg);
952 
953  // Symbolic expression for augmented DAE
954  std::vector<std::vector<MatType>> aug_in(DYN_NUM_IN);
955  for (casadi_int i = 0; i < DYN_NUM_IN; ++i) aug_in[i].push_back(arg.at(i));
956  std::vector<std::vector<MatType>> aug_out(DYN_NUM_OUT);
957  for (casadi_int i = 0; i < DYN_NUM_OUT; ++i) aug_out[i].push_back(res.at(i));
958 
959  // Zero of time dimension
960  MatType zero_t = MatType::zeros(oracle_.sparsity_in(DYN_T));
961 
962  // Augment aug_in with forward sensitivity seeds
963  std::vector<std::vector<MatType>> seed(nfwd_, std::vector<MatType>(DYN_NUM_IN));
964  for (casadi_int d = 0; d < nfwd_; ++d) {
965  // Create expressions for augmented states
966  std::string pref = "aug" + str(d) + "_";
967  for (casadi_int i = 0; i < DYN_NUM_IN; ++i) {
968  if (i == DYN_T) {
969  seed[d][i] = zero_t;
970  } else {
971  seed[d][i] = MatType::sym(pref + dyn_in(i), oracle_.sparsity_in(i));
972  }
973  }
974  // Save to augmented function inputs
975  for (casadi_int i = 0; i < DYN_NUM_IN; ++i) {
976  if (i != DYN_T) aug_in[i].push_back(seed[d][i]);
977  }
978  }
979 
980  // Calculate directional derivatives
981  std::vector<std::vector<MatType>> sens;
982  bool always_inline = oracle_.is_a("SXFunction") || oracle_.is_a("MXFunction");
983  oracle_->call_forward(arg, res, seed, sens, always_inline, false);
984 
985  // Augment aug_out with forward sensitivity equations
986  casadi_assert_dev(sens.size() == nfwd_);
987  for (casadi_int d = 0; d < nfwd_; ++d) {
988  casadi_assert_dev(sens[d].size() == DYN_NUM_OUT);
989  for (casadi_int i = 0; i < DYN_NUM_OUT; ++i) {
990  aug_out[i].push_back(project(sens[d][i], oracle_.sparsity_out(i)));
991  }
992  }
993 
994  // Concatenate arrays
995  for (casadi_int i = 0; i < DYN_NUM_IN; ++i) arg.at(i) = vertcat(aug_in[i]);
996  for (casadi_int i = 0; i < DYN_NUM_OUT; ++i) res.at(i) = vertcat(aug_out[i]);
997 
998  // Convert to oracle function and return
999  return Function(name, arg, res, dyn_in(), dyn_out());
1000 }
const Sparsity & sparsity_out(casadi_int ind) const
Get sparsity of a given output.
Definition: function.cpp:1183
const Sparsity & sparsity_in(casadi_int ind) const
Get sparsity of a given input.
Definition: function.cpp:1167
std::vector< std::string > dyn_out()
Get output scheme of a DAE function.
Definition: integrator.cpp:236
std::vector< std::string > dyn_in()
Get input scheme of a DAE function.
Definition: integrator.cpp:232

References casadi::FunctionInternal::call_forward(), casadi::dyn_in(), casadi::DYN_NUM_IN, casadi::DYN_NUM_OUT, casadi::dyn_out(), casadi::DYN_T, casadi::FunctionInternal::Function, casadi::Function::is_a(), casadi::ProtoFunction::name_, casadi::Integrator::ne_, casadi::Integrator::nfwd_, casadi::OracleFunction::oracle_, casadi::Function::sparsity_in(), casadi::Function::sparsity_out(), casadi::str(), and casadi::ProtoFunction::verbose_.

◆ get_free()

std::vector< std::string > casadi::FunctionInternal::get_free ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mc

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 1071 of file function_internal.cpp.

1071  {
1072  casadi_assert_dev(!has_free());
1073  return std::vector<std::string>();
1074  }
virtual bool has_free() const
Does the function have free variables.

References casadi::FunctionInternal::has_free().

◆ get_function() [1/2]

std::vector< std::string > casadi::OracleFunction::get_function ( ) const
overridevirtualinherited

-1 Indicates irregularity

Extra doc: https://github.com/casadi/casadi/wiki/L_i

Reimplemented from casadi::FunctionInternal.

Definition at line 531 of file oracle_function.cpp.

531  {
532  std::vector<std::string> ret;
533  ret.reserve(all_functions_.size());
534  for (auto&& e : all_functions_) {
535  ret.push_back(e.first);
536  }
537  return ret;
538 }

References casadi::OracleFunction::all_functions_.

Referenced by casadi::Rootfinder::ad_forward(), casadi::Rootfinder::ad_reverse(), casadi::SundialsInterface::calc_daeB(), casadi::OracleFunction::calc_function(), casadi::SundialsInterface::calc_quadB(), casadi::OracleFunction::calc_sp_forward(), casadi::OracleFunction::calc_sp_reverse(), casadi::FastNewton::codegen_body(), casadi::Feasiblesqpmethod::codegen_body(), casadi::Sqpmethod::codegen_body(), casadi::Nlpsol::codegen_declarations(), casadi::MadmpecInterface::codegen_declarations(), casadi::FatropInterface::codegen_declarations(), casadi::IpoptInterface::codegen_declarations(), casadi::MadnlpInterface::codegen_declarations(), casadi::UnoInterface::codegen_declarations(), casadi::FastNewton::codegen_declarations(), casadi::Feasiblesqpmethod::codegen_declarations(), casadi::Sqpmethod::codegen_declarations(), casadi::Feasiblesqpmethod::codegen_feasibility_iterations(), casadi::Nlpsol::codegen_post_solve(), casadi::FixedStepIntegrator::create_advanced(), casadi::OracleFunction::create_forward(), casadi::AlpaqaProblem::eval_hess_L(), casadi::AlpaqaProblem::eval_hess_ψ(), casadi::OracleFunction::finalize(), casadi::Nlpsol::get_forward(), casadi::OracleFunction::get_function(), casadi::AlpaqaProblem::get_hess_L_num_nonzeros(), casadi::AlpaqaProblem::get_hess_ψ_num_nonzeros(), casadi::Nlpsol::get_reverse(), casadi::FixedStepIntegrator::init(), casadi::ImplicitFixedStepIntegrator::init(), casadi::Blocksqp::init(), casadi::BonminInterface::init(), casadi::MadmpecInterface::init(), casadi::FatropInterface::init(), casadi::IpoptInterface::init(), casadi::MadnlpInterface::init(), casadi::SLEQPInterface::init(), casadi::SundialsInterface::init(), casadi::FastNewton::init(), casadi::Feasiblesqpmethod::init(), casadi::Sqpmethod::init(), casadi::OracleFunction::monitored(), casadi::MadmpecInterface::set_ccopt_prob(), casadi::FatropInterface::set_fatrop_prob(), casadi::IpoptInterface::set_ipopt_prob(), casadi::MadnlpInterface::set_madnlp_prob(), casadi::SundialsInterface::set_work(), casadi::Collocation::setup_step(), casadi::RungeKutta::setup_step(), casadi::Integrator::sp_jac_dae(), casadi::Integrator::sp_jac_rdae(), and casadi::FixedStepIntegrator::stepB().

◆ get_function() [2/2]

const Function & casadi::OracleFunction::get_function ( const std::string &  name) const
overridevirtualinherited

Reimplemented from casadi::FunctionInternal.

Definition at line 540 of file oracle_function.cpp.

540  {
541  auto it = all_functions_.find(name);
542  casadi_assert(it!=all_functions_.end(),
543  "No function \"" + name + "\" in " + name_ + ". " +
544  "Available functions: " + join(get_function()) + ".");
545  return it->second.f;
546 }

References casadi::OracleFunction::all_functions_, casadi::OracleFunction::get_function(), casadi::join(), and casadi::ProtoFunction::name_.

◆ get_jac_sparsity()

Sparsity casadi::FunctionInternal::get_jac_sparsity ( casadi_int  oind,
casadi_int  iind,
bool  symmetric 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kz Get, if necessary generate, the sparsity of a Jacobian block

Reimplemented in casadi::FmuFunction, casadi::GenericExternal, casadi::Expm, and casadi::CallbackInternal.

Definition at line 1928 of file function_internal.cpp.

1929  {
1930  if (symmetric) {
1931  casadi_assert(sparsity_out_[oind].is_dense(),
1932  "Symmetry exploitation in Jacobian assumes dense expression. "
1933  "A potential workaround is to apply densify().");
1934  }
1935  // Check if we are able to propagate dependencies through the function
1936  if (has_spfwd() || has_sprev()) {
1937  // Get weighting factor
1938  double w = sp_weight();
1939 
1940  // Skip generation, assume dense
1941  if (w == -1) return Sparsity();
1942 
1943  Sparsity sp;
1944  if (nnz_in(iind) > 3*bvec_size && nnz_out(oind) > 3*bvec_size &&
1946  if (symmetric) {
1947  sp = get_jac_sparsity_hierarchical_symm(oind, iind);
1948  } else {
1949  sp = get_jac_sparsity_hierarchical(oind, iind);
1950  }
1951  } else {
1952  // Number of nonzero inputs and outputs
1953  casadi_int nz_in = nnz_in(iind);
1954  casadi_int nz_out = nnz_out(oind);
1955 
1956  // Number of forward sweeps we must make
1957  casadi_int nsweep_fwd = nz_in/bvec_size;
1958  if (nz_in%bvec_size) nsweep_fwd++;
1959 
1960  // Number of adjoint sweeps we must make
1961  casadi_int nsweep_adj = nz_out/bvec_size;
1962  if (nz_out%bvec_size) nsweep_adj++;
1963 
1964  // Use forward mode?
1965  if (w*static_cast<double>(nsweep_fwd) <= (1-w)*static_cast<double>(nsweep_adj)) {
1966  sp = get_jac_sparsity_gen<true>(oind, iind);
1967  } else {
1968  sp = get_jac_sparsity_gen<false>(oind, iind);
1969  }
1970  }
1971  return sp;
1972  } else {
1973  // Not calculated
1974  return Sparsity();
1975  }
1976  }
virtual bool has_sprev() const
Is the class able to propagate seeds through the algorithm?
Sparsity get_jac_sparsity_hierarchical_symm(casadi_int oind, casadi_int iind) const
virtual double sp_weight() const
Weighting factor for chosing forward/reverse mode,.
Sparsity get_jac_sparsity_hierarchical(casadi_int oind, casadi_int iind) const
A flavor of get_jac_sparsity_gen that does hierarchical block structure recognition.
std::vector< double > nz_in(const std::vector< DM > &arg) const
Convert from/to flat vector of input/output nonzeros.
std::vector< double > nz_out(const std::vector< DM > &res) const
Convert from/to flat vector of input/output nonzeros.
virtual bool has_spfwd() const
Is the class able to propagate seeds through the algorithm?
static bool hierarchical_sparsity
const int bvec_size

References casadi::bvec_size, casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm(), casadi::FunctionInternal::has_spfwd(), casadi::FunctionInternal::has_sprev(), casadi::GlobalOptions::hierarchical_sparsity, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::nz_out(), casadi::FunctionInternal::sp_weight(), and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::Expm::get_jac_sparsity(), casadi::GenericExternal::get_jac_sparsity(), and casadi::FunctionInternal::jac_sparsity().

◆ get_jac_sparsity_gen()

template<bool fwd>
Sparsity casadi::FunctionInternal::get_jac_sparsity_gen ( casadi_int  oind,
casadi_int  iind 
) const
inherited

Definition at line 1273 of file function_internal.cpp.

1273  {
1274  // Number of nonzero inputs and outputs
1275  casadi_int nz_in = nnz_in(iind);
1276  casadi_int nz_out = nnz_out(oind);
1277 
1278  // Evaluation buffers
1279  std::vector<typename JacSparsityTraits<fwd>::arg_t> arg(sz_arg(), nullptr);
1280  std::vector<bvec_t*> res(sz_res(), nullptr);
1281  std::vector<casadi_int> iw(sz_iw());
1282  std::vector<bvec_t> w(sz_w(), 0);
1283 
1284  // Seeds and sensitivities
1285  std::vector<bvec_t> seed(nz_in, 0);
1286  arg[iind] = get_ptr(seed);
1287  std::vector<bvec_t> sens(nz_out, 0);
1288  res[oind] = get_ptr(sens);
1289  if (!fwd) std::swap(seed, sens);
1290 
1291  // Number of forward sweeps we must make
1292  casadi_int nsweep = seed.size() / bvec_size;
1293  if (seed.size() % bvec_size) nsweep++;
1294 
1295  // Print
1296  if (verbose_) {
1297  casadi_message(str(nsweep) + std::string(fwd ? " forward" : " reverse") + " sweeps "
1298  "needed for " + str(seed.size()) + " directions");
1299  }
1300 
1301  // Progress
1302  casadi_int progress = -10;
1303 
1304  // Temporary vectors
1305  std::vector<casadi_int> jcol, jrow;
1306 
1307  // Loop over the variables, bvec_size variables at a time
1308  for (casadi_int s=0; s<nsweep; ++s) {
1309 
1310  // Print progress
1311  if (verbose_) {
1312  casadi_int progress_new = (s*100)/nsweep;
1313  // Print when entering a new decade
1314  if (progress_new / 10 > progress / 10) {
1315  progress = progress_new;
1316  casadi_message(str(progress) + " %");
1317  }
1318  }
1319 
1320  // Nonzero offset
1321  casadi_int offset = s*bvec_size;
1322 
1323  // Number of local seed directions
1324  casadi_int ndir_local = seed.size()-offset;
1325  ndir_local = std::min(static_cast<casadi_int>(bvec_size), ndir_local);
1326 
1327  for (casadi_int i=0; i<ndir_local; ++i) {
1328  seed[offset+i] |= bvec_t(1)<<i;
1329  }
1330 
1331  // Propagate the dependencies
1332  JacSparsityTraits<fwd>::sp(this, get_ptr(arg), get_ptr(res),
1333  get_ptr(iw), get_ptr(w), memory(0));
1334 
1335  // Loop over the nonzeros of the output
1336  for (casadi_int el=0; el<sens.size(); ++el) {
1337 
1338  // Get the sparsity sensitivity
1339  bvec_t spsens = sens[el];
1340 
1341  if (!fwd) {
1342  // Clear the sensitivities for the next sweep
1343  sens[el] = 0;
1344  }
1345 
1346  // If there is a dependency in any of the directions
1347  if (spsens!=0) {
1348 
1349  // Loop over seed directions
1350  for (casadi_int i=0; i<ndir_local; ++i) {
1351 
1352  // If dependents on the variable
1353  if ((bvec_t(1) << i) & spsens) {
1354  // Add to pattern
1355  jcol.push_back(el);
1356  jrow.push_back(i+offset);
1357  }
1358  }
1359  }
1360  }
1361 
1362  // Remove the seeds
1363  for (casadi_int i=0; i<ndir_local; ++i) {
1364  seed[offset+i] = 0;
1365  }
1366  }
1367 
1368  // Construct sparsity pattern and return
1369  if (!fwd) swap(jrow, jcol);
1370  Sparsity ret = Sparsity::triplet(nz_out, nz_in, jcol, jrow);
1371  if (verbose_) {
1372  casadi_message("Formed Jacobian sparsity pattern (dimension " + str(ret.size()) + ", "
1373  + str(ret.nnz()) + " (" + str(ret.density()) + " %) nonzeros.");
1374  }
1375  return ret;
1376  }
static Sparsity triplet(casadi_int nrow, casadi_int ncol, const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, std::vector< casadi_int > &mapping, bool invert_mapping)
Create a sparsity pattern given the nonzeros in sparse triplet form *.
Definition: sparsity.cpp:1143

References casadi::bvec_size, casadi::Sparsity::density(), casadi::get_ptr(), casadi::ProtoFunction::memory(), casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::nz_out(), casadi::Sparsity::size(), casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::Sparsity::triplet(), and casadi::ProtoFunction::verbose_.

◆ get_jac_sparsity_hierarchical()

Sparsity casadi::FunctionInternal::get_jac_sparsity_hierarchical ( casadi_int  oind,
casadi_int  iind 
) const
inherited

Decide which ad_mode to take

Definition at line 1613 of file function_internal.cpp.

1613  {
1614  // Number of nonzero inputs
1615  casadi_int nz_in = nnz_in(iind);
1616 
1617  // Number of nonzero outputs
1618  casadi_int nz_out = nnz_out(oind);
1619 
1620  // Seeds and sensitivities
1621  std::vector<bvec_t> s_in(nz_in, 0);
1622  std::vector<bvec_t> s_out(nz_out, 0);
1623 
1624  // Evaluation buffers
1625  std::vector<const bvec_t*> arg_fwd(sz_arg(), nullptr);
1626  std::vector<bvec_t*> arg_adj(sz_arg(), nullptr);
1627  arg_fwd[iind] = arg_adj[iind] = get_ptr(s_in);
1628  std::vector<bvec_t*> res(sz_res(), nullptr);
1629  res[oind] = get_ptr(s_out);
1630  std::vector<casadi_int> iw(sz_iw());
1631  std::vector<bvec_t> w(sz_w());
1632 
1633  // Sparsity triplet accumulator
1634  std::vector<casadi_int> jcol, jrow;
1635 
1636  // Cols of the coarse blocks
1637  std::vector<casadi_int> coarse_col(2, 0); coarse_col[1] = nz_out;
1638  // Rows of the coarse blocks
1639  std::vector<casadi_int> coarse_row(2, 0); coarse_row[1] = nz_in;
1640 
1641  // Cols of the fine blocks
1642  std::vector<casadi_int> fine_col;
1643 
1644  // Rows of the fine blocks
1645  std::vector<casadi_int> fine_row;
1646 
1647  // In each iteration, subdivide each coarse block in this many fine blocks
1648  casadi_int subdivision = bvec_size;
1649 
1650  Sparsity r = Sparsity::dense(1, 1);
1651 
1652  // The size of a block
1653  casadi_int granularity_row = nz_in;
1654  casadi_int granularity_col = nz_out;
1655 
1656  bool use_fwd = true;
1657 
1658  casadi_int nsweeps = 0;
1659 
1660  bool hasrun = false;
1661 
1662  // Get weighting factor
1663  double sp_w = sp_weight();
1664 
1665  // Lookup table for bvec_t
1666  std::vector<bvec_t> bvec_lookup;
1667  bvec_lookup.reserve(bvec_size);
1668  for (casadi_int i=0;i<bvec_size;++i) {
1669  bvec_lookup.push_back(bvec_t(1) << i);
1670  }
1671 
1672  while (!hasrun || coarse_col.size()!=nz_out+1 || coarse_row.size()!=nz_in+1) {
1673  if (verbose_) {
1674  casadi_message("Block size: " + str(granularity_col) + " x " + str(granularity_row));
1675  }
1676 
1677  // Clear the sparsity triplet acccumulator
1678  jcol.clear();
1679  jrow.clear();
1680 
1681  // Clear the fine block structure
1682  fine_row.clear();
1683  fine_col.clear();
1684 
1685  // r transpose will be needed in the algorithm
1686  Sparsity rT = r.T();
1687 
1690  // Forward mode
1691  Sparsity D1 = rT.uni_coloring(r);
1692  // Adjoint mode
1693  Sparsity D2 = r.uni_coloring(rT);
1694  if (verbose_) {
1695  casadi_message("Coloring on " + str(r.dim()) + " (fwd seeps: " + str(D1.size2()) +
1696  " , adj sweeps: " + str(D2.size1()) + ")");
1697  }
1698 
1699  // Use whatever required less colors if we tried both (with preference to forward mode)
1700  double fwd_cost = static_cast<double>(use_fwd ? granularity_row : granularity_col) *
1701  sp_w*static_cast<double>(D1.size2());
1702  double adj_cost = static_cast<double>(use_fwd ? granularity_col : granularity_row) *
1703  (1-sp_w)*static_cast<double>(D2.size2());
1704  use_fwd = fwd_cost <= adj_cost;
1705  if (verbose_) {
1706  casadi_message(std::string(use_fwd ? "Forward" : "Reverse") + " mode chosen "
1707  "(fwd cost: " + str(fwd_cost) + ", adj cost: " + str(adj_cost) + ")");
1708  }
1709 
1710  // Get seeds and sensitivities
1711  bvec_t* seed_v = use_fwd ? get_ptr(s_in) : get_ptr(s_out);
1712  bvec_t* sens_v = use_fwd ? get_ptr(s_out) : get_ptr(s_in);
1713 
1714  // The number of zeros in the seed and sensitivity directions
1715  casadi_int nz_seed = use_fwd ? nz_in : nz_out;
1716  casadi_int nz_sens = use_fwd ? nz_out : nz_in;
1717 
1718  // Clear the seeds
1719  for (casadi_int i=0; i<nz_seed; ++i) seed_v[i]=0;
1720 
1721  // Choose the active jacobian coloring scheme
1722  Sparsity D = use_fwd ? D1 : D2;
1723 
1724  // Adjoint mode amounts to swapping
1725  if (!use_fwd) {
1726  std::swap(coarse_col, coarse_row);
1727  std::swap(granularity_col, granularity_row);
1728  std::swap(r, rT);
1729  }
1730 
1731  // Subdivide the coarse block cols
1732  for (casadi_int k=0;k<coarse_col.size()-1;++k) {
1733  casadi_int diff = coarse_col[k+1]-coarse_col[k];
1734  casadi_int new_diff = diff/subdivision;
1735  if (diff%subdivision>0) new_diff++;
1736  std::vector<casadi_int> temp = range(coarse_col[k], coarse_col[k+1], new_diff);
1737  fine_col.insert(fine_col.end(), temp.begin(), temp.end());
1738  }
1739  // Subdivide the coarse block rows
1740  for (casadi_int k=0;k<coarse_row.size()-1;++k) {
1741  casadi_int diff = coarse_row[k+1]-coarse_row[k];
1742  casadi_int new_diff = diff/subdivision;
1743  if (diff%subdivision>0) new_diff++;
1744  std::vector<casadi_int> temp = range(coarse_row[k], coarse_row[k+1], new_diff);
1745  fine_row.insert(fine_row.end(), temp.begin(), temp.end());
1746  }
1747  if (fine_row.back()!=coarse_row.back()) fine_row.push_back(coarse_row.back());
1748  if (fine_col.back()!=coarse_col.back()) fine_col.push_back(coarse_col.back());
1749 
1750  granularity_col = fine_col[1] - fine_col[0];
1751  granularity_row = fine_row[1] - fine_row[0];
1752 
1753  // The index into the bvec bit vector
1754  casadi_int bvec_i = 0;
1755 
1756  // Create lookup tables for the fine blocks
1757  std::vector<casadi_int> fine_col_lookup = lookupvector(fine_col, nz_sens+1);
1758  std::vector<casadi_int> fine_row_lookup = lookupvector(fine_row, nz_seed+1);
1759 
1760  // Triplet data used as a lookup table
1761  std::vector<casadi_int> lookup_col;
1762  std::vector<casadi_int> lookup_row;
1763  std::vector<casadi_int> lookup_value;
1764 
1765 
1766  // The maximum number of fine blocks contained in one coarse block
1767  casadi_int n_fine_blocks_max = 0;
1768  for (casadi_int i=0;i<coarse_row.size()-1;++i) {
1769  casadi_int del = fine_row_lookup[coarse_row[i+1]]-fine_row_lookup[coarse_row[i]];
1770  n_fine_blocks_max = std::max(n_fine_blocks_max, del);
1771  }
1772 
1773  // Loop over all coarse seed directions from the coloring
1774  for (casadi_int csd=0; csd<D.size2(); ++csd) {
1775 
1776  casadi_int fci_offset = 0;
1777  casadi_int fci_cap = bvec_size-bvec_i;
1778 
1779  // Flag to indicate if all fine blocks have been handled
1780  bool f_finished = false;
1781 
1782  // Loop while not finished
1783  while (!f_finished) {
1784 
1785  // Loop over all coarse rows that are found in the coloring for this coarse seed direction
1786  for (casadi_int k=D.colind(csd); k<D.colind(csd+1); ++k) {
1787  casadi_int cci = D.row(k);
1788 
1789  // The first and last rows of the fine block
1790  casadi_int fci_start = fine_row_lookup[coarse_row[cci]];
1791  casadi_int fci_end = fine_row_lookup[coarse_row[cci+1]];
1792 
1793  // Local counter that modifies index into bvec
1794  casadi_int bvec_i_mod = 0;
1795 
1796  casadi_int value = -bvec_i + fci_offset + fci_start;
1797 
1798  // Loop over the rows of the fine block
1799  for (casadi_int fci = fci_offset; fci < std::min(fci_end-fci_start, fci_cap); ++fci) {
1800 
1801  // Loop over the coarse block cols that appear in the coloring
1802  // for the current coarse seed direction
1803  for (casadi_int cri=rT.colind(cci);cri<rT.colind(cci+1);++cri) {
1804  lookup_col.push_back(rT.row(cri));
1805  lookup_row.push_back(bvec_i+bvec_i_mod);
1806  lookup_value.push_back(value);
1807  }
1808 
1809  // Toggle on seeds
1810  bvec_toggle(seed_v, fine_row[fci+fci_start], fine_row[fci+fci_start+1],
1811  bvec_i+bvec_i_mod);
1812  bvec_i_mod++;
1813  }
1814  }
1815 
1816  // Bump bvec_i for next major coarse direction
1817  bvec_i+= std::min(n_fine_blocks_max, fci_cap);
1818 
1819  // Check if bvec buffer is full
1820  if (bvec_i==bvec_size || csd==D.size2()-1) {
1821  // Calculate sparsity for bvec_size directions at once
1822 
1823  // Statistics
1824  nsweeps+=1;
1825 
1826  // Construct lookup table
1827  IM lookup = IM::triplet(lookup_row, lookup_col, lookup_value, bvec_size,
1828  coarse_col.size());
1829 
1830  // Propagate the dependencies
1831  if (use_fwd) {
1832  JacSparsityTraits<true>::sp(this, get_ptr(arg_fwd), get_ptr(res),
1833  get_ptr(iw), get_ptr(w), memory(0));
1834  } else {
1835  std::fill(w.begin(), w.end(), 0);
1836  JacSparsityTraits<false>::sp(this, get_ptr(arg_adj), get_ptr(res),
1837  get_ptr(iw), get_ptr(w), memory(0));
1838  }
1839 
1840  // Temporary bit work vector
1841  bvec_t spsens;
1842 
1843  // Loop over the cols of coarse blocks
1844  for (casadi_int cri=0;cri<coarse_col.size()-1;++cri) {
1845 
1846  // Loop over the cols of fine blocks within the current coarse block
1847  for (casadi_int fri=fine_col_lookup[coarse_col[cri]];
1848  fri<fine_col_lookup[coarse_col[cri+1]];++fri) {
1849  // Lump individual sensitivities together into fine block
1850  bvec_or(sens_v, spsens, fine_col[fri], fine_col[fri+1]);
1851 
1852  // Next iteration if no sparsity
1853  if (!spsens) continue;
1854 
1855  // Loop over all bvec_bits
1856  for (casadi_int bvec_i=0;bvec_i<bvec_size;++bvec_i) {
1857  if (spsens & bvec_lookup[bvec_i]) {
1858  // if dependency is found, add it to the new sparsity pattern
1859  casadi_int ind = lookup.sparsity().get_nz(bvec_i, cri);
1860  if (ind==-1) continue;
1861  jrow.push_back(bvec_i+lookup->at(ind));
1862  jcol.push_back(fri);
1863  }
1864  }
1865  }
1866  }
1867 
1868  // Clear the forward seeds/adjoint sensitivities, ready for next bvec sweep
1869  std::fill(s_in.begin(), s_in.end(), 0);
1870 
1871  // Clear the adjoint seeds/forward sensitivities, ready for next bvec sweep
1872  std::fill(s_out.begin(), s_out.end(), 0);
1873 
1874  // Clean lookup table
1875  lookup_col.clear();
1876  lookup_row.clear();
1877  lookup_value.clear();
1878  }
1879 
1880  if (n_fine_blocks_max>fci_cap) {
1881  fci_offset += std::min(n_fine_blocks_max, fci_cap);
1882  bvec_i = 0;
1883  fci_cap = bvec_size;
1884  } else {
1885  f_finished = true;
1886  }
1887 
1888  }
1889 
1890  }
1891 
1892  // Swap results if adjoint mode was used
1893  if (use_fwd) {
1894  // Construct fine sparsity pattern
1895  r = Sparsity::triplet(fine_row.size()-1, fine_col.size()-1, jrow, jcol);
1896  coarse_col = fine_col;
1897  coarse_row = fine_row;
1898  } else {
1899  // Construct fine sparsity pattern
1900  r = Sparsity::triplet(fine_col.size()-1, fine_row.size()-1, jcol, jrow);
1901  coarse_col = fine_row;
1902  coarse_row = fine_col;
1903  }
1904  hasrun = true;
1905  }
1906  if (verbose_) {
1907  casadi_message("Number of sweeps: " + str(nsweeps));
1908  casadi_message("Formed Jacobian sparsity pattern (dimension " + str(r.size()) + ", " +
1909  str(r.nnz()) + " (" + str(r.density()) + " %) nonzeros.");
1910  }
1911 
1912  return r.T();
1913  }
static Matrix< casadi_int > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< casadi_int > &d)
Construct a sparse matrix from triplet form.
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern *.
Definition: sparsity.cpp:1028
std::vector< casadi_int > range(casadi_int start, casadi_int stop, casadi_int step, casadi_int len)
Range function.
std::vector< casadi_int > lookupvector(const std::vector< casadi_int > &v, casadi_int size)
Returns a vector for quickly looking up entries of supplied list.
Matrix< casadi_int > IM
Definition: im_fwd.hpp:31
std::vector< T > diff(const std::vector< T > &values)
diff
bvec_t bvec_or(const bvec_t *arg, casadi_int n)
Bit-wise or operation on bvec_t array.
void bvec_toggle(bvec_t *s, casadi_int begin, casadi_int end, casadi_int j)

References casadi::bvec_or(), casadi::bvec_size, casadi::bvec_toggle(), casadi::Sparsity::colind(), casadi::D, casadi::Sparsity::dense(), casadi::Sparsity::density(), casadi::diff(), casadi::Sparsity::dim(), casadi::Sparsity::get_nz(), casadi::get_ptr(), casadi::lookupvector(), casadi::ProtoFunction::memory(), casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::nz_in(), casadi::FunctionInternal::nz_out(), casadi::range(), casadi::Sparsity::row(), casadi::Sparsity::size(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::FunctionInternal::sp_weight(), casadi::Matrix< Scalar >::sparsity(), casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::Sparsity::T(), casadi::Sparsity::triplet(), casadi::Matrix< casadi_int >::triplet(), casadi::Sparsity::uni_coloring(), and casadi::ProtoFunction::verbose_.

Referenced by casadi::FunctionInternal::get_jac_sparsity().

◆ get_jac_sparsity_hierarchical_symm()

Sparsity casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm ( casadi_int  oind,
casadi_int  iind 
) const
inherited

A flavor of get_jac_sparsity_gen that does hierarchical block structure recognition for symmetric Jacobians

Definition at line 1378 of file function_internal.cpp.

1379  {
1380  casadi_assert_dev(has_spfwd());
1381 
1382  // Number of nonzero inputs
1383  casadi_int nz = nnz_in(iind);
1384  casadi_assert_dev(nz==nnz_out(oind));
1385 
1386  // Evaluation buffers
1387  std::vector<const bvec_t*> arg(sz_arg(), nullptr);
1388  std::vector<bvec_t*> res(sz_res(), nullptr);
1389  std::vector<casadi_int> iw(sz_iw());
1390  std::vector<bvec_t> w(sz_w());
1391 
1392  // Seeds
1393  std::vector<bvec_t> seed(nz, 0);
1394  arg[iind] = get_ptr(seed);
1395 
1396  // Sensitivities
1397  std::vector<bvec_t> sens(nz, 0);
1398  res[oind] = get_ptr(sens);
1399 
1400  // Sparsity triplet accumulator
1401  std::vector<casadi_int> jcol, jrow;
1402 
1403  // Cols/rows of the coarse blocks
1404  std::vector<casadi_int> coarse(2, 0); coarse[1] = nz;
1405 
1406  // Cols/rows of the fine blocks
1407  std::vector<casadi_int> fine;
1408 
1409  // In each iteration, subdivide each coarse block in this many fine blocks
1410  casadi_int subdivision = bvec_size;
1411 
1412  Sparsity r = Sparsity::dense(1, 1);
1413 
1414  // The size of a block
1415  casadi_int granularity = nz;
1416 
1417  casadi_int nsweeps = 0;
1418 
1419  bool hasrun = false;
1420 
1421  while (!hasrun || coarse.size()!=nz+1) {
1422  if (verbose_) casadi_message("Block size: " + str(granularity));
1423 
1424  // Clear the sparsity triplet acccumulator
1425  jcol.clear();
1426  jrow.clear();
1427 
1428  // Clear the fine block structure
1429  fine.clear();
1430 
1431  Sparsity D = r.star_coloring();
1432 
1433  if (verbose_) {
1434  casadi_message("Star coloring on " + str(r.dim()) + ": "
1435  + str(D.size2()) + " <-> " + str(D.size1()));
1436  }
1437 
1438  // Clear the seeds
1439  std::fill(seed.begin(), seed.end(), 0);
1440 
1441  // Subdivide the coarse block
1442  for (casadi_int k=0; k<coarse.size()-1; ++k) {
1443  casadi_int diff = coarse[k+1]-coarse[k];
1444  casadi_int new_diff = diff/subdivision;
1445  if (diff%subdivision>0) new_diff++;
1446  std::vector<casadi_int> temp = range(coarse[k], coarse[k+1], new_diff);
1447  fine.insert(fine.end(), temp.begin(), temp.end());
1448  }
1449  if (fine.back()!=coarse.back()) fine.push_back(coarse.back());
1450 
1451  granularity = fine[1] - fine[0];
1452 
1453  // The index into the bvec bit vector
1454  casadi_int bvec_i = 0;
1455 
1456  // Create lookup tables for the fine blocks
1457  std::vector<casadi_int> fine_lookup = lookupvector(fine, nz+1);
1458 
1459  // Triplet data used as a lookup table
1460  std::vector<casadi_int> lookup_col;
1461  std::vector<casadi_int> lookup_row;
1462  std::vector<casadi_int> lookup_value;
1463 
1464  // The maximum number of fine blocks contained in one coarse block
1465  casadi_int n_fine_blocks_max = 0;
1466  for (casadi_int i=0;i<coarse.size()-1;++i) {
1467  casadi_int del = fine_lookup[coarse[i+1]]-fine_lookup[coarse[i]];
1468  n_fine_blocks_max = std::max(n_fine_blocks_max, del);
1469  }
1470 
1471  // Loop over all coarse seed directions from the coloring
1472  for (casadi_int csd=0; csd<D.size2(); ++csd) {
1473 
1474 
1475  casadi_int fci_offset = 0;
1476  casadi_int fci_cap = bvec_size-bvec_i;
1477 
1478  // Flag to indicate if all fine blocks have been handled
1479  bool f_finished = false;
1480 
1481  // Loop while not finished
1482  while (!f_finished) {
1483 
1484  // Loop over all coarse rows that are found in the coloring for this coarse seed direction
1485  for (casadi_int k=D.colind(csd); k<D.colind(csd+1); ++k) {
1486  casadi_int cci = D.row(k);
1487 
1488  // The first and last rows of the fine block
1489  casadi_int fci_start = fine_lookup[coarse[cci]];
1490  casadi_int fci_end = fine_lookup[coarse[cci+1]];
1491 
1492  // Local counter that modifies index into bvec
1493  casadi_int bvec_i_mod = 0;
1494 
1495  casadi_int value = -bvec_i + fci_offset + fci_start;
1496 
1497  //casadi_assert_dev(value>=0);
1498 
1499  // Loop over the rows of the fine block
1500  for (casadi_int fci = fci_offset; fci<std::min(fci_end-fci_start, fci_cap); ++fci) {
1501 
1502  // Loop over the coarse block cols that appear in the
1503  // coloring for the current coarse seed direction
1504  for (casadi_int cri=r.colind(cci);cri<r.colind(cci+1);++cri) {
1505  lookup_col.push_back(r.row(cri));
1506  lookup_row.push_back(bvec_i+bvec_i_mod);
1507  lookup_value.push_back(value);
1508  }
1509 
1510  // Toggle on seeds
1511  bvec_toggle(get_ptr(seed), fine[fci+fci_start], fine[fci+fci_start+1],
1512  bvec_i+bvec_i_mod);
1513  bvec_i_mod++;
1514  }
1515  }
1516 
1517  // Bump bvec_i for next major coarse direction
1518  bvec_i += std::min(n_fine_blocks_max, fci_cap);
1519 
1520  // Check if bvec buffer is full
1521  if (bvec_i==bvec_size || csd==D.size2()-1) {
1522  // Calculate sparsity for bvec_size directions at once
1523 
1524  // Statistics
1525  nsweeps+=1;
1526 
1527  // Construct lookup table
1528  IM lookup = IM::triplet(lookup_row, lookup_col, lookup_value,
1529  bvec_size, coarse.size());
1530 
1531  std::reverse(lookup_col.begin(), lookup_col.end());
1532  std::reverse(lookup_row.begin(), lookup_row.end());
1533  std::reverse(lookup_value.begin(), lookup_value.end());
1534  IM duplicates =
1535  IM::triplet(lookup_row, lookup_col, lookup_value, bvec_size, coarse.size())
1536  - lookup;
1537  duplicates = sparsify(duplicates);
1538  lookup(duplicates.sparsity()) = -bvec_size;
1539 
1540  // Propagate the dependencies
1541  JacSparsityTraits<true>::sp(this, get_ptr(arg), get_ptr(res),
1542  get_ptr(iw), get_ptr(w), nullptr);
1543 
1544  // Temporary bit work vector
1545  bvec_t spsens;
1546 
1547  // Loop over the cols of coarse blocks
1548  for (casadi_int cri=0; cri<coarse.size()-1; ++cri) {
1549 
1550  // Loop over the cols of fine blocks within the current coarse block
1551  for (casadi_int fri=fine_lookup[coarse[cri]];fri<fine_lookup[coarse[cri+1]];++fri) {
1552  // Lump individual sensitivities together into fine block
1553  bvec_or(get_ptr(sens), spsens, fine[fri], fine[fri+1]);
1554 
1555  // Loop over all bvec_bits
1556  for (casadi_int bvec_i=0;bvec_i<bvec_size;++bvec_i) {
1557  if (spsens & (bvec_t(1) << bvec_i)) {
1558  // if dependency is found, add it to the new sparsity pattern
1559  casadi_int ind = lookup.sparsity().get_nz(bvec_i, cri);
1560  if (ind==-1) continue;
1561  casadi_int lk = lookup->at(ind);
1562  if (lk>-bvec_size) {
1563  jrow.push_back(bvec_i+lk);
1564  jcol.push_back(fri);
1565  jrow.push_back(fri);
1566  jcol.push_back(bvec_i+lk);
1567  }
1568  }
1569  }
1570  }
1571  }
1572 
1573  // Clear the forward seeds/adjoint sensitivities, ready for next bvec sweep
1574  std::fill(seed.begin(), seed.end(), 0);
1575 
1576  // Clean lookup table
1577  lookup_col.clear();
1578  lookup_row.clear();
1579  lookup_value.clear();
1580  }
1581 
1582  if (n_fine_blocks_max>fci_cap) {
1583  fci_offset += std::min(n_fine_blocks_max, fci_cap);
1584  bvec_i = 0;
1585  fci_cap = bvec_size;
1586  } else {
1587  f_finished = true;
1588  }
1589  }
1590  }
1591 
1592  // Construct fine sparsity pattern
1593  r = Sparsity::triplet(fine.size()-1, fine.size()-1, jrow, jcol);
1594 
1595  // There may be false positives here that are not present
1596  // in the reverse mode that precedes it.
1597  // This can lead to an assymetrical result
1598  // cf. #1522
1599  r=r*r.T();
1600 
1601  coarse = fine;
1602  hasrun = true;
1603  }
1604  if (verbose_) {
1605  casadi_message("Number of sweeps: " + str(nsweeps));
1606  casadi_message("Formed Jacobian sparsity pattern (dimension " + str(r.size()) +
1607  ", " + str(r.nnz()) + " (" + str(r.density()) + " %) nonzeros.");
1608  }
1609 
1610  return r.T();
1611  }

References casadi::bvec_or(), casadi::bvec_size, casadi::bvec_toggle(), casadi::Sparsity::colind(), casadi::D, casadi::Sparsity::dense(), casadi::Sparsity::density(), casadi::diff(), casadi::Sparsity::dim(), casadi::Sparsity::get_nz(), casadi::get_ptr(), casadi::FunctionInternal::has_spfwd(), casadi::lookupvector(), casadi::Sparsity::nnz(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::range(), casadi::Sparsity::row(), casadi::Sparsity::size(), casadi::Matrix< Scalar >::sparsity(), casadi::Sparsity::star_coloring(), casadi::str(), casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), casadi::FunctionInternal::sz_w(), casadi::Sparsity::T(), casadi::Sparsity::triplet(), casadi::Matrix< casadi_int >::triplet(), and casadi::ProtoFunction::verbose_.

Referenced by casadi::FunctionInternal::get_jac_sparsity().

◆ get_jacobian()

Function casadi::FunctionInternal::get_jacobian ( const std::string &  name,
const std::vector< std::string > &  inames,
const std::vector< std::string > &  onames,
const Dict opts 
) const
virtualinherited

◆ get_jit_directory()

std::string casadi::FunctionInternal::get_jit_directory ( const Dict jit_options)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2ec

Definition at line 710 of file function_internal.cpp.

710  {
711  // Start with default temp work dir
712  std::string jit_directory = GlobalOptions::getTempWorkDir();
713 
714  // Get user-specified directory
715  std::string directory;
716  directory = get_from_dict(jit_options, "directory", std::string(""));
717 
718  // What if directory itself is absolute?
719  if (Filesystem::is_absolute(directory)) {
720  // Override
721  jit_directory = directory;
722  } else {
723  jit_directory = jit_directory + directory;
724  if (Filesystem::is_enabled()) {
725  jit_directory = Filesystem::absolute(jit_directory);
726  }
727  }
728 
729  return Filesystem::ensure_trailing_slash(jit_directory);
730  }
static std::string absolute(const std::string &path)
Definition: filesystem.cpp:78
static bool is_absolute(const std::string &path)
Definition: filesystem.cpp:162
static std::string ensure_trailing_slash(const std::string &path)
Definition: filesystem.cpp:155
static bool is_enabled()
Definition: filesystem.cpp:83
static std::string getTempWorkDir()
T get_from_dict(const std::map< std::string, T > &d, const std::string &key, const T &default_value)

References casadi::Filesystem::absolute(), casadi::Filesystem::ensure_trailing_slash(), casadi::get_from_dict(), casadi::GlobalOptions::getTempWorkDir(), casadi::Filesystem::is_absolute(), and casadi::Filesystem::is_enabled().

Referenced by casadi::FunctionInternal::finalize(), and casadi::ShellCompiler::init().

◆ get_max_in()

virtual double casadi::FunctionInternal::get_max_in ( casadi_int  ind) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mm

Definition at line 1103 of file function_internal.hpp.

1103  {
1104  return inf;
1105  }
const double inf
infinity
Definition: calculus.hpp:50

References casadi::inf.

◆ get_min_in()

virtual double casadi::FunctionInternal::get_min_in ( casadi_int  ind) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mn

Definition at line 1110 of file function_internal.hpp.

1110  {
1111  return -inf;
1112  }

References casadi::inf.

◆ get_n_in()

size_t casadi::Integrator::get_n_in ( )
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1lt

Reimplemented from casadi::FunctionInternal.

Definition at line 115 of file integrator_impl.hpp.

115 { return INTEGRATOR_NUM_IN;}

References casadi::INTEGRATOR_NUM_IN.

◆ get_n_out()

size_t casadi::Integrator::get_n_out ( )
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1lt

Reimplemented from casadi::FunctionInternal.

Definition at line 116 of file integrator_impl.hpp.

116 { return INTEGRATOR_NUM_OUT;}

References casadi::INTEGRATOR_NUM_OUT.

◆ get_name_in()

std::string casadi::Integrator::get_name_in ( casadi_int  i)
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1lv

Reimplemented from casadi::FunctionInternal.

Definition at line 131 of file integrator_impl.hpp.

131 { return integrator_in(i);}

References casadi::integrator_in().

◆ get_name_out()

std::string casadi::Integrator::get_name_out ( casadi_int  i)
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1lv

Reimplemented from casadi::FunctionInternal.

Definition at line 132 of file integrator_impl.hpp.

132 { return integrator_out(i);}

References casadi::integrator_out().

◆ get_nominal_in()

virtual std::vector<double> casadi::FunctionInternal::get_nominal_in ( casadi_int  ind) const
inlinevirtualinherited

Reimplemented in casadi::FmuFunction.

Definition at line 1114 of file function_internal.hpp.

1114  {
1115  return std::vector<double>(nnz_in(ind), 1.);
1116  }

Referenced by casadi::FmuFunction::get_nominal_in().

◆ get_nominal_out()

virtual std::vector<double> casadi::FunctionInternal::get_nominal_out ( casadi_int  ind) const
inlinevirtualinherited

Reimplemented in casadi::FmuFunction.

Definition at line 1118 of file function_internal.hpp.

1118  {
1119  return std::vector<double>(nnz_out(ind), 1.);
1120  }

Referenced by casadi::FmuFunction::get_nominal_out().

◆ get_options()

const Options& casadi::CvodesInterface::get_options ( ) const
inlineoverridevirtual

Reimplemented from casadi::Integrator.

Definition at line 111 of file cvodes_interface.hpp.

111 { return options_;}
static const Options options_
Options.

◆ get_partition()

void casadi::FunctionInternal::get_partition ( casadi_int  iind,
casadi_int  oind,
Sparsity D1,
Sparsity D2,
bool  compact,
bool  symmetric,
bool  allow_forward,
bool  allow_reverse 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_md

Definition at line 2068 of file function_internal.cpp.

2070  {
2071  if (verbose_) casadi_message(name_ + "::get_partition");
2072  casadi_assert(allow_forward || allow_reverse, "Inconsistent options");
2073 
2074  // Sparsity pattern with transpose
2075  Sparsity &AT = jac_sparsity(oind, iind, compact, symmetric);
2076  Sparsity A = symmetric ? AT : AT.T();
2077 
2078  // Get seed matrices by graph coloring
2079  if (symmetric) {
2080  casadi_assert_dev(enable_forward_ || enable_fd_);
2081  casadi_assert_dev(allow_forward);
2082 
2083  // Star coloring if symmetric
2084  if (verbose_) casadi_message("FunctionInternal::getPartition star_coloring");
2085  D1 = A.star_coloring();
2086  if (verbose_) {
2087  casadi_message("Star coloring completed: " + str(D1.size2())
2088  + " directional derivatives needed ("
2089  + str(A.size1()) + " without coloring).");
2090  }
2091 
2092  } else {
2093  casadi_assert_dev(enable_forward_ || enable_fd_ || enable_reverse_);
2094  // Get weighting factor
2095  double w = ad_weight();
2096 
2097  // Which AD mode?
2098  if (w==1) allow_forward = false;
2099  if (w==0) allow_reverse = false;
2100  casadi_assert(allow_forward || allow_reverse, "Conflicting ad weights");
2101 
2102  // Best coloring encountered so far (relatively tight upper bound)
2103  double best_coloring = std::numeric_limits<double>::infinity();
2104 
2105  // Test forward mode first?
2106  bool test_fwd_first = allow_forward && w*static_cast<double>(A.size1()) <=
2107  (1-w)*static_cast<double>(A.size2());
2108  casadi_int mode_fwd = test_fwd_first ? 0 : 1;
2109 
2110  // Test both coloring modes
2111  for (casadi_int mode=0; mode<2; ++mode) {
2112  // Is this the forward mode?
2113  bool fwd = mode==mode_fwd;
2114 
2115  // Skip?
2116  if (!allow_forward && fwd) continue;
2117  if (!allow_reverse && !fwd) continue;
2118 
2119  // Perform the coloring
2120  if (fwd) {
2121  if (verbose_) casadi_message("Unidirectional coloring (forward mode)");
2122  bool d = best_coloring>=w*static_cast<double>(A.size1());
2123  casadi_int max_colorings_to_test =
2124  d ? A.size1() : static_cast<casadi_int>(floor(best_coloring/w));
2125  D1 = AT.uni_coloring(A, max_colorings_to_test);
2126  if (D1.is_null()) {
2127  if (verbose_) {
2128  casadi_message("Forward mode coloring interrupted (more than "
2129  + str(max_colorings_to_test) + " needed).");
2130  }
2131  } else {
2132  if (verbose_) {
2133  casadi_message("Forward mode coloring completed: "
2134  + str(D1.size2()) + " directional derivatives needed ("
2135  + str(A.size1()) + " without coloring).");
2136  }
2137  D2 = Sparsity();
2138  best_coloring = w*static_cast<double>(D1.size2());
2139  }
2140  } else {
2141  if (verbose_) casadi_message("Unidirectional coloring (adjoint mode)");
2142  bool d = best_coloring>=(1-w)*static_cast<double>(A.size2());
2143  casadi_int max_colorings_to_test =
2144  d ? A.size2() : static_cast<casadi_int>(floor(best_coloring/(1-w)));
2145 
2146  D2 = A.uni_coloring(AT, max_colorings_to_test);
2147  if (D2.is_null()) {
2148  if (verbose_) {
2149  casadi_message("Adjoint mode coloring interrupted (more than "
2150  + str(max_colorings_to_test) + " needed).");
2151  }
2152  } else {
2153  if (verbose_) {
2154  casadi_message("Adjoint mode coloring completed: "
2155  + str(D2.size2()) + " directional derivatives needed ("
2156  + str(A.size2()) + " without coloring).");
2157  }
2158  D1 = Sparsity();
2159  best_coloring = (1-w)*static_cast<double>(D2.size2());
2160  }
2161  }
2162  }
2163 
2164  }
2165  }
Sparsity & jac_sparsity(casadi_int oind, casadi_int iind, bool compact, bool symmetric) const
Get Jacobian sparsity.

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::enable_fd_, casadi::FunctionInternal::enable_forward_, casadi::FunctionInternal::enable_reverse_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jac_sparsity(), casadi::ProtoFunction::name_, casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::Sparsity::star_coloring(), casadi::str(), casadi::Sparsity::T(), casadi::Sparsity::uni_coloring(), and casadi::ProtoFunction::verbose_.

◆ get_q()

void casadi::Integrator::get_q ( IntegratorMemory m,
double *  q 
) const
inherited

Definition at line 2554 of file integrator.cpp.

2554  {
2555  casadi_copy(m->q, nq_, q);
2556 }

References casadi::casadi_copy(), casadi::Integrator::nq_, and casadi::IntegratorMemory::q.

Referenced by casadi::Integrator::eval().

◆ get_reltol()

double casadi::SundialsInterface::get_reltol ( ) const
inlineoverridevirtualinherited

Reimplemented from casadi::FunctionInternal.

Definition at line 117 of file sundials_interface.hpp.

117 { return reltol_;}

◆ get_reverse()

Function casadi::Integrator::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
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1m8

Reimplemented from casadi::FunctionInternal.

Definition at line 1668 of file integrator.cpp.

1671  {
1672  if (verbose_) casadi_message(name_ + "::get_reverse");
1673 
1674  // Events not implemented
1675  casadi_assert(ne_ == 0, "Event support not implemented for Integrator::get_reverse");
1676 
1677  // Integrator options
1678  Dict aug_opts = getDerivativeOptions(false);
1679  for (auto&& i : augmented_options_) {
1680  aug_opts[i.first] = i.second;
1681  }
1682 
1683  // Get the current oracle, augmented with any existing forward sensitivity equations
1684  Function this_dae = augmented_dae();
1685 
1686  // Create integrator for augmented DAE
1687  std::string aug_prefix = "asens" + str(nadj) + "_";
1688  aug_opts["derivative_of"] = self();
1689  if (nrx_ == 0) {
1690  // Add backward problem
1691  aug_opts["nadj"] = nadj;
1692  aug_opts["nfwd"] = 0;
1693  } else {
1694  // Reformulate as forward-over-reverse
1695  aug_opts["nfwd"] = nadj;
1696  aug_opts["nadj"] = nadj_;
1697  }
1698  Function aug_int = integrator(aug_prefix + name_, plugin_name(),
1699  this_dae, t0_, tout_, aug_opts);
1700 
1701  // All inputs of the return function
1702  std::vector<MX> ret_in;
1704 
1705  // Add nondifferentiated inputs to ret_in
1706  for (casadi_int i = 0; i < INTEGRATOR_NUM_IN; ++i) {
1707  ret_in.push_back(MX::sym(integrator_in(i), sparsity_in(i)));
1708  }
1709 
1710  // Add nondifferentiated outputs (unused) to ret_in
1711  for (casadi_int i = 0; i < INTEGRATOR_NUM_OUT; ++i) {
1712  ret_in.push_back(MX::sym("out_" + integrator_out(i), Sparsity(size_out(i))));
1713  }
1714 
1715  // Create symbolic expressions for augmented problem, add adjoint seeds to ret_in
1716  std::vector<std::vector<MX>> aug_in(INTEGRATOR_NUM_OUT);
1717  std::vector<MX> v(nadj);
1718  for (casadi_int i = 0; i < INTEGRATOR_NUM_OUT; ++i) {
1719  for (casadi_int d=0; d<nadj; ++d) {
1720  v[d] = MX::sym("adj" + str(d) + "_" + integrator_out(i), sparsity_out(i));
1721  aug_in[i].push_back(v[d]);
1722  }
1723  ret_in.push_back(horzcat(v));
1724  }
1725 
1726  // Call the augmented integrator
1727  std::vector<MX> integrator_in(INTEGRATOR_NUM_IN);
1728  for (casadi_int i = 0; i < INTEGRATOR_NUM_IN; ++i) {
1729  // Output index contributing to adjoint seeds
1730  casadi_int j = adjmap_out(i);
1731  // Number of grid points for this integrator input
1732  casadi_int n_grid = grid_in(i) ? nt() : 1;
1733  // Split input and seeds by grid points, if necessary
1734  std::vector<MX> ret_in_split;
1735  std::vector<std::vector<MX>> aug_in_split(nadj);
1736  if (size1_in(i) > 0 && grid_in(i) && n_grid > 1) {
1737  // Split nondifferentiated input by grid point
1738  ret_in_split = horzsplit_n(ret_in[i], nt());
1739  // Split augmented input by grid point
1740  for (casadi_int d = 0; d < nadj; ++d) {
1741  aug_in_split[d] = horzsplit_n(aug_in[j][d], nt());
1742  }
1743  } else {
1744  // No reordering necessary
1745  ret_in_split = {ret_in[i]};
1746  for (casadi_int d = 0; d < nadj; ++d) aug_in_split[d] = {aug_in[j][d]};
1747  }
1748  // Vectorize all inputs to allow concatenation (unlike forward sensitivities,
1749  // number of rows for sensitivities may be different from original inputs)
1750  for (auto&& e : ret_in_split) e = vec(e);
1751  for (auto&& e1 : aug_in_split) {
1752  for (auto&& e2 : e1) e2 = vec(e2);
1753  }
1754  // Assemble input argument
1755  v.clear();
1756  for (casadi_int k = 0; k < ret_in_split.size(); ++k) {
1757  v.push_back(ret_in_split.at(k));
1758  for (casadi_int d = 0; d < nadj; ++d) {
1759  v.push_back(aug_in_split[d].at(k));
1760  }
1761  }
1762  integrator_in[i] = reshape(vertcat(v), aug_int.size_in(i));
1763  }
1764  std::vector<MX> integrator_out = aug_int(integrator_in);
1765 
1766  // Collect adjoint sensitivites
1767  std::vector<MX> ret_out;
1768  ret_out.reserve(INTEGRATOR_NUM_IN);
1769  for (casadi_int i = 0; i < INTEGRATOR_NUM_IN; ++i) {
1770  casadi_int j = adjmap_out(i);
1771  // Split return by grid points and sensitivities
1772  casadi_int n_grid = grid_out(j) ? nt() : 1;
1773  std::vector<casadi_int> offset = {0};
1774  for (casadi_int k = 0; k < n_grid; ++k) {
1775  offset.push_back(offset.back() + numel_out(j) / n_grid);
1776  for (casadi_int d = 0; d < nadj; ++d) {
1777  offset.push_back(offset.back() + numel_in(i) / n_grid);
1778  }
1779  }
1780  std::vector<MX> integrator_out_split = vertsplit(vec(integrator_out[j]), offset);
1781  // Collect sensitivity blocks in the right order
1782  std::vector<MX> ret_out_split;
1783  ret_out_split.reserve(n_grid * nadj);
1784  for (casadi_int d = 0; d < nadj; ++d) {
1785  for (casadi_int k = 0; k < n_grid; ++k) {
1786  ret_out_split.push_back(reshape(integrator_out_split.at((nadj + 1) * k + d + 1),
1787  size1_in(i), size2_in(i) / n_grid));
1788  }
1789  }
1790  ret_out.push_back(horzcat(ret_out_split));
1791  }
1792 
1793  Dict options = opts;
1794  options["allow_duplicate_io_names"] = true;
1795 
1796  // Create derivative function and return
1797  return Function(name, ret_in, ret_out, inames, onames, options);
1798 }
static casadi_int adjmap_out(casadi_int i)
Which output is used to calculate a given input in adjoint sensitivity analysis.
Definition: integrator.cpp:336

References casadi::Integrator::adjmap_out(), casadi::Integrator::augmented_dae(), casadi::Integrator::augmented_options_, casadi::FunctionInternal::Function, casadi::Integrator::getDerivativeOptions(), casadi::Integrator::grid_in(), casadi::Integrator::grid_out(), casadi::integrator(), casadi::integrator_in(), casadi::INTEGRATOR_NUM_IN, casadi::INTEGRATOR_NUM_OUT, casadi::integrator_out(), casadi::Integrator::nadj_, casadi::ProtoFunction::name_, casadi::Integrator::ne_, casadi::Integrator::nrx_, casadi::Integrator::nt(), casadi::FunctionInternal::numel_in(), casadi::FunctionInternal::numel_out(), casadi::PluginInterface< Integrator >::plugin_name(), casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size2_in(), casadi::Function::size_in(), casadi::FunctionInternal::size_out(), casadi::FunctionInternal::sparsity_in(), casadi::FunctionInternal::sparsity_out(), casadi::str(), casadi::GenericMatrix< MX >::sym(), casadi::Integrator::t0_, casadi::Integrator::tout_, and casadi::ProtoFunction::verbose_.

◆ get_sparsity_in()

Sparsity casadi::Integrator::get_sparsity_in ( casadi_int  i)
overridevirtualinherited

◆ get_sparsity_out()

Sparsity casadi::Integrator::get_sparsity_out ( casadi_int  i)
overridevirtualinherited

◆ get_stats()

Dict casadi::SundialsInterface::get_stats ( void *  mem) const
overridevirtualinherited

Reimplemented from casadi::OracleFunction.

Definition at line 430 of file sundials_interface.cpp.

430  {
431  Dict stats = Integrator::get_stats(mem);
432  auto m = static_cast<SundialsMemory*>(mem);
433 
434  // Counters, forward problem
435  stats["nsteps"] = static_cast<casadi_int>(m->nsteps);
436  stats["nfevals"] = static_cast<casadi_int>(m->nfevals);
437  stats["nlinsetups"] = static_cast<casadi_int>(m->nlinsetups);
438  stats["netfails"] = static_cast<casadi_int>(m->netfails);
439  stats["qlast"] = m->qlast;
440  stats["qcur"] = m->qcur;
441  stats["hinused"] = m->hinused;
442  stats["hlast"] = m->hlast;
443  stats["hcur"] = m->hcur;
444  stats["tcur"] = m->tcur;
445  stats["nniters"] = static_cast<casadi_int>(m->nniters);
446  stats["nncfails"] = static_cast<casadi_int>(m->nncfails);
447 
448  // Counters, backward problem
449  stats["nstepsB"] = static_cast<casadi_int>(m->nstepsB);
450  stats["nfevalsB"] = static_cast<casadi_int>(m->nfevalsB);
451  stats["nlinsetupsB"] = static_cast<casadi_int>(m->nlinsetupsB);
452  stats["netfailsB"] = static_cast<casadi_int>(m->netfailsB);
453  stats["qlastB"] = m->qlastB;
454  stats["qcurB"] = m->qcurB;
455  stats["hinusedB"] = m->hinusedB;
456  stats["hlastB"] = m->hlastB;
457  stats["hcurB"] = m->hcurB;
458  stats["tcurB"] = m->tcurB;
459  stats["nnitersB"] = static_cast<casadi_int>(m->nnitersB);
460  stats["nncfailsB"] = static_cast<casadi_int>(m->nncfailsB);
461  return stats;
462 }
Dict get_stats(void *mem) const override
Get all statistics.

References casadi::OracleFunction::get_stats(), and casadi::SundialsMemory::qlast.

◆ get_x()

void casadi::Integrator::get_x ( IntegratorMemory m,
double *  x 
) const
inherited

Definition at line 2558 of file integrator.cpp.

2558  {
2559  casadi_copy(m->x, nx_, x);
2560 }

References casadi::casadi_copy(), casadi::Integrator::nx_, and casadi::IntegratorMemory::x.

Referenced by casadi::Integrator::eval().

◆ get_z()

void casadi::Integrator::get_z ( IntegratorMemory m,
double *  z 
) const
inherited

Definition at line 2562 of file integrator.cpp.

2562  {
2563  casadi_copy(m->z, nz_, z);
2564 }

References casadi::casadi_copy(), casadi::Integrator::nz_, and casadi::IntegratorMemory::z.

Referenced by casadi::Integrator::eval().

◆ getAdaptorSolverName()

virtual std::string casadi::FunctionInternal::getAdaptorSolverName ( ) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_k3

Definition at line 304 of file function_internal.hpp.

304 { return ""; }

◆ getCount()

Definition at line 60 of file generic_shared_internal.hpp.

205  {
206  return static_cast<const Internal*>(this)->count;
207  }

◆ getDerivativeOptions()

Dict casadi::Integrator::getDerivativeOptions ( bool  fwd) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1ma

Definition at line 1800 of file integrator.cpp.

1800  {
1801  // Copy all options
1802  return opts_;
1803 }
Dict opts_
Copy of the options.

References casadi::Integrator::opts_.

Referenced by casadi::Integrator::get_forward(), and casadi::Integrator::get_reverse().

◆ getPlugin()

PluginInterface< Integrator >::Plugin & casadi::PluginInterface< Integrator >::getPlugin ( const std::string &  pname)
staticinherited

Definition at line 102 of file plugin_interface.hpp.

295  {
296 
297 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
298  std::lock_guard<std::mutex> lock(Derived::mutex_solvers_);
299 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
300 
301  // Check if the solver has been loaded
302  auto it=Derived::solvers_.find(pname);
303 
304  // Load the solver if needed
305  if (it==Derived::solvers_.end()) {
306  load_plugin(pname, true, false);
307  it=Derived::solvers_.find(pname);
308  }
309  casadi_assert_dev(it!=Derived::solvers_.end());
310  return it->second;
311  }
static Plugin load_plugin(const std::string &pname, bool register_plugin=true, bool needs_lock=true)
Load a plugin dynamically.

◆ grid_in()

bool casadi::Integrator::grid_in ( casadi_int  i)
staticinherited

Definition at line 312 of file integrator.cpp.

312  {
313  switch (static_cast<IntegratorInput>(i)) {
314  case INTEGRATOR_U:
315  case INTEGRATOR_ADJ_XF:
316  case INTEGRATOR_ADJ_ZF:
317  case INTEGRATOR_ADJ_QF:
318  return true;
319  default: break;
320  }
321  return false;
322 }

References casadi::INTEGRATOR_ADJ_QF, casadi::INTEGRATOR_ADJ_XF, casadi::INTEGRATOR_ADJ_ZF, and casadi::INTEGRATOR_U.

Referenced by casadi::Integrator::get_forward(), and casadi::Integrator::get_reverse().

◆ grid_out()

bool casadi::Integrator::grid_out ( casadi_int  i)
staticinherited

Definition at line 324 of file integrator.cpp.

324  {
325  switch (static_cast<IntegratorOutput>(i)) {
326  case INTEGRATOR_XF:
327  case INTEGRATOR_ZF:
328  case INTEGRATOR_QF:
329  case INTEGRATOR_ADJ_U:
330  return true;
331  default: break;
332  }
333  return false;
334 }

References casadi::INTEGRATOR_ADJ_U, casadi::INTEGRATOR_QF, casadi::INTEGRATOR_XF, and casadi::INTEGRATOR_ZF.

Referenced by casadi::Integrator::get_forward(), and casadi::Integrator::get_reverse().

◆ has_codegen()

virtual bool casadi::FunctionInternal::has_codegen ( ) const
inlinevirtualinherited

◆ has_derivative()

bool casadi::FunctionInternal::has_derivative ( ) const
inherited

◆ has_eval_dm()

virtual bool casadi::FunctionInternal::has_eval_dm ( ) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ke

Reimplemented in casadi::CallbackInternal.

Definition at line 434 of file function_internal.hpp.

434 { return false;}

Referenced by casadi::FunctionInternal::eval().

◆ has_forward()

bool casadi::Integrator::has_forward ( casadi_int  nfwd) const
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1m7

Reimplemented from casadi::FunctionInternal.

Definition at line 317 of file integrator_impl.hpp.

317 { return true;}

◆ has_free()

virtual bool casadi::FunctionInternal::has_free ( ) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l8

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 753 of file function_internal.hpp.

753 { return false;}

Referenced by casadi::FunctionInternal::get_free().

◆ has_function()

bool casadi::OracleFunction::has_function ( const std::string &  fname) const
overridevirtualinherited

◆ has_jac_sparsity()

virtual bool casadi::FunctionInternal::has_jac_sparsity ( casadi_int  oind,
casadi_int  iind 
) const
inlinevirtualinherited

◆ has_jacobian()

virtual bool casadi::FunctionInternal::has_jacobian ( ) const
inlinevirtualinherited

◆ has_memory()

bool casadi::ProtoFunction::has_memory ( int  ind) const
inherited

Definition at line 3854 of file function_internal.cpp.

3854  {
3855  return ind<mem_.size();
3856  }

◆ has_option()

bool casadi::ProtoFunction::has_option ( const std::string &  option_name) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jj

Definition at line 1055 of file function_internal.cpp.

1055  {
1056  return get_options().find(option_name) != nullptr;
1057  }
const Options::Entry * find(const std::string &name) const
Definition: options.cpp:32

References casadi::Options::find(), and casadi::ProtoFunction::get_options().

◆ has_plugin()

bool casadi::PluginInterface< Integrator >::has_plugin ( const std::string &  pname,
bool  verbose = false 
)
staticinherited

Definition at line 76 of file plugin_interface.hpp.

134  {
135 
136 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
137  std::lock_guard<std::mutex> lock(Derived::mutex_solvers_);
138 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
139 
140  // Quick return if available
141  if (Derived::solvers_.find(pname) != Derived::solvers_.end()) {
142  return true;
143  }
144 
145  // Try loading the plugin
146  try {
147  (void)load_plugin(pname, false, false);
148  return true;
149  } catch (CasadiException& ex) {
150  if (verbose) {
151  casadi_warning(ex.what());
152  }
153  return false;
154  }
155  }
std::vector< casadi_int > find(const std::vector< T > &v)
find nonzeros

◆ has_reverse()

bool casadi::Integrator::has_reverse ( casadi_int  nadj) const
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1m8

Reimplemented from casadi::FunctionInternal.

Definition at line 328 of file integrator_impl.hpp.

328 { return ne_ == 0;}

◆ has_spfwd()

bool casadi::Integrator::has_spfwd ( ) const
inlineoverridevirtualinherited

Is the class able to propagate seeds through the algorithm?

Reimplemented from casadi::FunctionInternal.

Definition at line 305 of file integrator_impl.hpp.

305 { return true;}

◆ has_sprev()

bool casadi::Integrator::has_sprev ( ) const
inlineoverridevirtualinherited

Is the class able to propagate seeds through the algorithm?

Reimplemented from casadi::FunctionInternal.

Definition at line 306 of file integrator_impl.hpp.

306 { return true;}

◆ impulseB()

void casadi::CvodesInterface::impulseB ( IntegratorMemory mem,
const double *  adj_x,
const double *  adj_z,
const double *  adj_q 
) const
overridevirtual

Implements casadi::Integrator.

Definition at line 301 of file cvodes_interface.cpp.

302  {
303  auto m = to_mem(mem);
304 
305  // Call method in base class
306  SundialsInterface::impulseB(mem, adj_x, adj_z, adj_q);
307 
308  if (m->first_callB) {
309  // Create backward problem
310  THROWING(CVodeCreateB, m->mem, lmm_, iter_, &m->whichB);
311  THROWING(CVodeInitB, m->mem, m->whichB, rhsB, m->t, m->v_adj_xz);
312  THROWING(CVodeSStolerancesB, m->mem, m->whichB, reltol_, abstol_);
313  THROWING(CVodeSetUserDataB, m->mem, m->whichB, m);
314  if (newton_scheme_==SD_DIRECT) {
315  // Direct scheme
316  CVodeMem cv_mem = static_cast<CVodeMem>(m->mem);
317  CVadjMem ca_mem = cv_mem->cv_adj_mem;
318  CVodeBMem cvB_mem = ca_mem->cvB_mem;
319  cvB_mem->cv_lmem = m;
320  cvB_mem->cv_mem->cv_lmem = m;
321  cvB_mem->cv_mem->cv_lsetup = lsetupB;
322  cvB_mem->cv_mem->cv_lsolve = lsolveB;
323  cvB_mem->cv_mem->cv_setupNonNull = TRUE;
324  } else {
325  // Iterative scheme
326  casadi_int pretype = use_precon_ ? PREC_LEFT : PREC_NONE;
327  switch (newton_scheme_) {
328  case SD_DIRECT: casadi_assert_dev(0);
329  case SD_GMRES: THROWING(CVSpgmrB, m->mem, m->whichB, pretype, max_krylov_); break;
330  case SD_BCGSTAB: THROWING(CVSpbcgB, m->mem, m->whichB, pretype, max_krylov_); break;
331  case SD_TFQMR: THROWING(CVSptfqmrB, m->mem, m->whichB, pretype, max_krylov_); break;
332  }
333  THROWING(CVSpilsSetJacTimesVecFnB, m->mem, m->whichB, jtimesB);
334  if (use_precon_) THROWING(CVSpilsSetPreconditionerB, m->mem, m->whichB, psetupB, psolveB);
335  }
336 
337  // Quadratures for the backward problem
338  THROWING(CVodeQuadInitB, m->mem, m->whichB, rhsQB, m->v_adj_pu);
339  if (quad_err_con_) {
340  THROWING(CVodeSetQuadErrConB, m->mem, m->whichB, true);
341  THROWING(CVodeQuadSStolerancesB, m->mem, m->whichB, reltol_, abstol_);
342  }
343 
344  // Mark initialized
345  m->first_callB = false;
346  } else {
347  // Save solver stats offsets before reset
348  save_offsets(m);
349 
350  // Reinitialize solver
351  THROWING(CVodeReInitB, m->mem, m->whichB, m->t, m->v_adj_xz);
352  THROWING(CVodeQuadReInitB, m->mem, m->whichB, m->v_adj_pu);
353  }
354 }
static int lsolveB(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector x, N_Vector xdot)
static int rhsQB(double t, N_Vector x, N_Vector rx, N_Vector ruqdot, void *user_data)
static int psolveB(double t, N_Vector x, N_Vector xB, N_Vector xdotB, N_Vector rvecB, N_Vector zvecB, double gammaB, double deltaB, int lr, void *user_data, N_Vector tmpB)
static int lsetupB(CVodeMem cv_mem, int convfail, N_Vector x, N_Vector xdot, booleantype *jcurPtr, N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3)
static int rhsB(double t, N_Vector x, N_Vector xB, N_Vector xdotB, void *user_data)
static int psetupB(double t, N_Vector x, N_Vector xB, N_Vector xdotB, booleantype jokB, booleantype *jcurPtrB, double gammaB, void *user_data, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B)
static int jtimesB(N_Vector vB, N_Vector JvB, double t, N_Vector x, N_Vector xB, N_Vector xdotB, void *user_data, N_Vector tmpB)
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 save_offsets(SundialsMemory *m) const
Save stats offsets before reset.

References casadi::SundialsInterface::abstol_, casadi::SundialsInterface::impulseB(), iter_, jtimesB(), lmm_, lsetupB(), lsolveB(), casadi::SundialsInterface::max_krylov_, casadi::SundialsInterface::newton_scheme_, psetupB(), psolveB(), casadi::SundialsInterface::quad_err_con_, casadi::SundialsInterface::reltol_, rhsB(), rhsQB(), casadi::SundialsInterface::save_offsets(), casadi::SundialsInterface::SD_BCGSTAB, casadi::SundialsInterface::SD_DIRECT, casadi::SundialsInterface::SD_GMRES, casadi::SundialsInterface::SD_TFQMR, to_mem(), and casadi::SundialsInterface::use_precon_.

◆ incache()

bool casadi::FunctionInternal::incache ( const std::string &  fname,
Function f,
const std::string &  suffix = "" 
) const
inherited

◆ index_in()

casadi_int casadi::FunctionInternal::index_in ( const std::string &  name) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mu

Definition at line 1159 of file function_internal.hpp.

1159  {
1160  for (casadi_int i=0; i<name_in_.size(); ++i) {
1161  if (name_in_[i]==name) return i;
1162  }
1163  casadi_error("FunctionInternal::index_in: could not find entry \""
1164  + name + "\". Available names are: " + str(name_in_) + ".");
1165  return -1;
1166  }

References casadi::str().

Referenced by casadi::FunctionInternal::convert_arg().

◆ index_out()

casadi_int casadi::FunctionInternal::index_out ( const std::string &  name) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mv

Definition at line 1171 of file function_internal.hpp.

1171  {
1172  for (casadi_int i=0; i<name_out_.size(); ++i) {
1173  if (name_out_[i]==name) return i;
1174  }
1175  casadi_error("FunctionInternal::index_out: could not find entry \""
1176  + name + "\". Available names are: " + str(name_out_) + ".");
1177  return -1;
1178  }

References casadi::str().

Referenced by casadi::FunctionInternal::convert_res().

◆ info()

Dict casadi::FunctionInternal::info ( ) const
virtualinherited

◆ init()

void casadi::CvodesInterface::init ( const Dict opts)
overridevirtual

Reimplemented from casadi::Integrator.

Definition at line 79 of file cvodes_interface.cpp.

79  {
80  if (verbose_) casadi_message(name_ + "::init");
81 
82  // Initialize the base classes
84 
85  // Default options
86  std::string linear_multistep_method = "bdf";
87  std::string nonlinear_solver_iteration = "newton";
88  min_step_size_ = 0;
90 
91  // Read options
92  for (auto&& op : opts) {
93  if (op.first=="linear_multistep_method") {
94  linear_multistep_method = op.second.to_string();
95  } else if (op.first=="min_step_size") {
96  min_step_size_ = op.second;
97  } else if (op.first=="nonlinear_solver_iteration") {
98  nonlinear_solver_iteration = op.second.to_string();
99  } else if (op.first=="always_recalculate_jacobian") {
100  always_recalculate_jacobian_ = op.second;
101  }
102  }
103 
104  // Algebraic variables not supported
105  casadi_assert(nz_==0 && nrz_==0,
106  "CVODES does not support algebraic variables");
107 
108  if (linear_multistep_method=="adams") {
109  lmm_ = CV_ADAMS;
110  } else if (linear_multistep_method=="bdf") {
111  lmm_ = CV_BDF;
112  } else {
113  casadi_error("Unknown linear multistep method: " + linear_multistep_method);
114  }
115 
116  if (nonlinear_solver_iteration=="newton") {
117  iter_ = CV_NEWTON;
118  } else if (nonlinear_solver_iteration=="functional") {
119  iter_ = CV_FUNCTIONAL;
120  } else {
121  casadi_error("Unknown nonlinear solver iteration: " + nonlinear_solver_iteration);
122  }
123 
124  // Misc
125  alloc_w(nx_); // casadi_project
126  alloc_w(nrx_); // casadi_project
127 }
void init(const Dict &opts) override
Initialize.

References casadi::FunctionInternal::alloc_w(), always_recalculate_jacobian_, casadi::SundialsInterface::init(), iter_, lmm_, min_step_size_, casadi::ProtoFunction::name_, casadi::Integrator::nrx_, casadi::Integrator::nrz_, casadi::Integrator::nx_, casadi::Integrator::nz_, and casadi::ProtoFunction::verbose_.

◆ init_mem()

int casadi::CvodesInterface::init_mem ( void *  mem) const
overridevirtual

Reimplemented from casadi::Integrator.

Definition at line 129 of file cvodes_interface.cpp.

129  {
130  if (SundialsInterface::init_mem(mem)) return 1;
131  auto m = to_mem(mem);
132 
133  // Create CVodes memory block
134  m->mem = CVodeCreate(lmm_, iter_);
135  casadi_assert(m->mem!=nullptr, "CVodeCreate: Creation failed");
136 
137  // Set error handler function
138  THROWING(CVodeSetErrHandlerFn, m->mem, ehfun, m);
139 
140  // Set user data
141  THROWING(CVodeSetUserData, m->mem, m);
142 
143  // Initialize CVodes
144  double t0 = 0;
145  THROWING(CVodeInit, m->mem, rhsF, t0, m->v_xz);
146 
147  // Set tolerances
148  if (scale_abstol_) {
149  THROWING(CVodeSVtolerances, m->mem, reltol_, m->abstolv);
150  } else {
151  THROWING(CVodeSStolerances, m->mem, reltol_, abstol_);
152  }
153 
154  // Maximum number of steps
155  THROWING(CVodeSetMaxNumSteps, m->mem, max_num_steps_);
156 
157  // Initial step size
158  if (step0_!=0) THROWING(CVodeSetInitStep, m->mem, step0_);
159 
160  // Min step size
161  if (min_step_size_!=0) THROWING(CVodeSetMinStep, m->mem, min_step_size_);
162 
163  // Max step size
164  if (max_step_size_!=0) THROWING(CVodeSetMaxStep, m->mem, max_step_size_);
165 
166  // Maximum order of method
167  if (max_order_) THROWING(CVodeSetMaxOrd, m->mem, max_order_);
168 
169  // Coeff. in the nonlinear convergence test
170  if (nonlin_conv_coeff_!=0) THROWING(CVodeSetNonlinConvCoef, m->mem, nonlin_conv_coeff_);
171 
172  // attach a linear solver
173  if (newton_scheme_==SD_DIRECT) {
174  // Direct scheme
175  CVodeMem cv_mem = static_cast<CVodeMem>(m->mem);
176  cv_mem->cv_lmem = m;
177  cv_mem->cv_lsetup = lsetupF;
178  cv_mem->cv_lsolve = lsolveF;
179  cv_mem->cv_setupNonNull = TRUE;
180  } else {
181  // Iterative scheme
182  casadi_int pretype = use_precon_ ? PREC_LEFT : PREC_NONE;
183  switch (newton_scheme_) {
184  case SD_DIRECT: casadi_assert_dev(0);
185  case SD_GMRES: THROWING(CVSpgmr, m->mem, pretype, max_krylov_); break;
186  case SD_BCGSTAB: THROWING(CVSpbcg, m->mem, pretype, max_krylov_); break;
187  case SD_TFQMR: THROWING(CVSptfqmr, m->mem, pretype, max_krylov_); break;
188  }
189  THROWING(CVSpilsSetJacTimesVecFn, m->mem, jtimesF);
190  if (use_precon_) THROWING(CVSpilsSetPreconditioner, m->mem, psetupF, psolveF);
191  }
192 
193  // Quadrature equations
194  if (nq_>0) {
195  // Initialize quadratures in CVodes
196  THROWING(CVodeQuadInit, m->mem, rhsQF, m->v_q);
197 
198  // Should the quadrature errors be used for step size control?
199  if (quad_err_con_) {
200  THROWING(CVodeSetQuadErrCon, m->mem, true);
201 
202  // Quadrature error tolerances
203  // TODO(Joel): vector absolute tolerances
204  THROWING(CVodeQuadSStolerances, m->mem, reltol_, abstol_);
205  }
206  }
207 
208  // Initialize adjoint sensitivities
209  if (nrx_>0) {
210  casadi_int interpType = interp_ == SD_HERMITE ? CV_HERMITE : CV_POLYNOMIAL;
211  THROWING(CVodeAdjInit, m->mem, steps_per_checkpoint_, interpType);
212  }
213 
214  m->first_callB = true;
215  return 0;
216 }
static int rhsF(double t, N_Vector x, N_Vector xdot, void *user_data)
static int psetupF(double t, N_Vector x, N_Vector xdot, booleantype jok, booleantype *jcurPtr, double gamma, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
static int lsetupF(CVodeMem cv_mem, int convfail, N_Vector x, N_Vector xdot, booleantype *jcurPtr, N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3)
static int jtimesF(N_Vector v, N_Vector Jv, double t, N_Vector x, N_Vector xdot, void *user_data, N_Vector tmp)
static void ehfun(int error_code, const char *module, const char *function, char *msg, void *user_data)
static int psolveF(double t, N_Vector x, N_Vector xdot, N_Vector r, N_Vector z, double gamma, double delta, int lr, void *user_data, N_Vector tmp)
static int rhsQF(double t, N_Vector x, N_Vector qdot, void *user_data)
static int lsolveF(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector x, N_Vector xdot)
int init_mem(void *mem) const override
Initalize memory block.

References casadi::SundialsInterface::abstol_, ehfun(), casadi::SundialsInterface::init_mem(), casadi::SundialsInterface::interp_, iter_, jtimesF(), lmm_, lsetupF(), lsolveF(), casadi::SundialsInterface::max_krylov_, casadi::SundialsInterface::max_num_steps_, casadi::SundialsInterface::max_order_, casadi::SundialsInterface::max_step_size_, min_step_size_, casadi::SundialsInterface::newton_scheme_, casadi::SundialsInterface::nonlin_conv_coeff_, casadi::Integrator::nq_, casadi::Integrator::nrx_, psetupF(), psolveF(), casadi::SundialsInterface::quad_err_con_, casadi::SundialsInterface::reltol_, rhsF(), rhsQF(), casadi::SundialsInterface::scale_abstol_, casadi::SundialsInterface::SD_BCGSTAB, casadi::SundialsInterface::SD_DIRECT, casadi::SundialsInterface::SD_GMRES, casadi::SundialsInterface::SD_HERMITE, casadi::SundialsInterface::SD_TFQMR, casadi::SundialsInterface::step0_, casadi::SundialsInterface::steps_per_checkpoint_, to_mem(), and casadi::SundialsInterface::use_precon_.

◆ initSingleton()

void casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::initSingleton ( )
inlineprotectedinherited

Called in the constructor of singletons to avoid that the counter reaches zero

Definition at line 71 of file generic_shared_internal.hpp.

71  {
72  casadi_assert_dev(static_cast<Internal*>(this)->count==0);
73  static_cast<Internal*>(this)->count++;
74  }

◆ instantiate()

Integrator * casadi::PluginInterface< Integrator >::instantiate ( const std::string &  fname,
const std::string &  pname,
Problem  problem 
)
staticinherited

Definition at line 106 of file plugin_interface.hpp.

317  {
318 
319  // Assert the plugin exists (needed for adaptors)
320  if (!has_plugin(pname, true)) {
321  casadi_error("Plugin '" + pname + "' is not found.");
322  }
323  return getPlugin(pname).creator(fname, problem);
324  }
static bool has_plugin(const std::string &pname, bool verbose=false)
Check if a plugin is available or can be loaded.
static Plugin & getPlugin(const std::string &pname)
Load and get the creator function.

◆ instruction_constant()

double casadi::FunctionInternal::instruction_constant ( casadi_int  k) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ld

Reimplemented in casadi::SXFunction.

Definition at line 3591 of file function_internal.cpp.

3591  {
3592  casadi_error("'instruction_constant' not defined for " + class_name());
3593  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_id()

casadi_int casadi::FunctionInternal::instruction_id ( casadi_int  k) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lb

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3583 of file function_internal.cpp.

3583  {
3584  casadi_error("'instruction_id' not defined for " + class_name());
3585  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_input()

std::vector< casadi_int > casadi::FunctionInternal::instruction_input ( casadi_int  k) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lc

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3587 of file function_internal.cpp.

3587  {
3588  casadi_error("'instruction_input' not defined for " + class_name());
3589  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_MX()

MX casadi::FunctionInternal::instruction_MX ( casadi_int  k) const
virtualinherited

Reimplemented in casadi::MXFunction.

Definition at line 3599 of file function_internal.cpp.

3599  {
3600  casadi_error("'instruction_MX' not defined for " + class_name());
3601  }

References casadi::SharedObjectInternal::class_name().

◆ instruction_output()

std::vector< casadi_int > casadi::FunctionInternal::instruction_output ( casadi_int  k) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_le

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3595 of file function_internal.cpp.

3595  {
3596  casadi_error("'instruction_output' not defined for " + class_name());
3597  }

References casadi::SharedObjectInternal::class_name().

◆ instructions_sx()

SX casadi::FunctionInternal::instructions_sx ( ) const
virtualinherited

Reimplemented in casadi::SXFunction.

Definition at line 3603 of file function_internal.cpp.

3603  {
3604  casadi_error("'instructions_sx' not defined for " + class_name());
3605  }

References casadi::SharedObjectInternal::class_name().

◆ is_a()

bool casadi::FunctionInternal::is_a ( const std::string &  type,
bool  recursive 
) const
virtualinherited

◆ jac_is_symm()

bool casadi::FunctionInternal::jac_is_symm ( casadi_int  oind,
casadi_int  iind 
) const
virtualinherited

Definition at line 1915 of file function_internal.cpp.

1915  {
1916  // If derivative expression
1917  if (!derivative_of_.is_null()) {
1918  std::string n = derivative_of_.name();
1919  // Reverse move
1920  if (name_ == "adj1_" + n) {
1921  if (iind == oind) return true;
1922  }
1923  }
1924  // Not symmetric by default
1925  return false;
1926  }
bool is_null() const
Is a null pointer?

References casadi::FunctionInternal::derivative_of_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Function::name(), and casadi::ProtoFunction::name_.

◆ jac_sparsity()

Sparsity & casadi::FunctionInternal::jac_sparsity ( casadi_int  oind,
casadi_int  iind,
bool  compact,
bool  symmetric 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kz Get, if necessary generate, the sparsity of a Jacobian block

Definition at line 2003 of file function_internal.cpp.

2004  {
2005 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
2006  // Safe access to jac_sparsity_
2007  std::lock_guard<std::mutex> lock(jac_sparsity_mtx_);
2008 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
2009  // If first call, allocate cache
2010  for (bool c : {false, true}) {
2011  if (jac_sparsity_[c].empty()) jac_sparsity_[c].resize(n_in_ * n_out_);
2012  }
2013  // Flat index
2014  casadi_int ind = iind + oind * n_in_;
2015  // Reference to the block
2016  Sparsity& jsp = jac_sparsity_[compact].at(ind);
2017  // If null, generate
2018  if (jsp.is_null()) {
2019  // Use (non)-compact pattern, if given
2020  Sparsity& jsp_other = jac_sparsity_[!compact].at(ind);
2021  if (!jsp_other.is_null()) {
2022  jsp = compact ? to_compact(oind, iind, jsp_other) : from_compact(oind, iind, jsp_other);
2023  } else {
2024  // Generate pattern
2025  Sparsity sp;
2026  bool sp_is_compact;
2027  if (!is_diff_out_.at(oind) || !is_diff_in_.at(iind)) {
2028  // All-zero sparse
2029  sp = Sparsity(nnz_out(oind), nnz_in(iind));
2030  sp_is_compact = true;
2031  } else {
2032  // Use internal routine to determine sparsity
2033  if (has_spfwd() || has_sprev() || has_jac_sparsity(oind, iind)) {
2034  sp = get_jac_sparsity(oind, iind, symmetric);
2035  }
2036  // If null, dense
2037  if (sp.is_null()) sp = Sparsity::dense(nnz_out(oind), nnz_in(iind));
2038  // Is the return the compact pattern?
2039  sp_is_compact = sp.size1() == nnz_out(oind) && sp.size2() == nnz_in(iind);
2040  }
2041  // Save to cache and convert if needed
2042  if (sp_is_compact == compact) {
2043  jsp = sp;
2044  } else {
2045  jsp_other = sp;
2046  jsp = compact ? to_compact(oind, iind, sp) : from_compact(oind, iind, sp);
2047  }
2048  }
2049  }
2050 
2051  // Make sure the Jacobian is symmetric if requested, cf. #1522, #3074, #3134
2052  if (symmetric) {
2053  if (compact) {
2054  Sparsity sp = from_compact(oind, iind, jsp);
2055  if (!sp.is_symmetric()) {
2056  sp = sp * sp.T();
2057  jsp = to_compact(oind, iind, sp);
2058  }
2059  } else {
2060  if (!jsp.is_symmetric()) jsp = jsp * jsp.T();
2061  }
2062  }
2063 
2064  // Return a reference to the block
2065  return jsp;
2066  }
std::vector< Sparsity > jac_sparsity_[2]
Cache for sparsities of the Jacobian blocks.
Sparsity to_compact(casadi_int oind, casadi_int iind, const Sparsity &sp) const
Convert to compact Jacobian sparsity pattern.
virtual bool has_jac_sparsity(casadi_int oind, casadi_int iind) const
Get Jacobian sparsity.
Sparsity from_compact(casadi_int oind, casadi_int iind, const Sparsity &sp) const
Convert from compact Jacobian sparsity pattern.
virtual Sparsity get_jac_sparsity(casadi_int oind, casadi_int iind, bool symmetric) const
Get Jacobian sparsity.

References casadi::Sparsity::dense(), casadi::FunctionInternal::from_compact(), casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::has_jac_sparsity(), casadi::FunctionInternal::has_spfwd(), casadi::FunctionInternal::has_sprev(), casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::GenericShared< Shared, Internal >::is_null(), casadi::Sparsity::is_symmetric(), casadi::FunctionInternal::jac_sparsity_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::nnz_out(), casadi::Sparsity::size1(), casadi::Sparsity::size2(), casadi::Sparsity::T(), and casadi::FunctionInternal::to_compact().

Referenced by casadi::FunctionInternal::get_partition(), casadi::FunctionInternal::sp_forward_block(), and casadi::FunctionInternal::sp_reverse().

◆ jacobian()

Function casadi::FunctionInternal::jacobian ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ky

Definition at line 2403 of file function_internal.cpp.

2403  {
2404  // Used wrapped function if jacobian not available
2405  if (!has_jacobian()) {
2406  // Derivative information must be available
2407  casadi_assert(has_derivative(),
2408  "Derivatives cannot be calculated for " + name_);
2409  return wrap().jacobian();
2410  }
2411  // Retrieve/generate cached
2412  Function f;
2413  std::string fname = "jac_" + name_;
2414  if (!incache(fname, f)) {
2415  // Names of inputs
2416  std::vector<std::string> inames;
2417  for (casadi_int i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2418  for (casadi_int i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2419  // Names of outputs
2420  std::vector<std::string> onames;
2421  onames.reserve(n_in_ * n_out_);
2422  for (size_t oind = 0; oind < n_out_; ++oind) {
2423  for (size_t iind = 0; iind < n_in_; ++iind) {
2424  onames.push_back("jac_" + name_out_[oind] + "_" + name_in_[iind]);
2425  }
2426  }
2427  // Options
2429  opts["derivative_of"] = self();
2430  // Generate derivative function
2431  casadi_assert_dev(enable_jacobian_);
2432  f = get_jacobian(fname, inames, onames, opts);
2433  // Consistency checks
2434  casadi_assert(f.n_in() == inames.size(),
2435  "Mismatching input signature, expected " + str(inames));
2436  casadi_assert(f.n_out() == onames.size(),
2437  "Mismatching output signature, expected " + str(onames));
2438  // Save to cache
2439  tocache_if_missing(f);
2440  }
2441  return f;
2442  }
virtual bool has_jacobian() const
Return Jacobian of all input elements with respect to all output elements.
virtual Function get_jacobian(const std::string &name, const std::vector< std::string > &inames, const std::vector< std::string > &onames, const Dict &opts) const
Return Jacobian of all input elements with respect to all output elements.
Function jacobian() const
Calculate all Jacobian blocks.
Definition: function.cpp:1068

References casadi::combine(), casadi::FunctionInternal::der_options_, casadi::FunctionInternal::enable_jacobian_, casadi::FunctionInternal::get_jacobian(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::has_jacobian(), casadi::FunctionInternal::incache(), casadi::Function::jacobian(), casadi::FunctionInternal::jacobian_options_, casadi::Function::n_in(), casadi::FunctionInternal::n_in_, casadi::Function::n_out(), casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::str(), casadi::FunctionInternal::tocache_if_missing(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_reverse(), and casadi::Function::jacobian().

◆ jit_dependencies()

void casadi::OracleFunction::jit_dependencies ( const std::string &  fname)
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_k

Reimplemented from casadi::FunctionInternal.

Definition at line 438 of file oracle_function.cpp.

438  {
439  if (compiler_.is_null()) {
440  if (verbose_) casadi_message("compiling to "+ fname+"'.");
441  // JIT dependent functions
442  compiler_ = Importer(generate_dependencies(fname, Dict()),
444  }
445  // Replace the Oracle functions with generated functions
446  for (auto&& e : all_functions_) {
447  if (verbose_) casadi_message("loading '" + e.second.f.name() + "' from '" + fname + "'.");
448  if (e.second.jit) {
449  e.second.f_original = e.second.f;
450  e.second.f = external(e.second.f.name(), compiler_);
451  }
452  }
453 }
std::string generate_dependencies(const std::string &fname, const Dict &opts) const override
Export / Generate C code for the generated functions.
Function external(const std::string &name, const Importer &li, const Dict &opts)
Load a just-in-time compiled external function.
Definition: external.cpp:42

References casadi::OracleFunction::all_functions_, casadi::FunctionInternal::compiler_, casadi::FunctionInternal::compiler_plugin_, casadi::external(), casadi::OracleFunction::generate_dependencies(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jit_options_, and casadi::ProtoFunction::verbose_.

◆ join_results()

void casadi::OracleFunction::join_results ( OracleMemory m) const
inherited

Definition at line 168 of file oracle_function.cpp.

168  {
169  // Combine runtime statistics
170  // Note: probably not correct to simply add wall times
171  for (int i = 0; i < max_num_threads_; ++i) {
172  auto* ml = m->thread_local_mem[i];
173  for (auto&& s : ml->fstats) {
174  m->fstats.at(s.first).join(s.second);
175  }
176  }
177 }

References casadi::ProtoFunctionMemory::fstats, casadi::OracleFunction::max_num_threads_, and casadi::OracleMemory::thread_local_mem.

Referenced by casadi::Nlpsol::eval(), and casadi::Integrator::eval().

◆ jtimesB()

int casadi::CvodesInterface::jtimesB ( N_Vector  vB,
N_Vector  JvB,
double  t,
N_Vector  x,
N_Vector  xB,
N_Vector  xdotB,
void *  user_data,
N_Vector  tmpB 
)
staticprotected

Definition at line 477 of file cvodes_interface.cpp.

478  {
479  try {
480  auto m = to_mem(user_data);
481  auto& s = m->self;
482  // The function is linear so the Jacobian-times-vector function is the function itself
483  if (s.calc_daeB(m, t, NV_DATA_S(x), nullptr, NV_DATA_S(v), nullptr, nullptr,
484  NV_DATA_S(Jv), nullptr)) return 1;
485  return 0;
486  } catch(std::exception& e) { // non-recoverable error
487  uerr() << "jtimesB failed: " << e.what() << std::endl;
488  return -1;
489  }
490 }

References to_mem(), and casadi::uerr().

Referenced by impulseB().

◆ jtimesF()

int casadi::CvodesInterface::jtimesF ( N_Vector  v,
N_Vector  Jv,
double  t,
N_Vector  x,
N_Vector  xdot,
void *  user_data,
N_Vector  tmp 
)
staticprotected

Definition at line 463 of file cvodes_interface.cpp.

464  {
465  try {
466  auto m = to_mem(user_data);
467  auto& s = m->self;
468  if (s.calc_jtimesF(m, t, NV_DATA_S(x), nullptr, NV_DATA_S(v), nullptr,
469  NV_DATA_S(Jv), nullptr)) return 1;
470  return 0;
471  } catch(std::exception& e) { // non-recoverable error
472  uerr() << "jtimesF failed: " << e.what() << std::endl;
473  return -1;
474  }
475 }

References to_mem(), and casadi::uerr().

Referenced by init_mem().

◆ load_library()

handle_t casadi::PluginInterface< Integrator >::load_library ( const std::string &  libname,
std::string &  resultpath,
bool  global 
)
staticinherited

Definition at line 92 of file plugin_interface.hpp.

187  {
188 
189 #ifndef WITH_DL
190  casadi_error("WITH_DL option needed for dynamic loading");
191 #else // WITH_DL
192 
193  // Get the name of the shared library
194  std::string lib = std::string(CasadiMeta::shared_library_prefix()) + libname +
195  CasadiMeta::shared_library_suffix();
196 
197  // Build up search paths;
198  std::vector<std::string> search_paths = get_search_paths();
199  return open_shared_library(lib, search_paths, resultpath,
200  "PluginInterface::load_plugin", global);
201 
202 #endif // WITH_DL
203  }
std::vector< std::string > get_search_paths()
Definition: casadi_os.cpp:79

◆ load_plugin()

PluginInterface< Integrator >::Plugin casadi::PluginInterface< Integrator >::load_plugin ( const std::string &  pname,
bool  register_plugin = true,
bool  needs_lock = true 
)
staticinherited

Definition at line 88 of file plugin_interface.hpp.

208  {
209 
210 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
211  casadi::conditional_lock_guard<std::mutex> lock(Derived::mutex_solvers_, needs_lock);
212 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
213 
214  // Issue warning and quick return if already loaded
215  if (Derived::solvers_.find(pname) != Derived::solvers_.end()) {
216  casadi_warning("PluginInterface: Solver " + pname + " is already in use. Ignored.");
217  return Plugin();
218  }
219 
220  // Logger singletons are lazily instantiated on first uout()/uerr() calls
221  // This instantation may lead to a data race with potential instatiations in plugin
222  // To be safe, trigger instantatin before any plugin loading
223  uout();
224  uerr();
225 
226 #ifndef WITH_DL
227  casadi_error("WITH_DL option needed for dynamic loading");
228 #else // WITH_DL
229  // Retrieve the registration function
230  RegFcn reg;
231 
232  // Load the dll
233  std::string regName = "casadi_register_" + Derived::infix_ + "_" + pname;
234 
235  std::string searchpath;
236  handle_t handle = load_library("casadi_" + Derived::infix_ + "_" + pname, searchpath,
237  false);
238 
239 #ifdef _WIN32
240 
241 #if __GNUC__
242 #pragma GCC diagnostic push
243 #pragma GCC diagnostic ignored "-Wcast-function-type"
244 #endif
245  reg = reinterpret_cast<RegFcn>(GetProcAddress(handle, TEXT(regName.c_str())));
246 #if __GNUC__
247 #pragma GCC diagnostic pop
248 #endif
249 
250 #else // _WIN32
251  // Reset error
252  dlerror();
253 
254  // Load creator
255  reg = reinterpret_cast<RegFcn>(dlsym(handle, regName.c_str()));
256 #endif // _WIN32
257  casadi_assert(reg!=nullptr,
258  "PluginInterface::load_plugin: no \"" + regName + "\" found in " + searchpath + ".");
259 
260  // Create a temporary struct
261  Plugin plugin = pluginFromRegFcn(reg);
262  // Register the plugin
263  if (register_plugin) {
264  registerPlugin(plugin, false);
265  }
266 
267  return plugin;
268 
269 #endif // WITH_DL
270  }
static handle_t load_library(const std::string &libname, std::string &resultpath, bool global)
Load a library dynamically.
static Plugin pluginFromRegFcn(RegFcn regfcn)
Instantiate a Plugin struct from a factory function.
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
void * handle_t
Definition: casadi_os.hpp:109

◆ local_init_mem()

int casadi::OracleFunction::local_init_mem ( void *  mem) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_m

Definition at line 465 of file oracle_function.cpp.

465  {
466  if (ProtoFunction::init_mem(mem)) return 1;
467  if (!mem) return 1;
468  auto *m = static_cast<LocalOracleMemory*>(mem);
469 
470  // Create statistics
471  for (auto&& e : all_functions_) {
472  m->add_stat(e.first);
473  }
474 
475  return 0;
476 }

References casadi::ProtoFunctionMemory::add_stat(), casadi::OracleFunction::all_functions_, and casadi::ProtoFunction::init_mem().

Referenced by casadi::OracleFunction::init_mem().

◆ lsetupB()

int casadi::CvodesInterface::lsetupB ( CVodeMem  cv_mem,
int  convfail,
N_Vector  x,
N_Vector  xdot,
booleantype *  jcurPtr,
N_Vector  vtemp1,
N_Vector  vtemp2,
N_Vector  vtemp3 
)
staticprotected

Definition at line 655 of file cvodes_interface.cpp.

656  {
657  try {
658  auto m = to_mem(cv_mem->cv_lmem);
659  CVadjMem ca_mem;
660  //CVodeBMem cvB_mem;
661 
662  // Current time
663  double t = cv_mem->cv_tn; // TODO(Joel): is this correct?
664  double gamma = cv_mem->cv_gamma;
665 
666  cv_mem = static_cast<CVodeMem>(cv_mem->cv_user_data);
667  ca_mem = cv_mem->cv_adj_mem;
668  //cvB_mem = ca_mem->ca_bckpbCrt;
669 
670  // Get FORWARD solution from interpolation.
671  int flag = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, nullptr);
672  if (flag != CV_SUCCESS) casadi_error("Could not interpolate forward states");
673 
674  // Call the preconditioner setup function (which sets up the linear solver)
675  return psetupB(t, ca_mem->ca_ytmp, x, xdot, FALSE, jcurPtr,
676  gamma, static_cast<void*>(m), vtemp1, vtemp2, vtemp3);
677 
678  } catch(std::exception& e) { // non-recoverable error
679  uerr() << "lsetupB failed: " << e.what() << std::endl;
680  return -1;
681  }
682 }

References psetupB(), to_mem(), and casadi::uerr().

Referenced by impulseB().

◆ lsetupF()

int casadi::CvodesInterface::lsetupF ( CVodeMem  cv_mem,
int  convfail,
N_Vector  x,
N_Vector  xdot,
booleantype *  jcurPtr,
N_Vector  vtemp1,
N_Vector  vtemp2,
N_Vector  vtemp3 
)
staticprotected

Definition at line 640 of file cvodes_interface.cpp.

641  {
642  try {
643  auto m = to_mem(cv_mem->cv_lmem);
644 
645  // Call the preconditioner setup function (which sets up the linear solver)
646  return psetupF(cv_mem->cv_tn, x, xdot, FALSE, jcurPtr,
647  cv_mem->cv_gamma, static_cast<void*>(m), vtemp1, vtemp2, vtemp3);
648 
649  } catch(std::exception& e) { // non-recoverable error
650  uerr() << "lsetup failed: " << e.what() << std::endl;
651  return -1;
652  }
653 }

References psetupF(), to_mem(), and casadi::uerr().

Referenced by init_mem().

◆ lsolveB()

int casadi::CvodesInterface::lsolveB ( CVodeMem  cv_mem,
N_Vector  b,
N_Vector  weight,
N_Vector  x,
N_Vector  xdot 
)
staticprotected

Definition at line 711 of file cvodes_interface.cpp.

712  {
713  try {
714  auto m = to_mem(cv_mem->cv_lmem);
715  CVadjMem ca_mem;
716  //CVodeBMem cvB_mem;
717 
718  // Current time
719  double t = cv_mem->cv_tn; // TODO(Joel): is this correct?
720  double gamma = cv_mem->cv_gamma;
721 
722  cv_mem = static_cast<CVodeMem>(cv_mem->cv_user_data);
723 
724  ca_mem = cv_mem->cv_adj_mem;
725  //cvB_mem = ca_mem->ca_bckpbCrt;
726 
727  // Get FORWARD solution from interpolation.
728  int flag = ca_mem->ca_IMget(cv_mem, t, ca_mem->ca_ytmp, nullptr);
729  if (flag != CV_SUCCESS) casadi_error("Could not interpolate forward states");
730 
731  // Accuracy
732  double delta = 0.0;
733 
734  // Left/right preconditioner
735  int lr = 1;
736 
737  // Call the preconditioner solve function (which solves the linear system)
738  return psolveB(t, ca_mem->ca_ytmp, x, xdot, b, b, gamma, delta, lr,
739  static_cast<void*>(m), nullptr);
740 
741  } catch(std::exception& e) { // non-recoverable error
742  uerr() << "lsolveB failed: " << e.what() << std::endl;
743  return -1;
744  }
745 }

References psolveB(), to_mem(), and casadi::uerr().

Referenced by impulseB().

◆ lsolveF()

int casadi::CvodesInterface::lsolveF ( CVodeMem  cv_mem,
N_Vector  b,
N_Vector  weight,
N_Vector  x,
N_Vector  xdot 
)
staticprotected

Definition at line 684 of file cvodes_interface.cpp.

685  {
686  try {
687  auto m = to_mem(cv_mem->cv_lmem);
688  //auto& s = m->self;
689 
690  // Current time
691  double t = cv_mem->cv_tn;
692 
693  // Scaling factor before J
694  double gamma = cv_mem->cv_gamma;
695 
696  // Accuracy
697  double delta = 0.0;
698 
699  // Left/right preconditioner
700  casadi_int lr = 1;
701 
702  // Call the preconditioner solve function (which solves the linear system)
703  return psolveF(t, x, xdot, b, b, gamma, delta, lr, static_cast<void*>(m), nullptr);
704 
705  } catch(std::exception& e) { // non-recoverable error
706  uerr() << "lsolveF failed: " << e.what() << std::endl;
707  return -1;
708  }
709 }

References psolveF(), to_mem(), and casadi::uerr().

Referenced by init_mem().

◆ map()

Function casadi::FunctionInternal::map ( casadi_int  n,
const std::string &  parallelization 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nd

Definition at line 1142 of file function_internal.cpp.

1142  {
1143  Function f;
1144  if (parallelization=="serial") {
1145  // Serial maps are cached
1146  std::string fname = "map" + str(n) + "_" + name_;
1147  if (!incache(fname, f)) {
1148  // Create new serial map
1149  f = Map::create(parallelization, self(), n);
1150  casadi_assert_dev(f.name()==fname);
1151  // Save in cache
1152  tocache_if_missing(f);
1153  }
1154  } else {
1155  // Non-serial maps are not cached
1156  f = Map::create(parallelization, self(), n);
1157  }
1158  return f;
1159  }
static Function create(const std::string &parallelization, const Function &f, casadi_int n)
Definition: map.cpp:39

References casadi::Map::create(), casadi::FunctionInternal::incache(), casadi::Function::name(), casadi::ProtoFunction::name_, casadi::str(), and casadi::FunctionInternal::tocache_if_missing().

Referenced by casadi::Dple::get_forward(), casadi::Dple::get_reverse(), and casadi::FunctionInternal::mapsum_mx().

◆ map2oracle()

template<typename XType >
Function casadi::Integrator::map2oracle ( const std::string &  name,
const std::map< std::string, XType > &  d 
)
staticinherited

Definition at line 2330 of file integrator.cpp.

2331  {
2332  std::vector<XType> de_in(DYN_NUM_IN), de_out(DYN_NUM_OUT);
2333  for (auto&& i : d) {
2334  if (i.first=="t") {
2335  de_in[DYN_T]=i.second;
2336  } else if (i.first=="x") {
2337  de_in[DYN_X]=i.second;
2338  } else if (i.first=="z") {
2339  de_in[DYN_Z]=i.second;
2340  } else if (i.first=="p") {
2341  de_in[DYN_P]=i.second;
2342  } else if (i.first=="u") {
2343  de_in[DYN_U]=i.second;
2344  } else if (i.first=="ode") {
2345  de_out[DYN_ODE]=i.second;
2346  } else if (i.first=="alg") {
2347  de_out[DYN_ALG]=i.second;
2348  } else if (i.first=="quad") {
2349  de_out[DYN_QUAD]=i.second;
2350  } else if (i.first=="zero") {
2351  de_out[DYN_ZERO]=i.second;
2352  } else {
2353  casadi_error("No such field: " + i.first);
2354  }
2355  }
2356 
2357  // Consistency checks, input sparsities
2358  for (casadi_int i = 0; i < DYN_NUM_IN; ++i) {
2359  const Sparsity& sp = de_in[i].sparsity();
2360  if (i == DYN_T) {
2361  casadi_assert(sp.is_empty() || sp.is_scalar(), "DAE time variable must be empty or scalar. "
2362  "Got dimension " + str(sp.size()));
2363  } else {
2364  casadi_assert(sp.is_empty() || sp.is_vector(), "DAE inputs must be empty or vectors. "
2365  + dyn_in(i) + " has dimension " + str(sp.size()) + ".");
2366  }
2367  casadi_assert(sp.is_dense(), "DAE inputs must be dense . "
2368  + dyn_in(i) + " is sparse.");
2369  // Convert row vectors to column vectors
2370  de_in[i] = vec(de_in[i]);
2371  }
2372 
2373  // Consistency checks, output sparsities
2374  for (casadi_int i = 0; i < DYN_NUM_OUT; ++i) {
2375  const Sparsity& sp = de_out[i].sparsity();
2376  casadi_assert(sp.is_empty() || sp.is_vector(), "DAE outputs must be empty or vectors. "
2377  + dyn_out(i) + " has dimension " + str(sp.size()));
2378  // Make sure dense and vector
2379  de_out[i] = vec(densify(de_out[i]));
2380  }
2381 
2382  // Construct
2383  return Function(name, de_in, de_out, dyn_in(), dyn_out());
2384 }

References casadi::DYN_ALG, casadi::dyn_in(), casadi::DYN_NUM_IN, casadi::DYN_NUM_OUT, casadi::DYN_ODE, casadi::dyn_out(), casadi::DYN_P, casadi::DYN_QUAD, casadi::DYN_T, casadi::DYN_U, casadi::DYN_X, casadi::DYN_Z, casadi::DYN_ZERO, casadi::FunctionInternal::Function, casadi::Sparsity::is_dense(), casadi::Sparsity::is_empty(), casadi::Sparsity::is_scalar(), casadi::Sparsity::is_vector(), casadi::Sparsity::size(), and casadi::str().

Referenced by casadi::integrator().

◆ mapsum_mx()

std::vector< MX > casadi::FunctionInternal::mapsum_mx ( const std::vector< MX > &  arg,
const std::string &  parallelization 
)
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kw

Definition at line 3612 of file function_internal.cpp.

3613  {
3614  if (x.empty()) return x;
3615  // Check number of arguments
3616  casadi_assert(x.size()==n_in_, "mapsum_mx: Wrong number_i of arguments");
3617  // Number of parallel calls
3618  casadi_int npar = 1;
3619  // Check/replace arguments
3620  std::vector<MX> x_mod(x.size());
3621  for (casadi_int i=0; i<n_in_; ++i) {
3622  if (check_mat(x[i].sparsity(), sparsity_in_[i], npar)) {
3623  x_mod[i] = replace_mat(x[i], sparsity_in_[i], npar);
3624  } else {
3625  // Mismatching sparsity: The following will throw an error message
3626  npar = 0;
3627  check_arg(x, npar);
3628  }
3629  }
3630 
3631  casadi_int n = 1;
3632  for (casadi_int i=0; i<x_mod.size(); ++i) {
3633  n = std::max(x_mod[i].size2() / size2_in(i), n);
3634  }
3635 
3636  std::vector<casadi_int> reduce_in;
3637  for (casadi_int i=0; i<x_mod.size(); ++i) {
3638  if (x_mod[i].size2()/size2_in(i)!=n) {
3639  reduce_in.push_back(i);
3640  }
3641  }
3642 
3643  Function ms = self().map("mapsum", parallelization, n, reduce_in, range(n_out_));
3644 
3645  // Call the internal function
3646  return ms(x_mod);
3647  }
Function map(casadi_int n, const std::string &parallelization) const
Generate/retrieve cached serial map.
void check_arg(const std::vector< M > &arg, casadi_int &npar) const
Check if input arguments have correct length and dimensions.
M replace_mat(const M &arg, const Sparsity &inp, casadi_int npar)

References casadi::FunctionInternal::check_arg(), casadi::FunctionInternal::check_mat(), casadi::FunctionInternal::map(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::range(), casadi::replace_mat(), casadi::FunctionInternal::size2_in(), and casadi::FunctionInternal::sparsity_in_.

◆ matching_arg()

template<typename M >
bool casadi::FunctionInternal::matching_arg ( const std::vector< M > &  arg,
casadi_int &  npar 
) const
inherited

Raises errors

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

Extra doc: https://github.com/casadi/casadi/wiki/L_kk

Definition at line 1801 of file function_internal.hpp.

1801  {
1802  check_arg(arg, npar);
1803  for (casadi_int i=0; i<n_in_; ++i) {
1804  if (arg.at(i).size1()!=size1_in(i)) return false;
1805  if (arg.at(i).size2()!=size2_in(i) && arg.at(i).size2()!=npar*size2_in(i)) return false;
1806  }
1807  return true;
1808  }

References casadi::FunctionInternal::check_arg(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::size1_in(), and casadi::FunctionInternal::size2_in().

Referenced by casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::FunctionInternal::call(), casadi::FunctionInternal::call_forward(), and casadi::FunctionInternal::nz_in().

◆ matching_res()

template<typename M >
bool casadi::FunctionInternal::matching_res ( const std::vector< M > &  arg,
casadi_int &  npar 
) const
inherited

Raises errors

Parameters
npar[in]normal usage: 1, disallow pararallel calls: -1
[out]nparmax number of horizontal repetitions across all arguments (or -1)

Extra doc: https://github.com/casadi/casadi/wiki/L_kl

Definition at line 1811 of file function_internal.hpp.

1811  {
1812  check_res(res, npar);
1813  for (casadi_int i=0; i<n_out_; ++i) {
1814  if (res.at(i).size1()!=size1_out(i)) return false;
1815  if (res.at(i).size2()!=size2_out(i) && res.at(i).size2()!=npar*size2_out(i)) return false;
1816  }
1817  return true;
1818  }
void check_res(const std::vector< M > &res, casadi_int &npar) const
Check if output arguments have correct length and dimensions.

References casadi::FunctionInternal::check_res(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::size1_out(), and casadi::FunctionInternal::size2_out().

Referenced by casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::FunctionInternal::call_reverse(), and casadi::FunctionInternal::nz_out().

◆ memory()

void * casadi::ProtoFunction::memory ( int  ind) const
inherited

Definition at line 3847 of file function_internal.cpp.

3847  {
3848 #ifdef CASADI_WITH_THREAD
3849  std::lock_guard<std::mutex> lock(mtx_);
3850 #endif //CASADI_WITH_THREAD
3851  return mem_.at(ind);
3852  }

Referenced by casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::get_jac_sparsity_gen(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::Sqpmethod::solve_ela_QP(), and casadi::Sqpmethod::solve_QP().

◆ merge()

void casadi::FunctionInternal::merge ( const std::vector< MX > &  arg,
std::vector< MX > &  subs_from,
std::vector< MX > &  subs_to 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2b8

Reimplemented in casadi::BlazingSplineFunction.

Definition at line 3562 of file function_internal.cpp.

3563  {
3564  }

◆ monitored()

bool casadi::OracleFunction::monitored ( const std::string &  name) const
virtualinherited

Definition at line 557 of file oracle_function.cpp.

557  {
558  auto it = all_functions_.find(name);
559  casadi_assert(it!=all_functions_.end(),
560  "No function \"" + name + "\" in " + name_+ ". " +
561  "Available functions: " + join(get_function()) + ".");
562  return it->second.monitored;
563 }

References casadi::OracleFunction::all_functions_, casadi::OracleFunction::get_function(), casadi::join(), and casadi::ProtoFunction::name_.

Referenced by casadi::OracleFunction::calc_function().

◆ mx_in() [1/2]

const std::vector< MX > casadi::FunctionInternal::mx_in ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Reimplemented in casadi::MXFunction.

Definition at line 3542 of file function_internal.cpp.

3542  {
3543  std::vector<MX> ret(n_in_);
3544  for (casadi_int i=0; i<ret.size(); ++i) {
3545  ret[i] = mx_in(i);
3546  }
3547  return ret;
3548  }
virtual const std::vector< MX > mx_in() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_in_.

Referenced by casadi::Nlpsol::get_forward(), casadi::LinearInterpolantJac::get_jacobian(), casadi::Nlpsol::get_reverse(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ mx_in() [2/2]

const MX casadi::FunctionInternal::mx_in ( casadi_int  ind) const
virtualinherited

◆ mx_out() [1/2]

const std::vector< MX > casadi::FunctionInternal::mx_out ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Definition at line 3550 of file function_internal.cpp.

3550  {
3551  std::vector<MX> ret(n_out_);
3552  for (casadi_int i=0; i<ret.size(); ++i) {
3553  ret[i] = mx_out(i);
3554  }
3555  return ret;
3556  }
virtual const std::vector< MX > mx_out() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_out_.

Referenced by casadi::Nlpsol::get_forward(), and casadi::Nlpsol::get_reverse().

◆ mx_out() [2/2]

const MX casadi::FunctionInternal::mx_out ( casadi_int  ind) const
virtualinherited

◆ n_instructions()

casadi_int casadi::FunctionInternal::n_instructions ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_la

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3579 of file function_internal.cpp.

3579  {
3580  casadi_error("'n_instructions' not defined for " + class_name());
3581  }

References casadi::SharedObjectInternal::class_name().

◆ n_nodes()

casadi_int casadi::FunctionInternal::n_nodes ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lf

Reimplemented in casadi::SXFunction, and casadi::MXFunction.

Definition at line 3607 of file function_internal.cpp.

3607  {
3608  casadi_error("'n_nodes' not defined for " + class_name());
3609  }

References casadi::SharedObjectInternal::class_name().

◆ next_stop()

casadi_int casadi::Integrator::next_stop ( casadi_int  k,
const double *  u 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_25b

Definition at line 2566 of file integrator.cpp.

2566  {
2567  // Integrate till the end if no input signals
2568  if (nu_ == 0 || u == nullptr) return nt() - 1;
2569  // Find the next discontinuity, if any
2570  for (; k + 1 < nt(); ++k) {
2571  // Next control value
2572  const double *u_next = u + nu_;
2573  // Check if there is any change in input from k to k + 1
2574  for (casadi_int i = 0; i < nu_; ++i) {
2575  // Step change detected: stop integration at k
2576  if (u[i] != u_next[i]) return k;
2577  }
2578  // Shift u
2579  u = u_next;
2580  }
2581  // No step changes detected
2582  return k;
2583 }

References casadi::Integrator::nt(), and casadi::Integrator::nu_.

Referenced by casadi::Integrator::eval().

◆ next_stopB()

casadi_int casadi::Integrator::next_stopB ( casadi_int  k,
const double *  u 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_25e

Definition at line 2738 of file integrator.cpp.

2738  {
2739  // Integrate till the beginning if no input signals
2740  if (nu_ == 0 || u == nullptr) return -1;
2741  // Find the next discontinuity, if any
2742  for (; k-- > 0; ) {
2743  // Next control value
2744  const double *u_next = u - nu_;
2745  // Check if there is any change in input from k to k + 1
2746  for (casadi_int i = 0; i < nu_; ++i) {
2747  // Step change detected: stop integration at k
2748  if (u[i] != u_next[i]) return k;
2749  }
2750  // Shift u
2751  u = u_next;
2752  }
2753  // No step changes detected
2754  return k;
2755 }

References casadi::Integrator::nu_.

Referenced by casadi::Integrator::eval().

◆ nnz_in() [1/2]

casadi_int casadi::FunctionInternal::nnz_in ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_me

Definition at line 2362 of file function_internal.cpp.

2362  {
2363  casadi_int ret=0;
2364  for (casadi_int iind=0; iind<n_in_; ++iind) ret += nnz_in(iind);
2365  return ret;
2366  }

References casadi::FunctionInternal::n_in_.

Referenced by casadi::FunctionInternal::adjViaJac(), casadi::FunctionInternal::call_gen(), casadi::JitFunction::codegen_body(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::eval_gen(), casadi::CallbackInternal::finalize(), casadi::FunctionInternal::from_compact(), casadi::FunctionInternal::fwdViaJac(), casadi::FunctionInternal::generate_in(), casadi::FunctionInternal::get_jac_sparsity(), casadi::Expm::get_jac_sparsity(), casadi::FmuFunction::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_gen(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm(), casadi::JitFunction::init(), casadi::Nlpsol::init(), casadi::CbcInterface::init(), casadi::ClpInterface::init(), casadi::CplexInterface::init(), casadi::OoqpInterface::init(), casadi::ProxqpInterface::init(), casadi::QpoasesInterface::init(), casadi::ImplicitToNlp::init(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::nz_in(), casadi::ImplicitToNlp::set_work(), casadi::CbcInterface::solve(), casadi::ClpInterface::solve(), casadi::CplexInterface::solve(), casadi::OoqpInterface::solve(), casadi::PiqpInterface::solve(), casadi::ProxqpInterface::solve(), casadi::QpToNlp::solve(), casadi::KinsolInterface::solve(), casadi::FunctionInternal::sp_forward(), and casadi::FunctionInternal::sp_reverse().

◆ nnz_in() [2/2]

casadi_int casadi::FunctionInternal::nnz_in ( casadi_int  ind) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_me

Definition at line 1007 of file function_internal.hpp.

1007 { return sparsity_in(ind).nnz(); }
casadi_int nnz() const
Get the number of (structural) non-zeros.
Definition: sparsity.cpp:148

◆ nnz_out() [1/2]

casadi_int casadi::FunctionInternal::nnz_out ( ) const
inherited

◆ nnz_out() [2/2]

casadi_int casadi::FunctionInternal::nnz_out ( casadi_int  ind) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_me

Definition at line 1009 of file function_internal.hpp.

1009 { return sparsity_out(ind).nnz(); }

◆ nt()

casadi_int casadi::Integrator::nt ( ) const
inlineinherited

◆ numel_in() [1/2]

casadi_int casadi::FunctionInternal::numel_in ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mf

Definition at line 2374 of file function_internal.cpp.

2374  {
2375  casadi_int ret=0;
2376  for (casadi_int iind=0; iind<n_in_; ++iind) ret += numel_in(iind);
2377  return ret;
2378  }

References casadi::FunctionInternal::n_in_.

Referenced by casadi::FunctionInternal::from_compact(), and casadi::Integrator::get_reverse().

◆ numel_in() [2/2]

casadi_int casadi::FunctionInternal::numel_in ( casadi_int  ind) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mf

Definition at line 1017 of file function_internal.hpp.

1017 { return sparsity_in(ind).numel(); }
casadi_int numel() const
The total number of elements, including structural zeros, i.e. size2()*size1()
Definition: sparsity.cpp:132

◆ numel_out() [1/2]

casadi_int casadi::FunctionInternal::numel_out ( ) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mf

Definition at line 2380 of file function_internal.cpp.

2380  {
2381  casadi_int ret=0;
2382  for (casadi_int oind=0; oind<n_out_; ++oind) ret += numel_out(oind);
2383  return ret;
2384  }

References casadi::FunctionInternal::n_out_.

Referenced by casadi::FunctionInternal::from_compact(), and casadi::Integrator::get_reverse().

◆ numel_out() [2/2]

casadi_int casadi::FunctionInternal::numel_out ( casadi_int  ind) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mf

Definition at line 1018 of file function_internal.hpp.

1018 { return sparsity_out(ind).numel(); }

◆ nz_in() [1/2]

std::vector< double > casadi::FunctionInternal::nz_in ( const std::vector< DM > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kt

Definition at line 3702 of file function_internal.cpp.

3702  {
3703  // Disallow parallel inputs
3704  casadi_int npar = -1;
3705  if (!matching_arg(arg, npar)) {
3706  return nz_in(replace_arg(arg, npar));
3707  }
3708 
3709  std::vector<DM> arg2 = project_arg(arg, 1);
3710  std::vector<double> ret(nnz_in());
3711  casadi_int offset = 0;
3712  for (casadi_int i=0;i<n_in_;++i) {
3713  const double* e = arg2.at(i).ptr();
3714  std::copy(e, e+nnz_in(i), ret.begin()+offset);
3715  offset+= nnz_in(i);
3716  }
3717  return ret;
3718  }

References casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::project_arg(), and casadi::FunctionInternal::replace_arg().

Referenced by casadi::SXFunction::call_activity(), casadi::SXFunction::call_fwd(), casadi::SXFunction::call_rev(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_gen(), and casadi::FunctionInternal::get_jac_sparsity_hierarchical().

◆ nz_in() [2/2]

std::vector< DM > casadi::FunctionInternal::nz_in ( const std::vector< double > &  arg) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kt

Definition at line 3672 of file function_internal.cpp.

3672  {
3673  casadi_assert(nnz_in()==arg.size(),
3674  "Dimension mismatch. Expecting " + str(nnz_in()) +
3675  ", got " + str(arg.size()) + " instead.");
3676 
3677  std::vector<DM> ret = dm_in();
3678  casadi_int offset = 0;
3679  for (casadi_int i=0;i<n_in_;++i) {
3680  DM& r = ret.at(i);
3681  std::copy(arg.begin()+offset, arg.begin()+offset+nnz_in(i), r.ptr());
3682  offset+= nnz_in(i);
3683  }
3684  return ret;
3685  }
Matrix< double > DM
Definition: dm_fwd.hpp:33

References casadi::FunctionInternal::dm_in(), casadi::FunctionInternal::n_in_, casadi::FunctionInternal::nnz_in(), casadi::Matrix< Scalar >::ptr(), and casadi::str().

◆ nz_out() [1/2]

std::vector< double > casadi::FunctionInternal::nz_out ( const std::vector< DM > &  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kt

Definition at line 3720 of file function_internal.cpp.

3720  {
3721  // Disallow parallel inputs
3722  casadi_int npar = -1;
3723  if (!matching_res(res, npar)) {
3724  return nz_out(replace_res(res, npar));
3725  }
3726 
3727  std::vector<DM> res2 = project_res(res, 1);
3728  std::vector<double> ret(nnz_out());
3729  casadi_int offset = 0;
3730  for (casadi_int i=0;i<n_out_;++i) {
3731  const double* e = res2.at(i).ptr();
3732  std::copy(e, e+nnz_out(i), ret.begin()+offset);
3733  offset+= nnz_out(i);
3734  }
3735  return ret;
3736  }
std::vector< M > project_res(const std::vector< M > &arg, casadi_int npar) const
Project sparsities.
std::vector< M > replace_res(const std::vector< M > &res, casadi_int npar) const
Replace 0-by-0 outputs.

References casadi::FunctionInternal::matching_res(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::project_res(), and casadi::FunctionInternal::replace_res().

Referenced by casadi::SXFunction::call_activity(), casadi::SXFunction::call_fwd(), casadi::SXFunction::call_rev(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_gen(), and casadi::FunctionInternal::get_jac_sparsity_hierarchical().

◆ nz_out() [2/2]

std::vector< DM > casadi::FunctionInternal::nz_out ( const std::vector< double > &  res) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kt

Definition at line 3687 of file function_internal.cpp.

3687  {
3688  casadi_assert(nnz_out()==res.size(),
3689  "Dimension mismatch. Expecting " + str(nnz_out()) +
3690  ", got " + str(res.size()) + " instead.");
3691 
3692  std::vector<DM> ret = dm_out();
3693  casadi_int offset = 0;
3694  for (casadi_int i=0;i<n_out_;++i) {
3695  DM& r = ret.at(i);
3696  std::copy(res.begin()+offset, res.begin()+offset+nnz_out(i), r.ptr());
3697  offset+= nnz_out(i);
3698  }
3699  return ret;
3700  }

References casadi::FunctionInternal::dm_out(), casadi::FunctionInternal::n_out_, casadi::FunctionInternal::nnz_out(), casadi::Matrix< Scalar >::ptr(), and casadi::str().

◆ oracle()

const Function& casadi::OracleFunction::oracle ( ) const
inlineoverridevirtualinherited

◆ plugin_deserialize()

Deserialize casadi::PluginInterface< Integrator >::plugin_deserialize ( const std::string &  pname)
staticinherited

Definition at line 82 of file plugin_interface.hpp.

165  {
166  Deserialize m = getPlugin(pname).deserialize;
167  casadi_assert(m, "Plugin \"" + pname + "\" does not support deserialize");
168  return m;
169  }
ProtoFunction *(* Deserialize)(DeserializingStream &)

◆ plugin_name()

const char* casadi::CvodesInterface::plugin_name ( ) const
inlineoverridevirtual

Implements casadi::PluginInterface< Integrator >.

Definition at line 103 of file cvodes_interface.hpp.

103 { return "cvodes";}

◆ plugin_options()

const Options & casadi::PluginInterface< Integrator >::plugin_options ( const std::string &  pname)
staticinherited

Definition at line 79 of file plugin_interface.hpp.

158  {
159  const Options *op = getPlugin(pname).options;
160  casadi_assert(op!=nullptr, "Plugin \"" + pname + "\" does not support options");
161  return *op;
162  }

◆ pluginFromRegFcn()

PluginInterface< Integrator >::Plugin casadi::PluginInterface< Integrator >::pluginFromRegFcn ( RegFcn  regfcn)
staticinherited

Definition at line 85 of file plugin_interface.hpp.

173  {
174  // Create a temporary struct
175  Plugin plugin;
176 
177  // Set the fields
178  int flag = regfcn(&plugin);
179  casadi_assert(flag==0, "Registration of plugin failed.");
180 
181  return plugin;
182  }

◆ predict_events()

int casadi::Integrator::predict_events ( IntegratorMemory m) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29p

Definition at line 2618 of file integrator.cpp.

2618  {
2619  // Event time same as stopping time, by default
2620  double t_event = m->t_stop;
2621  casadi_int event_index = -1;
2622  // Calculate m->e and m->edot
2623  if (calc_edot(m)) return 1;
2624  // Save the values of the zero-crossing functions
2625  casadi_copy(m->e, ne_, m->old_e);
2626  // Find the next event, if any
2627  for (casadi_int i = 0; i < ne_; ++i) {
2628  if (!m->event_triggered[i]) {
2629  // Check if zero crossing function is positive and moving in the negative direction
2630  if (m->e[i] > 0 && m->edot[i] < 0) {
2631  // Projected zero-crossing time
2632  double t = m->t - m->e[i] / m->edot[i];
2633  // Save if earlier than current t_event
2634  if (t < t_event) {
2635  t_event = t;
2636  event_index = i;
2637  }
2638  }
2639  }
2640  }
2641  // Zero crossing projected
2642  if (event_index >= 0) {
2643  // Print progress
2644  if (verbose_) casadi_message("Projected zero crossing for index " + str(event_index)
2645  + " at t = " + str(t_event));
2646  // Update t_stop and t_next accordingly
2647  m->t_stop = t_event;
2648  m->t_next = std::min(m->t_next, t_event);
2649  }
2650  return 0;
2651 }

References casadi::Integrator::calc_edot(), casadi::casadi_copy(), casadi::IntegratorMemory::e, casadi::IntegratorMemory::edot, casadi::IntegratorMemory::event_triggered, casadi::Integrator::ne_, casadi::IntegratorMemory::old_e, casadi::str(), casadi::IntegratorMemory::t, casadi::IntegratorMemory::t_next, casadi::IntegratorMemory::t_stop, and casadi::ProtoFunction::verbose_.

Referenced by casadi::Integrator::advance().

◆ print()

void casadi::ProtoFunction::print ( const char *  fmt,
  ... 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jr

Definition at line 4100 of file function_internal.cpp.

4100  {
4101  // Variable number of arguments
4102  va_list args;
4103  va_start(args, fmt);
4104  // Static & dynamic buffers
4105  char buf[256];
4106  size_t buf_sz = sizeof(buf);
4107  char* buf_dyn = nullptr;
4108  // Try to print with a small buffer
4109  casadi_int n = vsnprintf(buf, buf_sz, fmt, args);
4110  // Need a larger buffer?
4111  if (n>static_cast<casadi_int>(buf_sz)) {
4112  buf_sz = static_cast<size_t>(n+1);
4113  buf_dyn = new char[buf_sz];
4114  n = vsnprintf(buf_dyn, buf_sz, fmt, args);
4115  }
4116  // Print buffer content
4117  if (n>=0) uout() << (buf_dyn ? buf_dyn : buf) << std::flush;
4118  // Cleanup
4119  delete[] buf_dyn;
4120  va_end(args);
4121  // Throw error if failure
4122  casadi_assert(n>=0, "Print failure while processing '" + std::string(fmt) + "'");
4123  }

References casadi::uout().

Referenced by casadi::Feasiblesqpmethod::anderson_acc_step_update(), casadi::Nlpsol::callback(), casadi::Blocksqp::convertHessian(), casadi::FmuFunction::eval_task(), casadi::Feasiblesqpmethod::feasibility_iterations(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::Blocksqp::fullstep(), casadi::Blocksqp::init(), casadi::Feasiblesqpmethod::init(), casadi::Ipqp::init(), casadi::Qrqp::init(), casadi::Qrsqp::init(), casadi::Sqpmethod::init(), casadi::LinsolQr::nfact(), casadi::Feasiblesqpmethod::print_iteration(), casadi::Qrsqp::print_iteration(), casadi::Sqpmethod::print_iteration(), casadi::SundialsInterface::print_stats(), casadi::ProtoFunction::print_time(), casadi::Blocksqp::printInfo(), casadi::Blocksqp::printProgress(), casadi::Blocksqp::run(), casadi::Blocksqp::solve(), casadi::Feasiblesqpmethod::solve(), casadi::Qrsqp::solve(), casadi::Sqpmethod::solve(), casadi::Sqpmethod::solve_ela_QP(), casadi::Feasiblesqpmethod::solve_LP(), casadi::Feasiblesqpmethod::solve_QP(), casadi::Qrsqp::solve_QP(), casadi::Sqpmethod::solve_QP(), and casadi::Blocksqp::solveQP().

◆ print_canonical() [1/3]

void casadi::FunctionInternal::print_canonical ( std::ostream &  stream,
casadi_int  sz,
const double *  nz 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2di

Definition at line 909 of file function_internal.cpp.

909  {
910  StreamStateGuard backup(stream);
911  normalized_setup(stream);
912  if (nz) {
913  stream << "[";
914  for (casadi_int i=0; i<sz; ++i) {
915  if (i>0) stream << ", ";
916  normalized_out(stream, nz[i]);
917  }
918  stream << "]";
919  } else {
920  stream << "NULL";
921  }
922  }

References casadi::normalized_out(), and casadi::normalized_setup().

◆ print_canonical() [2/3]

void casadi::FunctionInternal::print_canonical ( std::ostream &  stream,
const Sparsity sp,
const double *  nz 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2dh

Definition at line 924 of file function_internal.cpp.

925  {
926  StreamStateGuard backup(stream);
927  normalized_setup(stream);
928  if (nz) {
929  if (!sp.is_scalar(true)) {
930  stream << sp.dim(false) << ": ";
931  stream << "[";
932  }
933  for (casadi_int i=0; i<sp.nnz(); ++i) {
934  if (i>0) stream << ", ";
935  normalized_out(stream, nz[i]);
936  }
937  if (!sp.is_scalar(true)) {
938  stream << "]";
939  if (!sp.is_dense()) {
940  stream << ", colind: [";
941  for (casadi_int i=0; i<sp.size2()+1; ++i) {
942  if (i>0) stream << ", ";
943  stream << sp.colind()[i];
944  }
945  stream << "]";
946  stream << ", row: [";
947  for (casadi_int i=0; i<sp.nnz(); ++i) {
948  if (i>0) stream << ", ";
949  stream << sp.row()[i];
950  }
951  stream << "]";
952  }
953  }
954  } else {
955  stream << "NULL";
956  }
957  }

References casadi::Sparsity::colind(), casadi::Sparsity::dim(), casadi::Sparsity::is_dense(), casadi::Sparsity::is_scalar(), casadi::Sparsity::nnz(), casadi::normalized_out(), casadi::normalized_setup(), casadi::Sparsity::row(), and casadi::Sparsity::size2().

Referenced by casadi::Monitor::eval(), casadi::MXFunction::print_arg(), casadi::SXFunction::print_arg(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::print_out(), casadi::MXFunction::print_res(), and casadi::SXFunction::print_res().

◆ print_canonical() [3/3]

void casadi::FunctionInternal::print_canonical ( std::ostream &  stream,
double  a 
)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2dj

Definition at line 959 of file function_internal.cpp.

959  {
960  StreamStateGuard backup(stream);
961  normalized_setup(stream);
962  normalized_out(stream, a);
963  }

References casadi::normalized_out(), and casadi::normalized_setup().

◆ print_dimensions()

void casadi::FunctionInternal::print_dimensions ( std::ostream &  stream) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mb

Definition at line 1034 of file function_internal.cpp.

1034  {
1035  stream << " Number of inputs: " << n_in_ << std::endl;
1036  for (casadi_int i=0; i<n_in_; ++i) {
1037  stream << " Input " << i << " (\"" << name_in_[i] << "\"): "
1038  << sparsity_in_[i].dim() << std::endl;
1039  }
1040  stream << " Number of outputs: " << n_out_ << std::endl;
1041  for (casadi_int i=0; i<n_out_; ++i) {
1042  stream << " Output " << i << " (\"" << name_out_[i] << "\"): "
1043  << sparsity_out_[i].dim() << std::endl;
1044  }
1045  }

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::sparsity_in_, and casadi::FunctionInternal::sparsity_out_.

◆ print_in()

void casadi::FunctionInternal::print_in ( std::ostream &  stream,
const double **  arg,
bool  truncate 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nv

Definition at line 875 of file function_internal.cpp.

875  {
876  stream << "Function " << name_ << " (" << this << ")" << std::endl;
877  for (casadi_int i=0; i<n_in_; ++i) {
878  stream << "Input " << i << " (" << name_in_[i] << "): ";
879  if (arg[i]) {
880  if (print_canonical_) {
881  print_canonical(stream, sparsity_in_[i], arg[i]);
882  } else {
883  DM::print_default(stream, sparsity_in_[i], arg[i], truncate);
884  }
885  stream << std::endl;
886  } else {
887  stream << "NULL" << std::endl;
888  }
889  }
890  }
static void print_canonical(std::ostream &stream, const Sparsity &sp, const double *nz)
Print canonical representation of a numeric matrix.
static void print_default(std::ostream &stream, const Sparsity &sp, const double *nonzeros, bool truncate=true)
Print default style.

References casadi::FunctionInternal::n_in_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::print_canonical(), casadi::FunctionInternal::print_canonical_, casadi::Matrix< double >::print_default(), and casadi::FunctionInternal::sparsity_in_.

Referenced by casadi::FunctionInternal::eval_gen().

◆ print_option()

void casadi::ProtoFunction::print_option ( const std::string &  name,
std::ostream &  stream 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ji

Definition at line 1051 of file function_internal.cpp.

1051  {
1052  get_options().print_one(name, stream);
1053  }
void print_one(const std::string &name, std::ostream &stream) const
Print all information there is to know about a certain option.
Definition: options.cpp:274

References casadi::ProtoFunction::get_options(), and casadi::Options::print_one().

◆ print_options()

void casadi::ProtoFunction::print_options ( std::ostream &  stream) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jh

Definition at line 1047 of file function_internal.cpp.

1047  {
1048  get_options().print_all(stream);
1049  }
void print_all(std::ostream &stream) const
Print list of options.
Definition: options.cpp:268

References casadi::ProtoFunction::get_options(), and casadi::Options::print_all().

◆ print_out()

void casadi::FunctionInternal::print_out ( std::ostream &  stream,
double **  res,
bool  truncate 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nw

Definition at line 892 of file function_internal.cpp.

892  {
893  stream << "Function " << name_ << " (" << this << ")" << std::endl;
894  for (casadi_int i=0; i<n_out_; ++i) {
895  stream << "Output " << i << " (" << name_out_[i] << "): ";
896  if (res[i]) {
897  if (print_canonical_) {
898  print_canonical(stream, sparsity_out_[i], res[i]);
899  } else {
900  DM::print_default(stream, sparsity_out_[i], res[i], truncate);
901  }
902  stream << std::endl;
903  } else {
904  stream << "NULL" << std::endl;
905  }
906  }
907  }

References casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::print_canonical(), casadi::FunctionInternal::print_canonical_, casadi::Matrix< double >::print_default(), and casadi::FunctionInternal::sparsity_out_.

Referenced by casadi::FunctionInternal::eval_gen().

◆ print_stats()

void casadi::SundialsInterface::print_stats ( IntegratorMemory mem) const
overridevirtualinherited

Reimplemented from casadi::Integrator.

Definition at line 464 of file sundials_interface.cpp.

464  {
465  auto m = to_mem(mem);
466  print("FORWARD INTEGRATION:\n");
467  print("Number of steps taken by SUNDIALS: %ld\n", m->nsteps);
468  print("Number of calls to the user's f function: %ld\n", m->nfevals);
469  print("Number of calls made to the linear solver setup function: %ld\n", m->nlinsetups);
470  print("Number of error test failures: %ld\n", m->netfails);
471  print("Method order used on the last internal step: %d\n", m->qlast);
472  print("Method order to be used on the next internal step: %d\n", m->qcur);
473  print("Actual value of initial step size: %g\n", m->hinused);
474  print("Step size taken on the last internal step: %g\n", m->hlast);
475  print("Step size to be attempted on the next internal step: %g\n", m->hcur);
476  print("Current internal time reached: %g\n", m->tcur);
477  print("Number of nonlinear iterations performed: %ld\n", m->nniters);
478  print("Number of nonlinear convergence failures: %ld\n", m->nncfails);
479  if (nrx_>0) {
480  print("BACKWARD INTEGRATION:\n");
481  print("Number of steps taken by SUNDIALS: %ld\n", m->nstepsB);
482  print("Number of calls to the user's f function: %ld\n", m->nfevalsB);
483  print("Number of calls made to the linear solver setup function: %ld\n", m->nlinsetupsB);
484  print("Number of error test failures: %ld\n", m->netfailsB);
485  print("Method order used on the last internal step: %d\n" , m->qlastB);
486  print("Method order to be used on the next internal step: %d\n", m->qcurB);
487  print("Actual value of initial step size: %g\n", m->hinusedB);
488  print("Step size taken on the last internal step: %g\n", m->hlastB);
489  print("Step size to be attempted on the next internal step: %g\n", m->hcurB);
490  print("Current internal time reached: %g\n", m->tcurB);
491  print("Number of nonlinear iterations performed: %ld\n", m->nnitersB);
492  print("Number of nonlinear convergence failures: %ld\n", m->nncfailsB);
493  }
494  print("\n");
495 }
void print(const char *fmt,...) const
C-style formatted printing during evaluation.
static SundialsMemory * to_mem(void *mem)
Cast to memory object.

References casadi::Integrator::nrx_, casadi::ProtoFunction::print(), and casadi::SundialsInterface::to_mem().

◆ print_time()

void casadi::ProtoFunction::print_time ( const std::map< std::string, FStats > &  fstats) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ju

Definition at line 4020 of file function_internal.cpp.

4020  {
4021  if (!print_time_) return;
4022  // Length of the name being printed
4023  size_t name_len=0;
4024  for (auto &&s : fstats) {
4025  name_len = std::max(s.first.size(), name_len);
4026  }
4027  name_len = std::max(name_.size(), name_len);
4028 
4029  // Print name with a given length. Format: "%NNs "
4030  char namefmt[10];
4031  sprint(namefmt, sizeof(namefmt), "%%%ds ", static_cast<casadi_int>(name_len));
4032 
4033  // Print header
4034  print(namefmt, name_.c_str());
4035 
4036  print(" : %8s %10s %8s %10s %9s\n", "t_proc", "(avg)", "t_wall", "(avg)", "n_eval");
4037 
4038 
4039  char buffer_proc[10];
4040  char buffer_wall[10];
4041  char buffer_proc_avg[10];
4042  char buffer_wall_avg[10];
4043 
4044  // Print keys
4045  for (const auto &s : fstats) {
4046  if (s.second.n_call!=0) {
4047  print(namefmt, s.first.c_str());
4048  format_time(buffer_proc, s.second.t_proc);
4049  format_time(buffer_wall, s.second.t_wall);
4050  format_time(buffer_proc_avg, s.second.t_proc/s.second.n_call);
4051  format_time(buffer_wall_avg, s.second.t_wall/s.second.n_call);
4052  print(" | %s (%s) %s (%s) %9d\n",
4053  buffer_proc, buffer_proc_avg,
4054  buffer_wall, buffer_wall_avg, s.second.n_call);
4055  }
4056  }
4057  }
void format_time(char *buffer, double time) const
Format time in a fixed width 8 format.

References casadi::ProtoFunction::format_time(), casadi::ProtoFunction::name_, casadi::ProtoFunction::print(), casadi::ProtoFunction::print_time_, and casadi::ProtoFunction::sprint().

Referenced by casadi::FunctionInternal::eval_gen().

◆ printvar() [1/2]

static void casadi::SundialsInterface::printvar ( const std::string &  id,
double  v 
)
inlinestaticinherited

Definition at line 221 of file sundials_interface.hpp.

221  {
222  uout() << id << " = " << v << std::endl;
223  }

References casadi::uout().

◆ printvar() [2/2]

static void casadi::SundialsInterface::printvar ( const std::string &  id,
N_Vector  v 
)
inlinestaticinherited

Definition at line 225 of file sundials_interface.hpp.

225  {
226  std::vector<double> tmp(NV_DATA_S(v), NV_DATA_S(v)+NV_LENGTH_S(v));
227  uout() << id << " = " << tmp << std::endl;
228  }

References casadi::uout().

◆ project_arg()

template<typename M >
std::vector< M > casadi::FunctionInternal::project_arg ( const std::vector< M > &  arg,
casadi_int  npar 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kn

Definition at line 1673 of file function_internal.hpp.

1674  {
1675  casadi_assert_dev(arg.size()==n_in_);
1676 
1677  // Which arguments require mapped evaluation
1678  std::vector<bool> mapped(n_in_);
1679  for (casadi_int i=0; i<n_in_; ++i) {
1680  mapped[i] = arg[i].size2()!=size2_in(i);
1681  }
1682 
1683  // Check if matching input sparsity
1684  std::vector<bool> matching(n_in_);
1685  bool any_mismatch = false;
1686  for (casadi_int i=0; i<n_in_; ++i) {
1687  if (mapped[i]) {
1688  matching[i] = arg[i].sparsity().is_stacked(sparsity_in(i), npar);
1689  } else {
1690  matching[i] = arg[i].sparsity()==sparsity_in(i);
1691  }
1692  any_mismatch = any_mismatch || !matching[i];
1693  }
1694 
1695  // Correct input sparsity
1696  if (any_mismatch) {
1697  std::vector<M> arg2(arg);
1698  for (casadi_int i=0; i<n_in_; ++i) {
1699  if (!matching[i]) {
1700  if (mapped[i]) {
1701  arg2[i] = project(arg2[i], repmat(sparsity_in(i), 1, npar));
1702  } else {
1703  arg2[i] = project(arg2[i], sparsity_in(i));
1704  }
1705  }
1706  }
1707  return arg2;
1708  }
1709  return arg;
1710  }

References casadi::FunctionInternal::n_in_, casadi::FunctionInternal::size2_in(), and casadi::FunctionInternal::sparsity_in().

Referenced by casadi::FunctionInternal::call_gen(), and casadi::FunctionInternal::nz_in().

◆ project_res()

template<typename M >
std::vector< M > casadi::FunctionInternal::project_res ( const std::vector< M > &  arg,
casadi_int  npar 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ko

Definition at line 1713 of file function_internal.hpp.

1714  {
1715  return arg;
1716  }

Referenced by casadi::FunctionInternal::nz_out().

◆ psetupB()

int casadi::CvodesInterface::psetupB ( double  t,
N_Vector  x,
N_Vector  xB,
N_Vector  xdotB,
booleantype  jokB,
booleantype *  jcurPtrB,
double  gammaB,
void *  user_data,
N_Vector  tmp1B,
N_Vector  tmp2B,
N_Vector  tmp3B 
)
staticprotected

Definition at line 624 of file cvodes_interface.cpp.

626  {
627  try {
628  auto m = to_mem(user_data);
629  // Store gamma for later
630  m->gammaB = gammaB;
631  // We use the same linear solver for the forward problem as for the backward problem
632  return psetupF(t, x, nullptr, jokB, jcurPtrB, -gammaB, user_data, tmp1B, tmp2B, tmp3B);
633 
634  } catch(std::exception& e) { // non-recoverable error
635  uerr() << "psetupB failed: " << e.what() << std::endl;
636  return -1;
637  }
638 }

References psetupF(), to_mem(), and casadi::uerr().

Referenced by impulseB(), and lsetupB().

◆ psetupF()

int casadi::CvodesInterface::psetupF ( double  t,
N_Vector  x,
N_Vector  xdot,
booleantype  jok,
booleantype *  jcurPtr,
double  gamma,
void *  user_data,
N_Vector  tmp1,
N_Vector  tmp2,
N_Vector  tmp3 
)
staticprotected

Definition at line 576 of file cvodes_interface.cpp.

578  {
579  try {
580  auto m = to_mem(user_data);
581  auto& s = m->self;
582  // Store gamma for later
583  m->gamma = gamma;
584 
585  // Sparsity patterns
586  const Sparsity& sp_jac_ode_x = s.get_function("jacF").sparsity_out(0);
587  const Sparsity& sp_jacF = s.linsolF_.sparsity();
588 
589  // Calculate Jacobian, if necessary
590  if (s.always_recalculate_jacobian_ || !jcurPtr || *jcurPtr == 0) {
591  // Re(calculate) Jacobian
592  if (s.calc_jacF(m, t, NV_DATA_S(x), nullptr,
593  m->jac_ode_x, nullptr, nullptr, nullptr)) return 1;
594 
595  // Jacobian is now current
596  if (jcurPtr) *jcurPtr = 1;
597  }
598 
599  // Project to expected sparsity pattern (with diagonal)
600  casadi_project(m->jac_ode_x, sp_jac_ode_x, m->jacF, sp_jacF, m->w);
601 
602  // Scale and shift diagonal
603  const casadi_int *colind = sp_jacF.colind(), *row = sp_jacF.row();
604  for (casadi_int c = 0; c < sp_jacF.size2(); ++c) {
605  for (casadi_int k = colind[c]; k < colind[c + 1]; ++k) {
606  casadi_int r = row[k];
607  // Scale Jacobian
608  m->jacF[k] *= -gamma;
609  // Add contribution to diagonal
610  if (r == c) m->jacF[k] += 1;
611  }
612  }
613 
614  // Prepare the solution of the linear system (e.g. factorize)
615  if (s.linsolF_.nfact(m->jacF, m->mem_linsolF)) return 1;
616 
617  return 0;
618  } catch(std::exception& e) { // non-recoverable error
619  uerr() << "psetup failed: " << e.what() << std::endl;
620  return -1;
621  }
622 }
void casadi_project(const T1 *x, const casadi_int *sp_x, T1 *y, const casadi_int *sp_y, T1 *w)
Sparse copy: y <- x, w work vector (length >= number of rows)

References casadi::casadi_project(), casadi::Sparsity::colind(), casadi::Sparsity::row(), casadi::Sparsity::size2(), to_mem(), and casadi::uerr().

Referenced by init_mem(), lsetupF(), and psetupB().

◆ psolveB()

int casadi::CvodesInterface::psolveB ( double  t,
N_Vector  x,
N_Vector  xB,
N_Vector  xdotB,
N_Vector  rvecB,
N_Vector  zvecB,
double  gammaB,
double  deltaB,
int  lr,
void *  user_data,
N_Vector  tmpB 
)
staticprotected

Definition at line 533 of file cvodes_interface.cpp.

534  {
535  try {
536  auto m = to_mem(user_data);
537  auto& s = m->self;
538 
539  // Get right-hand sides in m->tmp1
540  double* v = NV_DATA_S(rvecB);
541  casadi_copy(v, s.nrx_, m->tmp1);
542 
543  // Solve for undifferentiated right-hand-side, save to output
544  if (s.linsolF_.solve(m->jacF, m->tmp1, s.nadj_, true, m->mem_linsolF)) return 1;
545  v = NV_DATA_S(zvecB); // possibly different from rvecB
546  casadi_copy(m->tmp1, s.nrx1_ * s.nadj_, v);
547 
548  // Sensitivity equations
549  if (s.nfwd_ > 0) {
550  // Second order correction
551  if (s.second_order_correction_) {
552  // The outputs will double as seeds for calc_daeB
553  casadi_clear(v + s.nrx1_ * s.nadj_, s.nrx_ - s.nrx1_ * s.nadj_);
554  if (s.calc_daeB(m, t, NV_DATA_S(x), nullptr, v, nullptr, nullptr, m->tmp2, nullptr))
555  return 1;
556  // Subtract m->tmp2 from m->tmp1, scaled with gammaB
557  casadi_axpy(s.nrx_ - s.nrx1_ * s.nadj_, -m->gammaB, m->tmp2 + s.nrx1_ * s.nadj_,
558  m->tmp1 + s.nrx1_ * s.nadj_);
559  }
560 
561  // Solve for sensitivity right-hand-sides
562  if (s.linsolF_.solve(m->jacF, m->tmp1 + s.nx1_, s.nadj_ * s.nfwd_,
563  true, m->mem_linsolF)) return 1;
564 
565  // Save to output, reordered
566  casadi_copy(m->tmp1 + s.nx1_, s.nx_ - s.nx1_, v + s.nx1_);
567  }
568 
569  return 0;
570  } catch(std::exception& e) { // non-recoverable error
571  uerr() << "psolveB failed: " << e.what() << std::endl;
572  return -1;
573  }
574 }

References casadi::casadi_axpy(), casadi::casadi_clear(), casadi::casadi_copy(), to_mem(), and casadi::uerr().

Referenced by impulseB(), and lsolveB().

◆ psolveF()

int casadi::CvodesInterface::psolveF ( double  t,
N_Vector  x,
N_Vector  xdot,
N_Vector  r,
N_Vector  z,
double  gamma,
double  delta,
int  lr,
void *  user_data,
N_Vector  tmp 
)
staticprotected

Definition at line 492 of file cvodes_interface.cpp.

493  {
494  try {
495  auto m = to_mem(user_data);
496  auto& s = m->self;
497 
498  // Get right-hand sides in m->tmp1
499  double* v = NV_DATA_S(r);
500  casadi_copy(v, s.nx_, m->tmp1);
501 
502  // Solve for undifferentiated right-hand-side, save to output
503  if (s.linsolF_.solve(m->jacF, m->tmp1, 1, false, m->mem_linsolF)) return 1;
504  v = NV_DATA_S(z); // possibly different from r
505  casadi_copy(m->tmp1, s.nx1_, v);
506 
507  // Sensitivity equations
508  if (s.nfwd_ > 0) {
509  // Second order correction
510  if (s.second_order_correction_) {
511  // The outputs will double as seeds for jtimesF
512  casadi_clear(v + s.nx1_, s.nx_ - s.nx1_);
513  if (s.calc_jtimesF(m, t, NV_DATA_S(x), nullptr, v, nullptr, m->tmp2, nullptr)) return 1;
514 
515  // Subtract m->tmp2 from m->tmp1, scaled with -gamma
516  casadi_axpy(s.nx_ - s.nx1_, m->gamma, m->tmp2 + s.nx1_, m->tmp1 + s.nx1_);
517  }
518 
519  // Solve for sensitivity right-hand-sides
520  if (s.linsolF_.solve(m->jacF, m->tmp1 + s.nx1_, s.nfwd_, false, m->mem_linsolF)) return 1;
521 
522  // Save to output, reordered
523  casadi_copy(m->tmp1 + s.nx1_, s.nx_ - s.nx1_, v + s.nx1_);
524  }
525 
526  return 0;
527  } catch(std::exception& e) { // non-recoverable error
528  uerr() << "psolve failed: " << e.what() << std::endl;
529  return -1;
530  }
531 }

References casadi::casadi_axpy(), casadi::casadi_clear(), casadi::casadi_copy(), to_mem(), and casadi::uerr().

Referenced by init_mem(), and lsolveF().

◆ purgable()

template<typename MatType >
bool casadi::FunctionInternal::purgable ( const std::vector< MatType > &  seed)
staticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nq

Definition at line 1566 of file function_internal.hpp.

1566  {
1567  for (auto i=v.begin(); i!=v.end(); ++i) {
1568  if (!i->is_zero()) return false;
1569  }
1570  return true;
1571  }

Referenced by casadi::MXFunction::ad_forward(), and casadi::MXFunction::ad_reverse().

◆ quad_out()

static std::vector<std::string> casadi::Integrator::quad_out ( )
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_260

Definition at line 369 of file integrator_impl.hpp.

369 { return {"quad"}; }

Referenced by casadi::Integrator::init().

◆ registerPlugin() [1/2]

void casadi::PluginInterface< Integrator >::registerPlugin ( const Plugin &  plugin,
bool  needs_lock = true 
)
staticinherited

Definition at line 96 of file plugin_interface.hpp.

278  {
279 
280 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
281  casadi::conditional_lock_guard<std::mutex> lock(Derived::mutex_solvers_, needs_lock);
282 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
283 
284  // Check if the solver name is in use
285  typename std::map<std::string, Plugin>::iterator it=Derived::solvers_.find(plugin.name);
286  casadi_assert(it==Derived::solvers_.end(),
287  "Solver " + str(plugin.name) + " is already in use");
288 
289  // Add to list of solvers
290  Derived::solvers_[plugin.name] = plugin;
291  }

◆ registerPlugin() [2/2]

void casadi::PluginInterface< Integrator >::registerPlugin ( RegFcn  regfcn,
bool  needs_lock = true 
)
staticinherited

Definition at line 99 of file plugin_interface.hpp.

273  {
274  registerPlugin(pluginFromRegFcn(regfcn), needs_lock);
275  }

◆ release()

void casadi::ProtoFunction::release ( int  mem) const
inherited

Definition at line 3879 of file function_internal.cpp.

3879  {
3880 #ifdef CASADI_WITH_THREAD
3881  std::lock_guard<std::mutex> lock(mtx_);
3882 #endif //CASADI_WITH_THREAD
3883  unused_.push(mem);
3884  }

Referenced by casadi::FunctionInternal::codegen_meta().

◆ replace_arg()

template<typename M >
std::vector< M > casadi::FunctionInternal::replace_arg ( const std::vector< M > &  arg,
casadi_int  npar 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_km

Definition at line 1848 of file function_internal.hpp.

1849  {
1850  std::vector<M> r(arg.size());
1851  for (casadi_int i=0; i<r.size(); ++i) r[i] = replace_mat(arg[i], sparsity_in(i), npar);
1852  return r;
1853  }

References casadi::replace_mat(), and casadi::FunctionInternal::sparsity_in().

Referenced by casadi::FunctionInternal::call(), casadi::FunctionInternal::nz_in(), and casadi::FunctionInternal::replace_fseed().

◆ replace_aseed() [1/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_aseed ( const std::vector< std::vector< M > > &  aseed,
casadi_int  npar 
) const
inherited

Definition at line 1872 of file function_internal.hpp.

1873  {
1874  std::vector<std::vector<M> > r(aseed.size());
1875  for (casadi_int d=0; d<r.size(); ++d) r[d] = replace_res(aseed[d], npar);
1876  return r;
1877  }

References casadi::FunctionInternal::replace_res().

◆ replace_aseed() [2/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_aseed ( const std::vector< std::vector< M >> &  aseed,
casadi_int  npar 
) const
inherited

◆ replace_fseed() [1/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_fseed ( const std::vector< std::vector< M > > &  fseed,
casadi_int  npar 
) const
inherited

Definition at line 1864 of file function_internal.hpp.

1865  {
1866  std::vector<std::vector<M> > r(fseed.size());
1867  for (casadi_int d=0; d<r.size(); ++d) r[d] = replace_arg(fseed[d], npar);
1868  return r;
1869  }

References casadi::FunctionInternal::replace_arg().

◆ replace_fseed() [2/2]

template<typename M >
std::vector<std::vector<M> > casadi::FunctionInternal::replace_fseed ( const std::vector< std::vector< M >> &  fseed,
casadi_int  npar 
) const
inherited

◆ replace_res()

template<typename M >
std::vector< M > casadi::FunctionInternal::replace_res ( const std::vector< M > &  res,
casadi_int  npar 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_kp

Definition at line 1856 of file function_internal.hpp.

1857  {
1858  std::vector<M> r(res.size());
1859  for (casadi_int i=0; i<r.size(); ++i) r[i] = replace_mat(res[i], sparsity_out(i), npar);
1860  return r;
1861  }

References casadi::replace_mat(), and casadi::FunctionInternal::sparsity_out().

Referenced by casadi::FunctionInternal::nz_out(), and casadi::FunctionInternal::replace_aseed().

◆ reset()

void casadi::CvodesInterface::reset ( IntegratorMemory mem,
bool  first_call 
) const
overridevirtual

Reimplemented from casadi::Integrator.

Definition at line 231 of file cvodes_interface.cpp.

231  {
232  if (verbose_) casadi_message(name_ + "::reset");
233  auto m = to_mem(mem);
234 
235  // Reset the base classes
236  SundialsInterface::reset(mem, first_call);
237 
238  // Only reinitialize solver at first call or if event handling is required
239  // May want to always enable this after more testing
240  if (first_call || ne_ > 0) {
241  // Re-initialize forward integration
242  THROWING(CVodeReInit, m->mem, m->t, m->v_xz);
243 
244  // Re-initialize quadratures
245  if (nq_ > 0) {
246  THROWING(CVodeQuadReInit, m->mem, m->v_q);
247  }
248  }
249 
250  // How is this impacted by CVodeReInit?
251  if (first_call) {
252  // Re-initialize backward integration
253  if (nrx_ > 0) {
254  THROWING(CVodeAdjReInit, m->mem);
255  }
256  }
257 }
void reset(IntegratorMemory *mem, bool first_call) const override
Reset the forward solver at the start or after an event.

References casadi::ProtoFunction::name_, casadi::Integrator::ne_, casadi::Integrator::nq_, casadi::Integrator::nrx_, casadi::SundialsInterface::reset(), to_mem(), and casadi::ProtoFunction::verbose_.

◆ reset_dump_count()

void casadi::FunctionInternal::reset_dump_count ( )
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_2dx

Definition at line 471 of file function_internal.cpp.

471  {
472  dump_count_ = 0;
473  }

References casadi::FunctionInternal::dump_count_.

◆ reset_stats()

void casadi::SundialsInterface::reset_stats ( SundialsMemory m) const
inherited

Definition at line 346 of file sundials_interface.cpp.

346  {
347  // Reset stats, forward problem
348  m->nsteps = m->nfevals = m->nlinsetups = m->netfails = 0;
349  m->qlast = m->qcur = -1;
350  m->tcur = t0_;
351  m->hinused = m->hlast = m->hcur = casadi::nan;
352  m->nniters = m->nncfails = 0;
353 
354  // Reset stats, backward problem
355  m->nstepsB = m->nfevalsB = m->nlinsetupsB = m->netfailsB = 0;
356  m->qlastB = m->qcurB = -1;
357  m->hinusedB = m->hlastB = m->hcurB = m->tcurB = casadi::nan;
358  m->nnitersB = m->nncfailsB = 0;
359 
360  // Set offsets to zero
361  save_offsets(m);
362 }
const double nan
Not a number.
Definition: calculus.hpp:53

References casadi::SundialsMemory::hcur, casadi::SundialsMemory::hcurB, casadi::SundialsMemory::hinused, casadi::SundialsMemory::hinusedB, casadi::SundialsMemory::hlast, casadi::SundialsMemory::hlastB, casadi::nan, casadi::SundialsMemory::netfails, casadi::SundialsMemory::netfailsB, casadi::SundialsMemory::nfevals, casadi::SundialsMemory::nfevalsB, casadi::SundialsMemory::nlinsetups, casadi::SundialsMemory::nlinsetupsB, casadi::SundialsMemory::nncfails, casadi::SundialsMemory::nncfailsB, casadi::SundialsMemory::nniters, casadi::SundialsMemory::nnitersB, casadi::SundialsMemory::nsteps, casadi::SundialsMemory::nstepsB, casadi::SundialsMemory::qcur, casadi::SundialsMemory::qcurB, casadi::SundialsMemory::qlast, casadi::SundialsMemory::qlastB, casadi::SundialsInterface::save_offsets(), casadi::Integrator::t0_, casadi::SundialsMemory::tcur, and casadi::SundialsMemory::tcurB.

Referenced by casadi::SundialsInterface::init_mem(), and casadi::SundialsInterface::reset().

◆ resetB()

void casadi::SundialsInterface::resetB ( IntegratorMemory mem) const
overridevirtualinherited

Implements casadi::Integrator.

Definition at line 385 of file sundials_interface.cpp.

385  {
386  auto m = static_cast<SundialsMemory*>(mem);
387 
388  // Clear seeds
389  casadi_clear(m->adj_q, nrp_);
390  casadi_clear(NV_DATA_S(m->v_adj_xz), nrx_ + nrz_);
391 
392  // Reset summation states
393  N_VConst(0., m->v_adj_pu);
394 }

References casadi::casadi_clear(), casadi::Integrator::nrp_, casadi::Integrator::nrx_, and casadi::Integrator::nrz_.

Referenced by casadi::IdasInterface::resetB().

◆ retreat()

void casadi::CvodesInterface::retreat ( IntegratorMemory mem,
const double *  u,
double *  adj_x,
double *  adj_p,
double *  adj_u 
) const
overridevirtual

Implements casadi::Integrator.

Definition at line 356 of file cvodes_interface.cpp.

357  {
358  auto m = to_mem(mem);
359 
360  // Set controls
361  casadi_copy(u, nu_, m->u);
362 
363  // Integrate, unless already at desired time
364  if (m->t_next < m->t) {
365  THROWING(CVodeB, m->mem, m->t_next, CV_NORMAL);
366  double tret;
367  THROWING(CVodeGetB, m->mem, m->whichB, &tret, m->v_adj_xz);
368  if (nrq_ > 0 || nuq_ > 0) {
369  THROWING(CVodeGetQuadB, m->mem, m->whichB, &tret, m->v_adj_pu);
370  }
371  }
372 
373  // Save outputs
374  casadi_copy(NV_DATA_S(m->v_adj_xz), nrx_, adj_x);
375  casadi_copy(NV_DATA_S(m->v_adj_pu), nrq_, adj_p);
376  casadi_copy(NV_DATA_S(m->v_adj_pu) + nrq_, nuq_, adj_u);
377 
378  // Get stats
379  CVodeMem cv_mem = static_cast<CVodeMem>(m->mem);
380  CVadjMem ca_mem = cv_mem->cv_adj_mem;
381  CVodeBMem cvB_mem = ca_mem->cvB_mem;
382  THROWING(CVodeGetIntegratorStats, cvB_mem->cv_mem, &m->nstepsB,
383  &m->nfevalsB, &m->nlinsetupsB, &m->netfailsB, &m->qlastB,
384  &m->qcurB, &m->hinusedB, &m->hlastB, &m->hcurB, &m->tcurB);
385  THROWING(CVodeGetNonlinSolvStats, cvB_mem->cv_mem, &m->nnitersB, &m->nncfailsB);
386 
387  // Add offset corresponding to counters that were set to zero at reinitializations
388  add_offsets(m);
389 }
void add_offsets(SundialsMemory *m) const
Add stats offsets to stats.

References casadi::SundialsInterface::add_offsets(), casadi::casadi_copy(), casadi::Integrator::nrq_, casadi::Integrator::nrx_, casadi::Integrator::nu_, casadi::Integrator::nuq_, and to_mem().

◆ reverse()

Function casadi::FunctionInternal::reverse ( casadi_int  nadj) const
inherited

reverse(nadj) returns a cached instance if available, and calls Function get_reverse(casadi_int nadj) if no cached version is available.

Extra doc: https://github.com/casadi/casadi/wiki/L_l1

Definition at line 2285 of file function_internal.cpp.

2285  {
2286  casadi_assert_dev(nadj>=0);
2287  // Used wrapped function if reverse not available
2288  if (!enable_reverse_) {
2289  // Derivative information must be available
2290  casadi_assert(has_derivative(), "Derivatives cannot be calculated for " + name_);
2291  return wrap().reverse(nadj);
2292  }
2293  // Retrieve/generate cached
2294  Function f;
2295  std::string fname = reverse_name(name_, nadj);
2296  if (!incache(fname, f)) {
2297  casadi_int i;
2298  // Prefix to be used for adjoint seeds, sensitivities
2299  std::string pref = diff_prefix("adj");
2300  // Names of inputs
2301  std::vector<std::string> inames;
2302  for (i=0; i<n_in_; ++i) inames.push_back(name_in_[i]);
2303  for (i=0; i<n_out_; ++i) inames.push_back("out_" + name_out_[i]);
2304  for (i=0; i<n_out_; ++i) inames.push_back(pref + name_out_[i]);
2305  // Names of outputs
2306  std::vector<std::string> onames;
2307  for (casadi_int i=0; i<n_in_; ++i) onames.push_back(pref + name_in_[i]);
2308  // Options
2310  opts = combine(opts, generate_options("reverse"));
2311  opts["derivative_of"] = self();
2312  // Generate derivative function
2313  casadi_assert_dev(enable_reverse_);
2314  f = get_reverse(nadj, fname, inames, onames, opts);
2315  // Consistency check for inputs
2316  casadi_assert_dev(f.n_in()==n_in_ + n_out_ + n_out_);
2317  casadi_int ind=0;
2318  for (i=0; i<n_in_; ++i) f.assert_size_in(ind++, size1_in(i), size2_in(i));
2319  for (i=0; i<n_out_; ++i) f.assert_size_in(ind++, size1_out(i), size2_out(i));
2320  for (i=0; i<n_out_; ++i) f.assert_size_in(ind++, size1_out(i), nadj*size2_out(i));
2321  // Consistency check for outputs
2322  casadi_assert_dev(f.n_out()==n_in_);
2323  for (i=0; i<n_in_; ++i) f.assert_sparsity_out(i, sparsity_in(i), nadj);
2324  // Save to cache
2325  tocache_if_missing(f);
2326  }
2327  return f;
2328  }
virtual 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
Return function that calculates adjoint derivatives.
static std::string reverse_name(const std::string &fcn, casadi_int nadj)
Helper function: Get name of adjoint derivative function.
Function reverse(casadi_int nadj) const
Get a function that calculates nadj adjoint derivatives.
Definition: function.cpp:1332

References casadi::Function::assert_size_in(), casadi::Function::assert_sparsity_out(), casadi::combine(), casadi::FunctionInternal::der_options_, casadi::FunctionInternal::diff_prefix(), casadi::FunctionInternal::enable_reverse_, casadi::FunctionInternal::generate_options(), casadi::FunctionInternal::get_reverse(), casadi::FunctionInternal::has_derivative(), casadi::FunctionInternal::incache(), casadi::Function::n_in(), casadi::FunctionInternal::n_in_, casadi::Function::n_out(), casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::Function::reverse(), casadi::FunctionInternal::reverse_name(), casadi::FunctionInternal::reverse_options_, casadi::FunctionInternal::size1_in(), casadi::FunctionInternal::size1_out(), casadi::FunctionInternal::size2_in(), casadi::FunctionInternal::size2_out(), casadi::FunctionInternal::sparsity_in(), casadi::FunctionInternal::tocache_if_missing(), and casadi::FunctionInternal::wrap().

Referenced by casadi::FunctionInternal::call_reverse(), and casadi::Function::reverse().

◆ reverse_name()

static std::string casadi::FunctionInternal::reverse_name ( const std::string &  fcn,
casadi_int  nadj 
)
inlinestaticinherited

Definition at line 672 of file function_internal.hpp.

672  {
673  return "adj" + str(nadj) + "_" + fcn;
674  }

References casadi::str().

Referenced by casadi::FunctionInternal::reverse(), and casadi::FixedStepIntegrator::stepB().

◆ rhsB()

int casadi::CvodesInterface::rhsB ( double  t,
N_Vector  x,
N_Vector  xB,
N_Vector  xdotB,
void *  user_data 
)
staticprotected

Definition at line 429 of file cvodes_interface.cpp.

429  {
430  try {
431  casadi_assert_dev(user_data);
432  auto m = to_mem(user_data);
433  auto& s = m->self;
434  if (s.calc_daeB(m, t, NV_DATA_S(x), nullptr, NV_DATA_S(rx), nullptr, m->adj_q,
435  NV_DATA_S(rxdot), nullptr)) return 1;
436  // Negate (note definition of g)
437  casadi_scal(s.nrx_, -1., NV_DATA_S(rxdot));
438  return 0;
439  } catch(std::exception& e) { // non-recoverable error
440  uerr() << "rhsB failed: " << e.what() << std::endl;
441  return -1;
442  }
443 }
void casadi_scal(casadi_int n, T1 alpha, T1 *x)
SCAL: x <- alpha*x.

References casadi::casadi_scal(), to_mem(), and casadi::uerr().

Referenced by impulseB().

◆ rhsF()

int casadi::CvodesInterface::rhsF ( double  t,
N_Vector  x,
N_Vector  xdot,
void *  user_data 
)
staticprotected

Definition at line 218 of file cvodes_interface.cpp.

218  {
219  try {
220  casadi_assert_dev(user_data);
221  auto m = to_mem(user_data);
222  auto& s = m->self;
223  if (s.calc_daeF(m, t, NV_DATA_S(x), nullptr, NV_DATA_S(xdot), nullptr)) return 1;
224  return 0;
225  } catch(std::exception& e) { // non-recoverable error
226  uerr() << "rhs failed: " << e.what() << std::endl;
227  return -1;
228  }
229 }

References to_mem(), and casadi::uerr().

Referenced by init_mem().

◆ rhsQB()

int casadi::CvodesInterface::rhsQB ( double  t,
N_Vector  x,
N_Vector  rx,
N_Vector  ruqdot,
void *  user_data 
)
staticprotected

Definition at line 445 of file cvodes_interface.cpp.

445  {
446  try {
447  casadi_assert_dev(user_data);
448  auto m = to_mem(user_data);
449  auto& s = m->self;
450  if (s.calc_quadB(m, t, NV_DATA_S(x), nullptr, NV_DATA_S(rx), nullptr,
451  NV_DATA_S(ruqdot), NV_DATA_S(ruqdot) + s.nrq_)) return 1;
452 
453  // Negate (note definition of g)
454  casadi_scal((s.nrq_ + s.nuq_), -1., NV_DATA_S(ruqdot));
455 
456  return 0;
457  } catch(std::exception& e) { // non-recoverable error
458  uerr() << "rhsQB failed: " << e.what() << std::endl;
459  return -1;
460  }
461 }

References casadi::casadi_scal(), to_mem(), and casadi::uerr().

Referenced by impulseB().

◆ rhsQF()

int casadi::CvodesInterface::rhsQF ( double  t,
N_Vector  x,
N_Vector  qdot,
void *  user_data 
)
staticprotected

Definition at line 416 of file cvodes_interface.cpp.

416  {
417  try {
418  auto m = to_mem(user_data);
419  auto& s = m->self;
420  if (s.calc_quadF(m, t, NV_DATA_S(x), nullptr, NV_DATA_S(qdot))) return 1;
421 
422  return 0;
423  } catch(std::exception& e) { // non-recoverable error
424  uerr() << "rhsQ failed: " << e.what() << std::endl;
425  return -1;
426  }
427 }

References to_mem(), and casadi::uerr().

Referenced by init_mem().

◆ save_offsets()

void casadi::SundialsInterface::save_offsets ( SundialsMemory m) const
inherited

Definition at line 364 of file sundials_interface.cpp.

364  {
365  // Retrieve stats offset, backward problem
366  m->nstepsB_off = m->nstepsB;
367  m->nfevalsB_off = m->nfevalsB;
368  m->nlinsetupsB_off = m->nlinsetupsB;
369  m->netfailsB_off = m->netfailsB;
370  m->nnitersB_off = m->nnitersB;
371  m->nncfailsB_off = m->nncfailsB;
372 }

References casadi::SundialsMemory::netfailsB, casadi::SundialsMemory::netfailsB_off, casadi::SundialsMemory::nfevalsB, casadi::SundialsMemory::nfevalsB_off, casadi::SundialsMemory::nlinsetupsB, casadi::SundialsMemory::nlinsetupsB_off, casadi::SundialsMemory::nncfailsB, casadi::SundialsMemory::nncfailsB_off, casadi::SundialsMemory::nnitersB, casadi::SundialsMemory::nnitersB_off, casadi::SundialsMemory::nstepsB, and casadi::SundialsMemory::nstepsB_off.

Referenced by impulseB(), and casadi::SundialsInterface::reset_stats().

◆ self()

Function casadi::FunctionInternal::self ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_k8

Definition at line 353 of file function_internal.hpp.

353 { return shared_from_this<Function>();}

Referenced by casadi::casadi_uno_term_cb_cpp().

◆ serialize()

void casadi::ProtoFunction::serialize ( SerializingStream s) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_jv

Definition at line 4393 of file function_internal.cpp.

4393  {
4394  serialize_type(s);
4395  serialize_body(s);
4396  }
virtual void serialize_type(SerializingStream &s) const
Serialize type information.
virtual void serialize_body(SerializingStream &s) const
Serialize an object without type information.

References casadi::ProtoFunction::serialize_body(), and casadi::ProtoFunction::serialize_type().

◆ serialize_base_function()

std::string casadi::Integrator::serialize_base_function ( ) const
inlineoverridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1mg

Reimplemented from casadi::ProtoFunction.

Definition at line 479 of file integrator_impl.hpp.

479 { return "Integrator"; }

◆ serialize_body()

void casadi::CvodesInterface::serialize_body ( SerializingStream s) const
overridevirtual

Reimplemented from casadi::Integrator.

Definition at line 775 of file cvodes_interface.cpp.

775  {
777  s.version("CvodesInterface", 3);
778 
779  s.pack("CvodesInterface::lmm", lmm_);
780  s.pack("CvodesInterface::iter", iter_);
781  s.pack("CvodesInterface::min_step_size", min_step_size_);
782  s.pack("CvodesInterface::always_recalculate_jacobian", always_recalculate_jacobian_);
783 }
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.

References always_recalculate_jacobian_, iter_, lmm_, min_step_size_, casadi::SerializingStream::pack(), casadi::SundialsInterface::serialize_body(), and casadi::SerializingStream::version().

◆ serialize_type()

void casadi::Integrator::serialize_type ( SerializingStream s) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1me

Reimplemented from casadi::FunctionInternal.

Definition at line 2440 of file integrator.cpp.

2440  {
2443 }
void serialize_type(SerializingStream &s) const override
Serialize type information.
void serialize_type(SerializingStream &s) const
Serialize type information.

References casadi::PluginInterface< Derived >::serialize_type(), and casadi::FunctionInternal::serialize_type().

◆ set_function() [1/2]

void casadi::OracleFunction::set_function ( const Function fcn)
inlineinherited

Register the function for evaluation and statistics gathering

Definition at line 183 of file oracle_function.hpp.

183 { set_function(fcn, fcn.name()); }

References casadi::Function::name(), and casadi::OracleFunction::set_function().

Referenced by casadi::OracleFunction::set_function().

◆ set_function() [2/2]

void casadi::OracleFunction::set_function ( const Function fcn,
const std::string &  fname,
bool  jit = false 
)
inherited

◆ set_jac_sparsity()

void casadi::FunctionInternal::set_jac_sparsity ( casadi_int  oind,
casadi_int  iind,
const Sparsity sp 
)
protectedinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nx

Definition at line 3964 of file function_internal.cpp.

3964  {
3965 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
3966  // Safe access to jac_sparsity_
3967  std::lock_guard<std::mutex> lock(jac_sparsity_mtx_);
3968 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
3969  casadi_int ind = iind + oind * n_in_;
3970  jac_sparsity_[false].resize(n_in_ * n_out_);
3971  jac_sparsity_[false].at(ind) = sp;
3972  jac_sparsity_[true].resize(n_in_ * n_out_);
3973  jac_sparsity_[true].at(ind) = to_compact(oind, iind, sp);
3974  }

References casadi::FunctionInternal::jac_sparsity_, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, and casadi::FunctionInternal::to_compact().

◆ set_p()

void casadi::Integrator::set_p ( IntegratorMemory m,
const double *  p 
) const
inherited

Definition at line 2546 of file integrator.cpp.

2546  {
2547  casadi_copy(p, np_, m->p);
2548 }
casadi_int np_
Number of forward and backward parameters.

References casadi::casadi_copy(), casadi::Integrator::np_, and casadi::IntegratorMemory::p.

Referenced by casadi::Integrator::eval().

◆ set_q()

void casadi::Integrator::set_q ( IntegratorMemory m,
const double *  q 
) const
inherited

Definition at line 2534 of file integrator.cpp.

2534  {
2535  casadi_copy(q, nq_, m->q);
2536 }

References casadi::casadi_copy(), casadi::Integrator::nq_, and casadi::IntegratorMemory::q.

Referenced by casadi::Integrator::eval().

◆ set_temp()

void casadi::OracleFunction::set_temp ( void *  mem,
const double **  arg,
double **  res,
casadi_int *  iw,
double *  w 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_q

Reimplemented from casadi::FunctionInternal.

Definition at line 505 of file oracle_function.cpp.

506  {
507 
508  auto *m = static_cast<OracleMemory*>(mem);
509  m->arg = arg;
510  m->res = res;
511  m->iw = iw;
512  m->w = w;
513  m->d_oracle.arg = arg;
514  m->d_oracle.res = res;
515  m->d_oracle.iw = iw;
516  m->d_oracle.w = w;
517  for (int i = 0; i < max_num_threads_; ++i) {
518  auto* ml = m->thread_local_mem[i];
519  for (auto&& s : ml->fstats) s.second.reset();
520  ml->arg = arg;
521  ml->res = res;
522  ml->iw = iw;
523  ml->w = w;
524  arg += stride_arg_;
525  res += stride_res_;
526  iw += stride_iw_;
527  w += stride_w_;
528  }
529 }

References casadi::OracleMemory::arg, casadi::OracleFunction::max_num_threads_, casadi::OracleFunction::stride_arg_, casadi::OracleFunction::stride_iw_, casadi::OracleFunction::stride_res_, and casadi::OracleFunction::stride_w_.

◆ set_u()

void casadi::Integrator::set_u ( IntegratorMemory m,
const double *  u 
) const
inherited

Definition at line 2550 of file integrator.cpp.

2550  {
2551  casadi_copy(u, nu_, m->u);
2552 }

References casadi::casadi_copy(), casadi::Integrator::nu_, and casadi::IntegratorMemory::u.

Referenced by casadi::Integrator::eval().

◆ set_work()

void casadi::SundialsInterface::set_work ( void *  mem,
const double **&  arg,
double **&  res,
casadi_int *&  iw,
double *&  w 
) const
overridevirtualinherited

Reimplemented from casadi::Integrator.

Definition at line 275 of file sundials_interface.cpp.

276  {
277  auto m = static_cast<SundialsMemory*>(mem);
278 
279  // Set work in base classes
280  Integrator::set_work(mem, arg, res, iw, w);
281 
282  // Work vectors
283  m->jacF = w; w += linsolF_.sparsity().nnz();
284 
285  // Work vectors
286  const Function& jacF = get_function("jacF");
287  m->jac_ode_x = w; w += jacF.nnz_out(JACF_ODE_X);
288  m->jac_alg_x = w; w += jacF.nnz_out(JACF_ALG_X);
289  m->jac_ode_z = w; w += jacF.nnz_out(JACF_ODE_Z);
290  m->jac_alg_z = w; w += jacF.nnz_out(JACF_ALG_Z);
291 }
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
Definition: integrator.cpp:882
const Sparsity & sparsity() const
Get linear system sparsity.
Definition: linsol.cpp:69
Linsol linsolF_
Linear solver.

References casadi::OracleFunction::get_function(), casadi::SundialsInterface::JACF_ALG_X, casadi::SundialsInterface::JACF_ALG_Z, casadi::SundialsInterface::JACF_ODE_X, casadi::SundialsInterface::JACF_ODE_Z, casadi::SundialsInterface::linsolF_, casadi::Sparsity::nnz(), casadi::Function::nnz_out(), casadi::Integrator::set_work(), and casadi::Linsol::sparsity().

◆ set_x()

void casadi::Integrator::set_x ( IntegratorMemory m,
const double *  x 
) const
inherited

Definition at line 2538 of file integrator.cpp.

2538  {
2539  casadi_copy(x, nx_, m->x);
2540 }

References casadi::casadi_copy(), casadi::Integrator::nx_, and casadi::IntegratorMemory::x.

Referenced by casadi::Integrator::eval().

◆ set_z()

void casadi::Integrator::set_z ( IntegratorMemory m,
const double *  z 
) const
inherited

Definition at line 2542 of file integrator.cpp.

2542  {
2543  casadi_copy(z, nz_, m->z);
2544 }

References casadi::casadi_copy(), casadi::Integrator::nz_, and casadi::IntegratorMemory::z.

Referenced by casadi::Integrator::eval().

◆ setup()

void casadi::FunctionInternal::setup ( void *  mem,
const double **  arg,
double **  res,
casadi_int *  iw,
double *  w 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_nb

Definition at line 3738 of file function_internal.cpp.

3739  {
3740  set_work(mem, arg, res, iw, w);
3741  set_temp(mem, arg, res, iw, w);
3742  auto *m = static_cast<FunctionMemory*>(mem);
3743  m->stats_available = true;
3744  }
virtual void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const
Set the (persistent) work vectors.
virtual void set_temp(void *mem, const double **arg, double **res, casadi_int *iw, double *w) const
Set the (temporary) work vectors.

References casadi::FunctionInternal::set_temp(), casadi::FunctionInternal::set_work(), and casadi::FunctionMemory::stats_available.

Referenced by casadi::Conic::eval(), casadi::Nlpsol::eval(), casadi::CallbackInternal::eval(), casadi::FiniteDiff::eval(), casadi::FmuFunction::eval(), casadi::Integrator::eval(), casadi::Map::eval(), casadi::OmpMap::eval(), casadi::ThreadMap::eval(), casadi::MapSum::eval(), casadi::MXFunction::eval(), casadi::Rootfinder::eval(), casadi::Switch::eval(), casadi::SXFunction::eval(), casadi::SlicotDple::eval(), casadi::SlicotExpm::eval(), casadi::BSplineInterpolant::eval(), and casadi::LinearInterpolant::eval().

◆ shared_from_this() [1/2]

B casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::shared_from_this ( )
inlineprotectedinherited

Definition at line 83 of file generic_shared_internal.hpp.

83  {
84  casadi_assert_dev(B::test_cast(static_cast<Internal*>(this)));
85  B ret;
86  ret.own(static_cast<Internal*>(this));
87  return ret;
88  }

◆ shared_from_this() [2/2]

const B casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::shared_from_this ( ) const
inlineprotectedinherited

Definition at line 92 of file generic_shared_internal.hpp.

92  {
93  casadi_assert_dev(B::test_cast(static_cast<const Internal*>(this)));
94  B ret;
95  ret.own(const_cast<Internal*>(static_cast<const Internal*>(this)));
96  return ret;
97  }

◆ signature()

std::string casadi::FunctionInternal::signature ( const std::string &  fname) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ly

Definition at line 2497 of file function_internal.cpp.

2497  {
2498  return "int " + fname + "(const casadi_real** arg, casadi_real** res, "
2499  "casadi_int* iw, casadi_real* w, int mem)";
2500  }

Referenced by casadi::CodeGenerator::add(), casadi::FunctionInternal::codegen(), and casadi::External::codegen_declarations().

◆ signature_unrolled()

std::string casadi::FunctionInternal::signature_unrolled ( const std::string &  fname) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_27o

Definition at line 2502 of file function_internal.cpp.

2502  {
2503  std::vector<std::string> args;
2504  for (auto e : name_in_) {
2505  args.push_back("const casadi_real* " + str(e));
2506  }
2507  for (auto e : name_out_) {
2508  args.push_back("casadi_real* " + str(e));
2509  }
2510  args.push_back("const casadi_real** arg");
2511  args.push_back("casadi_real** res");
2512  args.push_back("casadi_int* iw");
2513  args.push_back("casadi_real* w");
2514  args.push_back("int mem");
2515  return "int " + fname + "_unrolled(" + join(args, ", ") + ")";
2516  }

References casadi::join(), casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, and casadi::str().

Referenced by casadi::CodeGenerator::add().

◆ simplify_passes()

Function casadi::FunctionInternal::simplify_passes ( const std::vector< std::pair< std::string, casadi_int > > &  tasks) const
virtualinherited

Each pass is a (task, count) pair; count>0 runs the task that many times, count==0 runs it until a fixed point.

Extra doc: https://github.com/casadi/casadi/wiki/L_2ix

Reimplemented in casadi::XFunction< DerivedType, MatType, NodeType >, casadi::XFunction< MXFunction, MX, MXNode >, and casadi::XFunction< SXFunction, Matrix< SXElem >, SXNode >.

Definition at line 3933 of file function_internal.cpp.

3934  {
3935  casadi_assert(tasks.empty(), "simplify passes not supported for " + class_name());
3936  return self();
3937  }

References casadi::SharedObjectInternal::class_name().

Referenced by casadi::Function::transform().

◆ size1_in()

casadi_int casadi::FunctionInternal::size1_in ( casadi_int  ind) const
inlineinherited

◆ size1_out()

casadi_int casadi::FunctionInternal::size1_out ( casadi_int  ind) const
inlineinherited

◆ size2_in()

casadi_int casadi::FunctionInternal::size2_in ( casadi_int  ind) const
inlineinherited

◆ size2_out()

casadi_int casadi::FunctionInternal::size2_out ( casadi_int  ind) const
inlineinherited

◆ size_in()

std::pair<casadi_int, casadi_int> casadi::FunctionInternal::size_in ( casadi_int  ind) const
inlineinherited

◆ size_out()

std::pair<casadi_int, casadi_int> casadi::FunctionInternal::size_out ( casadi_int  ind) const
inlineinherited

◆ slice()

Function casadi::FunctionInternal::slice ( const std::string &  name,
const std::vector< casadi_int > &  order_in,
const std::vector< casadi_int > &  order_out,
const Dict opts 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l2

Reimplemented in casadi::XFunction< DerivedType, MatType, NodeType >, casadi::XFunction< MXFunction, MX, MXNode >, and casadi::XFunction< SXFunction, Matrix< SXElem >, SXNode >.

Definition at line 3945 of file function_internal.cpp.

3947  {
3948  return wrap().slice(name, order_in, order_out, opts);
3949  }
Function slice(const std::string &name, const std::vector< casadi_int > &order_in, const std::vector< casadi_int > &order_out, const Dict &opts=Dict()) const
returns a new function with a selection of inputs/outputs of the original
Definition: function.cpp:899

References casadi::Function::slice(), and casadi::FunctionInternal::wrap().

Referenced by casadi::Function::slice().

◆ sp_forward()

int casadi::Integrator::sp_forward ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
void *  mem 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1m5

Reimplemented from casadi::FunctionInternal.

Definition at line 1147 of file integrator.cpp.

1148  {
1149  if (verbose_) casadi_message(name_ + "::sp_forward");
1150 
1151  // Inputs
1152  const bvec_t* x0 = arg[INTEGRATOR_X0];
1153  const bvec_t* p = arg[INTEGRATOR_P];
1154  const bvec_t* u = arg[INTEGRATOR_U];
1155  const bvec_t* adj_xf = arg[INTEGRATOR_ADJ_XF];
1156  const bvec_t* adj_qf = arg[INTEGRATOR_ADJ_QF];
1157  arg += n_in_;
1158 
1159  // Outputs
1160  bvec_t* xf = res[INTEGRATOR_XF];
1161  bvec_t* zf = res[INTEGRATOR_ZF];
1162  bvec_t* qf = res[INTEGRATOR_QF];
1163  bvec_t* adj_x0 = res[INTEGRATOR_ADJ_X0];
1164  bvec_t* adj_p0 = res[INTEGRATOR_ADJ_P];
1165  bvec_t* adj_u = res[INTEGRATOR_ADJ_U];
1166  res += n_out_;
1167 
1168  // Work vectors
1169  bvec_t *x = w; w += nx_;
1170 
1171  bvec_t *adj_x = w; w += nrx_;
1172  bvec_t *adj_z = w; w += nrz_;
1173  bvec_t *adj_p = w; w += nrq_;
1174 
1175  bvec_t *tmp1 = w; w += nx_ + nz_;
1176  bvec_t *tmp2 = w; w += nrx_;
1177 
1178  // Memory struct for function calls below
1179  SpForwardMem m = {arg, res, iw, w};
1180 
1181  // Copy initial guess to x
1182  std::copy_n(x0, nx_, x);
1183 
1184  // Propagate forward
1185  for (casadi_int k = 0; k < nt(); ++k) {
1186  // Propagate through DAE function
1187  if (fdae_sp_forward(&m, x, p, u, tmp1, tmp1 + nx_)) return 1;
1188  for (casadi_int i = 0; i < nx_; ++i) tmp1[i] |= x[i];
1189 
1190  // "Solve" in order to resolve interdependencies (cf. Rootfinder)
1191  std::copy_n(tmp1, nx_ + nx_, w);
1192  std::fill_n(tmp1, nx_ + nz_, 0);
1193  sp_jac_dae_.spsolve(tmp1, w, false);
1194 
1195  // Get xf and zf
1196  if (xf) std::copy_n(tmp1, nx_, xf);
1197  if (zf) std::copy_n(tmp1 + nx_, nz_, zf);
1198 
1199  // Propagate to quadratures
1200  if (nq_ > 0 && qf) {
1201  if (fquad_sp_forward(&m, tmp1, tmp1 + nx_, p, u, qf)) return 1;
1202  }
1203 
1204  // Shift time
1205  std::copy_n(tmp1, nx_, x);
1206  if (xf) xf += nx_;
1207  if (zf) zf += nz_;
1208  if (qf) qf += nq_;
1209  if (u) u += nu_;
1210  }
1211 
1212  if (nrx_ > 0) {
1213  // Clear tmp2, adj_p0
1214  std::fill_n(tmp2, nrx_, 0);
1215  if (adj_p0) std::fill_n(adj_p0, nrq_, 0);
1216 
1217  // Take adj_xf, rp, adj_u past the last grid point
1218  if (adj_xf) adj_xf += nrx_ * nt();
1219  if (adj_qf) adj_qf += nrp_ * nt();
1220  if (adj_u) adj_u += nuq_ * nt();
1221 
1222  // Integrate backward
1223  for (casadi_int k = nt(); k-- > 0; ) {
1224  // Shift time
1225  if (adj_xf) adj_xf -= nrx_;
1226  if (adj_qf) adj_qf -= nrp_;
1227  if (adj_u) adj_u -= nuq_;
1228  if (u) u -= nu_;
1229 
1230  // Add impulse from adj_xf
1231  if (adj_xf) {
1232  for (casadi_int i = 0; i < nrx_; ++i) tmp2[i] |= adj_xf[i];
1233  }
1234 
1235  // Propagate through DAE function
1236  if (bdae_sp_forward(&m, tmp1, tmp1 + nx_, p, u, tmp2, adj_qf, adj_x, adj_z)) return 1;
1237  for (casadi_int i = 0; i < nrx_; ++i) adj_x[i] |= tmp2[i];
1238 
1239  // "Solve" in order to resolve interdependencies (cf. Rootfinder)
1240  std::copy_n(adj_x, nrx_ + nrz_, w);
1241  std::fill_n(adj_x, nrx_ + nrz_, 0);
1242  sp_jac_rdae_.spsolve(adj_x, w, false);
1243 
1244  // Propagate to quadratures
1245  if ((nrq_ > 0 && adj_p0) || (nuq_ > 0 && adj_u)) {
1246  if (bquad_sp_forward(&m, tmp1, tmp1 + nx_, p, u, adj_x, adj_z, adj_qf, adj_p, adj_u))
1247  return 1;
1248  // Sum contributions to adj_p0
1249  if (adj_p0) {
1250  for (casadi_int i = 0; i < nrq_; ++i) adj_p0[i] |= adj_p[i];
1251  }
1252  }
1253 
1254  // Update tmp2
1255  std::copy_n(adj_x, nx_, tmp2);
1256  }
1257 
1258  // Get adj_x0 at initial time
1259  if (adj_x0) std::copy_n(adj_x, nrx_, adj_x0);
1260  }
1261  return 0;
1262 }
Sparsity sp_jac_dae_
Sparsity pattern of the extended Jacobians.
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.
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.
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.
void spsolve(bvec_t *X, bvec_t *B, bool tr) const
Propagate sparsity through a linear solve.
Definition: sparsity.cpp:725

References casadi::Integrator::bdae_sp_forward(), casadi::Integrator::bquad_sp_forward(), casadi::Integrator::fdae_sp_forward(), casadi::Integrator::fquad_sp_forward(), casadi::INTEGRATOR_ADJ_P, casadi::INTEGRATOR_ADJ_QF, casadi::INTEGRATOR_ADJ_U, casadi::INTEGRATOR_ADJ_X0, casadi::INTEGRATOR_ADJ_XF, casadi::INTEGRATOR_P, casadi::INTEGRATOR_QF, casadi::INTEGRATOR_U, casadi::INTEGRATOR_X0, casadi::INTEGRATOR_XF, casadi::INTEGRATOR_ZF, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::Integrator::nq_, casadi::Integrator::nrp_, casadi::Integrator::nrq_, casadi::Integrator::nrx_, casadi::Integrator::nrz_, casadi::Integrator::nt(), casadi::Integrator::nu_, casadi::Integrator::nuq_, casadi::Integrator::nx_, casadi::Integrator::nz_, casadi::Integrator::sp_jac_dae_, casadi::Integrator::sp_jac_rdae_, casadi::Sparsity::spsolve(), and casadi::ProtoFunction::verbose_.

◆ sp_forward_block()

int casadi::FunctionInternal::sp_forward_block ( const bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
void *  mem,
casadi_int  oind,
casadi_int  iind 
) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mx

Definition at line 3044 of file function_internal.cpp.

3045  {
3046  // Get the sparsity of the Jacobian block
3047  Sparsity sp = jac_sparsity(oind, iind, true, false);
3048  if (sp.is_null() || sp.nnz() == 0) return 0; // Skip if zero
3049  // Carry out the sparse matrix-vector multiplication
3050  casadi_int d1 = sp.size2();
3051  const casadi_int *colind = sp.colind(), *row = sp.row();
3052  for (casadi_int cc=0; cc<d1; ++cc) {
3053  for (casadi_int el = colind[cc]; el < colind[cc+1]; ++el) {
3054  res[oind][row[el]] |= arg[iind][cc];
3055  }
3056  }
3057  return 0;
3058  }

References casadi::Sparsity::colind(), casadi::GenericShared< Shared, Internal >::is_null(), casadi::FunctionInternal::jac_sparsity(), casadi::Sparsity::nnz(), casadi::Sparsity::row(), and casadi::Sparsity::size2().

Referenced by casadi::FunctionInternal::sp_forward().

◆ sp_jac_aug()

Sparsity casadi::Integrator::sp_jac_aug ( const Sparsity J,
const Sparsity J1 
) const
inherited

Definition at line 1805 of file integrator.cpp.

1805  {
1806  // Row 1, column 2 in the augmented Jacobian
1807  Sparsity J12(J.size1(), nfwd_ * J.size2());
1808  // Row 2, column 1 in the augmented Jacobian
1809  Sparsity J21 = vertcat(std::vector<Sparsity>(nfwd_, J1));
1810  // Row 2, column 2 in the augmented Jacobian
1811  Sparsity J22 = diagcat(std::vector<Sparsity>(nfwd_, J));
1812  // Form block matrix
1813  return blockcat(J, J12, J21, J22);
1814 }

References casadi::Integrator::nfwd_, casadi::Sparsity::size1(), and casadi::Sparsity::size2().

Referenced by casadi::Integrator::sp_jac_dae(), and casadi::Integrator::sp_jac_rdae().

◆ sp_jac_dae()

Sparsity casadi::Integrator::sp_jac_dae ( )
inherited

Definition at line 1817 of file integrator.cpp.

1817  {
1818  // Get the functions
1819  const Function& F = get_function("daeF");
1820  // Sparsity pattern for nonaugmented system
1821  Sparsity J_xx = F.jac_sparsity(DAE_ODE, DYN_X) + Sparsity::diag(nx1_);
1822  Sparsity J_xz = F.jac_sparsity(DAE_ODE, DYN_Z);
1823  Sparsity J_zx = F.jac_sparsity(DAE_ALG, DYN_X);
1824  Sparsity J_zz = F.jac_sparsity(DAE_ALG, DYN_Z);
1825  // Augment with sensitivity equations
1826  if (nfwd_ > 0) {
1827  const Function& fwd_F = get_function(forward_name("daeF", 1));
1828  J_xx = sp_jac_aug(J_xx, fwd_F.jac_sparsity(DAE_ODE, DYN_X));
1829  J_xz = sp_jac_aug(J_xz, fwd_F.jac_sparsity(DAE_ODE, DYN_Z));
1830  J_zx = sp_jac_aug(J_zx, fwd_F.jac_sparsity(DAE_ALG, DYN_X));
1831  J_zz = sp_jac_aug(J_zz, fwd_F.jac_sparsity(DAE_ALG, DYN_Z));
1832  }
1833  // Assemble the block matrix
1834  return blockcat(J_xx, J_xz, J_zx, J_zz);
1835 }
Sparsity sp_jac_aug(const Sparsity &J, const Sparsity &J1) const
Helper function, get augmented system Jacobian.
static Sparsity diag(casadi_int nrow)
Create diagonal sparsity pattern *.
Definition: sparsity.hpp:190

References casadi::Integrator::DAE_ALG, casadi::Integrator::DAE_ODE, casadi::Sparsity::diag(), casadi::DYN_X, casadi::DYN_Z, casadi::FunctionInternal::forward_name(), casadi::OracleFunction::get_function(), casadi::Function::jac_sparsity(), casadi::Integrator::nfwd_, casadi::Integrator::nx1_, and casadi::Integrator::sp_jac_aug().

Referenced by casadi::Integrator::init().

◆ sp_jac_rdae()

Sparsity casadi::Integrator::sp_jac_rdae ( )
inherited

Definition at line 1837 of file integrator.cpp.

1837  {
1838  // Get the functions
1839  const Function& G = get_function("daeB");
1840  // Sparsity pattern for nonaugmented system
1841  Sparsity J_xx = G.jac_sparsity(BDAE_ADJ_X, BDYN_ADJ_ODE) + Sparsity::diag(nrx1_ * nadj_);
1842  Sparsity J_xz = G.jac_sparsity(BDAE_ADJ_X, BDYN_ADJ_ALG);
1843  Sparsity J_zx = G.jac_sparsity(BDAE_ADJ_Z, BDYN_ADJ_ODE);
1844  Sparsity J_zz = G.jac_sparsity(BDAE_ADJ_Z, BDYN_ADJ_ALG);
1845  // Augment with sensitivity equations
1846  if (nfwd_ > 0) {
1847  const Function& fwd_G = get_function(forward_name("daeB", 1));
1848  J_xx = sp_jac_aug(J_xx, fwd_G.jac_sparsity(BDAE_ADJ_X, BDYN_ADJ_ODE));
1849  J_xz = sp_jac_aug(J_xz, fwd_G.jac_sparsity(BDAE_ADJ_X, BDYN_ADJ_ALG));
1850  J_zx = sp_jac_aug(J_zx, fwd_G.jac_sparsity(BDAE_ADJ_Z, BDYN_ADJ_ODE));
1851  J_zz = sp_jac_aug(J_zz, fwd_G.jac_sparsity(BDAE_ADJ_Z, BDYN_ADJ_ALG));
1852  }
1853  // Assemble the block matrix
1854  return blockcat(J_xx, J_xz, J_zx, J_zz);
1855 }

References casadi::Integrator::BDAE_ADJ_X, casadi::Integrator::BDAE_ADJ_Z, casadi::Integrator::BDYN_ADJ_ALG, casadi::Integrator::BDYN_ADJ_ODE, casadi::Sparsity::diag(), casadi::FunctionInternal::forward_name(), casadi::OracleFunction::get_function(), casadi::Function::jac_sparsity(), casadi::Integrator::nadj_, casadi::Integrator::nfwd_, casadi::Integrator::nrx1_, and casadi::Integrator::sp_jac_aug().

Referenced by casadi::Integrator::init().

◆ sp_reverse()

int casadi::Integrator::sp_reverse ( bvec_t **  arg,
bvec_t **  res,
casadi_int *  iw,
bvec_t w,
void *  mem 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1m6

Reimplemented from casadi::FunctionInternal.

Definition at line 1412 of file integrator.cpp.

1413  {
1414  if (verbose_) casadi_message(name_ + "::sp_reverse");
1415 
1416  // Inputs
1417  bvec_t* x0 = arg[INTEGRATOR_X0];
1418  bvec_t* p = arg[INTEGRATOR_P];
1419  bvec_t* u = arg[INTEGRATOR_U];
1420  bvec_t* adj_xf = arg[INTEGRATOR_ADJ_XF];
1421  bvec_t* adj_qf = arg[INTEGRATOR_ADJ_QF];
1422  arg += n_in_;
1423 
1424  // Outputs
1425  bvec_t* xf = res[INTEGRATOR_XF];
1426  bvec_t* zf = res[INTEGRATOR_ZF];
1427  bvec_t* qf = res[INTEGRATOR_QF];
1428  bvec_t* adj_x0 = res[INTEGRATOR_ADJ_X0];
1429  bvec_t* adj_p0 = res[INTEGRATOR_ADJ_P];
1430  bvec_t* adj_u = res[INTEGRATOR_ADJ_U];
1431  res += n_out_;
1432 
1433  // Work vectors
1434  bvec_t *x = w; w += nx_;
1435 
1436  bvec_t *adj_x = w; w += nrx_;
1437  bvec_t *adj_z = w; w += nrz_;
1438  bvec_t *adj_p = w; w += nrq_;
1439 
1440  bvec_t *tmp1 = w; w += nx_ + nz_;
1441  bvec_t *tmp2 = w; w += nrx_;
1442 
1443  // Memory struct for function calls below
1444  SpReverseMem m = {arg, res, iw, w};
1445 
1446  // Clear state vector
1447  std::fill_n(tmp1, nx_ + nz_, 0);
1448 
1449  if (nrx_ > 0) {
1450  // Propagate from adj_x0 initial time
1451  if (adj_x0) {
1452  std::copy_n(adj_x0, nrx_, adj_x);
1453  std::fill_n(adj_x0, nrx_, 0);
1454  } else {
1455  std::fill_n(adj_x, nrx_, 0);
1456  }
1457  // Reset adj_z
1458  std::fill_n(adj_z, nrz_, 0);
1459 
1460  // Save adj_p0: See note below
1461  if (adj_p0) std::copy_n(adj_p0, nrq_, adj_p);
1462 
1463  // Step backwards through backward problem
1464  for (casadi_int k = 0; k < nt(); ++k) {
1465  // Restore adj_p0: See note below
1466  if (adj_p0) std::copy_n(adj_p, nrq_, adj_p0);
1467 
1468  // Add impulse from adj_xf
1469  if (adj_xf) {
1470  for (casadi_int i = 0; i < nrx_; ++i) adj_x[i] |= adj_xf[i];
1471  std::fill_n(adj_xf, nrx_, 0);
1472  }
1473 
1474  // Get dependencies from backward quadratures
1475  if ((nrq_ > 0 && adj_p0) || (nuq_ > 0 && adj_u)) {
1476  if (bquad_sp_reverse(&m, tmp1, tmp1 + nx_, p, u, adj_x, adj_z, adj_qf, adj_p0, adj_u))
1477  return 1;
1478  }
1479 
1480  // Propagate interdependencies
1481  std::fill_n(w, nrx_ + nrz_, 0);
1482  sp_jac_rdae_.spsolve(w, adj_x, true);
1483  std::copy_n(w, nrx_ + nrz_, adj_x);
1484 
1485  // Direct dependency tmp2 -> adj_x
1486  std::copy_n(adj_x, nrx_, tmp2);
1487 
1488  // Indirect dependency via g
1489  if (bdae_sp_reverse(&m, tmp1, tmp1 + nx_, p, u, tmp2, adj_qf, adj_x, adj_z)) return 1;
1490 
1491  // Update adj_x, adj_z
1492  std::copy_n(tmp2, nrx_, adj_x);
1493  std::fill_n(adj_z, nrz_, 0);
1494 
1495  // Shift time
1496  if (adj_xf) adj_xf += nrx_;
1497  if (adj_qf) adj_qf += nrp_;
1498  if (adj_u) adj_u += nuq_;
1499  if (u) u += nu_;
1500  }
1501  } else {
1502  // Take u past the last grid point
1503  if (u) u += nu_ * nt();
1504  }
1505 
1506  // Take xf, zf, qf past the last grid point
1507  if (xf) xf += nx_ * nt();
1508  if (zf) zf += nz_ * nt();
1509  if (qf) qf += nq_ * nt();
1510 
1511  // Step backwards through forward problem
1512  for (casadi_int k = nt(); k-- > 0; ) {
1513  // Shift time
1514  if (xf) xf -= nx_;
1515  if (zf) zf -= nz_;
1516  if (qf) qf -= nq_;
1517  if (u) u -= nu_;
1518 
1519  // Add impulse from outputs
1520  if (xf) {
1521  for (casadi_int i = 0; i < nx_; ++i) tmp1[i] |= xf[i];
1522  std::fill_n(xf, nx_, 0);
1523  }
1524  if (zf) {
1525  for (casadi_int i = 0; i < nz_; ++i) tmp1[nx_ + i] |= zf[i];
1526  std::fill_n(zf, nz_, 0);
1527  }
1528 
1529  // Get dependencies from forward quadratures, if any
1530  if (nq_ > 0 && qf) {
1531  if (fquad_sp_reverse(&m, tmp1, tmp1 + nx_, p, u, qf)) return 1;
1532  }
1533 
1534  // Propagate interdependencies
1535  std::fill_n(w, nx_ + nz_, 0);
1536  sp_jac_dae_.spsolve(w, tmp1, true);
1537  std::copy_n(w, nx_ + nz_, tmp1);
1538 
1539  // Direct dependency ode -> x
1540  std::copy_n(tmp1, nx_, x);
1541 
1542  // Indirect dependency through f
1543  if (fdae_sp_reverse(&m, x, p, u, tmp1, tmp1 + nx_)) return 1;
1544 
1545  // Update x, z
1546  std::copy_n(x, nx_, tmp1);
1547  std::fill_n(tmp1 + nx_, nz_, 0);
1548  }
1549 
1550  // Direct dependency x0 -> x
1551  if (x0) {
1552  for (casadi_int i = 0; i < nx_; ++i) x0[i] |= x[i];
1553  }
1554 
1555  return 0;
1556 }
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.
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.
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.
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.

References casadi::Integrator::bdae_sp_reverse(), casadi::Integrator::bquad_sp_reverse(), casadi::Integrator::fdae_sp_reverse(), casadi::Integrator::fquad_sp_reverse(), casadi::INTEGRATOR_ADJ_P, casadi::INTEGRATOR_ADJ_QF, casadi::INTEGRATOR_ADJ_U, casadi::INTEGRATOR_ADJ_X0, casadi::INTEGRATOR_ADJ_XF, casadi::INTEGRATOR_P, casadi::INTEGRATOR_QF, casadi::INTEGRATOR_U, casadi::INTEGRATOR_X0, casadi::INTEGRATOR_XF, casadi::INTEGRATOR_ZF, casadi::FunctionInternal::n_in_, casadi::FunctionInternal::n_out_, casadi::ProtoFunction::name_, casadi::Integrator::nq_, casadi::Integrator::nrp_, casadi::Integrator::nrq_, casadi::Integrator::nrx_, casadi::Integrator::nrz_, casadi::Integrator::nt(), casadi::Integrator::nu_, casadi::Integrator::nuq_, casadi::Integrator::nx_, casadi::Integrator::nz_, casadi::Integrator::sp_jac_dae_, casadi::Integrator::sp_jac_rdae_, casadi::Sparsity::spsolve(), and casadi::ProtoFunction::verbose_.

◆ sp_weight()

double casadi::FunctionInternal::sp_weight ( ) const
virtualinherited

sparsity propagation

Extra doc: https://github.com/casadi/casadi/wiki/L_l6

Definition at line 3475 of file function_internal.cpp.

3475  {
3476  // If reverse mode propagation unavailable, use forward
3477  if (!has_sprev()) return 0;
3478 
3479  // If forward mode propagation unavailable, use reverse
3480  if (!has_spfwd()) return 1;
3481 
3482  // Use the (potentially user set) option
3483  return ad_weight_sp_;
3484  }

References casadi::FunctionInternal::ad_weight_sp_, casadi::FunctionInternal::has_spfwd(), and casadi::FunctionInternal::has_sprev().

Referenced by casadi::FunctionInternal::get_jac_sparsity(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::MXFunction::sp_forward(), casadi::SXFunction::sp_forward(), casadi::MXFunction::sp_reverse(), casadi::SXFunction::sp_reverse(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ sparsity_in()

const Sparsity& casadi::FunctionInternal::sparsity_in ( casadi_int  ind) const
inlineinherited

◆ sparsity_out()

const Sparsity& casadi::FunctionInternal::sparsity_out ( casadi_int  ind) const
inlineinherited

◆ sprint()

void casadi::ProtoFunction::sprint ( char *  buf,
size_t  buf_sz,
const char *  fmt,
  ... 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_js

Definition at line 4088 of file function_internal.cpp.

4088  {
4089  // Variable number of arguments
4090  va_list args;
4091  va_start(args, fmt);
4092  // Print to buffer
4093  casadi_int n = vsnprintf(buf, buf_sz, fmt, args);
4094  // Cleanup
4095  va_end(args);
4096  // Throw error if failure
4097  casadi_assert(n>=0 && n<buf_sz, "Print failure while processing '" + std::string(fmt) + "'");
4098  }

Referenced by casadi::ProtoFunction::format_time(), and casadi::ProtoFunction::print_time().

◆ string_from_UnifiedReturnStatus()

std::string casadi::FunctionInternal::string_from_UnifiedReturnStatus ( UnifiedReturnStatus  status)
staticinherited

Definition at line 4156 of file function_internal.cpp.

4156  {
4157  switch (status) {
4158  case SOLVER_RET_LIMITED: return "SOLVER_RET_LIMITED";
4159  case SOLVER_RET_NAN: return "SOLVER_RET_NAN";
4160  case SOLVER_RET_SUCCESS: return "SOLVER_RET_SUCCESS";
4161  default: return "SOLVER_RET_UNKNOWN";
4162  }
4163  }
@ SOLVER_RET_NAN
@ SOLVER_RET_LIMITED
@ SOLVER_RET_SUCCESS

References casadi::SOLVER_RET_LIMITED, casadi::SOLVER_RET_NAN, and casadi::SOLVER_RET_SUCCESS.

Referenced by casadi::Conic::get_stats(), casadi::Nlpsol::get_stats(), and casadi::Rootfinder::get_stats().

◆ sx_in() [1/2]

const std::vector< SX > casadi::FunctionInternal::sx_in ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Reimplemented in casadi::SXFunction.

Definition at line 3502 of file function_internal.cpp.

3502  {
3503  std::vector<SX> ret(n_in_);
3504  for (casadi_int i=0; i<ret.size(); ++i) {
3505  ret[i] = sx_in(i);
3506  }
3507  return ret;
3508  }
virtual const std::vector< SX > sx_in() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_in_.

◆ sx_in() [2/2]

const SX casadi::FunctionInternal::sx_in ( casadi_int  ind) const
virtualinherited

◆ sx_out() [1/2]

const std::vector< SX > casadi::FunctionInternal::sx_out ( ) const
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_l7

Definition at line 3510 of file function_internal.cpp.

3510  {
3511  std::vector<SX> ret(n_out_);
3512  for (casadi_int i=0; i<ret.size(); ++i) {
3513  ret[i] = sx_out(i);
3514  }
3515  return ret;
3516  }
virtual const std::vector< SX > sx_out() const
Get function input(s) and output(s)

References casadi::FunctionInternal::n_out_.

◆ sx_out() [2/2]

const SX casadi::FunctionInternal::sx_out ( casadi_int  ind) const
virtualinherited

◆ symbolic_output()

std::vector< MX > casadi::FunctionInternal::symbolic_output ( const std::vector< MX > &  arg) const
virtualinherited

Reimplemented in casadi::MXFunction.

Definition at line 1207 of file function_internal.cpp.

1207  {
1208  return self()(arg);
1209  }

Referenced by casadi::MXFunction::symbolic_output().

◆ symbolicAdjSeed()

template<typename MatType >
std::vector< std::vector< MatType > > casadi::FunctionInternal::symbolicAdjSeed ( casadi_int  nadj,
const std::vector< MatType > &  v 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_ns

Definition at line 1591 of file function_internal.hpp.

1592  {
1593  std::vector<std::vector<MatType> > aseed(nadj, v);
1594  for (casadi_int dir=0; dir<nadj; ++dir) {
1595  // Replace symbolic inputs
1596  casadi_int oind=0;
1597  for (typename std::vector<MatType>::iterator i=aseed[dir].begin();
1598  i!=aseed[dir].end();
1599  ++i, ++oind) {
1600  // Name of the adjoint seed
1601  std::stringstream ss;
1602  ss << "a";
1603  if (nadj>1) ss << dir << "_";
1604  ss << oind;
1605 
1606  // Save to matrix
1607  *i = MatType::sym(ss.str(), is_diff_out_[oind] ? i->sparsity() : Sparsity(i->size()));
1608 
1609  }
1610  }
1611  return aseed;
1612  }

References casadi::FunctionInternal::is_diff_out_.

◆ sz_arg()

size_t casadi::FunctionInternal::sz_arg ( ) const
inlineinherited

◆ sz_iw()

size_t casadi::FunctionInternal::sz_iw ( ) const
inlineinherited

◆ sz_res()

size_t casadi::FunctionInternal::sz_res ( ) const
inlineinherited

◆ sz_w()

size_t casadi::FunctionInternal::sz_w ( ) const
inlineinherited

◆ sz_work()

void casadi::FunctionInternal::sz_work ( size_t &  sz_arg,
size_t &  sz_res,
size_t &  sz_iw,
size_t &  sz_w 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_mz

Definition at line 3092 of file function_internal.cpp.

3093  {
3094  sz_arg = this->sz_arg();
3095  sz_res = this->sz_res();
3096  sz_iw = this->sz_iw();
3097  sz_w = this->sz_w();
3098  }

References casadi::FunctionInternal::sz_arg(), casadi::FunctionInternal::sz_iw(), casadi::FunctionInternal::sz_res(), and casadi::FunctionInternal::sz_w().

◆ to_compact()

Sparsity casadi::FunctionInternal::to_compact ( casadi_int  oind,
casadi_int  iind,
const Sparsity sp 
) const
inherited

Definition at line 1978 of file function_internal.cpp.

1979  {
1980  // Strip rows and columns
1981  std::vector<casadi_int> mapping;
1982  return sp.sub(sparsity_out(oind).find(), sparsity_in(iind).find(), mapping);
1983  }

References casadi::FunctionInternal::find(), casadi::FunctionInternal::sparsity_in(), casadi::FunctionInternal::sparsity_out(), and casadi::Sparsity::sub().

Referenced by casadi::FunctionInternal::jac_sparsity(), and casadi::FunctionInternal::set_jac_sparsity().

◆ to_mem()

static CvodesMemory* casadi::CvodesInterface::to_mem ( void *  mem)
inlinestatic

Definition at line 144 of file cvodes_interface.hpp.

144  {
145  CvodesMemory* m = static_cast<CvodesMemory*>(mem);
146  casadi_assert_dev(m);
147  return m;
148  }

Referenced by advance_noevent(), ehfun(), impulseB(), init_mem(), jtimesB(), jtimesF(), lsetupB(), lsetupF(), lsolveB(), lsolveF(), psetupB(), psetupF(), psolveB(), psolveF(), reset(), retreat(), rhsB(), rhsF(), rhsQB(), and rhsQF().

◆ tocache()

void casadi::FunctionInternal::tocache ( const Function f,
const std::string &  suffix = "" 
) const
inherited

◆ tocache_if_missing()

void casadi::FunctionInternal::tocache_if_missing ( Function f,
const std::string &  suffix = "" 
) const
inherited

◆ trigger_event()

int casadi::Integrator::trigger_event ( IntegratorMemory m,
casadi_int *  ind 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29q

Definition at line 2653 of file integrator.cpp.

2653  {
2654  // Throw an error if too many events are happening within a single control interval
2655  if (++m->num_events > max_events_) {
2656  casadi_error("At t = " + str(m->t) + ": Too many event iterations during interval "
2657  + str(m->k));
2658  }
2659  // Consistency checks
2660  if (*ind < 0 || m->event_triggered[*ind]) return 1;
2661  // Mark event as triggered
2662  m->event_triggered[*ind] = 1;
2663  // Print progress
2664  if (verbose_) casadi_message("Zero crossing for index " + str(*ind) + " at t = " + str(m->t));
2665  // The event time will be impacted by perturbations in x, z, u, p.
2666  // the perturbed time will be given by the following implicit function:
2667  // e[ind](t, x + (t - t_event) * xdot, z + (t - t_event) * zdot, u, p) = 0
2668  // The sensitivities of t as a functions of fwd_x, fwd_z, fwd_u and fwd_p
2669  // are given by the implicit function theorem:
2670  // de/dt(t, x, z, u, p) * fwd_t + de/dx * fwd_x + de/dz * fwd_z + de/du * fwd_u + de/dp * fwd_p
2671  // <=> fwd_t = -fwd_e(fwd_x, fwd_z, fwd_u, fwd_p) / edot
2672  if (nfwd_ > 0) {
2673  m->arg[DYN_NUM_IN + DYN_ODE] = m->xdot; // out:ode
2674  m->arg[DYN_NUM_IN + DYN_ALG] = nullptr; // out:alg
2675  m->arg[DYN_NUM_IN + DYN_QUAD] = nullptr; // out:quad
2676  m->arg[DYN_NUM_IN + DYN_ZERO] = m->e; // out:zero
2677  m->arg[DYN_NUM_IN + DYN_NUM_OUT + DYN_T] = nullptr; // fwd:t
2678  m->arg[DYN_NUM_IN + DYN_NUM_OUT + DYN_X] = m->x + nx1_; // fwd:x
2679  m->arg[DYN_NUM_IN + DYN_NUM_OUT + DYN_Z] = m->z + nz1_; // fwd:z
2680  m->arg[DYN_NUM_IN + DYN_NUM_OUT + DYN_P] = m->p + np1_; // fwd:p
2681  m->arg[DYN_NUM_IN + DYN_NUM_OUT + DYN_U] = m->u + nu1_; // fwd:u
2682  m->res[DYN_ODE] = nullptr; // fwd:ode
2683  m->res[DYN_ALG] = nullptr; // fwd:alg
2684  m->res[DYN_QUAD] = nullptr; // fwd:quad
2685  m->res[DYN_ZERO] = m->tmp1; // fwd:zero
2686  if (calc_function(m, forward_name("dae", nfwd_))) return 1;
2687  // Calculate sensitivity in t
2688  for (casadi_int i = 0; i < nfwd_; ++i) {
2689  m->tmp1[i] = -m->tmp1[*ind + ne_ * i] / m->edot[*ind];
2690  }
2691  // Propagate this sensitivity to the state vector
2692  for (casadi_int i = 0; i < nfwd_; ++i) {
2693  casadi_axpy(nx1_, m->tmp1[i], m->xdot, m->x + nx1_ * (1 + i));
2694  }
2695  }
2696  // Call event transition function, if any
2697  if (has_function("transition")) {
2698  // Evaluate to tmp2
2699  double index = *ind; // function expects floating point values
2700  m->arg[EVENT_INDEX] = &index; // index
2701  m->arg[EVENT_T] = &m->t; // t
2702  m->arg[EVENT_X] = m->x; // x
2703  m->arg[EVENT_Z] = m->z; // z
2704  m->arg[EVENT_P] = m->p; // p
2705  m->arg[EVENT_U] = m->u; // u
2706  m->res[EVENT_POST_X] = m->tmp2; // post_x
2707  m->res[EVENT_POST_Z] = m->tmp2 + nx_; // post_z
2708  if (calc_function(m, "transition")) return 1;
2709  // Propagate forward sensitivities
2710  if (nfwd_ > 0) {
2711  // Propagate sensitivities through event transition
2712  m->arg[EVENT_NUM_IN + EVENT_POST_X] = m->tmp2; // out:post_x
2713  m->arg[EVENT_NUM_IN + EVENT_POST_Z] = m->tmp2 + nx_; // out:post_z
2714  m->arg[EVENT_NUM_IN + EVENT_NUM_OUT + EVENT_INDEX] = nullptr; // fwd:index
2715  m->arg[EVENT_NUM_IN + EVENT_NUM_OUT + EVENT_T] = m->tmp1; // fwd:t
2716  m->arg[EVENT_NUM_IN + EVENT_NUM_OUT + EVENT_X] = m->x + nx1_; // fwd:x
2717  m->arg[EVENT_NUM_IN + EVENT_NUM_OUT + EVENT_Z] = m->z + nz1_; // fwd:z
2718  m->arg[EVENT_NUM_IN + EVENT_NUM_OUT + EVENT_P] = m->p + np1_; // fwd:p
2719  m->arg[EVENT_NUM_IN + EVENT_NUM_OUT + EVENT_U] = m->u + nu1_; // fwd:u
2720  m->res[EVENT_POST_X] = m->tmp2 + nx1_; // fwd:post_x
2721  m->res[EVENT_POST_Z] = m->tmp2 + nx_ + nz1_; // fwd:post_z
2722  calc_function(m, forward_name("transition", nfwd_));
2723  }
2724  }
2725  // Update x, z
2726  casadi_copy(m->tmp2, nx_ + nz_, m->x);
2727  // Calculate m->xdot and m->zdot
2728  if (calc_edot(m)) return 1;
2729  // Propagate this sensitivity to the state vector
2730  for (casadi_int i = 0; i < nfwd_; ++i) {
2731  casadi_axpy(nx1_, -m->tmp1[i], m->xdot, m->x + nx1_ * (1 + i));
2732  }
2733  // TODO(@jaeandersson): Check if other events need to be triggered
2734  *ind = -1; // for now, do not trigger other events
2735  return 0;
2736 }
casadi_int max_events_
Maximum total number of events during the simulation.
@ EVENT_INDEX
Definition: integrator.hpp:208
@ EVENT_NUM_IN
Definition: integrator.hpp:214
@ EVENT_POST_Z
Definition: integrator.hpp:219
@ EVENT_POST_X
Definition: integrator.hpp:218
@ EVENT_NUM_OUT
Definition: integrator.hpp:220

References casadi::OracleMemory::arg, casadi::Integrator::calc_edot(), casadi::OracleFunction::calc_function(), casadi::casadi_axpy(), casadi::casadi_copy(), casadi::DYN_ALG, casadi::DYN_NUM_IN, casadi::DYN_NUM_OUT, casadi::DYN_ODE, casadi::DYN_P, casadi::DYN_QUAD, casadi::DYN_T, casadi::DYN_U, casadi::DYN_X, casadi::DYN_Z, casadi::DYN_ZERO, casadi::IntegratorMemory::e, casadi::IntegratorMemory::edot, casadi::EVENT_INDEX, casadi::EVENT_NUM_IN, casadi::EVENT_NUM_OUT, casadi::EVENT_P, casadi::EVENT_POST_X, casadi::EVENT_POST_Z, casadi::EVENT_T, casadi::IntegratorMemory::event_triggered, casadi::EVENT_U, casadi::EVENT_X, casadi::EVENT_Z, casadi::FunctionInternal::forward_name(), casadi::OracleFunction::has_function(), casadi::IntegratorMemory::k, casadi::Integrator::max_events_, casadi::Integrator::ne_, casadi::Integrator::nfwd_, casadi::Integrator::np1_, casadi::Integrator::nu1_, casadi::IntegratorMemory::num_events, casadi::Integrator::nx1_, casadi::Integrator::nx_, casadi::Integrator::nz1_, casadi::Integrator::nz_, casadi::IntegratorMemory::p, casadi::OracleMemory::res, casadi::str(), casadi::IntegratorMemory::t, casadi::IntegratorMemory::tmp1, casadi::IntegratorMemory::tmp2, casadi::IntegratorMemory::u, casadi::ProtoFunction::verbose_, casadi::IntegratorMemory::x, casadi::IntegratorMemory::xdot, and casadi::IntegratorMemory::z.

Referenced by casadi::Integrator::eval().

◆ uses_output()

virtual bool casadi::FunctionInternal::uses_output ( ) const
inlinevirtualinherited

◆ weak()

Extra doc: https://github.com/casadi/casadi/wiki/L_1ai

Definition at line 67 of file generic_shared_internal.hpp.

210  {
211 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
212  auto* w = weak_ref_.load(std::memory_order_acquire);
213  if (!w) {
214  auto* nw = new GenericWeakRef<Shared, Internal>(static_cast<Internal*>(this));
215  GenericWeakRef<Shared, Internal>* expected = nullptr;
216  if (weak_ref_.compare_exchange_strong(
217  expected, nw, std::memory_order_release, std::memory_order_acquire)) {
218  w = nw;
219  } else {
220  delete nw; // lost the race; another thread published first
221  w = expected;
222  }
223  }
224  return w;
225 #else
226  if (weak_ref_==nullptr) {
227  weak_ref_ = new GenericWeakRef<Shared, Internal>(static_cast<Internal*>(this));
228  }
229  return weak_ref_;
230 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
231  }

◆ which_depends()

std::vector< bool > casadi::FunctionInternal::which_depends ( const std::string &  s_in,
const std::vector< std::string > &  s_out,
casadi_int  order,
bool  tr = false 
) const
virtualinherited
Parameters
[in]s_inInput name
[in]s_outOutput name(s)
[in]orderOnly 1 (linear) and 2 (nonlinear) allowed
[in]trFlip the relationship. Return which expressions contain the variables

Extra doc: https://github.com/casadi/casadi/wiki/L_k9

Reimplemented in casadi::XFunction< DerivedType, MatType, NodeType >, casadi::XFunction< MXFunction, MX, MXNode >, and casadi::XFunction< SXFunction, Matrix< SXElem >, SXNode >.

Definition at line 3925 of file function_internal.cpp.

3927  {
3928  Function f = shared_from_this<Function>();
3929  f = f.wrap();
3930  return f.which_depends(s_in, s_out, order, tr);
3931  }

References casadi::Function::which_depends(), and casadi::Function::wrap().

◆ wrap() [1/2]

Function casadi::FunctionInternal::wrap ( ) const
inherited

◆ wrap() [2/2]

Function casadi::FunctionInternal::wrap ( const std::string &  name) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_li

Definition at line 1186 of file function_internal.cpp.

1186  {
1187  Function f;
1188  if (!incache(name, f)) {
1189  // Options
1190  Dict opts;
1191  opts["derivative_of"] = derivative_of_;
1192  opts["ad_weight"] = ad_weight();
1193  opts["ad_weight_sp"] = sp_weight();
1194  opts["max_num_dir"] = max_num_dir_;
1195  opts["is_diff_in"] = is_diff_in_;
1196  opts["is_diff_out"] = is_diff_out_;
1197  // Wrap the function
1198  std::vector<MX> arg = mx_in();
1199  std::vector<MX> res = self()(arg);
1200  f = Function(name, arg, res, name_in_, name_out_, opts);
1201  // Save in cache
1202  tocache_if_missing(f);
1203  }
1204  return f;
1205  }

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::derivative_of_, casadi::FunctionInternal::Function, casadi::FunctionInternal::incache(), casadi::FunctionInternal::is_diff_in_, casadi::FunctionInternal::is_diff_out_, casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::mx_in(), casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, casadi::FunctionInternal::sp_weight(), and casadi::FunctionInternal::tocache_if_missing().

Referenced by casadi::Function::wrap().

◆ wrap_as_needed() [1/2]

Function casadi::FunctionInternal::wrap_as_needed ( const Dict opts) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lj

Definition at line 1161 of file function_internal.cpp.

1161  {
1162  return wrap_as_needed("wrap_" + name_, opts);
1163  }
Function wrap_as_needed(const std::string &name, const Dict &opts) const
Wrap in an Function instance consisting of only one MX call.

References casadi::ProtoFunction::name_, and casadi::FunctionInternal::wrap_as_needed().

◆ wrap_as_needed() [2/2]

Function casadi::FunctionInternal::wrap_as_needed ( const std::string &  name,
const Dict opts 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_lj

Definition at line 1165 of file function_internal.cpp.

1165  {
1166  if (opts.empty() && name==name_) return shared_from_this<Function>();
1167  // Options
1168  Dict my_opts = opts;
1169  my_opts["derivative_of"] = derivative_of_;
1170  if (my_opts.find("ad_weight")==my_opts.end())
1171  my_opts["ad_weight"] = ad_weight();
1172  if (my_opts.find("ad_weight_sp")==my_opts.end())
1173  my_opts["ad_weight_sp"] = sp_weight();
1174  if (my_opts.find("max_num_dir")==my_opts.end())
1175  my_opts["max_num_dir"] = max_num_dir_;
1176  // Wrap the function
1177  std::vector<MX> arg = mx_in();
1178  std::vector<MX> res = self()(arg);
1179  return Function(name, arg, res, name_in_, name_out_, my_opts);
1180  }

References casadi::FunctionInternal::ad_weight(), casadi::FunctionInternal::derivative_of_, casadi::FunctionInternal::Function, casadi::FunctionInternal::max_num_dir_, casadi::FunctionInternal::mx_in(), casadi::ProtoFunction::name_, casadi::FunctionInternal::name_in_, casadi::FunctionInternal::name_out_, and casadi::FunctionInternal::sp_weight().

Referenced by casadi::Function::wrap_as_needed(), and casadi::FunctionInternal::wrap_as_needed().

Member Data Documentation

◆ abstol_

double casadi::SundialsInterface::abstol_
inherited

◆ ad_weight_

double casadi::FunctionInternal::ad_weight_
inherited

◆ ad_weight_sp_

double casadi::FunctionInternal::ad_weight_sp_
inherited

◆ all_functions_

std::map<std::string, RegFun> casadi::OracleFunction::all_functions_
protectedinherited

◆ always_inline_

bool casadi::FunctionInternal::always_inline_
inherited

◆ always_recalculate_jacobian_

bool casadi::CvodesInterface::always_recalculate_jacobian_

Definition at line 113 of file cvodes_interface.hpp.

Referenced by CvodesInterface(), init(), and serialize_body().

◆ augmented_options_

Dict casadi::Integrator::augmented_options_
inherited

◆ cache_

WeakCache<std::string, Function> casadi::FunctionInternal::cache_
mutableinherited

◆ cache_init_

Dict casadi::FunctionInternal::cache_init_
inherited

◆ checkout_

casadi_checkout_t casadi::FunctionInternal::checkout_
inherited

◆ common_options_

Dict casadi::OracleFunction::common_options_
protectedinherited

◆ compiler_

Importer casadi::FunctionInternal::compiler_
inherited

◆ compiler_plugin_

std::string casadi::FunctionInternal::compiler_plugin_
inherited

◆ custom_jacobian_

Function casadi::FunctionInternal::custom_jacobian_
inherited

◆ decref_

signal_t casadi::FunctionInternal::decref_
inherited

◆ der_options_

Dict casadi::FunctionInternal::der_options_
inherited

◆ derivative_of_

Function casadi::FunctionInternal::derivative_of_
inherited

◆ deserialize_map

std::map< std::string, ProtoFunction *(*)(DeserializingStream &)> casadi::FunctionInternal::deserialize_map
staticinherited
Initial value:
= {
{"MXFunction", MXFunction::deserialize},
{"SXFunction", SXFunction::deserialize},
{"Interpolant", Interpolant::deserialize},
{"Switch", Switch::deserialize},
{"Map", Map::deserialize},
{"MapSum", MapSum::deserialize},
{"Nlpsol", Nlpsol::deserialize},
{"Rootfinder", Rootfinder::deserialize},
{"Integrator", Integrator::deserialize},
{"External", External::deserialize},
{"Conic", Conic::deserialize},
{"FmuFunction", FmuFunction::deserialize},
{"BlazingSplineFunction", BlazingSplineFunction::deserialize},
}
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
void deserialize(DeserializingStream &s, SDPToSOCPMem &m)
Definition: conic.cpp:744
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Definition: external.cpp:508
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize without type information.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Definition: mapsum.cpp:85
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Definition: map.cpp:110
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Definition: nlpsol.cpp:1444
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into a plugin instance (dispatches on the plugin name)
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
Definition: rootfinder.cpp:595
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize without type information.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize without type information.
Definition: switch.hpp:150

Definition at line 1511 of file function_internal.hpp.

Referenced by casadi::FunctionInternal::deserialize().

◆ disable_internal_warnings_

bool casadi::SundialsInterface::disable_internal_warnings_
inherited

◆ dump_

bool casadi::FunctionInternal::dump_
inherited

◆ dump_count_

casadi_int casadi::FunctionInternal::dump_count_
mutableinherited

◆ dump_dir_

std::string casadi::FunctionInternal::dump_dir_
inherited

◆ dump_format_

std::string casadi::FunctionInternal::dump_format_
inherited

◆ dump_in_

bool casadi::FunctionInternal::dump_in_
inherited

◆ dump_out_

bool casadi::FunctionInternal::dump_out_
inherited

◆ enable_fd_

bool casadi::FunctionInternal::enable_fd_
inherited

◆ enable_fd_op_

bool casadi::FunctionInternal::enable_fd_op_
inherited

◆ enable_forward_

bool casadi::FunctionInternal::enable_forward_
inherited

◆ enable_forward_op_

bool casadi::FunctionInternal::enable_forward_op_
inherited

◆ enable_jacobian_

bool casadi::FunctionInternal::enable_jacobian_
inherited

◆ enable_jacobian_op_

bool casadi::FunctionInternal::enable_jacobian_op_
inherited

◆ enable_reverse_

bool casadi::FunctionInternal::enable_reverse_
inherited

◆ enable_reverse_op_

bool casadi::FunctionInternal::enable_reverse_op_
inherited

◆ error_on_fail_

bool casadi::ProtoFunction::error_on_fail_
inherited

◆ eval_

eval_t casadi::FunctionInternal::eval_
inherited

◆ event_acceptable_tol_

double casadi::Integrator::event_acceptable_tol_
inherited

◆ event_tol_

double casadi::Integrator::event_tol_
inherited

◆ fd_method_

std::string casadi::FunctionInternal::fd_method_
inherited

◆ fd_options_

Dict casadi::FunctionInternal::fd_options_
inherited

◆ fd_step_

double casadi::FunctionInternal::fd_step_
inherited

◆ forward_options_

Dict casadi::FunctionInternal::forward_options_
inherited

◆ has_refcount_

bool casadi::FunctionInternal::has_refcount_
inherited

◆ has_refcount_in_deps_

bool casadi::FunctionInternal::has_refcount_in_deps_
inherited

◆ incref_

signal_t casadi::FunctionInternal::incref_
inherited

◆ infix_

const std::string casadi::Integrator::infix_ = "integrator"
staticinherited

Definition at line 456 of file integrator_impl.hpp.

◆ inputs_check_

bool casadi::FunctionInternal::inputs_check_
inherited

◆ interp_

enum casadi::SundialsInterface::InterpType casadi::SundialsInterface::interp_
inherited

◆ is_diff_in_

std::vector<bool> casadi::FunctionInternal::is_diff_in_
inherited

◆ is_diff_out_

std::vector<bool> casadi::FunctionInternal::is_diff_out_
inherited

◆ iter_

casadi_int casadi::CvodesInterface::iter_
protected

Definition at line 188 of file cvodes_interface.hpp.

Referenced by CvodesInterface(), impulseB(), init(), init_mem(), and serialize_body().

◆ jac_penalty_

double casadi::FunctionInternal::jac_penalty_
inherited

◆ jac_sparsity_

std::vector<Sparsity> casadi::FunctionInternal::jac_sparsity_[2]
mutableinherited

◆ jacobian_options_

Dict casadi::FunctionInternal::jacobian_options_
inherited

◆ jit_

bool casadi::FunctionInternal::jit_
inherited

◆ jit_base_name_

std::string casadi::FunctionInternal::jit_base_name_
inherited

◆ jit_cleanup_

bool casadi::FunctionInternal::jit_cleanup_
inherited

◆ jit_directory_

std::string casadi::FunctionInternal::jit_directory_
inherited

◆ jit_name_

std::string casadi::FunctionInternal::jit_name_
inherited

◆ jit_options_

Dict casadi::FunctionInternal::jit_options_
inherited

◆ jit_serialize_

std::string casadi::FunctionInternal::jit_serialize_
inherited

◆ jit_temp_suffix_

bool casadi::FunctionInternal::jit_temp_suffix_
inherited

◆ linear_solver_

std::string casadi::SundialsInterface::linear_solver_
inherited

◆ linear_solver_options_

Dict casadi::SundialsInterface::linear_solver_options_
inherited

◆ linsolF_

Linsol casadi::SundialsInterface::linsolF_
inherited

◆ lmm_

casadi_int casadi::CvodesInterface::lmm_
protected

Definition at line 187 of file cvodes_interface.hpp.

Referenced by CvodesInterface(), impulseB(), init(), init_mem(), and serialize_body().

◆ max_event_iter_

casadi_int casadi::Integrator::max_event_iter_
inherited

◆ max_events_

casadi_int casadi::Integrator::max_events_
inherited

◆ max_io_

casadi_int casadi::FunctionInternal::max_io_
inherited

◆ max_krylov_

casadi_int casadi::SundialsInterface::max_krylov_
inherited

◆ max_multistep_order_

casadi_int casadi::SundialsInterface::max_multistep_order_
inherited

◆ max_num_dir_

casadi_int casadi::FunctionInternal::max_num_dir_
inherited

◆ max_num_steps_

casadi_int casadi::SundialsInterface::max_num_steps_
inherited

◆ max_num_threads_

int casadi::OracleFunction::max_num_threads_
protectedinherited

◆ max_order_

casadi_int casadi::SundialsInterface::max_order_
inherited

◆ max_step_size_

double casadi::SundialsInterface::max_step_size_
inherited

◆ meta_doc

const std::string casadi::CvodesInterface::meta_doc
static

Definition at line 151 of file cvodes_interface.hpp.

Referenced by casadi::casadi_register_integrator_cvodes().

◆ min_step_size_

double casadi::CvodesInterface::min_step_size_

Definition at line 112 of file cvodes_interface.hpp.

Referenced by CvodesInterface(), init(), init_mem(), and serialize_body().

◆ monitor_

std::vector<std::string> casadi::OracleFunction::monitor_
protectedinherited

◆ n_in_

size_t casadi::FunctionInternal::n_in_
inherited

Definition at line 1309 of file function_internal.hpp.

Referenced by casadi::SXFunction::ad_forward(), casadi::Rootfinder::ad_reverse(), casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::FunctionInternal::all_scalar(), casadi::KinsolInterface::bjac(), casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::call_reverse(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::check_arg(), casadi::JitFunction::codegen_body(), casadi::Map::codegen_body(), casadi::OmpMap::codegen_body(), casadi::ThreadMap::codegen_body(), casadi::MapSum::codegen_body(), casadi::MXFunction::codegen_body(), casadi::Switch::codegen_body(), casadi::SXFunction::codegen_body(), casadi::FastNewton::codegen_body(), casadi::ThreadMap::codegen_declarations(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::convert_arg(), casadi::FunctionInternal::definition(), casadi::KinsolInterface::djac(), casadi::FunctionInternal::dm_in(), casadi::FunctionInternal::eval(), casadi::OmpMap::eval(), casadi::MXFunction::eval(), casadi::Switch::eval(), casadi::MXFunction::eval_activity(), casadi::FunctionInternal::eval_gen(), casadi::Map::eval_gen(), casadi::MapSum::eval_gen(), casadi::MXFunction::eval_mx(), casadi::SXFunction::eval_mx(), casadi::Switch::eval_sx(), casadi::SXFunction::export_code_body(), casadi::CallbackInternal::finalize(), casadi::FmuFunction::FmuFunction(), casadi::FunctionInternal::forward(), casadi::KinsolInterface::func(), casadi::FunctionInternal::FunctionInternal(), casadi::FunctionInternal::fwd_seed(), casadi::FunctionInternal::generate_in(), casadi::GenericExternal::get_jac_sparsity(), casadi::GenericExternal::has_jac_sparsity(), casadi::FunctionInternal::init(), casadi::MXFunction::init(), casadi::Switch::init(), casadi::SXFunction::init(), casadi::ImplicitToNlp::init(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::jacobian(), casadi::KinsolInterface::jtimes(), casadi::FunctionInternal::mapsum_mx(), casadi::FunctionInternal::matching_arg(), casadi::FunctionInternal::mx_in(), casadi::FunctionInternal::nnz_in(), casadi::FunctionInternal::numel_in(), casadi::FunctionInternal::nz_in(), casadi::SXFunction::print_arg(), casadi::FunctionInternal::print_dimensions(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::project_arg(), casadi::KinsolInterface::psetup(), casadi::FunctionInternal::reverse(), casadi::FmuFunction::serialize_body(), casadi::FunctionInternal::set_jac_sparsity(), casadi::Rootfinder::set_work(), casadi::QpToNlp::solve(), casadi::KinsolInterface::solve(), casadi::FastNewton::solve(), casadi::ImplicitToNlp::solve(), casadi::Newton::solve(), casadi::FunctionInternal::sp_forward(), casadi::Integrator::sp_forward(), casadi::MXFunction::sp_forward(), casadi::Rootfinder::sp_forward(), casadi::FunctionInternal::sp_reverse(), casadi::Integrator::sp_reverse(), casadi::Map::sp_reverse(), casadi::MapSum::sp_reverse(), casadi::MXFunction::sp_reverse(), casadi::Rootfinder::sp_reverse(), and casadi::FunctionInternal::sx_in().

◆ n_out_

size_t casadi::FunctionInternal::n_out_
inherited

Definition at line 1309 of file function_internal.hpp.

Referenced by casadi::Rootfinder::ad_forward(), casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::Rootfinder::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::FunctionInternal::all_scalar(), casadi::KinsolInterface::bjac(), casadi::FunctionInternal::call(), casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_gen(), casadi::FunctionInternal::call_reverse(), casadi::SXFunction::call_setup(), casadi::FunctionInternal::check_res(), casadi::JitFunction::codegen_body(), casadi::Map::codegen_body(), casadi::OmpMap::codegen_body(), casadi::ThreadMap::codegen_body(), casadi::MapSum::codegen_body(), casadi::MXFunction::codegen_body(), casadi::Switch::codegen_body(), casadi::SXFunction::codegen_body(), casadi::FastNewton::codegen_body(), casadi::ThreadMap::codegen_declarations(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::convert_res(), casadi::FunctionInternal::definition(), casadi::KinsolInterface::djac(), casadi::FunctionInternal::dm_out(), casadi::FunctionInternal::eval(), casadi::OmpMap::eval(), casadi::MXFunction::eval(), casadi::Switch::eval(), casadi::FunctionInternal::eval_activity(), casadi::MXFunction::eval_activity(), casadi::FunctionInternal::eval_gen(), casadi::Map::eval_gen(), casadi::MapSum::eval_gen(), casadi::Switch::eval_sx(), casadi::CallbackInternal::finalize(), casadi::FmuFunction::FmuFunction(), casadi::FunctionInternal::forward(), casadi::KinsolInterface::func(), casadi::FunctionInternal::FunctionInternal(), casadi::FunctionInternal::generate_out(), casadi::LinearInterpolantJac::get_jacobian(), casadi::FunctionInternal::init(), casadi::MapSum::init(), casadi::Nlpsol::init(), casadi::Switch::init(), casadi::FunctionInternal::jac_sparsity(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::mapsum_mx(), casadi::FunctionInternal::matching_res(), casadi::FunctionInternal::mx_out(), casadi::FunctionInternal::nnz_out(), casadi::FunctionInternal::numel_out(), casadi::FunctionInternal::nz_out(), casadi::FunctionInternal::print_dimensions(), casadi::FunctionInternal::print_out(), casadi::KinsolInterface::psetup(), casadi::FunctionInternal::reverse(), casadi::FmuFunction::serialize_body(), casadi::FunctionInternal::set_jac_sparsity(), casadi::Rootfinder::set_work(), casadi::QpToNlp::solve(), casadi::KinsolInterface::solve(), casadi::FastNewton::solve(), casadi::ImplicitToNlp::solve(), casadi::Newton::solve(), casadi::FunctionInternal::sp_forward(), casadi::Integrator::sp_forward(), casadi::MXFunction::sp_forward(), casadi::Rootfinder::sp_forward(), casadi::FunctionInternal::sp_reverse(), casadi::Integrator::sp_reverse(), casadi::Map::sp_reverse(), casadi::MapSum::sp_reverse(), casadi::MXFunction::sp_reverse(), casadi::Rootfinder::sp_reverse(), and casadi::FunctionInternal::sx_out().

◆ nadj_

casadi_int casadi::Integrator::nadj_
inherited

◆ name_

std::string casadi::ProtoFunction::name_
inherited

Definition at line 246 of file function_internal.hpp.

Referenced by casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::Integrator::augmented_dae(), casadi::OracleFunction::calc_function(), casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_reverse(), casadi::FunctionInternal::codegen_body(), casadi::External::codegen_body(), casadi::External::codegen_checkout(), casadi::External::codegen_declarations(), casadi::MXFunction::codegen_declarations(), casadi::SXFunction::codegen_declarations(), casadi::External::codegen_decref(), casadi::External::codegen_incref(), casadi::FunctionInternal::codegen_meta(), casadi::FunctionInternal::codegen_name(), casadi::External::codegen_release(), casadi::FunctionInternal::codegen_sparsities(), casadi::ProtoFunction::construct(), casadi::OracleFunction::create_function(), casadi::FunctionInternal::definition(), casadi::FunctionInternal::eval(), casadi::MXFunction::eval(), casadi::SXFunction::eval(), casadi::FunctionInternal::eval_mx(), casadi::MXFunction::eval_mx(), casadi::SXFunction::eval_mx(), casadi::SXFunction::eval_sx(), casadi::FmuFunction::factory(), casadi::FunctionInternal::finalize(), casadi::FunctionInternal::forward(), casadi::FunctionInternal::FunctionInternal(), casadi::Integrator::get_forward(), casadi::Integrator::get_forward_dae(), casadi::Map::get_function(), casadi::MapSum::get_function(), casadi::OracleFunction::get_function(), casadi::GenericExternal::get_jac_sparsity(), casadi::BlazingSplineFunction::get_jacobian(), casadi::FunctionInternal::get_n_in(), casadi::External::get_n_in(), casadi::FunctionInternal::get_n_out(), casadi::External::get_n_out(), casadi::FunctionInternal::get_name_in(), casadi::External::get_name_in(), casadi::FunctionInternal::get_name_out(), casadi::External::get_name_out(), casadi::FunctionInternal::get_partition(), casadi::Integrator::get_reverse(), casadi::FunctionInternal::get_sparsity_in(), casadi::GenericExternal::get_sparsity_in(), casadi::FunctionInternal::get_sparsity_out(), casadi::GenericExternal::get_sparsity_out(), casadi::FunctionInternal::get_stats(), casadi::External::has_forward(), casadi::GenericExternal::has_jac_sparsity(), casadi::External::has_jacobian(), casadi::External::has_reverse(), casadi::BlazingSplineFunction::init(), casadi::External::init(), casadi::FunctionInternal::init(), casadi::MXFunction::init(), casadi::SXFunction::init(), init(), casadi::IdasInterface::init(), casadi::External::init_external(), casadi::GenericExternal::init_external(), casadi::OnnxRuntimeInterface::init_mem(), casadi::FunctionInternal::jac_is_symm(), casadi::FunctionInternal::jacobian(), casadi::FunctionInternal::map(), casadi::OracleFunction::monitored(), casadi::MXFunction::print_arg(), casadi::SXFunction::print_arg(), casadi::FunctionInternal::print_in(), casadi::FunctionInternal::print_out(), casadi::MXFunction::print_res(), casadi::SXFunction::print_res(), casadi::ProtoFunction::print_time(), casadi::ProtoFunction::ProtoFunction(), reset(), casadi::IdasInterface::reset(), casadi::IdasInterface::resetB(), casadi::FunctionInternal::reverse(), casadi::ProtoFunction::serialize_body(), casadi::GurobiInterface::solve(), casadi::SnoptInterface::solve(), casadi::Integrator::sp_forward(), casadi::Integrator::sp_reverse(), casadi::FunctionInternal::wrap(), and casadi::FunctionInternal::wrap_as_needed().

◆ name_in_

std::vector<std::string> casadi::FunctionInternal::name_in_
inherited

◆ name_out_

std::vector<std::string> casadi::FunctionInternal::name_out_
inherited

◆ ne_

casadi_int casadi::Integrator::ne_
inherited

◆ never_inline_

bool casadi::FunctionInternal::never_inline_
inherited

◆ newton_scheme_

enum casadi::SundialsInterface::NewtonScheme casadi::SundialsInterface::newton_scheme_
inherited

◆ nfwd_

casadi_int casadi::Integrator::nfwd_
inherited

◆ nom_x_

std::vector<double> casadi::Integrator::nom_x_
inherited

◆ nom_z_

std::vector<double> casadi::Integrator::nom_z_
inherited

◆ nonlin_conv_coeff_

double casadi::SundialsInterface::nonlin_conv_coeff_
inherited

◆ np1_

casadi_int casadi::Integrator::np1_
inherited

◆ np_

casadi_int casadi::Integrator::np_
inherited

◆ nq1_

casadi_int casadi::Integrator::nq1_
inherited

◆ nq_

casadi_int casadi::Integrator::nq_
inherited

◆ nrp1_

casadi_int casadi::Integrator::nrp1_
inherited

◆ nrp_

casadi_int casadi::Integrator::nrp_
inherited

◆ nrq1_

casadi_int casadi::Integrator::nrq1_
inherited

◆ nrq_

casadi_int casadi::Integrator::nrq_
inherited

◆ nrx1_

casadi_int casadi::Integrator::nrx1_
inherited

◆ nrx_

casadi_int casadi::Integrator::nrx_
inherited

◆ nrz1_

casadi_int casadi::Integrator::nrz1_
inherited

◆ nrz_

casadi_int casadi::Integrator::nrz_
inherited

◆ ntmp_

casadi_int casadi::Integrator::ntmp_
inherited

◆ nu1_

casadi_int casadi::Integrator::nu1_
inherited

◆ nu_

casadi_int casadi::Integrator::nu_
inherited

◆ nuq1_

casadi_int casadi::Integrator::nuq1_
inherited

◆ nuq_

casadi_int casadi::Integrator::nuq_
inherited

◆ nx1_

casadi_int casadi::Integrator::nx1_
inherited

◆ nx_

casadi_int casadi::Integrator::nx_
inherited

◆ nz1_

casadi_int casadi::Integrator::nz1_
inherited

◆ nz_

casadi_int casadi::Integrator::nz_
inherited

◆ options_

const Options casadi::CvodesInterface::options_
static
Initial value:
{{"linear_multistep_method",
"Integrator scheme: BDF|adams"}},
{"nonlinear_solver_iteration",
"Nonlinear solver type: NEWTON|functional"}},
{"min_step_size",
"Min step size [default: 0/0.0]"}},
{"fsens_all_at_once",
"Calculate all right hand sides of the sensitivity equations at once"}},
{"always_recalculate_jacobian",
"Recalculate Jacobian before factorizations, even if Jacobian is current [default: true]"}}
}
}
static const Options options_
Options.

Definition at line 110 of file cvodes_interface.hpp.

Referenced by casadi::casadi_register_integrator_cvodes().

◆ opts_

Dict casadi::Integrator::opts_
inherited

◆ oracle_

Function casadi::OracleFunction::oracle_
protectedinherited

◆ post_expand_

bool casadi::OracleFunction::post_expand_
protectedinherited

◆ print_canonical_

bool casadi::FunctionInternal::print_canonical_
inherited

◆ print_in_

bool casadi::FunctionInternal::print_in_
inherited

◆ print_out_

bool casadi::FunctionInternal::print_out_
inherited

◆ print_stats_

bool casadi::Integrator::print_stats_
inherited

◆ print_time_

bool casadi::ProtoFunction::print_time_
inherited

◆ quad_err_con_

bool casadi::SundialsInterface::quad_err_con_
inherited

◆ rdae_

Function casadi::Integrator::rdae_
inherited

◆ record_time_

bool casadi::ProtoFunction::record_time_
inherited

◆ registered_functions_

std::vector<Function> casadi::FunctionInternal::registered_functions_
inherited

◆ regularity_check_

bool casadi::ProtoFunction::regularity_check_
inherited

◆ release_

casadi_release_t casadi::FunctionInternal::release_
inherited

◆ reltol_

double casadi::SundialsInterface::reltol_
inherited

◆ reverse_options_

Dict casadi::FunctionInternal::reverse_options_
inherited

◆ scale_abstol_

bool casadi::SundialsInterface::scale_abstol_
inherited

◆ second_order_correction_

bool casadi::SundialsInterface::second_order_correction_
inherited

◆ show_eval_warnings_

bool casadi::OracleFunction::show_eval_warnings_
protectedinherited

◆ solvers_

std::map< std::string, Integrator::Plugin > casadi::Integrator::solvers_
staticinherited

Definition at line 449 of file integrator_impl.hpp.

◆ sp_jac_dae_

Sparsity casadi::Integrator::sp_jac_dae_
inherited

◆ sp_jac_rdae_

Sparsity casadi::Integrator::sp_jac_rdae_
inherited

◆ sparsity_in_

std::vector<Sparsity> casadi::FunctionInternal::sparsity_in_
inherited

◆ sparsity_out_

std::vector<Sparsity> casadi::FunctionInternal::sparsity_out_
inherited

◆ specific_options_

Dict casadi::OracleFunction::specific_options_
protectedinherited

◆ stats_

Dict casadi::FunctionInternal::stats_
inherited

◆ step0_

double casadi::SundialsInterface::step0_
inherited

◆ steps_per_checkpoint_

casadi_int casadi::SundialsInterface::steps_per_checkpoint_
inherited

◆ stop_at_end_

bool casadi::SundialsInterface::stop_at_end_
inherited

◆ stride_arg_

size_t casadi::OracleFunction::stride_arg_
protectedinherited

◆ stride_iw_

size_t casadi::OracleFunction::stride_iw_
protectedinherited

◆ stride_res_

size_t casadi::OracleFunction::stride_res_
protectedinherited

◆ stride_w_

size_t casadi::OracleFunction::stride_w_
protectedinherited

◆ t0_

double casadi::Integrator::t0_
inherited

◆ tout_

std::vector<double> casadi::Integrator::tout_
inherited

◆ transition_

Function casadi::Integrator::transition_
inherited

◆ use_precon_

bool casadi::SundialsInterface::use_precon_
inherited

◆ user_data_

void* casadi::FunctionInternal::user_data_
inherited

◆ verbose_

bool casadi::ProtoFunction::verbose_
inherited

Definition at line 249 of file function_internal.hpp.

Referenced by casadi::MXFunction::ad_forward(), casadi::SXFunction::ad_forward(), casadi::MXFunction::ad_reverse(), casadi::SXFunction::ad_reverse(), casadi::Integrator::advance(), casadi::ProtoFunction::change_option(), casadi::BSplineInterpolant::construct_graph(), casadi::OracleFunction::create_function(), casadi::Integrator::eval(), casadi::MXFunction::eval(), casadi::SXFunction::eval(), casadi::MXFunction::eval_mx(), casadi::SXFunction::eval_mx(), casadi::SXFunction::eval_sx(), casadi::FmuFunction::factory(), casadi::FunctionInternal::finalize(), casadi::KinsolInterface::func(), casadi::CodeGenerator::generate_dump(), casadi::ProtoFunction::generate_options(), casadi::FmuFunction::get_forward(), casadi::Integrator::get_forward(), casadi::Integrator::get_forward_dae(), casadi::FunctionInternal::get_jac_sparsity_gen(), casadi::FunctionInternal::get_jac_sparsity_hierarchical(), casadi::FunctionInternal::get_jac_sparsity_hierarchical_symm(), casadi::FmuFunction::get_jacobian(), casadi::FunctionInternal::get_partition(), casadi::FmuFunction::get_reverse(), casadi::Integrator::get_reverse(), casadi::ProtoFunction::init(), casadi::FiniteDiff::init(), casadi::FmuFunction::init(), casadi::FunctionInternal::init(), casadi::MXFunction::init(), casadi::SXFunction::init(), casadi::Blocksqp::init(), casadi::MadmpecInterface::init(), casadi::FatropConicInterface::init(), casadi::FatropInterface::init(), casadi::HpipmInterface::init(), casadi::HpmpcInterface::init(), casadi::IpoptInterface::init(), casadi::MadnlpInterface::init(), init(), casadi::IdasInterface::init(), casadi::Feasiblesqpmethod::init(), casadi::Scpgen::init(), casadi::Sqpmethod::init(), casadi::IpoptInterface::init_mem(), casadi::MosekInterface::init_mem(), casadi::IdasInterface::init_mem(), casadi::UnoInterface::init_mem(), casadi::SXFunction::instructions_sx(), casadi::BonminInterface::intermediate_callback(), casadi::OracleFunction::jit_dependencies(), casadi::CsparseInterface::nfact(), casadi::LapackLu::nfact(), casadi::LapackQr::nfact(), casadi::LinsolQr::nfact(), casadi::Integrator::predict_events(), casadi::ProtoFunction::ProtoFunction(), reset(), casadi::IdasInterface::reset(), casadi::IdasInterface::resetB(), casadi::ProtoFunction::serialize_body(), casadi::CbcInterface::solve(), casadi::ClpInterface::solve(), casadi::CplexInterface::solve(), casadi::GurobiInterface::solve(), casadi::HpipmInterface::solve(), casadi::QpoasesInterface::solve(), casadi::Ipqp::solve(), casadi::Qrqp::solve(), casadi::AlpaqaInterface::solve(), casadi::AmplInterface::solve(), casadi::SnoptInterface::solve(), casadi::KinsolInterface::solve(), casadi::WorhpInterface::solve(), casadi::Newton::solve(), casadi::Qrsqp::solve(), casadi::Scpgen::solve(), casadi::Sqpmethod::solve(), casadi::Sqpmethod::solve_ela_QP(), casadi::Feasiblesqpmethod::solve_LP(), casadi::Feasiblesqpmethod::solve_QP(), casadi::Qrsqp::solve_QP(), casadi::Sqpmethod::solve_QP(), casadi::Integrator::sp_forward(), casadi::Integrator::sp_reverse(), and casadi::Integrator::trigger_event().


The documentation for this class was generated from the following files: