FreeFOAM The Cross-Platform CFD Toolkit
basicSource.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) 2010-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 
26 #include "basicSource.H"
27 #include <finiteVolume/fvMesh.H>
28 #include <finiteVolume/volFields.H>
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(basicSource, 0);
36  defineRunTimeSelectionTable(basicSource, dictionary);
37 }
38 
39 
40 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
41 
43 (
44  IStringStream("(points cellSet cellZone all)")()
45 );
46 
47 
48 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
49 
51 (
52  const word& smtName
53 ) const
54 {
55  forAll(selectionModeTypeNames_, i)
56  {
57  if (smtName == selectionModeTypeNames_[i])
58  {
59  return selectionModeType(i);
60  }
61  }
62 
64  (
65  "basicSource::selectionModeType"
66  "basicSource::wordToSelectionModeType"
67  "("
68  "const word&"
69  ")"
70  ) << "Unknown selectionMode type " << smtName
71  << ". Valid selectionMode types are:" << nl << selectionModeTypeNames_
72  << exit(FatalError);
73 
74  return selectionModeType(0);
75 }
76 
77 
79 (
80  const selectionModeType& smtType
81 ) const
82 {
83  if (smtType > selectionModeTypeNames_.size())
84  {
85  return "UNKNOWN";
86  }
87  else
88  {
89  return selectionModeTypeNames_[smtType];
90  }
91 }
92 
93 
95 {
96  switch (selectionMode_)
97  {
98  case smPoints:
99  {
100  // Do nothing. It should be sorted out by derived class
101  break;
102  }
103  case smCellSet:
104  {
105  dict.lookup("cellSet") >> cellSetName_;
106  break;
107  }
108  case smCellZone:
109  {
110  dict.lookup("cellZone") >> cellSetName_;
111  break;
112  }
113  case smAll:
114  {
115  break;
116  }
117  default:
118  {
120  (
121  "basicSource::setSelection(const dictionary&)"
122  ) << "Unknown selectionMode "
124  << ". Valid selectionMode types are" << selectionModeTypeNames_
125  << exit(FatalError);
126  }
127  }
128 }
129 
130 
132 {
133  Info<< incrIndent << indent << "Source: " << name_ << endl;
134  switch (selectionMode_)
135  {
136  case smPoints:
137  {
138  break;
139  }
140  case smCellSet:
141  {
142  Info<< indent << "- selecting cells using cellSet "
143  << cellSetName_ << endl;
144 
145  cellSet selectedCells(mesh_, cellSetName_);
146  cells_ = selectedCells.toc();
147 
148  break;
149  }
150  case smCellZone:
151  {
152  Info<< indent << "- selecting cells using cellZone "
153  << cellSetName_ << endl;
154  label zoneID = mesh_.cellZones().findZoneID(cellSetName_);
155  if (zoneID == -1)
156  {
157  FatalErrorIn("basicSource<Type>::setCellIds()")
158  << "Cannot find cellZone " << cellSetName_ << endl
159  << "Valid cellZones are " << mesh_.cellZones().names()
160  << exit(FatalError);
161  }
162  cells_ = mesh_.cellZones()[zoneID];
163 
164  break;
165  }
166  case smAll:
167  {
168  Info<< indent << "- selecting all cells" << endl;
169  cells_ = identity(mesh_.nCells());
170 
171  break;
172  }
173  default:
174  {
175  FatalErrorIn("basicSource<Type>::setCellIds()")
176  << "Unknown selectionMode "
177  << selectionModeTypeNames_[selectionMode_]
178  << ". Valid selectionMode types are" << selectionModeTypeNames_
179  << exit(FatalError);
180  }
181  }
182 
183  // Set volume information
184  if (selectionMode_ != smPoints)
185  {
186  V_ = 0.0;
187  forAll(cells_, i)
188  {
189  V_ += mesh_.V()[cells_[i]];
190  }
191  reduce(V_, sumOp<scalar>());
192 
193  Info<< indent << "- selected "
194  << returnReduce(cells_.size(), sumOp<label>())
195  << " cell(s) with volume " << V_ << nl << decrIndent << endl;
196  }
197 }
198 
199 
200 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
201 
203 (
204  const word& name,
205  const dictionary& dict,
206  const fvMesh& mesh
207 )
208 :
209  name_(name),
210  mesh_(mesh),
211  dict_(dict),
212  active_(readBool(dict_.lookup("active"))),
213  timeStart_(readScalar(dict_.lookup("timeStart"))),
214  duration_(readScalar(dict_.lookup("duration"))),
215  selectionMode_(wordToSelectionModeType(dict_.lookup("selectionMode"))),
216  cellSetName_("none"),
217  V_(1.0)
218 {
219  setSelection(dict_);
220 
221  setCellSet();
222 }
223 
224 
225 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
226 
228 (
229  const word& name,
230  const dictionary& dict,
231  const fvMesh& mesh
232 )
233 {
234  word typeModel(dict.lookup("typeModel"));
235 
236  Info<< "Selecting model type " << typeModel << endl;
237 
238  dictionaryConstructorTable::iterator cstrIter =
239  dictionaryConstructorTablePtr_->find(typeModel);
240 
241  if (cstrIter == dictionaryConstructorTablePtr_->end())
242  {
244  (
245  "basicSource::New(const volVectorField&, "
246  "const surfaceScalarField&, transportModel&)"
247  ) << "Unknown Model type " << typeModel
248  << nl << nl
249  << "Valid model types are :" << nl
250  << dictionaryConstructorTablePtr_->sortedToc()
251  << exit(FatalError);
252  }
253 
254  return autoPtr<basicSource>(cstrIter()(name, dict, mesh));
255 }
256 
257 
258 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
259 
261 {
262  if
263  (
264  active_
265  && (mesh_.time().value() >= timeStart_)
266  && (mesh_.time().value() <= timeEnd())
267  )
268  {
269  // Update the cell set if the mesh is changing
270  if (mesh_.changing())
271  {
272  setCellSet();
273  }
274  return true;
275  }
276  else
277  {
278  return false;
279  }
280 }
281 
282 
283 // ************************************************************************* //