1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
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 "fvMeshSubset.H"
27 #include "emptyFvsPatchField.H"
28 #include "emptyPointPatchField.H"
29 #include "emptyFvPatchFields.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
39 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::interpolate
41 const GeometricField<Type, fvPatchField, volMesh>& vf,
43 const labelList& patchMap,
44 const labelList& cellMap,
45 const labelList& faceMap
48 // Create and map the internal-field values
49 Field<Type> internalField(vf.internalField(), cellMap);
51 // Create and map the patch field values
52 PtrList<fvPatchField<Type> > patchFields(patchMap.size());
54 forAll (patchFields, patchI)
56 // Set the first one by hand as it corresponds to the
57 // exposed internal faces. Additional interpolation can be put here
59 if (patchMap[patchI] == -1)
64 new emptyFvPatchField<Type>
66 sMesh.boundary()[patchI],
67 DimensionedField<Type, volMesh>::null()
73 // Construct addressing
74 const fvPatch& subPatch = sMesh.boundary()[patchI];
75 const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
76 label baseStart = basePatch.patch().start();
77 label baseSize = basePatch.size();
79 labelList directAddressing(subPatch.size());
81 forAll(directAddressing, i)
83 label baseFaceI = faceMap[subPatch.patch().start()+i];
85 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
87 directAddressing[i] = baseFaceI-baseStart;
91 // Mapped from internal face. Do what? Map from element
93 directAddressing[i] = 0;
100 fvPatchField<Type>::New
102 vf.boundaryField()[patchMap[patchI]],
103 sMesh.boundary()[patchI],
104 DimensionedField<Type, volMesh>::null(),
105 patchFieldSubset(directAddressing)
109 // What to do with exposed internal faces if put into this patch?
114 // Create the complete field from the pieces
115 tmp<GeometricField<Type, fvPatchField, volMesh> > tresF
117 new GeometricField<Type, fvPatchField, volMesh>
122 sMesh.time().timeName(),
139 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::interpolate
141 const GeometricField<Type, fvPatchField, volMesh>& vf
156 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > fvMeshSubset::interpolate
158 const GeometricField<Type, fvsPatchField, surfaceMesh>& vf,
160 const labelList& patchMap,
161 const labelList& faceMap
164 // Create and map the internal-field values
165 Field<Type> internalField
171 sMesh.nInternalFaces()
175 // Create and map the patch field values
176 PtrList<fvsPatchField<Type> > patchFields(patchMap.size());
178 forAll (patchFields, patchI)
180 // Set the first one by hand as it corresponds to the
181 // exposed internal faces. Additional interpolation can be put here
183 if (patchMap[patchI] == -1)
188 new emptyFvsPatchField<Type>
190 sMesh.boundary()[patchI],
191 DimensionedField<Type, surfaceMesh>::null()
197 // Construct addressing
198 const fvPatch& subPatch = sMesh.boundary()[patchI];
199 const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
200 label baseStart = basePatch.patch().start();
201 label baseSize = basePatch.size();
203 labelList directAddressing(subPatch.size());
205 forAll(directAddressing, i)
207 label baseFaceI = faceMap[subPatch.patch().start()+i];
209 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
211 directAddressing[i] = baseFaceI-baseStart;
215 // Mapped from internal face. Do what? Map from element
217 directAddressing[i] = 0;
224 fvsPatchField<Type>::New
226 vf.boundaryField()[patchMap[patchI]],
227 sMesh.boundary()[patchI],
228 DimensionedField<Type, surfaceMesh>::null(),
229 patchFieldSubset(directAddressing)
236 // Map exposed internal faces. Note: Only nessecary if exposed faces added
237 // into existing patch but since we don't know that at this point...
238 forAll(patchFields, patchI)
240 fvsPatchField<Type>& pfld = patchFields[patchI];
242 label meshFaceI = pfld.patch().patch().start();
246 label oldFaceI = faceMap[meshFaceI++];
248 if (oldFaceI < vf.internalField().size())
250 pfld[i] = vf.internalField()[oldFaceI];
255 // Create the complete field from the pieces
256 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tresF
258 new GeometricField<Type, fvsPatchField, surfaceMesh>
263 sMesh.time().timeName(),
280 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > fvMeshSubset::interpolate
282 const GeometricField<Type, fvsPatchField, surfaceMesh>& sf
296 tmp<GeometricField<Type, pointPatchField, pointMesh> >
297 fvMeshSubset::interpolate
299 const GeometricField<Type, pointPatchField, pointMesh>& vf,
300 const pointMesh& sMesh,
301 const labelList& patchMap,
302 const labelList& pointMap
305 // Create and map the internal-field values
306 Field<Type> internalField(vf.internalField(), pointMap);
308 // Create and map the patch field values
309 PtrList<pointPatchField<Type> > patchFields(patchMap.size());
311 forAll (patchFields, patchI)
313 // Set the first one by hand as it corresponds to the
314 // exposed internal faces. Additional interpolation can be put here
316 if (patchMap[patchI] == -1)
321 new emptyPointPatchField<Type>
323 sMesh.boundary()[patchI],
324 DimensionedField<Type, pointMesh>::null()
330 // Construct addressing
331 const pointPatch& basePatch =
332 vf.mesh().boundary()[patchMap[patchI]];
334 const labelList& meshPoints = basePatch.meshPoints();
336 // Make addressing from mesh to patch point
337 Map<label> meshPointMap(2*meshPoints.size());
338 forAll(meshPoints, localI)
340 meshPointMap.insert(meshPoints[localI], localI);
343 // Find which subpatch points originate from which patch point
344 const pointPatch& subPatch = sMesh.boundary()[patchI];
345 const labelList& subMeshPoints = subPatch.meshPoints();
347 // If mapped from outside patch use point 0 for lack of better.
348 labelList directAddressing(subPatch.size(), 0);
350 forAll(subMeshPoints, localI)
352 // Get mesh point on original mesh.
353 label meshPointI = pointMap[subMeshPoints[localI]];
355 Map<label>::const_iterator iter = meshPointMap.find(meshPointI);
357 if (iter != meshPointMap.end())
359 directAddressing[localI] = iter();
366 pointPatchField<Type>::New
368 vf.boundaryField()[patchMap[patchI]],
370 DimensionedField<Type, pointMesh>::null(),
371 pointPatchFieldSubset(directAddressing)
377 // Create the complete field from the pieces
378 tmp<GeometricField<Type, pointPatchField, pointMesh> > tresF
380 new GeometricField<Type, pointPatchField, pointMesh>
385 vf.time().timeName(),
402 tmp<GeometricField<Type, pointPatchField, pointMesh> > fvMeshSubset::interpolate
404 const GeometricField<Type, pointPatchField, pointMesh>& sf
410 pointMesh::New(subMesh()), // subsetted point mesh
417 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
419 } // End namespace Foam
421 // ************************************************************************* //