|
[Sponsors] |
January 20, 2013, 19:30 |
writing a scalar in the output
|
#1 |
Senior Member
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 273
Rep Power: 18 |
I'm trying to write the Uprime of the field (in regard with spatial averaging not temporal) in a simple case. In order not to change the solver I'm trying to use the functionObjects and code stream, so I have:
Code:
functions { kineticEnergy { type coded; functionObjectLibs ( "libutilityFunctionObjects.so" ); redirectType error; code #{ const volVectorField& U = mesh().lookupObject<volVectorField>("U"); volScalarField TKE =magSqr(U-average(U)); IOList<scalar> TKEO ( IOobject ( "TKE", word("constant"), TKE.mesh(), IOobject::NO_READ, IOobject::AUTO_WRITE ), TKE ); TKEO.write(); #}; } } IS there anyway to output a scalar from OpenFoam? can you register it in objectRegistery to handle it with IOobject? Please give me a hint, I'm so short on time I tried to use AverageIOField but it is not defined when you wanna reach through a function object, the only way I see remained is to use IOList with size=1, still I have the problem of how to declare it? second argument (now TKE.mesh) should be objectRegistery and no scalar can be made which is part of objectRegistery. Can anyone give me a hint please? Last edited by anishtain4; January 20, 2013 at 19:46. |
|
January 21, 2013, 03:53 |
|
#2 |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22 |
Well, I don't know it in the proper OpenFOAM way, but if you're looking for a working solution and don't know about the rest, I have three suggestions
1. Keep it as you have it, and just write a small script to process the output files using your bash skills (like cat) 2. Use regular C++ file i/o, which you can just use to output to a single file 3. Output the scalar using Info << TKE, and obtain it from the log file using grep. But your title reads that you want to write a single scalar, but from your text I understand you write a volScalarField? Can you clarify this? |
|
January 21, 2013, 10:07 |
|
#3 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Code:
writeTKE { type expressionField; autowrite true; outputControl outputTime; fieldName TKE; expression "magSqr(U-UAvg)"; variables ( "UAvg=sum(U*vol())/sum(vol());" ); } TKEAverage { type swakExpression; valueType internalField; expression "vol()*TKE/sum(vol())"; accumulations ( sum ); verbose true; }
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||
January 22, 2013, 08:59 |
|
#4 |
Senior Member
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 273
Rep Power: 18 |
Bernhard,
1. I'm running an LES solution which solves a lot of time steps while it writes some of them, I want to calculate this scalar (and some similar ones) while I'm solving the case to check them for all the times, so a post process after the solution won't do much good for me. 2. I've tried it before, but when you add #include <fstream> compiler complains, and that is because it would be added in the wrong place, so no chance for this solution. 3. I though this might work, to put it in Info and get it by foamLog, but unfortunately it doesn't so I have to write a script myself which I'm not so expert in that. Gschaider: I'm not trying to learn c++, the matter is that I already know it but not swak4Foam, can you give me a hint about it? as a final point I want to measure turbulent kinetic energy which would be average of what I have written, I tried to use a field because it is in objectRegistry but a single scalar is not, what exactly I need is to calculate this in every time step and APPEND it to a file so I can plot it later: 0.5*average(magSqr(U-average(U))) of course this was just one of the things I wanted to do, but if I learn how to prepare it for plot I can manage the rest since I have enough control over openFoam objects but not it's outputs |
|
January 22, 2013, 09:38 |
|
#5 |
Senior Member
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 273
Rep Power: 18 |
I figured out what to do with foamLog, you have to copy the file foamLog.db from its source to current folder and add a line at the end according to the instructions it has mentioned in the header.
Still I want to learn how to do it with functionObjects |
|
January 22, 2013, 14:44 |
|
#6 | |||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
- the 0.5 factor is missing - the average is volume weighted (which makes a difference if the cells in your mesh are not of the same size) The results (as a function of time) is found in a file (it is not hard to find) A field with magSqr(U-average(U)) is written out as a bonus. But if you don't want that you can do it all with one function object. Quote:
Quote:
There is a link to a presentation from the 6th OF-workshop at PSU. It should give you an overview of the capabilities it had THEN. Another nice tutorial (not by me) is https://www.hpc.ntnu.no/display/hpc/...AM+-+swak4Foam
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
||||
January 25, 2013, 05:16 |
|
#7 |
Senior Member
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 273
Rep Power: 18 |
Thanks bernard, I will take a look at it right after I finish my thesis
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to Mix AIR and WATER | Elvis1991 | FLUENT | 12 | December 1, 2016 13:28 |
dieselFoam problem!! trying to introduce a new heat transfer model | vivek070176 | OpenFOAM Programming & Development | 10 | December 24, 2014 00:48 |
compressible flow in turbocharger | riesotto | OpenFOAM | 50 | May 26, 2014 02:47 |
writing Force in output file | emreg | FLUENT | 0 | May 25, 2011 15:53 |
Writing scalar to file | Tobb | OpenFOAM Programming & Development | 6 | December 1, 2010 17:19 |