openworm / sibernetic

This is a C++/OpenCL implementation of the PCISPH algorithm supplemented with a set of biomechanics related features applied to C. elegans locomotion
Other
353 stars 106 forks source link

Generate faster renders #101

Open nmsutton opened 8 years ago

nmsutton commented 8 years ago

The objective is to be able to better observe animation in renders by making the renders play at a faster fps. This idea was inspired by the downsampling concept used by tools like bokeh and hdf5 files. I am interested in working on behavioral simulations and that could benefit from observing results in fast renders. I also find my approach to be complementary to but not the same as the computation improvement issue ticket open because I want to do downsampling.

From what I understand the biophysics of the worm create the structure observed in the render (e.g. liquid-impermeable membranes constraining internal cells). In the approach I am interested in a representative downsampling of 3d objects is done (e.g cells). An algorithm such as self-organizing maps can cluster a set number of 3d objects into representative positions guided by the full set of original 3d objects. Physics can than be adjusted in the .cl file (like crawling) to expand the area of forces (like liquid-impermeability) to accommodate the reduced area of 3d objects. Some core objects would not want to be downsampled like the 302 neurons etc. but many more anatomically less core objects can be.

I am new here so please tell me are there already methods for accelerating neuromechanical modeling renders? Does my approach seem reasonable? If it sounds reasonable I'd like to list myself as working on this and anyone else is welcome to join in too.

skhayrulin commented 8 years ago

Hi @nmsutton! Sorry for late answer. Now when we are simulating worm movement we're usually turn off graphics case simulation usually takes more that day for simulating one second. So for analysis we storing data into special text files which contains info of dynamics of particle system more info here. But actually we have a problem that if in scene a lot of objects OpenGL part consumes a lot time. About your questions:

I am new here so please tell me are there already methods for accelerating neuromechanical modeling renders?

As far as I remember we didn't realized any algorithm for work with it.

Does my approach seem reasonable?

Why not it sounds reasonable.

nmsutton commented 8 years ago

No worries about the response, thanks so much for the excellent work on the project @skhayrulin! I appreciate your explanations and I am pleased to hear you finding my approach reasonable. I have begun work on it in this project. I can do the downsampling but the challenge I am on now is how to fully reconstruct config files once I do. That is related to work on ticket 102.

nmsutton commented 8 years ago

I have been progressing in this effort and my software produces for example this config file: tinyurl.com/demo2i-comb to recreate demo2. @skhayrulin I generate elastic connections by inputting position+velocity particles through sibernetic_config_gen , how can I make non-moving barrier planes for the cubes (my planes fall down) such as in demo2? It appears through elastic connections non-moving planes are made in demo2 but what particle settings are required for that?

skhayrulin commented 8 years ago

hi @nmsutton actually this configuration (I mean demo2) wasn't generate by sibernetic_gen_config it was done by me by custom code and I explicitly marked connections between elastic and boundary particles.

nmsutton commented 8 years ago

Ok, thanks @skhayrulin for the further clarification! Thinking about the whole worm and creating connections, if I write code that goes through my ~reduced~ particle worm version and specifically defines by coordinate region and particle type an adjusted neighborhood value for creating connections and uses code based on sibernetic_config_gen's methods of connection creation, does there happen to be physics formulas I should be aware of to guide the adjusted neighborhood values or is trial and error as good an approach as any?

In [membranes] section <id, jd, kd> appear to reference particle ids, a membrane triangle is made by selecting 3 particle vertices right? Since there is not code in sibernetic_config_gen for auto generating membranes from particles if convenient any code you could share that creates membranes for config files would be appreciated, even not cleaned up code is cool.

How do the values in [particleMembranesList] inform what elastic particles are in which membranes? i.e. with a single 144 value, how is that value used? Also, what is the purpose of specifying in which membranes the particles are included?

skhayrulin commented 8 years ago

... uses code based on sibernetic_config_gen's methods of connection creation, does there happen to be physics formulas I should be aware of to guide the adjusted neighborhood values or is trial and error as good an approach as any?

in Sibernetic we're implemented PCI SPH algorithm which is simulating in-compressible liquid so it's really important to run start configuration from state when density of modeling liquid is equal to steady-state value namely 1000 kg/m^3. So sibernetic_config_gen takes it into account when generating configuration. Main problem of sibernetic_config_gen's is that it can generate only simple scene with simple object inside like cube it really need mode research how to do it more universal :) unfortunately I don't have enough time to do that.

In [membranes] section appear to reference particle ids, a membrane triangle is made by selecting 3 particle vertices right?

Yes

Since there is not code in sibernetic_config_gen for auto generating membranes from particles if convenient any code you could share that creates membranes for config files would be appreciated, even not cleaned up code is cool.

Ok I'll try to find any on my machine I'll let you know, since I remember it' really non trivial task to generate membranes.

How do the values in [particleMembranesList] inform what elastic particles are in which membranes? i.e. with a single 144 value, how is that value used?Also, what is the purpose of specifying in which membranes the particles are included?

Yes it simply list of membranes in which particular particle is included max count of membranes for any elastic particle is MAX_MEMBRANES_INCLUDING_SAME_PARTICLE so size of this list is equal elastic_particle_count * MAX_MEMBRANES_INCLUDING_SAME_PARTICLE and for each elastic particle you can find list of membranes it start from[id_particle * MAX_MEMBRANES_INCLUDING_SAME_PARTICLE ] to [ id_particle * MAX_MEMBRANES_INCLUDING_SAME_PARTICLE + MAX_MEMBRANES_INCLUDING_SAME_PARTICLE]. This list is needed for fast taking list of membranes for each particle case it permanent throw the simulation. 144 - is id of membrane it used in OpenCL code for calculating of normal vector for calculating of repulsive force. You can read our's last paper it's about sibernetic and main algorithm inside here. Hope this will be helpful let me know if you need more explanation :)

nmsutton commented 8 years ago

Thanks @skhayrulin for the good quality explanations and sharing the article! This has helped my understanding of the work a lot!

nmsutton commented 8 years ago

Prototype version 1.0 of a downsampled worm is available. @skhayrulin your help was really valuable in making it! Config file: tinyurl.com/prtdwnwrm . There are known issues but it runs at a smooth 60 fps on my gtx 680 4gb vid ram. It was created through modeling it in blender and adding a lot of collada import functionality into sibernetic_config_gen. Blender: lcm6YbZ.jpg Siber: wMJ494m.jpg . I plan to clean up the code and push request it and add to docs how to make the config. I will further work on controlled muscle placement, with a procedurally generated model if needed. This issue should remain open because more work is needed.

Known issues and questions: Initially liquid leaks from the worm but stops leaking later. Why, is it too much liquid in the worm initially? Examples: Leaking – (link names random gen) Leaking Video , Not Leaking - Not Leaking Video

Worm initially deforms but later stabilizes shape. Particle distance formula was changed to ((Particle.distBetween_particles(part_j,part_i)*1.5) \ 100) for the new worm size. Why could this shape deformation occur? Due to the formula not matching the size quite right? Worm adjusts by deforming to accommodate? Even with elastic particles is this somehow related to density (therefore distances) of 1000 kg/m^3?

Worm floats up in the air. What may cause this? Density lighter than air (lighter than air wiki)? Example: Floating Video

I'm going to work with the 'muscle signal updating' module for simulating activity. Any general tips on getting that to work with such a new worm model in a config file?

skhayrulin commented 8 years ago

Hi @nmsutton great work! Sorry for late answer

Known issues and questions: Initially liquid leaks from the worm but stops leaking later. Why, is it too much liquid in the worm initially?

It could be connected with difference in calculation between CPU and GPU, as far as I remember I had similar problem when run the same configuration on GPU. As I remember that main problem is that membrane isn't detecting that liquid particle trying penetrating trow it.

Worm initially deforms but later stabilizes shape. Particle distance formula was changed to ((Particle.distBetween_particles(part_j,part_i)*1.5) \ 100) for the new worm size. Why could this shape deformation occur? Due to the formula not matching the size quite right? Worm adjusts by deforming to accommodate? Even with elastic particles is this somehow related to density (therefore distances) of 1000 kg/m^3?

It's needed for creation some tension in connection. Actually I experimented with that so I can say that it's correct :)

Worm floats up in the air. What may cause this? Density lighter than air (lighter than air wiki)?

Hmm it's wired but I suppose that possible problem could be in big pressure in inside particles. Do you have committed this configuration somewhere?

I'm going to work with the 'muscle signal updating' module for simulating activity. Any general tips on getting that to work with such a new worm model in a config file?

Actually there many news with this I've finished work with interface Sibernetic-NEURON. Now Sibernetic could take NEURON output in during the simulation. I've actually not written documentation yet but I hope to finish it soon. Lt me know if you'de like to know more.

nmsutton commented 8 years ago

@skhayrulin Thanks, glad you like it! No worries about the response timing. Thanks very much for the helpful answers and your valuable Sibernetic-NEURON work which I look forward to checking out, I only need to look in the Sibernetic-NEURON github repo? In response to your question about if an example configuration file has been committed, that is available at tinyurl.com/prtdwnwrm as a part of my pull request github.com/openworm/sibernetic_config_gen/pull/5 . While the reduced scale worm model is good for a first release, it could use fine tuning, the collada import function to which the pull request contributes is fully ready. Whenever you happen to get a chance please tell me can the pull request be approved?

skhayrulin commented 8 years ago

I only need to look in the Sibernetic-NEURON github repo?

Yes, actually I haven't written documentation how to run this with sibernetic but I'll do it soon. I'll let you know

Whenever you happen to get a chance please tell me can the pull request be approved?

Yes sure.

nmsutton commented 8 years ago

@skhayrulin Thanks for the assistance and really glad to see the Sibernetic-NEURON further work in particular! Also, sorry I didn’t read your response closer, to help show the floating example I additionally uploaded the floating worm config here and all blender files here . The tinyurl.com/prtdwnwrm config referred to is the latest downsampled worm I remodeled in blender and somehow that fixed floating. As you point out if it is a pressure issue than perhaps the density of either the elastic and/or liquid particles and connections being different as seen in the two blender model versions is the cause. Since it is fixed I assume it is only a small issue now.