,。
Learning Outcomes
This project requires you to demonstrate your understanding of dynamic memory, linked lists and basic numerical computation. The key objective of this assignment is to solve a set of tasks which involve processing of flow around a flat plate.
Flow Around a Flat Plate
In the field of Fluid Mechanics, flow around a flat plate perpendicular to the flow direction is still an active area of research. With advent of high performance computing and supercomputers, it has now become possible to look at this simple case with a greater deal of accuracy. The problem consists of a flat plate that is perpendicular to the main flow direction as shown in Figure 1 (left). The blue arrows indicate the direction of the flow while the shaded object is the flat plate. This generates a wake behind the flat plate and exerts a pressure force on the plate, similar to the force you feel when you hold your hand out in a moving car. At a given instant the flow behind the flat plate is extremely complex and a snapshot of the flow domain is shown in Figure 1 (right).
Working with the Data
For this assignment, you will process the wake data from a flat plate case. The data has been provided to you in a CSV format file (flow data.csv) with the following form:
x, y, u, v 10.028, -20, 1.0079, -0.0054866 10.077, -20, 1.0079, -0.0054739 10.126, -20, 1.0079, -0.0054612 10.175, -20, 1.0079, -0.0054484 10.224, -20, 1.0079, -0.0054357
Each line corresponds to a point in the flow domain with coordinates (x,y). The velocities at that given point in x and y are given by u and v respectively.
Processing Tasks
This assignment consists of four processing tasks which will be assessed independently. For each task you are to measure the run time it takes to complete the described task using your program (see program output below). Each of the four tasks must not require more than 60 seconds to run on dimefox. This means, in order to complete the task within this time limit, you may need to focus on the efficiency of your solution for each problem. Overall you have to write a single program, performing each of the four tasks sequentially. For each task you have to write your results to a file on the disk.
Task 1: Maximum Velocity Difference
It is sometimes helpful to understand what’s the range of velocities in the flow. For the first task, you must compute the maximum velocity difference in u and v after coordinate x = 20. Specifically, you must output first the two points in the domain where the magnitude of the u velocity difference is maximum followed by the two points in the grid where the magnitude of the v velocity difference is maximum. For each set of points, the point with the maximum of the given velocity must be first followed by the point with the minimum velocity. The output should be to the file called task1.csv and should be formatted as below. There must be no blank spaces between the values and around the commas. Each value must be written to 6 decimal places.
It is imperative that you write it out the way described above and shown below otherwise comparing your output to the solution would result in an error and you would lose marks.
x, y, u, v 40.512346, -19.595387, 1.007986, -0.001002 66.899192, -0.729056, 0.850117, 0.0005807 69.552467, -0.729056, 0.852483, 0.0004275 60.961891, 0.442134, 0.838355, -0.0006330
The above is an example of what the file should look like and is not the actual solution. Also note that the data provided in flow data.csv is not in any chronological order and you must efficiently look only at points where the value of x is greater than 20. You can use file io.c to understand how to output data to a file.
Task 2: Mean Velocities on a Coarser Grid
Each line in the file flow data.csv is a point location in the domain. These points when joined together will create a mesh (also called a grid). For this task, you will map these points onto a coarser grid, computing the new average coordinates (x,y) and the corresponding velocities (u,v). The flow domain can be thought as divided into a two dimensional grid such that each cell of the grid would contain multiple points, the number of which would depend on the cell upper and lower dimensions and the coordinates of the points. You would compute the average coordinates and velocities for each cell using the formula below for all points k within a given cell (this is for the x coordinate; same formula to be used for y, u, v).
Finally, you must output the results of the averaged values and the score to task2.csv in descending order based on the score for each cell. An example of what the output should look like is shown below. There must be no blank spaces between the values and around the commas. Any float value must be written to 6 decimal places as shown:
x, y, u, v, S 20.464390, 19.001188, 1.009472, 0.003123, 3.614885 26.493395, -2.917140, 0.950080, 0.003106, 3.564577 26.493395, 2.922365, 0.949606, -0.002937, 3.562721 26.493443, 10.961477, 1.016337, 0.001415, 3.544763 26.493443, -11.009443, 1.016268, -0.001393, 3.542255 23.490141, -16.954090, 1.010923, -0.002471, 3.489632 23.490141, 16.966158, 1.010908, 0.002496, 3.488729
The size of the grid (number of cells in each direction) must be an input parameter, allowing the code to run different grid sizes. Your implementation would be checked for the grid resolution of 24 i.e. 24 cells in x and 24 cells in y. The domain extent for this coarse grid in x and y is 10 to 70 units and -20 to 20 units respectively. An example of the coarse grid is shown in Figure 2 (left). The 24 cells in x direction would span from -10 to 70 units while the 24 cells in y direction would span -20 to 20 units. Also shown is an example of a cell within this grid. As can be seen, the cell is of width x and height y and the black dots show the points in the original grid. Once you do the averaging for all these points, you will end up with one average point (shown in red).
Task 3: Velocity and It’s Statistics
For this task, you have to compute the threshold statistics of u velocity magnitudes i.e. how many points in the domain have the magnitude of u under 0.5, under 0.6 and so on. Then you must compute the % of points under each band. An example of this is given below.
threshold, points, percentage 0.500000, 126, 11.012561 0.600000, 256, 22.536942 0.700000, 348, 30.613564 0.800000, 582, 51.300236 0.900000, 810, 71.352145 1.000000, 902, 79.496213 1.100000, 1136, 100.000000
This example shows that there are 582 points in the domain where the magnitude of u is under 0.8. You must output the results in the same format as above to task3.csv. There must be no blank spaces between the values and around the commas. Any float value must be written to 6 decimal places as shown above.
Task 4: Wake Profile Visualization
For this task, you will visualise the wake profile generated by writing the wake boundaries to a text file. To do this, you will first calculate the y coordinate of maximum u velocity. This is to be done for locations x = 10,15,20,25,30,35,40,45,50,55,60,65, i.e. you will look through all the relevant points for each specified x location to choose the maximum of u and pick the corresponding y coordinate. Since the data doesn’t contain exact x coordinates as described here, you will take the x coordinate which are closest to these these numbers. For instance, the closest number to x = 50 in the data file is x = 49.999. To pick the relevant x coordinate, you can use a bound of 0.05 about the specified location (Note that there is exactly one x coordinate that will fall inside the bound so you don’t have to worry about a tie). Output the chosen x location and the magnitude of the corresponding y coordinate in the following format to task4 1.csv. There must be no blank spaces between the values and around the commas. Any float value must be written to 6 decimal places as shown:
x, y_h 29.980000, 5.921400 49.999001, 6.739500 54.983002, 6.956200
Now that you’ve obtained the y coordinates, calculate the spacing for each location using the following formula:
spacing = ceil(10 |y|)
A skeleton version has been provided to you, complete with the print statements to print out the wake boundary. All you need to to do is to obtain the spacings for these 12 x locations into the array yheight where yheight[0] corresponds to the spacing for x=10. The output should be written to the file task4_2.txt.
Implementation
Your implementation should be based on the provided skeleton code. A total of marks are allocated to the quality of your code:
- Program compiles without warning using gcc -Wall -std=c99 on dimefox
- Exception handling (check return values of functions such as malloc or fscanf )
- No magic numbers in your code (use #define instead)
- Comments and authorship (top of the file)
- General code quality (use code formatters, check for memory leaks)
- No global variables
The following sections describe the required command line options and program output of your program.
Command-Line Options
Your program should support the following command-line options: terminal:
./flow flow data.csv 128
where flow data.csv is containing the flow related data and 128 is the grid resolution.
Program Output
The program should output the only following information to stdout in addition to the text files for each task:
terminal: ./flow flow data.csv 128 TASK 1: 200.63 milliseconds TASK 2: 14063.82 milliseconds TASK 3: 209.46 milliseconds TASK 4: 221.16 milliseconds
For each task, output the time in seconds taken to perform all computation associated with each task. This can be achieved by adopting the gettimeofday.c code available in the resource for Week 2. After the program is executed, the files task1.csv , task2.csv, task3.csv, task4 1.csv and task4 2.txt containing the results for the different tasks should be located in the current directory.
A total of marks is allocated for correct implementation of the output format in terms of console output and output written to the result file generated by each task.
Provided Code
The following files are provided to you for this assignment:
- main.c, where the parsing of data from command line is to be done and timing for each task implemented.
- tasks.c, where you would implement four functions maxveldiff(), coarsegrid(), velstat() and wakevis(), for each task.
- Task 4 is in two parts. Code for the second part has been provided to you in the wakevis() function and need not be modified, as described in the details in Task 4 above and the comment in the skeleton. Stick to this if you want to ouput the wake profile correctly.
- tasks.h, which need not be changed and acts as a header file to link the C file to the main file.
You are free to use guide programs provided during the lectures on the LMS and adapt them for your use. This could be any of the files like file io.c, linkedlist.c, bst.c and more. You may also use the header files if needed. Remember to fill in your details in each file you write, such as the student name and student number.
Submission
You need to submit your program for assessment. Submissions will not be done via the LMS; instead you will need to log in to the server dimefox and submit your files using the command submit . You can (and should) use submit both early and often to get used to the way it works, and also to check that your program compiles correctly on our test system, which has some different characteristics to the lab machines. Only the last submission will be marked. The submission server may be very slow towards the deadline as many students are submitting. Therefore, please do not wait until the last few minutes to make the first attempt of submission. If you make a submission attempt a few minutes before the deadline but the submission was completed after the deadline, your submission will be treated as a submission AFTER the deadline.