FreeFOAM The Cross-Platform CFD Toolkit
readerDatabase.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 
26 #include "readerDatabase.H"
28 #include <finiteVolume/fvMesh.H>
30 #include <OpenFOAM/Time.H>
31 #include <OpenFOAM/fileName.H>
32 #include <OpenFOAM/instant.H>
33 #include <meshTools/cellSet.H>
34 #include <OpenFOAM/cellModeller.H>
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 const bool Foam::readerDatabase::debug_ = Foam::env("readerDatabase");
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 // Gets cell numbers of all polyHedra
44 void Foam::readerDatabase::getPolyHedra()
45 {
46  const cellModel& tet = *(cellModeller::lookup("tet"));
47  const cellModel& pyr = *(cellModeller::lookup("pyr"));
48  const cellModel& prism = *(cellModeller::lookup("prism"));
49  const cellModel& wedge = *(cellModeller::lookup("wedge"));
50  const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
51  const cellModel& hex = *(cellModeller::lookup("hex"));
52 
53  DynamicList<label> polys(mesh().nCells()/100 + 1);
54 
56 
57  forAll(cellShapes, celli)
58  {
59  const cellShape& cellShape = cellShapes[celli];
60  const cellModel& cellModel = cellShape.model();
61 
62  if
63  (
64  (cellModel != tet)
65  && (cellModel != pyr)
66  && (cellModel != prism)
67  && (cellModel != wedge)
68  && (cellModel != tetWedge)
69  && (cellModel != hex)
70  )
71  {
72  polys.append(celli);
73  }
74  }
75 
76  Info<< "Found " << polys.size() << " polyhedral cells " << endl;
77  polys_.transfer(polys);
78 }
79 
80 
81 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
82 
83 // Null constructor
85 :
86  fieldviewNames_(10),
87  runTimePtr_(NULL),
88  meshPtr_(NULL),
89  setName_(""),
90  polys_(),
91  volScalarNames_(),
92  volVectorNames_()
93 {
94  // Initialize name mapping table. See note on static in header file.
95  fieldviewNames_.insert("alpha", "aalpha");
96  fieldviewNames_.insert("Alpha", "AAlpha");
97  fieldviewNames_.insert("fsmach", "ffsmach");
98  fieldviewNames_.insert("FSMach", "FFSMach");
99  fieldviewNames_.insert("re", "rre");
100  fieldviewNames_.insert("Re", "RRe");
101  fieldviewNames_.insert("time", "ttime");
102  fieldviewNames_.insert("Time", "TTime");
103  fieldviewNames_.insert("pi", "ppi");
104  fieldviewNames_.insert("PI", "PPI");
105  fieldviewNames_.insert("x", "xx");
106  fieldviewNames_.insert("X", "XX");
107  fieldviewNames_.insert("y", "yy");
108  fieldviewNames_.insert("Y", "YY");
109  fieldviewNames_.insert("z", "zz");
110  fieldviewNames_.insert("Z", "ZZ");
111  fieldviewNames_.insert("rcyl", "rrcyl");
112  fieldviewNames_.insert("Rcyl", "RRcyl");
113  fieldviewNames_.insert("theta", "ttheta");
114  fieldviewNames_.insert("Theta", "TTheta");
115  fieldviewNames_.insert("rsphere", "rrsphere");
116  fieldviewNames_.insert("Rsphere", "RRsphere");
117  fieldviewNames_.insert("k", "kk");
118  fieldviewNames_.insert("Kcond", "KKcond");
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
123 
125 {
126  deleteDemandDrivenData(meshPtr_);
127  deleteDemandDrivenData(runTimePtr_);
128 }
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
134 {
135  if (!runTimePtr_)
136  {
137  FatalErrorIn("readerDatabase::runTime()")
138  << "No database set" << abort(FatalError);
139  }
140  return *runTimePtr_;
141 }
142 
143 
145 {
146  if (!meshPtr_)
147  {
148  FatalErrorIn("readerDatabase::runTime()")
149  << "No mesh set" << abort(FatalError);
150  }
151 
152  if (setName_.empty())
153  {
154  return *meshPtr_;
155  }
156  else
157  {
158  return meshPtr_->subMesh();
159  }
160 }
161 
162 
164 {
165  return polys_;
166 }
167 
168 
170 {
171  return volScalarNames_;
172 }
173 
174 
176 {
177  return volVectorNames_;
178 }
179 
180 
181 const Foam::word& Foam::readerDatabase::getFvName(const word& foamName) const
182 {
183  if (fieldviewNames_.found(foamName))
184  {
185  return fieldviewNames_[foamName];
186  }
187  else
188  {
189  return foamName;
190  }
191 }
192 
193 
195 (
196  const fileName& rootDir,
197  const fileName& caseName,
198  const word& setName
199 )
200 {
201  bool newDatabase = false;
202 
203  if (runTimePtr_)
204  {
205  if
206  (
207  (runTimePtr_->caseName() != caseName)
208  || (runTimePtr_->rootPath() != rootDir)
209  || (setName_ != setName)
210  )
211  {
212  if (debug_)
213  {
214  Info<< "Deleting old mesh since deleting old database" << endl;
215  }
216 
217  deleteDemandDrivenData(meshPtr_);
218 
219  if (debug_)
220  {
221  Info<< "Deleting old database for " << runTimePtr_->caseName()
222  << endl;
223  }
224 
225  deleteDemandDrivenData(runTimePtr_);
226  }
227  }
228 
229  setName_ = setName;
230 
231  if (!runTimePtr_)
232  {
233  if (debug_)
234  {
235  Info<< "Deleting old mesh since loading new Time" << endl;
236  }
237 
238  deleteDemandDrivenData(meshPtr_);
239 
240  if (debug_)
241  {
242  Info<< "Creating database for " << caseName << endl;
243  }
244 
245  runTimePtr_ = new Time(Time::controlDictName, rootDir, caseName);
246 
247  newDatabase = true;
248  }
249 
250  return newDatabase;
251 }
252 
253 
255 {
256  deleteDemandDrivenData(meshPtr_);
257 
258  Info<< "Loading new mesh" << endl;
259 
260  meshPtr_ = new fvMeshSubset
261  (
262  *runTimePtr_,
265  );
266 
267  if (setName_.size())
268  {
269  Info<< "Subsetting mesh based on cellSet " << setName_ << endl;
270 
271  fvMeshSubset& mesh = *meshPtr_;
272 
273  cellSet currentSet(mesh, setName_);
274 
275  mesh.setCellSubset(currentSet);
276  }
277  getPolyHedra();
278 }
279 
280 
282 (
283  const instant& timeInstance,
284  const label timeIndex
285 )
286 {
287  runTime().setTime(timeInstance, timeIndex);
288 
289  polyMesh::readUpdateState meshChange;
290 
291  if (meshPtr_)
292  {
293  // Update loaded mesh
294  meshChange = meshPtr_->readUpdate();
295 
296  if (setName_.size() && meshChange != polyMesh::UNCHANGED)
297  {
298  Info<< "Subsetting mesh based on " << setName_ << endl;
299 
300  fvMeshSubset& mesh = *meshPtr_;
301 
302  cellSet currentSet(mesh, setName_);
303 
304  mesh.setCellSubset(currentSet);
305  }
306 
307  if
308  (
309  (meshChange == polyMesh::TOPO_CHANGE)
310  || (meshChange == polyMesh::TOPO_PATCH_CHANGE)
311  )
312  {
313  getPolyHedra();
314  }
315  }
316  else
317  {
318  // Force new mesh to be loaded for current time
319  loadMesh();
320  meshChange = polyMesh::TOPO_CHANGE;
321  }
322 
323  return meshChange;
324 }
325 
326 
328 (
329  const wordList& vsNames,
330  const wordList& vvNames
331 )
332 {
333  volScalarNames_ = vsNames;
334  volVectorNames_ = vvNames;
335 }
336 
337 
338 
339 
340 // ************************ vim: set sw=4 sts=4 et: ************************ //