1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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"
35 #include "addToRunTimeSelectionTable.H"
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(linearValveLayersFvMesh, 0);
43 addToRunTimeSelectionTable
46 linearValveLayersFvMesh,
52 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54 void Foam::linearValveLayersFvMesh::addZonesAndModifiers()
56 // Add zones and modifiers for motion action
60 pointZones().size() > 0
61 || faceZones().size() > 0
62 || cellZones().size() > 0
65 Info<< "void linearValveLayersFvMesh::addZonesAndModifiers() : "
66 << "Zones and modifiers already present. Skipping."
69 if (topoChanger_.size() == 0)
73 "void linearValveLayersFvMesh::addZonesAndModifiers()"
74 ) << "Mesh modifiers not read properly"
81 Info<< "Time = " << time().timeName() << endl
82 << "Adding zones and modifiers to the mesh" << endl;
85 List<pointZone*> pz(1);
86 List<faceZone*> fz(4);
87 List<cellZone*> cz(0);
90 // Add an empty zone for cut points
101 // Do face zones for slider
104 const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
105 const polyPatch& innerSlider =
106 boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
108 labelList isf(innerSlider.size());
112 isf[i] = innerSlider.start() + i;
119 boolList(innerSlider.size(), false),
125 const word outerSliderName
127 motionDict_.subDict("slider").lookup("outside")
130 const polyPatch& outerSlider =
131 boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
133 labelList osf(outerSlider.size());
137 osf[i] = outerSlider.start() + i;
144 boolList(outerSlider.size(), false),
149 // Add empty zone for cut faces
159 // Add face zone for layer addition
160 const word layerPatchName
162 motionDict_.subDict("layer").lookup("patch")
165 const polyPatch& layerPatch =
166 boundaryMesh()[boundaryMesh().findPatchID(layerPatchName)];
168 labelList lpf(layerPatch.size());
172 lpf[i] = layerPatch.start() + i;
179 boolList(layerPatch.size(), true),
185 Info << "Adding point and face zones" << endl;
186 addZones(pz, fz, cz);
188 // Add a topology modifier
189 topoChanger_.setSize(2);
198 outerSliderName + "Zone",
199 innerSliderName + "Zone",
204 slidingInterface::INTEGRAL, // Edge matching algorithm
205 true, // Attach-detach action
206 intersection::VISIBLE // Projection algorithm
213 new layerAdditionRemoval
221 motionDict_.subDict("layer").lookup("minThickness")
225 motionDict_.subDict("layer").lookup("maxThickness")
230 // Write mesh and modifiers
231 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
232 topoChanger_.write();
237 void Foam::linearValveLayersFvMesh::makeLayersLive()
239 const polyTopoChanger& topoChanges = topoChanger_;
242 forAll (topoChanges, modI)
244 if (isA<layerAdditionRemoval>(topoChanges[modI]))
246 topoChanges[modI].enable();
248 else if (isA<slidingInterface>(topoChanges[modI]))
250 topoChanges[modI].disable();
254 FatalErrorIn("void linearValveLayersFvMesh::makeLayersLive()")
255 << "Don't know what to do with mesh modifier "
256 << modI << " of type " << topoChanges[modI].type()
257 << abort(FatalError);
263 void Foam::linearValveLayersFvMesh::makeSlidersLive()
265 const polyTopoChanger& topoChanges = topoChanger_;
267 // Enable sliding interface
268 forAll (topoChanges, modI)
270 if (isA<layerAdditionRemoval>(topoChanges[modI]))
272 topoChanges[modI].disable();
274 else if (isA<slidingInterface>(topoChanges[modI]))
276 topoChanges[modI].enable();
280 FatalErrorIn("void linearValveLayersFvMesh::makeLayersLive()")
281 << "Don't know what to do with mesh modifier "
282 << modI << " of type " << topoChanges[modI].type()
283 << abort(FatalError);
289 bool Foam::linearValveLayersFvMesh::attached() const
291 const polyTopoChanger& topoChanges = topoChanger_;
295 forAll (topoChanges, modI)
297 if (isA<slidingInterface>(topoChanges[modI]))
301 || refCast<const slidingInterface>(topoChanges[modI]).attached();
305 // Check thal all sliders are in sync (debug only)
306 forAll (topoChanges, modI)
308 if (isA<slidingInterface>(topoChanges[modI]))
313 != refCast<const slidingInterface>(topoChanges[modI]).attached()
316 FatalErrorIn("bool linearValveLayersFvMesh::attached() const")
317 << "Slider " << modI << " named "
318 << topoChanges[modI].name()
319 << " out of sync: Should be" << result
320 << abort(FatalError);
329 Foam::tmp<Foam::pointField> Foam::linearValveLayersFvMesh::newPoints() const
331 tmp<pointField> tnewPoints
333 new pointField(points())
336 pointField& np = tnewPoints();
338 const word layerPatchName
340 motionDict_.subDict("layer").lookup("patch")
343 const polyPatch& layerPatch =
344 boundaryMesh()[boundaryMesh().findPatchID(layerPatchName)];
346 const labelList& patchPoints = layerPatch.meshPoints();
350 motionDict_.lookup("pistonVelocity")
353 forAll (patchPoints, ppI)
355 np[patchPoints[ppI]] += vel*time().deltaT().value();
363 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
365 // Construct from components
366 Foam::linearValveLayersFvMesh::linearValveLayersFvMesh(const IOobject& io)
368 topoChangerFvMesh(io),
381 ).subDict(typeName + "Coeffs")
384 addZonesAndModifiers();
388 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
390 Foam::linearValveLayersFvMesh::~linearValveLayersFvMesh()
394 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
396 bool Foam::linearValveLayersFvMesh::update()
398 // Detaching the interface
401 Info << "Decoupling sliding interfaces" << endl;
404 // Changing topology by hand
405 topoChanger_.changeMesh();
409 Info << "Sliding interfaces decoupled" << endl;
412 // Perform layer action and mesh motion
415 // Changing topology by hand
417 autoPtr<mapPolyMesh> topoChangeMap2 = topoChanger_.changeMesh();
419 if (topoChangeMap2->morphing())
421 if (topoChangeMap2->hasMotionPoints())
423 Info << "Topology change; executing pre-motion" << endl;
424 movePoints(topoChangeMap2->preMotionPoints());
430 movePoints(newPoints());
432 // Attach the interface
433 Info << "Coupling sliding interfaces" << endl;
436 // Changing topology by hand
438 // Grab old points to correct the motion
439 pointField oldPointsNew = oldAllPoints();
441 autoPtr<mapPolyMesh> topoChangeMap3 = topoChanger_.changeMesh();
443 if (topoChangeMap3->morphing())
447 Info << "Moving points post slider attach" << endl;
450 pointField newPoints = allPoints();
451 pointField mappedOldPointsNew(newPoints.size());
453 mappedOldPointsNew.map(oldPointsNew, topoChangeMap3->pointMap());
455 // Solve the correct mesh motion to make sure motion fluxes
456 // are solved for and not mapped
457 movePoints(mappedOldPointsNew);
460 movePoints(newPoints);
468 // ************************************************************************* //