pyviewfactor 0.1.12__tar.gz → 0.1.13__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 (24) hide show
  1. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/PKG-INFO +1 -1
  2. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor/_version.py +1 -1
  3. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor/pyviewfactor.py +50 -61
  4. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor.egg-info/PKG-INFO +1 -1
  5. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/LICENSE.txt +0 -0
  6. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/README.md +0 -0
  7. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor/11pyviewfactor.py +0 -0
  8. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor/OLD.py +0 -0
  9. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor/__init__.py +0 -0
  10. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor/pyviewfactor_906.py +0 -0
  11. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor/pyviewfactor_BKP12-06.py +0 -0
  12. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor/pyviewfactor_v1.py +0 -0
  13. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor/pyviewfactor_vis_obs_OK.py +0 -0
  14. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor/pyviewfactorv2.py +0 -0
  15. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor.egg-info/SOURCES.txt +0 -0
  16. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor.egg-info/dependency_links.txt +0 -0
  17. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor.egg-info/requires.txt +0 -0
  18. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/pyviewfactor.egg-info/top_level.txt +0 -0
  19. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/setup.cfg +0 -0
  20. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/setup.py +0 -0
  21. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/test/__init__.py +0 -0
  22. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/test/test_utils.py +0 -0
  23. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/test/test_view_factor.py +0 -0
  24. {pyviewfactor-0.1.12 → pyviewfactor-0.1.13}/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.12
3
+ Version: 0.1.13
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, 12
2
+ version_info = 0, 1, 13
3
3
 
4
4
  # Nice string for the version
5
5
  __version__ = ".".join(map(str, version_info))
@@ -59,48 +59,13 @@ class ProcessedGeometry:
59
59
  class FaceMeshPreprocessor:
60
60
  def __init__(self, mesh: pv.PolyData):
61
61
  if not mesh.is_all_triangles:
62
- mesh = mesh.triangulate
63
- self.N = mesh.n_cells
62
+ mesh = mesh.triangulate()
63
+ self.points = mesh.points.astype(np.float64)
64
64
  # cells array is [n, i0, i1, i2, n, ...]
65
65
  cells = mesh.faces.reshape(-1,4)[:,1:]
66
66
  self.faces = cells # shape (n_cells,3)
67
67
  self.triangles = np.array([self.points[c] for c in cells], dtype=np.float64)
68
- self.points = []
69
- self.normals = np.zeros((self.N, 3), dtype=np.float64)
70
- self.centroids = np.zeros((self.N, 3), dtype=np.float64)
71
- self.areas = np.zeros(self.N, dtype=np.float64)
72
- for i in range(self.N):
73
- raw = mesh.extract_cells(i)
74
- face = fc_unstruc2poly(raw)
75
- faces_i = face.faces
76
- n_i = int(faces_i[0])
77
- idxs = faces_i[1:1 + n_i]
78
- pts = np.round(face.points[idxs], rounding_decimal)
79
-
80
- self.points.append(pts)
81
- self.centroids[i] = polygon_centroid(pts)
82
-
83
- v1 = pts[1] - pts[0]
84
- v2 = pts[2] - pts[0]
85
- norm = np.cross(v1, v2)
86
- self.normals[i] = norm / np.linalg.norm(norm)
87
68
 
88
- self.areas[i] = polygon_area(np.round(face.points, rounding_decimal))
89
-
90
-
91
-
92
- def get_face(self, i):
93
- return self.points[i]
94
-
95
- def get_normal(self, i):
96
- return self.normals[i]
97
-
98
- def get_centroid(self, i):
99
- return self.centroids[i]
100
-
101
- def get_area(self, i):
102
- return self.areas[i]
103
-
104
69
  def aabb_filter(self, aabb_min, aabb_max):
105
70
  kept = []
106
71
  for tri in self.triangles: # tri.shape == (3,3)
@@ -121,7 +86,6 @@ class FaceMeshPreprocessor:
121
86
  return np.array(out, dtype=np.float64)
122
87
 
123
88
 
124
-
125
89
  def face_to_array(face):
126
90
  """Convert a single-cell PolyData face to an (n,3) ndarray."""
127
91
  return face.get_cell(0).points.astype(np.float64)
@@ -363,31 +327,32 @@ def get_obstruction_from_cache(i, j, cache, obstacle_mesh, strict=False, print_w
363
327
 
364
328
  # Optionally, use a similar cache for the obstacle mesh, or extract triangles as needed.
365
329
  # For now, fallback to regular PolyData interface:
366
- if isinstance(obstacle_mesh, FaceMeshPreprocessor):
367
- triangles = [obstacle_mesh.get_face(t) for t in range(obstacle_mesh.N)]
368
- else:
369
- triangles = [obstacle_mesh.get_cell(t).points for t in range(obstacle_mesh.n_cells)]
330
+ # if isinstance(obstacle_mesh, FaceMeshPreprocessor):
331
+ # triangles = [obstacle_mesh.get_face(t) for t in range(obstacle_mesh.N)]
332
+ # else:
333
+ # triangles = [obstacle_mesh.get_cell(t).points for t in range(obstacle_mesh.n_cells)]
370
334
 
371
335
  # Filter triangles by AABB
372
336
  all_pts = np.vstack((pts1, pts2))
373
337
  aabb_min = np.min(all_pts, axis=0)
374
338
  aabb_max = np.max(all_pts, axis=0)
375
- cand_tris = [tri for tri in triangles if tri_overlaps_aabb(tri, aabb_min, aabb_max)]
339
+ cand_tris = obstacle_mesh.aabb_filter(aabb_min, aabb_max)
340
+ cand_tris = obstacle_mesh.exclude_exact_match(pts1, pts2, cand_tris)
376
341
 
377
342
  # Exclude any triangles exactly matching face i or j
378
- set1 = {tuple(np.round(p, 8)) for p in pts1}
379
- set2 = {tuple(np.round(p, 8)) for p in pts2}
380
- def is_exact_match(tri, sets):
381
- s = {tuple(np.round(p, 8)) for p in tri}
382
- return s == sets[0] or s == sets[1]
383
- cand_tris = [tri for tri in cand_tris if not is_exact_match(tri, [set1, set2])]
384
-
385
- if not cand_tris:
343
+ # set1 = {tuple(np.round(p, 8)) for p in pts1}
344
+ # set2 = {tuple(np.round(p, 8)) for p in pts2}
345
+ # def is_exact_match(tri, sets):
346
+ # s = {tuple(np.round(p, 8)) for p in tri}
347
+ # return s == sets[0] or s == sets[1]
348
+ # cand_tris = [tri for tri in cand_tris if not is_exact_match(tri, [set1, set2])]
349
+
350
+ if cand_tris.size == 0:
386
351
  return True, "fully visible"
387
352
 
388
353
  # Strict/non-strict logic:
389
354
  if not strict:
390
- blocked = is_ray_blocked(c1, c2, np.array(cand_tris), eps=eps)
355
+ blocked = is_ray_blocked(c1, c2, cand_tris, eps=eps)
391
356
  if blocked:
392
357
  return False, ""
393
358
  else:
@@ -395,7 +360,7 @@ def get_obstruction_from_cache(i, j, cache, obstacle_mesh, strict=False, print_w
395
360
  else:
396
361
  for p1 in pts1:
397
362
  for p2 in pts2:
398
- if is_ray_blocked(p1, p2, np.array(cand_tris), eps=eps):
363
+ if is_ray_blocked(p1, p2, cand_tris, eps=eps):
399
364
  warning = "[PVF-Warning-1] Cells are partially obstructed (strict)."
400
365
  if print_warning:
401
366
  return False, warning
@@ -1111,6 +1076,29 @@ def _compute_pair(i, j,
1111
1076
  return i, j, F_ij, F_ji
1112
1077
 
1113
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
+
1114
1102
  def compute_viewfactor_matrix(
1115
1103
  mesh,
1116
1104
  obstacles=None,
@@ -1120,7 +1108,7 @@ def compute_viewfactor_matrix(
1120
1108
  strict_visibility=False,
1121
1109
  strict_obstruction=False,
1122
1110
  rounding_decimal=8,
1123
- epsilon=1e-6,
1111
+ epsilon=1e-3,
1124
1112
  verbose=False
1125
1113
  ):
1126
1114
  """
@@ -1163,7 +1151,7 @@ def compute_viewfactor_matrix(
1163
1151
  obstacles = []
1164
1152
  elif not isinstance(obstacles, (list, tuple)):
1165
1153
  obstacles = [obstacles]
1166
- obstacle_preprocs = [FaceMeshPreprocessor(obs) for obs in obstacles]
1154
+ obs_pre = [FaceMeshPreprocessor(obs) for obs in obstacles]
1167
1155
  # Precompute vertex sets for "touching" logic
1168
1156
  vertex_sets = [frozenset(tuple(np.round(vert, rounding_decimal)) for vert in pg.get_face(i)) for i in range(N)]
1169
1157
 
@@ -1191,12 +1179,12 @@ def compute_viewfactor_matrix(
1191
1179
  if not vis:
1192
1180
  continue
1193
1181
  # (B) Optional obstruction test
1194
- if not skip_obstruction and obstacle_preprocs:
1182
+ if not skip_obstruction and obs_pre:
1195
1183
  blocked = False
1196
- for obs in obstacle_preprocs:
1184
+ for obs in obs_pre:
1197
1185
  # You can use your get_obstruction_general or similar here (adapt as needed)
1198
1186
  # if not get_obstruction(pg.get_face(i), pg.get_face(j), obs, strict=strict_obstruction)[0]:
1199
- if not get_obstruction_from_cache(i, j, pg, obs, strict=False, print_warning=False, eps=1e-6):
1187
+ if not get_obstruction_from_cache(i, j, pg, obs, strict=False, print_warning=False, eps=1e-6)[0]:
1200
1188
  blocked = True
1201
1189
  break
1202
1190
  if blocked:
@@ -1212,6 +1200,7 @@ def compute_viewfactor_matrix(
1212
1200
  c2 = pg.get_centroid(j)
1213
1201
  direction = c2 - c1
1214
1202
  norm = np.linalg.norm(direction)
1203
+ epsilon = adaptive_epsilon(pts1, pts2, factor=epsilon)
1215
1204
  if norm > 0.0:
1216
1205
  direction /= norm
1217
1206
  pts2_adj = pts2_adj + epsilon * direction
@@ -1242,11 +1231,11 @@ def compute_viewfactor_matrix(
1242
1231
  valid_mask[k] = False
1243
1232
  continue
1244
1233
  # (B) Optional obstruction test
1245
- if not skip_obstruction and obstacles:
1234
+ if not skip_obstruction and obs_pre:
1246
1235
  blocked = False
1247
- for obs in obstacle_preprocs:
1236
+ for obs in obs_pre:
1248
1237
  # if not get_obstruction(pg.get_face(i), pg.get_face(j), obs, strict=strict_obstruction)[0]:
1249
- if not get_obstruction_from_cache(i, j, pg, obs, strict=False, print_warning=False, eps=1e-6):
1238
+ if not get_obstruction_from_cache(i, j, pg, obs, strict=False, print_warning=False, eps=1e-6)[0]:
1250
1239
  blocked = True
1251
1240
  break
1252
1241
  if blocked:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyviewfactor
3
- Version: 0.1.12
3
+ Version: 0.1.13
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
File without changes
File without changes
File without changes
File without changes