Is it possible to use Info inside #calc to print a string?
Hello,
I have a question about #calc directive in OpenFOAM v2106. I know how to print a numeric value as follow: Code:
myVariable 42; When I try to print a string message: Code:
msg "This is a message"; Code:
codeStreamTemplate.C:59:20: error: ‘This’ was not declared in this scope My question: Is it possible to print a string message using ONLY #code directive (without using #codeStream explicitly)? Thank you |
If this is a common enough use case, it might be worthwhile having a "#message" directive in OpenFOAM, otherwise you are throwing a rather expensive compile/link cycle for each "#calc" and just to get some information.
Since the dollar expansion occurs before the string is sent through, you are indeed trying to print bare words. The only way I can see would be to include quotes (haven't tried any of these though) Code:
msg #{"This is a message"#}; Code:
msg "This is a message"; Code:
msg "\"This is a message\""; |
I would like to thank you for your reply.
I made a mistake when I wrote the post: the #calc in openfoam 2106 doesn't show numeric values. For example: Code:
myVariable 42; I have tried your proposition to display text inside Info and found that the third one works (on openfoam8): Code:
|
Quote:
If you look at how calc is implemented: https://develop.openfoam.com/Develop...alcEntry.C#L85 there is very little difference to explain why it should work at all. If you expand it out, you are essentially doing this: Code:
OStringStream os; However, I assume that you are actually looking for a '#message' directive, if I am not mistaken. |
Quote:
I have taken a closer look, and opened a corresponding issue. https://develop.openfoam.com/Develop.../-/issues/2276 We can refine the requirements there (as needed). /mark |
Quote:
I think a #message directive would be better since I cannot see how one can easily debug #calc when it is used extensively. |
Quote:
If you are using '#calc' for actual calculations, I would really suggest taking a look at the '#eval' directive as an alternative. It uses a builtin parser evaluation, which means that you save the entire compile/load cycle. In the OpenFOAM tutorials/ we have managed to replace all instances of '#calc' with '#eval', so there are a reasonable number of examples. |
Quote:
Added into develop, will be in OpenFOAM-v2112. https://develop.openfoam.com/Develop.../-/issues/2276 https://develop.openfoam.com/Develop...a6c44f7daabd2b |
Quote:
Please accept my deepest thanks. |
All times are GMT -4. The time now is 15:49. |