1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "surfaceSlipDisplacementPointPatchVectorField.H"
28 #include "addToRunTimeSelectionTable.H"
30 #include "transformField.H"
32 #include "displacementLaplacianFvMotionSolver.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
43 NamedEnum<surfaceSlipDisplacementPointPatchVectorField::followMode, 3>::
51 const NamedEnum<surfaceSlipDisplacementPointPatchVectorField::followMode, 3>
52 surfaceSlipDisplacementPointPatchVectorField::followModeNames_;
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 surfaceSlipDisplacementPointPatchVectorField::
58 surfaceSlipDisplacementPointPatchVectorField
61 const DimensionedField<vector, pointMesh>& iF
64 pointPatchVectorField(p, iF),
65 projectMode_(NEAREST),
66 projectDir_(vector::zero),
71 surfaceSlipDisplacementPointPatchVectorField::
72 surfaceSlipDisplacementPointPatchVectorField
75 const DimensionedField<vector, pointMesh>& iF,
76 const dictionary& dict
79 pointPatchVectorField(p, iF, dict),
80 surfacesDict_(dict.subDict("geometry")),
81 projectMode_(followModeNames_.read(dict.lookup("followMode"))),
82 projectDir_(dict.lookup("projectDirection")),
83 wedgePlane_(readLabel(dict.lookup("wedgePlane"))),
84 frozenPointsZone_(dict.lookup("frozenPointsZone"))
88 surfaceSlipDisplacementPointPatchVectorField::
89 surfaceSlipDisplacementPointPatchVectorField
91 const surfaceSlipDisplacementPointPatchVectorField& ppf,
93 const DimensionedField<vector, pointMesh>& iF,
94 const pointPatchFieldMapper&
97 pointPatchVectorField(p, iF),
98 surfacesDict_(ppf.surfacesDict()),
99 projectMode_(ppf.projectMode()),
100 projectDir_(ppf.projectDir()),
101 wedgePlane_(ppf.wedgePlane()),
102 frozenPointsZone_(ppf.frozenPointsZone())
106 surfaceSlipDisplacementPointPatchVectorField::
107 surfaceSlipDisplacementPointPatchVectorField
109 const surfaceSlipDisplacementPointPatchVectorField& ppf
112 pointPatchVectorField(ppf),
113 surfacesDict_(ppf.surfacesDict()),
114 projectMode_(ppf.projectMode()),
115 projectDir_(ppf.projectDir()),
116 wedgePlane_(ppf.wedgePlane()),
117 frozenPointsZone_(ppf.frozenPointsZone())
121 surfaceSlipDisplacementPointPatchVectorField::
122 surfaceSlipDisplacementPointPatchVectorField
124 const surfaceSlipDisplacementPointPatchVectorField& ppf,
125 const DimensionedField<vector, pointMesh>& iF
128 pointPatchVectorField(ppf, iF),
129 surfacesDict_(ppf.surfacesDict()),
130 projectMode_(ppf.projectMode()),
131 projectDir_(ppf.projectDir()),
132 wedgePlane_(ppf.wedgePlane()),
133 frozenPointsZone_(ppf.frozenPointsZone())
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 const searchableSurfaces& surfaceSlipDisplacementPointPatchVectorField::
142 if (!surfacesPtr_.valid())
146 new searchableSurfaces
151 db().time().constant(), // directory
152 "triSurface", // instance
153 db().time(), // registry
161 return surfacesPtr_();
165 void surfaceSlipDisplacementPointPatchVectorField::evaluate
167 const Pstream::commsTypes commsType
170 const polyMesh& mesh = patch().boundaryMesh().mesh()();
172 //const scalar deltaT = mesh.time().deltaT().value();
174 // Construct large enough vector in direction of projectDir so
175 // we're guaranteed to hit something.
177 const scalar projectLen = mag(mesh.bounds().max()-mesh.bounds().min());
179 // For case of fixed projection vector:
181 if (projectMode_ == FIXEDNORMAL)
183 vector n = projectDir_/mag(projectDir_);
184 projectVec = projectLen*n;
187 //- Per point projection vector:
189 const pointField& localPoints = patch().localPoints();
190 const labelList& meshPoints = patch().meshPoints();
192 vectorField displacement(this->patchInternalField());
195 // Get fixed points (bit of a hack)
196 const pointZone* zonePtr = NULL;
198 if (frozenPointsZone_.size() > 0)
200 const pointZoneMesh& pZones = mesh.pointZones();
202 zonePtr = &pZones[pZones.findZoneID(frozenPointsZone_)];
204 Pout<< "surfaceSlipDisplacementPointPatchVectorField : Fixing all "
205 << zonePtr->size() << " points in pointZone " << zonePtr->name()
209 // Get the starting locations from the motionSolver
210 const displacementLaplacianFvMotionSolver& motionSolver =
211 mesh.lookupObject<displacementLaplacianFvMotionSolver>
215 const pointField& points0 = motionSolver.points0();
221 pointField start(meshPoints.size());
224 start[i] = points0[meshPoints[i]] + displacement[i];
227 if (projectMode_ == NEAREST)
229 List<pointIndexHit> nearest;
230 labelList hitSurfaces;
231 surfaces().findNearest
234 scalarField(start.size(), sqr(projectLen)),
241 if (zonePtr && (zonePtr->whichPoint(meshPoints[i]) >= 0))
243 // Fixed point. Reset to point0 location.
244 displacement[i] = points0[meshPoints[i]] - localPoints[i];
246 else if (nearest[i].hit())
249 nearest[i].hitPoint()
250 - points0[meshPoints[i]];
254 Pout<< " point:" << meshPoints[i]
255 << " coord:" << localPoints[i]
256 << " did not find any surface within " << projectLen
263 // Do tests on all points. Combine later on.
265 // 1. Check if already on surface
266 List<pointIndexHit> nearest;
268 labelList nearestSurface;
269 surfaces().findNearest
272 scalarField(start.size(), sqr(SMALL)),
278 // 2. intersection. (combined later on with information from nearest
280 vectorField projectVecs(start.size(), projectVec);
282 if (projectMode_ == POINTNORMAL)
284 projectVecs = projectLen*patch().pointNormals();
287 // Knock out any wedge component
288 scalarField offset(start.size(), 0.0);
289 if (wedgePlane_ >= 0 && wedgePlane_ <= vector::nComponents)
293 offset[i] = start[i][wedgePlane_];
294 start[i][wedgePlane_] = 0;
295 projectVecs[i][wedgePlane_] = 0;
299 List<pointIndexHit> rightHit;
302 surfaces().findAnyIntersection
311 List<pointIndexHit> leftHit;
314 surfaces().findAnyIntersection
323 // 3. Choose either -fixed, nearest, right, left.
324 forAll(displacement, i)
326 if (zonePtr && (zonePtr->whichPoint(meshPoints[i]) >= 0))
328 // Fixed point. Reset to point0 location.
329 displacement[i] = points0[meshPoints[i]] - localPoints[i];
331 else if (nearest[i].hit())
335 nearest[i].hitPoint()
336 - points0[meshPoints[i]];
340 pointIndexHit interPt;
342 if (rightHit[i].hit())
344 if (leftHit[i].hit())
348 magSqr(rightHit[i].hitPoint()-start[i])
349 < magSqr(leftHit[i].hitPoint()-start[i])
352 interPt = rightHit[i];
356 interPt = leftHit[i];
361 interPt = rightHit[i];
366 if (leftHit[i].hit())
368 interPt = leftHit[i];
375 if (wedgePlane_ >= 0 && wedgePlane_ <= vector::nComponents)
377 interPt.rawPoint()[wedgePlane_] += offset[i];
379 displacement[i] = interPt.rawPoint()-points0[meshPoints[i]];
383 Pout<< " point:" << meshPoints[i]
384 << " coord:" << localPoints[i]
385 << " did not find any intersection between ray from "
386 << start[i]-projectVecs[i]
387 << " to " << start[i]+projectVecs[i]
394 // Get internal field to insert values into
395 Field<vector>& iF = const_cast<Field<vector>&>(this->internalField());
397 //setInInternalField(iF, motionU);
398 setInInternalField(iF, displacement);
400 pointPatchVectorField::evaluate(commsType);
404 void surfaceSlipDisplacementPointPatchVectorField::write(Ostream& os) const
406 pointPatchVectorField::write(os);
407 os.writeKeyword("geometry") << surfacesDict_
408 << token::END_STATEMENT << nl;
409 os.writeKeyword("followMode") << followModeNames_[projectMode_]
410 << token::END_STATEMENT << nl;
411 os.writeKeyword("projectDirection") << projectDir_
412 << token::END_STATEMENT << nl;
413 os.writeKeyword("wedgePlane") << wedgePlane_
414 << token::END_STATEMENT << nl;
415 os.writeKeyword("frozenPointsZone") << frozenPointsZone_
416 << token::END_STATEMENT << nl;
420 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
422 makePointPatchTypeField
424 pointPatchVectorField,
425 surfaceSlipDisplacementPointPatchVectorField
429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
431 } // End namespace Foam
433 // ************************************************************************* //