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 #include "perfectInterface.H"
00032 #include "polyTopoChanger.H"
00033 #include "polyMesh.H"
00034 #include "polyTopoChange.H"
00035 #include "addToRunTimeSelectionTable.H"
00036 #include "mapPolyMesh.H"
00037 #include "matchPoints.H"
00038 #include "polyModifyFace.H"
00039 #include "polyRemovePoint.H"
00040 #include "polyRemoveFace.H"
00041
00042
00043
00044 namespace Foam
00045 {
00046 defineTypeNameAndDebug(perfectInterface, 0);
00047 addToRunTimeSelectionTable
00048 (
00049 polyMeshModifier,
00050 perfectInterface,
00051 dictionary
00052 );
00053 }
00054
00055
00056
00057 const Foam::scalar Foam::perfectInterface::tol_ = 1E-3;
00058
00059
00060
00061
00062 Foam::pointField Foam::perfectInterface::calcFaceCentres
00063 (
00064 const primitivePatch& pp
00065 )
00066 {
00067 const pointField& points = pp.points();
00068
00069 pointField ctrs(pp.size());
00070
00071 forAll(ctrs, patchFaceI)
00072 {
00073 ctrs[patchFaceI] = pp[patchFaceI].centre(points);
00074 }
00075
00076 return ctrs;
00077 }
00078
00079
00080
00081
00082
00083 Foam::perfectInterface::perfectInterface
00084 (
00085 const word& name,
00086 const label index,
00087 const polyTopoChanger& mme,
00088 const word& faceZoneName,
00089 const word& masterPatchName,
00090 const word& slavePatchName
00091 )
00092 :
00093 polyMeshModifier(name, index, mme, true),
00094 faceZoneID_(faceZoneName, mme.mesh().faceZones()),
00095 masterPatchID_(masterPatchName, mme.mesh().boundaryMesh()),
00096 slavePatchID_(slavePatchName, mme.mesh().boundaryMesh())
00097 {}
00098
00099
00100
00101 Foam::perfectInterface::perfectInterface
00102 (
00103 const word& name,
00104 const dictionary& dict,
00105 const label index,
00106 const polyTopoChanger& mme
00107 )
00108 :
00109 polyMeshModifier(name, index, mme, readBool(dict.lookup("active"))),
00110 faceZoneID_
00111 (
00112 dict.lookup("faceZoneName"),
00113 mme.mesh().faceZones()
00114 ),
00115 masterPatchID_
00116 (
00117 dict.lookup("masterPatchName"),
00118 mme.mesh().boundaryMesh()
00119 ),
00120 slavePatchID_
00121 (
00122 dict.lookup("slavePatchName"),
00123 mme.mesh().boundaryMesh()
00124 )
00125 {}
00126
00127
00128
00129
00130 Foam::perfectInterface::~perfectInterface()
00131 {}
00132
00133
00134
00135
00136 bool Foam::perfectInterface::changeTopology() const
00137 {
00138
00139 if (!active())
00140 {
00141 if (debug)
00142 {
00143 Pout<< "bool perfectInterface::changeTopology() const "
00144 << "for object " << name() << " : "
00145 << "Inactive" << endl;
00146 }
00147
00148 return false;
00149 }
00150 else
00151 {
00152
00153 return true;
00154 }
00155 }
00156
00157
00158 void Foam::perfectInterface::setRefinement(polyTopoChange& ref) const
00159 {
00160 if (debug)
00161 {
00162 Pout<< "bool perfectInterface::setRefinement(polyTopoChange&) const : "
00163 << "for object " << name() << " : "
00164 << "masterPatchID_:" << masterPatchID_
00165 << " slavePatchID_:" << slavePatchID_
00166 << " faceZoneID_:" << faceZoneID_ << endl;
00167 }
00168
00169 if
00170 (
00171 masterPatchID_.active()
00172 && slavePatchID_.active()
00173 && faceZoneID_.active()
00174 )
00175 {
00176 const polyMesh& mesh = topoChanger().mesh();
00177
00178 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00179
00180 const polyPatch& pp0 = patches[masterPatchID_.index()];
00181 const polyPatch& pp1 = patches[slavePatchID_.index()];
00182
00183
00184 const edgeList& edges0 = pp0.edges();
00185 const pointField& pts0 = pp0.localPoints();
00186 const pointField& pts1 = pp1.localPoints();
00187 const labelList& meshPts0 = pp0.meshPoints();
00188 const labelList& meshPts1 = pp1.meshPoints();
00189
00190
00191
00192
00193 scalar minLen = GREAT;
00194
00195 forAll(edges0, edgeI)
00196 {
00197 minLen = min(minLen, edges0[edgeI].mag(pts0));
00198 }
00199 scalar typDim = tol_*minLen;
00200
00201 if (debug)
00202 {
00203 Pout<< "typDim:" << typDim << " edges0:" << edges0.size()
00204 << " pts0:" << pts0.size() << " pts1:" << pts1.size()
00205 << " pp0:" << pp0.size() << " pp1:" << pp1.size() << endl;
00206 }
00207
00208
00209
00210
00211
00212 labelList renumberPoints(mesh.points().size());
00213 forAll(renumberPoints, i)
00214 {
00215 renumberPoints[i] = i;
00216 }
00217 {
00218 labelList from1To0Points(pts1.size());
00219
00220 bool matchOk = matchPoints
00221 (
00222 pts1,
00223 pts0,
00224 scalarField(pts1.size(), typDim),
00225 true,
00226 from1To0Points
00227 );
00228
00229 if (!matchOk)
00230 {
00231 FatalErrorIn
00232 (
00233 "perfectInterface::setRefinement(polyTopoChange& ref) const"
00234 ) << "Points on patches " << pp0.name() << " and "
00235 << pp1.name() << " do not match to within tolerance "
00236 << typDim << exit(FatalError);
00237 }
00238
00239 forAll(pts1, i)
00240 {
00241 renumberPoints[meshPts1[i]] = meshPts0[from1To0Points[i]];
00242 }
00243 }
00244
00245
00246
00247
00248
00249 labelList from0To1Faces(pp1.size());
00250
00251 bool matchOk = matchPoints
00252 (
00253 calcFaceCentres(pp0),
00254 calcFaceCentres(pp1),
00255 scalarField(pp0.size(), typDim),
00256 true,
00257 from0To1Faces
00258 );
00259
00260 if (!matchOk)
00261 {
00262 FatalErrorIn
00263 (
00264 "perfectInterface::setRefinement(polyTopoChange& ref) const"
00265 ) << "Face centres of patches " << pp0.name() << " and "
00266 << pp1.name() << " do not match to within tolerance " << typDim
00267 << exit(FatalError);
00268 }
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 labelHashSet affectedFaces(2*pp1.size());
00279 forAll(meshPts1, i)
00280 {
00281 label meshPointI = meshPts1[i];
00282
00283 if (meshPointI != renumberPoints[meshPointI])
00284 {
00285 const labelList& pFaces = mesh.pointFaces()[meshPointI];
00286
00287 forAll(pFaces, pFaceI)
00288 {
00289 affectedFaces.insert(pFaces[pFaceI]);
00290 }
00291 }
00292 }
00293 forAll(pp1, i)
00294 {
00295 affectedFaces.erase(pp1.start() + i);
00296 }
00297
00298
00299
00300
00301 forAll(pp0, i)
00302 {
00303 if (affectedFaces.erase(pp0.start() + i))
00304 {
00305 WarningIn
00306 (
00307 "perfectInterface::setRefinement(polyTopoChange&) const"
00308 ) << "Found face " << pp0.start() + i << " vertices "
00309 << mesh.faces()[pp0.start() + i] << " whose points are"
00310 << " used both by master patch " << pp0.name()
00311 << " and slave patch " << pp1.name()
00312 << endl;
00313 }
00314 }
00315
00316
00317
00318 for
00319 (
00320 labelHashSet::const_iterator iter = affectedFaces.begin();
00321 iter != affectedFaces.end();
00322 ++iter
00323 )
00324 {
00325 label faceI = iter.key();
00326
00327 const face& f = mesh.faces()[faceI];
00328
00329 face newFace(f.size());
00330
00331 forAll(newFace, fp)
00332 {
00333 newFace[fp] = renumberPoints[f[fp]];
00334 }
00335
00336 label nbr = -1;
00337
00338 label patchI = -1;
00339
00340 if (mesh.isInternalFace(faceI))
00341 {
00342 nbr = mesh.faceNeighbour()[faceI];
00343 }
00344 else
00345 {
00346 patchI = patches.whichPatch(faceI);
00347 }
00348
00349 label zoneID = mesh.faceZones().whichZone(faceI);
00350
00351 bool zoneFlip = false;
00352
00353 if (zoneID >= 0)
00354 {
00355 const faceZone& fZone = mesh.faceZones()[zoneID];
00356
00357 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00358 }
00359
00360 ref.setAction
00361 (
00362 polyModifyFace
00363 (
00364 newFace,
00365 faceI,
00366 mesh.faceOwner()[faceI],
00367 nbr,
00368 false,
00369 patchI,
00370 false,
00371 zoneID,
00372 zoneFlip
00373 )
00374 );
00375 }
00376
00377
00378
00379 forAll(meshPts1, i)
00380 {
00381 label meshPointI = meshPts1[i];
00382
00383 if (meshPointI != renumberPoints[meshPointI])
00384 {
00385 ref.setAction(polyRemovePoint(meshPointI));
00386 }
00387 }
00388
00389
00390
00391 forAll(pp1, i)
00392 {
00393 ref.setAction(polyRemoveFace(pp1.start() + i));
00394 }
00395
00396
00397
00398
00399
00400 const boolList& mfFlip =
00401 mesh.faceZones()[faceZoneID_.index()].flipMap();
00402
00403 forAll(pp0, i)
00404 {
00405 label faceI = pp0.start() + i;
00406
00407 const face& f = mesh.faces()[faceI];
00408
00409 face newFace(f.size());
00410
00411 forAll(newFace, fp)
00412 {
00413 newFace[fp] = renumberPoints[f[fp]];
00414 }
00415
00416 label own = mesh.faceOwner()[faceI];
00417
00418 label pp1FaceI = pp1.start() + from0To1Faces[i];
00419
00420 label nbr = mesh.faceOwner()[pp1FaceI];
00421
00422 if (own < nbr)
00423 {
00424 ref.setAction
00425 (
00426 polyModifyFace
00427 (
00428 newFace,
00429 faceI,
00430 own,
00431 nbr,
00432 false,
00433 -1,
00434 false,
00435 faceZoneID_.index(),
00436 mfFlip[i]
00437 )
00438 );
00439 }
00440 else
00441 {
00442 ref.setAction
00443 (
00444 polyModifyFace
00445 (
00446 newFace.reverseFace(),
00447 faceI,
00448 nbr,
00449 own,
00450 false,
00451 -1,
00452 false,
00453 faceZoneID_.index(),
00454 !mfFlip[i]
00455 )
00456 );
00457 }
00458 }
00459 }
00460 }
00461
00462
00463 void Foam::perfectInterface::modifyMotionPoints(pointField& motionPoints) const
00464 {
00465
00466
00467 }
00468
00469
00470 void Foam::perfectInterface::updateMesh(const mapPolyMesh& morphMap)
00471 {
00472
00473 const polyMesh& mesh = topoChanger().mesh();
00474
00475 faceZoneID_.update(mesh.faceZones());
00476 masterPatchID_.update(mesh.boundaryMesh());
00477 slavePatchID_.update(mesh.boundaryMesh());
00478 }
00479
00480
00481 void Foam::perfectInterface::write(Ostream& os) const
00482 {
00483 os << nl << type() << nl
00484 << name()<< nl
00485 << faceZoneID_.name() << nl
00486 << masterPatchID_.name() << nl
00487 << slavePatchID_.name() << endl;
00488 }
00489
00490
00491 void Foam::perfectInterface::writeDict(Ostream& os) const
00492 {
00493 os << nl << name() << nl << token::BEGIN_BLOCK << nl
00494
00495 << " type " << type()
00496 << token::END_STATEMENT << nl
00497
00498 << " active " << active()
00499 << token::END_STATEMENT << nl
00500
00501 << " faceZoneName " << faceZoneID_.name()
00502 << token::END_STATEMENT << nl
00503
00504 << " masterPatchName " << masterPatchID_.name()
00505 << token::END_STATEMENT << nl
00506
00507 << " slavePatchName " << slavePatchID_.name()
00508 << token::END_STATEMENT << nl
00509
00510 << token::END_BLOCK << endl;
00511 }
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523