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 "fvMeshSubset.H"
28 #include "calculatedFvPatchFields.H"
29 #include "calculatedFvsPatchFields.H"
30 #include "emptyFvPatchFields.H"
31 #include "emptyFvsPatchFields.H"
32 #include "calculatedPointPatchFields.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
42 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::meshToMesh
44 const GeometricField<Type, fvPatchField, volMesh>& vf,
46 const labelList& patchMap,
47 const labelList& cellMap,
48 const labelList& faceMap
51 // Create and map the internal-field values
52 Field<Type> internalField(vf.internalField(), cellMap);
54 // Create and map the patch field values
55 PtrList<fvPatchField<Type> > patchFields(patchMap.size());
57 forAll (patchFields, patchI)
59 // Set the first one by hand as it corresponds to the
60 // exposed internal faces. Additional interpolation can be put here
61 // as necessary. HJ, date deleted
62 if (patchMap[patchI] == -1)
67 new emptyFvPatchField<Type>
69 sMesh.boundary()[patchI],
70 DimensionedField<Type, volMesh>::null()
76 // Construct addressing
77 const fvPatch& subPatch = sMesh.boundary()[patchI];
78 const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
79 label baseStart = basePatch.patch().start();
80 label baseSize = basePatch.size();
82 labelList directAddressing(subPatch.size());
84 forAll(directAddressing, i)
86 label baseFaceI = faceMap[subPatch.patch().start()+i];
88 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
90 directAddressing[i] = baseFaceI-baseStart;
94 // Mapped from internal face. Do what? Map from element
96 directAddressing[i] = 0;
103 fvPatchField<Type>::New
105 vf.boundaryField()[patchMap[patchI]],
106 sMesh.boundary()[patchI],
107 DimensionedField<Type, volMesh>::null(),
110 vf.boundaryField()[patchMap[patchI]].size(),
116 // What to do with exposed internal faces if put into this patch?
121 // Create the complete field from the pieces
122 tmp<GeometricField<Type, fvPatchField, volMesh> > tresF
124 new GeometricField<Type, fvPatchField, volMesh>
129 sMesh.time().timeName(),
146 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::interpolate
148 const GeometricField<Type, fvPatchField, volMesh>& vf
151 // Get reference to the subset mesh
152 const fvMesh& sMesh = subMesh();
154 // Create and map the internal-field values
155 Field<Type> internalField(vf.internalField(), cellMap());
157 // Create and map the patch field values
158 const labelList& pm = patchMap();
160 // Create and map the patch field values
161 PtrList<fvPatchField<Type> > patchFields(pm.size());
163 label internalFacesPatchIndex = -1;
165 forAll (patchFields, patchI)
167 // Set the first one by hand as it corresponds to the
168 // exposed internal faces. Additional interpolation can be put here
169 // as necessary. HJ, date deleted
170 if (pm[patchI] == -1)
172 // Bug fix. Zeljko Tukovic, 10/Mar/2010
173 internalFacesPatchIndex = patchI;
178 new calculatedFvPatchField<Type>
180 sMesh.boundary()[patchI],
181 DimensionedField<Type, volMesh>::null()
190 fvPatchField<Type>::New
192 vf.boundaryField()[pm[patchI]],
193 sMesh.boundary()[patchI],
194 DimensionedField<Type, volMesh>::null(),
195 patchFieldSubset(*this, patchI)
201 // Linear interpolation for last patch
202 if (internalFacesPatchIndex > -1)
204 const Field<Type>& vfI = vf.internalField();
205 const scalarField& w = baseMesh().weights().internalField();
206 const labelList& own = baseMesh().faceOwner();
207 const labelList& ngb = baseMesh().faceNeighbour();
209 Field<Type>& lastPatchField = patchFields[internalFacesPatchIndex];
211 label lastPatchStart =
212 sMesh.boundaryMesh()[internalFacesPatchIndex].start();
214 const labelList& fm = faceMap();
216 forAll(lastPatchField, faceI)
218 lastPatchField[faceI] =
219 w[fm[lastPatchStart + faceI]]*
220 vfI[own[fm[lastPatchStart + faceI]]]
221 + (1.0 - w[fm[lastPatchStart + faceI]])*
222 vfI[ngb[fm[lastPatchStart + faceI]]];
226 // Create the complete field from the pieces
227 tmp<GeometricField<Type, fvPatchField, volMesh> > tresF
229 new GeometricField<Type, fvPatchField, volMesh>
234 sMesh.time().timeName(),
251 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
252 fvMeshSubset::meshToMesh
254 const GeometricField<Type, fvsPatchField, surfaceMesh>& vf,
256 const labelList& patchMap,
257 const labelList& faceMap
260 // Create and map the internal-field values
261 Field<Type> internalField
267 sMesh.nInternalFaces()
271 // Create and map the patch field values
272 PtrList<fvsPatchField<Type> > patchFields(patchMap.size());
274 forAll (patchFields, patchI)
276 // Set the first one by hand as it corresponds to the
277 // exposed internal faces. Additional interpolation can be put here
279 if (patchMap[patchI] == -1)
284 new emptyFvsPatchField<Type>
286 sMesh.boundary()[patchI],
287 DimensionedField<Type, surfaceMesh>::null()
293 // Construct addressing
294 const fvPatch& subPatch = sMesh.boundary()[patchI];
295 const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
296 label baseStart = basePatch.patch().start();
297 label baseSize = basePatch.size();
299 labelList directAddressing(subPatch.size());
301 forAll(directAddressing, i)
303 label baseFaceI = faceMap[subPatch.patch().start()+i];
305 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
307 directAddressing[i] = baseFaceI-baseStart;
311 // Mapped from internal face. Do what? Map from element
313 directAddressing[i] = 0;
320 fvsPatchField<Type>::New
322 vf.boundaryField()[patchMap[patchI]],
323 sMesh.boundary()[patchI],
324 DimensionedField<Type, surfaceMesh>::null(),
327 vf.boundaryField()[patchMap[patchI]].size(),
336 // Map exposed internal faces. Note: Only nessecary if exposed faces added
337 // into existing patch but since we don't know that at this point...
338 forAll(patchFields, patchI)
340 fvsPatchField<Type>& pfld = patchFields[patchI];
342 label meshFaceI = pfld.patch().patch().start();
346 label oldFaceI = faceMap[meshFaceI++];
348 if (oldFaceI < vf.internalField().size())
350 pfld[i] = vf.internalField()[oldFaceI];
355 // Create the complete field from the pieces
356 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tresF
358 new GeometricField<Type, fvsPatchField, surfaceMesh>
363 sMesh.time().timeName(),
380 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
381 fvMeshSubset::interpolate
383 const GeometricField<Type, fvsPatchField, surfaceMesh>& vf
386 // Get reference to the subset mesh
387 const fvMesh& sMesh = subMesh();
389 // Create and map the internal-field values
390 Field<Type> internalField
396 sMesh.nInternalFaces()
400 // Create and map the patch field values
401 const labelList& pm = patchMap();
403 // Create and map the patch field values
404 PtrList<fvsPatchField<Type> > patchFields(pm.size());
406 forAll (patchFields, patchI)
408 // Set the first one by hand as it corresponds to the
409 // exposed internal faces. Additional interpolation can be put here
410 // as necessary. HJ, date deleted
411 if (pm[patchI] == -1)
416 calculatedFvsPatchField<Type>
418 sMesh.boundary()[patchI],
419 DimensionedField<Type, surfaceMesh>::null()
428 fvsPatchField<Type>::New
430 vf.boundaryField()[pm[patchI]],
431 sMesh.boundary()[patchI],
432 DimensionedField<Type, surfaceMesh>::null(),
433 patchFieldSubset(*this, patchI)
440 const labelList& fm = faceMap();
442 // Map exposed internal faces. Note: Only nessecary if exposed faces added
443 // into existing patch but since we don't know that at this point...
444 forAll(patchFields, patchI)
446 fvsPatchField<Type>& pfld = patchFields[patchI];
448 label meshFaceI = pfld.patch().patch().start();
452 label oldFaceI = fm[meshFaceI++];
454 if (oldFaceI < vf.internalField().size())
456 pfld[i] = vf.internalField()[oldFaceI];
461 // Create the complete field from the pieces
462 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tresF
464 new GeometricField<Type, fvsPatchField, surfaceMesh>
469 sMesh.time().timeName(),
486 tmp<GeometricField<Type, pointPatchField, pointMesh> >
487 fvMeshSubset::interpolate
489 const GeometricField<Type, pointPatchField, pointMesh>& vf
492 // Get reference to the subset mesh
493 const pointMesh& sMesh = subPointMesh();
495 // Create and map the internal-field values
496 Field<Type> internalField(vf.internalField(), pointMap());
498 // Create and map the patch field values
499 const labelList& pm = patchMap();
501 // Create and map the patch field values
502 PtrList<pointPatchField<Type> > patchFields(pm.size());
504 forAll (patchFields, patchI)
506 // Set the first one by hand as it corresponds to the
507 // exposed internal faces. Additional interpolation can be put here
508 // as necessary. HJ, date deleted
509 if (pm[patchI] == -1)
514 new CalculatedPointPatchField
523 sMesh.boundary()[patchI],
524 DimensionedField<Type, pointMesh>::null()
530 // Construct addressing
531 const pointPatch& basePatch =
532 vf.mesh().boundary()[pm[patchI]];
534 const labelList& meshPoints = basePatch.meshPoints();
536 // Make addressing from mesh to patch point
537 Map<label> meshPointMap(2*meshPoints.size());
538 forAll(meshPoints, localI)
540 meshPointMap.insert(meshPoints[localI], localI);
543 // Find which subpatch points originate from which patch point
544 const pointPatch& subPatch = sMesh.boundary()[patchI];
545 const labelList& subMeshPoints = subPatch.meshPoints();
547 // If mapped from outside patch use point 0 for lack of better.
548 labelList directAddressing(subPatch.size(), 0);
550 const labelList& ptMap = pointMap();
552 forAll(subMeshPoints, localI)
554 // Get mesh point on original mesh.
555 label meshPointI = ptMap[subMeshPoints[localI]];
557 Map<label>::const_iterator iter =
558 meshPointMap.find(meshPointI);
560 if (iter != meshPointMap.end())
562 directAddressing[localI] = iter();
569 pointPatchField<Type>::New
571 vf.boundaryField()[pm[patchI]],
573 DimensionedField<Type, pointMesh>::null(),
574 pointPatchFieldSubset
583 // Create the complete field from the pieces
584 tmp<GeometricField<Type, pointPatchField, pointMesh> > tresF
586 new GeometricField<Type, pointPatchField, pointMesh>
591 vf.time().timeName(),
607 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
609 } // End namespace Foam
611 // ************************************************************************* //