1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 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"
32 #include "meshTools.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(movingConeTopoFvMesh, 0);
41 addToRunTimeSelectionTable
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52 Foam::tmp<Foam::scalarField> Foam::movingConeTopoFvMesh::vertexMarkup
55 const scalar& curLeft,
56 const scalar& curRight
59 Info<< "Updating vertex markup. curLeft: "
60 << curLeft << " curRight: " << curRight << endl;
62 tmp<scalarField> tvertexMarkup(new scalarField(p.size()));
63 scalarField& vertexMarkup = tvertexMarkup();
67 if (p[pI].x() < curLeft - SMALL)
69 vertexMarkup[pI] = -1;
71 else if (p[pI].x() > curRight + SMALL)
85 void Foam::movingConeTopoFvMesh::addZonesAndModifiers()
87 // Add zones and modifiers for motion action
94 || topoChanger_.size()
97 Info<< "void movingConeTopoFvMesh::addZonesAndModifiers() : "
98 << "Zones and modifiers already present. Skipping."
104 Info<< "Time = " << time().timeName() << endl
105 << "Adding zones and modifiers to the mesh" << endl;
107 const vectorField& fc = faceCentres();
108 const vectorField& fa = faceAreas();
110 labelList zone1(fc.size());
111 boolList flipZone1(fc.size(), false);
112 label nZoneFaces1 = 0;
114 labelList zone2(fc.size());
115 boolList flipZone2(fc.size(), false);
116 label nZoneFaces2 = 0;
122 fc[faceI].x() > -0.003501
123 && fc[faceI].x() < -0.003499
126 if ((fa[faceI] & vector(1, 0, 0)) < 0)
128 flipZone1[nZoneFaces1] = true;
131 zone1[nZoneFaces1] = faceI;
132 Info<< "face " << faceI << " for zone 1. Flip: "
133 << flipZone1[nZoneFaces1] << endl;
138 fc[faceI].x() > -0.00701
139 && fc[faceI].x() < -0.00699
142 zone2[nZoneFaces2] = faceI;
144 if ((fa[faceI] & vector(1, 0, 0)) > 0)
146 flipZone2[nZoneFaces2] = true;
149 Info << "face " << faceI << " for zone 2. Flip: "
150 << flipZone2[nZoneFaces2] << endl;
155 zone1.setSize(nZoneFaces1);
156 flipZone1.setSize(nZoneFaces1);
158 zone2.setSize(nZoneFaces2);
159 flipZone2.setSize(nZoneFaces2);
161 Info << "zone: " << zone1 << endl;
162 Info << "zone: " << zone2 << endl;
164 List<pointZone*> pz(0);
165 List<faceZone*> fz(2);
166 List<cellZone*> cz(0);
173 "rightExtrusionFaces",
184 "leftExtrusionFaces",
194 Info << "Adding mesh zones." << endl;
195 addZones(pz, fz, cz);
198 // Add layer addition/removal interfaces
200 List<polyMeshModifier*> tm(2);
204 new layerAdditionRemoval
209 "rightExtrusionFaces",
212 motionDict_.subDict("right").lookup("minThickness")
216 motionDict_.subDict("right").lookup("maxThickness")
221 tm[nMods] = new layerAdditionRemoval
226 "leftExtrusionFaces",
229 motionDict_.subDict("left").lookup("minThickness")
233 motionDict_.subDict("left").lookup("maxThickness")
239 Info << "Adding " << nMods << " mesh modifiers" << endl;
240 topoChanger_.addTopologyModifiers(tm);
246 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
248 // Construct from components
249 Foam::movingConeTopoFvMesh::movingConeTopoFvMesh(const IOobject& io)
251 topoChangerFvMesh(io),
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"))),
286 Pout<< "Initial time:" << time().value()
287 << " Initial curMotionVel_:" << curMotionVel_
290 addZonesAndModifiers();
296 faceZones().findZoneID("leftExtrusionFaces")
304 faceZones().findZoneID("rightExtrusionFaces")
310 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
312 Foam::movingConeTopoFvMesh::~movingConeTopoFvMesh()
316 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
318 bool Foam::movingConeTopoFvMesh::update()
320 // Do mesh changes (use inflation - put new points in topoChangeMap)
321 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
323 // Calculate the new point positions depending on whether the
324 // topological change has happened or not
325 pointField newPoints;
327 vector curMotionVel_ =
329 Foam::sin(time().value()*M_PI/motionVelPeriod_);
331 Pout<< "time:" << time().value() << " curMotionVel_:" << curMotionVel_
332 << " curLeft:" << curLeft_ << " curRight:" << curRight_
335 if (topoChangeMap.valid())
337 Info << "Topology change. Calculating motion points" << endl;
339 if (topoChangeMap().hasMotionPoints())
341 Info << "Topology change. Has premotion points" << endl;
342 //Info<< "preMotionPoints:" << topoChangeMap().preMotionPoints()
346 OFstream str(time().timePath()/"meshPoints.obj");
347 Pout<< "Writing mesh with meshPoints to " << str.name()
350 const pointField& currentPoints = points();
352 forAll(currentPoints, pointI)
354 meshTools::writeOBJ(str, currentPoints[pointI]);
357 forAll(edges(), edgeI)
359 const edge& e = edges()[edgeI];
360 str << "l " << e[0]+1 << ' ' << e[1]+1 << nl;
364 OFstream str(time().timePath()/"preMotionPoints.obj");
365 Pout<< "Writing mesh with preMotionPoints to " << str.name()
368 const pointField& newPoints = 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(),
393 Info << "Topology change. Already set mesh points" << endl;
404 // Create new points by moving old points but using the
405 // pre-motion points at the motion selector for the moving
410 pos(0.5 - mag(motionMask_)) // cells above the body
411 // + pos(motionMask_ - 0.5)* // cells in front of the body
413 // points().component(vector::X)/curRight
415 // + pos(-motionMask_ - 0.5)* // cells behind the body
418 // points().component(vector::X)
421 // (curLeft_ - leftEdge_)
423 )*curMotionVel_*time().deltaT().value();
427 Info << "No topology change" << endl;
428 // Set the mesh motion
432 pos(0.5 - mag(motionMask_)) // cells above the body
433 // + pos(motionMask_ - 0.5)* // cells in front of the body
435 // points().component(vector::X)/curRight
437 // + pos(-motionMask_ - 0.5)* // cells behind the body
440 // points().component(vector::X)
443 // (curLeft_ - leftEdge_)
445 )*curMotionVel_*time().deltaT().value();
448 // curLeft_ += curMotionVel_.x()*time().deltaT().value();
449 // curRight_ += curMotionVel_.x()*time().deltaT().value();
454 faceZones().findZoneID("leftExtrusionFaces")
462 faceZones().findZoneID("rightExtrusionFaces")
467 // The mesh now contains the cells with zero volume
469 Info << "Executing mesh motion" << endl;
470 movePoints(newPoints);
472 // The mesh now has got non-zero volume cells
478 // ************************************************************************* //