1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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 = boundaryMesh()[innerSliderName];
89 labelList isf(innerSlider.size());
93 isf[i] = innerSlider.start() + i;
100 boolList(innerSlider.size(), false),
106 const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
107 const polyPatch& outerSlider = boundaryMesh()[outerSliderName];
109 labelList osf(outerSlider.size());
113 osf[i] = outerSlider.start() + i;
120 boolList(outerSlider.size(), false),
125 // Add empty zone for cut faces
135 List<cellZone*> cz(0);
137 Info<< "Adding point, face and cell zones" << endl;
138 addZones(pz, fz, cz);
140 // Add a topology modifier
141 Info<< "Adding topology modifiers" << endl;
142 topoChanger_.setSize(1);
151 outerSliderName + "Zone",
152 innerSliderName + "Zone",
157 slidingInterface::INTEGRAL,
158 true // Attach-detach action
161 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
168 void Foam::linearValveFvMesh::makeSlidersDead()
170 const polyTopoChanger& topoChanges = topoChanger_;
173 forAll(topoChanges, modI)
175 if (isA<slidingInterface>(topoChanges[modI]))
177 topoChanges[modI].disable();
181 FatalErrorIn("void Foam::linearValveFvMesh::makeSlidersDead()")
182 << "Don't know what to do with mesh modifier "
183 << modI << " of type " << topoChanges[modI].type()
184 << abort(FatalError);
190 void Foam::linearValveFvMesh::makeSlidersLive()
192 const polyTopoChanger& topoChanges = topoChanger_;
194 // Enable sliding interface
195 forAll(topoChanges, modI)
197 if (isA<slidingInterface>(topoChanges[modI]))
199 topoChanges[modI].enable();
203 FatalErrorIn("void Foam::linearValveFvMesh::makeLayersLive()")
204 << "Don't know what to do with mesh modifier "
205 << modI << " of type " << topoChanges[modI].type()
206 << abort(FatalError);
212 bool Foam::linearValveFvMesh::attached() const
214 const polyTopoChanger& topoChanges = topoChanger_;
218 forAll(topoChanges, modI)
220 if (isA<slidingInterface>(topoChanges[modI]))
224 || refCast<const slidingInterface>(topoChanges[modI]).attached();
228 // Check thal all sliders are in sync (debug only)
229 forAll(topoChanges, modI)
231 if (isA<slidingInterface>(topoChanges[modI]))
236 != refCast<const slidingInterface>(topoChanges[modI]).attached()
239 FatalErrorIn("bool linearValveFvMesh::attached() const")
241 << " named " << topoChanges[modI].name()
242 << " out of sync: Should be" << result
243 << abort(FatalError);
250 Info<< "linearValveFvMesh: attached!" << endl;
254 Info<< "linearValveFvMesh: detached!" << endl;
261 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
263 // Construct from components
264 Foam::linearValveFvMesh::linearValveFvMesh(const IOobject& io)
266 topoChangerFvMesh(io),
276 IOobject::MUST_READ_IF_MODIFIED,
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 // ************************************************************************* //