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

How to sum up a volScalarField

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 4 Post By Lieven
  • 1 Post By lin

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 25, 2013, 03:39
Default How to sum up a volScalarField
  #1
Member
 
Martin
Join Date: Aug 2010
Location: Germany
Posts: 55
Rep Power: 16
RugbyGandalf is on a distinguished road
Dear Foamers,

i build a small postprocessing program, which calculates the volume of each cell and multiplies it by the a concentration of this cell. (It is a case, where I simulate the drug-transport through a coronary artery).
So I know about the mass of drug in each cell, but i would like to sum all values up, so that I get the overall value...

Does anyone have a clue, how to do this?

Thank you very much

Regards,
Martin
RugbyGandalf is offline   Reply With Quote

Old   March 25, 2013, 03:53
Default
  #2
Senior Member
 
Lieven
Join Date: Dec 2011
Location: Leuven, Belgium
Posts: 299
Rep Power: 23
Lieven will become famous soon enough
You can simply use
Code:
scalar sum = gSum(C);
where C is the mass scalarField.

Cheers,

Lieven
ayhan515, Luttappy, wht and 1 others like this.
Lieven is offline   Reply With Quote

Old   March 25, 2013, 05:05
Default
  #3
Member
 
Martin
Join Date: Aug 2010
Location: Germany
Posts: 55
Rep Power: 16
RugbyGandalf is on a distinguished road
Dear Lieven,

thank you very much for your answer.
Unfortunately wmake gives out the following errors:

wirkstoffgehalt.C: In function ‘int main(int, char**)’:
wirkstoffgehalt.C:158: error: ‘sum’ cannot be used as a function
wirkstoffgehalt.C:141: warning: unused variable ‘Gesamtwirkstoffgehalt’
make: *** [Make/linux64GccDPOpt/wirkstoffgehalt.o] Fehler 1






I added this line at the end of my program.C - Code, which now looks as follows:

Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Description
    Write the three components of the cell centres as volScalarFields so
    they can be used in postprocessing in thresholding.

\*---------------------------------------------------------------------------*/

#include "argList.H"
#include "timeSelector.H"
#include "Time.H"
#include "fvMesh.H"
#include "vectorIOField.H"
#include "volFields.H"
#include "fvCFD.H"

using namespace Foam;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 

// Main program:

int main(int argc, char *argv[])
{

    timeSelector::addOptions();

#   include "setRootCase.H"
#   include "createTime.H"

    instantList timeDirs = timeSelector::select0(runTime, args);

#   include "createMesh.H"

    forAll(timeDirs, timeI)
    {
        runTime.setTime(timeDirs[timeI], timeI);

        Info<< "Time = " << runTime.timeName() << endl;

        // Check for new mesh
        mesh.readUpdate();

    volScalarField C
    (
        IOobject
        (
            "C",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );


    volScalarField cv
    (
            IOobject
            (
                    "cellVolumes",
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::AUTO_WRITE
            ),
            mesh,
            dimensionedScalar("zero",dimVolume,0.0)
    );
    
    volScalarField wirkstoffgehalt
    (
            IOobject
            (
                    "Wirkstoffgehalt",
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::AUTO_WRITE
            ),
            mesh,
            dimensionedScalar("zero",dimMass,0.0)
    );

    cv.internalField() = mesh.V();

    Info<< "Schreibe den Wert " << cv.name() << " in "
             << runTime.timeName() << endl;

    wirkstoffgehalt.internalField() = mesh.V()*C.internalField();


         Info<< "Schreibe den Wirkstoffgehalt je Zelle in kg " << cv.name() << " in "
             << runTime.timeName() << endl;
        
         cv.write();
     wirkstoffgehalt.write();



    IOdictionary transportProperties
    (
        IOobject
        (
            "transportProperties",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    );


scalar sum = sum(wirkstoffgehalt);

    
    Info<< "Gesamtwirkstoffgehalt in kg beträgt " << sum << " in "
             << runTime.timeName() << endl;

   }


    Info<< "\nEnd" << endl;

    return 0;
}


// ************************************************************************* //
Could you tell me, what is wrong?

Regards,
Martin
RugbyGandalf is offline   Reply With Quote

Old   March 25, 2013, 05:24
Default
  #4
Senior Member
 
Lieven
Join Date: Dec 2011
Location: Leuven, Belgium
Posts: 299
Rep Power: 23
Lieven will become famous soon enough
Ok, but you should copy the code a bit more carefully (it is gSum and not simply sum) and it is also bit tricky what you try to do in your code.
You try to create a variable with the same name as the function you are calling. I'm certainly not an C++ experiment but I can imagine that could cause problems...

Cheers,

L
Lieven is offline   Reply With Quote

Old   March 25, 2013, 12:20
Default
  #5
Member
 
Martin
Join Date: Aug 2010
Location: Germany
Posts: 55
Rep Power: 16
RugbyGandalf is on a distinguished road
Hey Lieven,

I tried another way. The program from above gives out a volScalarField (let's call it "Values")
with another program, I read in Values, and tried your "gsum" lines again, but it did nor work.
# gsum is not defined in this scope
Is a header missing?

Regards,
Martin

Code:
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Description
    Write the three components of the cell centres as volScalarFields so
    they can be used in postprocessing in thresholding.

\*---------------------------------------------------------------------------*/

#include "argList.H"
#include "timeSelector.H"
#include "Time.H"
#include "fvMesh.H"
#include "vectorIOField.H"
#include "volFields.H"
#include "fvCFD.H"

using namespace Foam;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 

// Main program:

int main(int argc, char *argv[])
{

    timeSelector::addOptions();

#   include "setRootCase.H"
#   include "createTime.H"

    instantList timeDirs = timeSelector::select0(runTime, args);

#   include "createMesh.H"

    forAll(timeDirs, timeI)
    {
        runTime.setTime(timeDirs[timeI], timeI);

        Info<< "Time = " << runTime.timeName() << endl;

        // Check for new mesh
        mesh.readUpdate();

    volScalarField Wirkstoffgehalt
    (
        IOobject
        (
            "Wirkstoffgehalt",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        ),
        mesh
    );

scalar sum = gsum(Wirkstoffgehalt);


    Info<< "Schreibe den Wert " << sum << " in "
             << runTime.timeName() << endl;

   }


    Info<< "\nEnd" << endl;

    return 0;
   }
}
RugbyGandalf is offline   Reply With Quote

Old   March 25, 2013, 21:04
Default
  #6
lin
Senior Member
 
Hua Zen
Join Date: Mar 2009
Posts: 138
Rep Power: 17
lin is on a distinguished road
gSum!=gsum
ZhangPikai likes this.
lin is offline   Reply With Quote

Old   March 26, 2013, 11:40
Default
  #7
Member
 
Martin
Join Date: Aug 2010
Location: Germany
Posts: 55
Rep Power: 16
RugbyGandalf is on a distinguished road
Dear Leaven and Lin,

thank you very much for your help!
It was a spelling problem of mine.

Now it works fine
RugbyGandalf is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write k and epsilon before the abnormal end xiuying OpenFOAM Running, Solving & CFD 8 August 27, 2013 16:33
Upgraded from Karmic Koala 9.10 to Lucid Lynx10.04.3 bookie56 OpenFOAM Installation 8 August 13, 2011 05:03
Convergence moving mesh lr103476 OpenFOAM Running, Solving & CFD 30 November 19, 2007 15:09
IcoFoam parallel woes msrinath80 OpenFOAM Running, Solving & CFD 9 July 22, 2007 03:58
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 19:07


All times are GMT -4. The time now is 14:42.