Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / postProcessing / graphics / fieldview9Reader / readerDatabase.C
blobc5c379d67354d006bfad2badc984572783704eea
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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"
28 #include "fvMesh.H"
29 #include "fvMeshSubset.H"
30 #include "foamTime.H"
31 #include "fileName.H"
32 #include "instant.H"
33 #include "cellSet.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)
58     {
59         const cellShape& cellShape = cellShapes[celli];
60         const cellModel& cellModel = cellShape.model();
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     }
76     Info<< "Found " << polys.size() << " polyhedral cells " << endl;
77     polys_.transfer(polys);
81 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
83 // Null constructor
84 Foam::readerDatabase::readerDatabase()
86     fieldviewNames_(10),
87     runTimePtr_(NULL),
88     meshPtr_(NULL),
89     setName_(""),
90     polys_(),
91     volScalarNames_(),
92     volVectorNames_()
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
135     if (!runTimePtr_)
136     {
137         FatalErrorIn("readerDatabase::runTime()")
138             << "No database set" << abort(FatalError);
139     }
140     return *runTimePtr_;
144 const Foam::fvMesh& Foam::readerDatabase::mesh() const
146     if (!meshPtr_)
147     {
148         FatalErrorIn("readerDatabase::runTime()")
149             << "No mesh set" << abort(FatalError);
150     }
152     if (setName_.empty())
153     {
154         return *meshPtr_;
155     }
156     else
157     {
158         return meshPtr_->subMesh();
159     }
163 const Foam::labelList& Foam::readerDatabase::polys() const
165     return polys_;
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))
184     {
185         return fieldviewNames_[foamName];
186     }
187     else
188     {
189         return foamName;
190     }
194 bool Foam::readerDatabase::setRunTime
196     const fileName& rootDir,
197     const fileName& caseName,
198     const word& setName
201     bool newDatabase = false;
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             }
217             deleteDemandDrivenData(meshPtr_);
219             if (debug_)
220             {
221                 Info<< "Deleting old database for " << runTimePtr_->caseName()
222                     << endl;
223             }
225             deleteDemandDrivenData(runTimePtr_);
226         }
227     }
229     setName_ = setName;
231     if (!runTimePtr_)
232     {
233         if (debug_)
234         {
235             Info<< "Deleting old mesh since loading new Time" << endl;
236         }
238         deleteDemandDrivenData(meshPtr_);
240         if (debug_)
241         {
242             Info<< "Creating database for " << caseName << endl;
243         }
245         runTimePtr_ = new Time(Time::controlDictName, rootDir, caseName);
247         newDatabase = true;
248     }
250     return newDatabase;
254 void Foam::readerDatabase::loadMesh()
256     deleteDemandDrivenData(meshPtr_);
258     Info<< "Loading new mesh" << endl;
260     meshPtr_ = new fvMeshSubset
261     (
262         *runTimePtr_,
263         IOobject::MUST_READ,
264         IOobject::AUTO_WRITE
265     );
267     if (setName_.size())
268     {
269         Info<< "Subsetting mesh based on cellSet " << setName_ << endl;
271         fvMeshSubset& mesh = *meshPtr_;
273         cellSet currentSet(mesh, setName_);
275         mesh.setCellSubset(currentSet);
276     }
277     getPolyHedra();
281 Foam::polyMesh::readUpdateState Foam::readerDatabase::setTime
283     const instant& timeInstance,
284     const label timeIndex
287     runTime().setTime(timeInstance, timeIndex);
289     polyMesh::readUpdateState meshChange;
291     if (meshPtr_)
292     {
293         // Update loaded mesh
294         meshChange = meshPtr_->readUpdate();
296         if (setName_.size() && meshChange != polyMesh::UNCHANGED)
297         {
298             Info<< "Subsetting mesh based on " << setName_ << endl;
300             fvMeshSubset& mesh = *meshPtr_;
302             cellSet currentSet(mesh, setName_);
304             mesh.setCellSubset(currentSet);
305         }
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     }
323     return meshChange;
327 void Foam::readerDatabase::setFieldNames
329    const wordList& vsNames,
330    const wordList& vvNames
333     volScalarNames_ = vsNames;
334     volVectorNames_ = vvNames;
340 // ************************************************************************* //