Introduction to C++

This tutorial aims to provide an introduction to C++ by developing a real application that models heat transfer during welding.

Background

We will develop a simple heat transfer model based on equations of heat conduction in solids. The spatial variation of the heating or cooling rate in a Cartesian coordinate system can be related to the second derivative of the temperature gradients in the x-, y-, and z-directions1:

\frac{\partial T}{\partial t} = \frac{\lambda}{\rho c}\left [ \frac{\partial^2 T}{\partial x^2} + \frac{\partial^2 T}{\partial y^2} + \frac{\partial^2 T}{\partial z^2} \right ]
= a \left [ \frac{\partial^2 T}{\partial x^2} + \frac{\partial^2 T}{\partial y^2} + \frac{\partial^2 T}{\partial z^2} \right ]

where T is temperature, t is time, \lambda is thermal conductivity, rho is density, c is specific heat capacity, and a is the thermal diffusivity of the material being welded.

One solution of the generic equation for steady-state distribution of temperature in a plate during arc welding was given by Rosenthal2 as:

T\{x,R\} = T_0 + \frac{\eta V I}{2 \pi \lambda}\left ( \frac{1}{R} \right ) \mathrm{exp}\left \{ - \frac{v}{2 a} (R + x)\right \};
R = \sqrt{x^2 + y^2 + z^2}

where T\{x,R\} is the temperature as a function of the radial distance (R) and distance (x) along the welding centerline, T_0 is the preheat temperature, V is the arc voltage, I is the welding current, v is the welding speed, a is the thermal diffusivity, and \eta is the arc efficiency.

See the Introduction to Integrated Weld Modeling3 for more details on the model we will be using.

Overview

We will begin by looking at the basic features of C++, including variables, constants, operators, flow of control, and functions. Once we have enough background information, we will begin creating the heat transfer model based on the equations above. The goal will be to create a program that, give initial starting conditions, will output a file that describes the temperature isotherms during the welding process. We will then couple that with the Python plotting program we developed in the Python module to generate a contour plot of the temperature gradients.

References

  1. O. Grong, Metallurgical Modeling of Welding, 2nd ed., The Institute of Materials, United Kingdom, 1997 

  2. D. Rosenthal, Mathematical Theory of Heat Distribution during Welding and Cutting, Weld. J., Vol 20, 1941, p 220s–234s 

  3. S. Babu, Introduction to Integrated Weld Modeling, ASM Handbook, Metals Process Simulation, Volume 22B, D.U. Furrer and S.L. Semiatin, editors 

Schedule

00:00 Structure of a Program What are the basic elements of a C++ program?
How do I use comments in C++?
What are namespaces?
00:20 Variables and Types What fundamental types are available?
How are variables declared and initialized?
00:50 Constants What are the different types of literal constants in C++?
How are constant expressions defined?
01:15 Operators What built-in operators are availble?
02:05 Basic Input/Output
02:35 Control of Flow How do I control the flow of execution in C++?
03:05 Functions What are functions and how do I use them in C++?
04:05 Function Overloading
04:35 Templates
05:05 Name Visibility How does C++ control visibility of objects?
05:35 Arrays How does C++ represent multiple values of the same type?
06:05 Character Sequences
06:35 Pointers
07:05 Structs How are data types grouped together in C++?
07:35 Classes I What are classes and how are they defined and used in C++?
08:20 Exceptions How can programs deal with exceptional conditions?
08:40 Command Line Arguments How can programs deal with command line arguments?
09:00 Finish

The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.