python - Half-integer indices -
I am working on a liquid mobility simulation tool in Python. Traditionally (at least in my area), integer indices indicate the center of the cell. Some quantities are stored on the faces between the cells, and are marked by the half-integer index in the literature. In the code, however, they are moved to the integer so that they can fit into arrays. The problem is that the change is not always consistent: do you reduce or decrease? If you switch between adequate code, then you quickly lose track of conferences for a particular code. And honestly, there are enough bizarre conventions in every code, which will be a great help in destroying something ... but if this measure is worse than the original problem.
I have also thought about using the index is strange for cell centers and faces, but it is a rival, as well as for the quantities present on both face and cell centers, this is rare If you do not use more than half your indices, you can implement function plus_half (i) and minus_half (i), but which are verbose and incompatible (at least in my opinion). And of course, comparison of floating point is always problematic, when a person becomes beautiful in calculating 1/2.
Does anyone have any suggestions for a great way to implement the half-integer index in Python? I am sure that I am not the first person to wish for this, but I've never seen it in any ordinary way that is obvious to a user (without the need to remember the changes you make to the user) .
And just to clarify: I think the index is likely to be a hidden step from the user to get an integer (I want to wrap NumPy arrays for my data grid) . I am thinking about the interface coming in contact with the user, rather than how the data is stored.
__getitem __ which takes the arbitrary item as index (and Especially floating point numbers).
Comments
Post a Comment