1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "findRefCell.H"
29 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
33 const volScalarField& field,
34 const dictionary& dict,
37 const bool forceReference
40 if (field.needReference() || forceReference)
42 word refCellName = field.name() + "RefCell";
43 word refPointName = field.name() + "RefPoint";
45 word refValueName = field.name() + "RefValue";
47 if (dict.found(refCellName))
49 if (Pstream::master())
51 refCelli = readLabel(dict.lookup(refCellName));
53 if (refCelli < 0 || refCelli >= field.mesh().nCells())
57 "void Foam::setRefCell\n"
59 " const volScalarField&,\n"
60 " const dictionary&,\n"
65 ) << "Illegal master cellID " << refCelli
66 << ". Should be 0.." << field.mesh().nCells()
67 << exit(FatalIOError);
75 else if (dict.found(refPointName))
77 point refPointi(dict.lookup(refPointName));
78 refCelli = field.mesh().findCell(refPointi);
79 label hasRef = (refCelli >= 0 ? 1 : 0);
80 label sumHasRef = returnReduce<label>(hasRef, sumOp<label>());
85 "void Foam::setRefCell\n"
87 " const volScalarField&,\n"
88 " const dictionary&,\n"
93 ) << "Unable to set reference cell for field " << field.name()
94 << nl << " Reference point " << refPointName
96 << " found on " << sumHasRef << " domains (should be one)"
97 << nl << exit(FatalIOError);
104 "void Foam::setRefCell\n"
106 " const volScalarField&,\n"
107 " const dictionary&,\n"
112 ) << "Unable to set reference cell for field " << field.name()
114 << " Please supply either " << refCellName
115 << " or " << refPointName << nl << exit(FatalIOError);
118 refValue = readScalar(dict.lookup(refValueName));
123 Foam::scalar Foam::getRefCellValue
125 const volScalarField& field,
129 scalar refCellValue = (refCelli >= 0 ? field[refCelli] : 0.0);
130 return returnReduce(refCellValue, sumOp<scalar>());
134 // ************************************************************************* //