layerAdditionRemoval.C
Go to the documentation of this file.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 #include "layerAdditionRemoval.H"
00031 #include "polyTopoChanger.H"
00032 #include "polyMesh.H"
00033 #include "Time.H"
00034 #include "primitiveMesh.H"
00035 #include "polyTopoChange.H"
00036 #include "addToRunTimeSelectionTable.H"
00037
00038
00039
00040 namespace Foam
00041 {
00042 defineTypeNameAndDebug(layerAdditionRemoval, 0);
00043 addToRunTimeSelectionTable
00044 (
00045 polyMeshModifier,
00046 layerAdditionRemoval,
00047 dictionary
00048 );
00049 }
00050
00051
00052 const Foam::scalar Foam::layerAdditionRemoval::addDelta_ = 0.3;
00053 const Foam::scalar Foam::layerAdditionRemoval::removeDelta_ = 0.1;
00054
00055
00056
00057
00058 void Foam::layerAdditionRemoval::checkDefinition()
00059 {
00060 if (!faceZoneID_.active())
00061 {
00062 FatalErrorIn
00063 (
00064 "void Foam::layerAdditionRemoval::checkDefinition()"
00065 ) << "Master face zone named " << faceZoneID_.name()
00066 << " cannot be found."
00067 << abort(FatalError);
00068 }
00069
00070 if
00071 (
00072 minLayerThickness_ < VSMALL
00073 || maxLayerThickness_ < minLayerThickness_
00074 )
00075 {
00076 FatalErrorIn
00077 (
00078 "void Foam::layerAdditionRemoval::checkDefinition()"
00079 ) << "Incorrect layer thickness definition."
00080 << abort(FatalError);
00081 }
00082
00083 if (topoChanger().mesh().faceZones()[faceZoneID_.index()].empty())
00084 {
00085 FatalErrorIn
00086 (
00087 "void Foam::layerAdditionRemoval::checkDefinition()"
00088 ) << "Face extrusion zone contains no faces. "
00089 << " Please check your mesh definition."
00090 << abort(FatalError);
00091 }
00092
00093 if (debug)
00094 {
00095 Pout<< "Cell layer addition/removal object " << name() << " :" << nl
00096 << " faceZoneID: " << faceZoneID_ << endl;
00097 }
00098 }
00099
00100 Foam::scalar Foam::layerAdditionRemoval::readOldThickness
00101 (
00102 const dictionary& dict
00103 )
00104 {
00105 return dict.lookupOrDefault("oldLayerThickness", -1.0);
00106 }
00107
00108
00109 void Foam::layerAdditionRemoval::clearAddressing() const
00110 {
00111
00112 deleteDemandDrivenData(pointsPairingPtr_);
00113 deleteDemandDrivenData(facesPairingPtr_);
00114 }
00115
00116
00117
00118
00119
00120 Foam::layerAdditionRemoval::layerAdditionRemoval
00121 (
00122 const word& name,
00123 const label index,
00124 const polyTopoChanger& mme,
00125 const word& zoneName,
00126 const scalar minThickness,
00127 const scalar maxThickness
00128 )
00129 :
00130 polyMeshModifier(name, index, mme, true),
00131 faceZoneID_(zoneName, mme.mesh().faceZones()),
00132 minLayerThickness_(minThickness),
00133 maxLayerThickness_(maxThickness),
00134 oldLayerThickness_(-1.0),
00135 pointsPairingPtr_(NULL),
00136 facesPairingPtr_(NULL),
00137 triggerRemoval_(-1),
00138 triggerAddition_(-1)
00139 {
00140 checkDefinition();
00141 }
00142
00143
00144
00145 Foam::layerAdditionRemoval::layerAdditionRemoval
00146 (
00147 const word& name,
00148 const dictionary& dict,
00149 const label index,
00150 const polyTopoChanger& mme
00151 )
00152 :
00153 polyMeshModifier(name, index, mme, Switch(dict.lookup("active"))),
00154 faceZoneID_(dict.lookup("faceZoneName"), mme.mesh().faceZones()),
00155 minLayerThickness_(readScalar(dict.lookup("minLayerThickness"))),
00156 maxLayerThickness_(readScalar(dict.lookup("maxLayerThickness"))),
00157 oldLayerThickness_(readOldThickness(dict)),
00158 pointsPairingPtr_(NULL),
00159 facesPairingPtr_(NULL),
00160 triggerRemoval_(-1),
00161 triggerAddition_(-1)
00162 {
00163 checkDefinition();
00164 }
00165
00166
00167
00168
00169 Foam::layerAdditionRemoval::~layerAdditionRemoval()
00170 {
00171 clearAddressing();
00172 }
00173
00174
00175
00176
00177 bool Foam::layerAdditionRemoval::changeTopology() const
00178 {
00179
00180 if (triggerRemoval_ > -1 || triggerAddition_ > -1)
00181 {
00182 return true;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 const faceZone& fz = topoChanger().mesh().faceZones()[faceZoneID_.index()];
00194 const labelList& mc = fz.masterCells();
00195
00196 const scalarField& V = topoChanger().mesh().cellVolumes();
00197 const vectorField& S = topoChanger().mesh().faceAreas();
00198
00199 if (min(V) < -VSMALL)
00200 {
00201 FatalErrorIn("bool layerAdditionRemoval::changeTopology() const")
00202 << "negative cell volume. Error in mesh motion before "
00203 << "topological change.\n V: " << V
00204 << abort(FatalError);
00205 }
00206
00207 scalar avgDelta = 0;
00208 scalar minDelta = GREAT;
00209 scalar maxDelta = 0;
00210
00211 forAll (fz, faceI)
00212 {
00213 scalar curDelta = V[mc[faceI]]/mag(S[fz[faceI]]);
00214 avgDelta += curDelta;
00215 minDelta = min(minDelta, curDelta);
00216 maxDelta = max(maxDelta, curDelta);
00217 }
00218
00219 avgDelta /= fz.size();
00220
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 if (debug)
00269 {
00270 Pout<< "bool layerAdditionRemoval::changeTopology() const "
00271 << " for object " << name() << " : " << nl
00272 << "Layer thickness: min: " << minDelta
00273 << " max: " << maxDelta << " avg: " << avgDelta
00274 << " old thickness: " << oldLayerThickness_ << nl
00275 << "Removal threshold: " << minLayerThickness_
00276 << " addition threshold: " << maxLayerThickness_ << endl;
00277 }
00278
00279 bool topologicalChange = false;
00280
00281
00282
00283 if (oldLayerThickness_ < 0)
00284 {
00285 if (debug)
00286 {
00287 Pout << "First step. No addition/removal" << endl;
00288 }
00289
00290
00291
00292 oldLayerThickness_ = avgDelta;
00293
00294 topologicalChange = false;
00295 }
00296 else if (avgDelta < oldLayerThickness_)
00297 {
00298
00299 if (minDelta < minLayerThickness_)
00300 {
00301
00302 if (setLayerPairing())
00303 {
00304
00305 if (validCollapse())
00306 {
00307
00308
00309
00310
00311
00312 if (debug)
00313 {
00314 Pout<< "bool layerAdditionRemoval::changeTopology() "
00315 << " const for object " << name() << " : "
00316 << "Triggering layer removal" << endl;
00317 }
00318
00319 triggerRemoval_ = topoChanger().mesh().time().timeIndex();
00320
00321
00322
00323 oldLayerThickness_ = GREAT;
00324
00325 topologicalChange = true;
00326 }
00327 else
00328 {
00329
00330 clearAddressing();
00331 }
00332 }
00333 }
00334 else
00335 {
00336 oldLayerThickness_ = avgDelta;
00337 }
00338 }
00339 else
00340 {
00341
00342 if (maxDelta > maxLayerThickness_)
00343 {
00344 if (debug)
00345 {
00346 Pout<< "bool layerAdditionRemoval::changeTopology() const "
00347 << " for object " << name() << " : "
00348 << "Triggering layer addition" << endl;
00349 }
00350
00351 triggerAddition_ = topoChanger().mesh().time().timeIndex();
00352
00353
00354
00355 oldLayerThickness_ = 0;
00356
00357 topologicalChange = true;
00358 }
00359 else
00360 {
00361 oldLayerThickness_ = avgDelta;
00362 }
00363 }
00364
00365 return topologicalChange;
00366 }
00367
00368
00369 void Foam::layerAdditionRemoval::setRefinement(polyTopoChange& ref) const
00370 {
00371
00372
00373
00374 if (triggerRemoval_ == topoChanger().mesh().time().timeIndex())
00375 {
00376 removeCellLayer(ref);
00377
00378
00379 if (debug)
00380 {
00381 Pout<< "layerAdditionRemoval::setRefinement(polyTopoChange& ref) "
00382 << " for object " << name() << " : "
00383 << "Clearing addressing after layer removal. " << endl;
00384 }
00385
00386 triggerRemoval_ = -1;
00387 clearAddressing();
00388 }
00389
00390 if (triggerAddition_ == topoChanger().mesh().time().timeIndex())
00391 {
00392 addCellLayer(ref);
00393
00394
00395 if (debug)
00396 {
00397 Pout<< "layerAdditionRemoval::setRefinement(polyTopoChange& ref) "
00398 << " for object " << name() << " : "
00399 << "Clearing addressing after layer addition. " << endl;
00400 }
00401
00402 triggerAddition_ = -1;
00403 clearAddressing();
00404 }
00405 }
00406
00407
00408 void Foam::layerAdditionRemoval::updateMesh(const mapPolyMesh&)
00409 {
00410 if (debug)
00411 {
00412 Pout<< "layerAdditionRemoval::updateMesh(const mapPolyMesh&) "
00413 << " for object " << name() << " : "
00414 << "Clearing addressing on external request. ";
00415
00416 if (pointsPairingPtr_ || facesPairingPtr_)
00417 {
00418 Pout << "Pointers set." << endl;
00419 }
00420 else
00421 {
00422 Pout << "Pointers not set." << endl;
00423 }
00424 }
00425
00426
00427 faceZoneID_.update(topoChanger().mesh().faceZones());
00428
00429 clearAddressing();
00430 }
00431
00432
00433 void Foam::layerAdditionRemoval::setMinLayerThickness(const scalar t) const
00434 {
00435 if
00436 (
00437 t < VSMALL
00438 || maxLayerThickness_ < t
00439 )
00440 {
00441 FatalErrorIn
00442 (
00443 "void layerAdditionRemoval::setMinLayerThickness("
00444 "const scalar t) const"
00445 ) << "Incorrect layer thickness definition."
00446 << abort(FatalError);
00447 }
00448
00449 minLayerThickness_ = t;
00450 }
00451
00452
00453 void Foam::layerAdditionRemoval::setMaxLayerThickness(const scalar t) const
00454 {
00455 if
00456 (
00457 t < minLayerThickness_
00458 )
00459 {
00460 FatalErrorIn
00461 (
00462 "void layerAdditionRemoval::setMaxLayerThickness("
00463 "const scalar t) const"
00464 ) << "Incorrect layer thickness definition."
00465 << abort(FatalError);
00466 }
00467
00468 maxLayerThickness_ = t;
00469 }
00470
00471
00472 void Foam::layerAdditionRemoval::write(Ostream& os) const
00473 {
00474 os << nl << type() << nl
00475 << name()<< nl
00476 << faceZoneID_ << nl
00477 << minLayerThickness_ << nl
00478 << oldLayerThickness_ << nl
00479 << maxLayerThickness_ << endl;
00480 }
00481
00482
00483 void Foam::layerAdditionRemoval::writeDict(Ostream& os) const
00484 {
00485 os << nl << name() << nl << token::BEGIN_BLOCK << nl
00486 << " type " << type()
00487 << token::END_STATEMENT << nl
00488 << " faceZoneName " << faceZoneID_.name()
00489 << token::END_STATEMENT << nl
00490 << " minLayerThickness " << minLayerThickness_
00491 << token::END_STATEMENT << nl
00492 << " maxLayerThickness " << maxLayerThickness_
00493 << token::END_STATEMENT << nl
00494 << " oldLayerThickness " << oldLayerThickness_
00495 << token::END_STATEMENT << nl
00496 << " active " << active()
00497 << token::END_STATEMENT << nl
00498 << token::END_BLOCK << endl;
00499 }
00500
00501
00502
Copyright © 2000-2009 OpenCFD Ltd