Changeset 1dc9ec for src


Ignore:
Timestamp:
Jun 17, 2010, 3:09:22 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:
d386e8
Parents:
5f5a7b (diff), 0c7ed8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'VectorRefactoring' into stable

Conflicts:

molecuilder/src/vector.cpp

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/gslvector.cpp

    r5f5a7b r1dc9ec  
    1313#include "gslvector.hpp"
    1414#include "defs.hpp"
     15#include "vector.hpp"
    1516
    1617/** Constructor of class GSLVector.
     
    6162  gsl_vector_memcpy (vector, &m.vector);
    6263};
     64
     65/**
     66 * This function sets the GSLvector from an ordinary vector.
     67 *
     68 * Takes access to the internal gsl_vector and copies it
     69 */
     70void GSLVector::SetFromVector(Vector &v){
     71  gsl_vector_memcpy (vector, v.get());
     72}
    6373
    6474/** This function returns the i-th element of a vector.
  • src/gslvector.hpp

    r5f5a7b r1dc9ec  
    2424
    2525class GSLVector;
     26class Vector;
    2627
    2728/********************************************** declarations *******************************/
     
    3839  // Accessing
    3940  void SetFromDoubleArray(double *x);
     41  void SetFromVector(Vector &v);
    4042  double Get(size_t m) const;
    4143  void Set(size_t m, double x);
  • src/linearsystemofequations.cpp

    r5f5a7b r1dc9ec  
    5656{
    5757  assert ( columns == NDIM && "Vector class is always three-dimensional, unlike this LEqS!");
    58   b->SetFromDoubleArray(x->get());
     58  b->SetFromVector(*x);
    5959};
    6060
  • src/vector.cpp

    r5f5a7b r1dc9ec  
    2424Vector::Vector()
    2525{
    26   x[0] = x[1] = x[2] = 0.;
     26  content = gsl_vector_calloc (NDIM);
    2727};
    2828
     
    3333Vector::Vector(const Vector& src)
    3434{
    35   x[0] = src[0];
    36   x[1] = src[1];
    37   x[2] = src[2];
     35  content = gsl_vector_alloc(NDIM);
     36  gsl_vector_set(content,0,src[0]);
     37  gsl_vector_set(content,1,src[1]);
     38  gsl_vector_set(content,2,src[2]);
    3839}
    3940
     
    4243Vector::Vector(const double x1, const double x2, const double x3)
    4344{
    44   x[0] = x1;
    45   x[1] = x2;
    46   x[2] = x3;
     45  content = gsl_vector_alloc(NDIM);
     46  gsl_vector_set(content,0,x1);
     47  gsl_vector_set(content,1,x2);
     48  gsl_vector_set(content,2,x3);
    4749};
    4850
     
    5355  // check for self assignment
    5456  if(&src!=this){
    55     x[0] = src[0];
    56     x[1] = src[1];
    57     x[2] = src[2];
     57    gsl_vector_set(content,0,src[0]);
     58    gsl_vector_set(content,1,src[1]);
     59    gsl_vector_set(content,2,src[2]);
    5860  }
    5961  return *this;
     
    6264/** Desctructor of class vector.
    6365 */
    64 Vector::~Vector() {};
     66Vector::~Vector() {
     67  gsl_vector_free(content);
     68};
    6569
    6670/** Calculates square of distance between this and another vector.
     
    7276  double res = 0.;
    7377  for (int i=NDIM;i--;)
    74     res += (x[i]-y[i])*(x[i]-y[i]);
     78    res += (at(i)-y[i])*(at(i)-y[i]);
    7579  return (res);
    7680};
     
    200204  double res = 0.;
    201205  for (int i=NDIM;i--;)
    202     res += x[i]*y[i];
     206    res += at(i)*y[i];
    203207  return (res);
    204208};
     
    214218{
    215219  Vector tmp;
    216   tmp[0] = x[1]* y[2] - x[2]* y[1];
    217   tmp[1] = x[2]* y[0] - x[0]* y[2];
    218   tmp[2] = x[0]* y[1] - x[1]* y[0];
     220  for(int i=NDIM;i--;)
     221    tmp[i] = at((i+1)%NDIM)*y[(i+2)%NDIM] - at((i+2)%NDIM)*y[(i+1)%NDIM];
    219222  (*this) = tmp;
    220223};
     
    309312bool Vector::IsZero() const
    310313{
    311   return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON);
     314  return (fabs(at(0))+fabs(at(1))+fabs(at(2)) < MYEPSILON);
    312315};
    313316
     
    338341  bool status = true;
    339342  for (int i=0;i<NDIM;i++) {
    340     if (fabs(x[i] - a[i]) > MYEPSILON)
     343    if (fabs(at(i) - a[i]) > MYEPSILON)
    341344      status = false;
    342345  }
     
    366369double& Vector::operator[](size_t i){
    367370  ASSERT(i<=NDIM && i>=0,"Vector Index out of Range");
    368   return x[i];
     371  return *gsl_vector_ptr (content, i);
    369372}
    370373
    371374const double& Vector::operator[](size_t i) const{
    372375  ASSERT(i<=NDIM && i>=0,"Vector Index out of Range");
    373   return x[i];
     376  return *gsl_vector_ptr (content, i);
    374377}
    375378
     
    382385}
    383386
    384 double* Vector::get(){
    385   return x;
     387gsl_vector* Vector::get(){
     388  return content;
    386389}
    387390
     
    498501{
    499502  for (int i=NDIM;i--;)
    500     x[i] *= factor[i];
     503    at(i) *= factor[i];
    501504};
    502505
     
    506509{
    507510  for (int i=NDIM;i--;)
    508     x[i] *= factor;
     511    at(i) *= factor;
    509512};
    510513
     
    518521  // truncate to [0,1] for each axis
    519522  for (int i=0;i<NDIM;i++) {
    520     //x[i] += 0.5;  // set to center of box
    521     while (x[i] >= 1.)
    522       x[i] -= 1.;
    523     while (x[i] < 0.)
    524       x[i] += 1.;
     523    //at(i) += 0.5;  // set to center of box
     524    while (at(i) >= 1.)
     525      at(i) -= 1.;
     526    while (at(i) < 0.)
     527      at(i) += 1.;
    525528  }
    526529  MatrixMultiplication(M);
     
    549552void Vector::MatrixMultiplication(const double * const M)
    550553{
     554  Vector tmp;
    551555  // do the matrix multiplication
    552   at(0) = M[0]*x[0]+M[3]*x[1]+M[6]*x[2];
    553   at(1) = M[1]*x[0]+M[4]*x[1]+M[7]*x[2];
    554   at(2) = M[2]*x[0]+M[5]*x[1]+M[8]*x[2];
     556  for(int i=NDIM;i--;)
     557    tmp[i] = M[i]*at(0)+M[i+3]*at(1)+M[i+6]*at(2);
     558
     559  (*this) = tmp;
    555560};
    556561
     
    577582    B[8] =  detAReci*RDET2(A[0],A[1],A[3],A[4]);    // A_33
    578583
    579     // do the matrix multiplication
    580     at(0) = B[0]*x[0]+B[3]*x[1]+B[6]*x[2];
    581     at(1) = B[1]*x[0]+B[4]*x[1]+B[7]*x[2];
    582     at(2) = B[2]*x[0]+B[5]*x[1]+B[8]*x[2];
     584    MatrixMultiplication(B);
    583585
    584586    return true;
     
    616618  SubtractVector(x1);
    617619  for (int i=NDIM;i--;)
    618     result = result || (fabs(x[i]) > MYEPSILON);
     620    result = result || (fabs(at(i)) > MYEPSILON);
    619621
    620622  return result;
     
    678680{
    679681  for(int i=NDIM;i--;)
    680     x[i] += y[i];
     682    at(i) += y[i];
    681683}
    682684
     
    687689{
    688690  for(int i=NDIM;i--;)
    689     x[i] -= y[i];
     691    at(i) -= y[i];
    690692}
    691693
  • src/vector.hpp

    r5f5a7b r1dc9ec  
    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
     
    8279
    8380  // Access to internal structure
    84   double* get();
     81  gsl_vector* get();
    8582
    8683  // Methods that are derived directly from other methods
     
    107104
    108105private:
    109   double x[NDIM];
     106  gsl_vector *content;
    110107
    111108};
Note: See TracChangeset for help on using the changeset viewer.