From 7ee82c56a1503c07cf6d282500c222e7b7e7e1fd Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Tue, 8 Apr 2014 11:54:49 +0100
Subject: [PATCH] ENH: solidBodMotionFvMesh - add support for specifying cells
 by cellSet

---
 .../solidBodyMotionFvMesh.C                   | 58 ++++++++++++++-----
 .../solidBodyMotionFvMesh.H                   |  8 +--
 2 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFvMesh.C b/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFvMesh.C
index 44a1a2c4f24..184cbe60875 100644
--- a/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFvMesh.C
+++ b/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFvMesh.C
@@ -28,6 +28,7 @@ License
 #include "volFields.H"
 #include "transformField.H"
 #include "cellZoneMesh.H"
+#include "cellSet.H"
 #include "boolList.H"
 #include "syncTools.H"
 
@@ -74,8 +75,8 @@ Foam::solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject& io)
             false
         )
     ),
-    zoneID_(-1),
-    pointIDs_()
+    pointIDs_(),
+    UName_(dynamicMeshCoeffs_.lookupOrDefault<word>("UName", "U"))
 {
     if (undisplacedPoints_.size() != nPoints())
     {
@@ -92,14 +93,31 @@ Foam::solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject& io)
     word cellZoneName =
         dynamicMeshCoeffs_.lookupOrDefault<word>("cellZone", "none");
 
+    word cellSetName =
+        dynamicMeshCoeffs_.lookupOrDefault<word>("cellSet", "none");
+
+    if ((cellZoneName != "none") && (cellSetName != "none"))
+    {
+        FatalIOErrorIn
+        (
+            "solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject&)",
+            dynamicMeshCoeffs_
+        )
+            << "Either cellZone OR cellSet can be supplied, but not both. "
+            << "If neither is supplied, all cells will be included"
+            << exit(FatalIOError);
+    }
+
+
+    labelList cellIDs;
     if (cellZoneName != "none")
     {
         Info<< "Applying solid body motion to cellZone " << cellZoneName
             << endl;
 
-        zoneID_ = cellZones().findZoneID(cellZoneName);
+        label zoneID = cellZones().findZoneID(cellZoneName);
 
-        if (zoneID_ == -1)
+        if (zoneID == -1)
         {
             FatalErrorIn
             (
@@ -111,16 +129,28 @@ Foam::solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject& io)
                 << exit(FatalError);
         }
 
-        const cellZone& cz = cellZones()[zoneID_];
+        cellIDs = cellZones()[zoneID];
+    }
+
+    if (cellSetName != "none")
+    {
+        Info<< "Applying solid body motion to cellSet " << cellSetName
+            << endl;
+
+        cellSet set(*this, cellSetName);
 
+        cellIDs = set.toc();
+    }
 
+    if (cellIDs.size())
+    {
         // collect point IDs of points in cell zone
 
         boolList movePts(nPoints(), false);
 
-        forAll(cz, i)
+        forAll(cellIDs, i)
         {
-            label cellI = cz[i];
+            label cellI = cellIDs[i];
             const cell& c = cells()[cellI];
             forAll(c, j)
             {
@@ -165,7 +195,7 @@ bool Foam::solidBodyMotionFvMesh::update()
 {
     static bool hasWarned = false;
 
-    if (zoneID_ != -1)
+    if (pointIDs_.size())
     {
         pointField transformedPts(undisplacedPoints_);
 
@@ -191,18 +221,20 @@ bool Foam::solidBodyMotionFvMesh::update()
     }
 
 
-    if (foundObject<volVectorField>("U"))
+    if (foundObject<volVectorField>(UName_))
     {
-        const_cast<volVectorField&>(lookupObject<volVectorField>("U"))
-            .correctBoundaryConditions();
+        const volVectorField& U = lookupObject<volVectorField>(UName_);
+
+        const_cast<volVectorField&>(U).correctBoundaryConditions();
     }
     else if (!hasWarned)
     {
         hasWarned = true;
 
         WarningIn("solidBodyMotionFvMesh::update()")
-            << "Did not find volVectorField U."
-            << " Not updating U boundary conditions." << endl;
+            << "Did not find volVectorField " << UName_
+            << " Not updating " << UName_ << "boundary conditions."
+            << endl;
     }
 
     return true;
diff --git a/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFvMesh.H b/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFvMesh.H
index f6b9725fa05..3f691381fb3 100644
--- a/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFvMesh.H
+++ b/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFvMesh.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2014 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -65,12 +65,12 @@ class solidBodyMotionFvMesh
         //- The reference points which are transformed
         pointIOField undisplacedPoints_;
 
-        //- Specified cellZone or -1 for whole-body
-        label zoneID_;
-
         //- Points to move when cell zone is supplied
         labelList pointIDs_;
 
+        //- Name of velocity field
+        word UName_;
+
 
     // Private Member Functions
 
-- 
GitLab