argList - specializations for optionRead<string> etc.

- new optionLookupOrDefault and additional form of optionReadIfPresent
  with a default value
This commit is contained in:
Mark Olesen
2009-12-02 13:45:11 +01:00
parent 6b9534c9ce
commit c3457b5152
15 changed files with 263 additions and 174 deletions

View File

@ -74,9 +74,9 @@ int main(int argc, char *argv[])
args.printUsage();
}
if (args.optionFound("case"))
fileName pathName;
if (args.optionReadIfPresent("case", pathName))
{
fileName pathName = args.option("case");
Info<< nl
<< "-case" << nl
<< "path = " << args.path() << nl
@ -91,7 +91,7 @@ int main(int argc, char *argv[])
forAll(args.additionalArgs(), argI)
{
fileName pathName = args.additionalArgs()[argI];
pathName = args.additionalArgs()[argI];
printCleaning(pathName);
}

View File

@ -49,11 +49,9 @@ int main(int argc, char *argv[])
argList args(argc, argv, false, true);
label repeat = 1;
args.optionReadIfPresent<label>("repeat", repeat);
const label repeat = args.optionLookupOrDefault<label>("repeat", 1);
cpuTime timer;
for (label count = 0; count < repeat; ++count)
{
forAll(args.additionalArgs(), argI)

View File

@ -59,10 +59,6 @@ using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Sin of angle between two consecutive edges on a face. If sin(angle) larger
// than this the face will be considered concave.
const scalar defaultConcaveAngle = 30;
// Same check as snapMesh
void checkSnapMesh
@ -447,8 +443,9 @@ int main(int argc, char *argv[])
scalar minCos = Foam::cos(degToRad(featureAngle));
scalar concaveAngle = defaultConcaveAngle;
args.optionReadIfPresent("concaveAngle", concaveAngle);
// Sin of angle between two consecutive edges on a face.
// If sin(angle) larger than this the face will be considered concave.
scalar concaveAngle = args.optionLookupOrDefault("concaveAngle", 30.0);
scalar concaveSin = Foam::sin(degToRad(concaveAngle));
@ -483,8 +480,8 @@ int main(int argc, char *argv[])
// Merge points on straight edges and remove unused points
if (snapMeshDict)
{
Info<< "Merging all 'loose' points on surface edges"
<< ", regardless of the angle they make." << endl;
Info<< "Merging all 'loose' points on surface edges, "
<< "regardless of the angle they make." << endl;
// Surface bnound to be used to extrude. Merge all loose points.
nChanged += mergeEdges(-1, mesh);
@ -510,7 +507,7 @@ int main(int argc, char *argv[])
Info<< "Mesh unchanged." << endl;
}
Info<< "End\n" << endl;
Info<< "\nEnd\n" << endl;
return 0;
}

View File

@ -546,8 +546,7 @@ int main(int argc, char *argv[])
bool geometry = args.optionFound("geometry");
bool overwrite = args.optionFound("overwrite");
scalar edgeTol = 0.2;
args.optionReadIfPresent("tol", edgeTol);
scalar edgeTol = args.optionLookupOrDefault("tol", 0.2);
Info<< "Trying to split cells with internal angles > feature angle\n" << nl
<< "featureAngle : " << featureAngle << nl

View File

@ -776,17 +776,11 @@ int main(int argc, char *argv[])
args.optionReadIfPresent("scale", scaleFactor);
HashSet<word> ignoreCellGroups;
if (args.optionFound("ignoreCellGroups"))
{
args.optionLookup("ignoreCellGroups")() >> ignoreCellGroups;
}
wordHashSet ignoreCellGroups;
wordHashSet ignoreFaceGroups;
HashSet<word> ignoreFaceGroups;
if (args.optionFound("ignoreFaceGroups"))
{
args.optionLookup("ignoreFaceGroups")() >> ignoreFaceGroups;
}
args.optionReadIfPresent("ignoreCellGroups", ignoreCellGroups);
args.optionReadIfPresent("ignoreFaceGroups", ignoreFaceGroups);
cubitFile = args.options().found("cubit");

View File

@ -50,8 +50,7 @@ int main(int argc, char *argv[])
FatalError.exit();
}
scalar scaleFactor = 1.0;
args.optionReadIfPresent("scale", scaleFactor);
scalar scaleFactor = args.optionLookupOrDefault("scale", 1.0);
# include "createTime.H"

View File

@ -71,19 +71,13 @@ int main(int argc, char *argv[])
const stringList& params = args.additionalArgs();
// default rescale from [mm] to [m]
scalar scaleFactor = 0.001;
if (args.optionReadIfPresent("scale", scaleFactor))
scalar scaleFactor = args.optionLookupOrDefault("scale", 0.001);
if (scaleFactor <= 0)
{
if (scaleFactor <= 0)
{
scaleFactor = 1;
}
scaleFactor = 1;
}
if (args.optionFound("solids"))
{
meshReaders::STARCD::keepSolids = true;
}
meshReaders::STARCD::keepSolids = args.optionFound("solids");
// default to binary output, unless otherwise specified
IOstream::streamFormat format = IOstream::BINARY;

View File

@ -50,8 +50,7 @@ int main(int argc, char *argv[])
FatalError.exit();
}
scalar scaleFactor = 1.0;
args.optionReadIfPresent("scale", scaleFactor);
scalar scaleFactor = args.optionLookupOrDefault("scale", 1.0);
# include "createTime.H"

View File

@ -83,10 +83,9 @@ int main(int argc, char *argv[])
word regionName;
fileName polyMeshDir;
if (args.optionFound("region"))
if (args.optionReadIfPresent("region", regionName, polyMesh::defaultRegion))
{
// constant/<region>/polyMesh/blockMeshDict
regionName = args.option("region");
polyMeshDir = regionName/polyMesh::meshSubDir;
Info<< nl << "Generating mesh for region " << regionName << endl;
@ -94,7 +93,6 @@ int main(int argc, char *argv[])
else
{
// constant/polyMesh/blockMeshDict
regionName = polyMesh::defaultRegion;
polyMeshDir = polyMesh::meshSubDir;
}

View File

@ -301,7 +301,7 @@ int main(int argc, char *argv[])
}
word cellSetName;
string vtkName;
string vtkName = runTime.caseName();
if (args.optionFound("cellSet"))
{
@ -311,8 +311,6 @@ int main(int argc, char *argv[])
else if (Pstream::parRun())
{
// Strip off leading casename, leaving just processor_DDD ending.
vtkName = runTime.caseName();
string::size_type i = vtkName.rfind("processor");
if (i != string::npos)
@ -320,10 +318,6 @@ int main(int argc, char *argv[])
vtkName = vtkName.substr(i);
}
}
else
{
vtkName = runTime.caseName();
}
instantList timeDirs = timeSelector::select0(runTime, args);

View File

@ -88,8 +88,7 @@ int main(int argc, char *argv[])
const stringList& params = args.additionalArgs();
fileName exportName(params[0]);
word importName("default");
args.optionReadIfPresent("name", importName);
word importName = args.optionLookupOrDefault<word>("name", "default");
// check that writing is supported
if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))

View File

@ -177,13 +177,11 @@ int main(int argc, char *argv[])
Info<< "Reading surface from " << surfName << " ..." << endl;
bool readSet = args.optionFound("faceSet");
word setName;
bool readSet = args.optionReadIfPresent("faceSet", setName);
if (readSet)
{
setName = args.option("faceSet");
Info<< "Repatching only the faces in faceSet " << setName
<< " according to nearest surface triangle ..." << endl;
}
@ -193,8 +191,7 @@ int main(int argc, char *argv[])
<< " triangle ..." << endl;
}
scalar searchTol = 1E-3;
args.optionReadIfPresent("tol", searchTol);
scalar searchTol = args.optionLookupOrDefault("tol", 1e-3);
// Get search box. Anything not within this box will not be considered.
const boundBox& meshBb = mesh.globalData().bb();
@ -211,7 +208,7 @@ int main(int argc, char *argv[])
forAll(mesh.boundaryMesh(), patchI)
{
Info<< " " << mesh.boundaryMesh()[patchI].name() << '\t'
<< mesh.boundaryMesh()[patchI].size() << endl;
<< mesh.boundaryMesh()[patchI].size() << nl;
}
Info<< endl;