Changes in src/helpers.cpp [5034e1:99593f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/helpers.cpp
r5034e1 r99593f 6 6 7 7 #include "helpers.hpp" 8 9 #include "memoryusageobserver.hpp" 8 10 9 11 /********************************************** helpful functions *********************************/ … … 47 49 while (*b < lower_bound) 48 50 *b += step; 49 };50 51 /** Flips two doubles.52 * \param *x pointer to first double53 * \param *y pointer to second double54 */55 void flip(double *x, double *y)56 {57 double tmp;58 tmp = *x;59 *x = *y;60 *y = tmp;61 51 }; 62 52 … … 143 133 * \return allocated NDIM*NDIM array with the symmetric matrix 144 134 */ 145 double * ReturnFullMatrixforSymmetric( double *symm)135 double * ReturnFullMatrixforSymmetric(const double * const symm) 146 136 { 147 137 double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix"); … … 158 148 }; 159 149 150 /** Calculate the inverse of a 3x3 matrix. 151 * \param *matrix NDIM_NDIM array 152 */ 153 double * InverseMatrix( const double * const A) 154 { 155 double *B = Malloc<double>(NDIM * NDIM, "Vector::InverseMatrix: *B"); 156 double detA = RDET3(A); 157 double detAReci; 158 159 for (int i=0;i<NDIM*NDIM;++i) 160 B[i] = 0.; 161 // calculate the inverse B 162 if (fabs(detA) > MYEPSILON) {; // RDET3(A) yields precisely zero if A irregular 163 detAReci = 1./detA; 164 B[0] = detAReci*RDET2(A[4],A[5],A[7],A[8]); // A_11 165 B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]); // A_12 166 B[2] = detAReci*RDET2(A[1],A[2],A[4],A[5]); // A_13 167 B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]); // A_21 168 B[4] = detAReci*RDET2(A[0],A[2],A[6],A[8]); // A_22 169 B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]); // A_23 170 B[6] = detAReci*RDET2(A[3],A[4],A[6],A[7]); // A_31 171 B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]); // A_32 172 B[8] = detAReci*RDET2(A[0],A[1],A[3],A[4]); // A_33 173 } 174 return B; 175 }; 176 177 /** hard-coded determinant of a 3x3 matrix. 178 * \param a[9] matrix 179 * \return \f$det(a)\f$ 180 */ 181 double RDET3(const double a[NDIM*NDIM]) 182 { 183 return ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3]); 184 }; 185 186 /** hard-coded determinant of a 2x2 matrix. 187 * \param a[4] matrix 188 * \return \f$det(a)\f$ 189 */ 190 double RDET2(const double a[4]) 191 { 192 return ((a[0])*(a[3])-(a[1])*(a[2])); 193 }; 194 195 /** hard-coded determinant of a 2x2 matrix. 196 * \param a0 (0,0) entry of matrix 197 * \param a1 (0,1) entry of matrix 198 * \param a2 (1,0) entry of matrix 199 * \param a3 (1,1) entry of matrix 200 * \return \f$det(a)\f$ 201 */ 202 double RDET2(const double a0, const double a1, const double a2, const double a3) 203 { 204 return ((a0)*(a3)-(a1)*(a2)); 205 }; 206 160 207 /** Comparison function for GSL heapsort on distances in two molecules. 161 208 * \param *a … … 202 249 * Frees all memory registered by the memory observer and calls exit(225) afterwards. 203 250 */ 204 staticvoid performCriticalExit() {251 void performCriticalExit() { 205 252 map<void*, size_t> pointers = MemoryUsageObserver::getInstance()->getPointersToAllocatedMemory(); 206 253 for (map<void*, size_t>::iterator runner = pointers.begin(); runner != pointers.end(); runner++) {
Note:
See TracChangeset
for help on using the changeset viewer.