CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Passing variables to a codedBC (https://www.cfd-online.com/Forums/openfoam-programming-development/236415-passing-variables-codedbc.html)

tladd May 28, 2021 17:10

Passing variables to a codedBC
 
1 Attachment(s)
I am using a coded BC for an initial condition and a boundary condition (U.txt). I define omega as a parameter at the top of the file and then use it in setting the internal field via #codestream and in a rotating wall bc. I would also like to use it in a codedBC but the variable is not seen in the code. So $omega*y is interpreted as *y (an error of course). It works fine with a value (2) hardwired in (as in U.txt).

I understand that it's probably a scoping issue and we have encountered it before with coded BC's. But I was surprised it worked with codestream.

My questions are:

1) Why is the scoping different in coded BC and codestream (if that is what it is)
2) Is there any way to get a parameter defined in the BC file into the coded BC. We know how to read parameters from a dictionary but this seems overly complicated.

Thanks

Tony

Tobermory May 30, 2021 13:27

A reasonable question/request, but I guess the problem is that the codestream parts are compiled as a standalone piece of C++ ... which is why they do not see the variable definition at the top of the boundary file.

You probably need to write it as a dictionary, eg omegaParameter
Code:

omega          2;
and read it in as a dictionary in the codestream. In the boundary file, you can then just use an include command
Code:

#include "omegaParameter"
and it will be available as well in the other parts of the boundary file.

I haven't tested it, but that seems the "cleanest". Good luck.

PS - let us know if that works, since it will undoubtedly be useful for others!

tladd May 30, 2021 14:51

Quote:

Originally Posted by Tobermory (Post 804951)
I guess the problem is that the codestream parts are compiled as a standalone piece of C++


Actually codestream can process parameters. That was what I found confusing. But my much more C++ literate friend pointed out what's wrong. The dynamic code is put in some uniquely named directory while a coded BC goes in a directory with the bc name. You can look in there to see what happens. In the case of codestream the parameter is replaced by its value, whereas in the coded BC the parameter name just disappears. So I think the coded BC is not being parsed entirely correctly. I will file a bug report.


All times are GMT -4. The time now is 14:57.