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 "linearValveLayersFvMesh.H"
27 #include <OpenFOAM/Time.H>
28 #include <dynamicMesh/slidingInterface.H>
29 #include <dynamicMesh/layerAdditionRemoval.H>
30 #include <OpenFOAM/pointField.H>
31 #include <OpenFOAM/mapPolyMesh.H>
32 #include <dynamicMesh/polyTopoChange.H>
33 #include <OpenFOAM/addToRunTimeSelectionTable.H>
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(linearValveLayersFvMesh, 0);
41 addToRunTimeSelectionTable(topoChangerFvMesh, linearValveLayersFvMesh, IOobject);
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 void Foam::linearValveLayersFvMesh::addZonesAndModifiers()
49 // Add zones and modifiers for motion action
56 || topoChanger_.size()
59 Info<< "void linearValveLayersFvMesh::addZonesAndModifiers() : "
60 << "Zones and modifiers already present. Skipping."
66 Info<< "Time = " << time().timeName() << endl
67 << "Adding zones and modifiers to the mesh" << endl;
70 List<pointZone*> pz(1);
71 List<faceZone*> fz(4);
72 List<cellZone*> cz(0);
75 // Add an empty zone for cut points
86 // Do face zones for slider
89 const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
90 const polyPatch& innerSlider =
91 boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
93 labelList isf(innerSlider.size());
97 isf[i] = innerSlider.start() + i;
104 boolList(innerSlider.size(), false),
110 const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
111 const polyPatch& outerSlider =
112 boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
114 labelList osf(outerSlider.size());
118 osf[i] = outerSlider.start() + i;
125 boolList(outerSlider.size(), false),
130 // Add empty zone for cut faces
140 // Add face zone for layer addition
141 const word layerPatchName
143 motionDict_.subDict("layer").lookup("patch")
146 const polyPatch& layerPatch =
147 boundaryMesh()[boundaryMesh().findPatchID(layerPatchName)];
149 labelList lpf(layerPatch.size());
153 lpf[i] = layerPatch.start() + i;
160 boolList(layerPatch.size(), true),
166 Info << "Adding point and face zones" << endl;
167 addZones(pz, fz, cz);
169 // Add a topology modifier
171 List<polyMeshModifier*> tm(2);
173 tm[0] = new slidingInterface
178 outerSliderName + "Zone",
179 innerSliderName + "Zone",
184 slidingInterface::INTEGRAL,
185 true // Attach-detach action
189 new layerAdditionRemoval
197 motionDict_.subDict("layer").lookup("minThickness")
201 motionDict_.subDict("layer").lookup("maxThickness")
206 Info << "Adding topology modifiers" << endl;
207 addTopologyModifiers(tm);
214 void Foam::linearValveLayersFvMesh::makeLayersLive()
216 const polyTopoChanger& topoChanges = topoChanger_;
219 forAll (topoChanges, modI)
221 if (isA<layerAdditionRemoval>(topoChanges[modI]))
223 topoChanges[modI].enable();
225 else if (isA<slidingInterface>(topoChanges[modI]))
227 topoChanges[modI].disable();
231 FatalErrorIn("void linearValveLayersFvMesh::makeLayersLive()")
232 << "Don't know what to do with mesh modifier "
233 << modI << " of type " << topoChanges[modI].type()
234 << abort(FatalError);
240 void Foam::linearValveLayersFvMesh::makeSlidersLive()
242 const polyTopoChanger& topoChanges = topoChanger_;
244 // Enable sliding interface
245 forAll (topoChanges, modI)
247 if (isA<layerAdditionRemoval>(topoChanges[modI]))
249 topoChanges[modI].disable();
251 else if (isA<slidingInterface>(topoChanges[modI]))
253 topoChanges[modI].enable();
257 FatalErrorIn("void linearValveLayersFvMesh::makeLayersLive()")
258 << "Don't know what to do with mesh modifier "
259 << modI << " of type " << topoChanges[modI].type()
260 << abort(FatalError);
266 bool Foam::linearValveLayersFvMesh::attached() const
268 const polyTopoChanger& topoChanges = topoChanger_;
272 forAll (topoChanges, modI)
274 if (isA<slidingInterface>(topoChanges[modI]))
278 || refCast<const slidingInterface>(topoChanges[modI]).attached();
282 // Check thal all sliders are in sync (debug only)
283 forAll (topoChanges, modI)
285 if (isA<slidingInterface>(topoChanges[modI]))
290 != refCast<const slidingInterface>(topoChanges[modI]).attached()
293 FatalErrorIn("bool linearValveLayersFvMesh::attached() const")
294 << "Slider " << modI << " named "
295 << topoChanges[modI].name()
296 << " out of sync: Should be" << result
297 << abort(FatalError);
306 Foam::tmp<Foam::pointField> Foam::linearValveLayersFvMesh::newPoints() const
308 tmp<pointField> tnewPoints
310 new pointField(points())
313 pointField& np = tnewPoints();
315 const word layerPatchName
317 motionDict_.subDict("layer").lookup("patch")
320 const polyPatch& layerPatch =
321 boundaryMesh()[boundaryMesh().findPatchID(layerPatchName)];
323 const labelList& patchPoints = layerPatch.meshPoints();
327 motionDict_.lookup("pistonVelocity")
330 forAll (patchPoints, ppI)
332 np[patchPoints[ppI]] += vel*time().deltaT().value();
340 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
342 // Construct from components
343 Foam::linearValveLayersFvMesh::linearValveLayersFvMesh(const IOobject& io)
345 topoChangerFvMesh(io),
358 ).subDict(typeName + "Coeffs")
361 addZonesAndModifiers();
365 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
367 Foam::linearValveLayersFvMesh::~linearValveLayersFvMesh()
370 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
372 void Foam::linearValveLayersFvMesh::update()
374 // Detaching the interface
377 Info << "Decoupling sliding interfaces" << endl;
382 setMorphTimeIndex(3*time().timeIndex());
387 Info << "Sliding interfaces decoupled" << endl;
390 // Perform layer action and mesh motion
395 setMorphTimeIndex(3*time().timeIndex() + 1);
398 if (topoChangeMap.valid())
400 if (topoChangeMap().hasMotionPoints())
402 Info << "Topology change; executing pre-motion" << endl;
403 movePoints(topoChangeMap().preMotionPoints());
408 movePoints(newPoints());
410 // Attach the interface
411 Info << "Coupling sliding interfaces" << endl;
416 setMorphTimeIndex(3*time().timeIndex() + 2);
419 Info << "Moving points post slider attach" << endl;
420 // const pointField p = allPoints();
423 Info << "Sliding interfaces coupled: " << attached() << endl;
427 // ************************ vim: set sw=4 sts=4 et: ************************ //