Calculation of offset for nearly vertical pipeline segments fail with eccentric reducers/expanders
Background
The definition of component orientation is based on the orientation of the axis of the component so that angle zero means that the local y-axis points upwards, i.e. it is the projection of the vertical axis onto the plane that is orthogonal to the pipe direction.
This definition cannot be used when the pipe is perfectly vertical, so the definition of "up" is currently switched to the x-axis when the component is in a nearly vertical position, meaning that the local y-axis points to the global z-axis when the flow direction points towards the y-axis.
Problem
This creates a discontinuity in the orientation of the component when small changes are made to the pipe direction. This creates situations in which the calculation of the component offset for eccentric reducers does not converge, or in fact has no solution at all for some values of the rotation angle, resulting in broken results from PipingRules.calculateOffset()
. This is manifested by calculateOffset()
oscillating between two directions until all 100 iterations are exhausted, returning a non-converged solution.
The fact that the offset vector, defined as a function of the component flow direction vector, is discontinuous, is inevitable, as there can be no continuous vector field over the surface of a sphere, also known as the "hairy ball theorem" (https://en.wikipedia.org/wiki/Hairy_ball_theorem) that states that there can be no continuous non-vanishing vector field of tangents over a ball, in this case representing all the possible unit vectors of flow direction.
Solution
To prevent this, some other way to define the component orientation needs to be defined. One option is to bind the orientation angle to the direction of the line between the end points of the segment instead of the orientations of the components. This results in stable offset calculation in calculateOffset()
.