1 00:00:00,030 --> 00:00:02,400 The following content is provided under a Creative 2 00:00:02,400 --> 00:00:03,770 Commons license. 3 00:00:03,770 --> 00:00:06,020 Your support will help MIT OpenCourseWare 4 00:00:06,020 --> 00:00:10,100 continue to offer high quality educational resources for free. 5 00:00:10,100 --> 00:00:12,670 To make a donation or to view additional materials 6 00:00:12,670 --> 00:00:16,580 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:16,580 --> 00:00:17,235 at ocw.mit.edu. 8 00:00:25,817 --> 00:00:26,400 QIQI WANG: OK. 9 00:00:26,400 --> 00:00:31,040 So today is our lecture on finite volume method. 10 00:00:31,040 --> 00:00:33,800 So we talked about finite difference method. 11 00:00:33,800 --> 00:00:37,070 And we are going to be talking about finite volume method 12 00:00:37,070 --> 00:00:38,320 and finite element method. 13 00:00:38,320 --> 00:00:42,640 So I'm going to-- there is a request for me to go over 14 00:00:42,640 --> 00:00:46,710 what did I do on the matrix form of the two dimensional 15 00:00:46,710 --> 00:00:47,640 finite difference. 16 00:00:47,640 --> 00:00:49,060 So I'll go over that. 17 00:00:49,060 --> 00:00:51,300 But before I do that, let me show 18 00:00:51,300 --> 00:00:55,310 you what is the difference between finite volume method 19 00:00:55,310 --> 00:00:57,830 and finite difference method. 20 00:00:57,830 --> 00:01:01,840 Because there are two concepts, they 21 00:01:01,840 --> 00:01:03,900 are two conceptually different methods 22 00:01:03,900 --> 00:01:06,683 of describing and discretizing partial differential equations. 23 00:01:09,920 --> 00:01:11,420 So I have a few demos. 24 00:01:11,420 --> 00:01:13,037 I have a finite volume demo. 25 00:01:13,037 --> 00:01:14,370 I have a finite difference demo. 26 00:01:17,000 --> 00:01:18,680 I have also a finite element demo. 27 00:01:18,680 --> 00:01:21,970 So they are really three different conceptually 28 00:01:21,970 --> 00:01:25,180 different methods of solving PDEs. 29 00:01:25,180 --> 00:01:28,230 So first I have a finite difference demo. 30 00:01:28,230 --> 00:01:31,920 So let me explain what is happening here. 31 00:01:31,920 --> 00:01:38,180 We are representing a function of x, a function of space 32 00:01:38,180 --> 00:01:40,102 in solving partial differential equations. 33 00:01:40,102 --> 00:01:43,720 And this function is going to evolve as a function of time. 34 00:01:43,720 --> 00:01:48,120 But in order to [INAUDIBLE] that function of x, 35 00:01:48,120 --> 00:01:49,674 we need to discretize it. 36 00:01:49,674 --> 00:01:52,446 Because a function is an infinite dimension [INAUDIBLE]. 37 00:01:56,850 --> 00:01:59,415 Like that. 38 00:01:59,415 --> 00:02:01,290 Huh? 39 00:02:01,290 --> 00:02:03,700 AUDIENCE: [INAUDIBLE]. 40 00:02:03,700 --> 00:02:11,660 QIQI WANG: I think I-- I think there 41 00:02:11,660 --> 00:02:14,134 is something I can get rid of. 42 00:02:14,134 --> 00:02:24,835 I just don't know-- Advanced Settings. 43 00:02:24,835 --> 00:02:25,335 Monitor. 44 00:02:30,196 --> 00:02:30,696 Yeah. 45 00:02:30,696 --> 00:02:34,004 I don't know why. 46 00:02:34,004 --> 00:02:34,504 Oh. 47 00:02:34,504 --> 00:02:36,620 That went away? 48 00:02:36,620 --> 00:02:38,240 Oh OK. 49 00:02:38,240 --> 00:02:40,004 [INTERPOSING VOICES] 50 00:02:40,004 --> 00:02:41,670 AUDIENCE: Don't close that dialogue box. 51 00:02:41,670 --> 00:02:42,253 QIQI WANG: OK. 52 00:02:47,363 --> 00:02:50,261 Advanced Settings. 53 00:02:50,261 --> 00:02:51,230 Monitor. 54 00:02:51,230 --> 00:02:53,271 I think I didn't do anything except for-- 55 00:02:53,271 --> 00:02:54,146 AUDIENCE: [INAUDIBLE] 56 00:02:54,146 --> 00:02:55,625 QIQI WANG: Yeah, just like that. 57 00:02:55,625 --> 00:02:56,260 Yeah. 58 00:02:56,260 --> 00:02:57,176 AUDIENCE: [INAUDIBLE]. 59 00:02:59,424 --> 00:03:00,007 QIQI WANG: OK. 60 00:03:02,690 --> 00:03:03,674 Wow. 61 00:03:03,674 --> 00:03:07,120 [LAUGHTER] 62 00:03:07,120 --> 00:03:10,000 I have no idea. 63 00:03:10,000 --> 00:03:11,400 This is weird. 64 00:03:11,400 --> 00:03:12,744 Technology. 65 00:03:12,744 --> 00:03:14,090 OK. 66 00:03:14,090 --> 00:03:15,350 So I have a function of x. 67 00:03:15,350 --> 00:03:17,880 I need to discretize it. 68 00:03:17,880 --> 00:03:20,010 Can somebody come and draw me a function? 69 00:03:20,010 --> 00:03:23,806 And visualize how this is kind of different, 70 00:03:23,806 --> 00:03:26,700 how finite difference discretizes a function. 71 00:03:26,700 --> 00:03:28,849 So can somebody come up and draw a function? 72 00:03:28,849 --> 00:03:30,640 And maybe you can describe to me before you 73 00:03:30,640 --> 00:03:33,670 draw the function of how finite difference discretizes 74 00:03:33,670 --> 00:03:36,300 the function, how will you [INAUDIBLE] that function. 75 00:03:42,550 --> 00:03:44,640 How would the-- in a finite difference method, 76 00:03:44,640 --> 00:03:48,070 how do we represent, like, obviously a function? 77 00:03:48,070 --> 00:03:48,930 Let me see. 78 00:03:48,930 --> 00:03:54,160 These blue lines are where the grid is. 79 00:03:54,160 --> 00:03:56,330 [INAUDIBLE], Right. 80 00:03:56,330 --> 00:03:57,270 OK. 81 00:03:57,270 --> 00:04:00,971 So who wants to draw it for me? 82 00:04:00,971 --> 00:04:01,970 We just did the project. 83 00:04:01,970 --> 00:04:03,795 It's a time to relax a little bit. 84 00:04:03,795 --> 00:04:06,170 So [INAUDIBLE] the difference in [INAUDIBLE]. 85 00:04:08,401 --> 00:04:09,234 [INTERPOSING VOICES] 86 00:04:28,360 --> 00:04:29,810 QIQI WANG: All right. 87 00:04:29,810 --> 00:04:30,310 Good. 88 00:04:30,310 --> 00:04:33,532 So when we draw a function, it looks like this. 89 00:04:33,532 --> 00:04:34,990 Right? 90 00:04:34,990 --> 00:04:36,967 [? If this ?] curve is the function [INAUDIBLE] 91 00:04:36,967 --> 00:04:37,800 a little bit, right? 92 00:04:37,800 --> 00:04:40,090 On the-- if not the [INAUDIBLE]. 93 00:04:40,090 --> 00:04:43,110 In finite difference, we forget about that the function is. 94 00:04:43,110 --> 00:04:46,570 We only remember the value of the function 95 00:04:46,570 --> 00:04:49,680 at these distinct points. 96 00:04:49,680 --> 00:04:53,580 This is finite difference, though. 97 00:04:53,580 --> 00:04:56,890 Do we all have a mental picture of what this does? 98 00:04:56,890 --> 00:04:58,800 What finite difference does? 99 00:04:58,800 --> 00:05:02,000 And then when you have approximated derivative, right? 100 00:05:02,000 --> 00:05:03,890 For example the derivative here, we 101 00:05:03,890 --> 00:05:08,270 can approximate it either as the slope of this line 102 00:05:08,270 --> 00:05:10,530 or as the slope of this line. 103 00:05:10,530 --> 00:05:15,430 Depending on if we do backwards [INAUDIBLE] or [INAUDIBLE]. 104 00:05:15,430 --> 00:05:18,980 And in particular we may approximate the derivative 105 00:05:18,980 --> 00:05:22,740 here, [INAUDIBLE] taking this slope. 106 00:05:22,740 --> 00:05:24,440 If it's backwards [INAUDIBLE] then 107 00:05:24,440 --> 00:05:27,631 we are taking this slope [INAUDIBLE]. 108 00:05:27,631 --> 00:05:30,720 So there are some approximations [INAUDIBLE]. 109 00:05:30,720 --> 00:05:32,670 This is what finite difference does. 110 00:05:32,670 --> 00:05:33,260 OK. 111 00:05:33,260 --> 00:05:36,830 So can I invite somebody to do something that 112 00:05:36,830 --> 00:05:38,390 is completely unpredictable? 113 00:05:38,390 --> 00:05:41,590 Because we are going to be looking at the same thing. 114 00:05:41,590 --> 00:05:43,950 But we're going to be using the same grid. 115 00:05:43,950 --> 00:05:46,165 I'm also going to ask somebody to draw me a function. 116 00:05:46,165 --> 00:05:50,100 But now we have a visual of how finite volume is going 117 00:05:50,100 --> 00:05:52,410 to discretize this function. 118 00:05:52,410 --> 00:05:52,910 OK. 119 00:05:52,910 --> 00:05:55,060 I'm going to type FvDemo. 120 00:05:58,050 --> 00:06:02,260 It's the same plot before-- yes, I'm 121 00:06:02,260 --> 00:06:04,920 going to ask you to draw the function of the same plot. 122 00:06:04,920 --> 00:06:06,530 But can somebody draw-- 123 00:06:06,530 --> 00:06:11,299 [INTERPOSING VOICES] 124 00:06:17,210 --> 00:06:19,537 QIQI WANG: And let's see how a finite volume is going 125 00:06:19,537 --> 00:06:21,595 to discretize the function. 126 00:06:21,595 --> 00:06:22,094 Whoa. 127 00:06:24,721 --> 00:06:25,220 OK. 128 00:06:28,702 --> 00:06:29,987 AUDIENCE: [INAUDIBLE]. 129 00:06:29,987 --> 00:06:30,570 QIQI WANG: OK. 130 00:06:30,570 --> 00:06:33,080 Well, we all see the function in the background, OK? 131 00:06:33,080 --> 00:06:34,140 See that? 132 00:06:34,140 --> 00:06:37,510 This is how finite volume [INAUDIBLE] this function 133 00:06:37,510 --> 00:06:39,620 if we do that. 134 00:06:39,620 --> 00:06:42,280 What do we do? 135 00:06:42,280 --> 00:06:46,120 What does finite volume do? 136 00:06:46,120 --> 00:06:48,250 [INAUDIBLE] the function value anywhere? 137 00:06:54,500 --> 00:06:57,802 Would somebody describe to me what we did? 138 00:06:57,802 --> 00:06:58,774 What finite volume did? 139 00:07:02,662 --> 00:07:06,530 And we're taking like an average value 140 00:07:06,530 --> 00:07:10,150 in between the points, each two grid points. 141 00:07:13,100 --> 00:07:14,050 Right? 142 00:07:14,050 --> 00:07:17,040 In finite difference, we talked about grid points. 143 00:07:17,040 --> 00:07:20,192 Because we are exploring the value of the function 144 00:07:20,192 --> 00:07:22,170 at these grid points. 145 00:07:22,170 --> 00:07:25,450 In finite volume, we are talking about cells 146 00:07:25,450 --> 00:07:27,809 or controlled volumes, right? 147 00:07:27,809 --> 00:07:33,640 Each space is in two points, or controlled volume. 148 00:07:33,640 --> 00:07:37,260 We are discretizing the function by storing 149 00:07:37,260 --> 00:07:40,000 the average value of the function 150 00:07:40,000 --> 00:07:45,210 inside each controlled volume, or inside each cell. 151 00:07:45,210 --> 00:07:46,140 OK? 152 00:07:46,140 --> 00:07:49,320 So in particular, if we look at this one, 153 00:07:49,320 --> 00:07:52,030 we will have the [INAUDIBLE]. 154 00:07:52,030 --> 00:07:57,440 But [INAUDIBLE] for the average difference. 155 00:07:57,440 --> 00:07:57,940 OK. 156 00:07:57,940 --> 00:08:02,438 And as we see, when we use finite volume, 157 00:08:02,438 --> 00:08:05,960 we need to evolve these averages. 158 00:08:05,960 --> 00:08:09,270 And we know the function value. 159 00:08:09,270 --> 00:08:10,686 In finite difference, when we look 160 00:08:10,686 --> 00:08:13,275 at the function value, and the function value, of course, 161 00:08:13,275 --> 00:08:15,030 will satisfy the PDE. 162 00:08:15,030 --> 00:08:19,230 And the PDE in order to solve the PDE, 163 00:08:19,230 --> 00:08:22,860 we need to approximate the spatial derivative. 164 00:08:22,860 --> 00:08:24,652 Here, we need to evolve this average. 165 00:08:27,370 --> 00:08:30,530 And we are going to look at what the differential equations 166 00:08:30,530 --> 00:08:33,679 on this average can [INAUDIBLE], how these averages cannot 167 00:08:33,679 --> 00:08:36,672 satisfy the PDE. 168 00:08:36,672 --> 00:08:39,558 It satisfies something else. 169 00:08:39,558 --> 00:08:41,840 And this is what finite volume does. 170 00:08:41,840 --> 00:08:45,644 It is going to derive from the PDE 171 00:08:45,644 --> 00:08:49,030 a different set of equations than describe the evolution 172 00:08:49,030 --> 00:08:51,180 of these averages. 173 00:08:51,180 --> 00:08:55,210 And so this equation set describes the evolution 174 00:08:55,210 --> 00:08:57,680 of the averages. 175 00:08:57,680 --> 00:08:58,590 OK. 176 00:08:58,590 --> 00:09:00,570 So this is a conceptual difference 177 00:09:00,570 --> 00:09:03,660 between finite difference and finite volume. 178 00:09:03,660 --> 00:09:08,210 And when we start finite element, 179 00:09:08,210 --> 00:09:13,580 I'm also going to-- well, let me not show you today. 180 00:09:13,580 --> 00:09:14,170 OK? 181 00:09:14,170 --> 00:09:17,250 If you're interested in it, you can just go run it at home. 182 00:09:17,250 --> 00:09:20,170 I'm going to give you the three scripts. 183 00:09:20,170 --> 00:09:23,540 If interested, you can run it at home and see what you get. 184 00:09:23,540 --> 00:09:25,040 [INAUDIBLE] who don't have a tablet, 185 00:09:25,040 --> 00:09:28,750 you can go with your mouse on the function. 186 00:09:28,750 --> 00:09:33,380 So I'm going to give you the scripts later on. 187 00:09:33,380 --> 00:09:39,280 But right now let me first focus on and go to our last lecture 188 00:09:39,280 --> 00:09:42,620 folder which is 09. 189 00:09:42,620 --> 00:09:45,630 And I'm going to show you a little bit of what exactly 190 00:09:45,630 --> 00:09:47,930 we did. 191 00:09:47,930 --> 00:09:52,040 The two dimensional advection question. 192 00:09:52,040 --> 00:09:53,080 OK. 193 00:09:53,080 --> 00:09:55,900 So this is the two dimensional advection equation. 194 00:09:55,900 --> 00:10:02,710 I think Professor Willcox ran that last class, right? 195 00:10:02,710 --> 00:10:06,910 We have this wavelike thing going on there. 196 00:10:06,910 --> 00:10:09,877 Of course, this is not as advanced as your project. 197 00:10:09,877 --> 00:10:15,280 Because we are looking at the constant cx and cy. 198 00:10:15,280 --> 00:10:19,240 We're not looking at a cx and cy responding to the [INAUDIBLE]. 199 00:10:19,240 --> 00:10:21,160 So this is actually a simpler script 200 00:10:21,160 --> 00:10:28,956 than what you guys wrote in the project. 201 00:10:28,956 --> 00:10:31,300 But one thing I'm doing differently from the project 202 00:10:31,300 --> 00:10:35,900 is that I'm using implicit methods 203 00:10:35,900 --> 00:10:37,570 in solving this equation. 204 00:10:40,570 --> 00:10:41,070 [INAUDIBLE] 205 00:10:45,800 --> 00:10:49,850 So in using the implicit time-integration method, 206 00:10:49,850 --> 00:10:55,974 I have to use the matrix form of the finite difference. 207 00:10:55,974 --> 00:10:57,890 Right? 208 00:10:57,890 --> 00:11:00,530 Does everybody understand why by switching 209 00:11:00,530 --> 00:11:04,160 from explicit to implicit I need to use the matrix form 210 00:11:04,160 --> 00:11:07,040 of the finite difference? 211 00:11:07,040 --> 00:11:07,540 You don't? 212 00:11:10,520 --> 00:11:11,436 AUDIENCE: [INAUDIBLE]. 213 00:11:15,819 --> 00:11:19,290 Does the matrix only have a times b plus something 214 00:11:19,290 --> 00:11:21,250 else times [INAUDIBLE]? 215 00:11:21,250 --> 00:11:22,450 QIQI WANG: Exactly. 216 00:11:22,450 --> 00:11:24,960 The reason I have to use the matrix form 217 00:11:24,960 --> 00:11:29,350 is because in an implicit time-integration scheme, 218 00:11:29,350 --> 00:11:33,690 the spatial derivative is operated not only on time step 219 00:11:33,690 --> 00:11:38,450 n but also on time step n plus 1, which is not known 220 00:11:38,450 --> 00:11:40,600 before I do the time step. 221 00:11:43,150 --> 00:11:46,680 I have a spatial differential operator operating 222 00:11:46,680 --> 00:11:50,260 on some unknown solution. 223 00:11:50,260 --> 00:11:53,670 So I cannot compute it explicitly. 224 00:11:53,670 --> 00:11:57,820 I have to move that curve to the left hand side of the question 225 00:11:57,820 --> 00:11:58,921 and solve it. 226 00:12:01,570 --> 00:12:08,850 So let me make a new page and show you what this is. 227 00:12:08,850 --> 00:12:10,741 Page options. 228 00:12:10,741 --> 00:12:11,240 Insert. 229 00:12:16,317 --> 00:12:16,817 OK. 230 00:12:16,817 --> 00:12:18,030 It's more like this. 231 00:12:18,030 --> 00:12:19,980 [INAUDIBLE] 232 00:12:19,980 --> 00:12:21,940 OK. 233 00:12:21,940 --> 00:12:24,856 So in an explicit scheme which would be partial 234 00:12:24,856 --> 00:12:31,520 u-partial t equals to, for example, 235 00:12:31,520 --> 00:12:36,340 a simplified version of what you guys did is this, right? 236 00:12:36,340 --> 00:12:39,970 This is like the simplified version of what you did. 237 00:12:39,970 --> 00:12:44,940 And if I do explicit time step, and if I use forward Euler, 238 00:12:44,940 --> 00:12:49,090 then I can do U of n plus one minus Un over delta t. 239 00:12:49,090 --> 00:12:51,840 That is an approximation of the time derivative. 240 00:12:55,470 --> 00:12:56,080 OK. 241 00:12:56,080 --> 00:12:57,430 I can do matrix form. 242 00:12:57,430 --> 00:12:58,940 I can do non-matrix form. 243 00:12:58,940 --> 00:13:06,360 But whatever I do, I'm making-- I'm either evaluating distance 244 00:13:06,360 --> 00:13:09,370 in matrix form or not in matrix form. 245 00:13:09,370 --> 00:13:12,094 But I'm actually computing the differential operator 246 00:13:12,094 --> 00:13:14,816 operated on Un, which is known. 247 00:13:14,816 --> 00:13:17,877 The fact that Un is known makes it possible 248 00:13:17,877 --> 00:13:23,800 for me to evaluate this without [INAUDIBLE] the matrix A. 249 00:13:23,800 --> 00:13:26,200 Right? 250 00:13:26,200 --> 00:13:29,380 This is explicit. 251 00:13:29,380 --> 00:13:38,280 But what if I need to do this? 252 00:13:38,280 --> 00:13:43,250 What if I want to use an implicit method? 253 00:13:43,250 --> 00:13:48,010 For example, if I need to do backward Euler, 254 00:13:48,010 --> 00:13:54,447 then the difference is that these spatial finite difference 255 00:13:54,447 --> 00:13:58,110 operator is operated on not Un but Un plus one. 256 00:14:01,220 --> 00:14:05,250 Well, yes. 257 00:14:05,250 --> 00:14:13,720 Where a is finite difference, approximation 258 00:14:13,720 --> 00:14:16,400 of minus partial u-partial x minus partial u-partial y. 259 00:14:19,120 --> 00:14:20,540 Right? 260 00:14:20,540 --> 00:14:21,040 OK. 261 00:14:21,040 --> 00:14:25,200 So in this case, I do not know what we have for [INAUDIBLE]. 262 00:14:25,200 --> 00:14:32,120 Therefore, I cannot just evaluate-- I can no longer do-- 263 00:14:32,120 --> 00:14:38,200 most of you did, which is taking a bunch of indexing with this U 264 00:14:38,200 --> 00:14:43,900 and subtract from doing the indexing or doing the circular 265 00:14:43,900 --> 00:14:46,980 shifting of U and subtracting it from each other. 266 00:14:46,980 --> 00:14:47,895 I cannot do that. 267 00:14:47,895 --> 00:14:49,900 Because I don't have the n plus one. 268 00:14:49,900 --> 00:14:56,300 What I need to do instead is to move all the Un plus one terms, 269 00:14:56,300 --> 00:15:00,660 is I need to move all these blue terms to the left hand 270 00:15:00,660 --> 00:15:04,320 side of the equation and move the green terms 271 00:15:04,320 --> 00:15:06,870 to the right hand side of the equation. 272 00:15:06,870 --> 00:15:08,190 So this is what I need to do. 273 00:15:08,190 --> 00:15:10,670 I need to move these to this side. 274 00:15:10,670 --> 00:15:14,940 So what I end up getting is identity 275 00:15:14,940 --> 00:15:20,730 over delta t minus A of Un plus one is 276 00:15:20,730 --> 00:15:24,440 equal to Un over delta t. 277 00:15:24,440 --> 00:15:28,724 So I [? initially ?] was so busy [INAUDIBLE] I did not 278 00:15:28,724 --> 00:15:34,660 [INAUDIBLE] must have [? deflated ?] A, constructed. 279 00:15:34,660 --> 00:15:35,160 Right? 280 00:15:35,160 --> 00:15:38,500 So that is why, when I am solving-- 281 00:15:38,500 --> 00:15:41,000 when I'm using an implicit scheme, 282 00:15:41,000 --> 00:15:44,574 I need to have the matrix form of the finite difference 283 00:15:44,574 --> 00:15:45,074 operator. 284 00:15:47,920 --> 00:15:53,564 OK so this is how I did it in the finite difference matrix. 285 00:15:53,564 --> 00:16:02,370 I am taking-- so I am constructing 286 00:16:02,370 --> 00:16:08,540 the same derivative matrix I constructed in the [INAUDIBLE] 287 00:16:08,540 --> 00:16:10,030 case. 288 00:16:10,030 --> 00:16:13,800 This is-- if you let me-- OK. 289 00:16:16,800 --> 00:16:17,950 Let me run this. 290 00:16:17,950 --> 00:16:20,640 I get a grid that looks like this. 291 00:16:20,640 --> 00:16:33,690 And then when I run this, getting-- If I do a spy on Ax, 292 00:16:33,690 --> 00:16:35,660 I'm getting the same matrix as we 293 00:16:35,660 --> 00:16:38,768 get in a one-dimensional case. 294 00:16:38,768 --> 00:16:44,256 On the y diagonal, I think we have something on the diagonal 295 00:16:44,256 --> 00:16:44,756 [INAUDIBLE]. 296 00:16:47,550 --> 00:16:49,520 Remember this? 297 00:16:49,520 --> 00:16:56,070 And Ay has the same structure. 298 00:16:56,070 --> 00:16:59,513 It is almost identical, except for the dimension 299 00:16:59,513 --> 00:17:02,450 are a little bit different because the y direction has 300 00:17:02,450 --> 00:17:06,060 a different number of grid points as the x direction. 301 00:17:06,060 --> 00:17:09,540 Then I did something interesting. 302 00:17:09,540 --> 00:17:19,588 I did a run of Ax with Iy. 303 00:17:19,588 --> 00:17:23,484 So Iy is just an identity matrix. 304 00:17:23,484 --> 00:17:29,350 So I did a [INAUDIBLE] of Ax in Iy. 305 00:17:29,350 --> 00:17:33,340 To show what [? connect a product ?] does, 306 00:17:33,340 --> 00:17:42,430 I think I just want to do a spy of the product. 307 00:17:42,430 --> 00:17:44,280 This is what gets me. 308 00:17:44,280 --> 00:17:45,210 OK. 309 00:17:45,210 --> 00:17:51,183 You see, what I'm getting-- let me zoom in. 310 00:17:51,183 --> 00:17:53,498 Let me zoom in using my pen. 311 00:17:53,498 --> 00:17:55,350 I think it's a little better. 312 00:17:55,350 --> 00:18:00,064 So what I'm getting is a bi-diagonal matrix. 313 00:18:00,064 --> 00:18:07,490 But the [INAUDIBLE] I'm replacing each element in Ax 314 00:18:07,490 --> 00:18:09,430 with that identity matrix. 315 00:18:13,430 --> 00:18:18,470 So now this [INAUDIBLE] this is a series of dots. 316 00:18:18,470 --> 00:18:20,380 Each dot is one entry of a matrix. 317 00:18:22,890 --> 00:18:25,646 There is a bunch of elements over here. 318 00:18:25,646 --> 00:18:28,630 And there is a bunch of elements over here. 319 00:18:28,630 --> 00:18:31,925 So when I'm eventually doing is, OK. 320 00:18:31,925 --> 00:18:34,230 If I modify something with this matrix, 321 00:18:34,230 --> 00:18:38,806 I'm subtracting-- so let me look at this one-- 322 00:18:38,806 --> 00:18:40,600 I'm subtracting the value corresponding 323 00:18:40,600 --> 00:18:48,960 to this column from the elements corresponding to this column. 324 00:18:48,960 --> 00:18:53,410 So I'm subtracting two values that 325 00:18:53,410 --> 00:18:58,875 are spaced apart with the spacing exactly equal 326 00:18:58,875 --> 00:19:08,500 to the number of x elements. 327 00:19:08,500 --> 00:19:09,000 Right? 328 00:19:11,920 --> 00:19:15,755 So in terms of spacing, if I have-- let me 329 00:19:15,755 --> 00:19:16,990 insert another one. 330 00:19:26,025 --> 00:19:38,600 If I'm organizing U2 1, U2 2, et cetera, U 2nx, et cetera, 331 00:19:38,600 --> 00:19:44,730 to Uny1, et cetera, Uny2. 332 00:19:44,730 --> 00:19:48,820 So if I'm organizing my array like this and I'm 333 00:19:48,820 --> 00:19:54,014 going through-- [INAUDIBLE]. 334 00:20:09,770 --> 00:20:10,620 OK. 335 00:20:10,620 --> 00:20:15,230 And if I'm organizing my array like this, 336 00:20:15,230 --> 00:20:18,320 I'm organizing my array as this one 337 00:20:18,320 --> 00:20:20,710 goes to this one goes to this one goes to this one. 338 00:20:20,710 --> 00:20:23,500 So I'm storing this first in memory and then 339 00:20:23,500 --> 00:20:25,280 this one and then this one. 340 00:20:25,280 --> 00:20:29,930 And then you want to two in memory and following this. 341 00:20:29,930 --> 00:20:33,762 So I am storing one column the other column 342 00:20:33,762 --> 00:20:37,000 then another column, et cetera. 343 00:20:37,000 --> 00:20:42,330 Then if my two elements are spaced apart 344 00:20:42,330 --> 00:20:45,558 with ny elements in memory, then it 345 00:20:45,558 --> 00:20:49,174 is the exact same, the adjacent elements in the x direction. 346 00:20:53,530 --> 00:20:59,030 That is how my elements are stored in memory. 347 00:20:59,030 --> 00:21:05,140 So which means, if I'm taking derivative in the x direction, 348 00:21:05,140 --> 00:21:07,930 my spacing should be ny. 349 00:21:07,930 --> 00:21:15,700 And what happens if I take the derivative in the y direction? 350 00:21:15,700 --> 00:21:18,410 What if I do kron of Ix with Ay? 351 00:21:30,950 --> 00:21:31,450 Oh. 352 00:21:31,450 --> 00:21:32,370 OK. 353 00:21:32,370 --> 00:21:35,650 Yes, I mean this. 354 00:21:35,650 --> 00:21:36,860 OK. 355 00:21:36,860 --> 00:21:41,170 When I go to something like this, 356 00:21:41,170 --> 00:21:43,330 so if you look at each block-- so I'm 357 00:21:43,330 --> 00:21:46,034 getting a periodic structure. 358 00:21:46,034 --> 00:21:56,350 And each block [INAUDIBLE] is exactly 359 00:21:56,350 --> 00:21:59,250 the same as the one dimensional derivative matrix. 360 00:21:59,250 --> 00:22:04,615 And once we zoom in over here-- oh, you can't see anymore. 361 00:22:04,615 --> 00:22:06,930 But these are individual dots. 362 00:22:06,930 --> 00:22:10,040 So when we take the derivative in the y direction, 363 00:22:10,040 --> 00:22:13,550 we are taking [INAUDIBLE] adjacent values 364 00:22:13,550 --> 00:22:19,130 in the array, which is the adjacent value actually 365 00:22:19,130 --> 00:22:21,355 in the y direction. 366 00:22:21,355 --> 00:22:23,590 So adjacent values in the x direction 367 00:22:23,590 --> 00:22:28,154 are actually spaced over by ny in the memory. 368 00:22:28,154 --> 00:22:31,220 So these values in the y-direction 369 00:22:31,220 --> 00:22:33,940 are spaced with only one in memory. 370 00:22:33,940 --> 00:22:38,270 That is why we need to use the kron in the matrix form. 371 00:22:41,290 --> 00:22:41,790 OK. 372 00:22:41,790 --> 00:22:42,734 Questions on that? 373 00:22:48,880 --> 00:22:50,070 OK. 374 00:22:50,070 --> 00:22:56,890 Now let's go to our finite volume analysis. 375 00:22:56,890 --> 00:22:57,390 OK. 376 00:22:57,390 --> 00:22:59,290 In finding the volume, we are ultimately 377 00:22:59,290 --> 00:23:01,590 going to two dimensional too. 378 00:23:01,590 --> 00:23:03,440 Today, we are just going to focus 379 00:23:03,440 --> 00:23:05,650 on one dimension finite volume. 380 00:23:05,650 --> 00:23:15,380 And again, in finite volume-- OK. 381 00:23:15,380 --> 00:23:19,990 Let me go back to our last [INAUDIBLE]. 382 00:23:19,990 --> 00:23:22,210 In finite volume, we draw a function. 383 00:23:22,210 --> 00:23:25,900 And obviously in the function we are only 384 00:23:25,900 --> 00:23:30,390 storing the averages inside each cell. 385 00:23:30,390 --> 00:23:30,950 All right. 386 00:23:30,950 --> 00:23:37,986 So let's look at why that is, what kind of equations 387 00:23:37,986 --> 00:23:39,575 can finite volume solve? 388 00:23:39,575 --> 00:23:43,690 And why does it solve this kind of equations well? 389 00:23:43,690 --> 00:23:49,650 Finite volume only works if you have a conservation law. 390 00:23:49,650 --> 00:23:53,630 Finite volume is not for all differential equations. 391 00:23:53,630 --> 00:23:56,900 It works only when you have something 392 00:23:56,900 --> 00:24:00,626 that can be formulated in terms of conservation laws. 393 00:24:00,626 --> 00:24:02,126 And what does conservation law mean? 394 00:24:02,126 --> 00:24:04,860 Conservation laws mean the equations 395 00:24:04,860 --> 00:24:06,640 that are in this form. 396 00:24:11,970 --> 00:24:12,470 OK. 397 00:24:12,470 --> 00:24:13,594 You can have a [INAUDIBLE]. 398 00:24:13,594 --> 00:24:16,930 But like you can have a [INAUDIBLE] here. 399 00:24:16,930 --> 00:24:17,740 All right. 400 00:24:17,740 --> 00:24:20,890 So this is conservation laws. 401 00:24:20,890 --> 00:24:24,970 It's some kind of a conservative quantity. 402 00:24:24,970 --> 00:24:30,242 Can be mass, momentum energy, some molecules, 403 00:24:30,242 --> 00:24:34,580 number of [INAUDIBLE], number of people. 404 00:24:34,580 --> 00:24:40,600 Something that can be described as conservative. 405 00:24:40,600 --> 00:24:44,236 This F is the flux. 406 00:24:44,236 --> 00:24:49,376 The flux is the number of quantities u 407 00:24:49,376 --> 00:24:54,270 that goes through a boundary per unit amount of time. 408 00:24:54,270 --> 00:24:54,770 OK. 409 00:24:54,770 --> 00:24:57,812 That's what flux means. 410 00:24:57,812 --> 00:24:59,650 All right. 411 00:24:59,650 --> 00:25:01,950 And the specific force, the force 412 00:25:01,950 --> 00:25:09,075 is how much quantity, again described in u, is generated, 413 00:25:09,075 --> 00:25:14,260 comes out from nowhere, per unit amount of time. 414 00:25:14,260 --> 00:25:17,530 This is a case, for example, if you have some kind of a-- if 415 00:25:17,530 --> 00:25:20,455 u is describing the amount of molecules 416 00:25:20,455 --> 00:25:25,776 and F is the number of molecules generated in an amount of time 417 00:25:25,776 --> 00:25:29,330 if you have a chemical reaction or things like that. 418 00:25:29,330 --> 00:25:32,070 All right. 419 00:25:32,070 --> 00:25:39,650 And if u is describing momentum, then F is the flux of momentum 420 00:25:39,650 --> 00:25:41,500 through the boundary. 421 00:25:41,500 --> 00:25:46,108 And S would be something like the [INAUDIBLE] of gravity. 422 00:25:46,108 --> 00:25:48,470 Something like that. 423 00:25:48,470 --> 00:25:48,970 Right? 424 00:25:48,970 --> 00:25:50,803 Is it clear what the conservation law means? 425 00:25:55,160 --> 00:25:59,000 The conservation law really makes even more sense 426 00:25:59,000 --> 00:26:01,560 if you try to integrate it. 427 00:26:01,560 --> 00:26:02,270 OK? 428 00:26:02,270 --> 00:26:04,090 So this is the differential form. 429 00:26:09,350 --> 00:26:12,560 Now if you try to integrate the conservation law, 430 00:26:12,560 --> 00:26:14,170 it even makes more sense. 431 00:26:14,170 --> 00:26:17,610 And by integrate, I don't mean integrating time. 432 00:26:17,610 --> 00:26:20,250 I mean integrating space. 433 00:26:20,250 --> 00:26:24,340 So let's integrate over any control volume. 434 00:26:24,340 --> 00:26:29,726 And control volume is described as an interval from L to R. L 435 00:26:29,726 --> 00:26:31,100 is the left hand of the interval. 436 00:26:31,100 --> 00:26:33,962 R is the right hand of the interval. 437 00:26:33,962 --> 00:26:36,030 So the integral of left hand side 438 00:26:36,030 --> 00:26:41,960 has to be equal to the integral of the right hand side of S, 439 00:26:41,960 --> 00:26:44,890 both are dx. 440 00:26:44,890 --> 00:26:52,250 So let's do some manipulation to this integral form. 441 00:26:52,250 --> 00:26:58,665 So first of all, the integrative time derivative in space. 442 00:26:58,665 --> 00:27:04,590 Because time and space are two independent variables, 443 00:27:04,590 --> 00:27:08,240 the integral in space [INAUDIBLE] 444 00:27:08,240 --> 00:27:09,950 with the derivative in time. 445 00:27:12,910 --> 00:27:15,840 So the integral in space of a time derivative 446 00:27:15,840 --> 00:27:20,280 is equal to the time derivative of the integral in space. 447 00:27:23,880 --> 00:27:29,840 The first term can be written as this. 448 00:27:29,840 --> 00:27:33,860 And this is the time derivative of [INAUDIBLE] 449 00:27:33,860 --> 00:27:36,100 using that control volume. 450 00:27:36,100 --> 00:27:39,440 If U is density, then this is the amount 451 00:27:39,440 --> 00:27:41,830 of mass inside the control volume. 452 00:27:41,830 --> 00:27:47,768 If U is the density of [INAUDIBLE] like molecules, 453 00:27:47,768 --> 00:27:50,960 density is the total number of molecules in that control 454 00:27:50,960 --> 00:27:52,630 volume. 455 00:27:52,630 --> 00:27:53,390 OK. 456 00:27:53,390 --> 00:27:55,340 The second term. 457 00:27:55,340 --> 00:27:57,525 The second term is not a timed derivative. 458 00:27:57,525 --> 00:27:59,980 It is a spatial derivative. 459 00:27:59,980 --> 00:28:02,570 Now what is the spatial integral of the spatial derivative? 460 00:28:06,110 --> 00:28:07,080 The function itself. 461 00:28:07,080 --> 00:28:07,670 Exactly. 462 00:28:07,670 --> 00:28:20,460 So it is F of U at R minus F of U at L. All right? 463 00:28:20,460 --> 00:28:23,480 And let's actually move this to the right hand side. 464 00:28:23,480 --> 00:28:25,720 Because it makes more sense. 465 00:28:25,720 --> 00:28:27,620 Let's move it to the right hand side 466 00:28:27,620 --> 00:28:30,770 and put a minus sign here, put a plus sign here. 467 00:28:30,770 --> 00:28:31,270 OK. 468 00:28:31,270 --> 00:28:36,630 So this is the result of the spatial derivative term. 469 00:28:36,630 --> 00:28:38,360 And the [INAUDIBLE] that's [INAUDIBLE]. 470 00:28:43,310 --> 00:28:44,250 OK. 471 00:28:44,250 --> 00:28:47,252 So this is what the integral is going to give us. 472 00:28:50,410 --> 00:28:52,765 Now let's try to interpret that integral. 473 00:28:52,765 --> 00:28:55,990 The time derivative of the total quantity within the control 474 00:28:55,990 --> 00:29:00,840 volume is equal to the flux at the left 475 00:29:00,840 --> 00:29:04,230 minus the flux at the right. 476 00:29:04,230 --> 00:29:07,622 This is what goes into the control volume. 477 00:29:07,622 --> 00:29:10,280 This is what goes on the control volume. 478 00:29:15,190 --> 00:29:17,280 So makes sense? 479 00:29:17,280 --> 00:29:20,140 The rate of change of the amount of stuff inside the control 480 00:29:20,140 --> 00:29:22,570 volume is equal to the rate of change for the stuff 481 00:29:22,570 --> 00:29:27,610 going in minus the rate of stuff coming out 482 00:29:27,610 --> 00:29:31,815 plus the rate of stuff generated inside the control volume. 483 00:29:35,280 --> 00:29:37,030 So this is the integral form. 484 00:29:42,742 --> 00:29:48,610 This is the integral form of the conservation law. 485 00:29:48,610 --> 00:29:51,670 Now why is it important? 486 00:29:51,670 --> 00:29:54,163 And how does it relate to finite volume method? 487 00:29:59,476 --> 00:30:01,780 Because this is the equation we are solving 488 00:30:01,780 --> 00:30:03,990 in finite volume method. 489 00:30:03,990 --> 00:30:06,310 This is the equation we're solving in finite difference 490 00:30:06,310 --> 00:30:06,740 method. 491 00:30:06,740 --> 00:30:07,239 Right? 492 00:30:07,239 --> 00:30:10,254 We stick with this kind of equation. 493 00:30:10,254 --> 00:30:12,910 Because in finite difference method, the U, 494 00:30:12,910 --> 00:30:16,610 we are storing the value of the solution U 495 00:30:16,610 --> 00:30:18,890 at individual points. 496 00:30:18,890 --> 00:30:20,050 Right? 497 00:30:20,050 --> 00:30:26,390 And that is why we need to approximate the distance, 498 00:30:26,390 --> 00:30:28,984 approximate the spatial derivatives [? and it ?] kind 499 00:30:28,984 --> 00:30:31,580 of a finite difference method. 500 00:30:31,580 --> 00:30:39,160 And then we can do [INAUDIBLE] for U [INAUDIBLE]. 501 00:30:39,160 --> 00:30:42,230 With finite volume method, we are not 502 00:30:42,230 --> 00:30:46,720 interested in the solution at individual grid points. 503 00:30:46,720 --> 00:30:52,090 Instead, we are storing the average of the solutions. 504 00:30:52,090 --> 00:30:55,340 And the average of the solutions, 505 00:30:55,340 --> 00:30:57,110 what is a mathematical description 506 00:30:57,110 --> 00:30:59,980 of an average of a solution in a control volume? 507 00:31:02,770 --> 00:31:07,390 What is the average when we look at the amount of stuff 508 00:31:07,390 --> 00:31:07,890 [INAUDIBLE]? 509 00:31:11,880 --> 00:31:13,650 Yeah. 510 00:31:13,650 --> 00:31:15,974 It's the amount of stuff in space. 511 00:31:15,974 --> 00:31:19,820 If I ask you to write a mathematical formula 512 00:31:19,820 --> 00:31:24,640 of the value of the average as a function of-- in terms 513 00:31:24,640 --> 00:31:27,470 of the function within these intervals, what is it? 514 00:31:31,113 --> 00:31:33,899 AUDIENCE: [INAUDIBLE]. 515 00:31:33,899 --> 00:31:34,690 QIQI WANG: Exactly. 516 00:31:34,690 --> 00:31:39,030 The average would be equal to the integral of this function 517 00:31:39,030 --> 00:31:43,635 from 0.6 is 0.7 divided by the width 518 00:31:43,635 --> 00:31:47,450 of the integral, which is 0.1. 519 00:31:47,450 --> 00:31:50,280 That is what the average means. 520 00:31:50,280 --> 00:31:53,440 And now we have derived the integral form 521 00:31:53,440 --> 00:31:55,596 of the differential equation. 522 00:31:55,596 --> 00:31:59,190 And it describes the evolution of the integral. 523 00:31:59,190 --> 00:32:00,970 Do we have the evolution of the average? 524 00:32:05,870 --> 00:32:06,420 Of course. 525 00:32:06,420 --> 00:32:11,130 We just divide this thing by R minus L, right? 526 00:32:11,130 --> 00:32:13,950 We just divide the whole thing by R minus L. 527 00:32:13,950 --> 00:32:22,130 Then this whole term actually-- let 528 00:32:22,130 --> 00:32:25,140 me include the time derivative-- this 529 00:32:25,140 --> 00:32:29,460 is the d dt of the U average. 530 00:32:32,000 --> 00:32:32,850 Right? 531 00:32:32,850 --> 00:32:35,910 This whole term would be the time derivative 532 00:32:35,910 --> 00:32:42,800 of the average value of the function between L and R. 533 00:32:42,800 --> 00:32:46,210 The time derivative of the average value between L and R 534 00:32:46,210 --> 00:32:49,390 is just equal to the amount of stuff 535 00:32:49,390 --> 00:32:53,290 going in minus the amount of stuff going out 536 00:32:53,290 --> 00:32:58,240 divided by L over R. Plus the average amount of stuff 537 00:32:58,240 --> 00:33:02,702 generated in the control volume. 538 00:33:02,702 --> 00:33:04,140 Right? 539 00:33:04,140 --> 00:33:07,356 So the reason we derive the integral form 540 00:33:07,356 --> 00:33:12,390 from the differential form is because this integral form 541 00:33:12,390 --> 00:33:16,546 is what is satisfied by the finite volume method, 542 00:33:16,546 --> 00:33:20,650 by the volume average. 543 00:33:20,650 --> 00:33:24,420 So we use this form for the finite volume method. 544 00:33:24,420 --> 00:33:28,991 Now this form has distinct advantage over this form. 545 00:33:28,991 --> 00:33:29,491 Why? 546 00:33:32,380 --> 00:33:38,780 Why is sometimes this form valid while this form is invalid? 547 00:33:38,780 --> 00:33:41,780 Can you guys think of a case? 548 00:33:41,780 --> 00:33:44,157 AUDIENCE: [INAUDIBLE]. 549 00:33:44,157 --> 00:33:44,823 QIQI WANG: Yeah. 550 00:33:44,823 --> 00:33:47,060 Of course, this has derivatives [INAUDIBLE]. 551 00:33:47,060 --> 00:33:48,560 This has a spatial derivative. 552 00:33:48,560 --> 00:33:52,188 This does not have a spatial derivative. 553 00:33:52,188 --> 00:33:53,160 Right? 554 00:33:53,160 --> 00:33:56,255 So in what cases can you not have a derivative? 555 00:33:56,255 --> 00:33:58,294 AUDIENCE: [INAUDIBLE]. 556 00:33:58,294 --> 00:33:58,960 QIQI WANG: Yeah. 557 00:33:58,960 --> 00:34:00,043 We can have singularities. 558 00:34:00,043 --> 00:34:04,705 What kind of singularities have we 559 00:34:04,705 --> 00:34:11,860 seen that have no derivative? 560 00:34:11,860 --> 00:34:13,345 AUDIENCE: [INAUDIBLE]. 561 00:34:13,345 --> 00:34:14,335 QIQI WANG: Huh. 562 00:34:14,335 --> 00:34:15,325 AUDIENCE: [INAUDIBLE]. 563 00:34:15,325 --> 00:34:17,310 QIQI WANG: [INAUDIBLE]. 564 00:34:17,310 --> 00:34:19,090 Shocks. 565 00:34:19,090 --> 00:34:19,720 Shocks. 566 00:34:19,720 --> 00:34:20,220 Right? 567 00:34:20,220 --> 00:34:23,090 We saw-- when you say shocks in solving this kind 568 00:34:23,090 --> 00:34:25,380 of differential equation. 569 00:34:25,380 --> 00:34:30,449 Once we have a shock wave, you have a discontinuity over x. 570 00:34:30,449 --> 00:34:34,550 Do you accept you can take the derivative of a shock wave? 571 00:34:34,550 --> 00:34:35,816 No. 572 00:34:35,816 --> 00:34:38,209 Actually, I'm going to show you. 573 00:34:38,209 --> 00:34:40,250 If it applies to you to define a different method 574 00:34:40,250 --> 00:34:44,740 to solve a differential equation with a shock wave, 575 00:34:44,740 --> 00:34:46,660 sometimes you can still [INAUDIBLE]. 576 00:34:50,500 --> 00:34:52,354 And you only get correct solution 577 00:34:52,354 --> 00:34:53,770 when you use finite volume method, 578 00:34:53,770 --> 00:34:57,099 because finite volume method doesn't care 579 00:34:57,099 --> 00:34:58,990 if it has shock waves or not. 580 00:34:58,990 --> 00:35:02,151 It solves the integral form of the equation, which 581 00:35:02,151 --> 00:35:06,110 is immune to shock waves, and not 582 00:35:06,110 --> 00:35:08,750 even taking spatial derivative. 583 00:35:08,750 --> 00:35:13,280 As long as I can integrate, I can solve the equation. 584 00:35:13,280 --> 00:35:17,580 And the solutions with shock waves have their integral. 585 00:35:17,580 --> 00:35:19,310 All right. 586 00:35:19,310 --> 00:35:22,060 So before we go into finite volume method 587 00:35:22,060 --> 00:35:26,960 and look at its solution, let's review 588 00:35:26,960 --> 00:35:29,880 how the solutions behave. 589 00:35:29,880 --> 00:35:34,390 And I think we can do that review best 590 00:35:34,390 --> 00:35:38,460 if we just ran the Burgers equation phase again. 591 00:35:38,460 --> 00:35:39,620 All right. 592 00:35:39,620 --> 00:35:43,710 So Burgers' equation. 593 00:35:43,710 --> 00:35:46,530 I'm going to draw the initial condition this time. 594 00:35:46,530 --> 00:35:49,290 I haven't drawn it. 595 00:35:49,290 --> 00:35:52,070 So I'm just going to draw something that goes up and goes 596 00:35:52,070 --> 00:35:53,990 down and goes up again. 597 00:35:53,990 --> 00:35:54,490 OK. 598 00:35:54,490 --> 00:36:01,310 And let's look at how the solution evolves. 599 00:36:01,310 --> 00:36:01,920 OK. 600 00:36:01,920 --> 00:36:04,820 So this is a typical conservation law. [INAUDIBLE] 601 00:36:04,820 --> 00:36:07,390 is one of the simplest conservation laws. 602 00:36:07,390 --> 00:36:11,540 And remember, the solution moves with a speed proportional 603 00:36:11,540 --> 00:36:14,600 to the value itself. 604 00:36:14,600 --> 00:36:17,650 So if I have a high value and a positive value, 605 00:36:17,650 --> 00:36:18,720 I move toward the right. 606 00:36:18,720 --> 00:36:22,470 If I have a negative value, I move towards the left. 607 00:36:22,470 --> 00:36:22,970 Right? 608 00:36:22,970 --> 00:36:24,520 This is even more dramatic than the case 609 00:36:24,520 --> 00:36:25,770 where everybody's [INAUDIBLE]. 610 00:36:30,870 --> 00:36:34,840 This is the solution we are [INAUDIBLE]. 611 00:36:34,840 --> 00:36:40,462 So if I have something moving towards the right and I 612 00:36:40,462 --> 00:36:43,640 have something moving towards the left, 613 00:36:43,640 --> 00:36:47,878 and you can very clearly see a shock wave forming over here. 614 00:36:51,060 --> 00:36:57,955 And we can know what the solution is really intuitively 615 00:36:57,955 --> 00:37:03,060 because we know at each point, the solution 616 00:37:03,060 --> 00:37:09,290 moves proportional to the value, which 617 00:37:09,290 --> 00:37:12,760 if you look at the plot with [? accuracy ?] 618 00:37:12,760 --> 00:37:21,100 in space while at the same time, then the characeristic lines-- 619 00:37:21,100 --> 00:37:22,580 which are straight lines in space 620 00:37:22,580 --> 00:37:28,620 and time-- the flow-- or I should say the inverse flow 621 00:37:28,620 --> 00:37:34,130 because their speed is delta x over delta y. 622 00:37:34,130 --> 00:37:38,830 So the delta in the x axis over the delta in the y axis. 623 00:37:38,830 --> 00:37:39,860 AUDIENCE: [INAUDIBLE]. 624 00:37:39,860 --> 00:37:42,110 QIQI WANG: [INAUDIBLE] is always delta x over delta y. 625 00:37:42,110 --> 00:37:46,356 In this case, delta x is [INAUDIBLE] delta y. 626 00:37:46,356 --> 00:37:47,610 Delta t [INAUDIBLE]. 627 00:37:47,610 --> 00:37:51,080 Delta x over delta t is kind of the inverse. 628 00:37:51,080 --> 00:37:53,020 Does that make sense? 629 00:37:53,020 --> 00:37:56,910 I mean, a speed equal zero is like a vertical line. 630 00:37:56,910 --> 00:38:01,020 A vertical line has no delta x but lots of delta t. 631 00:38:01,020 --> 00:38:03,500 So it's low speed. 632 00:38:03,500 --> 00:38:08,578 And the line that is very shallow is the high speed 633 00:38:08,578 --> 00:38:12,710 line because it has a lot delta x over small delta t. 634 00:38:12,710 --> 00:38:17,785 So we see these are high speed. 635 00:38:17,785 --> 00:38:20,950 And these near vertical lines are low speed. 636 00:38:20,950 --> 00:38:24,871 And these lines sloping towards the left are negative speed. 637 00:38:24,871 --> 00:38:27,110 They are moving towards the left. 638 00:38:27,110 --> 00:38:28,460 Right? 639 00:38:28,460 --> 00:38:29,460 OK. 640 00:38:29,460 --> 00:38:32,398 The solution behaves like this. 641 00:38:32,398 --> 00:38:34,830 The characteristics are proportional 642 00:38:34,830 --> 00:38:37,180 to the solution itself. 643 00:38:37,180 --> 00:38:42,485 The redder it is, the larger the position is. 644 00:38:42,485 --> 00:38:47,160 And the more quantity, the larger the speed is. 645 00:38:47,160 --> 00:38:51,600 The bluer the solution is, the more negative the solution is. 646 00:38:51,600 --> 00:38:56,220 And the solution moves backwards at a negative velocity. 647 00:38:56,220 --> 00:38:59,430 This is how the solution behaves in a Burgers equation. 648 00:39:02,360 --> 00:39:05,896 And we also have this shock wave that 649 00:39:05,896 --> 00:39:14,410 moves at an average velocity of [? 6.54 ?]. 650 00:39:14,410 --> 00:39:14,910 Right? 651 00:39:14,910 --> 00:39:18,200 So we this shock wave moves kind of slowly towards the right. 652 00:39:18,200 --> 00:39:23,930 Because if you look at the average left value and right 653 00:39:23,930 --> 00:39:26,864 value, it's slightly positive. 654 00:39:26,864 --> 00:39:30,551 So the shock waves moves slightly towards the right. 655 00:39:30,551 --> 00:39:31,050 OK. 656 00:39:31,050 --> 00:39:33,720 That's how the solution for the Burgers' equation behaves. 657 00:39:33,720 --> 00:39:41,060 And we need to have a method to solve the Burgers equation. 658 00:39:41,060 --> 00:39:43,590 And we're interested not only in the smooth part 659 00:39:43,590 --> 00:39:48,272 of the solution, but also in the discontinuous part 660 00:39:48,272 --> 00:39:48,938 of the solution. 661 00:39:51,630 --> 00:40:01,651 OK let me just do another case and ask you 662 00:40:01,651 --> 00:40:03,150 how the solution is going to behave. 663 00:40:07,890 --> 00:40:08,460 All right. 664 00:40:08,460 --> 00:40:14,760 So if I have a function u of x for the Burgers equation, 665 00:40:14,760 --> 00:40:18,940 the Burgers equation is partial u-partial t 666 00:40:18,940 --> 00:40:23,040 plus U times partial-partial x equals zero. 667 00:40:25,970 --> 00:40:32,530 Or in a conservative form, it's partial u-partial t 668 00:40:32,530 --> 00:40:35,130 plus partial u over partial x and half 669 00:40:35,130 --> 00:40:37,827 of u squared equal to zero. 670 00:40:37,827 --> 00:40:38,327 Right? 671 00:40:38,327 --> 00:40:42,302 So this is-- this form is [INAUDIBLE] u squared out 672 00:40:42,302 --> 00:40:43,515 of the spatial derivative. 673 00:40:47,400 --> 00:40:49,170 After a while, can anybody tell me 674 00:40:49,170 --> 00:40:50,670 how the solution is going to look? 675 00:40:54,600 --> 00:40:55,329 Yeah? 676 00:40:55,329 --> 00:40:57,824 AUDIENCE: Is this periodic? 677 00:40:57,824 --> 00:40:59,820 QIQI WANG: Let's say they are periodic, 678 00:40:59,820 --> 00:41:00,736 AUDIENCE: [INAUDIBLE]. 679 00:41:02,820 --> 00:41:03,553 QIQI WANG: Yeah. 680 00:41:03,553 --> 00:41:05,761 AUDIENCE: The shock waves are formed and [INAUDIBLE]. 681 00:41:09,625 --> 00:41:10,250 QIQI WANG: Yes. 682 00:41:10,250 --> 00:41:11,914 Exactly. 683 00:41:11,914 --> 00:41:14,800 So this part moves at a positive speed. 684 00:41:14,800 --> 00:41:16,930 This part moves at a negative speed. 685 00:41:16,930 --> 00:41:21,110 So you can really see the solution later on should 686 00:41:21,110 --> 00:41:22,680 become something like this. 687 00:41:25,260 --> 00:41:28,100 And later on, the shock wave should form. 688 00:41:28,100 --> 00:41:31,004 I actually don't know if it's moving towards the left 689 00:41:31,004 --> 00:41:32,170 or moving towards the right. 690 00:41:32,170 --> 00:41:35,050 But the shock wave is going to form over here. 691 00:41:35,050 --> 00:41:36,490 AUDIENCE: [INAUDIBLE]. 692 00:41:36,490 --> 00:41:37,450 QIQI WANG: Uh huh. 693 00:41:37,450 --> 00:41:38,366 AUDIENCE: [INAUDIBLE]. 694 00:41:43,044 --> 00:41:43,710 QIQI WANG: Yeah. 695 00:41:43,710 --> 00:41:44,366 Good point. 696 00:41:44,366 --> 00:41:46,630 This part is a little bit [? difficult ?]. 697 00:41:46,630 --> 00:41:49,030 So the positive part is still dominant 698 00:41:49,030 --> 00:41:52,100 and the shock wave is going to move towards the right. 699 00:41:52,100 --> 00:41:53,290 Good point. 700 00:41:53,290 --> 00:41:53,820 OK. 701 00:41:53,820 --> 00:41:56,675 So this is how the equation behaves. 702 00:41:56,675 --> 00:42:03,790 And let's see how do we solve it using a finite volume method. 703 00:42:10,251 --> 00:42:10,750 OK. 704 00:42:14,740 --> 00:42:16,945 So let me write down the equation again. 705 00:42:16,945 --> 00:42:22,420 Partial u-partial t plus partial-partial x of half of u 706 00:42:22,420 --> 00:42:24,750 squared equal to zero. 707 00:42:24,750 --> 00:42:25,380 Right? 708 00:42:25,380 --> 00:42:28,870 Or in the more general form, I should 709 00:42:28,870 --> 00:42:33,780 be writing partial u-partial t plus partial F 710 00:42:33,780 --> 00:42:36,280 of u partial x equal to zero. 711 00:42:36,280 --> 00:42:40,700 And to specialize this general conservation law 712 00:42:40,700 --> 00:42:42,620 into the Burgers equation, we just 713 00:42:42,620 --> 00:42:46,628 need to set F of u equal to half of u squared. 714 00:42:49,620 --> 00:42:50,580 OK. 715 00:42:50,580 --> 00:42:53,330 And again, you find the volume. 716 00:42:53,330 --> 00:42:57,531 We are solving for the derivative. 717 00:42:57,531 --> 00:42:58,030 OK. 718 00:42:58,030 --> 00:43:03,640 Now we need to, we are solving the-- we 719 00:43:03,640 --> 00:43:10,150 are tracking the evolution of this Uk average. 720 00:43:10,150 --> 00:43:16,000 And the Uk average is defined as one over delta x. 721 00:43:16,000 --> 00:43:20,920 So delta x in this case is the size of each control volume. 722 00:43:20,920 --> 00:43:21,420 OK? 723 00:43:27,170 --> 00:43:31,470 Control volume. 724 00:43:31,470 --> 00:43:32,540 OK. 725 00:43:32,540 --> 00:43:39,300 Times the integral from the left of the k-th control 726 00:43:39,300 --> 00:43:43,352 volume to the right of the k-th control volume. 727 00:43:43,352 --> 00:43:44,204 OK. 728 00:43:44,204 --> 00:43:45,620 And the size of the control volume 729 00:43:45,620 --> 00:43:49,680 is of course equal to Rk minus Lk. 730 00:43:49,680 --> 00:43:50,180 OK. 731 00:43:50,180 --> 00:43:54,640 The integral is the u of x and t dx. 732 00:43:59,280 --> 00:44:01,600 This is my cell average. 733 00:44:04,400 --> 00:44:08,810 And in general, this is delta xk, right? 734 00:44:08,810 --> 00:44:11,240 Because each control volume can be different. 735 00:44:11,240 --> 00:44:13,070 And here we are just going to talk 736 00:44:13,070 --> 00:44:20,210 about the case with a uniform, uniform mesh. 737 00:44:20,210 --> 00:44:27,000 And the uniform mesh responds to delta Xk or r equal to delta x. 738 00:44:27,000 --> 00:44:35,430 And the L of k is equal to k minus one times delta x. 739 00:44:35,430 --> 00:44:40,961 And the r of k is equal to k times delta x. 740 00:44:40,961 --> 00:44:41,460 All right. 741 00:44:41,460 --> 00:44:44,640 So the L of 1, the left boundary of the first [INAUDIBLE] 742 00:44:44,640 --> 00:44:45,430 is at zero. 743 00:44:48,112 --> 00:44:54,370 The right boundary of the k-th control volume 744 00:44:54,370 --> 00:44:58,090 is always the same as the left boundary of the next control 745 00:44:58,090 --> 00:45:00,090 volume. 746 00:45:00,090 --> 00:45:03,520 That has to be satisfied for finite volume method. 747 00:45:03,520 --> 00:45:07,670 You have to divide the entire space, the entire domain 748 00:45:07,670 --> 00:45:15,800 into non-overlapping into non-overlapping control volumes 749 00:45:15,800 --> 00:45:19,640 and leave no empty space in between. 750 00:45:19,640 --> 00:45:22,540 You have to basically partition the entire [? combination ?] 751 00:45:22,540 --> 00:45:27,737 domain into non-overlapping control volumes. 752 00:45:27,737 --> 00:45:30,710 And you can't leave anything open. 753 00:45:30,710 --> 00:45:31,440 OK. 754 00:45:31,440 --> 00:45:34,510 So now let's take a look at what is the time 755 00:45:34,510 --> 00:45:40,200 derivative of this average? 756 00:45:40,200 --> 00:45:44,180 To figure out the time derivative of this average, 757 00:45:44,180 --> 00:45:49,090 we have to use the integral form of the conservation law. 758 00:45:49,090 --> 00:46:01,160 It is equal to one over delta k times d/dt of Lk Rk Uxk dx. 759 00:46:01,160 --> 00:46:06,260 And by applying the integral form of the conversion law, 760 00:46:06,260 --> 00:46:13,970 we get the flux at the right hand side minus the flux 761 00:46:13,970 --> 00:46:19,150 at the left hand side of the control volume divided by-- oh, 762 00:46:19,150 --> 00:46:21,520 we don't need to divide anything because we 763 00:46:21,520 --> 00:46:23,650 are looking at the derivative of the integral. 764 00:46:23,650 --> 00:46:24,350 Right? 765 00:46:24,350 --> 00:46:32,860 And plus the integral L to R of a [INAUDIBLE] 766 00:46:32,860 --> 00:46:36,640 which is zero in the Burgers equation case. 767 00:46:36,640 --> 00:46:40,940 Because in the Burgers equation, we don't have any source then. 768 00:46:40,940 --> 00:46:43,560 The source is zero. 769 00:46:43,560 --> 00:46:44,680 OK. 770 00:46:44,680 --> 00:46:52,400 Now we have an evolution equation for the cell average. 771 00:46:52,400 --> 00:46:55,762 And up to here, we've made no approximations. 772 00:46:55,762 --> 00:46:57,306 Right? 773 00:46:57,306 --> 00:46:59,055 In finite difference, we are approximating 774 00:46:59,055 --> 00:47:00,920 the spatial derivative. 775 00:47:00,920 --> 00:47:04,002 But here, we don't need to make any approximations 776 00:47:04,002 --> 00:47:06,930 in getting to here. 777 00:47:06,930 --> 00:47:13,450 And the flux in this case is half of u 778 00:47:13,450 --> 00:47:15,620 squared at the cell boundaries. 779 00:47:18,260 --> 00:47:22,510 Now this is the point we have to start making approximations. 780 00:47:22,510 --> 00:47:25,670 Because unlike in finite difference, 781 00:47:25,670 --> 00:47:29,212 we have the value of the function x at [? these ?] 782 00:47:29,212 --> 00:47:30,080 points. 783 00:47:30,080 --> 00:47:30,910 But here we don't. 784 00:47:34,109 --> 00:47:40,760 We don't have the solution at either Lk or Rk. 785 00:47:40,760 --> 00:47:41,260 Right? 786 00:47:41,260 --> 00:47:46,950 We don't have the solution at the control volume boundaries. 787 00:47:46,950 --> 00:47:50,900 We only have the cell average solution values. 788 00:47:50,900 --> 00:48:00,887 So we have to approximate, we have to do the finite volume 789 00:48:00,887 --> 00:48:01,470 approximation. 790 00:48:07,370 --> 00:48:15,480 I have to approximate the flux at rk. 791 00:48:15,480 --> 00:48:23,480 I have to approximate it as F of a function. 792 00:48:23,480 --> 00:48:33,740 The most simple cases u bar of x Uk minus one and u bar of k. 793 00:48:33,740 --> 00:48:40,800 F at-- sorry, this has to be at Lk because I'm on the left. 794 00:48:40,800 --> 00:48:48,155 Rk has to be approximated as a flux of Uk and Uk plus one. 795 00:48:48,155 --> 00:48:50,568 So let me draw what is happening here. 796 00:48:53,500 --> 00:48:56,830 So I have a bunch of cells. 797 00:48:56,830 --> 00:48:58,500 This is, let's say, k minus 1. 798 00:48:58,500 --> 00:49:00,310 This is k. 799 00:49:00,310 --> 00:49:01,570 k plus one. 800 00:49:01,570 --> 00:49:03,142 k plus two. 801 00:49:03,142 --> 00:49:04,830 Right? 802 00:49:04,830 --> 00:49:06,550 OK. 803 00:49:06,550 --> 00:49:13,630 So this point is the left boundary of k minus one. 804 00:49:13,630 --> 00:49:16,530 Here is the right boundary of k minus one. 805 00:49:16,530 --> 00:49:21,630 But it is also corresponding to the left boundary of k. 806 00:49:21,630 --> 00:49:23,315 This point is the right boundary of k 807 00:49:23,315 --> 00:49:27,370 but also corresponds to the left boundary of k plus one. 808 00:49:27,370 --> 00:49:30,140 This point is the right boundary of k plus one 809 00:49:30,140 --> 00:49:32,680 but is also the left boundary of k plus two. 810 00:49:32,680 --> 00:49:35,240 This point is the right boundary of k plus two 811 00:49:35,240 --> 00:49:37,132 but also the left boundary of k plus 3. 812 00:49:40,300 --> 00:49:45,685 I need to attach a flux value at each of these boundaries 813 00:49:45,685 --> 00:49:48,760 in order to solve this equation. 814 00:49:48,760 --> 00:49:52,550 For this equation, I need to not only resolve 815 00:49:52,550 --> 00:49:56,022 the cell average in each cell, I need 816 00:49:56,022 --> 00:50:01,478 to have the flux at these boundary points. 817 00:50:01,478 --> 00:50:04,410 But I don't have the solution at these boundary points. 818 00:50:04,410 --> 00:50:13,930 All I have is the cell average inside of the cells. 819 00:50:13,930 --> 00:50:17,860 How do I approximate the flux at these boundaries? 820 00:50:17,860 --> 00:50:22,646 It makes no sense to approximate the flux at this point using 821 00:50:22,646 --> 00:50:29,730 the cell averages around that cell boundary. 822 00:50:29,730 --> 00:50:32,882 At the left hand side of [INAUDIBLE], and this 823 00:50:32,882 --> 00:50:34,580 is [? like the cell interface ?]. 824 00:50:34,580 --> 00:50:37,975 On the left hand side interface is [INAUDIBLE] right 825 00:50:37,975 --> 00:50:39,430 of the interface [INAUDIBLE]. 826 00:50:39,430 --> 00:50:47,590 So I need to approximate the flux using the values. 827 00:50:47,590 --> 00:50:48,740 OK. 828 00:50:48,740 --> 00:50:51,410 The easiest way to approximate it 829 00:50:51,410 --> 00:50:54,550 is what we call first order upwinds. 830 00:50:54,550 --> 00:51:03,470 And upwind means the reverse of the direction towards which 831 00:51:03,470 --> 00:51:06,450 the solution goes. 832 00:51:06,450 --> 00:51:08,160 OK. 833 00:51:08,160 --> 00:51:14,940 In this situation, can somebody tell me 834 00:51:14,940 --> 00:51:18,050 what is the upwind direction? 835 00:51:18,050 --> 00:51:20,172 Yeah? 836 00:51:20,172 --> 00:51:22,050 AUDIENCE: [INAUDIBLE]. 837 00:51:22,050 --> 00:51:24,361 QIQI WANG: This direction is the upwind direction? 838 00:51:24,361 --> 00:51:24,860 Always? 839 00:51:27,918 --> 00:51:29,310 It depends. 840 00:51:29,310 --> 00:51:30,440 Right. 841 00:51:30,440 --> 00:51:33,720 The upwind direction in the Burgers equation 842 00:51:33,720 --> 00:51:36,310 actually means almost all [INAUDIBLE] 843 00:51:36,310 --> 00:51:38,290 conservation laws ends on the solution. 844 00:51:42,098 --> 00:51:48,800 In this part, the solution was here and now moved here. 845 00:51:48,800 --> 00:51:52,680 The solution is [INAUDIBLE] towards the right. 846 00:51:52,680 --> 00:51:56,320 It's kind of blown, like blown by the wind, 847 00:51:56,320 --> 00:52:01,090 and that comes from the left. 848 00:52:01,090 --> 00:52:03,420 So what is the optimum direction for this part 849 00:52:03,420 --> 00:52:06,180 in the red region? 850 00:52:06,180 --> 00:52:08,880 It's towards the left, right? 851 00:52:08,880 --> 00:52:13,308 What is the optimum direction over here in the blue region? 852 00:52:13,308 --> 00:52:14,720 Towards the right, right? 853 00:52:14,720 --> 00:52:17,690 The wind is coming from the right. 854 00:52:17,690 --> 00:52:22,050 So the wind is going this way, if this were the wind. 855 00:52:22,050 --> 00:52:27,049 So upwind direction is looking where the wind is coming from. 856 00:52:27,049 --> 00:52:29,090 And in the Burgers equation, the upwind direction 857 00:52:29,090 --> 00:52:33,204 is towards minus x if u is positive. 858 00:52:33,204 --> 00:52:37,350 It is plus x if u is negative. 859 00:52:37,350 --> 00:52:40,100 This is upwind. 860 00:52:40,100 --> 00:52:43,660 It makes a lot of sense to do upwind 861 00:52:43,660 --> 00:52:47,400 because that's where the solution comes from, right? 862 00:52:47,400 --> 00:52:54,880 So you want to-- I'm going to talk about upwinding, 863 00:52:54,880 --> 00:52:57,950 why upwinding makes sense really later when 864 00:52:57,950 --> 00:53:00,350 we talk about stability. 865 00:53:00,350 --> 00:53:01,270 OK. 866 00:53:01,270 --> 00:53:02,660 So upwinding schemes. 867 00:53:02,660 --> 00:53:07,330 At this point, I just need to tell you it gives stability. 868 00:53:07,330 --> 00:53:15,220 And in the upwinding scheme, I'm just going to say F of k-- so F 869 00:53:15,220 --> 00:53:20,330 at the interface-- so I'm going to define 870 00:53:20,330 --> 00:53:31,000 F of k plus 1/2, defined as F at the right boundary of the k 871 00:53:31,000 --> 00:53:35,660 value, which is also the same as the left boundary 872 00:53:35,660 --> 00:53:39,630 of the k plus one cell. 873 00:53:39,630 --> 00:53:44,430 It is the flux at the interface between the k 874 00:53:44,430 --> 00:53:45,700 and k plus one cell. 875 00:53:45,700 --> 00:53:46,200 Right? 876 00:53:46,200 --> 00:53:48,256 I call it k plus 1/2, because it's 877 00:53:48,256 --> 00:53:52,150 kind of a halfway between the k and k plus 1 cell. 878 00:53:52,150 --> 00:53:54,850 Right? 879 00:53:54,850 --> 00:53:57,810 And the first order upwind scheme 880 00:53:57,810 --> 00:54:04,610 is to compute F of k plus 1/2 is equal to 2 cases. 881 00:54:04,610 --> 00:54:10,910 It is either F of u bar at k, which in the Burgers equation 882 00:54:10,910 --> 00:54:17,890 is just u bar of k squared over 2. 883 00:54:17,890 --> 00:54:27,885 If the minus direction is the upwind direction, 884 00:54:27,885 --> 00:54:35,480 I'm here again at-- I'm going to draw the same cells again. 885 00:54:35,480 --> 00:54:39,580 So k minus 1, k, plus one. 886 00:54:39,580 --> 00:54:40,710 OK. 887 00:54:40,710 --> 00:54:44,730 I am looking at k plus 1/2, which 888 00:54:44,730 --> 00:54:48,869 is the interface between k and k plus 1. 889 00:54:48,869 --> 00:54:52,544 I am going to use the average method of k 890 00:54:52,544 --> 00:54:54,512 to approximate here. 891 00:54:54,512 --> 00:55:00,800 If k is the upwind direction of the cell, 892 00:55:00,800 --> 00:55:06,740 which means if the wind travels towards the right, 893 00:55:06,740 --> 00:55:09,406 if locally u is greater than zero. 894 00:55:13,300 --> 00:55:20,490 And here locally-- I can say locally u is greater than zero 895 00:55:20,490 --> 00:55:29,480 if the average between the two cells is greater than zero. 896 00:55:29,480 --> 00:55:34,090 And else, I'm going to approximate 897 00:55:34,090 --> 00:55:40,220 it using the upwind direction, which is now towards the right. 898 00:55:40,220 --> 00:55:41,720 It is this. 899 00:55:45,220 --> 00:55:47,720 Does it make any sense? 900 00:55:47,720 --> 00:55:52,130 This is what I'm going to write in the code. 901 00:55:52,130 --> 00:55:52,670 OK. 902 00:55:52,670 --> 00:55:57,320 This is what I'm going to implement in my code. 903 00:55:57,320 --> 00:56:00,186 That is, in the [INAUDIBLE] code [INAUDIBLE]. 904 00:56:03,162 --> 00:56:07,896 The F at interface is either the flux 905 00:56:07,896 --> 00:56:10,560 at the left value or the right value where [? it is ?]. 906 00:56:15,258 --> 00:56:16,174 Any questions on this? 907 00:56:20,750 --> 00:56:21,250 No? 908 00:56:21,250 --> 00:56:22,610 OK. 909 00:56:22,610 --> 00:56:26,800 Let's do it then. 910 00:56:26,800 --> 00:56:31,480 What I'm going to do is I'm going to pull up a skeleton. 911 00:56:31,480 --> 00:56:36,830 And I'm going to ask you to fill in the blanks. 912 00:56:36,830 --> 00:56:40,010 So I'm going to go to the shared border. 913 00:56:40,010 --> 00:56:43,056 Open your computers if you haven't. 914 00:56:43,056 --> 00:56:49,639 I'm going to create an order 2014. 915 00:56:49,639 --> 00:56:51,554 Today is the 10th, right? 916 00:56:54,771 --> 00:56:55,270 OK. 917 00:56:55,270 --> 00:56:56,660 I'm going to start from scratch. 918 00:56:59,360 --> 00:57:05,260 I'm going to make a function just called the du dt Burgers. 919 00:57:05,260 --> 00:57:06,250 OK. 920 00:57:06,250 --> 00:57:11,400 And like our-- so we're assuming PDEs. 921 00:57:11,400 --> 00:57:14,730 But as long as we can convert the PDEs into a set of ODEs, 922 00:57:14,730 --> 00:57:18,670 we know how to integrate it at this point. 923 00:57:18,670 --> 00:57:20,095 I'm sure you guys all can. 924 00:57:23,470 --> 00:57:25,050 So what is it going to be? 925 00:57:25,050 --> 00:57:27,910 The input is the u bars. 926 00:57:27,910 --> 00:57:30,750 And the output is d u bar dt. 927 00:57:35,470 --> 00:57:39,290 And what I need to do is I need to compute 928 00:57:39,290 --> 00:57:42,434 from the u bars the du bar dt. 929 00:57:46,230 --> 00:57:47,180 So what do I do first? 930 00:57:50,240 --> 00:57:54,570 I'm first going to do F bar is equal to u 931 00:57:54,570 --> 00:57:57,150 bar squared over two. 932 00:57:57,150 --> 00:57:58,420 What am I doing here? 933 00:58:03,760 --> 00:58:06,360 AUDIENCE: [INAUDIBLE]. 934 00:58:06,360 --> 00:58:07,740 QIQI WANG: Computing the flux. 935 00:58:07,740 --> 00:58:11,930 This is the only thing I need to change 936 00:58:11,930 --> 00:58:14,108 if I switch from the Burgers equation 937 00:58:14,108 --> 00:58:17,360 to some other equation. 938 00:58:17,360 --> 00:58:18,450 OK? 939 00:58:18,450 --> 00:58:20,770 This is really defining the flux. 940 00:58:20,770 --> 00:58:24,820 If I have a flux that is equal to another form, 941 00:58:24,820 --> 00:58:28,080 this is what I need to change. 942 00:58:28,080 --> 00:58:29,260 OK. 943 00:58:29,260 --> 00:58:31,780 And here, I'm going to have you fill in the blanks. 944 00:58:35,610 --> 00:58:39,315 Compute the flux at cell interfaces. 945 00:58:42,340 --> 00:58:50,700 So I need to compute F. Let me call this F of [INAUDIBLE] k. 946 00:58:50,700 --> 00:58:58,440 So this is F at k plus 1/2 equal to blah, blah, blah. 947 00:58:58,440 --> 00:59:00,421 This is what you need to do. 948 00:59:00,421 --> 00:59:00,920 OK? 949 00:59:03,670 --> 00:59:06,760 And then what I'm going to write down 950 00:59:06,760 --> 00:59:09,860 is this is the finite volume method. 951 00:59:09,860 --> 00:59:14,475 This is the same for all finite volume methods. 952 00:59:19,600 --> 00:59:21,580 What is it? 953 00:59:21,580 --> 00:59:29,840 It is the d u bar dt equal to-- according to our formula-- 954 00:59:29,840 --> 00:59:39,213 du bar dt is equal to one over delta x times the F, the flux, 955 00:59:39,213 --> 00:59:43,388 at the right boundary of k, which is k plus 1/2, 956 00:59:43,388 --> 00:59:46,676 minus the F at the left boundary of k, 957 00:59:46,676 --> 00:59:50,340 which is F of k minus 1/2. 958 00:59:50,340 --> 00:59:50,840 Right? 959 00:59:55,260 --> 01:00:06,950 So this is F k plus 1/2 minus F k minus 1/2 divided by delta x. 960 01:00:06,950 --> 01:00:11,520 And I need to compute F of k minus 1/2. 961 01:00:11,520 --> 01:00:16,570 It's basically a [INAUDIBLE] of F k plus 1/2. 962 01:00:16,570 --> 01:00:18,980 Let's assume they are periodic boundaries for now. 963 01:00:18,980 --> 01:00:22,830 So how should I compute F of k minus 1/2 from F of k plus 1/2? 964 01:00:28,480 --> 01:00:30,612 I'm going to use circshift, right? 965 01:00:33,757 --> 01:00:35,340 And which direction should I shift it? 966 01:00:42,750 --> 01:00:52,410 So I already have F of k-- I already have F of k 967 01:00:52,410 --> 01:00:53,790 plus 1/2 over here. 968 01:00:53,790 --> 01:00:59,480 I need to have-- so if I already have F of k up here, 969 01:00:59,480 --> 01:01:03,815 I need to shift it towards the right to get-- 970 01:01:03,815 --> 01:01:06,370 so that's the same point I have, F of k minus 1/2. 971 01:01:14,250 --> 01:01:17,740 So we assume-- let's assume it's a row vector, 972 01:01:17,740 --> 01:01:20,806 so that when I shift it, I shift it to 0 and 1. 973 01:01:20,806 --> 01:01:23,560 OK. 974 01:01:23,560 --> 01:01:30,306 And let's assume my boundary goes from 0 to 1. 975 01:01:30,306 --> 01:01:31,750 OK. 976 01:01:31,750 --> 01:01:34,890 So if I have a boundary that goes from 0 to 1, 977 01:01:34,890 --> 01:01:38,230 my delta x is equal to the length of the domain divided 978 01:01:38,230 --> 01:01:44,470 by the length of u bar, how many control volumes I have. 979 01:01:44,470 --> 01:01:46,280 So that's my delta x. 980 01:01:46,280 --> 01:01:48,430 The size of each control volume? 981 01:01:48,430 --> 01:01:51,430 I have F of k plus 1/2, F of k minus 1/2. 982 01:01:51,430 --> 01:01:56,290 Then I get the du bar dt. 983 01:01:56,290 --> 01:01:56,900 OK. 984 01:01:56,900 --> 01:02:03,150 Go ahead and just copy what I wrote here. 985 01:02:03,150 --> 01:02:05,930 Just rename it to whatever. 986 01:02:05,930 --> 01:02:11,065 Just rename it to dudtBurgers underscore your name. 987 01:02:11,065 --> 01:02:12,565 You can do it in the same directory. 988 01:02:16,169 --> 01:02:17,210 And tell me what you get. 989 01:02:17,210 --> 01:02:17,940 All right. 990 01:02:17,940 --> 01:02:20,640 Anybody have anything I did wrong? 991 01:02:20,640 --> 01:02:23,920 I just wrote a script. 992 01:02:23,920 --> 01:02:25,980 So it's writing [INAUDIBLE]. 993 01:02:31,440 --> 01:02:33,935 So this is basically making [INAUDIBLE]. 994 01:02:38,426 --> 01:02:40,422 OK. 995 01:02:40,422 --> 01:02:42,917 And using all the input [INAUDIBLE]. 996 01:02:45,888 --> 01:02:46,866 So [INAUDIBLE]. 997 01:02:58,591 --> 01:02:59,091 All right? 998 01:02:59,091 --> 01:03:00,080 So I'm [INAUDIBLE]. 999 01:03:15,975 --> 01:03:16,891 AUDIENCE: [INAUDIBLE]. 1000 01:03:26,360 --> 01:03:28,640 QIQI WANG: OK. 1001 01:03:28,640 --> 01:03:31,960 You can try. 1002 01:03:31,960 --> 01:03:34,325 All right. 1003 01:03:34,325 --> 01:03:36,131 AUDIENCE: [INAUDIBLE]. 1004 01:03:36,131 --> 01:03:36,714 QIQI WANG: OK. 1005 01:03:40,544 --> 01:03:41,460 AUDIENCE: [INAUDIBLE]. 1006 01:03:46,740 --> 01:03:47,700 The function in-- 1007 01:03:47,700 --> 01:03:47,853 QIQI WANG: Oh. 1008 01:03:47,853 --> 01:03:47,904 Oh. 1009 01:03:47,904 --> 01:03:48,404 OK. 1010 01:03:52,674 --> 01:03:54,658 Oops. 1011 01:03:54,658 --> 01:03:55,690 I added just-- 1012 01:03:59,136 --> 01:04:01,277 AUDIENCE: [INAUDIBLE]. 1013 01:04:01,277 --> 01:04:01,860 QIQI WANG: OK. 1014 01:04:01,860 --> 01:04:08,096 So this is-- let's see. 1015 01:04:08,096 --> 01:04:10,576 [INAUDIBLE] 1016 01:04:10,576 --> 01:04:16,560 So I goes from one to the length of u bar minus 1. 1017 01:04:16,560 --> 01:04:18,500 If u bar is [INAUDIBLE]. 1018 01:04:24,710 --> 01:04:26,648 You also put I here. 1019 01:04:26,648 --> 01:04:28,790 AUDIENCE: [INAUDIBLE]. 1020 01:04:28,790 --> 01:04:29,420 QIQI WANG: OK. 1021 01:04:29,420 --> 01:04:30,670 AUDIENCE: It's be a good idea. 1022 01:04:30,670 --> 01:04:31,336 QIQI WANG: Yeah. 1023 01:04:33,730 --> 01:04:38,090 I think I need to close this so that I don't get a [INAUDIBLE]. 1024 01:04:38,090 --> 01:04:38,590 OK. 1025 01:04:38,590 --> 01:04:39,131 It's updated. 1026 01:04:43,620 --> 01:04:45,130 OK. 1027 01:04:45,130 --> 01:04:47,135 Let's run the script again. 1028 01:04:47,135 --> 01:04:49,920 The driver. 1029 01:04:49,920 --> 01:04:50,420 Run. 1030 01:05:02,730 --> 01:05:05,209 Ah. 1031 01:05:05,209 --> 01:05:05,708 OK. 1032 01:05:05,708 --> 01:05:06,166 This is-- 1033 01:05:06,166 --> 01:05:06,999 [INTERPOSING VOICES] 1034 01:05:09,707 --> 01:05:10,290 QIQI WANG: OK. 1035 01:05:10,290 --> 01:05:12,297 Update it again. 1036 01:05:12,297 --> 01:05:15,291 AUDIENCE: [INAUDIBLE]. 1037 01:05:15,291 --> 01:05:19,782 [INTERPOSING VOICES] 1038 01:05:26,280 --> 01:05:29,060 QIQI WANG: Oh, you must-- OK. 1039 01:05:29,060 --> 01:05:30,170 So that's my problem. 1040 01:05:30,170 --> 01:05:33,870 I need to change it so that I [? deleted ?] a column vector. 1041 01:05:37,080 --> 01:05:40,262 Let me [? delete ?] a column vector and [INAUDIBLE] a column 1042 01:05:40,262 --> 01:05:41,111 vector. 1043 01:05:41,111 --> 01:05:41,610 OK. 1044 01:05:41,610 --> 01:05:42,193 Now let's see. 1045 01:05:47,790 --> 01:05:48,290 Ah. 1046 01:05:48,290 --> 01:05:52,090 You're returning a vector of length 63. 1047 01:05:52,090 --> 01:05:55,455 But the length I should get is 64. 1048 01:05:55,455 --> 01:05:56,288 AUDIENCE: Oh, right. 1049 01:05:56,288 --> 01:05:58,256 So it's returning [INAUDIBLE]. 1050 01:06:13,016 --> 01:06:14,500 QIQI WANG: Ah. 1051 01:06:14,500 --> 01:06:17,510 We are assuming the domain is periodic. 1052 01:06:17,510 --> 01:06:23,590 So at the last control volume, if we 1053 01:06:23,590 --> 01:06:25,880 need to take towards the right, we 1054 01:06:25,880 --> 01:06:28,610 should be taking the first value. 1055 01:06:28,610 --> 01:06:30,750 Right? 1056 01:06:30,750 --> 01:06:31,250 OK. 1057 01:06:31,250 --> 01:06:44,110 Let me see, I see to [? copy ?] the network, oh. 1058 01:06:44,110 --> 01:06:45,197 AUDIENCE: [INAUDIBLE]. 1059 01:06:45,197 --> 01:06:47,030 QIQI WANG: Into the [INAUDIBLE] [? space ?]. 1060 01:06:54,450 --> 01:06:55,250 Let me see. 1061 01:07:17,354 --> 01:07:19,800 Hm. 1062 01:07:19,800 --> 01:07:20,300 OK. 1063 01:07:20,300 --> 01:07:31,541 For the last cell, here I think I [INAUDIBLE] 1064 01:07:31,541 --> 01:07:34,242 from the [INAUDIBLE], I think that will 1065 01:07:34,242 --> 01:07:39,400 end after-- so let me see. 1066 01:07:39,400 --> 01:07:42,140 For r equals from 1 to 10, i n. 1067 01:07:42,140 --> 01:07:44,728 Yet, if I do i again, it is still 10. 1068 01:07:44,728 --> 01:07:46,162 It is not 11. 1069 01:07:46,162 --> 01:07:48,560 AUDIENCE: [INAUDIBLE]. 1070 01:07:48,560 --> 01:07:49,406 QIQI WANG: Yes. 1071 01:07:49,406 --> 01:07:50,322 AUDIENCE: [INAUDIBLE]. 1072 01:07:56,750 --> 01:07:59,064 QIQI WANG: OK. [INAUDIBLE] update. 1073 01:07:59,064 --> 01:08:02,120 [INAUDIBLE] update. 1074 01:08:02,120 --> 01:08:02,620 OK. 1075 01:08:02,620 --> 01:08:04,430 Let me do this again. 1076 01:08:09,660 --> 01:08:10,360 Oh. 1077 01:08:10,360 --> 01:08:12,745 I need a minus sign here. 1078 01:08:12,745 --> 01:08:13,245 Right? 1079 01:08:13,245 --> 01:08:14,990 [LAUGHTER] 1080 01:08:14,990 --> 01:08:17,260 Is that right? 1081 01:08:17,260 --> 01:08:17,760 OK. 1082 01:08:17,760 --> 01:08:20,080 I need a minus sign in my-- OK. 1083 01:08:20,080 --> 01:08:22,140 I need a minus sign in my script because-- 1084 01:08:22,140 --> 01:08:23,151 AUDIENCE: Yeah. 1085 01:08:23,151 --> 01:08:23,859 QIQI WANG: Right? 1086 01:08:23,859 --> 01:08:24,930 Is that right? 1087 01:08:24,930 --> 01:08:26,300 Let me see. 1088 01:08:26,300 --> 01:08:33,670 So it is equal to the right value minus the left one, which 1089 01:08:33,670 --> 01:08:34,350 I may be-- 1090 01:08:38,340 --> 01:08:39,770 AUDIENCE: Yes, it would be-- 1091 01:08:39,770 --> 01:08:43,760 QIQI WANG: Should have been the left value minus the right one. 1092 01:08:43,760 --> 01:08:44,630 Sorry. 1093 01:08:44,630 --> 01:08:47,380 I have been deriving it incorrectly. 1094 01:08:47,380 --> 01:08:50,069 So yes. 1095 01:08:50,069 --> 01:08:53,349 So for the time derivative of the average 1096 01:08:53,349 --> 01:08:57,529 is equal to what comes in from the left minus what 1097 01:08:57,529 --> 01:08:59,950 goes out from the right. 1098 01:08:59,950 --> 01:09:03,029 So I need a-- yes, I need a minus. 1099 01:09:03,029 --> 01:09:05,000 So don't change your code. 1100 01:09:05,000 --> 01:09:07,590 I just put a minus sign here. 1101 01:09:07,590 --> 01:09:08,540 All right. 1102 01:09:08,540 --> 01:09:13,710 Now it looks like it's behaving a little bit 1103 01:09:13,710 --> 01:09:15,510 weirder at the end. 1104 01:09:15,510 --> 01:09:17,219 Otherwise it seems to be working. 1105 01:09:17,219 --> 01:09:18,135 AUDIENCE: [INAUDIBLE]. 1106 01:09:22,572 --> 01:09:28,460 QIQI WANG: Let me-- OK Right. 1107 01:09:28,460 --> 01:09:31,649 So we do see a shock wave developing, right? 1108 01:09:31,649 --> 01:09:35,075 So let me change the delta t to be a little smaller. 1109 01:09:37,810 --> 01:09:41,250 And then run it again. 1110 01:09:41,250 --> 01:09:42,580 Ooh. 1111 01:09:42,580 --> 01:09:43,080 Right? 1112 01:09:43,080 --> 01:09:46,359 That's the correct behavior of the Burgers equation. 1113 01:09:46,359 --> 01:09:47,870 Right? 1114 01:09:47,870 --> 01:09:49,170 OK. 1115 01:09:49,170 --> 01:09:50,310 Very nice. 1116 01:09:50,310 --> 01:09:57,260 So who else-- I think the-- let's see. 1117 01:09:57,260 --> 01:09:57,760 Yeah. 1118 01:09:57,760 --> 01:09:59,210 OK. 1119 01:09:59,210 --> 01:10:00,235 Let me run it again. 1120 01:10:03,150 --> 01:10:05,750 All right. 1121 01:10:05,750 --> 01:10:06,250 Great. 1122 01:10:09,320 --> 01:10:10,260 That's great. 1123 01:10:10,260 --> 01:10:14,470 And let me see if I can break it without betraying 1124 01:10:14,470 --> 01:10:17,010 initial conditions. 1125 01:10:17,010 --> 01:10:20,635 And let me take it as x is zero equal 1126 01:10:20,635 --> 01:10:22,185 to draw periodic function. 1127 01:10:25,850 --> 01:10:27,010 Do I have that? 1128 01:10:27,010 --> 01:10:27,510 Oh no. 1129 01:10:27,510 --> 01:10:29,340 I don't have that in here. 1130 01:10:29,340 --> 01:10:30,772 So I'm just going to copy it. 1131 01:10:43,248 --> 01:10:44,164 AUDIENCE: [INAUDIBLE]. 1132 01:10:49,124 --> 01:10:52,252 QIQI WANG: Draw periodic function. 1133 01:10:52,252 --> 01:10:54,188 AUDIENCE: [INAUDIBLE]. 1134 01:10:54,188 --> 01:10:58,060 [INTERPOSING VOICES] 1135 01:11:02,430 --> 01:11:05,310 [INTERPOSING VOICES] 1136 01:11:13,680 --> 01:11:14,968 QIQI WANG: Let me do that. 1137 01:11:23,161 --> 01:11:23,660 OK. 1138 01:11:23,660 --> 01:11:24,493 Let me do something. 1139 01:11:38,750 --> 01:11:40,850 Anyway, OK. 1140 01:11:40,850 --> 01:11:45,680 So I see a lot of you are doing good work. 1141 01:11:45,680 --> 01:11:46,920 Anybody else? 1142 01:11:46,920 --> 01:11:49,731 I can try your solution. 1143 01:11:49,731 --> 01:11:50,230 OK. 1144 01:12:00,250 --> 01:12:02,390 Ah. 1145 01:12:02,390 --> 01:12:05,750 [LAUGHTER] 1146 01:12:07,200 --> 01:12:08,770 OK. 1147 01:12:08,770 --> 01:12:09,950 I think I'm going over time. 1148 01:12:09,950 --> 01:12:12,530 I had a lot of fun trying your scripts. 1149 01:12:12,530 --> 01:12:16,580 But let's meet on Wednesday and talk about more 1150 01:12:16,580 --> 01:12:19,054 of the finite volume method. 1151 01:12:19,054 --> 01:12:24,040 So if you want to stay, I'm going to try a little bit more 1152 01:12:24,040 --> 01:12:25,040 of your scripts. 1153 01:12:28,040 --> 01:12:28,540 [INAUDIBLE] 1154 01:12:36,904 --> 01:12:38,380 Oops. 1155 01:12:38,380 --> 01:12:39,886 OK. 1156 01:12:39,886 --> 01:12:40,802 AUDIENCE: [INAUDIBLE]. 1157 01:12:47,211 --> 01:12:50,190 QIQI WANG: Oops. 1158 01:12:50,190 --> 01:12:53,070 All right. 1159 01:12:53,070 --> 01:12:53,740 OK . 1160 01:12:53,740 --> 01:12:55,440 Anyway so once you have a script, 1161 01:12:55,440 --> 01:12:59,900 you can always try my driver and see how they work. 1162 01:12:59,900 --> 01:13:01,530 All right. 1163 01:13:01,530 --> 01:13:03,190 I'll see you on Wednesday. 1164 01:13:03,190 --> 01:13:03,690 Yes. 1165 01:13:03,690 --> 01:13:07,904 If you didn't send me a project here, please put it over here. 1166 01:13:07,904 --> 01:13:13,540 And the homework [INAUDIBLE] with the homework.