Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "readerDatabase.H"
00027 #include <OpenFOAM/demandDrivenData.H>
00028 #include <finiteVolume/fvMesh.H>
00029 #include <finiteVolume/fvMeshSubset.H>
00030 #include <OpenFOAM/Time.H>
00031 #include <OpenFOAM/fileName.H>
00032 #include <OpenFOAM/instant.H>
00033 #include <meshTools/cellSet.H>
00034 #include <OpenFOAM/cellModeller.H>
00035
00036
00037
00038 const bool Foam::readerDatabase::debug_ = Foam::env("readerDatabase");
00039
00040
00041
00042
00043
00044 void Foam::readerDatabase::getPolyHedra()
00045 {
00046 const cellModel& tet = *(cellModeller::lookup("tet"));
00047 const cellModel& pyr = *(cellModeller::lookup("pyr"));
00048 const cellModel& prism = *(cellModeller::lookup("prism"));
00049 const cellModel& wedge = *(cellModeller::lookup("wedge"));
00050 const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
00051 const cellModel& hex = *(cellModeller::lookup("hex"));
00052
00053 DynamicList<label> polys(mesh().nCells()/100 + 1);
00054
00055 const cellShapeList& cellShapes = mesh().cellShapes();
00056
00057 forAll(cellShapes, celli)
00058 {
00059 const cellShape& cellShape = cellShapes[celli];
00060 const cellModel& cellModel = cellShape.model();
00061
00062 if
00063 (
00064 (cellModel != tet)
00065 && (cellModel != pyr)
00066 && (cellModel != prism)
00067 && (cellModel != wedge)
00068 && (cellModel != tetWedge)
00069 && (cellModel != hex)
00070 )
00071 {
00072 polys.append(celli);
00073 }
00074 }
00075
00076 Info<< "Found " << polys.size() << " polyhedral cells " << endl;
00077 polys_.transfer(polys);
00078 }
00079
00080
00081
00082
00083
00084 Foam::readerDatabase::readerDatabase()
00085 :
00086 fieldviewNames_(10),
00087 runTimePtr_(NULL),
00088 meshPtr_(NULL),
00089 setName_(""),
00090 polys_(),
00091 volScalarNames_(),
00092 volVectorNames_()
00093 {
00094
00095 fieldviewNames_.insert("alpha", "aalpha");
00096 fieldviewNames_.insert("Alpha", "AAlpha");
00097 fieldviewNames_.insert("fsmach", "ffsmach");
00098 fieldviewNames_.insert("FSMach", "FFSMach");
00099 fieldviewNames_.insert("re", "rre");
00100 fieldviewNames_.insert("Re", "RRe");
00101 fieldviewNames_.insert("time", "ttime");
00102 fieldviewNames_.insert("Time", "TTime");
00103 fieldviewNames_.insert("pi", "ppi");
00104 fieldviewNames_.insert("PI", "PPI");
00105 fieldviewNames_.insert("x", "xx");
00106 fieldviewNames_.insert("X", "XX");
00107 fieldviewNames_.insert("y", "yy");
00108 fieldviewNames_.insert("Y", "YY");
00109 fieldviewNames_.insert("z", "zz");
00110 fieldviewNames_.insert("Z", "ZZ");
00111 fieldviewNames_.insert("rcyl", "rrcyl");
00112 fieldviewNames_.insert("Rcyl", "RRcyl");
00113 fieldviewNames_.insert("theta", "ttheta");
00114 fieldviewNames_.insert("Theta", "TTheta");
00115 fieldviewNames_.insert("rsphere", "rrsphere");
00116 fieldviewNames_.insert("Rsphere", "RRsphere");
00117 fieldviewNames_.insert("k", "kk");
00118 fieldviewNames_.insert("Kcond", "KKcond");
00119 }
00120
00121
00122
00123
00124 Foam::readerDatabase::~readerDatabase()
00125 {
00126 deleteDemandDrivenData(meshPtr_);
00127 deleteDemandDrivenData(runTimePtr_);
00128 }
00129
00130
00131
00132
00133 const Foam::Time& Foam::readerDatabase::runTime() const
00134 {
00135 if (!runTimePtr_)
00136 {
00137 FatalErrorIn("readerDatabase::runTime()")
00138 << "No database set" << abort(FatalError);
00139 }
00140 return *runTimePtr_;
00141 }
00142
00143
00144 const Foam::fvMesh& Foam::readerDatabase::mesh() const
00145 {
00146 if (!meshPtr_)
00147 {
00148 FatalErrorIn("readerDatabase::runTime()")
00149 << "No mesh set" << abort(FatalError);
00150 }
00151
00152 if (setName_.empty())
00153 {
00154 return *meshPtr_;
00155 }
00156 else
00157 {
00158 return meshPtr_->subMesh();
00159 }
00160 }
00161
00162
00163 const Foam::labelList& Foam::readerDatabase::polys() const
00164 {
00165 return polys_;
00166 }
00167
00168
00169 const Foam::wordList& Foam::readerDatabase::volScalarNames() const
00170 {
00171 return volScalarNames_;
00172 }
00173
00174
00175 const Foam::wordList& Foam::readerDatabase::volVectorNames() const
00176 {
00177 return volVectorNames_;
00178 }
00179
00180
00181 const Foam::word& Foam::readerDatabase::getFvName(const word& foamName) const
00182 {
00183 if (fieldviewNames_.found(foamName))
00184 {
00185 return fieldviewNames_[foamName];
00186 }
00187 else
00188 {
00189 return foamName;
00190 }
00191 }
00192
00193
00194 bool Foam::readerDatabase::setRunTime
00195 (
00196 const fileName& rootDir,
00197 const fileName& caseName,
00198 const word& setName
00199 )
00200 {
00201 bool newDatabase = false;
00202
00203 if (runTimePtr_)
00204 {
00205 if
00206 (
00207 (runTimePtr_->caseName() != caseName)
00208 || (runTimePtr_->rootPath() != rootDir)
00209 || (setName_ != setName)
00210 )
00211 {
00212 if (debug_)
00213 {
00214 Info<< "Deleting old mesh since deleting old database" << endl;
00215 }
00216
00217 deleteDemandDrivenData(meshPtr_);
00218
00219 if (debug_)
00220 {
00221 Info<< "Deleting old database for " << runTimePtr_->caseName()
00222 << endl;
00223 }
00224
00225 deleteDemandDrivenData(runTimePtr_);
00226 }
00227 }
00228
00229 setName_ = setName;
00230
00231 if (!runTimePtr_)
00232 {
00233 if (debug_)
00234 {
00235 Info<< "Deleting old mesh since loading new Time" << endl;
00236 }
00237
00238 deleteDemandDrivenData(meshPtr_);
00239
00240 if (debug_)
00241 {
00242 Info<< "Creating database for " << caseName << endl;
00243 }
00244
00245 runTimePtr_ = new Time(Time::controlDictName, rootDir, caseName);
00246
00247 newDatabase = true;
00248 }
00249
00250 return newDatabase;
00251 }
00252
00253
00254 void Foam::readerDatabase::loadMesh()
00255 {
00256 deleteDemandDrivenData(meshPtr_);
00257
00258 Info<< "Loading new mesh" << endl;
00259
00260 meshPtr_ = new fvMeshSubset
00261 (
00262 *runTimePtr_,
00263 IOobject::MUST_READ,
00264 IOobject::AUTO_WRITE
00265 );
00266
00267 if (setName_.size())
00268 {
00269 Info<< "Subsetting mesh based on cellSet " << setName_ << endl;
00270
00271 fvMeshSubset& mesh = *meshPtr_;
00272
00273 cellSet currentSet(mesh, setName_);
00274
00275 mesh.setCellSubset(currentSet);
00276 }
00277 getPolyHedra();
00278 }
00279
00280
00281 Foam::polyMesh::readUpdateState Foam::readerDatabase::setTime
00282 (
00283 const instant& timeInstance,
00284 const label timeIndex
00285 )
00286 {
00287 runTime().setTime(timeInstance, timeIndex);
00288
00289 polyMesh::readUpdateState meshChange;
00290
00291 if (meshPtr_)
00292 {
00293
00294 meshChange = meshPtr_->readUpdate();
00295
00296 if (setName_.size() && meshChange != polyMesh::UNCHANGED)
00297 {
00298 Info<< "Subsetting mesh based on " << setName_ << endl;
00299
00300 fvMeshSubset& mesh = *meshPtr_;
00301
00302 cellSet currentSet(mesh, setName_);
00303
00304 mesh.setCellSubset(currentSet);
00305 }
00306
00307 if
00308 (
00309 (meshChange == polyMesh::TOPO_CHANGE)
00310 || (meshChange == polyMesh::TOPO_PATCH_CHANGE)
00311 )
00312 {
00313 getPolyHedra();
00314 }
00315 }
00316 else
00317 {
00318
00319 loadMesh();
00320 meshChange = polyMesh::TOPO_CHANGE;
00321 }
00322
00323 return meshChange;
00324 }
00325
00326
00327 void Foam::readerDatabase::setFieldNames
00328 (
00329 const wordList& vsNames,
00330 const wordList& vvNames
00331 )
00332 {
00333 volScalarNames_ = vsNames;
00334 volVectorNames_ = vvNames;
00335 }
00336
00337
00338
00339
00340