|
|
|
motionSmoother.HGo to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM; if not, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Class 00026 motionSmoother 00027 00028 Description 00029 Given a displacement moves the mesh by scaling the displacement back 00030 until there are no more mesh errors. Holds displacement field 00031 (read upon construction since need boundary conditions) and scaling factor 00032 and optional patch number on which to scale back displacement. 00033 00034 E.g. 00035 00036 // Construct iterative mesh mover. 00037 motionSmoother meshMover(mesh, labelList(1, patchI)); 00038 00039 // Set wanted displacement: 00040 meshMover.displacement() = .. 00041 00042 for (label iter = 0; iter < maxIter; iter++) 00043 { 00044 if (meshMover.scaleMesh(true)) 00045 { 00046 Info<< "Successfully moved mesh" << endl; 00047 return true; 00048 } 00049 } 00050 00051 00052 Note: shared points (parallel). A processor can have points which are 00053 part of pp on another processor but have no pp itself (i.e. it has points 00054 and/or edges but no faces of pp). Hence we have to be careful when 00055 e.g. synchronising displacements that the value from the processor which 00056 has faces of pp get priority. This is currently handled in setDisplacement 00057 by resetting the internal displacement to zero before doing anything else. 00058 The combine operator used will give preference to non-zero values. 00059 00060 SourceFiles 00061 motionSmoother.C 00062 motionSmootherTemplates.C 00063 00064 \*---------------------------------------------------------------------------*/ 00065 00066 #ifndef motionSmoother_H 00067 #define motionSmoother_H 00068 00069 #include "pointFields.H" 00070 #include "labelHashSet.H" 00071 #include "PackedList.H" 00072 #include "indirectPrimitivePatch.H" 00073 #include "className.H" 00074 #include "twoDPointCorrector.H" 00075 00076 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00077 00078 namespace Foam 00079 { 00080 00081 class polyMeshGeometry; 00082 00083 /*---------------------------------------------------------------------------*\ 00084 Class motionSmoother Declaration 00085 \*---------------------------------------------------------------------------*/ 00086 00087 class motionSmoother 00088 { 00089 // Private class 00090 00091 //- To synchronise displacements. We want max displacement since 00092 // this is what is specified on pp and internal mesh will have 00093 // zero displacement. 00094 class maxMagEqOp 00095 { 00096 00097 public: 00098 00099 void operator()(vector& x, const vector& y) const 00100 { 00101 for (direction i = 0; i < vector::nComponents; i++) 00102 { 00103 scalar magX = mag(x[i]); 00104 scalar magY = mag(y[i]); 00105 00106 if (magX < magY) 00107 { 00108 x[i] = y[i]; 00109 } 00110 else if (magX == magY) 00111 { 00112 if (y[i] > x[i]) 00113 { 00114 x[i] = y[i]; 00115 } 00116 } 00117 } 00118 } 00119 }; 00120 00121 00122 // Private data 00123 00124 //- Reference to polyMesh. Non-const since we move mesh. 00125 polyMesh& mesh_; 00126 00127 //- Reference to pointMesh 00128 pointMesh& pMesh_; 00129 00130 //- Reference to face subset of all adaptPatchIDs 00131 indirectPrimitivePatch& pp_; 00132 00133 //- Indices of fixedValue patches that we're allowed to modify the 00134 // displacement on. 00135 const labelList adaptPatchIDs_; 00136 00137 00138 // Smoothing and checking parameters 00139 dictionary paramDict_; 00140 00141 // Internal data 00142 00143 //- Displacement field 00144 pointVectorField displacement_; 00145 00146 //- Scale factor for displacement 00147 pointScalarField scale_; 00148 00149 //- Starting mesh position 00150 pointField oldPoints_; 00151 00152 //- Is mesh point on boundary or not 00153 PackedList<1> isInternalPoint_; 00154 00155 //- 2-D motion corrector 00156 twoDPointCorrector twoDCorrector_; 00157 00158 // Muli-patch constraints (from pointPatchInterpolation) 00159 00160 labelList patchPatchPointConstraintPoints_; 00161 tensorField patchPatchPointConstraintTensors_; 00162 00163 00164 // Private Member Functions 00165 00168 //template <class Type> 00169 //static Type avg 00170 //( 00171 // const GeometricField<Type, pointPatchField, pointMesh>&, 00172 // const edgeList& edges, 00173 // const pointField& points, 00174 // const labelList& edgeLabels, 00175 // const label pointI 00176 //); 00177 // 00180 //template <class Type> 00181 //static Type avg 00182 //( 00183 // const GeometricField<Type, pointPatchField, pointMesh>&, 00184 // const scalarField& edgeGamma, 00185 // const edgeList& edges, 00186 // const pointField& points, 00187 // const labelList& edgeLabels, 00188 // const label pointI 00189 //); 00190 00191 //- Average of connected points. 00192 template <class Type> 00193 tmp<GeometricField<Type, pointPatchField, pointMesh> > avg 00194 ( 00195 const GeometricField<Type, pointPatchField, pointMesh>& fld, 00196 const scalarField& edgeWeight, 00197 const bool separation 00198 ) const; 00199 00200 //- Check constraints 00201 template<class Type> 00202 static void checkConstraints 00203 ( 00204 GeometricField<Type, pointPatchField, pointMesh>& 00205 ); 00206 00207 //- Multi-patch constraints 00208 template<class Type> 00209 void applyCornerConstraints 00210 ( 00211 GeometricField<Type, pointPatchField, pointMesh>& 00212 ) const; 00213 00214 //- Test synchronisation of pointField 00215 template<class Type, class CombineOp> 00216 void testSyncField 00217 ( 00218 const Field<Type>&, 00219 const CombineOp& cop, 00220 const Type& zero, 00221 const bool separation 00222 ) const; 00223 00224 //- Assemble tensors for multi-patch constraints 00225 void makePatchPatchAddressing(); 00226 00227 static void checkFld(const pointScalarField&); 00228 00229 //- Get points used by given faces 00230 labelHashSet getPoints(const labelHashSet&) const; 00231 00232 //- explicit smoothing and min on all internal points 00233 void minSmooth(const pointScalarField&, pointScalarField&) const; 00234 00235 //- same but only on selected points (usually patch points) 00236 void minSmooth 00237 ( 00238 const labelList& meshPoints, 00239 const pointScalarField& fld, 00240 pointScalarField& newFld 00241 ) const; 00242 00243 //- Scale certain (internal) points of a field 00244 void scaleField 00245 ( 00246 const labelHashSet& pointLabels, 00247 const scalar scale, 00248 pointScalarField& 00249 ) const; 00250 00251 //- As above but points have to be in meshPoints as well 00252 // (usually to scale patch points) 00253 void scaleField 00254 ( 00255 const labelList& meshPoints, 00256 const labelHashSet& pointLabels, 00257 const scalar scale, 00258 pointScalarField& 00259 ) const; 00260 00261 //- Helper function. Is point internal? 00262 bool isInternalPoint(const label pointI) const; 00263 00264 //- Disallow default bitwise copy construct 00265 motionSmoother(const motionSmoother&); 00266 00267 //- Disallow default bitwise assignment 00268 void operator=(const motionSmoother&); 00269 00270 00271 public: 00272 00273 ClassName("motionSmoother"); 00274 00275 // Constructors 00276 00277 //- Construct from mesh, patches to work on and smoothing parameters. 00278 // Reads displacement field (only boundary conditions used) 00279 motionSmoother 00280 ( 00281 polyMesh&, 00282 pointMesh&, 00283 indirectPrimitivePatch& pp, // 'outside' points 00284 const labelList& adaptPatchIDs, // patches forming 'outside' 00285 const dictionary& paramDict 00286 ); 00287 00288 //- Construct from mesh, patches to work on and smoothing parameters and 00289 // displacementfield (only boundary conditions used) 00290 motionSmoother 00291 ( 00292 polyMesh&, 00293 indirectPrimitivePatch& pp, // 'outside' points 00294 const labelList& adaptPatchIDs, // patches forming 'outside' 00295 const pointVectorField&, 00296 const dictionary& paramDict 00297 ); 00298 00299 00300 // Destructor 00301 00302 ~motionSmoother(); 00303 00304 00305 // Member Functions 00306 00307 // Access 00308 00309 //- Reference to mesh 00310 const polyMesh& mesh() const; 00311 00312 //- Reference to pointMesh 00313 const pointMesh& pMesh() const; 00314 00315 //- Reference to patch 00316 const indirectPrimitivePatch& patch() const; 00317 00318 //- Patch labels that are being adapted 00319 const labelList& adaptPatchIDs() const; 00320 00321 //- Reference to displacement field 00322 pointVectorField& displacement(); 00323 00324 //- Reference to displacement field 00325 const pointVectorField& displacement() const; 00326 00327 //- Reference to scale field 00328 const pointScalarField& scale() const; 00329 00330 //- Starting mesh position 00331 const pointField& oldPoints() const; 00332 00333 //- Return reference to 2D point motion correction 00334 twoDPointCorrector& twoDCorrector() 00335 { 00336 return twoDCorrector_; 00337 } 00338 00339 00340 00341 // Edit 00342 00343 //- Take over existing mesh position. 00344 void correct(); 00345 00346 //- Set displacement field from displacement on patch points. 00347 // Modify provided displacement to be consistent with actual 00348 // boundary conditions on displacement. Note: resets the 00349 // displacement to be 0 on coupled patches beforehand 00350 // to make sure shared points 00351 // partially on pp (on some processors) and partially not 00352 // (on other processors) get the value from pp. 00353 void setDisplacement(pointField& patchDisp); 00354 00355 //- Special correctBoundaryConditions which evaluates fixedValue 00356 // patches first so they get overwritten with any constraint 00357 // bc's. 00358 void correctBoundaryConditions(pointVectorField&) const; 00359 00360 //- Move mesh. Does 2D correction (modifies passed pointField) and 00361 // polyMesh::movePoints. Returns swept volumes. 00362 tmp<scalarField> movePoints(pointField&); 00363 00364 //- Set the errorReduction (by how much to scale the displacement 00365 // at error locations) parameter. Returns the old value. 00366 // Set to 0 (so revert to old mesh) grows out one cell layer 00367 // from error faces. 00368 scalar setErrorReduction(const scalar); 00369 00370 //- Move mesh with given scale. Return true if mesh ok or has 00371 // less than nAllow errors, false 00372 // otherwise and locally update scale. Smoothmesh=false means only 00373 // patch points get moved. 00374 // Parallel ok (as long as displacement field is consistent 00375 // across patches) 00376 bool scaleMesh 00377 ( 00378 const bool smoothMesh = true, 00379 const label nAllow = 0 00380 ); 00381 00382 //- Update topology 00383 void updateMesh(); 00384 00385 //- Check mesh with mesh settings in dict. Collects incorrect faces 00386 // in set. Returns true if one or more faces in error. 00387 // Parallel ok. 00388 static bool checkMesh 00389 ( 00390 const bool report, 00391 const polyMesh& mesh, 00392 const dictionary& dict, 00393 labelHashSet& wrongFaces 00394 ); 00395 00396 //- Check part of mesh with mesh settings in dict. 00397 // Collects incorrect faces in set. Returns true if one or 00398 // more faces in error. Parallel ok. 00399 static bool checkMesh 00400 ( 00401 const bool report, 00402 const dictionary& dict, 00403 const polyMeshGeometry&, 00404 const labelList& checkFaces, 00405 labelHashSet& wrongFaces 00406 ); 00407 00408 // Helper functions to manipulate displacement vector. 00409 00411 //template <class Type> 00412 //void smooth 00413 //( 00414 // GeometricField<Type, pointPatchField, pointMesh>& 00415 //) const; 00416 00417 //- Fully explicit smoothing of internal points with varying 00418 // diffusivity. 00419 template <class Type> 00420 void smooth 00421 ( 00422 const GeometricField<Type, pointPatchField, pointMesh>& fld, 00423 const scalarField& edgeWeight, 00424 const bool separation, 00425 GeometricField<Type, pointPatchField, pointMesh>& newFld 00426 ) const; 00427 }; 00428 00429 00430 template<> 00431 void motionSmoother::applyCornerConstraints<scalar> 00432 ( 00433 GeometricField<scalar, pointPatchField, pointMesh>& pf 00434 ) const; 00435 00436 00437 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00438 00439 } // End namespace Foam 00440 00441 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00442 00443 #ifdef NoRepository 00444 # include "motionSmootherTemplates.C" 00445 #endif 00446 00447 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00448 00449 #endif 00450 00451 // ************************************************************************* // |