1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "multiTopoBodyFvMesh.H"
28 #include "mapPolyMesh.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(multiTopoBodyFvMesh, 0);
37 addToRunTimeSelectionTable
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 void Foam::multiTopoBodyFvMesh::addZonesAndModifiers()
50 // Add zones and modifiers for motion action
52 if (!topoChanger_.empty())
54 Info<< "void multiTopoBodyFvMesh::addZonesAndModifiers() : "
55 << "Zones and modifiers already present. Skipping."
61 Info<< "Time = " << time().timeName() << endl
62 << "Adding zones and modifiers to the mesh. " << bodies_.size()
63 << " bodies found" << endl;
65 // Guess sizes of lists
66 DynamicList<pointZone*> pz(bodies_.size());
67 DynamicList<faceZone*> fz(4*bodies_.size() + faceZones().size());
68 DynamicList<cellZone*> cz(bodies_.size());
70 // Copy the face zones associated with the GGI interfaces
71 if (faceZones().size() > 0)
74 Info << "Copying existing point zones" << endl;
76 forAll (pointZones(), i)
78 pz.append(pointZones()[i].clone(pointZones()).ptr());
81 forAll (faceZones(), i)
83 fz.append(faceZones()[i].clone(faceZones()).ptr());
86 forAll (cellZones(), i)
88 cz.append(cellZones()[i].clone(cellZones()).ptr());
92 Info << "Adding point, face and cell zones" << endl;
93 forAll (bodies_, bodyI)
95 bodies_[bodyI].addZones(pz, fz, cz);
99 List<pointZone*> pzList;
100 pzList.transfer(pz.shrink());
102 List<faceZone*> fzList;
103 fzList.transfer(fz.shrink());
105 List<cellZone*> czList;
106 czList.transfer(cz.shrink());
109 addZones(pzList, fzList, czList);
114 topoChanger_.setSize(4*bodies_.size());
117 forAll (bodies_, bodyI)
119 bodies_[bodyI].addModifiers(topoChanger_, nextI);
122 Info<< "Adding topology modifiers. nModifiers = " << nextI << endl;
124 // Resize and set topo changer
125 topoChanger_.setSize(nextI);
126 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
127 topoChanger_.write();
130 // Write mesh with new zones, updating GGI zoning etc
137 Foam::tmp<Foam::vectorField> Foam::multiTopoBodyFvMesh::pointMotion() const
139 // Accumulate point motion
140 tmp<vectorField> tpointMotion
142 new vectorField(allPoints().size(), vector::zero)
145 vectorField& pointMotion = tpointMotion();
147 forAll (bodies_, bodyI)
149 pointMotion += bodies_[bodyI].pointMotion();
156 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
158 // Construct from components
159 Foam::multiTopoBodyFvMesh::multiTopoBodyFvMesh
164 topoChangerFvMesh(io),
177 ).subDict(typeName + "Coeffs")
181 // Read body entries from the dictionary
182 PtrList<entry> bodyEntries(dict_.lookup("bodies"));
183 bodies_.setSize(bodyEntries.size());
185 forAll (bodyEntries, bodyI)
192 bodyEntries[bodyI].keyword(),
194 bodyEntries[bodyI].dict()
199 addZonesAndModifiers();
203 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
205 Foam::multiTopoBodyFvMesh::~multiTopoBodyFvMesh()
209 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
211 bool Foam::multiTopoBodyFvMesh::update()
214 pointField oldPointsNew = allPoints();
215 pointField newPoints = allPoints() + pointMotion();
217 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
218 bool localMeshChanged = topoChangeMap->morphing();
219 bool globalMeshChanged = localMeshChanged;
220 reduce(globalMeshChanged, orOp<bool>());
222 if (globalMeshChanged)
224 forAll (bodies_, bodyI)
226 bodies_[bodyI].updateTopology();
230 if (localMeshChanged)
232 // Map old points onto the new mesh
233 // Not needed: only a single motion in time-step so old points
234 // are already in the correct postion for mesh motion.
236 // pointField mappedOldPointsNew(allPoints().size());
237 // mappedOldPointsNew.map(oldPointsNew, topoChangeMap->pointMap());
239 // // Note: using setOldPoints instead of movePoints.
240 // // HJ, 23/Aug/2015
241 // setOldPoints(mappedOldPointsNew);
245 // Get new points from preMotion
246 newPoints = topoChangeMap().preMotionPoints() + pointMotion();
250 // Topo change on other processors
253 Info << "Executing mesh motion" << endl;
254 movePoints(newPoints);
256 return localMeshChanged;
260 // ************************************************************************* //