Gh_CPython Alpha Release !!

I managed to finish the Alpha release of Gh_CPython plugin for Grasshopper, and I have used it to create the first plugin (NumpyZerosMatrix) as shown in the image.

GH_CPython, is an CPython plugin for grasshopper. By using it, it is possible to run any sophisticated Python libraries inside grasshopper, such as:  Numpy , scipy, matplotlib, scikitlearn, PyOpenGL, pygame, tensorflow, OpenCV and so on.

I look forward to being consistently developing it and enhancing its features and I'll be grateful to any one who is able to contribute to its development or testing.  and I hope that it will be useful to all users and developers' community.

The attached image shows CPython plugin(down right) , and the first implemented plugin (top right) and the code ide (left)

Feel free to download the plugin,  create new pull requests, submit bugs, comments or wishes on GitHub via this link:




I'm so much grateful to everyone who gave me feedback  and suggestions. Thanks so much.


GHPythonINTERFACE: A Python IDE interface for Rhino\Grasshopper

Running Numpy, SciPy and matplotlib from Rhino and grasshopper has been very demanding problem to developers' community. In this respect, I'm trying to develop a new tool which is intended to be able to import all the required modules such as Numpy ans scipy without problems as well as integrating them within Rhino\Grasshopper. This tool is called GHPythonINTERFACE. It is opensource and will be released under simplified BSD licence.

In the following example, I have applied some modules such as: numpy, scipy, matplotlib, PyOpenGL and Pygame using this new plugin, just to evaluate it. (it is still under development and requires a lot of work). All the work is done in Python Object Oriented Programming (OOP) for my upcoming research project.

Limitations and Further works: 
So far, this plugin is not fully functioning, it still needs a lot of improvements such as efficiency and text highlighting.. Also I'm working on it during my free time. So, any suggested improvements or contributions are most welcome and so much appreciated.




Running Python Process in Parallel

I have been trying to run multi-processes using python subprocess module. I'm using Python 2.7 and Yes, it is helpful and saves a lot of time indeed, but, I need to run about 10 thousand daylight simulations simultaneously, it is impossible to do this serially, thus I have to think about parallel computing. Ok, I know that the best solution lies in GPGPU but I would like to start applying CPU parallelism at first. I have stumbled across threading and multiporcessing modules which are thread-based parallelism and processing-based parallelism respectively. I'll spend sometimes trying these two modules and I will write about them soon as possible, If I find something better I'll blog about it as well.


Visualizing daylight data using matplotlib with radiance

It is possible to output daylight data from radiance using the following command line: 

rtrace [ options ] [ $EVAR ] [ @file ] octree]

Then, using numpy.filetxt() function, you can read the output rsult file for predefined points as an ndArray. After that, it will be easy to plot them either using matplotlib.pcolor() or matplotlib.contourf().
I prefer this method because it gives more flexibility in reading and reporting data. 

Genetic Algorithms Optimization Using Python .

Genetic algorithms have a lot of potentials for building performance, I look forward to using them in my upcoming research. This attempt was conducted using Python 2.7, Numpy and Matplotlib. You can download the IPython notebook via this link on GoogleDrive:


GhPlotLib, a Scientific Plotting Plugin for Grasshopper

[GhPlotLib], another project on the queue. 


This project aims to bring scientific plotting facilities to grasshopper. From its name, one can guess that it is based on Python\matplotlib module. 
Matplotlib is a python based plotting package developed by John D. Hunter during his final stages of preparing Ph.D. dissertation mainly to overcome problems of implementing complex code structures in MatLab. 
It is important for scientists and engineers to have such tools in their practice to express their discourse. On the other hand, a large community of designers and architects have moved towards quantitatively modeling their designs and expressing them computationally in a form of algorithms. this raised the need to having scientific computing facilities handy to architects and designers, in addition to having plotting facilities to express their mathematical modeling and computational expressions of the built environment. 

You can follow the project on GitHub via the following link: 



ANT a Machine Learning Plugin for Rhino-Grasshopper

During the last few weeks, I've been developing a new plugin for grasshopper called ANT, this plugin is meant to facilitate using Machine Learning techniques in Architecture and design. ANT is derived from the very well-known Python-based module scikit-learn.

Why depending on these techniques? 

Why Python ? 
Python is a powerful programming language. During the last few years, it has dramatically attracted the interest of scientists and engineers due to its power, interactive, efficiency, and consistent ecosystem of growing number of modules that cover major areas of science, technology, engineering and mathematics such as SciPy, NumPy, matplotlib. I have prepared a list of some topics about python importance for science and engineering I recommend them to anyone who is interested: 

Why Scikit-learn? 
There is a dramatic growing interest in applying machine learning in different disciplines, that is why it was important that machine learning algorithms become handy to non specialist users as stated by the developers of scikit-learn: "Scikit-learn is a Python module integrating a wide range of state-of-the-art machine learning algorithms for medium-scale supervised and unsupervised problems. This package focuses on bringing machine learning to non-specialists using a general-purpose high-level language. Emphasis is put on ease of use, performance, documentation, and API consistency. It has minimal dependencies and is distributed under the simplified BSD license, encouraging its use in both academic and commercial settings. Source code, binaries, and documentation can be downloaded from http://scikit-learn.sourceforge.net."

Why Grasshopper? 
Grasshopper is a visual programming language based on algorithmic design for Rhino3D. It has gained high interest by designers and architects due to its ease of use, robustness, plugin ecosystem and other features that make it widely used by computational designers and architects.

These reasons are the main driving force to develop a machine learning plugin for grasshopper by making use of the advantage of each tool. ANT is supposed to be released under BSD simplified licence on this GitHub Repository: 

To follow the updates on ResearchGate via this link: 

And, to join our team you can fill the following form: 


CFD code implementation

Hi every body, This is my trial to implement CFD code for a cavity using Python, numpy and matplotlib to solve continuity equation, momentum equation and divergence. you can find the code below. 

Here is the code , Python 2.7 and Ipython notebook have been used. 

import numpy as np
import matplotlib.pyplot as plt

g = 50

u = np.zeros((g, g+1))
un = np.zeros((g, g+1))
uc = np.zeros((g, g))

v = np.zeros((g+1, g))
vn = np.zeros((g+1, g))
vc = np.zeros((g, g))

p = np.zeros((g+1, g+1))
pn = np.zeros((g+1, g+1))
pc = np.zeros((g, g))

m = np.zeros((g+1, g+1))

dx = 1.0/(g-1)
dy = 1.0/(g-1)

dt = 0.001
delta = 4.5
error = 1.0
Re = 100.

errors = []

step = 1
step2 = 1

#initializing u, v, p
for i in range(g+1):
    u[g-2][i] = 1.0
    u[g-1][i] = 1.0

for i in range(g+1):
    for j in range(g+1):
        p[i][j] = 1.
#solving equations
while(error > 0.9):
    for i in range(1, g-1):
        for j in range(1, g):
            un[i][j]= u[i][j] - dt*(  (u[i+1][j]*u[i+1][j]-u[i-1][j]*u[i-1][j])/2.0/dx +0.25*( (u[i][j]+u[i][j+1])*(v[i][j]+v[i+1][j])-(u[i][j]+u[i][j-1])*(v[i+1][j-1]+v[i][j-1]) )/dy)- dt/dx*(p[i+1][j]-p[i][j]) + dt*1.0/Re*( (u[i+1][j]-2.0*u[i][j]+u[i-1][j])/dx/dx +(u[i][j+1]-2.0*u[i][j]+u[i][j-1])/dy/dy)

    for j in range(1, g):
        un[0][j] = 0.0
        un[g-1][j] = 0.0

    for i in range(g):
        un[i][0] = -un[i][1]
        un[i][g] = 2-un[i][g-1]
# Solve v - Momentum
    for i in range(1, g):
        for j in range(1, g-1):
            vn[i][j] = v[i][j] - dt* ( 0.25*( (u[i][j]+u[i][j+1])*(v[i][j]+v[i+1][j])-(u[i-1][j]+u[i-1][j+1])*(v[i][j]+v[i-1][j]) )/dx +(v[i][j+1]*v[i][j+1]-v[i][j-1]*v[i][j-1])/2.0/dy ) - dt/dy*(p[i][j+1]-p[i][j]) + dt*1.0/Re*( (v[i+1][j]-2.0*v[i][j]+v[i-1][j])/dx/dx+(v[i][j+1]-2.0*v[i][j]+v[i][j-1])/dy/dy )

#v - boundary conditions.
    for j in range(1, g-1):
        vn[0][j] = -vn[1][j]
        vn[g][j]= -vn[g-1][j]

    for i in range(g+1):
        vn[i][0] = 0.0
        vn[i][g-1] = 0.0
#Solve Continuity equation

    for i in range(1, g):
        for j in range(1, g):
            pn[i][j] = p[i][j]-dt*delta*(  ( un[i][j]-un[i-1][j] )/dx + ( vn[i][j]-vn[i][j-1] ) /dy  )

# Pressure boundary conditions
    for i in range(1, g):
        pn[i][0] = pn[i][1]
        pn[i][g] = pn[i][g-1]

    for j in range(g+1):
        pn[0][j] = pn[1][j]
        pn[g][j] = pn[g-1][j]

#Display Errors
    error = 0.0

    for i in range(1, g):
        for j in range(1, g):
            m[i][j] = (( un[i][j]-un[i-1][j] )/dx + ( vn[i][j]-vn[i][j-1] )/dy  )
            error = error + abs(m[i][j])
    if(step%5 == 1):
    if(step%500 == 1):
        print str(step2) + "  - Error: " + str(error) + " for step : " + str(step)
        step2 +=1
#iterating u
    for i in range(g):
        for j in range(g+1):
            u[i][j] = un[i][j]
#iterating v
    for i in range(g+1):
        for j in range(g):
            v[i][j] = vn[i][j]
#iterating p
    for i in range(g+1):
        for j in range(g+1):
            p[i][j] = pn[i][j]

    step += 1

f, ((plt1,plt2),(plt3, plt4)) = plt.subplots(2, 2)

f = plt1.pcolor(u.transpose())
f = plt2.pcolor(v.transpose())
f = plt3.contourf(p.transpose())
f = plt4.plot(errors)

plt1.set_title("u- velocity contour")
plt2.set_title("v- velocity contour")
plt3.set_title("pressure contour")
plt4.set_title("divergence ..")
f, ((plt1,plt2),(plt3, plt4)) = plt.subplots(2, 2)

f = plt1.pcolor(u.transpose(), shading = "flat")
f = plt2.pcolor(v.transpose(), shading = "flat")
f = plt3.pcolor(p.transpose(), shading = "flat")
f = plt4.plot(errors)


plt1.set_title("u- velocity contour")
plt2.set_title("v- velocity contour")
plt3.set_title("pressure contour")
plt4.set_title("divergence ..")