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 "linearValveLayersFvMesh.H"
29 #include "slidingInterface.H"
30 #include "layerAdditionRemoval.H"
31 #include "pointField.H"
32 #include "mapPolyMesh.H"
33 #include "polyTopoChange.H"
34 #include "addToRunTimeSelectionTable.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(linearValveLayersFvMesh, 0);
42 addToRunTimeSelectionTable(topoChangerFvMesh, linearValveLayersFvMesh, IOobject);
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 void Foam::linearValveLayersFvMesh::addZonesAndModifiers()
50 // Add zones and modifiers for motion action
57 || topoChanger_.size()
60 Info<< "void linearValveLayersFvMesh::addZonesAndModifiers() : "
61 << "Zones and modifiers already present. Skipping."
67 Info<< "Time = " << time().timeName() << endl
68 << "Adding zones and modifiers to the mesh" << endl;
71 List<pointZone*> pz(1);
72 List<faceZone*> fz(4);
73 List<cellZone*> cz(0);
76 // Add an empty zone for cut points
87 // Do face zones for slider
90 const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
91 const polyPatch& innerSlider =
92 boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
94 labelList isf(innerSlider.size());
98 isf[i] = innerSlider.start() + i;
105 boolList(innerSlider.size(), false),
111 const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
112 const polyPatch& outerSlider =
113 boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
115 labelList osf(outerSlider.size());
119 osf[i] = outerSlider.start() + i;
126 boolList(outerSlider.size(), false),
131 // Add empty zone for cut faces
141 // Add face zone for layer addition
142 const word layerPatchName
144 motionDict_.subDict("layer").lookup("patch")
147 const polyPatch& layerPatch =
148 boundaryMesh()[boundaryMesh().findPatchID(layerPatchName)];
150 labelList lpf(layerPatch.size());
154 lpf[i] = layerPatch.start() + i;
161 boolList(layerPatch.size(), true),
167 Info << "Adding point and face zones" << endl;
168 addZones(pz, fz, cz);
170 // Add a topology modifier
172 List<polyMeshModifier*> tm(2);
174 tm[0] = new slidingInterface
179 outerSliderName + "Zone",
180 innerSliderName + "Zone",
185 slidingInterface::INTEGRAL,
186 true // Attach-detach action
190 new layerAdditionRemoval
198 motionDict_.subDict("layer").lookup("minThickness")
202 motionDict_.subDict("layer").lookup("maxThickness")
207 Info << "Adding topology modifiers" << endl;
208 addTopologyModifiers(tm);
215 void Foam::linearValveLayersFvMesh::makeLayersLive()
217 const polyTopoChanger& topoChanges = topoChanger_;
220 forAll (topoChanges, modI)
222 if (typeid(topoChanges[modI]) == typeid(layerAdditionRemoval))
224 topoChanges[modI].enable();
226 else if (typeid(topoChanges[modI]) == typeid(slidingInterface))
228 topoChanges[modI].disable();
232 FatalErrorIn("void linearValveLayersFvMesh::makeLayersLive()")
233 << "Don't know what to do with mesh modifier "
234 << modI << " of type " << topoChanges[modI].type()
235 << abort(FatalError);
241 void Foam::linearValveLayersFvMesh::makeSlidersLive()
243 const polyTopoChanger& topoChanges = topoChanger_;
245 // Enable sliding interface
246 forAll (topoChanges, modI)
248 if (typeid(topoChanges[modI]) == typeid(layerAdditionRemoval))
250 topoChanges[modI].disable();
252 else if (typeid(topoChanges[modI]) == typeid(slidingInterface))
254 topoChanges[modI].enable();
258 FatalErrorIn("void linearValveLayersFvMesh::makeLayersLive()")
259 << "Don't know what to do with mesh modifier "
260 << modI << " of type " << topoChanges[modI].type()
261 << abort(FatalError);
267 bool Foam::linearValveLayersFvMesh::attached() const
269 const polyTopoChanger& topoChanges = topoChanger_;
273 forAll (topoChanges, modI)
275 if (typeid(topoChanges[modI]) == typeid(slidingInterface))
279 || refCast<const slidingInterface>(topoChanges[modI]).attached();
283 // Check thal all sliders are in sync (debug only)
284 forAll (topoChanges, modI)
286 if (typeid(topoChanges[modI]) == typeid(slidingInterface))
291 != refCast<const slidingInterface>(topoChanges[modI]).attached()
294 FatalErrorIn("bool linearValveLayersFvMesh::attached() const")
295 << "Slider " << modI << " named "
296 << topoChanges[modI].name()
297 << " out of sync: Should be" << result
298 << abort(FatalError);
307 Foam::tmp<Foam::pointField> Foam::linearValveLayersFvMesh::newPoints() const
309 tmp<pointField> tnewPoints
311 new pointField(points())
314 pointField& np = tnewPoints();
316 const word layerPatchName
318 motionDict_.subDict("layer").lookup("patch")
321 const polyPatch& layerPatch =
322 boundaryMesh()[boundaryMesh().findPatchID(layerPatchName)];
324 const labelList& patchPoints = layerPatch.meshPoints();
328 motionDict_.lookup("pistonVelocity")
331 forAll (patchPoints, ppI)
333 np[patchPoints[ppI]] += vel*time().deltaT().value();
341 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
343 // Construct from components
344 Foam::linearValveLayersFvMesh::linearValveLayersFvMesh(const IOobject& io)
346 topoChangerFvMesh(io),
359 ).subDict(typeName + "Coeffs")
362 addZonesAndModifiers();
366 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
368 Foam::linearValveLayersFvMesh::~linearValveLayersFvMesh()
371 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
373 void Foam::linearValveLayersFvMesh::update()
375 // Detaching the interface
378 Info << "Decoupling sliding interfaces" << endl;
383 setMorphTimeIndex(3*time().timeIndex());
388 Info << "Sliding interfaces decoupled" << endl;
391 // Perform layer action and mesh motion
396 setMorphTimeIndex(3*time().timeIndex() + 1);
399 if (topoChangeMap.valid())
401 if (topoChangeMap().hasMotionPoints())
403 Info << "Topology change; executing pre-motion" << endl;
404 movePoints(topoChangeMap().preMotionPoints());
409 movePoints(newPoints());
411 // Attach the interface
412 Info << "Coupling sliding interfaces" << endl;
417 setMorphTimeIndex(3*time().timeIndex() + 2);
420 Info << "Moving points post slider attach" << endl;
421 // const pointField p = allPoints();
424 Info << "Sliding interfaces coupled: " << attached() << endl;
428 // ************************************************************************* //