From 5f6f5e4364fc0dcaae71d4891a917dc5dc4476c0 Mon Sep 17 00:00:00 2001 From: andy <andy> Date: Thu, 16 Aug 2012 14:38:05 +0100 Subject: [PATCH] ENH: Added help utility for buondary conditions --- .../helpTypes/helpBoundary/helpBoundary.C | 185 ++++++++++++++++++ .../helpTypes/helpBoundary/helpBoundary.H | 109 +++++++++++ .../helpBoundary/helpBoundaryTemplates.C | 160 +++++++++++++++ 3 files changed, 454 insertions(+) create mode 100644 applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundary.C create mode 100644 applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundary.H create mode 100644 applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundaryTemplates.C diff --git a/applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundary.C b/applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundary.C new file mode 100644 index 00000000000..3d1c995018d --- /dev/null +++ b/applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundary.C @@ -0,0 +1,185 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "helpBoundary.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + namespace helpTypes + { + defineTypeNameAndDebug(helpBoundary, 0); + addNamedToRunTimeSelectionTable + ( + helpType, + helpBoundary, + dictionary, + boundary + ); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::helpTypes::helpBoundary::helpBoundary() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::helpTypes::helpBoundary::~helpBoundary() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::helpTypes::helpBoundary::init() +{ + helpType::init(); + + argList::validArgs.append("boundary"); + + argList::addOption + ( + "field", + "word", + "list available conditions for field" + ); + argList::addBoolOption + ( + "constraint", + "list constraint patches" + ); + argList::addBoolOption + ( + "fixedValue", + "list fixed value patches (use with -field option)" + ); +} + + +void Foam::helpTypes::helpBoundary::execute +( + const argList& args, + const fvMesh& mesh +) +{ + bool abortVar(env("FOAM_ABORT")); + if (abortVar) + { + FatalErrorIn + ( + "void Foam::helpTypes::helpBoundary::execute" + "(" + "const argList&, " + "const fvMesh&" + ")" + ) + << "Please unset FOAM_ABORT to use this utlity" + << exit(FatalError); + } + + word condition(word::null); + word fieldName(word::null); + + if (args.optionReadIfPresent("browse", condition)) + { + // TODO: strip scoping info if present? + // e.g. conditions with leading "compressible::" will not be found + // ".*[fF]vPatchField.*" + className + ".*" + displayDoc(condition, ".*[fF]vPatchField.*", false); + } + else if (args.optionFound("constraint")) + { + HashSet<word> constraintTypes(fvPatch::constraintTypes()); + Info<< "Constraint types:" << nl; + forAllConstIter(HashSet<word>, constraintTypes, iter) + { + Info<< " " << iter.key() << nl; + } + Info<< endl; + } + else if (args.optionReadIfPresent("field", fieldName)) + { + IOobject fieldHeader + ( + fieldName, + mesh.time().timeName(), + mesh, + IOobject::MUST_READ + ); + + if (fieldHeader.headerOk()) + { + if (args.optionFound("fixedValue")) + { + fixedValueFieldConditions<scalar>(fieldHeader); + fixedValueFieldConditions<vector>(fieldHeader); + fixedValueFieldConditions<sphericalTensor>(fieldHeader); + fixedValueFieldConditions<symmTensor>(fieldHeader); + fixedValueFieldConditions<tensor>(fieldHeader); + } + else + { + (void)fieldConditions<scalar>(fieldHeader, true); + (void)fieldConditions<vector>(fieldHeader, true); + (void)fieldConditions<sphericalTensor>(fieldHeader, true); + (void)fieldConditions<symmTensor>(fieldHeader, true); + (void)fieldConditions<tensor>(fieldHeader, true); + } + } + else + { + FatalErrorIn + ( + "void Foam::helpTypes::helpBoundary::execute" + "(" + "const argList&, " + "const fvMesh&" + ")" + ) + << "Unable to read field " << fieldName << exit(FatalError); + } + } + else if (args.optionReadIfPresent("fixedValue", fieldName)) + { + FatalErrorIn + ( + "void Foam::helpTypes::helpBoundary::execute" + "(" + "const argList&, " + "const fvMesh&" + ")" + ) + << "-field option must be specified when using the -fixedValue " + << "option" << exit(FatalError); + } +} + + +// ************************************************************************* // diff --git a/applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundary.H b/applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundary.H new file mode 100644 index 00000000000..515425b7bcc --- /dev/null +++ b/applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundary.H @@ -0,0 +1,109 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::helpBoundary + +Description + + +SourceFiles + helpBoundary.C + helpBoundaryTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef helpBoundary_H +#define helpBoundary_H + +#include "helpType.H" +#include "IOobject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace helpTypes +{ + +/*---------------------------------------------------------------------------*\ + Class helpBoundary Declaration +\*---------------------------------------------------------------------------*/ + +class helpBoundary +: + public helpType +{ + +protected: + + // Protected Member Functions + + //- Return/output the available boundary conditions for fields of Type + template<class Type> + wordList fieldConditions(const IOobject& io, const bool write) const; + + //- Output the available fixed boundary conditions for fields of Type + template<class Type> + void fixedValueFieldConditions(const IOobject& io) const; + + +public: + + //- Runtime type information + TypeName("helpBoundary"); + + //- Constructor + helpBoundary(); + + //- Destructor + virtual ~helpBoundary(); + + + // Member Functions + + //- Initialise - typically setting static variables, + // e.g. command line arguments + virtual void init(); + + //- Execute the help + virtual void execute(const argList& args, const fvMesh& mesh); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace helpTypes +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "helpBoundaryTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundaryTemplates.C b/applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundaryTemplates.C new file mode 100644 index 00000000000..d9ee2c92f1b --- /dev/null +++ b/applications/utilities/miscellaneous/foamHelp/helpTypes/helpBoundary/helpBoundaryTemplates.C @@ -0,0 +1,160 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + + +\*---------------------------------------------------------------------------*/ + +#include "GeometricField.H" +#include "fvPatchField.H" +#include "volMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template<class Type> +Foam::wordList Foam::helpTypes::helpBoundary::fieldConditions +( + const IOobject& io, + const bool write +) const +{ + typedef GeometricField<Type, fvPatchField, volMesh> fieldType; + + if (io.headerClassName() == fieldType::typeName) + { + wordList types + ( + fvPatchField<Type>::dictionaryConstructorTablePtr_->sortedToc() + ); + + if (write) + { + Info<< "Available boundary conditions for " + << pTraits<Type>::typeName << " field: " << io.name() << nl; + + forAll(types, i) + { + Info<< " " << types[i] << nl; + } + + Info<< endl; + } + + return types; + } + + return wordList(); +} + + +template<class Type> +void Foam::helpTypes::helpBoundary::fixedValueFieldConditions +( + const IOobject& io +) const +{ + wordList types(fieldConditions<Type>(io, false)); + + if (!types.size()) + { + return; + } + + typedef GeometricField<Type, fvPatchField, volMesh> fieldType; + + const fvMesh& mesh = dynamic_cast<const fvMesh&>(io.db()); + + fieldType fld + ( + IOobject + ( + "dummy", + mesh.time().timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + mesh, + dimensioned<Type>("zero", dimless, pTraits<Type>::zero) + ); + + + Info<< "Fixed value boundary conditions for " + << pTraits<Type>::typeName << " field: " << io.name() << nl; + + // throw exceptions to avoid fatal errors when casting from generic patch + // type to incompatible patch type + FatalIOError.throwExceptions(); + FatalError.throwExceptions(); + + bool foundFixed = false; + forAll(types, i) + { + const word& patchType = types[i]; + + try + { + polyPatch pp + ( + "defaultFaces", + 0, + mesh.nInternalFaces(), + 0, + mesh.boundaryMesh() + ); + + fvPatch fvp(pp, mesh.boundary()); + + tmp<fvPatchField<Type> > pf + ( + fvPatchField<Type>::New + ( + patchType, + fvp, + fld + ) + ); + + if (pf().fixesValue()) + { + Info<< " " << patchType << nl; + foundFixed = true; + } + } + catch (...) + { + // do nothing + } + } + + if (!foundFixed) + { + // no conditions??? + Info<< " none" << nl; + } + + Info<< endl; +} + + +// ************************************************************************* // -- GitLab