Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/helpers.cpp

    r5034e1 r99593f  
    66
    77#include "helpers.hpp"
     8
     9#include "memoryusageobserver.hpp"
    810
    911/********************************************** helpful functions *********************************/
     
    4749  while (*b < lower_bound)
    4850    *b += step;
    49 };
    50 
    51 /** Flips two doubles.
    52  * \param *x pointer to first double
    53  * \param *y pointer to second double
    54  */
    55 void flip(double *x, double *y)
    56 {
    57   double tmp;
    58   tmp = *x;
    59   *x = *y;
    60   *y = tmp;
    6151};
    6252
     
    143133 * \return allocated NDIM*NDIM array with the symmetric matrix
    144134 */
    145 double * ReturnFullMatrixforSymmetric(double *symm)
     135double * ReturnFullMatrixforSymmetric(const double * const symm)
    146136{
    147137  double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix");
     
    158148};
    159149
     150/** Calculate the inverse of a 3x3 matrix.
     151 * \param *matrix NDIM_NDIM array
     152 */
     153double * 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 */
     181double 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 */
     190double 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 */
     202double RDET2(const double a0, const double a1, const double a2, const double a3)
     203{
     204  return ((a0)*(a3)-(a1)*(a2));
     205};
     206
    160207/** Comparison function for GSL heapsort on distances in two molecules.
    161208 * \param *a
     
    202249 * Frees all memory registered by the memory observer and calls exit(225) afterwards.
    203250 */
    204 static void performCriticalExit() {
     251void performCriticalExit() {
    205252  map<void*, size_t> pointers = MemoryUsageObserver::getInstance()->getPointersToAllocatedMemory();
    206253  for (map<void*, size_t>::iterator runner = pointers.begin(); runner != pointers.end(); runner++) {
Note: See TracChangeset for help on using the changeset viewer.