pyviewfactor 0.1.13__tar.gz → 0.1.14__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 (25) hide show
  1. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/PKG-INFO +1 -1
  2. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor/_version.py +1 -1
  3. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor/pyviewfactor.py +25 -187
  4. pyviewfactor-0.1.14/pyviewfactor/pyviewfactor_integration.py +1242 -0
  5. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor.egg-info/PKG-INFO +1 -1
  6. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor.egg-info/SOURCES.txt +1 -0
  7. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/LICENSE.txt +0 -0
  8. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/README.md +0 -0
  9. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor/11pyviewfactor.py +0 -0
  10. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor/OLD.py +0 -0
  11. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor/__init__.py +0 -0
  12. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor/pyviewfactor_906.py +0 -0
  13. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor/pyviewfactor_BKP12-06.py +0 -0
  14. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor/pyviewfactor_v1.py +0 -0
  15. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor/pyviewfactor_vis_obs_OK.py +0 -0
  16. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor/pyviewfactorv2.py +0 -0
  17. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor.egg-info/dependency_links.txt +0 -0
  18. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor.egg-info/requires.txt +0 -0
  19. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/pyviewfactor.egg-info/top_level.txt +0 -0
  20. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/setup.cfg +0 -0
  21. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/setup.py +0 -0
  22. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/test/__init__.py +0 -0
  23. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/test/test_utils.py +0 -0
  24. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/test/test_view_factor.py +0 -0
  25. {pyviewfactor-0.1.13 → pyviewfactor-0.1.14}/test/test_visibility_obstruction.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyviewfactor
3
- Version: 0.1.13
3
+ Version: 0.1.14
4
4
  Summary: A python library to calculate numerically exact radiation view factors between planar faces.
5
5
  Home-page: https://gitlab.com/arep-dev/pyViewFactor/
6
6
  Author: Mateusz BOGDAN, Edouard WALTHER, Marc ALECIAN, Mina CHAPON
@@ -1,5 +1,5 @@
1
1
  """Version info for pyViewFactor"""
2
- version_info = 0, 1, 13
2
+ version_info = 0, 1, 14
3
3
 
4
4
  # Nice string for the version
5
5
  __version__ = ".".join(map(str, version_info))
@@ -24,6 +24,7 @@ class ProcessedGeometry:
24
24
  self.normals = np.zeros((self.N, 3), dtype=np.float64)
25
25
  self.centroids = np.zeros((self.N, 3), dtype=np.float64)
26
26
  self.areas = np.zeros(self.N, dtype=np.float64)
27
+ self.sizes = np.zeros(self.N, dtype=np.float64)
27
28
 
28
29
  for i in range(self.N):
29
30
  raw = mesh.extract_cells(i)
@@ -42,6 +43,9 @@ class ProcessedGeometry:
42
43
  self.normals[i] = norm / np.linalg.norm(norm)
43
44
 
44
45
  self.areas[i] = polygon_area(np.round(face.points, rounding_decimal))
46
+ edges = np.roll(pts, -1, axis=0) - pts
47
+ edge_lengths = np.linalg.norm(edges, axis=1)
48
+ self.sizes[i] = np.mean(edge_lengths)
45
49
 
46
50
  def get_face(self, i):
47
51
  return self.points[i]
@@ -55,6 +59,9 @@ class ProcessedGeometry:
55
59
  def get_area(self, i):
56
60
  return self.areas[i]
57
61
 
62
+ def get_size(self, i):
63
+ return self.sizes[i]
64
+
58
65
 
59
66
  class FaceMeshPreprocessor:
60
67
  def __init__(self, mesh: pv.PolyData):
@@ -147,8 +154,6 @@ def polygon_centroid(pts: np.ndarray) -> np.ndarray:
147
154
  return p0 + centroid_2D[0] * u + centroid_2D[1] * w
148
155
 
149
156
 
150
-
151
-
152
157
  @njit
153
158
  def face_normal_numpy(pts):
154
159
  """
@@ -205,18 +210,6 @@ def tri_overlaps_aabb(tri_pts, aabb_min, aabb_max):
205
210
  )
206
211
 
207
212
 
208
- def face_vertex_set(face_poly, decimals=8):
209
- """
210
- Return a set of sorted rounded (x, y, z) vertex tuples from a face.
211
- Sorting ensures symmetry regardless of vertex order.
212
- """
213
- raw_pts = face_poly.get_cell(0).points.astype(np.float64)
214
- raw_pts = np.round(raw_pts, decimals)
215
- vert_list = [tuple(p) for p in raw_pts]
216
- vert_set = frozenset(sorted(vert_list))
217
- return vert_set
218
-
219
-
220
213
  @njit
221
214
  def ray_intersects_triangle(orig, dest, v0, v1, v2, eps=1e-6):
222
215
  # 0) If origin or dest coincides with a vertex, skip this triangle
@@ -408,39 +401,6 @@ def fc_unstruc2poly(mesh_unstruc):
408
401
  return pv.PolyData(points, faces)
409
402
 
410
403
 
411
- def trunc(values, decs=0):
412
- """
413
- Truncate numeric values to a fixed number of decimals.
414
-
415
- Parameters
416
- ----------
417
- values : float or ndarray
418
- Float or array of floats to truncate.
419
- decs : int, optional
420
- Number of decimals to keep (default=0).
421
-
422
- Returns
423
- -------
424
- float or ndarray
425
- Truncated values.
426
-
427
- Examples
428
- --------
429
- >>> trunc(1.234567, 2)
430
- 1.23
431
- >>> import pyvista as pv
432
- >>> tri = pv.Triangle([[0.111111, 1.111111, 1.111111],
433
- ... [1.222222, 1.222222, 1.222222],
434
- ... [1.333333, 0.333333, 1.333333]])
435
- >>> trunc(tri.points, 2)
436
- array([[0.11, 1.11, 1.11],
437
- [1.22, 1.22, 1.22],
438
- [1.33, 0.33, 1.33]])
439
- """
440
- factor = 10 ** decs
441
- return np.trunc(values * factor) / factor
442
-
443
-
444
404
  # #########################
445
405
  # Visibility / Obstrucitons
446
406
  # #########################
@@ -587,6 +547,8 @@ def get_visibility_from_cache(i, j, cache, strict=False, print_warning=False, ro
587
547
  return True, warning_str
588
548
 
589
549
  return True, ""
550
+
551
+
590
552
  # ########################
591
553
  # View Factor Computations
592
554
  # ########################
@@ -911,8 +873,8 @@ def compute_viewfactor(cell1, cell2, *, epsilon=1e-6, rounding_decimal=8):
911
873
  pts2 = face_to_array(cell2)
912
874
 
913
875
  # 2) Small shift along normal‐bisector if they share vertices
914
- set1 = {tuple(p) for p in pts1}
915
- set2 = {tuple(p) for p in pts2}
876
+ set1 = {tuple(np.round(p, rounding_decimal)) for p in pts1}
877
+ set2 = {tuple(np.round(p, rounding_decimal)) for p in pts2}
916
878
  use_dblquad = bool(set1 & set2)
917
879
  if use_dblquad:
918
880
  c1 = polygon_centroid(pts1)
@@ -975,134 +937,10 @@ def batch_compute_viewfactors(pts1_arr, nverts1, pts2_arr, nverts2, const_arr, v
975
937
  # View Factor Full Matrix Computations
976
938
  # ####################################
977
939
 
978
- # Helper function to compute VF matrix for a complete mesh
979
- def _is_blocked(f_i, f_j, obstacles, obstruction_kwargs, skip_obstruction):
980
- """
981
- Check whether any obstacle mesh blocks the view between two facets.
982
-
983
- Parameters
984
- ----------
985
- f_i, f_j : pyvista.PolyData
986
- Receiving and emitting facets, respectively.
987
- obstacles : list of pyvista.PolyData
988
- One or more occluder meshes to test.
989
- obstruction_kwargs : dict
990
- Keyword args forwarded to `get_obstruction(...)`.
991
- skip_obstruction : bool
992
- If True, skip all obstruction tests (always returns False).
993
-
994
- Returns
995
- -------
996
- bool
997
- True if any obstacle reports a block (i.e., faces do *not* see each other),
998
- False otherwise.
999
- """
1000
- if skip_obstruction or not obstacles:
1001
- return False
1002
- for obs in obstacles:
1003
- vis_obs, _ = get_obstruction(f_i, f_j, obs, **(obstruction_kwargs or {}))
1004
- if not vis_obs:
1005
- return True
1006
- return False
1007
-
1008
-
1009
- def _compute_pair(i, j,
1010
- faces, areas,
1011
- obstacles,
1012
- skip_visibility, skip_obstruction,
1013
- visibility_kwargs, obstruction_kwargs,
1014
- epsilon, rounding_decimal,
1015
- use_reciprocity):
1016
- """
1017
- Compute the view‐factor pair for two facets in a mesh.
1018
-
1019
- Applies optional visibility and obstruction culling, then computes
1020
- F[i,j] (and F[j,i] via reciprocity or explicit integration).
1021
-
1022
- Parameters
1023
- ----------
1024
- i, j : int
1025
- Indices of the two facets in the `faces` list.
1026
- faces : list of pyvista.PolyData
1027
- All single‐cell facets extracted from the mesh.
1028
- areas : list of float
1029
- Precomputed facet areas, matching `faces`.
1030
- obstacles : list of pyvista.PolyData
1031
- Occluder meshes.
1032
- skip_visibility : bool
1033
- If False, runs `get_visibility` and sets F=0 on fail.
1034
- skip_obstruction : bool
1035
- If False, runs `_is_blocked` and sets F=0 on fail.
1036
- visibility_kwargs : dict
1037
- Forwarded to `get_visibility`.
1038
- obstruction_kwargs : dict
1039
- Forwarded to `get_obstruction`.
1040
- epsilon : float
1041
- Small shift magnitude for shared‐vertex cases.
1042
- rounding_decimal : int
1043
- Decimal‐rounding for vertex coords.
1044
- use_reciprocity : bool
1045
- If True, uses the relation F[j,i] = (A_i/A_j)*F[i,j]
1046
- otherwise computes both directions.
1047
-
1048
- Returns
1049
- -------
1050
- tuple of (i, j, F_ij, F_ji)
1051
- Indices and computed view factors. If culled by visibility or
1052
- obstruction, returns zeros for both F_ij and F_ji.
1053
- """
1054
- f_i, f_j = faces[i], faces[j]
1055
-
1056
- # 1) Visibility
1057
- if not skip_visibility:
1058
- vis, _ = get_visibility(f_i, f_j, **visibility_kwargs)
1059
- if not vis:
1060
- return i, j, 0.0, 0.0
1061
-
1062
- # 2) Obstruction
1063
- if _is_blocked(f_i, f_j, obstacles, obstruction_kwargs, skip_obstruction):
1064
- return i, j, 0.0, 0.0
1065
-
1066
- # 3) View-factor
1067
- F_ij = compute_viewfactor(f_i, f_j,
1068
- epsilon=epsilon,
1069
- rounding_decimal=rounding_decimal)
1070
- if use_reciprocity:
1071
- F_ji = F_ij * (areas[j] / areas[i])
1072
- else:
1073
- F_ji = compute_viewfactor(f_j, f_i,
1074
- epsilon=epsilon,
1075
- rounding_decimal=rounding_decimal)
1076
- return i, j, F_ij, F_ji
1077
-
1078
-
1079
- @njit
1080
- def adaptive_epsilon(pts1, pts2, factor=1e-6):
1081
- """
1082
- Compute an adaptive epsilon proportional to the smaller local cell dimension.
1083
- """
1084
- # Edge lengths for face 1
1085
- n1 = pts1.shape[0]
1086
- minlen1 = np.linalg.norm(pts1[0] - pts1[-1])
1087
- for i in range(n1 - 1):
1088
- l = np.linalg.norm(pts1[i+1] - pts1[i])
1089
- if l < minlen1:
1090
- minlen1 = l
1091
- # Edge lengths for face 2
1092
- n2 = pts2.shape[0]
1093
- minlen2 = np.linalg.norm(pts2[0] - pts2[-1])
1094
- for i in range(n2 - 1):
1095
- l = np.linalg.norm(pts2[i+1] - pts2[i])
1096
- if l < minlen2:
1097
- minlen2 = l
1098
- eps = factor * min(minlen1, minlen2)
1099
- return eps
1100
-
1101
-
1102
940
  def compute_viewfactor_matrix(
1103
941
  mesh,
1104
942
  obstacles=None,
1105
- use_reciprocity=True,
943
+ # use_reciprocity=True,
1106
944
  skip_visibility=False,
1107
945
  skip_obstruction=False,
1108
946
  strict_visibility=False,
@@ -1195,20 +1033,20 @@ def compute_viewfactor_matrix(
1195
1033
  set1 = vertex_sets[i]
1196
1034
  set2 = vertex_sets[j]
1197
1035
  pts2_adj = pts2.copy()
1198
- if set1 & set2:
1199
- c1 = pg.get_centroid(i)
1200
- c2 = pg.get_centroid(j)
1201
- direction = c2 - c1
1202
- norm = np.linalg.norm(direction)
1203
- epsilon = adaptive_epsilon(pts1, pts2, factor=epsilon)
1204
- if norm > 0.0:
1205
- direction /= norm
1206
- pts2_adj = pts2_adj + epsilon * direction
1036
+ # if set1 & set2:
1037
+ c1 = pg.get_centroid(i)
1038
+ c2 = pg.get_centroid(j)
1039
+ direction = c2 - c1
1040
+ norm = np.linalg.norm(direction)
1041
+ eps_ij = epsilon * 0.5 * (pg.get_size(i) + pg.get_size(j))
1042
+ if norm > 0.0:
1043
+ direction /= norm
1044
+ pts2_adj = pts2_adj + eps_ij * direction
1207
1045
  constante = 4.0 * np.pi * pg.get_area(j)
1208
1046
  vf = _compute_viewfactor_dblquad(pts1, pts2_adj, constante)
1209
1047
  F[i, j] = vf
1210
- if use_reciprocity:
1211
- F[j, i] = vf * (pg.get_area(j) / pg.get_area(i))
1048
+ # if use_reciprocity:
1049
+ F[j, i] = vf * (pg.get_area(j) / pg.get_area(i))
1212
1050
 
1213
1051
  # DISCONNECTED: Use batch Gauss-Legendre for speed
1214
1052
  if verbose:
@@ -1285,8 +1123,8 @@ def compute_viewfactor_matrix(
1285
1123
  i, j = disconnected_pairs[k]
1286
1124
  fij = vf_valid[idx]
1287
1125
  F[i, j] = fij
1288
- if use_reciprocity:
1289
- F[j, i] = fij * (pg.get_area(j) / pg.get_area(i))
1126
+ # if use_reciprocity:
1127
+ F[j, i] = fij * (pg.get_area(j) / pg.get_area(i))
1290
1128
 
1291
1129
  return F
1292
1130