From b9507c21f98372c90ebad377213759a2f20ba532 Mon Sep 17 00:00:00 2001 From: sergio Date: Fri, 8 Apr 2022 10:30:25 -0700 Subject: [PATCH 01/10] ENH: Adding viewFactorsGenExt which uses pbrt for ray tracing --- .../preProcessing/viewFactorsGen/shootRays.H | 1 + .../viewFactorsGenExt/Make/files | 3 + .../viewFactorsGenExt/Make/options | 39 + .../viewFactorsGenExt/searchingEngineExt.H | 121 ++ .../viewFactorsGenExt/shootRaysExt.H | 196 +++ .../viewFactorsGenExt/viewFactorsGenExt.C | 1224 +++++++++++++++++ .../radiationModels/viewFactor/viewFactor.C | 2 + 7 files changed, 1586 insertions(+) create mode 100644 applications/utilities/preProcessing/viewFactorsGenExt/Make/files create mode 100644 applications/utilities/preProcessing/viewFactorsGenExt/Make/options create mode 100644 applications/utilities/preProcessing/viewFactorsGenExt/searchingEngineExt.H create mode 100644 applications/utilities/preProcessing/viewFactorsGenExt/shootRaysExt.H create mode 100644 applications/utilities/preProcessing/viewFactorsGenExt/viewFactorsGenExt.C diff --git a/applications/utilities/preProcessing/viewFactorsGen/shootRays.H b/applications/utilities/preProcessing/viewFactorsGen/shootRays.H index 1df6e108f0..e35b2d4268 100644 --- a/applications/utilities/preProcessing/viewFactorsGen/shootRays.H +++ b/applications/utilities/preProcessing/viewFactorsGen/shootRays.H @@ -49,6 +49,7 @@ for (const int proci : Pstream::allProcs()) const vector d(remFc - fc); + if (((d & fA) < 0.) && ((d & remA) > 0)) { start.append(fc + 0.001*d); diff --git a/applications/utilities/preProcessing/viewFactorsGenExt/Make/files b/applications/utilities/preProcessing/viewFactorsGenExt/Make/files new file mode 100644 index 0000000000..6d18b01b2c --- /dev/null +++ b/applications/utilities/preProcessing/viewFactorsGenExt/Make/files @@ -0,0 +1,3 @@ +viewFactorsGenExt.C + +EXE = $(FOAM_APPBIN)/viewFactorsGenExt diff --git a/applications/utilities/preProcessing/viewFactorsGenExt/Make/options b/applications/utilities/preProcessing/viewFactorsGenExt/Make/options new file mode 100644 index 0000000000..2c9476be08 --- /dev/null +++ b/applications/utilities/preProcessing/viewFactorsGenExt/Make/options @@ -0,0 +1,39 @@ +PBRT = /home/sergio/pub/pbrt +PBRTSRC = $(PBRT)/pbrt-v3/src +EXTSRC = $(PBRT)/pbrt-v3/src/ext +GLOGSRC = $(EXTSRC)/glog/src + +PBRTBUILD = /home/sergio/pub/pbrt/pbrt-v3-build +EXTBUILD = $(PBRTBUILD)/src/ext +GLOGBUILD = $(EXTBUILD)/glog + +EXE_INC = \ + -Wno-old-style-cast \ + -I$(PBRTSRC)/core \ + -I$(PBRTSRC)/accelerators \ + -I$(PBRTSRC)/shapes \ + -I$(PBRTSRC) \ + -I$(EXTSRC) \ + -I$(GLOGSRC) \ + -I$(GLOGBUILD) \ + -I./rays \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/surfMesh/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/parallel/distributed/lnInclude \ + +EXE_LIBS = \ + -L$(GLOGBUILD) -lglog \ + -L$(PBRTBUILD) -lpbrt \ + -L$(EXTBUILD)/openexr/OpenEXR/IlmImf -lIlmImf \ + -L$(EXTBUILD)/openexr/IlmBase/Imath -lImath \ + -L$(EXTBUILD)/openexr/IlmBase/Half -lHalf \ + -L$(EXTBUILD)/openexr/IlmBase/Iex -lIex \ + -L$(EXTBUILD)/openexr/IlmBase/IexMath -lIexMath \ + -L$(EXTBUILD)/openexr/IlmBase/IlmThread -lIlmThread \ + -L$(EXTBUILD)/ptex/src/ptex -lPtex \ + -lfiniteVolume \ + -lsurfMesh \ + -lmeshTools \ + -ldistributed \ + -lradiationModels diff --git a/applications/utilities/preProcessing/viewFactorsGenExt/searchingEngineExt.H b/applications/utilities/preProcessing/viewFactorsGenExt/searchingEngineExt.H new file mode 100644 index 0000000000..678899fc7d --- /dev/null +++ b/applications/utilities/preProcessing/viewFactorsGenExt/searchingEngineExt.H @@ -0,0 +1,121 @@ +Random rndGen(653213); + +// Determine mesh bounding boxes: +List meshBb +( + 1, + treeBoundBox + ( + boundBox(coarseMesh.points(), false) + ).extend(rndGen, 1e-3) +); + +// Dummy bounds dictionary +dictionary dict; +dict.add("bounds", meshBb); +dict.add +( + "distributionType", + distributedTriSurfaceMesh::distributionTypeNames_ + [ + distributedTriSurfaceMesh::FROZEN + ] +); +dict.add("mergeDistance", SMALL); + +labelList triSurfaceToAgglom(5*nFineFaces); + +const triSurface localSurface = triangulate +( + patches, + includePatches, + finalAgglom, + triSurfaceToAgglom, + globalNumbering, + coarsePatches +); + + +distributedTriSurfaceMesh surfacesMesh +( + IOobject + ( + "wallSurface.stl", + runTime.constant(), // directory + "triSurface", // instance + runTime, // registry + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + localSurface, + dict +); + + +triSurfaceToAgglom.resize(surfacesMesh.size()); + +// pbrt surface +std::vector vertices; + +const pointField& pts = surfacesMesh.localPoints(); +for (const auto& pt : pts) +{ + vertices.push_back(Point3f(pt[0], pt[1], pt[2])); +} + +std::vector indices; +for (const auto& tri : surfacesMesh.localFaces()) +{ + indices.push_back(tri[0]); + indices.push_back(tri[1]); + indices.push_back(tri[2]); +} + +std::vector faceIndices; +faceIndices.reserve(surfacesMesh.localFaces().size()); + +for (label faceI = 0; faceI < surfacesMesh.localFaces().size(); faceI++) +{ + faceIndices.push_back(faceI); +} + +Transform o2w; +Transform w2o; + +std::vector> surfacesMesh_pbrt +( + CreateTriangleMesh + ( + &o2w, + &w2o, + false, // bool reverseOrientation + surfacesMesh.size(), // int nTriangles + &indices[0], // int *vertexIndices + vertices.size(), + &vertices[0], + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + &faceIndices[0] + ) +); + +std::vector> prims; + +prims.reserve(surfacesMesh_pbrt.size()); +for (auto s : surfacesMesh_pbrt) +{ + prims.push_back + ( + std::make_shared + (s, nullptr, nullptr, nullptr) + ); +} + +std::shared_ptr accel; + +ParamSet paramSet; + +accel = CreateBVHAccelerator(std::move(prims), paramSet); diff --git a/applications/utilities/preProcessing/viewFactorsGenExt/shootRaysExt.H b/applications/utilities/preProcessing/viewFactorsGenExt/shootRaysExt.H new file mode 100644 index 0000000000..29ace62fe6 --- /dev/null +++ b/applications/utilities/preProcessing/viewFactorsGenExt/shootRaysExt.H @@ -0,0 +1,196 @@ +// All rays expressed as start face (local) index end end face (global) +// Pre-size by assuming a certain percentage is visible. + +// Maximum length for dynamicList +const label maxDynListLength +( + viewFactorDict.getOrDefault