Ignore:
Timestamp:
Apr 15, 2010, 10:54:26 AM (16 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, Candidate_v1.7.0, 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:
753f02
Parents:
273382
Message:

Changed implementation of Vector to forward operations to contained objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SingleVector.cpp

    r273382 r1bd79e  
    2121#include <gsl/gsl_vector.h>
    2222
     23#include <iostream>
     24
     25using namespace std;
     26
    2327/************************************ Functions for class vector ************************************/
    2428
    2529/** Constructor of class vector.
    2630 */
    27 SingleVector::SingleVector()
     31SingleVector::SingleVector() :
     32  Vector(Baseconstructor())
    2833{
    2934  x[0] = x[1] = x[2] = 0.;
     
    3237/** Constructor of class vector.
    3338 */
    34 SingleVector::SingleVector(const double x1, const double x2, const double x3)
     39SingleVector::SingleVector(const double x1, const double x2, const double x3) :
     40  Vector(Baseconstructor())
    3541{
    3642  x[0] = x1;
     
    4248 * Copy constructor
    4349 */
    44 SingleVector::SingleVector(const Vector& src)
     50SingleVector::SingleVector(const Vector& src) :
     51  Vector(Baseconstructor())
    4552{
    4653  x[0] = src[0];
     
    4956}
    5057
    51 /**
    52  * Assignment operator
    53  */
    54 Vector& SingleVector::operator=(const Vector& src){
    55   // check for self assignment
    56   if(&src!=this){
    57     x[0] = src[0];
    58     x[1] = src[1];
    59     x[2] = src[2];
    60   }
    61   return *this;
     58SingleVector* SingleVector::clone() const{
     59  return new SingleVector(x[0],x[1],x[2]);
    6260}
    6361
     
    7674    res += (x[i]-y[i])*(x[i]-y[i]);
    7775  return (res);
    78 };
    79 
    80 /** Calculates distance between this and another vector.
    81  * \param *y array to second vector
    82  * \return \f$| x - y |\f$
    83  */
    84 double SingleVector::Distance(const Vector &y) const
    85 {
    86   double res = 0.;
    87   for (int i=NDIM;i--;)
    88     res += (x[i]-y[i])*(x[i]-y[i]);
    89   return (sqrt(res));
    9076};
    9177
     
    173159//  bool flag = false;
    174160  //vector Shifted, TranslationVector;
    175   Vector TestVector;
    176161//  Log() << Verbose(1) << "Begin of KeepPeriodic." << endl;
    177162//  Log() << Verbose(2) << "Vector is: ";
    178163//  Output(out);
    179164//  Log() << Verbose(0) << endl;
    180   TestVector = *this;
     165  SingleVector TestVector(*this);
    181166  TestVector.InverseMatrixMultiplication(matrix);
    182167  for(int i=NDIM;i--;) { // correct periodically
     
    208193
    209194
     195void SingleVector::AddVector(const Vector &y) {
     196  for(int i=NDIM;i--;)
     197    x[i] += y[i];
     198}
     199
     200void SingleVector::SubtractVector(const Vector &y){
     201  for(int i=NDIM;i--;)
     202    x[i] -= y[i];
     203}
     204
    210205/** Calculates VectorProduct between this and another vector.
    211206 *  -# returns the Product in place of vector from which it was initiated
     
    216211void SingleVector::VectorProduct(const Vector &y)
    217212{
    218   Vector tmp;
     213  SingleVector tmp;
    219214  tmp[0] = x[1]* (y[2]) - x[2]* (y[1]);
    220215  tmp[1] = x[2]* (y[0]) - x[0]* (y[2]);
    221216  tmp[2] = x[0]* (y[1]) - x[1]* (y[0]);
    222   (*this) = tmp;
     217  CopyVector(tmp);
    223218};
    224219
     
    245240double SingleVector::DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const
    246241{
    247   Vector temp;
    248 
    249242  // first create part that is orthonormal to PlaneNormal with withdraw
    250   temp = (*this )- PlaneOffset;
     243  Vector temp = VecFromRep(this)- PlaneOffset;
    251244  temp.MakeNormalTo(PlaneNormal);
    252245  temp.Scale(-1.);
    253246  // then add connecting vector from plane to point
    254   temp += (*this)-PlaneOffset;
     247  temp += VecFromRep(this)-PlaneOffset;
    255248  double sign = temp.ScalarProduct(PlaneNormal);
    256249  if (fabs(sign) > MYEPSILON)
     
    282275
    283276  return helper;
    284 };
    285 
    286 /** Calculates norm of this vector.
    287  * \return \f$|x|\f$
    288  */
    289 double SingleVector::Norm() const
    290 {
    291   double res = 0.;
    292   for (int i=NDIM;i--;)
    293     res += this->x[i]*this->x[i];
    294   return (sqrt(res));
    295 };
    296 
    297 /** Calculates squared norm of this vector.
    298  * \return \f$|x|^2\f$
    299  */
    300 double SingleVector::NormSquared() const
    301 {
    302   return (ScalarProduct(*this));
    303 };
    304 
    305 /** Normalizes this vector.
    306  */
    307 void SingleVector::Normalize()
    308 {
    309   double res = 0.;
    310   for (int i=NDIM;i--;)
    311     res += this->x[i]*this->x[i];
    312   if (fabs(res) > MYEPSILON)
    313     res = 1./sqrt(res);
    314   Scale(&res);
    315 };
    316 
    317 /** Zeros all components of this vector.
    318  */
    319 void SingleVector::Zero()
    320 {
    321   for (int i=NDIM;i--;)
    322     this->x[i] = 0.;
    323 };
    324 
    325 /** Zeros all components of this vector.
    326  */
    327 void SingleVector::One(const double one)
    328 {
    329   for (int i=NDIM;i--;)
    330     this->x[i] = one;
    331 };
    332 
    333 /** Initialises all components of this vector.
    334  */
    335 void SingleVector::Init(const double x1, const double x2, const double x3)
    336 {
    337   x[0] = x1;
    338   x[1] = x2;
    339   x[2] = x3;
    340277};
    341278
     
    410347}
    411348
    412 double& SingleVector::at(size_t i){
    413   return (*this)[i];
    414 }
    415 
    416 const double& SingleVector::at(size_t i) const{
    417   return (*this)[i];
    418 }
    419 
    420349double* SingleVector::get(){
    421350  return x;
     
    424353 * \param *factor pointer to scaling factor
    425354 */
    426 void SingleVector::Scale(const double ** const factor)
    427 {
    428   for (int i=NDIM;i--;)
    429     x[i] *= (*factor)[i];
    430 };
    431 
    432 void SingleVector::Scale(const double * const factor)
    433 {
    434   for (int i=NDIM;i--;)
    435     x[i] *= *factor;
     355void SingleVector::ScaleAll(const double *factor)
     356{
     357  for (int i=NDIM;i--;)
     358    x[i] *= factor[i];
    436359};
    437360
     
    440363  for (int i=NDIM;i--;)
    441364    x[i] *= factor;
    442 };
    443 
    444 /** Translate atom by given vector.
    445  * \param trans[] translation vector.
    446  */
    447 void SingleVector::Translate(const Vector &trans)
    448 {
    449   for (int i=NDIM;i--;)
    450     x[i] += trans[i];
    451365};
    452366
     
    474388void SingleVector::MatrixMultiplication(const double * const M)
    475389{
    476   Vector C;
     390  SingleVector C;
    477391  // do the matrix multiplication
    478392  C[0] = M[0]*x[0]+M[3]*x[1]+M[6]*x[2];
     
    480394  C[2] = M[2]*x[0]+M[5]*x[1]+M[8]*x[2];
    481395
    482   *this = C;
     396  CopyVector(C);
    483397};
    484398
     
    488402bool SingleVector::InverseMatrixMultiplication(const double * const A)
    489403{
    490   Vector C;
     404  SingleVector C;
    491405  double B[NDIM*NDIM];
    492406  double detA = RDET3(A);
     
    511425    C[2] = B[2]*x[0]+B[5]*x[1]+B[8]*x[2];
    512426
    513     *this = C;
     427    CopyVector(C);
    514428    return true;
    515429  } else {
     
    518432};
    519433
    520 
    521 /** Creates this vector as the b y *factors' components scaled linear combination of the given three.
    522  * this vector = x1*factors[0] + x2* factors[1] + x3*factors[2]
    523  * \param *x1 first vector
    524  * \param *x2 second vector
    525  * \param *x3 third vector
    526  * \param *factors three-component vector with the factor for each given vector
    527  */
    528 void SingleVector::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors)
    529 {
    530   for(int i=NDIM;i--;)
    531     x[i] = factors[0]*x1[i] + factors[1]*x2[i] + factors[2]*x3[i];
    532 };
    533434
    534435/** Mirrors atom against a given plane.
     
    615516bool SingleVector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const
    616517{
    617   Vector a = (*this) - offset;
     518  Vector a = VecFromRep(this);
     519  a -= offset;
    618520  a.InverseMatrixMultiplication(parallelepiped);
    619521  bool isInside = true;
     
    624526  return isInside;
    625527}
     528
     529
     530void SingleVector::CopyVector(SingleVector& vec) {
     531  for(int i =NDIM; i--;)
     532    x[i]=vec.x[i];
     533}
     534
     535bool SingleVector::isBaseClass() const{
     536  return false;
     537}
Note: See TracChangeset for help on using the changeset viewer.