コード例 #1
0
/* ---------------------------------
	Jacobi
---------------------------------- */
void jacobi( Matrix *m, int num_of_file ) {
	Matrix *eigen_values = m
	     , *eigen_vectors = generateIdentityMatrix( m->height )
	     , old
	;
	Coordinate position;
	char fname[256];
	double theta;
	int count = 0;

	while(1) {
		position = locateMaxValue( eigen_values );
		if ( position.value < THRESHOLD )
			break;

		printf("%d回目 : %lf\n", count++, position.value );

		theta = calcAngle( m, position );
		eigen_values  = rotate( eigen_values,  position, theta );
		eigen_vectors = append( eigen_vectors, position, theta );
		repair( eigen_values );
	}

	sprintf( fname, "EigenValues%02d.txt", num_of_file );
	printMatrixToFile( fname, eigen_values  );
	sprintf( fname, "EigenVectors%02d.txt", num_of_file );
	printMatrixToFile( fname, eigen_vectors );
}
コード例 #2
0
void exportWaveFieldToFile(structMatrix h_field,structMatrix v_field,int timeStep, char *destinyFile, char *folderName) {
	/*
		 *	Initiating the mesh
		 */

		structMatrix mesh_hmatrix,mesh_vmatrix;
		structMatrix u_matrix_timeV[N_TIME_STEPS],v_matrix_timeV[N_TIME_STEPS];

		// Initiating mesh
		mesh_hmatrix = initMatrix(N_HNODES,N_VNODES);
		mesh_vmatrix = initMatrix(N_HNODES,N_VNODES);
		loadMesh(mesh_hmatrix,mesh_vmatrix);

		char path[50] = "../testbench/";
		strcat(path,folderName);
		strcat(path,"/");
		strcat(path,destinyFile);
		char indexu[4],indexv[4],quiverexp[30],time_index[2];
		sprintf(time_index,"%d",timeStep);
		strcat(path,"_");
		strcat(path,time_index);
		strcat(path,"_c.m");


		sprintf(indexu,"u%d",timeStep);
		sprintf(indexv,"v%d",timeStep);
		sprintf(quiverexp,"quiver(x,y,%s,%s)\n",indexu,indexv);
		printMatrixToFile(h_field,path,indexu);
		printMatrixToFile(v_field,path,indexv);
		printMatrixToFile(mesh_hmatrix,path,"x");
		printMatrixToFile(mesh_vmatrix,path,"y");
		// At the end, print the "quiver" function
		FILE *destinyFileP = fopen(path,"a");
		fprintf(destinyFileP,"%s",quiverexp);
		fclose(destinyFileP);


		// Generate the plotter script
		char plotterName[MAX_FILENAME_LENGTH];
		FILE *plotter;
		strcpy(plotterName,"../testbench/");
		strcat(plotterName,folderName);
		strcat(plotterName,"/");
		strcat(plotterName,destinyFile);
		strcat(plotterName,"_c_plotter.m");
		plotter = fopen(plotterName,"w");
		for(int i=0; i< N_TIME_STEPS; i++ ) {
			fprintf(plotter,"%s_%d_c \nprint -djpg %s_%d_c.jpg\n",destinyFile,i,destinyFile,i);
		}
		fclose(plotter);


		// Memory Freeing
		destroyMatrix(mesh_hmatrix);
		destroyMatrix(mesh_vmatrix);
}
コード例 #3
0
ファイル: 03.c プロジェクト: yk-m/Knowledge-Engineering-II
void printEigen( Matrix *eigen_values, Matrix *eigen_vectors, int num_of_file ) {
	char fn[256];

	Matrix *eigen = createMatrix( eigen_vectors->height + 1, eigen_values->height );
	for ( int row = 0; row < eigen->height; row++ ) {
		eigen->a[row][0] = eigen_values->a[row][row];
		for ( int col = 1; col < eigen->width; col++ ) {
			eigen->a[row][col] = eigen_vectors->a[col-1][row];
		}
	}

	sort( eigen );
	sprintf( fn, "eigen%02d.txt", num_of_file );
	printMatrixToFile( fn, eigen );
}
コード例 #4
0
void generateWaveBenchmarkTimeVariant(char *destinyFileName,char *folderName,void (*waveFunction)(structMatrix,structMatrix,structMatrix*,structMatrix*)) {
	/*
	 *	Initiating the mesh
	 */

	structMatrix mesh_hmatrix,mesh_vmatrix;
	structMatrix u_matrix_timeV[N_TIME_STEPS],v_matrix_timeV[N_TIME_STEPS];

	// Initiating mesh
	mesh_hmatrix = initMatrix(N_HNODES,N_VNODES);
	mesh_vmatrix = initMatrix(N_HNODES,N_VNODES);
	loadMesh(mesh_hmatrix,mesh_vmatrix);

	char path[N_TIME_STEPS][MAX_FILENAME_LENGTH];
	generateFileNames(path,destinyFileName,folderName);



	for(int i=0; i< N_TIME_STEPS; i++) {
		//printf("path[%d]: %s\n",i,path[i]);
		// Initializing u and v matrixes
		u_matrix_timeV[i] = initMatrix(N_HNODES,N_VNODES);
		v_matrix_timeV[i] = initMatrix(N_HNODES,N_VNODES);
	}


	// Calculations are handled via callback
	// This function must calculate for every time-step!
	waveFunction(mesh_hmatrix,mesh_vmatrix,u_matrix_timeV,v_matrix_timeV);


	// Printing matrixes to files
	for(int i=0; i< N_TIME_STEPS; i++) {
		char indexu[4],indexv[4],quiverexp[30];
		sprintf(indexu,"u%d",i);
		sprintf(indexv,"v%d",i);
		sprintf(quiverexp,"quiver(x,y,%s,%s)\n",indexu,indexv);
		printMatrixToFile(u_matrix_timeV[i],path[i],indexu);
		printMatrixToFile(v_matrix_timeV[i],path[i],indexv);
		printMatrixToFile(mesh_hmatrix,path[i],"x");
		printMatrixToFile(mesh_vmatrix,path[i],"y");
		// At the end, print the "quiver" function
		FILE *destinyFile = fopen(path[i],"a");
		fprintf(destinyFile,"%s",quiverexp);
		fclose(destinyFile);
	}

	// Memory freeing
	for(int i=0; i< N_TIME_STEPS; i++) {
		destroyMatrix(u_matrix_timeV[i]);
		destroyMatrix(v_matrix_timeV[i]);
	}
	destroyMatrix(mesh_hmatrix);
	destroyMatrix(mesh_vmatrix);

	// Generate the plotter script
	char plotterName[MAX_FILENAME_LENGTH];
	FILE *plotter;
	strcpy(plotterName,"../testbench/");
	strcat(plotterName,folderName);
	strcat(plotterName,"/");
	strcat(plotterName,destinyFileName);
	strcat(plotterName,"_plotter.m");
	plotter = fopen(plotterName,"w");

		for(int i=0; i< N_TIME_STEPS; i++ ) {
			fprintf(plotter,"%s_%d \nprint -djpg %s_%d.jpg\n",destinyFileName,i,destinyFileName,i);
		}

	fclose(plotter);
}