acn_utils.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //Line number in the x direction. Range is from 0 to I-1.
  2. int i_vr(int l){
  3. return l%I;
  4. }
  5. //Line number in the y direction
  6. int j_vr(int l){
  7. return (l%(I*J))/I;
  8. }
  9. //Line number in the z direction
  10. int k_vr(int l){
  11. return l/(I*J);
  12. }
  13. //Characteristic velocity vectors of the LV model. Opposite vector pairs have to be written in odd-even combination (important for calcLBmnew function)!
  14. void initialiseE()
  15. {
  16. E[0][1]= 0; E[0][2]= 0; E[0][3]= 0;
  17. E[1][1]= 1; E[1][2]= 0; E[1][3]= 0;
  18. E[2][1]= -1; E[2][2]= 0; E[2][3]= 0;
  19. E[3][1]= 0; E[3][2]= 1; E[3][3]= 0;
  20. E[4][1]= 0; E[4][2]= -1; E[4][3]= 0;
  21. E[5][1]= 0; E[5][2]= 0; E[5][3]= 1;
  22. E[6][1]= 0; E[6][2]= 0; E[6][3]= -1;
  23. E[7][1]= 1; E[7][2]= 1; E[7][3]= 0;
  24. E[8][1]= -1; E[8][2]= -1; E[8][3]= 0;
  25. E[9][1]= -1; E[9][2]= 1; E[9][3]= 0;
  26. E[10][1]= 1; E[10][2]= -1; E[10][3]= 0;
  27. E[11][1]= 1; E[11][2]= 0; E[11][3]= 1;
  28. E[12][1]= -1; E[12][2]= 0; E[12][3]= -1;
  29. E[13][1]= -1; E[13][2]= 0; E[13][3]= 1;
  30. E[14][1]= 1; E[14][2]= 0; E[14][3]= -1;
  31. E[15][1]= 0; E[15][2]= 1; E[15][3]= 1;
  32. E[16][1]= 0; E[16][2]=-1; E[16][3]= -1;
  33. E[17][1]= 0; E[17][2]= -1; E[17][3]= 1;
  34. E[18][1]= 0; E[18][2]= 1; E[18][3]= -1;
  35. //Constants for the model. Adapted from Thurey, Rude, Korner
  36. int i;
  37. WKONST[0]=1.f/3.f;
  38. for(i=1;i<=6; i++) WKONST[i]=1.f/18.f;
  39. for(i=7;i<=18; i++) WKONST[i]=1.f/36.f;
  40. }
  41. //Function that multiplies matrices Aik x Bkj = Cij t and returns the element Cij
  42. void AMatrixB(float (*c)[4], float (*a)[4],float (*b)[4])
  43. {
  44. for (int i = 1; i<=3; i++)
  45. {
  46. for (int j = 1; j<=3; j++)
  47. {
  48. c[i][j]=a[i][1]*b[1][j]+a[i][2]*b[2][j]+a[i][3]*b[3][j];
  49. }
  50. }
  51. }
  52. // Function to take a little-endian encoded float and make it big-endian (or vice versa). Useful for reading to paraview
  53. float FloatSwap( float f )
  54. {
  55. union
  56. {
  57. float f;
  58. char b[4];
  59. } dat1, dat2;
  60. dat1.f = f;
  61. dat2.b[0] = dat1.b[3];
  62. dat2.b[1] = dat1.b[2];
  63. dat2.b[2] = dat1.b[1];
  64. dat2.b[3] = dat1.b[0];
  65. return dat2.f;
  66. }