|
[Sponsors] |
May 14, 2009, 06:11 |
How can write a field in openFOAM
|
#1 |
Member
Sven Degner
Join Date: Mar 2009
Location: Zürich
Posts: 55
Rep Power: 17 |
hi,
I will write out a variable of my own turb. model, but its doesn't work. First of all I define a ScalarField in my Header, volScalarField hybrid_; for the next step I edit the code file with a new Object hybrid_ ( IOobject ( "hybrid_", runTime_.timeName(), mesh_, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh_, dimensionedScalar("hybrid", dimless, 0.0) ), and follow of the definition in the memberfunction hybrid_ = tanh ( pow( max( scalar(0) , ( I_ / X_ ) - 1/2 ) , 3) ); // function = tanh( ( max( 0 , l/x - 1/2 ) )³ ) the compile shows now errors and the case run fine for me, except !! the code cant write out the values of my defined variable (hybrid_). When I add the line hybrid_.write() its works, but for every timestep and not for the defined writecontrol! Hope everyone got a idea ! Thanks Sven |
|
May 14, 2009, 16:27 |
|
#2 |
Senior Member
|
Hi Sven
you can test the following code if(runTime_.outputTime()) { hybrid_.write(); } Junwei |
|
May 15, 2009, 04:44 |
|
#3 |
Member
Sven Degner
Join Date: Mar 2009
Location: Zürich
Posts: 55
Rep Power: 17 |
thanks junwai,
it works Sven |
|
July 26, 2012, 10:44 |
|
#4 |
Senior Member
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 520
Rep Power: 19 |
Dear friends,
I am trying to solve the same problem you solved. Could you help me? Where should I add that code? And is it necessary to re-compile the code? Can't I do the same thing in the case-dir, editing the dictionaries (e.g. controlDict)? Thanks a lot for help, Samuele |
|
July 26, 2012, 17:52 |
|
#5 |
Senior Member
|
First of all, if you would like to change something in the code, you will - of course - have to recompile the respective parts. If you would just like to write a certain field to disk, that is not written automatically, I guess that there is a functionObject to do that.
Otherwise you will have to put something like this in your solver/library Code:
volScalarField foo = mesh.V(); foo.write(); |
|
July 26, 2012, 17:53 |
|
#6 |
Senior Member
|
And it would be great if you could just post your question once!
|
|
July 27, 2012, 04:25 |
|
#7 |
Senior Member
Samuele Z
Join Date: Oct 2009
Location: Mozzate - Co - Italy
Posts: 520
Rep Power: 19 |
Hi,
thanks for answering and sorry for the double question. Samuele |
|
August 29, 2013, 06:58 |
|
#8 |
New Member
Join Date: Feb 2012
Posts: 25
Rep Power: 14 |
I am having the same problem to solve. Can someone post the correct code because from above posts it is not clear what is the right way to code?
|
|
August 29, 2013, 07:00 |
|
#9 |
Senior Member
|
Different variants are correct :-)
__________________
Best regards, Dr. Alexander VAKHRUSHEV Christian Doppler Laboratory for "Metallurgical Applications of Magnetohydrodynamics" Simulation and Modelling of Metallurgical Processes Department of Metallurgy University of Leoben http://smmp.unileoben.ac.at |
|
January 31, 2014, 16:23 |
Unable to write field
|
#10 |
New Member
Daniel Duque
Join Date: Jan 2011
Location: ETSIN, Madrid
Posts: 28
Rep Power: 15 |
Hi every one.
I have tried to use these ideas, and other, but right now I am failing to write down a field. I try something as simple as modifying interFoam, and in createFields.H : Code:
volScalarField surfForce ( IOobject ( "surfForce", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), alpha1 ); Thanks in advance. Best, Daniel |
|
February 2, 2014, 09:16 |
|
#11 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128 |
Greetings to all!
@Daniel: OpenFOAM's C++ already seems voodoo'ish enough already, so it would be even more complicated if all it took to bind one field to another, would be to reference it only once at construction In other words, I suggest that you give a quick study to this tutorial: http://openfoamwiki.net/index.php/Ho...ure_to_icoFoam - You'll notice that the "T" field is changed on every iteration, not just at the start. Best regards, Bruno
__________________
|
|
February 2, 2014, 10:30 |
|
#12 |
New Member
Daniel Duque
Join Date: Jan 2011
Location: ETSIN, Madrid
Posts: 28
Rep Power: 15 |
Of course! I know that tutorial almost by heart, but somehow the fact that a whole equation was solved for T had obscured the obvious fact that T is changed. I only have to repeat the field=alpha1 (or whatever) at each iteration then.
Thanks a lot! Daniel |
|
May 14, 2014, 12:30 |
|
#13 |
New Member
Christoph Wenzel
Join Date: May 2014
Location: Germany
Posts: 21
Rep Power: 12 |
I actually try to program my own solver and there are some variables that I want to write down in an additional file. When I try this for the turbulent kinetic energy that works fine. Therefore I added in the createFields.H the following code:
Code:
volScalarField k_output ( IOobject ( "k_output", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), turbulence->k() ); Code:
... #include "createFields.H" ... while (runTime.run()) { ... k_output = turbulence->k(); ... } Now I want to do the same with a variable (volTensorField) that I created by myself. In this case the variable is called alphaEff. Therefore I added the same lines like before in the createField.H file for my own TensorField: Code:
volTensorField alphaEff_output ( IOobject ( "alphaEff_output", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), alphaEff (i also tried alphaEff_output together with (**) ) ); Code:
... #include "createFields.H" ... while (runTime.run()) { ... volTensorField alphaEff ( IOobject ( "alphaEff", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), turbulence->nu()/Pr*I + DT ); ... alphaEff_output=alphaEff; (**) (only when using alphaEff_output) ... } I think that the answer is extremely easy, but I'm sitting now about two days in front of my PC without any progress. Maybe one of you knows the answer for my little problem (the idea of Code:
if(runTime_.outputTime()) { alphaEff.write(); } |
|
May 14, 2014, 12:51 |
|
#14 |
Senior Member
|
Hi,
Why would you like to define alphaEff inside 'while (runTime.run())' loop and not outside? Also you can define it just like: Code:
volTensorField alphaEff ( IOobject ( "alphaEff", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, <dimensions of alphaEff> ); It will be automatically written every write time. |
|
May 15, 2014, 06:45 |
|
#15 |
New Member
Christoph Wenzel
Join Date: May 2014
Location: Germany
Posts: 21
Rep Power: 12 |
Thank you very much for your rapid answer, but this solution doesn't work at all.
When I tried your idea, OpenFoam needed an INPUT-File in the 0-folder and a MUST_READ in the IOobject because of the <mesh> entry. After changing this, all worked. So for all who have the same problem, this was my solution: In the solver-folder, I added the following IOobject into the <createfields.H> file: Code:
volTensorField alphaEff ( IOobject ( "alphaEff", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); In the .c file of the solver, I only have to update alphaEff in the time-loop, in my case: Code:
alphaEff=turbulence->nu()/Pr*I + DT; The only ugly part of this solution is the one, that you have to create an additional Input-File for alphaEff. Maybe someone knows a solution, where I don't need this file. When I try to create an IOobject with NO_READ, OpenFoam doesn't work anymore. Last edited by ChrisWe; May 15, 2014 at 08:04. |
|
May 15, 2014, 06:54 |
|
#16 |
Senior Member
|
I don't know what modifications you've done to proposed solution (I guess you've ignored the line with dimensions), but here's a piece of working code:
Code:
... flux_ ( IOobject ( "heatFlux", mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimEnergy/dimTime/dimVolume ) ... Code:
... flux_ ( IOobject ( "heatFlux", mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("flux", dimEnergy/dimTime/dimVolume, 0.0) ) ... In your case it should be tensor, not scalar. |
|
May 15, 2014, 08:42 |
|
#17 |
New Member
Christoph Wenzel
Join Date: May 2014
Location: Germany
Posts: 21
Rep Power: 12 |
Ahhhh, now its working without defining an Input-File for alphaEff. Thank you very much for your patience and your helpfulness!!!
In my version before, I had to replace your NO_READ with MUST_READ because I thought, that the dimensions aren't necessary at all. But I was wrong, NO_READ only works together with the dimensions in this case: Code:
mesh, dimensionedTensor("alphaEff", dimArea/dimTime, tensor::zero) |
|
July 21, 2014, 08:26 |
|
#18 |
Member
Vignesh
Join Date: Oct 2012
Location: Darmstadt, Germany
Posts: 66
Rep Power: 14 |
Dear All,
I am working on VOF method and using interFoam solver. I would like to write the whole surface tension term in UEqn.H (fvc::interpolate(interface.sigmaK())*fvc::snGrad(a lpha1)) to the output. I tried creating a volVectorField in CreateFields.H as below Code:
//*******************************************************************************// volVectorField ST ( IOobject ( "ST", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), fvc::interpolate(interface.sigmaK())*fvc::snGrad(alpha1) ); //*******************************************************************************// Code:
In file included from interFoam.C:60:0: createFields.H: In function 'int main(int, char**)': createFields.H:40:26: error: 'interface' was not declared in this scope createFields.H:40:58: error: 'alpha1' was not declared in this scope /opt/openfoam222/src/finiteVolume/lnInclude/readTimeControls.H:38:8: warning: unused variable 'maxDeltaT' [-Wunused-variable] make: *** [Make/linux64GccDPOpt/interFoam.o] Error 1
__________________
Thanks and Regards Vignesh |
|
July 21, 2014, 09:16 |
|
#19 |
Senior Member
|
Hi,
where exactly did you put the code? Obviously it should be placed after definition of alpha1 (line 36) and interface (line 76). From error output I can see that expression with alpha1 and interface is at the line 40, so I guess definition of volScalarField started before definition of alpha1 and interface (hence the error). Also Code:
fvc::interpolate(interface.sigmaK())*fvc::snGrad(alpha1) |
|
July 21, 2014, 09:52 |
|
#20 |
Member
Vignesh
Join Date: Oct 2012
Location: Darmstadt, Germany
Posts: 66
Rep Power: 14 |
Thanks Alex !! You pointed it out, i wrote the definition of surface tension term before alpha definition. Now i corrected it and it works !!
Thank you very much !!
__________________
Thanks and Regards Vignesh |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Critical errors during OpenFoam installation in OpenSuse 11.0 | amscosta | OpenFOAM | 5 | May 1, 2009 15:06 |
Problem installing OpenFOAM 1.5 installation on RHEL 4. | vwsj84 | OpenFOAM Installation | 4 | April 23, 2009 05:48 |
2009 OpenFOAM Summer School in Zagreb, Croatia | hjasak | OpenFOAM Announcements from Other Sources | 0 | March 27, 2009 13:08 |
Adventure of fisrst openfoam installation on Ubuntu 710 | jussi | OpenFOAM Installation | 0 | April 24, 2008 15:25 |
OpenFOAM Training and Workshop | Hrvoje Jasak | Main CFD Forum | 0 | October 7, 2005 08:14 |