It will cover both the physical problem and the coded solutions. There will be no particular order, it will just be as it occurs to me.
My program is written mostly in python with heavy use of the numpy and scipy libraries and a fair bit of Fortran using numpy's f2py tool and my first post is related to using dictionary keys in python.
To capture the properties of each individual physical element, be it a slat, an intake lip or an engine spinner for example, I have a class called 'body'. In all the main code I can save information relating to each body in a dictionary using the body object itself as a key. This makes it easy to call the methods of the body object when iterating through the dictionary, for example:
for body in bodies_list:....body.some_method()However, I also make use of the multiprocessing module in python to make use of multiple cores, when I use a new process to calculate something about a body I pass the body object to the new process, but what happens is a new copy of the body object is created in the new process so trying to write back to the dictionary would give me a key error. To get around this I give the body object a public property 'name', which gets copied to the new process as a string and this can be used as a key when writing back to the dictionary.
References in python is one of the behaviours that is more alien to languages such as C++ where it is clearer what is an object and what is a pointer.
No comments:
Post a Comment