You are on page 1of 6

Computational Mechanics: Coursework on ODEs SPRING 2013

Hand-in date: Thursday 21st February (11 pm)

This coursework contributes to your degree and must be your own individual work. You
should not confer with others. You are also solely responsible for putting your own
coursework in the correct submission box by the date and time above. No marks will be given
if working is not shown.

3.1 The Computer Program

The program can be used to solve, numerically, any initial-value problem of the form:
dY
= F, Y ( x0 ) = Y0
dx
In general, Y and F are vectors and F is a function of both x and Y.

Program Files

The following files can be downloaded from Blackboard or the web page for this module.
solve.f95 the Fortran source file
solve.in a sample input file

Breakdown of Program File solve.f95

PROGRAM SOLVE main control program


SUBROUTINE STEP performs one forward step
SUBROUTINE DERIV returns the derivative F at given (x,Y)
SUBROUTINE OUTPUT performs any required output at given (x,Y)
FUNCTION EXACT optionally, can return the exact solution (if known)

Input File solve.in

NDEP number of dependent variables; i.e. dimension of Y


METHOD method of solution one of EULER, MODIF, RUNGE
NSTEP number of steps
H step size
NPRINT output frequency
X initial x
Y(1)... Y(NDEP) initial Y (one value for each component)

The basic procedures are already coded for you in subprograms SOLVE and STEP. For any
given equation the user should amend the code to specify:
derivative F in subroutine DERIV;
any required output in subroutine OUTPUT;
(optionally) the solution in function EXACT; this is only for testing purposes;
numerical parameters and initial values in file solve.in.

Computational Mechanics 3-1 David Apsley


Sample Equations

2 sample equations have been provided in the code (see subprograms DERIV and EXACT).
dy
(A) = x+ y , y ( 0) = 0 (solution: y = e x x 1 )
dx
d2 y dy
(B) 2
+ 3 + 2 y = 2x , y (0) = 1, y (0) = 1 (solution: y = 5e x 52 e 2 x + x 23 )
dx d x

In the latter case, the system has been reduced to first order with
dy
Y1 = y, Y2 =
dx
d Y1 Y2 Y1 1
= , = at x = 0
dx Y2 2 x 2Y1 3Y2 Y2 1

The user may switch between these sample problems by:


un-commenting the appropriate lines in subprograms DERIV and EXACT;
setting the number of variables (NDEP) and initial values (X and Y) in solve.in

The default output (see subroutine OUTPUT) is both to screen and to a file (solve.out)
and consists of the following columns:
x y y(exact) error

Sample Files solve.in

Problem A: solved by the Euler method; step size 0.1; 10 steps; output every step.
1 number of dependent variables (NDEP)
EULER method of solution (METHOD)
10 number of steps (NSTEP)
0.1 step size (H)
1 output frequency (NPRINT)
0.0 initial x
0.0 0.0 initial Y(); number of values corresponds to NDEP

Problem B: solved by the Runge-Kutta method; step size 0.05; 20 steps; output every 2 steps.
2 number of dependent variables (NDEP)
RUNGE method of solution (METHOD)
20 number of steps (NSTEP)
0.05 step size (H)
2 output frequency (NPRINT)
0.0 initial x
1.0 1.0 initial Y(); number of values corresponds to NDEP

**** Very important **** The number of items of initial data for Y must correspond to the
number of dependent variables, NDEP.

Computational Mechanics 3-2 David Apsley


3.2 Coursework

PART A: NUMERICAL METHODS

A1. Compare Solution Methods

For the first equation (problem A), run Euler ('EULER'), modified Euler ('MODIF') and
standard Runge-Kutta ('RUNGE') methods to derive the solution in 0 x 1 with step size
x = 0.1.

Compare all numerical solutions and the exact solution in a single table (using the same
precision as the output of the code) and on a single graph.

In your report:
include a table containing y values for all of these methods against x;
include the graph requested above;
state the maximum absolute error for each method;
comment briefly on the relative errors produced by the different methods;
state the advantages and disadvantages of using a high-order method like Runge-
Kutta compared with a low-order method like Euler.

A2. Effect of Step Size

Using the modified Euler method ('MODIF'), integrate problem A between x = 0 and x = 1
using step sizes x = 0.1, 0.05, 0.02, 0.01 in turn. (You will need to adjust NSTEP as the step
size changes, in order that xmax = 1.)

Tabulate E, log10 E and log10 x against x, where E is the absolute error at x = 1. Use the
same precision as the output of the code.

Plot a graph of log10 E against log10 x.

In your report:
include a table of absolute error (at x = 1) against stepsize;
include the graph;
state what is meant by an order-2 numerical scheme and determine whether
your graph is consistent with this.

Computational Mechanics 3-3 David Apsley


PART B: PRACTICAL EXAMPLE: LAMINAR BOUNDARY-LAYER FLOWS

u
x

The wall-parallel (x) component of velocity in a high-Reynolds-number self-similar


boundary-layer flow is given by
y
u = U f () , where = (1)

Here, U(x) is the free-stream velocity, (x) is proportional to boundary-layer depth and f is
the normalised stream function. f () satisfies the Falkner-Skan equation1
f + ff + (1 f 2 ) = 0 (2)
subject to boundary conditions
f (0) = f (0) = 0, f () = 1 (3)

is a parameter that is related to changes in the free stream: < 0 for decelerating flow, > 0
for accelerating flow and = 0 for constant free-stream velocity (zero pressure gradient).

B1. Governing Equation

Show how Equation (2) can be written as a first-order differential equation with vector
dependent variable.

In your report:
explain how this is done (e.g. by stating the components of the relevant vectors).

B2. Implementation

Modify subroutine DERIV to solve Equation (2). Modify subroutine OUTPUT to output f,
df/d and d2f/d2 but no exact solutions or errors (since these are unknown). Leave as a
variable to be modified when necessary.

In your report:
include the modified subroutines DERIV and OUTPUT.

1
For reference (i.e. you dont need to know this to do the question!), if the free-stream velocity U xm then
2 x , 2m
( x) = =
1+ m U 1+ m
and the case m = 0 gives the famous Blasius boundary-layer profile.

Computational Mechanics 3-4 David Apsley


B3. Test Cases

Compute the solution for three cases:


= 0: constant free-stream velocity;
= 0.19: decelerating flow (e.g. near separation);
= 1: accelerating flow (e.g. away from a stagnation point).

In each case employ a shooting method with a sequence of guesses for f (0) , so as to find
one which gives f (10) = 1.0 (10 is sufficiently close to in this problem!). The step size
and choice of integration method are entirely yours, but will need to be justified.

Note that, for non-zero , solutions can be very sensitive to f (0) ; you need only search in
the range (0, 2.0) here.

In your report:
plot a single graph (comparing the results for the three values of ) showing the
U
normalised velocity, = f () against for 0 5;
U
state the value of f (0) used for each value of ;
justify the choice of step size and integration method which you have used;
include the input file SOLVE.IN for any one of the three values of (but state
which!)

Computational Mechanics 3-5 David Apsley


PART C: ADDITIONAL INTEGRATION METHODS

Modify subroutine STEP to allow two additional cases:

'RKFEH' for the Runge-Kutta-Fehlberg method defined by the following tableau.

0 0 0 0 0 0 0
1 1
4 4 0 0 0 0 0
3 3 9
8 32 32 0 0 0 0
12
13
1932
2197 7200
2197
7296
2197 0 0 0
1 439
216 8 3680
513 4104
845
0 0
1
2 8
27 2 3544
2565
1859
4104 11
40 0
16
135 0 6656
12825
28561
56430 509 2
55

'IMPLI' for the implicit modified Euler method defined by


Yi +1 = Yi + 12 x [F( xi , Yi ) + F( xi +1 , Yi +1 )]

You are advised to check that both sample equations can be solved with these methods.

Use the Runge-Kutta-Fehlberg method and both explicit and implicit modified Euler methods
to solve the equation
dy
= x 5y3 , y(0) = 1
dx
using 10 steps of length x = 0.1. Compare your numerical solutions in a single table and on
a graph.

In your report:
include the modified subroutine STEP and, for the equation above, the modified
subroutine DERIV;
include the table and graph requested above.

Computational Mechanics 3-6 David Apsley

You might also like