diff --git a/meshLibrary/Make/files b/meshLibrary/Make/files index 47ae223b8a6dd9f32c6e8826cf0a6003c6093600..ef528763c98ba9467352e6162eeeb75bfda94411 100644 --- a/meshLibrary/Make/files +++ b/meshLibrary/Make/files @@ -128,6 +128,8 @@ tetMeshExtractor = tetMesh/tetMeshExtractor tetMeshExtractorOctree = tetMesh/tetMeshExtractorOctree tetMeshGenerator = tetMesh/tetMeshGenerator +workflowControls = utilities/workflowControls + $(checkMeshDict)/checkMeshDict.C $(lists)/pointFieldPMG.C @@ -435,4 +437,6 @@ $(tetMeshGenerator)/tetMeshGenerator.C $(writeAsFPMA)/writeMeshFPMA.C $(writeAsFPMA)/fpmaMesh.C +$(workflowControls)/workflowControls.C + LIB = $(FOAM_USER_LIBBIN)/libmeshLibrary diff --git a/meshLibrary/utilities/workflowControls/workflowControls.C b/meshLibrary/utilities/workflowControls/workflowControls.C new file mode 100644 index 0000000000000000000000000000000000000000..35d26bf30423c69fd300ef3ba33d0d7872bb0f65 --- /dev/null +++ b/meshLibrary/utilities/workflowControls/workflowControls.C @@ -0,0 +1,162 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | cfMesh: A library for mesh generation + \\ / O peration | + \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com) + \\/ M anipulation | Copyright (C) Creative Fields, Ltd. +------------------------------------------------------------------------------- +License + This file is part of cfMesh. + + cfMesh 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. + + cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>. + +Description + +\*---------------------------------------------------------------------------*/ + +#include "workflowControls.H" +#include "polyMeshGen.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +const std::map<word, label> workflowControls::workflowSteps_ = + populateWorkflowSteps(); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +bool workflowControls::restartPossibleAfterCurrentStep() const +{ + return false; +} + +void workflowControls::setStepCompleted() const +{ + mesh_.metaData().add("lastStep", currentStep_); +} + +bool workflowControls::exitAfterCurrentStep() const +{ + const IOdictionary& meshDict = + mesh_.returnTime().lookupObject<IOdictionary>("meshDict"); + + const dictionary& workflowControls = meshDict.subDict("workflowControls"); + + if( workflowControls.found("stopAfter") ) + { + const word exitStep(workflowControls.lookup("stopAfter")); + + if( exitStep == currentStep_ ) + return true; + } + + return false; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +std::map<word, label> workflowControls::populateWorkflowSteps() +{ + std::map<word, label> workflowSteps; + workflowSteps.insert(std::make_pair(word("templateGeneration"), 1)); + workflowSteps.insert(std::make_pair(word("surfaceTopology"), 2)); + workflowSteps.insert(std::make_pair(word("surfaceProjection"), 4)); + workflowSteps.insert(std::make_pair(word("patchAssignment"), 8)); + workflowSteps.insert(std::make_pair(word("edgeExtraction"), 16)); + workflowSteps.insert(std::make_pair(word("boundaryLayerGeneration"), 32)); + workflowSteps.insert(std::make_pair(word("boundaryLayerRefinement"), 64)); + + return workflowSteps; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +workflowControls::workflowControls(polyMeshGen& mesh) +: + mesh_(mesh), + status_(0), + currentStep_() +{} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +workflowControls::~workflowControls() +{} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +void workflowControls::setCurrentStep(const word& stepName) +{ + //- check if the requested step exists in the database of steps + std::map<word, label>::const_iterator it = workflowSteps_.find(stepName); + if( it == workflowSteps_.end() ) + { + FatalErrorIn + ( + "void workflowControls::setCurrentStep(const word&)" + ) << "Step " << stepName << " is not a valid name." << exit(FatalError); + } + + currentStep_ = stepName; + status_ |= it->second; +} + +bool workflowControls::stopAfterCurrentStep() const +{ + setStepCompleted(); + + if( exitAfterCurrentStep() ) + { + bool writeSuccess(true); + + try + { + mesh_.write(); + } + catch(...) + { + writeSuccess = false; + } + + returnReduce(writeSuccess, minOp<bool>()); + + if( !writeSuccess ) + FatalErrorIn + ( + "bool workflowControls::stopAfterCurrentStep() const" + ) << "Mes was not written on disk" << exit(FatalError); + + return true; + } + + return false; +} + +bool workflowControls::restartAfterCurrentStep() const +{ + return false; +} + +void workflowControls::workflowCompleted() +{ + mesh_.metaData().remove("lastStep"); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/meshLibrary/utilities/workflowControls/workflowControls.H b/meshLibrary/utilities/workflowControls/workflowControls.H new file mode 100644 index 0000000000000000000000000000000000000000..1732c22e024331544363136e9e6267a36620a925 --- /dev/null +++ b/meshLibrary/utilities/workflowControls/workflowControls.H @@ -0,0 +1,120 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | cfMesh: A library for mesh generation + \\ / O peration | + \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com) + \\/ M anipulation | Copyright (C) Creative Fields, Ltd. +------------------------------------------------------------------------------- +License + This file is part of cfMesh. + + cfMesh 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. + + cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>. + +Class + workflowControls + +Description + A controller fo managing the mesh generation workflow. It allows the user + to stop the meshing process after selected steps in the workflow, + and restart from a selected point. + +SourceFiles + workflowControls.C + +\*---------------------------------------------------------------------------*/ + +#ifndef workflowControls_H +#define workflowControls_H + +#include "objectRegistry.H" +#include "Time.H" +#include "IOdictionary.H" + +#include <map> + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class polyMeshGen; + +/*---------------------------------------------------------------------------*\ + Class workflowControls Declaration +\*---------------------------------------------------------------------------*/ + +class workflowControls +{ + // Private data + //- reference to the mesh + polyMeshGen& mesh_; + + //- status of the workflow (sets bits to completed steps) + label status_; + + //- current step in the workflow + word currentStep_; + + // static private data + static const std::map<word, label> workflowSteps_; + + // Private member functions + //- check if it is possible to restart after the current step + bool restartPossibleAfterCurrentStep() const; + + //- sets the current step to completed + void setStepCompleted() const; + + //- shall the procedure stop after the current step + bool exitAfterCurrentStep() const; + + // Static private member functions + //- populate workflowSteps with values + static std::map<word, label> populateWorkflowSteps(); + +public: + + // Constructors + + //- Construct from IOdictionary + workflowControls(polyMeshGen& mesh); + + // Destructor + ~workflowControls(); + + // Public member functions + + //- set current step + void setCurrentStep(const word&); + + //- shall the workflow stop after the current step + bool stopAfterCurrentStep() const; + + //- shall the workflow restart after the current step + bool restartAfterCurrentStep() const; + + //- set the workflow completed flag + void workflowCompleted(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //