View Issue Details

IDProjectCategoryView StatusLast Update
0002015OpenFOAMBugpublic2016-03-06 21:37
Reporterwyldckat Assigned Tohenry  
Status resolvedResolutionfixed 
Product Versiondev 
Summary0002015: Sprucing up the tutorials folder and adding -dict to "collapseEdges"
DescriptionExtending on what was introduced in #1919 - - and in the spirit of the current effort on improving maintainability, the attached contribution aims to remove the need for "Allrun" scripts to delete or rename log files, simply because we need to execute an application more than once, with different settings each time, for the same case.
It was tested with the commit 51f93d3b437 from OpenFOAM-dev, but should still work with the latest changes present in the latest commits.

This contribution adds/modifies the following features:

 1. New "-suffix" argument for the script functions "runApplication" and "runParallel", which receives a second argument which will result in the name being appended to it.
    For example, this:
       runApplication topoSet
       mv log.topoSet log.topoSet.1
    was changed to this:
       runApplication -s 1 topoSet
    Another example:
       - faceAgglomerate -region $i -dict constant/viewFactorsDict > log.faceAgglomerate.$i 2>&1
       + runApplication -s $i \
       + faceAgglomerate -region $i -dict constant/viewFactorsDict

    Note: the line break is used in a lot of the changes to make it easier to read the script code.

    Associated with this change, all "Allrun*" tutorial scripts were updated accordingly with the new suffix option ("-s" to be specific).

 2. All arguments for "runApplication" and "runParallel" now have a shortened alias for them:

      -append or -a
      -overwrite or -o
      -suffix or -s
      -np or -n

 3. A few tutorials were using a somewhat confusing "while" loop to run 3 or 6 passes of a particular mesh manipulation strategy (e.g. refineMesh 6 times), have been changed to use a "for" loop and the new suffix option for "runApplication".

 4. A couple of minor fixes were done in "multiphase/interPhaseChangeDyMFoam/propeller/Allrun.pre".
 5. Changed the way "patchifyObstacles" is executed in "lagrangian/reactingParcelFilmFoam/hotBoxes/Allrun.pre".
 6. Modified "applications/utilities/mesh/advanced/collapseEdges/collapseEdges.C" to accept the usual "-dict" option for these kinds of applications in OpenFOAM. Along with this:

      - the class "src/dynamicMesh/polyMeshFilter" was adjusted accordingly, by adding a new constructor that accepts receiving a preloaded "dict" object, instead of only having options that load a hardcoded "collapseDict";

      - most of the tutorial cases that use "collapseEdges" have been modified to use the new "-dict" option and to no longer need renaming the dictionary files.

      - Note: I didn't add the ability to have a subdict in "foamyHexMeshDict" for a "collapseDict" block, because I wasn't certain if this would have been the best step to take. Nonetheless, now that I think about it, there is already a precedent for the "meshQualityDict" in "snappyHexMeshDict". Please let me know if you want me to provide this change as well, therefore dropping the hard-coded paths to the "dict" in "polyMeshFilter".
 7. The script "tutorials/Allrun" has a small change in the function "logReport()", so that it will properly recognize the name of the application that is in the log file. This changed cryptic reports like the following in "testLoopReport":

      Application 1 - case chtMultiRegionSimpleFoam/heatExchanger: completed

    To this:

      Application topoSet.air.1 - case chtMultiRegionSimpleFoam/heatExchanger: completed

 8. The script "tutorials/mesh/foamyHexMesh/mixerVessel/Allrun-pre" script was broken, because it was hardcoded to moving the contents of the folder "101/polyMesh" to "constant/polyMesh". The correction provided relies in using "foamListTimes -latestTime" instead.
    I didn't simply use the "-overwrite" option in "foamyHexMesh", simply because this tutorial is in "mesh/foamyHexMesh", which is dedicated mostly the demonstrating examples on how to use the meshers and related utilities in OpenFOAM.
    And as indicated in the "Additional Information" section below, this doesn't fix the simulation itself, therefore this ends up not being worth much at this moment.

 9. The script "Allrun" in "multiphase/interFoam/les/nozzleFlow2D" now uses the "-overwrite" option in "refineMesh", to avoid doing the hack'ish way of copying the files from the latest time folder into the constant one.

Steps To ReproduceInstructions on how to use the provided contribution:
 1. Unpack the attached file "sprucingRunFunctionsAndCollapseEdges_v2.tar.gz" inside the folder "OpenFOAM-dev".

 2. The file "tutorials/porousSimpleFoam/straightDuctImplicit/system/collapseDict" should be removed, to avoid accidental use of that dictionary file, which isn't used by "foamyHexMesh" in this specific tutorial case.
Additional InformationThe "Allrun*" scripts for the following cases within the "tutorials" directory, were the ones modified with the attached package:


These cases were tested with the "Alltest" script and compared the results (logs and files) achieved with a custom build (that has the attached contributions) versus a clean build, both using 64-bit labels and Double Precision floating point.

Everything seems to have worked properly, although:

  - the case "incompressible/porousSimpleFoam/straightDuctImplicit" did not give identical meshes. This seems to be because "foamyHexMesh" is currently not designed to create identical meshes between each run.

  - the case "mesh/foamyHexMesh/mixerVessel" crashes in a different place from the original OpenFOAM-dev case snapshot; this particular case is a rather computationally expensive meshing case, which I'll try to address in another bug report, if and when the need arises.

I wanted to have provided this contribution last week, but I ended up not having enough time to test everything back then. But today, hopefully, I didn't miss anything and everything works as intended.
TagsNo tags attached.



2016-03-05 17:40



2016-03-06 19:09

manager   ~0005998

Thanks for the effort you put into this Bruno, any improvement to the tutorial scripts to aid usability and maintainability is greatly appreciated.
Resolved by commit 499c221df4a5733d61cc2f4369a72939bcfd8ed7


2016-03-06 19:54

updater   ~0006002

Sorry, I missed (at least) one tiny detail: The file "src/dynamicMesh/polyMeshFilter/polyMeshFilter.H" that I provided reverted the new convention for the hashes in pre-preprocessor macros.
Attached is the updated file to meet the new convention.


2016-03-06 19:54


polyMeshFilter.H (8,325 bytes)   
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2012-2016 OpenFOAM Foundation
     \\/     M anipulation  |
    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 <>.


    Remove the edges and faces of a polyMesh whilst satisfying the given mesh
    quality criteria.

    Works on a copy of the mesh.



#ifndef polyMeshFilter_H
#define polyMeshFilter_H

#include "IOdictionary.H"
#include "Time.H"
#include "List.H"
#include "autoPtr.H"
#include "scalarField.H"
#include "polyMeshFilterSettings.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam

class polyMesh;
class fvMesh;
class PackedBoolList;
class faceSet;

                       Class polyMeshFilter Declaration

class polyMeshFilter
    private polyMeshFilterSettings
    // Private data

        //- Reference to the original mesh
        const fvMesh& mesh_;

        //- Copy of the original mesh to perform the filtering on
        autoPtr<fvMesh> newMeshPtr_;

        //- Original point priorities. If a point has a higher priority than
        //  another point then the edge between them collapses towards the
        //  point with the higher priority. (e.g. 2 is a higher priority than 1)
        labelList originalPointPriority_;

        //- Point priority associated with the new mesh
        autoPtr<labelList> pointPriority_;

        //- The minimum edge length for each edge
        scalarField minEdgeLen_;

        //- The face filter factor for each face
        scalarField faceFilterFactor_;

    // Private Member Functions

        template<typename T>
        static void updateSets(const mapPolyMesh& map);

        template<typename T>
        static void copySets(const polyMesh& oldMesh, const polyMesh& newMesh);

        label filterFacesLoop(const label nOriginalBadFaces);

        label filterFaces
            polyMesh& newMesh,
            scalarField& newMeshFaceFilterFactor,
            labelList& origToCurrentPointMap

        label filterEdges
            polyMesh& newMesh,
            scalarField& newMeshMinEdgeLen,
            labelList& origToCurrentPointMap

        //- Increment pointErrorCount for points attached to a bad face
        void updatePointErrorCount
            const PackedBoolList& isErrorPoint,
            const labelList& oldToNewMesh,
            labelList& pointErrorCount
        ) const;

        //- Given the new points that are part of bad faces, and a map from the
        //  old mesh points to the new mesh points, relax minEdgeLen_
        void checkMeshEdgesAndRelaxEdges
            const polyMesh& newMesh,
            const labelList& oldToNewMesh,
            const PackedBoolList& isErrorPoint,
            const labelList& pointErrorCount

        //- Given the new points that are part of bad faces, and a map from the
        //  old mesh points to the new mesh points, relax faceFilterFactor_
        void checkMeshFacesAndRelaxEdges
            const polyMesh& newMesh,
            const labelList& oldToNewMesh,
            const PackedBoolList& isErrorPoint,
            const labelList& pointErrorCount

        // Mark boundary points
        // boundaryPoint:
        // + -1 : point not on boundary
        // +  0 : point on a real boundary
        // + >0 : point on a processor patch with that ID
        // @todo Need to mark boundaryEdges as well, as an edge may have two
        //       boundary points but not itself lie on a boundary
        void updatePointPriorities
            const polyMesh& newMesh,
            const labelList& pointMap

        //- Print min/mean/max data for a field
        void printScalarFieldStats
            const string desc,
            const scalarField& fld
        ) const;

        //- Update minEdgeLen_ for the new mesh based upon the movement of the
        //  old points to the new points
        void mapOldMeshEdgeFieldToNewMesh
            const polyMesh& newMesh,
            const labelList& pointMap,
            scalarField& newMeshMinEdgeLen
        ) const;

        //- Update faceFilterFactor_ for the new mesh based upon the movement
        //  of the old faces to the new faces
        void mapOldMeshFaceFieldToNewMesh
            const polyMesh& newMesh,
            const labelList& faceMap,
            scalarField& newMeshFaceFilterFactor
        ) const;

        //- Maintain a map of the original mesh points to the latest version of
        //  the filtered mesh.
        void updateOldToNewPointMap
            const labelList& currToNew,
            labelList& origToCurrentPointMap
        ) const;

        //- Disallow default bitwise copy construct
        polyMeshFilter(const polyMeshFilter&);

        //- Disallow default bitwise assignment
        void operator=(const polyMeshFilter&);


    //- Runtime type information

    // Constructors

        //- Construct from fvMesh
        explicit polyMeshFilter(const fvMesh& mesh);

        //- Construct from fvMesh and a label list of point priorities
        polyMeshFilter(const fvMesh& mesh, const labelList& pointPriority);

        //- Construct from fvMesh and a label list of point priorities
            const fvMesh& mesh,
            const labelList& pointPriority,
            const dictionary& dict

    //- Destructor

    // Member Functions

        // Access

            //- Return reference to the filtered mesh. Does not check if the
            //  mesh has actually been filtered.
            const autoPtr<fvMesh>& filteredMesh() const;

            //- Return the new pointPriority list.
            const autoPtr<labelList>& pointPriority() const;

        // Edit

            //- Return a copy of an fvMesh
            static autoPtr<fvMesh> copyMesh(const fvMesh& mesh);

            //- Copy loaded topoSets from the old mesh to the new mesh
            static void copySets
                const polyMesh& oldMesh,
                const polyMesh& newMesh

            //- Update the loaded topoSets
            static void updateSets(const mapPolyMesh& map);

            //- Filter edges and faces
            label filter(const label nOriginalBadFaces);

            //- Filter all faces that are in the face set
            label filter(const faceSet& fSet);

            //- Filter edges only.
            label filterEdges(const label nOriginalBadFaces);

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#ifdef NoRepository
    #include "polyMeshFilterTemplates.C"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


// ************************************************************************* //
polyMeshFilter.H (8,325 bytes)   


2016-03-06 21:37

manager   ~0006004

Resolved by commit eae4c1289dace30c60690152f76ae73e5ee64095

Issue History

Date Modified Username Field Change
2016-03-05 17:40 wyldckat New Issue
2016-03-05 17:40 wyldckat Status new => assigned
2016-03-05 17:40 wyldckat Assigned To => henry
2016-03-05 17:40 wyldckat File Added: sprucingRunFunctionsAndCollapseEdges_v2.tar.gz
2016-03-05 20:19 wyldckat Reproducibility have not tried => N/A
2016-03-06 19:09 henry Note Added: 0005998
2016-03-06 19:09 henry Status assigned => resolved
2016-03-06 19:09 henry Resolution open => fixed
2016-03-06 19:54 wyldckat Note Added: 0006002
2016-03-06 19:54 wyldckat Status resolved => feedback
2016-03-06 19:54 wyldckat Resolution fixed => reopened
2016-03-06 19:54 wyldckat File Added: polyMeshFilter.H
2016-03-06 21:37 henry Note Added: 0006004
2016-03-06 21:37 henry Status feedback => resolved
2016-03-06 21:37 henry Resolution reopened => fixed