CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   How to add the values of any volscalarfield variable in every timestep (https://www.cfd-online.com/Forums/openfoam-solving/232632-how-add-values-any-volscalarfield-variable-every-timestep.html)

Pratik_21 December 22, 2020 13:21

How to add the values of any volscalarfield variable in every timestep
 
I am quite new to OpenFOAM and I would like to know if there is anything we can do in code to fetch the values of volscalarfield variable in all the time steps as it happens with the other filed values like k Omega etc. I tried Info statement but that method prints the values on screen but I would like to have it in timesteps so that I can see them in paraview.

dlahaye December 23, 2020 06:03

The likelihood that I am only partially understanding the question you raise is high.

Let me try to give an answer despite of this.

Typically additional volScalarFields are defined in createFields.H. By setting appropriate write attributes, the volScalarField is written to file at every time step.

Pratik_21 December 23, 2020 21:31

Yeh, you understood my questions correctly.I am trying to change createfields.H file of my solver but I am not able to compile it successfully. I tried some of the methods earlier posted on the forum. Do you know any method to compile the modified code successfully?

dlahaye December 24, 2020 12:48

Again, not sure what information you already have and what is missing.

Typically, however, solvers are compiled using the wmake (shell around make) guided by the Make/files and Make/options files. It suffices to look how standard solvers are compiled.

Pratik_21 December 24, 2020 12:56

Hello,
I managed to compile the code but I have another problem now

I get the file of the newly added field in the time steps folder but don't get the values in the timestep folders. It just shows the values that I mentioned in the 0 folder.

for curiosity, I used Info statement to print the values of the newly added field on-screen, and there it shows the expected values. but then why I am not getting them in timestep folders? compile the cod but

dlahaye December 24, 2020 13:42

Again, not sure.

How do you declare variable in createFields.H ?

Pratik_21 December 24, 2020 14:09

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

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

volScalarField gammabc
(
IOobject
(
"gammabc",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh (I have also tried adding dimensions here)
);

#include "createPhi.H"


label pRefCell = 0;
scalar pRefValue = 0.0;
setRefCell(p, simple.dict(), pRefCell, pRefValue);
mesh.setFluxRequired(p.name());


singlePhaseTransportModel laminarTransport(U, phi);

autoPtr<incompressible::turbulenceModel> turbulence
(
incompressible::turbulenceModel::New(U, phi, laminarTransport)
);

#include "createMRF.H"
#include "createFvOptions.H"



This is my createFields.H file

dlahaye December 24, 2020 14:12

Looks fine. Should write to file at every instance other fields are written to file.

Pratik_21 December 24, 2020 14:20

Yes fields are getting written but the newly defined field is not getting written as expected.

But my log file shows the expected values of new field gammabc

You can see the part of my log file below


Starting time loop

wallShearStress wallShearStress:
processing all wall patches

Reading set description:
line

Time = 1

smoothSolver: Solving for Ux, Initial residual = 1, Final residual = 0.0929271, No Iterations 6
smoothSolver: Solving for Uy, Initial residual = 1, Final residual = 0.0846516, No Iterations 2
GAMG: Solving for p, Initial residual = 1, Final residual = 0.0981968, No Iterations 28
time step continuity errors : sum local = 0.000144915, global = -3.05636e-06, cumulative = -3.05636e-06
gammabcdimensions [0 0 0 0 0 0 0];


internalField nonuniform List<scalar>
26820
(
0
0
0
0
0
0
0
0
0

Pratik_21 December 24, 2020 14:22

and this is how I have defined gammabc in the model



template<class BasicTurbulenceModel>
tmp<volScalarField> SABC<BasicTurbulenceModel>::gammabc
(
const volScalarField& Term1,
const volScalarField& Term2,
const volScalarField& nubc,
const volScalarField& Rev,
const volScalarField& ReTheta
) const
{

return
(
1 - exp(-sqrt(Term1)-sqrt(Term2))
);
}

dlahaye December 24, 2020 14:30

No idea.

How about setting your new field to constant value of 1. and check whether that is writing. Just guessing here.

Pratik_21 December 24, 2020 14:55

I can try this.
But one question. Do we need to make any changes in the .C file of the solver (simpleFoam.C) after adding new fields in createFields.H file?

dlahaye December 24, 2020 15:57

Nope, or better.

You should see that createFields.H is included in simpleFoam.C.

This means that after every change in createFields.C, the file simpleFoam.C should be re-compiled. The dependency list in the makefile system should take of that. Else you can you the unix touch utility to force the recompilation of the simpleFoam.C file


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