FeResPost is also distributed as a Python compiled library.
In general, the class names, their methods and attributes (properties), the parameters of these methods and attributes are the same as those available in the FeResPost ruby extension. The user is referred to Parts I, II, III and IV to find information on the use of the different classes and methods. In most cases, the information given there is sufficient to use the Python extension.
Typically, one imports the FeResPost Classes and Modules with a statement as:
from FeResPost import *Note however that it works only if the different environment variables have been initialized correctly. Typically, in our Windows examples, this is done through the batch files that are used to launch the example scripts, and the following variables are generally initialized:
set LIB= set INCLUDE= set PYTHONPATH=D:/SHARED/FERESPOST/SRC/OUTPUTS/PYTHON/PYTHON_27 set PATH=C:/NewProgs/PYTHON/PYTHON_27(Of course the different paths you will initialize will have to be adapted to you peculiar installation, and to the version of Python you are using.)
Most of the differences of FeResPost Python and ruby libraries are directly related to the differences of the two languages, which are very similar as far as the different language concepts are concerned. Therefore, the adaptation of ruby examples to Python language should not be very difficult.
One highlights below some differences between Python and ruby extensions that are related to specific programmatic aspects of the two different systems.
New instances of the FeResPost classes are obtained by calling the corresponding class constructor:
... from FeResPost import * ... db=NastranDb() ...
The Python ``list'' object corresponds to ruby ``Array'', and the Python ''Dictionary'' corresponds to ruby ``Hash'' objects. One remarks however that the Python dictionary keys cannot be ``list'' objects. When this problem occurs, the ruby Array should be converted in a Python tuple instead of a Python list.
It is not possible to define several iterators in a given class in Python. Therefore, several special ``Iterator'' classes have been created in Python library. They are returned by the different FeResPost classes as is done for the COM component.
Let us illustrate it by an example... Consider the ``each_ply'' iterator defined in ClaLam class of FeResPost ruby extension. With the ruby extension, the iteration on the plies of a laminate may be performed as follows:
... lam.each_ply do |plyDescr| ... end ...With Python, the code becomes:
... for ply in lam.iter_ply(): ... ...One could also write:
... x=lam.iter_ply() for ply in x: ... ...As in the FeResPost ruby extension, each iterator method name starts with ``each_'', correspondingly, the Python methods returning an Iterator object have a name that starts with ``iter_''. The correspondence between ruby extension methods and COM component methods is obvious: ``each_ply'' becomes ``iter_ply'', ``each_material'' becomes ``iter_material'',...
In the ``Result'' class, operators are replaced by other methods (as in COM component):
z=x+ybecomes, with COM component:
Note that in the ``Group'' and ``ResKeyList'' classes, the Python operators correspond to ruby operators. The reason for this difference is that the ``Result'' class operators can have arguments that are not ``Result'' objects. Then, the call to ``Result'' class operator is not ensured. We hope to fix this problem in the future.
With FeResPost ruby extension, an optional argument can be set to ``nil'' when not provided. The ``nil'' argument is to be replaced by ``None'' value in Python.