void operator() (const state_type x, state_type& dxdt, double t) { // for input voltage, model a step function at time zero double Va = 0; if (t > 0.0) { Va = vin_; } Matrix<double, 1, 1> u; u << Va; // All other node voltages are determined by odeint through our equations: Map<const Matrix<double, 2, 1> > xvec(x.data()); Map<Matrix<double, 2, 1> > result(dxdt.data()); result = coeff_ * xvec + input_ * u; }
// utility function for displaying data. Applies internal matrices to state std::vector<double> state2output(state_type const& x) { std::vector<double> result(2); Map<const Matrix<double, states, 1> > xvec(x.data()); Map<Matrix<double, 3, 1> > ovec(result.data()); ovec = Lred_.transpose() * xvec; // in theory the input could be involved via Dred_ return result; }
void operator() (const state_type x, state_type& dxdt, double t) { // determine input voltages double Vagg = (agg_slew_ < 0) ? v_ : 0; // initial value if (agg_slew_ == 0) { Vagg = 0.0; // quiescent } else { // find the "real" ramp starting point, since we use the center of the swing double transition_time = ( v_ / fabs(agg_slew_) ) / 2.0; double real_start = agg_start_ - transition_time; double real_end = agg_start_ + transition_time; if (t >= real_end) { Vagg = (agg_slew_ < 0) ? 0 : v_; // straight to final value } else if (t <= real_start) { Vagg = (agg_slew_ > 0) ? 0 : v_; // remain at initial value } else { Vagg += agg_slew_ * (t - real_start); // proportional to time in ramp } } // same for the victim driver double Vvic = (vic_slew_ < 0) ? v_ : 0; // initial value if (vic_slew_ == 0) { Vvic = 0.0; } else { // find the "real" ramp starting point, since we use the center of the swing double transition_time = ( v_ / fabs(vic_slew_) ) / 2.0; double real_start = vic_start_ - transition_time; double real_end = vic_start_ + transition_time; if (t >= real_end) { Vvic = (vic_slew_ < 0) ? 0 : v_; // straight to final value } else if (t <= real_start) { Vvic = (vic_slew_ > 0) ? 0 : v_; // remain at initial value } else { Vvic += vic_slew_ * (t - real_start); // proportional to time in ramp } } Map<const Matrix<double, states, 1> > xvec(x.data()); // turn state vector into Eigen matrix Matrix<double, 2, 1> u; u << Vagg, Vvic; // input excitation Map<Matrix<double, states, 1> > result(dxdt.data()); result = coeff_ * xvec + input_ * u; // sets dxdt via reference }
// utility function for displaying data. Applies internal matrices to state std::vector<double> state2output(state_type const& x, std::vector<double> const& in) { std::vector<double> result(3); Map<const Vector2d> xvec(x.data()); Map<const Matrix<double, 1, 1> > invec(in.data()); Map<Matrix<double, 3, 1> > ovec(result.data()); ovec = Lred_.transpose() * xvec + Dred_ * invec; return result; }