FreeFOAM The Cross-Platform CFD Toolkit
meshToMeshInterpolate.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "meshToMesh.H"
27 #include <finiteVolume/volFields.H>
29 #include <OpenFOAM/SubField.H>
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38 
39 template<class Type>
41 (
42  Field<Type>& toF,
43  const Field<Type>& fromVf,
44  const labelList& adr
45 ) const
46 {
47  // Direct mapping of nearest-cell values
48 
49  forAll(toF, celli)
50  {
51  if (adr[celli] != -1)
52  {
53  toF[celli] = fromVf[adr[celli]];
54  }
55  }
56 
57  //toF.map(fromVf, adr);
58 }
59 
60 
61 template<class Type>
63 (
64  Field<Type>& toF,
66  const labelList& adr,
67  const scalarListList& weights
68 ) const
69 {
70  // Inverse distance weighted interpolation
71 
72  // get reference to cellCells
73  const labelListList& cc = fromMesh_.cellCells();
74 
75  forAll (toF, celli)
76  {
77  if (adr[celli] != -1)
78  {
79  const labelList& neighbours = cc[adr[celli]];
80  const scalarList& w = weights[celli];
81 
82  toF[celli] = fromVf[adr[celli]]*w[0];
83 
84  for (label ni = 1; ni < w.size(); ni++)
85  {
86  toF[celli] += fromVf[neighbours[ni - 1]]*w[ni];
87  }
88  }
89  }
90 }
91 
92 
93 template<class Type>
95 (
96  Field<Type>& toF,
98  const labelList& adr,
99  const vectorField& centres
100 ) const
101 {
102  // Cell-Point interpolation
103  interpolationCellPoint<Type> interpolator(fromVf);
104 
105  forAll (toF, celli)
106  {
107  if (adr[celli] != -1)
108  {
109  toF[celli] = interpolator.interpolate
110  (
111  centres[celli],
112  adr[celli]
113  );
114  }
115  }
116 }
117 
118 
119 template<class Type>
121 (
122  Field<Type>& toF,
125 ) const
126 {
127  if (fromVf.mesh() != fromMesh_)
128  {
130  (
131  "meshToMesh::interpolateInternalField(Field<Type>& toF, "
132  "const GeometricField<Type, fvPatchField, volMesh>& fromVf, "
133  "meshToMesh::order ord) const"
134  ) << "the argument field does not correspond to the right mesh. "
135  << "Field size: " << fromVf.size()
136  << " mesh size: " << fromMesh_.nCells()
137  << exit(FatalError);
138  }
139 
140  if (toF.size() != toMesh_.nCells())
141  {
143  (
144  "meshToMesh::interpolateInternalField(Field<Type>& toF, "
145  "const GeometricField<Type, fvPatchField, volMesh>& fromVf, "
146  "meshToMesh::order ord) const"
147  ) << "the argument field does not correspond to the right mesh. "
148  << "Field size: " << toF.size()
149  << " mesh size: " << toMesh_.nCells()
150  << exit(FatalError);
151  }
152 
153  switch(ord)
154  {
155  case MAP:
156  mapField(toF, fromVf, cellAddressing_);
157  break;
158 
159  case INTERPOLATE:
160  interpolateField
161  (
162  toF,
163  fromVf,
164  cellAddressing_,
165  inverseDistanceWeights()
166  );
167  break;
168 
169  case CELL_POINT_INTERPOLATE:
170  interpolateField
171  (
172  toF,
173  fromVf,
174  cellAddressing_,
175  toMesh_.cellCentres()
176  );
177  break;
178 
179  default:
181  (
182  "meshToMesh::interpolateInternalField(Field<Type>& toF, "
183  "const GeometricField<Type, fvPatchField, volMesh>& fromVf, "
184  "meshToMesh::order ord) const"
185  ) << "unknown interpolation scheme " << ord
186  << exit(FatalError);
187  }
188 }
189 
190 
191 template<class Type>
193 (
194  Field<Type>& toF,
197 ) const
198 {
199  interpolateInternalField(toF, tfromVf(), ord);
200  tfromVf.clear();
201 }
202 
203 
204 template<class Type>
206 (
210 ) const
211 {
212  interpolateInternalField(toVf, fromVf, ord);
213 
214  forAll (toMesh_.boundaryMesh(), patchi)
215  {
216  const fvPatch& toPatch = toMesh_.boundary()[patchi];
217 
218  if (cuttingPatches_.found(toPatch.name()))
219  {
220  switch(ord)
221  {
222  case MAP:
223  mapField
224  (
225  toVf.boundaryField()[patchi],
226  fromVf,
227  boundaryAddressing_[patchi]
228  );
229  break;
230 
231  case INTERPOLATE:
232  interpolateField
233  (
234  toVf.boundaryField()[patchi],
235  fromVf,
236  boundaryAddressing_[patchi],
237  toPatch.Cf()
238  );
239  break;
240 
241  case CELL_POINT_INTERPOLATE:
242  interpolateField
243  (
244  toVf.boundaryField()[patchi],
245  fromVf,
246  boundaryAddressing_[patchi],
247  toPatch.Cf()
248  );
249  break;
250 
251  default:
253  (
254  "meshToMesh::interpolate("
255  "GeometricField<Type, fvPatchField, volMesh>& toVf, "
256  "const GeometricField<Type, fvPatchField, volMesh>& "
257  "fromVf, meshToMesh::order ord) const"
258  ) << "unknown interpolation scheme " << ord
259  << exit(FatalError);
260  }
261 
263  {
264  refCast<mixedFvPatchField<Type> >
265  (
266  toVf.boundaryField()[patchi]
267  ).refValue() = toVf.boundaryField()[patchi];
268  }
269  }
270  else if
271  (
272  patchMap_.found(toPatch.name())
273  && fromMeshPatches_.found(patchMap_.find(toPatch.name())())
274  )
275  {
276  /*
277  toVf.boundaryField()[patchi].map
278  (
279  fromVf.boundaryField()
280  [
281  fromMeshPatches_.find(patchMap_.find(toPatch.name())())()
282  ],
283  boundaryAddressing_[patchi]
284  );
285  */
286 
287  mapField
288  (
289  toVf.boundaryField()[patchi],
290  fromVf.boundaryField()
291  [
292  fromMeshPatches_.find(patchMap_.find(toPatch.name())())()
293  ],
294  boundaryAddressing_[patchi]
295  );
296  }
297  }
298 }
299 
300 
301 template<class Type>
303 (
307 ) const
308 {
309  interpolate(toVf, tfromVf(), ord);
310  tfromVf.clear();
311 }
312 
313 
314 template<class Type>
316 (
319 ) const
320 {
321  // Create and map the internal-field values
322  Field<Type> internalField(toMesh_.nCells());
323  interpolateInternalField(internalField, fromVf, ord);
324 
325  // check whether both meshes have got the same number
326  // of boundary patches
327  if (fromMesh_.boundary().size() != toMesh_.boundary().size())
328  {
330  (
331  "meshToMesh::interpolate"
332  "(const GeometricField<Type, fvPatchField, volMesh>& fromVf,"
333  "meshToMesh::order ord) const"
334  ) << "Incompatible meshes: different number of boundaries, "
335  "only internal field may be interpolated"
336  << exit(FatalError);
337  }
338 
339  // Create and map the patch field values
340  PtrList<fvPatchField<Type> > patchFields
341  (
342  boundaryAddressing_.size()
343  );
344 
345  forAll (boundaryAddressing_, patchI)
346  {
347  patchFields.set
348  (
349  patchI,
351  (
352  fromVf.boundaryField()[patchI],
353  toMesh_.boundary()[patchI],
356  (
357  boundaryAddressing_[patchI]
358  )
359  )
360  );
361  }
362 
363 
364  // Create the complete field from the pieces
366  (
368  (
369  IOobject
370  (
371  "interpolated(" + fromVf.name() + ')',
372  toMesh_.time().timeName(),
373  toMesh_,
376  ),
377  toMesh_,
378  fromVf.dimensions(),
379  internalField,
380  patchFields
381  )
382  );
383 
384  return ttoF;
385 }
386 
387 
388 template<class Type>
390 (
393 ) const
394 {
396  interpolate(tfromVf(), ord);
397  tfromVf.clear();
398 
399  return tint;
400 }
401 
402 
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
404 
405 } // End namespace Foam
406 
407 // ************************ vim: set sw=4 sts=4 et: ************************ //