CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Global use of a volScalarField (https://www.cfd-online.com/Forums/openfoam-programming-development/194085-global-use-volscalarfield.html)

Argyris October 10, 2017 08:27

Global use of a volScalarField
 
Dear FOAMers,

i created my own volScalarField myField in the creatFields.H:

volScalarField myField
(
IOobject
(
"myField",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("zero",dimensionSet(0,0,0,0,0,0, 0),-1.0),
);

and now i want to use it in the smoothSolver.C code as follows:

myField.internalField() = ( ...);

but the compiler says myField is out of scope. Isnt all Fields supposed to be globaly available?

Should i use some include ".H" file ?

Best regards,
Argyris

Marpole October 10, 2017 19:26

Hi Argyris,

smoothSolver can take a scalarField variable (e.g. myField) as an argument and process it. If myField is directly written in the code, it would cause not in problem (not declared in this scope) as myField is not declared in smoothSolver.

Argyris October 11, 2017 08:41

Thank you Charles for your reply.

I went to fvMatrixSolve.C where the smoothSolver is being called and passed the myField as an arguement. However now i have the same "myField was not declared in this scope" problem in the fvMatrixSolve.C and i cant find how to pass myField in the fvMatrixSolve as an arguement as well.

Any ideas?

Argyris

Marpole October 11, 2017 23:54

smoothSolver or fvMatrixSolve is used for solving linear system equation. It is odd that you need a scalar field but I believe you have your reason. I can only think of declaring myField in smoothSolver and read myField in smoothSolver where you need myField, i.e. put your following code inside smoothSolver.

Code:

volScalarField myField
(
    IOobject
    (
        "myField",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar("zero",dimensionSet(0,0,0,0,0,0,  0),-1.0),
);



All times are GMT -4. The time now is 02:59.