hunar4321/particle-life

Superfluid

Opened this issue · 10 comments

Hi! Viscosity quantifies the internal frictional force between adjacent layers of fluid that are in relative motion. So, Viscosity is a characteristic of the substance. So in this application it should be a parameter of the substance, i.e. the colour. So each colour should have its own viscosity. If a user wants to define red particles as superfluid they can do so by setting the red viscosity to zero.
I'd like to do that, but I have no idea how to define the velocity calculation on each color. I have defined the viscosity for each color, but I don't know how I could insert it into the p1.vx and p2.vy velocity calculation (how to make p1.vx and p2.vy refer to each color separately). Any ideas? Can you help me?
ofxFloatSlider viscoSliderR;
ofxFloatSlider viscoSliderG;
ofxFloatSlider viscoSliderW;
ofxFloatSlider viscoSliderB;
ofxFloatSlider viscoSliderO;
ofxFloatSlider viscoSliderK;
ofxFloatSlider viscoSliderC;
ofxFloatSlider viscoSliderD;
and
float viscosityR = 0.3F;
float viscosityG = 0.4F;
float viscosityW = 0.1F;
float viscosityB = 0.6F;
float viscosityO = 0.5F;
float viscosityK = 0.7F;
float viscosityC = 0.8F;
float viscosityD = 0.0F;
and
viscosityR = viscoSliderR;
viscosityG = viscoSliderG;
viscosityW = viscoSliderW;
viscosityB = viscoSliderB;
viscosityO = viscoSliderO;
viscosityK = viscoSliderK;
viscosityC = viscoSliderC;
viscosityD = viscoSliderD;

If you have defined the viscosities as global variables in ofApp.h, then you should be able to use them in ofApp.cpp like this

  1. add the viscosity parameter to the function definition
    void ofApp::interaction(std::vector* Group1, const std::vector* Group2, const float G, const float radius, float viscosity){ .....}

  2. In the update section pass the paramter for each color like this:
    if (numberSliderR > 0)
    {
    interaction(&red, &red, powerSliderRR, vSliderRR, viscosityR);
    if (numberSliderG > 0) interaction(&red, &green, powerSliderRG, vSliderRG, viscosityR );
    if (numberSliderB > 0) interaction(&red, &blue, powerSliderRB, vSliderRB, viscosityR);
    if (numberSliderW > 0) interaction(&red, &white, powerSliderRW, vSliderRW, viscosityR);
    }

  3. Reassign the gui sliders to the variables so that it can capture the changes life this.
    viscosityR = viscoSliderR;

  4. You may need to make some changes in other places so that you can export and import this parameter

Hope that helps

Thank you very much. Great idea. I've worked out the viscosity per color. Now I fail to save all the parameters and then load them from the saved file.
Can you help me? I made a mistake somewhere and I don't understand why when loading the saved model it shows negative particle numbers and everything gets messed up.
Here is what I get with viscosity per color:
image

Can you show me the link to your code?
To be honest, the way we save the parameters in this software is very primitive and probably not portable across different devices. A better way is to use an external C++ library like boost serialization or cereal https://uscilab.github.io/cereal/

OpenFrameworks also has it's own serialization method but it's documentation is lacking : https://openframeworks.cc/documentation/types/ofBaseSerializer/

Can you show me the link to your code? To be honest, the way we save the parameters in this software is very primitive and probably not portable across different devices. A better way is to use an external C++ library like boost serialization or cereal https://uscilab.github.io/cereal/

OpenFrameworks also has it's own serialization method but it's documentation is lacking : https://openframeworks.cc/documentation/types/ofBaseSerializer/
My code is here:
https://github.com/KhadrasWellun/particle-life/tree/main/particle_life/src
Also, I don't know how to show the new interaction model for 8 particles. I saw your model is built when the button "Show Model" is pressed. But I have a picture (in jpg or png format).
This is happening when I load a saved model
image

I peeked through your code, I couldn't find a mistake. These errors are hard to track and they are usually due to some casting errors or other hidden logical mistakes. I'll try a deeper look again when have time. Great job adding the additional colors!

I peeked through your code, I couldn't find a mistake. These errors are hard to track and they are usually due to some casting errors or other hidden logical mistakes. I'll try a deeper look again when have time. Great job adding the additional colors!

Thank you! Now I add probability for every type of interaction. So, an interaction will have; intensity, range, viscosity and probability of happening.

ker2x commented

yeah we should switch to some xml/json/yml file for import/export.
I'm busy learning oneAPI/DPC++ (still tempted to make a DPC++ version of particle-life :D)

yeah we should switch to some xml/json/yml file for import/export. I'm busy learning oneAPI/DPC++ (still tempted to make a DPC++ version of particle-life :D)

If you will write this code in another programming language, please insert more comments in it. Please also make it easy to insert new colours. Please use the full matrices of interaction strengths as well as their probabilities and viscosity per colour.

ker2x commented

yes, I will :)

It's still fully standard C++, it's part of the intel oneAPI.

  • DPC++: oneAPI’s core language for programming accelerators and multiprocessors. DPC++ allows developers to reuse code across hardware targets (CPUs and accelerators such as GPUs and FPGAs) and tune for a specific architecture
  • oneDPL: A companion to the DPC++ Compiler for programming oneAPI devices with APIs from C++ standard library, Parallel STL, and extensions
  • oneDNN: High-performance implementations of primitives for deep learning frameworks
  • oneCCL: Communication primitives for scaling deep learning frameworks across multiple devices
  • Level Zero: A system interface for oneAPI languages and libraries
  • oneDAL: Algorithms for accelerated data science
  • oneTBB: A library for adding thread-based parallelism to complex applications on multiprocessors
  • oneVPL: Algorithms for accelerated video processing
  • oneMKL: High-performance math routines for science, engineering, and financial applications

it's a bit like "cuda" (except that it's not). you can already compile particle-life with it without any change. Except that it won't really show much improvement.
It also come with Intel VTune and Intel Advisor (both are profiler).
All for free :)

particle life need to be fully rewritten :

  • use SOA (structure of array) instead of AOS (array of structure).
  • use vertex buffer (VBO) to replace tens of thousands of openGL call per frame with just a dozen call.
  • That would show the biggest performance improvement and allow much better gpu acceleration.

I peeked through your code, I couldn't find a mistake. These errors are hard to track and they are usually due to some casting errors or other hidden logical mistakes. I'll try a deeper look again when have time. Great job adding the additional colors!

I solved the problem with saving and loading. There was a mistake in my code.