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/)
-   -   Why is my new variable constant in all time steps? (https://www.cfd-online.com/Forums/openfoam-programming-development/243769-why-my-new-variable-constant-all-time-steps.html)

CharIie July 5, 2022 09:13

Why is my new variable constant in all time steps?
 
I am working in OpenFoamV8 with buoyantPimpleFoam. I have created a new variable "Test" in the solver code. Test should be the sum of the current temperature and a user defined constant value "Tc". My solver compiles and I get results, but the variable Test does not change over time!

Only the first time step "Test" is calculated and stays constant for all time steps. Although T changes over time! How can that be?

The error must be in the following code:
I have added these lines to Ueqn.H:
Code:

const volScalarField& T = mesh.lookupObject<volScalarField>("T");
dimensionedScalar    Tc(magneticProperties.lookup("Tc"));
volScalarField Test = T + Tc;

Test and Tc are created in createFields.H like this:
Code:

Info<< "Reading magnetic properties\n" << endl;
IOdictionary magneticProperties
(
    IOobject
    (
        "magneticProperties",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ_IF_MODIFIED,
        IOobject::NO_WRITE
    )
);
dimensionedScalar Tc(magneticProperties.lookup("Tc"));



Info<< "Reading field Test\n" <<endl;
volScalarField Test
(
    IOobject
    (
        "Test",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh
);


überschwupper July 5, 2022 10:05

One thing I see here, is that those variables in UEqn.H are going to be newly declared and defined everytime the solver steps into UEqn.H. You can easily put them into createFields and just add Test = T + Tc; inside UEqn.H.


The second thing what i find curious is the constant reference that you have named T. You are looking up a volScalarField from the objectRegistry named T and then overwriting it with a reference variable T?? Is that correct? I would suggest you to rename it for clear distinciton and to avoid name conflicts ( if you already defined a field called T, which I assume)


Please check if above recommandations already solve your problem.

CharIie July 5, 2022 10:13

Test and Tc are created in createFields.H
Code:

const volScalarField& T = mesh.lookupObject<volScalarField>("T");
just gets the current value of T, since buoyantPimpleFoam does not directly solve with T but the energy variable he.



Why is the volScalarField "Test" constant in all time steps?

überschwupper July 5, 2022 11:02

Quote:

Originally Posted by CharIie (Post 831025)
Test and Tc are created in createFields.H
Code:

const volScalarField& T = mesh.lookupObject<volScalarField>("T");
just gets the current value of T, since buoyantPimpleFoam does not directly solve with T but the energy variable he.



Why is the volScalarField "Test" constant in all time steps?




Yes I have seen that, but you redefine these variables everytime the solver is going into UEqn.H.


I would assum, that your T gets falsely read in.

T is calculated by the thermo package then - at least I assume that. T gets registred with "T" + phaseName


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