From dee88bceddb8c23f28b122d9326e0dbe1d8052ea Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Wed, 12 Jun 2013 10:33:36 +0100
Subject: [PATCH] BUG: displacementLayeredMotionSolver: too early evaluation of
 boundary conditions

---
 .../displacementInterpolationMotionSolver.H   |   5 +-
 .../displacementLayeredMotionMotionSolver.C   | 104 +++++++++---------
 .../displacementLayeredMotionMotionSolver.H   |  10 +-
 3 files changed, 57 insertions(+), 62 deletions(-)

diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationMotionSolver.H
index ec49b1e2231..b5da0b5b3b5 100644
--- a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationMotionSolver.H
+++ b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationMotionSolver.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -36,9 +36,6 @@ Description
 
     Tables are in the \a constant/tables directory.
 
-Note
-    could be a motionSolver - does not use any fvMesh structure.
-
 SourceFiles
     displacementInterpolationMotionSolver.C
 
diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.C
index f491ee586d7..ace954062bd 100644
--- a/src/fvMotionSolver/fvMotionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.C
+++ b/src/fvMotionSolver/fvMotionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -253,6 +253,16 @@ Foam::displacementLayeredMotionMotionSolver::faceZoneEvaluate
         // Only on boundary faces - follow boundary conditions
         fld = vectorField(pointDisplacement_, meshPoints);
     }
+    else if (type == "uniformFollow")
+    {
+        // Reads name of name of patch. Then get average point dislacement on
+        // patch. That becomes the value of fld.
+        const word patchName(dict.lookup("patch"));
+        label patchID = mesh().boundaryMesh().findPatchID(patchName);
+        pointField pdf =
+            pointDisplacement_.boundaryField()[patchID].patchInternalField();
+        fld = gAverage(pdf);
+    }
     else
     {
         FatalIOErrorIn
@@ -399,22 +409,6 @@ Info<< "For cellZone:" << cellZoneI
         // Implement real bc.
         patchDisp[patchI].correctBoundaryConditions();
 
-
-//Info<< "Writing displacement for faceZone " << fz.name()
-//    << " to " << patchDisp[patchI].name() << endl;
-//patchDisp[patchI].write();
-
-//        // Copy into pointDisplacement for other fields to use
-//        forAll(isZonePoint, pointI)
-//        {
-//            if (isZonePoint[pointI])
-//            {
-//                pointDisplacement_[pointI] = patchDisp[patchI][pointI];
-//            }
-//        }
-//        pointDisplacement_.correctBoundaryConditions();
-
-
         patchI++;
     }
 
@@ -423,37 +417,40 @@ Info<< "For cellZone:" << cellZoneI
     // ~~~~~
     // solving the interior is just interpolating
 
-//    // Get normalised distance
-//    pointScalarField distance
-//    (
-//        IOobject
-//        (
-//            "distance",
-//            mesh().time().timeName(),
-//            mesh(),
-//            IOobject::NO_READ,
-//            IOobject::NO_WRITE,
-//            false
-//        ),
-//        pointMesh::New(mesh()),
-//        dimensionedScalar("distance", dimLength, 0.0)
-//    );
-//    forAll(distance, pointI)
-//    {
-//        if (isZonePoint[pointI])
-//        {
-//            scalar d1 = patchDist[0][pointI];
-//            scalar d2 = patchDist[1][pointI];
-//            if (d1+d2 > SMALL)
-//            {
-//                scalar s = d1/(d1+d2);
-//                distance[pointI] = s;
-//            }
-//        }
-//    }
-//    Info<< "Writing distance pointScalarField to " << mesh().time().timeName()
-//        << endl;
-//    distance.write();
+    if (debug)
+    {
+        // Get normalised distance
+        pointScalarField distance
+        (
+            IOobject
+            (
+                "distance",
+                mesh().time().timeName(),
+                mesh(),
+                IOobject::NO_READ,
+                IOobject::NO_WRITE,
+                false
+            ),
+            pointMesh::New(mesh()),
+            dimensionedScalar("distance", dimLength, 0.0)
+        );
+        forAll(distance, pointI)
+        {
+            if (isZonePoint[pointI])
+            {
+                scalar d1 = patchDist[0][pointI];
+                scalar d2 = patchDist[1][pointI];
+                if (d1+d2 > SMALL)
+                {
+                    scalar s = d1/(d1+d2);
+                    distance[pointI] = s;
+                }
+            }
+        }
+        Info<< "Writing distance pointScalarField to "
+            << mesh().time().timeName() << endl;
+        distance.write();
+    }
 
     // Average
     forAll(pointDisplacement_, pointI)
@@ -470,7 +467,6 @@ Info<< "For cellZone:" << cellZoneI
               + s*patchDisp[1][pointI];
         }
     }
-    pointDisplacement_.correctBoundaryConditions();
 }
 
 
@@ -484,9 +480,7 @@ displacementLayeredMotionMotionSolver
 )
 :
     displacementMotionSolver(mesh, dict, typeName)
-{
-    pointDisplacement_.correctBoundaryConditions();
-}
+{}
 
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
@@ -518,6 +512,9 @@ void Foam::displacementLayeredMotionMotionSolver::solve()
     // the motionSolver accordingly
     movePoints(mesh().points());
 
+    // Apply boundary conditions
+    pointDisplacement_.boundaryField().updateCoeffs();
+
     // Apply all regions (=cellZones)
 
     const dictionary& regionDicts = coeffDict().subDict("regions");
@@ -544,6 +541,9 @@ void Foam::displacementLayeredMotionMotionSolver::solve()
 
         cellZoneSolve(zoneI, regionDict);
     }
+
+    // Update pointDisplacement for solved values
+    pointDisplacement_.correctBoundaryConditions();
 }
 
 
diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.H
index 0f29c4f88fd..1aa7884f52b 100644
--- a/src/fvMotionSolver/fvMotionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.H
+++ b/src/fvMotionSolver/fvMotionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -28,11 +28,6 @@ Description
     Mesh motion solver for an (multi-block) extruded fvMesh. Gets given the
     structure of the mesh blocks and boundary conditions on these blocks.
 
-    Note: should not be an fvMotionSolver but just a motionSolver. Only here
-    so we can reuse displacementFvMotionSolver functionality (e.g. surface
-    following boundary conditions)
-
-
     The displacementLayeredMotionCoeffs subdict of dynamicMeshDict specifies
     per region (=cellZone) the boundary conditions on two opposing patches
     (=faceZones). It then interpolates the boundary values using topological
@@ -44,6 +39,9 @@ Description
             Use this for faceZones on boundary faces (so it uses the
             proper boundary conditions on the pointDisplacement).
 
+    uniformFollow: like 'follow' but takes the average value of
+            a specified 'patch' (which is not necessarily colocated)
+
     fixedValue: fixed value.
 
     timeVaryingUniformFixedValue: table-driven fixed value.
-- 
GitLab