Changeset 99c484 for src


Ignore:
Timestamp:
Aug 19, 2009, 12:30:21 PM (15 years ago)
Author:
Frederik Heber <heber@…>
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:
1d9b7aa
Parents:
0077b5 (diff), ef9df36 (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 'VectorUnitTest' into ConcaveHull

Location:
src
Files:
4 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    r0077b5 r99c484  
    1 SOURCE = atom.cpp bond.cpp boundary.cpp builder.cpp config.cpp element.cpp ellipsoid.cpp helpers.cpp linkedcell.cpp moleculelist.cpp molecules.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
    2 HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
     1SOURCE = atom.cpp bond.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp helpers.cpp leastsquaremin.cpp linkedcell.cpp moleculelist.cpp molecules.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
     2HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
     3
     4noinst_PROGRAMS =  VectorUnitTest
    35
    46bin_PROGRAMS = molecuilder joiner analyzer
    57molecuilderdir = ${bindir}
    68molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db
    7 molecuilder_SOURCES =  ${SOURCE} ${HEADER}
     9molecuilder_SOURCES =  ${SOURCE} builder.cpp  ${HEADER}
    810joiner_SOURCES = joiner.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp datacreator.hpp helpers.hpp parser.hpp periodentafel.hpp
    911analyzer_SOURCES = analyzer.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp helpers.hpp periodentafel.hpp parser.hpp datacreator.hpp
    1012
     13TESTS = VectorUnitTest
     14check_PROGRAMS = $(TESTS)
     15VectorUnitTest_SOURCES = defs.hpp helpers.cpp helpers.hpp leastsquaremin.cpp leastsquaremin.hpp vectorunittest.cpp vectorunittest.hpp vector.cpp vector.hpp verbose.cpp verbose.hpp
     16VectorUnitTest_CXXFLAGS = $(CPPUNIT_CFLAGS)
     17VectorUnitTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl
    1118
    1219EXTRA_DIST = ${molecuilder_DATA}
  • src/boundary.cpp

    r0077b5 r99c484  
    308308
    309309      //*out << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
    310       if (ProjectedVector.Projection(&AngleReferenceNormalVector) > 0) {
     310      if (ProjectedVector.ScalarProduct(&AngleReferenceNormalVector) > 0) {
    311311        angle = 2. * M_PI - angle;
    312312      }
     
    775775      G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle
    776776      x.MakeNormalVector(runner->second->endpoints[0]->node->node, runner->second->endpoints[1]->node->node, runner->second->endpoints[2]->node->node);
    777       x.Scale(runner->second->endpoints[1]->node->node->Projection(&x));
     777      x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(&x));
    778778      h = x.Norm(); // distance of CoG to triangle
    779779      PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak)
  • src/builder.cpp

    r0077b5 r99c484  
    188188          // remove the projection onto the rotation plane of the second angle
    189189          n.CopyVector(&y);
    190           n.Scale(first->x.Projection(&y));
     190          n.Scale(first->x.ScalarProduct(&y));
    191191          cout << "N1: ",
    192192          n.Output((ofstream *)&cout);
     
    197197          cout << endl;
    198198          n.CopyVector(&z);
    199           n.Scale(first->x.Projection(&z));
     199          n.Scale(first->x.ScalarProduct(&z));
    200200          cout << "N2: ",
    201201          n.Output((ofstream *)&cout);
  • src/molecules.cpp

    r0077b5 r99c484  
    77#include "config.hpp"
    88#include "molecules.hpp"
    9 
    10 /************************************* Other Functions *************************************/
    11 
    12 /** Determines sum of squared distances of \a X to all \a **vectors.
    13  * \param *x reference vector
    14  * \param *params
    15  * \return sum of square distances
    16  */
    17 double LSQ (const gsl_vector * x, void * params)
    18 {
    19   double sum = 0.;
    20   struct LSQ_params *par = (struct LSQ_params *)params;
    21   Vector **vectors = par->vectors;
    22   int num = par->num;
    23 
    24   for (int i=num;i--;) {
    25     for(int j=NDIM;j--;)
    26       sum += (gsl_vector_get(x,j) - (vectors[i])->x[j])*(gsl_vector_get(x,j) - (vectors[i])->x[j]);
    27   }
    28 
    29   return sum;
    30 };
    319
    3210/************************************* Functions for class molecule *********************************/
  • src/molecules.hpp

    r0077b5 r99c484  
    2828#include "bond.hpp"
    2929#include "element.hpp"
     30#include "leastsquaremin.hpp"
    3031#include "linkedcell.hpp"
    3132#include "parser.hpp"
     
    8384
    8485
    85 // some algebraic matrix stuff
    86 #define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3])  //!< hard-coded determinant of a 3x3 matrix
    87 #define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2))                      //!< hard-coded determinant of a 2x2 matrix
    88 
    89 
    90 /** Parameter structure for least square minimsation.
    91  */
    92 struct LSQ_params {
    93   Vector **vectors;
    94   int num;
    95 };
    96 
    97 double LSQ(const gsl_vector * x, void * params);
    98 
    99 /** Parameter structure for least square minimsation.
    100  */
    101 struct lsq_params {
    102   gsl_vector *x;
    103   const molecule *mol;
    104   element *type;
    105 };
    10686
    10787#define MaxThermostats 6      //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented
  • src/tesselation.cpp

    r0077b5 r99c484  
    349349
    350350  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    351   if (NormalVector.Projection(&OtherVector) > 0)
     351  if (NormalVector.ScalarProduct(&OtherVector) > 0.)
    352352    NormalVector.Scale(-1.);
    353353};
     
    737737          TrialVector.CopyVector(checker->second->node->node);
    738738          TrialVector.SubtractVector(A->second->node->node);
    739           distance = TrialVector.Projection(&PlaneVector);
     739          distance = TrialVector.ScalarProduct(&PlaneVector);
    740740          if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
    741741            continue;
     
    897897        TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
    898898        //*out << Verbose(2) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
    899         if (PropagationVector.Projection(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
     899        if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
    900900          PropagationVector.Scale(-1.);
    901901        *out << Verbose(4) << "PropagationVector of base triangle is " << PropagationVector << endl;
     
    957957            TempVector.SubtractVector(Center);
    958958            // make it always point outward
    959             if (VirtualNormalVector.Projection(&TempVector) < 0)
     959            if (VirtualNormalVector.ScalarProduct(&TempVector) < 0)
    960960              VirtualNormalVector.Scale(-1.);
    961961            // calculate angle
     
    15301530        AddTesselationLine(TPS[0], TPS[1], 0);
    15311531      }
    1532       cout << Verbose(2) << "Projection is " << BTS->NormalVector.Projection(&Oben) << "." << endl;
     1532      cout << Verbose(2) << "Projection is " << BTS->NormalVector.ScalarProduct(&Oben) << "." << endl;
    15331533    }
    15341534    if (BTS != NULL) // we have created one starting triangle
  • src/tesselationhelpers.cpp

    r0077b5 r99c484  
    359359  HeightA.SubtractVector(&par.x1);
    360360
    361   t1 = HeightA.Projection(&SideA)/SideA.ScalarProduct(&SideA);
     361  t1 = HeightA.ScalarProduct(&SideA)/SideA.ScalarProduct(&SideA);
    362362
    363363  SideB.CopyVector(&par.x4);
     
    366366  HeightB.SubtractVector(&par.x3);
    367367
    368   t2 = HeightB.Projection(&SideB)/SideB.ScalarProduct(&SideB);
     368  t2 = HeightB.ScalarProduct(&SideB)/SideB.ScalarProduct(&SideB);
    369369
    370370  cout << Verbose(2) << "Intersection " << intersection << " is at "
  • src/vector.cpp

    r0077b5 r99c484  
    66
    77
    8 #include "molecules.hpp"
    9 
     8#include "defs.hpp"
     9#include "helpers.hpp"
     10#include "leastsquaremin.hpp"
     11#include "vector.hpp"
     12#include "verbose.hpp"
    1013
    1114/************************************ Functions for class vector ************************************/
     
    209212 * \param *PlaneNormal Plane's normal vector
    210213 * \param *PlaneOffset Plane's offset vector
    211  * \param *LineVector first vector of line
    212  * \param *LineVector2 second vector of line
     214 * \param *Origin first vector of line
     215 * \param *LineVector second vector of line
    213216 * \return true -  \a this contains intersection point on return, false - line is parallel to plane
    214217 */
     
    221224  Direction.CopyVector(LineVector);
    222225  Direction.SubtractVector(Origin);
     226  //*out << Verbose(4) << "INFO: Direction is " << Direction << "." << endl;
    223227  factor = Direction.ScalarProduct(PlaneNormal);
    224228  if (factor < MYEPSILON) { // Uniqueness: line parallel to plane?
     
    227231  }
    228232  helper.CopyVector(PlaneOffset);
    229   helper.SubtractVector(LineVector);
     233  helper.SubtractVector(Origin);
    230234  factor = helper.ScalarProduct(PlaneNormal)/factor;
    231235  //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal));
    232236  Direction.Scale(factor);
    233   CopyVector(LineVector);
     237  CopyVector(Origin);
     238  //*out << Verbose(4) << "INFO: Scaled direction is " << Direction << "." << endl;
    234239  AddVector(&Direction);
    235240
     
    238243  helper.SubtractVector(PlaneOffset);
    239244  if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) {
    240     *out << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl;
     245    //*out << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl;
    241246    return true;
    242247  } else {
     
    247252
    248253/** Calculates the intersection of the two lines that are both on the same plane.
    249  * Note that we do not check whether they are on the same plane.
     254 * We construct auxiliary plane with its vector normal to one line direction and the PlaneNormal, then a vector
     255 * from the first line's offset onto the plane. Finally, scale by factor is 1/cos(angle(line1,line2..)) = 1/SP(...), and
     256 * project onto the first line's direction and add its offset.
    250257 * \param *out output stream for debugging
    251258 * \param *Line1a first vector of first line
     
    258265bool Vector::GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b, const Vector *PlaneNormal)
    259266{
    260   double factor1, factor2;
    261   Vector helper, Line, LineNormal, *OtherNormal = NULL;
    262   const Vector *Normal;
    263   bool result = false;
    264 
    265   // create Plane normal vector
    266   if (PlaneNormal == NULL) {
    267     OtherNormal = new Vector(0.,0.,0.);
    268     if (!OtherNormal->MakeNormalVector(Line1a, Line1b, Line2a))
    269       if (!OtherNormal->MakeNormalVector(Line1a, Line1b, Line2b)) {
    270         *out << Verbose(1) << "ERROR: GetIntersectionOfTwoLinesOnPlane() cannot create a normal of the plane, everything is linear dependent." << endl;
    271         return false;
    272       }
    273     Normal = OtherNormal;
    274   } else
    275     Normal = PlaneNormal;
    276   *out << Verbose(3) << "INFO: Normal of plane is " << *Normal << "." << endl;
    277 
    278   // create normal vector to one line
    279   Line.CopyVector(Line1b);
    280   Line.SubtractVector(Line1a);
    281   LineNormal.MakeNormalVector(&Line, Normal);
    282   *out << Verbose(3) << "INFO: Normal of first line is " << LineNormal << "." << endl;
    283 
    284   // check if lines are parallel
    285   helper.CopyVector(Line2b);
    286   helper.SubtractVector(Line2a);
    287   if (fabs(helper.ScalarProduct(&LineNormal)) < MYEPSILON) {
    288     *out << Verbose(1) << "Lines " << helper << " and " << Line << " are parallel, no cross point!" << endl;
    289     result = false;
    290   } else { 
    291     helper.CopyVector(Line2a);
    292     helper.SubtractVector(Line1a);
    293     factor1 = helper.ScalarProduct(&LineNormal);
    294     helper.CopyVector(Line2b);
    295     helper.SubtractVector(Line1a);
    296     factor2 = helper.ScalarProduct(&LineNormal);
    297     if (fabs(factor2) > MYEPSILON) {
    298       CopyVector(Line2a);
    299       helper.Scale(factor1/factor2);
    300       AddVector(&helper);
     267  bool result = true;
     268  Vector Direction, OtherDirection;
     269  Vector AuxiliaryNormal;
     270  Vector Distance;
     271  const Vector *Normal = NULL;
     272  Vector *ConstructedNormal = NULL;
     273  bool FreeNormal = false;
     274
     275  // construct both direction vectors
     276  Zero();
     277  Direction.CopyVector(Line1b);
     278  Direction.SubtractVector(Line1a);
     279  if (Direction.IsZero())
     280    return false;
     281  OtherDirection.CopyVector(Line2b);
     282  OtherDirection.SubtractVector(Line2a);
     283  if (OtherDirection.IsZero())
     284    return false;
     285
     286  Direction.Normalize();
     287  OtherDirection.Normalize();
     288
     289  //*out << Verbose(4) << "INFO: Normalized Direction " << Direction << " and OtherDirection " << OtherDirection << "." << endl;
     290
     291  if (fabs(OtherDirection.ScalarProduct(&Direction) - 1.) < MYEPSILON) { // lines are parallel
     292    if ((Line1a == Line2a) || (Line1a == Line2b))
     293      CopyVector(Line1a);
     294    else if ((Line1b == Line2b) || (Line1b == Line2b))
     295        CopyVector(Line1b);
     296    else
     297      return false;
     298    *out << Verbose(4) << "INFO: Intersection is " << *this << "." << endl;
     299    return true;
     300  } else {
     301    // check whether we have a plane normal vector
     302    if (PlaneNormal == NULL) {
     303      ConstructedNormal = new Vector;
     304      ConstructedNormal->MakeNormalVector(&Direction, &OtherDirection);
     305      Normal = ConstructedNormal;
     306      FreeNormal = true;
     307    } else
     308      Normal = PlaneNormal;
     309
     310    AuxiliaryNormal.MakeNormalVector(&OtherDirection, Normal);
     311    //*out << Verbose(4) << "INFO: PlaneNormal is " << *Normal << " and AuxiliaryNormal " << AuxiliaryNormal << "." << endl;
     312
     313    Distance.CopyVector(Line2a);
     314    Distance.SubtractVector(Line1a);
     315    //*out << Verbose(4) << "INFO: Distance is " << Distance << "." << endl;
     316    if (Distance.IsZero()) {
     317      // offsets are equal, match found
     318      CopyVector(Line1a);
    301319      result = true;
    302320    } else {
    303       Zero();
    304       result = false;
     321      CopyVector(Distance.Projection(&AuxiliaryNormal));
     322      //*out << Verbose(4) << "INFO: Projected Distance is " << *this << "." << endl;
     323      double factor = Direction.ScalarProduct(&AuxiliaryNormal);
     324      //*out << Verbose(4) << "INFO: Scaling factor is " << factor << "." << endl;
     325      Scale(1./(factor*factor));
     326      //*out << Verbose(4) << "INFO: Scaled Distance is " << *this << "." << endl;
     327      CopyVector(Projection(&Direction));
     328      //*out << Verbose(4) << "INFO: Distance, projected into Direction, is " << *this << "." << endl;
     329      if (this->IsZero())
     330        result = false;
     331      else
     332        result = true;
     333      AddVector(Line1a);
    305334    }
    306   }
    307 
    308   if (OtherNormal != NULL)
    309     delete(OtherNormal);
     335
     336    if (FreeNormal)
     337      delete(ConstructedNormal);
     338  }
     339  if (result)
     340    *out << Verbose(4) << "INFO: Intersection is " << *this << "." << endl;
    310341
    311342  return result;
     
    314345/** Calculates the projection of a vector onto another \a *y.
    315346 * \param *y array to second vector
    316  * \return \f$\langle x, y \rangle\f$
    317  */
    318 double Vector::Projection(const Vector *y) const
    319 {
    320   return (ScalarProduct(y));
     347 */
     348void Vector::ProjectIt(const Vector *y)
     349{
     350  Vector helper(*y);
     351  helper.Scale(-(ScalarProduct(y)));
     352  AddVector(&helper);
     353};
     354
     355/** Calculates the projection of a vector onto another \a *y.
     356 * \param *y array to second vector
     357 * \return Vector
     358 */
     359Vector Vector::Projection(const Vector *y) const
     360{
     361  Vector helper(*y);
     362  helper.Scale((ScalarProduct(y)/y->NormSquared()));
     363
     364  return helper;
    321365};
    322366
     
    380424 * @return true - vector is zero, false - vector is not
    381425 */
    382 bool Vector::IsNull() const
    383 {
    384   return (fabs(x[0]+x[1]+x[2]) < MYEPSILON);
     426bool Vector::IsZero() const
     427{
     428  return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON);
     429};
     430
     431/** Checks whether vector has length of 1.
     432 * @return true - vector is normalized, false - vector is not
     433 */
     434bool Vector::IsOne() const
     435{
     436  return (fabs(Norm() - 1.) < MYEPSILON);
     437};
     438
     439/** Checks whether vector is normal to \a *normal.
     440 * @return true - vector is normalized, false - vector is not
     441 */
     442bool Vector::IsNormalTo(const Vector *normal) const
     443{
     444  if (ScalarProduct(normal) < MYEPSILON)
     445    return true;
     446  else
     447    return false;
    385448};
    386449
     
    392455{
    393456  double norm1 = Norm(), norm2 = y->Norm();
    394   double angle = 1;
     457  double angle = -1;
    395458  if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON))
    396459    angle = this->ScalarProduct(y)/norm1/norm2;
     
    413476  // normalise this vector with respect to axis
    414477  a.CopyVector(this);
    415   a.Scale(Projection(axis));
    416   SubtractVector(&a);
     478  a.ProjectOntoPlane(axis);
    417479  // construct normal vector
    418480  y.MakeNormalVector(axis,this);
     
    427489};
    428490
     491/** Compares vector \a to vector \a b component-wise.
     492 * \param a base vector
     493 * \param b vector components to add
     494 * \return a == b
     495 */
     496bool operator==(const Vector& a, const Vector& b)
     497{
     498  bool status = true;
     499  for (int i=0;i<NDIM;i++)
     500    status = status && (fabs(a.x[i] - b.x[i]) < MYEPSILON);
     501  return status;
     502};
     503
    429504/** Sums vector \a to this lhs component-wise.
    430505 * \param a base vector
     
    437512  return a;
    438513};
     514
     515/** Subtracts vector \a from this lhs component-wise.
     516 * \param a base vector
     517 * \param b vector components to add
     518 * \return lhs - a
     519 */
     520Vector& operator-=(Vector& a, const Vector& b)
     521{
     522  a.SubtractVector(&b);
     523  return a;
     524};
     525
    439526/** factor each component of \a a times a double \a m.
    440527 * \param a base vector
     
    461548};
    462549
     550/** Subtracts vector \a from \b component-wise.
     551 * \param a first vector
     552 * \param b second vector
     553 * \return a - b
     554 */
     555Vector& operator-(const Vector& a, const Vector& b)
     556{
     557  Vector *x = new Vector;
     558  x->CopyVector(&a);
     559  x->SubtractVector(&b);
     560  return *x;
     561};
     562
    463563/** Factors given vector \a a times \a m.
    464564 * \param a vector
    465565 * \param m factor
    466  * \return a + b
     566 * \return m * a
    467567 */
    468568Vector& operator*(const Vector& a, const double m)
     569{
     570  Vector *x = new Vector;
     571  x->CopyVector(&a);
     572  x->Scale(m);
     573  return *x;
     574};
     575
     576/** Factors given vector \a a times \a m.
     577 * \param m factor
     578 * \param a vector
     579 * \return m * a
     580 */
     581Vector& operator*(const double m, const Vector& a )
    469582{
    470583  Vector *x = new Vector;
     
    660773  x2.SubtractVector(y2);
    661774  if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    662     cout << Verbose(4) << "Given vectors are linear dependent." << endl;
     775    cout << Verbose(4) << "WARNING: Given vectors are linear dependent." << endl;
    663776    return false;
    664777  }
     
    694807  Zero();
    695808  if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    696     cout << Verbose(4) << "Given vectors are linear dependent." << endl;
     809    cout << Verbose(4) << "WARNING: Given vectors are linear dependent." << endl;
    697810    return false;
    698811  }
     
    714827/** Calculates orthonormal vector to one given vectors.
    715828 * Just subtracts the projection onto the given vector from this vector.
     829 * The removed part of the vector is Vector::Projection()
    716830 * \param *x1 vector
    717831 * \return true - success, false - vector is zero
     
    720834{
    721835  bool result = false;
    722   double factor = y1->Projection(this)/y1->Norm()/y1->Norm();
     836  double factor = y1->ScalarProduct(this)/y1->NormSquared();
    723837  Vector x1;
    724838  x1.CopyVector(y1);
     
    777891};
    778892
    779 /** Determines paramter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.
     893/** Determines parameter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.
    780894 * \param *A first plane vector
    781895 * \param *B second plane vector
     
    790904//  cout << "C " << C->Projection(this) << "\t";
    791905//  cout << endl;
    792   return A->Projection(this);
     906  return A->ScalarProduct(this);
    793907};
    794908
     
    9021016  for (int i=NDIM;i--;)
    9031017    this->x[i] = y->x[i];
     1018}
     1019
     1020/** Copy vector \a y componentwise.
     1021 * \param y vector
     1022 */
     1023void Vector::CopyVector(const Vector y)
     1024{
     1025  for (int i=NDIM;i--;)
     1026    this->x[i] = y.x[i];
    9041027}
    9051028
  • src/vector.hpp

    r0077b5 r99c484  
    55
    66#include "helpers.hpp"
     7
     8#include <gsl/gsl_vector.h>
     9#include <gsl/gsl_multimin.h>
    710
    811class Vector;
     
    2427  double PeriodicDistanceSquared(const Vector *y, const double *cell_size) const;
    2528  double ScalarProduct(const Vector *y) const;
    26   double Projection(const Vector *y) const;
    2729  double Norm() const;
    2830  double NormSquared() const;
    2931  double Angle(const Vector *y) const;
    30   bool IsNull() const;
     32  bool IsZero() const;
     33  bool IsOne() const;
     34  bool IsNormalTo(const Vector *normal) const;
    3135
    3236  void AddVector(const Vector *y);
    3337  void SubtractVector(const Vector *y);
    3438  void CopyVector(const Vector *y);
     39  void CopyVector(const Vector y);
    3540  void RotateVector(const Vector *y, const double alpha);
    3641  void VectorProduct(const Vector *y);
    3742  void ProjectOntoPlane(const Vector *y);
     43  void ProjectIt(const Vector *y);
     44  Vector Projection(const Vector *y) const;
    3845  void Zero();
    3946  void One(double one);
     
    6471
    6572ostream & operator << (ostream& ost, const Vector &m);
    66 //Vector& operator+=(Vector& a, const Vector& b);
    67 //Vector& operator*=(Vector& a, const double m);
    68 //Vector& operator*(const Vector& a, const double m);
    69 //Vector& operator+(const Vector& a, const Vector& b);
     73bool operator==(const Vector& a, const Vector& b);
     74Vector& operator+=(Vector& a, const Vector& b);
     75Vector& operator-=(Vector& a, const Vector& b);
     76Vector& operator*=(Vector& a, const double m);
     77Vector& operator*(const Vector& a, const double m);
     78Vector& operator*(const double m, const Vector& a);
     79Vector& operator+(const Vector& a, const Vector& b);
     80Vector& operator-(const Vector& a, const Vector& b);
     81
     82// some algebraic matrix stuff
     83#define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3])  //!< hard-coded determinant of a 3x3 matrix
     84#define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2))                      //!< hard-coded determinant of a 2x2 matrix
     85
     86
    7087
    7188#endif /*VECTOR_HPP_*/
Note: See TracChangeset for help on using the changeset viewer.