Skip to main content

A python library to calculate numerically exact radiation view factors between planar faces.

Project description

PyViewFactor

Latest Release License: MIT Pypi Version

A python library to compute exact view factors between planar faces.

This code computes the radiation view factor between polygons using the double contour integral method. It uses the handy Pyvista package to deal with geometrical aspects of such problems.

Minimum working example : facet to face view factor computation

Suppose we want to compute the radiation view factor between a triangle and a rectangle.

Triangle and rectangle configuration

You are now 18 lines of code away from your first view factor computation:

pointa = [1, 0, 0] # first define a rectangle...
pointb = [1, 1, 0]
pointc = [0, 1, 0]
pointd = [0, 0, 0]
rectangle = pv.Rectangle([pointa, pointb, pointc, pointd])

pointa = [1, 0, 1] # ... then a triangle
pointb = [1, 1, 1]
pointc = [0, 1, 1]
liste_pts=[pointa, pointb, pointc]
liste_pts.reverse() # let'us put the normal the other way around (facing the rectangle)
triangle = pv.Triangle(liste_pts) # ... done with geometry.

# preliminary check for visibility
if get_visibility(rectangle , triangle):
    F=compute_viewfactor(rectangle, triangle)
    print("View factor from triangle to rectangle = ", F)
else:
    print("Not facing each other")

Example with a closed geometry and the VTK file format

We will now compute the view factors within a more complex geometry: a closed sphere (clipped in half below), with inwards facing normals, so the faces can "see" each other. Note that the face-to-face visibility is unobstructed (for obstructed geometries, see next section).

The field of view factors from one facet to all others will be computed and stored in a VTK file, which you can explore with the open source Paraview software. Sphere

Following snippet can be reused as a kickstart for your own purposes:

import pyvista as pv
import numpy as np
from pyviewfactor import  compute_viewfactor, fc_unstruc2poly # viewfactor + a useful conversion function
from tqdm import tqdm # for a fancy progress bar

# create a raw sphere with pyvista
sphere=pv.Sphere(radius=50, center=(0, 0, 0), direction=(0, 0, 1),
                 theta_resolution=9, phi_resolution=9)
# and put the normals inwards please
sphere.flip_normals()

# let us chose a cell to compute view factors from
chosen_face=sphere.extract_cells(10)
# convert the face from UnstructuredGrid to PolyData
chosen_face=fc_unstruc2poly(chosen_face)
# "one array to contain them all" -> the results will be stored there
F=np.zeros(sphere.n_cells) 

# now let us compute the view factor to all other faces
# (with a fancy progress bar, iterating over the mesh's faces)
for i in tqdm(range(sphere.n_cells), total=sphere.n_cells):
    face=sphere.extract_cells(i) # other facet
    face=fc_unstruc2poly(face) # convert to PolyData
    F[i]=compute_viewfactor(face, chosen_face) # compute VF

print("Complementarity check: \n (e.g. is \sum_{i=0}^n F_i =? 1)", np.sum(F))

# put the scalar values in the geometry
sphere.cell_data["F"]=F
sphere.save("./sphere.vtk") # ... and save.

The results look as per following images showing the view factor from the chosen cell to all others.

VF to other faces inside the sphere Clipped result

Understanding the obstruction check function

In real life problems, obstacles may well hinder the radiation heat transfer between surfaces. We make use here of pyvista's raytrace function to perform obstruction tests, as per following example, much inspired from pyvista's online documentation.

Obstruction check between rectangles

The code snippet below shows how the ray tracing function works and allows to understand its usage in the pyviewfactor get_visibility_raytrace function.

# let us first create two rectangles
pointa = [1, 0, 0]
pointb = [1, 1, 0]
pointc = [0, 1, 0]
pointd = [0, 0, 0]
rectangle_down = pv.Rectangle([pointa, pointb, pointc, pointd])
pointa = [1, 0, 1]
pointb = [1, 1, 1]
pointc = [0, 1, 1]
pointd = [0, 0, 1]
rectangle_up = pv.Rectangle([pointa, pointb, pointc, pointd])

# a circle will be the obstruction
z_translation,r=0.5,2
obstacle= pv.Circle(radius=r,resolution=10)
# we translate the obstruction right between both rectangles
obstacle.translate([0,0,z_translation],inplace=True)
# Define line segment
start = rectangle_down.cell_centers().points[0]
stop = rectangle_up.cell_centers().points[0]
# Perform ray trace
points, ind = obstacle.ray_trace(start, stop)

# Create geometry to represent ray trace
ray = pv.Line(start, stop)
intersection = pv.PolyData(points)

# Render the result
p = pv.Plotter(notebook=True)
p.add_mesh(obstacle, show_edges=True, opacity=0.5, color="red", lighting=False, label="obstacle")
p.add_mesh(rectangle_up, color="blue", line_width=5, opacity=0.5, label="rect up")
p.add_mesh(rectangle_down, color="yellow", line_width=5,opacity=0.5, label="rect down")
p.add_mesh(ray, color="green", line_width=5, label="ray trace")

# if any intersection
if intersection.n_cells>0:
    p.add_mesh(intersection, color="green", point_size=25, label="Intersection Points")
p.add_legend()
p.show(cpos="yz")

#now a call to the obstruction check function
print (get_visibility_raytrace(rectangle_up, rectangle_down, obstacle))

More complex scenes can then be treated with the function get_visibility_raytrace. Obstruction within an enclosure

Installation

pyViewFactor can be installed from PyPi using pip on Python >= 3.7:

pip install pyviewfactor

You can also visit PyPi or Gitlab to download the source.

Requirements:

numpy==1.17.4
pandas==1.4.2
pyvista==0.35.2
scipy==1.8.1

The code will probably work with lower versions of the required packages, however this has not been tested.

Authors and acknowledgment

Mateusz BOGDAN, Edouard WALTHER, Marc ALECIAN, Mina CHAPON

Citation

There is even a conference paper, showing analytical validations.

Bibtex entry:

@inproceedings{pyViewFactor22bogdan,
  authors      = "Mateusz BOGDAN and Edouard WALTHER and Marc ALECIAN and Mina CHAPON",
  title        = "Calcul des facteurs de forme entre polygones - Application à la thermique urbaine et aux études de confort",
  year         = "2022",
  organization = "IBPSA France",
  venue        = "Châlons-en-Champagne, France"
  note         = "IBPSA France 2022",
}

License

MIT License - Copyright (c) AREP 2022

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyviewfactor-0.0.6.tar.gz (7.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page