|
[Sponsors] |
November 27, 2018, 10:07 |
including parameter file in codedFixedValue
|
#1 |
New Member
Loek
Join Date: Oct 2018
Posts: 14
Rep Power: 8 |
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 |
|
November 27, 2018, 11:13 |
Partial solution to the problem
|
#2 |
New Member
Loek
Join Date: Oct 2018
Posts: 14
Rep Power: 8 |
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 |
|
June 9, 2020, 17:31 |
|
#3 | |
Member
Yousef
Join Date: Feb 2015
Posts: 40
Rep Power: 11 |
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:
|
||
August 19, 2022, 13:01 |
|
#4 |
New Member
Colorado
Join Date: Aug 2022
Posts: 1
Rep Power: 0 |
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! |
|
November 9, 2023, 17:56 |
|
#5 | |
New Member
Prom
Join Date: Aug 2023
Posts: 8
Rep Power: 3 |
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:
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom Thermophysical Properties | wsmith02 | OpenFOAM | 4 | June 1, 2023 15:30 |
[OpenFOAM.org] Patches to compile OpenFOAM 2.2 on Mac OS X | gschaider | OpenFOAM Installation | 136 | October 10, 2017 18:25 |
[foam-extend.org] problem when installing foam-extend-1.6 | Thomas pan | OpenFOAM Installation | 7 | September 9, 2015 22:53 |
[swak4Foam] swak4foam building problem | GGerber | OpenFOAM Community Contributions | 54 | April 24, 2015 17:02 |
SparceImage v1.7.x Issue on MAC OS X | rcarmi | OpenFOAM Installation | 4 | August 14, 2014 07:42 |