Digital Fluid Mechanics Laboratory: Sudden Expansion Pressure Loss

August Young walks through a Mathematica simulation that models pressure loss when fluid hits a sudden pipe expansion. Students solve the Navier-Stokes equations numerically, run parameter sweeps on aspect ratio and inlet velocity, and compare results to the standard analytical model that underestimates the actual loss.
Questions this video answers
August Young, PhD candidate at Duke University.
Wolfram Mathematica using NDsolve (Navier–Stokes and continuity equations).
Around 2,300 (students are instructed to remain below ≈2,300).
Results and fits are shown up to Re = 800 (noted as the lower portion of the laminar range).
Chapters
My name is August young. I'm a PhD candidate at Duke University, and I'm walking through a virtual lab solver used for undergraduate fluid mechanics. My name is August, I'm at Duke University, and my advisor and I put together a digital fluid mechanics laboratory for his undergraduate fluid mechanics students. There's a nice little experiment that can't happen in our traditional laboratory space just because of its impracticality. This geometry right here, it's a sudden expansion and it's commonly encountered in any piping distribution networks where you have valves or fittings. There's a pressure loss that happens when the flow goes through that sudden expansion. It's important that we quantify those pressure losses. So thinking about how much energy you need to put into your flow, you can properly overcome those losses. But if you were to try to actually measure that pressure loss in real life by inserting sensors inside of that flow geometry, you're disrupting the geometry. And the very thing that you want to measure, you've now changed. So we can't have our students actually measure this. And if we would like to do things to that geometry like vary the aspect ratio of that sudden expansion, that would be very impractical if we could even get over the measurement errors we would induce with the sensors. So a numerical simulation allows us to study what would happen if we change our flow rate through that geometry or we change the aspect ratio, that sudden expansion very easily, especially when we do it in Mathematica and we don't require our students to have a very high fluency in the low level programming languages like py, matlab. So these are the files that we give the students. And I'm just going to be walking through these since they'll be posted online, available to everybody, then they can listen to this talk and understand how to better use them. I'm introducing them exactly how our students get the files. So there's an analytical model that's applied to that geometry that I just showed you. And that analytical model, it's a good first order approximation to determine what your anticipated pressure drop is for any sudden expansion. But of course it comes with a cost. You have to make some very large simplifying assumptions. So I'm just going to glaze through some of the details here where we talk about what our typical assumptions are in our fluid mechanics classes and just jump to the simplifying assumption that we need to make. So when we look at all of our governing equations, we get this, this result right here where we're looking at our pressure drop. And we don't know, like I said earlier, that velocity before and after the sudden expansion. And so that's why that nice analytical model only has our aspect ratio areas in them. And in order to get rid of this velocity difference using these three equations up here, we look back at this, this geometry, and we say that if we're going from point one to point two, well, we're going to move our point one here. And we have an area and a constant uniform pressure profile that is the same as if we were back here. And then through some simplifying assumption, that simplifying assumption, we're able to come up with this, this nice loss coefficient that will define our pressure drop in that, in that geometry. So that, that simplifying assumption, like I said, is okay for first pass, but it's not true. So if you didn't want to make that simplifying assumption, you get stuck with a loss coefficient that you need to plug into. You need to know pressures and you need to know velocities within your flow geometry. So how do we do that? Well, that's when we use Mathematica. So we say we're going to use ND solve our differential equation solver, we're going to plug in our governing equations, and then we'll actually be able to probe our flow field to find out these pressures and these velocities. And if you came to my talk yesterday, I'm using the same equations that we use to simulate fluid flow, the Navier Stokes equations and the continuity equation. And the beauty of Mathematica is that we take these symbolic equations and we can pretty much type them in exactly as you see them above. And no other programming language allows you to do that. So the assignment here is for the students to one, change the aspect ratio of the geometry that the flow is going through and then also vary the flow speed through that geometry. And we asked them to compare what happens when you apply that analytical expression for the pressure drop and then apply the numerical expression for the pressure drop and look at the difference. What is the error in our analytical solution? So once we, once we introduce the physics and review that with them, we go through the Mathematica file that they'll actually use as kind of a guide to how they should walk through the problem. So we tell them the basic things that they need to do, the package that they need to download, that they need to run their initialization cells, et cetera. Because we found that most of our students actually, the first time we gave us, none of our students had previous experience with Mathematica at all. So just writing a notebook was a new thing for them. And then we kind of format it for them so it's easy to see, like, where the instructions are, what blocks of code they'll need to edit in order to generate their own results. And we walk them through opening the package, setting the directory so that they're pulling from the right spot, and then the functions within the package. So we have three different things that we allow the students to do. Like I said, we wanted them to change the aspect ratio of the flow geometry. So right here we give them the option to change the channel length. So. And we made it longer. The points of calculation that we output from this flow solver, x1 and x2, they can change the locations of those as well. And we give them the Reynolds number down here because we're requiring that they stay in the laminar flow regime. So they know that they have to be below a number of around 2,300. And that just lets them do a little check on themselves. So then we have them set their parameters, and we let them pick a mesh that they think will be appropriate for the problem. And they will quickly find out if the mesh is not appropriate from the errors that ndsolve spits out. So once we have set our parameters, we let them use the flow solver, so they input the geometric parameters that they set, the velocity that they chose that would give them an appropriate Reynolds number, their calculation points and their mesh parameters. And we just let them access whatever it would be necessary for an analysis. So they get a stream plot. They get. We'll go over what all these variables are. But we've calculated velocities, pressures, averages, and point quantities where They've selected their X1 and their X2s. We give them direct access to the actual interpolating functions that ndsolve spits out and the mesh so that they can visualize that the solver mesh. And then we just show them, like, how you would access certain parts of that results output. If they just wanted to see the stream plot, this is, this is how they would use their index notation. And if they wanted to see the mesh, this is the command that they need to use. And then we also walk them through how now to go through the laboratory assignment. So if you're going to vary your aspect ratio or you're going to vary your input velocity, what you need to do. And for the less comfortable with coding, we give them the option to run through it. One parameter set at a time. And then for those that are more comfortable, we give them the option to do a parameter sweep. So, so in this example, we run through a range of flow velocities and we say we're going to run between these two values, a U min and a umax. This is our step. And then it outputs a nice table for us. So before, when you saw that, our first output from our results function was a bunch of numbers, here, we assigned them to the variables. So we have our channel length, our widths, and so this is relevant once we start varying the aspect ratio, the input velocity, where we picked our two points, our point and averaged velocities and pressures, we give them both of these quantities so that they can start to play around and figure out, given the derivation assumption, should they be using point or average quantities. Then we also show them some of the benefits of using Mathematica, that they could combine all their stream plots and animate it and see what happens, for instance, when you ramp up the flow speed through that geometry. And then we encourage that they use Mathematica for the rest of their assignment. So it would be comfortable to do this in Excel, for instance, or Matlab or Python. So we kind of give them examples of the code that they would need to just slightly manipulate answer the questions that we ask in the laboratory assignment. So we show them how to do a contour plot, how they would take specific data points out of that matrix, actually calculate their loss coefficients across that expansion so that they can then calculate the pressure drop and how they would do a list plot if they would like to do that, and then how they could, for instance, probe that interpolating function that comes out of our ndsolve function and to draw something like the inlet velocity profile. So we try to quickly show them the many benefits that are associated with solving this system in Mathematica. And then we also, because we are trying to put this out for the public and publish this, we are thinking about other instructors here. So if they wanted to assign this to a more advanced class, maybe they're going to do a mesh analysis and try to do a convergence and see what the appropriate parameters. So we give them the option right here to change their boundary and their interior mesh size cell measures. And then maybe they want to start looking at what happens when we refine our grid. What does the velocity profile look like as you start to make your cell sizes smaller? And then you can see what happens to the results when you start subtracting them from one another. When does that difference start to become negligible. So once the students have gone through this kind of help file, there is another file that we're going to be making available. And it is the results that they should expect to see. So if they do this assignment properly and they do their parameter sweep and say they run through that range of flow velocities that they put through their geometry, and they can pull out their parameters of interest so their pressures and their velocities before and after the sudden expansion, and they can plug them into their different approximations. So here is that analytical expression with the over approximation in it saying that there's a uniform pressure profile right at that sudden expansion. And then here's what happens if you don't make that approximation and you still use the governing equations for the problem. And then finally, I've also included in this demonstration what happens if you just simply look at the two pressure points just directly from our simulation results. So not using any of these analytical models. And what we see is that our approximate, that analytical result is, it is very inaccurate compared to our numerical solution. So the numerical solution is when I just probe what ND solve gives me the true solution is when we don't make that over approximation. And we can do things like take advantage of Mathematica's ability to fit datasets, and we can extrapolate out what happens throughout the whole range of laminar flow. So here, up to a Reynolds Number of 800, we're in the bottom quarter of it or a third of it. And if we go out to the entire range of Reynolds numbers and laminar flow regime, we see that the analytical expression does a really poor job at approximating what our actual pressure drop is, which is this green curve right here. And students can start to do an error analysis on. On that analytical approximation with that. That is all the files that the students would get and then turn into us. We do have like, some poll results from them. We wanted to know about their experience since it was all of their first times using Mathematica. And for the most part, we got a pretty pleasant response, which was surprising because this lab does come towards the end of the semester, right before Christmas, but after Thanksgiving break. So there's like that push between having some time off and final. And we got some pretty good responses. I think that the only issue that they were having was that for a lot of them, it was their first time downloading Mathematica. So this Professor Zebegnu, he does all of his course notes in Mathematica. But getting started versus just watching somebody interact with the environment was the biggest hurdle that most of them had. But we're giving this again this year and hopefully we get some more good data points. All right. And does anybody have any questions? Yes.
So what is the main purpose here? To decide inside or to internalize certain, like recognize certain patterns in practice to recognize what situation we are.
So like the application of the sudden expansion is that. Yeah. So we're just trying to show that if you really wanted to be accurate about your pressure job and something like a sun expansion or contraction, which is like in every valve or pipe fitting, you would really just want to apply Mathematica to do like a quick simulation because that, that analytical expression is just so incorrect.
Yeah, yeah, this is possible to be done with.
I actually haven't done any work in the system modeler and I was downstairs this morning asking about that and I was kind of looking around at some of the different demonstrations they had. I haven't probed the fluid package yet to see what's I do under my understanding though is that most of it's pre populated and you kind of put together different elements. So I'm not sure, I'm not sure what this lab would look like in that environment.
I think you can. Right. It might be more work, but you can do the same. Exactly the situation.
Yeah.
The question is that you might not know what exactly are the grid symbols. Actually. Yeah. It's now system model interaction. Much more.
Yeah.
So okay. Well in this fitting if you go to one of the meshes you have. So is it by accident that you have denser meshes around the boundaries?
No, that's not by accident. So let me jump. Wrong screen. Sorry. Nope. So what we're getting at here is that you want to be refining the boundaries because we want to show that we're satisfying our boundary conditions. So I have to close out the screen share. It's a zoom thing. Okay.
So.
Yeah, so you're asking about like the refinement at the boundaries. Yeah, yeah. Because if you, if you don't refine the boundaries enough, you're going to get errors from ndsolve.
So.
So we're giving them the option to see here that like you can, you can really take this refinement to the extreme or you can leave it, you can leave the inside even way more coarse. So we're just trying to like give them the ability to visualize where their calculation points are going to be in the region.
Right. And in general this messages depending on say Raymonds.
Yeah. Yep. Exactly.
All right, so very interestingly here, so you, if I want to change. So this is a very regular shape, right?
Yeah, so, so just for, for the sake of this lab, it's just that shape. But we also have the, and I haven't shown this yet. Let me open that up. It's the, the solver package and we give that to the students as well so that they can. So this is part of the benefit of doing it in Mathematica is that it's not like a commercial flow solver where most of it is just under the hood and you can't access it. In this case, you can actually see what's going on. And it's also readable, unlike those low level programming languages. So let me just open that up. So if you, if you had Mathematica downloaded, you can go in and change. So we, we just make this available for whoever. If they don't have Mathematica and they just have the Wolfram player, then they can run the scripts and not change what's under the hood. But if you have Mathematica, then you can change any of this to your liking. So this is the code for generating that shape, which is really nice and concise. So you can go in and define it however you would like. And then right here, this is the code to changing the meshing of the shape. And then finally we have the code for the flow module, which is the longest, but it's still very concise compared to what those students would be doing. And you can see I've over defined my X and Y. But okay, so this is the file and we encourage them, we actually ask them a few questions about the file so that they have to go in and see what their boundary conditions are and see if that they can start to identify parts of the code and really recognize how readable it is. Anybody else have any questions? Yeah, Yeah. So like if your grid is too coarse, you're not going to capture what's happening inside of your domain. So all of your calculations are happening at the intersections. And depending on what kind of mesh you set, you specify it might be happening along the midpoints too. So let me go back so you can see here we have a lot of calculation points. So we're saying we want to know the flow field and the pressure field at all of these places. And we're giving the solver an opportunity to make less guesses about what's happening between our points because we have so many more points so much closer together. So here we're kind of like hanging nd solve out to dry. And we're saying like, well, there's a lot that could happen between these points. Like you can guess for me, and maybe it'll have enough information to do it, maybe it won't. But yeah, depending on the type of mesh that you specify, you might be dealing with triangles, you might tell it you want squares or any type of quadrilateral lateral element or perhaps more. Haven't had the need to even venture beyond this triangular mesh because Mathematica does such a good job without even having to refine it. And yeah, you can specify if you want multiple points between your intersections. Yeah. Yes. Yeah, they were very aware of that. I mean like the. Unfortunately we didn't. Since the first time that we gave it, we probably should have set up more help sessions than we did. So many of them are asking questions via email. The one thing besides that that they really didn't like was they felt that they didn't see things in real life. Like they couldn't observe anything tangible. And so that bothered them. And so we figured that our improvement on that would be we didn't give them any. So I showed you earlier how the stream plot will change with an increase in flow speed. So we didn't give them any like dynamic visualizations and they were stuck with just static observations of what was going on. And we think that really contributed to how they felt about their interaction with the lab. So we'll see if they like some of this ability to make observations in real time by just giving the visualizations a time component. Yeah.
What is the background?
So they, they all have experience with partial differential equations. These are third to fourth year undergraduate engineering students in the civil and environmental engineering department. So they've all taken classes with partial differential equations before. They finished most of their math requirements at that point, even so. And most of them have taken either like heat transfer or thermo. So they've seen very similar systems. It's just in a different application.
Yeah.
Yeah, yeah, yeah, exactly. So like one of the things that we didn't emphasize is like we're giving you a walkthrough. Like just make a copy of that walkthrough and then make edits to that notebook. Right, right, exactly. So like that is something that like we, so we did like incorporate some of their, their comments into like our reader's notes. So we tell them like they need to do shift enter. Defined variables are in black, undefined are in blue. If you know, things are just going off the wall and they need to clear the kernel just to get their program to completely reset. That's how you, that's how you would do it. So we, because they all, we have the site license, so they all have access to Mathematica, so they shouldn't be using just the CDF version.
So I guess if you go to, if you try to do this, I don't know to what degree your students have you say I don't know, 500 Jupiter.
Yeah, I'm not, yeah, I'm not very familiar with their experience with Jupiter. So.
Yeah.
Right. And that was the point is that they're able to manipulate those two aspect ratios to see how their error changes between their approximations as they go through the manipulations.
Like the packages show, it's actually, it's not exactly like a very complicated package. It is supposed to be changed by the.
So the students won't be actually changing that just because it is. They haven't coded before in Mathematica, so they don't know the right syntax. They don't know like certain standard built in functions like ND Solve. Like we're introducing that to them for the first time. They, they can if they want it, if they wanted to, for instance, experiment with this in the future. They have the file, they can manipulate it. The whole point was to, by providing them that package was for them to see how short and concise it is. Because most of them, most all of them have experience with matlab and Python and that is just to write an equation solver like for the Navier Stokes equations. And in Python or matlab they just don't have the fluency to do that.
Yeah, it might be a familiar environment.
It's not definitely, it's not, yeah, it's not practical for this application because then this would become an exercise in the tool rather than in what we're trying to show them the physical results of, of this sudden expansion. So yeah, we're trying to use like a nice high level but effective way of solving this, this experiment. Any other questions? Okay, well, thank you guys so much for spending the last part of the day with.
More from Guy

Cheryl Strauss Einhorn | The Human Edge: Smarter Decisions in the Age of AI | Talks at Google

Rachel Glennerster | Innovation and the Center for Global Development | Talks at Google

Rebecca Winthrop | Rethinking the Purpose of Education in the Age of AI | Talks at Google

Dr. Robert Wachter | A Giant Leap: How AI Is Transforming Healthcare... | Talks at Google






