|
[Sponsors] |
Cumulative averaging of a vectorField in OpenFOAM |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 10, 2023, 04:34 |
Cumulative averaging of a vectorField in OpenFOAM
|
#1 |
New Member
Join Date: Feb 2018
Posts: 17
Rep Power: 8 |
Hi,
The problem I have: I need to perform cumulative averaging on a vectorField. I don't know if I can use 'counters' as the main time loop is 2 levels above this piece of code. This writes out the surfaceVectorF every timestep!!! surfaceVectorF is initiated in createFields.H. Is there a way for the code to keep it in memory.. I'm not in the main code and this is 2 functions deep so is the only way to do this by putting a variable outside the main time loop? Or is there a more elegant way to achieve this? I found some threads here and on stackoverflow.. But none that really tackled this specific problem. Thanks! Part of my code that I wrote: Code:
vectorField vcField; //operations done on vcField that fill the values in if(currTimeIndex%label(meanInterval)) { Info << " Starting cumulative addition of vcField" <<endl; forAl(surfaceVectorF,i) { surfaceVectorF[i] += vcField[i]; } Info << "Writing out surfaceVectorF" << endl; surfaceVectorF.write(); } else if(meanInterval==1) { Info << "meanInterval = 1, no mean calculated" <<endl; forAll(surfaceVectorF,i) { surfaceVectorF[i] = vcField[i]; } } else { Info << "Calculate cumulative value for current timestep" <<endl; forAll(surfaceVectorF,i) { surfaceVectorF[i] += vcField[i]; } // not sure if cumulative addition and averaging can be done in the same loop... Info << "Calculate average value for current timestep" <<endl; forAll(surfaceVectorF,k) { surfaceVectorF[k] = surfaceVectorF[k]/label(meanInterval); } } |
|
July 16, 2023, 17:38 |
|
#2 |
New Member
Join Date: Feb 2018
Posts: 17
Rep Power: 8 |
Anybody? Please.
|
|
July 17, 2023, 06:57 |
|
#3 |
Senior Member
Yann
Join Date: Apr 2012
Location: France
Posts: 1,236
Rep Power: 29 |
Hello,
I don't know in which context you need a cumulative average, but isn't it what the fieldAverage function object does? https://www.openfoam.com/documentati...ldAverage.html Regards, Yann |
|
July 17, 2023, 09:38 |
|
#4 |
New Member
Join Date: Feb 2018
Posts: 17
Rep Power: 8 |
Hello,
The problem is that the fieldAverage is useful for post processing but in my case, after the cumulative average is calculated for the vectorField I want, I still have to perform other operations on it. This is not possible with the fieldAverage function.. Thanks!. |
|
July 17, 2023, 10:34 |
|
#5 |
Senior Member
Yann
Join Date: Apr 2012
Location: France
Posts: 1,236
Rep Power: 29 |
What other operations do you have to perform? If it's doable with functions object, you can use the results of fieldAverage to perform other operations.
Hope this helps, Yann |
|
July 17, 2023, 11:44 |
|
#6 |
New Member
Join Date: Feb 2018
Posts: 17
Rep Power: 8 |
Hi Yann,
The calculated mean value is used in the code to calculate the bed load flux which in turn is used to calculate the dynamic mesh movement based on exner equation. Can this be done with the post processing tool? If so, could you please let me know where i could find some info on that.? Thanks! |
|
July 18, 2023, 06:01 |
|
#7 |
Senior Member
Yann
Join Date: Apr 2012
Location: France
Posts: 1,236
Rep Power: 29 |
Hello rku,
If it was for post-processing purpose, you could have tried using fieldAverage then a coded function object to achieve whatever you want to do. But since you seem to be developing your own solver (am I right?) it's probably better to deal with it right in the solver itself. I'm afraid I cannot help much here, but maybe it's worth having a look at the fieldAverage source code, to check how the averaging is done there and use it as an inspiration for your own solver. Good luck with that! Yann |
|
July 18, 2023, 06:55 |
|
#8 |
New Member
Join Date: Feb 2018
Posts: 17
Rep Power: 8 |
Thank you for your time Yann!
Indeed, it is for my own solver.. I'll look into the source code for the fieldaverage function. Just thinking about it, I didn't think this was such a unique problem though that no one has ever tried to average a vectorfield over an interval of timesteps. (or more probably they aren't active on the forum anymore).. Cheers. |
|
July 19, 2023, 09:55 |
|
#9 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
This isn't anything particularly unique with the problem, but you either need to have the averaging field stored on the objectRegistry or make it a class member to have it remain persistent in memory. |
||
July 22, 2023, 04:26 |
|
#10 |
New Member
Join Date: May 2021
Posts: 5
Rep Power: 5 |
Hi rku,
Any variable produced in createFields.H is still in the scope of main(). The solver writes that surfaceField so that you can restart the simuation if it get's terminated by some reasopn. Further, you can use the default weighted averaging functions available along with several other field operations for geometricField<> object. I would recomment you to look into the geometric field class source file for same. If you want more specific answer, then you may have to explain more precisely the "cummallative Average" operation. Have a nice Day and do post a reply! Thanks and Regards Abhishek Singh |
|
July 24, 2023, 11:01 |
|
#11 |
New Member
Join Date: Feb 2018
Posts: 17
Rep Power: 8 |
Dear Abhishek Singh,
Thank you for your reply! The entire problem is that the operations available for the class vectorField (not vol or surface, just the base vectorField) are pretty lackluster. I tried to solve this problem a bit on my own again and I had a pretty basic question: Is it possible to interpolate a vectorField to a surfaceVectorField by assigning the geometrical information of each face to the each of the vector in vectorField? Or is it 'just not done' in Openfoam? Are there any examples of how the variables can be manipulated this way? Thank you all for your contributions! |
|
July 24, 2023, 14:40 |
|
#12 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Depends on what you mean by "lackluster". If you mean that there aren't any geometric operations for Field or vectorField, you are entirely correct. A Field is simply a List (which is a UList) with intrusive ref-counting (for managing tmps) and various operations such as +=, mag() etc.
Since a vectorField is a really low-level building block, it is used for both representing the internal fields (of a volume, area, point or surface mesh) as well as the parts of the boundary patch fields. If you need fields with associated geometric information, you should be using one of the GeometricFields (eg, volVectorField, surfaceVectorField etc). /mark |
|
Tags |
average field, cumulative, openfoam 5.x |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Map of the OpenFOAM Forum - Understanding where to post your questions! | wyldckat | OpenFOAM | 10 | September 2, 2021 06:29 |
OpenFOAM course for beginners | Jibran | OpenFOAM Announcements from Other Sources | 2 | November 4, 2019 09:51 |
Stuck in a Rut- interDyMFoam! | xoitx | OpenFOAM Running, Solving & CFD | 14 | March 25, 2016 08:09 |
OpenFOAM Training, London, Chicago, Munich, Sep-Oct 2015 | cfd.direct | OpenFOAM Announcements from Other Sources | 2 | August 31, 2015 14:36 |
Micro Scale Pore, icoFoam | gooya_kabir | OpenFOAM Running, Solving & CFD | 2 | November 2, 2013 14:58 |