From 8cb90dab4f9af1b3c2d401deb44dd056d2ae5d64 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Wed, 26 Jan 2022 12:02:07 +0000 Subject: [PATCH] functionObjectList: Improved error message if a functionObject configuration file is not foundation e.g. if streamlinesLines is specified rather than the correct streamlinesLine in the controlDict::functions list: functions { #includeFunc streamlinesLines ( funcName=streamlines, start=(-0.0205 0.001 0.00001), end=(-0.0205 0.0251 0.00001), nPoints=10, fields=(p k U) ) } the following error message is generated providing a list of all the functionObject configuration files available and the run stops rather than continuing regardless of the error: --> FOAM FATAL IO ERROR: Cannot find functionObject configuration file streamlinesLines Available configured functionObjects: 88 ( CourantNo Lambda2 MachNo PecletNo Q Qdot XiReactionRate add age boundaryProbes cellMax cellMaxMag cellMin cellMinMag components cutPlaneSurface ddt div divide dsmcFields enstrophy faceZoneAverage faceZoneFlowRate fieldAverage flowType forceCoeffsCompressible forceCoeffsIncompressible forcesCompressible forcesIncompressible grad graphCell graphCellFace graphFace graphLayerAverage graphUniform interfaceHeight internalProbes isoSurface log mag magSqr moments multiply particles patchAverage patchDifference patchFlowRate patchIntegrate patchSurface phaseForces phaseMap phaseScalarTransport probes randomise residuals scalarTransport scale shearStress sizeDistribution staticPressureIncompressible stopAtClockTime stopAtFile streamFunction streamlinesLine streamlinesPatch streamlinesPoints streamlinesSphere subtract surfaceInterpolate time timeStep totalEnthalpy totalPressureCompressible totalPressureIncompressible triSurfaceDifference triSurfaceVolumetricFlowRate turbulenceFields turbulenceIntensity uniform vorticity wallHeatFlux wallHeatTransferCoeff wallShearStress writeCellCentres writeCellVolumes writeObjects writeVTK yPlus ) file: /home/dm2/henry/OpenFOAM/OpenFOAM-dev/tutorials/incompressible/simpleFoam/pitzDaily/system/controlDict/functions From function static bool Foam::functionObjectList::readFunctionObject(const Foam::string&, Foam::dictionary&, const Foam::Pair&, const Foam::word&) in file db/functionObjects/functionObjectList/functionObjectList.C at line 250. FOAM exiting --- .../postProcessing/postProcess/postProcess.C | 7 ++- .../functionObject/functionObject.C | 6 +- .../functionObjectList/functionObjectList.C | 56 +++++++------------ .../functionObjectList/functionObjectList.H | 6 +- .../functionObjectList/postProcess.H | 7 ++- 5 files changed, 36 insertions(+), 46 deletions(-) diff --git a/applications/utilities/postProcessing/postProcess/postProcess.C b/applications/utilities/postProcessing/postProcess/postProcess.C index a557dbe14a..24127e7e32 100644 --- a/applications/utilities/postProcessing/postProcess/postProcess.C +++ b/applications/utilities/postProcessing/postProcess/postProcess.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -148,7 +148,10 @@ int main(int argc, char *argv[]) if (args.optionFound("list")) { - functionObjectList::list(); + Info<< nl + << "Available configured functionObjects:" + << functionObjectList::list() + << endl; return 0; } diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C index 8878dc618e..7529abd0c5 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -89,7 +89,7 @@ Foam::autoPtr Foam::functionObject::New FatalErrorInFunction << "Unknown function type " << functionType << nl << nl - << "Table of functionObjects is empty" << endl + << "Table of functionObjects is empty" << exit(FatalError); } @@ -102,7 +102,7 @@ Foam::autoPtr Foam::functionObject::New << "Unknown function type " << functionType << nl << nl << "Valid functions are : " << nl - << dictionaryConstructorTablePtr_->sortedToc() << endl + << dictionaryConstructorTablePtr_->sortedToc() << exit(FatalError); } diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 2687448290..dd94984cac 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -99,7 +99,7 @@ void Foam::functionObjectList::listDir } -void Foam::functionObjectList::list() +Foam::wordList Foam::functionObjectList::list() { HashSet foMap; @@ -110,10 +110,7 @@ void Foam::functionObjectList::list() listDir(etcDirs[ed], foMap); } - Info<< nl - << "Available configured functionObjects:" - << foMap.sortedToc() - << nl; + return foMap.sortedToc(); } @@ -250,8 +247,12 @@ bool Foam::functionObjectList::readFunctionObject if (path == fileName::null) { - WarningInFunction - << "Cannot find functionObject file " << funcType << endl; + FatalIOErrorInFunction(functionsDict) + << "Cannot find functionObject configuration file " + << funcType << nl << nl + << "Available configured functionObjects:" + << list() + << exit(FatalIOError); return false; } @@ -759,7 +760,7 @@ bool Foam::functionObjectList::read() } const dictionary& dict = iter().dict(); - bool enabled = dict.lookupOrDefault("enabled", true); + const bool enabled = dict.lookupOrDefault("enabled", true); newDigs[nFunc] = dict.digest(); @@ -788,38 +789,21 @@ bool Foam::functionObjectList::read() { autoPtr foPtr; - FatalError.throwExceptions(); - FatalIOError.throwExceptions(); - try + if + ( + dict.found("writeControl") + || dict.found("outputControl") + ) { - if + foPtr.set ( - dict.found("writeControl") - || dict.found("outputControl") - ) - { - foPtr.set - ( - new functionObjects::timeControl(key, time_, dict) - ); - } - else - { - foPtr = functionObject::New(key, time_, dict); - } + new functionObjects::timeControl(key, time_, dict) + ); } - catch (Foam::IOerror& ioErr) + else { - Info<< ioErr << nl << endl; - ::exit(1); + foPtr = functionObject::New(key, time_, dict); } - catch (Foam::error& err) - { - WarningInFunction - << "Caught FatalError " << err << nl << endl; - } - FatalError.dontThrowExceptions(); - FatalIOError.dontThrowExceptions(); if (foPtr.valid()) { diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index 7308e5c678..34f6e7d994 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -174,7 +174,7 @@ public: //- Find the ID of a given function object by name label findObjectID(const word& name) const; - //- Print a list of functionObject configuration files in + //- Return the list of functionObject configuration files in // user/group/shipped directories. // The search scheme allows for version-specific and // version-independent files using the following hierarchy: @@ -190,7 +190,7 @@ public: // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/postProcessing // - \b other (shipped) settings: // - $WM_PROJECT_DIR/etc/caseDicts/postProcessing - static void list(); + static wordList list(); //- Search for functionObject dictionary file for given region // and if not present also search the case directory as well as the diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/postProcess.H b/src/OpenFOAM/db/functionObjects/functionObjectList/postProcess.H index 325bf381dc..f13caaad1a 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/postProcess.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/postProcess.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -76,7 +76,10 @@ if (argList::postProcess(argc, argv)) if (args.optionFound("list")) { - functionObjectList::list(); + Info<< nl + << "Available configured functionObjects:" + << functionObjectList::list() + << endl; return 0; }