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 "linearValveFvMesh.H"
29 #include "slidingInterface.H"
30 #include "mapPolyMesh.H"
31 #include "polyTopoChange.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(linearValveFvMesh, 0);
41 addToRunTimeSelectionTable(topoChangerFvMesh, linearValveFvMesh, IOobject);
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 void Foam::linearValveFvMesh::addZonesAndModifiers()
49 // Add zones and modifiers for motion action
53 pointZones().size() > 0
54 || faceZones().size() > 0
55 || cellZones().size() > 0
58 Info<< "void linearValveFvMesh::addZonesAndModifiers() : "
59 << "Zones and modifiers already present. Skipping."
62 if (topoChanger_.size() == 0)
66 "void linearValveFvMesh::addZonesAndModifiers()"
67 ) << "Mesh modifiers not read properly"
74 Info<< "Time = " << time().timeName() << endl
75 << "Adding zones and modifiers to the mesh" << endl;
78 List<pointZone*> pz(1);
80 // Add an empty zone for cut points
91 // Do face zones for slider
93 List<faceZone*> fz(3);
96 const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
97 const polyPatch& innerSlider =
98 boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
100 labelList isf(innerSlider.size());
104 isf[i] = innerSlider.start() + i;
111 boolList(innerSlider.size(), false),
117 const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
118 const polyPatch& outerSlider =
119 boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
121 labelList osf(outerSlider.size());
125 osf[i] = outerSlider.start() + i;
132 boolList(outerSlider.size(), false),
137 // Add empty zone for cut faces
147 List<cellZone*> cz(0);
149 Info << "Adding point, face and cell zones" << endl;
150 addZones(pz, fz, cz);
152 // Add a topology modifier
153 Info << "Adding topology modifiers" << endl;
154 topoChanger_.setSize(1);
163 outerSliderName + "Zone",
164 innerSliderName + "Zone",
169 slidingInterface::INTEGRAL, // Edge matching algorithm
170 true, // Attach-detach action
171 intersection::VISIBLE // Projection algorithm
175 // Write mesh and modifiers
176 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
177 topoChanger_.write();
182 void Foam::linearValveFvMesh::makeSlidersDead()
184 const polyTopoChanger& topoChanges = topoChanger_;
187 forAll (topoChanges, modI)
189 if (isA<slidingInterface>(topoChanges[modI]))
191 topoChanges[modI].disable();
195 FatalErrorIn("void Foam::linearValveFvMesh::makeSlidersDead()")
196 << "Don't know what to do with mesh modifier "
197 << modI << " of type " << topoChanges[modI].type()
198 << abort(FatalError);
204 void Foam::linearValveFvMesh::makeSlidersLive()
206 const polyTopoChanger& topoChanges = topoChanger_;
208 // Enable sliding interface
209 forAll (topoChanges, modI)
211 if (isA<slidingInterface>(topoChanges[modI]))
213 topoChanges[modI].enable();
217 FatalErrorIn("void Foam::linearValveFvMesh::makeLayersLive()")
218 << "Don't know what to do with mesh modifier "
219 << modI << " of type " << topoChanges[modI].type()
220 << abort(FatalError);
226 bool Foam::linearValveFvMesh::attached() const
228 const polyTopoChanger& topoChanges = topoChanger_;
232 forAll (topoChanges, modI)
234 if (isA<slidingInterface>(topoChanges[modI]))
238 || refCast<const slidingInterface>(topoChanges[modI]).attached();
242 // Check thal all sliders are in sync (debug only)
243 forAll (topoChanges, modI)
245 if (isA<slidingInterface>(topoChanges[modI]))
250 != refCast<const slidingInterface>(topoChanges[modI]).attached()
253 FatalErrorIn("bool linearValveFvMesh::attached() const")
254 << "Slider " << modI << " named " << topoChanges[modI].name()
255 << " out of sync: Should be" << result
256 << abort(FatalError);
263 Info << "linearValveFvMesh: attached!" << endl;
267 Info << "linearValveFvMesh: detached!" << endl;
274 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
276 // Construct from components
277 Foam::linearValveFvMesh::linearValveFvMesh(const IOobject& io)
279 topoChangerFvMesh(io),
292 ).subDict(typeName + "Coeffs")
294 msPtr_(motionSolver::New(*this))
296 addZonesAndModifiers();
300 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
302 Foam::linearValveFvMesh::~linearValveFvMesh()
306 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
308 bool Foam::linearValveFvMesh::update()
310 // Detaching the interface
313 Info << "Decoupling sliding interfaces" << endl;
316 // Changing topology by hand
317 autoPtr<mapPolyMesh> topoChangeMap1 = topoChanger_.changeMesh();
319 if (topoChangeMap1->morphing())
321 msPtr_->updateMesh(topoChangeMap1());
326 Info << "Sliding interfaces decoupled" << endl;
329 // Perform mesh motion
332 // Changing topology by hand
334 autoPtr<mapPolyMesh> topoChangeMap2 = topoChanger_.changeMesh();
336 if (topoChangeMap2->morphing())
338 msPtr_->updateMesh(topoChangeMap2());
340 if (topoChangeMap2->hasMotionPoints())
342 Info << "Topology change; executing pre-motion" << endl;
343 movePoints(topoChangeMap2->preMotionPoints());
351 movePoints(msPtr_->curPoints());
353 // Attach the interface
354 Info << "Coupling sliding interfaces" << endl;
357 // Changing topology by hand
359 // Grab old points to correct the motion
360 pointField oldPointsNew = oldAllPoints();
362 autoPtr<mapPolyMesh> topoChangeMap3 = topoChanger_.changeMesh();
364 Info << "Moving points post slider attach" << endl;
366 if (topoChangeMap3->morphing())
368 msPtr_->updateMesh(topoChangeMap3());
372 Info << "Moving points post slider attach" << endl;
375 pointField newPoints = allPoints();
376 pointField mappedOldPointsNew(newPoints.size());
378 mappedOldPointsNew.map(oldPointsNew, topoChangeMap3->pointMap());
380 // Solve the correct mesh motion to make sure motion fluxes
381 // are solved for and not mapped
382 movePoints(mappedOldPointsNew);
385 movePoints(newPoints);
389 Info << "Sliding interfaces coupled: " << attached() << endl;
395 // ************************************************************************* //