gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/lava/gfx Makefile rd1.cxx


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/lava/gfx Makefile rd1.cxx
Date: Fri, 30 Aug 2002 06:32:35 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/08/30 06:32:35

Modified files:
        lava/gfx       : Makefile rd1.cxx 

Log message:
        Save textures

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gfx/Makefile.diff?tr1=1.26&tr2=1.27&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gfx/rd1.cxx.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: gzz/lava/gfx/Makefile
diff -c gzz/lava/gfx/Makefile:1.26 gzz/lava/gfx/Makefile:1.27
*** gzz/lava/gfx/Makefile:1.26  Mon Aug 26 10:15:53 2002
--- gzz/lava/gfx/Makefile       Fri Aug 30 06:32:35 2002
***************
*** 15,22 ****
  paper1: paper1.cxx 
        g++-3.0 -O3 -march=pentiumpro -I fonts/libgummi -g -o paper1 paper1.cxx 
$(LIBS)
  
  rd1: rd1.cxx
!       g++-3.1 -g -O3 -march=pentiumpro -ffast-math -fno-math-errno 
-fstrength-reduce -fcse-follow-jumps -fcse-skip-blocks -frerun-cse-after-loop 
-frerun-loop-opt -fexpensive-optimizations -fregmove -fschedule-insns2 
-funroll-loops -fmove-all-movables -falign-loops -fsingle-precision-constant 
-frename-registers rd1.cxx -o rd1 -lglut
  
  papermill.o: papermill.cxx paperobj.hxx texgen.hxx
        cd ../../gzz/gfx/gl/callgl && make callgl.o
--- 15,32 ----
  paper1: paper1.cxx 
        g++-3.0 -O3 -march=pentiumpro -I fonts/libgummi -g -o paper1 paper1.cxx 
$(LIBS)
  
+ #  -msse2 -mfpmath=sse,387
  rd1: rd1.cxx
!       g++-3.2 -g -O3 -march=pentium4 -ffast-math -fno-math-errno 
-fstrength-reduce -fcse-follow-jumps -fcse-skip-blocks -frerun-cse-after-loop 
-frerun-loop-opt -fexpensive-optimizations -fregmove -fschedule-insns2 
-funroll-loops -fmove-all-movables -falign-loops -fsingle-precision-constant 
-frename-registers rd1.cxx -o rd1 -lglut -Wa,-alh=rd1.s
! 
! rd1b: rd1b.cxx
!       g++-3.2 -g -O3 -march=pentium4 -ffast-math -fno-math-errno 
-fstrength-reduce -fcse-follow-jumps -fcse-skip-blocks -frerun-cse-after-loop 
-frerun-loop-opt -fexpensive-optimizations -fregmove -fschedule-insns2 
-funroll-loops -fmove-all-movables -falign-loops -fsingle-precision-constant 
-frename-registers rd1b.cxx -o rd1b -lglut -Wa,-alh=rd1b.s
! 
! rd2: rd2.cxx
!       g++-3.1 -g -O3 -march=pentium4 -ffast-math -fno-math-errno 
-fstrength-reduce -fcse-follow-jumps -fcse-skip-blocks -frerun-cse-after-loop 
-frerun-loop-opt -fexpensive-optimizations -fregmove -fschedule-insns2 
-funroll-loops -fmove-all-movables -falign-loops -fsingle-precision-constant 
-frename-registers rd2.cxx -o rd2 -lglut -Wa,-alh=rd2.s
! 
! rd3: rd3.cxx
!       g++-3.1 -g -O3 -march=pentium4 -ffast-math -fno-math-errno 
-fstrength-reduce -fcse-follow-jumps -fcse-skip-blocks -frerun-cse-after-loop 
-frerun-loop-opt -fexpensive-optimizations -fregmove -fschedule-insns2 
-funroll-loops -fmove-all-movables -falign-loops -fsingle-precision-constant 
-frename-registers rd3.cxx -o rd3 -lglut -Wa,-alh=rd3.s
  
  papermill.o: papermill.cxx paperobj.hxx texgen.hxx
        cd ../../gzz/gfx/gl/callgl && make callgl.o
Index: gzz/lava/gfx/rd1.cxx
diff -c gzz/lava/gfx/rd1.cxx:1.4 gzz/lava/gfx/rd1.cxx:1.5
*** gzz/lava/gfx/rd1.cxx:1.4    Tue Aug 27 09:40:17 2002
--- gzz/lava/gfx/rd1.cxx        Fri Aug 30 06:32:35 2002
***************
*** 2,30 ****
  #include <stdlib.h>
  #include <math.h>
  #include <GL/glut.h>
  
  //#define float double
  
  #if 1
  /* 3D map */
! /* Note: x, y, z \in [0, 2\pi] */
! #define eps .02
  
! //#define Du(i) 2E-5 / (eps*eps)
! #define Du(i) Du_arr[i]
! #define Du_init(x,y,z) exp(log(2E-5) + .7*triang2(z)) / (eps*eps)
  
! #define Dv(i) 1E-5 / (eps*eps)
  
! //#define F(i) 0.04
! #define F(i) F_arr[i]
! #define F_init(x,y,z) .04 - .04 * triang2(y)
  
! //#define k(i) 0.06
! #define k(i) k_arr[i]
! #define k_init(x,y,z) .05 - .02 * triang2(x)
  
! const int alln = 128;
  const int n0 = alln+2;
  const int n1 = alln+2;
  const int n2 = alln+2;
--- 2,34 ----
  #include <stdlib.h>
  #include <math.h>
  #include <GL/glut.h>
+ #include <iostream>
+ 
+ using std::cout;
+ using std::cerr;
  
  //#define float double
  
  #if 1
  /* 3D map */
! #define eps .015
! #define teps .5
  
! #define Du_f(x,y,z) (2E-5 / (eps*eps))
  
! #define Dv_f(x,y,z) 1E-5 / (eps*eps)
! //#define Dv_f(x,y,z) (( .75E-5 + .5E-5 * z ) / (eps*eps))
  
! #define F_f(x,y,z) 0.015
! //#define F_f(x,y,z) (.08 * y)
! //#define F_f(x,y,z) (.04 + .01 * y)
  
! #define k_f(x,y,z) 0.04
! //#define k_f(x,y,z) (.03 + .04 * x)
! //#define k_f(x,y,z) (.06 + .0075 * x)
  
! #define SCALE 81
! const int alln = 81;
  const int n0 = alln+2;
  const int n1 = alln+2;
  const int n2 = alln+2;
***************
*** 35,49 ****
  
  #define eps .01
  
! #define Du(i) 2E-5 / (eps*eps)
! #define Dv(i) 1E-5 / (eps*eps)
! 
! #define F(i) F_arr[i]
! #define F_init(x,y,z) .04 - .04 * triang2(y)
  
! #define k(i) k_arr[i]
! #define k_init(x,y,z) .05 - .02 * triang2(x)
  
  const int n0 = 512+2;
  const int n1 = 512+2;
  const int n2 = 1+2;
--- 39,51 ----
  
  #define eps .01
  
! #define Du_f(x,y,z) (2E-5 / (eps*eps))
! #define Dv_f(x,y,z) (1E-5 / (eps*eps))
  
! #define F_f(x,y,z) (.08 * y)
! #define k_f(x,y,z) (.03 + .04 * x)
  
+ #define SCALE 512
  const int n0 = 512+2;
  const int n1 = 512+2;
  const int n2 = 1+2;
***************
*** 66,89 ****
  
  bool repaintRightaway = false;
  
- // priod 2 pi
- //  /\
- // /  \   
- //     \  /
- //      \/
- float triang(float x) {
-   return asin(sin(x))/M_PI_2;
- }
- 
- // \ 
- //   \
- //     \
- //       \
- //
- float triang2(float x) {
-   return 1-x/M_PI;
- }
- 
  void init() {
    // Initialize arrays
  
--- 68,73 ----
***************
*** 92,123 ****
    U2 = new float[n0 * n1 * n2];
    V2 = new float[n0 * n1 * n2];
  
-   F_arr = new float[n0 * n1 * n2];
-   k_arr = new float[n0 * n1 * n2];
-   Du_arr = new float[n0 * n1 * n2];
-   Dv_arr = new float[n0 * n1 * n2];
- 
    for (int i = 0; i < n0 * n1 * n2; i++) {
  
!     float z = (float)(i / e2) / n2 * 2 * M_PI;
!     float y = (float)(i % e2 / e1) / n1 * 2 * M_PI;
!     float x = (float)(i % e2 % e1) / n0 * 2 * M_PI;
!       
!     U[i] = 0.5+0.5*sin(x + y + 3*z);
!     V[i] = 0.5+0.5*sin(2 * y - 2*z);
! 
! #ifdef k_init
!     k_arr[i] = k_init(x,y,z);
! #endif
! #ifdef F_init
!     F_arr[i] = F_init(x,y,z);
! #endif
! #ifdef Du_init
!     Du_arr[i] = Du_init(x,y,z);
! #endif
! #ifdef Dv_init
!     Dv_arr[i] = Dv_init(x,y,z);
! #endif
    }
  
    iter = 0;
--- 76,93 ----
    U2 = new float[n0 * n1 * n2];
    V2 = new float[n0 * n1 * n2];
  
    for (int i = 0; i < n0 * n1 * n2; i++) {
  
!     float z = (float)(i / e2 - 1) / (n2 - 2) * 2 * M_PI;
!     float y = (float)(i % e2 / e1 - 1) / (n1 - 2) * 2 * M_PI;
!     float x = (float)(i % e2 % e1 - 1) / (n0 - 2) * 2 * M_PI;
!     
!     float xp = x + 2*sin(2*z);
!     float yp = y + 3*cos(x);
!     float zp = z + sin(x) - sin(2*y);
!   
!     U[i] = 0.5+0.5*sin(xp + yp + 3*zp);
!     V[i] = 0.5+0.5*sin(2 * yp - 2*zp*zp);
    }
  
    iter = 0;
***************
*** 135,164 ****
    }
  }
  
  void evolve() {
    float *__restrict__ U = ::U;
    float *__restrict__ V = ::V;
    float *__restrict__ U2 = ::U2;
    float *__restrict__ V2 = ::V2;
-   
-   // Copy borders for proper tiling
-   copy2d(U, 0, e2 * (n2-2),  e0, n0, e1, n1);
-   copy2d(U, e2 * (n2-1), e2, e0, n0, e1, n1);
  
!   copy2d(V, 0, e2 * (n2-2),  e0, n0, e1, n1);
!   copy2d(V, e2 * (n2-1), e2, e0, n0, e1, n1);
  
!   copy2d(U, 0, e1 * (n1-2),  e0, n0, e2, n2);
!   copy2d(U, e1 * (n1-1), e1, e0, n0, e2, n2);
  
!   copy2d(V, 0, e1 * (n1-2),  e0, n0, e2, n2);
!   copy2d(V, e1 * (n1-1), e1, e0, n0, e2, n2);
! 
!   copy2d(U, 0, e0 * (n0-2),  e1, n1, e2, n2);
!   copy2d(U, e0 * (n0-1), e0, e1, n1, e2, n2);
! 
!   copy2d(V, 0, e0 * (n0-2),  e1, n1, e2, n2);
!   copy2d(V, e0 * (n0-1), e0, e1, n1, e2, n2);
  
  #ifndef LAPLACIAN_2D
  #define laplacian(a) (a[i-e0]+a[i+e0]+a[i-e1]+a[i+e1]+a[i-e2]+a[i+e2]-6*a[i])
--- 105,134 ----
    }
  }
  
+ void copy2d2(float *data1, float *data2,
+           int dst, int src, 
+           int e0, int n0,
+            int e1, int n1) {
+   copy2d(data1, dst, src, e0, n0, e1, n1);
+   copy2d(data2, dst, src, e0, n0, e1, n1);
+ }
+ 
  void evolve() {
    float *__restrict__ U = ::U;
    float *__restrict__ V = ::V;
    float *__restrict__ U2 = ::U2;
    float *__restrict__ V2 = ::V2;
  
! #if 1 /* Periodic boundary conditions */
!   copy2d2(U, V, 0, e2 * (n2-2),  e0, n0, e1, n1);
!   copy2d2(U, V, e2 * (n2-1), e2, e0, n0, e1, n1);
  
!   copy2d2(U, V, 0, e1 * (n1-2),  e0, n0, e2, n2);
!   copy2d2(U, V, e1 * (n1-1), e1, e0, n0, e2, n2);
  
!   copy2d2(U, V, 0, e0 * (n0-2),  e1, n1, e2, n2);
!   copy2d2(U, V, e0 * (n0-1), e0, e1, n1, e2, n2);
! #endif
  
  #ifndef LAPLACIAN_2D
  #define laplacian(a) (a[i-e0]+a[i+e0]+a[i-e1]+a[i+e1]+a[i-e2]+a[i+e2]-6*a[i])
***************
*** 167,178 ****
  #endif
  
    // Evaluate
!   int n = n0 * n1 * n2;
!   for (int i = e2; i < n - e2; i++) {
!     U2[i] = U[i] + (Du(i) * laplacian(U) - U[i] * V[i]*V[i] + F(i) * (1 - 
U[i]));
!     V2[i] = V[i] + (Dv(i) * laplacian(V) + U[i] * V[i]*V[i] - (F(i)+k(i)) * 
V[i]);
    }
!   
    // Swap
    ::U = U2; ::U2 = U;
    ::V = V2; ::V2 = V;
--- 137,176 ----
  #endif
  
    // Evaluate
!   const float dx = 1.0 / (n0 - 2);
!   const float dy = 1.0 / (n1 - 2);
!   const float dz = 1.0 / (n2 - 2);
! 
!   const float dk = dx * (k_f(1, 0, 0) - k_f(0, 0, 0));
!   const float dF = dx * (F_f(1, 0, 0) - F_f(0, 0, 0));
!   const float dDu = dx * (Du_f(1, 0, 0) - Du_f(0, 0, 0));
!   const float dDv = dx * (Dv_f(1, 0, 0) - Dv_f(0, 0, 0));
! 
!   int i = e0 + e1 + e2;
!   for (int i2 = 1; i2 < n2 - 1; i2++) {
!     for (int i1 = 1; i1 < n1 - 1; i1++) {
!       float z = dz * (i2 - 1);
!       float y = dy * (i1 - 1);
! 
!       float k = k_f(0, y, z);
!       float F = F_f(0, y, z);
!       float Du = Du_f(0, y, z);
!       float Dv = Dv_f(0, y, z);
! 
!       int i_end = i + n0 - 2;
!       for (; i < i_end; i++) {
!       U2[i] = U[i] + teps * (Du * laplacian(U) - U[i] * V[i]*V[i] + F * (1 - 
U[i]));
!       V2[i] = V[i] + teps * (Dv * laplacian(V) + U[i] * V[i]*V[i] - (F+k) * 
V[i]);
!       F += dF;
!       k += dk;
!       Du += dDu;
!       Dv += dDv;
!       }
!       i += 2 * e0;
!     }
!     i += 2 * e1;
    }
! 
    // Swap
    ::U = U2; ::U2 = U;
    ::V = V2; ::V2 = V;
***************
*** 180,185 ****
--- 178,209 ----
    iter++;
  }
  
+ void writeout() {
+   const char *filenew = "map3d.dat.new";
+   char *file = "map3d.dat";
+   
+ 
+   FILE *f = fopen(filenew, "w");
+   if (!f) {
+     perror(file);
+     exit(1);
+   }
+ 
+   fprintf(f, "%d %d %d 2\n", n2-2, n1-2, n0-2);
+ 
+   for (int i2 = 1; i2 < n2 - 1; i2++)
+     for (int i1 = 1; i1 < n1 - 1; i1++)
+       for (int i0 = 1; i0 < n0 - 1; i0++) {
+       int i = e0 * i0 + e1 * i1 + e2 * i2;
+       fwrite(&U[i], sizeof(U[i]), 1, f);
+       fwrite(&V[i], sizeof(V[i]), 1, f);
+       //fprintf(f, "%G %G\n", U[i], V[i]);
+       }
+   fclose(f);
+   rename(filenew, file);
+ 
+ }
+ 
  void stats() {
    int n = n0 * n1 * n2;
    fprintf(stderr, "Iteration %d: ", iter);
***************
*** 188,208 ****
    int num=0;
    float umin=1E30, umax=-1E30, usum=0;
    float vmin=1E30, vmax=-1E30, vsum=0;
!   for (int i = e2; i < n - e2; i++) {
!     if (!finite(U2[i]) || !finite(V2[i])) {
!       fprintf(stderr, "Not finite %d\n", i);
!       abort();
!     }
!     
!     num++;
!     if (U2[i] < umin) umin = U2[i];
!     if (U2[i] > umax) umax = U2[i];
!     usum += U2[i];
!     
!     if (V2[i] < vmin) vmin = V2[i];
!     if (V2[i] > vmax) vmax = V2[i];
!     vsum += V2[i];
!   }
    fprintf(stderr, "\tu: %G %G %G\tv: %G %G %G\n", 
          umin, usum/num, umax,
          vmin, vsum/num, vmax);
--- 212,236 ----
    int num=0;
    float umin=1E30, umax=-1E30, usum=0;
    float vmin=1E30, vmax=-1E30, vsum=0;
!   for (int i2 = 1; i2 < n2 - 1; i2++)
!     for (int i1 = 1; i1 < n1 - 1; i1++)
!       for (int i0 = 1; i0 < n0 - 1; i0++) {
!       int i = e0 * i0 + e1 * i1 + e2 * i2;
!       if (!finite(U[i]) || !finite(V[i])) {
!         fprintf(stderr, "Not finite %d\n", i);
!         abort();
!       }
!       
!       num++;
!       if (U[i] < umin) umin = U[i];
!       if (U[i] > umax) umax = U[i];
!       usum += U[i];
!       
!       if (V[i] < vmin) vmin = V[i];
!       if (V[i] > vmax) vmax = V[i];
!       vsum += V[i];
!       }
! 
    fprintf(stderr, "\tu: %G %G %G\tv: %G %G %G\n", 
          umin, usum/num, umax,
          vmin, vsum/num, vmax);
***************
*** 225,230 ****
--- 253,259 ----
    c[3] = w;
  }
  
+ float threshold = 51./128;
  
  void display() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
***************
*** 261,269 ****
      glMultMatrixf(mat);
  
  
!   glTranslatef(-1, -1, -1);
!   glScalef(2./(n0 - 2), 2./(n1-2), 2./(n2-2));
!   glTranslatef(-1, -1, -1);
  
    glPointSize(5);
    int i = 0;
--- 290,297 ----
      glMultMatrixf(mat);
  
  
!   glScalef(2./SCALE, 2./SCALE, 2./SCALE);
!   glTranslatef(-n0/2, -n1/2, -n2/2);
  
    glPointSize(5);
    int i = 0;
***************
*** 278,284 ****
      for (int i1 = 1; i1 < n1-1; i1++) {
        int i = i1 * e1 + i2 * e2 + e0;
        for (int i0 = 1; i0 < n0-1; i0++) {
!       if(U[i] < 0.4 || i2 == through) {
            bool stripe = 
                (i1 % 16 == 0) ||
                (i0 % 16 == 0) ||
--- 306,312 ----
      for (int i1 = 1; i1 < n1-1; i1++) {
        int i = i1 * e1 + i2 * e2 + e0;
        for (int i0 = 1; i0 < n0-1; i0++) {
!       if(U[i] < threshold || i2 == through) {
            bool stripe = 
                (i1 % 16 == 0) ||
                (i0 % 16 == 0) ||
***************
*** 305,310 ****
--- 333,339 ----
    if(!repaintRightaway) {
         evolve(); i++;
         if (iter % 100 == 0) stats();
+        if (iter % 1000  == 0) writeout();
         if (iter %20 == 0) repaintRightaway = true;
      } else {
        repaintRightaway = false;
***************
*** 313,318 ****
--- 342,355 ----
  }
  
  
+ void keypress(unsigned char key, int x, int y) {
+   cout << key << " pressed\n";
+   switch (key) {
+   case '+': cout << (threshold += 1./128) << "\n"; break;
+   case '-': cout << (threshold -= 1./128) << "\n"; break;
+   }
+ }
+ 
  
  bool buttons[3] = {0,0,0};
  float buttonx[3] = {0,0,0};
***************
*** 369,374 ****
--- 406,412 ----
  
    glutDisplayFunc(display);
    glutIdleFunc(idle);
+   glutKeyboardFunc(keypress);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]