ed450ea4883c6ff4652872a4a5f7eae633e2f129
[OpenFOAM-1.5.x.git] / src / finiteVolume / cfdTools / general / findRefCell / findRefCell.C
blobed450ea4883c6ff4652872a4a5f7eae633e2f129
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 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
19     for more details.
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  * * * * * * * * * * * * * //
31 void Foam::setRefCell
33     const volScalarField& field,
34     const dictionary& dict,
35     label& refCelli,
36     scalar& refValue,
37     const bool forceReference
40     if (field.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 dictionary&,\n"
61                          "    label& scalar&,\n"
62                          "    bool\n"
63                          ")",
64                         dict
65                     )   << "Illegal master cellID " << refCelli
66                         << ". Should be 0.." << field.mesh().nCells()
67                         << exit(FatalIOError);
68                 }
69             }
70             else
71             {
72                 refCelli = -1;
73             }
74         }
75         else if (dict.found(refPointName))
76         {
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>());
81             if (sumHasRef != 1)
82             {
83                 FatalIOErrorIn
84                 (
85                     "void Foam::setRefCell\n"
86                      "(\n"
87                      "    const volScalarField&,\n"
88                      "    const dictionary&,\n"
89                      "    label& scalar&,\n"
90                      "    bool\n"
91                      ")",
92                     dict
93                 )   << "Unable to set reference cell for field " << field.name()
94                     << nl << "    Reference point " << refPointName
95                     << " found on " << sumHasRef << " domains (should be one)"
96                     << nl << exit(FatalIOError);
97             }
98         }
99         else
100         {
101             FatalIOErrorIn
102             (
103                 "void Foam::setRefCell\n"
104                  "(\n"
105                  "    const volScalarField&,\n"
106                  "    const dictionary&,\n"
107                  "    label& scalar&,\n"
108                  "    bool\n"
109                  ")",
110                 dict
111             )   << "Unable to set reference cell for field" << field.name()
112                 << nl
113                 << "    Please supply either " << refCellName
114                 << " or " << refPointName << nl << exit(FatalIOError);
115         }
117         refValue = readScalar(dict.lookup(refValueName));
118     }
122 Foam::scalar Foam::getRefCellValue
124     const volScalarField& field,
125     const label refCelli
128     scalar refCellValue = (refCelli >= 0 ? field[refCelli] : 0.0);
129     return returnReduce<label>(refCellValue, sumOp<scalar>());
133 // ************************************************************************* //