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/)
-   -   How to integrate a parameter in whole domain(domainIntegrate(alfa)) (https://www.cfd-online.com/Forums/openfoam-programming-development/235515-how-integrate-parameter-whole-domain-domainintegrate-alfa.html)

farzadmech April 17, 2021 11:39

How to integrate a parameter in whole domain(domainIntegrate(alfa))
 
Dear foamers
I want to use domainIntegrate(alfa) to integrate a parameter in all my domain. I checked the main code for domainIntegrate(alfa) in below address;

https://cpp.openfoam.org/v3/a05655_source.html

and it is written as below;

Code:

 
  82
  83 template<class Type>
  84 dimensioned<Type>
  85 domainIntegrate
  86 (
  87    const GeometricField<Type, fvPatchField, volMesh>& vf
  88 )
  89 {
  90    return dimensioned<Type>
  91    (
  92        "domainIntegrate(" + vf.name() + ')',
  93        dimVol*vf.dimensions(),
  94        gSum(fvc::volumeIntegrate(vf))
  95    );
  96 }
  97
  98
  99 template<class Type>
  100 dimensioned<Type> domainIntegrate
  101 (
  102    const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf
  103 )
  104 {
  105    dimensioned<Type> integral = domainIntegrate(tvf());
  106    tvf.clear();
  107    return integral;
  108 }
  109
  110
  111 template<class Type>
  112 dimensioned<Type> domainIntegrate
  113 (
  114    const DimensionedField<Type, volMesh>& df
  115 )
  116 {
  117    return dimensioned<Type>
  118    (
  119        "domainIntegrate(" + df.name() + ')',
  120        dimVol*df.dimensions(),
  121        gSum(fvc::volumeIntegrate(df))
  122    );
  123 }
  124
  125
  126 template<class Type>
  127 dimensioned<Type> domainIntegrate
  128 (
  129    const tmp<DimensionedField<Type, volMesh> >& tdf
  130 )
  131 {
  132    dimensioned<Type> integral = domainIntegrate(tdf());
  133    tdf.clear();
  134    return integral;
  135 }
  136
  137

Now, my question is very simple;
if I want to integrate alfa over whole domain, I should use domainIntegrate(alfa), but what is alfa? I mean it is volScalarField? or Scalar? or dimensionedScalar?


Thanks,
Farzad

farzadmech April 17, 2021 17:50

Extra explanation
 
For clarification, I used pressure to integrate which is a volScalarField and it gives me error;

Code:

In file included from DPMFoamFarzadd.C:216:0:
YO2cEqnYN2cEqn.H: In function ‘int main(int, char**)’:
YO2cEqnYN2cEqn.H:20:40: error: cannot convert ‘Foam::dimensioned<double>’ to ‘Foam::scalar {aka double}’ in assignment
  sumcloudSYO2 = fvc::domainIntegrate(p);


and it gives me this error;

Code:

YO2cEqnYN2cEqn.H:20:40: error: cannot convert ‘Foam::dimensioned<double>’ to ‘Foam::scalar {aka double}’ in assignment


Do you know why?


Thanks,
Farzad

farzadmech April 17, 2021 18:26

Answer!!!
 
Ok, instead of writing
Code:

fvc::domainIntegrate(p)
it must be written;
Code:

fvc::domainIntegrate(p).value();
Thanks,
Farzad

Tobi April 18, 2021 02:52

The clarification of the problem was discussed within 3 text messages in LinkedIn between him and myself., 😉

farzadmech April 18, 2021 12:01

Thanks
 
Yes, Thanks a lot Tobias Holzmann. I am still working on other parts of domainIntegration and if I find something new, I will write it down in this post.




Quote:

Originally Posted by Tobi (Post 801863)
The clarification of the problem was discussed within 3 text messages in LinkedIn between him and myself., 😉


farzadmech April 18, 2021 13:11

New problem after integration
 
I am doing a lagrangian particel tracking using DPMFoam, and inside lagrangian part(src/lagrangian/intermediate/parcels/Templates/KinematicParcel), you need to add

Code:

#include "fvCFD.H"
in order to use fvc::domainIntegrate(alfa).value();

I did this, and code compiles and works fine, but still I have a problem after doing the integration. Let's I explain it;

Code:


        scalar np0 = 1
        Info<< "dMass[0] = " << dMass[0] << endl;
       
        scalar dm = np0*dMass[0];                                                             
        label gid = 0;     
        cloud.rhoTrans(gid)[this->cell()] += dm;
       
        Info<< "cloud.rhoTrans(gid)[this->cell()] = "<<cloud.rhoTrans(gid)[this->cell()]  <<endl;
               
        scalar sumKinematicParcelYO2 = 0.;

        sumKinematicParcelYO2 = fvc::domainIntegrate(cloud.rhoTrans(0)).value();

        Info<<"WaterfordMizz(insideKinematicParcel.C) - sumKinematicParcelYO2 ="<< sumKinematicParcelYO2 <<endl;

And the result is this one

Code:

        dMass[0] = 3.5044329e-28
        cloud.rhoTrans(gid)[this->cell()] = 3.5044329e-28
        WaterfordMizz(insideKinematicParcel.C) - sumKinematicParcelYO2 = 3.4299845e-34
       
        Or in the next Lagrangian time step(2)
       
        dMass[0] = 2.6911542e-15
        cloud.rhoTrans(gid)[this->cell()] = 2.6911542e-15
        WaterfordMizz(insideKinematicParcel.C) - sumKinematicParcelYO2 = 2.6339832e-21
       

        And in the next Lagrangian time step(3)
       
        dMass[0] = 3.1145925e-15
        cloud.rhoTrans(gid)[this->cell()] = 8.7192363e-15
        WaterfordMizz(insideKinematicParcel.C) - sumKinematicParcelYO2 = 8.5340044e-21


Now, we have the value inside one cell, and the remaining cells are empty(initialized zero). After integration, integration results is 6 order magnitude less than the value inside one cell, why?


Farzad

Tobi April 20, 2021 02:57

I expect that domainIntegrate is not suitable for particles. Check out any lagrangian code to see how they create the overall mass or whatever you want to do.


All times are GMT -4. The time now is 21:40.