Sunteți pe pagina 1din 6

Computational Civil Engineering 2005, International Symposium

Iai, Romnia, May 27, 2005

Python is a C++ made easy for Civil Engineers


Dan V. Turda (Ph.D.)1, F.-Zsongor Gobesz (Ph.D.)2
1

Chair of Structural Mechanics, Technical University of Cluj, Cluj-Napoca, 400020, Romania

Chair of Structural Mechanics, Technical University of Cluj, Cluj-Napoca, 400020, Romania

Summary
There exists an issue on the teaching of the programming, when non-programmers
are the subject. It is, in our opinion, the "appeal to programming" which should be
the "corner stone" a teacher should find. Python is a very modern programming
language, interpreted, very fast, built as a C++ wrapper having a Pascal-like
syntax. When it is used with specific libraries, like wxPython, SciPy or vtkPython,
it becomes a very powerfull tool in developping even professional engineering
applications. Not only there is the ease of programming, but also it transforms
programming in a pleasure. Moreover, py2exe can transform any interpreted
Python code in a MS-Windows .exe, by translating in C++ code and doing native
compilation. We like FORTRAN, but we really love Python. Here is our motivation,
along with examples.
KEYWORDS: teaching, programming, civil, engineer, python, C++ .

1. INTRODUCTION
Civil Engineers are often put in situations when hand-calculus is too complicated,
even if a pocket calculator would be available. From on-site situations up to
designing in short term, making its own program could solve the problem.
While we recognize the tradition of FORTRAN, we have to advocate our
conviction that we are talking about a lost tradition. The original FORTRAN was
conceived under the concept of "structure of procedures". It was added a support
for "structure of data", but the separation between data and statements was
rigorously respected. One can remark the position of COMMON or EQUIVALENT
blocks in a FORTRAN program.

We have to remark that at the time when FORTRAN was the only scientific
programming language, a compiler had to fight hard restrictions. Beyond
the processor's speed, it was the amount of RAM (Random Access Memory)
available for a program. Some of us remember how the trepassing from
FELIX-256 to FELIX-1024 was seen as a "big step forward". Yes, upgrading

D.V. Turda, F.Zs. Gobesz

from 256kb of RAM to 1Mb RAM was an important step. We do not realize
now, when a single no-name PC can have 512Mb, how our "ancestors"
could solve heavy problems. FORTRAN was the answer of the time.
However, this language remain the fastest under any comparison, and use
the smallest memory spot.
While reconigsing the merits of the old FORTRAN (upto FORTRAN77), we
have the right that the new versions of FORTRAN (from FORTRAN90),
denaturate the principles of the original concept. One cannot say that a new
language is born, and that should have another name! We have no more
FORTRAN. We get compilers with a payed license for which the learning
curve is very long. The learning process exclude organigrams as the starting
point in teaching Logic Mathematics and Boolean Algebra. This exclusion
make many students to put an inocent question: "What for we have to learn
that?". And this question is a ultimate one for a teacher.
2. OBJECTS
2.1 The object paradigm
With the advent of modern computers, including network facilities, there is no
more need of such data and statement structures as in the original FORTRAN. Data
and statements are contained (encapsulated) in objects. As a result an object can be
created or deleted, but the gain is that an object can communicate inside the
program (or outside of it) as the object include statements. It appeared also the
Application Interface Programming (API) concept, which allow a programmer to
address or to link to objects already compiled and tested.
The advent of objects is surely not the final point in the evolution of computer
programming, but it was a major "step forward". From a list of hierarchical
structures of data and statements, as in FORTRAN, the new technique approach a
n-dimensional graph. It is not a philosophy here, it is just about changing a point of
view. With care for the inheritance, we have to mention that Python can inherit
FORTRAN programs or libraries.

Guido van Rossum have had a marvellous idea to make a C++ wrapper
using a Pascal-like syntax. Using a strong-typed and objectual approaches,
he wrote a new language. This new language got the name Python, as Guido
like very much the Monty Python film series. The intention, form the very
start, was to make a language very easy to learn, very powerful, and to be in
the position to declare: Do you see how easy is to program a computer? And

Computational Civil Engineering 2005, International Symposium

he had a great succes. He was hired at the main education center in the
United States.
2.2 About the Graphical User Interface (GUI)
The evolution of the personal computers, but also of other devices like the mobile
phones is going in (at least) two directions, namely computation power and a mix
of text and image information.

We, as teachers, know that an image could "worth a thousand of words". We


know that, because any time when it is necessary, we drop a sketch on the
blackboard. However, we are not still able to make dynamic representations.
Moreover, once the blackboard is wipped, we are not able to make back
comparison, unless we redraw the sketch.
From now on, we will call FORTRAN as any version upto FORTRAN77.
FORTRAN is not able to carry GUI programming, nor to have access at
XML parsing, as examples. Graphics are necessary but are not teached. Our
proposal was to use FORTRAN for heavy computation (it is unbeatable!)
and to use Python for GUI programming and for small computation (it is
unbeatable!). As Python can wrap FORTRAN, we could get a swiss tool
instead a single one.
2.3 What we did
We created an experimental tool for teaching some matters in Python. We gave the
name aicSimpleSol to the program, and there is a free download, use and
distribution at http://www.aic.info.ro/ in the "Software" section.
It consist's of a main pannel which contains a tree, from any particular application
can be launched (Figure 1).
Once launched, each new window has three areas, namely the data area, the
graphic area and the help area. The help area use a wxPython widget which allowed
us to right the help text in HTML format (Figure 2).
There is an important feature we had in mind when we designed the program, and
that is the link between data and graphics. That is, any time data change, the
graphic window is updated. At this time, the graphics window is unsensitive, i.e. no
data can be changed using pointing devices (e.g. the mouse). It is not a
disadvantage, as we have to focus on data, and to give the mean to see how a
change in data affect the stress distribution, as an example.

D.V. Turda, F.Zs. Gobesz

Figure 1. aicSimpleSol's main panel

The entire task was possible by using PYTHON in combination with wxPython and
Boa Constructor. wxPython stands for a port of wxWidgets to Python, i.e. the
implemantation of windows, buttons, scrollbars, etc., as elements of a GUI, for
their direct use under PYTHON. Boa Constructor is a powerful tool for editing
PYTHON files and arange GUI elements on a frame.
So, we did a mix. It is the programming, on one hand, and elements of Civil
Engineering disciplines, on the other. Using a laptop and a big screen projector we
can now better explain the matter issues. But this a point of view. Seeing the fact
from another point of view, we succeeded in new concepts and language appraisals.
We know now how to integrate a perfect heavy computation tool (FORTRAN) with
a GUI, with network facilities, with database server access, and with XML
facilities, all platform independent.
After all these gains, we put ourselves, rethorically, a single question: Why not
developing ourselves the tools we need for teaching, just by teaching new
programming languages and not a single one?

Computational Civil Engineering 2005, International Symposium

Figure 2. A launched application.

For anyone curios about how a PYTHON script is looking, we give in Figure 3 a
fragment of the code for the application shown in Figure 2. One can observe that
the syntax is close to the C and C++ programming languages, even if has a very
interesting particularity: the white space is important. That means that the
programmer is obliged to take care of the source layout, as the statements that are
more in-depth are subordinated to the one which is less nested. One can observe
how an if statement is looking like, in the Figure 3.
We underline that all the tools we used are free of charge, and can be downloaded
from INTERNET. This aspect is very important in teaching, as most of the students
have computers at home, or have access to a collegue's one. This mean that we had
been used commercial software, the students could do their homework using only
commercial software. As most of them do not have enough financial support, we
would encourage them to use pirated software. But our mission is to teach for the
good behaviour, not for a bad one. Or this is not a part of our mission?

D.V. Turda, F.Zs. Gobesz

Figure 3. Code fragment in PYTHON

3. CONCLUSIONS
The teaching process is a very complex one. The modern technology offers a wide
range of tools, and we should learn how to use them. We should do so, because the
technological advance is very fast, and there remain only two years or so until
Romania will be part of the European Union. And from than on, will not be a
surprise to hear phrases as "Learning in other EU country is better than in
Romania, even if it a bit more expensive". For that we are preparing!

References
1.

PYTHON, http://www.python.org/.

2.

wxWidgets, http://www.wxwindows.org/.

3.

Boa Constructor, http://www.boa.sourceforge.net/.

S-ar putea să vă placă și