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 "sixDofTopoMotion.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "motionSolver.H"
30 #include "volFields.H"
33 #include "tetFemMatrices.H"
34 #include "tetPointFields.H"
35 #include "faceTetPolyPatch.H"
36 #include "fixedValueTetPolyPatchFields.H"
38 #include "incompressible/singlePhaseTransportModel/singlePhaseTransportModel.H"
40 #include "slidingInterface.H"
41 #include "mapPolyMesh.H"
43 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
47 defineTypeNameAndDebug(sixDofTopoMotion, 0);
49 addToRunTimeSelectionTable(dynamicFvMesh, sixDofTopoMotion, IOobject);
50 } // End namespace Foam
53 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
55 void Foam::sixDofTopoMotion::addZonesAndModifiers()
57 // Add zones and modifiers for motion action
63 pointZones().size() > 0
64 || faceZones().size() > 0
65 || cellZones().size() > 0
68 Info<< "void sixDofTopoMotion::addZonesAndModifiers() : "
69 << "Zones and modifiers already present. Skipping."
72 if (topoChanger_.size() == 0)
76 "void sixDofTopoMotion::addZonesAndModifiers()"
77 ) << "Mesh modifiers not read properly"
84 Info<< "Time = " << time().timeName() << endl
85 << "Adding zones and modifiers to the mesh" << endl;
88 List<pointZone*> pz(3*bodies_.size());
89 List<faceZone*> fz(3*bodies_.size());
90 List<cellZone*> cz(0);
96 forAll (bodies_, bodyI)
98 const floatingBody& curBody = bodies_[bodyI];
102 curBody.hullSlider().active()
103 && curBody.fixedSlider().active()
108 // Add an empty zone for cut points
109 pz[npz] = new pointZone
111 curBody.name() + "CutPointZone",
118 // Do face zones for slider
121 const polyPatch& innerSlider =
122 boundaryMesh()[curBody.hullSlider().index()];
124 labelList isf(innerSlider.size());
128 isf[i] = innerSlider.start() + i;
131 fz[nfz] = new faceZone
133 curBody.name() + "InsideSliderZone",
135 boolList(innerSlider.size(), false),
142 const polyPatch& outerSlider =
143 boundaryMesh()[curBody.fixedSlider().index()];
145 labelList osf(outerSlider.size());
149 osf[i] = outerSlider.start() + i;
152 fz[nfz] = new faceZone
154 curBody.name() + "OutsideSliderZone",
156 boolList(outerSlider.size(), false),
162 // Add empty zone for cut faces
163 fz[nfz] = new faceZone
165 curBody.name() + "CutFaceZone",
179 Info << "Adding point and face zones" << endl;
180 addZones(pz, fz, cz);
182 // Add topology modifiers
183 topoChanger_.setSize(nSliders);
186 forAll (bodies_, bodyI)
188 const floatingBody& curBody = bodies_[bodyI];
192 curBody.hullSlider().active()
193 && curBody.fixedSlider().active()
201 curBody.name() + "Slider",
204 curBody.name() + "OutsideSliderZone",
205 curBody.name() + "InsideSliderZone",
206 curBody.name() + "CutPointZone",
207 curBody.name() + "CutFaceZone",
208 curBody.fixedSlider().name(),
209 curBody.hullSlider().name(),
210 slidingInterface::INTEGRAL, // Edge matching algorithm
211 true, // Attach-detach action
212 intersection::VISIBLE // Projection algorithm
218 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
219 topoChanger_.write();
222 else if (topoChanger_.size() > 0)
224 if (topoChanger_.size() != 0)
228 "void sixDofTopoMotion::addZonesAndModifiers()"
229 ) << "Mesh modifiers are present and topo sliding is set to off"
230 << abort(FatalError);
236 bool Foam::sixDofTopoMotion::attached() const
238 const polyTopoChanger& topoChanges = topoChanger_;
242 forAll (topoChanges, modI)
244 if (typeid(topoChanges[modI]) == typeid(slidingInterface))
248 || refCast<const slidingInterface>(topoChanges[modI]).attached();
256 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
258 Foam::sixDofTopoMotion::sixDofTopoMotion(const IOobject& io)
260 topoChangerFvMesh(io),
273 ).subDict(typeName + "Coeffs")
275 bodies_(*this, dict_.lookup("bodies")),
276 useTopoSliding_(dict_.lookup("useTopoSliding")),
277 motionPtr_(motionSolver::New(*this))
279 addZonesAndModifiers();
283 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
285 Foam::sixDofTopoMotion::~sixDofTopoMotion()
289 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
291 bool Foam::sixDofTopoMotion::update()
293 // Detaching the interface
298 // Changing topology by hand
299 autoPtr<mapPolyMesh> topoChangeMap1 = topoChanger_.changeMesh();
301 if (topoChangeMap1.valid())
303 Info << "Decoupling sliding interfaces" << endl;
304 motionPtr_->updateMesh(topoChangeMap1());
309 Info << "Sliding interfaces decoupled" << endl;
313 // Set the motion onto the motion patch
314 tetPointVectorField& motionU =
315 const_cast<tetPointVectorField&>
317 this->objectRegistry::lookupObject<tetPointVectorField>("motionU")
320 // Set motion from bodies
321 bodies_.setMotion(motionU);
324 pointField oldPointsNew = allPoints();
326 // Calculate the motion and move points
327 movePoints(motionPtr_->newPoints());
329 // Attach the interface
330 // Changing topology by hand
333 autoPtr<mapPolyMesh> topoChangeMap2 = topoChanger_.changeMesh();
335 bool meshChanged2 = topoChangeMap2.valid();
339 Info << "Coupling sliding interfaces" << endl;
340 motionPtr_->updateMesh(topoChangeMap2());
344 Info << "Moving points post slider attach" << endl;
347 pointField mappedOldPointsNew(allPoints().size());
348 mappedOldPointsNew.map(oldPointsNew, topoChangeMap2->pointMap());
350 movePoints(mappedOldPointsNew);
354 movePoints(topoChangeMap2->preMotionPoints());
357 // Topological change: return true
367 // ************************************************************************* //