Run a model for a few cycles

Moderators: Frank, paul, Hiwot, Chris, peter

Post Reply
Buck
Posts: 15
Joined: Fri May 04, 2007 12:16 pm

Run a model for a few cycles

Post by Buck » Wed May 30, 2007 12:07 pm

I am working on 20-Sim to simulate an aircraft and there is something I need to do but I am not sure that 20-Sim can handle it.

What I would like to do is being able to run the model for a given number of cycles let say 5 cycles to evaluate some variables. Is it possible ? I have seen in the "Help" about the "timevent" function but as I do not know how much time is required for one cycle it is not very convenient.

This code should also be executed before any other code. Does the "initial conditions" section fit as I also want to run the model for a few cycles as written before.

More questions may arise later on according to your answer but these both points are the crucial ones.

Thank you a lot for your answer.

Buck
Posts: 15
Joined: Fri May 04, 2007 12:16 pm

Post by Buck » Mon Jun 04, 2007 9:30 am

I have finally found the 'stepsize' variable which allow to know the time taken into account for integrating.

Is it possible to apply a step to one input of a system for 5*stepsize, then evaluate some variables, then apply a step to another input for 5*stepsize and so on ?

I am not sure about how the 'timeevent' function works. Does it allow to check when a given time is elapsed and start some calculations at that time ?
Is the following code okay ?

Code: Select all

code
    y = timeevent(5*stepsize);
    if y then
        ..............
    end if

Thank you a lot for any answer.

paul
Posts: 152
Joined: Mon Sep 19, 2005 2:00 pm
Location: Controllab Products B.V.

Post by paul » Sat Jun 16, 2007 1:04 pm

Sorry for the very late response, somehow the automatic email of forum posts does not seem to work anymore.
Buck wrote:I have finally found the 'stepsize' variable which allow to know the time taken into account for integrating.

Is it possible to apply a step to one input of a system for 5*stepsize, then evaluate some variables, then apply a step to another input for 5*stepsize and so on ?
Yes you can, but probably only for fixed-step integration methods. Otherwise the stepsize variabel will change due to the change in input value. Did you also find the major keyword? It is a boolean that is false on intermediate model computations of the integration method. For instance, RK4 has 3 intermediate (minor) calculations, and one final (major) calculation.

For your information, with the stepsize keyword and a fixed integration scheme you can create an impulse function as well:
output = (1 / stepsize) * (step (t_start) - step (t_start + stepsize));

20-sim 4.0 will have an impulse function build in that also has a minimum stepsize, so variable step integration methods will work as well.
Buck wrote: I am not sure about how the 'timeevent' function works. Does it allow to check when a given time is elapsed and start some calculations at that time ?
Is the following code okay ?

Code: Select all

code
    y = timeevent(5*stepsize);
    if y then
        ..............
    end if
Yes, that code works, but only once. The timeevent function, like all event functions, triggers the integration method to compute the model just before the event and just after the event. This is done for 2 reasons: numerical accuracy (events are not missed due to possible large integration steps), and switching behavior based on the boolean event result.

Use a timeevent if you know the moment in time something happens, use a event if this is uncertain (for instance if it depends on a state value). There is also a frequencyevent that allows for timeevents on a frequency basis, instead of a given moment in time.

A tip is to put logical code in one submodel and use the code keyword for this like you already did (since it is often sorted, sequential, procedure like code). Put the integration and physical stuff that may depend on the logical state in another submodel and use the equations keyword there (since these are often relations that may / need reshaping and sorting).
member 20-sim development team

Post Reply