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 "motionSmoother.H"
00028 #include "meshTools.H"
00029 #include "processorPointPatchFields.H"
00030 #include "globalPointPatchFields.H"
00031 #include "pointConstraint.H"
00032 #include "syncTools.H"
00033
00034
00035
00036 template<class Type>
00037 void Foam::motionSmoother::checkConstraints
00038 (
00039 GeometricField<Type, pointPatchField, pointMesh>& pf
00040 )
00041 {
00042 typedef GeometricField<Type, pointPatchField, pointMesh> FldType;
00043
00044 const polyMesh& mesh = pf.mesh();
00045
00046 const polyBoundaryMesh& bm = mesh.boundaryMesh();
00047
00048
00049
00050 label nPatchPatchPoints = 0;
00051
00052 forAll(bm, patchi)
00053 {
00054 if(!isA<emptyPolyPatch>(bm[patchi]))
00055 {
00056 nPatchPatchPoints += bm[patchi].boundaryPoints().size();
00057 }
00058 }
00059
00060
00061 typename FldType::GeometricBoundaryField& bFld = pf.boundaryField();
00062
00063
00064
00065
00066 forAllReverse(bFld, patchi)
00067 {
00068 bFld[patchi].initEvaluate(Pstream::blocking);
00069 }
00070
00071 forAllReverse(bFld, patchi)
00072 {
00073 bFld[patchi].evaluate(Pstream::blocking);
00074 }
00075
00076
00077
00078
00079 Field<Type> boundaryPointValues(nPatchPatchPoints);
00080 nPatchPatchPoints = 0;
00081
00082 forAll(bm, patchi)
00083 {
00084 if(!isA<emptyPolyPatch>(bm[patchi]))
00085 {
00086 const labelList& bp = bm[patchi].boundaryPoints();
00087 const labelList& meshPoints = bm[patchi].meshPoints();
00088
00089 forAll(bp, pointi)
00090 {
00091 label ppp = meshPoints[bp[pointi]];
00092 boundaryPointValues[nPatchPatchPoints++] = pf[ppp];
00093 }
00094 }
00095 }
00096
00097
00098
00099
00100 bFld.evaluate();
00101
00102
00103
00104
00105 nPatchPatchPoints = 0;
00106
00107 forAll(bm, patchi)
00108 {
00109 if(!isA<emptyPolyPatch>(bm[patchi]))
00110 {
00111 const labelList& bp = bm[patchi].boundaryPoints();
00112 const labelList& meshPoints = bm[patchi].meshPoints();
00113
00114 forAll(bp, pointi)
00115 {
00116 label ppp = meshPoints[bp[pointi]];
00117
00118 const Type& savedVal = boundaryPointValues[nPatchPatchPoints++];
00119
00120 if (savedVal != pf[ppp])
00121 {
00122 FatalErrorIn
00123 (
00124 "motionSmoother::checkConstraints"
00125 "(GeometricField<Type, pointPatchField, pointMesh>&)"
00126 ) << "Patch fields are not consistent on mesh point "
00127 << ppp << " coordinate " << mesh.points()[ppp]
00128 << " at patch " << bm[patchi].name() << '.'
00129 << endl
00130 << "Reverse evaluation gives value " << savedVal
00131 << " , forward evaluation gives value " << pf[ppp]
00132 << abort(FatalError);
00133 }
00134 }
00135 }
00136 }
00137 }
00138
00139
00140 template<class Type>
00141 void Foam::motionSmoother::applyCornerConstraints
00142 (
00143 GeometricField<Type, pointPatchField, pointMesh>& pf
00144 ) const
00145 {
00146 forAll(patchPatchPointConstraintPoints_, pointi)
00147 {
00148 pf[patchPatchPointConstraintPoints_[pointi]] = transform
00149 (
00150 patchPatchPointConstraintTensors_[pointi],
00151 pf[patchPatchPointConstraintPoints_[pointi]]
00152 );
00153 }
00154 }
00155
00156
00157
00158 template <class Type>
00159 Foam::tmp<Foam::GeometricField<Type, Foam::pointPatchField, Foam::pointMesh> >
00160 Foam::motionSmoother::avg
00161 (
00162 const GeometricField<Type, pointPatchField, pointMesh>& fld,
00163 const scalarField& edgeWeight,
00164 const bool separation
00165 ) const
00166 {
00167 tmp<GeometricField<Type, pointPatchField, pointMesh> > tres
00168 (
00169 new GeometricField<Type, pointPatchField, pointMesh>
00170 (
00171 IOobject
00172 (
00173 "avg("+fld.name()+')',
00174 fld.time().timeName(),
00175 fld.db(),
00176 IOobject::NO_READ,
00177 IOobject::NO_WRITE
00178 ),
00179 fld.mesh(),
00180 dimensioned<Type>("zero", fld.dimensions(), pTraits<Type>::zero)
00181 )
00182 );
00183 GeometricField<Type, pointPatchField, pointMesh>& res = tres();
00184
00185 const polyMesh& mesh = fld.mesh()();
00186
00187
00188
00189
00190
00191
00192
00193
00194 scalarField sumWeight(mesh.nPoints(), 0.0);
00195
00196 const edgeList& edges = mesh.edges();
00197
00198 forAll(edges, edgeI)
00199 {
00200 if (isMasterEdge_.get(edgeI) == 1)
00201 {
00202 const edge& e = edges[edgeI];
00203 const scalar w = edgeWeight[edgeI];
00204
00205 res[e[0]] += w*fld[e[1]];
00206 sumWeight[e[0]] += w;
00207
00208 res[e[1]] += w*fld[e[0]];
00209 sumWeight[e[1]] += w;
00210 }
00211 }
00212
00213
00214
00215
00216
00217 syncTools::syncPointList
00218 (
00219 mesh,
00220 res,
00221 plusEqOp<Type>(),
00222 pTraits<Type>::zero,
00223 separation
00224 );
00225
00226 syncTools::syncPointList
00227 (
00228 mesh,
00229 sumWeight,
00230 plusEqOp<scalar>(),
00231 scalar(0),
00232 false
00233 );
00234
00235
00236
00237
00238
00239 forAll(res, pointI)
00240 {
00241 if (mag(sumWeight[pointI]) < VSMALL)
00242 {
00243
00244 res[pointI] = fld[pointI];
00245 }
00246 else
00247 {
00248 res[pointI] /= sumWeight[pointI];
00249 }
00250 }
00251
00252 res.correctBoundaryConditions();
00253 applyCornerConstraints(res);
00254
00255 return tres;
00256 }
00257
00258
00259
00260 template <class Type>
00261 void Foam::motionSmoother::smooth
00262 (
00263 const GeometricField<Type, pointPatchField, pointMesh>& fld,
00264 const scalarField& edgeWeight,
00265 const bool separation,
00266 GeometricField<Type, pointPatchField, pointMesh>& newFld
00267 ) const
00268 {
00269 tmp<pointVectorField> tavgFld = avg
00270 (
00271 fld,
00272 edgeWeight,
00273 separation
00274 );
00275 const pointVectorField& avgFld = tavgFld();
00276
00277 forAll(fld, pointI)
00278 {
00279 if (isInternalPoint(pointI))
00280 {
00281 newFld[pointI] = 0.5*fld[pointI] + 0.5*avgFld[pointI];
00282 }
00283 }
00284
00285 newFld.correctBoundaryConditions();
00286 applyCornerConstraints(newFld);
00287 }
00288
00289
00290
00291 template<class Type, class CombineOp>
00292 void Foam::motionSmoother::testSyncField
00293 (
00294 const Field<Type>& fld,
00295 const CombineOp& cop,
00296 const Type& zero,
00297 const bool separation
00298 ) const
00299 {
00300 if (debug)
00301 {
00302 Pout<< "testSyncField : testing synchronisation of Field<Type>."
00303 << endl;
00304 }
00305
00306 Field<Type> syncedFld(fld);
00307
00308 syncTools::syncPointList
00309 (
00310 mesh_,
00311 syncedFld,
00312 cop,
00313 zero,
00314 separation
00315 );
00316
00317 forAll(syncedFld, i)
00318 {
00319 if (syncedFld[i] != fld[i])
00320 {
00321 FatalErrorIn
00322 (
00323 "motionSmoother::testSyncField"
00324 "(const Field<Type>&, const CombineOp&"
00325 ", const Type&, const bool)"
00326 ) << "On element " << i << " value:" << fld[i]
00327 << " synchronised value:" << syncedFld[i]
00328 << abort(FatalError);
00329 }
00330 }
00331 }
00332
00333
00334