|
[Sponsors] |
March 30, 2018, 05:30 |
Writing a new variable as output
|
#1 |
Member
K
Join Date: Mar 2018
Posts: 34
Rep Power: 8 |
Hey everyone!
I am new to OpenFoam and I am learning about interFoam. Currently I am trying to write the data for a new variable that can be read in Paraview. For example: Say I want to write the rho variable data for the user defined writeInterval. I edited the CreateFields.H file as (the part dealing with rho variable) volScalarField rho ( IOobject ( "rho", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE ), alpha1*rho1 + alpha2*rho2 ); rho.oldTime(); // writing a new variable rho.write(); But this doesnot seem to work, any suggestions on how to address this problem? Thank you! |
|
April 3, 2018, 23:23 |
|
#2 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
I am not sure why interfoam doesn't automatically write rho, but an easy to understand work around is to define a new field, say rhoWrite, that's written automatically. Then you just need to compute/update rhoWrite with rho before the solver writes data with runTime.write(). So, add
Code:
volScalarField rhoWrite ( IOobject ( "rhoWrite", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), alpha1*rho1 + alpha2*rho2 ); Code:
rhoWrite = alpha1*rho1 + alpha2*rho2; Caelan. |
|
April 12, 2018, 06:41 |
|
#3 |
Member
K
Join Date: Mar 2018
Posts: 34
Rep Power: 8 |
Hey Caelan
Great! That worked Thank you -Kurian |
|
September 5, 2019, 00:26 |
|
#4 |
New Member
Aashay Tinaikar
Join Date: May 2019
Location: Boston
Posts: 19
Rep Power: 7 |
Hii Kuria and Clapointe,
Thanks for posting the question and giving a very working answer. I was facing an issue where the scalar field variable was not written at output. Precisely, I just added a variable in a manner given in the wiki page https://openfoamwiki.net/index.php/H...ure_to_icoFoam I found out that the new variable is written when I specify fixedValue velocity condition but not when I change it to flowRateInletVelocity. Therefore, I suppose it might have some bug. Quick fix: Add variable_Name.write() just before runTime.write() |
|
September 6, 2019, 18:57 |
|
#5 | |
New Member
Aashay Tinaikar
Join Date: May 2019
Location: Boston
Posts: 19
Rep Power: 7 |
Quote:
if(runtime.outputTime()) { variable_Name.write(); } Thanks. Hope this helps. |
||
February 9, 2021, 18:30 |
|
#6 |
New Member
Vishal
Join Date: Sep 2020
Posts: 6
Rep Power: 6 |
Hey Guys, is there a possibility where the changes should not be done in the solver but in the controlDict file to write a new variable?
I am trying to write drag coefficients in the multiphaseEulerFoam. I can not make changes in the original solver due to some permission rights. Is there a way that I can add lines in a case directory to write it? Thank you |
|
February 9, 2021, 18:44 |
|
#7 |
Senior Member
Join Date: Aug 2015
Posts: 494
Rep Power: 15 |
Yep, this is possible via function objects compiled at runtime. You can do something like the following (which is added to controlDict) :
Code:
functions { vorticity { libs ("libutilityFunctionObjects.so"); type coded; name vorticity; codeExecute #{ const volVectorField& U = mesh().lookupObject<volVectorField>("U"); volScalarField enst = 0.5*magSqr(fvc::curl(U)); static autoPtr<volScalarField> pField; if(!pField.valid()) { pField.set ( new volScalarField ( IOobject ( "enstrophy", mesh().time().timeName(), U.mesh(), IOobject::NO_READ, IOobject::AUTO_WRITE ), enst ) ); } volScalarField& enstrophy = pField(); enstrophy.checkIn(); enstrophy = enst; #}; } } Caelan |
|
May 12, 2021, 14:01 |
|
#8 | |
New Member
sujata
Join Date: Dec 2019
Posts: 10
Rep Power: 7 |
Quote:
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] refineWallLayer Error | Yuby | OpenFOAM Meshing & Mesh Conversion | 2 | November 11, 2021 12:04 |
[mesh manipulation] How to write cellSet for different regions in constant/polyMesh/sets | Struggle_Achieve | OpenFOAM Meshing & Mesh Conversion | 3 | June 17, 2019 10:29 |
Need help in writing UDF for an oscillating airfoil to get Output parameters | ned.musab | FLUENT | 0 | October 27, 2017 12:21 |
writing a scalar in the output | anishtain4 | OpenFOAM | 6 | January 25, 2013 05:16 |
Env variable not set | gruber2 | OpenFOAM Installation | 5 | December 30, 2005 05:27 |