Merge remote-tracking branch 'origin/nr/multiSolverFix' into nextRelease
[foam-extend-3.2.git] / src / sampling / meshToMeshInterpolation / meshToMesh / meshToMesh.H
blob68bd5c97f32bec05572c6286e6fe8765ac626058
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 Class
26     Foam::meshToMesh
28 Description
29     mesh to mesh interpolation class.
31 SourceFiles
32     meshToMesh.C
33     calculateMeshToMeshAddressing.C
34     calculateMeshToMeshWeights.C
35     meshToMeshInterpolate.C
37 \*---------------------------------------------------------------------------*/
39 #ifndef meshtoMesh_H
40 #define meshtoMesh_H
42 #include "fvMesh.H"
43 #include "HashTable.H"
44 #include "fvPatchMapper.H"
45 #include "scalarList.H"
46 #include "className.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 namespace Foam
53 template<class Type>
54 class octree;
56 class octreeDataCell;
58 /*---------------------------------------------------------------------------*\
59                            Class meshToMesh Declaration
60 \*---------------------------------------------------------------------------*/
62 class meshToMesh
64     // Private data
66         // mesh references
68         const fvMesh& fromMesh_;
69         const fvMesh& toMesh_;
71         //- fromMesh patch labels
72         HashTable<label> fromMeshPatches_;
74         //- toMesh patch labels
75         HashTable<label> toMeshPatches_;
77         //- Patch map
78         HashTable<word> patchMap_;
80         //- toMesh patch labels which cut the from-mesh
81         HashTable<label> cuttingPatches_;
83         //- Cell addressing
84         labelList cellAddressing_;
86         //- Boundary addressing
87         labelListList boundaryAddressing_;
89         //- Inverse-distance interpolation weights
90         mutable scalarListList* inverseDistanceWeightsPtr_;
93     // Private Member Functions
95         void calcAddressing();
97         void cellAddresses
98         (
99             labelList& cells,
100             const pointField& points,
101             const fvMesh& fromMesh,
102             const List<bool>& boundaryCell,
103             const octree<octreeDataCell>& oc,
104             bool forceFind = false
105         ) const;
107         void calculateInverseDistanceWeights() const;
109         const scalarListList& inverseDistanceWeights() const;
112     // Private static data members
114         //- Direct hit tolerance
115         static const scalar directHitTol;
117         //- Cell centre distance required to establish a hit
118         static const scalar cellCentreDistanceTol;
121 public:
123     // Declare name of the class and its debug switch
124     ClassName("meshToMesh");
127     //- Enumeration specifying required accuracy
128     enum order
129     {
130         MAP,
131         INTERPOLATE,
132         CELL_POINT_INTERPOLATE
133     };
136     // Constructors
138         //- Construct from the two meshes, the patch name map for the patches
139         //  to be interpolated and the names of the toMesh-patches which
140         //  cut the fromMesh
141         meshToMesh
142         (
143             const fvMesh& fromMesh,
144             const fvMesh& toMesh,
145             const HashTable<word>& patchMap,
146             const wordList& cuttingPatchNames
147         );
149         //- Construct from the two meshes assuming there is an exact mapping
150         //  between the patches
151         meshToMesh
152         (
153             const fvMesh& fromMesh,
154             const fvMesh& toMesh
155         );
158     // Destructor
160         ~meshToMesh();
163     //- Patch-field interpolation class
164     class patchFieldInterpolator
165     :
166         public fvPatchFieldMapper
167     {
168         const labelList& directAddressing_;
170     public:
172         // Constructors
174             //- Construct given addressing
175             patchFieldInterpolator(const labelList& addr)
176             :
177                 directAddressing_(addr)
178             {}
181         // Destructor
183             virtual ~patchFieldInterpolator()
184             {}
187         // Member Functions
189             virtual label size() const
190             {
191                 return directAddressing_.size();
192             }
194             virtual label sizeBeforeMapping() const
195             {
196                 return directAddressing_.size();
197             }
199             virtual bool direct() const
200             {
201                 return true;
202             }
204             const labelList& directAddressing() const
205             {
206                 return directAddressing_;
207             }
208     };
211     // Member Functions
213         // Access
215             const fvMesh& fromMesh() const
216             {
217                 return fromMesh_;
218             }
220             const fvMesh& toMesh() const
221             {
222                 return toMesh_;
223             }
225             //- From toMesh cells to fromMesh cells
226             const labelList& cellAddressing() const
227             {
228                 return cellAddressing_;
229             }
231         // Interpolation
233             //- Map field
234             template<class Type>
235             void mapField
236             (
237                 Field<Type>&,
238                 const Field<Type>&,
239                 const labelList& adr
240             ) const;
242             //- Interpolate field using inverse-distance weights
243             template<class Type>
244             void interpolateField
245             (
246                 Field<Type>&,
247                 const GeometricField<Type, fvPatchField, volMesh>&,
248                 const labelList& adr,
249                 const scalarListList& weights
250             ) const;
252             //- Interpolate field using cell-point interpolation
253             template<class Type>
254             void interpolateField
255             (
256                 Field<Type>&,
257                 const GeometricField<Type, fvPatchField, volMesh>&,
258                 const labelList& adr,
259                 const vectorField& centres
260             ) const;
263             //- Interpolate internal volume field
264             template<class Type>
265             void interpolateInternalField
266             (
267                 Field<Type>&,
268                 const GeometricField<Type, fvPatchField, volMesh>&,
269                 order=INTERPOLATE
270             ) const;
272             template<class Type>
273             void interpolateInternalField
274             (
275                 Field<Type>&,
276                 const tmp<GeometricField<Type, fvPatchField, volMesh> >&,
277                 order=INTERPOLATE
278             ) const;
281             //- Interpolate volume field
282             template<class Type>
283             void interpolate
284             (
285                 GeometricField<Type, fvPatchField, volMesh>&,
286                 const GeometricField<Type, fvPatchField, volMesh>&,
287                 order=INTERPOLATE
288             ) const;
290             template<class Type>
291             void interpolate
292             (
293                 GeometricField<Type, fvPatchField, volMesh>&,
294                 const tmp<GeometricField<Type, fvPatchField, volMesh> >&,
295                 order=INTERPOLATE
296             ) const;
299             //- Interpolate volume field
300             template<class Type>
301             tmp<GeometricField<Type, fvPatchField, volMesh> > interpolate
302             (
303                 const GeometricField<Type, fvPatchField, volMesh>&,
304                 order=INTERPOLATE
305             ) const;
307             template<class Type>
308             tmp<GeometricField<Type, fvPatchField, volMesh> > interpolate
309             (
310                 const tmp<GeometricField<Type, fvPatchField, volMesh> >&,
311                 order=INTERPOLATE
312             ) const;
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
318 } // End namespace Foam
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 #ifdef NoRepository
323 #   include "meshToMeshInterpolate.C"
324 #endif
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
328 #endif
330 // ************************************************************************* //