CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   help:How to get mass integral axial Velocity & momentum (https://www.cfd-online.com/Forums/openfoam/80675-help-how-get-mass-integral-axial-velocity-momentum.html)

 bruxellois October 3, 2010 07:04

help:How to get mass integral axial Velocity & momentum

Dear Foamers,

I'm working with openFoam (sonicFoam solver), i'm interesting to calculate and plot the equivalent to ''mass integral axial velocity" in respect to this formula:

Q=∫rho U_x dV=∑ rho .U_x.V_cell

(V_cell= cell volume)

How can i calculate Q either with paraview (calculator, integratevariables filters?) Or with OpenFOAM.

Any suggestions will be appreciated.

Best regards

 nuovodna October 4, 2010 06:03

partial solution

Hi, you can compute the cell volume with OF introducing in the solver code a piece like this

Code:

```        forAll(mesh.cells(), cellii)         {                      cellVolume = mesh.V()[cellii];         }```
And in createFields.H file

Code:

```    volScalarField cellVolume     (         IOobject         (             "PecletX",             runTime.timeName(),             mesh,             IOobject::NO_READ,             IOobject::AUTO_WRITE         ),         mesh,         dimensionedScalar("cellVolume", dimensionSet(0,3,0,0,0,0,0),1)     );```
These parts will be necessary to print a new variable named "cellVariable" ready to be read from paraFoam.
Then you can proceed with integrateVariables i guess

Emanuele

 bruxellois October 4, 2010 06:22

Hi Emanuele,

Many thanks to you response.

Could you please explain the intergrate filter is it a volume integration? i have to multiply the result by the volume, the number of cells or no?

Best regards

 nuovodna October 4, 2010 06:37

Hi, you can bypass paraview in this way

Add this line in .C solver before the
Code:

`while (runTime.run())`
:

Code:

`    OFstream massIntegral("massIntegral.dat");`
Then in runTime loop put this line:

Code:

```        forAll(mesh.cells(), celli)         {                 Q+= rho * U[celli] * mesh.V()[cellii]; // i m not sure U = Ux it should be something like this: U.component(0)[celli]       }         massIntegral << runTime.timeName() << " "<< Q.value() << endl;```
define Q in createFields.H

Code:

```    dimensionedScalar Q     (         "Q",         dimensionSet(1,-3,0,0,0),  // adjust the dimension here!!!         0.0     );```
Forgot the previous post

 bruxellois October 4, 2010 06:44

Really Thanks a lot Emanuele,

I'll try it and i'll keep you informed.

Thanks again!!

 bruxellois October 4, 2010 08:04

Hi Emanuele,

I did what you said step by step but i don't receive any information about my new field Q.

Any idea?

Best regards

 nuovodna October 4, 2010 08:21

text file

The solver should have written a file named massIntegral.dat in your case directory. The file contains the values of Q at corresponding values of time

Regards

Emanuele

 bruxellois October 4, 2010 08:29

I didn't find massIntegral.dat,

i have to put this evrywhere (arbitrary location) in runTime loop ??

forAll(mesh.cells(), celli)
{
Q+= rho * U[celli] * mesh.V()[cellii]; // i m not sure U = Ux it should be something like this: U.component(0)[celli]
}

massIntegral << runTime.timeName() << " "<< Q.value() << endl;

The same for createFields.H ( i put the new lines in a arbitrary location)??

I have to recompile the solver with wmake??

Regards

 nuovodna October 4, 2010 08:34

recompile the solver

In createFields.H put these lines at the top

Code:

```    dimensionedScalar Q     (         "Q",         dimensionSet(1,-3,0,0,0),  // adjust the dimension here!!!         0.0     );```
Then you have to recompile the solver. Sorry i missed you to say that previously :)

 bruxellois October 4, 2010 08:41

Thanks a lot for your quick response!!

I've put these lines at the top of createFields.H but i receive errors

:~/OpenFOAM/OpenFOAM-1.6/applications/solvers/compressible/sonicFoam\$ wmake
Making dependency list for source file sonicFoam.C
SOURCE=sonicFoam.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-40 -I/home/moumen/OpenFOAM/OpenFOAM-1.6/src/thermophysicalModels/basic/lnInclude -I/home/moumen/OpenFOAM/OpenFOAM-1.6/src/turbulenceModels/compressible/turbulenceModel -I/home/moumen/OpenFOAM/OpenFOAM-1.6/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/moumen/OpenFOAM/OpenFOAM-1.6/src/OpenFOAM/lnInclude -I/home/moumen/OpenFOAM/OpenFOAM-1.6/src/OSspecific/POSIX/lnInclude -fPIC -c \$SOURCE -o Make/linux64GccDPOpt/sonicFoam.o
sonicFoam.C: In function ‘int main(int, char**)’:
sonicFoam.C:51: error: ‘OFstream’ was not declared in this scope
sonicFoam.C:51: error: ‘massIntegral’ was not declared in this scope
sonicFoam.C:85: error: ‘cellii’ was not declared in this scope
make: *** [Make/linux64GccDPOpt/sonicFoam.o] Error 1

Regards.

 nuovodna October 4, 2010 08:55

Add these lines before the int main on solver .C file:

Code:

```#include "OFstream.H" #include <fstream> #include <sstream> #include <string>```
and modify the

Code:

`mesh.V()[cellii]`
to

Code:

`mesh.V()[celli]`
Bye
Emanuele

 bruxellois October 4, 2010 09:03

I'm sorry but i'm receiving errors

Making dependency list for source file sonicFoam.C
SOURCE=sonicFoam.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-40 -I/home/moumen/OpenFOAM/OpenFOAM-1.6/src/thermophysicalModels/basic/lnInclude -I/home/moumen/OpenFOAM/OpenFOAM-1.6/src/turbulenceModels/compressible/turbulenceModel -I/home/moumen/OpenFOAM/OpenFOAM-1.6/src/finiteVolume/lnInclude -IlnInclude -I. -I/home/moumen/OpenFOAM/OpenFOAM-1.6/src/OpenFOAM/lnInclude -I/home/moumen/OpenFOAM/OpenFOAM-1.6/src/OSspecific/POSIX/lnInclude -fPIC -c \$SOURCE -o Make/linux64GccDPOpt/sonicFoam.o
sonicFoam.C: In function ‘int main(int, char**)’:
sonicFoam.C:89: error: no match for ‘operator[]’ in ‘Foam::GeometricField<Type, PatchField, GeoMesh>::component(Foam::direction) const [with Type = Foam::Vector<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh](0)[celli]’
make: *** [Make/linux64GccDPOpt/sonicFoam.o] Error 1

 santiagomarquezd October 4, 2010 09:06

Alex, you can do it using Paraview. The first step is to use the Calculator filter to create the field rho*U_0, then apply the Integrate Variables filter in order to integrate this new variable in the whole domain.

Regards.

 bruxellois October 4, 2010 09:12

Hi santiagomarquezd,

I did that with paraview but the result i had dont correspond for what i had with fluent, it seems tha i have to multiply it with a factor (volume, cell numbers??)

Also the integrate filter gives me one line, so i can say that's the integration of the whole domain but i'm confused it indicates cell ID 0, is it an integration for one cell volume or what?

Best regards

 santiagomarquezd October 4, 2010 12:46

Alex, I checked the integration with a case and it seems to be OK. The line that it is shown reports the whole integral values. Maybe you could check it with a simple case, like a square cavity with given rho and U and then check the results.

Best.

 bruxellois October 4, 2010 13:47

Hi santiagomarquezd,

Is it the same for an axisymetric geometry?

 bruxellois October 7, 2010 07:30

Problem solved

Just in case someone's having the same problem and is using the search-function, here's the solution:

Paraview may calculate the momentum :The first step is to use the Calculator filter to create the field then apply the Integrate Variables filter in order to integrate this new variable in the whole domain. But fo axisymetric geometry you have to multiply results by this factor (real Volume/axisymetric volume).

Best regards.

 hyperion October 7, 2010 23:41

Hi Alex - I think I am trying to do something similar to what you were doing and I was hoping you might be able to explain how to do it. The solver I am using, dsmcFOAM, outputs mass density and number density (# of molecules per m^3). I was wondering if there was a way in paraFoam to output the number of molecules per cell. Thank you for any and all help.

Thanks

 bruxellois October 8, 2010 05:57

Hi hyperion,

I have any experience with dsmcFOAM but since uou have number density (# of molecules per m^3) you have to integrate (i.e paraview filter) it to obtain # of molecules in yous domaine.

 benk October 8, 2010 10:36

Just out of interest, wouldn't

Code:

`scalar Q = fvc::domainIntegrate(rho*U_x).value();`
accomplish Q=∫rho U_x dV=∑ rho .U_x.V_cell ? ( where U_x would probably be something like U.component(0) )

 All times are GMT -4. The time now is 16:55.