Changeset 1bd79e for src/SingleVector.cpp
- Timestamp:
- Apr 15, 2010, 10:54:26 AM (16 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, 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
- File:
-
- 1 edited
-
src/SingleVector.cpp (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SingleVector.cpp
r273382 r1bd79e 21 21 #include <gsl/gsl_vector.h> 22 22 23 #include <iostream> 24 25 using namespace std; 26 23 27 /************************************ Functions for class vector ************************************/ 24 28 25 29 /** Constructor of class vector. 26 30 */ 27 SingleVector::SingleVector() 31 SingleVector::SingleVector() : 32 Vector(Baseconstructor()) 28 33 { 29 34 x[0] = x[1] = x[2] = 0.; … … 32 37 /** Constructor of class vector. 33 38 */ 34 SingleVector::SingleVector(const double x1, const double x2, const double x3) 39 SingleVector::SingleVector(const double x1, const double x2, const double x3) : 40 Vector(Baseconstructor()) 35 41 { 36 42 x[0] = x1; … … 42 48 * Copy constructor 43 49 */ 44 SingleVector::SingleVector(const Vector& src) 50 SingleVector::SingleVector(const Vector& src) : 51 Vector(Baseconstructor()) 45 52 { 46 53 x[0] = src[0]; … … 49 56 } 50 57 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; 58 SingleVector* SingleVector::clone() const{ 59 return new SingleVector(x[0],x[1],x[2]); 62 60 } 63 61 … … 76 74 res += (x[i]-y[i])*(x[i]-y[i]); 77 75 return (res); 78 };79 80 /** Calculates distance between this and another vector.81 * \param *y array to second vector82 * \return \f$| x - y |\f$83 */84 double SingleVector::Distance(const Vector &y) const85 {86 double res = 0.;87 for (int i=NDIM;i--;)88 res += (x[i]-y[i])*(x[i]-y[i]);89 return (sqrt(res));90 76 }; 91 77 … … 173 159 // bool flag = false; 174 160 //vector Shifted, TranslationVector; 175 Vector TestVector;176 161 // Log() << Verbose(1) << "Begin of KeepPeriodic." << endl; 177 162 // Log() << Verbose(2) << "Vector is: "; 178 163 // Output(out); 179 164 // Log() << Verbose(0) << endl; 180 TestVector = *this;165 SingleVector TestVector(*this); 181 166 TestVector.InverseMatrixMultiplication(matrix); 182 167 for(int i=NDIM;i--;) { // correct periodically … … 208 193 209 194 195 void SingleVector::AddVector(const Vector &y) { 196 for(int i=NDIM;i--;) 197 x[i] += y[i]; 198 } 199 200 void SingleVector::SubtractVector(const Vector &y){ 201 for(int i=NDIM;i--;) 202 x[i] -= y[i]; 203 } 204 210 205 /** Calculates VectorProduct between this and another vector. 211 206 * -# returns the Product in place of vector from which it was initiated … … 216 211 void SingleVector::VectorProduct(const Vector &y) 217 212 { 218 Vector tmp;213 SingleVector tmp; 219 214 tmp[0] = x[1]* (y[2]) - x[2]* (y[1]); 220 215 tmp[1] = x[2]* (y[0]) - x[0]* (y[2]); 221 216 tmp[2] = x[0]* (y[1]) - x[1]* (y[0]); 222 (*this) = tmp;217 CopyVector(tmp); 223 218 }; 224 219 … … 245 240 double SingleVector::DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const 246 241 { 247 Vector temp;248 249 242 // first create part that is orthonormal to PlaneNormal with withdraw 250 temp = (*this)- PlaneOffset;243 Vector temp = VecFromRep(this)- PlaneOffset; 251 244 temp.MakeNormalTo(PlaneNormal); 252 245 temp.Scale(-1.); 253 246 // then add connecting vector from plane to point 254 temp += (*this)-PlaneOffset;247 temp += VecFromRep(this)-PlaneOffset; 255 248 double sign = temp.ScalarProduct(PlaneNormal); 256 249 if (fabs(sign) > MYEPSILON) … … 282 275 283 276 return helper; 284 };285 286 /** Calculates norm of this vector.287 * \return \f$|x|\f$288 */289 double SingleVector::Norm() const290 {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() const301 {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;340 277 }; 341 278 … … 410 347 } 411 348 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 420 349 double* SingleVector::get(){ 421 350 return x; … … 424 353 * \param *factor pointer to scaling factor 425 354 */ 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; 355 void SingleVector::ScaleAll(const double *factor) 356 { 357 for (int i=NDIM;i--;) 358 x[i] *= factor[i]; 436 359 }; 437 360 … … 440 363 for (int i=NDIM;i--;) 441 364 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];451 365 }; 452 366 … … 474 388 void SingleVector::MatrixMultiplication(const double * const M) 475 389 { 476 Vector C;390 SingleVector C; 477 391 // do the matrix multiplication 478 392 C[0] = M[0]*x[0]+M[3]*x[1]+M[6]*x[2]; … … 480 394 C[2] = M[2]*x[0]+M[5]*x[1]+M[8]*x[2]; 481 395 482 *this = C;396 CopyVector(C); 483 397 }; 484 398 … … 488 402 bool SingleVector::InverseMatrixMultiplication(const double * const A) 489 403 { 490 Vector C;404 SingleVector C; 491 405 double B[NDIM*NDIM]; 492 406 double detA = RDET3(A); … … 511 425 C[2] = B[2]*x[0]+B[5]*x[1]+B[8]*x[2]; 512 426 513 *this = C;427 CopyVector(C); 514 428 return true; 515 429 } else { … … 518 432 }; 519 433 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 vector524 * \param *x2 second vector525 * \param *x3 third vector526 * \param *factors three-component vector with the factor for each given vector527 */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 };533 434 534 435 /** Mirrors atom against a given plane. … … 615 516 bool SingleVector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const 616 517 { 617 Vector a = (*this) - offset; 518 Vector a = VecFromRep(this); 519 a -= offset; 618 520 a.InverseMatrixMultiplication(parallelepiped); 619 521 bool isInside = true; … … 624 526 return isInside; 625 527 } 528 529 530 void SingleVector::CopyVector(SingleVector& vec) { 531 for(int i =NDIM; i--;) 532 x[i]=vec.x[i]; 533 } 534 535 bool SingleVector::isBaseClass() const{ 536 return false; 537 }
Note:
See TracChangeset
for help on using the changeset viewer.
