CFD Online Logo CFD Online URL
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Variable decleration problem

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Search this Thread Display Modes
Old   September 17, 2022, 05:44
Default Variable decleration problem
Join Date: Dec 2014
Location: Turkey
Posts: 53
Rep Power: 9
rewol is on a distinguished road
Hello Everyone,

I am trying to implement a new solver based on reactingFoam.
Currently i am on very early stages and try to implement necessery codes step by step.

My first attempt was to create a scalar that will be read from a dictionary i created. Below code is written in a file named "readThickenedFlameProperties.H" and this header is in the same directory as "reactingFoam.C" and "createFields.H".

IOdictionary thickenedFlameProperties

// Define a scalar for thickening factor

scalar TF = readScalar(thickenedFlameProperties.lookup("thicke ningFactor"));

scalar yfSt = readScalar(thickenedFlameProperties.lookup("fuelSt oicRatio"));

I also created the thickened flame properties file in the tutorial case and compilation works up to this point. ("readThickenedFlameProperties.H" is reactingFoam.C right before "createFields.H")

But when i try to create a scalar field inside the "createFields.H" with the scalar i read from my dictionary, i get an decleration error during compilation.

Piece of code in createFields.H is:

volScalarField& yf = composition.Y("CH4");
volScalarField c("c", 1 - yf / yfSt);

and also in reactingFoam.C

int main(int argc, char *argv[])

#include "readThickenedFlameProperties.H"
#include "createFields.H"

The error i get is:

In file included from /usr/lib/openfoam/openfoam2112/src/OpenFOAM/lnInclude/postProcess.H:147:0,
from myReactingFoam.C:57:
./createFields.H: In function ‘int main(int, char**)’:
./createFields.H:104:32: error: ‘yfSt’ was not declared in this scope
volScalarField c("c", 1 - yf / yfSt);

I know yfSt is defined prior to volScalarField c but it seems there is a problem in communication which is weird.

Do you have any suggestions as to how to overcome this problem ?
I know i could place readThickenedFlameProperties.H inside createFields.H but i want to code them seperately for later usage and extended code.

Best regards.


Last edited by rewol; September 17, 2022 at 13:58.
rewol is offline   Reply With Quote

Old   September 22, 2022, 05:25
Join Date: Jan 2022
Location: Germany
Posts: 49
Rep Power: 2
überschwupper is on a distinguished road
Without seeing the whole Code of "readThickenedFlameProperties.H", its hard to guess where your error is.

According to the errror message I would guess that you defined your variables in "readThickenedFlameProperties.H" under a different scope. Because of the different scope the program is not able to find your variables defined earlier. Maybe you have to get your variable via the scope resolution operator (:. Take a look on your code and look if you have declared for example a block scope in your "readThickenedFlameProperties.H" file or something else.
überschwupper is offline   Reply With Quote

Old   October 2, 2022, 15:43
Join Date: Dec 2014
Location: Turkey
Posts: 53
Rep Power: 9
rewol is on a distinguished road

I overcame this problem by moving my new solver folder to user solver folder inside applications. Though I did not understand why it worked.
rewol is offline   Reply With Quote


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Problem diverges when exhaust valve opens swerner0711 AVL FIRE 0 September 21, 2018 08:14
[swak4Foam] Variable T_inf for convection problem in a pipe using groovyBC Mojtaba.a OpenFOAM Community Contributions 4 September 4, 2013 20:10
Problem with variable in expression CFX-Pre TallesC CFX 4 March 7, 2013 18:32
A realy easy variable - problem wernsen OpenFOAM Programming & Development 3 January 7, 2013 14:25
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 21:09

All times are GMT -4. The time now is 17:12.