1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "readerDatabase.H"
27 #include "demandDrivenData.H"
29 #include "fvMeshSubset.H"
34 #include "cellModeller.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 const bool Foam::readerDatabase::debug_ = Foam::env("readerDatabase");
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 // Gets cell numbers of all polyHedra
44 void Foam::readerDatabase::getPolyHedra()
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"));
53 DynamicList<label> polys(mesh().nCells()/100 + 1);
55 const cellShapeList& cellShapes = mesh().cellShapes();
57 forAll(cellShapes, celli)
59 const cellShape& cellShape = cellShapes[celli];
60 const cellModel& cellModel = cellShape.model();
66 && (cellModel != prism)
67 && (cellModel != wedge)
68 && (cellModel != tetWedge)
76 Info<< "Found " << polys.size() << " polyhedral cells " << endl;
77 polys_.transfer(polys);
81 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
84 Foam::readerDatabase::readerDatabase()
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("K", "KK");
122 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
124 Foam::readerDatabase::~readerDatabase()
126 deleteDemandDrivenData(meshPtr_);
127 deleteDemandDrivenData(runTimePtr_);
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 const Foam::Time& Foam::readerDatabase::runTime() const
137 FatalErrorIn("readerDatabase::runTime()")
138 << "No database set" << abort(FatalError);
144 const Foam::fvMesh& Foam::readerDatabase::mesh() const
148 FatalErrorIn("readerDatabase::runTime()")
149 << "No mesh set" << abort(FatalError);
152 if (setName_.empty())
158 return meshPtr_->subMesh();
163 const Foam::labelList& Foam::readerDatabase::polys() const
169 const Foam::wordList& Foam::readerDatabase::volScalarNames() const
171 return volScalarNames_;
175 const Foam::wordList& Foam::readerDatabase::volVectorNames() const
177 return volVectorNames_;
181 const Foam::word& Foam::readerDatabase::getFvName(const word& foamName) const
183 if (fieldviewNames_.found(foamName))
185 return fieldviewNames_[foamName];
194 bool Foam::readerDatabase::setRunTime
196 const fileName& rootDir,
197 const fileName& caseName,
201 bool newDatabase = false;
207 (runTimePtr_->caseName() != caseName)
208 || (runTimePtr_->rootPath() != rootDir)
209 || (setName_ != setName)
214 Info<< "Deleting old mesh since deleting old database" << endl;
217 deleteDemandDrivenData(meshPtr_);
221 Info<< "Deleting old database for " << runTimePtr_->caseName()
225 deleteDemandDrivenData(runTimePtr_);
235 Info<< "Deleting old mesh since loading new Time" << endl;
238 deleteDemandDrivenData(meshPtr_);
242 Info<< "Creating database for " << caseName << endl;
245 runTimePtr_ = new Time(Time::controlDictName, rootDir, caseName);
254 void Foam::readerDatabase::loadMesh()
256 deleteDemandDrivenData(meshPtr_);
258 Info<< "Loading new mesh" << endl;
260 meshPtr_ = new fvMeshSubset
269 Info<< "Subsetting mesh based on cellSet " << setName_ << endl;
271 fvMeshSubset& mesh = *meshPtr_;
273 cellSet currentSet(mesh, setName_);
275 mesh.setCellSubset(currentSet);
281 Foam::polyMesh::readUpdateState Foam::readerDatabase::setTime
283 const instant& timeInstance,
284 const label timeIndex
287 runTime().setTime(timeInstance, timeIndex);
289 polyMesh::readUpdateState meshChange;
293 // Update loaded mesh
294 meshChange = meshPtr_->readUpdate();
296 if (setName_.size() && meshChange != polyMesh::UNCHANGED)
298 Info<< "Subsetting mesh based on " << setName_ << endl;
300 fvMeshSubset& mesh = *meshPtr_;
302 cellSet currentSet(mesh, setName_);
304 mesh.setCellSubset(currentSet);
309 (meshChange == polyMesh::TOPO_CHANGE)
310 || (meshChange == polyMesh::TOPO_PATCH_CHANGE)
318 // Force new mesh to be loaded for current time
320 meshChange = polyMesh::TOPO_CHANGE;
327 void Foam::readerDatabase::setFieldNames
329 const wordList& vsNames,
330 const wordList& vvNames
333 volScalarNames_ = vsNames;
334 volVectorNames_ = vvNames;
340 // ************************************************************************* //