|
27 | 27 | int IsFalse(char *str);
|
28 | 28 | static
|
29 | 29 | double ModDiff(double f1, double f2);
|
| 30 | +static |
| 31 | +int DiffNCycle(double f1, double f2); |
30 | 32 |
|
31 | 33 |
|
32 | 34 | /* function: IsTrue()
|
@@ -105,6 +107,30 @@ double ModDiff(double f1, double f2){
|
105 | 107 | }
|
106 | 108 |
|
107 | 109 |
|
| 110 | +/* function: DiffNCycle() |
| 111 | + * ------------------- |
| 112 | + * Computes the number of cycles of 2pi that must be added to the |
| 113 | + * difference between f1 and f2 in order to "wrap" it to the interval |
| 114 | + * (-pi,pi]. f1 and f2 should be between [0,2pi). Assumes that PI has |
| 115 | + * been defined. |
| 116 | + * |
| 117 | + * See also: ModDiff() |
| 118 | + */ |
| 119 | +static |
| 120 | +int DiffNCycle(double f1, double f2){ |
| 121 | + |
| 122 | + const auto f3=f1-f2; |
| 123 | + if(f3>PI){ |
| 124 | + return -1; |
| 125 | + } |
| 126 | + if(f3<=-PI){ |
| 127 | + return 1; |
| 128 | + } |
| 129 | + |
| 130 | + return(0); |
| 131 | +} |
| 132 | + |
| 133 | + |
108 | 134 | /* function: WrapPhase()
|
109 | 135 | * ---------------------
|
110 | 136 | * Makes sure the passed float array is properly wrapped into the [0,2pi)
|
@@ -302,30 +328,27 @@ int CalcFlow(Array2D<float>& phase, Array2D<short>* flowsptr, long nrow, long nc
|
302 | 328 | * wrapped phase to create an unwrapped phase field. The unwrapped
|
303 | 329 | * phase field will be the same size as the wrapped field. The array
|
304 | 330 | * rowflow should have size N-1xM and colflow size NxM-1 where the
|
305 |
| - * phase fields are NxM. Output is saved to a file. |
| 331 | + * phase fields are NxM. |
306 | 332 | */
|
307 | 333 | int IntegratePhase(Array2D<float>& psi, Array2D<float>& phi, Array2D<short>& flows,
|
308 | 334 | long nrow, long ncol){
|
309 | 335 |
|
310 |
| - long row, col; |
311 |
| - |
312 |
| - auto rowflow = flows.block(0,0,nrow-1,ncol); |
313 |
| - auto colflow = flows.block(nrow-1,0,nrow,ncol-1); |
314 |
| - |
315 |
| - /* set first element as seed */ |
316 |
| - phi(0,0)=psi(0,0); |
| 336 | + auto rowflow=flows.block(0,0,nrow-1,ncol); |
| 337 | + auto colflow=flows.block(nrow-1,0,nrow,ncol-1); |
317 | 338 |
|
318 |
| - /* integrate over first row */ |
319 |
| - for(col=1;col<ncol;col++){ |
320 |
| - phi(0,col)=phi(0,col-1)+(ModDiff(psi(0,col),psi(0,col-1)) |
321 |
| - +colflow(0,col-1)*TWOPI); |
322 |
| - } |
323 |
| - |
324 |
| - /* integrate over columns */ |
325 |
| - for(row=1;row<nrow;row++){ |
326 |
| - for(col=0;col<ncol;col++){ |
327 |
| - phi(row,col)=phi(row-1,col)+(ModDiff(psi(row,col),psi(row-1,col)) |
328 |
| - -rowflow(row-1,col)*TWOPI); |
| 339 | + /* compute unwrapped phase by accumulating the total number of cycles to be |
| 340 | + added along an integration path that spans each row */ |
| 341 | + long initcycles=0; |
| 342 | + for(long row=0;row<nrow;row++){ |
| 343 | + if(row>0){ |
| 344 | + initcycles+=DiffNCycle(psi(row,0),psi(row-1,0))-rowflow(row-1,0); |
| 345 | + } |
| 346 | + long cycles=initcycles; |
| 347 | + for(long col=0;col<ncol;col++){ |
| 348 | + if(col>0){ |
| 349 | + cycles+=DiffNCycle(psi(row,col),psi(row,col-1))+colflow(row,col-1); |
| 350 | + } |
| 351 | + phi(row,col)=psi(row,col)+TWOPI*cycles; |
329 | 352 | }
|
330 | 353 | }
|
331 | 354 |
|
|
0 commit comments