Пример #1
0
void initGrid(double u0[], double u1[], double v0[], double v1[], int w) {
  int i, j;

  for (i=0; i<w; i++) {
    for (j=0; j<w; j++) {
      dataAt(u0, i, j, w) = 1.;
      dataAt(u1, i, j, w) = 1.;
      dataAt(v0, i, j, w) = 0.;
      dataAt(v1, i, j, w) = 0.;
    }
  }
}
Пример #2
0
void cuDumpGrid(double g[], double h[], int w) {
  int i, j;
  FILE *fp;

  fp = fopen("cudump.out", "w");
  
  for (i=0; i<w; i++) {
    for (j=0; j<w; j++) {
      fprintf(fp, "%d %d %f %f\n", i, j, dataAt(g, i, j, w), dataAt(h, i, j, w));
    }
  }
  fclose(fp);
}
Пример #3
0
	void Matrix::inverse(void)
	{
		Matrix m;
		int a, i, j;
		Vector4 v, vec[3];
		float det;
		float temp;
 
		det = determinant();
	
		if(det)	// Matrix invertierbar?
		{
			for(i = 0; i < 4; i++)
			{
				for(j = 0; j < 4; j++)
				{
					if(j != i )
					{
						a = j;
				
						if(j > i)
						{
							a = a - 1;
						}
				
						vec[a].x = dataAt( j, 0 );
						vec[a].y = dataAt( j, 1 );
						vec[a].z = dataAt( j, 2 );
						vec[a].w = dataAt( j, 3 );
					}
				}
		
				v = vec[0].cross( vec[1], vec[2] );
		
				temp = pow( -1.0f, i );
		
				m.dataAt( 0, i ) = temp * v.x / det;
				m.dataAt( 1, i ) = temp * v.y / det;
				m.dataAt( 2, i ) = temp * v.z / det;
				m.dataAt( 3, i ) = temp * v.w / det;
			}

			*this = m;
		}
	}
Пример #4
0
void printGrid(double g[], int w) {
  int i, j;

  for (i=0; i<w; i++) {
    for (j=0; j<w; j++) {
      printf("%7.3f ", dataAt(g, i, j, w));
    }
    printf("\n");
  }
}
Пример #5
0
	void Matrix::transpose(void)
	{
		Matrix m;
		for(int i = 0; i < 4; i++)
		{
			for(int j = 0; j < 4; j++)
			{
				m.dataAt( i, j ) = dataAt( j, i );
			}
		}
		*this = m;
	}
Пример #6
0
	Matrix Matrix::getTranspose(void) const
	{
		Matrix m;
		for(int i = 0; i < 4; i++)
		{
			for(int j = 0; j < 4; j++)
			{
				m.dataAt( i, j ) = dataAt( j, i );
			}
		}

		return m;
	}
Пример #7
0
void updateGrid(double u[], double tu[], double v[], double tv[], int w) {
  int i, j;
  double uv2;

  for (i=1; i<w-1; i++) {
    for (j=1; j<w-1; j++) {
      uv2 = dataAt(tu, i, j, w) * dataAt(tv, i, j, w) * dataAt(tv, i, j, w);


      double u1 = dataAt(tu, i, j, w)
        + .2 * (dataAt(tu, i+1, j, w) + dataAt(tu, i-1, j, w)
                + dataAt(tu, i, j+1, w) + dataAt(tu, i, j-1, w)
                - 4 * dataAt(tu, i, j, w))
        - uv2 + .025 * (1 - dataAt(tu, i, j, w));

      u1 = fmin(1, u1);
      dataAt(u, i, j, w) = fmax(0, u1);
      
      double v1 = dataAt(tv, i, j, w)
        + .1 * (dataAt(tv, i+1, j, w) + dataAt(tv, i-1, j, w)
                + dataAt(tv, i, j+1, w) + dataAt(tv, i, j-1, w)
                - 4 * dataAt(tv, i, j, w))
        + uv2 - .08 * dataAt(tv, i, j, w);
      v1 = fmin(1, v1);
      dataAt(v, i, j, w) = fmax(0, v1);
    }
  }
}