pyviewfactor 1.0.0__tar.gz → 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. pyviewfactor-1.0.2/PKG-INFO +374 -0
  2. pyviewfactor-1.0.2/README.md +353 -0
  3. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor/__init__.py +4 -2
  4. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor/_version.py +2 -1
  5. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor/pvf_geometry_preprocess.py +160 -13
  6. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor/pvf_integrators.py +2 -0
  7. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor/pvf_plot.py +1 -0
  8. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor/pvf_viewfactor_computations.py +95 -55
  9. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor/pvf_visibility_obstruction.py +216 -75
  10. pyviewfactor-1.0.2/pyviewfactor.egg-info/PKG-INFO +374 -0
  11. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor.egg-info/SOURCES.txt +2 -1
  12. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/setup.cfg +1 -1
  13. pyviewfactor-1.0.2/setup.py +6 -0
  14. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/test/test_geometry_preprocess.py +41 -0
  15. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/test/test_view_factor.py +208 -0
  16. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/test/test_visibility_obstruction.py +134 -6
  17. pyviewfactor-1.0.2/test/test_visibility_obstruction_semantics.py +462 -0
  18. pyviewfactor-1.0.0/PKG-INFO +0 -487
  19. pyviewfactor-1.0.0/README.md +0 -466
  20. pyviewfactor-1.0.0/pyviewfactor.egg-info/PKG-INFO +0 -487
  21. pyviewfactor-1.0.0/setup.py +0 -7
  22. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/LICENSE.txt +0 -0
  23. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor.egg-info/dependency_links.txt +0 -0
  24. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor.egg-info/requires.txt +0 -0
  25. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/pyviewfactor.egg-info/top_level.txt +0 -0
  26. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/test/__init__.py +0 -0
  27. {pyviewfactor-1.0.0 → pyviewfactor-1.0.2}/test/test_plot.py +0 -0
@@ -0,0 +1,374 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyviewfactor
3
+ Version: 1.0.2
4
+ Summary: "A lightweight open-source Python library for exact view-factor computations on polygonal meshes"
5
+ Home-page: https://gitlab.com/arep-dev/pyViewFactor/
6
+ Author: Mateusz BOGDAN, Edouard WALTHER
7
+ Author-email: mateusz.bogdan@arep.fr
8
+ License: MIT
9
+ Keywords: radiative-transfer,radiation,vtk,geometry,viewfactor,visibility
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Topic :: Scientific/Engineering :: Physics
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE.txt
17
+ Requires-Dist: numpy>=1.26
18
+ Requires-Dist: scipy>=1.11
19
+ Requires-Dist: numba>=0.61
20
+ Requires-Dist: pyvista>=0.45
21
+
22
+ # PyViewFactor
23
+
24
+
25
+ <div align="center">
26
+ <img src="https://gitlab.com/arep-dev/pyViewFactor/-/raw/da36d4a0b08308009d9e71876091492ecb97d476/img/Logo%20pVF%20512x512%20v3%20transparent%20crop.png" alt="pvf_logo" width="256px"/>
27
+ </div>
28
+
29
+
30
+ > `pyViewFactor` is a lightweight open-source Python library for exact view-factor computations on polygonal meshes.
31
+ > It provides robust tools for:
32
+ > - geometric visibility analysis,
33
+ > - obstruction detection,
34
+ > - accurate view factor computation.
35
+
36
+ *Full documentation available [here](https://arep-dev.gitlab.io/pyViewFactor/).*
37
+
38
+
39
+ <img src="https://gitlab.com/arep-dev/pyViewFactor/-/raw/3d40d1804eccbaefbc8b1736ff30d0d9f08141ad/img/FF_sceneUrbaine_cyl_RT.png" alt="Urban View Factor" width="800" />
40
+
41
+ [![Latest Release](https://gitlab.com/arep-dev/pyViewFactor/-/badges/release.svg)](https://gitlab.com/arep-dev/pyViewFactor/-/releases)
42
+ [![pipeline status](https://gitlab.com/arep-dev/pyViewFactor/badges/main/pipeline.svg)](https://gitlab.com/arep-dev/pyViewFactor/pipelines)
43
+ [![codecov](https://codecov.io/gl/arep-dev/pyViewFactor/graph/badge.svg?token=HPHU835UZ8)](https://codecov.io/gl/arep-dev/pyViewFactor)
44
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
45
+ [![Pypi Version](https://img.shields.io/pypi/v/pyviewfactor)](https://pypi.org/project/pyviewfactor/)
46
+ [![Pypi Downloads](https://img.shields.io/pypi/dm/pyviewfactor.svg?label=pypi%20downloads)](https://pypi.org/project/pyviewfactor/)
47
+
48
+
49
+
50
+ ## Features
51
+
52
+ * This library enables the computation of radiation view factors between planar polygons using an **accurate** double‐contour integration method described in
53
+ [(Mazumder and Ravishankar 2012)](https://www.academia.edu/download/77459051/Viewfactor_paper_IJHMT.pdf)
54
+ with insights from [(Schmid 2016)](https://hal.archives-ouvertes.fr/tel-01734545/).
55
+ * It uses the handy [`Pyvista`](https://docs.pyvista.org/) package to deal with geometry imports (`*.stl`, `*.vtk`, `*.obj`, ...),
56
+ geometry creations, and some other mesh functionalities under the hood.
57
+ * It enables:
58
+ - 🔺 View factor computation between planar polygons
59
+ - 👁️ Visibility checks based on face orientation
60
+ - 🚧 Obstruction detection using ray-triangle intersection
61
+ - ⚙️ Strict / non-strict modes for robustness control
62
+ - ⚡ Optimized full matrix computation with caching
63
+ - 📦 Built on `numpy`, `scipy`, `pyvista`, `numba`
64
+
65
+
66
+
67
+ ## Installation
68
+ `pyViewFactor` can be installed from [PyPi](https://pypi.org/project/pyviewfactor/)
69
+ using `pip` on Python >= 3.10:
70
+ ```shell
71
+ pip install pyviewfactor
72
+ ```
73
+ You can also visit [PyPi](https://pypi.org/project/pyviewfactor/) or
74
+ [Gitlab](https://gitlab.com/arep-dev/pyViewFactor) to download the sources.
75
+
76
+ Requirements:
77
+ ```
78
+ numpy==1.26.4
79
+ pyvista==0.45
80
+ scipy==1.11.4
81
+ numba==0.61.2
82
+ joblib==1.2.0
83
+ tqdm==4.65.0
84
+
85
+ ```
86
+ The code will probably work with lower versions of the required packages, however this has not been tested.
87
+
88
+ > [!NOTE]
89
+ > If you are alergic to `numba`, you may `pip install pyviewfactor==0.0.10` that works (and give up the times 3+ speed-up in view factor computation).
90
+
91
+
92
+ ## Quick Start
93
+
94
+ Suppose we want to compute the radiation view factor between a triangle
95
+ and a rectangle facing each other:
96
+
97
+ <img src="https://gitlab.com/arep-dev/pyViewFactor/-/raw/9dbd31d124eb898cc5d17913cfc1f010116e2245/img/mwe.png" alt="Triangle and rectangle configuration" width="260"/>
98
+
99
+ You are few lines of code away from your first view factor computation:
100
+
101
+ ```python
102
+ import pyvista as pv
103
+ import pyviewfactor as pvf
104
+
105
+ # Create a rectangle and a triangle facing each other
106
+ pointa1 = [0.0, 0.0, 0.0]
107
+ pointb1 = [1.0, 0.0, 0.0]
108
+ pointc1 = [0.0, 1.0, 0.0]
109
+ rectangle = pv.Rectangle([pointa1, pointb1, pointc1])
110
+
111
+ pointa2 = [0.0, 0.0, 1.0]
112
+ pointb2 = [0.0, 1.0, 1.0]
113
+ pointc2 = [1.0, 1.0, 1.0]
114
+ triangle = pv.Triangle([pointa2, pointb2, pointc2])
115
+
116
+ if pvf.get_visibility(rectangle, triangle)[0]:
117
+ F = pvf.compute_viewfactor(triangle, rectangle)
118
+ print("VF from rectangle to triangle :", F)
119
+ else:
120
+ print("Not facing each other")
121
+
122
+ pl = pv.Plotter()
123
+ pl.add_mesh(rectangle, color="lightblue", opacity=0.7)
124
+ pl.add_mesh(triangle, color="salmon", opacity=0.7)
125
+
126
+ # compute and glyph normals for mesh1
127
+ n1 = rectangle.compute_normals(cell_normals=True, point_normals=False)
128
+ arrows1 = n1.glyph(orient="Normals", factor=0.1)
129
+ pl.add_mesh(arrows1, color="blue")
130
+ # similarly for mesh2
131
+ n2 = triangle.compute_normals(cell_normals=True, point_normals=False)
132
+ arrows2 = n2.glyph(orient="Normals", factor=0.1)
133
+ pl.add_mesh(arrows2, color="darkred")
134
+
135
+ pl.show()
136
+ ```
137
+
138
+ You usually get your geometry from a different format?
139
+ (`*.dat`, `*.idf`, ...)
140
+
141
+ Check pyvista's documentation on [how to generate a PolyData facet from points](https://docs.pyvista.org/examples/00-load/create-poly.html).
142
+
143
+
144
+ ### Example 1 : View factors of an individual with a wall
145
+
146
+ For comfort computations, it may be useful to determine heat transfer between an
147
+ individual and a wall. We will use here PyVista's
148
+ [doorman example](https://docs.pyvista.org/api/examples/_autosummary/pyvista.examples.downloads.download_doorman.html?highlight=example+man#pyvista.examples.downloads.download_doorman)
149
+ as a basis for the human geometry.
150
+
151
+ <img src="https://gitlab.com/arep-dev/pyViewFactor/-/raw/9dbd31d124eb898cc5d17913cfc1f010116e2245/img/Fground.png" alt="View factors of the doorman's faces to the ground" width="380"/>
152
+
153
+ The following code and `.vtk` file of the doorman example are available in
154
+ the [./examples/](https://gitlab.com/arep-dev/pyViewFactor/-/tree/main/examples) folder.
155
+
156
+ ```python
157
+ from tqdm import tqdm
158
+ import numpy as np
159
+ import pyvista as pv
160
+ import pyviewfactor as pvf
161
+
162
+ def fc_Fwall(nom_vtk):
163
+ # This function is bit more generic than this specific use case,
164
+ # so it can be reused for other applications
165
+ mesh = pv.read(nom_vtk)
166
+
167
+ # find all types of walls : in this example only a ground
168
+ wall_types = list(np.unique(mesh["geom_id"]))
169
+ # remove the individual from the list (still named "cylinder"...)
170
+ wall_types.remove("doorman")
171
+ # where is the doorman in the list?
172
+ index_doorman = np.where(mesh["geom_id"] == "doorman")[0]
173
+ # prepare storage for the different walls in a dict
174
+ dict_F = {}
175
+ # loop over wall types
176
+ for type_wall in wall_types:
177
+ # prepare for storing doorman to wall view factor
178
+ F = np.zeros(mesh.n_cells)
179
+ # get the indices of this type of wall
180
+ indices = np.where(mesh["geom_id"] == type_wall)[0]
181
+ # loop over
182
+ for i in indices:
183
+ wall = mesh.extract_cells(i)
184
+ wall = pvf.fc_unstruc2poly(wall) # convert for normals
185
+ # ... for each facet of the individual
186
+ for idx in tqdm(index_doorman):
187
+ face = mesh.extract_cells(idx)
188
+ face = pvf.fc_unstruc2poly(face) # convert for normals
189
+ # check if faces can "see" each other
190
+ if pvf.get_visibility(wall, face):
191
+ # compute face2wall view factor
192
+ Ffp = pvf.compute_viewfactor(wall, face)
193
+ else:
194
+ Ffp = 0
195
+ F[idx] = Ffp
196
+ # store array F in e.g. dict_F["F_ceiling"]
197
+ dict_F["F_" + type_wall.replace("\r", "")] = F
198
+ return dict_F
199
+
200
+ # You can get the doorman geomtry it directly from here:
201
+ # https://gitlab.com/arep-dev/pyViewFactor/-/blob/main/examples/example_doorman_clean.vtk
202
+ # ... or get it from this repository's examples
203
+ file = "./src_data/example_doorman_clean.vtk"
204
+
205
+ # compute the VFs for the doorman to the different wall types in the scene
206
+ dict_F = fc_Fwall(file)
207
+
208
+ # re-read and store
209
+ mesh = pv.read(file)
210
+ # loop over what is in the dictionary of view factors
211
+ for elt in dict_F.keys():
212
+ mesh[elt.replace("\r", "")] = dict_F[elt] # name the field
213
+ mesh.save("./src_data/example_doorman_VFground.vtk") # store in the intial VTK
214
+
215
+ # have a look without paraview with fancy colors
216
+ mesh.plot(cmap="magma_r", lighting=False)
217
+ ```
218
+
219
+ More details and view factors abacuses can be found [here](https://lhypercube.arep.fr/en/confort/calcul-de-la-temperature-radiante/).
220
+
221
+
222
+ ### Example 2 : Urban Scene
223
+
224
+ For building simulation purposes, it may prove to be useful to compute the ground and sky view factors of a given wall, or the view factor of the wall to other walls in the built environment. In following example (available in the [`/examples/` folder](https://gitlab.com/arep-dev/pyViewFactor/-/tree/main/examples)), we compute the view factors of the environment of the purple wall depicted below.
225
+
226
+ <img src="https://gitlab.com/arep-dev/pyViewFactor/-/raw/9dbd31d124eb898cc5d17913cfc1f010116e2245/img/wall_view_factors.png" alt="View factors in built environment" width="430"/>
227
+
228
+ ```python
229
+
230
+ import numpy as np
231
+ import pyvista as pv
232
+ import pyviewfactor as pvf
233
+
234
+ # -------------------------
235
+ # Load geometry
236
+ # -------------------------
237
+ mesh = pv.read("./src_data/built_envmt.vtk")
238
+ meshpoly = pvf.fc_unstruc2poly(mesh)
239
+
240
+ # Identify groups
241
+ i_wall = np.where(mesh["wall_names"] == "wall")[0]
242
+ i_sky = np.where(mesh["wall_names"] == "sky")[0]
243
+ i_building1 = np.where(mesh["wall_names"] == "building1")[0]
244
+ i_building2 = np.where(mesh["wall_names"] == "building2")[0]
245
+
246
+ # Extract wall
247
+ wall = mesh.extract_cells(i_wall).extract_surface()
248
+
249
+ # Parameters
250
+ strict_visibility = False
251
+ strict_obstruction = False
252
+ rounding_decimal = 5
253
+
254
+ # -------------------------
255
+ # Wall → Sky
256
+ # -------------------------
257
+ Fsky = 0.0
258
+ print("> Computation F_wall>sky")
259
+
260
+ for patch in i_sky:
261
+ sky = mesh.extract_cells(patch).extract_surface()
262
+
263
+ if pvf.get_visibility(sky, wall,
264
+ strict=strict_visibility,
265
+ rounding_decimal=rounding_decimal)[0]:
266
+
267
+ if pvf.get_obstruction(sky, wall, meshpoly,
268
+ strict=strict_obstruction,
269
+ rounding_decimal=rounding_decimal)[0]:
270
+
271
+ Fsky += pvf.compute_viewfactor(sky, wall)
272
+
273
+ # -------------------------
274
+ # Wall → Building 1
275
+ # -------------------------
276
+ Fbuilding1 = 0.0
277
+ print("> Computation F_wall>building1")
278
+
279
+ for patch in i_building1:
280
+ bld = pvf.fc_unstruc2poly(mesh.extract_cells(patch))
281
+
282
+ if pvf.get_visibility(bld, wall,
283
+ strict=strict_visibility,
284
+ rounding_decimal=rounding_decimal)[0]:
285
+
286
+ if pvf.get_obstruction(bld, wall, meshpoly,
287
+ strict=strict_obstruction,
288
+ rounding_decimal=rounding_decimal)[0]:
289
+
290
+ Fbuilding1 += pvf.compute_viewfactor(bld, wall)
291
+
292
+ # -------------------------
293
+ # Wall → Building 2
294
+ # -------------------------
295
+ Fbuilding2 = 0.0
296
+ print("> Computation F_wall>building2")
297
+
298
+ for patch in i_building2:
299
+ bld = pvf.fc_unstruc2poly(mesh.extract_cells(patch))
300
+
301
+ if pvf.get_visibility(bld, wall,
302
+ strict=strict_visibility,
303
+ rounding_decimal=rounding_decimal)[0]:
304
+
305
+ if pvf.get_obstruction(bld, wall, meshpoly,
306
+ strict=strict_obstruction,
307
+ rounding_decimal=rounding_decimal)[0]:
308
+
309
+ Fbuilding2 += pvf.compute_viewfactor(bld, wall)
310
+
311
+ # -------------------------
312
+ # Ground by complementarity
313
+ # -------------------------
314
+ Fground = 1.0 - Fsky - Fbuilding1 - Fbuilding2
315
+
316
+ # -------------------------
317
+ # Results
318
+ # -------------------------
319
+ print("\n--- View Factors ---")
320
+ print(f"Sky : {Fsky:.4f}")
321
+ print(f"Building 1 : {Fbuilding1:.4f}")
322
+ print(f"Building 2 : {Fbuilding2:.4f}")
323
+ print(f"Ground : {Fground:.4f}")
324
+ ```
325
+
326
+ The code yields following view factors :
327
+ ```math
328
+ F_{\text{sky}} = 0.3173 \\
329
+ F_{\text{ground}} = 0.4009 \\
330
+ F_{\text{building1}} = 0.2506 \\
331
+ F_{\text{building2}} = 0.0312 \\
332
+ ```
333
+
334
+ ## Documentation
335
+
336
+ For detailed explanations and advanced usage, see:
337
+
338
+ https://arep-dev.gitlab.io/pyViewFactor/pyviewfactor.html
339
+
340
+ The documentation includes:
341
+ * visibility and obstruction semantics,
342
+ * strict vs non-strict modes,
343
+ * geometry preprocessing utilities,
344
+ * numerical robustness guidelines,
345
+ * extended examples (that can also be found in the `examples/` folder).
346
+
347
+
348
+ ## Citation & Acknowledgments
349
+ * Main contributors:
350
+ * Mateusz BOGDAN,
351
+ * Edouard WALTHER.
352
+ * Acknowledgment: The authors would like to acknowledge *M. Alecian* for his initial work on the quadrature
353
+ code and *M. Chapon* for her contribution to the code validation.
354
+
355
+ There is even a [conference paper](https://www.researchgate.net/publication/360835982_Calcul_des_facteurs_de_forme_entre_polygones_-Application_a_la_thermique_urbaine_et_aux_etudes_de_confort), showing analytical validations.
356
+
357
+ So if you use `pyViewFactor` in your work, please cite:
358
+ > [!IMPORTANT] Citation:
359
+ > Mateusz BOGDAN, Edouard WALTHER, Marc ALECIAN and Mina CHAPON. *Calcul des facteurs de forme entre polygones - Application à la thermique urbaine et aux études de confort*. IBPSA France 2022, Châlons-en-Champagne.
360
+
361
+ Bibtex entry:
362
+ ``` latex
363
+ @inproceedings{pyViewFactor22bogdan,
364
+ authors = "Mateusz BOGDAN and Edouard WALTHER and Marc ALECIAN and Mina CHAPON",
365
+ title = "Calcul des facteurs de forme entre polygones - Application à la thermique urbaine et aux études de confort",
366
+ year = "2022",
367
+ organization = "IBPSA France",
368
+ venue = "Châlons-en-Champagne, France"
369
+ note = "IBPSA France 2022",
370
+ }
371
+ ```
372
+
373
+ ## License
374
+ MIT License - Copyright (c) AREP 2025