Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Modern Programming Concepts in Engineering

universal machine program specialized machine

Topic 1: Introduction

Matthias Baitsch

Vietnamese-German Universit y
About the course. . .
Goals of the course

After successfully completing this course, you will


I know the key concepts of object-oriented programming
I master a programming language: Java
I be able to tackle many different programming problems in
engineering sciences
I know about types of algorithms and you will be able to
implement them
I know a variety of data structures and you will choose the right
one for your problem at hand
I build your own software upon existing libraries
What other students programmed after one semester Java

Simulation of a nonlinear pendulum

Start application: Mac OS X/Windows


We use an existing software package: view3D

What is the “view3D” package?


I Java library for interactive 3D graphics
I Based on freely available Visualization Toolkit (VTK)
I Developed at the Institute for Computational Engineering
Learning approach: Outside-in

What does outside-in mean?


You start as consumer of software and you will become a producer
of software later on. We will start with the view3D package.

Using the view3D library, you


I build three-dimensional models easily
I create interesting programs from the first day on
I learn from existing software which serves as model and
inspiration
I become familiar to the use of software through abstract
interfaces
Why modern programming concepts in engineering?
Why modern programming concepts in engineering?

1. Computing is pervasive in engineering:


I Numerical simulations
I Optimization of structures and processes
I Computer aided design
I Environmental modeling
I Construction management
I Data management

Advances in engineering depend on advances in computing


Why modern programming concepts in engineering?

2. Engineering problems become:


I Bigger (in terms of simulation model size)
I More complicated (coupled fields, probability, . . . )
I Multidisciplinary (take into account engineering aspects,
economics, energy management, . . . )

Industry demands for software solutions


Why modern programming concepts in engineering?

In order to cope with current and future challenges, creators of


engineering software have to
I employ efficient solution procedures (numerical methods)
I exploit modern computer hardware (parallel computing)
I use the Internet (distributed and grid computing)
I establish interactive simulation models (computational
steering, virtual reality)
I provide comprehensible evaluation methods (visualization)
I ensure correctness of results (as far as possible)

Problems can not be solved simply by trial and error, rather a rich
set of methods and concepts is required
What are modern programming concepts in engineering?

Most important methods and concepts:


I Object-oriented programming (OOP)
I Formal modeling techniques (Unified Modeling Language)
I Use of existing software packages, frameworks and services
I Automated testing and test driven development
I Modern user interfaces and interactive visualization
→ Choice of methods and concepts depend on software project
Why object-oriented programming (OOP)?

Short answer
Because object-oriented programming works!
Why object-oriented programming (OOP)?

Short answer
Because object-oriented programming works!

Long answer
Because object-oriented programming
I provides a natural and powerful way to model actual
(engineering) problems
I simplifies the development of software which is extensible and
maintainable
I lets developers split software up into separate, reusable parts
I helps developers to build reliable software systems
I simplifies programming in a team of programmers
→ OOP helps to keep complex software systems manageable
Choosing a programming language for MPCE
We use Java because Java is
I strictly object-oriented
I comparatively easy to learn
I a modern programming language
I supported by various freely available development
environments
I platform independent and programs are portable

We do we not use
I Fortran: Not object oriented, limited to numerics
I C++: Widely used and powerful but hard to learn
I C#: Would be an alternative but proprietary
I Visual Basic: Not suitable for numerical computations
Languages in green: Widely used in engineering
The Java Virtual Machine
Compiled language Java VM

hello.cpp Source code hello.java Source code

C++ compiler Java compiler

Byte code Virtual machine

hello.exe Executable hello.class java.exe

I Compiler generates machine I Compiler generates byte


code code
I Machine code is directly I Byte code is executed by
executed by CPU virtual machinea which is
executed by CPU

a
Often, VMs are implemented in C
The Java Virtual Machine

Advantages of using a Virtual Machine


I VM manages memory (garbage collection)
I VM performs extensive runtime error checking
I VM handles access to system resources (memory etc.)
I A Java program can run on any platform where a virtual
machine is available
Simplifies the development of portable, secure and reliable
software!

Disadvantages
I Impact on execution speed
I Java needs to be installed on the target computer
Summary

Modern Programming Concepts in Engineering


I covers theory and practice of object-oriented programming
I uses Java as a programming language, but concepts can be
transferred easily to other languages
I covers fundamental data structures, how they work and how
to make use of them
I introduces basic algorithms from the field of engineering, both
theoretically (complexity) as well as practically (through
examples)
Programming computers
Computers

Blue Gene at Sandia national labs Linux cluster Bochum Laptop computer Mobile phone

Computers are
I coming in very different flavours
I becoming faster and more powerful
I nowadays everywhere
I present in nearly every aspect of daily life

Computers are universal machines executing programs


What do the components of a computers do?
Outside world Computer

- Humans Communication Processors Memories


- Other computers devices
- Devices
Monitor
- Environment
Keyboard/Mouse

Network device

Sensor

Processors carry out instructions, send and receive data from


communication devices, store and retrieve data and
programs from memories
Memories store program and data, persistent or temporary
Communication devices connect the computer to the outside
world, present and gather data

Processors are instructed by the program they execute


What is a program?
What is a program?
Examples. . .
Interactive program with graphical user interface

Interactive programs
I are started by users by clicking an icon
I send and receive data from devices such as monitor, printer,
network card, speakers, hard disk drive
I react on user input from mouse and keyboard
Console program

Console programs
I are started by users by typing a command
I typically do not require user input during execution
I most often store results of computation on the hard disk
I are common in scientific and high-performance computing
Program running on a server computer

User's computer (yours) Server computer

http request Web server


(e.g. apache)

html document

Web browser

Server programs
I are started automatically when the computer starts up
I run for weeks or months
I usually do not require any user interaction
I interact with other programs running on another computer
Programs turn computers into specialized machines

universal machine program specialized machine

A computer is a universal machine. When you feed it with a


program, it becomes a specialized machine which can be used to
carry out a specific task.

Examples:
I Start Word – Your computer becomes a machine for writing a
letter (for your thesis, you might use something else)
I Start Ansys – Your computer becomes a machine for
structural analysis
Program execution
Data
Flow Start of program execution

Monitor Program

Keyboard/Mouse Persistent storage


(HDD)
Network device processing

Sensor

Program termination
A program
I has a well-defined entry point where program execution starts
I receives input from communication devices
I sends data to communication devices
I reads and writes data to persistent storage devices
I has one or more conditions which terminate program execution

An executing program is an immaterial machine


Building and running programs

writes a
Program
A programmer
which

a user

runs on

a computer
Building and running programs

using writes a
Program
A programmer
a computer
which

a user

runs on

a computer
Building and running programs

using writes a
Program
A programmer
a computer
which

users
run on

their computers
Building and running programs

using write a
Program
programmers
computers
which

users
run on

their computers
What makes a program a good program?

A good program is
correct: It does what it’s supposed to. This sounds trivial but
do you know any program which never crashes?
extensible: It is easy to change and to add new functionality
readable: The program source code is understandable to
humans!
reusable: Parts of the program can be used later to build other
programs (prevent reinvention of the wheel)
robust: It reacts appropriately to errors
secure: It does not let others misuse your computer
Writing computer programs

Writing programs it tough:


I Programs crash
I Programs give wrong results
I Getting a program right can be really hard
→ As a programmer, you are in charge
Writing computer programs

Writing programs it tough:


I Programs crash
I Programs give wrong results
I Getting a program right can be really hard
→ As a programmer, you are in charge

Writing programs is fun:


I Design and build your own machines
I Exert your creativity and imagination
I Having created a running program is a good feeling
→ There are (nearly) no limits, what you can do
A first example. . .
A first example: Elastic pendulum

Elements: Node at (0.0, 2.5) Node at (2.5, 2.5)


- circular section d = 0.1
Material:
- E = 500000 N/m², ρ = 10 kg/m³

y
g = 9.81 m/s²
Node at (0, 0) x
Constraint

Next slide: Use existing Java package (miniFE – developed in


Bochum) in order to create a finite-element model of the system
and to perform a nonlinear transient analysis simulating 20 seconds
using 2000 timesteps.
p u b l i c c l a s s PendulumProgram {
p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) {
Model m = new Model ( ) ;
Node n1 = m. c r e a t e N o d e ( 0 . 0 , 0 . 0 ) ;
Node n2 = m. c r e a t e N o d e ( 2 . 5 , 2 . 5 ) ;
Node n3 = m. c r e a t e N o d e ( 0 . 0 , 2 . 5 ) ;
C o n s t r a i n t c = new C o n s t r a i n t ( f a l s e , f a l s e , t r u e ) ;
M a t e r i a l mat = m. c r e a t e M a t e r i a l ( 5 0 0 0 0 0 . 0 , 1 0 . 0 ) ;
C i r c l e S s c t = m. c r e a t e S e c t i o n ( C i r c l e S . TYPE ) ;

n1 . s e t C o n s t r a i n t ( c ) ;
sct . setDiameter ( 0 . 1 ) ;
m. c r e a t e E l e m e n t ( Truss2D . TYPE, mat , s c t , n1 , n2 ) ;
m. c r e a t e E l e m e n t ( Truss2D . TYPE, mat , s c t , n2 , n3 ) ;

m. g e t S e t t i n g s ( ) . s e t A c c e l e r a t i o n (DOF . T Y , 9 . 8 1 ) ;
A n a l y s i s T y p e s . n o n l i n e a r T r a n s i e n t (m, 2 0 , 2 0 0 0 , 1 e − 6 , 0 . 7 ) ;

V i e w e r 2 v i e w e r = new V i e w e r 2 (m) ;
viewer . s e t V i s i b l e ( true ) ;
}
}
The running program
Summary
I Today, engineering and computing are closely connected
I Computers are universal machines
I Feeding a computer with a program turns the computer into a
specialized machine
I An executing program is an immaterial machine
I Object-oriented software models can be close to the problem
domain
I Existing libraries can provide powerful functionality

You might also like