From 9ffa7df9930735de08fe931465a2e1d91f8e4689 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Tue, 18 Dec 2012 14:56:24 +0000
Subject: [PATCH] ENH: badQuality: cell/faceSources for motionSmoother checks

---
 src/dynamicMesh/Make/files                    |   2 +
 .../badQualityToCell/badQualityToCell.C       | 127 ++++++++++++++++++
 .../badQualityToCell/badQualityToCell.H       | 119 ++++++++++++++++
 .../badQualityToFace/badQualityToFace.C       | 123 +++++++++++++++++
 .../badQualityToFace/badQualityToFace.H       | 119 ++++++++++++++++
 5 files changed, 490 insertions(+)
 create mode 100644 src/dynamicMesh/motionSmoother/badQualityToCell/badQualityToCell.C
 create mode 100644 src/dynamicMesh/motionSmoother/badQualityToCell/badQualityToCell.H
 create mode 100644 src/dynamicMesh/motionSmoother/badQualityToFace/badQualityToFace.C
 create mode 100644 src/dynamicMesh/motionSmoother/badQualityToFace/badQualityToFace.H

diff --git a/src/dynamicMesh/Make/files b/src/dynamicMesh/Make/files
index a3e8de68925..4bc6aa0c529 100644
--- a/src/dynamicMesh/Make/files
+++ b/src/dynamicMesh/Make/files
@@ -87,6 +87,8 @@ fvMeshTools/fvMeshTools.C
 motionSmoother/motionSmoother.C
 motionSmoother/motionSmootherCheck.C
 motionSmoother/polyMeshGeometry/polyMeshGeometry.C
+motionSmoother/badQualityToCell/badQualityToCell.C
+motionSmoother/badQualityToFace/badQualityToFace.C
 
 motionSolver/motionSolver/motionSolver.C
 motionSolver/displacement/displacementMotionSolver.C
diff --git a/src/dynamicMesh/motionSmoother/badQualityToCell/badQualityToCell.C b/src/dynamicMesh/motionSmoother/badQualityToCell/badQualityToCell.C
new file mode 100644
index 00000000000..80f15127aff
--- /dev/null
+++ b/src/dynamicMesh/motionSmoother/badQualityToCell/badQualityToCell.C
@@ -0,0 +1,127 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
+     \\/     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 "badQualityToCell.H"
+#include "polyMesh.H"
+#include "motionSmoother.H"
+#include "addToRunTimeSelectionTable.H"
+#include "faceSet.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+defineTypeNameAndDebug(badQualityToCell, 0);
+
+addToRunTimeSelectionTable(topoSetSource, badQualityToCell, word);
+
+addToRunTimeSelectionTable(topoSetSource, badQualityToCell, istream);
+
+}
+
+
+Foam::topoSetSource::addToUsageTable Foam::badQualityToCell::usage_
+(
+    badQualityToCell::typeName,
+    "\n    Usage: badQualityToCell mesh-quality-dictionary\n\n"
+    "    Select all cells that do not satisfy the selection criterion\n\n"
+);
+
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::badQualityToCell::combine(topoSet& set, const bool add) const
+{
+    faceSet faces(mesh_, "meshQualityFaces", mesh_.nFaces()/100+1);
+    motionSmoother::checkMesh(false, mesh_, dict_, faces);
+    faces.sync(mesh_);
+
+    forAllConstIter(faceSet, faces, iter)
+    {
+        label faceI = iter.key();
+        addOrDelete(set, mesh_.faceOwner()[faceI], add);
+        if (mesh_.isInternalFace(faceI))
+        {
+            addOrDelete(set, mesh_.faceNeighbour()[faceI], add);
+        }
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+// Construct from dictionary
+Foam::badQualityToCell::badQualityToCell
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetSource(mesh),
+    dict_(dict)
+{}
+
+
+// Construct from Istream
+Foam::badQualityToCell::badQualityToCell
+(
+    const polyMesh& mesh,
+    Istream& is
+)
+:
+    topoSetSource(mesh),
+    dict_(is)
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::badQualityToCell::~badQualityToCell()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::badQualityToCell::applyToSet
+(
+    const topoSetSource::setAction action,
+    topoSet& set
+) const
+{
+    if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
+    {
+        Info<< "    Adding bad-quality cells" << endl;
+        combine(set, true);
+    }
+    else if (action == topoSetSource::DELETE)
+    {
+        Info<< "    Removing bad-quality cells" << endl;
+        combine(set, false);
+    }
+}
+
+
+// ************************************************************************* //
diff --git a/src/dynamicMesh/motionSmoother/badQualityToCell/badQualityToCell.H b/src/dynamicMesh/motionSmoother/badQualityToCell/badQualityToCell.H
new file mode 100644
index 00000000000..4b52b0ff170
--- /dev/null
+++ b/src/dynamicMesh/motionSmoother/badQualityToCell/badQualityToCell.H
@@ -0,0 +1,119 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
+     \\/     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::badQualityToCell
+
+Description
+    Selects bad quality cells (using snappyHexMesh/cvMesh mesh quality selector)
+
+SourceFiles
+    badQualityToCell.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef badQualityToCell_H
+#define badQualityToCell_H
+
+#include "topoSetSource.H"
+#include "PackedBoolList.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                         Class badQualityToCell Declaration
+\*---------------------------------------------------------------------------*/
+
+class badQualityToCell
+:
+    public topoSetSource
+{
+
+    // Private data
+
+        //- Add usage string
+        static addToUsageTable usage_;
+
+        //- Mesh quality dictionary
+        const dictionary dict_;
+
+
+    // Private Member Functions
+
+        void combine(topoSet& set, const bool add) const;
+
+
+public:
+
+    //- Runtime type information
+    TypeName("badQualityToCell");
+
+    // Constructors
+
+        //- Construct from dictionary
+        badQualityToCell
+        (
+            const polyMesh& mesh,
+            const dictionary& dict
+        );
+
+        //- Construct from Istream
+        badQualityToCell
+        (
+            const polyMesh& mesh,
+            Istream&
+        );
+
+
+    //- Destructor
+    virtual ~badQualityToCell();
+
+
+    // Member Functions
+
+        virtual sourceType setType() const
+        {
+            return CELLSETSOURCE;
+        }
+
+        virtual void applyToSet
+        (
+            const topoSetSource::setAction action,
+            topoSet&
+        ) const;
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/dynamicMesh/motionSmoother/badQualityToFace/badQualityToFace.C b/src/dynamicMesh/motionSmoother/badQualityToFace/badQualityToFace.C
new file mode 100644
index 00000000000..a692c61569e
--- /dev/null
+++ b/src/dynamicMesh/motionSmoother/badQualityToFace/badQualityToFace.C
@@ -0,0 +1,123 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
+     \\/     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 "badQualityToFace.H"
+#include "polyMesh.H"
+#include "motionSmoother.H"
+#include "addToRunTimeSelectionTable.H"
+#include "faceSet.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+defineTypeNameAndDebug(badQualityToFace, 0);
+
+addToRunTimeSelectionTable(topoSetSource, badQualityToFace, word);
+
+addToRunTimeSelectionTable(topoSetSource, badQualityToFace, istream);
+
+}
+
+
+Foam::topoSetSource::addToUsageTable Foam::badQualityToFace::usage_
+(
+    badQualityToFace::typeName,
+    "\n    Usage: badQualityToFace mesh-quality-dictionary\n\n"
+    "    Select all faces that do not satisfy the selection criterion\n\n"
+);
+
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::badQualityToFace::combine(topoSet& set, const bool add) const
+{
+    faceSet faces(mesh_, "meshQualityFaces", mesh_.nFaces()/100+1);
+    motionSmoother::checkMesh(false, mesh_, dict_, faces);
+    faces.sync(mesh_);
+
+    forAllConstIter(faceSet, faces, iter)
+    {
+        label faceI = iter.key();
+        addOrDelete(set, faceI, add);
+    }
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+// Construct from dictionary
+Foam::badQualityToFace::badQualityToFace
+(
+    const polyMesh& mesh,
+    const dictionary& dict
+)
+:
+    topoSetSource(mesh),
+    dict_(dict)
+{}
+
+
+// Construct from Istream
+Foam::badQualityToFace::badQualityToFace
+(
+    const polyMesh& mesh,
+    Istream& is
+)
+:
+    topoSetSource(mesh),
+    dict_(is)
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::badQualityToFace::~badQualityToFace()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::badQualityToFace::applyToSet
+(
+    const topoSetSource::setAction action,
+    topoSet& set
+) const
+{
+    if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
+    {
+        Info<< "    Adding bad-quality faces" << endl;
+        combine(set, true);
+    }
+    else if (action == topoSetSource::DELETE)
+    {
+        Info<< "    Removing bad-quality faces" << endl;
+        combine(set, false);
+    }
+}
+
+
+// ************************************************************************* //
diff --git a/src/dynamicMesh/motionSmoother/badQualityToFace/badQualityToFace.H b/src/dynamicMesh/motionSmoother/badQualityToFace/badQualityToFace.H
new file mode 100644
index 00000000000..d59964bad82
--- /dev/null
+++ b/src/dynamicMesh/motionSmoother/badQualityToFace/badQualityToFace.H
@@ -0,0 +1,119 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
+     \\/     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::badQualityToFace
+
+Description
+    Selects bad quality faces (using snappyHexMesh/cvMesh mesh quality selector)
+
+SourceFiles
+    badQualityToFace.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef badQualityToFace_H
+#define badQualityToFace_H
+
+#include "topoSetSource.H"
+#include "PackedBoolList.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                         Class badQualityToFace Declaration
+\*---------------------------------------------------------------------------*/
+
+class badQualityToFace
+:
+    public topoSetSource
+{
+
+    // Private data
+
+        //- Add usage string
+        static addToUsageTable usage_;
+
+        //- Mesh quality dictionary
+        const dictionary dict_;
+
+
+    // Private Member Functions
+
+        void combine(topoSet& set, const bool add) const;
+
+
+public:
+
+    //- Runtime type information
+    TypeName("badQualityToFace");
+
+    // Constructors
+
+        //- Construct from dictionary
+        badQualityToFace
+        (
+            const polyMesh& mesh,
+            const dictionary& dict
+        );
+
+        //- Construct from Istream
+        badQualityToFace
+        (
+            const polyMesh& mesh,
+            Istream&
+        );
+
+
+    //- Destructor
+    virtual ~badQualityToFace();
+
+
+    // Member Functions
+
+        virtual sourceType setType() const
+        {
+            return CELLSETSOURCE;
+        }
+
+        virtual void applyToSet
+        (
+            const topoSetSource::setAction action,
+            topoSet&
+        ) const;
+
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
-- 
GitLab