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
25 \*---------------------------------------------------------------------------*/
27 #include "meshToMesh.H"
28 #include "volFields.H"
29 #include "interpolationCellPoint.H"
31 #include "mixedFvPatchField.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 void meshToMesh::mapField
44 const Field<Type>& fromVf,
48 // Direct mapping of nearest-cell values
54 toF[celli] = fromVf[adr[celli]];
58 //toF.map(fromVf, adr);
63 void meshToMesh::interpolateField
66 const GeometricField<Type, fvPatchField, volMesh>& fromVf,
68 const scalarListList& weights
71 // Inverse distance weighted interpolation
73 // get reference to cellCells
74 const labelListList& cc = fromMesh_.cellCells();
80 const labelList& neighbours = cc[adr[celli]];
81 const scalarList& w = weights[celli];
83 toF[celli] = fromVf[adr[celli]]*w[0];
85 for (label ni = 1; ni < w.size(); ni++)
87 toF[celli] += fromVf[neighbours[ni - 1]]*w[ni];
95 void meshToMesh::interpolateField
98 const GeometricField<Type, fvPatchField, volMesh>& fromVf,
100 const vectorField& centres
103 // Cell-Point interpolation
104 interpolationCellPoint<Type> interpolator(fromVf);
108 if (adr[celli] != -1)
110 toF[celli] = interpolator.interpolate
121 void meshToMesh::interpolateInternalField
124 const GeometricField<Type, fvPatchField, volMesh>& fromVf,
125 meshToMesh::order ord
128 if (fromVf.mesh() != fromMesh_)
132 "meshToMesh::interpolateInternalField(Field<Type>& toF, "
133 "const GeometricField<Type, fvPatchField, volMesh>& fromVf, "
134 "meshToMesh::order ord) const"
135 ) << "the argument field does not correspond to the right mesh. "
136 << "Field size: " << fromVf.size()
137 << " mesh size: " << fromMesh_.nCells()
141 if (toF.size() != toMesh_.nCells())
145 "meshToMesh::interpolateInternalField(Field<Type>& toF, "
146 "const GeometricField<Type, fvPatchField, volMesh>& fromVf, "
147 "meshToMesh::order ord) const"
148 ) << "the argument field does not correspond to the right mesh. "
149 << "Field size: " << toF.size()
150 << " mesh size: " << toMesh_.nCells()
157 mapField(toF, fromVf, cellAddressing_);
166 inverseDistanceWeights()
170 case CELL_POINT_INTERPOLATE:
176 toMesh_.cellCentres()
183 "meshToMesh::interpolateInternalField(Field<Type>& toF, "
184 "const GeometricField<Type, fvPatchField, volMesh>& fromVf, "
185 "meshToMesh::order ord) const"
186 ) << "unknown interpolation scheme " << ord
193 void meshToMesh::interpolateInternalField
196 const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfromVf,
197 meshToMesh::order ord
200 interpolateInternalField(toF, tfromVf(), ord);
206 void meshToMesh::interpolate
208 GeometricField<Type, fvPatchField, volMesh>& toVf,
209 const GeometricField<Type, fvPatchField, volMesh>& fromVf,
210 meshToMesh::order ord
213 interpolateInternalField(toVf, fromVf, ord);
215 forAll (toMesh_.boundaryMesh(), patchi)
217 const fvPatch& toPatch = toMesh_.boundary()[patchi];
219 if (cuttingPatches_.found(toPatch.name()))
226 toVf.boundaryField()[patchi],
228 boundaryAddressing_[patchi]
235 toVf.boundaryField()[patchi],
237 boundaryAddressing_[patchi],
242 case CELL_POINT_INTERPOLATE:
245 toVf.boundaryField()[patchi],
247 boundaryAddressing_[patchi],
255 "meshToMesh::interpolate("
256 "GeometricField<Type, fvPatchField, volMesh>& toVf, "
257 "const GeometricField<Type, fvPatchField, volMesh>& "
258 "fromVf, meshToMesh::order ord) const"
259 ) << "unknown interpolation scheme " << ord
263 if (isA<mixedFvPatchField<Type> >(toVf.boundaryField()[patchi]))
265 refCast<mixedFvPatchField<Type> >
267 toVf.boundaryField()[patchi]
268 ).refValue() = toVf.boundaryField()[patchi];
273 patchMap_.found(toPatch.name())
274 && fromMeshPatches_.found(patchMap_.find(toPatch.name())())
278 toVf.boundaryField()[patchi].map
280 fromVf.boundaryField()
282 fromMeshPatches_.find(patchMap_.find(toPatch.name())())()
284 boundaryAddressing_[patchi]
290 toVf.boundaryField()[patchi],
291 fromVf.boundaryField()
293 fromMeshPatches_.find(patchMap_.find(toPatch.name())())()
295 boundaryAddressing_[patchi]
303 void meshToMesh::interpolate
305 GeometricField<Type, fvPatchField, volMesh>& toVf,
306 const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfromVf,
307 meshToMesh::order ord
310 interpolate(toVf, tfromVf(), ord);
316 tmp<GeometricField<Type, fvPatchField, volMesh> > meshToMesh::interpolate
318 const GeometricField<Type, fvPatchField, volMesh>& fromVf,
319 meshToMesh::order ord
322 // Create and map the internal-field values
323 Field<Type> internalField(toMesh_.nCells());
324 interpolateInternalField(internalField, fromVf, ord);
326 // check whether both meshes have got the same number
327 // of boundary patches
328 if (fromMesh_.boundary().size() != toMesh_.boundary().size())
332 "meshToMesh::interpolate"
333 "(const GeometricField<Type, fvPatchField, volMesh>& fromVf,"
334 "meshToMesh::order ord) const"
335 ) << "Incompatible meshes: different number of boundaries, "
336 "only internal field may be interpolated"
340 // Create and map the patch field values
341 PtrList<fvPatchField<Type> > patchFields
343 boundaryAddressing_.size()
346 forAll (boundaryAddressing_, patchI)
351 fvPatchField<Type>::New
353 fromVf.boundaryField()[patchI],
354 toMesh_.boundary()[patchI],
355 DimensionedField<Type, volMesh>::null(),
356 patchFieldInterpolator
358 boundaryAddressing_[patchI]
365 // Create the complete field from the pieces
366 tmp<GeometricField<Type, fvPatchField, volMesh> > ttoF
368 new GeometricField<Type, fvPatchField, volMesh>
372 "interpolated(" + fromVf.name() + ')',
373 toMesh_.time().timeName(),
390 tmp<GeometricField<Type, fvPatchField, volMesh> > meshToMesh::interpolate
392 const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfromVf,
393 meshToMesh::order ord
396 tmp<GeometricField<Type, fvPatchField, volMesh> > tint =
397 interpolate(tfromVf(), ord);
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406 } // End namespace Foam
408 // ************************************************************************* //