How to store final time of simulation in a variable ?

Please login with a confirmed email address before reporting spam

I'm chaining two time-dependent simulations, the first one finishing on a stop condition and yielding the solution, say 'sol 1'.

I know how to create and start a new simulation starting from the final state of the latter.

What I don't manage to do is to record the value of the last time of simulation 1 and use it as the starting time of simulation 2. I've tried do define a variable tlast1 with the expression :

withsol( 'sol1', t, setind(t, 'last') )

It yields the correct value of final time, but repeated at each output time of 'sol1'. Thus, no surprise that when I try to use this quantity as the starting time of the second simulation, I get the error :

Unknown model parameter. - Parameter: tlast1 - Property: tlist (Output times) - Time dependent: Time Dependent

because tlast1 is not a scalar (by the way, why ?)

I've been deeply through the documentation and can't manage to find a way to do that. If anyone can help, thank you very much by advance.


3 Replies Last Post 18.03.2024, 15:14 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 5 months ago 09.12.2023, 05:48 GMT-5

Sorry, I forgot to join a basic MPH file reproducing the problem. Here it is.

Sorry, I forgot to join a basic MPH file reproducing the problem. Here it is.


Please login with a confirmed email address before reporting spam

Posted: 1 month ago 18.03.2024, 14:27 GMT-4
Updated: 1 month ago 18.03.2024, 14:20 GMT-4

Hi Olivier,

Did you mamage to solve this problem? I am facing similar situation.

Thank you!

Hi Olivier, Did you mamage to solve this problem? I am facing similar situation. Thank you!

Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 1 month ago 18.03.2024, 15:14 GMT-4

Olivier,

your issue is that the time list in the time dependent study is not accepting variables, only parameters. This is for a reason because variables might produce cumbersome conditions for a solver. A workaround might be to run a model method at the end of study 1 that sets a parameter in the parameter list to the tlast1 value and you can use this parameter then in study 2. I never did that by myself in such a case but I think it should be feasible. I successfully did write methods that create and set parameters for other purposes, e.g. geometry where variables can't be used as well.

Cheers Edgar

-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Olivier, your issue is that the time list in the time dependent study is not accepting variables, only parameters. This is for a reason because variables might produce cumbersome conditions for a solver. A workaround might be to run a model method at the end of study 1 that sets a parameter in the parameter list to the tlast1 value and you can use this parameter then in study 2. I never did that by myself in such a case but I think it should be feasible. I successfully did write methods that create and set parameters for other purposes, e.g. geometry where variables can't be used as well. Cheers Edgar

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.