1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "fvMeshSubset.H"
27 #include "calculatedFvPatchFields.H"
28 #include "calculatedFvsPatchFields.H"
29 #include "emptyFvPatchFields.H"
30 #include "emptyFvsPatchFields.H"
31 #include "calculatedPointPatchFields.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::meshToMesh
43 const GeometricField<Type, fvPatchField, volMesh>& vf,
45 const labelList& patchMap,
46 const labelList& cellMap,
47 const labelList& faceMap
50 // Create and map the internal-field values
51 Field<Type> internalField(vf.internalField(), cellMap);
53 // Create and map the patch field values
54 PtrList<fvPatchField<Type> > patchFields(patchMap.size());
56 forAll (patchFields, patchI)
58 // Set the first one by hand as it corresponds to the
59 // exposed internal faces. Additional interpolation can be put here
60 // as necessary. HJ, date deleted
61 if (patchMap[patchI] == -1)
66 new emptyFvPatchField<Type>
68 sMesh.boundary()[patchI],
69 DimensionedField<Type, volMesh>::null()
75 // Construct addressing
76 const fvPatch& subPatch = sMesh.boundary()[patchI];
77 const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
78 label baseStart = basePatch.patch().start();
79 label baseSize = basePatch.size();
81 labelList directAddressing(subPatch.size());
83 forAll(directAddressing, i)
85 label baseFaceI = faceMap[subPatch.patch().start()+i];
87 if (baseFaceI >= baseStart && baseFaceI < baseStart + baseSize)
89 directAddressing[i] = baseFaceI-baseStart;
93 // Mapped from internal face. Do what? Map from element
95 directAddressing[i] = 0;
102 fvPatchField<Type>::New
104 vf.boundaryField()[patchMap[patchI]],
105 sMesh.boundary()[patchI],
106 DimensionedField<Type, volMesh>::null(),
109 vf.boundaryField()[patchMap[patchI]].size(),
115 // What to do with exposed internal faces if put into this patch?
120 // Create the complete field from the pieces
121 tmp<GeometricField<Type, fvPatchField, volMesh> > tresF
123 new GeometricField<Type, fvPatchField, volMesh>
128 sMesh.time().timeName(),
145 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::interpolate
147 const GeometricField<Type, fvPatchField, volMesh>& vf
150 // Get reference to the subset mesh
151 const fvMesh& sMesh = subMesh();
153 // Create and map the internal-field values
154 Field<Type> internalField(vf.internalField(), cellMap());
156 // Create and map the patch field values
157 const labelList& pm = patchMap();
159 // Create and map the patch field values
160 PtrList<fvPatchField<Type> > patchFields(pm.size());
162 label internalFacesPatchIndex = -1;
164 forAll (patchFields, patchI)
166 // Set the first one by hand as it corresponds to the
167 // exposed internal faces. Additional interpolation can be put here
168 // as necessary. HJ, date deleted
169 if (pm[patchI] == -1)
171 // Bug fix. Zeljko Tukovic, 10/Mar/2010
172 internalFacesPatchIndex = patchI;
177 new calculatedFvPatchField<Type>
179 sMesh.boundary()[patchI],
180 DimensionedField<Type, volMesh>::null()
189 fvPatchField<Type>::New
191 vf.boundaryField()[pm[patchI]],
192 sMesh.boundary()[patchI],
193 DimensionedField<Type, volMesh>::null(),
194 patchFieldSubset(*this, patchI)
200 // Linear interpolation for last patch
201 if (internalFacesPatchIndex > -1)
203 const Field<Type>& vfI = vf.internalField();
204 const scalarField& w = baseMesh().weights().internalField();
205 const labelList& own = baseMesh().faceOwner();
206 const labelList& ngb = baseMesh().faceNeighbour();
208 Field<Type>& lastPatchField = patchFields[internalFacesPatchIndex];
210 label lastPatchStart =
211 sMesh.boundaryMesh()[internalFacesPatchIndex].start();
213 const labelList& fm = faceMap();
215 forAll(lastPatchField, faceI)
217 lastPatchField[faceI] =
218 w[fm[lastPatchStart + faceI]]*
219 vfI[own[fm[lastPatchStart + faceI]]]
220 + (1.0 - w[fm[lastPatchStart + faceI]])*
221 vfI[ngb[fm[lastPatchStart + faceI]]];
225 // Create the complete field from the pieces
226 tmp<GeometricField<Type, fvPatchField, volMesh> > tresF
228 new GeometricField<Type, fvPatchField, volMesh>
233 sMesh.time().timeName(),
250 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
251 fvMeshSubset::meshToMesh
253 const GeometricField<Type, fvsPatchField, surfaceMesh>& vf,
255 const labelList& patchMap,
256 const labelList& faceMap
259 // Create and map the internal-field values
260 Field<Type> internalField
266 sMesh.nInternalFaces()
270 // Create and map the patch field values
271 PtrList<fvsPatchField<Type> > patchFields(patchMap.size());
273 forAll (patchFields, patchI)
275 // Set the first one by hand as it corresponds to the
276 // exposed internal faces. Additional interpolation can be put here
278 if (patchMap[patchI] == -1)
283 new emptyFvsPatchField<Type>
285 sMesh.boundary()[patchI],
286 DimensionedField<Type, surfaceMesh>::null()
292 // Construct addressing
293 const fvPatch& subPatch = sMesh.boundary()[patchI];
294 const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
295 label baseStart = basePatch.patch().start();
296 label baseSize = basePatch.size();
298 labelList directAddressing(subPatch.size());
300 forAll(directAddressing, i)
302 label baseFaceI = faceMap[subPatch.patch().start()+i];
304 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
306 directAddressing[i] = baseFaceI-baseStart;
310 // Mapped from internal face. Do what? Map from element
312 directAddressing[i] = 0;
319 fvsPatchField<Type>::New
321 vf.boundaryField()[patchMap[patchI]],
322 sMesh.boundary()[patchI],
323 DimensionedField<Type, surfaceMesh>::null(),
326 vf.boundaryField()[patchMap[patchI]].size(),
335 // Map exposed internal faces. Note: Only nessecary if exposed faces added
336 // into existing patch but since we don't know that at this point...
337 forAll(patchFields, patchI)
339 fvsPatchField<Type>& pfld = patchFields[patchI];
341 label meshFaceI = pfld.patch().patch().start();
345 label oldFaceI = faceMap[meshFaceI++];
347 if (oldFaceI < vf.internalField().size())
349 pfld[i] = vf.internalField()[oldFaceI];
354 // Create the complete field from the pieces
355 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tresF
357 new GeometricField<Type, fvsPatchField, surfaceMesh>
362 sMesh.time().timeName(),
379 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
380 fvMeshSubset::interpolate
382 const GeometricField<Type, fvsPatchField, surfaceMesh>& vf
385 // Get reference to the subset mesh
386 const fvMesh& sMesh = subMesh();
388 // Create and map the internal-field values
389 Field<Type> internalField
395 sMesh.nInternalFaces()
399 // Create and map the patch field values
400 const labelList& pm = patchMap();
402 // Create and map the patch field values
403 PtrList<fvsPatchField<Type> > patchFields(pm.size());
405 forAll (patchFields, patchI)
407 // Set the first one by hand as it corresponds to the
408 // exposed internal faces. Additional interpolation can be put here
409 // as necessary. HJ, date deleted
410 if (pm[patchI] == -1)
415 calculatedFvsPatchField<Type>
417 sMesh.boundary()[patchI],
418 DimensionedField<Type, surfaceMesh>::null()
427 fvsPatchField<Type>::New
429 vf.boundaryField()[pm[patchI]],
430 sMesh.boundary()[patchI],
431 DimensionedField<Type, surfaceMesh>::null(),
432 patchFieldSubset(*this, patchI)
439 const labelList& fm = faceMap();
441 // Map exposed internal faces. Note: Only nessecary if exposed faces added
442 // into existing patch but since we don't know that at this point...
443 forAll(patchFields, patchI)
445 fvsPatchField<Type>& pfld = patchFields[patchI];
447 label meshFaceI = pfld.patch().patch().start();
451 label oldFaceI = fm[meshFaceI++];
453 if (oldFaceI < vf.internalField().size())
455 pfld[i] = vf.internalField()[oldFaceI];
460 // Create the complete field from the pieces
461 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tresF
463 new GeometricField<Type, fvsPatchField, surfaceMesh>
468 sMesh.time().timeName(),
485 tmp<GeometricField<Type, pointPatchField, pointMesh> >
486 fvMeshSubset::interpolate
488 const GeometricField<Type, pointPatchField, pointMesh>& vf
491 // Get reference to the subset mesh
492 const pointMesh& sMesh = subPointMesh();
494 // Create and map the internal-field values
495 Field<Type> internalField(vf.internalField(), pointMap());
497 // Create and map the patch field values
498 const labelList& pm = patchMap();
500 // Create and map the patch field values
501 PtrList<pointPatchField<Type> > patchFields(pm.size());
503 forAll (patchFields, patchI)
505 // Set the first one by hand as it corresponds to the
506 // exposed internal faces. Additional interpolation can be put here
507 // as necessary. HJ, date deleted
508 if (pm[patchI] == -1)
513 new CalculatedPointPatchField
522 sMesh.boundary()[patchI],
523 DimensionedField<Type, pointMesh>::null()
529 // Construct addressing
530 const pointPatch& basePatch =
531 vf.mesh().boundary()[pm[patchI]];
533 const labelList& meshPoints = basePatch.meshPoints();
535 // Make addressing from mesh to patch point
536 Map<label> meshPointMap(2*meshPoints.size());
537 forAll(meshPoints, localI)
539 meshPointMap.insert(meshPoints[localI], localI);
542 // Find which subpatch points originate from which patch point
543 const pointPatch& subPatch = sMesh.boundary()[patchI];
544 const labelList& subMeshPoints = subPatch.meshPoints();
546 // If mapped from outside patch use point 0 for lack of better.
547 labelList directAddressing(subPatch.size(), 0);
549 const labelList& ptMap = pointMap();
551 forAll(subMeshPoints, localI)
553 // Get mesh point on original mesh.
554 label meshPointI = ptMap[subMeshPoints[localI]];
556 Map<label>::const_iterator iter =
557 meshPointMap.find(meshPointI);
559 if (iter != meshPointMap.end())
561 directAddressing[localI] = iter();
568 pointPatchField<Type>::New
570 vf.boundaryField()[pm[patchI]],
572 DimensionedField<Type, pointMesh>::null(),
573 pointPatchFieldSubset
582 // Create the complete field from the pieces
583 tmp<GeometricField<Type, pointPatchField, pointMesh> > tresF
585 new GeometricField<Type, pointPatchField, pointMesh>
590 vf.time().timeName(),
606 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
608 } // End namespace Foam
610 // ************************************************************************* //