Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /* Periodic boundary condition and minimum image in D4 lattice (4-dimensional dense packing)
  2. * Created by Yi Hu on 6/13/19.
  3. * Refer to: J. Convay and N. Sloane, IEEE Trans Inform Theory 28, 227 (1982).
  4. */
  5.  
  6. #include <cstdint>
  7. #include <cmath>
  8.  
  9. #define DIM 4
  10.  
  11. /* input value:
  12. p - vector of coordinates. Modify to its minimum image
  13. mirror - store the lattice point
  14. return value: 0 (suggest mirror is zeros and p is unchanged)
  15. or 1 (mirror is not all zeros and p has been changed)
  16. */
  17. int latticepoint(double p[DIM], int32_t mirror[DIM])
  18. {
  19. int rp, gind = 0, summr = 0, is_mird = 0;
  20. double maxdelta = 0, dtmp;
  21. for(rp=0; rp<DIM; ++rp)
  22. {
  23. // fast round eqv mirror[rp] = round(p[rp]);
  24. dtmp = p[rp] + 6755399441055744.0;
  25. mirror[rp] = reinterpret_cast<int32_t&>(dtmp);
  26. p[rp] -= mirror[rp];
  27. dtmp = fabs(p[rp]);
  28. if(maxdelta < dtmp)
  29. {
  30. maxdelta = dtmp;
  31. gind = rp;
  32. }
  33. summr += mirror[rp];
  34. }
  35. if(summr%2 != 0)
  36. {
  37. // use next nearest neighbor image
  38. if(p[gind] < 0)
  39. {
  40. --mirror[gind];
  41. ++p[gind];
  42. }
  43. else
  44. {
  45. ++mirror[gind];
  46. --p[gind];
  47. }
  48. }
  49. for(rp=0; rp<DIM; ++rp)
  50. {
  51. if(mirror[rp] != 0)
  52. {
  53. is_mird = 1;
  54. break;
  55. }
  56. }
  57. return is_mird;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement