FreeFOAM The Cross-Platform CFD Toolkit
findRefCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
29 
31 (
32  const volScalarField& field,
33  const volScalarField& fieldRef,
34  const dictionary& dict,
35  label& refCelli,
36  scalar& refValue,
37  const bool forceReference
38 )
39 {
40  if (fieldRef.needReference() || forceReference)
41  {
42  word refCellName = field.name() + "RefCell";
43  word refPointName = field.name() + "RefPoint";
44 
45  word refValueName = field.name() + "RefValue";
46 
47  if (dict.found(refCellName))
48  {
49  if (Pstream::master())
50  {
51  refCelli = readLabel(dict.lookup(refCellName));
52 
53  if (refCelli < 0 || refCelli >= field.mesh().nCells())
54  {
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  {
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  {
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  }
120 
121  refValue = readScalar(dict.lookup(refValueName));
122  }
123 }
124 
125 
126 void Foam::setRefCell
127 (
128  const volScalarField& field,
129  const dictionary& dict,
130  label& refCelli,
131  scalar& refValue,
132  const bool forceReference
133 )
134 {
135  setRefCell(field, field, dict, refCelli, refValue, forceReference);
136 }
137 
138 
139 Foam::scalar Foam::getRefCellValue
140 (
141  const volScalarField& field,
142  const label refCelli
143 )
144 {
145  scalar refCellValue = (refCelli >= 0 ? field[refCelli] : 0.0);
146  return returnReduce(refCellValue, sumOp<scalar>());
147 }
148 
149 
150 // ************************ vim: set sw=4 sts=4 et: ************************ //