Forward compatibility: flex
[foam-extend-3.2.git] / src / dynamicMesh / topoChangerFvMesh / multiTopoBodyFvMesh / multiTopoBodyFvMesh.C
blobf931abf6f453c97ac37be54193d1d690cab6a529
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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"
27 #include "foamTime.H"
28 #include "mapPolyMesh.H"
29 #include "volMesh.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(multiTopoBodyFvMesh, 0);
37     addToRunTimeSelectionTable
38     (
39         topoChangerFvMesh,
40         multiTopoBodyFvMesh,
41         IOobject
42     );
46 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
48 void Foam::multiTopoBodyFvMesh::addZonesAndModifiers()
50     // Add zones and modifiers for motion action
52     if (!topoChanger_.empty())
53     {
54         Info<< "void multiTopoBodyFvMesh::addZonesAndModifiers() : "
55             << "Zones and modifiers already present.  Skipping."
56             << endl;
58         return;
59     }
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)
72     {
73         // Copy point zones
74         Info << "Copying existing point zones" << endl;
76         forAll (pointZones(), i)
77         {
78             pz.append(pointZones()[i].clone(pointZones()).ptr());
79         }
81         forAll (faceZones(), i)
82         {
83             fz.append(faceZones()[i].clone(faceZones()).ptr());
84         }
86         forAll (cellZones(), i)
87         {
88             cz.append(cellZones()[i].clone(cellZones()).ptr());
89         }
90     }
92     Info << "Adding point, face and cell zones" << endl;
93     forAll (bodies_, bodyI)
94     {
95         bodies_[bodyI].addZones(pz, fz, cz);
96     }
98     {
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());
108         removeZones();
109         addZones(pzList, fzList, czList);
110     }
112     // Add modifiers
113     {
114         topoChanger_.setSize(4*bodies_.size());
115         label nextI = 0;
117         forAll (bodies_, bodyI)
118         {
119             bodies_[bodyI].addModifiers(topoChanger_, nextI);
120         }
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();
128     }
130     // Write mesh with new zones, updating GGI zoning etc
131     syncUpdateMesh();
133     write();
137 Foam::tmp<Foam::vectorField> Foam::multiTopoBodyFvMesh::pointMotion() const
139     // Accumulate point motion
140     tmp<vectorField> tpointMotion
141     (
142         new vectorField(allPoints().size(), vector::zero)
143     );
145     vectorField& pointMotion = tpointMotion();
147     forAll (bodies_, bodyI)
148     {
149         pointMotion += bodies_[bodyI].pointMotion();
150     }
152     return tpointMotion;
156 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
158 // Construct from components
159 Foam::multiTopoBodyFvMesh::multiTopoBodyFvMesh
161     const IOobject& io
164     topoChangerFvMesh(io),
165     dict_
166     (
167         IOdictionary
168         (
169             IOobject
170             (
171                 "dynamicMeshDict",
172                 time().constant(),
173                 *this,
174                 IOobject::MUST_READ,
175                 IOobject::NO_WRITE
176             )
177         ).subDict(typeName + "Coeffs")
178     ),
179     bodies_()
181     // Read body entries from the dictionary
182     PtrList<entry> bodyEntries(dict_.lookup("bodies"));
183     bodies_.setSize(bodyEntries.size());
185     forAll (bodyEntries, bodyI)
186     {
187         bodies_.set
188         (
189             bodyI,
190             new topoBody
191             (
192                 bodyEntries[bodyI].keyword(),
193                 *this,
194                 bodyEntries[bodyI].dict()
195             )
196         );
197     }
199     addZonesAndModifiers();
203 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
205 Foam::multiTopoBodyFvMesh::~multiTopoBodyFvMesh()
209 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
211 bool Foam::multiTopoBodyFvMesh::update()
213     // Save old points
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)
223     {
224         forAll (bodies_, bodyI)
225         {
226             bodies_[bodyI].updateTopology();
227         }
228     }
230     if (localMeshChanged)
231     {
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.
235         // HJ, 19/May/2014
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);
242 //         resetMotion();
243 //         setV0();
245         // Get new points from preMotion
246         newPoints = topoChangeMap().preMotionPoints() + pointMotion();
247     }
248     else
249     {
250         // Topo change on other processors
251     }
253     Info << "Executing mesh motion" << endl;
254     movePoints(newPoints);
256     return localMeshChanged;
260 // ************************************************************************* //