Expressions in .prj file

According to this issue, the function to define a certain parameter does not limit to “simple” expressions, but it can be extremely refined, for example using boolean conditions.

I repost here the documentation link:

I personally never tried them (will do asap), but I think it would be useful to have it somewhere in the OGS conventions section (but in the meanwhile I post it here).

Hi Lurpi,

indeed, the documentation of the exprtk features in OGS could be better. I’ll try to extend it ASAP. The relevant sections in the Doxygen documentation are rather brief, see:

for function material properties and parameters, respectively. The pages only say: “For the evaluation of the expressions the exprtk library is used”.

Btw.: Besides “normal” formulas, we have one test in OGS that uses “advanced” features of exprtk:

            <expression>if (x &lt; 2) 19; else if (x &lt; 2.1) 0.95; else 9.5;</expression>

Note: the "<"s have been changed to "&lt;"s to avoid conflicts with the enclosing XML syntax.

However, this test is not easy to find.

Best regards,

1 Like

I just created an issue for this: Extend function parameter documentation (#3346) · Issues · ogs / ogs · GitLab

1 Like

Thanks, yes I tried a similar expression, with the always beautiful nesting of if clauses and it works.

However, I tried the switching case and for the OGS parser it is difficult to understand. I will open an issue

            <expression> switch {                                                       
                        case y > 3 : if (z+20 > y+3) -9e6; else -5e6;;                                               
                        case y < 3 : -7e6;
                        default          : 7.5e6;

and the error is

info: Reading project file /projects2/AG3193/aug_22/run/test_functions-expr/test_stress.prj.
Entity: line 418: parser error : StartTag: invalid element name
case y < 3 : -7e6;
critical: /projects2/AG3193/ogs_branch/ogsPW/BaseLib/PrjProcessing.cpp:124 replaceIncludes()

please note that

case y > 3

works fine.


maybe everything has to be in one line?

no, multiple lines and multiple cases are fine, the issue is with the “<” char. I just saw that the OGS test provides

the "<"s have been changed to "<"s

which is a solution, although it is an obscure one.

Sure, this makes sense because < collides with the XML.


No, spaces have meaning in XML. However, <, >, &, ', " are considered as special characters and therefore these need to be replaced the same way as you would do in HTML.

I was trying to see if there is a quick fix for the parser. At the moment it reads correctly the >, but not < , from the expressions .

I should have read this thread to the end and saved me my longish answer to your GitLab issue :slight_smile:

Like Jörg said above, please use &lt; instead of <. That should work. Actually I already wrote that in my very first answer in this thread :slight_smile: