mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: topoSet: time loop
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -33,15 +33,72 @@ Description
|
||||
#include "cellSet.H"
|
||||
#include "faceSet.H"
|
||||
#include "pointSet.H"
|
||||
#include "globalMeshData.H"
|
||||
#include "timeSelector.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
void printMesh(const Time& runTime, const polyMesh& mesh)
|
||||
{
|
||||
Info<< "Time:" << runTime.timeName()
|
||||
<< " cells:" << mesh.globalData().nTotalCells()
|
||||
<< " faces:" << mesh.globalData().nTotalFaces()
|
||||
<< " points:" << mesh.globalData().nTotalPoints()
|
||||
<< " patches:" << mesh.boundaryMesh().size()
|
||||
<< " bb:" << mesh.bounds() << nl;
|
||||
}
|
||||
|
||||
|
||||
polyMesh::readUpdateState meshReadUpdate(polyMesh& mesh)
|
||||
{
|
||||
polyMesh::readUpdateState stat = mesh.readUpdate();
|
||||
|
||||
switch(stat)
|
||||
{
|
||||
case polyMesh::UNCHANGED:
|
||||
{
|
||||
Info<< " mesh not changed." << endl;
|
||||
break;
|
||||
}
|
||||
case polyMesh::POINTS_MOVED:
|
||||
{
|
||||
Info<< " points moved; topology unchanged." << endl;
|
||||
break;
|
||||
}
|
||||
case polyMesh::TOPO_CHANGE:
|
||||
{
|
||||
Info<< " topology changed; patches unchanged." << nl
|
||||
<< " ";
|
||||
printMesh(mesh.time(), mesh);
|
||||
break;
|
||||
}
|
||||
case polyMesh::TOPO_PATCH_CHANGE:
|
||||
{
|
||||
Info<< " topology changed and patches changed." << nl
|
||||
<< " ";
|
||||
printMesh(mesh.time(), mesh);
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
FatalErrorIn("meshReadUpdate(polyMesh&)")
|
||||
<< "Illegal mesh update state "
|
||||
<< stat << abort(FatalError);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
timeSelector::addOptions(true, false);
|
||||
argList::addOption
|
||||
(
|
||||
"dict",
|
||||
@ -57,6 +114,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
# include "setRootCase.H"
|
||||
# include "createTime.H"
|
||||
|
||||
instantList timeDirs = timeSelector::selectIfPresent(runTime, args);
|
||||
|
||||
# include "createNamedPolyMesh.H"
|
||||
|
||||
const bool noSync = args.optionFound("noSync");
|
||||
@ -99,128 +159,142 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
// Read set construct info from dictionary
|
||||
PtrList<dictionary> patchSources(topoSetDict.lookup("actions"));
|
||||
PtrList<dictionary> actions(topoSetDict.lookup("actions"));
|
||||
|
||||
forAll(patchSources, i)
|
||||
forAll(timeDirs, timeI)
|
||||
{
|
||||
const dictionary& dict = patchSources[i];
|
||||
runTime.setTime(timeDirs[timeI], timeI);
|
||||
Info<< "Time = " << runTime.timeName() << endl;
|
||||
|
||||
const word setName(dict.lookup("name"));
|
||||
const word actionName(dict.lookup("action"));
|
||||
const word setType(dict.lookup("type"));
|
||||
// Optionally re-read mesh
|
||||
meshReadUpdate(mesh);
|
||||
|
||||
|
||||
topoSetSource::setAction action = topoSetSource::toAction(actionName);
|
||||
|
||||
autoPtr<topoSet> currentSet;
|
||||
if
|
||||
(
|
||||
(action == topoSetSource::NEW)
|
||||
|| (action == topoSetSource::CLEAR)
|
||||
)
|
||||
// Execute all actions
|
||||
forAll(actions, i)
|
||||
{
|
||||
currentSet = topoSet::New(setType, mesh, setName, 10000);
|
||||
Info<< "Created set " << setName << endl;
|
||||
}
|
||||
else if (action == topoSetSource::REMOVE)
|
||||
{
|
||||
//?
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSet = topoSet::New
|
||||
const dictionary& dict = actions[i];
|
||||
|
||||
const word setName(dict.lookup("name"));
|
||||
const word actionName(dict.lookup("action"));
|
||||
const word setType(dict.lookup("type"));
|
||||
|
||||
|
||||
topoSetSource::setAction action = topoSetSource::toAction
|
||||
(
|
||||
setType,
|
||||
mesh,
|
||||
setName,
|
||||
IOobject::MUST_READ
|
||||
actionName
|
||||
);
|
||||
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:
|
||||
autoPtr<topoSet> currentSet;
|
||||
if
|
||||
(
|
||||
(action == topoSetSource::NEW)
|
||||
|| (action == topoSetSource::CLEAR)
|
||||
)
|
||||
{
|
||||
Info<< " Applying source " << word(dict.lookup("source"))
|
||||
<< endl;
|
||||
autoPtr<topoSetSource> source = topoSetSource::New
|
||||
(
|
||||
dict.lookup("source"),
|
||||
mesh,
|
||||
dict.subDict("sourceInfo")
|
||||
);
|
||||
|
||||
source().applyToSet(action, currentSet());
|
||||
// Synchronize for coupled patches.
|
||||
if (!noSync) currentSet().sync(mesh);
|
||||
currentSet().write();
|
||||
currentSet = topoSet::New(setType, mesh, setName, 10000);
|
||||
Info<< "Created set " << setName << endl;
|
||||
}
|
||||
break;
|
||||
|
||||
case topoSetSource::SUBSET:
|
||||
else if (action == topoSetSource::REMOVE)
|
||||
{
|
||||
Info<< " Applying source " << word(dict.lookup("source"))
|
||||
<< endl;
|
||||
autoPtr<topoSetSource> source = topoSetSource::New
|
||||
//?
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSet = topoSet::New
|
||||
(
|
||||
dict.lookup("source"),
|
||||
setType,
|
||||
mesh,
|
||||
dict.subDict("sourceInfo")
|
||||
setName,
|
||||
IOobject::MUST_READ
|
||||
);
|
||||
Info<< "Read set " << setName << " with size "
|
||||
<< currentSet().size() << endl;
|
||||
}
|
||||
|
||||
// Backup current set.
|
||||
autoPtr<topoSet> oldSet
|
||||
(
|
||||
topoSet::New
|
||||
|
||||
|
||||
// Handle special actions (clear, invert) locally, rest through
|
||||
// sources.
|
||||
switch (action)
|
||||
{
|
||||
case topoSetSource::NEW:
|
||||
case topoSetSource::ADD:
|
||||
case topoSetSource::DELETE:
|
||||
{
|
||||
Info<< " Applying source " << word(dict.lookup("source"))
|
||||
<< endl;
|
||||
autoPtr<topoSetSource> source = topoSetSource::New
|
||||
(
|
||||
setType,
|
||||
dict.lookup("source"),
|
||||
mesh,
|
||||
currentSet().name() + "_old2",
|
||||
currentSet()
|
||||
)
|
||||
);
|
||||
dict.subDict("sourceInfo")
|
||||
);
|
||||
|
||||
currentSet().clear();
|
||||
source().applyToSet(topoSetSource::NEW, currentSet());
|
||||
source().applyToSet(action, currentSet());
|
||||
// Synchronize for coupled patches.
|
||||
if (!noSync) currentSet().sync(mesh);
|
||||
currentSet().write();
|
||||
}
|
||||
break;
|
||||
|
||||
// Combine new value of currentSet with old one.
|
||||
currentSet().subset(oldSet());
|
||||
// Synchronize for coupled patches.
|
||||
if (!noSync) currentSet().sync(mesh);
|
||||
currentSet().write();
|
||||
case topoSetSource::SUBSET:
|
||||
{
|
||||
Info<< " Applying source " << word(dict.lookup("source"))
|
||||
<< endl;
|
||||
autoPtr<topoSetSource> source = topoSetSource::New
|
||||
(
|
||||
dict.lookup("source"),
|
||||
mesh,
|
||||
dict.subDict("sourceInfo")
|
||||
);
|
||||
|
||||
// Backup current set.
|
||||
autoPtr<topoSet> oldSet
|
||||
(
|
||||
topoSet::New
|
||||
(
|
||||
setType,
|
||||
mesh,
|
||||
currentSet().name() + "_old2",
|
||||
currentSet()
|
||||
)
|
||||
);
|
||||
|
||||
currentSet().clear();
|
||||
source().applyToSet(topoSetSource::NEW, currentSet());
|
||||
|
||||
// Combine new value of currentSet with old one.
|
||||
currentSet().subset(oldSet());
|
||||
// Synchronize for coupled patches.
|
||||
if (!noSync) 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));
|
||||
currentSet().write();
|
||||
break;
|
||||
|
||||
default:
|
||||
WarningIn(args.executable())
|
||||
<< "Unhandled action " << action << endl;
|
||||
break;
|
||||
}
|
||||
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));
|
||||
currentSet().write();
|
||||
break;
|
||||
|
||||
default:
|
||||
WarningIn(args.executable())
|
||||
<< "Unhandled action " << action << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentSet.valid())
|
||||
{
|
||||
Info<< " Set " << currentSet().name()
|
||||
<< " now size " << currentSet().size()
|
||||
<< endl;
|
||||
if (currentSet.valid())
|
||||
{
|
||||
Info<< " Set " << currentSet().name()
|
||||
<< " now size " << currentSet().size()
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user