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 #include "slidingInterface.H"
00028 #include "polyTopoChanger.H"
00029 #include "polyMesh.H"
00030 #include "primitiveMesh.H"
00031 #include "polyTopoChange.H"
00032 #include "addToRunTimeSelectionTable.H"
00033 #include "triPointRef.H"
00034 #include "plane.H"
00035
00036
00037
00038
00039
00040
00041
00042 namespace Foam
00043 {
00044 defineTypeNameAndDebug(slidingInterface, 0);
00045 addToRunTimeSelectionTable
00046 (
00047 polyMeshModifier,
00048 slidingInterface,
00049 dictionary
00050 );
00051 }
00052
00053
00054 template<>
00055 const char* Foam::NamedEnum<Foam::slidingInterface::typeOfMatch, 2>::names[] =
00056 {
00057 "integral",
00058 "partial"
00059 };
00060
00061
00062 const Foam::NamedEnum<Foam::slidingInterface::typeOfMatch, 2>
00063 Foam::slidingInterface::typeOfMatchNames_;
00064
00065
00066
00067
00068 void Foam::slidingInterface::checkDefinition()
00069 {
00070 const polyMesh& mesh = topoChanger().mesh();
00071
00072 if
00073 (
00074 !masterFaceZoneID_.active()
00075 || !slaveFaceZoneID_.active()
00076 || !cutPointZoneID_.active()
00077 || !cutFaceZoneID_.active()
00078 || !masterPatchID_.active()
00079 || !slavePatchID_.active()
00080 )
00081 {
00082 FatalErrorIn
00083 (
00084 "void slidingInterface::checkDefinition()"
00085 ) << "Not all zones and patches needed in the definition "
00086 << "have been found. Please check your mesh definition."
00087 << abort(FatalError);
00088 }
00089
00090
00091 if
00092 (
00093 mesh.faceZones()[masterFaceZoneID_.index()].empty()
00094 || mesh.faceZones()[slaveFaceZoneID_.index()].empty()
00095 )
00096 {
00097 FatalErrorIn("void slidingInterface::checkDefinition()")
00098 << "Master or slave face zone contain no faces. "
00099 << "Please check your mesh definition."
00100 << abort(FatalError);
00101 }
00102
00103 if (debug)
00104 {
00105 Pout<< "Sliding interface object " << name() << " :" << nl
00106 << " master face zone: " << masterFaceZoneID_.index() << nl
00107 << " slave face zone: " << slaveFaceZoneID_.index() << endl;
00108 }
00109 }
00110
00111
00112 void Foam::slidingInterface::clearOut() const
00113 {
00114 clearPointProjection();
00115 clearAttachedAddressing();
00116 clearAddressing();
00117 }
00118
00119
00120
00121
00122
00123
00124 Foam::slidingInterface::slidingInterface
00125 (
00126 const word& name,
00127 const label index,
00128 const polyTopoChanger& mme,
00129 const word& masterFaceZoneName,
00130 const word& slaveFaceZoneName,
00131 const word& cutPointZoneName,
00132 const word& cutFaceZoneName,
00133 const word& masterPatchName,
00134 const word& slavePatchName,
00135 const typeOfMatch tom,
00136 const bool coupleDecouple,
00137 const intersection::algorithm algo
00138 )
00139 :
00140 polyMeshModifier(name, index, mme, true),
00141 masterFaceZoneID_
00142 (
00143 masterFaceZoneName,
00144 mme.mesh().faceZones()
00145 ),
00146 slaveFaceZoneID_
00147 (
00148 slaveFaceZoneName,
00149 mme.mesh().faceZones()
00150 ),
00151 cutPointZoneID_
00152 (
00153 cutPointZoneName,
00154 mme.mesh().pointZones()
00155 ),
00156 cutFaceZoneID_
00157 (
00158 cutFaceZoneName,
00159 mme.mesh().faceZones()
00160 ),
00161 masterPatchID_
00162 (
00163 masterPatchName,
00164 mme.mesh().boundaryMesh()
00165 ),
00166 slavePatchID_
00167 (
00168 slavePatchName,
00169 mme.mesh().boundaryMesh()
00170 ),
00171 matchType_(tom),
00172 coupleDecouple_(coupleDecouple),
00173 attached_(false),
00174 projectionAlgo_(algo),
00175 trigger_(false),
00176 cutFaceMasterPtr_(NULL),
00177 cutFaceSlavePtr_(NULL),
00178 masterFaceCellsPtr_(NULL),
00179 slaveFaceCellsPtr_(NULL),
00180 masterStickOutFacesPtr_(NULL),
00181 slaveStickOutFacesPtr_(NULL),
00182 retiredPointMapPtr_(NULL),
00183 cutPointEdgePairMapPtr_(NULL),
00184 slavePointPointHitsPtr_(NULL),
00185 slavePointEdgeHitsPtr_(NULL),
00186 slavePointFaceHitsPtr_(NULL),
00187 masterPointEdgeHitsPtr_(NULL),
00188 projectedSlavePointsPtr_(NULL)
00189 {
00190 checkDefinition();
00191
00192 if (attached_)
00193 {
00194 FatalErrorIn
00195 (
00196 "Foam::slidingInterface::slidingInterface\n"
00197 "(\n"
00198 " const word& name,\n"
00199 " const label index,\n"
00200 " const polyTopoChanger& mme,\n"
00201 " const word& masterFaceZoneName,\n"
00202 " const word& slaveFaceZoneName,\n"
00203 " const word& cutFaceZoneName,\n"
00204 " const word& cutPointZoneName,\n"
00205 " const word& masterPatchName,\n"
00206 " const word& slavePatchName,\n"
00207 " const typeOfMatch tom,\n"
00208 " const bool coupleDecouple\n"
00209 ")"
00210 ) << "Creation of a sliding interface from components "
00211 << "in attached state not supported."
00212 << abort(FatalError);
00213 }
00214 else
00215 {
00216 calcAttachedAddressing();
00217 }
00218 }
00219
00220
00221
00222 Foam::slidingInterface::slidingInterface
00223 (
00224 const word& name,
00225 const dictionary& dict,
00226 const label index,
00227 const polyTopoChanger& mme
00228 )
00229 :
00230 polyMeshModifier(name, index, mme, Switch(dict.lookup("active"))),
00231 masterFaceZoneID_
00232 (
00233 dict.lookup("masterFaceZoneName"),
00234 mme.mesh().faceZones()
00235 ),
00236 slaveFaceZoneID_
00237 (
00238 dict.lookup("slaveFaceZoneName"),
00239 mme.mesh().faceZones()
00240 ),
00241 cutPointZoneID_
00242 (
00243 dict.lookup("cutPointZoneName"),
00244 mme.mesh().pointZones()
00245 ),
00246 cutFaceZoneID_
00247 (
00248 dict.lookup("cutFaceZoneName"),
00249 mme.mesh().faceZones()
00250 ),
00251 masterPatchID_
00252 (
00253 dict.lookup("masterPatchName"),
00254 mme.mesh().boundaryMesh()
00255 ),
00256 slavePatchID_
00257 (
00258 dict.lookup("slavePatchName"),
00259 mme.mesh().boundaryMesh()
00260 ),
00261 matchType_(typeOfMatchNames_.read((dict.lookup("typeOfMatch")))),
00262 coupleDecouple_(dict.lookup("coupleDecouple")),
00263 attached_(dict.lookup("attached")),
00264 projectionAlgo_
00265 (
00266 intersection::algorithmNames_.read(dict.lookup("projection"))
00267 ),
00268 trigger_(false),
00269 cutFaceMasterPtr_(NULL),
00270 cutFaceSlavePtr_(NULL),
00271 masterFaceCellsPtr_(NULL),
00272 slaveFaceCellsPtr_(NULL),
00273 masterStickOutFacesPtr_(NULL),
00274 slaveStickOutFacesPtr_(NULL),
00275 retiredPointMapPtr_(NULL),
00276 cutPointEdgePairMapPtr_(NULL),
00277 slavePointPointHitsPtr_(NULL),
00278 slavePointEdgeHitsPtr_(NULL),
00279 slavePointFaceHitsPtr_(NULL),
00280 masterPointEdgeHitsPtr_(NULL),
00281 projectedSlavePointsPtr_(NULL)
00282 {
00283 checkDefinition();
00284
00285
00286
00287 if (attached_)
00288 {
00289 if (debug)
00290 {
00291 Pout<< "slidingInterface::slidingInterface(...) "
00292 << " for object " << name << " : "
00293 << "Interface attached. Reading master and slave face zones "
00294 << "and retired point lookup." << endl;
00295 }
00296
00297
00298 masterFaceCellsPtr_ = new labelList(dict.lookup("masterFaceCells"));
00299 slaveFaceCellsPtr_ = new labelList(dict.lookup("slaveFaceCells"));
00300
00301 masterStickOutFacesPtr_ =
00302 new labelList(dict.lookup("masterStickOutFaces"));
00303 slaveStickOutFacesPtr_ =
00304 new labelList(dict.lookup("slaveStickOutFaces"));
00305
00306 retiredPointMapPtr_ = new Map<label>(dict.lookup("retiredPointMap"));
00307 cutPointEdgePairMapPtr_ =
00308 new Map<Pair<edge> >(dict.lookup("cutPointEdgePairMap"));
00309 }
00310 else
00311 {
00312 calcAttachedAddressing();
00313 }
00314 }
00315
00316
00317
00318
00319 Foam::slidingInterface::~slidingInterface()
00320 {
00321 clearOut();
00322 }
00323
00324
00325 void Foam::slidingInterface::clearAddressing() const
00326 {
00327 deleteDemandDrivenData(cutFaceMasterPtr_);
00328 deleteDemandDrivenData(cutFaceSlavePtr_);
00329 }
00330
00331
00332
00333
00334 const Foam::faceZoneID& Foam::slidingInterface::masterFaceZoneID() const
00335 {
00336 return masterFaceZoneID_;
00337 }
00338
00339
00340 const Foam::faceZoneID& Foam::slidingInterface::slaveFaceZoneID() const
00341 {
00342 return slaveFaceZoneID_;
00343 }
00344
00345
00346 bool Foam::slidingInterface::changeTopology() const
00347 {
00348 if (coupleDecouple_)
00349 {
00350
00351 if (debug)
00352 {
00353 Pout<< "bool slidingInterface::changeTopology() const "
00354 << "for object " << name() << " : "
00355 << "Couple-decouple mode." << endl;
00356 }
00357
00358 if (!attached_)
00359 {
00360 projectPoints();
00361 }
00362 else
00363 {
00364 }
00365
00366 return true;
00367 }
00368
00369 if
00370 (
00371 attached_
00372 && !topoChanger().mesh().changing()
00373 )
00374 {
00375
00376
00377 return false;
00378 }
00379 else
00380 {
00381
00382 return projectPoints();
00383 }
00384 }
00385
00386
00387 void Foam::slidingInterface::setRefinement(polyTopoChange& ref) const
00388 {
00389 if (coupleDecouple_)
00390 {
00391 if (attached_)
00392 {
00393
00394 decoupleInterface(ref);
00395 }
00396 else
00397 {
00398
00399 coupleInterface(ref);
00400 }
00401
00402 return;
00403 }
00404
00405 if (trigger_)
00406 {
00407 if (attached_)
00408 {
00409
00410 clearCouple(ref);
00411 }
00412
00413 coupleInterface(ref);
00414
00415 trigger_ = false;
00416 }
00417 }
00418
00419
00420 void Foam::slidingInterface::modifyMotionPoints(pointField& motionPoints) const
00421 {
00422 if (debug)
00423 {
00424 Pout<< "void slidingInterface::modifyMotionPoints("
00425 << "pointField& motionPoints) const for object " << name() << " : "
00426 << "Adjusting motion points." << endl;
00427 }
00428
00429 const polyMesh& mesh = topoChanger().mesh();
00430
00431
00432 const labelList& cutPoints = mesh.pointZones()[cutPointZoneID_.index()];
00433
00434 if (cutPoints.size() && !projectedSlavePointsPtr_)
00435 {
00436 return;
00437 }
00438 else
00439 {
00440 const pointField& projectedSlavePoints = *projectedSlavePointsPtr_;
00441
00442 const Map<label>& rpm = retiredPointMap();
00443
00444 const Map<Pair<edge> >& cpepm = cutPointEdgePairMap();
00445
00446 const Map<label>& slaveZonePointMap =
00447 mesh.faceZones()[slaveFaceZoneID_.index()]().meshPointMap();
00448
00449 const primitiveFacePatch& masterPatch =
00450 mesh.faceZones()[masterFaceZoneID_.index()]();
00451 const edgeList& masterEdges = masterPatch.edges();
00452 const pointField& masterLocalPoints = masterPatch.localPoints();
00453
00454 const primitiveFacePatch& slavePatch =
00455 mesh.faceZones()[slaveFaceZoneID_.index()]();
00456 const edgeList& slaveEdges = slavePatch.edges();
00457 const pointField& slaveLocalPoints = slavePatch.localPoints();
00458 const vectorField& slavePointNormals = slavePatch.pointNormals();
00459
00460 forAll (cutPoints, pointI)
00461 {
00462
00463 Map<label>::const_iterator rpmIter = rpm.find(cutPoints[pointI]);
00464
00465 if (rpmIter != rpm.end())
00466 {
00467 if (debug)
00468 {
00469 Pout << "p";
00470 }
00471
00472
00473 motionPoints[cutPoints[pointI]] =
00474 projectedSlavePoints[slaveZonePointMap.find(rpmIter())()];
00475 }
00476 else
00477 {
00478
00479
00480
00481 Map<Pair<edge> >::const_iterator cpepmIter =
00482 cpepm.find(cutPoints[pointI]);
00483
00484 if (cpepmIter != cpepm.end())
00485 {
00486
00487
00488
00489
00490
00491
00492
00493
00494 const edge& globalMasterEdge = cpepmIter().first();
00495
00496 const label curMasterEdgeIndex =
00497 masterPatch.whichEdge
00498 (
00499 edge
00500 (
00501 masterPatch.whichPoint
00502 (
00503 globalMasterEdge.start()
00504 ),
00505 masterPatch.whichPoint
00506 (
00507 globalMasterEdge.end()
00508 )
00509 )
00510 );
00511
00512 const edge& cme = masterEdges[curMasterEdgeIndex];
00513
00514 const edge& globalSlaveEdge = cpepmIter().second();
00515
00516 const label curSlaveEdgeIndex =
00517 slavePatch.whichEdge
00518 (
00519 edge
00520 (
00521 slavePatch.whichPoint
00522 (
00523 globalSlaveEdge.start()
00524 ),
00525 slavePatch.whichPoint
00526 (
00527 globalSlaveEdge.end()
00528 )
00529 )
00530 );
00531
00532 const edge& curSlaveEdge = slaveEdges[curSlaveEdgeIndex];
00533
00534 const point& a = projectedSlavePoints[curSlaveEdge.start()];
00535 const point& b = projectedSlavePoints[curSlaveEdge.end()];
00536
00537 point c =
00538 0.5*
00539 (
00540 slaveLocalPoints[curSlaveEdge.start()]
00541 + slavePointNormals[curSlaveEdge.start()]
00542 + slaveLocalPoints[curSlaveEdge.end()]
00543 + slavePointNormals[curSlaveEdge.end()]
00544 );
00545
00546
00547 plane cutPlane(a, b, c);
00548
00549 linePointRef curSlaveLine =
00550 curSlaveEdge.line(slaveLocalPoints);
00551 const scalar curSlaveLineMag = curSlaveLine.mag();
00552
00553 scalar cutOnMaster =
00554 cutPlane.lineIntersect
00555 (
00556 cme.line(masterLocalPoints)
00557 );
00558
00559 if
00560 (
00561 cutOnMaster > edgeEndCutoffTol_
00562 && cutOnMaster < 1.0 - edgeEndCutoffTol_
00563 )
00564 {
00565
00566 point masterCutPoint =
00567 masterLocalPoints[cme.start()]
00568 + cutOnMaster*cme.vec(masterLocalPoints);
00569
00570 pointHit slaveCut =
00571 curSlaveLine.nearestDist(masterCutPoint);
00572
00573 if (slaveCut.hit())
00574 {
00575
00576
00577 scalar cutOnSlave =
00578 (
00579 (
00580 slaveCut.hitPoint()
00581 - curSlaveLine.start()
00582 ) & curSlaveLine.vec()
00583 )/sqr(curSlaveLineMag);
00584
00585
00586
00587 scalar mergeTol =
00588 edgeCoPlanarTol_*mag(b - a);
00589
00590 if
00591 (
00592 cutOnSlave > edgeEndCutoffTol_
00593 && cutOnSlave < 1.0 - edgeEndCutoffTol_
00594 && slaveCut.distance() < mergeTol
00595 )
00596 {
00597
00598 motionPoints[cutPoints[pointI]] =
00599 masterCutPoint;
00600 }
00601 }
00602 else
00603 {
00604 Pout<< "Missed slave edge!!! This is an error. "
00605 << "Master edge: "
00606 << cme.line(masterLocalPoints)
00607 << " slave edge: " << curSlaveLine
00608 << " point: " << masterCutPoint
00609 << " weight: " <<
00610 (
00611 (
00612 slaveCut.missPoint()
00613 - curSlaveLine.start()
00614 ) & curSlaveLine.vec()
00615 )/sqr(curSlaveLineMag)
00616 << endl;
00617 }
00618 }
00619 else
00620 {
00621 Pout<< "Missed master edge!!! This is an error"
00622 << endl;
00623 }
00624 }
00625 else
00626 {
00627 FatalErrorIn
00628 (
00629 "void slidingInterface::modifyMotionPoints"
00630 "(pointField&) const"
00631 ) << "Cut point " << cutPoints[pointI]
00632 << " not recognised as either the projected "
00633 << "or as intersection point. Error in point "
00634 << "projection or data mapping"
00635 << abort(FatalError);
00636 }
00637 }
00638 }
00639 if (debug)
00640 {
00641 Pout << endl;
00642 }
00643 }
00644 }
00645
00646
00647 void Foam::slidingInterface::updateMesh(const mapPolyMesh& m)
00648 {
00649 if (debug)
00650 {
00651 Pout<< "void slidingInterface::updateMesh(const mapPolyMesh& m)"
00652 << " const for object " << name() << " : "
00653 << "Updating topology." << endl;
00654 }
00655
00656
00657 const polyMesh& mesh = topoChanger().mesh();
00658
00659 masterFaceZoneID_.update(mesh.faceZones());
00660 slaveFaceZoneID_.update(mesh.faceZones());
00661 cutPointZoneID_.update(mesh.pointZones());
00662 cutFaceZoneID_.update(mesh.faceZones());
00663
00664 masterPatchID_.update(mesh.boundaryMesh());
00665 slavePatchID_.update(mesh.boundaryMesh());
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676 }
00677
00678
00679 const Foam::pointField& Foam::slidingInterface::pointProjection() const
00680 {
00681 if (!projectedSlavePointsPtr_)
00682 {
00683 projectPoints();
00684 }
00685
00686 return *projectedSlavePointsPtr_;
00687 }
00688
00689
00690 void Foam::slidingInterface::write(Ostream& os) const
00691 {
00692 os << nl << type() << nl
00693 << name()<< nl
00694 << masterFaceZoneID_.name() << nl
00695 << slaveFaceZoneID_.name() << nl
00696 << cutPointZoneID_.name() << nl
00697 << cutFaceZoneID_.name() << nl
00698 << masterPatchID_.name() << nl
00699 << slavePatchID_.name() << nl
00700 << typeOfMatchNames_[matchType_] << nl
00701 << coupleDecouple_ << nl
00702 << attached_ << endl;
00703 }
00704
00705
00706 void Foam::slidingInterface::writeDict(Ostream& os) const
00707 {
00708 os << nl << name() << nl << token::BEGIN_BLOCK << nl
00709 << " type " << type() << token::END_STATEMENT << nl
00710 << " masterFaceZoneName " << masterFaceZoneID_.name()
00711 << token::END_STATEMENT << nl
00712 << " slaveFaceZoneName " << slaveFaceZoneID_.name()
00713 << token::END_STATEMENT << nl
00714 << " cutPointZoneName " << cutPointZoneID_.name()
00715 << token::END_STATEMENT << nl
00716 << " cutFaceZoneName " << cutFaceZoneID_.name()
00717 << token::END_STATEMENT << nl
00718 << " masterPatchName " << masterPatchID_.name()
00719 << token::END_STATEMENT << nl
00720 << " slavePatchName " << slavePatchID_.name()
00721 << token::END_STATEMENT << nl
00722 << " typeOfMatch " << typeOfMatchNames_[matchType_]
00723 << token::END_STATEMENT << nl
00724 << " coupleDecouple " << coupleDecouple_
00725 << token::END_STATEMENT << nl
00726 << " projection " << intersection::algorithmNames_[projectionAlgo_]
00727 << token::END_STATEMENT << nl
00728 << " attached " << attached_
00729 << token::END_STATEMENT << nl
00730 << " active " << active()
00731 << token::END_STATEMENT << nl;
00732
00733 if (attached_)
00734 {
00735 masterFaceCellsPtr_->writeEntry("masterFaceCells", os);
00736 slaveFaceCellsPtr_->writeEntry("slaveFaceCells", os);
00737 masterStickOutFacesPtr_->writeEntry("masterStickOutFaces", os);
00738 slaveStickOutFacesPtr_->writeEntry("slaveStickOutFaces", os);
00739
00740 os << " retiredPointMap " << retiredPointMap()
00741 << token::END_STATEMENT << nl
00742 << " cutPointEdgePairMap " << cutPointEdgePairMap()
00743 << token::END_STATEMENT << nl;
00744 }
00745
00746 os << token::END_BLOCK << endl;
00747 }
00748
00749
00750