A skeleton code for these exercises are provided under this folder.
a) Create a two-dimensional 258x258
array of double precision numbers. Initialize the array such that the values are:
20.0
on the left boundary85.0
on the upper boundary70.0
on the right boundary5.0
on the lower boundary
and otherwise zeros. A skeleton code is provided in 2d_array.c.
b) Write a double-for loop for evaluating the Laplacian using the finite-difference approximation:
As an input use the 258x258
array of Exercise a (or start from the skeleton
laplacian.c. Evaluate the Laplacian only at the inner 256x256
points, the outer points are used as a boundary condition. As a grid spacing,
use dx=dy=0.01
. You can use the provided Makefile
(use command make
) for
building the code.
c) Create a struct for a temperature field. The struct has the following elements:
- number of grid points
nx
andny
in the x- and y-direction - the grid spacings
dx
anddy
in the x- and y-direction - the squares of grid spacings
dx2
anddy2
- two dimensional array containing the data points of the field. The array contains also the boundary values, so its dimensions are
nx+2
andny+2
.
d) Implement the initialization of the two dimensional array (exercise a) and finite-difference Laplacian (exercise b) in their own functions, which take as input the struct representing the temperature field (exercise 5c).