From 4a0729523877bbe606648900bd71b5bf8b19c904 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Mon, 2 Apr 2012 10:52:42 +0100
Subject: [PATCH] ENH: cvMeshBackgroundMesh: new application to get a
 background mesh

---
 .../mesh/generation/cvMesh/Allwclean          |   2 +
 .../utilities/mesh/generation/cvMesh/Allwmake |   1 +
 .../backgroundMeshDecomposition.C             | 107 +++++++++++++++---
 .../backgroundMeshDecomposition.H             |  47 +++++++-
 .../backgroundMeshDecompositionI.H            |  25 +++-
 5 files changed, 157 insertions(+), 25 deletions(-)

diff --git a/applications/utilities/mesh/generation/cvMesh/Allwclean b/applications/utilities/mesh/generation/cvMesh/Allwclean
index 6dd3690c256..3eff84006aa 100755
--- a/applications/utilities/mesh/generation/cvMesh/Allwclean
+++ b/applications/utilities/mesh/generation/cvMesh/Allwclean
@@ -4,5 +4,7 @@ set -x
 
 wclean libso conformalVoronoiMesh
 wclean
+wclean cvMeshSurfaceSimplify
+wclean cvMeshBackgroundMesh
 
 # ----------------------------------------------------------------- end-of-file
diff --git a/applications/utilities/mesh/generation/cvMesh/Allwmake b/applications/utilities/mesh/generation/cvMesh/Allwmake
index f059754bab6..2a998cb690a 100755
--- a/applications/utilities/mesh/generation/cvMesh/Allwmake
+++ b/applications/utilities/mesh/generation/cvMesh/Allwmake
@@ -5,5 +5,6 @@ set -x
 wmake libso conformalVoronoiMesh
 wmake
 wmake cvMeshSurfaceSimplify
+wmake cvMeshBackgroundMesh
 
 # ----------------------------------------------------------------- end-of-file
diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C
index 395b6c78b2d..cf7a1eb9021 100644
--- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C
+++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -142,7 +142,7 @@ void Foam::backgroundMeshDecomposition::initialRefinement()
         zeroGradientFvPatchScalarField::typeName
     );
 
-    const conformationSurfaces& geometry = cvMesh_.geometryToConformTo();
+    const conformationSurfaces& geometry = geometryToConformTo_;
 
     decompositionMethod& decomposer = decomposerPtr_();
 
@@ -512,7 +512,7 @@ bool Foam::backgroundMeshDecomposition::refineCell
     // Sample the box to find an estimate of the min size, and a volume
     // estimate when overlapping == true.
 
-    const conformationSurfaces& geometry = cvMesh_.geometryToConformTo();
+    const conformationSurfaces& geometry = geometryToConformTo_;
 
     treeBoundBox cellBb
     (
@@ -578,7 +578,7 @@ bool Foam::backgroundMeshDecomposition::refineCell
 
         forAll(samplePoints, i)
         {
-            scalar s = cvMesh_.cellSizeControl().cellSize
+            scalar s = cellSizeControl_.cellSize
             (
                 hitInfo[i].hitPoint()
             );
@@ -693,7 +693,7 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree()
     // Overall bb
     treeBoundBox overallBb(boundaryFacesPtr_().localPoints());
 
-    Random& rnd = cvMesh_.rndGen();
+    Random& rnd = rndGen_;
 
     bFTreePtr_.reset
     (
@@ -726,11 +726,11 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree()
 
     octreeNearestDistances_ = bFTreePtr_().calcNearestDistance();
 
-    if (cvMesh_.cvMeshControls().objOutput())
+    if (cvMeshControls_.objOutput())
     {
         OFstream fStr
         (
-            cvMesh_.time().path()
+            mesh_.time().path()
            /"backgroundMeshDecomposition_proc_"
           + name(Pstream::myProcNo())
           + "_boundaryFaces.obj"
@@ -777,15 +777,18 @@ Foam::backgroundMeshDecomposition::backgroundMeshDecomposition
     const conformalVoronoiMesh& cvMesh
 )
 :
-    coeffsDict_(coeffsDict),
-    cvMesh_(cvMesh),
+    runTime_(cvMesh.time()),
+    geometryToConformTo_(cvMesh.geometryToConformTo()),
+    cellSizeControl_(cvMesh.cellSizeControl()),
+    rndGen_(cvMesh.rndGen()),
+    cvMeshControls_(cvMesh.cvMeshControls()),
     mesh_
     (
         IOobject
         (
             fvMesh::defaultRegion,
-            cvMesh_.time().timeName(),
-            cvMesh_.time(),
+            runTime_.timeName(),
+            runTime_,
             IOobject::MUST_READ
         )
     ),
@@ -805,22 +808,22 @@ Foam::backgroundMeshDecomposition::backgroundMeshDecomposition
         IOobject
         (
             "decomposeParDict",
-            cvMesh_.time().system(),
-            cvMesh_.time(),
+            runTime_.system(),
+            runTime_,
             IOobject::MUST_READ_IF_MODIFIED,
             IOobject::NO_WRITE
         )
     ),
     decomposerPtr_(decompositionMethod::New(decomposeDict_)),
     mergeDist_(1e-6*mesh_.bounds().mag()),
-    spanScale_(readScalar(coeffsDict_.lookup("spanScale"))),
+    spanScale_(readScalar(coeffsDict.lookup("spanScale"))),
     minCellSizeLimit_
     (
-        coeffsDict_.lookupOrDefault<scalar>("minCellSizeLimit", 0.0)
+        coeffsDict.lookupOrDefault<scalar>("minCellSizeLimit", 0.0)
     ),
-    minLevels_(readLabel(coeffsDict_.lookup("minLevels"))),
-    volRes_(readLabel(coeffsDict_.lookup("sampleResolution"))),
-    maxCellWeightCoeff_(readScalar(coeffsDict_.lookup("maxCellWeightCoeff")))
+    minLevels_(readLabel(coeffsDict.lookup("minLevels"))),
+    volRes_(readLabel(coeffsDict.lookup("sampleResolution"))),
+    maxCellWeightCoeff_(readScalar(coeffsDict.lookup("maxCellWeightCoeff")))
 {
     if (!Pstream::parRun())
     {
@@ -854,6 +857,74 @@ Foam::backgroundMeshDecomposition::backgroundMeshDecomposition
 }
 
 
+Foam::backgroundMeshDecomposition::backgroundMeshDecomposition
+(
+    const scalar spanScale,
+    const scalar minCellSizeLimit,
+    const label minLevels,
+    const label volRes,
+    const scalar maxCellWeightCoeff,
+
+    const Time& runTime,
+    const conformationSurfaces& geometryToConformTo,
+    const cellSizeControlSurfaces& cellSizeControl,
+    Random& rndGen,
+    const cvControls& cvMeshControls
+)
+:
+    runTime_(runTime),
+    geometryToConformTo_(geometryToConformTo),
+    cellSizeControl_(cellSizeControl),
+    rndGen_(rndGen),
+    cvMeshControls_(cvMeshControls),
+    mesh_
+    (
+        IOobject
+        (
+            fvMesh::defaultRegion,
+            runTime_.timeName(),
+            runTime_,
+            IOobject::MUST_READ
+        )
+    ),
+    meshCutter_
+    (
+        mesh_,
+        labelList(mesh_.nCells(), 0),
+        labelList(mesh_.nPoints(), 0)
+    ),
+    boundaryFacesPtr_(),
+    bFTreePtr_(),
+    octreeNearestDistances_(),
+    allBackgroundMeshBounds_(Pstream::nProcs()),
+    globalBackgroundBounds_(),
+    decomposeDict_
+    (
+        IOobject
+        (
+            "decomposeParDict",
+            runTime_.system(),
+            runTime_,
+            IOobject::MUST_READ_IF_MODIFIED,
+            IOobject::NO_WRITE
+        )
+    ),
+    decomposerPtr_(decompositionMethod::New(decomposeDict_)),
+    mergeDist_(1e-6*mesh_.bounds().mag()),
+    spanScale_(spanScale),
+    minCellSizeLimit_(minCellSizeLimit),
+    minLevels_(minLevels),
+    volRes_(volRes),
+    maxCellWeightCoeff_(maxCellWeightCoeff)
+{
+    // Stand-alone operation
+
+    Info<< nl << "Building initial background mesh decomposition" << endl;
+
+    initialRefinement();
+}
+
+
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
 Foam::backgroundMeshDecomposition::~backgroundMeshDecomposition()
diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.H b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.H
index 01572a48f9a..910732fa7ac 100644
--- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.H
+++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -92,10 +92,22 @@ class backgroundMeshDecomposition
     // Private data
 
         //- Method details dictionary
-        dictionary coeffsDict_;
+        //dictionary coeffsDict_;
 
-        //- Reference to the conformalVoronoiMesh holding this object
-        const conformalVoronoiMesh& cvMesh_;
+        //- Reference to runtime
+        const Time& runTime_;
+
+        //- Reference to surface
+        const conformationSurfaces& geometryToConformTo_;
+
+        //- The cell size control object
+        const cellSizeControlSurfaces& cellSizeControl_;
+
+        //- Random number generator
+        Random& rndGen_;
+
+        //- Controls
+        const cvControls& cvMeshControls_;
 
         //- Mesh stored on for this processor, specifiying the domain that it
         //  is responsible for.
@@ -191,13 +203,29 @@ public:
 
     // Constructors
 
-        //- Construct from components
+        //- Construct from components in cvMesh operation
         backgroundMeshDecomposition
         (
             const dictionary& coeffsDict,
             const conformalVoronoiMesh& cvMesh
         );
 
+        //- Construct from components for standalone operation
+        backgroundMeshDecomposition
+        (
+            const scalar spanScale,
+            const scalar minCellSizeLimit,
+            const label minLevels,
+            const label volRes,
+            const scalar maxCellWeightCoeff,
+
+            const Time& runTime,
+            const conformationSurfaces& geometryToConformTo,
+            const cellSizeControlSurfaces& cellSizeControl,
+            Random& rndGen,
+            const cvControls& cvMeshControls
+        );
+
 
     //- Destructor
     ~backgroundMeshDecomposition();
@@ -299,6 +327,15 @@ public:
 
             //- Return the boundBox of this processor
             inline const treeBoundBox& procBounds() const;
+
+            //- Return the cell level of the underlying mesh
+            inline const labelList& cellLevel() const;
+
+            //- Return the point level of the underlying mesh
+            inline const labelList& pointLevel() const;
+
+            //- Return the current decomposition method
+            inline const decompositionMethod& decomposer() const;
 };
 
 
diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecompositionI.H b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecompositionI.H
index 94a05c4134a..44a007193d8 100644
--- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecompositionI.H
+++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecompositionI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -43,9 +43,30 @@ Foam::backgroundMeshDecomposition::octreeNearestDistances() const
 }
 
 
-const Foam::treeBoundBox& Foam::backgroundMeshDecomposition::procBounds() const
+const Foam::treeBoundBox&
+Foam::backgroundMeshDecomposition::procBounds() const
 {
     return allBackgroundMeshBounds_[Pstream::myProcNo()];
 }
 
+
+const Foam::labelList& Foam::backgroundMeshDecomposition::cellLevel() const
+{
+    return meshCutter_.cellLevel();
+}
+
+
+const Foam::labelList& Foam::backgroundMeshDecomposition::pointLevel() const
+{
+    return meshCutter_.pointLevel();
+}
+
+
+const Foam::decompositionMethod&
+Foam::backgroundMeshDecomposition::decomposer() const
+{
+    return decomposerPtr_();
+}
+
+
 // ************************************************************************* //
-- 
GitLab