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 "linearValveFvMesh.H"
29 #include "slidingInterface.H"
30 #include "mapPolyMesh.H"
31 #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
55 || topoChanger_.size()
58 Info<< "void linearValveFvMesh::addZonesAndModifiers() : "
59 << "Zones and modifiers already present. Skipping."
65 Info<< "Time = " << time().timeName() << endl
66 << "Adding zones and modifiers to the mesh" << endl;
69 List<pointZone*> pz(1);
71 // Add an empty zone for cut points
82 // Do face zones for slider
84 List<faceZone*> fz(3);
87 const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
88 const polyPatch& innerSlider =
89 boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
91 labelList isf(innerSlider.size());
95 isf[i] = innerSlider.start() + i;
102 boolList(innerSlider.size(), false),
108 const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
109 const polyPatch& outerSlider =
110 boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
112 labelList osf(outerSlider.size());
116 osf[i] = outerSlider.start() + i;
123 boolList(outerSlider.size(), false),
128 // Add empty zone for cut faces
138 List<cellZone*> cz(0);
140 Info << "Adding point, face and cell zones" << endl;
141 addZones(pz, fz, cz);
143 // Add a topology modifier
144 Info << "Adding topology modifiers" << endl;
145 topoChanger_.setSize(1);
154 outerSliderName + "Zone",
155 innerSliderName + "Zone",
160 slidingInterface::INTEGRAL,
161 true // Attach-detach action
164 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
171 void Foam::linearValveFvMesh::makeSlidersDead()
173 const polyTopoChanger& topoChanges = topoChanger_;
176 forAll (topoChanges, modI)
178 if (typeid(topoChanges[modI]) == typeid(slidingInterface))
180 topoChanges[modI].disable();
184 FatalErrorIn("void Foam::linearValveFvMesh::makeSlidersDead()")
185 << "Don't know what to do with mesh modifier "
186 << modI << " of type " << topoChanges[modI].type()
187 << abort(FatalError);
193 void Foam::linearValveFvMesh::makeSlidersLive()
195 const polyTopoChanger& topoChanges = topoChanger_;
197 // Enable sliding interface
198 forAll (topoChanges, modI)
200 if (typeid(topoChanges[modI]) == typeid(slidingInterface))
202 topoChanges[modI].enable();
206 FatalErrorIn("void Foam::linearValveFvMesh::makeLayersLive()")
207 << "Don't know what to do with mesh modifier "
208 << modI << " of type " << topoChanges[modI].type()
209 << abort(FatalError);
215 bool Foam::linearValveFvMesh::attached() const
217 const polyTopoChanger& topoChanges = topoChanger_;
221 forAll (topoChanges, modI)
223 if (typeid(topoChanges[modI]) == typeid(slidingInterface))
227 || refCast<const slidingInterface>(topoChanges[modI]).attached();
231 // Check thal all sliders are in sync (debug only)
232 forAll (topoChanges, modI)
234 if (typeid(topoChanges[modI]) == typeid(slidingInterface))
239 != refCast<const slidingInterface>(topoChanges[modI]).attached()
242 FatalErrorIn("bool linearValveFvMesh::attached() const")
243 << "Slider " << modI << " named " << topoChanges[modI].name()
244 << " out of sync: Should be" << result
245 << abort(FatalError);
252 Info << "linearValveFvMesh: attached!" << endl;
256 Info << "linearValveFvMesh: detached!" << endl;
263 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
265 // Construct from components
266 Foam::linearValveFvMesh::linearValveFvMesh(const IOobject& io)
268 topoChangerFvMesh(io),
281 ).subDict(typeName + "Coeffs")
283 msPtr_(motionSolver::New(*this))
285 addZonesAndModifiers();
289 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
291 Foam::linearValveFvMesh::~linearValveFvMesh()
295 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
297 void Foam::linearValveFvMesh::update()
299 // Detaching the interface
302 Info << "Decoupling sliding interfaces" << endl;
305 // Changing topology by hand
307 setMorphTimeIndex(3*time().timeIndex());
310 msPtr_->updateMesh();
314 Info << "Sliding interfaces decoupled" << endl;
317 // Perform mesh motion
320 // Changing topology by hand
322 setMorphTimeIndex(3*time().timeIndex() + 1);
325 msPtr_->updateMesh();
327 if (topoChangeMap.valid())
329 if (topoChangeMap().hasMotionPoints())
331 Info << "Topology change; executing pre-motion" << endl;
332 movePoints(topoChangeMap().preMotionPoints());
339 movePoints(msPtr_->curPoints());
341 // Attach the interface
342 Info << "Coupling sliding interfaces" << endl;
345 setMorphTimeIndex(3*time().timeIndex() + 2);
348 Info << "Moving points post slider attach" << endl;
350 msPtr_->updateMesh();
352 Info << "Sliding interfaces coupled: " << attached() << endl;
356 // ************************************************************************* //