1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "linearValveFvMesh.H"
28 #include "slidingInterface.H"
29 #include "mapPolyMesh.H"
30 #include "polyTopoChange.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(linearValveFvMesh, 0);
40 addToRunTimeSelectionTable(topoChangerFvMesh, linearValveFvMesh, IOobject);
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 void Foam::linearValveFvMesh::addZonesAndModifiers()
48 // Add zones and modifiers for motion action
52 pointZones().size() > 0
53 || faceZones().size() > 0
54 || cellZones().size() > 0
57 Info<< "void linearValveFvMesh::addZonesAndModifiers() : "
58 << "Zones and modifiers already present. Skipping."
61 if (topoChanger_.size() == 0)
65 "void linearValveFvMesh::addZonesAndModifiers()"
66 ) << "Mesh modifiers not read properly"
73 Info<< "Time = " << time().timeName() << endl
74 << "Adding zones and modifiers to the mesh" << endl;
77 List<pointZone*> pz(1);
79 // Add an empty zone for cut points
90 // Do face zones for slider
92 List<faceZone*> fz(3);
95 const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
96 const polyPatch& innerSlider =
97 boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
99 labelList isf(innerSlider.size());
103 isf[i] = innerSlider.start() + i;
110 boolList(innerSlider.size(), false),
116 const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
117 const polyPatch& outerSlider =
118 boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
120 labelList osf(outerSlider.size());
124 osf[i] = outerSlider.start() + i;
131 boolList(outerSlider.size(), false),
136 // Add empty zone for cut faces
146 List<cellZone*> cz(0);
148 Info << "Adding point, face and cell zones" << endl;
149 addZones(pz, fz, cz);
151 // Add a topology modifier
152 Info << "Adding topology modifiers" << endl;
153 topoChanger_.setSize(1);
162 outerSliderName + "Zone",
163 innerSliderName + "Zone",
168 slidingInterface::INTEGRAL, // Edge matching algorithm
169 true, // Attach-detach action
170 intersection::VISIBLE // Projection algorithm
174 // Write mesh and modifiers
175 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
176 topoChanger_.write();
181 void Foam::linearValveFvMesh::deactivateSliders()
183 const polyTopoChanger& topoChanges = topoChanger_;
186 forAll (topoChanges, modI)
188 if (isA<slidingInterface>(topoChanges[modI]))
190 topoChanges[modI].disable();
194 FatalErrorIn("void Foam::linearValveFvMesh::deactivateSliders()")
195 << "Don't know what to do with mesh modifier "
196 << modI << " of type " << topoChanges[modI].type()
197 << abort(FatalError);
203 void Foam::linearValveFvMesh::activateSliders()
205 const polyTopoChanger& topoChanges = topoChanger_;
207 // Enable sliding interface
208 forAll (topoChanges, modI)
210 if (isA<slidingInterface>(topoChanges[modI]))
212 topoChanges[modI].enable();
216 FatalErrorIn("void Foam::linearValveFvMesh::activateSliders()")
217 << "Don't know what to do with mesh modifier "
218 << modI << " of type " << topoChanges[modI].type()
219 << abort(FatalError);
225 bool Foam::linearValveFvMesh::attached() const
227 const polyTopoChanger& topoChanges = topoChanger_;
231 forAll (topoChanges, modI)
233 if (isA<slidingInterface>(topoChanges[modI]))
237 || refCast<const slidingInterface>(topoChanges[modI]).attached();
241 // Check thal all sliders are in sync (debug only)
242 forAll (topoChanges, modI)
244 if (isA<slidingInterface>(topoChanges[modI]))
249 != refCast<const slidingInterface>(topoChanges[modI]).attached()
252 FatalErrorIn("bool linearValveFvMesh::attached() const")
253 << "Slider " << modI << " named "
254 << 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 bool localMorphing3 = topoChangeMap3->morphing();
367 bool globalMorphing3 = localMorphing3;
369 reduce(globalMorphing3, orOp<bool>());
373 pointField newPoints = allPoints();
377 msPtr_->updateMesh(topoChangeMap3());
379 pointField mappedOldPointsNew(newPoints.size());
381 mappedOldPointsNew.map
384 topoChangeMap3->pointMap()
387 // Solve the correct mesh motion to make sure motion fluxes
388 // are solved for and not mapped
389 // Note: using setOldPoints instead of movePoints.
391 setOldPoints(mappedOldPointsNew);
396 fvMesh::movePoints(newPoints);
400 // No local topological change. Execute double motion for
401 // sync with topological changes
402 // Note: using setOldPoints instead of movePoints.
404 setOldPoints(oldPointsNew);
409 // Set new point motion
410 fvMesh::movePoints(newPoints);
415 Info << "Sliding interfaces coupled: " << attached() << endl;
421 // ************************************************************************* //