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 "faFieldReconstructor.H"
30 #include "faPatchFields.H"
31 #include "emptyFaPatch.H"
32 #include "emptyFaPatchField.H"
33 #include "emptyFaePatchField.H"
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38 Foam::tmp<Foam::GeometricField<Type, Foam::faPatchField, Foam::areaMesh> >
39 Foam::faFieldReconstructor::reconstructFaAreaField
41 const IOobject& fieldIoObject
44 // Read the field for all the processors
45 PtrList<GeometricField<Type, faPatchField, areaMesh> > procFields
50 forAll (procMeshes_, procI)
55 new GeometricField<Type, faPatchField, areaMesh>
60 procMeshes_[procI].time().timeName(),
70 // Create the internalField
71 Field<Type> internalField(mesh_.nFaces());
73 // Create the patch fields
74 PtrList<faPatchField<Type> > patchFields(mesh_.boundary().size());
77 // Create global mesh patchs starts
79 labelList gStarts(mesh_.boundary().size(), -1);
81 if (mesh_.boundary().size() > 0)
83 gStarts[0] = mesh_.nInternalEdges();
86 for(label i=1; i<mesh_.boundary().size(); i++)
88 gStarts[i] = gStarts[i-1] + mesh_.boundary()[i-1].labelList::size();
91 forAll (procMeshes_, procI)
93 const GeometricField<Type, faPatchField, areaMesh>& procField =
96 // Set the face values in the reconstructed field
99 procField.internalField(),
100 faceProcAddressing_[procI]
105 // Set the boundary patch values in the reconstructed field
107 labelList starts(procMeshes_[procI].boundary().size(), -1);
109 if(procMeshes_[procI].boundary().size() > 0)
111 starts[0] = procMeshes_[procI].nInternalEdges();
114 for(label i=1; i<procMeshes_[procI].boundary().size(); i++)
118 + procMeshes_[procI].boundary()[i-1].labelList::size();
121 forAll(boundaryProcAddressing_[procI], patchI)
123 // Get patch index of the original patch
124 const label curBPatch = boundaryProcAddressing_[procI][patchI];
126 // Get addressing slice for this patch
128 // const labelList::subList cp =
129 // procMeshes_[procI].boundary()[patchI].patchSlice
131 // edgeProcAddressing_[procI]
134 const labelList::subList cp =
137 edgeProcAddressing_[procI],
138 procMeshes_[procI].boundary()[patchI].size(),
142 // check if the boundary patch is not a processor patch
145 // Regular patch. Fast looping
147 if (!patchFields(curBPatch))
152 faPatchField<Type>::New
154 procField.boundaryField()[patchI],
155 mesh_.boundary()[curBPatch],
156 DimensionedField<Type, areaMesh>::null(),
157 faPatchFieldReconstructor
159 mesh_.boundary()[curBPatch].size(),
160 procField.boundaryField()[patchI].size()
166 const label curPatchStart = gStarts[curBPatch];
167 // mesh_.boundary()[curBPatch].start();
169 labelList reverseAddressing(cp.size());
173 // Subtract one to take into account offsets for
175 // reverseAddressing[edgeI] = cp[edgeI] - 1 - curPatchStart;
176 reverseAddressing[edgeI] = cp[edgeI] - curPatchStart;
179 patchFields[curBPatch].rmap
181 procField.boundaryField()[patchI],
187 const Field<Type>& curProcPatch =
188 procField.boundaryField()[patchI];
190 // In processor patches, there's a mix of internal faces (some
191 // of them turned) and possible cyclics. Slow loop
194 // Subtract one to take into account offsets for
196 // label curE = cp[edgeI] - 1;
197 label curE = cp[edgeI];
199 // Is the face on the boundary?
200 if (curE >= mesh_.nInternalEdges())
202 // label curBPatch = mesh_.boundary().whichPatch(curE);
203 label curBPatch = -1;
205 forAll (mesh_.boundary(), pI)
213 + mesh_.boundary()[pI].labelList::size()
221 if (!patchFields(curBPatch))
226 faPatchField<Type>::New
228 mesh_.boundary()[curBPatch].type(),
229 mesh_.boundary()[curBPatch],
230 DimensionedField<Type, areaMesh>::null()
236 // label curPatchEdge =
238 // [curBPatch].whichEdge(curE);
240 label curPatchEdge = curE - gStarts[curBPatch];
242 patchFields[curBPatch][curPatchEdge] =
250 forAll(mesh_.boundary(), patchI)
255 typeid(mesh_.boundary()[patchI]) == typeid(emptyFaPatch)
256 && !patchFields(patchI)
262 faPatchField<Type>::New
264 emptyFaPatchField<Type>::typeName,
265 mesh_.boundary()[patchI],
266 DimensionedField<Type, areaMesh>::null()
273 // Now construct and write the field
274 // setting the internalField and patchFields
275 return tmp<GeometricField<Type, faPatchField, areaMesh> >
277 new GeometricField<Type, faPatchField, areaMesh>
281 fieldIoObject.name(),
282 mesh_.time().timeName(),
288 procFields[0].dimensions(),
297 Foam::tmp<Foam::GeometricField<Type, Foam::faePatchField, Foam::edgeMesh> >
298 Foam::faFieldReconstructor::reconstructFaEdgeField
300 const IOobject& fieldIoObject
303 // Read the field for all the processors
304 PtrList<GeometricField<Type, faePatchField, edgeMesh> > procFields
309 forAll (procMeshes_, procI)
314 new GeometricField<Type, faePatchField, edgeMesh>
318 fieldIoObject.name(),
319 procMeshes_[procI].time().timeName(),
320 procMeshes_[procI](),
330 // Create the internalField
331 Field<Type> internalField(mesh_.nInternalEdges());
333 // Create the patch fields
334 PtrList<faePatchField<Type> > patchFields(mesh_.boundary().size());
337 labelList gStarts(mesh_.boundary().size(), -1);
339 if(mesh_.boundary().size() > 0)
341 gStarts[0] = mesh_.nInternalEdges();
344 for(label i=1; i<mesh_.boundary().size(); i++)
346 gStarts[i] = gStarts[i-1] + mesh_.boundary()[i-1].labelList::size();
350 forAll (procMeshes_, procI)
352 const GeometricField<Type, faePatchField, edgeMesh>& procField =
355 // Set the face values in the reconstructed field
357 // It is necessary to create a copy of the addressing array to
358 // take care of the face direction offset trick.
361 labelList curAddr(edgeProcAddressing_[procI]);
363 // forAll (curAddr, addrI)
365 // curAddr[addrI] -= 1;
370 procField.internalField(),
375 // Set the boundary patch values in the reconstructed field
377 labelList starts(procMeshes_[procI].boundary().size(), -1);
379 if(procMeshes_[procI].boundary().size() > 0)
381 starts[0] = procMeshes_[procI].nInternalEdges();
384 for(label i=1; i<procMeshes_[procI].boundary().size(); i++)
388 + procMeshes_[procI].boundary()[i-1].labelList::size();
391 forAll(boundaryProcAddressing_[procI], patchI)
393 // Get patch index of the original patch
394 const label curBPatch = boundaryProcAddressing_[procI][patchI];
396 // Get addressing slice for this patch
398 // const labelList::subList cp =
399 // procMeshes_[procI].boundary()[patchI].patchSlice
401 // faceProcAddressing_[procI]
404 const labelList::subList cp =
407 edgeProcAddressing_[procI],
408 procMeshes_[procI].boundary()[patchI].size(),
412 // check if the boundary patch is not a processor patch
415 // Regular patch. Fast looping
417 if (!patchFields(curBPatch))
422 faePatchField<Type>::New
424 procField.boundaryField()[patchI],
425 mesh_.boundary()[curBPatch],
426 DimensionedField<Type, edgeMesh>::null(),
427 faPatchFieldReconstructor
429 mesh_.boundary()[curBPatch].size(),
430 procField.boundaryField()[patchI].size()
436 const label curPatchStart = gStarts[curBPatch];
437 // mesh_.boundary()[curBPatch].start();
439 labelList reverseAddressing(cp.size());
443 // Subtract one to take into account offsets for
445 // reverseAddressing[faceI] = cp[faceI] - 1 - curPatchStart;
446 reverseAddressing[edgeI] = cp[edgeI] - curPatchStart;
449 patchFields[curBPatch].rmap
451 procField.boundaryField()[patchI],
457 const Field<Type>& curProcPatch =
458 procField.boundaryField()[patchI];
460 // In processor patches, there's a mix of internal faces (some
461 // of them turned) and possible cyclics. Slow loop
464 // label curF = cp[edgeI] - 1;
465 label curE = cp[edgeI];
467 // Is the face turned the right side round
470 // Is the face on the boundary?
471 if (curE >= mesh_.nInternalEdges())
474 // mesh_.boundary().whichPatch(curF);
476 label curBPatch = -1;
478 forAll (mesh_.boundary(), pI)
486 + mesh_.boundary()[pI].labelList::size()
494 if (!patchFields(curBPatch))
499 faePatchField<Type>::New
501 mesh_.boundary()[curBPatch].type(),
502 mesh_.boundary()[curBPatch],
503 DimensionedField<Type, edgeMesh>
510 // label curPatchFace =
512 // [curBPatch].whichEdge(curF);
514 label curPatchEdge = curE - gStarts[curBPatch];
516 patchFields[curBPatch][curPatchEdge] =
522 internalField[curE] = curProcPatch[edgeI];
530 forAll(mesh_.boundary(), patchI)
535 typeid(mesh_.boundary()[patchI]) == typeid(emptyFaPatch)
536 && !patchFields(patchI)
542 faePatchField<Type>::New
544 emptyFaePatchField<Type>::typeName,
545 mesh_.boundary()[patchI],
546 DimensionedField<Type, edgeMesh>::null()
553 // Now construct and write the field
554 // setting the internalField and patchFields
555 return tmp<GeometricField<Type, faePatchField, edgeMesh> >
557 new GeometricField<Type, faePatchField, edgeMesh>
561 fieldIoObject.name(),
562 mesh_.time().timeName(),
568 procFields[0].dimensions(),
576 // Reconstruct and write all area fields
578 void Foam::faFieldReconstructor::reconstructFaAreaFields
580 const IOobjectList& objects
583 const word& fieldClassName =
584 GeometricField<Type, faPatchField, areaMesh>::typeName;
586 IOobjectList fields = objects.lookupClass(fieldClassName);
590 Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
594 IOobjectList::const_iterator fieldIter = fields.begin();
595 fieldIter != fields.end();
599 Info << " " << fieldIter()->name() << endl;
601 reconstructFaAreaField<Type>(*fieldIter())().write();
608 // Reconstruct and write all edge fields
610 void Foam::faFieldReconstructor::reconstructFaEdgeFields
612 const IOobjectList& objects
615 const word& fieldClassName =
616 GeometricField<Type, faePatchField, edgeMesh>::typeName;
618 IOobjectList fields = objects.lookupClass(fieldClassName);
622 Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
626 IOobjectList::const_iterator fieldIter = fields.begin();
627 fieldIter != fields.end();
631 Info<< " " << fieldIter()->name() << endl;
633 reconstructFaEdgeField<Type>(*fieldIter())().write();
641 // ************************************************************************* //