1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "meshToMesh.H"
27 #include "volFields.H"
28 #include "interpolationCellPoint.H"
30 #include "mixedFvPatchField.H"
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
35 void Foam::meshToMesh::mapField
38 const Field<Type>& fromVf,
42 // Direct mapping of nearest-cell values
48 toF[celli] = fromVf[adr[celli]];
52 //toF.map(fromVf, adr);
57 void Foam::meshToMesh::interpolateField
60 const GeometricField<Type, fvPatchField, volMesh>& fromVf,
62 const scalarListList& weights
65 // Inverse distance weighted interpolation
67 // get reference to cellCells
68 const labelListList& cc = fromMesh_.cellCells();
74 const labelList& neighbours = cc[adr[celli]];
75 const scalarList& w = weights[celli];
77 toF[celli] = fromVf[adr[celli]]*w[0];
79 for (label ni = 1; ni < w.size(); ni++)
81 toF[celli] += fromVf[neighbours[ni - 1]]*w[ni];
89 void Foam::meshToMesh::interpolateField
92 const GeometricField<Type, fvPatchField, volMesh>& fromVf,
94 const vectorField& centres
97 // Cell-Point interpolation
98 interpolationCellPoint<Type> interpolator(fromVf);
102 if (adr[celli] != -1)
104 toF[celli] = interpolator.interpolate
115 void Foam::meshToMesh::interpolateInternalField
118 const GeometricField<Type, fvPatchField, volMesh>& fromVf,
119 meshToMesh::order ord
122 if (fromVf.mesh() != fromMesh_)
126 "meshToMesh::interpolateInternalField(Field<Type>& toF, "
127 "const GeometricField<Type, fvPatchField, volMesh>& fromVf, "
128 "meshToMesh::order ord) const"
129 ) << "the argument field does not correspond to the right mesh. "
130 << "Field size: " << fromVf.size()
131 << " mesh size: " << fromMesh_.nCells()
135 if (toF.size() != toMesh_.nCells())
139 "meshToMesh::interpolateInternalField(Field<Type>& toF, "
140 "const GeometricField<Type, fvPatchField, volMesh>& fromVf, "
141 "meshToMesh::order ord) const"
142 ) << "the argument field does not correspond to the right mesh. "
143 << "Field size: " << toF.size()
144 << " mesh size: " << toMesh_.nCells()
151 mapField(toF, fromVf, cellAddressing_);
160 inverseDistanceWeights()
164 case CELL_POINT_INTERPOLATE:
170 toMesh_.cellCentres()
177 "meshToMesh::interpolateInternalField(Field<Type>& toF, "
178 "const GeometricField<Type, fvPatchField, volMesh>& fromVf, "
179 "meshToMesh::order ord) const"
180 ) << "unknown interpolation scheme " << ord
187 void Foam::meshToMesh::interpolateInternalField
190 const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfromVf,
191 meshToMesh::order ord
194 interpolateInternalField(toF, tfromVf(), ord);
200 void Foam::meshToMesh::interpolate
202 GeometricField<Type, fvPatchField, volMesh>& toVf,
203 const GeometricField<Type, fvPatchField, volMesh>& fromVf,
204 meshToMesh::order ord
207 interpolateInternalField(toVf, fromVf, ord);
209 forAll(toMesh_.boundaryMesh(), patchi)
211 const fvPatch& toPatch = toMesh_.boundary()[patchi];
213 if (cuttingPatches_.found(toPatch.name()))
220 toVf.boundaryField()[patchi],
222 boundaryAddressing_[patchi]
229 toVf.boundaryField()[patchi],
231 boundaryAddressing_[patchi],
236 case CELL_POINT_INTERPOLATE:
239 toVf.boundaryField()[patchi],
241 boundaryAddressing_[patchi],
249 "meshToMesh::interpolate("
250 "GeometricField<Type, fvPatchField, volMesh>& toVf, "
251 "const GeometricField<Type, fvPatchField, volMesh>& "
252 "fromVf, meshToMesh::order ord) const"
253 ) << "unknown interpolation scheme " << ord
257 if (isA<mixedFvPatchField<Type> >(toVf.boundaryField()[patchi]))
259 refCast<mixedFvPatchField<Type> >
261 toVf.boundaryField()[patchi]
262 ).refValue() = toVf.boundaryField()[patchi];
267 patchMap_.found(toPatch.name())
268 && fromMeshPatches_.found(patchMap_.find(toPatch.name())())
272 toVf.boundaryField()[patchi].map
274 fromVf.boundaryField()
276 fromMeshPatches_.find(patchMap_.find(toPatch.name())())()
278 boundaryAddressing_[patchi]
284 toVf.boundaryField()[patchi],
285 fromVf.boundaryField()
287 fromMeshPatches_.find(patchMap_.find(toPatch.name())())()
289 boundaryAddressing_[patchi]
297 void Foam::meshToMesh::interpolate
299 GeometricField<Type, fvPatchField, volMesh>& toVf,
300 const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfromVf,
301 meshToMesh::order ord
304 interpolate(toVf, tfromVf(), ord);
310 Foam::tmp< Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
311 Foam::meshToMesh::interpolate
313 const GeometricField<Type, fvPatchField, volMesh>& fromVf,
314 meshToMesh::order ord
317 // Create and map the internal-field values
318 Field<Type> internalField(toMesh_.nCells());
319 interpolateInternalField(internalField, fromVf, ord);
321 // check whether both meshes have got the same number
322 // of boundary patches
323 if (fromMesh_.boundary().size() != toMesh_.boundary().size())
327 "meshToMesh::interpolate"
328 "(const GeometricField<Type, fvPatchField, volMesh>& fromVf,"
329 "meshToMesh::order ord) const"
330 ) << "Incompatible meshes: different number of boundaries, "
331 "only internal field may be interpolated"
335 // Create and map the patch field values
336 PtrList<fvPatchField<Type> > patchFields
338 boundaryAddressing_.size()
341 forAll(boundaryAddressing_, patchI)
346 fvPatchField<Type>::New
348 fromVf.boundaryField()[patchI],
349 toMesh_.boundary()[patchI],
350 DimensionedField<Type, volMesh>::null(),
351 patchFieldInterpolator
353 boundaryAddressing_[patchI]
360 // Create the complete field from the pieces
361 tmp<GeometricField<Type, fvPatchField, volMesh> > ttoF
363 new GeometricField<Type, fvPatchField, volMesh>
367 "interpolated(" + fromVf.name() + ')',
368 toMesh_.time().timeName(),
385 Foam::tmp< Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
386 Foam::meshToMesh::interpolate
388 const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfromVf,
389 meshToMesh::order ord
392 tmp<GeometricField<Type, fvPatchField, volMesh> > tint =
393 interpolate(tfromVf(), ord);
400 // ************************************************************************* //