- Timestamp:
- Aug 19, 2009, 12:30:21 PM (15 years ago)
- 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. - 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 1 SOURCE = 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 2 HEADER = 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 4 noinst_PROGRAMS = VectorUnitTest 3 5 4 6 bin_PROGRAMS = molecuilder joiner analyzer 5 7 molecuilderdir = ${bindir} 6 8 molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db 7 molecuilder_SOURCES = ${SOURCE} ${HEADER}9 molecuilder_SOURCES = ${SOURCE} builder.cpp ${HEADER} 8 10 joiner_SOURCES = joiner.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp datacreator.hpp helpers.hpp parser.hpp periodentafel.hpp 9 11 analyzer_SOURCES = analyzer.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp helpers.hpp periodentafel.hpp parser.hpp datacreator.hpp 10 12 13 TESTS = VectorUnitTest 14 check_PROGRAMS = $(TESTS) 15 VectorUnitTest_SOURCES = defs.hpp helpers.cpp helpers.hpp leastsquaremin.cpp leastsquaremin.hpp vectorunittest.cpp vectorunittest.hpp vector.cpp vector.hpp verbose.cpp verbose.hpp 16 VectorUnitTest_CXXFLAGS = $(CPPUNIT_CFLAGS) 17 VectorUnitTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl 11 18 12 19 EXTRA_DIST = ${molecuilder_DATA} -
src/boundary.cpp
r0077b5 r99c484 308 308 309 309 //*out << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl; 310 if (ProjectedVector. Projection(&AngleReferenceNormalVector) > 0) {310 if (ProjectedVector.ScalarProduct(&AngleReferenceNormalVector) > 0) { 311 311 angle = 2. * M_PI - angle; 312 312 } … … 775 775 G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle 776 776 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)); 778 778 h = x.Norm(); // distance of CoG to triangle 779 779 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 188 188 // remove the projection onto the rotation plane of the second angle 189 189 n.CopyVector(&y); 190 n.Scale(first->x. Projection(&y));190 n.Scale(first->x.ScalarProduct(&y)); 191 191 cout << "N1: ", 192 192 n.Output((ofstream *)&cout); … … 197 197 cout << endl; 198 198 n.CopyVector(&z); 199 n.Scale(first->x. Projection(&z));199 n.Scale(first->x.ScalarProduct(&z)); 200 200 cout << "N2: ", 201 201 n.Output((ofstream *)&cout); -
src/molecules.cpp
r0077b5 r99c484 7 7 #include "config.hpp" 8 8 #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 vector14 * \param *params15 * \return sum of square distances16 */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 };31 9 32 10 /************************************* Functions for class molecule *********************************/ -
src/molecules.hpp
r0077b5 r99c484 28 28 #include "bond.hpp" 29 29 #include "element.hpp" 30 #include "leastsquaremin.hpp" 30 31 #include "linkedcell.hpp" 31 32 #include "parser.hpp" … … 83 84 84 85 85 // some algebraic matrix stuff86 #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 matrix87 #define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2)) //!< hard-coded determinant of a 2x2 matrix88 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 };106 86 107 87 #define MaxThermostats 6 //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented -
src/tesselation.cpp
r0077b5 r99c484 349 349 350 350 // 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.) 352 352 NormalVector.Scale(-1.); 353 353 }; … … 737 737 TrialVector.CopyVector(checker->second->node->node); 738 738 TrialVector.SubtractVector(A->second->node->node); 739 distance = TrialVector. Projection(&PlaneVector);739 distance = TrialVector.ScalarProduct(&PlaneVector); 740 740 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 741 741 continue; … … 897 897 TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 898 898 //*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 baseline899 if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline 900 900 PropagationVector.Scale(-1.); 901 901 *out << Verbose(4) << "PropagationVector of base triangle is " << PropagationVector << endl; … … 957 957 TempVector.SubtractVector(Center); 958 958 // make it always point outward 959 if (VirtualNormalVector. Projection(&TempVector) < 0)959 if (VirtualNormalVector.ScalarProduct(&TempVector) < 0) 960 960 VirtualNormalVector.Scale(-1.); 961 961 // calculate angle … … 1530 1530 AddTesselationLine(TPS[0], TPS[1], 0); 1531 1531 } 1532 cout << Verbose(2) << "Projection is " << BTS->NormalVector. Projection(&Oben) << "." << endl;1532 cout << Verbose(2) << "Projection is " << BTS->NormalVector.ScalarProduct(&Oben) << "." << endl; 1533 1533 } 1534 1534 if (BTS != NULL) // we have created one starting triangle -
src/tesselationhelpers.cpp
r0077b5 r99c484 359 359 HeightA.SubtractVector(&par.x1); 360 360 361 t1 = HeightA. Projection(&SideA)/SideA.ScalarProduct(&SideA);361 t1 = HeightA.ScalarProduct(&SideA)/SideA.ScalarProduct(&SideA); 362 362 363 363 SideB.CopyVector(&par.x4); … … 366 366 HeightB.SubtractVector(&par.x3); 367 367 368 t2 = HeightB. Projection(&SideB)/SideB.ScalarProduct(&SideB);368 t2 = HeightB.ScalarProduct(&SideB)/SideB.ScalarProduct(&SideB); 369 369 370 370 cout << Verbose(2) << "Intersection " << intersection << " is at " -
src/vector.cpp
r0077b5 r99c484 6 6 7 7 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" 10 13 11 14 /************************************ Functions for class vector ************************************/ … … 209 212 * \param *PlaneNormal Plane's normal vector 210 213 * \param *PlaneOffset Plane's offset vector 211 * \param * LineVectorfirst vector of line212 * \param *LineVector 2second vector of line214 * \param *Origin first vector of line 215 * \param *LineVector second vector of line 213 216 * \return true - \a this contains intersection point on return, false - line is parallel to plane 214 217 */ … … 221 224 Direction.CopyVector(LineVector); 222 225 Direction.SubtractVector(Origin); 226 //*out << Verbose(4) << "INFO: Direction is " << Direction << "." << endl; 223 227 factor = Direction.ScalarProduct(PlaneNormal); 224 228 if (factor < MYEPSILON) { // Uniqueness: line parallel to plane? … … 227 231 } 228 232 helper.CopyVector(PlaneOffset); 229 helper.SubtractVector( LineVector);233 helper.SubtractVector(Origin); 230 234 factor = helper.ScalarProduct(PlaneNormal)/factor; 231 235 //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal)); 232 236 Direction.Scale(factor); 233 CopyVector(LineVector); 237 CopyVector(Origin); 238 //*out << Verbose(4) << "INFO: Scaled direction is " << Direction << "." << endl; 234 239 AddVector(&Direction); 235 240 … … 238 243 helper.SubtractVector(PlaneOffset); 239 244 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; 241 246 return true; 242 247 } else { … … 247 252 248 253 /** 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. 250 257 * \param *out output stream for debugging 251 258 * \param *Line1a first vector of first line … … 258 265 bool Vector::GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b, const Vector *PlaneNormal) 259 266 { 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); 301 319 result = true; 302 320 } 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); 305 334 } 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; 310 341 311 342 return result; … … 314 345 /** Calculates the projection of a vector onto another \a *y. 315 346 * \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 */ 348 void 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 */ 359 Vector Vector::Projection(const Vector *y) const 360 { 361 Vector helper(*y); 362 helper.Scale((ScalarProduct(y)/y->NormSquared())); 363 364 return helper; 321 365 }; 322 366 … … 380 424 * @return true - vector is zero, false - vector is not 381 425 */ 382 bool Vector::IsNull() const 383 { 384 return (fabs(x[0]+x[1]+x[2]) < MYEPSILON); 426 bool 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 */ 434 bool 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 */ 442 bool Vector::IsNormalTo(const Vector *normal) const 443 { 444 if (ScalarProduct(normal) < MYEPSILON) 445 return true; 446 else 447 return false; 385 448 }; 386 449 … … 392 455 { 393 456 double norm1 = Norm(), norm2 = y->Norm(); 394 double angle = 1;457 double angle = -1; 395 458 if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON)) 396 459 angle = this->ScalarProduct(y)/norm1/norm2; … … 413 476 // normalise this vector with respect to axis 414 477 a.CopyVector(this); 415 a.Scale(Projection(axis)); 416 SubtractVector(&a); 478 a.ProjectOntoPlane(axis); 417 479 // construct normal vector 418 480 y.MakeNormalVector(axis,this); … … 427 489 }; 428 490 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 */ 496 bool 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 429 504 /** Sums vector \a to this lhs component-wise. 430 505 * \param a base vector … … 437 512 return a; 438 513 }; 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 */ 520 Vector& operator-=(Vector& a, const Vector& b) 521 { 522 a.SubtractVector(&b); 523 return a; 524 }; 525 439 526 /** factor each component of \a a times a double \a m. 440 527 * \param a base vector … … 461 548 }; 462 549 550 /** Subtracts vector \a from \b component-wise. 551 * \param a first vector 552 * \param b second vector 553 * \return a - b 554 */ 555 Vector& 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 463 563 /** Factors given vector \a a times \a m. 464 564 * \param a vector 465 565 * \param m factor 466 * \return a + b566 * \return m * a 467 567 */ 468 568 Vector& 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 */ 581 Vector& operator*(const double m, const Vector& a ) 469 582 { 470 583 Vector *x = new Vector; … … 660 773 x2.SubtractVector(y2); 661 774 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; 663 776 return false; 664 777 } … … 694 807 Zero(); 695 808 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; 697 810 return false; 698 811 } … … 714 827 /** Calculates orthonormal vector to one given vectors. 715 828 * Just subtracts the projection onto the given vector from this vector. 829 * The removed part of the vector is Vector::Projection() 716 830 * \param *x1 vector 717 831 * \return true - success, false - vector is zero … … 720 834 { 721 835 bool result = false; 722 double factor = y1-> Projection(this)/y1->Norm()/y1->Norm();836 double factor = y1->ScalarProduct(this)/y1->NormSquared(); 723 837 Vector x1; 724 838 x1.CopyVector(y1); … … 777 891 }; 778 892 779 /** Determines param ter 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. 780 894 * \param *A first plane vector 781 895 * \param *B second plane vector … … 790 904 // cout << "C " << C->Projection(this) << "\t"; 791 905 // cout << endl; 792 return A-> Projection(this);906 return A->ScalarProduct(this); 793 907 }; 794 908 … … 902 1016 for (int i=NDIM;i--;) 903 1017 this->x[i] = y->x[i]; 1018 } 1019 1020 /** Copy vector \a y componentwise. 1021 * \param y vector 1022 */ 1023 void Vector::CopyVector(const Vector y) 1024 { 1025 for (int i=NDIM;i--;) 1026 this->x[i] = y.x[i]; 904 1027 } 905 1028 -
src/vector.hpp
r0077b5 r99c484 5 5 6 6 #include "helpers.hpp" 7 8 #include <gsl/gsl_vector.h> 9 #include <gsl/gsl_multimin.h> 7 10 8 11 class Vector; … … 24 27 double PeriodicDistanceSquared(const Vector *y, const double *cell_size) const; 25 28 double ScalarProduct(const Vector *y) const; 26 double Projection(const Vector *y) const;27 29 double Norm() const; 28 30 double NormSquared() const; 29 31 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; 31 35 32 36 void AddVector(const Vector *y); 33 37 void SubtractVector(const Vector *y); 34 38 void CopyVector(const Vector *y); 39 void CopyVector(const Vector y); 35 40 void RotateVector(const Vector *y, const double alpha); 36 41 void VectorProduct(const Vector *y); 37 42 void ProjectOntoPlane(const Vector *y); 43 void ProjectIt(const Vector *y); 44 Vector Projection(const Vector *y) const; 38 45 void Zero(); 39 46 void One(double one); … … 64 71 65 72 ostream & 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); 73 bool operator==(const Vector& a, const Vector& b); 74 Vector& operator+=(Vector& a, const Vector& b); 75 Vector& operator-=(Vector& a, const Vector& b); 76 Vector& operator*=(Vector& a, const double m); 77 Vector& operator*(const Vector& a, const double m); 78 Vector& operator*(const double m, const Vector& a); 79 Vector& operator+(const Vector& a, const Vector& b); 80 Vector& 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 70 87 71 88 #endif /*VECTOR_HPP_*/
Note:
See TracChangeset
for help on using the changeset viewer.