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 "surfaceSlipDisplacementPointPatchVectorField.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "Time.H"
00030 #include "transformField.H"
00031 #include "fvMesh.H"
00032 #include "displacementFvMotionSolver.H"
00033
00034
00035
00036 namespace Foam
00037 {
00038
00039
00040
00041 template<>
00042 const char*
00043 NamedEnum<surfaceSlipDisplacementPointPatchVectorField::projectMode, 3>::
00044 names[] =
00045 {
00046 "nearest",
00047 "pointNormal",
00048 "fixedNormal"
00049 };
00050
00051 const NamedEnum<surfaceSlipDisplacementPointPatchVectorField::projectMode, 3>
00052 surfaceSlipDisplacementPointPatchVectorField::projectModeNames_;
00053
00054
00055
00056
00057 void surfaceSlipDisplacementPointPatchVectorField::calcProjection
00058 (
00059 vectorField& displacement
00060 ) const
00061 {
00062 const polyMesh& mesh = patch().boundaryMesh().mesh()();
00063 const pointField& localPoints = patch().localPoints();
00064 const labelList& meshPoints = patch().meshPoints();
00065
00066
00067
00068
00069
00070
00071
00072 const scalar projectLen = mag(mesh.bounds().max()-mesh.bounds().min());
00073
00074
00075 vector projectVec;
00076 if (projectMode_ == FIXEDNORMAL)
00077 {
00078 vector n = projectDir_/mag(projectDir_);
00079 projectVec = projectLen*n;
00080 }
00081
00082
00083
00084 const pointZone* zonePtr = NULL;
00085
00086 if (frozenPointsZone_.size() > 0)
00087 {
00088 const pointZoneMesh& pZones = mesh.pointZones();
00089
00090 zonePtr = &pZones[pZones.findZoneID(frozenPointsZone_)];
00091
00092 Pout<< "surfaceSlipDisplacementPointPatchVectorField : Fixing all "
00093 << zonePtr->size() << " points in pointZone " << zonePtr->name()
00094 << endl;
00095 }
00096
00097
00098 const pointField& points0 = mesh.lookupObject<displacementFvMotionSolver>
00099 (
00100 "dynamicMeshDict"
00101 ).points0();
00102
00103
00104 pointField start(meshPoints.size());
00105 forAll(start, i)
00106 {
00107 start[i] = points0[meshPoints[i]] + displacement[i];
00108 }
00109
00110 label nNotProjected = 0;
00111
00112 if (projectMode_ == NEAREST)
00113 {
00114 List<pointIndexHit> nearest;
00115 labelList hitSurfaces;
00116 surfaces().findNearest
00117 (
00118 start,
00119 scalarField(start.size(), sqr(projectLen)),
00120 hitSurfaces,
00121 nearest
00122 );
00123
00124 forAll(nearest, i)
00125 {
00126 if (zonePtr && (zonePtr->whichPoint(meshPoints[i]) >= 0))
00127 {
00128
00129 displacement[i] = points0[meshPoints[i]] - localPoints[i];
00130 }
00131 else if (nearest[i].hit())
00132 {
00133 displacement[i] =
00134 nearest[i].hitPoint()
00135 - points0[meshPoints[i]];
00136 }
00137 else
00138 {
00139 nNotProjected++;
00140
00141 if (debug)
00142 {
00143 Pout<< " point:" << meshPoints[i]
00144 << " coord:" << localPoints[i]
00145 << " did not find any surface within " << projectLen
00146 << endl;
00147 }
00148 }
00149 }
00150 }
00151 else
00152 {
00153
00154
00155
00156 List<pointIndexHit> nearest;
00157 {
00158 labelList nearestSurface;
00159 surfaces().findNearest
00160 (
00161 start,
00162 scalarField(start.size(), sqr(SMALL)),
00163 nearestSurface,
00164 nearest
00165 );
00166 }
00167
00168
00169
00170 vectorField projectVecs(start.size(), projectVec);
00171
00172 if (projectMode_ == POINTNORMAL)
00173 {
00174 projectVecs = projectLen*patch().pointNormals();
00175 }
00176
00177
00178 scalarField offset(start.size(), 0.0);
00179 if (wedgePlane_ >= 0 && wedgePlane_ <= vector::nComponents)
00180 {
00181 forAll(offset, i)
00182 {
00183 offset[i] = start[i][wedgePlane_];
00184 start[i][wedgePlane_] = 0;
00185 projectVecs[i][wedgePlane_] = 0;
00186 }
00187 }
00188
00189 List<pointIndexHit> rightHit;
00190 {
00191 labelList rightSurf;
00192 surfaces().findAnyIntersection
00193 (
00194 start,
00195 start+projectVecs,
00196 rightSurf,
00197 rightHit
00198 );
00199 }
00200
00201 List<pointIndexHit> leftHit;
00202 {
00203 labelList leftSurf;
00204 surfaces().findAnyIntersection
00205 (
00206 start,
00207 start-projectVecs,
00208 leftSurf,
00209 leftHit
00210 );
00211 }
00212
00213
00214 forAll(displacement, i)
00215 {
00216 if (zonePtr && (zonePtr->whichPoint(meshPoints[i]) >= 0))
00217 {
00218
00219 displacement[i] = points0[meshPoints[i]] - localPoints[i];
00220 }
00221 else if (nearest[i].hit())
00222 {
00223
00224 displacement[i] =
00225 nearest[i].hitPoint()
00226 - points0[meshPoints[i]];
00227 }
00228 else
00229 {
00230 pointIndexHit interPt;
00231
00232 if (rightHit[i].hit())
00233 {
00234 if (leftHit[i].hit())
00235 {
00236 if
00237 (
00238 magSqr(rightHit[i].hitPoint()-start[i])
00239 < magSqr(leftHit[i].hitPoint()-start[i])
00240 )
00241 {
00242 interPt = rightHit[i];
00243 }
00244 else
00245 {
00246 interPt = leftHit[i];
00247 }
00248 }
00249 else
00250 {
00251 interPt = rightHit[i];
00252 }
00253 }
00254 else
00255 {
00256 if (leftHit[i].hit())
00257 {
00258 interPt = leftHit[i];
00259 }
00260 }
00261
00262
00263 if (interPt.hit())
00264 {
00265 if (wedgePlane_ >= 0 && wedgePlane_ <= vector::nComponents)
00266 {
00267 interPt.rawPoint()[wedgePlane_] += offset[i];
00268 }
00269 displacement[i] = interPt.rawPoint()-points0[meshPoints[i]];
00270 }
00271 else
00272 {
00273 nNotProjected++;
00274
00275 if (debug)
00276 {
00277 Pout<< " point:" << meshPoints[i]
00278 << " coord:" << localPoints[i]
00279 << " did not find any intersection between"
00280 << " ray from " << start[i]-projectVecs[i]
00281 << " to " << start[i]+projectVecs[i] << endl;
00282 }
00283 }
00284 }
00285 }
00286 }
00287
00288 reduce(nNotProjected, sumOp<label>());
00289
00290 if (nNotProjected > 0)
00291 {
00292 Info<< "surfaceSlipDisplacement :"
00293 << " on patch " << patch().name()
00294 << " did not project " << nNotProjected
00295 << " out of " << returnReduce(localPoints.size(), sumOp<label>())
00296 << " points." << endl;
00297 }
00298 }
00299
00300
00301
00302
00303 surfaceSlipDisplacementPointPatchVectorField::
00304 surfaceSlipDisplacementPointPatchVectorField
00305 (
00306 const pointPatch& p,
00307 const DimensionedField<vector, pointMesh>& iF
00308 )
00309 :
00310 pointPatchVectorField(p, iF),
00311 projectMode_(NEAREST),
00312 projectDir_(vector::zero),
00313 wedgePlane_(-1)
00314 {}
00315
00316
00317 surfaceSlipDisplacementPointPatchVectorField::
00318 surfaceSlipDisplacementPointPatchVectorField
00319 (
00320 const pointPatch& p,
00321 const DimensionedField<vector, pointMesh>& iF,
00322 const dictionary& dict
00323 )
00324 :
00325 pointPatchVectorField(p, iF, dict),
00326 surfacesDict_(dict.subDict("geometry")),
00327 projectMode_(projectModeNames_.read(dict.lookup("projectMode"))),
00328 projectDir_(dict.lookup("projectDirection")),
00329 wedgePlane_(readLabel(dict.lookup("wedgePlane"))),
00330 frozenPointsZone_(dict.lookupOrDefault("frozenPointsZone", word::null))
00331 {}
00332
00333
00334 surfaceSlipDisplacementPointPatchVectorField::
00335 surfaceSlipDisplacementPointPatchVectorField
00336 (
00337 const surfaceSlipDisplacementPointPatchVectorField& ppf,
00338 const pointPatch& p,
00339 const DimensionedField<vector, pointMesh>& iF,
00340 const pointPatchFieldMapper&
00341 )
00342 :
00343 pointPatchVectorField(p, iF),
00344 surfacesDict_(ppf.surfacesDict_),
00345 projectMode_(ppf.projectMode_),
00346 projectDir_(ppf.projectDir_),
00347 wedgePlane_(ppf.wedgePlane_),
00348 frozenPointsZone_(ppf.frozenPointsZone_)
00349 {}
00350
00351
00352 surfaceSlipDisplacementPointPatchVectorField::
00353 surfaceSlipDisplacementPointPatchVectorField
00354 (
00355 const surfaceSlipDisplacementPointPatchVectorField& ppf
00356 )
00357 :
00358 pointPatchVectorField(ppf),
00359 surfacesDict_(ppf.surfacesDict_),
00360 projectMode_(ppf.projectMode_),
00361 projectDir_(ppf.projectDir_),
00362 wedgePlane_(ppf.wedgePlane_),
00363 frozenPointsZone_(ppf.frozenPointsZone_)
00364 {}
00365
00366
00367 surfaceSlipDisplacementPointPatchVectorField::
00368 surfaceSlipDisplacementPointPatchVectorField
00369 (
00370 const surfaceSlipDisplacementPointPatchVectorField& ppf,
00371 const DimensionedField<vector, pointMesh>& iF
00372 )
00373 :
00374 pointPatchVectorField(ppf, iF),
00375 surfacesDict_(ppf.surfacesDict_),
00376 projectMode_(ppf.projectMode_),
00377 projectDir_(ppf.projectDir_),
00378 wedgePlane_(ppf.wedgePlane_),
00379 frozenPointsZone_(ppf.frozenPointsZone_)
00380 {}
00381
00382
00383
00384
00385 const searchableSurfaces&
00386 surfaceSlipDisplacementPointPatchVectorField::surfaces() const
00387 {
00388 if (surfacesPtr_.empty())
00389 {
00390 surfacesPtr_.reset
00391 (
00392 new searchableSurfaces
00393 (
00394 IOobject
00395 (
00396 "abc",
00397 db().time().constant(),
00398 "triSurface",
00399 db().time(),
00400 IOobject::MUST_READ,
00401 IOobject::NO_WRITE
00402 ),
00403 surfacesDict_
00404 )
00405 );
00406 }
00407 return surfacesPtr_();
00408 }
00409
00410
00411 void surfaceSlipDisplacementPointPatchVectorField::evaluate
00412 (
00413 const Pstream::commsTypes commsType
00414 )
00415 {
00416 vectorField displacement(this->patchInternalField());
00417
00418
00419 calcProjection(displacement);
00420
00421
00422 Field<vector>& iF = const_cast<Field<vector>&>(this->internalField());
00423
00424
00425 setInInternalField(iF, displacement);
00426
00427 pointPatchVectorField::evaluate(commsType);
00428 }
00429
00430
00431 void surfaceSlipDisplacementPointPatchVectorField::write(Ostream& os) const
00432 {
00433 pointPatchVectorField::write(os);
00434 os.writeKeyword("geometry") << surfacesDict_
00435 << token::END_STATEMENT << nl;
00436 os.writeKeyword("projectMode") << projectModeNames_[projectMode_]
00437 << token::END_STATEMENT << nl;
00438 os.writeKeyword("projectDirection") << projectDir_
00439 << token::END_STATEMENT << nl;
00440 os.writeKeyword("wedgePlane") << wedgePlane_
00441 << token::END_STATEMENT << nl;
00442 if (frozenPointsZone_ != word::null)
00443 {
00444 os.writeKeyword("frozenPointsZone") << frozenPointsZone_
00445 << token::END_STATEMENT << nl;
00446 }
00447 }
00448
00449
00450
00451
00452 makePointPatchTypeField
00453 (
00454 pointPatchVectorField,
00455 surfaceSlipDisplacementPointPatchVectorField
00456 );
00457
00458
00459
00460
00461 }
00462
00463