1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "findRefCell.H"
28 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
32 const volScalarField& field,
33 const volScalarField& fieldRef,
34 const dictionary& dict,
37 const bool forceReference
40 if (fieldRef.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 volScalarField&,\n"
61 " const dictionary&,\n"
66 ) << "Illegal master cellID " << refCelli
67 << ". Should be 0.." << field.mesh().nCells()
68 << exit(FatalIOError);
76 else if (dict.found(refPointName))
78 point refPointi(dict.lookup(refPointName));
79 refCelli = field.mesh().findCell(refPointi);
80 label hasRef = (refCelli >= 0 ? 1 : 0);
81 label sumHasRef = returnReduce<label>(hasRef, sumOp<label>());
86 "void Foam::setRefCell\n"
88 " const volScalarField&,\n"
89 " const volScalarField&,\n"
90 " const dictionary&,\n"
95 ) << "Unable to set reference cell for field " << field.name()
96 << nl << " Reference point " << refPointName
98 << " found on " << sumHasRef << " domains (should be one)"
99 << nl << exit(FatalIOError);
106 "void Foam::setRefCell\n"
108 " const volScalarField&,\n"
109 " const volScalarField&,\n"
110 " const dictionary&,\n"
115 ) << "Unable to set reference cell for field " << field.name()
117 << " Please supply either " << refCellName
118 << " or " << refPointName << nl << exit(FatalIOError);
121 refValue = readScalar(dict.lookup(refValueName));
126 void Foam::setRefCell
128 const volScalarField& field,
129 const dictionary& dict,
132 const bool forceReference
135 setRefCell(field, field, dict, refCelli, refValue, forceReference);
139 Foam::scalar Foam::getRefCellValue
141 const volScalarField& field,
145 scalar refCellValue = (refCelli >= 0 ? field[refCelli] : 0.0);
146 return returnReduce(refCellValue, sumOp<scalar>());
150 // ************************************************************************* //