Changeset 753f02 for src


Ignore:
Timestamp:
Apr 28, 2010, 2:52:56 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
8cbb97
Parents:
1bd79e
Message:

Removed Algebraic Hierachy from vector.

Location:
src
Files:
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • src/Helpers/fast_functions.hpp

    r1bd79e r753f02  
    88#ifndef FAST_FUNCTIONS_HPP_
    99#define FAST_FUNCTIONS_HPP_
     10
     11#include "defs.hpp"
    1012
    1113/**
  • src/Makefile.am

    r1bd79e r753f02  
    99                           gslvector.cpp \
    1010                           linearsystemofequations.cpp \
    11                            SingleVector.cpp \
    1211                           vector.cpp
    1312                           
     
    1514                           gslvector.hpp \
    1615                           linearsystemofequations.hpp \
    17                            SingleVector.hpp \
    1816                           vector.hpp
    1917                           
  • src/vector.cpp

    r1bd79e r753f02  
    66
    77
    8 #include "SingleVector.hpp"
     8#include "vector.hpp"
    99#include "Helpers/Assert.hpp"
     10#include "Helpers/fast_functions.hpp"
    1011
    1112#include <iostream>
     
    1819/** Constructor of class vector.
    1920 */
    20 Vector::Vector() :
    21   rep(new SingleVector())
    22 {};
    23 
    24 Vector::Vector(Baseconstructor)  // used by derived objects to construct their bases
    25 {}
    26 
    27 Vector::Vector(Baseconstructor,const Vector* v) :
    28   rep(v->clone())
    29 {}
    30 
    31 Vector Vector::VecFromRep(const Vector* v){
    32   return Vector(Baseconstructor(),v);
    33 }
    34 
    35 /** Constructor of class vector.
    36  */
    37 Vector::Vector(const double x1, const double x2, const double x3) :
    38   rep(new SingleVector(x1,x2,x3))
    39 {};
     21Vector::Vector()
     22{
     23  x[0] = x[1] = x[2] = 0.;
     24};
    4025
    4126/**
    4227 * Copy constructor
    4328 */
    44 Vector::Vector(const Vector& src) :
    45   rep(src.rep->clone())
    46 {}
     29
     30Vector::Vector(const Vector& src)
     31{
     32  x[0] = src[0];
     33  x[1] = src[1];
     34  x[2] = src[2];
     35}
     36
     37/** Constructor of class vector.
     38 */
     39Vector::Vector(const double x1, const double x2, const double x3)
     40{
     41  x[0] = x1;
     42  x[1] = x2;
     43  x[2] = x3;
     44};
    4745
    4846/**
     
    5048 */
    5149Vector& Vector::operator=(const Vector& src){
    52   ASSERT(isBaseClass(),"Operator used on Derived Vector object");
    5350  // check for self assignment
    5451  if(&src!=this){
    55     rep.reset(src.rep->clone());
     52    x[0] = src[0];
     53    x[1] = src[1];
     54    x[2] = src[2];
    5655  }
    5756  return *this;
     
    6867double Vector::DistanceSquared(const Vector &y) const
    6968{
    70   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    71   return rep->DistanceSquared(y);
     69  double res = 0.;
     70  for (int i=NDIM;i--;)
     71    res += (x[i]-y[i])*(x[i]-y[i]);
     72  return (res);
    7273};
    7374
     
    8889double Vector::PeriodicDistance(const Vector &y, const double * const cell_size) const
    8990{
    90   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    91   return rep->PeriodicDistance(y,cell_size);
     91  double res = Distance(y), tmp, matrix[NDIM*NDIM];
     92    Vector Shiftedy, TranslationVector;
     93    int N[NDIM];
     94    matrix[0] = cell_size[0];
     95    matrix[1] = cell_size[1];
     96    matrix[2] = cell_size[3];
     97    matrix[3] = cell_size[1];
     98    matrix[4] = cell_size[2];
     99    matrix[5] = cell_size[4];
     100    matrix[6] = cell_size[3];
     101    matrix[7] = cell_size[4];
     102    matrix[8] = cell_size[5];
     103    // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells
     104    for (N[0]=-1;N[0]<=1;N[0]++)
     105      for (N[1]=-1;N[1]<=1;N[1]++)
     106        for (N[2]=-1;N[2]<=1;N[2]++) {
     107          // create the translation vector
     108          TranslationVector.Zero();
     109          for (int i=NDIM;i--;)
     110            TranslationVector[i] = (double)N[i];
     111          TranslationVector.MatrixMultiplication(matrix);
     112          // add onto the original vector to compare with
     113          Shiftedy = y + TranslationVector;
     114          // get distance and compare with minimum so far
     115          tmp = Distance(Shiftedy);
     116          if (tmp < res) res = tmp;
     117        }
     118    return (res);
    92119};
    93120
     
    99126double Vector::PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const
    100127{
    101   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    102   return rep->PeriodicDistanceSquared(y,cell_size);
     128  double res = DistanceSquared(y), tmp, matrix[NDIM*NDIM];
     129    Vector Shiftedy, TranslationVector;
     130    int N[NDIM];
     131    matrix[0] = cell_size[0];
     132    matrix[1] = cell_size[1];
     133    matrix[2] = cell_size[3];
     134    matrix[3] = cell_size[1];
     135    matrix[4] = cell_size[2];
     136    matrix[5] = cell_size[4];
     137    matrix[6] = cell_size[3];
     138    matrix[7] = cell_size[4];
     139    matrix[8] = cell_size[5];
     140    // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells
     141    for (N[0]=-1;N[0]<=1;N[0]++)
     142      for (N[1]=-1;N[1]<=1;N[1]++)
     143        for (N[2]=-1;N[2]<=1;N[2]++) {
     144          // create the translation vector
     145          TranslationVector.Zero();
     146          for (int i=NDIM;i--;)
     147            TranslationVector[i] = (double)N[i];
     148          TranslationVector.MatrixMultiplication(matrix);
     149          // add onto the original vector to compare with
     150          Shiftedy = y + TranslationVector;
     151          // get distance and compare with minimum so far
     152          tmp = DistanceSquared(Shiftedy);
     153          if (tmp < res) res = tmp;
     154        }
     155    return (res);
    103156};
    104157
     
    109162void Vector::KeepPeriodic(const double * const matrix)
    110163{
    111   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    112   rep->KeepPeriodic(matrix);
     164  //  int N[NDIM];
     165  //  bool flag = false;
     166    //vector Shifted, TranslationVector;
     167  //  Log() << Verbose(1) << "Begin of KeepPeriodic." << endl;
     168  //  Log() << Verbose(2) << "Vector is: ";
     169  //  Output(out);
     170  //  Log() << Verbose(0) << endl;
     171    InverseMatrixMultiplication(matrix);
     172    for(int i=NDIM;i--;) { // correct periodically
     173      if (at(i) < 0) {  // get every coefficient into the interval [0,1)
     174        at(i) += ceil(at(i));
     175      } else {
     176        at(i) -= floor(at(i));
     177      }
     178    }
     179    MatrixMultiplication(matrix);
     180  //  Log() << Verbose(2) << "New corrected vector is: ";
     181  //  Output(out);
     182  //  Log() << Verbose(0) << endl;
     183  //  Log() << Verbose(1) << "End of KeepPeriodic." << endl;
    113184};
    114185
     
    119190double Vector::ScalarProduct(const Vector &y) const
    120191{
    121   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    122   return rep->ScalarProduct(y);
     192  double res = 0.;
     193  for (int i=NDIM;i--;)
     194    res += x[i]*y[i];
     195  return (res);
    123196};
    124197
     
    132205void Vector::VectorProduct(const Vector &y)
    133206{
    134   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    135   rep->VectorProduct(y);
     207  Vector tmp;
     208  tmp[0] = x[1]* (y[2]) - x[2]* (y[1]);
     209  tmp[1] = x[2]* (y[0]) - x[0]* (y[2]);
     210  tmp[2] = x[0]* (y[1]) - x[1]* (y[0]);
     211  (*this) = tmp;
    136212};
    137213
     
    143219void Vector::ProjectOntoPlane(const Vector &y)
    144220{
    145   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    146   rep->ProjectOntoPlane(y);
     221  Vector tmp;
     222  tmp = y;
     223  tmp.Normalize();
     224  tmp.Scale(ScalarProduct(tmp));
     225  *this -= tmp;
    147226};
    148227
     
    155234double Vector::DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const
    156235{
    157   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    158   return rep->DistanceToPlane(PlaneNormal,PlaneOffset);
     236  // first create part that is orthonormal to PlaneNormal with withdraw
     237  Vector temp = (*this) - PlaneOffset;
     238  temp.MakeNormalTo(PlaneNormal);
     239  temp.Scale(-1.);
     240  // then add connecting vector from plane to point
     241  temp += (*this)-PlaneOffset;
     242  double sign = temp.ScalarProduct(PlaneNormal);
     243  if (fabs(sign) > MYEPSILON)
     244    sign /= fabs(sign);
     245  else
     246    sign = 0.;
     247
     248  return (temp.Norm()*sign);
    159249};
    160250
     
    164254void Vector::ProjectIt(const Vector &y)
    165255{
    166   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    167   rep->ProjectIt(y);
     256  (*this) += (-ScalarProduct(y))*y;
    168257};
    169258
     
    174263Vector Vector::Projection(const Vector &y) const
    175264{
    176   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    177   return rep->Projection(y);
     265  Vector helper = y;
     266  helper.Scale((ScalarProduct(y)/y.NormSquared()));
     267
     268  return helper;
    178269};
    179270
     
    206297void Vector::Zero()
    207298{
    208   rep.reset(new SingleVector());
     299  at(0)=at(1)=at(2)=0;
    209300};
    210301
     
    213304void Vector::One(const double one)
    214305{
    215   rep.reset(new SingleVector(one,one,one));
     306  at(0)=at(1)=at(2)=one;
    216307};
    217308
     
    221312bool Vector::IsZero() const
    222313{
    223   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    224   return rep->IsZero();
     314  return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON);
    225315};
    226316
     
    230320bool Vector::IsOne() const
    231321{
    232   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    233   return rep->IsOne();
     322  return (fabs(Norm() - 1.) < MYEPSILON);
    234323};
    235324
     
    239328bool Vector::IsNormalTo(const Vector &normal) const
    240329{
    241   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    242   return rep->IsNormalTo(normal);
     330  if (ScalarProduct(normal) < MYEPSILON)
     331    return true;
     332  else
     333    return false;
    243334};
    244335
     
    248339bool Vector::IsEqualTo(const Vector &a) const
    249340{
    250   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    251   return rep->IsEqualTo(a);
     341  bool status = true;
     342  for (int i=0;i<NDIM;i++) {
     343    if (fabs(x[i] - a[i]) > MYEPSILON)
     344      status = false;
     345  }
     346  return status;
    252347};
    253348
     
    258353double Vector::Angle(const Vector &y) const
    259354{
    260   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    261   return rep->Angle(y);
     355  double norm1 = Norm(), norm2 = y.Norm();
     356  double angle = -1;
     357  if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON))
     358    angle = this->ScalarProduct(y)/norm1/norm2;
     359  // -1-MYEPSILON occured due to numerical imprecision, catch ...
     360  //Log() << Verbose(2) << "INFO: acos(-1) = " << acos(-1) << ", acos(-1+MYEPSILON) = " << acos(-1+MYEPSILON) << ", acos(-1-MYEPSILON) = " << acos(-1-MYEPSILON) << "." << endl;
     361  if (angle < -1)
     362    angle = -1;
     363  if (angle > 1)
     364    angle = 1;
     365  return acos(angle);
    262366};
    263367
    264368
    265369double& Vector::operator[](size_t i){
    266   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    267   return (*rep)[i];
     370  ASSERT(i<=NDIM && i>=0,"Vector Index out of Range");
     371  return x[i];
    268372}
    269373
    270374const double& Vector::operator[](size_t i) const{
    271   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    272   return (*rep)[i];
     375  ASSERT(i<=NDIM && i>=0,"Vector Index out of Range");
     376  return x[i];
    273377}
    274378
     
    282386
    283387double* Vector::get(){
    284   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    285   return rep->get();
     388  return x;
    286389}
    287390
     
    293396bool Vector::operator==(const Vector& b) const
    294397{
    295   ASSERT(isBaseClass(),"Operator used on Derived Vector object");
    296398  return IsEqualTo(b);
    297399};
     
    337439Vector const Vector::operator+(const Vector& b) const
    338440{
    339   ASSERT(isBaseClass(),"Operator used on Derived Vector object");
    340441  Vector x = *this;
    341442  x.AddVector(b);
     
    350451Vector const Vector::operator-(const Vector& b) const
    351452{
    352   ASSERT(isBaseClass(),"Operator used on Derived Vector object");
    353453  Vector x = *this;
    354454  x.SubtractVector(b);
     
    395495void Vector::ScaleAll(const double *factor)
    396496{
    397   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    398   rep->ScaleAll(factor);
     497  for (int i=NDIM;i--;)
     498    x[i] *= factor[i];
    399499};
    400500
     
    403503void Vector::Scale(const double factor)
    404504{
    405   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    406   rep->Scale(factor);
     505  for (int i=NDIM;i--;)
     506    x[i] *= factor;
    407507};
    408508
     
    413513void Vector::WrapPeriodically(const double * const M, const double * const Minv)
    414514{
    415   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    416   rep->WrapPeriodically(M,Minv);
     515  MatrixMultiplication(Minv);
     516  // truncate to [0,1] for each axis
     517  for (int i=0;i<NDIM;i++) {
     518    x[i] += 0.5;  // set to center of box
     519    while (x[i] >= 1.)
     520      x[i] -= 1.;
     521    while (x[i] < 0.)
     522      x[i] += 1.;
     523  }
     524  MatrixMultiplication(M);
    417525};
    418526
     
    422530void Vector::MatrixMultiplication(const double * const M)
    423531{
    424   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    425   rep->MatrixMultiplication(M);
     532  // do the matrix multiplication
     533  at(0) = M[0]*x[0]+M[3]*x[1]+M[6]*x[2];
     534  at(1) = M[1]*x[0]+M[4]*x[1]+M[7]*x[2];
     535  at(2) = M[2]*x[0]+M[5]*x[1]+M[8]*x[2];
    426536};
    427537
     
    431541bool Vector::InverseMatrixMultiplication(const double * const A)
    432542{
    433   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    434   return rep->InverseMatrixMultiplication(A);
     543  double B[NDIM*NDIM];
     544  double detA = RDET3(A);
     545  double detAReci;
     546
     547  // calculate the inverse B
     548  if (fabs(detA) > MYEPSILON) {;  // RDET3(A) yields precisely zero if A irregular
     549    detAReci = 1./detA;
     550    B[0] =  detAReci*RDET2(A[4],A[5],A[7],A[8]);    // A_11
     551    B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]);    // A_12
     552    B[2] =  detAReci*RDET2(A[1],A[2],A[4],A[5]);    // A_13
     553    B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]);    // A_21
     554    B[4] =  detAReci*RDET2(A[0],A[2],A[6],A[8]);    // A_22
     555    B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]);    // A_23
     556    B[6] =  detAReci*RDET2(A[3],A[4],A[6],A[7]);    // A_31
     557    B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]);    // A_32
     558    B[8] =  detAReci*RDET2(A[0],A[1],A[3],A[4]);    // A_33
     559
     560    // do the matrix multiplication
     561    at(0) = B[0]*x[0]+B[3]*x[1]+B[6]*x[2];
     562    at(1) = B[1]*x[0]+B[4]*x[1]+B[7]*x[2];
     563    at(2) = B[2]*x[0]+B[5]*x[1]+B[8]*x[2];
     564
     565    return true;
     566  } else {
     567    return false;
     568  }
    435569};
    436570
     
    455589void Vector::Mirror(const Vector &n)
    456590{
    457   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    458   rep->Mirror(n);
     591  double projection;
     592  projection = ScalarProduct(n)/n.NormSquared();    // remove constancy from n (keep as logical one)
     593  // withdraw projected vector twice from original one
     594  for (int i=NDIM;i--;)
     595    x[i] -= 2.*projection*n[i];
    459596};
    460597
     
    468605bool Vector::MakeNormalTo(const Vector &y1)
    469606{
    470   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    471   return rep->MakeNormalTo(y1);
     607  bool result = false;
     608  double factor = y1.ScalarProduct(*this)/y1.NormSquared();
     609  Vector x1;
     610  x1 = factor * y1;
     611  SubtractVector(x1);
     612  for (int i=NDIM;i--;)
     613    result = result || (fabs(x[i]) > MYEPSILON);
     614
     615  return result;
    472616};
    473617
     
    480624bool Vector::GetOneNormalVector(const Vector &GivenVector)
    481625{
    482   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    483   return rep->GetOneNormalVector(GivenVector);
     626  int Components[NDIM]; // contains indices of non-zero components
     627  int Last = 0;   // count the number of non-zero entries in vector
     628  int j;  // loop variables
     629  double norm;
     630
     631  for (j=NDIM;j--;)
     632    Components[j] = -1;
     633  // find two components != 0
     634  for (j=0;j<NDIM;j++)
     635    if (fabs(GivenVector[j]) > MYEPSILON)
     636      Components[Last++] = j;
     637
     638  switch(Last) {
     639    case 3:  // threecomponent system
     640    case 2:  // two component system
     641      norm = sqrt(1./(GivenVector[Components[1]]*GivenVector[Components[1]]) + 1./(GivenVector[Components[0]]*GivenVector[Components[0]]));
     642      x[Components[2]] = 0.;
     643      // in skp both remaining parts shall become zero but with opposite sign and third is zero
     644      x[Components[1]] = -1./GivenVector[Components[1]] / norm;
     645      x[Components[0]] = 1./GivenVector[Components[0]] / norm;
     646      return true;
     647      break;
     648    case 1: // one component system
     649      // set sole non-zero component to 0, and one of the other zero component pendants to 1
     650      x[(Components[0]+2)%NDIM] = 0.;
     651      x[(Components[0]+1)%NDIM] = 1.;
     652      x[Components[0]] = 0.;
     653      return true;
     654      break;
     655    default:
     656      return false;
     657  }
    484658};
    485659
     
    489663void Vector::AddVector(const Vector &y)
    490664{
    491   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    492   rep->AddVector(y);
     665  for(int i=NDIM;i--;)
     666    x[i] += y[i];
    493667}
    494668
     
    498672void Vector::SubtractVector(const Vector &y)
    499673{
    500   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    501   rep->SubtractVector(y);
     674  for(int i=NDIM;i--;)
     675    x[i] -= y[i];
    502676}
    503677
     
    511685bool Vector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const
    512686{
    513   ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");
    514   return rep->IsInParallelepiped(offset, parallelepiped);
    515 }
    516 
    517 bool Vector::isBaseClass() const{
    518   return true;
    519 }
    520 
    521 Vector* Vector::clone() const{
    522   ASSERT(false, "Cannot clone a base Vector object");
    523   return 0;
    524 }
     687  Vector a = (*this)-offset;
     688  a.InverseMatrixMultiplication(parallelepiped);
     689  bool isInside = true;
     690
     691  for (int i=NDIM;i--;)
     692    isInside = isInside && ((a[i] <= 1) && (a[i] >= 0));
     693
     694  return isInside;
     695}
  • src/vector.hpp

    r1bd79e r753f02  
    3737  // Method implemented by forwarding to the Representation
    3838
    39   virtual double DistanceSquared(const Vector &y) const;
    40   virtual double DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const;
    41   virtual double PeriodicDistance(const Vector &y, const double * const cell_size) const;
    42   virtual double PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const;
    43   virtual double ScalarProduct(const Vector &y) const;
    44   virtual double Angle(const Vector &y) const;
    45   virtual bool IsZero() const;
    46   virtual bool IsOne() const;
    47   virtual bool IsNormalTo(const Vector &normal) const;
    48   virtual bool IsEqualTo(const Vector &a) const;
     39  double DistanceSquared(const Vector &y) const;
     40  double DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const;
     41  double PeriodicDistance(const Vector &y, const double * const cell_size) const;
     42  double PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const;
     43  double ScalarProduct(const Vector &y) const;
     44  double Angle(const Vector &y) const;
     45  bool IsZero() const;
     46  bool IsOne() const;
     47  bool IsNormalTo(const Vector &normal) const;
     48  bool IsEqualTo(const Vector &a) const;
    4949
    50   virtual void AddVector(const Vector &y);
    51   virtual void SubtractVector(const Vector &y);
    52   virtual void VectorProduct(const Vector &y);
    53   virtual void ProjectOntoPlane(const Vector &y);
    54   virtual void ProjectIt(const Vector &y);
    55   virtual Vector Projection(const Vector &y) const;
    56   virtual void Mirror(const Vector &x);
    57   virtual void ScaleAll(const double *factor);
    58   virtual void Scale(const double factor);
    59   virtual void MatrixMultiplication(const double * const M);
    60   virtual bool InverseMatrixMultiplication(const double * const M);
    61   virtual void KeepPeriodic(const double * const matrix);
    62   virtual bool GetOneNormalVector(const Vector &x1);
    63   virtual bool MakeNormalTo(const Vector &y1);
    64   virtual bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const;
    65   virtual void WrapPeriodically(const double * const M, const double * const Minv);
     50  void AddVector(const Vector &y);
     51  void SubtractVector(const Vector &y);
     52  void VectorProduct(const Vector &y);
     53  void ProjectOntoPlane(const Vector &y);
     54  void ProjectIt(const Vector &y);
     55  Vector Projection(const Vector &y) const;
     56  void Mirror(const Vector &x);
     57  void ScaleAll(const double *factor);
     58  void Scale(const double factor);
     59  void MatrixMultiplication(const double * const M);
     60  bool InverseMatrixMultiplication(const double * const M);
     61  void KeepPeriodic(const double * const matrix);
     62  bool GetOneNormalVector(const Vector &x1);
     63  bool MakeNormalTo(const Vector &y1);
     64  bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const;
     65  void WrapPeriodically(const double * const M, const double * const Minv);
    6666
    6767  // Accessors ussually come in pairs... and sometimes even more than that
    68   virtual double& operator[](size_t i);
    69   virtual const double& operator[](size_t i) const;
     68  double& operator[](size_t i);
     69  const double& operator[](size_t i) const;
    7070  double& at(size_t i);
    7171  const double& at(size_t i) const;
    7272
    7373  // Assignment operator
    74   virtual Vector &operator=(const Vector& src);
     74  Vector &operator=(const Vector& src);
    7575
    7676  // Access to internal structure
    77   virtual double* get();
     77  double* get();
    7878
    7979  // Methods that are derived directly from other methods
     
    9494
    9595protected:
    96   typedef std::auto_ptr<Vector> rep_ptr;
    97   Vector(Baseconstructor);
    98   Vector(Baseconstructor,const Vector*);
    99   static Vector VecFromRep(const Vector*);
    10096
    10197private:
    102   // method used for protection, i.e. to avoid infinite recursion
    103   // when our internal rep becomes messed up
    104   virtual bool isBaseClass() const;
    105   virtual Vector* clone() const;
    106   // this is used to represent the vector internally
    107   rep_ptr rep;
     98  double x[NDIM];
    10899
    109100};
Note: See TracChangeset for help on using the changeset viewer.