|
[Sponsors] |
January 20, 2022, 12:12 |
Problems with declaration
|
#1 |
Member
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5 |
Hey,
I wrote a program that modified simpleFoam solver... Therefore I implemented some new header files... Now I would like to split my solver into two possible calculation methods. As a consequence I have some parameters which I read from an constant/InputData file for both variants and other parameter just for one or the other calculation... When I´m trying to split the input by if else statement, I run lots of "not declared in this scope" errors. Anny suggestions how to do this? Here are some code snippets: constant/InputData/ Code:
X 1; A A [1 0 0 0 0 0 0] 1.0; B B [1 0 0 0 0 0 0] 2.0; C C [1 0 0 0 0 0 0] 3.0; Programm: createFields.H is calling #include "readInputData.H" Code:
label X(readLabel(InputData.lookup("X"))); dimensionedScalar A(InputData.lookup("A")); if(X==0) { dimensionedScalar B(InputData.lookup("B")); } else if(X==1) { dimensionedScalar C(InputData.lookup("C"));} If I do it like this, the following program do not know the lookup data from B and C, leading to the above mentioned error. Thanks in advance Pyro |
|
January 22, 2022, 16:07 |
|
#2 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 670
Rep Power: 14 |
This is because you are declaring the dimensioned scalars B & C inside the if/else statement. That means that when you leave the if/else statement, they go out of scope and are lost. You need to do it another way.
For example, you could use the value of X as the key for the item to read from the dictionary - eg "B" or "C". Then you do not need the if statement. Otherwise you need to declare the variables outside the if statement. |
|
January 24, 2022, 03:22 |
|
#3 |
Member
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5 |
Thank you, I will try this out.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[solids4Foam] Problems while validating Turek and Hron (2006) FSI2 and FSI3 problems in solids4Foam | subhasisa.rath | OpenFOAM CC Toolkits for Fluid-Structure Interaction | 0 | September 6, 2021 17:02 |
Needed Benchmark Problems for FSI | Mechstud | Main CFD Forum | 4 | July 26, 2011 12:13 |
compile errors of boundary condition "expDirectionMixed" | liying02ts | OpenFOAM Bugs | 2 | February 1, 2010 20:11 |
Compiling problems with hello worldC | fw407 | OpenFOAM Installation | 21 | January 6, 2008 17:38 |
DecomposePar links against liblamso0 with OpenMPI | jens_klostermann | OpenFOAM Bugs | 11 | June 28, 2007 17:51 |