CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Running, Solving & CFD

volum integral of mag(U)...?

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree6Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   February 27, 2012, 05:31
Default volum integral of mag(U)...?
  #1
Member
 
Tom
Join Date: Jan 2012
Location: France
Posts: 43
Rep Power: 4
sawyer86 is on a distinguished road
Hi there,

my question is how is possible to get the scalar value of the volume integral of the mag(U) in OpenFoam?

To me it will be ok at least to know what is the function/command/whatever that allow to compute the scalar value of the volume integral of mag(U) for a given mesh...

thank you very much in advance!
MPJ likes this.
sawyer86 is offline   Reply With Quote

Old   February 28, 2012, 04:06
Default
  #2
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,880
Rep Power: 25
alberto will become famous soon enoughalberto will become famous soon enough
The fast way (but not necessarily the easy one ), if you use OpenFOAM 2.1.x, is to add this piece of code to the controlDict of your case:

Code:
functions
(
  magUIntegral
  {
    functionObjectLibs ("libutilityFunctionObjects.so");
    type coded;
    redirectType integral;
    outputControl timeStep;
    code
    #{
      const volVectorField& U = mesh().lookupObject<volVectorField>("U");
      volScalarField magU(mag(U));

      scalar volIntegral = 0;

      forAll (magU, cellI)
      {
    volIntegral += magU[cellI]*mesh().V()[cellI];
      }

      Info<<"Volume integral: " << volIntegral << endl;

    #};
  }
);
To be able to run the case, you must allow system operations in the system controlDict. You have to locate it with

foamEtcFile controlDict

and change

allowSystemOperations 1;

When you run the code the first time, OpenFOAM will compile the additional code, and print the volume integral at each time step.
elvis, Toorop and Nucleophobe like this.
__________________
Alberto

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as live DVD/USB, hard drive image and virtual image.
GeekoCFD 32bit - The 32bit edition of GeekoCFD.
GeekoCFD text mode - A smaller version of GeekoCFD, text-mode only, with only OpenFOAM. Available in a variety of virtual formats.
alberto is offline   Reply With Quote

Old   February 28, 2012, 04:08
Default
  #3
Member
 
Tom
Join Date: Jan 2012
Location: France
Posts: 43
Rep Power: 4
sawyer86 is on a distinguished road
Quote:
Originally Posted by alberto View Post
The fast way (but not necessarily the easy one ), if you use OpenFOAM 2.1.x, is to add this piece of code to the controlDict of your case:

Code:
functions
(
  magUIntegral
  {
    functionObjectLibs ("libutilityFunctionObjects.so");
    type coded;
    redirectType integral;
    outputControl timeStep;
    code
    #{
      const volVectorField& U = mesh().lookupObject<volVectorField>("U");
      volScalarField magU(mag(U));

      scalar volIntegral = 0;

      forAll (magU, cellI)
      {
    volIntegral += magU[cellI]*mesh().V()[cellI];
      }

      Info<<"Volume integral: " << volIntegral << endl;

    #};
  }
);
To be able to run the case, you must allow system operations in the system controlDict. You have to locate it with

foamEtcFile controlDict

and change

allowSystemOperations 1;

When you run the code the first time, OpenFOAM will compile the additional code, and print the volume integral at each time step.
Thank you very much Alberto! I will test it but it seems to be very useful and smart!

Regards
sawyer86 is offline   Reply With Quote

Old   February 28, 2012, 04:48
Default
  #4
Member
 
Tom
Join Date: Jan 2012
Location: France
Posts: 43
Rep Power: 4
sawyer86 is on a distinguished road
Quote:
Originally Posted by alberto View Post
The fast way (but not necessarily the easy one ), if you use OpenFOAM 2.1.x, is to add this piece of code to the controlDict of your case:

Code:
functions
(
  magUIntegral
  {
    functionObjectLibs ("libutilityFunctionObjects.so");
    type coded;
    redirectType integral;
    outputControl timeStep;
    code
    #{
      const volVectorField& U = mesh().lookupObject<volVectorField>("U");
      volScalarField magU(mag(U));

      scalar volIntegral = 0;

      forAll (magU, cellI)
      {
    volIntegral += magU[cellI]*mesh().V()[cellI];
      }

      Info<<"Volume integral: " << volIntegral << endl;

    #};
  }
);
To be able to run the case, you must allow system operations in the system controlDict. You have to locate it with

foamEtcFile controlDict

and change

allowSystemOperations 1;

When you run the code the first time, OpenFOAM will compile the additional code, and print the volume integral at each time step.
Hi Alberto,

i did what you suggest me, and it works good!

But how can I do to print the value of run.Time and the mag(U) in a file instead than to screen...without modify the code, that means always in the controlDict...?

Thank you in advance...
sawyer86 is offline   Reply With Quote

Old   February 28, 2012, 13:02
Default
  #5
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,880
Rep Power: 25
alberto will become famous soon enoughalberto will become famous soon enough
You can store the execution log, and process it to extract the values you need (and the corresponding times) with the standard Linux utilities.

As an alternative, you could try to open a text file in the code snippet, but I am not sure it's going to work.
__________________
Alberto

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as live DVD/USB, hard drive image and virtual image.
GeekoCFD 32bit - The 32bit edition of GeekoCFD.
GeekoCFD text mode - A smaller version of GeekoCFD, text-mode only, with only OpenFOAM. Available in a variety of virtual formats.
alberto is offline   Reply With Quote

Old   February 29, 2012, 03:17
Default
  #6
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 912
Rep Power: 16
akidess will become famous soon enough
If I may shamelessly promote my own utility here:

http://code.google.com/p/foamcalcex/

I extended the standard foamCalc tool to support min, max and volumeIntegrate calculations.

Code:
foamCalcEx mag U
foamCalcEx volIntegrate magU > data.txt
The above lines will write the volume integral into a text file data.txt.
Nucleophobe and banji like this.
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
*Check out the scientific computing exchange http://scicomp.stackexchange.com
akidess is offline   Reply With Quote

Old   February 29, 2012, 09:31
Default
  #7
Senior Member
 
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 119
Rep Power: 8
eelcovv is on a distinguished road
Hi Anton,

Seems to be an interesting utility. I would like to check it out, but the hg clone command as described on your page does not work for me. Could you upload a tar-ball to the forum with source ?
Thanks!
Eelco
eelcovv is offline   Reply With Quote

Old   February 29, 2012, 10:14
Default
  #8
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 912
Rep Power: 16
akidess will become famous soon enough
Eelco, did you use this link: https://code.google.com/p/foamcalcex/ ?

I'm attaching a tarball with the code to this post. Let me know if you have any troubles with it.
Attached Files
File Type: gz foamcalcex.tar.gz (65.6 KB, 49 views)
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
*Check out the scientific computing exchange http://scicomp.stackexchange.com
akidess is offline   Reply With Quote

Old   February 29, 2012, 11:07
Default
  #9
Senior Member
 
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 119
Rep Power: 8
eelcovv is on a distinguished road
Hi Anton,

Yes, and then I tried

hg clone https://code.google.com/p/foamcalcex/

but this hg think does not work properly on our system Anyway, I will try you ultility.
Thanks!
Eelco
eelcovv is offline   Reply With Quote

Old   March 7, 2012, 10:52
Default
  #10
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 260
Rep Power: 6
Andrea_85 is on a distinguished road
Hi Anton,
I downloaded and compiled your utility (i put it under OpenFoam/application/utility/postprocessing/miscellaneous/ but now how can i use it?
neither ./foamCalcEx nor foamCalcEx works.

best

andrea
Andrea_85 is offline   Reply With Quote

Old   March 7, 2012, 11:49
Default
  #11
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 912
Rep Power: 16
akidess will become famous soon enough
Andrea, are you sure it compiled correctly, and that you started your foam environment? At the end of the compilation, you will see the location of the executable (highlighted in red here):

Code:
g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter \ 
-Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 \ 
-I/home/user/OpenFOAM/OpenFOAM-2.0.x/src/finiteVolume/lnInclude \
-I../postProcessing/foamCalcFunctionsEx/lnInclude/ -IlnInclude -I. \ 
-I/home/user/OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude \
-I/home/user/OpenFOAM/OpenFOAM-2.0.x/src/OSspecific/POSIX/lnInclude  \
 -fPIC -Xlinker --add-needed Make/linux64GccDPOpt/foamCalc.o -L/home/user/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64GccDPOpt/lib \
             -lfiniteVolume     -lgenericPatchFields -L/home/user/OpenFOAM/akidess-2.0.x/platforms/linux64GccDPOpt/lib \ 
-lfoamCalcFunctionsEx -lOpenFOAM -ldl   -lm -o /home/user/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64GccDPOpt/bin/foamCalcEx
This corresponds to ${FOAM_APPBIN}/foamCalcEx. You should be able to call the tool using "foamCalcEx". "./foamCalcEx" will generally NOT work.

- Anton
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
*Check out the scientific computing exchange http://scicomp.stackexchange.com
akidess is offline   Reply With Quote

Old   March 7, 2012, 11:56
Default
  #12
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 260
Rep Power: 6
Andrea_85 is on a distinguished road
Hi Anton,
i used ./Allwmake and this is what i got

Code:
+ wmake libo postCalc
wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file postCalc.C
SOURCE=postCalc.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/postCalc.o
ld -r -o /home/aferrari/OpenFOAM/OpenFOAM-2.1.0/platforms/linux64GccDPOpt/lib/postCalc.o Make/linux64GccDPOpt/postCalc.o
'/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/platforms/linux64GccDPOpt/lib/postCalc.o' is up to date.
+ wmake libso foamCalcFunctionsEx
wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file calcType/calcType.C
Making dependency list for source file calcType/calcTypeNew.C
Making dependency list for source file field/components/components.C
Making dependency list for source file field/mag/mag.C
Making dependency list for source file field/magSqr/magSqr.C
Making dependency list for source file field/magGrad/magGrad.C
Making dependency list for source file field/div/div.C
Making dependency list for source file field/randomise/randomise.C
Making dependency list for source file field/interpolate/interpolate.C
Making dependency list for source file field/min/min.C
Making dependency list for source file field/max/max.C
Making dependency list for source file field/maxAbs/maxAbs.C
Making dependency list for source file field/volIntegrate/volIntegrate.C
Making dependency list for source file basic/addSubtract/addSubtract.C
SOURCE=calcType/calcType.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/calcType.o
SOURCE=calcType/calcTypeNew.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/calcTypeNew.o
SOURCE=field/components/components.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/components.o
SOURCE=field/mag/mag.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/mag.o
SOURCE=field/magSqr/magSqr.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/magSqr.o
SOURCE=field/magGrad/magGrad.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/magGrad.o
SOURCE=field/div/div.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/div.o
SOURCE=field/randomise/randomise.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/randomise.o
SOURCE=field/interpolate/interpolate.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/interpolate.o
SOURCE=field/min/min.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/min.o
SOURCE=field/max/max.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/max.o
SOURCE=field/maxAbs/maxAbs.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/maxAbs.o
SOURCE=field/volIntegrate/volIntegrate.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/volIntegrate.o
SOURCE=basic/addSubtract/addSubtract.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OpenFOAM/lnInclude -I/home/aferrari/OpenFOAM/OpenFOAM-2.1.0/src/OSspecific/POSIX/lnInclude   -fPIC -c $SOURCE -o Make/linux64GccDPOpt/addSubtract.o
'/home/aferrari/OpenFOAM/aferrari-2.1.0/platforms/linux64GccDPOpt/lib/libfoamCalcFunctionsEx.so' is up to date.
actually i cannot see the executable.
i'm using OF 2.1.0 as you can see.


best

andrea
Andrea_85 is offline   Reply With Quote

Old   March 7, 2012, 12:27
Default
  #13
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 912
Rep Power: 16
akidess will become famous soon enough
You just compiled the post-processing libraries postCalc and foamCalcFunctionsEx, but not the application. I think you are in the wrong directory.

The directory tree should look like this:

Code:
foamcalcex
---- Allwmake
---- foamCalcExApp
-------- foamCalc.C
-------- Make
---- postProcessing
-------- Allwmake
-------- foamCalcFunctionsEx
-------- postCalc
Are you using the Allwmake script in the top level directory?
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
*Check out the scientific computing exchange http://scicomp.stackexchange.com
akidess is offline   Reply With Quote

Old   March 7, 2012, 15:17
Default
  #14
Senior Member
 
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 119
Rep Power: 8
eelcovv is on a distinguished road
Hi Alberto,

I tried you piece of code to do the volume averaging. It works, so this is very useful. Thanks for that! Only one thing: it seems that it does not work if I run the code in parallel. Any quick example how to deal with that ?

Thanks!

Regards
Eelco
eelcovv is offline   Reply With Quote

Old   March 8, 2012, 04:07
Default
  #15
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 260
Rep Power: 6
Andrea_85 is on a distinguished road
Hi,
you area right Anton, i was copiling from second level.
Thanks

andrea
Andrea_85 is offline   Reply With Quote

Old   March 26, 2012, 04:23
Default
  #16
Member
 
Laurens Van Dyck
Join Date: Jul 2011
Location: Netherlands/Germany
Posts: 34
Rep Power: 4
laurensvd is on a distinguished road
Quote:
Originally Posted by eelcovv View Post
Hi Alberto,

I tried you piece of code to do the volume averaging. It works, so this is very useful. Thanks for that! Only one thing: it seems that it does not work if I run the code in parallel. Any quick example how to deal with that ?

Thanks!

Regards
Eelco
I have the same problem with a code which I wrote myself. I use the same code in a boundary condition code and it works but when I try it with the coded functions it crashes when using parallel. Any idea on how we can fix this (Alberto)?

Ok after searching for a day I find the solution right after posting this Very typical

Quote:
in OpenFoam-2.x.x/etc/controlDict, you need to change this line to

fileModificationChecking timeStamp;
Also, is there a reason (performance/accuracy) that you calculate the volume integral by looping over the cells instead of using the standard fvc::domainIntegrate(field).value() function?

Last edited by laurensvd; March 26, 2012 at 04:49.
laurensvd is offline   Reply With Quote

Old   March 26, 2012, 04:46
Default
  #17
Senior Member
 
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 119
Rep Power: 8
eelcovv is on a distinguished road
I reported it as a bug at Mantis. The error can be avoided by the following suggestion

'As a workaround switch off the 'masterOnly' file reading (set fileModificationChecking to timeStamp instead of timeStampMaster) in the etc/controlDict (or your personal one). '

So copy the $FOAM_INST_DIR/etc/bashrc

to the directory (create is if you dont have it yet, with the appropriate OF version of course)

$HOME/.OpenFOAM/2.1.0/

and change line with timeStampMaster

Eelco
eelcovv is offline   Reply With Quote

Old   March 26, 2012, 05:05
Default
  #18
Member
 
Laurens Van Dyck
Join Date: Jul 2011
Location: Netherlands/Germany
Posts: 34
Rep Power: 4
laurensvd is on a distinguished road
I found it minutes earlier in another posts of yours.

Bedankt
laurensvd is offline   Reply With Quote

Old   March 26, 2012, 07:30
Default
  #19
Senior Member
 
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 119
Rep Power: 8
eelcovv is on a distinguished road
I just saw your remark on the fvc::domainIntegrate. Thanks for that hint! I did not know this function. I just worked out the parallelisation of the routine for manually integrating over the cell. In case of a parallel run, this requires that information from the slave is explicitely communicated to the master. The makes the scripting error prone and more complex. I just tried you domainIntegrate function, and now live gets much more easy. I reprogrammed the script and checked it: the results are identical.

In case anybody is interested for an example of code funtions of both example: I try to obain the average position of a single gas bubble in a grid by calculating int_(gasfraction*position)/int_(gasfraction). My first version uses the explicite integration

Code:
bubblePosition
{
    functionObjectLibs ("libutilityFunctionObjects.so");
    type coded;
    redirectType average;
    outputControl timeStep;
    code
    #{
      const volScalarField& alpha1=mesh().lookupObject<volScalarField>("alpha1");

      scalar sumGasFraction = 0;
      vector sumGasPosition  = vector(0,0,0);

      // store number of processors np and current processor id
      label np=Pstream::nProcs();
      label id=Pstream::myProcNo();

      // loop over the cells and caclutate integral of gasfraction*position
      forAll (alpha1, cellI)
      {
         scalar gf=(1-alpha1[cellI])*mesh().V()[cellI];
         vector pos=mesh().C()[cellI];
         sumGasFraction += gf;
         sumGasPosition += gf*pos;
      }

      if(id==0)
      {
         // on the master: receive values from other nodes
         scalar getSumGasFraction=0;
         vector getSumGasPosition=vector(0,0,0);

         for(label i=1; i<np; i++)
         {
            // receive a stream with heat flux and area from the others
            IPstream vStream(Pstream::blocking, i);
            vStream >> getSumGasFraction >> getSumGasPosition;
            sumGasFraction += getSumGasFraction;
            sumGasPosition += getSumGasPosition;
         }
 
         // report mean bubble position
         vector meanBubblePosition=vector(0,0,0);
         if(sumGasFraction>0)
         {
            meanBubblePosition=sumGasPosition/sumGasFraction;
            Info<<"Mean bubble position : " << meanBubblePosition << endl;
         }
         else
         {
            Info<<"No gas present." << endl;
         }
      }
      else
      {
         // on the slaves: send info to the master node
         OPstream infoStream (Pstream::blocking, 0);
         infoStream << sumGasFraction << sumGasPosition;
      }
    #};
}
It works, however, is quite a long script for something simple. Now the domainIntegrate version of the same routine

Code:
bubblePosition
{
    functionObjectLibs ("libutilityFunctionObjects.so");
    type coded;
    redirectType average;
    outputControl timeStep;
    code
    #{
      const volScalarField& alpha1=mesh().lookupObject<volScalarField>("alpha1");
      const volVectorField& positions=mesh().C();

      scalar sumGasFrc=fvc::domainIntegrate((1-alpha1)).value();
      vector sumGasPos=fvc::domainIntegrate((1-alpha1)*positions).value();

      vector meanBubblePosition=vector(0,0,0);
      if(sumGasFrc>0)
      {
         meanBubblePosition=sumGasPos/sumGasFrc;
         Info<<"Mean bubble position : " << meanBubblePosition << endl;
      }
      else
      {
         Info<<"No gas present." << endl;
      }

    #};
}
Much shorter, and it yields exactly the same result (in both serial and parallel mode) as the first example. In order words, I would recommend the domainIntegrate version.

Regards
Eelco
eelcovv is offline   Reply With Quote

Old   March 26, 2012, 10:07
Default
  #20
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,880
Rep Power: 25
alberto will become famous soon enoughalberto will become famous soon enough
Quote:
Originally Posted by laurensvd View Post
I have the same problem with a code which I wrote myself. I use the same code in a boundary condition code and it works but when I try it with the coded functions it crashes when using parallel. Any idea on how we can fix this (Alberto)?

Ok after searching for a day I find the solution right after posting this Very typical
It was cited already, but for reference: http://www.openfoam.org/mantisbt/view.php?id=480

Quote:
Also, is there a reason (performance/accuracy) that you calculate the volume integral by looping over the cells instead of using the standard fvc::domainIntegrate(field).value() function?
No preference, they are equivalent in terms of accuracy and performance. The only difference is that fvc::domainIntegrate uses gsum to perform the summation, and, as such, takes advantage of parallelization.

Best,
__________________
Alberto

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as live DVD/USB, hard drive image and virtual image.
GeekoCFD 32bit - The 32bit edition of GeekoCFD.
GeekoCFD text mode - A smaller version of GeekoCFD, text-mode only, with only OpenFOAM. Available in a variety of virtual formats.
alberto is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
RANS in integral form siw Main CFD Forum 0 August 17, 2010 03:18
please help to patch volum of secondary phase VOF zidouni FLUENT 1 February 27, 2008 05:46
monitor surface integral & report surface integral Ning FLUENT 0 March 18, 2007 13:51
Evaluation of boundary integral aunola Main CFD Forum 0 May 8, 2006 07:54
Von Karman Integral Length Scale Txingurri Main CFD Forum 0 May 2, 2002 12:05


All times are GMT -4. The time now is 20:13.