
[Sponsors] 
September 1, 2020, 07:55 
Modified volFieldValue

#1 
New Member
Giovanni Farina
Join Date: Nov 2019
Posts: 2
Rep Power: 0 
Hi all,
I'm new to OpenFOAM and have very limited knowledge of C++, I'm trying to modify the volFieldValue postProcess function in order to calculate 'weighted' percentiles (weighted with alpha.water  I'm using a modified interFoam  and cells volume). I'm using openfoam6. I think I managed to compile a modified version of volFieldValue called "myvolFieldValue" without changing anything but adding a new operation (which doesn't do anything). Now I'm trying to implement my function: basically I want to sort "values" of concentration field in a certain region of my mesh from lowest to highest, at the same time sort corresponding cell volumes and alphas with the same order; then sum over indices (dividing by the total ) until I tick the various percentiles (0.05 , 0.15 etc.). I modified a quicksort algorithm in c++ but I can't define the right variable type for the arrays. It would be useful to reshape the arrays to simple vectors, I don't know if this is already done by volFieldValue when 'values', 'weightField' and 'V' are passed. I attach all relevant files, this is the main error (for now): fieldValues/myvolFieldValue/myvolFieldValueTemplates.C:230:14: error: cannot convert ‘const Foam::Field<double>’ to ‘const Foam::Field<double>*’ for argument ‘1’ to ‘void quickSort(const Foam::Field<double>*, const Foam::Field<double>*, const Foam::Field<double>*, int, int)’ quickSort(values, weightField, V, 0, n1); I also don't know if quicksort function definition is at the right place in the code and if I loop correctly over the fields once they are sorted. I apologise for my poor knowledge, any help would be much appreciated Giovanni 

September 11, 2020, 10:56 

#2 
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.io/
Posts: 1,001
Rep Power: 27 
Quote:
https://develop.openfoam.com/Develop...ListOps.H#L190 When doing your sorted order, you use the 'primitiveField()' method on your volume field to obtain the underlying plain 'Field' (no dimensions, no boundaries). With this sorted order (the cell Ids in the sorted order), you can then walk through your other fields. I guess you will have to do all of the binning on each local process and then sum/merge the results across all processors. 

October 2, 2020, 05:56 

#3  
New Member
Giovanni Farina
Join Date: Nov 2019
Posts: 2
Rep Power: 0 
Dear Mark,
Thank you very much! That's been very helpful! I managed to make it work with this code Quote:
Moreover, the run crashes (after 2438 s of computational time though) for floating point exception, but this maybe is related to solver and mesh refinement issues. I have also two other problems:  I don't know how to give different percentiles without defining more operations, I tried by defining more components of 'result' but it does not seem to work  More importantly, I really don't know how to run it on parallel: the distribution sorting needs to be done over all the region, it would be much more convenient to make calculations after recontructPar and reconstructParMesh (I'm using dynamic mesh, maybe this also gives some kind of issue), but I can't find how to do functionObject postprocessing after the run, I guess it's something quite feasible and you probably know Even partial solutions, guesses, or links to useful documentation/resources are welcome. (PS I will update this reply : the solver gives some unreasonably high values of max concentration and unreasonable low (negative) values of minimum concentration, this could vanishes with a more refined mesh; however, running on parallel is still a big issue) Giovanni Last edited by the_ichthyologist; October 2, 2020 at 07:32. 

October 3, 2020, 09:37 

#4 
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.io/
Posts: 1,001
Rep Power: 27 
Take a look at the forces function object for some ideas about "binning" into a histogram. There is a far bit of code to sift through, but sure you'll find something useful.


Tags 
coding, modified code, modified function, openfoam, postprocess function 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
[General] Extracting ParaView Data into Python Arrays  Jeffzda  ParaView  19  June 11, 2020 15:54 
Problem while compiling modified simpleFoam solver  mattiafc  OpenFOAM Programming & Development  0  May 26, 2020 20:01 
Modified simpleFOAM using given Reynolds stress field  K62  OpenFOAM Running, Solving & CFD  2  March 24, 2017 03:41 
Modified rhoCentralFoam slip boundary fails in parallel  ChrisA  OpenFOAM Programming & Development  0  June 25, 2014 20:28 
Modified Equation for CFX algorithm  Craig Johansen  CFX  0  August 27, 2004 23:02 