Effective Analysis Programming 1: Difference between revisions

From Gridkaschool
Jump to navigationJump to search
(Created page with "== Technical specification/requirements == {| class="wikitable" width="85%" style="border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-c…")
 
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Introduction==
== Technical specification/requirements ==


We give an introduction to advanced topics of C++. These include inheritance, templates, stable numerical calculations, debugging and profiling.
{| class="wikitable" width="85%" style="border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; padding: 0"
The main focus is on rules and guidelines to write clear code and avoid common pitfalls.
! colspan="6" style="background:#ABE" | Effective Analysis Programming 1&2

|-
Desirable Prerequisite: Basic knowledge of C/C++
| colspan="6" style="background:#ffffcc" | Christoph-Erdmann Pfeiler, Hartmut Stadie (not contacted)

|-

! style="width: 5%; border-style: solid; border-width: 1px 1px 0 0" | # of nodes
==Books==
! style="width: 20%; border-style: solid; border-width: 1px 1px 0 0" | Hardware
* Stroustrup: "The C++ Programming Language", 3rd edition
! style="width: 25%; border-style: solid; border-width: 1px 1px 0 0" | Software/Utilities
* Sutter, Alexandrescu: "C++ Coding Standards"
! style="width: 30%; border-style: solid; border-width: 1px 1px 0 0" | Miscellaneous
* Press et al.: "Numerical Recipes", 3rd edition
! style="width: 10%; border-style: solid; border-width: 1px 1px 0 0" | Status (ToDo/DONE)
* Meyers: "Effective C++" etc.
! style="width: 10%; border-style: solid; border-width: 1px 0 0 0" | Tested (YES/NO)

|-

| style="border-style: solid; border-width: 1px 1px 0 0" align="center" | ??
==Nodes==
| style="border-style: solid; border-width: 1px 1px 0 0" |
* gks-044.scc.kit.edu 141.52.174.44
* HDD: ??GB
* gks-246.scc.kit.edu 141.52.174.246
* RAM: ??GB

* ...

| style="border-style: solid; border-width: 1px 1px 0 0" | awk, sed
==Lectures==
| style="border-style: solid; border-width: 1px 1px 0 0" | open port
* Floating point arithmetic, numerical algorithms
| style="border-style: solid; border-color: #000; border-width: 1px 1px 0 0; color: red;" align="center" | ToDo
* Coding Guidelines 1(Organization and policy, Design style, Coding style, Function) [[Media:Effprog.pdf]]
| style="border-style: solid; border-color: #000; border-width: 1px 0 0 0; color: red;" align="center" | NO

|}
==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 [[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: [[File:cylinder.cc]]

To get started, execute:
<pre>
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
</pre>

===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===

Add the following Makefile to your project: [[File:Makefile.junk]] and rename it to Makefile.

===Class with overloaded operator()===

===Inheritance===

Latest revision as of 17:02, 28 August 2012

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 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 Sum1.png.

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.

  1. Complete the class implementation with the following files: File:Vector.hh,File:Vector.cc,File:Vectortest.cc
  2. 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.

Class with overloaded operator()

Inheritance