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 #include "attachDetach.H"
00033 #include "polyTopoChanger.H"
00034 #include "polyMesh.H"
00035 #include "Time.H"
00036 #include "primitiveMesh.H"
00037 #include "polyTopoChange.H"
00038 #include "addToRunTimeSelectionTable.H"
00039
00040
00041
00042 namespace Foam
00043 {
00044 defineTypeNameAndDebug(attachDetach, 0);
00045 addToRunTimeSelectionTable
00046 (
00047 polyMeshModifier,
00048 attachDetach,
00049 dictionary
00050 );
00051 }
00052
00053
00054
00055
00056 void Foam::attachDetach::checkDefinition()
00057 {
00058 if
00059 (
00060 !faceZoneID_.active()
00061 || !masterPatchID_.active()
00062 || !slavePatchID_.active()
00063 )
00064 {
00065 FatalErrorIn
00066 (
00067 "void Foam::attachDetach::checkDefinition()"
00068 ) << "Not all zones and patches needed in the definition "
00069 << "have been found. Please check your mesh definition."
00070 << abort(FatalError);
00071 }
00072
00073 const polyMesh& mesh = topoChanger().mesh();
00074
00075 if (debug)
00076 {
00077 Pout<< "Attach/detach object " << name() << " :" << nl
00078 << " faceZoneID: " << faceZoneID_ << nl
00079 << " masterPatchID: " << masterPatchID_ << nl
00080 << " slavePatchID: " << slavePatchID_ << endl;
00081 }
00082
00083
00084 if
00085 (
00086 mesh.boundaryMesh()[masterPatchID_.index()].empty()
00087 && mesh.boundaryMesh()[slavePatchID_.index()].empty()
00088 )
00089 {
00090
00091 if (debug)
00092 {
00093 Pout<< " Attached on construction" << endl;
00094 }
00095
00096 state_ = ATTACHED;
00097
00098
00099 if (mesh.faceZones()[faceZoneID_.index()].empty())
00100 {
00101 FatalErrorIn
00102 (
00103 "void Foam::attachDetach::checkDefinition()"
00104 ) << "Attach/detach zone contains no faces. Please check your "
00105 << "mesh definition."
00106 << abort(FatalError);
00107 }
00108
00109
00110 if (debug)
00111 {
00112 const labelList& addr = mesh.faceZones()[faceZoneID_.index()];
00113
00114 DynamicList<label> bouFacesInZone(addr.size());
00115
00116 forAll (addr, faceI)
00117 {
00118 if (!mesh.isInternalFace(addr[faceI]))
00119 {
00120 bouFacesInZone.append(addr[faceI]);
00121 }
00122 }
00123
00124 if (bouFacesInZone.size())
00125 {
00126 FatalErrorIn
00127 (
00128 "void Foam::attachDetach::checkDefinition()"
00129 ) << "Found boundary faces in the zone defining "
00130 << "attach/detach boundary "
00131 << " for object " << name()
00132 << " : . This is not allowed." << nl
00133 << "Boundary faces: " << bouFacesInZone
00134 << abort(FatalError);
00135 }
00136 }
00137 }
00138 else
00139 {
00140
00141 if (debug)
00142 {
00143 Pout<< " Detached on construction" << endl;
00144 }
00145
00146 state_ = DETACHED;
00147
00148
00149
00150 if
00151 (
00152 (
00153 mesh.boundaryMesh()[masterPatchID_.index()].size()
00154 != mesh.boundaryMesh()[slavePatchID_.index()].size()
00155 )
00156 || (
00157 mesh.boundaryMesh()[masterPatchID_.index()].size()
00158 != mesh.faceZones()[faceZoneID_.index()].size()
00159 )
00160 )
00161 {
00162 FatalErrorIn
00163 (
00164 "void Foam::attachDetach::checkDefinition()"
00165 ) << "Problem with sizes in mesh modifier. The face zone,"
00166 << " master and slave patch should have the same size"
00167 << " for object " << name() << ". " << nl
00168 << "Zone size: "
00169 << mesh.faceZones()[faceZoneID_.index()].size()
00170 << " Master patch size: "
00171 << mesh.boundaryMesh()[masterPatchID_.index()].size()
00172 << " Slave patch size: "
00173 << mesh.boundaryMesh()[slavePatchID_.index()].size()
00174 << abort(FatalError);
00175 }
00176
00177
00178 if (debug)
00179 {
00180 const labelList& addr = mesh.faceZones()[faceZoneID_.index()];
00181
00182 DynamicList<label> zoneProblemFaces(addr.size());
00183
00184 forAll (addr, faceI)
00185 {
00186 label facePatch =
00187 mesh.boundaryMesh().whichPatch(addr[faceI]);
00188
00189 if
00190 (
00191 facePatch != masterPatchID_.index()
00192 && facePatch != slavePatchID_.index()
00193 )
00194 {
00195 zoneProblemFaces.append(addr[faceI]);
00196 }
00197 }
00198
00199 if (zoneProblemFaces.size())
00200 {
00201 FatalErrorIn
00202 (
00203 "void Foam::attachDetach::checkDefinition()"
00204 ) << "Found faces in the zone defining "
00205 << "attach/detach boundary which do not belong to "
00206 << "either master or slave patch. "
00207 << "This is not allowed." << nl
00208 << "Problem faces: " << zoneProblemFaces
00209 << abort(FatalError);
00210 }
00211 }
00212 }
00213
00214
00215 bool triggersOK = true;
00216
00217 for (label i = 0; i < triggerTimes_.size() - 1; i++)
00218 {
00219 triggersOK = triggersOK && (triggerTimes_[i] < triggerTimes_[i + 1]);
00220 }
00221
00222 if
00223 (
00224 !triggersOK
00225 || (triggerTimes_.empty() && !manualTrigger())
00226 )
00227 {
00228 FatalErrorIn
00229 (
00230 "void Foam::attachDetach::checkDefinition()"
00231 ) << "Problem with definition of trigger times: "
00232 << triggerTimes_
00233 << abort(FatalError);
00234 }
00235 }
00236
00237
00238 void Foam::attachDetach::clearAddressing() const
00239 {
00240 deleteDemandDrivenData(pointMatchMapPtr_);
00241 }
00242
00243
00244
00245
00246
00247 Foam::attachDetach::attachDetach
00248 (
00249 const word& name,
00250 const label index,
00251 const polyTopoChanger& mme,
00252 const word& faceZoneName,
00253 const word& masterPatchName,
00254 const word& slavePatchName,
00255 const scalarField& triggerTimes,
00256 const bool manualTrigger
00257 )
00258 :
00259 polyMeshModifier(name, index, mme, true),
00260 faceZoneID_(faceZoneName, mme.mesh().faceZones()),
00261 masterPatchID_(masterPatchName, mme.mesh().boundaryMesh()),
00262 slavePatchID_(slavePatchName, mme.mesh().boundaryMesh()),
00263 triggerTimes_(triggerTimes),
00264 manualTrigger_(manualTrigger),
00265 triggerIndex_(0),
00266 state_(UNKNOWN),
00267 trigger_(false),
00268 pointMatchMapPtr_(NULL)
00269 {
00270 checkDefinition();
00271 }
00272
00273
00274
00275 Foam::attachDetach::attachDetach
00276 (
00277 const word& name,
00278 const dictionary& dict,
00279 const label index,
00280 const polyTopoChanger& mme
00281 )
00282 :
00283 polyMeshModifier(name, index, mme, Switch(dict.lookup("active"))),
00284 faceZoneID_
00285 (
00286 dict.lookup("faceZoneName"),
00287 mme.mesh().faceZones()
00288 ),
00289 masterPatchID_
00290 (
00291 dict.lookup("masterPatchName"),
00292 mme.mesh().boundaryMesh()
00293 ),
00294 slavePatchID_
00295 (
00296 dict.lookup("slavePatchName"),
00297 mme.mesh().boundaryMesh()
00298 ),
00299 triggerTimes_(dict.lookup("triggerTimes")),
00300 manualTrigger_(dict.lookup("manualTrigger")),
00301 triggerIndex_(0),
00302 state_(UNKNOWN),
00303 trigger_(false),
00304 pointMatchMapPtr_(NULL)
00305 {
00306 checkDefinition();
00307 }
00308
00309
00310
00311
00312 Foam::attachDetach::~attachDetach()
00313 {
00314 clearAddressing();
00315 }
00316
00317
00318
00319
00320 bool Foam::attachDetach::setAttach() const
00321 {
00322 if (!attached())
00323 {
00324 trigger_ = true;
00325 }
00326 else
00327 {
00328 trigger_ = false;
00329 }
00330
00331 return trigger_;
00332 }
00333
00334
00335 bool Foam::attachDetach::setDetach() const
00336 {
00337 if (attached())
00338 {
00339 trigger_ = true;
00340 }
00341 else
00342 {
00343 trigger_ = false;
00344 }
00345
00346 return trigger_;
00347 }
00348
00349
00350 bool Foam::attachDetach::changeTopology() const
00351 {
00352 if (manualTrigger())
00353 {
00354 if (debug)
00355 {
00356 Pout<< "bool attachDetach::changeTopology() const "
00357 << " for object " << name() << " : "
00358 << "Manual trigger" << endl;
00359 }
00360
00361 return trigger_;
00362 }
00363
00364
00365
00366 if (trigger_)
00367 {
00368 if (debug)
00369 {
00370 Pout<< "bool attachDetach::changeTopology() const "
00371 << " for object " << name() << " : "
00372 << "Already triggered for current time step" << endl;
00373 }
00374
00375 return true;
00376 }
00377
00378
00379
00380 if (triggerIndex_ >= triggerTimes_.size())
00381 {
00382 if (debug)
00383 {
00384 Pout<< "bool attachDetach::changeTopology() const "
00385 << " for object " << name() << " : "
00386 << "Reached end of trigger list" << endl;
00387 }
00388 return false;
00389 }
00390
00391 if (debug)
00392 {
00393 Pout<< "bool attachDetach::changeTopology() const "
00394 << " for object " << name() << " : "
00395 << "Triggering attach/detach topology change." << nl
00396 << "Current time: " << topoChanger().mesh().time().value()
00397 << " current trigger time: " << triggerTimes_[triggerIndex_]
00398 << " trigger index: " << triggerIndex_ << endl;
00399 }
00400
00401
00402
00403 if (topoChanger().mesh().time().value() >= triggerTimes_[triggerIndex_])
00404 {
00405 trigger_ = true;
00406
00407
00408 triggerIndex_++;
00409
00410 return true;
00411 }
00412
00413
00414 return false;
00415 }
00416
00417
00418 void Foam::attachDetach::setRefinement(polyTopoChange& ref) const
00419 {
00420
00421
00422 if (trigger_)
00423 {
00424
00425 clearAddressing();
00426
00427 if (state_ == ATTACHED)
00428 {
00429 detachInterface(ref);
00430
00431
00432 state_ = DETACHED;
00433 }
00434 else if (state_ == DETACHED)
00435 {
00436 attachInterface(ref);
00437
00438
00439 state_ = ATTACHED;
00440 }
00441 else
00442 {
00443 FatalErrorIn
00444 (
00445 "void attachDetach::setRefinement(polyTopoChange&) const"
00446 ) << "Requested attach/detach event and currect state "
00447 << "is not known."
00448 << abort(FatalError);
00449 }
00450
00451 trigger_ = false;
00452 }
00453 }
00454
00455
00456 void Foam::attachDetach::updateMesh(const mapPolyMesh&)
00457 {
00458
00459 const polyMesh& mesh = topoChanger().mesh();
00460
00461 faceZoneID_.update(mesh.faceZones());
00462 masterPatchID_.update(mesh.boundaryMesh());
00463 slavePatchID_.update(mesh.boundaryMesh());
00464
00465 clearAddressing();
00466 }
00467
00468
00469 void Foam::attachDetach::write(Ostream& os) const
00470 {
00471 os << nl << type() << nl
00472 << name()<< nl
00473 << faceZoneID_.name() << nl
00474 << masterPatchID_.name() << nl
00475 << slavePatchID_.name() << nl
00476 << triggerTimes_ << endl;
00477 }
00478
00479
00480 void Foam::attachDetach::writeDict(Ostream& os) const
00481 {
00482 os << nl << name() << nl << token::BEGIN_BLOCK << nl
00483 << " type " << type()
00484 << token::END_STATEMENT << nl
00485 << " faceZoneName " << faceZoneID_.name()
00486 << token::END_STATEMENT << nl
00487 << " masterPatchName " << masterPatchID_.name()
00488 << token::END_STATEMENT << nl
00489 << " slavePatchName " << slavePatchID_.name()
00490 << token::END_STATEMENT << nl
00491 << " triggerTimes " << triggerTimes_
00492 << token::END_STATEMENT << nl
00493 << " manualTrigger " << manualTrigger()
00494 << token::END_STATEMENT << nl
00495 << " active " << active()
00496 << token::END_STATEMENT << nl
00497 << token::END_BLOCK << endl;
00498 }
00499
00500
00501