mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: have -loop option on setSet to enable -batch over a set of directories.
Only allowed in batch mode. Causes any set to be written to time directory instead of facesInstance.
This commit is contained in:
@ -45,6 +45,7 @@ Description
|
|||||||
#include "cellZoneSet.H"
|
#include "cellZoneSet.H"
|
||||||
#include "faceZoneSet.H"
|
#include "faceZoneSet.H"
|
||||||
#include "pointZoneSet.H"
|
#include "pointZoneSet.H"
|
||||||
|
#include "timeSelector.H"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -82,45 +83,6 @@ Istream& selectStream(Istream* is0Ptr, Istream* is1Ptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy set
|
|
||||||
void backup
|
|
||||||
(
|
|
||||||
const word& setType,
|
|
||||||
const polyMesh& mesh,
|
|
||||||
const word& fromName,
|
|
||||||
const topoSet& fromSet,
|
|
||||||
const word& toName
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (fromSet.size())
|
|
||||||
{
|
|
||||||
Info<< " Backing up " << fromName << " into " << toName << endl;
|
|
||||||
|
|
||||||
topoSet::New(setType, mesh, toName, fromSet)().write();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Read and copy set
|
|
||||||
void backup
|
|
||||||
(
|
|
||||||
const word& setType,
|
|
||||||
const polyMesh& mesh,
|
|
||||||
const word& fromName,
|
|
||||||
const word& toName
|
|
||||||
)
|
|
||||||
{
|
|
||||||
autoPtr<topoSet> fromSet = topoSet::New
|
|
||||||
(
|
|
||||||
setType,
|
|
||||||
mesh,
|
|
||||||
fromName,
|
|
||||||
IOobject::READ_IF_PRESENT
|
|
||||||
);
|
|
||||||
|
|
||||||
backup(setType, mesh, fromName, fromSet(), toName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Write set to VTK readable files
|
// Write set to VTK readable files
|
||||||
void writeVTK
|
void writeVTK
|
||||||
@ -477,6 +439,7 @@ bool doCommand
|
|||||||
const word& setName,
|
const word& setName,
|
||||||
const word& actionName,
|
const word& actionName,
|
||||||
const bool writeVTKFile,
|
const bool writeVTKFile,
|
||||||
|
const bool writeCurrentTime,
|
||||||
Istream& is
|
Istream& is
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -640,8 +603,6 @@ bool doCommand
|
|||||||
/currentSet.name()
|
/currentSet.name()
|
||||||
<< " and to vtk file " << vtkName << endl << endl;
|
<< " and to vtk file " << vtkName << endl << endl;
|
||||||
|
|
||||||
currentSet.write();
|
|
||||||
|
|
||||||
writeVTK(mesh, currentSet, vtkName);
|
writeVTK(mesh, currentSet, vtkName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -650,9 +611,13 @@ bool doCommand
|
|||||||
<< " (size " << currentSet.size() << ") to "
|
<< " (size " << currentSet.size() << ") to "
|
||||||
<< currentSet.instance()/currentSet.local()
|
<< currentSet.instance()/currentSet.local()
|
||||||
/currentSet.name() << endl << endl;
|
/currentSet.name() << endl << endl;
|
||||||
|
|
||||||
currentSet.write();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (writeCurrentTime)
|
||||||
|
{
|
||||||
|
currentSet.instance() = mesh.time().timeName();
|
||||||
|
}
|
||||||
|
currentSet.write();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -704,6 +669,48 @@ void printMesh(const Time& runTime, const polyMesh& mesh)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
commandStatus parseType
|
commandStatus parseType
|
||||||
(
|
(
|
||||||
@ -742,44 +749,10 @@ commandStatus parseType
|
|||||||
<< " to " << Times[nearestIndex].name()
|
<< " to " << Times[nearestIndex].name()
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
|
// Set time
|
||||||
runTime.setTime(Times[nearestIndex], nearestIndex);
|
runTime.setTime(Times[nearestIndex], nearestIndex);
|
||||||
polyMesh::readUpdateState stat = mesh.readUpdate();
|
// Optionally re-read mesh
|
||||||
|
meshReadUpdate(mesh);
|
||||||
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(runTime, mesh);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case polyMesh::TOPO_PATCH_CHANGE:
|
|
||||||
{
|
|
||||||
Info<< " topology changed and patches changed." << nl
|
|
||||||
<< " ";
|
|
||||||
printMesh(runTime, mesh);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
FatalErrorIn("parseType")
|
|
||||||
<< "Illegal mesh update state "
|
|
||||||
<< stat << abort(FatalError);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return INVALID;
|
return INVALID;
|
||||||
}
|
}
|
||||||
@ -852,23 +825,28 @@ commandStatus parseAction(const word& actionName)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
timeSelector::addOptions(true, false);
|
||||||
# include "addRegionOption.H"
|
# include "addRegionOption.H"
|
||||||
# include "addTimeOptions.H"
|
argList::addBoolOption("noVTK", "do not write VTK files");
|
||||||
|
argList::addBoolOption("loop", "execute batch commands for all timesteps");
|
||||||
argList::addBoolOption("noVTK");
|
|
||||||
argList::addOption("batch", "file");
|
argList::addOption("batch", "file");
|
||||||
|
|
||||||
# include "setRootCase.H"
|
# include "setRootCase.H"
|
||||||
# include "createTime.H"
|
# include "createTime.H"
|
||||||
|
instantList timeDirs = timeSelector::select0(runTime, args);
|
||||||
|
|
||||||
bool writeVTK = !args.optionFound("noVTK");
|
bool writeVTK = !args.optionFound("noVTK");
|
||||||
|
bool loop = args.optionFound("loop");
|
||||||
|
bool batch = args.optionFound("batch");
|
||||||
|
|
||||||
// Get times list
|
|
||||||
instantList Times = runTime.times();
|
|
||||||
|
|
||||||
# include "checkTimeOptions.H"
|
if (loop && !batch)
|
||||||
|
{
|
||||||
|
FatalErrorIn(args.executable())
|
||||||
|
<< "Can only loop when in batch mode."
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
runTime.setTime(Times[startTime], startTime);
|
|
||||||
|
|
||||||
# include "createNamedPolyMesh.H"
|
# include "createNamedPolyMesh.H"
|
||||||
|
|
||||||
@ -878,11 +856,34 @@ int main(int argc, char *argv[])
|
|||||||
// Print current sets
|
// Print current sets
|
||||||
printAllSets(mesh, Info);
|
printAllSets(mesh, Info);
|
||||||
|
|
||||||
|
// Read history if interactive
|
||||||
|
# if READLINE != 0
|
||||||
|
if (!batch && !read_history(historyFile))
|
||||||
|
{
|
||||||
|
Info<< "Successfully read history from " << historyFile << endl;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
|
||||||
std::ifstream* fileStreamPtr(NULL);
|
// Exit status
|
||||||
|
int status = 0;
|
||||||
|
|
||||||
if (args.optionFound("batch"))
|
|
||||||
|
forAll(timeDirs, timeI)
|
||||||
|
{
|
||||||
|
runTime.setTime(timeDirs[timeI], timeI);
|
||||||
|
Info<< "Time = " << runTime.timeName() << endl;
|
||||||
|
|
||||||
|
// Handle geometry/topology changes
|
||||||
|
meshReadUpdate(mesh);
|
||||||
|
|
||||||
|
|
||||||
|
// Main command read & execute loop
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
autoPtr<IFstream> fileStreamPtr(NULL);
|
||||||
|
|
||||||
|
if (batch)
|
||||||
{
|
{
|
||||||
fileName batchFile(args.option("batch"));
|
fileName batchFile(args.option("batch"));
|
||||||
|
|
||||||
@ -895,18 +896,14 @@ int main(int argc, char *argv[])
|
|||||||
<< "Cannot open file " << batchFile << exit(FatalError);
|
<< "Cannot open file " << batchFile << exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
fileStreamPtr = new std::ifstream(batchFile.c_str());
|
fileStreamPtr.reset(new IFstream(batchFile));
|
||||||
}
|
}
|
||||||
#if READLINE != 0
|
|
||||||
else if (!read_history(historyFile))
|
|
||||||
{
|
|
||||||
Info<< "Successfully read history from " << historyFile << endl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Info<< "Please type 'help', 'quit' or a set command after prompt." << endl;
|
Info<< "Please type 'help', 'quit' or a set command after prompt."
|
||||||
|
<< endl;
|
||||||
|
|
||||||
bool ok = true;
|
// Whether to quit
|
||||||
|
bool quit = false;
|
||||||
|
|
||||||
FatalError.throwExceptions();
|
FatalError.throwExceptions();
|
||||||
FatalIOError.throwExceptions();
|
FatalIOError.throwExceptions();
|
||||||
@ -924,15 +921,16 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
commandStatus stat = INVALID;
|
commandStatus stat = INVALID;
|
||||||
|
|
||||||
if (fileStreamPtr)
|
if (fileStreamPtr.valid())
|
||||||
{
|
{
|
||||||
if (!fileStreamPtr->good())
|
if (!fileStreamPtr().good())
|
||||||
{
|
{
|
||||||
Info<< "End of batch file" << endl;
|
Info<< "End of batch file" << endl;
|
||||||
|
// No error.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::getline(*fileStreamPtr, rawLine);
|
fileStreamPtr().getLine(rawLine);
|
||||||
|
|
||||||
if (rawLine.size())
|
if (rawLine.size())
|
||||||
{
|
{
|
||||||
@ -985,28 +983,44 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ok = true;
|
|
||||||
|
|
||||||
if (stat == QUIT)
|
if (stat == QUIT)
|
||||||
{
|
{
|
||||||
break;
|
// Make sure to quit
|
||||||
|
quit = true;
|
||||||
}
|
}
|
||||||
else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
|
else if (stat == VALIDSETCMD || stat == VALIDZONECMD)
|
||||||
{
|
{
|
||||||
ok = doCommand(mesh, setType, setName, actionName, writeVTK, is);
|
bool ok = doCommand
|
||||||
|
(
|
||||||
|
mesh,
|
||||||
|
setType,
|
||||||
|
setName,
|
||||||
|
actionName,
|
||||||
|
writeVTK,
|
||||||
|
loop, // if in looping mode dump sets to time directory
|
||||||
|
is
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
// Exit with error.
|
||||||
|
quit = true;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (ok);
|
} while (!quit);
|
||||||
|
|
||||||
|
if (quit)
|
||||||
if (fileStreamPtr)
|
|
||||||
{
|
{
|
||||||
delete fileStreamPtr;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< "\nEnd\n" << endl;
|
Info<< "\nEnd\n" << endl;
|
||||||
|
|
||||||
return 0;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user