PIC/FLIP Fluid Simulation in Fabric Engine (GridFluidSim3d)

AlexanderMAlexanderM Posts: 132 ✭✭


Hi folks,
I want to share my new experiment. It's not the complete tool, it's just the result of my "Fabric" + "Cpp" training.
I set a goal to study how much Fabric is ready for fluid simulation. In general, except for some shortcomings, it is quite ready.
At this moment I'm studying different solvers and libraries, and that is one of them.
I like this source code and this conceprtion, only water, with foam, bubbles and spray. But unfortunately it is not full multi-threaded, but uses OpenCL for some tasks. I will make update as soon as something changes in the source code. I share all sources with example scene.
Big thanks to Ryan Guy for sources https://github.com/rlguy/GridFluidSim3D , and he explained some of the issues, and made some fixes.
Also thanks to Oleg"Kaiser of CG"Bliznuk for consultation

upd: v.3 file is actual

Let's say NO to Autodesk®Fabric®

Comments

  • scaronscaron Fabric for Houdini Posts: 171
  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    Moin,

    that's looking quite good.

    But unfortunately it is not full multi-threaded, but uses OpenCL for some tasks.

    Well, OpenCL may be faster than multi-threading. But if you have got the opencl-code, you should be able to port it to KL and make it PEX. A grid-based simulation (my "simpleGas" is grid as well) should parallel nicely.

    Marc


    Marc Albrecht - marc-albrecht.de - does things.

  • AlexanderMAlexanderM Posts: 132 ✭✭

    Hi Marc,
    I just dont want to make changes to the original core code part. But I looked at the core code and found a few cycles, some of which can be done parallel, with "pragma omp" for example.
    But at the moment I am satisfied with the speed of this solver (I compare with other solvers, that I'm also testing) OpenCL significantly accelerates the computing, and this solver uses low of memory.
    About KL, I'll wait until when it will be possible to create classes/objects in canvas and other functional features

    Let's say NO to Autodesk®Fabric®

  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    Hi,

    I'll wait until when it will be possible to create classes/objects in canvas

    oh, that will be possible? Wow ... can't wait!

    Yeah, I understand that you want to be able to switch the external library for when a new version is available - makes sense. I am more the "redo it and put your own ideas in" type of guy :)

    Marc


    Marc Albrecht - marc-albrecht.de - does things.

  • AlexanderMAlexanderM Posts: 132 ✭✭
    edited January 8

    oh, that will be possible? Wow ... can't wait!

    I don't know exactly, I assume that this problem can not last forever)

    Let's say NO to Autodesk®Fabric®

  • AlexanderMAlexanderM Posts: 132 ✭✭
    edited January 8

    I am more the "redo it and put your own ideas in" type of guy

    I have no problem to use the free ideas and sources of those who are better than I versed in physics and coding. Priority for me is that the program worked well, not owning

    Let's say NO to Autodesk®Fabric®

  • AhmidouAhmidou Posts: 179 ✭✭

    Hey @AlexanderM, thanks for sharing, this is pretty awesome. You should consider putting it on github.
    @malbrecht this could indeed be done in Cuda PEX operators, but there's currently a limitation/bug.
    While uning single kernels are fine, making sequential kernels call is very slow, and defeating the purpose of using Cuda in that specific scenario.

  • AlexanderMAlexanderM Posts: 132 ✭✭
    I forgot to say, in this library is also implemented internal mesher and it works in Fabric (I have fixed offset issue with it and updated archive).

    After the simulation tests I want to say what it would be good to improve in Canvas
    1) It needs to improve the timeline and the player, it sometimes behaves bad, does not stop few seconds after click, and produces incorrect values, and it needs to fix synchronization between timeline and output time value
    2) I was faced with the difficulty in stopping heavy simulation. Fabric is not responding between frames. I know it's normal, but it would be nice to stop the computing with Esc button. Maybe it's my omission and it is necessary to add "hotkey tracking" in the extension code, but I don't know how to realise it now. And I think that it is necessary to add a separate "Stop/Pause" hotkey, now I found only Space hotkey "Play/Pause" toggle, it does not help stop the simulation when I click many times.
    3) I have not found the possibility to save the viewport render result as image data. I hope SceneHub extension gives this possibility

    Let's say NO to Autodesk®Fabric®

  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    Fabric is not responding between frames. I know it's normal, but it would be nice to stop the computing with Esc button. Maybe it's my omission and it is necessary to add "hotkey tracking" in the extension code, but I don't know how to realise it now.

    This is both tricky and important. Houdini, for the most of it, does a good job on it.

    One component is that Fabric itself should, whenever possible (and maybe a bit more often) do a system-loop (what this is depends on the OS, what I mean is "give the OS time to do its job") and take all interruptions seriously.

    The other component is more tricky: If you link an external library that does NOT check for interruptions, you're lost. Many "modern" (hehe) DCC use an external Python interpreter to run scripts that back-communicate with the host application. They, often, don't have any way of sending a "break" to the interpreter. So the best they can do is "break" when they are carrying out tasks handed back from the interpreter - which may have a "hanging" script as the outcome.
    Meaning: If the external libraries don't respect user interaction, there may not be much Fabric can do EXCEPT for taking care of all break commands it receives for itself.

    THAT I would like to see.

    Marc


    Marc Albrecht - marc-albrecht.de - does things.

  • scaronscaron Fabric for Houdini Posts: 171

    In this case it is Fabric calling this function... fluidsim.update() in it's own loop right? So this is on Canvas/FabricEngine break that loop. But how to do that well is still difficult, I am unsure of how to do it in KL at this time.

  • AhmidouAhmidou Posts: 179 ✭✭
    edited January 9

    Hey @AlexanderM I can't get it woking, on my system, I'll try at home tonight, but it's crashing at home.
    First I had to copy openCL.dll from my system32 to the extension folder to get it to load. I had multiple versions of it but it seems that
    the good one is the 1.2.11.0.
    Once I got the extension loaded, I tried the sample graph (which is disconnected by default right??) but it's crashing every time.
    for some reason it's failing at creating the positions cl buffer:

    ERROR: Creating position data buffer (-37)
    Assertion failed: err == CL_SUCCESS, file src\clscalarfield.cpp, function CLScalarField::_checkError, line 522

    Have someone got it working?
    Thanks

  • AlexanderMAlexanderM Posts: 132 ✭✭
    edited January 9

    Hi Ahmidou,
    I will find out what the problem. But this extension works fine on other computers I asked to check.
    Do you have the NVidia device? I tried to compile with different OpenCL libs "NVidia" and "Intel". Now it compiled with NVidia libs.
    I will try to compile it for your device. Is it the Intel CPU?

    which is disconnected by default right??

    Yes, you need to connect the execute node

    I have recorded the process on old Intel Q6600 + GTX780 with 320 driver version

    Let's say NO to Autodesk®Fabric®

  • RLGUYRLGUY Posts: 1

    Hey @AlexanderM, that test video looks amazing!

    @Ahmidou said:

    Once I got the extension loaded, I tried the sample graph (which is disconnected by default right??) but it's crashing every time.
    for some reason it's failing at creating the positions cl buffer:

    ERROR: Creating position data buffer (-37)
    Assertion failed: err == CL_SUCCESS, file src\clscalarfield.cpp, function CLScalarField::_checkError, line 522

    Have someone got it working?
    Thanks

    Hey, I'm the author the fluid simulator code. I have only had a chance to test the code on Windows using an Intel graphics chip, and also using an NVidia graphics card. I am not too experienced with OpenCL, and I am not sure what is the cause of that error. I just thought I would provide some information on the error in this post.

    Error code -37 is a CL_INVALID_HOST_PTR error.

    The OpenCL command that is causing this error can be found in the GridFluidSim3D GitHub repository here (Line 1182 of src/clscalarfield.cpp):

    buffer.positionDataCL = cl::Buffer(_CLContext, 
                                       CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, 
                                       pointDataBytes, 
                                       (void*)&(buffer.pointDataH[0]), 
                                       (cl_int*)&err);
    

    Documentation for cl::Buffer can be found here (on page 12).

  • AhmidouAhmidou Posts: 179 ✭✭

    Hi @RLGUY, thanks for the infos, but there's definitely something wrong at work, it's working straight on my personal laptop.
    I'll try to investigate later this week.

    Cheers

  • borjaborja Administrator, Fabric Employee Posts: 480 admin

    @AlexanderM
    Thanks for your feedback. I have filed internal ticket FE-7926 to implement a "playbast" like feature in Canvas and FE-7927 to make Fabric more responsive when trying to cancel computations.

    Borja Morales
    Technical Product Manager
    Fabric Software Inc.

  • Xue CuiXue Cui Posts: 2
    edited May 29

    Hey man,

    I am very interested in your work. But I am quite new to FE. Now I have your files downloaded and successfully loaded your scene in to the canvas. But when I connect the results to exec, it returns and says some FLIP nodes "Type not registered" (port 'outFLIP': 'almFLIPObject': type not registered / port 'inFLIP': 'almFLIPObject': type not registered / port 'inFLIP': 'almFLIPObject': type not registered). I am considering maybe there is a problem for the extension path or maybe I put the file in wrong location? (I put your whole file at FE_ROOT_DIR/Ext/Builtin/)

    I wish there would be more official tutorial for basic step by step tutorial for writing a cpp extension for FE. I saw Kludge but its documents has many missing words which makes some idea so confused.

  • AlexanderMAlexanderM Posts: 132 ✭✭

    Hi Xue Cui,
    Do you use 2.4 version of Fabric? This extension is compiled for 2.4 and dont work with 2.5. Your log looks like extension is not loaded.

    I also want to see more tutorials, but as I know Kludge also uses EDK, and because it I don't see a big reason to stop using SCons. For starting you may install SCons and look at the scons script examples from extension projects, there is all "hard" of setup of cpp extension

    Let's say NO to Autodesk®Fabric®

  • Xue CuiXue Cui Posts: 2

    @AlexanderM said:
    Hi Xue Cui,
    Do you use 2.4 version of Fabric? This extension is compiled for 2.4 and dont work with 2.5. Your log looks like extension is not loaded.

    I also want to see more tutorials, but as I know Kludge also uses EDK, and because it I don't see a big reason to stop using SCons. For starting you may install SCons and look at the scons script examples from extension projects, there is all "hard" of setup of cpp extension

    Hey Thanks! Yeah. I tried it on 2.5. I will have it tried on 2.4 for sure!! Thanks a lot! Yeah, I just had pain on using scons for compiling PHYSBAM. Seems I will meet it here again!

Sign In or Register to comment.