Changeset d466f0


Ignore:
Timestamp:
Jun 2, 2010, 10:46:31 AM (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:
d690fa
Parents:
27ac00
Message:

Made the internal parts of Vector use accessor functions instead of direct access

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/vector.cpp

    r27ac00 rd466f0  
    2323Vector::Vector()
    2424{
    25   x[0] = x[1] = x[2] = 0.;
     25  content[0]=content[1]=content[2]=0;
    2626};
    2727
     
    3232Vector::Vector(const Vector& src)
    3333{
    34   x[0] = src[0];
    35   x[1] = src[1];
    36   x[2] = src[2];
     34  content[0]=src[0];
     35  content[1]=src[1];
     36  content[2]=src[2];
    3737}
    3838
     
    4141Vector::Vector(const double x1, const double x2, const double x3)
    4242{
    43   x[0] = x1;
    44   x[1] = x2;
    45   x[2] = x3;
     43  content[0]=x1;
     44  content[1]=x2;
     45  content[2]=x3;
    4646};
    4747
     
    5252  // check for self assignment
    5353  if(&src!=this){
    54     x[0] = src[0];
    55     x[1] = src[1];
    56     x[2] = src[2];
     54    content[0]=src[0];
     55    content[1]=src[1];
     56    content[2]=src[2];
    5757  }
    5858  return *this;
     
    6161/** Desctructor of class vector.
    6262 */
    63 Vector::~Vector() {};
     63Vector::~Vector() {
     64};
    6465
    6566/** Calculates square of distance between this and another vector.
     
    7172  double res = 0.;
    7273  for (int i=NDIM;i--;)
    73     res += (x[i]-y[i])*(x[i]-y[i]);
     74    res += (at(i)-y[i])*(at(i)-y[i]);
    7475  return (res);
    7576};
     
    199200  double res = 0.;
    200201  for (int i=NDIM;i--;)
    201     res += x[i]*y[i];
     202    res += at(i)*y[i];
    202203  return (res);
    203204};
     
    213214{
    214215  Vector tmp;
    215   tmp[0] = x[1]* y[2] - x[2]* y[1];
    216   tmp[1] = x[2]* y[0] - x[0]* y[2];
    217   tmp[2] = x[0]* y[1] - x[1]* y[0];
     216  for(int i=NDIM;i--;)
     217    tmp[i] = at((i+1)%NDIM)*y[(i+2)%NDIM] - at((i+2)%NDIM)*y[(i+1)%NDIM];
    218218  (*this) = tmp;
    219219};
     
    308308bool Vector::IsZero() const
    309309{
    310   return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON);
     310  return (fabs(at(0))+fabs(at(1))+fabs(at(2)) < MYEPSILON);
    311311};
    312312
     
    337337  bool status = true;
    338338  for (int i=0;i<NDIM;i++) {
    339     if (fabs(x[i] - a[i]) > MYEPSILON)
     339    if (fabs(at(i) - a[i]) > MYEPSILON)
    340340      status = false;
    341341  }
     
    365365double& Vector::operator[](size_t i){
    366366  ASSERT(i<=NDIM && i>=0,"Vector Index out of Range");
    367   return x[i];
     367  return content[i];
    368368}
    369369
    370370const double& Vector::operator[](size_t i) const{
    371371  ASSERT(i<=NDIM && i>=0,"Vector Index out of Range");
    372   return x[i];
     372  return content[i];
    373373}
    374374
     
    382382
    383383double* Vector::get(){
    384   return x;
     384  return content;
    385385}
    386386
     
    497497{
    498498  for (int i=NDIM;i--;)
    499     x[i] *= factor[i];
     499    at(i) *= factor[i];
    500500};
    501501
     
    505505{
    506506  for (int i=NDIM;i--;)
    507     x[i] *= factor;
     507    at(i) *= factor;
    508508};
    509509
     
    517517  // truncate to [0,1] for each axis
    518518  for (int i=0;i<NDIM;i++) {
    519     x[i] += 0.5;  // set to center of box
    520     while (x[i] >= 1.)
    521       x[i] -= 1.;
    522     while (x[i] < 0.)
    523       x[i] += 1.;
     519    at(i) += 0.5;  // set to center of box
     520    while (at(i) >= 1.)
     521      at(i) -= 1.;
     522    while (at(i) < 0.)
     523      at(i) += 1.;
    524524  }
    525525  MatrixMultiplication(M);
     
    548548void Vector::MatrixMultiplication(const double * const M)
    549549{
     550  Vector tmp;
    550551  // do the matrix multiplication
    551   at(0) = M[0]*x[0]+M[3]*x[1]+M[6]*x[2];
    552   at(1) = M[1]*x[0]+M[4]*x[1]+M[7]*x[2];
    553   at(2) = M[2]*x[0]+M[5]*x[1]+M[8]*x[2];
     552  for(int i=NDIM;i--;)
     553    tmp[i] = M[i]*at(0)+M[i+3]*at(1)+M[i+6]*at(2);
     554
     555  (*this) = tmp;
    554556};
    555557
     
    576578    B[8] =  detAReci*RDET2(A[0],A[1],A[3],A[4]);    // A_33
    577579
    578     // do the matrix multiplication
    579     at(0) = B[0]*x[0]+B[3]*x[1]+B[6]*x[2];
    580     at(1) = B[1]*x[0]+B[4]*x[1]+B[7]*x[2];
    581     at(2) = B[2]*x[0]+B[5]*x[1]+B[8]*x[2];
     580    MatrixMultiplication(B);
    582581
    583582    return true;
     
    615614  SubtractVector(x1);
    616615  for (int i=NDIM;i--;)
    617     result = result || (fabs(x[i]) > MYEPSILON);
     616    result = result || (fabs(at(i)) > MYEPSILON);
    618617
    619618  return result;
     
    677676{
    678677  for(int i=NDIM;i--;)
    679     x[i] += y[i];
     678    at(i) += y[i];
    680679}
    681680
     
    686685{
    687686  for(int i=NDIM;i--;)
    688     x[i] -= y[i];
     687    at(i) -= y[i];
    689688}
    690689
  • src/vector.hpp

    r27ac00 rd466f0  
    3131 */
    3232class Vector : public Space{
    33 protected:
    34   // this struct is used to indicate calls to the Baseconstructor from inside vectors.
    35   struct Baseconstructor{};
    3633public:
    3734
     
    107104
    108105private:
    109   double x[NDIM];
     106  double content[NDIM];
    110107
    111108};
Note: See TracChangeset for help on using the changeset viewer.