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

False warning: unused variable

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 25, 2018, 10:23
Default False warning: unused variable
  #1
New Member
 
Mohamed Elshahat Ouda
Join Date: May 2010
Posts: 29
Rep Power: 15
me.ouda is on a distinguished road
Dear All;

I have weird problem when I try to compile my solver. I have a some variables defined in creatFields.H, for example:

Code:
//Dispersed phase diameter
const dimensionedScalar& dd(mixture.dd());

//Turbulent Schmidt number
const dimensionedScalar& Sct(mixture.Sct());
Then I use those variables in another file, e.g. Ueqn.H

The problem is that when I try to compile the code it gives me the following warning:

Code:
./createFields.H: In function ‘int main(int, char**)’:
./createFields.H:140:26: warning: unused variable ‘dd’ [-Wunused-variable]
 const dimensionedScalar& dd(mixture.dd());
                          ^
./createFields.H:143:26: warning: unused variable ‘Sct’ [-Wunused-variable]
 const dimensionedScalar& Sct(mixture.Sct());
I am sure that the variables are used. When I comment the declaration of them I get a compilation error:

Code:
‘Sct’ was not declared in this scope
‘dd’ was not declared in this scope
And when I move the declaration from creatFields.H to the mySolver.C the problem disappear.

I just wonder why does this problem appear? and which variables should be declared in createFields.H and which should be declared directly in the solver source file?

Best regards
me.ouda is offline   Reply With Quote

Old   May 30, 2018, 02:58
Default
  #2
Member
 
Join Date: Oct 2015
Location: Finland
Posts: 39
Rep Power: 10
blttkgl is on a distinguished road
Hey,

I think it looks like you declare a reference but does not initialize it in your createFields.

I tested it like following with dummy variables and no warning messages: In createFields.H:

Code:
const scalarField& Sct = mesh.V();
const scalarField& vols = mesh.V();
then main solver:
Code:
#include "createFields.H"
scalarField test = vols + Sct;
Try initializing them at the same time you create them. Afterwards you can use them in your main file.

Code:
//Dispersed phase diameter
const dimensionedScalar& dd = mixture.dd();

//Turbulent Schmidt number
 const dimensionedScalar& Sct = mixture.Sct();

Bulut
blttkgl is offline   Reply With Quote

Old   February 5, 2021, 07:48
Default
  #3
Member
 
K
Join Date: Jul 2017
Posts: 97
Rep Power: 8
mkhm is on a distinguished road
Did you find any solution to your problem ? I do have the same issue:
a warning about an unused variable. But I am 100% it is used.
mkhm 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
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 11:04
CFD by anderson, chp 10.... supersonic flow over flat plate varunjain89 Main CFD Forum 18 May 11, 2018 07:31
Cells with t below lower limit Purushothama Siemens 2 May 31, 2010 21:58
Version 15 on Mac OS X gschaider OpenFOAM Installation 113 December 2, 2009 10:23
Gentoo Compilation woes on AMD64 with fluentMeshToFoamL connclark OpenFOAM Installation 8 February 29, 2008 14:18


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