 Welcome to today's session on Fluid Simulation with Mantaflow and Well, yeah, my name is Sebastian Boschkes. I'm the one who's been working on Fluid Simulation for the past two and a half years and Well, I'm still a computer science student and I'm working together with Niels Tuggeri from Teominschen and Well, we've been working on several types of fluids and Today I want to show you some stuff that I've been working on over the past two summers basically the two school summer of course that participated in and Yeah, let's get right into it Well, this is actually my very first test scene that I created when I started the project and I Just thought it was funny to show you the little animation that I made at the time so this was my very first fluid animation if you so will and What's interesting about this simulation is that it's super ugly and That the message is basically that there is so much more room for fluid simulations and blender and of course You can create a much better simulation with the current blender version, but we are going to make it even better with Mantaflow so here's a short overview of the The entire project so it started back in 2014 there was one developer before me's who did a Google summer of code project as well so he basically started with the basic smoke simulations and the Python API and One year later, I picked up the project so he left by the time and I picked up the project and Actually was going to do or was planning or hoping to do a Google summer approach code Google summer of code project but Turned out that Linda didn't get selected that year. So I just worked on the project by myself as part of my bachelor thesis and Yeah, I finished fire effects high resolution smoke effects, you know the wavelet noise that you know from blender already and Then the next year 2016 I actually got selected into the Google summer of code project and that was the year where I Started with the integration of liquid effects So it turns out that liquid and smoke are actually from the developers perspective perspective very similar so it made a lot of sense to move the liquid into the smoke modifier and That sounds maybe sounds a bit counterintuitive, but That's the way Montaflo works and so what I did is I created this unified Montaflo solver in blender and so every side everything is unified the cash is unified and it just makes things a lot easier and Well this year I did a second project and was slightly different. I worked on flip effects or flip the flip side the flip particles and also the secondary particles which you already know from from blender I Think there is drop tracer and flow particles already and I added to Montaflo even bubble effects and then the second part of my Google summer of code project was the fluid guiding part and that basically is a technique which allows you to Enforce a velocity field onto a fluid simulation and this creates a artistic motion if you so will well, yeah, now it's 2017 and Blender 2.8 is on the shelf or nearly and well I'm at least hoping that we can get this integration into a blender 2.8 and so that you all can play with it Yeah Next up I have two papers for you because as you know behind every good algorithm There is some science and some people who think about it and These are the two papers that will influence my project a lot. The first one is the one on the left-hand side the narrow band flip for liquid simulations and the idea that the author's hat is Actually quite straightforward You have at the bottom right you have the simulation where you have a liquid with entire volume of the liquid is filled with flip particles and If you think about it, this is actually quite a waste of memory and computation time because in the end what actually makes the Fluid or the liquid look good is just a surface So the idea that the author's hat was to say, okay Let's just model the surface that make a narrow band where the particles live in and simulate just that just that and So you can see we have at the top scene you have 100,000 particles and at the bottom scene for the same scene you have six times as much particles and this saves a lot of computation time so it's quite an improvement and the good thing about this paper is that the authors already implemented the entire Algorithm in Montaflo so it's actually quite easy to port it over to blender. It's just a matter of pushing the files over to blender and the second paper is the one on Fluid guiding which was published just this year it's primal do up dual optimization for fluids and in this paper or part of this paper deals with the idea of having this Target velocity grid which you then take and enforce onto your simulation So in this case you have this little smoke inflow and In the background you can see the the velocity field and it's giving this spiral like rotation and that rotation is then in the pressure solve applied onto the actual smoke density field and Actually, what's what's so nice about what I wanted to show with these two papers is that Every time we get one of those advances in research with Montaflo We can directly apply it into or port it over to blender. So it's actually very easy Yeah Let's talk a bit about blend our Montaflo itself so Montaflo itself is actually a fluid simulation framework for research and It's mainly used by professors and PhD students to test out the algorithm But they also have a very nice GUI as you can see here on the left-hand side You can view the Each of the grids that you have in your simulation for example in this scene It's showing the obstacle grid. You have the sphere in the in the middle and this is the obstacle and Yeah, the entire Montaflo is based on C++. So it's fast enough for blender as well It has a plug-in like structure or architecture And this makes it quite easy to develop new algorithms. For example, when I worked on the fire effects I just had to write the algorithms put them into a plug-in and copy that plug-in over to Montaflo and Then in a next step from a Python theme I was able to just call the functions and have my simulation running So and then I'm at my next point and that is the Python Scenes so the way you interact with Montaflo is directly through Python. So you have a Python script and There are several building blocks. So At the top you always declare your model your your solver object So that can be either 2d 3d then you can set the domain size those sort of things and Later on you say okay, what what data structures do I need what grids do I need to any particle systems? And I don't want to go to everything that's on the slide But the main idea is that you can break down the script or you can tear it apart That's basically what I did in blender You can tear it apart and have those Python snippets as I call them and these Python snippets Are callable from blender so you can call them at any time in your simulation and say okay I want to change my solver object change their resolution and Just you just call the snippet and it gets actually executed and changes your your setup and This is actually quite convenient because it makes the whole process of On one hand most makes the process of developing very easy. You can export the the scene as a Montaflo script So to say you reverse engineer your simulation So you have it in blender and then port it over to Montaflo and then debug your code But that's not the point. That's just the development side The major point is to have a setup that's suitable for the future node editor and the node editor is still a future project, but Nils and I think that this is the perfect basis for such a node editor and I mean Other platforms like I think Houdini has a node editor and it would just make sense to have a Node editor in blender as well. So, yeah Now, let me talk about a bit that a bit of the stuff that changes and bit of the stuff that remains the same because With smoke and fire for example The algorithms that are in Montaflo are pretty much the same that are in blender already So it's just a part of the code or that there's no too much difference So when you use the new smoke simulator, you will use the blood in the Montaflo simulator, but you won't see much difference Another thing that I'd like to mention is If you've played around with this smoke simulator, you know that there is the adaptive domain and with Montaflo unfortunately, this won't be possible because of the way it has organized its memory and I don't see this changing anytime soon. So this won't be possible however, I think as I mentioned earlier, there are quite a few optimizations like the narrowband with the flip liquids would make up for this for this shortcoming and so These are some of the news new things like the flip liquids then adaptive time stepping adaptive time stepping is when you have Two frames frame one frame two and you compute in between those frames extra computation steps this is especially useful when you have very fast simulations and Basically, you can just toggle it on and off and it works automatically and then of course the other two parts that are new are the fluid particles and the fluid guiding that I worked on this summer and Yeah, that's also a bigger change Okay, and the rest of the stock will focus on the new parts. So that's what's highlighted in the box and Before I forget it. I want to mention this terminology change because it's actually a bit Different in the current blender current blender uses fluid for liquids and actually a bit misleading because smoke is a liquid and Smoke is a fluid and liquid is also a fluid So just keep that in mind when using the new simulator that you will see a fluid modifier and Inside the fluid modifier you find subtypes liquid and smoke. It's just terminology cleanup Okay So now I've been using the term flip the entire time and maybe some of you don't know what flip actually is Flip stands for fluid implicit particle and what that means is that the entire simulation is actually if particle simulation so the particles track the surface and Then in a later step you can generate a mesh from those particles. So the mesh is actually just an addition and Yeah, for the cash this makes also sense you can then choose between the between simulating the just the mesh or just the particles or both and This is the mesh and the particle are really just the outcome of your simulation And here you can see one of those really high-resolution splashes This is 512 divisions and you can really see in the middle the high detail We can see all the Particles in the scene. Yeah, okay here. I have a Small comparison of the current blender and the blender with month of low version. So at the top half you see the this is the current Blender fluid simulation as it is right now and What's interesting about the the splash or what most people complain about in the splash is that The drops are actually not real drops. They are these little like strands or strips. They're I mean They look okay, but not too realistic and with month of low it changes a bit you get more uniform splash and Yeah, it's really up to the artist to say what's looks well what what looks better or what looks more realistic and I would just say that with month of low you always get a bigger splash, so to say it's much more detail in the splash and Just a richer fluid simulation Alright, so now let's move on to the first demo that I have for you and Let me just change to blender Open up the first scene and Well, this is what I talked about earlier. This is the new fluid you I and in the fluid modifier You have different types of domain you right now. You have just two you have just the gas type and the Liquid type so gas would be smoke or fire and liquids is just liquids So it's inside one modifier here. You can see the old modifier, which will hopefully be removed very soon and Yeah, this is the single one the single fluid modifier and Another thing I wanted to show you is the fluid cache. So I mentioned earlier Flick Rickets is either just particles or just or mesh or you can mix and match them and this is what the UI at the bottom here is all about it's on one hand the surface format that you define so that would be the mesh and You can also toggle the volumetric format, which would give you the the flip particles Okay And that's all for this demo now I will come back to the scene in just a second Let me just go back to the slides And move on to fluid particles So I've been talking about flip particles the entire time So it's the fluid implicit particle that makes the surface you on the right hand side. You can see those two images top one is exclusively flip particles and the bottom one is overlaying a mesh and the fluid particles and The most interesting about fluid particles actually the secondary particles and you know the from blender already and The same Well, the same technique is now implemented in month of law as well So you have drop bubble float and trace the particles I think bubble particles doesn't even exist in the current blender. So it's and one new type of particle and then I put there that The upper three ones so drop bubble and float are recycled and What that means as you will see it in just a second is that these particles Run through a particle life cycle. So the drop particles generated then convert it into a bubble and then again convert it into a float and I have another visualization here and this is basically just the different fluid particles stacked on top of each other so you have the Tracer particles that fill up the entire volume then the float particles on the surface bubble and drop particles which make the crown of this splash and then flip particles which also Are at the surface. All right. Now I have this little Sketch here to show you how the particles are actually generated. So flip particles It's clear. They are at the surface and they are generated automatically. You don't have to worry about them You can just visualize them, but everything else is up to the simulation itself Now to drop particles, how do you generate the drop particle? Well, if you think about it, it's actually or if you think about where you have drop particles Then just quickly realize that drop particles usually Are generated at very fast moving fluid objects So for example, you have this wave and at the tip of this wave you would want to generate a drop particle So the first check that you have to perform is okay is The shape convex in this for is it is it the tip of the the fluid and is it fast enough? And when you have Made those checks you can generate a flip a drop particle send it off on its own way with its own velocity And then right at the bottom. I put this Oilers method. This is just the formula if you don't have to understand it This is just a formula that it's used to compute the next particle position Yeah, so this particle is on its own way. It's Generated there's some gravity applied on it and then it's falling onto the surface and One day once it hits the surface it gets converted into the bubble particle The bubble particle itself will then Get some buoyancy so that it floats to the surface and once it's at the surface it gets converted into the particle Okay, and this is the particle lifecycle. I was talking about and So you have the drop particle is generated and everything else happens on a set on its own Now on to that's the life cycle Now on to the tracer particles because the tracer particles are a bit on their own so how they work is basically that You have a probability and This probability tells you how likely you want to generate a particle in a cell. So for example if you say, okay Tracer particles with 100% probability Probability means that in every cell I would generate a particle 50% we would mean Okay, on average every second cell gets a tracer particle Yeah, and the same can also be used for float particles. So if you want to add some more float particles you can add the same Technique with probability and sample more float particles at the surface Okay, that's this theoretical part Now let's go to the more practical Part and that's this demo scene and in this demo scene. I've already baked it. I have this inflow object at the top. It's just a Liquid splash It's not a particularly a highly resolution, but that doesn't matter for now. It's just this splash And what I'd like to do now is maybe stop it at frame. Yeah frame 30 And now we can go in the through into the fluid UI and to the fluid particles UI And here is what you see is all the different particle types It's a bit grayed out right now, but that's because of the cash is already baked and Yeah, I've enabled all of them and what you can then do is you can go on to the particles in the vase and you'll see that for each particle type you have an known particle system and We can take a look at them and you'll see okay here You can see the flip particles at the surface of the fluid Then we have the drop particles flying around in the in the air so to say then moving on a bit into the fluid we have the Drop particles at the bubble particles as you can see they rise to the surface and then we have at the surface the flow particles Again floating only at the top and These are actually quite similar to the to the flip particles, but they are actually originating from the drop drop particle and Then at the end we have tracer particles In the entire volume of the fluid So these move with the flow of the fluid Okay, so I think once you play with these particles. It just makes a lot more sense and It's actually quite fun to play around with Okay moving back to the slides Let's move on to fluid guiding so fluid guiding is as I told you a Method which allows you to enforce a velocity field onto a simulation and Blend or month of flow itself will then ensure that the whole Simulator that the motion stays divergence free that basically means that there is no Unrealistic behavior happening and So the way we approach this problem or this problem of creating a fluid guiding scene is that we say, okay We need a guiding object So for example, we take the cylinder object and we say, okay, we animate it for example, we could say, okay, this cylinder rotates around the z-axis and This way it creates a velocity field. This velocity field can then be taken and Handed on to the internal mantra presses pressure solve and then we can also define blur and Blur and the weight and the blur is you can see on the right hand side basically just the size of the vortices vortices in the in the guiding and Yeah, this will give you Something similar to this This is something as I I rendered Took quite some time to render but what you can see is that the smoke follows this guiding motion in the against counterclockwise so Actually, this is I mean the possibilities with this are endless you can Perform any more any motion you can think of all right. So now let's take a look at Fluid guiding. I've also prepared a small scene for that and Yes, that's the tornado demo That's okay. We have again. We have a domain object and In this case, it's a gas domain for the for the smoke effect Then we have in the center. We have the small torus which will be our smoke inflow and Then we have this cylinder which I showed you earlier and the cylinder is animated and will rotate around the z-axis and will thus create the velocity field and once we play the simulation you can see okay, it generates the motion and The density follows the animation All right So, I mean the the cylinder example is probably the most straightforward example, but you could also say okay Let's create a create a path and let's Let's and our guiding object follow this path and then we get a fluid motion along this path Be also possible. Okay I am wanted to show you one more thing. I Wanted to show you the fluid Exporter and That's down here. So I told you that you can reverse engineer your simulation by exporting the scene as a month of low script And that's probably only for the developers of you, but what you can do is we can step to like this frame export our scene then bring up month of low so month of low is started from the terminal and We can feed in the the month of low script Run it and what we'll get is you will get the month of low GUI and the month of low GUI basically gives you Or gives you the ability to step through through the the individual grids And what you can see here is the density field This is this just a two-dimensional view from the top and we could also say, okay, we want to step Into the simulation So now you can see the velocities you can Scale up the velocity scale down the velocities and there are a couple of more grids So this is a density grid and there's a pressure grid obstacle grid External forces guiding field Weight density and so on so it's actually quite fun to play around with but Yeah, it's mostly it. It's mostly useful debugging and developing new stuff. All right, so then let's switch back to the presentation and My last example I would like to show you a bug that we had and this bug was reported by Gottfried Hoffmann and This example just shows a bit of the process of how You how I solve the problem or how we get from bug to working program so in this case he reported that He had this coffee mug and With liquid inflow and the coffee or the liquid simply wouldn't hit the obstacle And so the problem with this team was that the obstacle was simply too thin and This can happen because Montafloor is based on a on a it relies on an obstacle level set Basically a grid and when the resolution is too high and the obstacle is too thin It can happen that it simply doesn't recognize the the obstacle and what you can do in this case is you can say, okay We artificially thicken the obstacle And what you get here is a thickened version of the obstacle and this is important for for Montafloor so that it Actually recognizes the obstacle Okay, so here at the bottom you see the the the level set as it thickens from zero to two point five You can just go to any value make it thicker And the second reason why you might not get an obstacle or obstacle collision is that your time step is too big and That's where the adaptive time stepping comes into play when you have very fast moving moving fluids It I would say in most of the cases it makes a lot of sense to enable adaptive time stepping it will Take a lot more time to compute those extra steps, but in the end it will give you the effect that you're looking for So I would always switch it on if possible Yeah, and here you can see at the bottom This is what happens when you don't have adaptive time stepping you might get a situation where the particles are actually one step ahead and never knew about the the obstacle all right a Couple of next steps that are on my agenda at least So some to-dos for 2.8 are especially just bug fixes So I'm not going to do any more features. I'd say I'm just going to focus focus on bugs and therefore I heavily rely on bug reports on and bug feedbacks from from blender artists or from wherever You send me a message Then of course next step would be to remove the fluid modifier the old one Because it's actually not necessary to have two liquid simulations liquid simulators and the new one should simply replace the old one and Then of course next step would be to merge this branch into 2.8 and see how it performs and Yeah, to have more people play around with it and I also have some ideas for future projects But those projects are definitely after the 2.8 release I would say and that is one on one hand the node editor the node editor I Think it makes sense to have because the entire setup that we have right now implemented would make it Or should make it possible to have and then the second thing thing is Again fluid particles, but for the gas domain and if you think about it it would be actually quite feasible to have like fire sparks around the fire simulation that are automatically generated and Follow the the motion of the fire. So that will be actually quite a nice effect Yeah, so that's about it More information can be found on my blender wiki there I have basically all my Google summer of code reports and there you can also find some tips on how to build the branch and Yeah, general stuff just Another link that I'd recommend you is the website from the research group there You'll find all the the papers and also cool videos and Simulations, yeah, and that's about it and yeah questions Yeah, I'm just gonna start at the left hand side. Yeah Before you get too keen on throwing away the old fluid simulation. What's the back compatibility support? I've got 2.8 or 2.7 sorry 2.7 7 blend file with some fluid in it at the moment Am I not going to be able to run it in your brave new world? You I mean it's not going to be Compatible because it's a completely different different approach The flip has simply has a lot of different settings So it obviously wouldn't work and wouldn't also make sense to port those settings So I'd say no, I mean you all Scenes would then probably only work up to 2.7 9 or whatever If we decide to remove the fluid modifier, but I would say so. Yeah. Yeah more hands Do multiple In particle simulations interact with each other. So if I have us to smoke simulations, can they interact? Mmm, you mean to diff to separate domains. I don't know if I can set up one of two Spawn objects in one domain then it would solve the problem But if I would have two separate simulations So I mean if you have two Like smoke inflow objects in one smoke domain, they would interact. Yes, okay, but if you had one Smoke inflow and one liquid inflow they wouldn't work Okay, and it seems like a pretty robust particle system wouldn't it be To wouldn't it be possible to replace the old system? You mean the entire particle system? Yeah I mean if we would do that I guess then the entire games community would throw me out of the window because the I guess the current particle system in blender is SPH particle system and that's Lot better for real time because everything that you just saw is just heavy computation. So Yeah, thank you very much Does the the guiding also support? Geometry that's changing and like surface to form and stuff does that affect the the velocity at all you mean for example Like let's say you take that cylinder right and you throw like a displacement modifier on it And you just have it move around a little bit with a texture would that affect the the overall Movement of it is all mmm. I mean I would say it should work but I mean this is really experimental even the The developers of the fluid guiding didn't know of if the the liquids really work with the guiding so in theory it should work But I guess no one has really tried it out yet. I'll test it. No, yeah It was a while when I last loaded up month of flow, but I still have the questions You said that you don't want to add any new features, but right now is We scosity as a setting. Is it available right now? Not yet. Will you add it? Before 2.8. Hmm. Good question I would say probably not Just because I would rather focus on the bugs that are currently there But I mean viscosity is a pretty pretty big feature in that case I would say don't remove L beam until viscosity is a month of true So that's yeah, that's one one more thing we have to discuss now Because viscosity is currently not supported in month of low So that would first have to be developed and yeah Yeah, she was From the user point of view how easy is to play with these settings to achieve desired Flow velocity or for example for smoke and I Know The old system was quite difficult to you know to you you would need to play around and yeah Try different settings and you know, it's more Triline error. Yeah to get what you want. Is it going to be easier? I mean I Designed the from the UI perspective. I would say you definitely yes because everything is in one place and That's it The one thing that especially with guiding that would be problematic is that it just takes a lot of resources for the computation what you just saw was already baked but If you really crank up the resolution it can get really really expensive very quickly So just keep that in mind but of course there's also something I would like to improve is the The ability to play around with a low-resolution simulation and then later on When you see that it looks like what I want to simulate the big one. Thank you another thing Can you animate for example if using or no the multi-threads like the instance to when they hit obstacles? just to enable it from let's say frame 10 10 to 50 and After that just don't use that so it's like a quicker computation after that because the velocity maybe when the obstacles like the coffee cup is filled up is not going to Particles are not going to pass anymore through the thickness of the object so Maybe would be I don't know to don't use any more the multi samples between frames So can be animated that let's say use them between only in 10 frames that you need them I mean, I don't know exactly what what you mean, okay? So you you you use that multi-threads because the particles are passing are very fast and are passing through the Coffee mug. Yeah. Yes. Yeah Samples can be animated You mean the time steps in between of this it yes, I mean, okay the liquid is going to hit the mug at frame 10 and From frame 15 is not going to I will not need it Anymore because the velocity is not high, right? So I will not need that thing You mean you will not need the obstacle anymore. Yeah Velocity will not pass through Yeah, just on and on and off and animate the adaptive time-save Right now You cannot but it would be really easy to implement that I mean like the I mean it's similar to the Inflow which you can enable and disable and keyframe. Yes, I don't think you need them always. Yeah I mean that would be easy to add Yeah, thank you. I Think he was one question at the front No, no, no. Yeah, I have a question regarding the the obstacle object Can the obstacle object be animated while it's filled up with water? Yes, and then still be and the fluid will react to it. Yeah So the obstacle can move around first. Yeah, for example, you have a character You want to fill it up with water? Yeah, and then the character would would move and the water inside would yeah would react to it Sure. Yeah In the as long as it stays in the domain the obstacle. Yeah. Okay. Thank you. I think not anymore If I've got a physical object that can I float it in your fluids or can your fluid only flow around it? Like a passive object you mean like a little ship which floats Yes Ship the first and is carried by your fluid as part of its simulation. Do I have to animate the ship myself? I think right now you'd have to animate it But I remember that Niels told me about the paper that he's working on and I think he's working on it To have floating objects in the simulation. So it's future project Are there any plans for optimization of Mantaflow? so like maybe better multi-threading faster algorithms or Maybe like support for graphic cards like in Houdini you got open CL Accelerated simulations, which is pretty extreme Not that I know of I know that they once had One of those mantaflow scenes Implemented for a CUDA. I think it was the the vortex heat which was implemented for CUDA But I don't think there are any plans for that They're mainly focusing on new papers right now so but and I mean We already have in in mantaflow the the entire system is accelerated with either open MP or TBB yeah, so depending on what you're running So cut right now if you're running on a Mac it automatically switches to TBB because open MP is a mess right now, but Other than that it would switch on to open MP. Any more questions? Okay