Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / layerSmooth / layerSmooth.C
blobdc444b396845614e35790e7234bd1ec890eece19
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "layerSmooth.H"
27 #include "layerAdditionRemoval.H"
28 #include "attachDetach.H"
29 #include "componentMixedTetPolyPatchVectorField.H"
30 #include "mapPolyMesh.H"
31 #include "polyTopoChange.H"
32 #include "addToRunTimeSelectionTable.H"
33 #include "GeometricField.H"
34 #include "volMesh.H"
35 #include "engineTime.H"
36 #include "pointField.H"
37 #include "fvPatchField.H"
38 #include "Switch.H"
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 defineTypeNameAndDebug(Foam::layerSmooth, 0);
44 addToRunTimeSelectionTable
46     Foam::engineTopoChangerMesh,
47     Foam::layerSmooth,
48     IOobject
52 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
54 bool Foam::layerSmooth::realDeformation() const
57     if
58     (
59         virtualPistonPosition() + engTime().pistonDisplacement().value()
60       > deckHeight_ - SMALL
61     )
62     {
63         return true;
64     }
65     else
66     {
67         return deformation();
68     }
72 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
74 // Construct from components
75 Foam::layerSmooth::layerSmooth
77     const IOobject& io
80     engineTopoChangerMesh(io),
81     piston_(*this, engTime().engineDict().subDict("piston")),
82     valves_(*this, engTime().engineDict().lookup("layerSmooth")),
83     deformSwitch_(readScalar(engTime().engineDict().lookup("deformAngle"))),
84     delta_(readScalar(engTime().engineDict().lookup("delta"))),
85     offSet_(readScalar(engTime().engineDict().lookup("offSet"))),
86     pistonPosition_(-GREAT),
87     virtualPistonPosition_(-GREAT),
88     deckHeight_(GREAT),
89     msPtr_(motionSolver::New(*this)),
90     valvePlaneTol_(readScalar(engTime().engineDict().lookup("valvePlaneTol")))
94     forAll(valves(), valveI)
95     {
96         if
97         (
98             valves()[valveI].stemPatchID().active()
99          && valves()[valveI].bottomPatchID().active()
100         )
101         {
102             label bottomIndex = valves()[valveI].bottomPatchID().index();
103             label stemIndex = valves()[valveI].stemPatchID().index();
105             const polyPatch& stemPatch =
106                     boundaryMesh()[stemIndex];
108             const polyPatch& bottomPatch =
109                     boundaryMesh()[bottomIndex];
111             point bottomPatchCentre = vector::zero;
112             point stemPatchCentre = vector::zero;
114             scalar bottomArea = 0;
115             scalar stemArea = 0;
117             Switch halfGeometry(engTime().engineDict().lookup("halfGeometry"));
119             forAll(stemPatch, i)
120             {
121                 stemPatchCentre +=
122                     stemPatch.faceCentres()[i]*mag(stemPatch.faceAreas()[i]);
124                 stemArea += mag(stemPatch.faceAreas()[i]);
125             }
127             forAll(bottomPatch, i)
128             {
129                 bottomPatchCentre +=bottomPatch.faceCentres()[i]*
130                     mag(bottomPatch.faceAreas()[i]);
132                 bottomArea += mag(bottomPatch.faceAreas()[i]);
133             }
135             if (halfGeometry)
136             {
137                 Info << "half Geometry active" << endl;
139                 forAll(stemPatch, i)
140                 {
141                     stemPatchCentre +=
142                         vector
143                         (
144                             stemPatch.faceCentres()[i].x(),
145                             -1.0*stemPatch.faceCentres()[i].y(),
146                             stemPatch.faceCentres()[i].z()
147                         )*mag(stemPatch.faceAreas()[i]);
149                     stemArea += mag(stemPatch.faceAreas()[i]);
150                 }
152                 forAll(bottomPatch, i)
153                 {
154                     bottomPatchCentre +=
155                         vector
156                         (
157                             bottomPatch.faceCentres()[i].x(),
158                             -1.0*bottomPatch.faceCentres()[i].y(),
159                             bottomPatch.faceCentres()[i].z()
160                         )*mag(bottomPatch.faceAreas()[i]);
162                     bottomArea += mag(bottomPatch.faceAreas()[i]);
163                 }
164             }
166             stemPatchCentre /= stemArea;
167             bottomPatchCentre /= bottomArea;
170             Info<< "Foam::layerSmooth::layerSmooth"
171                 << " calculated origin for valve n. " << valveI
172                 << " is " <<  (stemPatchCentre) << endl;
174             Info<< "Foam::layerSmooth::layerSmooth"
175                 << " calculated axis for valve n. " << valveI
176                 << " is "
177                 << (stemPatchCentre - bottomPatchCentre)/
178                 mag(stemPatchCentre-bottomPatchCentre)
179                 << endl;
180         }
181     }
183     // Add zones and modifiers if not already there.
184     addZonesAndModifiers();
188 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
191 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
194 void Foam::layerSmooth::setBoundaryVelocity(volVectorField& U)
196     // Set valve velociaty
197     forAll (valves(), valveI)
198     {
199         vector valveVel =
200             valves()[valveI].curVelocity()*valves()[valveI].cs().axis();
202         // If valve is present in geometry, set the motion
203         if (valves()[valveI].curtainInPortPatchID().active())
204         {
205             // Bottom of the valve moves with given velocity
206             U.boundaryField()
207                 [valves()[valveI].curtainInPortPatchID().index()] == valveVel;
208         }
210         // If valve is present in geometry, set the motion
211         if (valves()[valveI].curtainInCylinderPatchID().active())
212         {
213             // Bottom of the valve moves with given velocity
214             U.boundaryField()
215                 [valves()[valveI].curtainInCylinderPatchID().index()] ==
216                 valveVel;
217         }
219         // If valve is present in geometry, set the motion
220         if (valves()[valveI].stemPatchID().active())
221         {
222             // Bottom of the valve moves with given velocity
223             U.boundaryField()[valves()[valveI].stemPatchID().index()] ==
224                 valveVel;
225         }
227         // If valve is present in geometry, set the motion
228         if (valves()[valveI].detachInPortPatchID().active())
229         {
230             // Bottom of the valve moves with given velocity
231             U.boundaryField()
232                 [valves()[valveI].detachInPortPatchID().index()] ==
233                 vector::zero;
235             U.oldTime().boundaryField()
236                 [valves()[valveI].detachInPortPatchID().index()] ==
237                 vector::zero;
238         }
240         // If valve is present in geometry, set the motion
241         if (valves()[valveI].detachInCylinderPatchID().active())
242         {
243             // Bottom of the valve moves with given velocity
244             U.boundaryField()
245                 [valves()[valveI].detachInCylinderPatchID().index()] ==
246                vector::zero;
248             U.oldTime().boundaryField()
249                 [valves()[valveI].detachInCylinderPatchID().index()] ==
250                vector::zero;
251         }
252     }
256 bool Foam::layerSmooth::isACylinderHeadFace
258     const labelList& cylHeadFaces,
259     const label face
262     if(face >= cylHeadFaces[0] && face <= cylHeadFaces[cylHeadFaces.size()-1])
263     {
264         return true;
265     }
268     forAll(cylHeadFaces, i)
269     {
270         if(cylHeadFaces[i] == face)
271         {
272             return true;
273         }
274     }
277     return false;
282 // ************************************************************************* //