From a7c8d1cfca13b30df10bf5d2ff4657e5f0b5893e Mon Sep 17 00:00:00 2001 From: sergio Date: Mon, 19 Dec 2016 15:39:13 -0800 Subject: [PATCH 1/9] ENH: changing rhoSimpleFoam to rhothermo and bounding thermo.rho between minRho and maxRho. Bounding thermo.rho in rhoPorousSimpleFoam. Changing initial time step in externalSolarLoad tutorial. Commenting out momemtun source term in steamInjection which causes problems --- .../solvers/compressible/rhoSimpleFoam/createFields.H | 7 +++---- applications/solvers/compressible/rhoSimpleFoam/pEqn.H | 5 +++++ applications/solvers/compressible/rhoSimpleFoam/pcEqn.H | 2 ++ .../compressible/rhoSimpleFoam/rhoPorousSimpleFoam/pEqn.H | 4 ++++ .../solvers/compressible/rhoSimpleFoam/rhoSimpleFoam.C | 2 +- .../externalSolarLoad/system/controlDict | 6 +++++- .../laminar/steamInjection/constant/fvOptions | 6 +++--- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/applications/solvers/compressible/rhoSimpleFoam/createFields.H b/applications/solvers/compressible/rhoSimpleFoam/createFields.H index e8c2ce6d54..176a61a0c1 100644 --- a/applications/solvers/compressible/rhoSimpleFoam/createFields.H +++ b/applications/solvers/compressible/rhoSimpleFoam/createFields.H @@ -1,10 +1,9 @@ Info<< "Reading thermophysical properties\n" << endl; - -autoPtr pThermo +autoPtr pThermo ( - psiThermo::New(mesh) + rhoThermo::New(mesh) ); -psiThermo& thermo = pThermo(); +rhoThermo& thermo = pThermo(); thermo.validate(args.executable(), "h", "e"); volScalarField rho diff --git a/applications/solvers/compressible/rhoSimpleFoam/pEqn.H b/applications/solvers/compressible/rhoSimpleFoam/pEqn.H index e46f2a6691..291c220b95 100644 --- a/applications/solvers/compressible/rhoSimpleFoam/pEqn.H +++ b/applications/solvers/compressible/rhoSimpleFoam/pEqn.H @@ -1,4 +1,6 @@ { + //const volScalarField& psi = thermo.psi(); + volScalarField rAU(1.0/UEqn.A()); surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); @@ -93,6 +95,9 @@ rho = max(rho, rhoMin); rho = min(rho, rhoMax); + thermo.rho() = max(thermo.rho(), rhoMin); + thermo.rho() = min(thermo.rho(), rhoMax); + if (!simple.transonic()) { rho.relax(); diff --git a/applications/solvers/compressible/rhoSimpleFoam/pcEqn.H b/applications/solvers/compressible/rhoSimpleFoam/pcEqn.H index 67b962f805..446a7849d0 100644 --- a/applications/solvers/compressible/rhoSimpleFoam/pcEqn.H +++ b/applications/solvers/compressible/rhoSimpleFoam/pcEqn.H @@ -109,6 +109,8 @@ if (closedVolume) rho = thermo.rho(); rho = max(rho, rhoMin); rho = min(rho, rhoMax); +thermo.rho() = max(thermo.rho(), rhoMin); +thermo.rho() = min(thermo.rho(), rhoMax); if (!simple.transonic()) { diff --git a/applications/solvers/compressible/rhoSimpleFoam/rhoPorousSimpleFoam/pEqn.H b/applications/solvers/compressible/rhoSimpleFoam/rhoPorousSimpleFoam/pEqn.H index 7b55983161..cdabc4dad9 100644 --- a/applications/solvers/compressible/rhoSimpleFoam/rhoPorousSimpleFoam/pEqn.H +++ b/applications/solvers/compressible/rhoSimpleFoam/rhoPorousSimpleFoam/pEqn.H @@ -86,6 +86,10 @@ rho = thermo.rho(); rho = max(rho, rhoMin); rho = min(rho, rhoMax); + + thermo.rho() = max(thermo.rho(), rhoMin); + thermo.rho() = min(thermo.rho(), rhoMax); + rho.relax(); Info<< "rho max/min : " << max(rho).value() << " " diff --git a/applications/solvers/compressible/rhoSimpleFoam/rhoSimpleFoam.C b/applications/solvers/compressible/rhoSimpleFoam/rhoSimpleFoam.C index 5cffb13411..63f00f881d 100644 --- a/applications/solvers/compressible/rhoSimpleFoam/rhoSimpleFoam.C +++ b/applications/solvers/compressible/rhoSimpleFoam/rhoSimpleFoam.C @@ -33,7 +33,7 @@ Description \*---------------------------------------------------------------------------*/ #include "fvCFD.H" -#include "psiThermo.H" +#include "rhoThermo.H" #include "turbulentFluidThermoModel.H" #include "simpleControl.H" #include "fvOptions.H" diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/externalSolarLoad/system/controlDict b/tutorials/heatTransfer/chtMultiRegionFoam/externalSolarLoad/system/controlDict index cedfba6ff5..b03a976296 100644 --- a/tutorials/heatTransfer/chtMultiRegionFoam/externalSolarLoad/system/controlDict +++ b/tutorials/heatTransfer/chtMultiRegionFoam/externalSolarLoad/system/controlDict @@ -25,7 +25,7 @@ stopAt endTime; endTime 18000; -deltaT 10; +deltaT 1; writeControl adjustableRunTime; @@ -49,4 +49,8 @@ adjustTimeStep yes; maxCo 15; +maxDeltaT 10; + +maxDi 0.25; + // ************************************************************************* // diff --git a/tutorials/multiphase/reactingTwoPhaseEulerFoam/laminar/steamInjection/constant/fvOptions b/tutorials/multiphase/reactingTwoPhaseEulerFoam/laminar/steamInjection/constant/fvOptions index ae17055b8c..92a4b462c0 100644 --- a/tutorials/multiphase/reactingTwoPhaseEulerFoam/laminar/steamInjection/constant/fvOptions +++ b/tutorials/multiphase/reactingTwoPhaseEulerFoam/laminar/steamInjection/constant/fvOptions @@ -43,7 +43,7 @@ options } } } - +/* momentumSource1 { type vectorSemiImplicitSource; @@ -55,11 +55,11 @@ options volumeMode absolute; injectionRateSuSp { - U.steam ((0 1e-1 0) 0); // kg*m/s^2 + U.steam ((0 1e-2 0) 0); // kg*m/s^2 } } } - +*/ energySource1 { type scalarSemiImplicitSource; From 6f5cece322996d23278fe7e27ae4fb97e0c59634 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 18 Dec 2016 22:35:20 +0100 Subject: [PATCH 2/9] STYLE: documentation for wordRe DETECT vs REGEXP was swapped around - Use wordRe::REGEXP (not wordRe::DETECT) if the content is known to be a regular expression anyhow. --- .../preProcessing/createZeroDirectory/boundaryInfo.C | 2 +- src/OpenFOAM/primitives/strings/wordRe/wordRe.H | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/applications/utilities/preProcessing/createZeroDirectory/boundaryInfo.C b/applications/utilities/preProcessing/createZeroDirectory/boundaryInfo.C index 6dd055b6a3..62ca3f5514 100644 --- a/applications/utilities/preProcessing/createZeroDirectory/boundaryInfo.C +++ b/applications/utilities/preProcessing/createZeroDirectory/boundaryInfo.C @@ -169,7 +169,7 @@ void Foam::boundaryInfo::setType(const label patchI, const word& condition) return; } - if (wordRe(".*[mM]apped.*", wordRe::DETECT).match(types_[patchI])) + if (wordRe(".*[Mm]apped.*", wordRe::REGEXP).match(types_[patchI])) { // ugly hack to avoid overriding mapped types return; diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H index d8e7fb3eb9..c5a0a3b95e 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H @@ -95,12 +95,12 @@ public: // Note that 'REGEXP' is implicit if 'NOCASE' is specified alone. enum compOption { - LITERAL = 0, //!< treat as a string literal - DETECT = 1, //!< treat as regular expression - REGEXP = 2, //!< detect if the string contains meta-characters - NOCASE = 4, //!< ignore case in regular expression - DETECT_NOCASE = DETECT | NOCASE, - REGEXP_NOCASE = REGEXP | NOCASE + LITERAL = 0, //!< Treat as a string literal + DETECT = 1, //!< Detect if the string contains meta-characters + REGEXP = 2, //!< Treat as regular expression + NOCASE = 4, //!< Ignore case in regular expression + DETECT_NOCASE = DETECT | NOCASE, //!< Combined DETECT and NOCASE + REGEXP_NOCASE = REGEXP | NOCASE //!< Combined REGEXP and NOCASE }; From c2b0531081c86472f8c405910f9371083f3f91c2 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 19 Dec 2016 00:24:54 +0100 Subject: [PATCH 3/9] ENH: only report the architecture information for binary output files - not required for ASCII, and makes normal dictionaries too noisy. STYLE: move archHint to be a file-scope static --- .../db/IOobject/IOobjectWriteHeader.C | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C index 82de72d3d2..51d6f7d853 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C @@ -33,26 +33,28 @@ Description #include "label.H" #include "scalar.H" +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +// file-scope +// Hint about machine endian, OpenFOAM label and scalar sizes +static const std::string archHint = +( +#ifdef WM_LITTLE_ENDIAN + "LSB" +#elif defined (WM_BIG_ENDIAN) + "MSB" +#else + "???" +#endif + ";label=" + std::to_string(8*sizeof(Foam::label)) + + ";scalar=" + std::to_string(8*sizeof(Foam::scalar)) +); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const { - static std::string archHint; - - // Hint about machine endian, OpenFOAM label and scalar sizes - if (archHint.empty()) - { - #ifdef WM_LITTLE_ENDIAN - archHint.append("LSB;"); - #elif defined (WM_BIG_ENDIAN) - archHint.append("MSB;"); - #endif - archHint.append("label="); - archHint.append(std::to_string(8*sizeof(label))); - archHint.append(";scalar="); - archHint.append(std::to_string(8*sizeof(scalar))); - } - if (!os.good()) { InfoInFunction @@ -66,10 +68,14 @@ bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const << "FoamFile\n{\n" << " version " << os.version() << ";\n" << " format " << os.format() << ";\n" - << " arch " << archHint << ";\n" << " class " << type << ";\n"; - if (note().size()) + if (os.format() == IOstream::BINARY) + { + os << " arch " << archHint << ";\n"; + } + + if (!note().empty()) { os << " note " << note() << ";\n"; } From f45db9cec9a4e11e53eab0d1414fd415a68ec3f2 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 19 Dec 2016 20:08:58 +0100 Subject: [PATCH 4/9] ENH: argList option to remove the noFunctionObjects option (issue #352) --- src/OpenFOAM/global/argList/argList.C | 37 ++++++++++++++++++++++----- src/OpenFOAM/global/argList/argList.H | 6 ++++- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index f645a7ef35..b93aabd0a6 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -158,6 +158,21 @@ void Foam::argList::noBanner() } +void Foam::argList::noFunctionObjects(bool addWithOption) +{ + removeOption("noFunctionObjects"); + + if (addWithOption) + { + addBoolOption + ( + "withFunctionObjects", + "execute functionObjects" + ); + } +} + + void Foam::argList::noParallel() { removeOption("parallel"); @@ -459,6 +474,9 @@ Foam::argList::argList ) ) { + // If the option is known to require an argument, + // get it or emit a FatalError. + ++argI; if (argI >= args_.size()) { @@ -475,6 +493,9 @@ Foam::argList::argList } else { + // All other options (including unknown ones) are simply + // registered as existing. + options_.insert(optionName, ""); } } @@ -527,29 +548,31 @@ void Foam::argList::parse // -help print the usage // -doc display application documentation in browser // -srcDoc display source code in browser - if - ( - options_.found("help") - || options_.found("doc") - || options_.found("srcDoc") - ) { + bool quickExit = false; + if (options_.found("help")) { printUsage(); + quickExit = true; } // Only display one or the other if (options_.found("srcDoc")) { displayDoc(true); + quickExit = true; } else if (options_.found("doc")) { displayDoc(false); + quickExit = true; } - ::exit(0); + if (quickExit) + { + ::exit(0); + } } // Print the usage message and exit if the number of arguments is incorrect diff --git a/src/OpenFOAM/global/argList/argList.H b/src/OpenFOAM/global/argList/argList.H index 711a28084a..81612f2857 100644 --- a/src/OpenFOAM/global/argList/argList.H +++ b/src/OpenFOAM/global/argList/argList.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -348,6 +348,10 @@ public: //- Disable emitting the banner information static void noBanner(); + //- Remove the 'noFunctionObjects' option, + // optionally adding a 'withFunctionObjects' option instead + static void noFunctionObjects(bool addWithOption = false); + //- Remove the parallel options static void noParallel(); From b08dadff62b52f56665628a6b3a9c8d9e6a9a75c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 18 Dec 2016 20:09:58 +0100 Subject: [PATCH 5/9] ENH: initializer list constructor for fileName This slightly more convenient when working with char[] input: fileName file1{ "path", "name", "to", "file.ext" }; vs. fileName file1 = fileName(path)/"name"/"to"/"file.ext"; But is a bit more efficient since it avoid most of the intermediate copying and resizing incurred by the '/' operator. --- applications/test/fileName/Test-fileName.C | 87 +++++++++++++++++-- .../primitives/strings/fileName/fileName.C | 41 ++++++++- .../primitives/strings/fileName/fileName.H | 8 +- 3 files changed, 123 insertions(+), 13 deletions(-) diff --git a/applications/test/fileName/Test-fileName.C b/applications/test/fileName/Test-fileName.C index e214e98813..de8751c7b0 100644 --- a/applications/test/fileName/Test-fileName.C +++ b/applications/test/fileName/Test-fileName.C @@ -29,26 +29,98 @@ Description \*---------------------------------------------------------------------------*/ +#include "argList.H" #include "fileName.H" #include "SubList.H" +#include "DynamicList.H" #include "IOobject.H" #include "IOstreams.H" #include "OSspecific.H" #include "POSIX.H" +#include "etcFiles.H" using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: -int main() +int main(int argc, char *argv[]) { - wordList wrdList(5); - wrdList[0] = "hello"; - wrdList[1] = "hello1"; - wrdList[2] = "hello2"; - wrdList[3] = "hello3"; - wrdList[4] = "hello4.hmm"; + argList::noParallel(); + argList::addBoolOption("construct", "test constructors"); + argList::addBoolOption("default", "reinstate default tests"); + argList::addNote("runs default tests or specified ones only"); + + #include "setRootCase.H" + + // Run default tests, unless only specific tests are requested + const bool defaultTests = + args.optionFound("default") || args.options().empty(); + + if (args.optionFound("construct")) + { + Info<< "From initializer_list = "; + fileName file1 + { + "hello", + "hello1", + "hello2", + "hello3", + "hello4.hmm" + }; + + Info<< file1 << nl; + + Info<< "From initializer_list = "; + fileName file2 + { + file1, + "some", + "more/things.hmm" + }; + + Info<< file2 << nl; + + + Info<< "From initializer_list with nesting = "; + fileName file3 + { + std::string("ffO"), + "some", + "more/things.hmm" + }; + Info<< file3 << nl; + + DynamicList base + { + "hello", + "hello1" + }; + + fileName file4 + { + "some", + file3, + "more/things.hmm", + file1 + }; + Info<< "All ==> " << file4 << nl; + } + + + if (!defaultTests) + { + return 0; + } + + DynamicList wrdList + { + "hello", + "hello1", + "hello2", + "hello3", + "hello4.hmm" + }; fileName pathName(wrdList); @@ -191,7 +263,6 @@ int main() } - // test findEtcFile Info<< "\n\nfindEtcFile tests:" << nl << " controlDict => " << findEtcFile("controlDict") << nl diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 2186c5f171..7110bdf2f6 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -37,11 +37,46 @@ const Foam::fileName Foam::fileName::null; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::fileName::fileName(const wordList& lst) +Foam::fileName::fileName(const UList& lst) { - forAll(lst, elemI) + // Estimate overall size + size_type sz = lst.size(); + for (const word& item : lst) { - operator=((*this)/lst[elemI]); + sz += item.size(); + } + reserve(sz); + + sz = 0; + for (const word& item : lst) + { + if (item.size()) + { + if (sz++) operator+=('/'); + operator+=(item); + } + } +} + + +Foam::fileName::fileName(std::initializer_list lst) +{ + // Estimate overall size + size_type sz = lst.size(); + for (const word& item : lst) + { + sz += item.size(); + } + reserve(sz); + + sz = 0; + for (const word& item : lst) + { + if (item.size()) + { + if (sz++) operator+=('/'); + operator+=(item); + } } } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index 18198ea0fc..cc49f365e4 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -53,10 +53,10 @@ namespace Foam { template class List; +template class UList; typedef List wordList; // Forward declaration of friend functions and operators - class fileName; Istream& operator>>(Istream&, fileName&); @@ -119,7 +119,11 @@ public: inline fileName(const char*, const bool doStripInvalid=true); //- Construct by concatenating elements of wordList separated by '/' - explicit fileName(const wordList&); + explicit fileName(const UList&); + + //- Construct by concatenating words separated by '/' + explicit fileName(std::initializer_list); + //- Construct from Istream fileName(Istream&); From e379720053050acd2959fc5416876fff021a61ce Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 18 Dec 2016 20:40:03 +0100 Subject: [PATCH 6/9] ENH: additional fileName methods - add an extension to the file name - remove a file extension - check if a file name has an extension - check if a file name has a particular extension (as word), or matches a particular grouping of extensions (as wordRe). --- applications/test/fileName/Test-fileName.C | 127 ++++++++++++++++++ .../primitives/strings/fileName/fileName.C | 74 +++++++++- .../primitives/strings/fileName/fileName.H | 79 ++++++++--- .../primitives/strings/fileName/fileNameI.H | 15 +++ .../primitives/strings/fileName/fileNameIO.C | 2 - 5 files changed, 270 insertions(+), 27 deletions(-) diff --git a/applications/test/fileName/Test-fileName.C b/applications/test/fileName/Test-fileName.C index de8751c7b0..18f89b6db0 100644 --- a/applications/test/fileName/Test-fileName.C +++ b/applications/test/fileName/Test-fileName.C @@ -37,6 +37,7 @@ Description #include "IOstreams.H" #include "OSspecific.H" #include "POSIX.H" +#include "Switch.H" #include "etcFiles.H" using namespace Foam; @@ -47,6 +48,7 @@ using namespace Foam; int main(int argc, char *argv[]) { argList::noParallel(); + argList::addBoolOption("ext", "test handing of file extensions"); argList::addBoolOption("construct", "test constructors"); argList::addBoolOption("default", "reinstate default tests"); argList::addNote("runs default tests or specified ones only"); @@ -108,6 +110,131 @@ int main(int argc, char *argv[]) } + // Test various ext() methods + if (args.optionFound("ext")) + { + Info< -> " << input1.ext(e) << nl; + } + Info<< nl; + + + Info<<"Test hasExt(word)" << nl + <<"~~~~~~~~~~~~~~~~~" << nl; + Info<<"Has extension(s):" << nl + << "input: " << input1 << nl; + for (const word& e : exts) + { + Info<<" '" << e << "' -> " + << Switch(input1.hasExt(e)) << nl; + } + Info<< nl; + + Info<<"Has extension(s):" << nl + << "input: " << endWithDot << nl; + for (const word& e : exts) + { + Info<<" '" << e << "' -> " + << Switch(endWithDot.hasExt(e)) << nl; + } + Info<< nl; + + + Info<<"Test hasExt(wordRe)" << nl + <<"~~~~~~~~~~~~~~~~~~~" << nl; + + // A regex with a zero length matcher doesn't work at all: + // eg "(png|jpg|txt|)" regex matcher itself + + wordRe matcher0("()", wordRe::REGEXP); + wordRe matcher1("(png|jpg|txt)", wordRe::REGEXP); + wordRe matcher2("(png|txt)", wordRe::REGEXP); + + Info<<"Has extension(s):" << nl + << "input: " << endWithDot << nl; + Info<<" " << matcher0 << " -> " + << Switch(endWithDot.hasExt(matcher0)) << nl; + Info<<" " << matcher1 << " -> " + << Switch(endWithDot.hasExt(matcher1)) << nl; + Info<<" " << matcher2 << " -> " + << Switch(endWithDot.hasExt(matcher2)) << nl; + + Info<< "input: " << input1 << nl; + Info<<" " << matcher0 << " -> " + << Switch(input1.hasExt(matcher0)) << nl; + Info<<" " << matcher1 << " -> " + << Switch(input1.hasExt(matcher1)) << nl; + Info<<" " << matcher2 << " -> " + << Switch(input1.hasExt(matcher2)) << nl; + Info<< nl; + + Info<<"Remove extension(s):" << nl << "input: " << input1 << nl; + while (!input1.empty()) + { + if (input1.removeExt()) + { + Info<< " -> " << input1 << nl; + } + else + { + Info<< "stop> " << input1 << nl; + break; + } + } + Info<< nl; + + input0.clear(); + Info<<"test with zero-sized: " << input0 << nl; + Info<<"add extension: " << input0.ext("abc") << nl; + Info<< nl; + + input0 = "this/"; + Info<<"test add after slash: " << input0 << nl; + Info<<"add extension: " << input0.ext("abc") + << " <-- avoids accidentally creating hidden files" << nl; + Info<< nl; + + input0 = "this.file."; + Info<<"test after dot: " << input0 << nl; + Info<<"add extension: " << input0.ext("abc") + << " <-- No check for repeated dots (user error!)" << nl; + Info<< nl; + } + if (!defaultTests) { return 0; diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 7110bdf2f6..70e925ea01 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -27,6 +27,7 @@ License #include "wordList.H" #include "DynamicList.H" #include "OSspecific.H" +#include "wordRe.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -303,9 +304,9 @@ Foam::fileName Foam::fileName::path() const Foam::fileName Foam::fileName::lessExt() const { - size_type i = find_last_of("./"); + size_type i = find_ext(); - if (i == npos || i == 0 || operator[](i) == '/') + if (i == npos) { return *this; } @@ -318,9 +319,9 @@ Foam::fileName Foam::fileName::lessExt() const Foam::word Foam::fileName::ext() const { - size_type i = find_last_of("./"); + size_type i = find_ext(); - if (i == npos || i == 0 || operator[](i) == '/') + if (i == npos) { return word::null; } @@ -331,6 +332,71 @@ Foam::word Foam::fileName::ext() const } +Foam::fileName& Foam::fileName::ext(const word& ending) +{ + if (!ending.empty() && !empty() && operator[](size()-1) != '/') + { + append("."); + append(ending); + } + + return *this; +} + + +bool Foam::fileName::hasExt() const +{ + return (find_ext() != npos); +} + + +bool Foam::fileName::hasExt(const word& ending) const +{ + size_type i = find_ext(); + if (i == npos) + { + return false; + } + + ++i; // Do next comparison *after* the dot + return + ( + // Lengths must match + ((size() - i) == ending.size()) + && !compare(i, npos, ending) + ); +} + + +bool Foam::fileName::hasExt(const wordRe& ending) const +{ + size_type i = find_ext(); + if (i == npos) + { + return false; + } + + std::string end = substr(i+1, npos); + return ending.match(end); +} + + +bool Foam::fileName::removeExt() +{ + const size_type i = find_ext(); + + if (i == npos) + { + return false; + } + else + { + this->resize(i); + return true; + } +} + + Foam::wordList Foam::fileName::components(const char delimiter) const { DynamicList wrdList(20); diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index cc49f365e4..4195077d81 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -57,6 +57,7 @@ template class UList; typedef List wordList; // Forward declaration of friend functions and operators +class wordRe; class fileName; Istream& operator>>(Istream&, fileName&); @@ -73,6 +74,10 @@ class fileName { // Private Member Functions + //- Find position of the file extension dot, return npos on failure. + // A wrapped version of find_last_of("./") with additional logic. + inline size_type find_ext() const; + //- Strip invalid characters inline void stripInvalid(); @@ -104,35 +109,35 @@ public: inline fileName(); //- Construct as copy - inline fileName(const fileName&); + inline fileName(const fileName& fn); //- Construct as copy of word - inline fileName(const word&); + inline fileName(const word& s); //- Construct as copy of string - inline fileName(const string&, const bool doStripInvalid=true); + inline fileName(const string& s, const bool doStripInvalid=true); //- Construct as copy of std::string - inline fileName(const std::string&, const bool doStripInvalid=true); + inline fileName(const std::string& s, const bool doStripInvalid=true); //- Construct as copy of character array - inline fileName(const char*, const bool doStripInvalid=true); + inline fileName(const char* s, const bool doStripInvalid=true); //- Construct by concatenating elements of wordList separated by '/' - explicit fileName(const UList&); + explicit fileName(const UList& lst); //- Construct by concatenating words separated by '/' - explicit fileName(std::initializer_list); + explicit fileName(std::initializer_list lst); //- Construct from Istream - fileName(Istream&); + fileName(Istream& is); // Member functions //- Is this character valid for a fileName? - inline static bool valid(char); + inline static bool valid(char c); //- Cleanup file name // @@ -209,6 +214,24 @@ public: //- Return file name extension (part after last .) word ext() const; + //- Append a '.' and the ending, and return the object. + // The '.' and ending will not be added when the ending is empty, + // or when the file name is empty or ended with a '/'. + fileName& ext(const word& ending); + + //- Return true if it has an extension or simply ends with a '.' + bool hasExt() const; + + //- Return true if the extension is the same as the given ending. + bool hasExt(const word& ending) const; + + //- Return true if the extension matches the given ending. + bool hasExt(const wordRe& ending) const; + + //- Remove extension, returning true if string changed. + bool removeExt(); + + //- Return path components as wordList // // Behaviour: @@ -219,32 +242,46 @@ public: // "foo/bar" 2("foo", "bar") // "/foo/bar" 2("foo", "bar") // "/foo/bar/" 2("foo", "bar") - wordList components(const char delimiter='/') const; + wordList components(const char delimiter = '/') const; //- Return a single component of the path - word component(const size_type, const char delimiter='/') const; + word component + ( + const size_type cmpt, + const char delimiter = '/' + ) const; // Member operators - // Assignment + // Assignment - void operator=(const fileName&); - void operator=(const word&); - void operator=(const string&); - void operator=(const std::string&); - void operator=(const char*); + //- Copy, no character validation required + void operator=(const fileName& str); + + //- Copy, no character validation required + void operator=(const word& str); + + //- Copy, stripping invalid characters + void operator=(const string& str); + + //- Copy, stripping invalid characters + void operator=(const std::string& str); + + //- Copy, stripping invalid characters + void operator=(const char* str); // IOstream operators - friend Istream& operator>>(Istream&, fileName&); - friend Ostream& operator<<(Ostream&, const fileName&); + friend Istream& operator>>(Istream& is, fileName& fn); + friend Ostream& operator<<(Ostream& os, const fileName& fn); }; -//- Assemble words and fileNames as pathnames by adding a '/' separator -fileName operator/(const string&, const string&); +//- Assemble words and fileNames as pathnames by adding a '/' separator. +// No '/' separator is added if either argument is an empty string. +fileName operator/(const string& a, const string& b); //- Recursively search the given directory for the file diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H index 6c2bb37f9a..e2055f7474 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H @@ -25,6 +25,21 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +inline std::string::size_type Foam::fileName::find_ext() const +{ + const size_type i = find_last_of("./"); + + if (i == npos || i == 0 || operator[](i) == '/') + { + return npos; + } + else + { + return i; + } +} + + inline void Foam::fileName::stripInvalid() { // skip stripping unless debug is active to avoid diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C b/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C index b87431ca5c..dd686bb131 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileNameIO.C @@ -78,5 +78,3 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const fileName& fn) // ************************************************************************* // - - From 2b1436066221bf8a599e1b7e2695c378ef01f066 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 18 Dec 2016 23:21:51 +0100 Subject: [PATCH 7/9] ENH: additional startsWith(), endsWith() string methods - As the names describe, check if the string starts or ends with a particular value. Always true if the given text is empty or if the string is identical to the given text. --- applications/test/string/Test-string.C | 72 +++++++++++++++++++ .../primitives/strings/string/string.C | 29 +++++++- .../primitives/strings/string/string.H | 52 +++++++++----- 3 files changed, 132 insertions(+), 21 deletions(-) diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C index a8276c2926..ec7defadd3 100644 --- a/applications/test/string/Test-string.C +++ b/applications/test/string/Test-string.C @@ -34,6 +34,8 @@ Description #include "int.H" #include "uint.H" #include "scalar.H" +#include "Switch.H" +#include "stringList.H" using namespace Foam; @@ -166,6 +168,76 @@ int main(int argc, char *argv[]) << Foam::name("formatted >%08d<", val) << "\n"; } + // test startsWith, endsWith methods + { + string empty; //; + string input1 = "shorter input"; + string input2 = "longer input text"; + + stringList checks{"match", "long", "", "short", "text", "s", "l", "t"}; + + Info<< nl; + Info<< "check startsWith:" << nl + << "~~~~~~~~~~~~~~~~~" << nl; + + Info<<"input: " << empty << nl; + for (const string& test : checks) + { + Info<< " startsWith(" << test << ") = " + << Switch(empty.startsWith(test)) << nl; + } + Info<<"input: " << input1 << nl; + for (const string& test : checks) + { + Info<< " startsWith(" << test << ") = " + << Switch(input1.startsWith(test)) << nl; + } + Info<<"input: " << input2 << nl; + for (const string& test : checks) + { + Info<< " startsWith(" << test << ") = " + << Switch(input2.startsWith(test)) << nl; + } + + + Info<< nl; + Info<< "check endsWith:" << nl + << "~~~~~~~~~~~~~~~~~" << nl; + + Info<<"input: " << empty << nl; + for (const string& test : checks) + { + Info<< " endsWith(" << test << ") = " + << Switch(empty.endsWith(test)) << nl; + } + Info<<"input: " << input1 << nl; + for (const string& test : checks) + { + Info<< " endsWith(" << test << ") = " + << Switch(input1.endsWith(test)) << nl; + } + Info<<"input: " << input2 << nl; + for (const string& test : checks) + { + Info<< " endsWith(" << test << ") = " + << Switch(input2.endsWith(test)) << nl; + } + + Info<< nl; + Info<< "check endsWith as applied to field names:" << nl + << "~~~~~~~~~~~~~~~~~" << nl; + + string input3 = "field_0"; + string input4 = "_0"; + + Info<size(); + const size_type txtLen = text.size(); + + return + ( + !txtLen + || (strLen >= txtLen && !compare(0, txtLen, text)) + ); +} + + +bool Foam::string::endsWith(const std::string& text) const +{ + const size_type strLen = this->size(); + const size_type txtLen = text.size(); + + return + ( + !txtLen + || (strLen >= txtLen && !compare(strLen - txtLen, npos, text)) + ); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H index 67d6b2b688..0b05a868b3 100644 --- a/src/OpenFOAM/primitives/strings/string/string.H +++ b/src/OpenFOAM/primitives/strings/string/string.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -104,49 +104,53 @@ public: inline string(); //- Construct from std::string - inline string(const std::string&); + inline string(const std::string& str); //- Construct as copy of character array - inline string(const char*); + inline string(const char* str); //- Construct as copy of specified number of characters - inline string(const char*, const size_type); + inline string(const char* str, const size_type len); //- Construct from a single character - inline string(const char); + inline string(const char c); //- Construct from Istream - string(Istream&); + string(Istream& is); // Member Functions //- Count and return the number of a given character in the string - size_type count(const char) const; + size_type count(const char c) const; //- Is this string type valid? template - static inline bool valid(const string&); + static inline bool valid(const string& str); //- Does this string have particular meta-characters? // The meta characters can be optionally quoted. template - static inline bool meta(const string&, const char quote='\\'); + static inline bool meta(const string& str, const char quote = '\\'); //- Strip invalid characters from the given string template - static inline bool stripInvalid(string&); + static inline bool stripInvalid(string& str); //- Return a valid String from the given string template - static inline String validate(const string&); + static inline String validate(const string& str); //- Return a String with quoted meta-characters from the given string template - static inline string quotemeta(const string&, const char quote='\\'); + static inline string quotemeta + ( + const string& str, + const char quote = '\\' + ); //- True when strings match literally - inline bool match(const std::string&) const; + inline bool match(const std::string& str) const; //- Avoid masking the normal std::string replace using std::string::replace; @@ -186,16 +190,26 @@ public: string& expand(const bool allowEmpty = false); //- Remove repeated characters returning true if string changed - bool removeRepeated(const char); + bool removeRepeated(const char character); //- Return string with repeated characters removed - string removeRepeated(const char) const; + string removeRepeated(const char character) const; //- Remove trailing character returning true if string changed - bool removeTrailing(const char); + bool removeTrailing(const char character); //- Return string with trailing character removed - string removeTrailing(const char) const; + string removeTrailing(const char character) const; + + //- True if the string starts with the given text. + // Always true if the given text is empty or if the string + // is identical to the given text. + bool startsWith(const std::string& text) const; + + //- True if the string ends with the given text. + // Always true if the given text is empty or if the string + // is identical to the given text. + bool endsWith(const std::string& text) const; // Member Operators @@ -216,8 +230,8 @@ public: // IOstream Operators - friend Istream& operator>>(Istream&, string&); - friend Ostream& operator<<(Ostream&, const string&); + friend Istream& operator>>(Istream& is, string& s); + friend Ostream& operator<<(Ostream& os, const string& s); }; From 7b4680482ea5be4f20aafe17af39922708c80471 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 18 Dec 2016 23:58:45 +0100 Subject: [PATCH 8/9] ENH: use string endsWith in a few places fieldName.endsWith("_0") vs fieldName.size() > 2 && fieldName(fieldName.size()-2, 2) == "_0" --- .../dataConversion/foamToEnsight/checkData.H | 5 ++--- .../dataConversion/foamToEnsightParts/findFields.H | 8 ++------ .../GeometricFields/GeometricField/GeometricField.C | 5 +---- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H index 73a0e17417..f33a8f727f 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H @@ -11,9 +11,8 @@ if (!fieldsToUse.found(fieldName)) { variableGood = ( - fieldName.size() > 2 && fieldName(fieldName.size()-2, 2) == "_0" - ? false - : IOobject + !fieldName.endsWith("_0") + && IOobject ( fieldName, timeDirs[n1].name(), diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H index 721ba05101..0c841369cf 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H @@ -19,13 +19,9 @@ if (timeDirs.size()) const word& fieldName = obj.name(); const word& fieldType = obj.headerClassName(); - if (fieldName.size() > 2 && fieldName(fieldName.size()-2, 2) == "_0") + if (volFieldTypes.found(fieldType) && !fieldName.endsWith("_0")) { - // ignore _0 fields - } - else if (volFieldTypes.found(fieldType)) - { - // simply ignore types that we don't handle + // ignore types that we don't handle, and ignore _0 fields volumeFields.insert(fieldName, fieldType); } } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index 8f84b90986..e7d6ea9140 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -766,10 +766,7 @@ void Foam::GeometricField::storeOldTimes() const ( field0Ptr_ && timeIndex_ != this->time().timeIndex() - && !( - this->name().size() > 2 - && this->name()(this->name().size()-2, 2) == "_0" - ) + && !this->name().endsWith("_0") ) { storeOldTime(); From 5fdb20c35e96a9e073466eb69def1ca8b041a8a8 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 19 Dec 2016 18:04:12 +0100 Subject: [PATCH 9/9] STYLE: bump min gcc for foamInstallationTest - cleanup some code in foamInstallationTest --- bin/foamInstallationTest | 391 ++++++++++++++++++--------------------- 1 file changed, 175 insertions(+), 216 deletions(-) diff --git a/bin/foamInstallationTest b/bin/foamInstallationTest index 17b285a5ab..0b92b8f74c 100755 --- a/bin/foamInstallationTest +++ b/bin/foamInstallationTest @@ -26,30 +26,27 @@ # foamInstallationTest # # Description -# Checks the machine system, the installation of OpenFOAM, and the user's +# Check the machine system, the installation of OpenFOAM, and the user's # personal configuration for running OpenFOAM. # #------------------------------------------------------------------------------ # Base settings -MIN_VERSION_GCC=4.5.0 +MIN_VERSION_GCC=4.8.0 # General WIDTH=20 -# Global variables -fatalError=0 -criticalError=0 - # System variables -HOST=`uname -n` -OSTYPE=`uname -s` -USER_NAME=$LOGNAME -: ${USER_NAME:=$USER} +HOST=$(uname -n) +OSTYPE=$(uname -s) -# which OpenFOAM application to test for the Version +# OpenFOAM application to test for the Version foamTestApp=icoFoam +# Global variables +unset fatalError criticalError + #============================================================================== # HELPER FUNCTIONS #============================================================================== @@ -68,43 +65,22 @@ heading() } -lenBase() -{ - echo $1 | tr -d " " | wc -m | tr -d " " -} - - -length() -{ - NOCHAR=`lenBase $1` - NOCHAR=`expr $NOCHAR - 1` - [ $NOCHAR -ge 0 ] || NOCHAR=0 - echo $NOCHAR -} - - -stringLength() -{ - echo $1 | wc -m | tr -d " " -} - - fixlen() { WORD=$1 - ONELEN=`stringLength $1` - LDIFF=`expr $ONELEN - $2` + LDIFF=$(expr ${#WORD} - ${2:-4}) + if [ $LDIFF -le 1 ] then while [ $LDIFF -lt 0 ] do WORD="$WORD " - LDIFF=`expr $LDIFF + 1` + LDIFF=$(expr $LDIFF + 1) done echo "$WORD" else - LDIFF=`expr $LDIFF + 4` - WORD=`echo "$WORD" | cut -c${LDIFF}-` + LDIFF=$(expr $LDIFF + 4) + WORD=$(echo "$WORD" | cut -c${LDIFF}-) echo "...${WORD}" fi } @@ -112,83 +88,54 @@ fixlen() reportEnv() { - EXP_ENV=`eval "echo $1"` - EXP_PATH=`eval "echo $2"` + eval EXP_ENV="$1" + eval EXP_PATH="$2" CRIT="$3" EXISTS=" no " ON_PATH="" - if [ `length $EXP_ENV` -gt 0 ] + + if [ -n "$EXP_ENV" ] then - case "$OSTYPE" in - SunOS) - if /usr/bin/test -e $EXP_ENV + if test -e "$EXP_ENV" + then + EXISTS=" yes " + if [ "$2" != noPath ] then - EXISTS=" yes " - if [ "$2" != noPath ] - then - ON_PATH=" no " - oldIFS=$IFS - IFS=':' - for e in $EXP_PATH - do - case "$e" in - "$EXP_ENV" | "$EXP_ENV/bin" | "$EXP_ENV/lib") - ON_PATH="yes " - ;; - esac - done - IFS=$oldIFS - else - CRIT=" $3" - fi - else - ON_PATH=" " - fi - echo "`fixlen "$1" 21` `fixlen "$EXP_ENV" 40` $EXISTS $ON_PATH $CRIT" - ;; - *) - if [ -e "$EXP_ENV" ] - then - EXISTS=" yes " - if [ "$2" != noPath ] - then - ON_PATH=" no " - oldIFS=$IFS - IFS=':' - for e in $EXP_PATH - do - case "$e" in - "$EXP_ENV" | "$EXP_ENV/bin" | "$EXP_ENV/lib") - ON_PATH="yes " - ;; - esac - done - IFS=$oldIFS - else - CRIT=" $3" - fi - else - ON_PATH=" " - fi - echo "`fixlen "$1" 21` `fixlen "$EXP_ENV" 40` $EXISTS $ON_PATH $CRIT" - ;; - esac + ON_PATH=" no " + oldIFS=$IFS + IFS=':' + for e in $EXP_PATH + do + case "$e" in + "$EXP_ENV" | "$EXP_ENV/bin" | "$EXP_ENV/lib") + ON_PATH="yes " + break + ;; + esac + done + IFS=$oldIFS + else + CRIT=" $3" + fi + else + ON_PATH=" " + fi + echo "$(fixlen "$1" 21) $(fixlen "$EXP_ENV" 40) $EXISTS $ON_PATH $CRIT" else - echo "`fixlen "$1" 21` --------- env variable not set --------- $3" + echo "$(fixlen "$1" 21) --------- env variable not set --------- $3" fi - ERROR="false" + ERROR=false if [ "$EXISTS" = no ] || [ "$ON_PATH" = no ] then - ERROR="true" + ERROR=true fi if [ "$3" = yes ] && [ "$ERROR" = true ] then - criticalError=`expr $criticalError + 1` + criticalError="x${criticalError}" echo "WARNING: CRITICAL ERROR" echo fi - } @@ -198,139 +145,149 @@ findExec() IFS=':' for d in $1 do - case "$OSTYPE" in - SunOS) - if /usr/bin/test ! -d "$d/$2" -a -x "$d/$2" - then - IFS=$oldIFS - echo "$d/$2" - return 0 - fi - ;; - *) - if [ ! -d "$d/$2" -a -x "$d/$2" ] - then - IFS=$oldIFS - echo "$d/$2" - return 0 - fi - ;; - esac + if test ! -d "$d/$2" -a -x "$d/$2" + then + IFS=$oldIFS + echo "$d/$2" + return 0 + fi done IFS=$oldIFS return 1 } +# compare (required-version, version) +# Major.minor.patch <= Major.minor.patch +# +vercmp_3() +{ + local arg1="$1" + local arg2="$2" + + oldIFS=$IFS + IFS='.' + set -- $arg1 + local arg1Major=$1 arg1Minor=$2 arg1Patch="${3:-0}" + + set -- $arg2 + local arg2Major=$1 arg2Minor=$2 arg2Patch="${3:-0}" + + IFS=$oldIFS + + #debug> echo "check $arg1 vs $arg2" + #debug> echo "arg1maj=$arg1Major arg1min=$arg1Minor arg1patch=$arg1Patch" + #debug> echo "arg2maj=$arg2Major arg2min=$arg2Minor arg2patch=$arg2Patch" + + # Major version + if [ $arg1Major -lt $arg2Major ] + then + return 0 + elif [ $arg1Major -gt $arg2Major ] + then + return 1 + fi + + # Minor version + if [ $arg1Minor -lt $arg2Minor ] + then + return 0 + elif [ $arg1Minor -gt $arg2Minor ] + then + return 2 + fi + + # Patch + if [ -n "$arg1Patch" -a -n "$arg2Patch" ] + then + if [ "$arg1Patch" -gt "$arg2Patch" ] + then + return 3 + fi + fi + + return 0 +} + + reportExecutable() { - APP_PATH="" - APP_PATH=`findExec $PATH $1` + APP_NAME="$1" APP_SPEC="$2" - if [ ! -n $APP_PATH ] + APP_PATH="$(findExec $PATH $1)" + if [ -z "$APP_PATH" ] then - echo "`fixlen "$1" 9`" "*** not installed ***" + echo "$(fixlen "$1" 9)" "*** not installed ***" VERSION="" case "$1" in gcc* | $foamTestApp) echo " CRITICAL ERROR" - criticalError=`expr $criticalError + 1` + criticalError="x${criticalError}" ;; esac echo return 1 fi - case "$1" in + case "$APP_NAME" in $foamTestApp) - VERSION=`$1 -case /dev/null 2>&1 \ - | sed -ne 's/^.*Version: *\([^ ][^ ]*\).*/\1/p'` + VERSION=$($APP_NAME -case /dev/null 2>&1 \ + | sed -ne 's/^.*Version: *\([^ ][^ ]*\).*/\1/p') ;; flex) - VERSION=`$1 --version /dev/null 2>&1 \ - | sed -ne 's/flex \([0-9][0-9.]*\).*/\1/p' ` + VERSION=$($APP_NAME --version /dev/null 2>&1 \ + | sed -ne 's/flex \([0-9][0-9.]*\).*/\1/p') ;; gcc* | g++*) - VERSION=`$1 -v 2>&1 \ - | sed -ne 's/^gcc version \([0-9][0-9.]*\).*/\1/p' ` + VERSION=$($APP_NAME -v 2>&1 \ + | sed -ne 's/^gcc version \([0-9][0-9.]*\).*/\1/p') - case "$1" in - gcc*) - BINARYCODENAME=gcc - ;; - g++*) - BINARYCODENAME=g++ - ;; - esac + if ! vercmp_3 "$MIN_VERSION_GCC" "$VERSION" + then + case "$APP_NAME" in + gcc*) + SHORT_NAME=gcc + ;; + g++*) + SHORT_NAME=g++ + ;; + esac - MINV1=`echo $MIN_VERSION_GCC | cut -d. -f1` - MINV2=`echo $MIN_VERSION_GCC | cut -d. -f2` - MINV3=`echo $MIN_VERSION_GCC | cut -d. -f3` - - V1=`echo $VERSION | cut -d. -f1` - V2=`echo $VERSION | cut -d. -f2` - V3=`echo $VERSION | cut -d. -f3` - - - gccOK="" - pass="" - if [ $V1 -lt $MINV1 ]; then - gccOk="ERROR" - elif [ $V1 -gt $MINV1 ]; then - pass="yes" - fi - - if [ "$pass" = "" ] && [ "$gccOk" = "" ]; then - if [ $V2 -lt $MINV2 ]; then - gccOk="ERROR" - elif [ $V2 -gt $MINV2 ]; then - pass="yes" - fi - fi - - if [ "$pass" = "" ] && [ "$gccOk" = "" ] && [ $V3 != "" ] && [ $MINV3 != "" ]; then - if [ $V3 -lt $MINV3 ]; then - gccOk="ERROR" - fi - fi - - if [ "$gccOk" != "" ]; then - echo "ERROR: $BINARYCODENAME version is too old for this release of OpenFOAM" + echo "ERROR: $SHORT_NAME version is too old for this release of OpenFOAM" echo " User version : $VERSION" echo " Minimum required: $MIN_VERSION_GCC" echo "" - fatalError=`expr $fatalError + 1` + fatalError="x${fatalError}" fi - ;; gtar) - VERSION=`$APP_PATH --version | head -1` + VERSION=$($APP_PATH --version | head -1) ;; tar) - VERSION=`$APP_PATH --version | head -1 | cut -d" " -f4` + VERSION=$($APP_PATH --version | head -1 | cut -d" " -f4) ;; gzip) case "$OSTYPE" in SunOS) - VERSION=`$1 --version 2>&1 | grep gzip | cut -d" " -f2` + VERSION=$($APP_NAME --version 2>&1 | grep gzip | cut -d" " -f2) ;; *) - VERSION=`$1 --version | head -1 | cut -d" " -f2` + VERSION=$($APP_NAME --version | head -1 | cut -d" " -f2) ;; esac ;; esac - if [ "$APP_PATH" = "$APP_SPEC" ] || [ ! "$2" ] + if [ "$APP_PATH" = "$APP_SPEC" ] || [ -z "$APP_SPEC" ] then - echo "`fixlen "$1" 9` `fixlen "$VERSION" 10` `fixlen "$APP_PATH" 58`" + echo "$(fixlen "$APP_NAME" 9) $(fixlen "$VERSION" 10) $(fixlen "$APP_PATH" 58)" else - echo "`fixlen "$1" 9` `fixlen "$VERSION" 10`" + echo "$(fixlen "$APP_NAME" 9) $(fixlen "$VERSION" 10)" echo "WARNING: Conflicting installations:" echo " OpenFOAM settings : $APP_SPEC" echo " current path : $APP_PATH" - case "$1" in + case "$APP_NAME" in gcc | $foamTestApp) echo " CRITICAL ERROR" - criticalError=`expr $criticalError + 1` + criticalError="x${criticalError}" ;; esac echo "" @@ -340,7 +297,9 @@ reportExecutable() checkOpenFOAMEnvironment() { - [ -d "$WM_PROJECT_INST_DIR" ] && [ -d "$WM_THIRD_PARTY_DIR" ] || { + [ -d "$WM_PROJECT_INST_DIR" ] && \ + [ -d "$WM_PROJECT_DIR" ] && \ + [ -d "$WM_THIRD_PARTY_DIR" ] || { echo "" echo "FATAL ERROR: OpenFOAM environment not configured." echo "" @@ -350,12 +309,15 @@ checkOpenFOAMEnvironment() echo "" exit 1 } + + echo "$(fixlen OpenFOAM: $WIDTH) ${WM_PROJECT_DIR##*/}" + echo "$(fixlen ThirdParty: $WIDTH) ${WM_THIRD_PARTY_DIR##*/}" } checkUserShell() { - echo "`fixlen Shell: $WIDTH` ${SHELL##*/}" + echo "$(fixlen Shell: $WIDTH) ${SHELL##*/}" case $SHELL in */csh | */tcsh | */bash | */ksh) ;; @@ -364,7 +326,7 @@ checkUserShell() echo " OpenFOAM ${WM_PROJECT_VERSION} is compatible with " echo " csh, tcsh, ksh and bash." echo - fatalError=`expr $fatalError + 1` + fatalError="x${fatalError}" ;; esac } @@ -372,15 +334,15 @@ checkUserShell() checkHostName() { - echo "`fixlen Host: $WIDTH` $HOST" - if [ ! "$HOST" ] + echo "$(fixlen Host: $WIDTH) $HOST" + if [ -z "$HOST" ] then echo "FATAL ERROR: Cannot stat hostname." echo " Contact your system administrator, " echo " OpenFOAM ${WM_PROJECT_VERSION} needs a valid " echo " hostname to function." echo - fatalError=`expr $fatalError + 1` + fatalError="x${fatalError}" fi } @@ -389,14 +351,14 @@ checkOS() { case "$OSTYPE" in Linux | LinuxAMD64 | SunOS ) - echo "`fixlen OS: $WIDTH` $OSTYPE version $(uname -r)" + echo "$(fixlen OS: $WIDTH) $OSTYPE version $(uname -r)" ;; *) echo "FATAL ERROR: Incompatible operating system \"$OSTYPE\"." echo " OpenFOAM ${FWM_PROJECT_VERSION} is currently " echo " available for Linux and SunOS only." echo - fatalError=`expr $fatalError + 1` + fatalError="x${fatalError}" ;; esac } @@ -409,7 +371,7 @@ checkOS() echo "Executing $0:" #------------------------------------------------------------------------------ -heading "Checking basic setup..." +heading "Basic setup :" hline checkOpenFOAMEnvironment checkUserShell @@ -418,51 +380,48 @@ checkOS hline #------------------------------------------------------------------------------ -heading "Checking main OpenFOAM env variables..." -COL1=`fixlen Environment_variable 21` -COL2=`fixlen Set_to_file_or_directory 40` +heading "Main OpenFOAM env variables :" +COL1=$(fixlen EnvironmentVariable 21) +COL2=$(fixlen FileOrDirectory 40) COL3="Valid" COL4="Path" COL5="Crit" hline echo "$COL1 $COL2 $COL3 $COL5" hline -reportEnv '$WM_PROJECT_INST_DIR' 'noPath' "yes" -reportEnv '$WM_PROJECT_USER_DIR' 'noPath' "no" -reportEnv '$WM_THIRD_PARTY_DIR' 'noPath' "yes" +reportEnv '$WM_PROJECT_INST_DIR' noPath yes +reportEnv '$WM_PROJECT_USER_DIR' noPath no +reportEnv '$WM_THIRD_PARTY_DIR' noPath yes hline #------------------------------------------------------------------------------ -heading "Checking the OpenFOAM env variables set on the PATH..." +heading "OpenFOAM env variables in PATH :" hline echo "$COL1 $COL2 $COL3 $COL4 $COL5" hline -reportEnv '$WM_PROJECT_DIR' '$PATH' "yes" +reportEnv '$WM_PROJECT_DIR' '$PATH' yes echo "" -reportEnv '$FOAM_APPBIN' '$PATH' "yes" -reportEnv '$FOAM_SITE_APPBIN' '$PATH' "no" -reportEnv '$FOAM_USER_APPBIN' '$PATH' "no" -reportEnv '$WM_DIR' '$PATH' "yes" +reportEnv '$FOAM_APPBIN' '$PATH' yes +reportEnv '$FOAM_SITE_APPBIN' '$PATH' no +reportEnv '$FOAM_USER_APPBIN' '$PATH' no +reportEnv '$WM_DIR' '$PATH' yes hline #------------------------------------------------------------------------------ -heading "Checking the OpenFOAM env variables set on the LD_LIBRARY_PATH..." +heading "OpenFOAM env variables in LD_LIBRARY_PATH :" hline echo "$COL1 $COL2 $COL3 $COL4 $COL5" hline -reportEnv '$FOAM_LIBBIN' '$LD_LIBRARY_PATH' "yes" -reportEnv '$FOAM_SITE_LIBBIN' '$LD_LIBRARY_PATH' "no" -reportEnv '$FOAM_USER_LIBBIN' '$LD_LIBRARY_PATH' "no" -reportEnv '$MPI_ARCH_PATH' '$LD_LIBRARY_PATH' "yes" +reportEnv '$FOAM_LIBBIN' '$LD_LIBRARY_PATH' yes +reportEnv '$FOAM_SITE_LIBBIN' '$LD_LIBRARY_PATH' no +reportEnv '$FOAM_USER_LIBBIN' '$LD_LIBRARY_PATH' no +reportEnv '$MPI_ARCH_PATH' '$LD_LIBRARY_PATH' yes hline #------------------------------------------------------------------------------ -heading "Third party software" -COL1=`fixlen Software 9` -COL2=`fixlen Version 10` -COL3=`fixlen Location 10` +heading "Third-party software" hline -echo "$COL1 $COL2 $COL3" +echo "$(fixlen Software 9) $(fixlen Version 10) $(fixlen Location 10)" hline reportExecutable flex reportExecutable "$WM_CC" @@ -482,19 +441,19 @@ hline heading "Summary" hline -if [ $fatalError -gt 0 ] +if [ "${#fatalError}" -gt 0 ] then - echo "The system test has evoked $fatalError fatal error(s)." + echo "The system test evoked ${#fatalError} fatal error(s)." else echo "Base configuration ok." fi -if [ $criticalError -gt 0 ] +if [ "${#criticalError}" -gt 0 ] then - echo "The foam installation contains $criticalError critical error(s)." + echo "The foam installation contains ${#criticalError} critical error(s)." else echo "Critical systems ok." fi -if [ $criticalError -gt 0 ] || [ $fatalError -gt 0 ] +if [ "${#criticalError}" -gt 0 ] || [ "${#fatalError}" -gt 0 ] then echo echo "Review the output for warning messages and consult"