COMP1730/6730 Project Assignment
In this assignment you will implement a temperature diffusion simulation, emphasizing proper handling of edge cases and use of visualization techniques.
Practical information#
The project assignment is due Friday 10/05/2024, 23:55PM (end of week 10). To submit your solution, you have to upload via wattle:
- A single Python source file.
- A report with your answers to a set of predefined questions. Details about the format of the report and the questions are provided in the section Questions for the individual report below.
Here is the assignment submission link.
NOTE: You must attend the lab in week 11/12 to discuss your solution with a tutor. If absent without prior approval by the convener, you will receive zero mark.
NOTE: No excuses about technical problems like Internet connection or computer issues are accepted. You can actually submit the assignment as many times as you like, as the last submitted file will be marked. Do not wait until the last minute!
The project assignment is individual. You must write your own solution, and you are expected to be able to explain every aspect of it. You are not allowed to share your solution (code) with other students; this includes posting it (or parts of it) to the discussion forum, or to any other on-line forum.
If you have questions:
- Ask the tutor in your lab,
- Look at the Wattle discussion forum for a similar question, and only post your question if not found,
- Go to drop-in sessions.
Background#
Assignment: Temperature Diffusion Simulation Background Information:
This assignment explores temperature diffusion, a fundamental concept in thermodynamics where heat moves from higher to lower temperature regions. The simulation models how heat diffuses over time across a medium, either in one dimension (1D) or two dimensions (2D), using a nearest-neighbor averaging algorithm. Understanding this can help in environmental studies, materials science, and climatology.
A nearest-neighbor (NN) averaging algorithm takes the mean of a data point and its immediate neighbours (i.e. cells sharing a side with it, so not including diagonal neighbours). At the boundaries of a 2D table, or 1D vector, there are fewer values that are averaged due to missing neighbours. For example in the table
1.0 2.0 3.0
4.0 5.0 6.0
7.0 8.0 9.0
a NN average of the middle value 5.0 would be (5.0+2.0+6.0+8.0+4.0)/5 = 5.0, and the NN average of the top left corner 1.0 would be (1.0+2.0+4.0)/3=2.333.
Objective:
Develop Python programs that simulate and visualise temperature diffusion. You start with simple 1D diffusion and progress to more complex 2D and graph scenarios. You will need to handle boundary conditions properly to ensure the simulation does not attempt to access out-of-range data.
Questions for analysis (code)#
A template file for the assignment code is provided here:
In this file, there are several functions that you must implement.
These functions only have a pass
statement that you should replace with
your own implementation.
The provided functions exercise_1D_diffusion, exercise_2D_diffusion, exercise_2D_diffusion_numpy, and exercise_graph_diffusion can be used to call the associated implementation for testing and debugging purposes.
You do not have to solve all the tasks, but you can only gain marks for
the ones that you have attempted (see Marking criteria below for details on how we
will mark your submission).
Note that only task 6 should use numpy. Other tasks should use base python.
Note that the figures shown here are examples only to demonstrate the type of plot required. They should not be assumed to be correct solutions of questions in this assignment (and indeed may have been created with different parameters from the questions in this assignment).
Task 1: 1D temperature initial state#
Implement create_array() function to create a 1D array of 10 elements with initial temperatures at 0°C in the interior and 1.0°C at boundary cells.
Task 2: 1D NN averaging algorithm#
Implement simulate_1d_diffusion() function to apply a nearest-neighbor averaging algorithm to simulate temperature diffusion across the 1D array. Remember to handle edge cases correctly.
Task 3: 1D diffusion visualisation#
Implement plot_temperatures() function to visualize and compare the temperature changes across the original and two iterations of NN averaging, using line plots (e.g. Figure 1).
Task 4: 2D temperature initial state#
Implement create_grid() function to generate a 2D grid of 5x5 elements with initial temperatures at 0°C in the interior and 1.0°C at boundary cells.
Task 5: 2D temperature diffusion#
Implement simulate_2d_diffusion() function to simulate one iteration of temperature diffusion in the 2D grid using nearest-neighbor averaging. Ensure correct handling of boundaries.
Task 6: vectorised 2D diffusion.#
Implement simulate_large_scale() function, using NumPy, to optimize the diffusion simulation for a larger grid (i.e. 10x10). This function should compute the simulation for multiple iterations and visualise each step using a heatmap from matplotlib e.g. see Figure 2. You should show 5 heatmaps, including the initial state and 4 further iterations of the simulation. For COMP1730, any working solution is acceptable. For COMP6730, for full marks the solution needs to involve a vectorised expression with no nested loops (hint: look at the numpy pad function.)
Task 7: 2D diffusion on arbitrary graph.#
Temperature diffusion in structured grids as seen in the previous questions is a standard model in environmental science, physics, and engineering. However, many real-world systems are better represented as arbitrary networks or graphs where nodes represent locations (like cities or habitats) and edges represent connections (like roads, rivers, or migration paths). This question explores temperature diffusion across such arbitrary graphs, simulating how heat (or other information) might spread in a network.
Graph Representation: The graph is represented using an adjacency list (edges), where each index corresponds to a node and its list contains connected nodes. Temperatures are stored in a separate list (temperatures), indexed correspondingly. You are provided with function that create_graph() that will create such a graph, where nodes represent different regions, each with an initial random temperature, and edges between nodes indicate that temperature can diffuse between these nodes. Study this function to understand how the two list store the graph and how the graph is created.
You are also provided with function visualize_graph that will display such a graph. An example plot is shown in Figure 3. You do not need to understand the implementation of this function.
You should implement the function simulate_diffusion() which has as parameters the two lists defining the graph and should simulate one iteration of temperature diffusion, calculated by NN average, on the graph. It returns the updated node temperatures.
Questions for the individual report#
A template for your report is provided here:
The template is a plain text file; write your answers where indicated
in this file. Do not convert it to doc
, docx
, pdf
or any other format.
The questions for you to answer in the report are:
-
Report question 1: Write your name and ANU ID.
-
Report question 2: Select a piece of code in your assignment solution that you have written, and explain:
(a) What does this piece of code do?
(b) How does it work?
(c) What other possible ways did you consider to implement this functionality, and why did you choose the one you did?
For this question, you should choose a piece of code of reasonable size and complexity. If your code has an appropriate level of functional decomposition, then a single function is likely to be a suitable choice, but it can also be a part of a function. It should not be something trivial (like a single line, or a simple loop).
For all parts of this question, it is important that your answers are at an appropriate level of detail. For part (a), describe the purpose of the code, including assumptions and restrictions. For parts (b) and (c), provide a high-level description of the algorithmic idea (and alternative ideas), not a line-by-line description of each statement.
There is no hard limit on how short or how long your answer can be, but an answer that is short and clear is always better than one that is long and confusing, if both of them convey the same essential information. As a rough guideline, an appropriate answer may be about 100 - 300 words for each of parts (a) - (c).
Submission requirements#
Every student must submit two files: Your assignment code (assignment.py
)
and your individual report (assignment_report.txt
) through the
assignment submission link available on wattle.
Restrictions on code#
There are certain restrictions on your code:
- You should NOT use any global variables or code outside of functions.
- You can import modules that you find useful. If in doubt about whether a module can be used, post a question to the Wattle discussion forum before you decide to use it.
It is very important that you follow these restrictions. If you do not, we may not be able to test your code, in which case you can not gain any marks for code functionality.
Referencing#
In the course of solving the assignment problem, you will probably want to make use of all sources of knowledge available: the course materials, text books, on-line python documentation, and other help that you can find on-line. This is all allowed. However, keep in mind that:
-
If you find a piece of code, or an algorithmic idea that you implement, somewhere on-line, or in a book or other material, you must reference it. Include the URL where you found it, the title of the book, or whatever is needed for us to find the source, and explain how you have used it in an appropriate place in your code (docstring or comment).
-
Although you can often find helpful information in on-line forums (like stackexchange, for example), you may not use them to ask questions that are specific to the assignment. Asking someone else to solve an assignment problem for you, whether it is in a public forum or in private, is a form of plagiarism, and if we find any indication that this may have occurred, we will be forced to investigate. The same applies to generative AI tools, such as, ChatGPT or Github Co-pilot.
-
If you have any doubt about if a question is ok to ask or not, you can always post your question to the Wattle discussion forum. We will answer it at a level of detail that is appropriate.
Marking criteria#
The code component accounts for 90% of the total assignment marks, and your individual report for the remaining 10%. For the questions of the code component, the breakdown is as follows:
- Task 1: 5%
- Task 2: 15%
- Task 3: 15%
- Task 4: 15%
- Task 5: 15%
- Task 6: 15%
- Task 7: 20%
Your code will be marked on two criteria: Functionality and code quality. The division of marks between them is 60% for functionality and 40% for code quality. We will also consider the efficiency of your code. Efficiency is part of both functionality and code quality.
Functionality encompasses code running without error and produces an output that is correct. Examples of increasing levels of functionality are:
Code quality includes the aspects that we have discussed in lectures and homeworks:
- Good code documentation. This includes appropriate use of docstrings and comments.
- Good naming. This includes variable and function names.
- Logical and clearly set out code.
- Good code organisation, including appropriate use of functional decomposition. It should be based on functions which are concise (they must do only one thing!).
- Efficiency. This includes things like considering the complexity of the operations that you use, and avoiding unnecessarily slow methods of doing things. We do not require that every part is implemented in an optimally efficient way, but code that has many or large inefficiencies is considered to have lower quality.