|
[Sponsors] |
Starting field averaging using libFunctionObject after certain time |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 9, 2011, 10:47 |
Starting field averaging using libFunctionObject after certain time
|
#1 |
Senior Member
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19 |
Hi Foamers,
I am quite often using simpleFunctionObjects (http://openfoamwiki.net/index.php/Co...unctionObjects), in order to do for instance averaging of data field. In this tread I want to find out how to start the averaging after a certain time such that first the flow can first develop. For data averging over time I put in the controlDict Code:
functions ( #include "fieldAverageDict" ); Code:
fieldAverage1 { type fieldAverage; functionObjectLibs ("libfieldFunctionObjects.so" ); enabled true; outputControl outputTime; fields ( U { mean on; prime2Mean off; base time; } ); } The question is: how can I automatically start the averaging during a run after a certain time with the function objects? According to the simpleFunctionobject manual there is an entry to the functionobject called 'after' which should define the time after which the function is read, however, this does not work. If I add after 100; (for instance), nothing happens, it just starts averaging right from the start. So I have thought another trick: using the timeActivatedFileUpdate lib: http://foam.sourceforge.net/docs/cpp/a02055.html With this dict, I add a file to the system directory called fileUpdate with the content Code:
fileUpdate1 { type timeActivatedFileUpdate; functionObjectLibs ("libutilityFunctionObjects.so"); outputControl timeStep; outputInterval 1; fileToUpdate "$FOAM_CASE/system/fieldAverageDict"; timeVsFile ( (-1 "$FOAM_CASE/system/fieldAverageDict_0") (20 "$FOAM_CASE/system/fieldAverageDict_1") ); Code:
fucntions ( #include "fieldAverageDict" #include "fileUpdate" ); This works, however, although the file fieldAverageDict got modified, it does not get reread during the run. Next trick: also use trackDictionary from simpleSwakFunctionObjects.so, in which aparently you can specify all the files which are read during the run and reread if modified. So I add to the functions the include line Code:
#include "trackDictionary" Code:
trackDictionaryContent { type trackDictionary; // Where to load it from (if not already in solver) functionObjectLibs ("simpleSwakFunctionObjects.so"); // Names of dictionaries to track. dictionaryNameList ( "system/controlDict" "system/fvSchemes" "system/fvSolution" "constant/transportProperties" "system/fieldAverage" ); echoControlDictDebugSwitches false; echoControlDictInfoSwitches true; echoControlDictOptimisationSwitches true; echoControlDictTolerances true; echoControlDictDimensionedConstants true; sectionStartSeparator "############ Start of: _sectionIdToken_ ############"; sectionEndSeparator "############ End of: _sectionIdToken_ ############"; } Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 2.0.0 | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object fieldAverage; type fieldAverage; enabled true; outputControl outputTime; functionObjectLibs ("libfieldFunctionObjects.so" ); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // type fieldAverage; enabled true; functionObjectLibs ("libfieldFunctionObjects.so" ); outputControl outputTime; fields ( U { mean on; prime2Mean off; base time; } ); the fileUpdate is used to update the fieldAverage dictionary file to enable field averaging at a certain time, and then the trackdictionary should ensured it got reread during the code. Unfortrunately: it does not work Anybody see where is goes wrong ? Why is trackDictionary not rereading my fieldAverage file after it has been updated? If I change something in the other files in the list (controlDict, etc), they do get reread. I am sure that the file fieldAverage does get updated with the enable flag set to true. It is only not read again, even it is defined in trackDictionary. To conclude: I have found a way around, and that is to not use trackDictionary, but to hard-code the fieldAverageDict include file in the controlDict it self. I then defined two controlDict: controlDict_0 and controlDict_1, which are idendentical except the enabling of the field averaging. I then use the fileUpdate library to update the controldict: Code:
fileUpdate2 { type timeActivatedFileUpdate; functionObjectLibs ("libutilityFunctionObjects.so"); outputControl timeStep; outputInterval 1; fileToUpdate "$FOAM_CASE/system/controlDict"; timeVsFile ( (20 "$FOAM_CASE/system/controlDict_1") ); } Hopefully anybody sees what goes wrong with the trackDictionary/fileUpdate procedure. Any hints appreciated! Regards Eelco |
|
September 9, 2011, 11:19 |
|
#2 |
Senior Member
Steven van Haren
Join Date: Aug 2010
Location: The Netherlands
Posts: 149
Rep Power: 16 |
Hi Eelco,
We had the same problem, we added a keyword 'after' to the fieldAverage function. This will delay averaging untill the specified time is reached (this is specified in controlDict). You can unzip this folder and compile it (wmake libso), in the controlDict which is in the folder you can see how to use it. I hope this solves your problem, please let me know if you have any more questions. Regards, Steven |
|
September 9, 2011, 11:47 |
field average after certain time works!
|
#3 |
Senior Member
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19 |
Hi Steven,
Many thanks! I compiled you piece of code and it works like a charm! This is much more convenient than all the struggling with trackDict etc., so thanks again Regards, Eelco |
|
September 10, 2011, 18:39 |
|
#4 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
The function object fieldAverage (which averages a field during time) is part of the regular OF distribution (you used the right library in your example). There is a functionObject volumeAverage in the simpleFunctionObjects which does something different: it averages the field at a time and prints this single value. The Information in the SFO-documentation about the after-parameter therefor applies only to volumeAverage but not fieldAverage |
||
September 12, 2011, 06:11 |
fieldAverage vs volumeAverage
|
#5 |
Senior Member
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19 |
Hi Bernard,
You are right, the after option is found in the volumeAverage and not in the fieldAverage manual. I erroneously assumed that it would be available for the fieldAverage too. The modified library posted by Steven adds the after option to the fieldAverage. Perhaps the 'after' option can be added to the official release of fieldAverage as well? About the trackDictionary: can you see why the reloading of the file fieldAverage does not work ? With this trick I tried to turn on averaging during a run (by modifying the file fieldAverage using fileUpdate), but some how is does not get reread by the solver, although it is defined in the trackDirctionary (and it is loaded at the start of the run, so it is seen correctly). Although with the modified fieldAverage library containing the 'after' option I don't use this trick anymore, I still think this combination of trackDictionary and fileUpdate can be quite powerful, so I would like it get it working. Any suggestion ? Regards Eelco |
|
September 13, 2011, 07:52 |
|
#6 | ||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Quote:
I'll ask Martin Beaudoin (the original author) about his opinion |
|||
September 13, 2011, 09:59 |
|
#7 |
Senior Member
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19 |
Hi Bernard
I have switched on runTimeModifiable to "yes" indeed. It looks as if this not taken into account though, since the dictionary is read correctly the first time, but not update when the file is updated. Well, it is a minor problem, may be I overlook something trivial. Anyway, I have added the request for the -after option to the mantis opencfd bug report, so hopefully it will be updated soon. Kind regards, Eelco |
|
September 14, 2011, 05:54 |
|
#8 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Saw that. Although I'm not 100% sure whether they know the volumeAverage-FO you're talking about |
||
September 15, 2011, 09:22 |
|
#9 |
Senior Member
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19 |
I was aware of include files not being reread if they get updated. If you have an include file and changes something manually during the run, it does not get updated, so what I do is I touch touch the controlDict, and then also the include file gets reread.
My first attempt was therefore to touch the controlDict during the run if I want to have to reread the include file automatically, but I could not figure out how to do that. However, with the trackDictionary trick, the file containing the fieldAveraging is never included in the controlDict anymore, because now it is defined in the trackDictionary list, i.e. it is read automatically. That is the reason why I have added a header to the include file, because trackDict expects that. I have added a sample in which I show my construction with fileUpdate and trackDict. If you run, you can see that at time t=20 the fieldAverage file indeed gets updated, but it is not reread by trackDictionary. The first time steps it does get read. Well, again, the trick is not required anymore with the custum fieldAverage lib (and hopefully later the newly updated fieldAverage including the -after option), however, it could be a quite powerful l construction. By the way, if controlDict (or one of the other files which are default in the reread list) is updated by fileUpdate, it is indeed read again. It only does not work for the user added file which are defined in trackDict. Well, just run my sample and you will see what happens. Regards, Eelco |
|
September 15, 2011, 11:59 |
|
#10 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Added Code:
wait { type systemCall; outputControl timeStep; outputInterval 1; writeCalls ( "sleep 1" ); } Bernhard |
||
September 19, 2011, 06:11 |
|
#11 |
Senior Member
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19 |
Bug in trackDictionary is reported now.
I saw that the -after option has been added to the new fieldAveraging functionobject now. Thanks for the quick feature fix! Regards Eelco |
|
May 24, 2012, 11:33 |
Starting field averaging using libFunctionObject after certain time
|
#12 |
New Member
Join Date: Jan 2012
Posts: 22
Rep Power: 14 |
Hi there,
This would be ideal for me if a similar method could be used to obtain the average for expressions created using swak4Foam. Does anyone know if this is possible? |
|
May 24, 2012, 11:58 |
|
#13 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Or do you mean this "after" thing (it is not obvious what you're referring to): all swak-functionObjects based on the simpleFunctionObjects have a "hidden" after-parameter that starts them after a certain time. For FOs that are not based on that there is also a solution but that is a bit more challenging. @time-average: if you want to time-average a whole field the solution would be to create a field foo with expressionField and then tell the regular fieldAverage-FO to average foo. For values on patches things are a bit more complicated but possible too (keywords: storedVariables and readAndUpdateFields) But if you tell me what you're trying to achieve then I can probably assist you ... if you promise to do a little write-up on the solution on the Wiki (doesn't have to be long) |
||
May 25, 2012, 05:30 |
Starting field averaging using libFunctionObject after certain time
|
#14 |
New Member
Join Date: Jan 2012
Posts: 22
Rep Power: 14 |
Thanks for responding so quickly!
Sorry, I should have been clearer about my question. I mean time-averaged, yes. Basically I have a simple setup with inlet and outlet patches and I currently use swak4Foam (patchExpression) in order to find the pressure difference as well as using some other custom expressions which I log and then plot via gnuplot. My goal is to be able to log (and potentially plot) time-averaged values (such as pressure difference) from the patchExpression outputs taking, for example, the last 25% of the iterations during the run. What would you suggest would be the best way forward? |
|
May 25, 2012, 06:39 |
|
#15 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Code:
timeAverageP { type patchExpression; verbose true; expression "averageP"; variables ( "relax=0.9;" "averageP=relax*averageP+(1-relax)*p;" ); storedVariables ( { name averageP; initialValue "p";. } ); accumulations ( min max average // this is not area weighted!!! Results are only correct if all patch faces are the same size ); } This should work with any swak4Foam-version from the last year. The nice thing is that the approach preserves the individual values until the accumulation. With the "readAndUpdateFields"-functionObject added to the development version you can generate a postprocessing field where a similar groovyBC is defined (so you can have a look at the spatial distribution in paraview .... or for instance record the pressure maxima to see "what is the maximum pressure where on the patch") If the above approach works for you it would be nice if you add it as a paragraph to the swak-Wiki-page |
||
May 25, 2012, 08:00 |
Starting field averaging using libFunctionObject after certain time
|
#16 |
New Member
Join Date: Jan 2012
Posts: 22
Rep Power: 14 |
I suppose you're right regarding reading the information in excel although it would be easier (well, nicer) to do everything in OF if possible like you say.
I've just added the code you supplied me with to the controlDict and from what I can see it works well in terms of the pressures at the inlet/outlet, looks to be a good workaround there! I am wondering if you could assist one final time by confirming how a custom expression can be introduced to the time-averaged code so that the expression itself can be time-averaged? Probably very simple and I may have been silly by asking this! I have a generic piece of code here: PRESSURE_DIFF { type patchExpression; variables ( "pOut{patch'outlet}=sum(p*area())/sum(area());"); accumulations ( average ); patches ( inlet ); expression "pOut-p"; verbose true; } Again, I am probably being silly but I would appreciate any help - new Foamer and exploring its capabilities (impressed so far!). |
|
May 25, 2012, 08:37 |
|
#17 | ||
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Quote:
Quote:
|
|||
August 7, 2012, 12:48 |
|
#18 | |
New Member
Getnet
Join Date: Aug 2011
Location: LSU
Posts: 20
Rep Power: 15 |
Quote:
scalar dt = obr_.time().deltaTValue(); forAll(faItems_, i) { if ( faItems_[i].prime2Mean() && meanFieldList[i].size() && prime2MeanFieldList[i].size() ) { const word& fieldName = faItems_[i].fieldName(); const fieldType1& baseField = obr_.lookupObject<fieldType1>(fieldName); const fieldType1& meanField = obr_.lookupObject<fieldType1>(meanFieldList[i]); fieldType2& prime2MeanField = const_cast<fieldType2&> ( obr_.lookupObject<fieldType2>(prime2MeanFieldList[i]) ); scalar Dt = totalTime_[i]; if (faItems_[i].iterBase()) { dt = 1.0; Dt = scalar(totalIter_[i]); } scalar alpha = (Dt - dt)/Dt; scalar beta = dt/Dt; if (faItems_[i].window() > 0) { const scalar w = faItems_[i].window(); if (Dt - dt >= w) { alpha = (w - dt)/w; beta = dt/w; } } prime2MeanField = alpha*prime2MeanField + beta*sqr(baseField) - sqr(meanField); } } } |
||
August 9, 2012, 06:05 |
|
#19 |
Senior Member
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19 |
I just replied to you private message.
Again: good back ground on this topic can be found here http://www.cfd-online.com/Forums/ope...ome-grids.html Regards Eelco |
|
August 10, 2012, 03:22 |
|
#20 |
New Member
Getnet
Join Date: Aug 2011
Location: LSU
Posts: 20
Rep Power: 15 |
Thanks a lot, I read the link and it is so helpful. I understand most of the mathematical derivations however, I am not still convinced in using the current mean value instead of the final mean. Gregor used in his mathematical derivation and sentence the following and it is not still clear for me. "The point is you want to have a variance every time step but your final mean value is unknown, therefore you take the current mean value. But once you use the current mean value the old mean values has to be taken out."
|
|
Tags |
libutilityfunctionobjects, swak4foam, timeactivatedfileupdate, trackdictionary |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Physical Reason for stability of Implicit Schemes? | radhakrishnan | Main CFD Forum | 26 | October 3, 2023 23:05 |
TwoPhaseEulerFoam and Boundary conditions | raagh77 | OpenFOAM Running, Solving & CFD | 99 | February 6, 2018 19:31 |
Field averaging in a certain time interval | misakagan | OpenFOAM Running, Solving & CFD | 1 | December 11, 2009 06:39 |
Convergence moving mesh | lr103476 | OpenFOAM Running, Solving & CFD | 30 | November 19, 2007 15:09 |
IcoFoam parallel woes | msrinath80 | OpenFOAM Running, Solving & CFD | 9 | July 22, 2007 03:58 |