1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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 "movingConeTopoFvMesh.H"
29 #include "mapPolyMesh.H"
30 #include "layerAdditionRemoval.H"
31 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(movingConeTopoFvMesh, 0);
40 addToRunTimeSelectionTable
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 Foam::tmp<Foam::scalarField> Foam::movingConeTopoFvMesh::vertexMarkup
54 const scalar& curLeft,
55 const scalar& curRight
58 Info<< "Updating vertex markup. curLeft: "
59 << curLeft << " curRight: " << curRight << endl;
61 tmp<scalarField> tvertexMarkup(new scalarField(p.size()));
62 scalarField& vertexMarkup = tvertexMarkup();
66 if (p[pI].x() < curLeft - 1e-10)
68 vertexMarkup[pI] = -1;
70 else if (p[pI].x() > curRight + 1e-10)
84 void Foam::movingConeTopoFvMesh::addZonesAndModifiers()
86 // Add zones and modifiers for motion action
90 pointZones().size() > 0
91 || faceZones().size() > 0
92 || cellZones().size() > 0
95 Info<< "void movingConeTopoFvMesh::addZonesAndModifiers() : "
96 << "Zones and modifiers already present. Skipping."
99 if (topoChanger_.size() == 0)
103 "void movingConeTopoFvMesh::addZonesAndModifiers()"
104 ) << "Mesh modifiers not read properly"
105 << abort(FatalError);
111 Info<< "Time = " << time().timeName() << endl
112 << "Adding zones and modifiers to the mesh" << endl;
114 const vectorField& fc = faceCentres();
115 const vectorField& fa = faceAreas();
117 labelList zone1(fc.size());
118 boolList flipZone1(fc.size(), false);
119 label nZoneFaces1 = 0;
121 labelList zone2(fc.size());
122 boolList flipZone2(fc.size(), false);
123 label nZoneFaces2 = 0;
129 fc[faceI].x() > -0.003501
130 && fc[faceI].x() < -0.003499
133 if ((fa[faceI] & vector(1, 0, 0)) < 0)
135 flipZone1[nZoneFaces1] = true;
138 zone1[nZoneFaces1] = faceI;
139 Info<< "face " << faceI << " for zone 1. Flip: "
140 << flipZone1[nZoneFaces1] << endl;
145 fc[faceI].x() > -0.00701
146 && fc[faceI].x() < -0.00699
149 zone2[nZoneFaces2] = faceI;
151 if ((fa[faceI] & vector(1, 0, 0)) > 0)
153 flipZone2[nZoneFaces2] = true;
156 Info << "face " << faceI << " for zone 2. Flip: "
157 << flipZone2[nZoneFaces2] << endl;
162 zone1.setSize(nZoneFaces1);
163 flipZone1.setSize(nZoneFaces1);
165 zone2.setSize(nZoneFaces2);
166 flipZone2.setSize(nZoneFaces2);
168 Info << "zone: " << zone1 << endl;
169 Info << "zone: " << zone2 << endl;
171 List<pointZone*> pz(0);
172 List<faceZone*> fz(2);
173 List<cellZone*> cz(0);
180 "rightExtrusionFaces",
191 "leftExtrusionFaces",
201 Info << "Adding mesh zones." << endl;
202 addZones(pz, fz, cz);
205 // Add layer addition/removal interfaces
207 topoChanger_.setSize(2);
213 new layerAdditionRemoval
218 "rightExtrusionFaces",
221 motionDict_.subDict("right").lookup("minThickness")
225 motionDict_.subDict("right").lookup("maxThickness")
234 new layerAdditionRemoval
239 "leftExtrusionFaces",
242 motionDict_.subDict("left").lookup("minThickness")
246 motionDict_.subDict("left").lookup("maxThickness")
252 Info << "Adding " << nMods << " mesh modifiers" << endl;
254 // Write mesh and modifiers
255 topoChanger_.write();
260 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
262 // Construct from components
263 Foam::movingConeTopoFvMesh::movingConeTopoFvMesh(const IOobject& io)
265 topoChangerFvMesh(io),
278 ).subDict(typeName + "Coeffs")
280 motionVelAmplitude_(motionDict_.lookup("motionVelAmplitude")),
281 motionVelPeriod_(readScalar(motionDict_.lookup("motionVelPeriod"))),
285 Foam::sin(time().value()*M_PI/motionVelPeriod_)
287 leftEdge_(readScalar(motionDict_.lookup("leftEdge"))),
288 curLeft_(readScalar(motionDict_.lookup("leftObstacleEdge"))),
289 curRight_(readScalar(motionDict_.lookup("rightObstacleEdge"))),
300 addZonesAndModifiers();
306 faceZones().findZoneID("leftExtrusionFaces")
314 faceZones().findZoneID("rightExtrusionFaces")
320 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
322 Foam::movingConeTopoFvMesh::~movingConeTopoFvMesh()
326 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
328 bool Foam::movingConeTopoFvMesh::update()
330 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
332 // Calculate the new point positions depending on whether the
333 // topological change has happened or not
334 pointField newPoints;
336 vector curMotionVel_ =
338 Foam::sin(time().value()*M_PI/motionVelPeriod_);
340 bool meshChanged = topoChangeMap->morphing();
344 Info << "Topology change. Calculating motion points" << endl;
346 if (topoChangeMap().hasMotionPoints())
351 topoChangeMap().preMotionPoints(),
367 // Create new points by moving old points but using the
368 // pre-motion points at the motion selector for the moving
373 pos(0.5 - mag(motionMask_)) // cells above the body
374 // + pos(motionMask_ - 0.5)* // cells in front of the body
376 // points().component(vector::X)/curRight
378 // + pos(-motionMask_ - 0.5)* // cells behind the body
381 // points().component(vector::X)
384 // (curLeft_ - leftEdge_)
386 )*curMotionVel_*time().deltaT().value();
388 // Correct mesh motion for correct volume continuity
389 movePoints(topoChangeMap().preMotionPoints());
395 Info << "No topology change" << endl;
396 // Set the mesh motion
400 pos(0.5 - mag(motionMask_)) // cells above the body
401 // + pos(motionMask_ - 0.5)* // cells in front of the body
403 // points().component(vector::X)/curRight
405 // + pos(-motionMask_ - 0.5)* // cells behind the body
408 // points().component(vector::X)
411 // (curLeft_ - leftEdge_)
413 )*curMotionVel_*time().deltaT().value();
416 curLeft_ += curMotionVel_.x()*time().deltaT().value();
417 curRight_ += curMotionVel_.x()*time().deltaT().value();
419 // The mesh now contains the cells with zero volume
421 Info << "Executing mesh motion" << endl;
422 movePoints(newPoints);
424 // The mesh now has got non-zero volume cells
430 // ************************************************************************* //