Commit a67be719 authored by mattijs's avatar mattijs
Browse files

ENH: Added new ceeateZeroDirectory utility

Uses a system/caseProperties file to select templates from
etc/caseDicts/createZeroDirectoryTemplates to enable high-level setup
of a case.
See
- etc/caseDicts/createZeroDirectoryTemplates
- tutorials/preProcessing/createZeroDirectory
parent 7cb12e20
boundaryInfo.C
boundaryTemplates.C
caseInfo.C
solverTemplate.C
createZeroDirectory.C
EXE = $(FOAM_APPBIN)/createZeroDirectory
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/regionModels/regionModel/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-ldynamicMesh \
-lmeshTools \
-lregionModels
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM 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.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "boundaryInfo.H"
#include "Time.H"
#include "polyMesh.H"
#include "processorPolyPatch.H"
using namespace Foam;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTemplateTypeNameAndDebug(IOPtrList<entry>, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::IOPtrList<Foam::entry> Foam::boundaryInfo::readBoundaryDict
(
const Time& runTime,
const word& regionName
) const
{
Info<< " Reading mesh boundaries" << endl;
const_cast<word&>(IOPtrList<entry>::typeName) = polyBoundaryMesh::typeName;
IOPtrList<entry> boundaryPatchList
(
IOobject
(
"boundary",
runTime.findInstance(regionName/polyMesh::meshSubDir, "boundary"),
regionName/polyMesh::meshSubDir,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
// remove zero-sized patches
PtrList<entry> boundaryPatchListNew;
forAll(boundaryPatchList, patchI)
{
const dictionary& dict = boundaryPatchList[patchI].dict();
const word pType = dict.lookup("type");
bool procPatch = pType == processorPolyPatch::typeName;
bool addPatch = true;
if (!procPatch)
{
label nFaces = readLabel(dict.lookup("nFaces"));
reduce(nFaces, sumOp<label>());
if (nFaces == 0)
{
addPatch = false;
}
}
if (addPatch)
{
boundaryPatchListNew.append(boundaryPatchList[patchI].clone());
}
}
boundaryPatchList.transfer(boundaryPatchListNew);
return boundaryPatchList;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::boundaryInfo::boundaryInfo(const Time& runTime, const word& regionName)
:
boundaryDict_(readBoundaryDict(runTime, regionName)),
names_(),
types_(),
constraint_(),
groups_(),
allGroupNames_()
{
names_.setSize(boundaryDict_.size());
types_.setSize(boundaryDict_.size());
constraint_.setSize(boundaryDict_.size(), false);
groups_.setSize(boundaryDict_.size());
forAll(boundaryDict_, patchI)
{
const dictionary& dict = boundaryDict_[patchI].dict();
names_[patchI] = dict.dictName();
dict.lookup("type") >> types_[patchI];
if (polyPatch::constraintType(types_[patchI]))
{
constraint_[patchI] = true;
}
if (dict.found("inGroups"))
{
dict.lookup("inGroups") >> groups_[patchI];
allGroupNames_.insert(groups_[patchI]);
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::wordList& Foam::boundaryInfo::names() const
{
return names_;
}
const Foam::wordList& Foam::boundaryInfo::types() const
{
return types_;
}
const Foam::boolList& Foam::boundaryInfo::constraint() const
{
return constraint_;
}
const Foam::List<Foam::wordList>& Foam::boundaryInfo::groups() const
{
return groups_;
}
const Foam::wordHashSet& Foam::boundaryInfo::allGroupNames() const
{
return allGroupNames_;
}
void Foam::boundaryInfo::setType(const label patchI, const word& condition)
{
if (constraint_[patchI])
{
// not overriding constraint types
return;
}
if (wordRe(".*[mM]apped.*", wordRe::DETECT).match(types_[patchI]))
{
// ugly hack to avoid overriding mapped types
return;
}
if (condition == "wall")
{
types_[patchI] = condition;
}
else
{
types_[patchI] = "patch";
}
dictionary& patchDict = boundaryDict_[patchI].dict();
patchDict.add("type", types_[patchI], true);
}
void Foam::boundaryInfo::write() const
{
boundaryDict_.write();
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM 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.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::boundaryInfo
Description
Class to interrogate the polyMesh/boundary file to provide mesh patching
information, without the need to read the mesh.
\*---------------------------------------------------------------------------*/
#ifndef boundaryInfo_H
#define boundaryInfo_H
#include "boolList.H"
#include "wordList.H"
#include "HashSet.H"
#include "IOPtrList.H"
#include "entry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class Time;
/*---------------------------------------------------------------------------*\
Class boundaryInfo Declaration
\*---------------------------------------------------------------------------*/
class boundaryInfo
{
// Private data
//- Boundary dictionary
IOPtrList<entry> boundaryDict_;
//- Patch names
wordList names_;
//- Patch types
wordList types_;
//- Constraint flag
boolList constraint_;
//- Groups per patch
List<wordList> groups_;
//- Set of all group names
wordHashSet allGroupNames_;
// Private member functions
//- Read the boundary dict
IOPtrList<entry> readBoundaryDict
(
const Time& runTime,
const word& regionName
) const;
public:
//- Constructor
boundaryInfo(const Time& runTime, const word& regionName);
// Public member functions
//- Patch names
const wordList& names() const;
//- Patch types
const wordList& types() const;
//- Constraint flag
const boolList& constraint() const;
//- Groups
const List<wordList>& groups() const;
//- Set of all group names
const wordHashSet& allGroupNames() const;
//- Set the patch type based on the condition
void setType(const label patchI, const word& condition);
//- Write the boundary dictionary
void write() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM 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.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "boundaryTemplates.H"
#include "Time.H"
#include "IFstream.H"
#include "OStringStream.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::boundaryTemplates::boundaryTemplates
(
const fileName& baseDir,
const Time& runTime,
const word& solverType
)
:
templates_(dictionary::null),
options_(dictionary::null)
{
Info<< " Reading boundary templates" << endl;
fileName BCDir(baseDir/"boundaryConditions");
IOdictionary regionBCs
(
IOobject
(
fileName(BCDir/"boundaries"),
runTime,
IOobject::MUST_READ
)
);
forAllConstIter(dictionary, regionBCs, iter)
{
const word& regionType = iter().keyword();
wordList patchTypes(regionBCs.lookup(regionType));
dictionary regionTemplate = dictionary::null;
dictionary regionOptions = dictionary::null;
// read general boundary types
forAll(patchTypes, i)
{
IOdictionary dict
(
IOobject
(
fileName(BCDir/regionType/patchTypes[i]),
runTime,
IOobject::MUST_READ
)
);
regionTemplate.add(patchTypes[i], dictionary(dict));
}
// add solver type boundary types
forAll(patchTypes, i)
{
IOobject io
(
fileName(BCDir/regionType/solverType/patchTypes[i]),
runTime,
IOobject::MUST_READ
);
if (io.headerOk())
{
IOdictionary dict(io);
regionTemplate.subDict(patchTypes[i]).merge(dict);
}
}
// read general boundary options
forAll(patchTypes, i)
{
fileName optFile(BCDir/regionType/patchTypes[i] + "Options");
IFstream is(optFile);
if (is.good())
{
IOdictionary dict
(
IOobject
(
optFile,
runTime,
IOobject::MUST_READ
)
);
regionOptions.add(patchTypes[i], dictionary(dict));
}
}
// add solver type boundary options
forAll(patchTypes, i)
{
// options are optional - however, if file exists, assume that it
// is to be read
fileName optFile
(
BCDir/regionType/solverType/patchTypes[i] + "Options"
);
IFstream is(optFile);
if (is.good())
{
IOdictionary dict
(
IOobject
(
optFile,
runTime,
IOobject::MUST_READ
)
);
regionOptions.subDict(patchTypes[i]).merge(dict);
}
}
templates_.add(regionType, regionTemplate);
options_.add(regionType, regionOptions);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::dictionary& Foam::boundaryTemplates::templates() const
{
return templates_;
}
Foam::dictionary Foam::boundaryTemplates::generatePatchDict
(
const word& regionPrefix,
const word& fieldName,
const word& condition,
const word& category,
const word& patchType,
const dictionary& conditionOptions
) const
{
const dictionary& regionTemplates = templates_.subDict(regionPrefix);
// look for inlet, outlet, wall etc
if (regionTemplates.found(category))
{
const dictionary& categoryDict(regionTemplates.subDict(category));
// look for subSonic, slip etc
if (categoryDict.found(patchType))
{
dictionary patchDict = categoryDict.subDict(patchType);
// add any options
if (patchDict.found("OPTIONS"))
{
const dictionary& regionOptions =
options_.subDict(regionPrefix);
if (!regionOptions.found(category))
{
FatalError<< "No options available for category "
<< category << exit(FatalError);
}
const dictionary& dict = regionOptions.subDict(category);
const wordList requiredOptions(patchDict.lookup("OPTIONS"));
forAll(requiredOptions, i)
{
const word& option = requiredOptions[i];
word selected;
if (!conditionOptions.readIfPresent(option, selected))
{
FatalErrorIn
(
"Foam::dictionary "
"Foam::boundaryTemplates::generatePatchDict"
"("
"const word&, "
"const word&, "
"const word&, "
"const word&, "
"const word&, "
"const dictionary&"
") const"
)
<< "Condition " << condition << ": "
<< "No option '" << option
<< "' available for category '" << category
<< "' and patch type '" << patchType
<< "'. Valid options are: "
<< conditionOptions.toc()
<< exit(FatalError);
}
if (!dict.found(option))
{
FatalErrorIn
(
"Foam::dictionary "
"Foam::boundaryTemplates::generatePatchDict"
"("
"const word&, "
"const word&, "
"const word&, "
"const word&, "
"const word&, "
"const dictionary&"
") const"
)
<< "Condition " << condition << ": "
<< "No option '" << option
<< "' available for category '" << category