Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / engine / engineTopoChangerMesh / layerSmooth / layerSmooth.C
blob5f8b31a8818a9fd89677f504f39cee3ace8dec8b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM 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 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "layerSmooth.H"
28 #include "layerAdditionRemoval.H"
29 #include "attachDetach.H"
30 #include "componentMixedTetPolyPatchVectorField.H"
31 #include "mapPolyMesh.H"
32 #include "polyTopoChange.H"
33 #include "addToRunTimeSelectionTable.H"
34 #include "GeometricField.H"
35 #include "volMesh.H"
36 #include "engineTime.H"
37 #include "pointField.H"
38 #include "fvPatchField.H"
39 #include "Switch.H"
41 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
43 defineTypeNameAndDebug(Foam::layerSmooth, 0);
45 addToRunTimeSelectionTable
47     Foam::engineTopoChangerMesh,
48     Foam::layerSmooth,
49     IOobject
53 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
55 bool Foam::layerSmooth::realDeformation() const
58     if
59     (
60         virtualPistonPosition() + engTime().pistonDisplacement().value()
61       > deckHeight_ - SMALL
62     )
63     {
64         return true;
65     }
66     else
67     {
68         return deformation();
69     }
73 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
75 // Construct from components
76 Foam::layerSmooth::layerSmooth
78     const IOobject& io
81     engineTopoChangerMesh(io),
82     piston_(*this, engTime().engineDict().subDict("piston")),
83     valves_(*this, engTime().engineDict().lookup("layerSmooth")),
84     deformSwitch_(readScalar(engTime().engineDict().lookup("deformAngle"))),
85     delta_(readScalar(engTime().engineDict().lookup("delta"))),
86     offSet_(readScalar(engTime().engineDict().lookup("offSet"))),
87     pistonPosition_(-GREAT),
88     virtualPistonPosition_(-GREAT),
89     deckHeight_(GREAT),
90     msPtr_(motionSolver::New(*this)),
91     valvePlaneTol_(readScalar(engTime().engineDict().lookup("valvePlaneTol")))
95     forAll(valves(), valveI)
96     {
97         if
98         (
99             valves()[valveI].stemPatchID().active()
100          && valves()[valveI].bottomPatchID().active()
101         )
102         {
103             label bottomIndex = valves()[valveI].bottomPatchID().index();
104             label stemIndex = valves()[valveI].stemPatchID().index();
106             const polyPatch& stemPatch =
107                     boundaryMesh()[stemIndex];
109             const polyPatch& bottomPatch =
110                     boundaryMesh()[bottomIndex];
112             point bottomPatchCentre = vector::zero;
113             point stemPatchCentre = vector::zero;
115             scalar bottomArea = 0;
116             scalar stemArea = 0;
118             Switch halfGeometry(engTime().engineDict().lookup("halfGeometry"));
120             forAll(stemPatch, i)
121             {
122                 stemPatchCentre +=
123                     stemPatch.faceCentres()[i]*mag(stemPatch.faceAreas()[i]);
125                 stemArea += mag(stemPatch.faceAreas()[i]);
126             }
128             forAll(bottomPatch, i)
129             {
130                 bottomPatchCentre +=bottomPatch.faceCentres()[i]*
131                     mag(bottomPatch.faceAreas()[i]);
133                 bottomArea += mag(bottomPatch.faceAreas()[i]);
134             }
136             if (halfGeometry)
137             {
138                 Info << "half Geometry active" << endl;
140                 forAll(stemPatch, i)
141                 {
142                     stemPatchCentre +=
143                         vector
144                         (
145                             stemPatch.faceCentres()[i].x(),
146                             -1.0*stemPatch.faceCentres()[i].y(),
147                             stemPatch.faceCentres()[i].z()
148                         )*mag(stemPatch.faceAreas()[i]);
150                     stemArea += mag(stemPatch.faceAreas()[i]);
151                 }
153                 forAll(bottomPatch, i)
154                 {
155                     bottomPatchCentre +=
156                         vector
157                         (
158                             bottomPatch.faceCentres()[i].x(),
159                             -1.0*bottomPatch.faceCentres()[i].y(),
160                             bottomPatch.faceCentres()[i].z()
161                         )*mag(bottomPatch.faceAreas()[i]);
163                     bottomArea += mag(bottomPatch.faceAreas()[i]);
164                 }
165             }
167             stemPatchCentre /= stemArea;
168             bottomPatchCentre /= bottomArea;
171             Info<< "Foam::layerSmooth::layerSmooth"
172                 << " calculated origin for valve n. " << valveI
173                 << " is " <<  (stemPatchCentre) << endl;
175             Info<< "Foam::layerSmooth::layerSmooth"
176                 << " calculated axis for valve n. " << valveI
177                 << " is "
178                 << (stemPatchCentre - bottomPatchCentre)/
179                 mag(stemPatchCentre-bottomPatchCentre)
180                 << endl;
181         }
182     }
184     // Add zones and modifiers if not already there.
185     addZonesAndModifiers();
189 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
192 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
195 void Foam::layerSmooth::setBoundaryVelocity(volVectorField& U)
197     // Set valve velociaty
198     forAll (valves(), valveI)
199     {
200         vector valveVel =
201             valves()[valveI].curVelocity()*valves()[valveI].cs().axis();
203         // If valve is present in geometry, set the motion
204         if (valves()[valveI].curtainInPortPatchID().active())
205         {
206             // Bottom of the valve moves with given velocity
207             U.boundaryField()
208                 [valves()[valveI].curtainInPortPatchID().index()] == valveVel;
209         }
211         // If valve is present in geometry, set the motion
212         if (valves()[valveI].curtainInCylinderPatchID().active())
213         {
214             // Bottom of the valve moves with given velocity
215             U.boundaryField()
216                 [valves()[valveI].curtainInCylinderPatchID().index()] ==
217                 valveVel;
218         }
220         // If valve is present in geometry, set the motion
221         if (valves()[valveI].stemPatchID().active())
222         {
223             // Bottom of the valve moves with given velocity
224             U.boundaryField()[valves()[valveI].stemPatchID().index()] ==
225                 valveVel;
226         }
228         // If valve is present in geometry, set the motion
229         if (valves()[valveI].detachInPortPatchID().active())
230         {
231             // Bottom of the valve moves with given velocity
232             U.boundaryField()
233                 [valves()[valveI].detachInPortPatchID().index()] ==
234                 vector::zero;
236             U.oldTime().boundaryField()
237                 [valves()[valveI].detachInPortPatchID().index()] ==
238                 vector::zero;
239         }
241         // If valve is present in geometry, set the motion
242         if (valves()[valveI].detachInCylinderPatchID().active())
243         {
244             // Bottom of the valve moves with given velocity
245             U.boundaryField()
246                 [valves()[valveI].detachInCylinderPatchID().index()] ==
247                vector::zero;
249             U.oldTime().boundaryField()
250                 [valves()[valveI].detachInCylinderPatchID().index()] ==
251                vector::zero;
252         }
253     }
257 bool Foam::layerSmooth::isACylinderHeadFace
259     const labelList& cylHeadFaces,
260     const label face
263     if(face >= cylHeadFaces[0] && face <= cylHeadFaces[cylHeadFaces.size()-1])
264     {
265         return true;
266     }
269     forAll(cylHeadFaces, i)
270     {
271         if(cylHeadFaces[i] == face)
272         {
273             return true;
274         }
275     }
278     return false;
283 // ************************************************************************* //