SMR Logo

SMR Home Page
About SMR
Products
Services
Documentation
Miscellaneous
Infos

Python Course

The original program of the Python course can be downloaded as a text file here.

Some Useful Links for Python Programming

Due to its popularity, a lot of documentation material on Python is available in the web. We just list these links:

Example Block 1

For the Python introductory course held at NLR, 23.-24.9.2003, a set of example scripts has been prepared. These examples range from quick and easy to lengthy and intricate. The more advanced examples are geared towards the needs of engineers in computational structural mechanics (CSM) intending to use Python as a rapid-application development tool.

Prerequisites

Arithmetical expressions, simple variables, the math module, while loops, functions, function references as arguments to functions.

Tasks

  1. Write a function which calculates the factorial of a number. Download source code.
  2. Write the function which takes a starting point, an end point, a 'refinement factor', and an evaluation function, and which calculates the integral of that function by e.g. a trapezoidal or simpson rule. Write a function which, when given the analytical result, computes the relative error. Compare results. Download source code.
  3. Create a graph in baspl++ for e.g. sin(x). Download source code. The result should look like this:

Example Block 2

Prerequisites

Character string creation, slices, string formatting, lists, tuples, dictionaries, basic file I/O, Numeric arrays, the LinearAlgebra module (part of the Numeric software).

Tasks

  1. Write a program that asks for a file name and then prints out the number of lines of that file. Download source code.
  2. Write a simple file browser: Display a directory with os.listdir() and ask for action. Actions are: change directory, view file, quit. Download source code.
  3. Create a plate model using Q8/Q9 elements and write it to a B2000 database. Display the result with baspl++. Download source code.

Example Block 3

Prerequisites

F2PY and SWIG programs for extending Python with Fortran and C/C++ code, linear structural dynamics (modal analysis), B2000.

Tasks

  1. Create a subroutine in Fortran which takes a integer value as argument and prints it out. Wrap this subroutine with F2PY and call it from within Python.
  2. Create a simple C++ class and wrap it using SWIG. Create objects of this class from within Python, manipulate them, and delete them.
  3. Modal analysis example using Newmark or FFT. The b2map processor of B2000 is used to create a "reference" solution. The Numeric and LinearAlgebra modules are used to do the mathematics. Finally the results are displayed with baspl++.