Adaptive time step for fluid particles #27442

Closed
opened 2011-05-20 01:45:51 +02:00 by Alex Fraser · 11 comments

%%%This patch adds a feature to allow the number of subframes to be altered automatically while a particle simulation is running. Currently, only SPH fluid particles implement this feature.

The code works by calculating the maximum Courant number- [x] for the simulation. The user inputs a preferred Courant number to aim for. If the calculated Courant number is greater than the preferred one, the time step will be reduced; if it is greater, the time step will be increased. The Courant number is calculated by comparing the speed of each particle to the distance to its neighbours. But first, the speed of its neighbours are subtracted from its speed: this allows free-falling particles to simulate with zero subframes. Turbulent flows will simulate with more subframes.

This patch modifies the simulation loop in system_step to allow the time step to vary mid-frame. However, the last time step in the frame is adjusted so that it syncs with the end of the frame. Then, the effective number of subframes is stored as the initial time step size for the next frame. This causes the time step size to oscillate a little, but the results are still good.

Attached are some sample files for testing. Note that, although the adaptive subframe feature is stored in the .blend, it currently isn't read because it is waiting for a version bump for do_versions. Therefore to run these tests, you will need to enable adaptive subframes: find the Subframes control in the particle properties, and tick the new checkbox that is next to it; the Subframes control will then be replaced with one title Threshold, which controles the preferred Courant number. Values of 0.2 - 0.4 are sensible.

  • http://en.wikipedia.org/wiki/Courant%E2%80%93Friedrichs%E2%80%93Lewy_condition%%%
%%%This patch adds a feature to allow the number of subframes to be altered automatically while a particle simulation is running. Currently, only SPH fluid particles implement this feature. The code works by calculating the maximum Courant number- [x] for the simulation. The user inputs a preferred Courant number to aim for. If the calculated Courant number is greater than the preferred one, the time step will be reduced; if it is greater, the time step will be increased. The Courant number is calculated by comparing the speed of each particle to the distance to its neighbours. But first, the speed of its neighbours are subtracted from its speed: this allows free-falling particles to simulate with zero subframes. Turbulent flows will simulate with more subframes. This patch modifies the simulation loop in system_step to allow the time step to vary mid-frame. However, the last time step in the frame is adjusted so that it syncs with the end of the frame. Then, the effective number of subframes is stored as the initial time step size for the next frame. This causes the time step size to oscillate a little, but the results are still good. Attached are some sample files for testing. Note that, although the adaptive subframe feature is stored in the .blend, it currently isn't read because it is waiting for a version bump for do_versions. Therefore to run these tests, you will need to enable adaptive subframes: find the Subframes control in the particle properties, and tick the new checkbox that is next to it; the Subframes control will then be replaced with one title Threshold, which controles the preferred Courant number. Values of 0.2 - 0.4 are sensible. - [x] http://en.wikipedia.org/wiki/Courant%E2%80%93Friedrichs%E2%80%93Lewy_condition%%%
Author

Changed status to: 'Open'

Changed status to: 'Open'
Member

%%%Assigned to self for review.%%%

%%%Assigned to self for review.%%%
Author

%%%The code currently prints out some debugging information to show the current time step. This is for your interest while testing, but it should be easy to remove. I can remove it if you like; just let me know.%%%

%%%The code currently prints out some debugging information to show the current time step. This is for your interest while testing, but it should be easy to remove. I can remove it if you like; just let me know.%%%
Author

%%%Ooops! I forgot to reset the max Courant number to zero after each time step, so the time step would often shrink to 1/100th of a frame. I have added a new version of the patch that fixes this. The new version also prints out the Courant number on the console as CSV for graphing. The fields are: frame, partial frame, dt (in frames), Courant number, subframes. For example, this is the trace for frame 21 of a simulation:

21.000000,1.000000,0.228203,0.298578,3
21.250000,0.250000,0.250000,0.351534
21.534468,0.534467,0.284467,0.379051
21.834656,0.834657,0.300189,0.392197
22.000000,1.000000,0.165343,0.252009,3%%%

%%%Ooops! I forgot to reset the max Courant number to zero after each time step, so the time step would often shrink to 1/100th of a frame. I have added a new version of the patch that fixes this. The new version also prints out the Courant number on the console as CSV for graphing. The fields are: frame, partial frame, dt (in frames), Courant number, subframes. For example, this is the trace for frame 21 of a simulation: 21.000000,1.000000,0.228203,0.298578,3 21.250000,0.250000,0.250000,0.351534 21.534468,0.534467,0.284467,0.379051 21.834656,0.834657,0.300189,0.392197 22.000000,1.000000,0.165343,0.252009,3%%%
Author

%%%Also, both patches apply against revision 36757. Let me know if you want an updated patch against HEAD.%%%

%%%Also, both patches apply against revision 36757. Let me know if you want an updated patch against HEAD.%%%
Author

%%%Added a new version of the patch: dyn_subframe_vector3.patch. This one still applies against r36757. Changes:

  • Default Courant number of 0.2, instead of 0.4.
  • Tooltip now suggests a range of 0.1-0.3.
  • Invalidating particle cache when enabling adaptive time step.
  • Removed debugging print messages. To see them (if you're curious about how the code works, or to make some charts), use version 2 of the patch.%%%
%%%Added a new version of the patch: dyn_subframe_vector3.patch. This one still applies against r36757. Changes: - Default Courant number of 0.2, instead of 0.4. - Tooltip now suggests a range of 0.1-0.3. - Invalidating particle cache when enabling adaptive time step. - Removed debugging print messages. To see them (if you're curious about how the code works, or to make some charts), use version 2 of the patch.%%%
Author

%%%Attaching two files that show how the simulation progresses for the Drop.blend test, with a Courant target of 0.2.

  • ATSChart_Drop.png is a graph of the time, timestep size and Courant number versus simulation step.
  • Drop.png shows screenshots for two frames of the test.
    In both images, (a) shows the state immediately before the particles in the tube are released, and (b) shows the state immediately before the falling particles land in the bowl. The graph shows that the time step is small while the bowl fills. As the fluid slows, the time step increases. When the particles in the tube are released the time step decreases again, and becomes very small when they strike the stationary particles. This is because at that time, their relative velocities are very different.%%%
%%%Attaching two files that show how the simulation progresses for the Drop.blend test, with a Courant target of 0.2. - ATSChart_Drop.png is a graph of the time, timestep size and Courant number versus simulation step. - Drop.png shows screenshots for two frames of the test. In both images, (a) shows the state immediately before the particles in the tube are released, and (b) shows the state immediately before the falling particles land in the bowl. The graph shows that the time step is small while the bowl fills. As the fluid slows, the time step increases. When the particles in the tube are released the time step decreases again, and becomes very small when they strike the stationary particles. This is because at that time, their relative velocities are very different.%%%
Author

%%%Attaching a new version of the patch (version 4) that deals with determinism. The previous version was deterministic between runs, but if two objects shared the same ParticleSettings they would evaluate differently. Now, the time step size is stored in ParticleSystem instead, so the state is not shared between objects.

Also attached is a .blend that demonstrates this. It contains two emitter objects that are identical, and share a ParticleSettings object. If you play or bake the animation, you should see that the particles in both systems are in the same locations. Try selecting just one of the emitters to visualise this: if the particles were in different locations, half of them would not be outlined as selected.

Subsequent runs should also produce the same results.%%%

%%%Attaching a new version of the patch (version 4) that deals with determinism. The previous version was deterministic between runs, but if two objects shared the same ParticleSettings they would evaluate differently. Now, the time step size is stored in ParticleSystem instead, so the state is not shared between objects. Also attached is a .blend that demonstrates this. It contains two emitter objects that are identical, and share a ParticleSettings object. If you play or bake the animation, you should see that the particles in both systems are in the same locations. Try selecting just one of the emitters to visualise this: if the particles were in different locations, half of them would not be outlined as selected. Subsequent runs should also produce the same results.%%%
Author

%%%This new version of the patch follows up the discussion around attribution. A notice that will appear on the credits page on the web has been added (in intern/tools/credits_svn_gen.py). The attribution notices in two of the C files have been modified to show what the change was, so that it is clear copyright is not being claimed for the whole file. This roughly follows the convention in some of the Linux kernel files, such as http://lxr.linux.no/linux+v3.0.4/kernel/cgroup.c

By making a contribution to this project, I certify that the contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file.

Signed-off-by: Alex Fraser adfries@vpac.org on behalf of VPAC Ltd.%%%

%%%This new version of the patch follows up the discussion around attribution. A notice that will appear on the credits page on the web has been added (in intern/tools/credits_svn_gen.py). The attribution notices in two of the C files have been modified to show what the change was, so that it is clear copyright is not being claimed for the whole file. This roughly follows the convention in some of the Linux kernel files, such as http://lxr.linux.no/linux+v3.0.4/kernel/cgroup.c By making a contribution to this project, I certify that the contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file. Signed-off-by: Alex Fraser <adfries@vpac.org> on behalf of VPAC Ltd.%%%
Member

%%%Committed, revision 40537.%%%

%%%Committed, revision 40537.%%%
Member

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#27442
No description provided.