Usage of IF, ELSE statement in mathematical expression editor

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
jankolino
Posts: 12
Joined: Fri Jun 22, 2018 2:03 pm

Usage of IF, ELSE statement in mathematical expression editor

Post by jankolino »

Hi,

could someone provide me some example with if else statement in mathematical expression editor.

What I am trying to do:

if(scalar<0.5){
density = ...
}
else{
density = ...
}

And it doesnt work.

Thanks
rodion
Posts: 98
Joined: Wed Jan 11, 2017 4:13 pm

Re: Usage of IF, ELSE statement in mathematical expression editor

Post by rodion »

Hi,

Unfortunately these things never worked in my simulation on Windows. Try using the file cs_user_physical_properties.f90 for your custom physical properties. You can find several examples in the folder \SRC\EXAMPLES

Best regards,
Rodion
Yvan Fournier
Posts: 4251
Joined: Mon Feb 20, 2012 3:25 pm

Re: Usage of IF, ELSE statement in mathematical expression editor

Post by Yvan Fournier »

Hello,

What do you mean never work ? Syntax refused by GUI or execution error. ?

Regards,

Yvan
jankolino
Posts: 12
Joined: Fri Jun 22, 2018 2:03 pm

Re: Usage of IF, ELSE statement in mathematical expression editor

Post by jankolino »

For me, the GUI never accepts my code.
Yvan Fournier
Posts: 4251
Joined: Mon Feb 20, 2012 3:25 pm

Re: Usage of IF, ELSE statement in mathematical expression editor

Post by Yvan Fournier »

Hello,

The expression interpreter should be OK for already-defined cases, as the test suite has been tested on Windows and many cases include MEI expressions, but I wonder whether there might be a Windows-specific issue with the way the GUI and the expression evaluation test program communicate... If this is the case, a "cheat" directly editing the xml file should be ok, and a simple workaround would be to not check the syntax in the GUI. This would be easy to test on Linux, but not so easy with the Windows version, which uses a "frozen Python" distribution method, where editing a simple Python file is not possible...

Could you provide a simple expression you tried on Windows (which fails) so I can test it on Linux ? Also, if you are running on Windows 10, the Linux subsystem for Windows may be a good option to have a full "linux-like" install that plays nice with debugging tools.

Best regards,

Yvan
Luciano Garelli
Posts: 284
Joined: Fri Dec 04, 2015 1:42 pm

Re: Usage of IF, ELSE statement in mathematical expression editor

Post by Luciano Garelli »

Hello,

Here is an example of use (linux version),
MEI_example.png
jankolino wrote: Mon Jun 25, 2018 8:47 pm For me, the GUI never accepts my code.
Your "scalar" is computed inside the MEI or it is a variable of your problem. Did you check that it exist in the predefined symbol list.

Regards,

Luciano
Yvan Fournier
Posts: 4251
Joined: Mon Feb 20, 2012 3:25 pm

Re: Usage of IF, ELSE statement in mathematical expression editor

Post by Yvan Fournier »

Hello,

I'll add that I just tested the editor validation in the GUI under Windows and it seems to work.

So the issues jankolino mentions are probably due to syntax errors. The syntax is almost identical to that of the C language, with the exception of the "x % y" operator being "mod(x, y)" under the MEI.

Best regards,

Yvan
jankolino
Posts: 12
Joined: Fri Jun 22, 2018 2:03 pm

Re: Usage of IF, ELSE statement in mathematical expression editor

Post by jankolino »

Thanks to all replies. Sorry I didnt answer earlier, but I got to make it work. It was a problem on my side.
Post Reply