00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #include "fvCFD.H"
00060 #include "polyTopoChanger.H"
00061 #include "mapPolyMesh.H"
00062 #include "ListOps.H"
00063 #include "slidingInterface.H"
00064 #include "perfectInterface.H"
00065 #include "IOobjectList.H"
00066 #include "ReadFields.H"
00067
00068
00069
00070
00071
00072 void checkPatch(const polyBoundaryMesh& bMesh, const word& name)
00073 {
00074 label patchI = bMesh.findPatchID(name);
00075
00076 if (patchI == -1)
00077 {
00078 FatalErrorIn("checkPatch(const polyBoundaryMesh&, const word&)")
00079 << "Cannot find patch " << name << endl
00080 << "It should be present and of non-zero size" << endl
00081 << "Valid patches are " << bMesh.names()
00082 << exit(FatalError);
00083 }
00084
00085 if (bMesh[patchI].empty())
00086 {
00087 FatalErrorIn("checkPatch(const polyBoundaryMesh&, const word&)")
00088 << "Patch " << name << " is present but zero size"
00089 << exit(FatalError);
00090 }
00091 }
00092
00093
00094
00095
00096 int main(int argc, char *argv[])
00097 {
00098 Foam::argList::noParallel();
00099
00100 Foam::argList::validArgs.append("masterPatch");
00101 Foam::argList::validArgs.append("slavePatch");
00102
00103 Foam::argList::validOptions.insert("partial", "");
00104 Foam::argList::validOptions.insert("perfect", "");
00105
00106 Foam::argList::validOptions.insert("overwrite", "");
00107
00108 # include "setRootCase.H"
00109 # include "createTime.H"
00110 runTime.functionObjects().off();
00111 # include "createMesh.H"
00112 const word oldInstance = mesh.pointsInstance();
00113
00114
00115 word masterPatchName(args.additionalArgs()[0]);
00116 word slavePatchName(args.additionalArgs()[1]);
00117
00118 bool partialCover = args.optionFound("partial");
00119 bool perfectCover = args.optionFound("perfect");
00120 bool overwrite = args.optionFound("overwrite");
00121
00122 if (partialCover && perfectCover)
00123 {
00124 FatalErrorIn(args.executable())
00125 << "Cannot both supply partial and perfect." << endl
00126 << "Use perfect match option if the patches perfectly align"
00127 << " (both vertex positions and face centres)" << endl
00128 << exit(FatalError);
00129 }
00130
00131
00132 const word mergePatchName(masterPatchName + slavePatchName);
00133 const word cutZoneName(mergePatchName + "CutFaceZone");
00134
00135 slidingInterface::typeOfMatch tom = slidingInterface::INTEGRAL;
00136
00137 if (partialCover)
00138 {
00139 Info<< "Coupling partially overlapping patches "
00140 << masterPatchName << " and " << slavePatchName << nl
00141 << "Resulting internal faces will be in faceZone " << cutZoneName
00142 << nl
00143 << "Any uncovered faces will remain in their patch"
00144 << endl;
00145
00146 tom = slidingInterface::PARTIAL;
00147 }
00148 else if (perfectCover)
00149 {
00150 Info<< "Coupling perfectly aligned patches "
00151 << masterPatchName << " and " << slavePatchName << nl
00152 << "Resulting (internal) faces will be in faceZone " << cutZoneName
00153 << nl << nl
00154 << "Note: both patches need to align perfectly." << nl
00155 << "Both the vertex"
00156 << " positions and the face centres need to align to within" << nl
00157 << "a tolerance given by the minimum edge length on the patch"
00158 << endl;
00159 }
00160 else
00161 {
00162 Info<< "Coupling patches " << masterPatchName << " and "
00163 << slavePatchName << nl
00164 << "Resulting (internal) faces will be in faceZone " << cutZoneName
00165 << nl << nl
00166 << "Note: the overall area covered by both patches should be"
00167 << " identical (\"integral\" interface)." << endl
00168 << "If this is not the case use the -partial option" << nl << endl;
00169 }
00170
00171
00172 checkPatch(mesh.boundaryMesh(), masterPatchName);
00173 checkPatch(mesh.boundaryMesh(), slavePatchName);
00174
00175
00176
00177
00178 const polyPatch& masterPatch =
00179 mesh.boundaryMesh()
00180 [
00181 mesh.boundaryMesh().findPatchID(masterPatchName)
00182 ];
00183
00184
00185 labelList isf(masterPatch.size());
00186
00187 forAll (isf, i)
00188 {
00189 isf[i] = masterPatch.start() + i;
00190 }
00191
00192 polyTopoChanger stitcher(mesh);
00193 stitcher.setSize(1);
00194
00195 DynamicList<pointZone*> pz;
00196 DynamicList<faceZone*> fz;
00197 DynamicList<cellZone*> cz;
00198
00199 if (perfectCover)
00200 {
00201
00202 fz.append
00203 (
00204 new faceZone
00205 (
00206 cutZoneName,
00207 isf,
00208 boolList(masterPatch.size(), false),
00209 0,
00210 mesh.faceZones()
00211 )
00212 );
00213
00214
00215
00216 Info << "Adding point and face zones" << endl;
00217 mesh.addZones(pz.shrink(), fz.shrink(), cz.shrink());
00218
00219
00220 stitcher.set
00221 (
00222 0,
00223 new perfectInterface
00224 (
00225 "couple",
00226 0,
00227 stitcher,
00228 cutZoneName,
00229 masterPatchName,
00230 slavePatchName
00231 )
00232 );
00233 }
00234 else
00235 {
00236 pz.append
00237 (
00238 new pointZone
00239 (
00240 mergePatchName + "CutPointZone",
00241 labelList(0),
00242 0,
00243 mesh.pointZones()
00244 )
00245 );
00246
00247 fz.append
00248 (
00249 new faceZone
00250 (
00251 mergePatchName + "MasterZone",
00252 isf,
00253 boolList(masterPatch.size(), false),
00254 0,
00255 mesh.faceZones()
00256 )
00257 );
00258
00259
00260 const polyPatch& slavePatch =
00261 mesh.boundaryMesh()
00262 [
00263 mesh.boundaryMesh().findPatchID(slavePatchName)
00264 ];
00265
00266 labelList osf(slavePatch.size());
00267
00268 forAll (osf, i)
00269 {
00270 osf[i] = slavePatch.start() + i;
00271 }
00272
00273 fz.append
00274 (
00275 new faceZone
00276 (
00277 mergePatchName + "SlaveZone",
00278 osf,
00279 boolList(slavePatch.size(), false),
00280 1,
00281 mesh.faceZones()
00282 )
00283 );
00284
00285
00286 fz.append
00287 (
00288 new faceZone
00289 (
00290 cutZoneName,
00291 labelList(0),
00292 boolList(0, false),
00293 2,
00294 mesh.faceZones()
00295 )
00296 );
00297
00298
00299
00300
00301 Info << "Adding point and face zones" << endl;
00302 mesh.addZones(pz.shrink(), fz.shrink(), cz.shrink());
00303
00304
00305 stitcher.set
00306 (
00307 0,
00308 new slidingInterface
00309 (
00310 "couple",
00311 0,
00312 stitcher,
00313 mergePatchName + "MasterZone",
00314 mergePatchName + "SlaveZone",
00315 mergePatchName + "CutPointZone",
00316 cutZoneName,
00317 masterPatchName,
00318 slavePatchName,
00319 tom,
00320 true
00321 )
00322 );
00323 }
00324
00325
00326
00327 IOobjectList objects(mesh, runTime.timeName());
00328
00329
00330 Info<< "Reading all current volfields" << endl;
00331 PtrList<volScalarField> volScalarFields;
00332 ReadFields(mesh, objects, volScalarFields);
00333
00334 PtrList<volVectorField> volVectorFields;
00335 ReadFields(mesh, objects, volVectorFields);
00336
00337 PtrList<volSphericalTensorField> volSphericalTensorFields;
00338 ReadFields(mesh, objects, volSphericalTensorFields);
00339
00340 PtrList<volSymmTensorField> volSymmTensorFields;
00341 ReadFields(mesh, objects, volSymmTensorFields);
00342
00343 PtrList<volTensorField> volTensorFields;
00344 ReadFields(mesh, objects, volTensorFields);
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 if (!overwrite)
00358 {
00359 runTime++;
00360 }
00361
00362
00363 autoPtr<mapPolyMesh> morphMap = stitcher.changeMesh(true);
00364
00365 mesh.movePoints(morphMap->preMotionPoints());
00366
00367
00368 if (overwrite)
00369 {
00370 mesh.setInstance(oldInstance);
00371 stitcher.instance() = oldInstance;
00372 }
00373 Info << nl << "Writing polyMesh to time " << runTime.timeName() << endl;
00374
00375 IOstream::defaultPrecision(10);
00376
00377
00378 if
00379 (
00380 !runTime.objectRegistry::writeObject
00381 (
00382 runTime.writeFormat(),
00383 IOstream::currentVersion,
00384 runTime.writeCompression()
00385 )
00386 )
00387 {
00388 FatalErrorIn(args.executable())
00389 << "Failed writing polyMesh."
00390 << exit(FatalError);
00391 }
00392
00393 mesh.faceZones().write();
00394 mesh.pointZones().write();
00395 mesh.cellZones().write();
00396
00397
00398 runTime.write();
00399
00400 Info<< nl << "end" << endl;
00401
00402 return 0;
00403 }
00404
00405
00406