On obtaining time values for specific conditions

Please login with a confirmed email address before reporting spam

If I want to get the moment when a certain condition is triggered (e.g. the time when the pressure P>1MPa), what statement should I use; Or I thought about using if(P>1MPa, assign the time t, other) or something like that, but assuming that P>1MPa will continue to rise for a short period of time, then the “time t” will keep changing, and I won't be able to get the first time P>1MPa, is there any way to make the if statement only execute once and then exit, so that the t that I get won't change? Is there any way to make the if statement execute only once and exit so that the t I get will not change?


2 Replies Last Post 2024年5月22日 GMT-4 00:47
Henrik Sönnerlind COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 4 weeks ago 2024年5月21日 GMT-4 05:28
Updated: 4 weeks ago 2024年5月22日 GMT-4 02:34

There are two different ways in which I interpret your question:

a) Store the first time at which p exceeds 1 MPa anywhere.
b) For every point in space, store the time at which 1 MPa is exceeded at that point

Both are doable. In either case, the idea is to use a variable which is originally initialized to zero (which would be the default). Then you set it, using an expression of the type

if variable = 0 AND p > 1 MPa
variable = t
else
variable = variable

You will get the time of the first time step at which the reference value is exceeded, which is more or less later than the true time, depending on your time step. There are more sophisticated variants of this scheme which would make an interpolation possible. Then, you would have to use more than one auxiliary variable.

For case a) above, the Events interface can also be useful.

-------------------
Henrik Sönnerlind
COMSOL
There are two different ways in which I interpret your question: a) Store the first time at which p exceeds 1 MPa anywhere. b) For every point in space, store the time at which 1 MPa is exceeded at that point Both are doable. In either case, the idea is to use a variable which is originally initialized to zero (which would be the default). Then you set it, using an expression of the type if variable = 0 AND p > 1 MPa variable = t else variable = variable You will get the time of the first time step at which the reference value is exceeded, which is more or less later than the true time, depending on your time step. There are more sophisticated variants of this scheme which would make an interpolation possible. Then, you would have to use more than one auxiliary variable. For case a) above, the Events interface can also be useful.

Please login with a confirmed email address before reporting spam

Posted: 4 weeks ago 2024年5月22日 GMT-4 00:47

There are two different ways in which I interpret your question:

a) Store the first time at which p exceeds 1 MPa anywhere.
b) For every point in space, store the time at which 1 MPa is exceeded at that point

Both are doable. In either case, the idea is to use a variable which is originally initialized to zero (which would be the default). Then you set it, using an expression of the type

if variable = 0 AND p > 1 MPa
variable = t
else
variable = variable

You will get the time of the first time step at which the reference value is exceeded, which is more or less later than the true time, depending on your time step. There are more sophisticated variants of this scheme which would make an interpolation possible. The, you would have to use more than one auxiliary variable.

For case a) above, the Events interface can also be useful.

I understood what you meant and managed to get the time I wanted through your method, thank you very much!

>There are two different ways in which I interpret your question: > >a) Store the first time at which p exceeds 1 MPa anywhere. >b) For every point in space, store the time at which 1 MPa is exceeded at that point > >Both are doable. In either case, the idea is to use a variable which is originally initialized to zero (which would be the default). Then you set it, using an expression of the type > >if variable = 0 AND p > 1 MPa > variable = t >else > variable = variable > >You will get the time of the first time step at which the reference value is exceeded, which is more or less later than the true time, depending on your time step. There are more sophisticated variants of this scheme which would make an interpolation possible. The, you would have to use more than one auxiliary variable. > >For case a) above, the Events interface can also be useful. I understood what you meant and managed to get the time I wanted through your method, thank you very much!

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.