代写COMP528、代做c/c++,Python程序语言
- 首页 >> Java编程 University of Liverpool Assignment 2 Resit COMP528
In this assignment, you are asked to implement a numerical method for solving a partial
differential equation. This document explains the operation in detail, so you do not have to
have studied calculus. You are encouraged to begin work on this as soon as possible to avoid
the queue times on Barkla closer to the deadline. We would be happy to clarify anything
you do not understand in this report.
1 Laplace solver
Modelling heat transfer in a room can be done by using the Laplace equation, a second-order
partial differential equation. This can be approximated using a iterative stencil method.
Consider this two-dimensional array which represents a 25m2
room.
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
Figure 1: An example of the room
This two-dimensional array represents the space in the room, where the dimensions are NxN.
Each element in this array represents the temperature of that point within the room. The
boundaries of the array represent the walls. The points equal to 100, represent a radiator
within the room. The radiator always occupies 60% of the right wall and is centred. That is
the radiator starts at t [N−1][ffoor((N−1)∗0.3)], and ends at t [N−1][ceil((N−1)∗0.7)]
assuming 0 based indexing. Note that the room will always be 25m2
. That means the number
of the points only changes the resolution of the points in the room, not the actual size of the
room.
To model how the heat from the radiator moves throughout the room, we use the following
calculation for each point.
curr t[ i ][ j]=AVERAGE(prev t[i][j+1]+prev t[i][j−1]+prev t[i+1][j]+prev t[i−1][j])
Figure 2: The iterative calculation to ffnd the temperature moving through the room
2023-2024 1University of Liverpool Assignment 2 Resit COMP528
That is, each point is equal to the average of the surrounding points. When applying this to
Figure 1, we have these new temperatures. Figure 3 is after the ffrst iteration, and Figure
4 is after the second iteration.
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
Figure 3: An example of the room after one iteration
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 15.625 10
10 10 10 10 10 10 10 15.625 38.125 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 38.125 100
10 10 10 10 10 10 10 10 15.625 10
10 10 10 10 10 10 10 10 10 10
Figure 4: An example of the room after two iterations
We can observe that we do not update the boundary elements, in order to avoid any access
to memory that does not exist. To update the array, only the elements within the range of
indices from the second row to the second-to-last row (rows 1 to N-2) and from the second
column to the second-to-last column (columns 1 to N-2) should be modiffed.
2023-2024 2University of Liverpool Assignment 2 Resit COMP528
1.1 OpenMP laplace solver
You are asked to implement this operation in a C function with the following signature. This
function should be saved in a ffle called heat.c
double g e t fi n a l t e m p e r a t u r e s ( int N, int maxIter , double radTemp){
// . . . your code here
int pointx = f l o o r ((N−1 ) ∗ 0 . 5 );
int pointy = f l o o r ((N−1 ) ∗ 0 . 5 );
double r e s u lt = c u rr t [ pointx ] [ pointy ] ;
return r e s u lt ;
}
N is the number of points along one axis of the room matrix and maxIter is the number of
iterations to be performed in one run. Both pointX and pointY are the coordinates for the
centre of the room and therefore curr t[pointx][pointy] is the temperature at the centre of
the room. radTemp is the value for the radiator to be set to. Therefore the function returns
the temperature of the centre of the room for a given radiator temperature after maxIter
iterations have been performed.
1.2 Serial Implementation
You are asked to implement a sequential main C ffle which can do the following.
• Read a string of radiator temperatures from an input ffle and store them in a onedimensional
array.
• Call the ‘get ffnal temperature()‘ function for each temperature.
• Store the results in a one-dimensional array.
• Write the results to an output ffle.
Once compiled, the sequential program should be called like so:
$ ./
In this assignment, you are asked to implement a numerical method for solving a partial
differential equation. This document explains the operation in detail, so you do not have to
have studied calculus. You are encouraged to begin work on this as soon as possible to avoid
the queue times on Barkla closer to the deadline. We would be happy to clarify anything
you do not understand in this report.
1 Laplace solver
Modelling heat transfer in a room can be done by using the Laplace equation, a second-order
partial differential equation. This can be approximated using a iterative stencil method.
Consider this two-dimensional array which represents a 25m2
room.
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
Figure 1: An example of the room
This two-dimensional array represents the space in the room, where the dimensions are NxN.
Each element in this array represents the temperature of that point within the room. The
boundaries of the array represent the walls. The points equal to 100, represent a radiator
within the room. The radiator always occupies 60% of the right wall and is centred. That is
the radiator starts at t [N−1][ffoor((N−1)∗0.3)], and ends at t [N−1][ceil((N−1)∗0.7)]
assuming 0 based indexing. Note that the room will always be 25m2
. That means the number
of the points only changes the resolution of the points in the room, not the actual size of the
room.
To model how the heat from the radiator moves throughout the room, we use the following
calculation for each point.
curr t[ i ][ j]=AVERAGE(prev t[i][j+1]+prev t[i][j−1]+prev t[i+1][j]+prev t[i−1][j])
Figure 2: The iterative calculation to ffnd the temperature moving through the room
2023-2024 1University of Liverpool Assignment 2 Resit COMP528
That is, each point is equal to the average of the surrounding points. When applying this to
Figure 1, we have these new temperatures. Figure 3 is after the ffrst iteration, and Figure
4 is after the second iteration.
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
Figure 3: An example of the room after one iteration
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 15.625 10
10 10 10 10 10 10 10 15.625 38.125 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 38.125 100
10 10 10 10 10 10 10 10 15.625 10
10 10 10 10 10 10 10 10 10 10
Figure 4: An example of the room after two iterations
We can observe that we do not update the boundary elements, in order to avoid any access
to memory that does not exist. To update the array, only the elements within the range of
indices from the second row to the second-to-last row (rows 1 to N-2) and from the second
column to the second-to-last column (columns 1 to N-2) should be modiffed.
2023-2024 2University of Liverpool Assignment 2 Resit COMP528
1.1 OpenMP laplace solver
You are asked to implement this operation in a C function with the following signature. This
function should be saved in a ffle called heat.c
double g e t fi n a l t e m p e r a t u r e s ( int N, int maxIter , double radTemp){
// . . . your code here
int pointx = f l o o r ((N−1 ) ∗ 0 . 5 );
int pointy = f l o o r ((N−1 ) ∗ 0 . 5 );
double r e s u lt = c u rr t [ pointx ] [ pointy ] ;
return r e s u lt ;
}
N is the number of points along one axis of the room matrix and maxIter is the number of
iterations to be performed in one run. Both pointX and pointY are the coordinates for the
centre of the room and therefore curr t[pointx][pointy] is the temperature at the centre of
the room. radTemp is the value for the radiator to be set to. Therefore the function returns
the temperature of the centre of the room for a given radiator temperature after maxIter
iterations have been performed.
1.2 Serial Implementation
You are asked to implement a sequential main C ffle which can do the following.
• Read a string of radiator temperatures from an input ffle and store them in a onedimensional
array.
• Call the ‘get ffnal temperature()‘ function for each temperature.
• Store the results in a one-dimensional array.
• Write the results to an output ffle.
Once compiled, the sequential program should be called like so:
$ ./