ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / finiteVolume / cfdTools / general / findRefCell / findRefCell.C
blob45c8d2edba4f4b378221e3267516bcae368d15b6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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  * * * * * * * * * * * * * //
30 void Foam::setRefCell
32     const volScalarField& field,
33     const volScalarField& fieldRef,
34     const dictionary& dict,
35     label& refCelli,
36     scalar& refValue,
37     const bool forceReference
40     if (fieldRef.needReference() || forceReference)
41     {
42         word refCellName = field.name() + "RefCell";
43         word refPointName = field.name() + "RefPoint";
45         word refValueName = field.name() + "RefValue";
47         if (dict.found(refCellName))
48         {
49             if (Pstream::master())
50             {
51                 refCelli = readLabel(dict.lookup(refCellName));
53                 if (refCelli < 0 || refCelli >= field.mesh().nCells())
54                 {
55                     FatalIOErrorIn
56                     (
57                         "void Foam::setRefCell\n"
58                          "(\n"
59                          "    const volScalarField&,\n"
60                          "    const volScalarField&,\n"
61                          "    const dictionary&,\n"
62                          "    label& scalar&,\n"
63                          "    bool\n"
64                          ")",
65                         dict
66                     )   << "Illegal master cellID " << refCelli
67                         << ". Should be 0.." << field.mesh().nCells()
68                         << exit(FatalIOError);
69                 }
70             }
71             else
72             {
73                 refCelli = -1;
74             }
75         }
76         else if (dict.found(refPointName))
77         {
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>());
82             if (sumHasRef != 1)
83             {
84                 FatalIOErrorIn
85                 (
86                     "void Foam::setRefCell\n"
87                      "(\n"
88                      "    const volScalarField&,\n"
89                      "    const volScalarField&,\n"
90                      "    const dictionary&,\n"
91                      "    label& scalar&,\n"
92                      "    bool\n"
93                      ")",
94                     dict
95                 )   << "Unable to set reference cell for field " << field.name()
96                     << nl << "    Reference point " << refPointName
97                     << " " << refPointi
98                     << " found on " << sumHasRef << " domains (should be one)"
99                     << nl << exit(FatalIOError);
100             }
101         }
102         else
103         {
104             FatalIOErrorIn
105             (
106                 "void Foam::setRefCell\n"
107                  "(\n"
108                  "    const volScalarField&,\n"
109                  "    const volScalarField&,\n"
110                  "    const dictionary&,\n"
111                  "    label& scalar&,\n"
112                  "    bool\n"
113                  ")",
114                 dict
115             )   << "Unable to set reference cell for field " << field.name()
116                 << nl
117                 << "    Please supply either " << refCellName
118                 << " or " << refPointName << nl << exit(FatalIOError);
119         }
121         refValue = readScalar(dict.lookup(refValueName));
122     }
126 void Foam::setRefCell
128     const volScalarField& field,
129     const dictionary& dict,
130     label& refCelli,
131     scalar& refValue,
132     const bool forceReference
135     setRefCell(field, field, dict, refCelli, refValue, forceReference);
139 Foam::scalar Foam::getRefCellValue
141     const volScalarField& field,
142     const label refCelli
145     scalar refCellValue = (refCelli >= 0 ? field[refCelli] : 0.0);
146     return returnReduce(refCellValue, sumOp<scalar>());
150 // ************************************************************************* //