General Commands > About General Commands > model.solverEvent()

model.solverEvent()
Create and define events for the solver.
Syntax
model.solverEvent().create(<tag>,evtype);
model.solverEvent(<tag>).start(expr);
model.solverEvent(<tag>).start();
model.solverEvent(<tag>).period(expr);
model.solverEvent(<tag>).period();
model.solverEvent(<tag>).condition(expr);
model.solverEvent(<tag>).condition();
model.solverEvent(<tag>).reinit();
model.solverEvent(<tag>).reinit().create(<tag>);
model.solverEvent(<tag>).reinit(<tag>).set(<var>,expr);
Description
Create events and control event settings. There are two types of events; Explicit and Implicit.
model.solverEvent().create(<tag>,evtype) creates a new event of type evtype, either Explicit and Implicit.
Explicit Events
Explicit events triggers on a predefined timing.
model.solverEvent(<tag>).start(expr) sets the start time for an explicit event.
model.solverEvent(<tag>).period(expr) sets the period for an explicit event. After the start time, the event then triggers after each period.
Implicit Events
Implicit events trigger when a condition goes from false to true.
model.solverEvent(<tag>).condition(expr) sets the condition for an implicit event.
Re-Initialization
When an event is triggered, any degree of freedom can be re-initialized. This typically means that they get a new value. You specify these values with a re-initialization method, reinit(...), which has the same syntax as model.init(...) .
model.solverEvent(<tag>).reinit().create(<tag>) adds a new reinit feature to the event. In most cases you only need one, but you need more when you have reinitialization conditions on several geometric entity levels, for example on a global selection and a domain selection.
Event State Variables
An event needs state variables in most cases. There are discrete states and indicator states. Discrete states are just ODE states that only change during re-initialization, and can only have a zero-valued equation (or no equation). The indicator states are needed for implicit events and are ODE states with nonzero equations.
model.ode().create(<tag>).type(<ode type>) creates a new global equation that contains event state variables if you set the ode type to discrete for discrete states and quadrature for indicator states.
model.ode(<tag>).state(<states>) adds a new discrete states to the global equation.
model.ode(<tag>).ode(<state>,"sin(2*pi*t)") adds a new indicator state and its right-hand side to the global equation. The left-hand side of the equation is the state variable, so the full equation for the indicator state becomes nojac(sin(2*pi*t))-<state>.
Example
Example of an idealized bouncing ball using implicit events.
Code for use with Java
Model model = ModelUtil.create("Model");
model.study().create("std1");
model.study("std1").create("time1", "Transient");
model.study("std1").feature("time1").set("tlist", "0 10");
model.study("std1").feature("time1").set("rtol", 1e-6);// Nondiscrete states
model.ode().create("ode1");
model.ode("ode1").ode("y", "-2*y-ytt");
model.init().create("ode1");
model.init("ode1").selection().global();
model.init("ode1").set("y", "1");
// Discrete states
model.ode().create("ode2").type("quadrature");
model.ode("ode2").ode("z1", "y");
// Implicit event
model.solverEvent().create("impl1", "Implicit");
model.solverEvent("impl1").condition("!(z1>=0)");
model.solverEvent("impl1").reinit().create("reinit");
model.solverEvent("impl1").reinit("reinit").selection().global();
model.solverEvent("impl1").reinit("reinit").set("y", "y");
// Bounce reverts velocity
model.solverEvent("impl1").reinit("reinit").set("yt", "-yt");
model.sol().create("sol1");
model.sol("sol1").createAutoSequence("std1");
// Special solver settings for events
model.sol("sol1").feature("t1").set("tout", "tsteps");
model.sol("sol1").feature("t1").set("atolglobal", "1e-6");
model.sol("sol1").feature("t1").set("initialstepbdfactive", "on");
model.sol("sol1").feature("t1").set("initialstepbdf", "1e-6");
model.sol("sol1").feature("t1").set("eventtol", "2e-6");
model.sol("sol1").feature("t1").set("ewtrescale", "off");
model.sol("sol1").runAll();
Code for use with MATLAB
model = ModelUtil.create('Model');
model.study.create('std1');
model.study('std1').create('time1', 'Transient');
model.study('std1').feature('time1').set('tlist', '0 10');
model.study('std1').feature('time1').set('rtol', 1e-6);
% Nondiscrete states
model.ode.create('ode1');
model.ode('ode1').ode('y', '-2*y-ytt');
model.init.create('ode1');
model.init('ode1').selection().global();
model.init('ode1').set('y', '1');
% Discrete states
model.ode.create('ode2').type('quadrature');
model.ode('ode2').ode('z1', 'y');
% Implicit event
model.solverEvent.create('impl1', 'Implicit');
model.solverEvent('impl1').condition('!(z1>=0)');
model.solverEvent('impl1').reinit().create('reinit');
model.solverEvent('impl1').reinit('reinit').selection().global();
model.solverEvent('impl1').reinit('reinit').set('y', 'y');
% Bounce reverts velocity
model.solverEvent('impl1').reinit('reinit').set('yt', '-yt');
model.sol().create('sol1');
model.sol('sol1').createAutoSequence('std1');
% Special solver settings for events
model.sol('sol1').feature('t1').set('tout', 'tsteps');
model.sol('sol1').feature('t1').set('atolglobal', '1e-6');
model.sol('sol1').feature('t1').set('initialstepbdfactive', 'on');
model.sol('sol1').feature('t1').set('initialstepbdf', '1e-6');
model.sol('sol1').feature('t1').set('eventtol', '2e-6');
model.sol('sol1').feature('t1').set('ewtrescale', 'off');
model.sol('sol1').runAll;
See Also
model.ode(), model.init()