CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Cumulative averaging of a vectorField in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 10, 2023, 04:34
Question Cumulative averaging of a vectorField in OpenFOAM
  #1
rku
New Member
 
Join Date: Feb 2018
Posts: 17
Rep Power: 8
rku is on a distinguished road
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);
                                }
                         }
rku is offline   Reply With Quote

Old   July 16, 2023, 17:38
Default
  #2
rku
New Member
 
Join Date: Feb 2018
Posts: 17
Rep Power: 8
rku is on a distinguished road
Anybody? Please.
rku is offline   Reply With Quote

Old   July 17, 2023, 06:57
Default
  #3
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,236
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
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
Yann is offline   Reply With Quote

Old   July 17, 2023, 09:38
Default
  #4
rku
New Member
 
Join Date: Feb 2018
Posts: 17
Rep Power: 8
rku is on a distinguished road
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!.
rku is offline   Reply With Quote

Old   July 17, 2023, 10:34
Default
  #5
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,236
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
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
Yann is offline   Reply With Quote

Old   July 17, 2023, 11:44
Default
  #6
rku
New Member
 
Join Date: Feb 2018
Posts: 17
Rep Power: 8
rku is on a distinguished road
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!
rku is offline   Reply With Quote

Old   July 18, 2023, 06:01
Default
  #7
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,236
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
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
Yann is offline   Reply With Quote

Old   July 18, 2023, 06:55
Default
  #8
rku
New Member
 
Join Date: Feb 2018
Posts: 17
Rep Power: 8
rku is on a distinguished road
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.
rku is offline   Reply With Quote

Old   July 19, 2023, 09:55
Default
  #9
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by rku View Post
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.

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.
olesen is offline   Reply With Quote

Old   July 22, 2023, 04:26
Default
  #10
New Member
 
Join Date: May 2021
Posts: 5
Rep Power: 5
abhishekmonu96` is on a distinguished road
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
abhishekmonu96` is offline   Reply With Quote

Old   July 24, 2023, 11:01
Default
  #11
rku
New Member
 
Join Date: Feb 2018
Posts: 17
Rep Power: 8
rku is on a distinguished road
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!
rku is offline   Reply With Quote

Old   July 24, 2023, 14:40
Default
  #12
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
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
olesen is offline   Reply With Quote

Reply

Tags
average field, cumulative, openfoam 5.x


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 15:57.