viewFactorsGen.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Application
28  viewFactorsGen
29 
30 Group
31  grpPreProcessingUtilities
32 
33 Description
34  View factors are calculated based on a face agglomeration array
35  (finalAgglom generated by faceAgglomerate utility).
36 
37  Each view factor between the agglomerated faces i and j (Fij) is calculated
38  using a double integral of the sub-areas composing the agglomeration.
39 
40  The patches involved in the view factor calculation are taken from the
41  boundary file and should be part on the group viewFactorWall. ie.:
42 
43  floor
44  {
45  type wall;
46  inGroups 2(wall viewFactorWall);
47  nFaces 100;
48  startFace 3100;
49  }
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #include "argList.H"
54 #include "fvMesh.H"
55 #include "volFields.H"
56 #include "surfaceFields.H"
58 #include "meshTools.H"
59 
61 #include "DynamicField.H"
62 #include "unitConversion.H"
63 
64 #include "scalarMatrices.H"
65 #include "labelListIOList.H"
66 #include "scalarListIOList.H"
67 
68 #include "singleCellFvMesh.H"
69 
70 #include "IOmapDistribute.H"
71 
72 using namespace Foam;
73 
74 
75 triSurface triangulate
76 (
77  const polyBoundaryMesh& bMesh,
78  const labelHashSet& includePatches,
79  const labelListIOList& finalAgglom,
81  const globalIndex& globalNumbering,
82  const polyBoundaryMesh& coarsePatches
83 )
84 {
85  const polyMesh& mesh = bMesh.mesh();
86 
87  // Storage for surfaceMesh. Size estimate.
89 
90  label newPatchI = 0;
91  label localTriFaceI = 0;
92 
93  for (const label patchI : includePatches)
94  {
95  const polyPatch& patch = bMesh[patchI];
96  const pointField& points = patch.points();
97 
98  label nTriTotal = 0;
99 
100  forAll(patch, patchFaceI)
101  {
102  const face& f = patch[patchFaceI];
103 
104  faceList triFaces(f.nTriangles(points));
105 
106  label nTri = 0;
107 
108  f.triangles(points, nTri, triFaces);
109 
110  forAll(triFaces, triFaceI)
111  {
112  const face& f = triFaces[triFaceI];
113 
114  triangles.append(labelledTri(f[0], f[1], f[2], newPatchI));
115 
116  nTriTotal++;
117 
118  triSurfaceToAgglom[localTriFaceI++] = globalNumbering.toGlobal
119  (
121  finalAgglom[patchI][patchFaceI]
122  + coarsePatches[patchI].start()
123  );
124  }
125  }
126 
127  newPatchI++;
128  }
129 
130  //striSurfaceToAgglom.resize(localTriFaceI-1);
131 
132  triangles.shrink();
133 
134  // Create globally numbered tri surface
135  triSurface rawSurface(triangles, mesh.points());
136 
137  // Create locally numbered tri surface
138  triSurface surface
139  (
140  rawSurface.localFaces(),
141  rawSurface.localPoints()
142  );
143 
144  // Add patch names to surface
145  surface.patches().setSize(newPatchI);
146 
147  newPatchI = 0;
148 
149  for (const label patchI : includePatches)
150  {
151  const polyPatch& patch = bMesh[patchI];
152 
153  surface.patches()[newPatchI].index() = patchI;
154  surface.patches()[newPatchI].name() = patch.name();
155  surface.patches()[newPatchI].geometricType() = patch.type();
156 
157  newPatchI++;
158  }
159 
160  return surface;
161 }
162 
163 
164 void writeRays
165 (
166  const fileName& fName,
167  const pointField& compactCf,
168  const pointField& myFc,
169  const labelListList& visibleFaceFaces
170 )
171 {
172  OFstream str(fName);
173  label vertI = 0;
174 
175  Pout<< "Dumping rays to " << str.name() << endl;
176 
177  forAll(myFc, faceI)
178  {
179  const labelList visFaces = visibleFaceFaces[faceI];
180  forAll(visFaces, faceRemote)
181  {
182  label compactI = visFaces[faceRemote];
183  const point& remoteFc = compactCf[compactI];
184 
185  meshTools::writeOBJ(str, myFc[faceI]);
186  vertI++;
187  meshTools::writeOBJ(str, remoteFc);
188  vertI++;
189  str << "l " << vertI-1 << ' ' << vertI << nl;
190  }
191  }
192  str.flush();
193 }
194 
195 
196 scalar calculateViewFactorFij
197 (
198  const vector& i,
199  const vector& j,
200  const vector& dAi,
201  const vector& dAj
202 )
203 {
204  vector r = i - j;
205  scalar rMag = mag(r);
206 
207  if (rMag > SMALL)
208  {
209  scalar dAiMag = mag(dAi);
210  scalar dAjMag = mag(dAj);
211 
212  vector ni = dAi/dAiMag;
213  vector nj = dAj/dAjMag;
214  scalar cosThetaJ = mag(nj & r)/rMag;
215  scalar cosThetaI = mag(ni & r)/rMag;
216 
217  return
218  (
219  (cosThetaI*cosThetaJ*dAjMag*dAiMag)
221  );
222  }
223  else
224  {
225  return 0;
226  }
227 }
228 
229 
230 void insertMatrixElements
231 (
232  const globalIndex& globalNumbering,
233  const label fromProcI,
234  const labelListList& globalFaceFaces,
235  const scalarListList& viewFactors,
236  scalarSquareMatrix& matrix
237 )
238 {
239  forAll(viewFactors, faceI)
240  {
241  const scalarList& vf = viewFactors[faceI];
242  const labelList& globalFaces = globalFaceFaces[faceI];
243 
244  label globalI = globalNumbering.toGlobal(fromProcI, faceI);
245  forAll(globalFaces, i)
246  {
247  matrix[globalI][globalFaces[i]] = vf[i];
248  }
249  }
250 }
251 
252 
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 
255 int main(int argc, char *argv[])
256 {
258  (
259  "Calculate view factors from face agglomeration array."
260  " The finalAgglom generated by faceAgglomerate utility."
261  );
262 
263  #include "addRegionOption.H"
264  #include "setRootCase.H"
265  #include "createTime.H"
266  #include "createNamedMesh.H"
267 
268  // Read view factor dictionary
269  IOdictionary viewFactorDict
270  (
271  IOobject
272  (
273  "viewFactorsDict",
274  runTime.constant(),
275  mesh,
278  )
279  );
280 
281  const word viewFactorWall("viewFactorWall");
282 
283  const bool writeViewFactors =
284  viewFactorDict.getOrDefault("writeViewFactorMatrix", false);
285 
286  const bool dumpRays =
287  viewFactorDict.getOrDefault("dumpRays", false);
288 
289  const label debug = viewFactorDict.getOrDefault<label>("debug", 0);
290 
291  // Read agglomeration map
292  labelListIOList finalAgglom
293  (
294  IOobject
295  (
296  "finalAgglom",
298  mesh,
301  false
302  )
303  );
304 
305  // Create the coarse mesh using agglomeration
306  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
307 
308  if (debug)
309  {
310  Pout << "\nCreating single cell mesh..." << endl;
311  }
312 
313  singleCellFvMesh coarseMesh
314  (
315  IOobject
316  (
317  "coarse:" + mesh.name(),
318  runTime.timeName(),
319  runTime,
322  ),
323  mesh,
324  finalAgglom
325  );
326 
327  if (debug)
328  {
329  Pout << "\nCreated single cell mesh..." << endl;
330  }
331 
332 
333  // Calculate total number of fine and coarse faces
334  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
335 
336  label nCoarseFaces = 0; //total number of coarse faces
337  label nFineFaces = 0; //total number of fine faces
338 
340  const polyBoundaryMesh& coarsePatches = coarseMesh.boundaryMesh();
341 
342  labelList viewFactorsPatches(patches.indices(viewFactorWall));
343  for (const label patchi : viewFactorsPatches)
344  {
345  nCoarseFaces += coarsePatches[patchi].size();
346  nFineFaces += patches[patchi].size();
347  }
348 
349  // total number of coarse faces
350  label totalNCoarseFaces = nCoarseFaces;
351 
352  reduce(totalNCoarseFaces, sumOp<label>());
353 
354  if (Pstream::master())
355  {
356  Info << "\nTotal number of coarse faces: "<< totalNCoarseFaces << endl;
357  }
358 
359  if (Pstream::master() && debug)
360  {
361  Pout << "\nView factor patches included in the calculation : "
362  << viewFactorsPatches << endl;
363  }
364 
365  // Collect local Cf and Sf on coarse mesh
366  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367 
368  DynamicList<point> localCoarseCf(nCoarseFaces);
369  DynamicList<point> localCoarseSf(nCoarseFaces);
370  DynamicList<label> localAgg(nCoarseFaces);
371  labelHashSet includePatches;
372 
373  for (const label patchID : viewFactorsPatches)
374  {
375  const polyPatch& pp = patches[patchID];
376  const labelList& agglom = finalAgglom[patchID];
377 
378  includePatches.insert(patchID);
379 
380  if (agglom.size() > 0)
381  {
382  label nAgglom = max(agglom)+1;
383  labelListList coarseToFine(invertOneToMany(nAgglom, agglom));
384  const labelList& coarsePatchFace =
385  coarseMesh.patchFaceMap()[patchID];
386 
387  const pointField& coarseCf =
388  coarseMesh.Cf().boundaryField()[patchID];
389  const pointField& coarseSf =
390  coarseMesh.Sf().boundaryField()[patchID];
391 
392  forAll(coarseCf, faceI)
393  {
394  point cf = coarseCf[faceI];
395 
396  const label coarseFaceI = coarsePatchFace[faceI];
397  const labelList& fineFaces = coarseToFine[coarseFaceI];
398  const label agglomI =
399  agglom[fineFaces[0]] + coarsePatches[patchID].start();
400 
401  // Construct single face
403  (
404  UIndirectList<face>(pp, fineFaces),
405  pp.points()
406  );
407 
408  List<point> availablePoints
409  (
410  upp.faceCentres().size()
411  + upp.localPoints().size()
412  );
413 
415  (
416  availablePoints,
417  upp.faceCentres().size()
418  ) = upp.faceCentres();
419 
421  (
422  availablePoints,
423  upp.localPoints().size(),
424  upp.faceCentres().size()
425  ) = upp.localPoints();
426 
427  point cfo = cf;
428  scalar dist = GREAT;
429  forAll(availablePoints, iPoint)
430  {
431  point cfFine = availablePoints[iPoint];
432  if (mag(cfFine-cfo) < dist)
433  {
434  dist = mag(cfFine-cfo);
435  cf = cfFine;
436  }
437  }
438 
439  point sf = coarseSf[faceI];
440  localCoarseCf.append(cf);
441  localCoarseSf.append(sf);
442  localAgg.append(agglomI);
443 
444  }
445  }
446  }
447 
448  // Distribute local coarse Cf and Sf for shooting rays
449  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
450 
451  List<pointField> remoteCoarseCf(Pstream::nProcs());
452  List<pointField> remoteCoarseSf(Pstream::nProcs());
453  List<labelField> remoteCoarseAgg(Pstream::nProcs());
454 
455  remoteCoarseCf[Pstream::myProcNo()] = localCoarseCf;
456  remoteCoarseSf[Pstream::myProcNo()] = localCoarseSf;
457  remoteCoarseAgg[Pstream::myProcNo()] = localAgg;
458 
459  Pstream::gatherList(remoteCoarseCf);
460  Pstream::scatterList(remoteCoarseCf);
461  Pstream::gatherList(remoteCoarseSf);
462  Pstream::scatterList(remoteCoarseSf);
463  Pstream::gatherList(remoteCoarseAgg);
464  Pstream::scatterList(remoteCoarseAgg);
465 
466 
467  globalIndex globalNumbering(nCoarseFaces);
468 
469  // Set up searching engine for obstacles
470  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
471  #include "searchingEngine.H"
472 
473  // Determine rays between coarse face centres
474  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
475  DynamicList<label> rayStartFace(nCoarseFaces + 0.01*nCoarseFaces);
476 
477  DynamicList<label> rayEndFace(rayStartFace.size());
478 
479 
480  // Return rayStartFace in local index and rayEndFace in global index
481  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
482 
483  #include "shootRays.H"
484 
485  // Calculate number of visible faces from local index
486  labelList nVisibleFaceFaces(nCoarseFaces, Zero);
487 
488  forAll(rayStartFace, i)
489  {
490  nVisibleFaceFaces[rayStartFace[i]]++;
491  }
492 
493  labelListList visibleFaceFaces(nCoarseFaces);
494 
495  label nViewFactors = 0;
496  forAll(nVisibleFaceFaces, faceI)
497  {
498  visibleFaceFaces[faceI].setSize(nVisibleFaceFaces[faceI]);
499  nViewFactors += nVisibleFaceFaces[faceI];
500  }
501 
502  // - Construct compact numbering
503  // - return map from remote to compact indices
504  // (per processor (!= myProcNo) a map from remote index to compact index)
505  // - construct distribute map
506  // - renumber rayEndFace into compact addressing
507 
508  List<Map<label>> compactMap(Pstream::nProcs());
509 
510  mapDistribute map(globalNumbering, rayEndFace, compactMap);
511 
512  // visibleFaceFaces has:
513  // (local face, local viewed face) = compact viewed face
514  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
515 
516  nVisibleFaceFaces = 0;
517  forAll(rayStartFace, i)
518  {
519  label faceI = rayStartFace[i];
520  label compactI = rayEndFace[i];
521  visibleFaceFaces[faceI][nVisibleFaceFaces[faceI]++] = compactI;
522  }
523 
524 
525  // Construct data in compact addressing
526  // I need coarse Sf (Ai), fine Sf (dAi) and fine Cf(r) to calculate Fij
527  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
528 
529  pointField compactCoarseCf(map.constructSize(), Zero);
530  pointField compactCoarseSf(map.constructSize(), Zero);
531  List<List<point>> compactFineSf(map.constructSize());
532  List<List<point>> compactFineCf(map.constructSize());
533 
534  DynamicList<label> compactPatchId(map.constructSize());
535 
536  // Insert my coarse local values
537  SubList<point>(compactCoarseSf, nCoarseFaces) = localCoarseSf;
538  SubList<point>(compactCoarseCf, nCoarseFaces) = localCoarseCf;
539 
540  // Insert my fine local values
541  label compactI = 0;
542  forAll(viewFactorsPatches, i)
543  {
544  label patchID = viewFactorsPatches[i];
545 
546  const labelList& agglom = finalAgglom[patchID];
547  if (agglom.size() > 0)
548  {
549  label nAgglom = max(agglom)+1;
550  labelListList coarseToFine(invertOneToMany(nAgglom, agglom));
551  const labelList& coarsePatchFace =
552  coarseMesh.patchFaceMap()[patchID];
553 
554  forAll(coarseToFine, coarseI)
555  {
556  compactPatchId.append(patchID);
557  List<point>& fineCf = compactFineCf[compactI];
558  List<point>& fineSf = compactFineSf[compactI++];
559 
560  const label coarseFaceI = coarsePatchFace[coarseI];
561  const labelList& fineFaces = coarseToFine[coarseFaceI];
562 
563  fineCf.setSize(fineFaces.size());
564  fineSf.setSize(fineFaces.size());
565 
566  fineCf = UIndirectList<point>
567  (
569  coarseToFine[coarseFaceI]
570  );
571  fineSf = UIndirectList<point>
572  (
574  coarseToFine[coarseFaceI]
575  );
576  }
577  }
578  }
579 
580  // Do all swapping
581  map.distribute(compactCoarseSf);
582  map.distribute(compactCoarseCf);
583  map.distribute(compactFineCf);
584  map.distribute(compactFineSf);
585 
586  map.distribute(compactPatchId);
587 
588 
589  // Plot all rays between visible faces.
590  if (dumpRays)
591  {
592  writeRays
593  (
594  runTime.path()/"allVisibleFaces.obj",
595  compactCoarseCf,
596  remoteCoarseCf[Pstream::myProcNo()],
597  visibleFaceFaces
598  );
599  }
600 
601 
602  // Fill local view factor matrix
603  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
604 
606  (
607  IOobject
608  (
609  "F",
611  mesh,
614  false
615  ),
616  nCoarseFaces
617  );
618 
619  label totalPatches = coarsePatches.size();
620  reduce(totalPatches, maxOp<label>());
621 
622  // Matrix sum in j(Fij) for each i (if enclosure sum = 1)
623  scalarSquareMatrix sumViewFactorPatch
624  (
625  totalPatches,
626  0.0
627  );
628 
629  scalarList patchArea(totalPatches, Zero);
630 
631  if (Pstream::master())
632  {
633  Info<< "\nCalculating view factors..." << endl;
634  }
635 
636  if (mesh.nSolutionD() == 3)
637  {
638  forAll(localCoarseSf, coarseFaceI)
639  {
640  const List<point>& localFineSf = compactFineSf[coarseFaceI];
641  const vector Ai = sum(localFineSf);
642  const List<point>& localFineCf = compactFineCf[coarseFaceI];
643  const label fromPatchId = compactPatchId[coarseFaceI];
644  patchArea[fromPatchId] += mag(Ai);
645 
646  const labelList& visCoarseFaces = visibleFaceFaces[coarseFaceI];
647 
648  forAll(visCoarseFaces, visCoarseFaceI)
649  {
650  F[coarseFaceI].setSize(visCoarseFaces.size());
651  label compactJ = visCoarseFaces[visCoarseFaceI];
652  const List<point>& remoteFineSj = compactFineSf[compactJ];
653  const List<point>& remoteFineCj = compactFineCf[compactJ];
654 
655  const label toPatchId = compactPatchId[compactJ];
656 
657  scalar Fij = 0;
658  forAll(localFineSf, i)
659  {
660  const vector& dAi = localFineSf[i];
661  const vector& dCi = localFineCf[i];
662 
663  forAll(remoteFineSj, j)
664  {
665  const vector& dAj = remoteFineSj[j];
666  const vector& dCj = remoteFineCj[j];
667 
668  scalar dIntFij = calculateViewFactorFij
669  (
670  dCi,
671  dCj,
672  dAi,
673  dAj
674  );
675 
676  Fij += dIntFij;
677  }
678  }
679  F[coarseFaceI][visCoarseFaceI] = Fij/mag(Ai);
680  sumViewFactorPatch[fromPatchId][toPatchId] += Fij;
681  }
682  }
683  }
684  else if (mesh.nSolutionD() == 2)
685  {
686  const boundBox& box = mesh.bounds();
687  const Vector<label>& dirs = mesh.geometricD();
688  vector emptyDir = Zero;
689  forAll(dirs, i)
690  {
691  if (dirs[i] == -1)
692  {
693  emptyDir[i] = 1.0;
694  }
695  }
696 
697  scalar wideBy2 = (box.span() & emptyDir)*2.0;
698 
699  forAll(localCoarseSf, coarseFaceI)
700  {
701  const vector& Ai = localCoarseSf[coarseFaceI];
702  const vector& Ci = localCoarseCf[coarseFaceI];
703  vector Ain = Ai/mag(Ai);
704  vector R1i = Ci + (mag(Ai)/wideBy2)*(Ain ^ emptyDir);
705  vector R2i = Ci - (mag(Ai)/wideBy2)*(Ain ^ emptyDir) ;
706 
707  const label fromPatchId = compactPatchId[coarseFaceI];
708  patchArea[fromPatchId] += mag(Ai);
709 
710  const labelList& visCoarseFaces = visibleFaceFaces[coarseFaceI];
711  forAll(visCoarseFaces, visCoarseFaceI)
712  {
713  F[coarseFaceI].setSize(visCoarseFaces.size());
714  label compactJ = visCoarseFaces[visCoarseFaceI];
715  const vector& Aj = compactCoarseSf[compactJ];
716  const vector& Cj = compactCoarseCf[compactJ];
717 
718  const label toPatchId = compactPatchId[compactJ];
719 
720  vector Ajn = Aj/mag(Aj);
721  vector R1j = Cj + (mag(Aj)/wideBy2)*(Ajn ^ emptyDir);
722  vector R2j = Cj - (mag(Aj)/wideBy2)*(Ajn ^ emptyDir);
723 
724  scalar d1 = mag(R1i - R2j);
725  scalar d2 = mag(R2i - R1j);
726  scalar s1 = mag(R1i - R1j);
727  scalar s2 = mag(R2i - R2j);
728 
729  scalar Fij = mag((d1 + d2) - (s1 + s2))/(4.0*mag(Ai)/wideBy2);
730 
731  F[coarseFaceI][visCoarseFaceI] = Fij;
732  sumViewFactorPatch[fromPatchId][toPatchId] += Fij*mag(Ai);
733  }
734  }
735  }
736 
737  if (Pstream::master())
738  {
739  Info << "Writing view factor matrix..." << endl;
740  }
741 
742  // Write view factors matrix in listlist form
743  F.write();
744 
745  reduce(sumViewFactorPatch, sumOp<scalarSquareMatrix>());
746  reduce(patchArea, sumOp<scalarList>());
747 
748 
749  if (Pstream::master() && debug)
750  {
751  forAll(viewFactorsPatches, i)
752  {
753  label patchI = viewFactorsPatches[i];
754  forAll(viewFactorsPatches, i)
755  {
756  label patchJ = viewFactorsPatches[i];
757  Info << "F" << patchI << patchJ << ": "
758  << sumViewFactorPatch[patchI][patchJ]/patchArea[patchI]
759  << endl;
760  }
761  }
762  }
763 
764 
765  if (writeViewFactors)
766  {
767  volScalarField viewFactorField
768  (
769  IOobject
770  (
771  "viewFactorField",
772  mesh.time().timeName(),
773  mesh,
776  ),
777  mesh,
779  );
780 
781  label compactI = 0;
782 
783  volScalarField::Boundary& vfbf = viewFactorField.boundaryFieldRef();
784  forAll(viewFactorsPatches, i)
785  {
786  label patchID = viewFactorsPatches[i];
787  const labelList& agglom = finalAgglom[patchID];
788  if (agglom.size() > 0)
789  {
790  label nAgglom = max(agglom)+1;
791  labelListList coarseToFine(invertOneToMany(nAgglom, agglom));
792  const labelList& coarsePatchFace =
793  coarseMesh.patchFaceMap()[patchID];
794 
795  forAll(coarseToFine, coarseI)
796  {
797  const scalar Fij = sum(F[compactI]);
798  const label coarseFaceID = coarsePatchFace[coarseI];
799  const labelList& fineFaces = coarseToFine[coarseFaceID];
800  forAll(fineFaces, fineId)
801  {
802  const label faceID = fineFaces[fineId];
803  vfbf[patchID][faceID] = Fij;
804  }
805  compactI++;
806  }
807  }
808  }
809  viewFactorField.write();
810  }
811 
812 
813  // Invert compactMap (from processor+localface to compact) to go
814  // from compact to processor+localface (expressed as a globalIndex)
815  // globalIndex globalCoarFaceNum(coarseMesh.nFaces());
816  labelList compactToGlobal(map.constructSize());
817 
818  // Local indices first (note: are not in compactMap)
819  for (label i = 0; i < globalNumbering.localSize(); i++)
820  {
821  compactToGlobal[i] = globalNumbering.toGlobal(i);
822  }
823 
824 
825  forAll(compactMap, procI)
826  {
827  const Map<label>& localToCompactMap = compactMap[procI];
828 
829  forAllConstIters(localToCompactMap, iter)
830  {
831  compactToGlobal[*iter] = globalNumbering.toGlobal
832  (
833  procI,
834  iter.key()
835  );
836  }
837  }
838 
839 
840  labelListList globalFaceFaces(visibleFaceFaces.size());
841 
842  // Create globalFaceFaces needed to insert view factors
843  // in F to the global matrix Fmatrix
844  forAll(globalFaceFaces, faceI)
845  {
846  globalFaceFaces[faceI] = renumber
847  (
848  compactToGlobal,
849  visibleFaceFaces[faceI]
850  );
851  }
852 
853  labelListIOList IOglobalFaceFaces
854  (
855  IOobject
856  (
857  "globalFaceFaces",
859  mesh,
862  false
863  ),
864  std::move(globalFaceFaces)
865  );
866  IOglobalFaceFaces.write();
867 
868 
869  labelListIOList IOvisibleFaceFaces
870  (
871  IOobject
872  (
873  "visibleFaceFaces",
875  mesh,
878  false
879  ),
880  std::move(visibleFaceFaces)
881  );
882  IOvisibleFaceFaces.write();
883 
884  IOmapDistribute IOmapDist
885  (
886  IOobject
887  (
888  "mapDist",
890  mesh,
893  ),
894  std::move(map)
895  );
896 
897  IOmapDist.write();
898 
899  Info<< "End\n" << endl;
900  return 0;
901 }
902 
903 
904 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::PrimitivePatch::points
const Field< point_type > & points() const noexcept
Return reference to global points.
Definition: PrimitivePatch.H:299
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
volFields.H
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::maxOp
Definition: ops.H:223
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
meshTools.H
distributedTriSurfaceMesh.H
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
uindirectPrimitivePatch.H
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:203
Foam::IOmapDistribute
IOmapDistribute is derived from mapDistribute and IOobject to give the mapDistribute automatic IO fun...
Definition: IOmapDistribute.H:54
Foam::Pstream::scatterList
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
Definition: gatherScatterList.C:215
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:54
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:412
Foam::polyMesh::facesInstance
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: polyMesh.C:852
Foam::Map< label >
unitConversion.H
Unit conversion functions.
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:457
F
volVectorField F(fluid.F())
Foam::globalIndex::localSize
label localSize() const
My local size.
Definition: globalIndexI.H:187
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
surfaceFields.H
Foam::surfaceFields.
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::HashSet< label, Hash< label > >
Foam::DynamicList::shrink
DynamicList< T, SizeMin > & shrink()
Shrink the allocated space to the number of elements used.
Definition: DynamicListI.H:434
Foam::polyMesh::geometricD
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
Definition: polyMesh.C:858
Foam::triSurface::patches
const geometricSurfacePatchList & patches() const noexcept
Definition: triSurface.H:399
Foam::polyBoundaryMesh::start
label start() const
The start label of the boundary faces in the polyMesh face list.
Definition: polyBoundaryMesh.C:611
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
labelListIOList.H
Foam::boundBox::span
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:127
Foam::singleCellFvMesh
fvMesh as subset of other mesh. Consists of one cell and all original bounday faces....
Definition: singleCellFvMesh.H:56
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::Field< vector >
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Write using setting from DB.
Definition: regIOobjectWrite.C:132
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:76
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::OSstream::name
virtual const fileName & name() const
Get the name of the stream.
Definition: OSstream.H:107
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
argList.H
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:163
patchID
label patchID
Definition: boundaryProcessorFaPatchPoints.H:5
addRegionOption.H
Foam::primitiveMesh::nBoundaryFaces
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
Definition: primitiveMeshI.H:84
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
singleCellFvMesh.H
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
searchingEngine.H
triSurfaceToAgglom
labelList triSurfaceToAgglom(5 *nFineFaces)
createNamedMesh.H
Required Variables.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
shootRays.H
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
Foam::polyMesh::nSolutionD
label nSolutionD() const
Return the number of valid solved-for dimensions in the mesh.
Definition: polyMesh.C:886
Foam::polyMesh::bounds
const boundBox & bounds() const
Return mesh bounding box.
Definition: polyMesh.H:450
setRootCase.H
Foam::renumber
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values (not the indices) of a list.
Definition: ListOpsTemplates.C:37
Foam::SquareMatrix< scalar >
IOmapDistribute.H
Foam::Pstream::gatherList
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Definition: gatherScatterList.C:52
DynamicField.H
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:463
Foam::constant::mathematical::pi
constexpr scalar pi(M_PI)
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:358
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
f
labelList f(nPoints)
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
scalarListIOList.H
Foam::GeometricField::boundaryFieldRef
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
Definition: GeometricField.C:783
Foam::Vector< scalar >
Foam::polyBoundaryMesh::indices
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) patch indices for all matches.
Definition: polyBoundaryMesh.C:642
Foam::List< label >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::IOList< labelList >
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:327
createTime.H
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::labelledTri
A triFace with additional (region) index.
Definition: labelledTri.H:57
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
scalarMatrices.H
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::invertOneToMany
labelListList invertOneToMany(const label len, const labelUList &map)
Invert one-to-many map. Unmapped elements will be size 0.
Definition: ListOps.C:114
Foam::fvMesh::Cf
const surfaceVectorField & Cf() const
Return face centres as surfaceVectorField.
Definition: fvMeshGeometry.C:352
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
Definition: UPstream.H:445
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189
Foam::globalIndex::toGlobal
label toGlobal(const label i) const
From local to global index.
Definition: globalIndexI.H:240
Foam::fvMesh::name
const word & name() const
Return reference to name.
Definition: fvMesh.H:300
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79
Foam::IOobject::MUST_READ
Definition: IOobject.H:185
Foam::fvMesh::Sf
const surfaceVectorField & Sf() const
Return cell face area vectors.
Definition: fvMeshGeometry.C:319