Hi,
just one short question: Is there any such thing as a select, if-elseif or nested if-else control structure in MATC?
The manual says that there is only if-else, without mentioning a nesting possibility.
Thanks,
Matthias
MATC: if-elseif or select?
Re: MATC: if-elseif or select?
I believe there's only if-else, but you can nest them. I've used the following as an enthalpy definition, it seems to work as expected. (note most of those except tx are MATC variables defined eariler in the sif file, tx is the temperature variable).
Also, in case anyone wonders, as an enthalpy formula this uses a simple linear equation for the final else state, which would be much more efficiently set just using a lookup table.
I'm not sure how line splitting works for MATC within a sif file, that would make it more legible for complex structures. someone else may want to comment on that.
Code: Select all
Enthalpy = Variable Temperature
MATC "if (tx<=T1) (cpvs*tx); else if (tx>=T2) ((tx-Tm)*cpvl+Tm*cpvs+Lh); else (P1*tx+P0);"
I'm not sure how line splitting works for MATC within a sif file, that would make it more legible for complex structures. someone else may want to comment on that.
Re: MATC: if-elseif or select?
Thank you!
-
- Posts: 4
- Joined: 09 Feb 2018, 23:27
- Antispam: Yes
Re: MATC: if-elseif or select?
Hi,
I realize I'm resurfacing a pretty old thread, but this has been a huge help for me, so maybe there is still someone around who can answer this!
Within MATC if statements, is there a way to set greater than and less than bounds in the same expression?
Say my tx is a Variable Coordinate from 0 to 10, and I want a value applied from 2 to 8 (and a different value from 0-2 and 8-10).
I've tried: Real MATC "if (2 < tx < 8) 0.01; else 1.0"
And: Real MATC "if ((tx+2) < 8) 0.01; else 1.0"
But nothing seems to work. Is there something I can do with &, or some other creative way to go about it?
Thank you!
Kate
I realize I'm resurfacing a pretty old thread, but this has been a huge help for me, so maybe there is still someone around who can answer this!
Within MATC if statements, is there a way to set greater than and less than bounds in the same expression?
Say my tx is a Variable Coordinate from 0 to 10, and I want a value applied from 2 to 8 (and a different value from 0-2 and 8-10).
I've tried: Real MATC "if (2 < tx < 8) 0.01; else 1.0"
And: Real MATC "if ((tx+2) < 8) 0.01; else 1.0"
But nothing seems to work. Is there something I can do with &, or some other creative way to go about it?
Thank you!
Kate
-
- Posts: 2355
- Joined: 25 Jan 2019, 01:28
- Antispam: Yes
Re: MATC: if-elseif or select?
check out MATC general flow control structures
in the MATC manual
http://www.nic.funet.fi/pub/sci/physics/elmer/doc/
in the MATC manual
http://www.nic.funet.fi/pub/sci/physics/elmer/doc/
-
- Posts: 2355
- Joined: 25 Jan 2019, 01:28
- Antispam: Yes
Re: MATC: if-elseif or select?
"Say my tx is a Variable Coordinate from 0 to 10, and I want a value applied from 2 to 8 (and a different value from 0-2 and 8-10).
I've tried: Real MATC "if (2 < tx < 8) 0.01; else 1.0"
And: Real MATC "if ((tx+2) < 8) 0.01; else 1.0"
In general you would have to nest several if statements that overwrite the values
If tx < 2 then tx = .01
if tx >= 2 then tx = 1.0
if tx < 8 then tx = .01
if tx >= 8 then tx = 1.0
basically you over write the variable with each if statement
Kevin
I've tried: Real MATC "if (2 < tx < 8) 0.01; else 1.0"
And: Real MATC "if ((tx+2) < 8) 0.01; else 1.0"
In general you would have to nest several if statements that overwrite the values
If tx < 2 then tx = .01
if tx >= 2 then tx = 1.0
if tx < 8 then tx = .01
if tx >= 8 then tx = 1.0
basically you over write the variable with each if statement
Kevin
-
- Posts: 2355
- Joined: 25 Jan 2019, 01:28
- Antispam: Yes
Re: MATC: if-elseif or select?
What's the LUA equivalent construct?
-
- Posts: 4
- Joined: 09 Feb 2018, 23:27
- Antispam: Yes
Re: MATC: if-elseif or select?
Rad, thanks!
The code that works is:
Real MATC "if (tx < 2) 1.0; if (tx > 8) 1.0; else 0.01"
The code that works is:
Real MATC "if (tx < 2) 1.0; if (tx > 8) 1.0; else 0.01"