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

including parameter file in codedFixedValue

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 3 Post By Loekatoni

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 27, 2018, 09:07
Default including parameter file in codedFixedValue
  #1
New Member
 
Loek
Join Date: Oct 2018
Posts: 14
Rep Power: 7
Loekatoni is on a distinguished road
Hi all,

Intro
I have a boundary condition in which i give a profile to the inlet of my system via codedFixedValue. Now I want to be able to scale the whol system, so I want to put as many parameters in a separate file, in which I can change to desired values. This file is called parameters. So I want to include the file in the 0/U file. For a boundary which doens't include codedFixedValue it worked by including in the start of the 0/U file like:


______________________

/* start of openfoam file */

#include "../../parameters"

dimensions [0 1 -1 0 0 0 0];



// rest of file
______________________


I did this with the BC flowRateInletVelocity.


Now the above line didn't work for codedFixedValue. As far as I tried some random things, it looks like it needs to be included in the specific codedFixedValue BC if I want to use it in the code:
________________________________________________
boundaryField
{

inlet
{
type codedFixedValue;
value uniform (0 0 0);
name velocityProfile;

code
#{
#include "/home/path/to/parameters"
scalar A = ((($p0-$pL)/$L + $rho*$g)*pow($R, 2))/(2*$mu);
scalar U_TB = $U_TB;
scalar R = $R;
fixedValueFvPatchVectorField inlet(*this);

forAll(this->patch().Cf(),i)
{
inlet[i] = vector(0, 0, A*(Foam:ow(this->patch().Cf()[i].x()/R, 2)-1)-U_TB);
}
operator == (inlet);
#};
}
}
________________________________________________



the #include "../../parameters" didn't work here, it needed to be changed to #include "/home/path/to/parameters", otherwise it gave the error: no such file or directory. No it recognizes the file, but gives a couple of errors.

Errors
Now it is able to include it, but I get two kinds of errors;
1. /home/path/to/parameters:line:element: error: 'parameter' was not declared in this scope


This refers to a parameter I have defined, for example L:
L #calc "$tau*$U_TB"; where tau and U_TB are defined before this line comes along.



2. /home/path/to/parameters:line:element: error: stray '#' in program.


This refers to a calculation that needs to be done to obtain a parameter, which as example can also be the line for L from above.


Questions
- How can I solve these errors?
- Is there a way I can do this include with ../../parameters instead of /home/path/to/parameters?


Sincerely,
Loek
Loekatoni is offline   Reply With Quote

Old   November 27, 2018, 10:13
Default Partial solution to the problem
  #2
New Member
 
Loek
Join Date: Oct 2018
Posts: 14
Rep Power: 7
Loekatoni is on a distinguished road
So I have succeeded in getting the codedFixedValue to work with including the parameter file. Here is how I did it:


Partial solution
I made a parameters2 file. In this file my parameters are defined differently:


______________________________________
// Variable paremeters
double R = 0.0005; // m, channel radius
double tau = 5; // s, residence time
double p0 = 1.001; // bar, inlet pressure
double pL = 1; // bar, outlet pressure


// Fixed parameters
double g = 9.81; // m/s2, gravitational constant
double rho = 870; // kg/m3, density fluid
double mu = 0.00056; // Pa*s, viscosity fluid


// Calculated parameters
double U_TB = 0.351*sqrt(g*2*R);

double L = tau*U_TB;
______________________________________


Now with this file included while in

boundaryFields
{
inlet
{
blabla
code
#{
#include "/home/path/to/parameters2"

formulation of equation

#}


New problem
While this works for codedFixedValue, for initialising the velocity of the wall of my channel I also need a U_TB. This one needs to be initiated differently. This parameters file needs to be included at the start of the 0/U file as follows:
#include "../../parameters"
as it is two directories down the line.

And has the form:
______________________________________

// Variable paremeters
R 0.0005; // m, channel radius
tau 5; // s, residence time
p0 5e5; // Pa, inlet pressure
pL 1e5; // Pa, outlet pressure


// Fixed parameters
g 9.81; // m/s2, gravitational constant
rho 870; // kg/m3, density fluid
mu 0.00056; // Pa*s, viscosity fluid


// Calculated parameters
U_TB #calc "0.351*sqrt($g*2*$R)";

L #calc "$tau*$U_TB";
______________________________________

A side note: the files parameters and parameters2 are in the same directory.


New questions
Can someone explain to me what the different forms of defining parameters are?
And why does the first type work for the codedFixedValue and not for the flowRateInletVelocity?
And why does the second type works vice versa?


Sincerely,
Loek
lourencosm, ykanani and gbope7 like this.
Loekatoni is offline   Reply With Quote

Old   June 9, 2020, 16:31
Default
  #3
Member
 
Yousef
Join Date: Feb 2015
Posts: 40
Rep Power: 11
ykanani is on a distinguished road
Thanks for the workaround.

The first way of defining parameter is recognizable to OpenFOAM IODictionaries and that is why it works fine for flowRateInletVelocity or within any other dictionary.

This seems to be not recognized within the "code" section of the codedFixedValue, and hence, in your workaround, you define the parameters using C++ syntax, and include it within the code itself, and hence it works fine.


This is still puzzling for me as I had used this feature (the first way you tried) earlier withing the blockmeshdict in a codestream block and it worked fine. you can also see other people using it too:
#codeStream loop inside a blockMeshDict

But your solution fixes my problem, so thanks!

Quote:
Originally Posted by Loekatoni View Post
So I have succeeded in getting the codedFixedValue to work with including the parameter file. Here is how I did it:


Partial solution
I made a parameters2 file. In this file my parameters are defined differently:


______________________________________
// Variable paremeters
double R = 0.0005; // m, channel radius
double tau = 5; // s, residence time
double p0 = 1.001; // bar, inlet pressure
double pL = 1; // bar, outlet pressure


// Fixed parameters
double g = 9.81; // m/s2, gravitational constant
double rho = 870; // kg/m3, density fluid
double mu = 0.00056; // Pa*s, viscosity fluid


// Calculated parameters
double U_TB = 0.351*sqrt(g*2*R);

double L = tau*U_TB;
______________________________________


Now with this file included while in

boundaryFields
{
inlet
{
blabla
code
#{
#include "/home/path/to/parameters2"

formulation of equation

#}


New problem
While this works for codedFixedValue, for initialising the velocity of the wall of my channel I also need a U_TB. This one needs to be initiated differently. This parameters file needs to be included at the start of the 0/U file as follows:
#include "../../parameters"
as it is two directories down the line.

And has the form:
______________________________________

// Variable paremeters
R 0.0005; // m, channel radius
tau 5; // s, residence time
p0 5e5; // Pa, inlet pressure
pL 1e5; // Pa, outlet pressure


// Fixed parameters
g 9.81; // m/s2, gravitational constant
rho 870; // kg/m3, density fluid
mu 0.00056; // Pa*s, viscosity fluid


// Calculated parameters
U_TB #calc "0.351*sqrt($g*2*$R)";

L #calc "$tau*$U_TB";
______________________________________

A side note: the files parameters and parameters2 are in the same directory.


New questions
Can someone explain to me what the different forms of defining parameters are?
And why does the first type work for the codedFixedValue and not for the flowRateInletVelocity?
And why does the second type works vice versa?


Sincerely,
Loek
ykanani is offline   Reply With Quote

Old   August 19, 2022, 12:01
Default
  #4
New Member
 
Colorado
Join Date: Aug 2022
Posts: 1
Rep Power: 0
dMonty is on a distinguished road
Thanks for the info. I've had good luck using this approach with internal fields and boundary conditions, but have ran into a problem when I try to decompose the boundary conditions for parallel applications. The problem comes from how decomposePar writes the code for each processor. I've been putting the #include "$FOAM_CASES/inputParams" line above the code since the "/home/to/path/inputParams" always leads to an error.

Do you know where the /home/to/path is pointing? Where are you storing your input file?

Thanks!
dMonty is offline   Reply With Quote

Old   November 9, 2023, 16:56
Default
  #5
New Member
 
Prom
Join Date: Aug 2023
Posts: 7
Rep Power: 2
gbope7 is on a distinguished road
Hi Loek, were your parameters files written in OpenFOAM/C++ syntax? I have a text file (r132406.txt) that contains position data that I would like to be parsed by a function that I defined in a local struct in the codedFixedValue BC.


I was able able to include the text file using your method, but I got an error as OpenFOAM tried parsing through it automatically. Is there a way to include any text file without running into this issue?



Quote:
Invoking wmake libso /Users/promisea/OpenFOAM/ibukunOluwa/testCases/blockTest/testNSTX/dynamicCode/surfaceBC
wmake libso /Users/promisea/OpenFOAM/ibukunOluwa/testCases/blockTest/testNSTX/dynamicCode/surfaceBC
ln: ./lnInclude
dep: fixedValueFvPatchFieldTemplate.C
wmkdepend: parse error while scanning '/Users/promisea/OpenFOAM/ibukunOluwa/testCases/blockTest/testNSTX/r132406.txt' ... perhaps missing a final newline
Ctoo: fixedValueFvPatchFieldTemplate.C
In file included from /Users/promisea/OpenFOAM/ibukunOluwa/testCases/blockTest/testNSTX/0/T.boundaryField.top:35:
/Users/promisea/OpenFOAM/ibukunOluwa/testCases/blockTest/testNSTX/r132406.txt:1:1: error: expected unqualified-id
0.647001
^
1 error generated.
make: *** [Make/darwin64ClangDPInt32Opt/fixedValueFvPatchFieldTemplate.o] Error 1


--> FOAM FATAL IO ERROR: (openfoam-2306)
Failed wmake "dynamicCode/surfaceBC/platforms/darwin64ClangDPInt32Opt/lib/libsurfaceBC_303d73216935d55234d3e56b4a68e30ac2c21 169.dylib"


file: 0/T.boundaryField.top at line 28 to 43.

From void Foam::codedBase::createLibrary(Foam::dynamicCode &, const Foam::dynamicCodeContext &) const
in file db/dynamicLibrary/codedBase/codedBase.C at line 245.

FOAM exiting
gbope7 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
Custom Thermophysical Properties wsmith02 OpenFOAM 4 June 1, 2023 14:30
[OpenFOAM.org] Patches to compile OpenFOAM 2.2 on Mac OS X gschaider OpenFOAM Installation 136 October 10, 2017 17:25
[foam-extend.org] problem when installing foam-extend-1.6 Thomas pan OpenFOAM Installation 7 September 9, 2015 21:53
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 16:02
SparceImage v1.7.x Issue on MAC OS X rcarmi OpenFOAM Installation 4 August 14, 2014 06:42


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