Difference between revisions of "Effective Analysis Programming 1"
(→Monte Carlo method for moment of inertia) |
(→Implement a 3D-Vector) |
||
(14 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
Desirable Prerequisite: Basic knowledge of C/C++ |
Desirable Prerequisite: Basic knowledge of C/C++ |
||
+ | |||
+ | |||
+ | ==Books== |
||
+ | * Stroustrup: "The C++ Programming Language", 3rd edition |
||
+ | * Sutter, Alexandrescu: "C++ Coding Standards" |
||
+ | * Press et al.: "Numerical Recipes", 3rd edition |
||
+ | * Meyers: "Effective C++" etc. |
||
Line 10: | Line 17: | ||
* gks-044.scc.kit.edu 141.52.174.44 |
* gks-044.scc.kit.edu 141.52.174.44 |
||
* gks-246.scc.kit.edu 141.52.174.246 |
* gks-246.scc.kit.edu 141.52.174.246 |
||
+ | |||
==Lectures== |
==Lectures== |
||
− | * Floating point arithmetic, numerical |
+ | * Floating point arithmetic, numerical algorithms |
− | * Coding Guidelines 1(Organization and policy, Design style, Coding style, Function) |
+ | * Coding Guidelines 1(Organization and policy, Design style, Coding style, Function) [[Media:Effprog.pdf]] |
==Exercises== |
==Exercises== |
||
Line 20: | Line 28: | ||
Random numbers can be used to solve complex integrals. Here, you are asked to compute the moment of inertia [[Image:int1.png]] of a thin cylindrical shell and a cylinder, with radius R and length l. View the body as a composition of points with equal mass and sum up each point's moment of inertia [[Image:sum1.png]]. |
Random numbers can be used to solve complex integrals. Here, you are asked to compute the moment of inertia [[Image:int1.png]] of a thin cylindrical shell and a cylinder, with radius R and length l. View the body as a composition of points with equal mass and sum up each point's moment of inertia [[Image:sum1.png]]. |
||
− | Start with the program: [[ |
+ | Start with the program: [[File:cylinder.cc]] |
− | To get started execute: |
+ | To get started, execute: |
<pre> |
<pre> |
||
− | mkdir |
+ | mkdir inertia |
+ | cd inertia |
||
− | wget |
||
+ | wget https://wiki.scc.kit.edu/gridkaschool/upload/2/2d/Cylinder.cc |
||
− | g++ -o zylinder zylinder.cc |
||
+ | mv Cylinder.cc cylinder.cc |
||
− | ./zylinder |
||
+ | g++ -o cylinder cylinder.cc |
||
+ | ./cylinder |
||
</pre> |
</pre> |
||
− | ===Implement Vector class=== |
||
===Version Control=== |
===Version Control=== |
||
+ | Create the root directory of CVS: |
||
+ | <pre> |
||
+ | mkdir cvsroot |
||
+ | cvs -d $PWD/cvsroot init |
||
+ | </pre> |
||
+ | |||
+ | Point CVSROOT to the new directory: |
||
+ | <pre> |
||
+ | export CVSROOT=<full path to cvsroot> |
||
+ | </pre> |
||
+ | |||
+ | Import your project into CVS: |
||
+ | <pre> |
||
+ | cd inertia |
||
+ | cvs import -m "start" Inertia INITIAL start |
||
+ | </pre> |
||
+ | |||
+ | Test it: |
||
+ | <pre> |
||
+ | cd |
||
+ | cvs co -d inertiawork Inertia |
||
+ | </pre> |
||
+ | |||
+ | Other commands: |
||
+ | <pre> |
||
+ | cvs diff |
||
+ | cvs status |
||
+ | cvs commit -m"precise description" <files> |
||
+ | cvs diff --brief |
||
+ | cvs up |
||
+ | cvs add |
||
+ | cvs delete |
||
+ | </pre> |
||
+ | |||
+ | ===Implement a 3D-Vector=== |
||
+ | |||
+ | In order to make our program more general (different bodies, different axis) we need a class for 3D vectors that can also compute the cross product. |
||
+ | |||
+ | # Complete the class implementation with the following files: [[File:Vector.hh]],[[File:Vector.cc]],[[File:Vectortest.cc]] |
||
+ | # Adapt cylinder.cc to use the new Vector class |
||
+ | |||
+ | Solution for 1st part: [[File:Vector_cor.hh]],[[File:Vector_cor.cc]],[[File:Vectortest_cor.cc]] [[File:Cylinder_cor.cc]] |
||
+ | |||
===Makefile=== |
===Makefile=== |
||
− | ===Overload operator()=== |
||
− | ===Inheritance=== |
||
+ | Add the following Makefile to your project: [[File:Makefile.junk]] and rename it to Makefile. |
||
+ | ===Class with overloaded operator()=== |
||
− | ===[[Internals:EA|Technical specification/requirements]]=== |
||
+ | |||
+ | ===Inheritance=== |
Latest revision as of 17:02, 28 August 2012
Contents
Introduction
We give an introduction to advanced topics of C++. These include inheritance, templates, stable numerical calculations, debugging and profiling. The main focus is on rules and guidelines to write clear code and avoid common pitfalls.
Desirable Prerequisite: Basic knowledge of C/C++
Books
- Stroustrup: "The C++ Programming Language", 3rd edition
- Sutter, Alexandrescu: "C++ Coding Standards"
- Press et al.: "Numerical Recipes", 3rd edition
- Meyers: "Effective C++" etc.
Nodes
- gks-044.scc.kit.edu 141.52.174.44
- gks-246.scc.kit.edu 141.52.174.246
Lectures
- Floating point arithmetic, numerical algorithms
- Coding Guidelines 1(Organization and policy, Design style, Coding style, Function) Media:Effprog.pdf
Exercises
Monte Carlo method for moment of inertia
Random numbers can be used to solve complex integrals. Here, you are asked to compute the moment of inertia of a thin cylindrical shell and a cylinder, with radius R and length l. View the body as a composition of points with equal mass and sum up each point's moment of inertia .
Start with the program: File:Cylinder.cc
To get started, execute:
mkdir inertia cd inertia wget https://wiki.scc.kit.edu/gridkaschool/upload/2/2d/Cylinder.cc mv Cylinder.cc cylinder.cc g++ -o cylinder cylinder.cc ./cylinder
Version Control
Create the root directory of CVS:
mkdir cvsroot cvs -d $PWD/cvsroot init
Point CVSROOT to the new directory:
export CVSROOT=<full path to cvsroot>
Import your project into CVS:
cd inertia cvs import -m "start" Inertia INITIAL start
Test it:
cd cvs co -d inertiawork Inertia
Other commands:
cvs diff cvs status cvs commit -m"precise description" <files> cvs diff --brief cvs up cvs add cvs delete
Implement a 3D-Vector
In order to make our program more general (different bodies, different axis) we need a class for 3D vectors that can also compute the cross product.
- Complete the class implementation with the following files: File:Vector.hh,File:Vector.cc,File:Vectortest.cc
- Adapt cylinder.cc to use the new Vector class
Solution for 1st part: File:Vector cor.hh,File:Vector cor.cc,File:Vectortest cor.cc File:Cylinder cor.cc
Makefile
Add the following Makefile to your project: File:Makefile.junk and rename it to Makefile.