CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Center of Mass / volume (https://www.cfd-online.com/Forums/openfoam-programming-development/126336-center-mass-volume.html)

Aurelien Thinat November 14, 2013 10:26

Center of Mass / volume
 
Hi everyone,

I'm trying to add the calculation of the center of mass in the solver InterFoam. I wrote in interFoam.C :

Code:

vector CoM = sum(mesh.V()*(alpha1*rho1 + (1-alpha1)*rho2)*mesh.C().internalField())/sum(mesh.V()*(alpha1*rho1+(1-alpha1)*rho2));
So far it compiles correctly but the results are wrong. So I added another vector relative to the center of volume :

Code:

vector CoV = sum(mesh.V()*mesh.C().internalField())/sum(mesh.V());
And now it doesn't compile anymore.

I can't see the probleme. If the first line compile, the second should too. Does anyone of you have any idea ?


EDIT :

After some tests it seems the problem is coming from "mesh.C().internalField()". As soon as I use this in the "sum" operator, the dimensions are deleted.
Exemple :
- sum(rho*mesh.V()) -> dimension is kg.
- sum(rho*mesh.V()*mesh.C().internalField() -> dimmensionless.

Is there a way to fix that ?

marupio November 14, 2013 13:50

Try .dimensionedInternalField()

Aurelien Thinat November 15, 2013 03:36

Wonderfull, it works ! Thank you very much.


All times are GMT -4. The time now is 23:45.