1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
29 Thin interface to the Mesquite Mesh Improvement library.
30 Also provides surface-mesh smoothing capabilities.
33 mesquiteMotionSolver.C
35 \*---------------------------------------------------------------------------*/
37 #ifndef mesquiteMotionSolver_H
38 #define mesquiteMotionSolver_H
40 #include "motionSolver.H"
45 #include "labelPair.H"
46 #include "pointIOField.H"
47 #include "MeshObject.H"
50 // Have gcc ignore certain warnings while including mesquite headers
51 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
52 # pragma GCC diagnostic ignored "-Wold-style-cast"
55 #include "Mesquite_all_headers.hpp"
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 // Class forward declarations
65 /*---------------------------------------------------------------------------*\
66 Class mesquiteMotionSolver Declaration
67 \*---------------------------------------------------------------------------*/
69 class mesquiteMotionSolver
72 public MeshObject<polyMesh, mesquiteMotionSolver>
77 //- The mesh to be moved
78 const polyMesh& Mesh_;
80 //- Mesh characteristics [2D/3D]
83 //- Flag to determine if arrays have been initialized
84 bool arraysInitialized_;
87 unsigned long nPoints_;
89 //- Number of elements
90 unsigned long nCells_;
92 //- Number of auxiliary points
93 labelList nAuxPoints_;
95 //- Number of auxiliary elements
98 //- Switch to toggle surface smoothing
99 Switch surfaceSmoothing_;
101 //- Switch to toggle volume correction
102 Switch volumeCorrection_;
104 //- Specify tolerance for volume correction
105 scalar volCorrTolerance_;
107 //- Specify max volume correction iterations
108 label volCorrMaxIter_;
110 // Specify tolerance for the CG solver
113 //- Specify multiple mesh-motion sweeps
116 //- Specify the surface-smoothing interval
119 //- Specify a relaxation factor for surface-smoothing
122 //- Vertex coordinate array passed into Mesquite
123 mutable List<double> vtxCoords_;
125 //- Connectivity array passed into mesquite
126 mutable List<unsigned long> cellToNode_;
128 //- Flag array for vertices (fixed/free)
129 mutable List<int> fixFlags_;
131 //- Array with element types
132 mutable List<Mesquite::EntityTopology> mixedTypes_;
135 mutable pointIOField refPoints_;
137 //- Original points prior to surface-smoothing
138 mutable pointField origPoints_;
140 //- Quality metric list
143 //- Pointers to base element metric class
144 HashTable<autoPtr<Mesquite::QualityMetric> > qMetricTable_;
146 //- Pointer to base objective function
147 autoPtr<Mesquite::ObjectiveFunction> objFunction_;
149 //- Pointer to base optimization algorithm (vertex mover)
150 autoPtr<Mesquite::VertexMover> optAlgorithm_;
152 //- Termination criteria
153 Mesquite::TerminationCriterion tcInner_;
154 Mesquite::TerminationCriterion tcOuter_;
156 //- Data specific to Laplacian surface smoothing
159 List<vectorField> pNormals_;
160 List<vectorField> gradEdge_;
161 List<vectorField> localPts_;
162 List<scalarField> edgeMarker_;
164 //- Data for the auxiliary entities
165 labelList procIndices_;
166 scalarField pointFractions_;
167 labelListList procPointLabels_;
168 List<List<labelPair> > globalProcPoints_;
170 List<Map<label> > unmatchedRecvPoints_;
171 List<vectorField> sendSurfFields_, recvSurfFields_;
172 List<Map<label> > sendSurfPointMap_, recvSurfPointMap_;
174 List<Map<label> > sendPointMap_, recvPointMap_;
175 List<labelList> sendCellToNode_, recvCellToNode_;
176 List<vectorField> sendPointBuffer_, recvPointBuffer_;
178 //- Explicit patch coupling for surface smoothing
179 Map<label> patchCoupling_;
181 // Fields for the CG solver
188 scalarField pointMarker_;
192 // Private Member Functions
194 // Sparse Matrix multiply
195 void A(const vectorField& p, vectorField& w);
198 scalar dot(const vectorField& f1, const vectorField& f2);
203 const vectorField& b,
210 // Compute the normalization factor for the matrix
213 const vectorField& x,
214 const vectorField& b,
215 const vectorField& w,
216 vectorField& tmpField
219 // Component-wise sumMag
220 scalar cmptSumMag(const vectorField& field);
222 // Transfer buffers for surface point fields
223 void transferBuffers(vectorField &field);
225 // Apply boundary conditions
226 void applyBCs(vectorField &field);
228 // Private member function to compute connectivity data
231 // Private member function to construct parallel connectivity data
232 void initParallelConnectivity();
235 void parWrite(const label toID, const label& data);
237 // Parallel send (for lists)
238 template <class Type>
239 void parWrite(const label toID, const UList<Type>& data);
242 void parRead(const label fromID, label& data);
244 // Parallel receive (for lists)
245 template <class Type>
246 void parRead(const label fromID, UList<Type>& data);
248 // Identify coupled patches
249 void identifyCoupledPatches();
251 // Prepare for parallel surface smoothing
252 void initParallelSurfaceSmoothing();
254 // Prepare mesquite connectivity for parallel runs
255 void initMesquiteParallelArrays();
257 // Copy auxiliary points to/from buffers
258 void copyAuxiliaryPoints(bool firstCopy);
260 // Private member functions to read dictionary options
263 // Apply fixed-value boundary conditions, if any.
264 void applyFixedValuePatches();
266 // Private member function to perform Laplacian surface smoothing
267 void smoothSurfaces();
269 // Compute quality of a tetrahedral cell
273 const pointField& pField,
274 bool returnVolume = false
277 // Private member function to check for invalid
278 // cells and correct if necessary.
279 void correctInvalidCells();
281 // Correct global volume
282 void correctGlobalVolume();
284 // Enforce cylindrical constraints for slip-patches
285 void enforceCylindricalConstraints();
287 // Prepare point-normals with updated point positions
288 void preparePointNormals();
290 // Utility method to check validity of cells connected to a point.
294 const labelList& jList,
298 // Update on topology change
299 void update(const mapPolyMesh&);
303 //- Runtime type information
304 TypeName("mesquiteMotionSolver");
309 //- Construct from polyMesh
310 mesquiteMotionSolver(const polyMesh& mesh);
312 mesquiteMotionSolver(const polyMesh& mesh, Istream& msData);
316 virtual ~mesquiteMotionSolver();
321 //- Return reference to the mesh to be moved
322 const polyMesh& mesh() const
327 //- Return point location obtained from the current motion field
328 virtual tmp<pointField> curPoints() const;
331 virtual void solve();
334 virtual bool movePoints() const;
337 virtual void updateMesh(const mapPolyMesh&);
339 //- Update topology (using meshObjectBase)
340 virtual bool updateMesh(const mapPolyMesh&) const;
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
346 } // End namespace Foam
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
352 // ************************************************************************* //