question

Axel Kohonen avatar image
0 Likes"
Axel Kohonen asked Matt Long commented

Run process flow on model reset

Hi,

I would like to initialize my model by running a Process flow on model reset. Is this possible somehow?

It works nicely when I run the process flow at time zero, but then the user cannot see what happens at reset until he runs the model.

I tried calling createtoken in the onModelReset trigger and it creates a token into the process flow. But immediately as the onModelReset code ends the token disappears. See the attached executeprocessflowonmodelreset-170.fsm model.

Any hints on how/if this can be achieved?

Thank you!

Kind regards,

Axel

FlexSim 17.0.3
process flowonmodelreset
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Matt Long avatar image
4 Likes"
Matt Long answered Matt Long commented

Do not run Process Flow on reset.

We specifically removed the OnReset event from Event-Triggered Source as it can cause serious issues having tokens in your model at reset.

If you choose to do so, you do so at your own risk.

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Axel Kohonen avatar image Axel Kohonen commented ·

Hi @Matt Long

Thank you for that information!

How is it then generally with creating operators/timetables after reset? Is it a bad idea? I previously created operators and timetables in the onModelReset code using custom coding and it worked nicely, but it would be easier and more clear to use process flow. At least one problem that I get when creating operators after reset is that I have to manually open the input of the operators or else they will not receive tasks. Also, when generating operators after reset their FlexScript nodes are not built either. I did not see any difference due to them not being built, but I build them just to make sure.

If it does not cause problems to create operators & timetables after reset at time zero then find the attached and simplified solution executeprocessflowonmodelreset-170-runmodelshortti.fsm to my problem where I use a normal process flow that starts at time zero to create a box. To make it look like the box is created at reset I add

//set stoptime
stoptime(0.01);
//start simulation
go();

to the end of the onModelReset trigger. So practically I run the model a little bit forward (the time can be made very short) from model reset. In some cases this might not be desirable, but in most models it is ok to do.

But is this a good approach?

Thank you!

Kind regards,

Axel

1 Like 1 ·
Matt Long avatar image Matt Long Axel Kohonen commented ·

The issue really comes down to having tokens in your model at reset. I don't know if we ever discovered why it creates such problems, but it does. Haven't played around much with having a token be created at reset and destroyed before reset is finished (completing all of it's logic in one stack).

But the general rule would be to perform whatever logic and create whatever objects you need to at time 0. This can easily be accomplished by using a Scheduled Source that creates one token at time 0. You can use Create Object activities to create your Operators, or of course you can tie an Operator to a Resource and then up its resource count to copy the operator.

As for setting the stop time, that would definitely work as well. You could even make that number smaller if needed.

0 Likes 0 ·
Mischa Spelt avatar image
2 Likes"
Mischa Spelt answered

If your process flow is "instantaneous", _i.e._ doesn't have activities like Delay, you could try calling executesubflow from the Model Reset trigger. However this is probably not the intended use of executesubflows and a there are probably a thousand ways that this may break.

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Axel Kohonen avatar image Axel Kohonen commented ·

Hi @Mischa Spelt,

I actually got it to work with executesubflow. The problem was that I had "Destroy Objects" activities in the process flow with the asynchronous setting on. This causes a zero second delay due to which the executesubflow did not work.

However, the solution is not perfect, as one cannot debug it with process flow. But I can of course debug it first with a normal Schedule source and when it works I can change it to run with executesubflow.

Is it even possible to run a process flow with delays on model reset? It seems that everything on reset has to happen in zero time for it to be on reset. Am I right?

And I am still curios about why the createtoken approach does not work. I would be happy if someone can answer that.

Thank you!

Axel

0 Likes 0 ·
Sam Stubbs avatar image Sam Stubbs ♦ Axel Kohonen commented ·

From what I understand, just creating a token will place the token in the Process Flow, but there is nothing telling the Process Flow to execute. Process Flow will run if the model is running, but if the model is stopped, the Process Flow is stopped as well. (That's why you can "step" through Process Flow Activities)

As Mischa showed, if you call the executesubflow command, that command specifically tells the Process Flow to execute.

1 Like 1 ·