|
[Sponsors] |
Is it possible to use Info inside #calc to print a string? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
November 14, 2021, 10:59 |
Is it possible to use Info inside #calc to print a string?
|
#1 |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
Hello,
I have a question about #calc directive in OpenFOAM v2106. I know how to print a numeric value as follow: Code:
myVariable 42; #calc "Info << $myVariable << endl"; When I try to print a string message: Code:
msg "This is a message"; #calc "Info << $msg << endl"; Code:
codeStreamTemplate.C:59:20: error: ‘This’ was not declared in this scope 59 | os << (Info << This is a message << endl); | ^~~~ codeStreamTemplate.C:59:24: error: expected ‘)’ before ‘is’ 59 | os << (Info << This is a message << endl); | ~ ^~~ My question: Is it possible to print a string message using ONLY #code directive (without using #codeStream explicitly)? Thank you |
|
November 20, 2021, 07:17 |
|
#2 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
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"#}; #calc "Info << $msg << endl"; Code:
msg "This is a message"; #calc "Info << \"$msg\" << endl"; Code:
msg "\"This is a message\""; #calc "Info << $msg << endl"; |
|
November 21, 2021, 01:06 |
|
#3 |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
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; #calc "Info << $myVariable << endl"; I have tried your proposition to display text inside Info and found that the third one works (on openfoam8): Code:
msg "\"This is a message\""; #calc "Info << $msg << endl"; Last edited by NotOverUnderated; November 21, 2021 at 07:56. |
|
November 23, 2021, 12:26 |
|
#4 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
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; os << Info << "something" << nl; However, I assume that you are actually looking for a '#message' directive, if I am not mistaken. |
||
November 23, 2021, 15:33 |
|
#5 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
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 |
||
November 23, 2021, 20:42 |
|
#6 | |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
Quote:
I think a #message directive would be better since I cannot see how one can easily debug #calc when it is used extensively. |
||
November 24, 2021, 04:59 |
|
#7 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
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. |
||
November 26, 2021, 14:25 |
|
#8 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
Added into develop, will be in OpenFOAM-v2112. https://develop.openfoam.com/Develop.../-/issues/2276 https://develop.openfoam.com/Develop...a6c44f7daabd2b |
||
November 27, 2021, 01:19 |
|
#9 | |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
Quote:
Please accept my deepest thanks. |
||
Tags |
openfoam, programming |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
decomposePar problem: Cell 0contains face labels out of range | vaina74 | OpenFOAM Pre-Processing | 37 | July 20, 2020 06:38 |
[snappyHexMesh] SHM error: inside mesh not possible | Naresh yathuru | OpenFOAM Meshing & Mesh Conversion | 1 | January 11, 2017 00:58 |
OpenFOAM on MinGW crosscompiler hosted on Linux | allenzhao | OpenFOAM Installation | 127 | January 30, 2009 20:08 |
Modelling the Heat flow inside the curing oven | Marios Vlad | CFX | 1 | February 6, 2008 08:11 |
meshing F1 front wing | Steve | FLUENT | 0 | April 17, 2003 13:37 |