CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Passing variables to a codedBC

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 28, 2021, 17:10
Default Passing variables to a codedBC
  #1
Member
 
Tony Ladd
Join Date: Aug 2013
Posts: 48
Rep Power: 12
tladd is on a distinguished road
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
Attached Files
File Type: txt U.txt (2.4 KB, 11 views)

Last edited by tladd; May 28, 2021 at 17:28. Reason: PS. The case is in the zip file
tladd is offline   Reply With Quote

Old   May 30, 2021, 13:27
Default
  #2
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 668
Rep Power: 14
Tobermory will become famous soon enough
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!
Tobermory is offline   Reply With Quote

Old   May 30, 2021, 14:51
Default
  #3
Member
 
Tony Ladd
Join Date: Aug 2013
Posts: 48
Rep Power: 12
tladd is on a distinguished road
Quote:
Originally Posted by Tobermory View Post
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.
tladd is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[swak4Foam] How to define boundary condition variables by using previosly defined variables? pawlo OpenFOAM Community Contributions 8 September 13, 2020 11:37
Optimal tolerance and variables scaling settings 4513645ygq Main CFD Forum 0 July 28, 2020 08:56
SU2 violates the lower bound of the FFD design variables cfdjetman SU2 4 October 2, 2019 16:15
Some variables not loading in Tecplot nick.l.thomas Tecplot 1 October 25, 2018 17:48
Passing fortran variables to C in mixed programmin Quarkz Main CFD Forum 1 January 9, 2008 06:17


All times are GMT -4. The time now is 08:07.