|
[Sponsors] |
March 25, 2013, 03:39 |
How to sum up a volScalarField
|
#1 |
Member
Martin
Join Date: Aug 2010
Location: Germany
Posts: 55
Rep Power: 16 |
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 |
|
March 25, 2013, 03:53 |
|
#2 |
Senior Member
Lieven
Join Date: Dec 2011
Location: Leuven, Belgium
Posts: 299
Rep Power: 23 |
You can simply use
Code:
scalar sum = gSum(C); Cheers, Lieven |
|
March 25, 2013, 05:05 |
|
#3 |
Member
Martin
Join Date: Aug 2010
Location: Germany
Posts: 55
Rep Power: 16 |
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; } // ************************************************************************* // Regards, Martin |
|
March 25, 2013, 05:24 |
|
#4 |
Senior Member
Lieven
Join Date: Dec 2011
Location: Leuven, Belgium
Posts: 299
Rep Power: 23 |
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 |
|
March 25, 2013, 12:20 |
|
#5 |
Member
Martin
Join Date: Aug 2010
Location: Germany
Posts: 55
Rep Power: 16 |
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; } } |
|
March 25, 2013, 21:04 |
|
#6 |
Senior Member
Hua Zen
Join Date: Mar 2009
Posts: 138
Rep Power: 17 |
gSum!=gsum
|
|
March 26, 2013, 11:40 |
|
#7 |
Member
Martin
Join Date: Aug 2010
Location: Germany
Posts: 55
Rep Power: 16 |
Dear Leaven and Lin,
thank you very much for your help! It was a spelling problem of mine. Now it works fine |
|
|
|
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 |