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
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).
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
请加QQ:99515681 邮箱:99515681@qq.com WX:codinghelp
- 赛诺威盛:大孔径专科化CT领航者
- 网易硬刚腾讯 两大游戏玩家之间的口水仗不断
- 全球“最独特”的一台华为 nova 6 5G 版手机是什么样子的?
- 拼多多抖音淘宝京东,谁是真低价?
- 老杨第一次再度抓握住一瓶水,他由此产生了新的憧憬
- 丰田章男称未来依然需要内燃机 已经启动电动机新项目
- B站更新决策机构名单:共有 29 名掌权管理者,包括陈睿、徐逸、李旎、樊欣等人
- 苹果罕见大降价,华为的压力给到了?
- 三明列东又有房子要拆迁!住这里的人要发了!
- 放大招后,广州又忍不住了…
- 私募积极加仓,百亿股票私募仓位指数创出近八周新高
- 他,传闻中马云最想见的人
- 升级的脉脉,正在以招聘业务铺开商业化版图
- 如何经营一家好企业,需要具备什么要素特点
- 智慧驱动 共创未来| 东芝硬盘创新数据存储技术