[Bf-blender-cvs] [f235da9] hair_immediate_fixes: Debug printing code for large sparse vectors and matrices, to compare solver input/output of the old and new methods.

Lukas Tönne noreply at git.blender.org
Wed Sep 10 18:56:51 CEST 2014


Commit: f235da9b53939c96e1c92d203a7b04c2d603741a
Author: Lukas Tönne
Date:   Wed Sep 10 16:04:31 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rBf235da9b53939c96e1c92d203a7b04c2d603741a

Debug printing code for large sparse vectors and matrices, to compare
solver input/output of the old and new methods.

===================================================================

M	source/blender/blenkernel/intern/implicit.c
M	source/blender/blenkernel/intern/implicit.h
M	source/blender/blenkernel/intern/implicit_eigen.cpp

===================================================================

diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c
index 7172c8f..5791b23 100644
--- a/source/blender/blenkernel/intern/implicit.c
+++ b/source/blender/blenkernel/intern/implicit.c
@@ -367,6 +367,62 @@ static void print_sparse_matrix(fmatrix3x3 *m)
 }
 #endif
 
+static void print_lvector(lfVector *v, int numverts)
+{
+	int i;
+	for (i = 0; i < numverts; ++i) {
+		if (i > 0)
+			printf("\n");
+		
+		printf("%f\n", v[i][0]);
+		printf("%f\n", v[i][1]);
+		printf("%f\n", v[i][2]);
+	}
+}
+
+static void print_bfmatrix(fmatrix3x3 *m)
+{
+	int tot = m[0].vcount + m[0].scount;
+	int size = m[0].vcount * 3;
+	float *t = MEM_callocN(sizeof(float) * size*size, "bfmatrix");
+	int q, i, j;
+	
+	for (q = 0; q < tot; ++q) {
+		int k = 3 * m[q].r;
+		int l = 3 * m[q].c;
+		
+		for (j = 0; j < 3; ++j) {
+			for (i = 0; i < 3; ++i) {
+//				if (t[k + i + (l + j) * size] != 0.0f) {
+//					printf("warning: overwriting value at %d, %d\n", m[q].r, m[q].c);
+//				}
+				if (k == l) {
+					t[k + i + (k + j) * size] += m[q].m[i][j];
+				}
+				else {
+					t[k + i + (l + j) * size] += m[q].m[i][j];
+					t[l + j + (k + i) * size] += m[q].m[j][i];
+				}
+			}
+		}
+	}
+	
+	for (j = 0; j < size; ++j) {
+		if (j > 0 && j % 3 == 0)
+			printf("\n");
+		
+		for (i = 0; i < size; ++i) {
+			if (i > 0 && i % 3 == 0)
+				printf("  ");
+			
+			implicit_print_matrix_elem(t[i + j * size]);
+		}
+		printf("\n");
+	}
+	
+	MEM_freeN(t);
+}
+
 /* copy 3x3 matrix */
 DO_INLINE void cp_fmatrix(float to[3][3], float from[3][3])
 {
@@ -1030,6 +1086,17 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z,
 	/* delta = r^T * c */
 	delta_new = dot_lfvector(r, c, numverts);
 	
+#ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT
+	printf("==== A ====\n");
+	print_bfmatrix(lA);
+	printf("==== z ====\n");
+	print_lvector(z, numverts);
+	printf("==== B ====\n");
+	print_lvector(lB, numverts);
+	printf("==== S ====\n");
+	print_bfmatrix(S);
+#endif
+	
 	while (delta_new > delta_target && conjgrad_loopcount < conjgrad_looplimit) {
 		mul_bfmatrix_lfvector(q, lA, c);
 		filter(q, S);
@@ -1050,6 +1117,12 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z,
 		
 		conjgrad_loopcount++;
 	}
+
+#ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT
+	printf("==== dV ====\n");
+	print_lvector(ldV, numverts);
+	printf("========\n");
+#endif
 	
 	del_lfvector(fB);
 	del_lfvector(AdV);
diff --git a/source/blender/blenkernel/intern/implicit.h b/source/blender/blenkernel/intern/implicit.h
index dd12cb9..91c4ebb 100644
--- a/source/blender/blenkernel/intern/implicit.h
+++ b/source/blender/blenkernel/intern/implicit.h
@@ -32,7 +32,16 @@
  *  \ingroup bke
  */
 
+#include "BLI_utildefines.h"
+
 #define IMPLICIT_SOLVER_EIGEN
 //#define IMPLICIT_SOLVER_BLENDER
 
+#define IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT
+
+BLI_INLINE void implicit_print_matrix_elem(float v)
+{
+    printf("%-8.3f", v);
+}
+
 #endif
diff --git a/source/blender/blenkernel/intern/implicit_eigen.cpp b/source/blender/blenkernel/intern/implicit_eigen.cpp
index e4f1d11..03d69a8 100644
--- a/source/blender/blenkernel/intern/implicit_eigen.cpp
+++ b/source/blender/blenkernel/intern/implicit_eigen.cpp
@@ -120,6 +120,9 @@ using Eigen::ComputationInfo;
 static void print_lvector(const lVector &v)
 {
 	for (int i = 0; i < v.rows(); ++i) {
+		if (i > 0 && i % 3 == 0)
+			printf("\n");
+		
 		printf("%f,\n", v[i]);
 	}
 }
@@ -127,8 +130,14 @@ static void print_lvector(const lVector &v)
 static void print_lmatrix(const lMatrix &m)
 {
 	for (int j = 0; j < m.rows(); ++j) {
+		if (j > 0 && j % 3 == 0)
+			printf("\n");
+		
 		for (int i = 0; i < m.cols(); ++i) {
-			printf("%-8.3f,", m.coeff(j, i));
+			if (i > 0 && i % 3 == 0)
+				printf("  ");
+			
+			implicit_print_matrix_elem(m.coeff(j, i));
 		}
 		printf("\n");
 	}
@@ -300,7 +309,22 @@ static bool simulate_implicit_euler(Implicit_Data *id, float dt)
 	cg.filter() = id->S;
 	
 	id->B = dt * id->F + dt*dt * id->dFdX * id->V;
+#ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT
+	printf("==== A ====\n");
+	print_lmatrix(id->A);
+	printf("==== z ====\n");
+	print_lvector(id->z);
+	printf("==== B ====\n");
+	print_lvector(id->B);
+	printf("==== S ====\n");
+	print_lmatrix(id->S);
+#endif
 	id->dV = cg.solveWithGuess(id->B, id->z);
+#ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT
+	printf("==== dV ====\n");
+	print_lvector(id->dV);
+	printf("========\n");
+#endif
 	
 	id->Vnew = id->V + id->dV;




More information about the Bf-blender-cvs mailing list