A SERIOUS SURGICAL simulation!

Share with us how are you using the powerrrr of the force

Moderator: Alain

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Mon Mar 09, 2020 4:04 am

Hi Julio,

Now I have 2 rods one moving within another. The 2 rods interact physically. I add 4 box collider to each node of the outer rod as the wall. But the problem is that the inter rod will jitter when the outer rod bend enough:

jitter:
https://youtu.be/9E0fDQl6aG0
the collider of outer rod's node:
https://drive.google.com/file/d/1FCCiGR ... sp=sharing

I have tried many settings of properties of the 2 rods, but it gets no better. What could be the reason and how can it be fixed?
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Mon Mar 09, 2020 9:40 am

is the capsule is tight inside the four boxes?
this lead to a singular mass matrix for the contact on each capsule, you need to leave some wiggle room for the contacts.
you can also try the soft contact option, the will relax the contact mass matrix, but that is a new feature you need to add it to your contact call back, in your contact call back you add something like this
Code: Select all
static void TestSoftContacts(const NewtonJoint* const contactJoint, dFloat timestep, int threadIndex)
{
   dAssert(NewtonJointIsActive(contactJoint));
   for (void* contact = NewtonContactJointGetFirstContact(contactJoint); contact; contact = NewtonContactJointGetNextContact(contactJoint, contact)) {
      NewtonMaterial* const material = NewtonContactGetMaterial(contact);
      NewtonMaterialSetAsSoftContact(material, 0.1f);
   }
}


this will make the diagonal of the block contact matrix larger to eliminate the ill conditioning.
and add penetration penealty on teh right side to make for the deficiency.
in matrix talk, say you have a circle sandwiched between a left and right wall with no room to move.
this will form a matrix of the form

1 -1 x0 = b0
-1 1 x1 = b1

this matrix is singular and can't be solved because the detereminat is zero.
Even using singular value decomposition yield a wrong answer because SVD tell to remove one row, setting the force in one wall to zero.
but the required answer is that both walls assert force of the *, not that one wall is removed from the solution.

the option NewtonMaterialSetAsSoftContact(material, 0.1f), modify the matrix like follows

(1+0.1) -1 x0 = b0 + penaty0
-1 (1+0.1) x1 = b1 + penaty1

now the determinat is a small value which allows to get a close solution to the ideal one.
and the penealty on the right side make up for the small penetration value.

this feature seems to work very well, but I have not tried much.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Mon Mar 09, 2020 12:16 pm

When I look at the video, it appears that the catheter inside the mesh that represent the vain does has room to move sideways, is this a visual effect.?
Because the picture you show me, shows a tight fit.

A know nothing about biology and the physiology of humans. But it seems to me that a tight fit will never work in reality.

My experience are in mechanical engineering and I can tell you that when you stick a pilon on the ground to support any structure, there is a point in the penetration where it can't penetrate any more because of the friction, the friction is stronger that the weight that will support or the impact that hit the pilon.

I assume this is similar, so a tight fit is extremely problematic for two reasons.
1 the longitudinal friction
2 the contacts of each capsule generate singular minor block matrices.

You most allow for some side motion.
Also, you are hitting a second problem.
This is the time response of the simulation numerical simulation.
This is a more advanced analysis. But it can be explain like this.
Because this is a discrete numerical integration of a second order differential equations. Assuming the integration is perfect which is not.
In every time step the input to the system is a finite impulse.
The repose to the system is and infinite frequency that they are obviously banishing. But banishing is not enough.
If you take any body of the chain and plot the velocity as a function of the, time for any fix input, and you the take and fft, you will see that there will be some frequencies that are comparably to the time step this is bad.

The reason for this is that the non linear factor in the chain all combine, this is a real effect that is caller resonance in real system, in simulation is fart harder because the discrete nature of the integration.

Basically you most simulate with a short time step.
On the bright side, this is the reason that simulation tend to work in real life, is a second order discrete simulation is stable the real life version is even more stable.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Mon Mar 09, 2020 8:03 pm

Julio Jerez wrote:When I look at the video, it appears that the catheter inside the mesh that represent the bain does has room to move sideway, is this a visual effect.?
Because the picture you show me, shows a tight fit.


Sorry for this ambiguous description. It's not a tight fit. The cylinder showed in the center of the 4 box collider is belonged to the outer rod but the cylinder collider has no collision with the inter rod(using compound collision's shapeID :D ). When come to visual effect in the vedio, i hide the 4 box colliders and only show the cylinder collider to represent the outer rod. So, the space is almost the same as what you can see in the vedio, about 3 times the size of the inter rod's diameter.

I will check what you said deeply now , just clarify my bad description first, sorry about that.

Oh, I have one more point to add. When the inter rod moves in the tube of a static vessel, it never jitters. The outer rod is not a static object, it's a rod can be manipulated too. Maybe this is important i think, just complete the context.
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Mon Mar 09, 2020 9:39 pm

Julio Jerez wrote:Also, you are hitting a secund problem.
This is the time reponse of the simulation numerical simulation.
This is a more advanced analisy. But it can be explain like this.
Because this is a discrete numerical integration of a secund order differential equations. Assuming the integration is perfect which is not.
In every time step the input to the system is a finate impulse.
The repose to the system is and infinite frequency that they are obviously banishing. But banishing is not enought.
If you take any body of the chain and plot the velocity as a function of the, time for any fix input, and you the take and fft, you will see that there will be some frequencies that are comparably to the time step this is bad.

The reason for this is that the non linear factor in the chain all combine, this is a real effect that is called resonance in real system. In simulation is far harder because the discrete nature of the integration.

Basically you most simulate with a short time step.
On the bright side, this is the reason that simulation tend to work in real life, is a second order discrete simulation is stable the real life version is even more stable.


Thanks, it is indeed as what you said. I am using a very short time step and 4 work threads, and problem sovled!
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Mon Mar 09, 2020 9:54 pm

so every thing is fine now? what time step are you using?
remember the sub sample is always better that using the dt passed to the update.

one last thong you can do. remember the trick I added that magisterially lower the friction
using this call? NewtonMaterialSetDefaultFriction(world, materialID, materialID, 0.2f, 0.2f);
now that you have a better approximation of the hollow tube, you can set the fiction to 0.
them instead of using dry friction, use a viscous friction on each body.
You can do that in the force and torque callback for each capsule or by setting the default build in drag.
I say this because a virtuoso friction is a better approximation of the medium in witch that thong is moving.

also can you make another video, so that I can see how it looks now?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Mon Mar 09, 2020 11:03 pm

Julio Jerez wrote:so every thing is fine now? what time step are you using?
remember the sub sample is always better that using the dt passed to the update.


Yes i always use sub samples first to reduce the cost of calling function between C# and C++.

Julio Jerez wrote:also can you make another video, so that I can see how it looks now?


I will show you my finally environment directly(the vessel is static now, but later it will have amination). I have made 2 vedios with different time step settings:

long time step: https://youtu.be/CzpC1qi61WY
settings:
https://drive.google.com/file/d/1tUGmx3 ... sp=sharing

short time step: https://youtu.be/4Z_-v8iWHaM
settings: the only different from above is setting "Update rate" to 800.

It has almost no jitter. But the disturbing thing is there will be the 3rd rod which i have not tested yet.

Julio Jerez wrote:one last thong you can do. remember the trick I added that magisterially lower the friction
using this call? NewtonMaterialSetDefaultFriction(world, materialID, materialID, 0.2f, 0.2f);
now that you have a better approximation of the hollow tube, you can set the fiction to 0.

I have been using friction of 0.02.

Julio Jerez wrote:them instead of using dry friction, use a viscous friction on each body.
You can do that in the force and torque callback for each capsule or by setting the default build in drag.
I say this because a virtuoso friction is a better approximation of the medium in witch that thong is moving.

Thanks! I will have a try about this. :D
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Tue Mar 10, 2020 2:18 am

Hi Julio,

I have added the viscous friction to Unity, just let you know. It seems that the viscous friction dosen't reduce the jitter. But the hollow tube is filled with blood in reality, so the viscous sounds more rational. I will just keep using it now.

And after adding the 3rd rod, the application runs stable enough. Newton Amazing! :D
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Tue Mar 10, 2020 7:33 am

the vicuos friction sujestion was not for reducing jitter, it was for the fact that the motion was suppose to be inside some kind of heavy fluid.

Anyway, the next thing you can try is setting dry friction zero, making the contacts with the walls friction less. This is probably closer to the real motion plus also reduces size of the mass matrix, yielding faster convergence.
And the final thing to try is to increase the iteration count, this is the root of the jitter, what is happening is the contact solver is not converging fast enought because the default iteration count is too low for this kind of contration. The default is set to four, try making 8, this does not affect the performance that much, since the count is and upper limit, the system is converging most of the time, or else will be unstable, you just need to make it converge all the time.

The secund video looks quite impressive and convincing, I bet you never thought Newton would yield this kind of simultation with just few tweaks that are nothing really special, in fact we are using physics principle that adhere to real physics, but do not let the stablishement knows that, they will simply dismiss you sumarilly blaming you for not understanding their brand new laws of physics. Me, the old stuff still does just fine .

Anyway I think you can now move on your stuff and not need to constantly wretstle the physics library, and fucus on you work.
Charles wrote:And after adding the 3rd rod, the application runs stable enough. Newton Amazing! :D

That's how Newton rolls.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Tue Mar 10, 2020 8:38 pm

Julio Jerez wrote:Anyway, the next thing you can try is setting dry friction zero, making the contacts with the walls friction less. This is probably closer to the real motion plus also reduces size of the mass matrix, yielding faster convergence.
And the final thing to try is to increase the iteration count, this is the root of the jitter, what is happening is the contact solver is not converging fast enought because the default iteration count is too low for this kind of contration. The default is set to four, try making 8, this does not affect the performance that much, since the count is and upper limit, the system is converging most of the time, or else will be unstable, you just need to make it converge all the time.

Thanks, I will try them.

Julio Jerez wrote:The secund video looks quite impressive and convincing, I bet you never thought Newton would yield this kind of simultation with just few tweaks that are nothing really special,

I was very worried about the jitter at first. I felt this was a convergence problem which might be a hard one to handle. Never expected Newton would solve this problem just by some few tweaks. :D In fact, I never thought any engine could solve this kind of simulatuion with features of accurate, stable, fast at the same time and so easy to use! The first thing that came to mind are some finite element engines, but that kind of engines are too slowly. Lucky I can use Newton! :D
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Tue Mar 10, 2020 11:59 pm

Charles wrote:Never expected Newton would solve this problem just by some few tweaks. :D In fact, I never thought any engine could solve this kind of simulation with features of accurate, stable, fast at the same time and so easy to use!

again, that's how Newton rolls, and it had for the pass 16 years. 8)
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Wed Mar 11, 2020 8:52 pm

Hi Julio,

I need the rod to be more elastic. It's more elastic than before after your last improvement , but not enough according to my latest test.

Here is why:
I want the tip of the rod to move into the target branch, but it's almost impossible:
https://youtu.be/ZeqgiSmBEBU
I think it's the internal spring force that force the tip into the branch in reality. So the player just need to twist the rod and the rod will be forced into the branch as soon as its tip is aiming at the entrance of the branch.

Also, i make a very short vedio about the realistic catheter just to illustrate the elastic of the rod.
https://youtu.be/oz4pdYZy6GE

Could Newton has the elastic rod like that? Or how much could it be improved? :D
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Wed Mar 11, 2020 9:51 pm

that's not a problem, remember when we talked about adding the spring damper functionality, and the after I tested I saw that using the default penalty seemed enought.
this class.
Code: Select all
   dFlexyPipeSpinner (const dMatrix& pinAndPivotFrame, NewtonBody* const child, NewtonBody* const parent)
      :dCustomBallAndSocket(pinAndPivotFrame, child, parent)
   {
      EnableTwist(false);
      EnableCone(true);
      SetConeLimits(0.0f);
      SetConeFriction(1.0e20f);
      SetConeStiffness(0.6f);
   }


this line SetConeStiffness(0.6f);
set the regularization of the mass matrix, but still using the default spring mass on the right side.
the default happen to be quite stiff and very heavily damped.
I will explain later how this come about, but the conclusion is that each capsule is acting as a very super critically damped motion. almost every joint class in newton exposes how to override the right side penalty, except few joints like relational and the basketball.

I will add the interface to override the spring damper, them you can make it as flexible or as plastic as can be allowed.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: A SERIOUS SURGICAL simulation!

Postby Charles » Thu Mar 12, 2020 7:55 pm

Julio Jerez wrote:I will explain later how this come about, but the conclusion is that each capsule is acting as a very super critically damped motion. almost every joint class in newton exposes how to override the right side penalty, except few joints like relational and the basketball.

I will add the interface to override the spring damper, them you can make it as flexible or as plastic as can be allowed.


Thanks, an interface plus explaination, cool 8) !
Charles
 
Posts: 43
Joined: Thu Jan 16, 2020 12:58 am

Re: A SERIOUS SURGICAL simulation!

Postby Julio Jerez » Fri Mar 13, 2020 10:25 am

I did not have time to do it, I do it over the weekend.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

PreviousNext

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 2 guests

cron