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 "faFieldReconstructor.H"
29 #include "faPatchFields.H"
30 #include "emptyFaPatch.H"
31 #include "emptyFaPatchField.H"
32 #include "emptyFaePatchField.H"
34 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 Foam::tmp<Foam::GeometricField<Type, Foam::faPatchField, Foam::areaMesh> >
38 Foam::faFieldReconstructor::reconstructFaAreaField
40 const IOobject& fieldIoObject
43 // Read the field for all the processors
44 PtrList<GeometricField<Type, faPatchField, areaMesh> > procFields
49 forAll (procMeshes_, procI)
54 new GeometricField<Type, faPatchField, areaMesh>
59 procMeshes_[procI].time().timeName(),
69 // Create the internalField
70 Field<Type> internalField(mesh_.nFaces());
72 // Create the patch fields
73 PtrList<faPatchField<Type> > patchFields(mesh_.boundary().size());
76 // Create global mesh patchs starts
78 labelList gStarts(mesh_.boundary().size(), -1);
80 if (mesh_.boundary().size() > 0)
82 gStarts[0] = mesh_.nInternalEdges();
85 for(label i=1; i<mesh_.boundary().size(); i++)
87 gStarts[i] = gStarts[i-1] + mesh_.boundary()[i-1].labelList::size();
90 forAll (procMeshes_, procI)
92 const GeometricField<Type, faPatchField, areaMesh>& procField =
95 // Set the face values in the reconstructed field
98 procField.internalField(),
99 faceProcAddressing_[procI]
104 // Set the boundary patch values in the reconstructed field
106 labelList starts(procMeshes_[procI].boundary().size(), -1);
108 if(procMeshes_[procI].boundary().size() > 0)
110 starts[0] = procMeshes_[procI].nInternalEdges();
113 for(label i=1; i<procMeshes_[procI].boundary().size(); i++)
117 + procMeshes_[procI].boundary()[i-1].labelList::size();
120 forAll(boundaryProcAddressing_[procI], patchI)
122 // Get patch index of the original patch
123 const label curBPatch = boundaryProcAddressing_[procI][patchI];
125 // Get addressing slice for this patch
127 // const labelList::subList cp =
128 // procMeshes_[procI].boundary()[patchI].patchSlice
130 // edgeProcAddressing_[procI]
133 const labelList::subList cp =
136 edgeProcAddressing_[procI],
137 procMeshes_[procI].boundary()[patchI].size(),
141 // check if the boundary patch is not a processor patch
144 // Regular patch. Fast looping
146 if (!patchFields(curBPatch))
151 faPatchField<Type>::New
153 procField.boundaryField()[patchI],
154 mesh_.boundary()[curBPatch],
155 DimensionedField<Type, areaMesh>::null(),
156 faPatchFieldReconstructor
158 mesh_.boundary()[curBPatch].size(),
159 procField.boundaryField()[patchI].size()
165 const label curPatchStart = gStarts[curBPatch];
166 // mesh_.boundary()[curBPatch].start();
168 labelList reverseAddressing(cp.size());
172 // Subtract one to take into account offsets for
174 // reverseAddressing[edgeI] = cp[edgeI] - 1 - curPatchStart;
175 reverseAddressing[edgeI] = cp[edgeI] - curPatchStart;
178 patchFields[curBPatch].rmap
180 procField.boundaryField()[patchI],
186 const Field<Type>& curProcPatch =
187 procField.boundaryField()[patchI];
189 // In processor patches, there's a mix of internal faces (some
190 // of them turned) and possible cyclics. Slow loop
193 // Subtract one to take into account offsets for
195 // label curE = cp[edgeI] - 1;
196 label curE = cp[edgeI];
198 // Is the face on the boundary?
199 if (curE >= mesh_.nInternalEdges())
201 // label curBPatch = mesh_.boundary().whichPatch(curE);
202 label curBPatch = -1;
204 forAll (mesh_.boundary(), pI)
212 + mesh_.boundary()[pI].labelList::size()
220 if (!patchFields(curBPatch))
225 faPatchField<Type>::New
227 mesh_.boundary()[curBPatch].type(),
228 mesh_.boundary()[curBPatch],
229 DimensionedField<Type, areaMesh>::null()
235 // label curPatchEdge =
237 // [curBPatch].whichEdge(curE);
239 label curPatchEdge = curE - gStarts[curBPatch];
241 patchFields[curBPatch][curPatchEdge] =
249 forAll(mesh_.boundary(), patchI)
254 typeid(mesh_.boundary()[patchI]) == typeid(emptyFaPatch)
255 && !patchFields(patchI)
261 faPatchField<Type>::New
263 emptyFaPatchField<Type>::typeName,
264 mesh_.boundary()[patchI],
265 DimensionedField<Type, areaMesh>::null()
272 // Now construct and write the field
273 // setting the internalField and patchFields
274 return tmp<GeometricField<Type, faPatchField, areaMesh> >
276 new GeometricField<Type, faPatchField, areaMesh>
280 fieldIoObject.name(),
281 mesh_.time().timeName(),
287 procFields[0].dimensions(),
296 Foam::tmp<Foam::GeometricField<Type, Foam::faePatchField, Foam::edgeMesh> >
297 Foam::faFieldReconstructor::reconstructFaEdgeField
299 const IOobject& fieldIoObject
302 // Read the field for all the processors
303 PtrList<GeometricField<Type, faePatchField, edgeMesh> > procFields
308 forAll (procMeshes_, procI)
313 new GeometricField<Type, faePatchField, edgeMesh>
317 fieldIoObject.name(),
318 procMeshes_[procI].time().timeName(),
319 procMeshes_[procI](),
329 // Create the internalField
330 Field<Type> internalField(mesh_.nInternalEdges());
332 // Create the patch fields
333 PtrList<faePatchField<Type> > patchFields(mesh_.boundary().size());
336 labelList gStarts(mesh_.boundary().size(), -1);
338 if(mesh_.boundary().size() > 0)
340 gStarts[0] = mesh_.nInternalEdges();
343 for(label i=1; i<mesh_.boundary().size(); i++)
345 gStarts[i] = gStarts[i-1] + mesh_.boundary()[i-1].labelList::size();
349 forAll (procMeshes_, procI)
351 const GeometricField<Type, faePatchField, edgeMesh>& procField =
354 // Set the face values in the reconstructed field
356 // It is necessary to create a copy of the addressing array to
357 // take care of the face direction offset trick.
360 labelList curAddr(edgeProcAddressing_[procI]);
362 // forAll (curAddr, addrI)
364 // curAddr[addrI] -= 1;
369 procField.internalField(),
374 // Set the boundary patch values in the reconstructed field
376 labelList starts(procMeshes_[procI].boundary().size(), -1);
378 if(procMeshes_[procI].boundary().size() > 0)
380 starts[0] = procMeshes_[procI].nInternalEdges();
383 for(label i=1; i<procMeshes_[procI].boundary().size(); i++)
387 + procMeshes_[procI].boundary()[i-1].labelList::size();
390 forAll(boundaryProcAddressing_[procI], patchI)
392 // Get patch index of the original patch
393 const label curBPatch = boundaryProcAddressing_[procI][patchI];
395 // Get addressing slice for this patch
397 // const labelList::subList cp =
398 // procMeshes_[procI].boundary()[patchI].patchSlice
400 // faceProcAddressing_[procI]
403 const labelList::subList cp =
406 edgeProcAddressing_[procI],
407 procMeshes_[procI].boundary()[patchI].size(),
411 // check if the boundary patch is not a processor patch
414 // Regular patch. Fast looping
416 if (!patchFields(curBPatch))
421 faePatchField<Type>::New
423 procField.boundaryField()[patchI],
424 mesh_.boundary()[curBPatch],
425 DimensionedField<Type, edgeMesh>::null(),
426 faPatchFieldReconstructor
428 mesh_.boundary()[curBPatch].size(),
429 procField.boundaryField()[patchI].size()
435 const label curPatchStart = gStarts[curBPatch];
436 // mesh_.boundary()[curBPatch].start();
438 labelList reverseAddressing(cp.size());
442 // Subtract one to take into account offsets for
444 // reverseAddressing[faceI] = cp[faceI] - 1 - curPatchStart;
445 reverseAddressing[edgeI] = cp[edgeI] - curPatchStart;
448 patchFields[curBPatch].rmap
450 procField.boundaryField()[patchI],
456 const Field<Type>& curProcPatch =
457 procField.boundaryField()[patchI];
459 // In processor patches, there's a mix of internal faces (some
460 // of them turned) and possible cyclics. Slow loop
463 // label curF = cp[edgeI] - 1;
464 label curE = cp[edgeI];
466 // Is the face turned the right side round
469 // Is the face on the boundary?
470 if (curE >= mesh_.nInternalEdges())
473 // mesh_.boundary().whichPatch(curF);
475 label curBPatch = -1;
477 forAll (mesh_.boundary(), pI)
485 + mesh_.boundary()[pI].labelList::size()
493 if (!patchFields(curBPatch))
498 faePatchField<Type>::New
500 mesh_.boundary()[curBPatch].type(),
501 mesh_.boundary()[curBPatch],
502 DimensionedField<Type, edgeMesh>
509 // label curPatchFace =
511 // [curBPatch].whichEdge(curF);
513 label curPatchEdge = curE - gStarts[curBPatch];
515 patchFields[curBPatch][curPatchEdge] =
521 internalField[curE] = curProcPatch[edgeI];
529 forAll(mesh_.boundary(), patchI)
534 typeid(mesh_.boundary()[patchI]) == typeid(emptyFaPatch)
535 && !patchFields(patchI)
541 faePatchField<Type>::New
543 emptyFaePatchField<Type>::typeName,
544 mesh_.boundary()[patchI],
545 DimensionedField<Type, edgeMesh>::null()
552 // Now construct and write the field
553 // setting the internalField and patchFields
554 return tmp<GeometricField<Type, faePatchField, edgeMesh> >
556 new GeometricField<Type, faePatchField, edgeMesh>
560 fieldIoObject.name(),
561 mesh_.time().timeName(),
567 procFields[0].dimensions(),
575 // Reconstruct and write all area fields
577 void Foam::faFieldReconstructor::reconstructFaAreaFields
579 const IOobjectList& objects
582 const word& fieldClassName =
583 GeometricField<Type, faPatchField, areaMesh>::typeName;
585 IOobjectList fields = objects.lookupClass(fieldClassName);
589 Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
593 IOobjectList::const_iterator fieldIter = fields.begin();
594 fieldIter != fields.end();
598 Info << " " << fieldIter()->name() << endl;
600 reconstructFaAreaField<Type>(*fieldIter())().write();
607 // Reconstruct and write all edge fields
609 void Foam::faFieldReconstructor::reconstructFaEdgeFields
611 const IOobjectList& objects
614 const word& fieldClassName =
615 GeometricField<Type, faePatchField, edgeMesh>::typeName;
617 IOobjectList fields = objects.lookupClass(fieldClassName);
621 Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
625 IOobjectList::const_iterator fieldIter = fields.begin();
626 fieldIter != fields.end();
630 Info<< " " << fieldIter()->name() << endl;
632 reconstructFaEdgeField<Type>(*fieldIter())().write();
640 // ************************************************************************* //