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
28 Takes a mesh and two patches and merges the faces on the two patches
29 (if geometrically possible) so the faces become internal.
32 - 'perfect' match: faces and points on patches align exactly. Order might
34 - 'integral' match: where the surfaces on both patches exactly
35 match but the individual faces not
36 - 'partial' match: where the non-overlapping part of the surface remains
37 in the respective patch.
39 Note : Is just a front-end to perfectInterface/slidingInterface.
41 Comparable to running a meshModifier of the form
42 (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
57 \*---------------------------------------------------------------------------*/
60 #include "polyTopoChanger.H"
61 #include "mapPolyMesh.H"
63 #include "slidingInterface.H"
64 #include "perfectInterface.H"
65 #include "IOobjectList.H"
66 #include "ReadFields.H"
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 // Checks whether patch present
72 void checkPatch(const polyBoundaryMesh& bMesh, const word& name)
74 label patchI = bMesh.findPatchID(name);
78 FatalErrorIn("checkPatch(const polyBoundaryMesh&, const word&)")
79 << "Cannot find patch " << name << endl
80 << "It should be present and of non-zero size" << endl
81 << "Valid patches are " << bMesh.names()
85 if (bMesh[patchI].empty())
87 FatalErrorIn("checkPatch(const polyBoundaryMesh&, const word&)")
88 << "Patch " << name << " is present but zero size"
96 int main(int argc, char *argv[])
98 Foam::argList::noParallel();
99 # include "addRegionOption.H"
100 Foam::argList::validArgs.append("masterPatch");
101 Foam::argList::validArgs.append("slavePatch");
103 Foam::argList::validOptions.insert("partial", "");
104 Foam::argList::validOptions.insert("perfect", "");
106 Foam::argList::validOptions.insert("overwrite", "");
108 # include "setRootCase.H"
109 # include "createTime.H"
110 runTime.functionObjects().off();
111 # include "createNamedMesh.H"
112 const word oldInstance = mesh.pointsInstance();
115 word masterPatchName(args.additionalArgs()[0]);
116 word slavePatchName(args.additionalArgs()[1]);
118 bool partialCover = args.optionFound("partial");
119 bool perfectCover = args.optionFound("perfect");
120 bool overwrite = args.optionFound("overwrite");
122 if (partialCover && perfectCover)
124 FatalErrorIn(args.executable())
125 << "Cannot both supply partial and perfect." << endl
126 << "Use perfect match option if the patches perfectly align"
127 << " (both vertex positions and face centres)" << endl
132 const word mergePatchName(masterPatchName + slavePatchName);
133 const word cutZoneName(mergePatchName + "CutFaceZone");
135 slidingInterface::typeOfMatch tom = slidingInterface::INTEGRAL;
139 Info<< "Coupling partially overlapping patches "
140 << masterPatchName << " and " << slavePatchName << nl
141 << "Resulting internal faces will be in faceZone " << cutZoneName
143 << "Any uncovered faces will remain in their patch"
146 tom = slidingInterface::PARTIAL;
148 else if (perfectCover)
150 Info<< "Coupling perfectly aligned patches "
151 << masterPatchName << " and " << slavePatchName << nl
152 << "Resulting (internal) faces will be in faceZone " << cutZoneName
154 << "Note: both patches need to align perfectly." << nl
156 << " positions and the face centres need to align to within" << nl
157 << "a tolerance given by the minimum edge length on the patch"
162 Info<< "Coupling patches " << masterPatchName << " and "
163 << slavePatchName << nl
164 << "Resulting (internal) faces will be in faceZone " << cutZoneName
166 << "Note: the overall area covered by both patches should be"
167 << " identical (\"integral\" interface)." << endl
168 << "If this is not the case use the -partial option" << nl << endl;
171 // Check for non-empty master and slave patches
172 checkPatch(mesh.boundaryMesh(), masterPatchName);
173 checkPatch(mesh.boundaryMesh(), slavePatchName);
175 // Create and add face zones and mesh modifiers
178 const polyPatch& masterPatch =
181 mesh.boundaryMesh().findPatchID(masterPatchName)
184 // Make list of masterPatch faces
185 labelList isf(masterPatch.size());
189 isf[i] = masterPatch.start() + i;
192 polyTopoChanger stitcher(mesh);
195 DynamicList<pointZone*> pz;
196 DynamicList<faceZone*> fz;
197 DynamicList<cellZone*> cz;
201 // Add empty zone for resulting internal faces
208 boolList(masterPatch.size(), false),
214 // Note: make sure to add the zones BEFORE constructing polyMeshModifier
215 // (since looks up various zones at construction time)
216 Info << "Adding point and face zones" << endl;
217 mesh.addZones(pz.shrink(), fz.shrink(), cz.shrink());
219 // Add the perfect interface mesh modifier
240 mergePatchName + "CutPointZone",
251 mergePatchName + "MasterZone",
253 boolList(masterPatch.size(), false),
260 const polyPatch& slavePatch =
263 mesh.boundaryMesh().findPatchID(slavePatchName)
266 labelList osf(slavePatch.size());
270 osf[i] = slavePatch.start() + i;
277 mergePatchName + "SlaveZone",
279 boolList(slavePatch.size(), false),
285 // Add empty zone for cut faces
299 // Note: make sure to add the zones BEFORE constructing
300 // polyMeshModifier (since looks up various zones at construction time)
301 Info << "Adding point and face zones" << endl;
302 mesh.addZones(pz.shrink(), fz.shrink(), cz.shrink());
304 // Add the sliding interface mesh modifier
313 mergePatchName + "MasterZone",
314 mergePatchName + "SlaveZone",
315 mergePatchName + "CutPointZone",
319 tom, // integral or partial
320 false, // Attach-detach action
321 intersection::VISIBLE
327 // Search for list of objects for this time
328 IOobjectList objects(mesh, runTime.timeName());
330 // Read all current fvFields so they will get mapped
331 Info<< "Reading all current volfields" << endl;
332 PtrList<volScalarField> volScalarFields;
333 ReadFields(mesh, objects, volScalarFields);
335 PtrList<volVectorField> volVectorFields;
336 ReadFields(mesh, objects, volVectorFields);
338 PtrList<volSphericalTensorField> volSphericalTensorFields;
339 ReadFields(mesh, objects, volSphericalTensorFields);
341 PtrList<volSymmTensorField> volSymmTensorFields;
342 ReadFields(mesh, objects, volSymmTensorFields);
344 PtrList<volTensorField> volTensorFields;
345 ReadFields(mesh, objects, volTensorFields);
347 //- uncomment if you want to interpolate surface fields (usually bad idea)
348 //Info<< "Reading all current surfaceFields" << endl;
349 //PtrList<surfaceScalarField> surfaceScalarFields;
350 //ReadFields(mesh, objects, surfaceScalarFields);
352 //PtrList<surfaceVectorField> surfaceVectorFields;
353 //ReadFields(mesh, objects, surfaceVectorFields);
355 //PtrList<surfaceTensorField> surfaceTensorFields;
356 //ReadFields(mesh, objects, surfaceTensorFields);
363 // Execute all polyMeshModifiers
364 autoPtr<mapPolyMesh> morphMap = stitcher.changeMesh();
366 mesh.movePoints(morphMap->preMotionPoints());
371 mesh.setInstance(oldInstance);
372 stitcher.instance() = oldInstance;
374 Info << nl << "Writing polyMesh to time " << runTime.timeName() << endl;
376 IOstream::defaultPrecision(10);
378 // Bypass runTime write (since only writes at outputTime)
381 !runTime.objectRegistry::writeObject
383 runTime.writeFormat(),
384 IOstream::currentVersion,
385 runTime.writeCompression()
389 FatalErrorIn(args.executable())
390 << "Failed writing polyMesh."
394 mesh.faceZones().write();
395 mesh.pointZones().write();
396 mesh.cellZones().write();
401 Info<< nl << "end" << endl;
407 // ************************************************************************* //