diff --git a/stim/biomodels/flow.h b/stim/biomodels/flow.h index 2b6cd4a..3ab8740 100644 --- a/stim/biomodels/flow.h +++ b/stim/biomodels/flow.h @@ -3,7 +3,7 @@ #include // Required for setw #include // Required for cout, cin, etc. #include // Required for returning multiple values from a function -//#include +#include //#include //#include // Required to remove ambiguous error for cout, cin, etc. @@ -13,15 +13,15 @@ using namespace std; class flow { public: - void backupToTxt(unsigned int nL, float **D, char filename[]); + void backupToTxt(unsigned int nL, double **D, char filename[]); tuple copySrcDesRadLen(char filename[]); - void copyToArray(int *src, int *dest, float *radii, float *len); + void copyToArray(int *src, int *dest, double *radii, double *len); int getDangleNodes(int datarow, int numNodes, int *row, int *column, int *dangleNodes); - void inversion(float **a, int n, float **b); + void inversion(double **a, int n, double **b); protected: - float determinant(float **a, int n); - int minor(float **src, float **dest, int row, int col, int order); + float determinant(double **a, int n); + int minor(double **src, double **dest, int row, int col, int order); }; /* Function to find the dangle nodes in a network */ @@ -116,7 +116,7 @@ int flow::getDangleNodes(int datarow, int numNodes, int *column1, int *column2, // Function to make a backup copy of the contents of a matrix to a .txt file // Created by Cherub P. Harder (8/10/2015), U of Houston -void flow::backupToTxt(unsigned int nL, float **D, char filename[]) +void flow::backupToTxt(unsigned int nL, double **D, char filename[]) { ofstream output_file(filename); @@ -203,10 +203,10 @@ tuple flow::copySrcDesRadLen(char filename[]) // Function to copy data for .txt files to their respective arrays // Created by Cherub P. Harder (8/11/2015), U of Houston -void flow::copyToArray(int *src, int *dest, float *radii, float *len) +void flow::copyToArray(int *src, int *dest, double *radii, double *len) { int v = 0; - float tmp = 0, R = 0, L = 0; + double tmp = 0, R = 0, L = 0; // Store source node values to the array src ifstream readSrc("srcCol.txt"); @@ -258,14 +258,15 @@ void flow::copyToArray(int *src, int *dest, float *radii, float *len) // Function to find the inverse of a square matrix -void flow::inversion(float **a, int n, float **b) +void flow::inversion(double **a, int n, double **b) { - // Get the determinant of A - float det = (float)(1.0/determinant(a, n)); + // Get 1 over the determinant of A + double det = (double)(1.0/determinant(a, n)); + cerr << "\n1/det(C) = " << det << endl; // DELETE!!! // Memory allocation - float *tmp = new float[(n-1) * (n-1)]; - float **m = new float * [n-1]; + double *tmp = new double[(n-1) * (n-1)]; + double **m = new double * [n-1]; for( int i = 0; i < n-1; i++ ) m[i] = tmp + ( i * (n-1) ); @@ -275,7 +276,6 @@ void flow::inversion(float **a, int n, float **b) { // Get the cofactor (matrix) of a(j,i) minor(a, m, j, i, n); -// coFactor(a, 3, b); b[i][j] = det * determinant( m, n-1 ); if( (i+j)%2 == 1 ) b[i][j] = -b[i][j]; @@ -294,11 +294,11 @@ void flow::inversion(float **a, int n, float **b) // Modified by Cherub P. Harder (7/15/2015), U of Houston // Arguments: a(double **) - pointer to a pointer of an arbitrary square matrix // n(int) - dimension of the square matrix -float flow::determinant(float **a, int n) +float flow::determinant(double **a, int n) { int i, j, j1, j2; // General loop and matrix subscripts - float det = 0; // Initialize determinant - float **m = NULL; // Pointer to pointer to implement 2D square array + double det = 0; // Initialize determinant + double **m = NULL; // Pointer to pointer to implement 2D square array // Display contents of matrix C (DELETE!!!) /* std::cout << "\nThe updated matrix C:\n"; @@ -332,10 +332,10 @@ float flow::determinant(float **a, int n) for (j1 = 0; j1 < n; j1++) // For each column in sub-matrix get space for the { // pointer list - m = (float **) malloc((n-1) * sizeof(float *)); + m = (double **) malloc((n-1) * sizeof(double *)); for (i = 0; i < n-1; i++) - m[i] = (float *) malloc((n-1)* sizeof(float)); + m[i] = (double *) malloc((n-1)* sizeof(double)); // i[0][1][2][3] first malloc // m -> + + + + space for 4 pointers // | | | | j second malloc @@ -362,7 +362,7 @@ float flow::determinant(float **a, int n) } } - det += (float)pow(-1.0, 1.0 + j1 + 1.0) * a[0][j1] * determinant(m, n-1); + det += (double)pow(-1.0, 1.0 + j1 + 1.0) * a[0][j1] * determinant(m, n-1); // Sum x raised to y power // recursively get determinant of next // sub-matrix which is now one @@ -380,17 +380,17 @@ float flow::determinant(float **a, int n) // Function to calculate the cofactor of element (row, col) -int flow::minor(float **src, float **dest, int row, int col, int order) +int flow::minor(double **src, double **dest, int row, int col, int order) { // Indicate which col and row is being copied to dest int colCount=0,rowCount=0; - for(int i = 0; i < order; i++ ) + for(int i = 0; i < order; i++) { - if( i != row ) + if(i != row) { colCount = 0; - for(int j = 0; j < order; j++ ) + for(int j = 0; j < order; j++) { // When j is not the element if( j != col ) -- libgit2 0.21.4