# Numerical Solver Error in Custom Python Script

I am developing a buoyancy plugin using the Python Scripting Components to apply to bodies within an IsaacSim simulation. I have a stage with a Ground Plane, three cubes with varying densities and a PhysicsScene.

The buoyancy plugin is a script that inherits from BehaviorScript and applies the buoyancy force at the center of mass of the object. In order to test that the physics are working correctly, I am emulating the Demo found at this link: Gazebo : Tutorial : Hydrodynamics (gazebosim.org)

I have manually set the mass of each cube to be 1000.0 kg and the density of the Buoyant Cube to be 1000.0 kg/m^3, the Floater density is 500 kg/m^3 and the Sinker cube density to be 1500 kg/m^3. When running the simulation, the Sinker and Floater cube behave as expected. The buoyant cube start to sink very slowly, then stops for maybe 1-2 seconds, then starts to very slowly float upward and never settles, gaining velocity as it travels upward.

I do not think that this is due to an imbalance of forces being applied since it is a very simple net force, (mass*gravity = density_water * vol_obj * gravity) where the volume of the cube is calculated as vol_obj = mass_obj/density_obj. For the buoyant cube, with a mass of 1000 kg and a density of 1000 kg/m^3, the math turns out to be 1000 kg * 9.8066 m/s^2 = 1000 kg/m^3 *(1000 kg/1000 kg/m^3) * 9.8066 m/s^2. The left hand side exactly equals the right hand side and thus no net force should be applied.

It seems to me that this could be a numerical solver issue but I’m really not sure what to look at for fixing that. I will say there must be something with how the gravity force is applied from the PhysicsScene in combination with any forces from my Python Scripting Component because when I set the magnitude of gravity in the PhysicsScene prim to 0 and calculate the net force in my script, each cube behaves as expected.

Here is a video of what happens when I run the simulation and have the Inspect Physics tool running on the Buoyant cube. Clearly, there is small very very small acceleration being applied with some periodicity that makes me think it is coming from the numerical solver.

Any help or guidance is greatly appreciated!

@sam.lovelace can you share your code, It would help us debug this issue better.