2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2018-05-29 07:35:20 +00:00
|
|
|
\\ / O peration | Version: 4.1
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "readerDatabase.H"
|
|
|
|
#include "demandDrivenData.H"
|
|
|
|
#include "fvMesh.H"
|
|
|
|
#include "fvMeshSubset.H"
|
2015-06-17 13:53:59 +00:00
|
|
|
#include "foamTime.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
#include "fileName.H"
|
|
|
|
#include "instant.H"
|
|
|
|
#include "cellSet.H"
|
|
|
|
#include "cellModeller.H"
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
const bool Foam::readerDatabase::debug_ = Foam::env("readerDatabase");
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
|
|
|
|
|
|
|
// Gets cell numbers of all polyHedra
|
|
|
|
void Foam::readerDatabase::getPolyHedra()
|
|
|
|
{
|
|
|
|
const cellModel& tet = *(cellModeller::lookup("tet"));
|
|
|
|
const cellModel& pyr = *(cellModeller::lookup("pyr"));
|
|
|
|
const cellModel& prism = *(cellModeller::lookup("prism"));
|
|
|
|
const cellModel& wedge = *(cellModeller::lookup("wedge"));
|
|
|
|
const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
|
|
|
|
const cellModel& hex = *(cellModeller::lookup("hex"));
|
|
|
|
|
2019-02-01 12:36:12 +00:00
|
|
|
dynamicLabelList polys(mesh().nCells()/100 + 1);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
const cellShapeList& cellShapes = mesh().cellShapes();
|
|
|
|
|
|
|
|
forAll(cellShapes, celli)
|
|
|
|
{
|
|
|
|
const cellShape& cellShape = cellShapes[celli];
|
|
|
|
const cellModel& cellModel = cellShape.model();
|
|
|
|
|
|
|
|
if
|
|
|
|
(
|
|
|
|
(cellModel != tet)
|
|
|
|
&& (cellModel != pyr)
|
|
|
|
&& (cellModel != prism)
|
|
|
|
&& (cellModel != wedge)
|
|
|
|
&& (cellModel != tetWedge)
|
|
|
|
&& (cellModel != hex)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
polys.append(celli);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Info<< "Found " << polys.size() << " polyhedral cells " << endl;
|
|
|
|
polys_.transfer(polys);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
// Null constructor
|
|
|
|
Foam::readerDatabase::readerDatabase()
|
|
|
|
:
|
|
|
|
fieldviewNames_(10),
|
2019-01-25 16:22:44 +00:00
|
|
|
runTimePtr_(nullptr),
|
|
|
|
meshPtr_(nullptr),
|
2010-05-12 13:27:55 +00:00
|
|
|
setName_(""),
|
|
|
|
polys_(),
|
|
|
|
volScalarNames_(),
|
|
|
|
volVectorNames_()
|
|
|
|
{
|
|
|
|
// Initialize name mapping table. See note on static in header file.
|
|
|
|
fieldviewNames_.insert("alpha", "aalpha");
|
|
|
|
fieldviewNames_.insert("Alpha", "AAlpha");
|
|
|
|
fieldviewNames_.insert("fsmach", "ffsmach");
|
|
|
|
fieldviewNames_.insert("FSMach", "FFSMach");
|
|
|
|
fieldviewNames_.insert("re", "rre");
|
|
|
|
fieldviewNames_.insert("Re", "RRe");
|
|
|
|
fieldviewNames_.insert("time", "ttime");
|
|
|
|
fieldviewNames_.insert("Time", "TTime");
|
|
|
|
fieldviewNames_.insert("pi", "ppi");
|
|
|
|
fieldviewNames_.insert("PI", "PPI");
|
|
|
|
fieldviewNames_.insert("x", "xx");
|
|
|
|
fieldviewNames_.insert("X", "XX");
|
|
|
|
fieldviewNames_.insert("y", "yy");
|
|
|
|
fieldviewNames_.insert("Y", "YY");
|
|
|
|
fieldviewNames_.insert("z", "zz");
|
|
|
|
fieldviewNames_.insert("Z", "ZZ");
|
|
|
|
fieldviewNames_.insert("rcyl", "rrcyl");
|
|
|
|
fieldviewNames_.insert("Rcyl", "RRcyl");
|
|
|
|
fieldviewNames_.insert("theta", "ttheta");
|
|
|
|
fieldviewNames_.insert("Theta", "TTheta");
|
|
|
|
fieldviewNames_.insert("rsphere", "rrsphere");
|
|
|
|
fieldviewNames_.insert("Rsphere", "RRsphere");
|
|
|
|
fieldviewNames_.insert("k", "kk");
|
|
|
|
fieldviewNames_.insert("K", "KK");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
Foam::readerDatabase::~readerDatabase()
|
|
|
|
{
|
|
|
|
deleteDemandDrivenData(meshPtr_);
|
|
|
|
deleteDemandDrivenData(runTimePtr_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
const Foam::Time& Foam::readerDatabase::runTime() const
|
|
|
|
{
|
|
|
|
if (!runTimePtr_)
|
|
|
|
{
|
|
|
|
FatalErrorIn("readerDatabase::runTime()")
|
|
|
|
<< "No database set" << abort(FatalError);
|
|
|
|
}
|
|
|
|
return *runTimePtr_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Foam::fvMesh& Foam::readerDatabase::mesh() const
|
|
|
|
{
|
|
|
|
if (!meshPtr_)
|
|
|
|
{
|
|
|
|
FatalErrorIn("readerDatabase::runTime()")
|
|
|
|
<< "No mesh set" << abort(FatalError);
|
|
|
|
}
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (setName_.empty())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
return *meshPtr_;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
return meshPtr_->subMesh();
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Foam::labelList& Foam::readerDatabase::polys() const
|
|
|
|
{
|
|
|
|
return polys_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Foam::wordList& Foam::readerDatabase::volScalarNames() const
|
|
|
|
{
|
|
|
|
return volScalarNames_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Foam::wordList& Foam::readerDatabase::volVectorNames() const
|
|
|
|
{
|
|
|
|
return volVectorNames_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Foam::word& Foam::readerDatabase::getFvName(const word& foamName) const
|
|
|
|
{
|
|
|
|
if (fieldviewNames_.found(foamName))
|
|
|
|
{
|
|
|
|
return fieldviewNames_[foamName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return foamName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Foam::readerDatabase::setRunTime
|
|
|
|
(
|
|
|
|
const fileName& rootDir,
|
|
|
|
const fileName& caseName,
|
|
|
|
const word& setName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
bool newDatabase = false;
|
|
|
|
|
|
|
|
if (runTimePtr_)
|
|
|
|
{
|
|
|
|
if
|
|
|
|
(
|
|
|
|
(runTimePtr_->caseName() != caseName)
|
|
|
|
|| (runTimePtr_->rootPath() != rootDir)
|
|
|
|
|| (setName_ != setName)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (debug_)
|
|
|
|
{
|
|
|
|
Info<< "Deleting old mesh since deleting old database" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteDemandDrivenData(meshPtr_);
|
|
|
|
|
|
|
|
if (debug_)
|
|
|
|
{
|
|
|
|
Info<< "Deleting old database for " << runTimePtr_->caseName()
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteDemandDrivenData(runTimePtr_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setName_ = setName;
|
|
|
|
|
|
|
|
if (!runTimePtr_)
|
|
|
|
{
|
|
|
|
if (debug_)
|
|
|
|
{
|
|
|
|
Info<< "Deleting old mesh since loading new Time" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteDemandDrivenData(meshPtr_);
|
|
|
|
|
|
|
|
if (debug_)
|
|
|
|
{
|
|
|
|
Info<< "Creating database for " << caseName << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
runTimePtr_ = new Time(Time::controlDictName, rootDir, caseName);
|
|
|
|
|
|
|
|
newDatabase = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newDatabase;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::readerDatabase::loadMesh()
|
|
|
|
{
|
|
|
|
deleteDemandDrivenData(meshPtr_);
|
|
|
|
|
|
|
|
Info<< "Loading new mesh" << endl;
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
meshPtr_ = new fvMeshSubset
|
2010-05-12 13:27:55 +00:00
|
|
|
(
|
2010-08-25 21:42:57 +00:00
|
|
|
*runTimePtr_,
|
|
|
|
IOobject::MUST_READ,
|
|
|
|
IOobject::AUTO_WRITE
|
2010-05-12 13:27:55 +00:00
|
|
|
);
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (setName_.size())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
Info<< "Subsetting mesh based on cellSet " << setName_ << endl;
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
fvMeshSubset& mesh = *meshPtr_;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
cellSet currentSet(mesh, setName_);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
mesh.setCellSubset(currentSet);
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
getPolyHedra();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Foam::polyMesh::readUpdateState Foam::readerDatabase::setTime
|
|
|
|
(
|
|
|
|
const instant& timeInstance,
|
|
|
|
const label timeIndex
|
|
|
|
)
|
|
|
|
{
|
|
|
|
runTime().setTime(timeInstance, timeIndex);
|
|
|
|
|
|
|
|
polyMesh::readUpdateState meshChange;
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (meshPtr_)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
// Update loaded mesh
|
|
|
|
meshChange = meshPtr_->readUpdate();
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (setName_.size() && meshChange != polyMesh::UNCHANGED)
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< "Subsetting mesh based on " << setName_ << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
fvMeshSubset& mesh = *meshPtr_;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
cellSet currentSet(mesh, setName_);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
mesh.setCellSubset(currentSet);
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if
|
|
|
|
(
|
|
|
|
(meshChange == polyMesh::TOPO_CHANGE)
|
|
|
|
|| (meshChange == polyMesh::TOPO_PATCH_CHANGE)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
getPolyHedra();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Force new mesh to be loaded for current time
|
|
|
|
loadMesh();
|
|
|
|
meshChange = polyMesh::TOPO_CHANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return meshChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Foam::readerDatabase::setFieldNames
|
|
|
|
(
|
|
|
|
const wordList& vsNames,
|
|
|
|
const wordList& vvNames
|
|
|
|
)
|
|
|
|
{
|
|
|
|
volScalarNames_ = vsNames;
|
|
|
|
volVectorNames_ = vvNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|