Commit 9a1c681c6aed7075262ae86675a89258952b1c06

Authored by cherub
1 parent 4277a87d

modified flow.h

Showing 1 changed file with 25 additions and 25 deletions   Show diff stats
stim/biomodels/flow.h
... ... @@ -3,7 +3,7 @@
3 3 #include <iomanip> // Required for setw
4 4 #include <iostream> // Required for cout, cin, etc.
5 5 #include <tuple> // Required for returning multiple values from a function
6   -//#include <vector>
  6 +#include <vector>
7 7 //#include <string>
8 8 //#include <stdlib.h> // Required to remove ambiguous error for cout, cin, etc.
9 9  
... ... @@ -13,15 +13,15 @@ using namespace std;
13 13 class flow
14 14 {
15 15 public:
16   - void backupToTxt(unsigned int nL, float **D, char filename[]);
  16 + void backupToTxt(unsigned int nL, double **D, char filename[]);
17 17 tuple<int, int> copySrcDesRadLen(char filename[]);
18   - void copyToArray(int *src, int *dest, float *radii, float *len);
  18 + void copyToArray(int *src, int *dest, double *radii, double *len);
19 19 int getDangleNodes(int datarow, int numNodes, int *row, int *column, int *dangleNodes);
20   - void inversion(float **a, int n, float **b);
  20 + void inversion(double **a, int n, double **b);
21 21  
22 22 protected:
23   - float determinant(float **a, int n);
24   - int minor(float **src, float **dest, int row, int col, int order);
  23 + float determinant(double **a, int n);
  24 + int minor(double **src, double **dest, int row, int col, int order);
25 25 };
26 26  
27 27 /* Function to find the dangle nodes in a network */
... ... @@ -116,7 +116,7 @@ int flow::getDangleNodes(int datarow, int numNodes, int *column1, int *column2,
116 116  
117 117 // Function to make a backup copy of the contents of a matrix to a .txt file
118 118 // Created by Cherub P. Harder (8/10/2015), U of Houston
119   -void flow::backupToTxt(unsigned int nL, float **D, char filename[])
  119 +void flow::backupToTxt(unsigned int nL, double **D, char filename[])
120 120 {
121 121 ofstream output_file(filename);
122 122  
... ... @@ -203,10 +203,10 @@ tuple&lt;int, int&gt; flow::copySrcDesRadLen(char filename[])
203 203  
204 204 // Function to copy data for .txt files to their respective arrays
205 205 // Created by Cherub P. Harder (8/11/2015), U of Houston
206   -void flow::copyToArray(int *src, int *dest, float *radii, float *len)
  206 +void flow::copyToArray(int *src, int *dest, double *radii, double *len)
207 207 {
208 208 int v = 0;
209   - float tmp = 0, R = 0, L = 0;
  209 + double tmp = 0, R = 0, L = 0;
210 210  
211 211 // Store source node values to the array src
212 212 ifstream readSrc("srcCol.txt");
... ... @@ -258,14 +258,15 @@ void flow::copyToArray(int *src, int *dest, float *radii, float *len)
258 258  
259 259  
260 260 // Function to find the inverse of a square matrix
261   -void flow::inversion(float **a, int n, float **b)
  261 +void flow::inversion(double **a, int n, double **b)
262 262 {
263   - // Get the determinant of A
264   - float det = (float)(1.0/determinant(a, n));
  263 + // Get 1 over the determinant of A
  264 + double det = (double)(1.0/determinant(a, n));
  265 + cerr << "\n1/det(C) = " << det << endl; // DELETE!!!
265 266  
266 267 // Memory allocation
267   - float *tmp = new float[(n-1) * (n-1)];
268   - float **m = new float * [n-1];
  268 + double *tmp = new double[(n-1) * (n-1)];
  269 + double **m = new double * [n-1];
269 270 for( int i = 0; i < n-1; i++ )
270 271 m[i] = tmp + ( i * (n-1) );
271 272  
... ... @@ -275,7 +276,6 @@ void flow::inversion(float **a, int n, float **b)
275 276 {
276 277 // Get the cofactor (matrix) of a(j,i)
277 278 minor(a, m, j, i, n);
278   -// coFactor(a, 3, b);
279 279 b[i][j] = det * determinant( m, n-1 );
280 280 if( (i+j)%2 == 1 )
281 281 b[i][j] = -b[i][j];
... ... @@ -294,11 +294,11 @@ void flow::inversion(float **a, int n, float **b)
294 294 // Modified by Cherub P. Harder (7/15/2015), U of Houston
295 295 // Arguments: a(double **) - pointer to a pointer of an arbitrary square matrix
296 296 // n(int) - dimension of the square matrix
297   -float flow::determinant(float **a, int n)
  297 +float flow::determinant(double **a, int n)
298 298 {
299 299 int i, j, j1, j2; // General loop and matrix subscripts
300   - float det = 0; // Initialize determinant
301   - float **m = NULL; // Pointer to pointer to implement 2D square array
  300 + double det = 0; // Initialize determinant
  301 + double **m = NULL; // Pointer to pointer to implement 2D square array
302 302  
303 303 // Display contents of matrix C (DELETE!!!)
304 304 /* std::cout << "\nThe updated matrix C:\n";
... ... @@ -332,10 +332,10 @@ float flow::determinant(float **a, int n)
332 332  
333 333 for (j1 = 0; j1 < n; j1++) // For each column in sub-matrix get space for the
334 334 { // pointer list
335   - m = (float **) malloc((n-1) * sizeof(float *));
  335 + m = (double **) malloc((n-1) * sizeof(double *));
336 336  
337 337 for (i = 0; i < n-1; i++)
338   - m[i] = (float *) malloc((n-1)* sizeof(float));
  338 + m[i] = (double *) malloc((n-1)* sizeof(double));
339 339 // i[0][1][2][3] first malloc
340 340 // m -> + + + + space for 4 pointers
341 341 // | | | | j second malloc
... ... @@ -362,7 +362,7 @@ float flow::determinant(float **a, int n)
362 362 }
363 363 }
364 364  
365   - det += (float)pow(-1.0, 1.0 + j1 + 1.0) * a[0][j1] * determinant(m, n-1);
  365 + det += (double)pow(-1.0, 1.0 + j1 + 1.0) * a[0][j1] * determinant(m, n-1);
366 366 // Sum x raised to y power
367 367 // recursively get determinant of next
368 368 // sub-matrix which is now one
... ... @@ -380,17 +380,17 @@ float flow::determinant(float **a, int n)
380 380  
381 381  
382 382 // Function to calculate the cofactor of element (row, col)
383   -int flow::minor(float **src, float **dest, int row, int col, int order)
  383 +int flow::minor(double **src, double **dest, int row, int col, int order)
384 384 {
385 385 // Indicate which col and row is being copied to dest
386 386 int colCount=0,rowCount=0;
387 387  
388   - for(int i = 0; i < order; i++ )
  388 + for(int i = 0; i < order; i++)
389 389 {
390   - if( i != row )
  390 + if(i != row)
391 391 {
392 392 colCount = 0;
393   - for(int j = 0; j < order; j++ )
  393 + for(int j = 0; j < order; j++)
394 394 {
395 395 // When j is not the element
396 396 if( j != col )
... ...