Skip to content
Snippets Groups Projects
Commit 6660ec17 authored by mattijs's avatar mattijs
Browse files

ENH: topoSet tool to replace cellSet,faceSet,pointSet.

parent c5b801c5
Branches
Tags
No related merge requests found
topoSet.C
EXE = $(FOAM_APPBIN)/topoSet
EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lmeshTools
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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/>.
Description
Operates on cellSets/faceSets/pointSets through a dictionary.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "polyMesh.H"
#include "topoSetSource.H"
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::addOption
(
"dict",
"file",
"specify an alternative dictionary for the topoSet dictionary"
);
# include "addRegionOption.H"
# include "setRootCase.H"
# include "createTime.H"
# include "createNamedPolyMesh.H"
const word dictName("topoSetDict");
fileName dictPath = dictName;
if (args.optionFound("dict"))
{
dictPath = args["dict"];
if (isDir(dictPath))
{
dictPath = dictPath / dictName;
}
}
Info<< "Reading " << dictName << "\n" << endl;
IOdictionary topoSetDict
(
(
args.optionFound("dict")
? IOobject
(
dictPath,
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
: IOobject
(
dictName,
runTime.system(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
);
// Read set construct info from dictionary
PtrList<dictionary> patchSources(topoSetDict.lookup("actions"));
forAll(patchSources, i)
{
const dictionary& dict = patchSources[i];
const word setName(dict.lookup("name"));
const word actionName(dict.lookup("action"));
const word setType(dict.lookup("type"));
topoSetSource::setAction action = topoSetSource::toAction(actionName);
autoPtr<topoSet> currentSet;
if
(
(action == topoSetSource::NEW)
|| (action == topoSetSource::CLEAR)
)
{
currentSet = topoSet::New(setType, mesh, setName, 10000);
Info<< "Created set " << setName << endl;
}
else if (action == topoSetSource::REMOVE)
{
//?
}
else
{
currentSet = topoSet::New
(
setType,
mesh,
setName,
IOobject::MUST_READ
);
Info<< "Read set " << setName << " with size "
<< currentSet().size() << endl;
}
// Handle special actions (clear, invert) locally, rest through sources.
switch (action)
{
case topoSetSource::NEW:
case topoSetSource::ADD:
case topoSetSource::DELETE:
case topoSetSource::SUBSET:
{
Info<< " Applying source " << word(dict.lookup("source"))
<< endl;
autoPtr<topoSetSource> source = topoSetSource::New
(
dict.lookup("source"),
mesh,
dict.subDict("sourceDict")
);
source().applyToSet(action, currentSet());
// Synchronize for coupled patches.
currentSet().sync(mesh);
currentSet().write();
}
break;
case topoSetSource::CLEAR:
Info<< " Clearing set" << endl;
currentSet().clear();
currentSet().write();
break;
case topoSetSource::INVERT:
Info<< " Inverting set" << endl;
currentSet().invert(currentSet().maxSize(mesh));
break;
default:
WarningIn(args.executable())
<< "Unhandled action " << action << endl;
break;
}
if (currentSet.valid())
{
Info<< " Set " << currentSet().name()
<< " now size " << currentSet().size()
<< endl;
}
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.6 |
| \\ / A nd | Web: http://www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object topoSetDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
actions
(
{
name c0;
type cellSet;
action new;
source labelToCell;
sourceDict
{
value (12 13 56); // labels of cells
}
}
{
name c0;
type cellSet;
action invert;
}
{
name c0;
type cellSet;
action delete;
source labelToCell;
sourceDict
{
value (1 2 3); // labels of cells
}
}
);
// ************************************************************************* //
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment