1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "movingConeTopoFvMesh.H"
28 #include "mapPolyMesh.H"
29 #include "layerAdditionRemoval.H"
30 #include "addToRunTimeSelectionTable.H"
31 #include "meshTools.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(movingConeTopoFvMesh, 0);
40 addToRunTimeSelectionTable
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 Foam::tmp<Foam::scalarField> Foam::movingConeTopoFvMesh::vertexMarkup
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 - SMALL)
68 vertexMarkup[pI] = -1;
70 else if (p[pI].x() > curRight + SMALL)
84 void Foam::movingConeTopoFvMesh::addZonesAndModifiers()
86 // Add zones and modifiers for motion action
93 || topoChanger_.size()
96 Info<< "void movingConeTopoFvMesh::addZonesAndModifiers() : "
97 << "Zones and modifiers already present. Skipping."
103 Info<< "Time = " << time().timeName() << endl
104 << "Adding zones and modifiers to the mesh" << endl;
106 const vectorField& fc = faceCentres();
107 const vectorField& fa = faceAreas();
109 labelList zone1(fc.size());
110 boolList flipZone1(fc.size(), false);
111 label nZoneFaces1 = 0;
113 labelList zone2(fc.size());
114 boolList flipZone2(fc.size(), false);
115 label nZoneFaces2 = 0;
121 fc[faceI].x() > -0.003501
122 && fc[faceI].x() < -0.003499
125 if ((fa[faceI] & vector(1, 0, 0)) < 0)
127 flipZone1[nZoneFaces1] = true;
130 zone1[nZoneFaces1] = faceI;
131 Info<< "face " << faceI << " for zone 1. Flip: "
132 << flipZone1[nZoneFaces1] << endl;
137 fc[faceI].x() > -0.00701
138 && fc[faceI].x() < -0.00699
141 zone2[nZoneFaces2] = faceI;
143 if ((fa[faceI] & vector(1, 0, 0)) > 0)
145 flipZone2[nZoneFaces2] = true;
148 Info<< "face " << faceI << " for zone 2. Flip: "
149 << flipZone2[nZoneFaces2] << endl;
154 zone1.setSize(nZoneFaces1);
155 flipZone1.setSize(nZoneFaces1);
157 zone2.setSize(nZoneFaces2);
158 flipZone2.setSize(nZoneFaces2);
160 Info<< "zone: " << zone1 << endl;
161 Info<< "zone: " << zone2 << endl;
163 List<pointZone*> pz(0);
164 List<faceZone*> fz(2);
165 List<cellZone*> cz(0);
172 "rightExtrusionFaces",
183 "leftExtrusionFaces",
193 Info<< "Adding mesh zones." << endl;
194 addZones(pz, fz, cz);
197 // Add layer addition/removal interfaces
199 List<polyMeshModifier*> tm(2);
203 new layerAdditionRemoval
208 "rightExtrusionFaces",
211 motionDict_.subDict("right").lookup("minThickness")
215 motionDict_.subDict("right").lookup("maxThickness")
220 tm[nMods] = new layerAdditionRemoval
225 "leftExtrusionFaces",
228 motionDict_.subDict("left").lookup("minThickness")
232 motionDict_.subDict("left").lookup("maxThickness")
238 Info<< "Adding " << nMods << " mesh modifiers" << endl;
239 topoChanger_.addTopologyModifiers(tm);
245 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
247 // Construct from components
248 Foam::movingConeTopoFvMesh::movingConeTopoFvMesh(const IOobject& io)
250 topoChangerFvMesh(io),
260 IOobject::MUST_READ_IF_MODIFIED,
264 ).subDict(typeName + "Coeffs")
266 motionVelAmplitude_(motionDict_.lookup("motionVelAmplitude")),
267 motionVelPeriod_(readScalar(motionDict_.lookup("motionVelPeriod"))),
271 Foam::sin(time().value()*M_PI/motionVelPeriod_)
273 leftEdge_(readScalar(motionDict_.lookup("leftEdge"))),
274 curLeft_(readScalar(motionDict_.lookup("leftObstacleEdge"))),
275 curRight_(readScalar(motionDict_.lookup("rightObstacleEdge")))
277 Pout<< "Initial time:" << time().value()
278 << " Initial curMotionVel_:" << curMotionVel_
281 addZonesAndModifiers();
287 faceZones().findZoneID("leftExtrusionFaces")
295 faceZones().findZoneID("rightExtrusionFaces")
299 motionMask_ = vertexMarkup
308 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
310 Foam::movingConeTopoFvMesh::~movingConeTopoFvMesh()
314 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
316 bool Foam::movingConeTopoFvMesh::update()
318 // Do mesh changes (use inflation - put new points in topoChangeMap)
319 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
321 // Calculate the new point positions depending on whether the
322 // topological change has happened or not
323 pointField newPoints;
325 vector curMotionVel_ =
327 Foam::sin(time().value()*M_PI/motionVelPeriod_);
329 Pout<< "time:" << time().value() << " curMotionVel_:" << curMotionVel_
330 << " curLeft:" << curLeft_ << " curRight:" << curRight_
333 if (topoChangeMap.valid())
335 Info<< "Topology change. Calculating motion points" << endl;
337 if (topoChangeMap().hasMotionPoints())
339 Info<< "Topology change. Has premotion points" << endl;
340 //Info<< "preMotionPoints:" << topoChangeMap().preMotionPoints()
343 //mkDir(time().timePath());
345 // OFstream str(time().timePath()/"meshPoints.obj");
346 // Pout<< "Writing mesh with meshPoints to " << str.name()
349 // const pointField& currentPoints = points();
351 // forAll(currentPoints, pointI)
353 // meshTools::writeOBJ(str, currentPoints[pointI]);
356 // forAll(edges(), edgeI)
358 // const edge& e = edges()[edgeI];
359 // str << "l " << e[0]+1 << ' ' << e[1]+1 << nl;
363 // OFstream str(time().timePath()/"preMotionPoints.obj");
364 // Pout<< "Writing mesh with preMotionPoints to " << str.name()
367 // const pointField& newPoints =
368 // topoChangeMap().preMotionPoints();
370 // forAll(newPoints, pointI)
372 // meshTools::writeOBJ(str, newPoints[pointI]);
375 // forAll(edges(), edgeI)
377 // const edge& e = edges()[edgeI];
378 // str << "l " << e[0]+1 << ' ' << e[1]+1 << nl;
386 topoChangeMap().preMotionPoints(),
391 // Move points inside the motionMask
393 topoChangeMap().preMotionPoints()
395 pos(0.5 - mag(motionMask_)) // cells above the body
396 )*curMotionVel_*time().deltaT().value();
400 Info<< "Topology change. Already set mesh points" << endl;
410 // Move points inside the motionMask
414 pos(0.5 - mag(motionMask_)) // cells above the body
415 )*curMotionVel_*time().deltaT().value();
420 Info<< "No topology change" << endl;
421 // Set the mesh motion
425 pos(0.5 - mag(motionMask_)) // cells above the body
426 )*curMotionVel_*time().deltaT().value();
429 // The mesh now contains the cells with zero volume
430 Info << "Executing mesh motion" << endl;
431 movePoints(newPoints);
432 // The mesh now has got non-zero volume cells
438 faceZones().findZoneID("leftExtrusionFaces")
446 faceZones().findZoneID("rightExtrusionFaces")
455 // ************************************************************************* //