Commit 689d4b28 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: provide operator[] for accessing argList options.

- operator[] with label -> get args at index
- operator[] with word  -> get named option
parent b61537bd
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -90,7 +90,7 @@ int main(int argc, char *argv[])
if (args.optionFound("flag"))
{
Info<<"-flag:" << args.option("flag") << endl;
Info<<"-flag:" << args["flag"] << endl;
}
if (args.optionReadIfPresent<scalar>("float", xxx))
......
......@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
if (args.optionFound("ext"))
{
if (mvBak(srcFile, args.option("ext")))
if (mvBak(srcFile, args["ext"]))
{
ok++;
}
......
......@@ -94,11 +94,11 @@ int main(int argc, char *argv[])
{
for (label count = 0; count < repeat; ++count)
{
IFstream is(args.option("file"));
IFstream is(args["file"]);
if (count == 0)
{
Info<< "tokenizing file: " << args.option("file") << nl;
Info<< "tokenizing file: " << args["file"] << nl;
}
while (is.good())
......
......@@ -101,20 +101,17 @@ int main(int argc, char *argv[])
// List of cells to refine
//
bool useSet = args.optionFound("useSet");
if (useSet)
word setName;
if (args.optionReadIfPresent("useSet", setName))
{
word setName(args.option("useSet"));
Info<< "Subsetting cells to cut based on cellSet" << setName << endl
<< endl;
Info<< "Subsetting cells to cut based on cellSet"
<< setName << nl << endl;
cellSet cells(mesh, setName);
Info<< "Read " << cells.size() << " cells from cellSet "
<< cells.instance()/cells.local()/cells.name()
<< endl << endl;
<< nl << endl;
for
(
......@@ -125,8 +122,8 @@ int main(int argc, char *argv[])
{
cutCells.erase(iter.key());
}
Info<< "Removed from cells to cut all the ones not in set " << setName
<< endl << endl;
Info<< "Removed from cells to cut all the ones not in set "
<< setName << nl << endl;
}
// Mark all meshpoints on patch
......@@ -180,9 +177,9 @@ int main(int argc, char *argv[])
allCutEdges.shrink();
allCutEdgeWeights.shrink();
Info<< "Cutting:" << endl
<< " cells:" << cutCells.size() << endl
<< " edges:" << allCutEdges.size() << endl
Info<< "Cutting:" << nl
<< " cells:" << cutCells.size() << nl
<< " edges:" << allCutEdges.size() << nl
<< endl;
// Transfer DynamicLists to straight ones.
......
......@@ -552,7 +552,7 @@ int main(int argc, char *argv[])
<< "edge snapping tol : " << edgeTol << nl;
if (readSet)
{
Info<< "candidate cells : cellSet " << args.option("set") << nl;
Info<< "candidate cells : cellSet " << args["set"] << nl;
}
else
{
......@@ -580,7 +580,7 @@ int main(int argc, char *argv[])
if (readSet)
{
// Read cells to cut from cellSet
cellSet cells(mesh, args.option("set"));
cellSet cells(mesh, args["set"]);
cellsToCut = cells;
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -68,15 +68,12 @@ int main(int argc, char *argv[])
# include "createTime.H"
fileName kivaFileName("otape17");
if (args.optionFound("file"))
{
kivaFileName = args.option("file");
}
args.optionReadIfPresent("file", kivaFileName);
kivaVersions kivaVersion = kiva3v;
if (args.optionFound("version"))
{
word kivaVersionName = args.option("version");
const word kivaVersionName = args["version"];
if (kivaVersionName == "kiva3")
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -463,7 +463,7 @@ int main(int argc, char *argv[])
}
if (doCellSet)
{
word setName(args.option("cellSet"));
const word setName = args["cellSet"];
cellSet cells(mesh, setName);
......@@ -475,7 +475,7 @@ int main(int argc, char *argv[])
}
if (doFaceSet)
{
word setName(args.option("faceSet"));
const word setName = args["faceSet"];
faceSet faces(mesh, setName);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -110,7 +110,7 @@ int main(int argc, char *argv[])
if (args.optionFound("dict"))
{
fileName dictPath(args.option("dict"));
const fileName dictPath = args["dict"];
meshDictIoPtr.set
(
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -835,15 +835,14 @@ int main(int argc, char *argv[])
# include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
bool writeVTK = !args.optionFound("noVTK");
bool loop = args.optionFound("loop");
bool batch = args.optionFound("batch");
const bool writeVTK = !args.optionFound("noVTK");
const bool loop = args.optionFound("loop");
const bool batch = args.optionFound("batch");
if (loop && !batch)
{
FatalErrorIn(args.executable())
<< "Can only loop when in batch mode."
<< "Can only loop in batch mode."
<< exit(FatalError);
}
......@@ -885,7 +884,7 @@ int main(int argc, char *argv[])
if (batch)
{
fileName batchFile(args.option("batch"));
const fileName batchFile = args["batch"];
Info<< "Reading commands from file " << batchFile << endl;
......
......@@ -1326,9 +1326,8 @@ int main(int argc, char *argv[])
const word oldInstance = mesh.pointsInstance();
word blockedFacesName;
if (args.optionFound("blockedFaces"))
if (args.optionReadIfPresent("blockedFaces", blockedFacesName))
{
blockedFacesName = args.option("blockedFaces");
Info<< "Reading blocked internal faces from faceSet "
<< blockedFacesName << nl << endl;
}
......@@ -1882,7 +1881,7 @@ int main(int argc, char *argv[])
if (insidePoint)
{
point insidePoint(args.optionLookup("insidePoint")());
const point insidePoint = args.optionRead<point>("insidePoint");
label regionI = -1;
......
......@@ -174,7 +174,7 @@ int main(int argc, char *argv[])
if (args.optionFound("patch"))
{
word patchName(args.option("patch"));
const word patchName = args["patch"];
patchI = mesh.boundaryMesh().findPatchID(patchName);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -210,7 +210,9 @@ int main(int argc, char *argv[])
)
);
const bool doRotateFields = args.optionFound("rotateFields");
// this is not actually stringent enough:
if (args.options().empty())
{
FatalErrorIn(args.executable())
......@@ -219,18 +221,20 @@ int main(int argc, char *argv[])
<< exit(FatalError);
}
if (args.optionFound("translate"))
vector v;
if (args.optionReadIfPresent("translate", v))
{
vector transVector(args.optionLookup("translate")());
Info<< "Translating points by " << v << endl;
Info<< "Translating points by " << transVector << endl;
points += transVector;
points += v;
}
if (args.optionFound("rotate"))
{
Pair<vector> n1n2(args.optionLookup("rotate")());
Pair<vector> n1n2
(
args.optionLookup("rotate")()
);
n1n2[0] /= mag(n1n2[0]);
n1n2[1] /= mag(n1n2[1]);
tensor T = rotationTensor(n1n2[0], n1n2[1]);
......@@ -239,20 +243,17 @@ int main(int argc, char *argv[])
points = transform(T, points);
if (args.optionFound("rotateFields"))
if (doRotateFields)
{
rotateFields(args, runTime, T);
}
}
else if (args.optionFound("rollPitchYaw"))
else if (args.optionReadIfPresent("rollPitchYaw", v))
{
vector v(args.optionLookup("rollPitchYaw")());
Info<< "Rotating points by" << nl
<< " roll " << v.x() << nl
<< " pitch " << v.y() << nl
<< " yaw " << v.z() << endl;
<< " yaw " << v.z() << nl;
// Convert to radians
v *= pi/180.0;
......@@ -262,20 +263,17 @@ int main(int argc, char *argv[])
Info<< "Rotating points by quaternion " << R << endl;
points = transform(R, points);
if (args.optionFound("rotateFields"))
if (doRotateFields)
{
rotateFields(args, runTime, R.R());
}
}
else if (args.optionFound("yawPitchRoll"))
else if (args.optionReadIfPresent("yawPitchRoll", v))
{
vector v(args.optionLookup("yawPitchRoll")());
Info<< "Rotating points by" << nl
<< " yaw " << v.x() << nl
<< " pitch " << v.y() << nl
<< " roll " << v.z() << endl;
<< " roll " << v.z() << nl;
// Convert to radians
v *= pi/180.0;
......@@ -291,21 +289,19 @@ int main(int argc, char *argv[])
Info<< "Rotating points by quaternion " << R << endl;
points = transform(R, points);
if (args.optionFound("rotateFields"))
if (doRotateFields)
{
rotateFields(args, runTime, R.R());
}
}
if (args.optionFound("scale"))
if (args.optionReadIfPresent("scale", v))
{
vector scaleVector(args.optionLookup("scale")());
Info<< "Scaling points by " << scaleVector << endl;
Info<< "Scaling points by " << v << endl;
points.replace(vector::X, scaleVector.x()*points.component(vector::X));
points.replace(vector::Y, scaleVector.y()*points.component(vector::Y));
points.replace(vector::Z, scaleVector.z()*points.component(vector::Z));
points.replace(vector::X, v.x()*points.component(vector::X));
points.replace(vector::Y, v.y()*points.component(vector::Y));
points.replace(vector::Z, v.z()*points.component(vector::Z));
}
// Set the precision of the points data to 10
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -66,7 +66,7 @@ int main(int argc, char *argv[])
{
fileName dictFileName
(
args.rootPath()/args.caseName()/args.option("dictionary")
args.rootPath()/args.caseName()/args["dictionary"]
);
IFstream dictFile(dictFileName);
......@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
true // wildcards
);
for (int i=1; i<entryNames.size(); i++)
for (int i=1; i<entryNames.size(); ++i)
{
if (entPtr->dict().found(entryNames[i]))
{
......@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
{
FatalErrorIn(args.executable())
<< "Cannot find sub-entry " << entryNames[i]
<< " in entry " << args.option("entry")
<< " in entry " << args["entry"]
<< " in dictionary " << dictFileName;
FatalError.exit(3);
}
......@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
{
FatalErrorIn(args.executable())
<< "Cannot find entry "
<< args.option("entry")
<< args["entry"]
<< " in dictionary " << dictFileName
<< " is not a sub-dictionary";
FatalError.exit(4);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -80,7 +80,10 @@ Foam::ensightMesh::ensightMesh
if (args.optionFound("patches"))
{
wordList patchNameList(args.optionLookup("patches")());
wordList patchNameList
(
args.optionLookup("patches")()
);
if (patchNameList.empty())
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -215,9 +215,8 @@ int main(int argc, char *argv[])
word cellSetName;
string vtkName;
if (args.optionFound("cellSet"))
if (args.optionReadIfPresent("cellSet", cellSetName))
{
cellSetName = args.option("cellSet");
vtkName = cellSetName;
}
else if (Pstream::parRun())
......@@ -738,7 +737,7 @@ int main(int argc, char *argv[])
if (args.optionFound("faceSet"))
{
// Load the faceSet
word setName(args.option("faceSet"));
const word setName = args["faceSet"];
labelList faceLabels(faceSet(mesh, setName).toc());
// Filename as if patch with same name.
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -329,9 +329,8 @@ int main(int argc, char *argv[])
word cellSetName;
string vtkName = runTime.caseName();
if (args.optionFound("cellSet"))
if (args.optionReadIfPresent("cellSet", cellSetName))
{
cellSetName = args.option("cellSet");
vtkName = cellSetName;
}
else if (Pstream::parRun())
......@@ -423,7 +422,7 @@ int main(int argc, char *argv[])
if (args.optionFound("faceSet"))
{
// Load the faceSet
faceSet set(mesh, args.option("faceSet"));
faceSet set(mesh, args["faceSet"]);
// Filename as if patch with same name.
mkDir(fvPath/set.name());
......@@ -446,7 +445,7 @@ int main(int argc, char *argv[])
if (args.optionFound("pointSet"))
{
// Load the pointSet
pointSet set(mesh, args.option("pointSet"));
pointSet set(mesh, args["pointSet"]);
// Filename as if patch with same name.
mkDir(fvPath/set.name());
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -59,7 +59,7 @@ namespace Foam
(
IOobject
(
args.option("dict"),
args["dict"],
runTime.system(),
runTime,
IOobject::MUST_READ
......
......@@ -2,7 +2,7 @@
label sourceTimeIndex = runTimeSource.timeIndex();
if (args.optionFound("sourceTime"))
{
if (args.option("sourceTime") == "latestTime")
if (args["sourceTime"] == "latestTime")
{
sourceTimeIndex = sourceTimes.size() - 1;
}
......
......@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
<< nl << endl;
Info<< "Surface : " << inFileName1<< nl
<< "Points : " << args.option("points") << nl
<< "Points : " << args["points"] << nl
<< "Writing : " << outFileName << nl << endl;
}
else
......@@ -113,7 +113,7 @@ int main(int argc, char *argv[])
if (addPoint)
{
IFstream pointsFile(args.option("points"));
IFstream pointsFile(args["points"]);
pointField extraPoints(pointsFile);
Info<< "Additional Points:" << extraPoints.size() << endl;
......
<
......@@ -136,7 +136,7 @@ int main(int argc, char *argv[])
if (args.optionFound("set"))
{
fileName setName(args.option("set"));
const fileName setName = args["set"];
Info<< "Reading existing feature set from file " << setName << endl;
......@@ -151,7 +151,7 @@ int main(int argc, char *argv[])
set = surfaceFeatures(surf, includedAngle);
Info<< endl << "Writing initial features" << endl;
Info<< nl << "Writing initial features" << endl;
set.write("initial.fSet");
set.writeObj("initial");
}
......@@ -210,7 +210,10 @@ int main(int argc, char *argv[])
if (args.optionFound("subsetBox"))
{
treeBoundBox bb(args.optionLookup("subsetBox")());
treeBoundBox bb
(
args.optionLookup("subsetBox")()
);
Info<< "Removing all edges outside bb " << bb << endl;
dumpBox(bb, "subsetBox.obj");
......@@ -225,7 +228,10 @@ int main(int argc, char *argv[])
}
else if (args.optionFound("deleteBox"))
{
treeBoundBox bb(args.optionLookup("deleteBox")());
treeBoundBox bb
(
args.optionLookup("deleteBox")()