1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
27 Takes a mesh and two patches and merges the faces on the two patches
28 (if geometrically possible) so the faces become internal.
31 - 'perfect' match: faces and points on patches align exactly. Order might
33 - 'integral' match: where the surfaces on both patches exactly
34 match but the individual faces not
35 - 'partial' match: where the non-overlapping part of the surface remains
36 in the respective patch.
38 Note : Is just a front-end to perfectInterface/slidingInterface.
40 Comparable to running a meshModifier of the form
41 (if masterPatch is called "M" and slavePatch "S"):
46 type slidingInterface;
47 masterFaceZoneName MSMasterZone
48 slaveFaceZoneName MSSlaveZone
49 cutPointZoneName MSCutPointZone
50 cutFaceZoneName MSCutFaceZone
53 typeOfMatch partial or integral
58 \*---------------------------------------------------------------------------*/
61 #include "polyTopoChanger.H"
62 #include "mapPolyMesh.H"
64 #include "slidingInterface.H"
65 #include "perfectInterface.H"
66 #include "IOobjectList.H"
67 #include "ReadFields.H"
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 label addPointZone(const polyMesh& mesh, const word& name)
74 label zoneID = mesh.pointZones().findZoneID(name);
78 Info<< "Reusing existing pointZone "
79 << mesh.pointZones()[zoneID].name()
80 << " at index " << zoneID << endl;
84 pointZoneMesh& pointZones = const_cast<polyMesh&>(mesh).pointZones();
85 zoneID = pointZones.size();
86 Info<< "Adding pointZone " << name << " at index " << zoneID << endl;
88 pointZones.setSize(zoneID+1);
105 label addFaceZone(const polyMesh& mesh, const word& name)
107 label zoneID = mesh.faceZones().findZoneID(name);
111 Info<< "Reusing existing faceZone " << mesh.faceZones()[zoneID].name()
112 << " at index " << zoneID << endl;
116 faceZoneMesh& faceZones = const_cast<polyMesh&>(mesh).faceZones();
117 zoneID = faceZones.size();
118 Info<< "Adding faceZone " << name << " at index " << zoneID << endl;
120 faceZones.setSize(zoneID+1);
138 label addCellZone(const polyMesh& mesh, const word& name)
140 label zoneID = mesh.cellZones().findZoneID(name);
144 Info<< "Reusing existing cellZone " << mesh.cellZones()[zoneID].name()
145 << " at index " << zoneID << endl;
149 cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh).cellZones();
150 zoneID = cellZones.size();
151 Info<< "Adding cellZone " << name << " at index " << zoneID << endl;
153 cellZones.setSize(zoneID+1);
170 // Checks whether patch present
171 void checkPatch(const polyBoundaryMesh& bMesh, const word& name)
173 const label patchI = bMesh.findPatchID(name);
177 FatalErrorIn("checkPatch(const polyBoundaryMesh&, const word&)")
178 << "Cannot find patch " << name << endl
179 << "It should be present and of non-zero size" << endl
180 << "Valid patches are " << bMesh.names()
184 if (bMesh[patchI].empty())
186 FatalErrorIn("checkPatch(const polyBoundaryMesh&, const word&)")
187 << "Patch " << name << " is present but zero size"
195 int main(int argc, char *argv[])
199 "merge the faces on the specified patches (if geometrically possible)\n"
200 "so the faces become internal"
203 argList::noParallel();
204 #include "addOverwriteOption.H"
205 #include "addRegionOption.H"
207 argList::validArgs.append("masterPatch");
208 argList::validArgs.append("slavePatch");
210 argList::addBoolOption
213 "couple partially overlapping patches"
215 argList::addBoolOption
218 "couple perfectly aligned patches"
224 "dictionary file with tolerances"
227 #include "setRootCase.H"
228 #include "createTime.H"
229 runTime.functionObjects().off();
230 #include "createNamedMesh.H"
232 const word oldInstance = mesh.pointsInstance();
234 const word masterPatchName = args[1];
235 const word slavePatchName = args[2];
237 const bool partialCover = args.optionFound("partial");
238 const bool perfectCover = args.optionFound("perfect");
239 const bool overwrite = args.optionFound("overwrite");
241 if (partialCover && perfectCover)
243 FatalErrorIn(args.executable())
244 << "Cannot supply both partial and perfect." << endl
245 << "Use perfect match option if the patches perfectly align"
246 << " (both vertex positions and face centres)" << endl
251 const word mergePatchName(masterPatchName + slavePatchName);
252 const word cutZoneName(mergePatchName + "CutFaceZone");
254 slidingInterface::typeOfMatch tom = slidingInterface::INTEGRAL;
258 Info<< "Coupling partially overlapping patches "
259 << masterPatchName << " and " << slavePatchName << nl
260 << "Resulting internal faces will be in faceZone " << cutZoneName
262 << "Any uncovered faces will remain in their patch"
265 tom = slidingInterface::PARTIAL;
267 else if (perfectCover)
269 Info<< "Coupling perfectly aligned patches "
270 << masterPatchName << " and " << slavePatchName << nl
271 << "Resulting (internal) faces will be in faceZone " << cutZoneName
273 << "Note: both patches need to align perfectly." << nl
275 << " positions and the face centres need to align to within" << nl
276 << "a tolerance given by the minimum edge length on the patch"
281 Info<< "Coupling patches " << masterPatchName << " and "
282 << slavePatchName << nl
283 << "Resulting (internal) faces will be in faceZone " << cutZoneName
285 << "Note: the overall area covered by both patches should be"
286 << " identical (\"integral\" interface)." << endl
287 << "If this is not the case use the -partial option" << nl << endl;
290 // set up the tolerances for the sliding mesh
291 dictionary slidingTolerances;
292 if (args.options().found("toleranceDict"))
294 IOdictionary toleranceFile
298 args.options()["toleranceDict"],
301 IOobject::MUST_READ_IF_MODIFIED,
305 slidingTolerances += toleranceFile;
308 // Check for non-empty master and slave patches
309 checkPatch(mesh.boundaryMesh(), masterPatchName);
310 checkPatch(mesh.boundaryMesh(), slavePatchName);
312 // Create and add face zones and mesh modifiers
315 const polyPatch& masterPatch = mesh.boundaryMesh()[masterPatchName];
317 // Make list of masterPatch faces
318 labelList isf(masterPatch.size());
322 isf[i] = masterPatch.start() + i;
325 polyTopoChanger stitcher(mesh);
328 mesh.pointZones().clearAddressing();
329 mesh.faceZones().clearAddressing();
330 mesh.cellZones().clearAddressing();
334 // Add empty zone for resulting internal faces
335 label cutZoneID = addFaceZone(mesh, cutZoneName);
337 mesh.faceZones()[cutZoneID].resetAddressing
340 boolList(masterPatch.size(), false)
343 // Add the perfect interface mesh modifier
360 label pointZoneID = addPointZone(mesh, mergePatchName + "CutPointZone");
361 mesh.pointZones()[pointZoneID] = labelList(0);
363 label masterZoneID = addFaceZone(mesh, mergePatchName + "MasterZone");
365 mesh.faceZones()[masterZoneID].resetAddressing
368 boolList(masterPatch.size(), false)
372 const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchName];
374 labelList osf(slavePatch.size());
378 osf[i] = slavePatch.start() + i;
381 label slaveZoneID = addFaceZone(mesh, mergePatchName + "SlaveZone");
382 mesh.faceZones()[slaveZoneID].resetAddressing
385 boolList(slavePatch.size(), false)
388 // Add empty zone for cut faces
389 label cutZoneID = addFaceZone(mesh, cutZoneName);
390 mesh.faceZones()[cutZoneID].resetAddressing
397 // Add the sliding interface mesh modifier
406 mergePatchName + "MasterZone",
407 mergePatchName + "SlaveZone",
408 mergePatchName + "CutPointZone",
412 tom, // integral or partial
413 true // couple/decouple mode
416 static_cast<slidingInterface&>(stitcher[0]).setTolerances
424 // Search for list of objects for this time
425 IOobjectList objects(mesh, runTime.timeName());
427 // Read all current fvFields so they will get mapped
428 Info<< "Reading all current volfields" << endl;
429 PtrList<volScalarField> volScalarFields;
430 ReadFields(mesh, objects, volScalarFields);
432 PtrList<volVectorField> volVectorFields;
433 ReadFields(mesh, objects, volVectorFields);
435 PtrList<volSphericalTensorField> volSphericalTensorFields;
436 ReadFields(mesh, objects, volSphericalTensorFields);
438 PtrList<volSymmTensorField> volSymmTensorFields;
439 ReadFields(mesh, objects, volSymmTensorFields);
441 PtrList<volTensorField> volTensorFields;
442 ReadFields(mesh, objects, volTensorFields);
444 //- uncomment if you want to interpolate surface fields (usually bad idea)
445 //Info<< "Reading all current surfaceFields" << endl;
446 //PtrList<surfaceScalarField> surfaceScalarFields;
447 //ReadFields(mesh, objects, surfaceScalarFields);
449 //PtrList<surfaceVectorField> surfaceVectorFields;
450 //ReadFields(mesh, objects, surfaceVectorFields);
452 //PtrList<surfaceTensorField> surfaceTensorFields;
453 //ReadFields(mesh, objects, surfaceTensorFields);
460 // Execute all polyMeshModifiers
461 autoPtr<mapPolyMesh> morphMap = stitcher.changeMesh(true);
463 mesh.movePoints(morphMap->preMotionPoints());
468 mesh.setInstance(oldInstance);
469 stitcher.instance() = oldInstance;
471 Info<< nl << "Writing polyMesh to time " << runTime.timeName() << endl;
473 IOstream::defaultPrecision(10);
475 // Bypass runTime write (since only writes at outputTime)
478 !runTime.objectRegistry::writeObject
480 runTime.writeFormat(),
481 IOstream::currentVersion,
482 runTime.writeCompression()
486 FatalErrorIn(args.executable())
487 << "Failed writing polyMesh."
491 mesh.faceZones().write();
492 mesh.pointZones().write();
493 mesh.cellZones().write();
498 Info<< nl << "end" << endl;
504 // ************************************************************************* //