1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 "fvMeshSubset.H"
28 #include "emptyFvsPatchField.H"
29 #include "emptyPointPatchField.H"
30 #include "emptyFvPatchFields.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
40 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::interpolate
42 const GeometricField<Type, fvPatchField, volMesh>& vf,
44 const labelList& patchMap,
45 const labelList& cellMap,
46 const labelList& faceMap
49 // Create and map the internal-field values
50 Field<Type> internalField(vf.internalField(), cellMap);
52 // Create and map the patch field values
53 PtrList<fvPatchField<Type> > patchFields(patchMap.size());
55 forAll (patchFields, patchI)
57 // Set the first one by hand as it corresponds to the
58 // exposed internal faces. Additional interpolation can be put here
60 if (patchMap[patchI] == -1)
65 new emptyFvPatchField<Type>
67 sMesh.boundary()[patchI],
68 DimensionedField<Type, volMesh>::null()
74 // Construct addressing
75 const fvPatch& subPatch = sMesh.boundary()[patchI];
76 const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
77 label baseStart = basePatch.patch().start();
78 label baseSize = basePatch.size();
80 labelList directAddressing(subPatch.size());
82 forAll(directAddressing, i)
84 label baseFaceI = faceMap[subPatch.patch().start()+i];
86 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
88 directAddressing[i] = baseFaceI-baseStart;
92 // Mapped from internal face. Do what? Map from element
94 directAddressing[i] = 0;
101 fvPatchField<Type>::New
103 vf.boundaryField()[patchMap[patchI]],
104 sMesh.boundary()[patchI],
105 DimensionedField<Type, volMesh>::null(),
106 patchFieldSubset(directAddressing)
110 // What to do with exposed internal faces if put into this patch?
115 // Create the complete field from the pieces
116 tmp<GeometricField<Type, fvPatchField, volMesh> > tresF
118 new GeometricField<Type, fvPatchField, volMesh>
123 sMesh.time().timeName(),
140 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::interpolate
142 const GeometricField<Type, fvPatchField, volMesh>& vf
157 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > fvMeshSubset::interpolate
159 const GeometricField<Type, fvsPatchField, surfaceMesh>& vf,
161 const labelList& patchMap,
162 const labelList& faceMap
165 // Create and map the internal-field values
166 Field<Type> internalField
172 sMesh.nInternalFaces()
176 // Create and map the patch field values
177 PtrList<fvsPatchField<Type> > patchFields(patchMap.size());
179 forAll (patchFields, patchI)
181 // Set the first one by hand as it corresponds to the
182 // exposed internal faces. Additional interpolation can be put here
184 if (patchMap[patchI] == -1)
189 new emptyFvsPatchField<Type>
191 sMesh.boundary()[patchI],
192 DimensionedField<Type, surfaceMesh>::null()
198 // Construct addressing
199 const fvPatch& subPatch = sMesh.boundary()[patchI];
200 const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
201 label baseStart = basePatch.patch().start();
202 label baseSize = basePatch.size();
204 labelList directAddressing(subPatch.size());
206 forAll(directAddressing, i)
208 label baseFaceI = faceMap[subPatch.patch().start()+i];
210 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
212 directAddressing[i] = baseFaceI-baseStart;
216 // Mapped from internal face. Do what? Map from element
218 directAddressing[i] = 0;
225 fvsPatchField<Type>::New
227 vf.boundaryField()[patchMap[patchI]],
228 sMesh.boundary()[patchI],
229 DimensionedField<Type, surfaceMesh>::null(),
230 patchFieldSubset(directAddressing)
237 // Map exposed internal faces. Note: Only nessecary if exposed faces added
238 // into existing patch but since we don't know that at this point...
239 forAll(patchFields, patchI)
241 fvsPatchField<Type>& pfld = patchFields[patchI];
243 label meshFaceI = pfld.patch().patch().start();
247 label oldFaceI = faceMap[meshFaceI++];
249 if (oldFaceI < vf.internalField().size())
251 pfld[i] = vf.internalField()[oldFaceI];
256 // Create the complete field from the pieces
257 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tresF
259 new GeometricField<Type, fvsPatchField, surfaceMesh>
264 sMesh.time().timeName(),
281 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > fvMeshSubset::interpolate
283 const GeometricField<Type, fvsPatchField, surfaceMesh>& sf
297 tmp<GeometricField<Type, pointPatchField, pointMesh> >
298 fvMeshSubset::interpolate
300 const GeometricField<Type, pointPatchField, pointMesh>& vf,
301 const pointMesh& sMesh,
302 const labelList& patchMap,
303 const labelList& pointMap
306 // Create and map the internal-field values
307 Field<Type> internalField(vf.internalField(), pointMap);
309 // Create and map the patch field values
310 PtrList<pointPatchField<Type> > patchFields(patchMap.size());
312 forAll (patchFields, patchI)
314 // Set the first one by hand as it corresponds to the
315 // exposed internal faces. Additional interpolation can be put here
317 if (patchMap[patchI] == -1)
322 new emptyPointPatchField<Type>
324 sMesh.boundary()[patchI],
325 DimensionedField<Type, pointMesh>::null()
331 // Construct addressing
332 const pointPatch& basePatch =
333 vf.mesh().boundary()[patchMap[patchI]];
335 const labelList& meshPoints = basePatch.meshPoints();
337 // Make addressing from mesh to patch point
338 Map<label> meshPointMap(2*meshPoints.size());
339 forAll(meshPoints, localI)
341 meshPointMap.insert(meshPoints[localI], localI);
344 // Find which subpatch points originate from which patch point
345 const pointPatch& subPatch = sMesh.boundary()[patchI];
346 const labelList& subMeshPoints = subPatch.meshPoints();
348 // If mapped from outside patch use point 0 for lack of better.
349 labelList directAddressing(subPatch.size(), 0);
351 forAll(subMeshPoints, localI)
353 // Get mesh point on original mesh.
354 label meshPointI = pointMap[subMeshPoints[localI]];
356 Map<label>::const_iterator iter = meshPointMap.find(meshPointI);
358 if (iter != meshPointMap.end())
360 directAddressing[localI] = iter();
367 pointPatchField<Type>::New
369 vf.boundaryField()[patchMap[patchI]],
371 DimensionedField<Type, pointMesh>::null(),
372 pointPatchFieldSubset(directAddressing)
378 // Create the complete field from the pieces
379 tmp<GeometricField<Type, pointPatchField, pointMesh> > tresF
381 new GeometricField<Type, pointPatchField, pointMesh>
386 vf.time().timeName(),
403 tmp<GeometricField<Type, pointPatchField, pointMesh> > fvMeshSubset::interpolate
405 const GeometricField<Type, pointPatchField, pointMesh>& sf
411 pointMesh::New(subMesh()), // subsetted point mesh
418 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
420 } // End namespace Foam
422 // ************************************************************************* //