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 "movingConeTopoFvMesh.H"
00028 #include "Time.H"
00029 #include "mapPolyMesh.H"
00030 #include "layerAdditionRemoval.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 #include "meshTools.H"
00033 #include "OFstream.H"
00034
00035
00036
00037 namespace Foam
00038 {
00039 defineTypeNameAndDebug(movingConeTopoFvMesh, 0);
00040
00041 addToRunTimeSelectionTable
00042 (
00043 topoChangerFvMesh,
00044 movingConeTopoFvMesh,
00045 IOobject
00046 );
00047 }
00048
00049
00050
00051
00052 Foam::tmp<Foam::scalarField> Foam::movingConeTopoFvMesh::vertexMarkup
00053 (
00054 const pointField& p,
00055 const scalar& curLeft,
00056 const scalar& curRight
00057 ) const
00058 {
00059 Info<< "Updating vertex markup. curLeft: "
00060 << curLeft << " curRight: " << curRight << endl;
00061
00062 tmp<scalarField> tvertexMarkup(new scalarField(p.size()));
00063 scalarField& vertexMarkup = tvertexMarkup();
00064
00065 forAll (p, pI)
00066 {
00067 if (p[pI].x() < curLeft - SMALL)
00068 {
00069 vertexMarkup[pI] = -1;
00070 }
00071 else if (p[pI].x() > curRight + SMALL)
00072 {
00073 vertexMarkup[pI] = 1;
00074 }
00075 else
00076 {
00077 vertexMarkup[pI] = 0;
00078 }
00079 }
00080
00081 return tvertexMarkup;
00082 }
00083
00084
00085 void Foam::movingConeTopoFvMesh::addZonesAndModifiers()
00086 {
00087
00088
00089 if
00090 (
00091 pointZones().size()
00092 || faceZones().size()
00093 || cellZones().size()
00094 || topoChanger_.size()
00095 )
00096 {
00097 Info<< "void movingConeTopoFvMesh::addZonesAndModifiers() : "
00098 << "Zones and modifiers already present. Skipping."
00099 << endl;
00100
00101 return;
00102 }
00103
00104 Info<< "Time = " << time().timeName() << endl
00105 << "Adding zones and modifiers to the mesh" << endl;
00106
00107 const vectorField& fc = faceCentres();
00108 const vectorField& fa = faceAreas();
00109
00110 labelList zone1(fc.size());
00111 boolList flipZone1(fc.size(), false);
00112 label nZoneFaces1 = 0;
00113
00114 labelList zone2(fc.size());
00115 boolList flipZone2(fc.size(), false);
00116 label nZoneFaces2 = 0;
00117
00118 forAll (fc, faceI)
00119 {
00120 if
00121 (
00122 fc[faceI].x() > -0.003501
00123 && fc[faceI].x() < -0.003499
00124 )
00125 {
00126 if ((fa[faceI] & vector(1, 0, 0)) < 0)
00127 {
00128 flipZone1[nZoneFaces1] = true;
00129 }
00130
00131 zone1[nZoneFaces1] = faceI;
00132 Info<< "face " << faceI << " for zone 1. Flip: "
00133 << flipZone1[nZoneFaces1] << endl;
00134 nZoneFaces1++;
00135 }
00136 else if
00137 (
00138 fc[faceI].x() > -0.00701
00139 && fc[faceI].x() < -0.00699
00140 )
00141 {
00142 zone2[nZoneFaces2] = faceI;
00143
00144 if ((fa[faceI] & vector(1, 0, 0)) > 0)
00145 {
00146 flipZone2[nZoneFaces2] = true;
00147 }
00148
00149 Info << "face " << faceI << " for zone 2. Flip: "
00150 << flipZone2[nZoneFaces2] << endl;
00151 nZoneFaces2++;
00152 }
00153 }
00154
00155 zone1.setSize(nZoneFaces1);
00156 flipZone1.setSize(nZoneFaces1);
00157
00158 zone2.setSize(nZoneFaces2);
00159 flipZone2.setSize(nZoneFaces2);
00160
00161 Info << "zone: " << zone1 << endl;
00162 Info << "zone: " << zone2 << endl;
00163
00164 List<pointZone*> pz(0);
00165 List<faceZone*> fz(2);
00166 List<cellZone*> cz(0);
00167
00168 label nFz = 0;
00169
00170 fz[nFz] =
00171 new faceZone
00172 (
00173 "rightExtrusionFaces",
00174 zone1,
00175 flipZone1,
00176 nFz,
00177 faceZones()
00178 );
00179 nFz++;
00180
00181 fz[nFz] =
00182 new faceZone
00183 (
00184 "leftExtrusionFaces",
00185 zone2,
00186 flipZone2,
00187 nFz,
00188 faceZones()
00189 );
00190 nFz++;
00191
00192 fz.setSize(nFz);
00193
00194 Info << "Adding mesh zones." << endl;
00195 addZones(pz, fz, cz);
00196
00197
00198
00199
00200 List<polyMeshModifier*> tm(2);
00201 label nMods = 0;
00202
00203 tm[nMods] =
00204 new layerAdditionRemoval
00205 (
00206 "right",
00207 nMods,
00208 topoChanger_,
00209 "rightExtrusionFaces",
00210 readScalar
00211 (
00212 motionDict_.subDict("right").lookup("minThickness")
00213 ),
00214 readScalar
00215 (
00216 motionDict_.subDict("right").lookup("maxThickness")
00217 )
00218 );
00219 nMods++;
00220
00221 tm[nMods] = new layerAdditionRemoval
00222 (
00223 "left",
00224 nMods,
00225 topoChanger_,
00226 "leftExtrusionFaces",
00227 readScalar
00228 (
00229 motionDict_.subDict("left").lookup("minThickness")
00230 ),
00231 readScalar
00232 (
00233 motionDict_.subDict("left").lookup("maxThickness")
00234 )
00235 );
00236 nMods++;
00237 tm.setSize(nMods);
00238
00239 Info << "Adding " << nMods << " mesh modifiers" << endl;
00240 topoChanger_.addTopologyModifiers(tm);
00241
00242 write();
00243 }
00244
00245
00246
00247
00248
00249 Foam::movingConeTopoFvMesh::movingConeTopoFvMesh(const IOobject& io)
00250 :
00251 topoChangerFvMesh(io),
00252 motionDict_
00253 (
00254 IOdictionary
00255 (
00256 IOobject
00257 (
00258 "dynamicMeshDict",
00259 time().constant(),
00260 *this,
00261 IOobject::MUST_READ,
00262 IOobject::NO_WRITE
00263 )
00264 ).subDict(typeName + "Coeffs")
00265 ),
00266 motionVelAmplitude_(motionDict_.lookup("motionVelAmplitude")),
00267 motionVelPeriod_(readScalar(motionDict_.lookup("motionVelPeriod"))),
00268 curMotionVel_
00269 (
00270 motionVelAmplitude_*
00271 Foam::sin(time().value()*M_PI/motionVelPeriod_)
00272 ),
00273 leftEdge_(readScalar(motionDict_.lookup("leftEdge"))),
00274 curLeft_(readScalar(motionDict_.lookup("leftObstacleEdge"))),
00275 curRight_(readScalar(motionDict_.lookup("rightObstacleEdge"))),
00276 motionMask_
00277 (
00278 vertexMarkup
00279 (
00280 points(),
00281 curLeft_,
00282 curRight_
00283 )
00284 )
00285 {
00286 Pout<< "Initial time:" << time().value()
00287 << " Initial curMotionVel_:" << curMotionVel_
00288 << endl;
00289
00290 addZonesAndModifiers();
00291
00292 curLeft_ = average
00293 (
00294 faceZones()
00295 [
00296 faceZones().findZoneID("leftExtrusionFaces")
00297 ]().localPoints()
00298 ).x() - SMALL;
00299
00300 curRight_ = average
00301 (
00302 faceZones()
00303 [
00304 faceZones().findZoneID("rightExtrusionFaces")
00305 ]().localPoints()
00306 ).x() + SMALL;
00307 }
00308
00309
00310
00311
00312 Foam::movingConeTopoFvMesh::~movingConeTopoFvMesh()
00313 {}
00314
00315
00316
00317
00318 bool Foam::movingConeTopoFvMesh::update()
00319 {
00320
00321 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
00322
00323
00324
00325 pointField newPoints;
00326
00327 vector curMotionVel_ =
00328 motionVelAmplitude_*
00329 Foam::sin(time().value()*M_PI/motionVelPeriod_);
00330
00331 Pout<< "time:" << time().value() << " curMotionVel_:" << curMotionVel_
00332 << " curLeft:" << curLeft_ << " curRight:" << curRight_
00333 << endl;
00334
00335 if (topoChangeMap.valid())
00336 {
00337 Info << "Topology change. Calculating motion points" << endl;
00338
00339 if (topoChangeMap().hasMotionPoints())
00340 {
00341 Info << "Topology change. Has premotion points" << endl;
00342
00343
00344
00345 {
00346 OFstream str(time().timePath()/"meshPoints.obj");
00347 Pout<< "Writing mesh with meshPoints to " << str.name()
00348 << endl;
00349
00350 const pointField& currentPoints = points();
00351 label vertI = 0;
00352 forAll(currentPoints, pointI)
00353 {
00354 meshTools::writeOBJ(str, currentPoints[pointI]);
00355 vertI++;
00356 }
00357 forAll(edges(), edgeI)
00358 {
00359 const edge& e = edges()[edgeI];
00360 str << "l " << e[0]+1 << ' ' << e[1]+1 << nl;
00361 }
00362 }
00363 {
00364 OFstream str(time().timePath()/"preMotionPoints.obj");
00365 Pout<< "Writing mesh with preMotionPoints to " << str.name()
00366 << endl;
00367
00368 const pointField& newPoints = topoChangeMap().preMotionPoints();
00369 label vertI = 0;
00370 forAll(newPoints, pointI)
00371 {
00372 meshTools::writeOBJ(str, newPoints[pointI]);
00373 vertI++;
00374 }
00375 forAll(edges(), edgeI)
00376 {
00377 const edge& e = edges()[edgeI];
00378 str << "l " << e[0]+1 << ' ' << e[1]+1 << nl;
00379 }
00380 }
00381
00382
00383 motionMask_ =
00384 vertexMarkup
00385 (
00386 topoChangeMap().preMotionPoints(),
00387 curLeft_,
00388 curRight_
00389 );
00390 }
00391 else
00392 {
00393 Info << "Topology change. Already set mesh points" << endl;
00394
00395 motionMask_ =
00396 vertexMarkup
00397 (
00398 points(),
00399 curLeft_,
00400 curRight_
00401 );
00402 }
00403
00404
00405
00406
00407 newPoints =
00408 points()
00409 + (
00410 pos(0.5 - mag(motionMask_))
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423 )*curMotionVel_*time().deltaT().value();
00424 }
00425 else
00426 {
00427 Info << "No topology change" << endl;
00428
00429 newPoints =
00430 points()
00431 + (
00432 pos(0.5 - mag(motionMask_))
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445 )*curMotionVel_*time().deltaT().value();
00446 }
00447
00448
00449
00450 curLeft_ = average
00451 (
00452 faceZones()
00453 [
00454 faceZones().findZoneID("leftExtrusionFaces")
00455 ]().localPoints()
00456 ).x() - SMALL;
00457
00458 curRight_ = average
00459 (
00460 faceZones()
00461 [
00462 faceZones().findZoneID("rightExtrusionFaces")
00463 ]().localPoints()
00464 ).x() + SMALL;
00465
00466
00467
00468
00469 Info << "Executing mesh motion" << endl;
00470 movePoints(newPoints);
00471
00472
00473
00474 return true;
00475 }
00476
00477
00478