CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Post-Processing

How to calculate CoG in interDyMFoam

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

Reply
 
LinkBack Thread Tools Display Modes
Old   January 12, 2012, 17:40
Default How to calculate CoG in interDyMFoam
  #1
Member
 
angel
Join Date: May 2009
Location: Spain
Posts: 46
Rep Power: 8
anmartin is on a distinguished road
Hello,
I would like to calculate the centre of gravity of liquid fraction in a sloshing simulation.
Are there any options to calculate it in OF or in Paraview?

Regards
Angel
anmartin is offline   Reply With Quote

Old   January 12, 2012, 19:58
Default
  #2
Senior Member
 
sail's Avatar
 
Vieri Abolaffio
Join Date: Jul 2010
Location: Always on the move.
Posts: 308
Rep Power: 7
sail is on a distinguished road
Quote:
Originally Posted by anmartin View Post
Hello,
I would like to calculate the centre of gravity of liquid fraction in a sloshing simulation.
Are there any options to calculate it in OF or in Paraview?

Regards
Angel
Hi angel.

i have never done it by myself, but i would use the threshold filter to selct just the cells with alpha_water > 0.5, and than use the calculator filter, in conjunction with each cell's coordinates and volumes, to obtain a new array with just one value.


good luck
__________________
http://www.leadingedge.it/
Naval architecture and CFD consultancy
sail is offline   Reply With Quote

Old   January 12, 2012, 21:16
Default
  #3
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,912
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by anmartin View Post
Hello,
I would like to calculate the centre of gravity of liquid fraction in a sloshing simulation.
Are there any options to calculate it in OF or in Paraview?

Regards
Angel
You mean by calculating the weighted average of position of all the cells? Like this:

sum(pos()*alpha1*vol())/(vol()*alpha1)

In swak4Foam there is a functionobject swakExpression where the line

expression "sum(pos()*alpha1*vol())/(vol()*alpha1)";

will print exactly that at every timestep (OK. you've got to add a bit more to the controlDict, but it is less than 20 lines)
gschaider is offline   Reply With Quote

Old   January 23, 2012, 10:53
Default
  #4
Member
 
angel
Join Date: May 2009
Location: Spain
Posts: 46
Rep Power: 8
anmartin is on a distinguished road
Quote:
Originally Posted by gschaider View Post
You mean by calculating the weighted average of position of all the cells? Like this:

sum(pos()*alpha1*vol())/(vol()*alpha1)

In swak4Foam there is a functionobject swakExpression where the line

expression "sum(pos()*alpha1*vol())/(vol()*alpha1)";

will print exactly that at every timestep (OK. you've got to add a bit more to the controlDict, but it is less than 20 lines)
Hello,
First at all, many thanks to Bernhard and Vieri for your quick response.
I’ve tried first, with swak4foam and after installed and read yours presentations, I finally discovered one easy way to obtain the cog that works for me, but not very smart, because in can’t remove the floating point exception.
This is my controlDict, with the different options that I have tried, and the results obtained, included the error:
libs (
"libsimpleSwakFunctionObjects.so"
"libswakFunctionObjects.so"
);
functions
{
liquid_COG //simpleFunctionObjects
{
type swakExpression;
valueType internalField;
setName liquidCog;
accumulations (sum);
expression "(pos()*alpha1*vol())/0.034167"; //works
/*# Time sum
0.01 (0.000309988 0.0903394 0.25)*/
verbose true;
outputControl outputTime;
}
liquid_COG1
{
type swakExpression;
valueType internalField;
setName liquidCog;
accumulations (sum);
expression "pos()"; //works
/*# Time sum
0.01 (-401.694 14571.8 22412.5)*/
verbose true;
outputControl outputTime;
}
liquid_COG2
{
type swakExpression;
valueType internalField;
setName liquidCog;
accumulations (sum);
expression "alpha1*vol()"; //works
/*# Time sum
0.01 0.034167*/
verbose true;
outputControl outputTime;
}
liquid_COG3
{
type swakExpression;
valueType internalField;
setName liquidCog;
accumulations (sum);
expression "pos()*alpha1*vol()"; //works
/*# Time sum
0.01 (1.05913e-05 0.00308663 0.00854175)*/
verbose true;
outputControl outputTime;
}
liquidCOG4
{
type swakExpression;
//functionObjectLibs ("libswakFunctionObjects.so"); Not needed if it is called in libs ("libsimpleSwakFunctionObjects.so" "libswakFunctionObjects.so");
valueType internalField;
setName liquid_Cog;
accumulations (sum);
//expression "(pos()*alpha1*vol())/(alpha1*vol())"; //Floating point exceptio
variables (
"posX=(pos().x>0.0001) ? pos().x : 0;"
"posT=vector(posX,pos().y,pos().z);"
);
expression "posT*alpha1*vol()/(alpha1*vol())"; //ERROR
/*Expression liquidCOG4 : #0 Foam::error:rintStack(Foam::Ostream&) in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#1 Foam::sigFpe::sigHandler(int) in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#2 __restore_rt at sigaction.c:0
#3 Foam::tmp<Foam::GeometricField<Foam::Vector<double >, Foam::fvPatchField, Foam::volMesh> > Foam:perator/<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>(Foam::GeometricField<Foam::Vector<d ouble>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&) in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib/libfiniteVolume.so"
#4 parserField::FieldValueExpressionParser:arse() in "/home/anmartin3/OpenFOAM/anmartin3-2.0.x/platforms/linux64Gcc45DPOpt/lib/libswak4FoamParsers.so"
#5 Foam::FieldValueExpressionDriver:arse(std::strin g const&) in "/home/anmartin3/OpenFOAM/anmartin3-2.0.x/platforms/linux64Gcc45DPOpt/lib/libswak4FoamParsers.so"
#6 Foam::swakExpressionFunctionObject::write() in "/home/anmartin3/OpenFOAM/anmartin3-2.0.x/platforms/linux64Gcc45DPOpt/lib/libsimpleSwakFunctionObjects.so"
#7 Foam::simpleFunctionObject::execute(bool) in "/home/anmartin3/OpenFOAM/anmartin3-2.0.x/platforms/linux64Gcc45DPOpt/lib/libsimpleFunctionObjects.so"
#8 Foam::functionObjectList::execute(bool) in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#9 Foam::Time::run() const in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#10 main in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/bin/interDyMFoam"
#11 __libc_start_main in "/lib64/libc.so.6"
#12 Foam::UOPstream::write(char) in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/bin/interDyMFoam"
Floating point exception*/
verbose true;
outputControl outputTime;
}
};

By the other hand, in paraview, it is possible to obtain de volume with meshQuality, and then pass celldata to point data and obtain the cellcenters. Then is possible using the calculator to multiply coord(x y z)*alpha*vol, but I don’t know how to make the summation of all cell values.

If anybody knows how it is possible to solve these questiongs, I will be very gratefully.
Best regards,
anmartin is offline   Reply With Quote

Old   January 23, 2012, 18:24
Default
  #5
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,912
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by anmartin View Post
Hello,
First at all, many thanks to Bernhard and Vieri for your quick response.
Iíve tried first, with swak4foam and after installed and read yours presentations, I finally discovered one easy way to obtain the cog that works for me, but not very smart, because in canít remove the floating point exception.
This is my controlDict, with the different options that I have tried, and the results obtained, included the error:
libs (
"libsimpleSwakFunctionObjects.so"
"libswakFunctionObjects.so"
);
functions
{
liquid_COG //simpleFunctionObjects
{
type swakExpression;
valueType internalField;
setName liquidCog;
accumulations (sum);
expression "(pos()*alpha1*vol())/0.034167"; //works
/*# Time sum
0.01 (0.000309988 0.0903394 0.25)*/
verbose true;
outputControl outputTime;
}
liquid_COG1
{
type swakExpression;
valueType internalField;
setName liquidCog;
accumulations (sum);
expression "pos()"; //works
/*# Time sum
0.01 (-401.694 14571.8 22412.5)*/
verbose true;
outputControl outputTime;
}
liquid_COG2
{
type swakExpression;
valueType internalField;
setName liquidCog;
accumulations (sum);
expression "alpha1*vol()"; //works
/*# Time sum
0.01 0.034167*/
verbose true;
outputControl outputTime;
}
liquid_COG3
{
type swakExpression;
valueType internalField;
setName liquidCog;
accumulations (sum);
expression "pos()*alpha1*vol()"; //works
/*# Time sum
0.01 (1.05913e-05 0.00308663 0.00854175)*/
verbose true;
outputControl outputTime;
}
liquidCOG4
{
type swakExpression;
//functionObjectLibs ("libswakFunctionObjects.so"); Not needed if it is called in libs ("libsimpleSwakFunctionObjects.so" "libswakFunctionObjects.so");
valueType internalField;
setName liquid_Cog;
accumulations (sum);
//expression "(pos()*alpha1*vol())/(alpha1*vol())"; //Floating point exceptio
variables (
"posX=(pos().x>0.0001) ? pos().x : 0;"
"posT=vector(posX,pos().y,pos().z);"
);
expression "posT*alpha1*vol()/(alpha1*vol())"; //ERROR
/*Expression liquidCOG4 : #0 Foam::error:rintStack(Foam::Ostream&) in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#1 Foam::sigFpe::sigHandler(int) in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#2 __restore_rt at sigaction.c:0
#3 Foam::tmp<Foam::GeometricField<Foam::Vector<double >, Foam::fvPatchField, Foam::volMesh> > Foam:perator/<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>(Foam::GeometricField<Foam::Vector<d ouble>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&) in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib/libfiniteVolume.so"
#4 parserField::FieldValueExpressionParser:arse() in "/home/anmartin3/OpenFOAM/anmartin3-2.0.x/platforms/linux64Gcc45DPOpt/lib/libswak4FoamParsers.so"
#5 Foam::FieldValueExpressionDriver:arse(std::strin g const&) in "/home/anmartin3/OpenFOAM/anmartin3-2.0.x/platforms/linux64Gcc45DPOpt/lib/libswak4FoamParsers.so"
#6 Foam::swakExpressionFunctionObject::write() in "/home/anmartin3/OpenFOAM/anmartin3-2.0.x/platforms/linux64Gcc45DPOpt/lib/libsimpleSwakFunctionObjects.so"
#7 Foam::simpleFunctionObject::execute(bool) in "/home/anmartin3/OpenFOAM/anmartin3-2.0.x/platforms/linux64Gcc45DPOpt/lib/libsimpleFunctionObjects.so"
#8 Foam::functionObjectList::execute(bool) in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#9 Foam::Time::run() const in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib/libOpenFOAM.so"
#10 main in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/bin/interDyMFoam"
#11 __libc_start_main in "/lib64/libc.so.6"
#12 Foam::UOPstream::write(char) in "/home/anmartin/OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/bin/interDyMFoam"
Floating point exception*/
verbose true;
outputControl outputTime;
}
};

By the other hand, in paraview, it is possible to obtain de volume with meshQuality, and then pass celldata to point data and obtain the cellcenters. Then is possible using the calculator to multiply coord(x y z)*alpha*vol, but I donít know how to make the summation of all cell values.

If anybody knows how it is possible to solve these questiongs, I will be very gratefully.
Best regards,
I think you'll want to write sum(alpha1*vol()) instead of alpha1*vol(). Because if in ANY cell the alpha1 is 0 then you get a division by zero there. Apart from that sum(pos()*alpha1*vol())/sum(alpha1*vol) is NOT the same as sum(pos()*alpha1*vol()/(alpha1*vol)) (which is what you wrote)
gschaider is offline   Reply With Quote

Old   January 24, 2012, 09:43
Default
  #6
Member
 
Duong A. Hoang
Join Date: Apr 2009
Location: Delft, Netherlands
Posts: 92
Rep Power: 8
duongquaphim is on a distinguished road
Send a message via Yahoo to duongquaphim
Quote:
Originally Posted by anmartin View Post
By the other hand, in paraview, it is possible to obtain de volume with meshQuality, and then pass celldata to point data and obtain the cellcenters. Then is possible using the calculator to multiply coord(x y z)*alpha*vol, but I donít know how to make the summation of all cell values.
Hi,

You can use function Filter -> Integrate Variables to make the summation.

Cheers,

Duong
duongquaphim is offline   Reply With Quote

Old   January 27, 2012, 07:21
Default
  #7
Member
 
angel
Join Date: May 2009
Location: Spain
Posts: 46
Rep Power: 8
anmartin is on a distinguished road
Quote:
Originally Posted by duongquaphim View Post
Hi,

You can use function Filter -> Integrate Variables to make the summation.

Cheers,

Duong

Hello,

many thanks to everybody that helped me.

Work done perfectly.

Thanks again,
anmartin is offline   Reply With Quote

Old   March 5, 2012, 10:20
Default A little utility
  #8
New Member
 
Ivo
Join Date: Feb 2012
Posts: 22
Rep Power: 5
Ivooo is on a distinguished road
Hi,

I created a utility to do just this, basically as a first step to get to know the coding style, but it works for me; it reads the alpha fraction for each time step and provides the centre of mass as a weighted average (with the cell volume), and the total volume and outputs these numbers to stdout.

I'll leave this just here in case somebody could use it. It's as simple as the ptot utility on which it is based, and it seems to work too on dynamic meshes. No guarantees

(unpack in $WM_PROJECT_USER_DIR/applications/utilities/postProcessing/miscellaneous , go to alpha1Tot directory and run wmake - tested on v2.1.0)
Attached Files
File Type: gz alpha1Tot.tar.gz (60.4 KB, 33 views)
Ivooo 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
interDyMFoam - One rigid body, multiple boundaries mattkram OpenFOAM Running, Solving & CFD 0 January 11, 2012 18:15
interDyMFoam with GGI in 3d stawrogin OpenFOAM Running, Solving & CFD 2 January 5, 2011 03:17
calculate values for eps and k from Re or u????? sbar OpenFOAM Pre-Processing 5 August 16, 2010 04:10
error using interDyMFoam with kOmegaSST to simulate sloshing anmartin OpenFOAM Running, Solving & CFD 0 July 20, 2010 13:21
How to calculate Torque for francis turbine manish CFX 4 March 15, 2007 03:57


All times are GMT -4. The time now is 01:08.