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

How to add the values of any volscalarfield variable in every timestep

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By dlahaye

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 22, 2020, 14:21
Default How to add the values of any volscalarfield variable in every timestep
  #1
New Member
 
Pratik
Join Date: May 2020
Posts: 11
Rep Power: 4
Pratik_21 is on a distinguished road
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.
Pratik_21 is offline   Reply With Quote

Old   December 23, 2020, 07:03
Default
  #2
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 517
Blog Entries: 1
Rep Power: 14
dlahaye is on a distinguished road
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 likes this.
dlahaye is offline   Reply With Quote

Old   December 23, 2020, 22:31
Default
  #3
New Member
 
Pratik
Join Date: May 2020
Posts: 11
Rep Power: 4
Pratik_21 is on a distinguished road
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?
Pratik_21 is offline   Reply With Quote

Old   December 24, 2020, 13:48
Default
  #4
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 517
Blog Entries: 1
Rep Power: 14
dlahaye is on a distinguished road
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.
dlahaye is offline   Reply With Quote

Old   December 24, 2020, 13:56
Default
  #5
New Member
 
Pratik
Join Date: May 2020
Posts: 11
Rep Power: 4
Pratik_21 is on a distinguished road
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
Pratik_21 is offline   Reply With Quote

Old   December 24, 2020, 14:42
Default
  #6
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 517
Blog Entries: 1
Rep Power: 14
dlahaye is on a distinguished road
Again, not sure.

How do you declare variable in createFields.H ?
dlahaye is offline   Reply With Quote

Old   December 24, 2020, 15:09
Default
  #7
New Member
 
Pratik
Join Date: May 2020
Posts: 11
Rep Power: 4
Pratik_21 is on a distinguished road
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
Pratik_21 is offline   Reply With Quote

Old   December 24, 2020, 15:12
Default
  #8
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 517
Blog Entries: 1
Rep Power: 14
dlahaye is on a distinguished road
Looks fine. Should write to file at every instance other fields are written to file.
dlahaye is offline   Reply With Quote

Old   December 24, 2020, 15:20
Default
  #9
New Member
 
Pratik
Join Date: May 2020
Posts: 11
Rep Power: 4
Pratik_21 is on a distinguished road
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 is offline   Reply With Quote

Old   December 24, 2020, 15:22
Default
  #10
New Member
 
Pratik
Join Date: May 2020
Posts: 11
Rep Power: 4
Pratik_21 is on a distinguished road
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))
);
}
Pratik_21 is offline   Reply With Quote

Old   December 24, 2020, 15:30
Default
  #11
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 517
Blog Entries: 1
Rep Power: 14
dlahaye is on a distinguished road
No idea.

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

Old   December 24, 2020, 15:55
Default
  #12
New Member
 
Pratik
Join Date: May 2020
Posts: 11
Rep Power: 4
Pratik_21 is on a distinguished road
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?
Pratik_21 is offline   Reply With Quote

Old   December 24, 2020, 16:57
Default
  #13
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 517
Blog Entries: 1
Rep Power: 14
dlahaye is on a distinguished road
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
dlahaye is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Creating variable including results from earlier timestep gcoopermax CFX 0 May 31, 2017 05:53
using chemkin JMDag2004 OpenFOAM Pre-Processing 2 March 8, 2016 23:38
Reference Values for Troughs @ variable Angle? hornig FLUENT 1 April 12, 2014 23:26
Add values of points from two different files with paraview nunoloureiro OpenFOAM 0 May 5, 2010 04:30
Env variable not set gruber2 OpenFOAM Installation 5 December 30, 2005 05:27


All times are GMT -4. The time now is 03:01.