Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_geometry.cpp

    r68f03d ra67d19  
    2727  bool status = true;
    2828  const Vector *Center = DetermineCenterOfAll();
    29   double * const cell_size = World::getInstance().getDomain();
     29  double * const cell_size = World::get()->cell_size;
    3030  double *M = ReturnFullMatrixforSymmetric(cell_size);
    3131  double *Minv = InverseMatrix(M);
    3232
    3333  // go through all atoms
    34   ActOnAllVectors( &Vector::SubtractVector, *Center);
     34  ActOnAllVectors( &Vector::SubtractVector, Center);
    3535  ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    3636
     
    4848{
    4949  bool status = true;
    50   double * const cell_size = World::getInstance().getDomain();
     50  double * const cell_size = World::get()->cell_size;
    5151  double *M = ReturnFullMatrixforSymmetric(cell_size);
    5252  double *Minv = InverseMatrix(M);
     
    7272  if (ptr != end) {   //list not empty?
    7373    for (int i=NDIM;i--;) {
    74       max->at(i) = ptr->x[i];
    75       min->at(i) = ptr->x[i];
     74      max->x[i] = ptr->x.x[i];
     75      min->x[i] = ptr->x.x[i];
    7676    }
    7777    while (ptr->next != end) {  // continue with second if present
     
    7979      //ptr->Output(1,1,out);
    8080      for (int i=NDIM;i--;) {
    81         max->at(i) = (max->at(i) < ptr->x[i]) ? ptr->x[i] : max->at(i);
    82         min->at(i) = (min->at(i) > ptr->x[i]) ? ptr->x[i] : min->at(i);
     81        max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i];
     82        min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i];
    8383      }
    8484    }
     
    8989//    Log() << Verbose(0) << endl;
    9090    min->Scale(-1.);
    91     (*max) += (*min);
     91    max->AddVector(min);
    9292    Translate(min);
    9393    Center.Zero();
     
    112112      ptr = ptr->next;
    113113      Num++;
    114       Center += ptr->x;
     114      Center.AddVector(&ptr->x);
    115115    }
    116116    Center.Scale(-1./Num); // divide through total number (and sign for direction)
     
    136136      ptr = ptr->next;
    137137      Num += 1.;
    138       tmp = ptr->x;
    139       (*a) += tmp;
     138      tmp.CopyVector(&ptr->x);
     139      a->AddVector(&tmp);
    140140    }
    141141    a->Scale(1./Num); // divide through total mass (and sign for direction)
     
    161161      ptr = ptr->next;
    162162      Num += ptr->type->mass;
    163       tmp = ptr->type->mass * ptr->x;
    164       (*a) += tmp;
     163      tmp.CopyVector(&ptr->x);
     164      tmp.Scale(ptr->type->mass);  // scale by mass
     165      a->AddVector(&tmp);
    165166    }
    166167    a->Scale(-1./Num); // divide through total mass (and sign for direction)
     
    188189void molecule::CenterAtVector(Vector *newcenter)
    189190{
    190   Center = *newcenter;
     191  Center.CopyVector(newcenter);
    191192};
    192193
     
    194195/** Scales all atoms by \a *factor.
    195196 * \param *factor pointer to scaling factor
    196  *
    197  * TODO: Is this realy what is meant, i.e.
    198  * x=(x[0]*factor[0],x[1]*factor[1],x[2]*factor[2]) (current impl)
    199  * or rather
    200  * x=(**factor) * x (as suggested by comment)
    201197 */
    202198void molecule::Scale(const double ** const factor)
     
    207203    ptr = ptr->next;
    208204    for (int j=0;j<MDSteps;j++)
    209       ptr->Trajectory.R.at(j).ScaleAll(*factor);
    210     ptr->x.ScaleAll(*factor);
     205      ptr->Trajectory.R.at(j).Scale(factor);
     206    ptr->x.Scale(factor);
    211207  }
    212208};
     
    222218    ptr = ptr->next;
    223219    for (int j=0;j<MDSteps;j++)
    224       ptr->Trajectory.R.at(j) += (*trans);
    225     ptr->x += (*trans);
     220      ptr->Trajectory.R.at(j).Translate(trans);
     221    ptr->x.Translate(trans);
    226222  }
    227223};
     
    233229void molecule::TranslatePeriodically(const Vector *trans)
    234230{
    235   double * const cell_size = World::getInstance().getDomain();
     231  double * const cell_size = World::get()->cell_size;
    236232  double *M = ReturnFullMatrixforSymmetric(cell_size);
    237233  double *Minv = InverseMatrix(M);
    238234
    239235  // go through all atoms
    240   ActOnAllVectors( &Vector::SubtractVector, *trans);
     236  ActOnAllVectors( &Vector::SubtractVector, trans);
    241237  ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    242238
     
    251247void molecule::Mirror(const Vector *n)
    252248{
    253   ActOnAllVectors( &Vector::Mirror, *n );
     249  ActOnAllVectors( &Vector::Mirror, n );
    254250};
    255251
     
    260256{
    261257  atom *Walker = start;
    262   double * const cell_size = World::getInstance().getDomain();
     258  double * const cell_size = World::get()->cell_size;
    263259  double *matrix = ReturnFullMatrixforSymmetric(cell_size);
    264260  double *inversematrix = InverseMatrix(cell_size);
     
    275271      if (Walker->type->Z != 1) {
    276272#endif
    277         Testvector = Walker->x;
     273        Testvector.CopyVector(&Walker->x);
    278274        Testvector.MatrixMultiplication(inversematrix);
    279275        Translationvector.Zero();
     
    281277         if (Walker->nr < (*Runner)->GetOtherAtom(Walker)->nr) // otherwise we shift one to, the other fro and gain nothing
    282278            for (int j=0;j<NDIM;j++) {
    283               tmp = Walker->x[j] - (*Runner)->GetOtherAtom(Walker)->x[j];
     279              tmp = Walker->x.x[j] - (*Runner)->GetOtherAtom(Walker)->x.x[j];
    284280              if ((fabs(tmp)) > BondDistance) {
    285281                flag = false;
    286                 DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << Walker->getName() << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl);
     282                DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << Walker->Name << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl);
    287283                if (tmp > 0)
    288                   Translationvector[j] -= 1.;
     284                  Translationvector.x[j] -= 1.;
    289285                else
    290                   Translationvector[j] += 1.;
     286                  Translationvector.x[j] += 1.;
    291287              }
    292288            }
    293289        }
    294         Testvector += Translationvector;
     290        Testvector.AddVector(&Translationvector);
    295291        Testvector.MatrixMultiplication(matrix);
    296         Center += Testvector;
    297         Log() << Verbose(1) << "vector is: " << Testvector << endl;
     292        Center.AddVector(&Testvector);
     293        DoLog(1) && (Log() << Verbose(1) << "vector is: ");
     294        Testvector.Output();
     295        DoLog(0) && (Log() << Verbose(0) << endl);
    298296#ifdef ADDHYDROGEN
    299297        // now also change all hydrogens
    300298        for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    301299          if ((*Runner)->GetOtherAtom(Walker)->type->Z == 1) {
    302             Testvector = (*Runner)->GetOtherAtom(Walker)->x;
     300            Testvector.CopyVector(&(*Runner)->GetOtherAtom(Walker)->x);
    303301            Testvector.MatrixMultiplication(inversematrix);
    304             Testvector += Translationvector;
     302            Testvector.AddVector(&Translationvector);
    305303            Testvector.MatrixMultiplication(matrix);
    306             Center += Testvector;
    307             Log() << Verbose(1) << "Hydrogen vector is: " << Testvector << endl;
     304            Center.AddVector(&Testvector);
     305            DoLog(1) && (Log() << Verbose(1) << "Hydrogen vector is: ");
     306            Testvector.Output();
     307            DoLog(0) && (Log() << Verbose(0) << endl);
    308308          }
    309309        }
     
    338338  while (ptr->next != end) {
    339339    ptr = ptr->next;
    340     Vector x = ptr->x;
     340    Vector x;
     341    x.CopyVector(&ptr->x);
    341342    //x.SubtractVector(CenterOfGravity);
    342     InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]);
    343     InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]);
    344     InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]);
    345     InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]);
    346     InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]);
    347     InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]);
    348     InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]);
    349     InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]);
    350     InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]);
     343    InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]);
     344    InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]);
     345    InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]);
     346    InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]);
     347    InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]);
     348    InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]);
     349    InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]);
     350    InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]);
     351    InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]);
    351352  }
    352353  // print InertiaTensor for debugging
     
    389390    while (ptr->next != end) {
    390391      ptr = ptr->next;
    391       Vector x = ptr->x;
     392      Vector x;
     393      x.CopyVector(&ptr->x);
    392394      //x.SubtractVector(CenterOfGravity);
    393       InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]);
    394       InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]);
    395       InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]);
    396       InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]);
    397       InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]);
    398       InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]);
    399       InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]);
    400       InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]);
    401       InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]);
     395      InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]);
     396      InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]);
     397      InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]);
     398      InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]);
     399      InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]);
     400      InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]);
     401      InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]);
     402      InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]);
     403      InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]);
    402404    }
    403405    // print InertiaTensor for debugging
     
    426428  double alpha, tmp;
    427429  Vector z_axis;
    428   z_axis[0] = 0.;
    429   z_axis[1] = 0.;
    430   z_axis[2] = 1.;
     430  z_axis.x[0] = 0.;
     431  z_axis.x[1] = 0.;
     432  z_axis.x[2] = 1.;
    431433
    432434  // rotate on z-x plane
    433435  DoLog(0) && (Log() << Verbose(0) << "Begin of Aligning all atoms." << endl);
    434   alpha = atan(-n->at(0)/n->at(2));
     436  alpha = atan(-n->x[0]/n->x[2]);
    435437  DoLog(1) && (Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... ");
    436438  while (ptr->next != end) {
    437439    ptr = ptr->next;
    438     tmp = ptr->x[0];
    439     ptr->x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->x[2];
    440     ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2];
     440    tmp = ptr->x.x[0];
     441    ptr->x.x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];
     442    ptr->x.x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];
    441443    for (int j=0;j<MDSteps;j++) {
    442       tmp = ptr->Trajectory.R.at(j)[0];
    443       ptr->Trajectory.R.at(j)[0] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];
    444       ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2];
     444      tmp = ptr->Trajectory.R.at(j).x[0];
     445      ptr->Trajectory.R.at(j).x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2];
     446      ptr->Trajectory.R.at(j).x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2];
    445447    }
    446448  }
    447449  // rotate n vector
    448   tmp = n->at(0);
    449   n->at(0) =  cos(alpha) * tmp +  sin(alpha) * n->at(2);
    450   n->at(2) = -sin(alpha) * tmp +  cos(alpha) * n->at(2);
    451   DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: " << n << endl);
     450  tmp = n->x[0];
     451  n->x[0] =  cos(alpha) * tmp +  sin(alpha) * n->x[2];
     452  n->x[2] = -sin(alpha) * tmp +  cos(alpha) * n->x[2];
     453  DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: ");
     454  n->Output();
     455  DoLog(0) && (Log() << Verbose(0) << endl);
    452456
    453457  // rotate on z-y plane
    454458  ptr = start;
    455   alpha = atan(-n->at(1)/n->at(2));
     459  alpha = atan(-n->x[1]/n->x[2]);
    456460  DoLog(1) && (Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... ");
    457461  while (ptr->next != end) {
    458462    ptr = ptr->next;
    459     tmp = ptr->x[1];
    460     ptr->x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->x[2];
    461     ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2];
     463    tmp = ptr->x.x[1];
     464    ptr->x.x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];
     465    ptr->x.x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];
    462466    for (int j=0;j<MDSteps;j++) {
    463       tmp = ptr->Trajectory.R.at(j)[1];
    464       ptr->Trajectory.R.at(j)[1] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];
    465       ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2];
     467      tmp = ptr->Trajectory.R.at(j).x[1];
     468      ptr->Trajectory.R.at(j).x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2];
     469      ptr->Trajectory.R.at(j).x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2];
    466470    }
    467471  }
    468472  // rotate n vector (for consistency check)
    469   tmp = n->at(1);
    470   n->at(1) =  cos(alpha) * tmp +  sin(alpha) * n->at(2);
    471   n->at(2) = -sin(alpha) * tmp +  cos(alpha) * n->at(2);
    472 
    473 
    474   DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: " << n << endl);
     473  tmp = n->x[1];
     474  n->x[1] =  cos(alpha) * tmp +  sin(alpha) * n->x[2];
     475  n->x[2] = -sin(alpha) * tmp +  cos(alpha) * n->x[2];
     476
     477  DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: ");
     478  n->Output();
     479  DoLog(1) && (Log() << Verbose(1) << endl);
    475480  DoLog(0) && (Log() << Verbose(0) << "End of Aligning all atoms." << endl);
    476481};
     
    490495
    491496  // initialize vectors
    492   a[0] = gsl_vector_get(x,0);
    493   a[1] = gsl_vector_get(x,1);
    494   a[2] = gsl_vector_get(x,2);
    495   b[0] = gsl_vector_get(x,3);
    496   b[1] = gsl_vector_get(x,4);
    497   b[2] = gsl_vector_get(x,5);
     497  a.x[0] = gsl_vector_get(x,0);
     498  a.x[1] = gsl_vector_get(x,1);
     499  a.x[2] = gsl_vector_get(x,2);
     500  b.x[0] = gsl_vector_get(x,3);
     501  b.x[1] = gsl_vector_get(x,4);
     502  b.x[2] = gsl_vector_get(x,5);
    498503  // go through all atoms
    499504  while (ptr != par->mol->end) {
    500505    ptr = ptr->next;
    501506    if (ptr->type == ((struct lsq_params *)params)->type) { // for specific type
    502       c = ptr->x - a;
    503       t = c.ScalarProduct(b);           // get direction parameter
    504       d = t*b;       // and create vector
    505       c -= d;   // ... yielding distance vector
    506       res += d.ScalarProduct(d);        // add squared distance
     507      c.CopyVector(&ptr->x);  // copy vector to temporary one
     508      c.SubtractVector(&a);   // subtract offset vector
     509      t = c.ScalarProduct(&b);           // get direction parameter
     510      d.CopyVector(&b);       // and create vector
     511      d.Scale(&t);
     512      c.SubtractVector(&d);   // ... yielding distance vector
     513      res += d.ScalarProduct((const Vector *)&d);        // add squared distance
    507514    }
    508515  }
Note: See TracChangeset for help on using the changeset viewer.