Starting field averaging using libFunctionObject after certain time
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 Code:
fieldAverage1 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 Code:
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 Code:
/*--------------------------------*- C++ -*----------------------------------*\ 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 Hopefully anybody sees what goes wrong with the trackDictionary/fileUpdate procedure. Any hints appreciated! Regards Eelco |
1 Attachment(s)
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 |
field average after certain time works!
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 |
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 |
fieldAverage vs volumeAverage
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 |
Quote:
Quote:
I'll ask Martin Beaudoin (the original author) about his opinion |
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 |
Quote:
Quote:
|
1 Attachment(s)
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 |
Quote:
Added Code:
Bernhard |
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 |
Starting field averaging using libFunctionObject after certain time
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? |
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) |
Starting field averaging using libFunctionObject after certain time
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? |
Quote:
Code:
timeAverageP { 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 |
Starting field averaging using libFunctionObject after certain time
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!). |
Quote:
Quote:
|
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); } } } |
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 |
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."
|
solution to non updating trackDict
The answer can be found in the function object source code: the fileModificationSkew si not allowed to be too large. Just create a directory
$HOME/.OpenFOAM/2.2.x or what ever you version is, copy $WM_PROJECT_DIR/etc/controlDict to this directory and modify the line fileModificationSkew 30 to something smaller. Then an update of a dictionary being tracked will result in a reread of it. Regards Eelco |
reread the subdictionaries from an regIOobject
One more question on this topic
When a dictionary is re-read after an file-update, only the content at the 'top-level is read, not the sub-dictionaries. This can be seen in the file $FOAM_SRC/OpenFOAM/db/regIOobject/regIOobjectRead.C, line 285-292. It says: reread object name(), which is the name of the dictionary. however, sometimes you want to read the subdictionaries as well. For instance in kinematicCloudProperties, you want to update the mass flow rate of the injectors by modifying the file during the run. Is there an easy way to force OF to re-read the subdictionaries during a run ? Well, not so important, but it would be handy Thanks for the hints! Regards Eelco |
Hello Everyone
I am beginner in OpenFoam, may be my question looks very busy, I am sorry for that. I am using fieldAverage to get time-averaged of velocity. I get the time-averaged file in respective time step folder but I don't know how can I view this average field using paraview. When I load my case to paraview, it shows only entities which are present in "0" folder. It does not show averaged field i.e. UMean Regards Waqas |
Hello Steven,
I am using 2.2.x version of OpenFoam. The averaging utility you attached give me a compilation error. Do you have an updated version of this utility? I greatly appreciate your support. MMMN |
compile field meet error
Hi, Steven !I also want to start field averaging at a certain time when the field is fully developed.I down load the field.zip and unzip it.Then I put the directory at the path home/OpenFoam and run 'wmake libso' to compile it. But it come to error like this:
[hpc@hpcserver:~/OpenFOAM/field$ wmake libso SOURCE=fieldAverage/fieldAverage/fieldAverage.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam222/src/finiteVolume/lnInclude -I/opt/openfoam222/src/meshTools/lnInclude -I/opt/openfoam222/src/lagrangian/basic/lnInclude -I/opt/openfoam222/src/sampling/lnInclude -IlnInclude -I. -I/opt/openfoam222/src/OpenFOAM/lnInclude -I/opt/openfoam222/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64GccDPOpt/fieldAverage.o In file included from /opt/openfoam222/src/OpenFOAM/lnInclude/className.H:34:0, from /opt/openfoam222/src/OpenFOAM/lnInclude/typeInfo.H:57, from /opt/openfoam222/src/OpenFOAM/lnInclude/token.H:46, from /opt/openfoam222/src/OpenFOAM/lnInclude/Istream.H:47, from /opt/openfoam222/src/OpenFOAM/lnInclude/ISstream.H:39, from /opt/openfoam222/src/OpenFOAM/lnInclude/IOstreams.H:38, from /opt/openfoam222/src/OpenFOAM/lnInclude/VectorSpace.C:27, from /opt/openfoam222/src/OpenFOAM/lnInclude/VectorSpace.H:171, from /opt/openfoam222/src/OpenFOAM/lnInclude/Vector.H:44, from /opt/openfoam222/src/OpenFOAM/lnInclude/vector.H:39, from /opt/openfoam222/src/OpenFOAM/lnInclude/fieldTypes.H:35, from /opt/openfoam222/src/finiteVolume/lnInclude/volFieldsFwd.H:37, from fieldAverage/fieldAverage/fieldAverage.H:88, from fieldAverage/fieldAverage/fieldAverage.C:26: /opt/openfoam222/src/OpenFOAM/lnInclude/debugName.H:45:11: error: ?.ddFoam?.has not been declared class add##Tag##ToDebug \ ^ /opt/openfoam222/src/OpenFOAM/lnInclude/debugName.H:125:5: note: in expansion of macro ?.egisterDebugSwitchWithName? registerDebugSwitchWithName(Type, Type, Type::typeName_()) ^ /opt/openfoam222/src/OpenFOAM/lnInclude/className.H:145:5: note: in expansion of macro ?.efineDebugSwitch? defineDebugSwitch(Type, DebugSwitch) ^ fieldAverage/fieldAverage/fieldAverage.C:34:1: note: in expansion of macro ?.efineTypeNameAndDebug? defineTypeNameAndDebug(Foam::fieldAverage, 0); ^ /opt/openfoam222/src/OpenFOAM/lnInclude/debugName.H:46:5: error: expected unqualified-id before ?.?.token : \ ^ /opt/openfoam222/src/OpenFOAM/lnInclude/debugName.H:125:5: note: in expansion of macro ?.egisterDebugSwitchWithName? registerDebugSwitchWithName(Type, Type, Type::typeName_()) ^ /opt/openfoam222/src/OpenFOAM/lnInclude/className.H:145:5: note: in expansion of macro ?.efineDebugSwitch? defineDebugSwitch(Type, DebugSwitch) ^ fieldAverage/fieldAverage/fieldAverage.C:34:1: note: in expansion of macro ?.efineTypeNameAndDebug? defineTypeNameAndDebug(Foam::fieldAverage, 0); ^ make: *** [Make/linux64GccDPOpt/fieldAverage.o] Error 1] could you tell me how to fix the errors ? Quote:
|
Hello, do you solver the problem caused by the different version? My OPENFOAM is the 2.2.2version.
Quote:
|
All times are GMT -4. The time now is 10:25. |