discipline velocity potential Velocity; enddiscipline discipline position potential Position; enddiscipline module bouncing_ball(); parameter real init_pos=10.0 from (0:inf), // initial position of ball in m g=9.81 from (0:inf), // gravitational accelaration c onst air_res=0.1 from (0:inf); // air resistance velocity v; position p; integer mode; `define revers 1 `define normal 0 analog begin mode = `normal; // using the cross function to detect if Pos(p) has been fallen to zero // this will controll the time step, so that zero +- abstol is detected // accuracy of the resolution is controlled by the Position nature // accuracy can be tied by cross opt_args too @(cross(Pos(p),-1)) begin discontinuity(0); // for velocity, 1st order for position mode = `revers; end if (Vel(v) > 0.0) af = -g - pow(Vel(v),2)*air_res; else af = -g + pow(Vel(v),2)*air_res; // use -Vel(v) at Pos(p) = 0 Vel(v) <+ idt(af,-Vel(v),mode); // initial values for position are supplied as parameter and // used for initial value of the integral during dc analysis Pos(p) <+ idt(Vel(v),init_pos,analysis("static")); end endmodule