Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

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 22 mai 2024, 00:47 UTC−4
Henrik Sönnerlind COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 months ago 21 mai 2024, 05:28 UTC−4
Updated: 6 months ago 22 mai 2024, 02:34 UTC−4

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: 6 months ago 22 mai 2024, 00:47 UTC−4

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!

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.