ttricco / sarracen

A Python library for smoothed particle hydrodynamics (SPH) analysis and visualization.
https://sarracen.readthedocs.io
GNU General Public License v3.0
15 stars 18 forks source link

Maybe a bug in rotation? #57

Closed becnealon closed 1 year ago

becnealon commented 1 year ago

Not sure what I could be doing wrong here, but wanted to see a disc both face on and side on in plots next to each other. Simulation contains gas and sinks only.

Code I've used is

fig, ax = plt.subplots(1,2,figsize=(14,5))

## Plot the density
sdf, sdf_sinks = sarracen.read_phantom('N106_p1_7.5au/disc_00100')
ax[0] = sdf.render('rho',
                ax = ax[0],
                xlim=(-50,50),
                ylim=(-50,50),
                log_scale=True)
ax[0].scatter(x=sdf_sinks['x'],y=sdf_sinks['y'],color='green')

ax[1] = sdf.render('rho',
                ax = ax[1],
                log_scale=True,
                rotation=[0,0,90],
                xsec = 0,
                xlim=(-50,50),
                ylim=(-100,100))
ax[1].scatter(x=sdf_sinks['x'],y=sdf_sinks['z'],color='green')

And resultant plot is:

image

I can't work out why the rotated version has the disc well below centre and not coincident with the sinks? I've checked in splash and this doesn't agree with what is here. Can provide dumpfile if that's helpful.

ttricco commented 1 year ago

I have investigated and concluded that this is not a bug in rotation, but due to default rotation parameters that are not intuitive.

Currently, the point around which the rotation is performed is the centre point from the bounds of the data. In this example, the disc is originally centred on x,y,z=0, but at a later time, a few stray particles off the edges of the disc cause the midpoint to move away from x,y,z=0, leading to the unexpected (but correct) rotation. A workaround is to specify the rot_origin=.

Will close this issue and open a new issue to switch to a more practical default rotation origin.