1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-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 "linearValveFvMesh.H"
28 #include "slidingInterface.H"
29 #include "mapPolyMesh.H"
30 #include "polyTopoChange.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(linearValveFvMesh, 0);
39 addToRunTimeSelectionTable(topoChangerFvMesh, linearValveFvMesh, IOobject);
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 void Foam::linearValveFvMesh::addZonesAndModifiers()
47 // Add zones and modifiers for motion action
54 || topoChanger_.size()
57 Info<< "void linearValveFvMesh::addZonesAndModifiers() : "
58 << "Zones and modifiers already present. Skipping."
64 Info<< "Time = " << time().timeName() << endl
65 << "Adding zones and modifiers to the mesh" << endl;
68 List<pointZone*> pz(1);
70 // Add an empty zone for cut points
81 // Do face zones for slider
83 List<faceZone*> fz(3);
86 const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
87 const polyPatch& innerSlider =
88 boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
90 labelList isf(innerSlider.size());
94 isf[i] = innerSlider.start() + i;
101 boolList(innerSlider.size(), false),
107 const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
108 const polyPatch& outerSlider =
109 boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
111 labelList osf(outerSlider.size());
115 osf[i] = outerSlider.start() + i;
122 boolList(outerSlider.size(), false),
127 // Add empty zone for cut faces
137 List<cellZone*> cz(0);
139 Info << "Adding point, face and cell zones" << endl;
140 addZones(pz, fz, cz);
142 // Add a topology modifier
143 Info << "Adding topology modifiers" << endl;
144 topoChanger_.setSize(1);
153 outerSliderName + "Zone",
154 innerSliderName + "Zone",
159 slidingInterface::INTEGRAL,
160 true // Attach-detach action
163 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
170 void Foam::linearValveFvMesh::makeSlidersDead()
172 const polyTopoChanger& topoChanges = topoChanger_;
175 forAll (topoChanges, modI)
177 if (isA<slidingInterface>(topoChanges[modI]))
179 topoChanges[modI].disable();
183 FatalErrorIn("void Foam::linearValveFvMesh::makeSlidersDead()")
184 << "Don't know what to do with mesh modifier "
185 << modI << " of type " << topoChanges[modI].type()
186 << abort(FatalError);
192 void Foam::linearValveFvMesh::makeSlidersLive()
194 const polyTopoChanger& topoChanges = topoChanger_;
196 // Enable sliding interface
197 forAll (topoChanges, modI)
199 if (isA<slidingInterface>(topoChanges[modI]))
201 topoChanges[modI].enable();
205 FatalErrorIn("void Foam::linearValveFvMesh::makeLayersLive()")
206 << "Don't know what to do with mesh modifier "
207 << modI << " of type " << topoChanges[modI].type()
208 << abort(FatalError);
214 bool Foam::linearValveFvMesh::attached() const
216 const polyTopoChanger& topoChanges = topoChanger_;
220 forAll (topoChanges, modI)
222 if (isA<slidingInterface>(topoChanges[modI]))
226 || refCast<const slidingInterface>(topoChanges[modI]).attached();
230 // Check thal all sliders are in sync (debug only)
231 forAll (topoChanges, modI)
233 if (isA<slidingInterface>(topoChanges[modI]))
238 != refCast<const slidingInterface>(topoChanges[modI]).attached()
241 FatalErrorIn("bool linearValveFvMesh::attached() const")
242 << "Slider " << modI << " named " << topoChanges[modI].name()
243 << " out of sync: Should be" << result
244 << abort(FatalError);
251 Info << "linearValveFvMesh: attached!" << endl;
255 Info << "linearValveFvMesh: detached!" << endl;
262 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
264 // Construct from components
265 Foam::linearValveFvMesh::linearValveFvMesh(const IOobject& io)
267 topoChangerFvMesh(io),
280 ).subDict(typeName + "Coeffs")
282 msPtr_(motionSolver::New(*this))
284 addZonesAndModifiers();
288 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
290 Foam::linearValveFvMesh::~linearValveFvMesh()
294 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
296 void Foam::linearValveFvMesh::update()
298 // Detaching the interface
301 Info << "Decoupling sliding interfaces" << endl;
304 // Changing topology by hand
306 setMorphTimeIndex(3*time().timeIndex());
309 msPtr_->updateMesh();
313 Info << "Sliding interfaces decoupled" << endl;
316 // Perform mesh motion
319 // Changing topology by hand
321 setMorphTimeIndex(3*time().timeIndex() + 1);
324 msPtr_->updateMesh();
326 if (topoChangeMap.valid())
328 if (topoChangeMap().hasMotionPoints())
330 Info << "Topology change; executing pre-motion" << endl;
331 movePoints(topoChangeMap().preMotionPoints());
338 movePoints(msPtr_->curPoints());
340 // Attach the interface
341 Info << "Coupling sliding interfaces" << endl;
344 setMorphTimeIndex(3*time().timeIndex() + 2);
347 Info << "Moving points post slider attach" << endl;
349 msPtr_->updateMesh();
351 Info << "Sliding interfaces coupled: " << attached() << endl;
355 // ************************************************************************* //