Contents of /trunk/finley/src/Util.cpp

Revision 4789 - (show annotations)
Fri Mar 21 00:30:32 2014 UTC (5 years, 2 months ago) by sshaw
File size: 12750 byte(s)
```changing more awkward logic into more obvious (and correct, though i doubt a negative length ever happens) logic
```
 1 2 /***************************************************************************** 3 * 4 * Copyright (c) 2003-2014 by University of Queensland 5 6 * 7 * Primary Business: Queensland, Australia 8 * Licensed under the Open Software License version 3.0 9 10 * 11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC) 12 * Development 2012-2013 by School of Earth Sciences 13 * Development from 2014 by Centre for Geoscience Computing (GeoComp) 14 * 15 *****************************************************************************/ 16 17 18 /**************************************************************************** 19 20 Some utility routines 21 22 *****************************************************************************/ 23 24 #include "Finley.h" 25 #include "Util.h" 26 #include "esysUtils/index.h" 27 28 #include // std::sort 29 #include 30 31 namespace finley { 32 namespace util { 33 34 /// comparison function for sortValueAndIndex 35 bool ValueAndIndexCompare(const std::pair &i, const std::pair &j) 36 { 37 // to ensure we have a strict ordering as required by std 38 if (i.first == j.first) 39 return i.second < j.second; 40 return i.first < j.first; 41 } 42 43 /// orders a ValueAndIndexList by value 44 void sortValueAndIndex(ValueAndIndexList& array) 45 { 46 std::sort(array.begin(), array.end(), ValueAndIndexCompare); 47 } 48 49 /// gathers values into vector out from vector in using index: 50 /// out(1:numData, 1:len) := in(1:numData, index(1:len)) 51 void gather(int len, const int* index, int numData, const double* in, double* out) 52 { 53 for (int s=0; s& B, 77 const std::vector& C) 78 { 79 for (int i=0; i& B, 93 const std::vector& C) 94 { 95 for (int q=0; q 0) { 116 det[q]=D; 117 invA[q]=1./D; 118 } else { 119 setError(ZERO_DIVISION_ERROR, "InvertSmallMat: Non-regular matrix"); 120 break; 121 } 122 } 123 break; 124 125 case 2: 126 for (int q=0; q 0) { 134 det[q]=D; 135 invA[INDEX3(0,0,q,2,2)]= A22/D; 136 invA[INDEX3(1,0,q,2,2)]=-A21/D; 137 invA[INDEX3(0,1,q,2,2)]=-A12/D; 138 invA[INDEX3(1,1,q,2,2)]= A11/D; 139 } else { 140 setError(ZERO_DIVISION_ERROR, "InvertSmallMat: Non-regular matrix"); 141 break; 142 } 143 } 144 break; 145 146 case 3: 147 for (int q=0; q 0) { 160 det[q]=D; 161 invA[INDEX3(0,0,q,3,3)]=(A22*A33-A23*A32)/D; 162 invA[INDEX3(1,0,q,3,3)]=(A31*A23-A21*A33)/D; 163 invA[INDEX3(2,0,q,3,3)]=(A21*A32-A31*A22)/D; 164 invA[INDEX3(0,1,q,3,3)]=(A13*A32-A12*A33)/D; 165 invA[INDEX3(1,1,q,3,3)]=(A11*A33-A31*A13)/D; 166 invA[INDEX3(2,1,q,3,3)]=(A12*A31-A11*A32)/D; 167 invA[INDEX3(0,2,q,3,3)]=(A12*A23-A13*A22)/D; 168 invA[INDEX3(1,2,q,3,3)]=(A13*A21-A11*A23)/D; 169 invA[INDEX3(2,2,q,3,3)]=(A11*A22-A12*A21)/D; 170 } else { 171 setError(ZERO_DIVISION_ERROR, "InvertSmallMat: Non-regular matrix"); 172 break; 173 } 174 } 175 break; 176 177 default: 178 setError(VALUE_ERROR, "InvertSmallMat: dim must be <=3"); 179 break; 180 } 181 } 182 183 /// returns the normalized vector Normal[dim,len] orthogonal to A(:,0,q) and 184 /// A(:,1,q) in the case of dim=3, or the vector A(:,0,q) in the case of dim=2 185 void normalVector(int len, int dim, int dim1, const double* A, double* Normal) 186 { 187 int q; 188 double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33,length,invlength; 189 190 switch(dim) { 191 case 1: 192 for (q=0;q::max(); 239 if (values && dim*N > 0) { 240 out=values[0]; 241 #pragma omp parallel 242 { 243 int out_local=out; 244 #pragma omp for 245 for (int j=0; j::min(); 260 if (values && dim*N > 0) { 261 out=values[0]; 262 #pragma omp parallel 263 { 264 int out_local=out; 265 #pragma omp for 266 for (int j=0; j getMinMaxInt(int dim, int N, const int* values) 278 { 279 int vmin = std::numeric_limits::max(); 280 int vmax = std::numeric_limits::min(); 281 if (values && dim*N > 0) { 282 vmin = vmax = values[0]; 283 #pragma omp parallel 284 { 285 int vmin_local=vmin; 286 int vmax_local=vmax; 287 #pragma omp for 288 for (int j=0; j(vmin,vmax); 302 } 303 304 /// calculates the minimum and maximum value from an integer array of length N 305 /// disregarding the value 'ignore' 306 std::pair getFlaggedMinMaxInt(int N, const int* values, int ignore) 307 { 308 int vmin = std::numeric_limits::max(); 309 int vmax = std::numeric_limits::min(); 310 if (values && N > 0) { 311 vmin = vmax = values[0]; 312 #pragma omp parallel 313 { 314 int vmin_local=vmin; 315 int vmax_local=vmax; 316 #pragma omp for 317 for (int i=0; i(vmin,vmax); 331 } 332 333 /// determines the indices of the positive entries in mask returning the 334 /// length of index. 335 std::vector packMask(const std::vector& mask) 336 { 337 std::vector index; 338 for (int k=0; k= 0) { 340 index.push_back(k); 341 } 342 } 343 return index; 344 } 345 346 void setValuesInUse(const int *values, const int numValues, 347 std::vector& valuesInUse, Esys_MPIInfo* mpiinfo) 348 { 349 int lastFoundValue=INDEX_T_MIN; 350 bool allFound=false; 351 352 valuesInUse.clear(); 353 354 while (!allFound) { 355 // find smallest value bigger than lastFoundValue 356 int minFoundValue = INDEX_T_MAX; 357 #pragma omp parallel 358 { 359 int local_minFoundValue=minFoundValue; 360 #pragma omp for 361 for (int i=0; ilastFoundValue) && (valcomm); 375 #endif 376 377 // if we found a new value we need to add this to valuesInUse 378 if (minFoundValue < INDEX_T_MAX) { 379 valuesInUse.push_back(minFoundValue); 380 lastFoundValue=minFoundValue; 381 } else { 382 allFound=true; 383 } 384 } 385 } 386 387 } // namespace util 388 } // namespace finley 389

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/lapack2681/finley/src/Util.cpp:2682-2741 /branches/pasowrap/finley/src/Util.cpp:3661-3674 /branches/py3_attempt2/finley/src/Util.cpp:3871-3891 /branches/restext/finley/src/Util.cpp:2610-2624 /branches/ripleygmg_from_3668/finley/src/Util.cpp:3669-3791 /branches/stage3.0/finley/src/Util.cpp:2569-2590 /branches/symbolic_from_3470/finley/src/Util.cpp:3471-3974 /release/3.0/finley/src/Util.cpp:2591-2601 /trunk/finley/src/Util.cpp:4257-4344