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

Min Max of scalarField

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 2 Post By alexeym
  • 2 Post By alexeym

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 5, 2014, 12:02
Default Min Max of scalarField
  #1
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 16
Andrea_85 is on a distinguished road
Hi All,

Do min and max function work for scalarField? something like

scalar xMin = min(myScalarField);
scalar xMax = max(myScalarField);

Do they work also in parallel?
I need to calcualte the minimum and maximum value of a vector during a parallel simulation and use them for some calculations. I got different values when using or not the "reduce" command on xMin and xMax and it looks like i get the correct values when "reduce" is not used. I am a bit confused.

Which is the best/correct way to calculate minimum and maximum value of a scalarField during a parallel run?

Thanks

Andrea
Andrea_85 is offline   Reply With Quote

Old   November 5, 2014, 13:44
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

if you just use min or max you get minimum/maximum on a processor. In case of serial run you've got one process, so value is unique. In case of parallel run you can either use gMax/gMin functions (they do reduce thing for you), or first do min/max to get minimum/maximum on a processor and then do reduce to get minimum/maximum of all processors.
alexeym is offline   Reply With Quote

Old   November 5, 2014, 14:47
Default
  #3
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 16
Andrea_85 is on a distinguished road
Hi Alexey,

thank you for interesting in my post.
Which is the correct sintax for the reduce operations? Something like

reduce(xMin, minOp<scalar>());
reduce(xMax, maxOp<scalar>());

i will also try with gmax/gmin...

thanks again

andrea
Andrea_85 is offline   Reply With Quote

Old   November 5, 2014, 15:02
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Well, if you take a look at src/OpenFOAM/fields/Fields/Field/FieldFunctions.C

Code:
#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc)                      \
                                                                              \
template<class Type>                                                          \
ReturnType gFunc(const UList<Type>& f, const int comm)                        \
{                                                                             \
    ReturnType res = Func(f);                                                 \
    reduce(res, rFunc##Op<Type>(), Pstream::msgType(), comm);                 \
    return res;                                                               \
}                                                                             \
TMP_UNARY_FUNCTION(ReturnType, gFunc)
    
G_UNARY_FUNCTION(Type, gMax, max, max)
G_UNARY_FUNCTION(Type, gMin, min, min)
so gMax will be preprocessed into

Code:
template<class Type>
Type gMax(const UList<Type>& f, const int comm)
{
    Type res = max(f);
    reduce(res, maxOp<type>(), Pstream::msgType(), comm);
    return res;
}
...
so, yes, for scalar field reduce call will be

Code:
reduce(xMax, maxOp<scalar>());
kaifu and mm.abdollahzadeh like this.
alexeym is offline   Reply With Quote

Reply


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
y+ and u+ values with low-Re RANS turbulence models: utility + testcase florian_krause OpenFOAM 114 August 23, 2023 05:37
multiphase turbulance case floating error harsha_kulkarni OpenFOAM Running, Solving & CFD 3 February 18, 2016 05:06
Problem of simulating of small droplet with radius of 2mm liguifan OpenFOAM Running, Solving & CFD 5 June 3, 2014 02:53
On the damBreak4phaseFine cases paean OpenFOAM Running, Solving & CFD 0 November 14, 2008 21:14
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 18:07


All times are GMT -4. The time now is 00:24.