# How to solve for components of Center of mass?

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

 March 17, 2015, 11:53 How to solve for components of Center of mass? #1 Member   Muhammad Usman Join Date: Feb 2014 Posts: 91 Rep Power: 10 Hye Foamers, i calculated center of mass by writing following formula in interFoam.C CoM = sum(rho*mesh.V()*mesh.C().dimensionedInternalField ())/sum(rho*mesh.V()); now i want to calculate acceleration of center of mass in each dimension. So first i tried to calculate x y and z components of CoM using following formula. CoMx = CoM.x(); CoMy = CoM.y(); CoMz = CoM.z(); then i tried volScalarField CoMx = CoM.component(vector::X); volScalarField CoMy = CoM.component(vector::Y); volScalarField CoMz = CoM.component(vector::Z); there was still error which was this myInterFoamDDT.C: In function ‘int main(int, char**)’: myInterFoamDDT.C:111:46: error: conversion from ‘Foam::dimensioned’ to non-scalar type ‘Foam::volScalarField {aka Foam::GeometricField}’ requested volScalarField CoMx = CoM.component(vector::X); myInterFoamDDT.C:112:46: error: conversion from ‘Foam::dimensioned’ to non-scalar type ‘Foam::volScalarField {aka Foam::GeometricField}’ requested volScalarField CoMy = CoM.component(vector::Y); myInterFoamDDT.C:113:46: error: conversion from ‘Foam::dimensioned’ to non-scalar type ‘Foam::volScalarField {aka Foam::GeometricField}’ requested volScalarField CoMz = CoM.component(vector::Z); After that i tried volScalarField CoMx = CoM.component(0); Error was myInterFoamDDT.C: In function ‘int main(int, char**)’: myInterFoamDDT.C:111:38: error: conversion from ‘Foam::dimensioned’ to non-scalar type ‘Foam::volScalarField {aka Foam::GeometricField}’ requested volScalarField CoMx = CoM.component(0); i Got following error please help me myInterFoamDDT.C: In function ‘int main(int, char**)’: myInterFoamDDT.C:111:1: error: ‘CoMx’ was not declared in this scope CoMx = CoM.x(); ^ myInterFoamDDT.C:111:12: error: ‘Foam::dimensionedVector’ has no member named ‘x’ CoMx = CoM.x(); ^

 March 17, 2015, 12:26 #2 Senior Member   Alexey Matveichev Join Date: Aug 2011 Location: Nancy, France Posts: 1,930 Rep Power: 37 Hi, Centre of mass is vector (in your particular case it is dimensionedVector due to the definition), so Code: ```volScalarField CoMx = CoM.component(vector::X); volScalarField CoMy = CoM.component(vector::Y); volScalarField CoMz = CoM.component(vector::Z);``` this is non-sence as you are trying to create field from scalar. Code: `volScalarField CoMx = CoM.component(0);` is non-sence like the previous expressions. Compiler tries to help you, gives you hints like this Code: ```myInterFoamDDT.C:111:12: error: ‘Foam::dimensionedVector’ has no member named ‘x’ CoMx = CoM.x();``` but you ignore him. If you would like to get components of dimensionedVector, you should use something like Code: `scalar CoMx = CoM.value().x()` or if you would like component as dimensionedScalar: Code: ```dimensionedScalar CoMx ( "CoMx", CoM.dimensions(), CoM.value().x() );```

 March 17, 2015, 12:43 #3 Member   Muhammad Usman Join Date: Feb 2014 Posts: 91 Rep Power: 10 Thank you sir i got the point...... sorry i am new in openFoam

 March 17, 2015, 12:46 #4 Member   Muhammad Usman Join Date: Feb 2014 Posts: 91 Rep Power: 10 Thank you sir i got the point...... sorry i am new in openFoam Please tell me how to define it in creatFields.H as for center of mass i did CoM = sum(rho*mesh.V()*mesh.C().dimensionedInternalField ())/sum(rho*mesh.V()); in interFoam.C and specified dimensionedVector CoM("CoM", dimLength, vector::zero); in creatFields.H with the help of teachers like you :-)