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

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 using a closed geometry and the VTK file format

Now with a more complex, closed geometry: a sphere (clipped in half below), with inwards facing normals, so the faces can "see" each other. 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
from tqdm import tqdm # for a fancy progress bar

def fc_unstruc2poly(mesh_unstruc):
    """
    A function to convert unstructuredgrid to polydata.
    :param mesh_unstruc: unstructured pyvista grid
    :type mesh_unstruc: pv.UnstructuredGrid
    :return: pv.PolyData
    :rtype: pv.PolyData

    """
    vertices=mesh_unstruc.points
    faces=mesh_unstruc.cells
    return pv.PolyData(vertices, faces)

# 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 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(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

Using 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 function 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 intersection.n_cells>0:
    p.add_mesh(intersection, color="green", point_size=25, label="Intersection Points")
p.add_legend()
p.show(cpos="yz")

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

Installation

Copy the code/pyviewfactor.py file to your working directory, import relevant functions.

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, but has not been tested.

Authors and acknowledgment

Mateusz BOGDAN, Edouard WALTHER, Marc ALECIAN, Mina CHAPON

Citation

There is even a conference paper.

Bibtex entry:

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

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.4.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file pyviewfactor-0.0.4.tar.gz.

File metadata

  • Download URL: pyviewfactor-0.0.4.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for pyviewfactor-0.0.4.tar.gz
Algorithm Hash digest
SHA256 24599d88a3639b338d9e2d8c41b481e74c66166dcf230012957d8d3eea8a7513
MD5 14ab18e841925ec27f78791d55ad44ae
BLAKE2b-256 fa39978ed7e0e438e78103b535667b017a517c4b3040d2ed7a1a214e811c05cb

See more details on using hashes here.

Supported by

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