next up previous contents index
Next: IX.1 Python examples Up: IX. FeResPost Python bindings Previous: IX. FeResPost Python bindings   Contents   Index

Subsections

IX.0 Introduction

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.


IX.0.1 Accessing 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.)


IX.0.2 Python versus ruby

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.


IX.0.2.1 Creating class instances

New instances of the FeResPost classes are obtained by calling the corresponding class constructor:

   ...
   from FeResPost import *
   ...
   db=NastranDb()
   ...


IX.0.2.2 Associative containers and Arrays

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.


IX.0.2.3 Iterators

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'',...


IX.0.2.4 Operators

In the ``Result'' class, operators are replaced by other methods (as in COM component):

For example, the following ruby statement:
    z=x+y
becomes, with COM component:
    z=x.opAdd(y)

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.


IX.0.2.5 ``nil'' arguments

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.


next up previous contents index
Next: IX.1 Python examples Up: IX. FeResPost Python bindings Previous: IX. FeResPost Python bindings   Contents   Index
FeResPost User Manual Version 4.4.0 (2017/08/27)