Changeset 8cbb97
- Timestamp:
- Apr 29, 2010, 1:55: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:
- d79639
- Parents:
- 632bc3 (diff), 753f02 (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:
-
- 9 added
- 45 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Legacy/oldmenu.cpp
r632bc3 r8cbb97 24 24 #include "molecule.hpp" 25 25 #include "periodentafel.hpp" 26 #include "vector_ops.hpp" 27 #include "Plane.hpp" 26 28 27 29 #include "UIElements/UIFactory.hpp" … … 59 61 char choice; // menu choice char 60 62 bool valid; 63 bool aborted; 61 64 62 65 Log() << Verbose(0) << "===========ADD ATOM============================" << endl; … … 77 80 break; 78 81 case 'a': // absolute coordinates of atom 79 Log() << Verbose(0) << "Enter absolute coordinates." << endl; 82 { 83 Dialog *dialog = UIFactory::getInstance().makeDialog(); 80 84 first = World::getInstance().createAtom(); 81 first->x.AskPosition(World::getInstance().getDomain(), false); 82 first->type = periode->AskElement(); // give type 83 mol->AddAtom(first); // add to molecule 85 dialog->queryVector("Please enter coordinates: ",&first->x,World::getInstance().getDomain(), false); 86 dialog->queryElement("Please choose element: ",&first->type); 87 if(dialog->display()){ 88 mol->AddAtom(first); // add to molecule 89 } 90 else{ 91 World::getInstance().destroyAtom(first); 92 } 93 } 94 break; 95 96 case 'b': // relative coordinates of atom wrt to reference point 97 first = World::getInstance().createAtom(); 98 valid = true; 99 aborted = false; 100 do { 101 if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; 102 auto_ptr<Dialog> dialog(UIFactory::getInstance().makeDialog()); 103 dialog->queryVector("Enter reference coordinates.",&x,World::getInstance().getDomain(), true); 104 dialog->queryVector("Enter relative coordinates.",&first->x,World::getInstance().getDomain(), false); 105 if((aborted = !dialog->display())){ 106 continue; 107 } 108 first->x += x; 109 } while (!aborted && !(valid = mol->CheckBounds((const Vector *)&first->x))); 110 if(!aborted){ 111 first->type = periode->AskElement(); // give type 112 mol->AddAtom(first); // add to molecule 113 } 114 else{ 115 World::getInstance().destroyAtom(first); 116 } 84 117 break; 85 118 86 case 'b': // relative coordinates of atom wrt to reference point 119 case 'c': // relative coordinates of atom wrt to already placed atom 120 { 87 121 first = World::getInstance().createAtom(); 88 122 valid = true; 89 123 do { 90 124 if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; 91 Log() << Verbose(0) << "Enter reference coordinates." << endl; 92 x.AskPosition(World::getInstance().getDomain(), true); 93 Log() << Verbose(0) << "Enter relative coordinates." << endl; 94 first->x.AskPosition(World::getInstance().getDomain(), false); 95 first->x.AddVector((const Vector *)&x); 96 Log() << Verbose(0) << "\n"; 97 } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); 98 first->type = periode->AskElement(); // give type 99 mol->AddAtom(first); // add to molecule 100 break; 101 102 case 'c': // relative coordinates of atom wrt to already placed atom 103 first = World::getInstance().createAtom(); 104 valid = true; 105 do { 106 if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; 125 auto_ptr<Dialog> dialog(UIFactory::getInstance().makeDialog()); 107 126 second = mol->AskAtom("Enter atom number: "); 108 Log() << Verbose(0) << "Enter relative coordinates." << endl;109 first->x.AskPosition(World::getInstance().getDomain(), false);127 dialog->queryVector("Enter relative coordinates.",&first->x,World::getInstance().getDomain(), false); 128 dialog->display(); 110 129 for (int i=NDIM;i--;) { 111 first->x .x[i] += second->x.x[i];130 first->x[i] += second->x[i]; 112 131 } 113 132 } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); 114 133 first->type = periode->AskElement(); // give type 115 134 mol->AddAtom(first); // add to molecule 116 break; 135 } 136 break; 117 137 118 138 case 'd': // two atoms, two angles and a distance … … 154 174 */ 155 175 // calc axis vector 156 x.CopyVector(&second->x); 157 x.SubtractVector(&third->x); 176 x= second->x - third->x; 158 177 x.Normalize(); 159 Log() << Verbose(0) << "x: ", 160 x.Output(); 161 Log() << Verbose(0) << endl; 162 z.MakeNormalVector(&second->x,&third->x,&fourth->x); 163 Log() << Verbose(0) << "z: ", 164 z.Output(); 165 Log() << Verbose(0) << endl; 166 y.MakeNormalVector(&x,&z); 167 Log() << Verbose(0) << "y: ", 168 y.Output(); 169 Log() << Verbose(0) << endl; 178 Log() << Verbose(0) << "x: " << x << endl; 179 z = Plane(second->x,third->x,fourth->x).getNormal(); 180 Log() << Verbose(0) << "z: " << z << endl; 181 y = Plane(x,z,0).getNormal(); 182 Log() << Verbose(0) << "y: " << y << endl; 170 183 171 184 // rotate vector around first angle 172 first->x.CopyVector(&x); 173 first->x.RotateVector(&z,b - M_PI); 174 Log() << Verbose(0) << "Rotated vector: ", 175 first->x.Output(); 176 Log() << Verbose(0) << endl; 185 first->x = x; 186 first->x = RotateVector(first->x,z,b - M_PI); 187 Log() << Verbose(0) << "Rotated vector: " << first->x << endl, 177 188 // remove the projection onto the rotation plane of the second angle 178 n.CopyVector(&y); 179 n.Scale(first->x.ScalarProduct(&y)); 180 Log() << Verbose(0) << "N1: ", 181 n.Output(); 182 Log() << Verbose(0) << endl; 183 first->x.SubtractVector(&n); 184 Log() << Verbose(0) << "Subtracted vector: ", 185 first->x.Output(); 186 Log() << Verbose(0) << endl; 187 n.CopyVector(&z); 188 n.Scale(first->x.ScalarProduct(&z)); 189 Log() << Verbose(0) << "N2: ", 190 n.Output(); 191 Log() << Verbose(0) << endl; 192 first->x.SubtractVector(&n); 193 Log() << Verbose(0) << "2nd subtracted vector: ", 194 first->x.Output(); 195 Log() << Verbose(0) << endl; 189 n = y; 190 n.Scale(first->x.ScalarProduct(y)); 191 Log() << Verbose(0) << "N1: " << n << endl; 192 first->x -= n; 193 Log() << Verbose(0) << "Subtracted vector: " << first->x << endl; 194 n = z; 195 n.Scale(first->x.ScalarProduct(z)); 196 Log() << Verbose(0) << "N2: " << n << endl; 197 first->x -= n; 198 Log() << Verbose(0) << "2nd subtracted vector: " << first->x << endl; 196 199 197 200 // rotate another vector around second angle 198 n.CopyVector(&y); 199 n.RotateVector(&x,c - M_PI); 200 Log() << Verbose(0) << "2nd Rotated vector: ", 201 n.Output(); 202 Log() << Verbose(0) << endl; 201 n = y; 202 n = RotateVector(n,x,c - M_PI); 203 Log() << Verbose(0) << "2nd Rotated vector: " << n << endl; 203 204 204 205 // add the two linear independent vectors 205 first->x .AddVector(&n);206 first->x += n; 206 207 first->x.Normalize(); 207 208 first->x.Scale(a); 208 first->x.AddVector(&second->x); 209 210 Log() << Verbose(0) << "resulting coordinates: "; 211 first->x.Output(); 212 Log() << Verbose(0) << endl; 209 first->x += second->x; 210 211 Log() << Verbose(0) << "resulting coordinates: " << first->x << endl; 213 212 } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); 214 213 first->type = periode->AskElement(); // give type … … 233 232 } while ((j != -1) && (i<128)); 234 233 if (i >= 2) { 235 first->x.LSQdistance((const Vector **)atoms, i);236 237 first->x.Output();234 LSQdistance(first->x,(const Vector **)atoms, i); 235 236 Log() << Verbose(0) << first->x; 238 237 first->type = periode->AskElement(); // give type 239 238 mol->AddAtom(first); // add to molecule … … 280 279 for (int i=0;i<NDIM;i++) { 281 280 Log() << Verbose(0) << "Enter axis " << i << " boundary: "; 282 cin >> y .x[i];281 cin >> y[i]; 283 282 } 284 283 mol->CenterEdge(&x); // make every coordinate positive 285 mol->Center.AddVector(&y); // translate by boundary 286 helper.CopyVector(&y); 287 helper.Scale(2.); 288 helper.AddVector(&x); 284 mol->Center += y; // translate by boundary 285 helper = (2*y)+x; 289 286 mol->SetBoxDimension(&helper); // update Box of atoms by boundary 290 287 break; … … 293 290 for (int i=0;i<NDIM;i++) { 294 291 Log() << Verbose(0) << "Enter axis " << i << " boundary: "; 295 cin >> x .x[i];292 cin >> x[i]; 296 293 } 297 294 // update Box of atoms by boundary … … 330 327 third = mol->AskAtom("Enter third atom: "); 331 328 332 n .MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);329 n = Plane(first->x,second->x,third->x).getNormal(); 333 330 break; 334 331 case 'b': // normal vector of mirror plane 335 Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl; 336 n.AskPosition(World::getInstance().getDomain(),0); 332 { 333 Dialog *dialog = UIFactory::getInstance().makeDialog(); 334 dialog->queryVector("Enter normal vector of mirror plane.",&n,World::getInstance().getDomain(),false); 335 dialog->display(); 336 delete dialog; 337 337 n.Normalize(); 338 break; 338 } 339 break; 340 339 341 case 'c': // three atoms defining mirror plane 340 342 first = mol->AskAtom("Enter first atom: "); 341 343 second = mol->AskAtom("Enter second atom: "); 342 344 343 n.CopyVector((const Vector *)&first->x); 344 n.SubtractVector((const Vector *)&second->x); 345 n = first->x - second->x; 345 346 n.Normalize(); 346 347 break; … … 356 357 mol->GetAlignvector(¶m); 357 358 for (int i=NDIM;i--;) { 358 x .x[i] = gsl_vector_get(param.x,i);359 n .x[i] = gsl_vector_get(param.x,i+NDIM);359 x[i] = gsl_vector_get(param.x,i); 360 n[i] = gsl_vector_get(param.x,i+NDIM); 360 361 } 361 362 gsl_vector_free(param.x); 362 Log() << Verbose(0) << "Offset vector: "; 363 x.Output(); 364 Log() << Verbose(0) << endl; 363 Log() << Verbose(0) << "Offset vector: " << x << endl; 365 364 n.Normalize(); 366 365 break; 367 366 }; 368 Log() << Verbose(0) << "Alignment vector: "; 369 n.Output(); 370 Log() << Verbose(0) << endl; 367 Log() << Verbose(0) << "Alignment vector: " << n << endl; 371 368 mol->Align(&n); 372 369 }; … … 397 394 third = mol->AskAtom("Enter third atom: "); 398 395 399 n .MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);396 n = Plane(first->x,second->x,third->x).getNormal(); 400 397 break; 401 398 case 'b': // normal vector of mirror plane 402 Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl; 403 n.AskPosition(World::getInstance().getDomain(),0); 399 { 400 Dialog *dialog = UIFactory::getInstance().makeDialog(); 401 dialog->queryVector("Enter normal vector of mirror plane.",&n,World::getInstance().getDomain(),false); 402 dialog->display(); 403 delete dialog; 404 404 n.Normalize(); 405 break; 405 } 406 break; 407 406 408 case 'c': // three atoms defining mirror plane 407 409 first = mol->AskAtom("Enter first atom: "); 408 410 second = mol->AskAtom("Enter second atom: "); 409 411 410 n.CopyVector((const Vector *)&first->x); 411 n.SubtractVector((const Vector *)&second->x); 412 n = first->x - second->x; 412 413 n.Normalize(); 413 414 break; 414 415 }; 415 Log() << Verbose(0) << "Normal vector: "; 416 n.Output(); 417 Log() << Verbose(0) << endl; 416 Log() << Verbose(0) << "Normal vector: " << n << endl; 418 417 mol->Mirror((const Vector *)&n); 419 418 }; … … 455 454 first = second; 456 455 second = first->next; 457 if (first->x.DistanceSquared( (const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...456 if (first->x.DistanceSquared(second->x) > tmp1*tmp1) // distance to first above radius ... 458 457 mol->RemoveAtom(first); 459 458 } … … 471 470 first = second; 472 471 second = first->next; 473 if ((first->x .x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ...472 if ((first->x[axis] < tmp1) || (first->x[axis] > tmp2)) {// out of boundary ... 474 473 //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl; 475 474 mol->RemoveAtom(first); … … 522 521 tmp1 = 0.; 523 522 if (first != second) { 524 x.CopyVector((const Vector *)&first->x); 525 x.SubtractVector((const Vector *)&second->x); 523 x = first->x - second->x; 526 524 tmp1 = x.Norm(); 527 525 } … … 538 536 for (int i=NDIM;i--;) 539 537 min[i] = 0.; 540 x.CopyVector((const Vector *)&first->x); 541 x.SubtractVector((const Vector *)&second->x); 538 x = first->x - second->x; 542 539 tmp1 = x.Norm(); 543 Log() << Verbose(1) << "Distance vector is "; 544 x.Output(); 545 Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl; 540 Log() << Verbose(1) << "Distance vector is " << x << "." << "/n" 541 << "Norm of distance is " << tmp1 << "." << endl; 546 542 break; 547 543 … … 552 548 third = mol->AskAtom("Enter last atom: "); 553 549 tmp1 = tmp2 = tmp3 = 0.; 554 x.CopyVector((const Vector *)&first->x); 555 x.SubtractVector((const Vector *)&second->x); 556 y.CopyVector((const Vector *)&third->x); 557 y.SubtractVector((const Vector *)&second->x); 550 x = first->x - second->x; 551 y = third->x - second->x; 558 552 Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": "; 559 Log() << Verbose(0) << (acos(x.ScalarProduct( (const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;553 Log() << Verbose(0) << (acos(x.ScalarProduct(y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl; 560 554 break; 561 555 case 'd': … … 676 670 minBond = 0.; 677 671 for (int i=NDIM;i--;) 678 minBond += (first->x .x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);672 minBond += (first->x[i]-second->x[i])*(first->x[i] - second->x[i]); 679 673 minBond = sqrt(minBond); 680 674 Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl; … … 682 676 cin >> bond; 683 677 for (int i=NDIM;i--;) { 684 second->x .x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond);678 second->x[i] -= (second->x[i]-first->x[i])/minBond*(minBond-bond); 685 679 } 686 680 //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: "; … … 778 772 x.Zero(); 779 773 y.Zero(); 780 y .x[abs(axis)-1] = World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude774 y[abs(axis)-1] = World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude 781 775 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times 782 x .AddVector(&y); // per factor one cell width further776 x += y; // per factor one cell width further 783 777 for (int k=count;k--;) { // go through every atom of the original cell 784 778 first = World::getInstance().createAtom(); // create a new body 785 first->x.CopyVector(vectors[k]); // use coordinate of original atom 786 first->x.AddVector(&x); // translate the coordinates 779 first->x = (*vectors[k]) + x; // use coordinate of original atom 787 780 first->type = Elements[k]; // insert original element 788 781 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) … … 796 789 // correct cell size 797 790 if (axis < 0) { // if sign was negative, we have to translate everything 798 x.Zero(); 799 x.AddVector(&y); 791 x = y; 800 792 x.Scale(-(faktor-1)); 801 793 mol->Translate(&x); … … 893 885 mol = *ListRunner; 894 886 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; 895 Log() << Verbose(0) << "Enter translation vector." << endl; 896 x.AskPosition(World::getInstance().getDomain(),0); 897 mol->Center.AddVector((const Vector *)&x); 887 Dialog *dialog = UIFactory::getInstance().makeDialog(); 888 dialog->queryVector("Enter translation vector.",&x,World::getInstance().getDomain(),false); 889 if(dialog->display()){ 890 mol->Center += x; 891 } 892 delete dialog; 898 893 } 899 894 break; -
src/Makefile.am
r632bc3 r8cbb97 1 # this includes source files that need to be present at multiple points 2 HELPERSOURCE = Helpers/Assert.cpp \ 3 Helpers/MemDebug.cpp 4 1 5 ATOMSOURCE = atom.cpp atom_atominfo.cpp atom_bondedparticle.cpp atom_bondedparticleinfo.cpp atom_graphnode.cpp atom_graphnodeinfo.cpp atom_particleinfo.cpp atom_trajectoryparticle.cpp atom_trajectoryparticleinfo.cpp 2 6 ATOMHEADER = atom.hpp atom_atominfo.hpp atom_bondedparticle.hpp atom_bondedparticleinfo.hpp atom_graphnode.hpp atom_graphnodeinfo.hpp atom_particleinfo.hpp atom_trajectoryparticle.hpp atom_trajectoryparticleinfo.hpp 3 7 4 LINALGSOURCE = gslmatrix.cpp gslvector.cpp linearsystemofequations.cpp 5 LINALGHEADER = gslmatrix.hpp gslvector.hpp linearsystemofequations.hpp 8 LINALGSOURCE = ${HELPERSOURCE} \ 9 gslmatrix.cpp \ 10 gslvector.cpp \ 11 linearsystemofequations.cpp \ 12 vector.cpp 13 14 LINALGHEADER = gslmatrix.hpp \ 15 gslvector.hpp \ 16 linearsystemofequations.hpp \ 17 vector.hpp 18 6 19 7 20 ANALYSISSOURCE = analysis_bonds.cpp analysis_correlation.cpp … … 70 83 71 84 85 EXCEPTIONSOURCE = Exceptions/CustomException.cpp \ 86 Exceptions/LinearDependenceException.cpp 87 88 EXCEPTIONHEADER = Exceptions/CustomException.hpp \ 89 Exceptions/LinearDependenceException.hpp 90 72 91 SOURCE = ${ANALYSISSOURCE} \ 73 92 ${ATOMSOURCE} \ … … 75 94 ${UISOURCE} \ 76 95 ${DESCRIPTORSOURCE} \ 96 ${HELPERSOURCE} \ 77 97 ${LEGACYSOURCE} \ 98 ${EXCEPTIONSOURCE} \ 78 99 bond.cpp \ 79 100 bondgraph.cpp \ … … 85 106 graph.cpp \ 86 107 helpers.cpp \ 87 Helpers/Assert.cpp \88 Helpers/MemDebug.cpp \89 108 info.cpp \ 90 109 leastsquaremin.cpp \ … … 103 122 parser.cpp \ 104 123 periodentafel.cpp \ 124 Plane.cpp \ 105 125 tesselation.cpp \ 106 126 tesselationhelpers.cpp \ 107 127 triangleintersectionlist.cpp \ 108 vector.cpp \109 128 verbose.cpp \ 129 vector_ops.cpp \ 110 130 World.cpp 111 131 112 132 HEADER = \ 113 ${ANALYSISHEADER} \ 114 ${ATOMHEADER} \ 115 ${PATTERNHEADER} \ 116 ${UIHEADER} \ 117 ${DESCRIPTORHEADER} \ 118 ${LEGACYHEADER} \ 119 bond.hpp \ 120 bondgraph.hpp \ 121 boundary.hpp \ 122 config.hpp \ 123 defs.hpp \ 124 element.hpp \ 125 ellipsoid.hpp \ 126 errorlogger.hpp \ 127 graph.hpp \ 128 helpers.hpp \ 129 info.hpp \ 130 leastsquaremin.hpp \ 131 linkedcell.hpp \ 132 lists.hpp \ 133 log.hpp \ 134 logger.hpp \ 135 memoryallocator.hpp \ 136 memoryusageobserver.hpp \ 137 molecule.hpp \ 138 molecule_template.hpp \ 139 parser.hpp \ 140 periodentafel.hpp \ 141 stackclass.hpp \ 142 tesselation.hpp \ 143 tesselationhelpers.hpp \ 144 triangleintersectionlist.hpp \ 145 vector.hpp \ 146 verbose.hpp \ 147 World.hpp 133 ${ANALYSISHEADER} \ 134 ${ATOMHEADER} \ 135 ${PATTERNHEADER} \ 136 ${UIHEADER} \ 137 ${DESCRIPTORHEADER} \ 138 ${EXCEPTIONHEADER} \ 139 ${LEGACYHEADER} \ 140 bond.hpp \ 141 bondgraph.hpp \ 142 boundary.hpp \ 143 config.hpp \ 144 defs.hpp \ 145 element.hpp \ 146 ellipsoid.hpp \ 147 errorlogger.hpp \ 148 graph.hpp \ 149 helpers.hpp \ 150 info.hpp \ 151 leastsquaremin.hpp \ 152 linkedcell.hpp \ 153 lists.hpp \ 154 log.hpp \ 155 logger.hpp \ 156 memoryallocator.hpp \ 157 memoryusageobserver.hpp \ 158 molecule.hpp \ 159 molecule_template.hpp \ 160 parser.hpp \ 161 periodentafel.hpp \ 162 Plane.hpp \ 163 stackclass.hpp \ 164 tesselation.hpp \ 165 tesselationhelpers.hpp \ 166 triangleintersectionlist.hpp \ 167 verbose.hpp \ 168 vector_ops.hpp \ 169 World.hpp 148 170 149 171 BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB) -
src/UIElements/TextDialog.cpp
r632bc3 r8cbb97 154 154 155 155 bool TextDialog::VectorTextQuery::handle() { 156 Log() << Verbose(0) << getTitle(); 157 tmp->AskPosition(cellSize,check); 158 return true; 156 Log() << Verbose(0) << getTitle(); 157 158 char coords[3] = {'x','y','z'}; 159 int j = -1; 160 for (int i=0;i<3;i++) { 161 j += i+1; 162 do { 163 Log() << Verbose(0) << coords[i] << "[0.." << cellSize[j] << "]: "; 164 cin >> (*tmp)[i]; 165 } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= cellSize[j])) && (check)); 166 } 167 return true; 159 168 } 160 169 -
src/analysis_bonds.cpp
r632bc3 r8cbb97 93 93 Vector OOBond; 94 94 95 OHBond.CopyVector(first); 96 OHBond.SubtractVector(central); 97 OOBond.CopyVector(second); 98 OOBond.SubtractVector(central); 99 const double angle = OHBond.Angle(&OOBond); 95 OHBond = (*first) - (*central); 96 OOBond = (*second) - (*central); 97 const double angle = OHBond.Angle(OOBond); 100 98 return angle; 101 99 }; … … 145 143 if ((Walker->type->Z == 8) && (Runner->type->Z == 8)) { 146 144 // check distance 147 const double distance = Runner->x.DistanceSquared( &Walker->x);145 const double distance = Runner->x.DistanceSquared(Walker->x); 148 146 if ((distance > MYEPSILON) && (distance < HBRIDGEDISTANCE*HBRIDGEDISTANCE)) { // distance >0 means different atoms 149 147 // on other atom(Runner) we check for bond to interface element and -
src/analysis_correlation.cpp
r632bc3 r8cbb97 57 57 if (Walker->nr < OtherWalker->nr) 58 58 if ((type2 == NULL) || (OtherWalker->type == type2)) { 59 distance = Walker->node->PeriodicDistance( OtherWalker->node, World::getInstance().getDomain());59 distance = Walker->node->PeriodicDistance(*OtherWalker->node, World::getInstance().getDomain()); 60 60 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl; 61 61 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) ); … … 106 106 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl); 107 107 if ((type1 == NULL) || (Walker->type == type1)) { 108 periodicX .CopyVector(Walker->node);108 periodicX = *(Walker->node); 109 109 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 110 110 // go through every range in xyz and get distance … … 112 112 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) 113 113 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { 114 checkX.Init(n[0], n[1], n[2]); 115 checkX.AddVector(&periodicX); 114 checkX = Vector(n[0], n[1], n[2]) + periodicX; 116 115 checkX.MatrixMultiplication(FullMatrix); 117 116 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++) … … 124 123 if (Walker->nr < OtherWalker->nr) 125 124 if ((type2 == NULL) || (OtherWalker->type == type2)) { 126 periodicOtherX .CopyVector(OtherWalker->node);125 periodicOtherX = *(OtherWalker->node); 127 126 periodicOtherX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 128 127 // go through every range in xyz and get distance … … 130 129 for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++) 131 130 for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) { 132 checkOtherX.Init(Othern[0], Othern[1], Othern[2]); 133 checkOtherX.AddVector(&periodicOtherX); 131 checkOtherX = Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX; 134 132 checkOtherX.MatrixMultiplication(FullMatrix); 135 distance = checkX.Distance( &checkOtherX);133 distance = checkX.Distance(checkOtherX); 136 134 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl; 137 135 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) ); … … 176 174 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl); 177 175 if ((type == NULL) || (Walker->type == type)) { 178 distance = Walker->node->PeriodicDistance( point, World::getInstance().getDomain());176 distance = Walker->node->PeriodicDistance(*point, World::getInstance().getDomain()); 179 177 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl); 180 178 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) ); … … 218 216 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl); 219 217 if ((type == NULL) || (Walker->type == type)) { 220 periodicX .CopyVector(Walker->node);218 periodicX = *(Walker->node); 221 219 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 222 220 // go through every range in xyz and get distance … … 224 222 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) 225 223 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { 226 checkX.Init(n[0], n[1], n[2]); 227 checkX.AddVector(&periodicX); 224 checkX = Vector(n[0], n[1], n[2]) + periodicX; 228 225 checkX.MatrixMultiplication(FullMatrix); 229 distance = checkX.Distance( point);226 distance = checkX.Distance(*point); 230 227 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl); 231 228 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) ); … … 322 319 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl); 323 320 if ((type == NULL) || (Walker->type == type)) { 324 periodicX .CopyVector(Walker->node);321 periodicX = *(Walker->node); 325 322 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 326 323 // go through every range in xyz and get distance … … 329 326 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) 330 327 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { 331 checkX.Init(n[0], n[1], n[2]); 332 checkX.AddVector(&periodicX); 328 checkX = Vector(n[0], n[1], n[2]) + periodicX; 333 329 checkX.MatrixMultiplication(FullMatrix); 334 330 TriangleIntersectionList Intersections(&checkX,Surface,LC); … … 402 398 *file << runner->first; 403 399 for (int i=0;i<NDIM;i++) 404 *file << "\t" << setprecision(8) << (runner->second.first->node-> x[i] - runner->second.second->x[i]);400 *file << "\t" << setprecision(8) << (runner->second.first->node->at(i) - runner->second.second->at(i)); 405 401 *file << endl; 406 402 } -
src/atom.cpp
r632bc3 r8cbb97 33 33 { 34 34 type = pointer->type; // copy element of atom 35 x .CopyVector(&pointer->x); // copy coordination36 v .CopyVector(&pointer->v); // copy velocity35 x = pointer->x; // copy coordination 36 v = pointer->v; // copy velocity 37 37 FixedIon = pointer->FixedIon; 38 38 node = &x; … … 46 46 res->sort = &res->nr; 47 47 res->type = type; 48 res->x .CopyVector(&this->x);49 res->v .CopyVector(&this->v);48 res->x = this->x; 49 res->v = this->v; 50 50 res->FixedIon = FixedIon; 51 51 res->node = &x; … … 130 130 if (out != NULL) { 131 131 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint; 132 *out << x .x[0] << "\t" << x.x[1] << "\t" << x.x[2];132 *out << x[0] << "\t" << x[1] << "\t" << x[2]; 133 133 *out << "\t" << FixedIon; 134 134 if (v.Norm() > MYEPSILON) 135 *out << "\t" << scientific << setprecision(6) << v .x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";135 *out << "\t" << scientific << setprecision(6) << v[0] << "\t" << v[1] << "\t" << v[2] << "\t"; 136 136 if (comment != NULL) 137 137 *out << " # " << comment << endl; … … 155 155 if (out != NULL) { 156 156 *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t" << fixed << setprecision(9) << showpoint; 157 *out << x .x[0] << "\t" << x.x[1] << "\t" << x.x[2];157 *out << x[0] << "\t" << x[1] << "\t" << x[2]; 158 158 *out << "\t" << FixedIon; 159 159 if (v.Norm() > MYEPSILON) 160 *out << "\t" << scientific << setprecision(6) << v .x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";160 *out << "\t" << scientific << setprecision(6) << v[0] << "\t" << v[1] << "\t" << v[2] << "\t"; 161 161 if (comment != NULL) 162 162 *out << " # " << comment << endl; … … 175 175 { 176 176 if (out != NULL) { 177 *out << type->symbol << "\t" << x .x[0] << "\t" << x.x[1] << "\t" << x.x[2] << "\t" << endl;177 *out << type->symbol << "\t" << x[0] << "\t" << x[1] << "\t" << x[2] << "\t" << endl; 178 178 return true; 179 179 } else … … 193 193 if (out != NULL) { 194 194 *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t" << fixed << setprecision(9) << showpoint; 195 *out << Trajectory.R.at(step) .x[0] << "\t" << Trajectory.R.at(step).x[1] << "\t" << Trajectory.R.at(step).x[2];195 *out << Trajectory.R.at(step)[0] << "\t" << Trajectory.R.at(step)[1] << "\t" << Trajectory.R.at(step)[2]; 196 196 *out << "\t" << FixedIon; 197 197 if (Trajectory.U.at(step).Norm() > MYEPSILON) 198 *out << "\t" << scientific << setprecision(6) << Trajectory.U.at(step) .x[0] << "\t" << Trajectory.U.at(step).x[1] << "\t" << Trajectory.U.at(step).x[2] << "\t";198 *out << "\t" << scientific << setprecision(6) << Trajectory.U.at(step)[0] << "\t" << Trajectory.U.at(step)[1] << "\t" << Trajectory.U.at(step)[2] << "\t"; 199 199 if (Trajectory.F.at(step).Norm() > MYEPSILON) 200 *out << "\t" << scientific << setprecision(6) << Trajectory.F.at(step) .x[0] << "\t" << Trajectory.F.at(step).x[1] << "\t" << Trajectory.F.at(step).x[2] << "\t";200 *out << "\t" << scientific << setprecision(6) << Trajectory.F.at(step)[0] << "\t" << Trajectory.F.at(step)[1] << "\t" << Trajectory.F.at(step)[2] << "\t"; 201 201 *out << "\t# Number in molecule " << nr << endl; 202 202 return true; … … 214 214 if (out != NULL) { 215 215 *out << type->symbol << "\t"; 216 *out << Trajectory.R.at(step) .x[0] << "\t";217 *out << Trajectory.R.at(step) .x[1] << "\t";218 *out << Trajectory.R.at(step) .x[2] << endl;216 *out << Trajectory.R.at(step)[0] << "\t"; 217 *out << Trajectory.R.at(step)[1] << "\t"; 218 *out << Trajectory.R.at(step)[2] << endl; 219 219 return true; 220 220 } else … … 229 229 void atom::OutputMPQCLine(ofstream * const out, const Vector *center, int *AtomNo = NULL) const 230 230 { 231 *out << "\t\t" << type->symbol << " [ " << x .x[0]-center->x[0] << "\t" << x.x[1]-center->x[1] << "\t" << x.x[2]-center->x[2]<< " ]" << endl;231 *out << "\t\t" << type->symbol << " [ " << x[0]-center->at(0) << "\t" << x[1]-center->at(1) << "\t" << x[2]-center->at(2) << " ]" << endl; 232 232 if (AtomNo != NULL) 233 233 *AtomNo++; … … 252 252 double atom::DistanceSquaredToVector(const Vector &origin) const 253 253 { 254 return origin.DistanceSquared( &x);254 return origin.DistanceSquared(x); 255 255 }; 256 256 … … 261 261 double atom::DistanceToVector(const Vector &origin) const 262 262 { 263 return origin.Distance( &x);263 return origin.Distance(x); 264 264 }; 265 265 -
src/atom_trajectoryparticle.cpp
r632bc3 r8cbb97 34 34 { 35 35 for (int i=NDIM;i--;) 36 *temperature += type->mass * Trajectory.U.at(step) .x[i]* Trajectory.U.at(step).x[i];36 *temperature += type->mass * Trajectory.U.at(step)[i]* Trajectory.U.at(step)[i]; 37 37 }; 38 38 … … 49 49 // set forces 50 50 for (int i=NDIM;i++;) 51 Force->Matrix[0][nr][5+i] += 2.*constant*sqrt(Trajectory.R.at(startstep).Distance( &Sprinter->Trajectory.R.at(endstep)));51 Force->Matrix[0][nr][5+i] += 2.*constant*sqrt(Trajectory.R.at(startstep).Distance(Sprinter->Trajectory.R.at(endstep))); 52 52 }; 53 53 … … 60 60 { 61 61 for(int d=0;d<NDIM;d++) { 62 Trajectory.U.at(Step) .x[d] -= CoGVelocity->x[d];63 *ActualTemp += 0.5 * type->mass * Trajectory.U.at(Step) .x[d] * Trajectory.U.at(Step).x[d];62 Trajectory.U.at(Step)[d] -= CoGVelocity->at(d); 63 *ActualTemp += 0.5 * type->mass * Trajectory.U.at(Step)[d] * Trajectory.U.at(Step)[d]; 64 64 } 65 65 }; … … 89 89 90 90 for (int n=NDIM;n--;) { 91 Trajectory.R.at(dest) .x[n] = Trajectory.R.at(src).x[n];92 Trajectory.U.at(dest) .x[n] = Trajectory.U.at(src).x[n];93 Trajectory.F.at(dest) .x[n] = Trajectory.F.at(src).x[n];91 Trajectory.R.at(dest)[n] = Trajectory.R.at(src)[n]; 92 Trajectory.U.at(dest)[n] = Trajectory.U.at(src)[n]; 93 Trajectory.F.at(dest)[n] = Trajectory.F.at(src)[n]; 94 94 } 95 95 }; … … 105 105 //a = configuration.Deltat*0.5/walker->type->mass; // (F+F_old)/2m = a and thus: v = (F+F_old)/2m * t = (F + F_old) * a 106 106 for (int d=0; d<NDIM; d++) { 107 Trajectory.F.at(NextStep) .x[d] = -Force->Matrix[0][nr][d+5]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.);108 Trajectory.R.at(NextStep) .x[d] = Trajectory.R.at(NextStep-1).x[d];109 Trajectory.R.at(NextStep) .x[d] += configuration->Deltat*(Trajectory.U.at(NextStep-1).x[d]); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2110 Trajectory.R.at(NextStep) .x[d] += 0.5*configuration->Deltat*configuration->Deltat*(Trajectory.F.at(NextStep).x[d]/type->mass); // F = m * a and s =107 Trajectory.F.at(NextStep)[d] = -Force->Matrix[0][nr][d+5]*(configuration->GetIsAngstroem() ? AtomicLengthToAngstroem : 1.); 108 Trajectory.R.at(NextStep)[d] = Trajectory.R.at(NextStep-1)[d]; 109 Trajectory.R.at(NextStep)[d] += configuration->Deltat*(Trajectory.U.at(NextStep-1)[d]); // s(t) = s(0) + v * deltat + 1/2 a * deltat^2 110 Trajectory.R.at(NextStep)[d] += 0.5*configuration->Deltat*configuration->Deltat*(Trajectory.F.at(NextStep)[d]/type->mass); // F = m * a and s = 111 111 } 112 112 // Update U 113 113 for (int d=0; d<NDIM; d++) { 114 Trajectory.U.at(NextStep) .x[d] = Trajectory.U.at(NextStep-1).x[d];115 Trajectory.U.at(NextStep) .x[d] += configuration->Deltat * (Trajectory.F.at(NextStep).x[d]+Trajectory.F.at(NextStep-1).x[d]/type->mass); // v = F/m * t114 Trajectory.U.at(NextStep)[d] = Trajectory.U.at(NextStep-1)[d]; 115 Trajectory.U.at(NextStep)[d] += configuration->Deltat * (Trajectory.F.at(NextStep)[d]+Trajectory.F.at(NextStep-1)[d]/type->mass); // v = F/m * t 116 116 } 117 117 // Update R (and F) … … 134 134 *TotalMass += type->mass; // sum up total mass 135 135 for(int d=0;d<NDIM;d++) { 136 TotalVelocity-> x[d] += Trajectory.U.at(Step).x[d]*type->mass;136 TotalVelocity->at(d) += Trajectory.U.at(Step)[d]*type->mass; 137 137 } 138 138 }; … … 145 145 void TrajectoryParticle::Thermostat_Woodcock(double ScaleTempFactor, int Step, double *ekin) 146 146 { 147 double *U = Trajectory.U.at(Step).x;147 Vector &U = Trajectory.U.at(Step); 148 148 if (FixedIon == 0) // even FixedIon moves, only not by other's forces 149 149 for (int d=0; d<NDIM; d++) { … … 160 160 void TrajectoryParticle::Thermostat_Gaussian_init(int Step, double *G, double *E) 161 161 { 162 double *U = Trajectory.U.at(Step).x;163 double *F = Trajectory.F.at(Step).x;162 Vector &U = Trajectory.U.at(Step); 163 Vector &F = Trajectory.F.at(Step); 164 164 if (FixedIon == 0) // even FixedIon moves, only not by other's forces 165 165 for (int d=0; d<NDIM; d++) { … … 177 177 void TrajectoryParticle::Thermostat_Gaussian_least_constraint(int Step, double G_over_E, double *ekin, config *configuration) 178 178 { 179 double *U = Trajectory.U.at(Step).x;179 Vector &U = Trajectory.U.at(Step); 180 180 if (FixedIon == 0) // even FixedIon moves, only not by other's forces 181 181 for (int d=0; d<NDIM; d++) { … … 194 194 { 195 195 double sigma = sqrt(configuration->TargetTemp/type->mass); // sigma = (k_b T)/m (Hartree/atomicmass = atomiclength/atomictime) 196 double *U = Trajectory.U.at(Step).x;196 Vector &U = Trajectory.U.at(Step); 197 197 if (FixedIon == 0) { // even FixedIon moves, only not by other's forces 198 198 // throw a dice to determine whether it gets hit by a heat bath particle … … 218 218 void TrajectoryParticle::Thermostat_Berendsen(int Step, double ScaleTempFactor, double *ekin, config *configuration) 219 219 { 220 double *U = Trajectory.U.at(Step).x;220 Vector &U = Trajectory.U.at(Step); 221 221 if (FixedIon == 0) { // even FixedIon moves, only not by other's forces 222 222 for (int d=0; d<NDIM; d++) { … … 233 233 void TrajectoryParticle::Thermostat_NoseHoover_init(int Step, double *delta_alpha) 234 234 { 235 double *U = Trajectory.U.at(Step).x;235 Vector &U = Trajectory.U.at(Step); 236 236 if (FixedIon == 0) { // even FixedIon moves, only not by other's forces 237 237 for (int d=0; d<NDIM; d++) { … … 248 248 void TrajectoryParticle::Thermostat_NoseHoover_scale(int Step, double *ekin, config *configuration) 249 249 { 250 double *U = Trajectory.U.at(Step).x;250 Vector &U = Trajectory.U.at(Step); 251 251 if (FixedIon == 0) { // even FixedIon moves, only not by other's forces 252 252 for (int d=0; d<NDIM; d++) { -
src/bond.cpp
r632bc3 r8cbb97 119 119 double bond::GetDistance() const 120 120 { 121 return (leftatom->node->Distance( rightatom->node));121 return (leftatom->node->Distance(*rightatom->node)); 122 122 }; 123 123 … … 127 127 double bond::GetDistanceSquared() const 128 128 { 129 return (leftatom->node->DistanceSquared( rightatom->node));129 return (leftatom->node->DistanceSquared(*rightatom->node)); 130 130 }; -
src/boundary.cpp
r632bc3 r8cbb97 19 19 #include "tesselationhelpers.hpp" 20 20 #include "World.hpp" 21 #include "Plane.hpp" 21 22 22 23 #include<gsl/gsl_poly.h> … … 78 79 if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around 79 80 Neighbour = BoundaryPoints[axis].begin(); 80 DistanceVector.CopyVector(&runner->second.second->x); 81 DistanceVector.SubtractVector(&Neighbour->second.second->x); 81 DistanceVector = runner->second.second->x - Neighbour->second.second->x; 82 82 do { // seek for neighbour pair where it flips 83 OldComponent = DistanceVector .x[Othercomponent];83 OldComponent = DistanceVector[Othercomponent]; 84 84 Neighbour++; 85 85 if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around 86 86 Neighbour = BoundaryPoints[axis].begin(); 87 DistanceVector.CopyVector(&runner->second.second->x); 88 DistanceVector.SubtractVector(&Neighbour->second.second->x); 87 DistanceVector = runner->second.second->x - Neighbour->second.second->x; 89 88 //Log() << Verbose(2) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl; 90 89 } while ((runner != Neighbour) && (fabs(OldComponent / fabs( 91 OldComponent) - DistanceVector .x[Othercomponent] / fabs(92 DistanceVector .x[Othercomponent])) < MYEPSILON)); // as long as sign does not flip90 OldComponent) - DistanceVector[Othercomponent] / fabs( 91 DistanceVector[Othercomponent])) < MYEPSILON)); // as long as sign does not flip 93 92 if (runner != Neighbour) { 94 93 OtherNeighbour = Neighbour; … … 98 97 //Log() << Verbose(1) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl; 99 98 // now we have found the pair: Neighbour and OtherNeighbour 100 OtherVector.CopyVector(&runner->second.second->x); 101 OtherVector.SubtractVector(&OtherNeighbour->second.second->x); 99 OtherVector = runner->second.second->x - OtherNeighbour->second.second->x; 102 100 //Log() << Verbose(1) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl; 103 101 //Log() << Verbose(1) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl; 104 102 // do linear interpolation between points (is exact) to extract exact intersection between Neighbour and OtherNeighbour 105 w1 = fabs(OtherVector .x[Othercomponent]);106 w2 = fabs(DistanceVector .x[Othercomponent]);107 tmp = fabs((w1 * DistanceVector .x[component] + w2108 * OtherVector .x[component]) / (w1 + w2));103 w1 = fabs(OtherVector[Othercomponent]); 104 w2 = fabs(DistanceVector[Othercomponent]); 105 tmp = fabs((w1 * DistanceVector[component] + w2 106 * OtherVector[component]) / (w1 + w2)); 109 107 // mark if it has greater diameter 110 108 //Log() << Verbose(1) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl; … … 160 158 AngleReferenceVector.Zero(); 161 159 AngleReferenceNormalVector.Zero(); 162 AxisVector .x[axis] = 1.;163 AngleReferenceVector .x[(axis + 1) % NDIM] = 1.;164 AngleReferenceNormalVector .x[(axis + 2) % NDIM] = 1.;160 AxisVector[axis] = 1.; 161 AngleReferenceVector[(axis + 1) % NDIM] = 1.; 162 AngleReferenceNormalVector[(axis + 2) % NDIM] = 1.; 165 163 166 164 DoLog(1) && (Log() << Verbose(1) << "Axisvector is " << AxisVector << " and AngleReferenceVector is " << AngleReferenceVector << ", and AngleReferenceNormalVector is " << AngleReferenceNormalVector << "." << endl); … … 170 168 while (Walker->next != mol->end) { 171 169 Walker = Walker->next; 172 ProjectedVector.CopyVector(&Walker->x); 173 ProjectedVector.SubtractVector(MolCenter); 174 ProjectedVector.ProjectOntoPlane(&AxisVector); 170 ProjectedVector = Walker->x - (*MolCenter); 171 ProjectedVector.ProjectOntoPlane(AxisVector); 175 172 176 173 // correct for negative side 177 174 const double radius = ProjectedVector.NormSquared(); 178 175 if (fabs(radius) > MYEPSILON) 179 angle = ProjectedVector.Angle( &AngleReferenceVector);176 angle = ProjectedVector.Angle(AngleReferenceVector); 180 177 else 181 178 angle = 0.; // otherwise it's a vector in Axis Direction and unimportant for boundary issues 182 179 183 180 //Log() << Verbose(1) << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl; 184 if (ProjectedVector.ScalarProduct( &AngleReferenceNormalVector) > 0) {181 if (ProjectedVector.ScalarProduct(AngleReferenceNormalVector) > 0) { 185 182 angle = 2. * M_PI - angle; 186 183 } … … 197 194 DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl); 198 195 } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) { 199 helper.CopyVector(&Walker->x); 200 helper.SubtractVector(MolCenter); 196 helper = Walker->x - (*MolCenter); 201 197 const double oldhelperNorm = helper.NormSquared(); 202 helper.CopyVector(&BoundaryTestPair.first->second.second->x); 203 helper.SubtractVector(MolCenter); 198 helper = BoundaryTestPair.first->second.second->x - (*MolCenter); 204 199 if (helper.NormSquared() < oldhelperNorm) { 205 200 BoundaryTestPair.first->second.second = Walker; … … 251 246 { 252 247 Vector SideA, SideB, SideC, SideH; 253 SideA.CopyVector(&left->second.second->x); 254 SideA.SubtractVector(MolCenter); 255 SideA.ProjectOntoPlane(&AxisVector); 248 SideA = left->second.second->x - (*MolCenter); 249 SideA.ProjectOntoPlane(AxisVector); 256 250 // Log() << Verbose(1) << "SideA: " << SideA << endl; 257 251 258 SideB.CopyVector(&right->second.second->x); 259 SideB.SubtractVector(MolCenter); 260 SideB.ProjectOntoPlane(&AxisVector); 252 SideB = right->second.second->x -(*MolCenter); 253 SideB.ProjectOntoPlane(AxisVector); 261 254 // Log() << Verbose(1) << "SideB: " << SideB << endl; 262 255 263 SideC.CopyVector(&left->second.second->x); 264 SideC.SubtractVector(&right->second.second->x); 265 SideC.ProjectOntoPlane(&AxisVector); 256 SideC = left->second.second->x - right->second.second->x; 257 SideC.ProjectOntoPlane(AxisVector); 266 258 // Log() << Verbose(1) << "SideC: " << SideC << endl; 267 259 268 SideH.CopyVector(&runner->second.second->x); 269 SideH.SubtractVector(MolCenter); 270 SideH.ProjectOntoPlane(&AxisVector); 260 SideH = runner->second.second->x -(*MolCenter); 261 SideH.ProjectOntoPlane(AxisVector); 271 262 // Log() << Verbose(1) << "SideH: " << SideH << endl; 272 263 … … 277 268 const double h = SideH.Norm(); 278 269 // calculate the angles 279 const double alpha = SideA.Angle( &SideH);280 const double beta = SideA.Angle( &SideC);281 const double gamma = SideB.Angle( &SideH);282 const double delta = SideC.Angle( &SideH);270 const double alpha = SideA.Angle(SideH); 271 const double beta = SideA.Angle(SideC); 272 const double gamma = SideB.Angle(SideH); 273 const double delta = SideC.Angle(SideH); 283 274 const double MinDistance = a * sin(beta) / (sin(delta)) * (((alpha < M_PI / 2.) || (gamma < M_PI / 2.)) ? 1. : -1.); 284 275 //Log() << Verbose(1) << " I calculated: a = " << a << ", h = " << h << ", beta(" << left->second.second->Name << "," << left->second.second->Name << "-" << right->second.second->Name << ") = " << beta << ", delta(" << left->second.second->Name << "," << runner->second.second->Name << ") = " << delta << ", Min = " << MinDistance << "." << endl; … … 629 620 for (TriangleMap::iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++) 630 621 { // go through every triangle, calculate volume of its pyramid with CoG as peak 631 x.CopyVector(runner->second->endpoints[0]->node->node); 632 x.SubtractVector(runner->second->endpoints[1]->node->node); 633 y.CopyVector(runner->second->endpoints[0]->node->node); 634 y.SubtractVector(runner->second->endpoints[2]->node->node); 635 const double a = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(runner->second->endpoints[1]->node->node)); 636 const double b = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(runner->second->endpoints[2]->node->node)); 637 const double c = sqrt(runner->second->endpoints[2]->node->node->DistanceSquared(runner->second->endpoints[1]->node->node)); 622 x = (*runner->second->endpoints[0]->node->node) - (*runner->second->endpoints[1]->node->node); 623 y = (*runner->second->endpoints[0]->node->node) - (*runner->second->endpoints[2]->node->node); 624 const double a = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(*runner->second->endpoints[1]->node->node)); 625 const double b = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(*runner->second->endpoints[2]->node->node)); 626 const double c = sqrt(runner->second->endpoints[2]->node->node->DistanceSquared(*runner->second->endpoints[1]->node->node)); 638 627 const double G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle 639 x.MakeNormalVector(runner->second->endpoints[0]->node->node, runner->second->endpoints[1]->node->node, runner->second->endpoints[2]->node->node); 640 x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(&x)); 628 x = Plane(*(runner->second->endpoints[0]->node->node), 629 *(runner->second->endpoints[1]->node->node), 630 *(runner->second->endpoints[2]->node->node)).getNormal(); 631 x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(x)); 641 632 const double h = x.Norm(); // distance of CoG to triangle 642 633 const double PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak) … … 752 743 DoLog(0) && (Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl); 753 744 for (int i = 0; i < NDIM; i++) 754 BoxLengths .x[i] = GreatestDiameter[i];745 BoxLengths[i] = GreatestDiameter[i]; 755 746 mol->CenterEdge(&BoxLengths); 756 747 } else { 757 BoxLengths .x[0] = (repetition[0] * GreatestDiameter[0] + repetition[1] * GreatestDiameter[1] + repetition[2] * GreatestDiameter[2]);758 BoxLengths .x[1] = (repetition[0] * repetition[1] * GreatestDiameter[0] * GreatestDiameter[1] + repetition[0] * repetition[2] * GreatestDiameter[0] * GreatestDiameter[2] + repetition[1] * repetition[2] * GreatestDiameter[1] * GreatestDiameter[2]);759 BoxLengths .x[2] = minimumvolume - cellvolume;748 BoxLengths[0] = (repetition[0] * GreatestDiameter[0] + repetition[1] * GreatestDiameter[1] + repetition[2] * GreatestDiameter[2]); 749 BoxLengths[1] = (repetition[0] * repetition[1] * GreatestDiameter[0] * GreatestDiameter[1] + repetition[0] * repetition[2] * GreatestDiameter[0] * GreatestDiameter[2] + repetition[1] * repetition[2] * GreatestDiameter[1] * GreatestDiameter[2]); 750 BoxLengths[2] = minimumvolume - cellvolume; 760 751 double x0 = 0.; 761 752 double x1 = 0.; 762 753 double x2 = 0.; 763 if (gsl_poly_solve_cubic(BoxLengths .x[0], BoxLengths.x[1], BoxLengths.x[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return754 if (gsl_poly_solve_cubic(BoxLengths[0], BoxLengths[1], BoxLengths[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return 764 755 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl); 765 756 else { … … 770 761 cellvolume = 1.; 771 762 for (int i = 0; i < NDIM; i++) { 772 BoxLengths .x[i] = repetition[i] * (x0 + GreatestDiameter[i]);773 cellvolume *= BoxLengths .x[i];763 BoxLengths[i] = repetition[i] * (x0 + GreatestDiameter[i]); 764 cellvolume *= BoxLengths[i]; 774 765 } 775 766 … … 781 772 // update Box of atoms by boundary 782 773 mol->SetBoxDimension(&BoxLengths); 783 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting cell dimensions are: " << BoxLengths .x[0] << " and " << BoxLengths.x[1] << " and " << BoxLengths.x[2] << " with total volume of " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);774 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting cell dimensions are: " << BoxLengths[0] << " and " << BoxLengths[1] << " and " << BoxLengths[2] << " with total volume of " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl); 784 775 }; 785 776 … … 844 835 845 836 // calculate filler grid in [0,1]^3 846 FillerDistance .Init(distance[0], distance[1], distance[2]);837 FillerDistance = Vector(distance[0], distance[1], distance[2]); 847 838 FillerDistance.InverseMatrixMultiplication(M); 848 839 for(int i=0;i<NDIM;i++) 849 N[i] = (int) ceil(1./FillerDistance .x[i]);840 N[i] = (int) ceil(1./FillerDistance[i]); 850 841 DoLog(1) && (Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl); 851 842 … … 858 849 for (n[2] = 0; n[2] < N[2]; n[2]++) { 859 850 // calculate position of current grid vector in untransformed box 860 CurrentPosition .Init((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);851 CurrentPosition = Vector((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]); 861 852 CurrentPosition.MatrixMultiplication(M); 862 853 // create molecule random translation vector ... 863 854 for (int i=0;i<NDIM;i++) 864 FillerTranslations .x[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.);855 FillerTranslations[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.); 865 856 DoLog(2) && (Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "+" << FillerTranslations << "." << endl); 866 857 … … 874 865 // create atomic random translation vector ... 875 866 for (int i=0;i<NDIM;i++) 876 AtomTranslations .x[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.);867 AtomTranslations[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.); 877 868 878 869 // ... and rotation matrix … … 894 885 895 886 // ... and put at new position 896 Inserter .CopyVector(&(Walker->x));887 Inserter = Walker->x; 897 888 if (DoRandomRotation) 898 889 Inserter.MatrixMultiplication(Rotations); 899 Inserter.AddVector(&AtomTranslations); 900 Inserter.AddVector(&FillerTranslations); 901 Inserter.AddVector(&CurrentPosition); 890 Inserter += AtomTranslations + FillerTranslations + CurrentPosition; 902 891 903 892 // check whether inserter is inside box … … 905 894 FillIt = true; 906 895 for (int i=0;i<NDIM;i++) 907 FillIt = FillIt && (Inserter .x[i] >= -MYEPSILON) && ((Inserter.x[i]-1.) <= MYEPSILON);896 FillIt = FillIt && (Inserter[i] >= -MYEPSILON) && ((Inserter[i]-1.) <= MYEPSILON); 908 897 Inserter.MatrixMultiplication(M); 909 898 … … 921 910 // copy atom ... 922 911 CopyAtoms[Walker->nr] = Walker->clone(); 923 CopyAtoms[Walker->nr]->x .CopyVector(&Inserter);912 CopyAtoms[Walker->nr]->x = Inserter; 924 913 Filling->AddAtom(CopyAtoms[Walker->nr]); 925 914 DoLog(4) && (Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl); -
src/builder.cpp
r632bc3 r8cbb97 1741 1741 DoLog(2) && (Log() << Verbose(2) << "found element " << first->type->name << endl); 1742 1742 for (int i=NDIM;i--;) 1743 first->x .x[i] = atof(argv[argptr+1+i]);1743 first->x[i] = atof(argv[argptr+1+i]); 1744 1744 if (first->type != NULL) { 1745 1745 mol->AddAtom(first); // add to molecule … … 2013 2013 first = World::getInstance().createAtom(); 2014 2014 first->type = periode->FindElement(1); 2015 first->x .Init(0.441, -0.143, 0.);2015 first->x = Vector(0.441, -0.143, 0.); 2016 2016 filler->AddAtom(first); 2017 2017 second = World::getInstance().createAtom(); 2018 2018 second->type = periode->FindElement(1); 2019 second->x .Init(-0.464, 1.137, 0.0);2019 second->x = Vector(-0.464, 1.137, 0.0); 2020 2020 filler->AddAtom(second); 2021 2021 third = World::getInstance().createAtom(); 2022 2022 third->type = periode->FindElement(8); 2023 third->x .Init(-0.464, 0.177, 0.);2023 third->x = Vector(-0.464, 0.177, 0.); 2024 2024 filler->AddAtom(third); 2025 2025 filler->AddBond(first, third, 1); … … 2186 2186 first = second; 2187 2187 second = first->next; 2188 if (first->x.DistanceSquared( (const Vector *)&third->x) > tmp1*tmp1) // distance to first above radius ...2188 if (first->x.DistanceSquared(third->x) > tmp1*tmp1) // distance to first above radius ... 2189 2189 mol->RemoveAtom(first); 2190 2190 } … … 2206 2206 DoLog(1) && (Log() << Verbose(1) << "Translating all ions by given vector." << endl); 2207 2207 for (int i=NDIM;i--;) 2208 x .x[i] = atof(argv[argptr+i]);2208 x[i] = atof(argv[argptr+i]); 2209 2209 mol->Translate((const Vector *)&x); 2210 2210 argptr+=3; … … 2222 2222 DoLog(1) && (Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl); 2223 2223 for (int i=NDIM;i--;) 2224 x .x[i] = atof(argv[argptr+i]);2224 x[i] = atof(argv[argptr+i]); 2225 2225 mol->TranslatePeriodically((const Vector *)&x); 2226 2226 argptr+=3; … … 2245 2245 for (int i=0;i<NDIM;i++) { 2246 2246 j += i+1; 2247 x .x[i] = atof(argv[NDIM+i]);2247 x[i] = atof(argv[NDIM+i]); 2248 2248 cell_size[j]*=factor[i]; 2249 2249 } … … 2309 2309 for (int i=0;i<NDIM;i++) { 2310 2310 j += i+1; 2311 x .x[i] = atof(argv[argptr+i]);2312 cell_size[j] += x .x[i]*2.;2311 x[i] = atof(argv[argptr+i]); 2312 cell_size[j] += x[i]*2.; 2313 2313 } 2314 2314 mol->Translate((const Vector *)&x); … … 2468 2468 x.Zero(); 2469 2469 y.Zero(); 2470 y .x[abs(axis)-1] = cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude2470 y[abs(axis)-1] = cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude 2471 2471 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times 2472 x .AddVector(&y); // per factor one cell width further2472 x += y; // per factor one cell width further 2473 2473 for (int k=count;k--;) { // go through every atom of the original cell 2474 2474 first = World::getInstance().createAtom(); // create a new body 2475 first->x.CopyVector(vectors[k]); // use coordinate of original atom 2476 first->x.AddVector(&x); // translate the coordinates 2475 first->x = (*vectors[k]) + x; 2477 2476 first->type = Elements[k]; // insert original element 2478 2477 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) … … 2484 2483 // correct cell size 2485 2484 if (axis < 0) { // if sign was negative, we have to translate everything 2486 x.Zero(); 2487 x.AddVector(&y); 2488 x.Scale(-(faktor-1)); 2485 x =(-(faktor-1)) * y; 2489 2486 mol->Translate(&x); 2490 2487 } -
src/config.cpp
r632bc3 r8cbb97 742 742 neues = AtomList[i][j]; 743 743 status = (status && 744 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x .x[0], 1, (repetition == 0) ? critical : optional) &&745 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x .x[1], 1, (repetition == 0) ? critical : optional) &&746 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x .x[2], 1, (repetition == 0) ? critical : optional) &&744 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x[0], 1, (repetition == 0) ? critical : optional) && 745 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x[1], 1, (repetition == 0) ? critical : optional) && 746 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x[2], 1, (repetition == 0) ? critical : optional) && 747 747 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional)); 748 748 if (!status) break; … … 758 758 // put into trajectories list 759 759 for (int d=0;d<NDIM;d++) 760 neues->Trajectory.R.at(repetition) .x[d] = neues->x.x[d];760 neues->Trajectory.R.at(repetition)[d] = neues->x[d]; 761 761 762 762 // parse velocities if present 763 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v .x[0], 1,optional))764 neues->v .x[0] = 0.;765 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v .x[1], 1,optional))766 neues->v .x[1] = 0.;767 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v .x[2], 1,optional))768 neues->v .x[2] = 0.;763 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v[0], 1,optional)) 764 neues->v[0] = 0.; 765 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v[1], 1,optional)) 766 neues->v[1] = 0.; 767 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v[2], 1,optional)) 768 neues->v[2] = 0.; 769 769 for (int d=0;d<NDIM;d++) 770 neues->Trajectory.U.at(repetition) .x[d] = neues->v.x[d];770 neues->Trajectory.U.at(repetition)[d] = neues->v[d]; 771 771 772 772 // parse forces if present … … 778 778 value[2] = 0.; 779 779 for (int d=0;d<NDIM;d++) 780 neues->Trajectory.F.at(repetition) .x[d] = value[d];780 neues->Trajectory.F.at(repetition)[d] = value[d]; 781 781 782 782 // Log() << Verbose(0) << "Parsed position of step " << (repetition) << ": ("; … … 821 821 neues = AtomList[i][j]; 822 822 // then parse for each atom the coordinates as often as present 823 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x .x[0], repetition,critical);824 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x .x[1], repetition,critical);825 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x .x[2], repetition,critical);823 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x[0], repetition,critical); 824 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x[1], repetition,critical); 825 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x[2], repetition,critical); 826 826 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical); 827 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v .x[0], repetition,optional))828 neues->v .x[0] = 0.;829 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v .x[1], repetition,optional))830 neues->v .x[1] = 0.;831 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v .x[2], repetition,optional))832 neues->v .x[2] = 0.;827 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v[0], repetition,optional)) 828 neues->v[0] = 0.; 829 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v[1], repetition,optional)) 830 neues->v[1] = 0.; 831 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v[2], repetition,optional)) 832 neues->v[2] = 0.; 833 833 // here we don't care if forces are present (last in trajectories is always equal to current position) 834 834 neues->type = elementhash[i]; // find element type … … 1293 1293 istringstream input2(zeile); 1294 1294 atom *neues = World::getInstance().createAtom(); 1295 input2 >> neues->x .x[0]; // x1296 input2 >> neues->x .x[1]; // y1297 input2 >> neues->x .x[2]; // z1295 input2 >> neues->x[0]; // x 1296 input2 >> neues->x[1]; // y 1297 input2 >> neues->x[2]; // z 1298 1298 input2 >> l; 1299 1299 neues->type = elementhash[No]; // find element type … … 1575 1575 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */ 1576 1576 MolNo, /* residue sequence number */ 1577 Walker->node-> x[0], /* position X in Angstroem */1578 Walker->node-> x[1], /* position Y in Angstroem */1579 Walker->node-> x[2], /* position Z in Angstroem */1577 Walker->node->at(0), /* position X in Angstroem */ 1578 Walker->node->at(1), /* position Y in Angstroem */ 1579 Walker->node->at(2), /* position Z in Angstroem */ 1580 1580 (double)Walker->type->Valence, /* occupancy */ 1581 1581 (double)Walker->type->NoValenceOrbitals, /* temperature factor */ … … 1629 1629 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */ 1630 1630 0, /* residue sequence number */ 1631 Walker->node-> x[0], /* position X in Angstroem */1632 Walker->node-> x[1], /* position Y in Angstroem */1633 Walker->node-> x[2], /* position Z in Angstroem */1631 Walker->node->at(0), /* position X in Angstroem */ 1632 Walker->node->at(1), /* position Y in Angstroem */ 1633 Walker->node->at(2), /* position Z in Angstroem */ 1634 1634 (double)Walker->type->Valence, /* occupancy */ 1635 1635 (double)Walker->type->NoValenceOrbitals, /* temperature factor */ … … 1683 1683 *output << mol->name << "\t"; 1684 1684 *output << 0 << "\t"; 1685 *output << Walker->node-> x[0] << "\t" << Walker->node->x[1] << "\t" << Walker->node->x[2]<< "\t";1686 *output << (double)Walker->type->Valence<< "\t";1685 *output << Walker->node->at(0) << "\t" << Walker->node->at(1) << "\t" << Walker->node->at(2) << "\t"; 1686 *output << static_cast<double>(Walker->type->Valence) << "\t"; 1687 1687 *output << Walker->type->symbol << "\t"; 1688 1688 for (BondList::iterator runner = Walker->ListOfBonds.begin(); runner != Walker->ListOfBonds.end(); runner++) … … 1759 1759 *output << (*MolWalker)->name << "\t"; 1760 1760 *output << MolCounter+1 << "\t"; 1761 *output << Walker->node-> x[0] << "\t" << Walker->node->x[1] << "\t" << Walker->node->x[2]<< "\t";1761 *output << Walker->node->at(0) << "\t" << Walker->node->at(1) << "\t" << Walker->node->at(2) << "\t"; 1762 1762 *output << (double)Walker->type->Valence << "\t"; 1763 1763 *output << Walker->type->symbol << "\t"; -
src/ellipsoid.cpp
r632bc3 r8cbb97 42 42 43 43 // 1. translate coordinate system so that ellipsoid center is in origin 44 helper.CopyVector(&x); 45 helper.SubtractVector(&EllipsoidCenter); 46 RefPoint.CopyVector(&helper); 44 RefPoint = helper = x - EllipsoidCenter; 47 45 //Log() << Verbose(4) << "Translated given point is at " << RefPoint << "." << endl; 48 46 … … 61 59 Matrix[8] = cos(theta); 62 60 helper.MatrixMultiplication(Matrix); 63 helper.Scale (InverseLength);61 helper.ScaleAll(InverseLength); 64 62 //Log() << Verbose(4) << "Transformed RefPoint is at " << helper << "." << endl; 65 63 … … 72 70 theta = -EllipsoidAngle[1]; 73 71 phi = -EllipsoidAngle[2]; 74 helper.Scale (EllipsoidLength);72 helper.ScaleAll(EllipsoidLength); 75 73 Matrix[0] = cos(psi)*cos(phi) - sin(psi)*cos(theta)*sin(phi); 76 74 Matrix[1] = -cos(psi)*sin(phi) - sin(psi)*cos(theta)*cos(phi); … … 86 84 87 85 // 5. determine distance between backtransformed point and x 88 distance = RefPoint.DistanceSquared( &helper);86 distance = RefPoint.DistanceSquared(helper); 89 87 //Log() << Verbose(4) << "Squared distance between intersection and RefPoint is " << distance << "." << endl; 90 88 … … 116 114 // put parameters into suitable ellipsoid form 117 115 for (int i=0;i<3;i++) { 118 Center .x[i] = gsl_vector_get(x, i+0);116 Center[i] = gsl_vector_get(x, i+0); 119 117 EllipsoidLength[i] = gsl_vector_get(x, i+3); 120 118 EllipsoidAngle[i] = gsl_vector_get(x, i+6); … … 160 158 x = gsl_vector_alloc (9); 161 159 for (int i=0;i<3;i++) { 162 gsl_vector_set (x, i+0, EllipsoidCenter-> x[i]);160 gsl_vector_set (x, i+0, EllipsoidCenter->at(i)); 163 161 gsl_vector_set (x, i+3, EllipsoidLength[i]); 164 162 gsl_vector_set (x, i+6, EllipsoidAngle[i]); … … 195 193 if (status == GSL_SUCCESS) { 196 194 for (int i=0;i<3;i++) { 197 EllipsoidCenter-> x[i]= gsl_vector_get (s->x,i+0);195 EllipsoidCenter->at(i) = gsl_vector_get (s->x,i+0); 198 196 EllipsoidLength[i] = gsl_vector_get (s->x, i+3); 199 197 EllipsoidAngle[i] = gsl_vector_get (s->x, i+6); … … 304 302 Candidate = (*Runner); 305 303 DoLog(2) && (Log() << Verbose(2) << "Current picked node is " << **Runner << " with index " << index << "." << endl); 306 x[PointsPicked++] .CopyVector(Candidate->node); // we have one more atom picked304 x[PointsPicked++] = *Candidate->node; // we have one more atom picked 307 305 current++; // next pre-picked atom 308 306 } … … 350 348 //Log() << Verbose(3) << "Current node is " << *Runner->second->node << " with " << value << " ... " << threshold << ": "; 351 349 if (value > threshold) { 352 x[PointsPicked] .CopyVector(Runner->second->node->node);350 x[PointsPicked] = (*Runner->second->node->node); 353 351 PointsPicked++; 354 352 //Log() << Verbose(0) << "IN." << endl; … … 387 385 Center.Zero(); 388 386 for (PointMap::iterator Runner = T->PointsOnBoundary.begin(); Runner != T->PointsOnBoundary.end(); Runner++) 389 Center .AddVector(Runner->second->node->node);387 Center += (*Runner->second->node->node); 390 388 Center.Scale(1./T->PointsOnBoundaryCount); 391 389 DoLog(1) && (Log() << Verbose(1) << "Center is at " << Center << "." << endl); … … 405 403 // calculate some sensible starting values for parameter fit 406 404 MaxDistance = 0.; 407 MinDistance = x[0].ScalarProduct( &x[0]);405 MinDistance = x[0].ScalarProduct(x[0]); 408 406 for (int i=0;i<N;i++) { 409 distance = x[i].ScalarProduct( &x[i]);407 distance = x[i].ScalarProduct(x[i]); 410 408 if (distance > MaxDistance) 411 409 MaxDistance = distance; … … 414 412 } 415 413 //Log() << Verbose(2) << "MinDistance " << MinDistance << ", MaxDistance " << MaxDistance << "." << endl; 416 EllipsoidCenter .CopyVector(&Center); // use Center of Gravity as initial center of ellipsoid414 EllipsoidCenter = Center; // use Center of Gravity as initial center of ellipsoid 417 415 for (int i=0;i<3;i++) 418 416 EllipsoidAngle[i] = 0.; … … 427 425 output << number << "\t"; 428 426 for (int i=0;i<3;i++) 429 output << setprecision(9) << EllipsoidCenter .x[i] << "\t";427 output << setprecision(9) << EllipsoidCenter[i] << "\t"; 430 428 for (int i=0;i<3;i++) 431 429 output << setprecision(9) << EllipsoidLength[i] << "\t"; -
src/gslmatrix.cpp
r632bc3 r8cbb97 10 10 #include "gslmatrix.hpp" 11 11 #include "helpers.hpp" 12 #include "Helpers/fast_functions.hpp" 12 13 13 14 #include <cassert> -
src/helpers.cpp
r632bc3 r8cbb97 6 6 7 7 #include "helpers.hpp" 8 #include "Helpers/fast_functions.hpp" 8 9 #include "log.hpp" 9 10 #include "memoryusageobserver.hpp" … … 49 50 while (*b < lower_bound) 50 51 *b += step; 51 };52 53 /** Returns the power of \a n with respect to \a base.54 * \param base basis55 * \param n power56 * \return \f$base^n\f$57 */58 int pot(int base, int n)59 {60 int res = 1;61 int j;62 for (j=n;j--;)63 res *= base;64 return res;65 52 }; 66 53 … … 175 162 }; 176 163 177 /** hard-coded determinant of a 3x3 matrix. 178 * \param a[9] matrix 179 * \return \f$det(a)\f$ 180 */ 181 double RDET3(const double a[NDIM*NDIM]) 182 { 183 return ((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]); 184 }; 185 186 /** hard-coded determinant of a 2x2 matrix. 187 * \param a[4] matrix 188 * \return \f$det(a)\f$ 189 */ 190 double RDET2(const double a[4]) 191 { 192 return ((a[0])*(a[3])-(a[1])*(a[2])); 193 }; 194 195 /** hard-coded determinant of a 2x2 matrix. 196 * \param a0 (0,0) entry of matrix 197 * \param a1 (0,1) entry of matrix 198 * \param a2 (1,0) entry of matrix 199 * \param a3 (1,1) entry of matrix 200 * \return \f$det(a)\f$ 201 */ 202 double RDET2(const double a0, const double a1, const double a2, const double a3) 203 { 204 return ((a0)*(a3)-(a1)*(a2)); 205 }; 164 206 165 207 166 /** Comparison function for GSL heapsort on distances in two molecules. -
src/helpers.hpp
r632bc3 r8cbb97 24 24 /********************************************** definitions *********************************/ 25 25 26 // some algebraic matrix stuff27 double RDET3(const double a[NDIM*NDIM]);28 double RDET2(const double a[4]);29 double RDET2(const double a0, const double a1, const double a2, const double a3);30 31 26 /********************************************** helpful functions *********************************/ 32 27 … … 53 48 bool check_bounds(double *x, double *cell_size); 54 49 void bound(double *b, double lower_bound, double upper_bound); 55 int pot(int base, int n);56 50 int CountLinesinFile(ifstream &InputFile); 57 51 char *FixedDigitNumber(const int FragmentNumber, const int digits); … … 64 58 /********************************************** helpful template functions *********************************/ 65 59 66 /** Flips two values.67 * \param x first value68 * \param y second value69 */70 template <typename T> void flip(T &x, T &y)71 {72 T tmp;73 tmp = x;74 x = y;75 y = tmp;76 };77 60 78 61 /** returns greater of the two values. -
src/leastsquaremin.cpp
r632bc3 r8cbb97 25 25 for (int i=num;i--;) { 26 26 for(int j=NDIM;j--;) 27 sum += (gsl_vector_get(x,j) - (vectors[i])-> x[j])*(gsl_vector_get(x,j) - (vectors[i])->x[j]);27 sum += (gsl_vector_get(x,j) - (vectors[i])->at(j))*(gsl_vector_get(x,j) - (vectors[i])->at(j)); 28 28 } 29 29 -
src/linearsystemofequations.cpp
r632bc3 r8cbb97 54 54 { 55 55 assert ( columns == NDIM && "Vector class is always three-dimensional, unlike this LEqS!"); 56 b->SetFromDoubleArray(x-> x);56 b->SetFromDoubleArray(x->get()); 57 57 }; 58 58 … … 100 100 // copy solution 101 101 for (size_t i=0;i<x->dimension;i++) 102 v .x[i] = x->Get(i);102 v[i] = x->Get(i); 103 103 return status; 104 104 }; -
src/linkedcell.cpp
r632bc3 r8cbb97 54 54 Walker = set->GetPoint(); 55 55 for (int i=0;i<NDIM;i++) { 56 max .x[i] = Walker->node->x[i];57 min .x[i] = Walker->node->x[i];56 max[i] = Walker->node->at(i); 57 min[i] = Walker->node->at(i); 58 58 } 59 59 set->GoToFirst(); … … 61 61 Walker = set->GetPoint(); 62 62 for (int i=0;i<NDIM;i++) { 63 if (max .x[i] < Walker->node->x[i])64 max .x[i] = Walker->node->x[i];65 if (min .x[i] > Walker->node->x[i])66 min .x[i] = Walker->node->x[i];63 if (max[i] < Walker->node->at(i)) 64 max[i] = Walker->node->at(i); 65 if (min[i] > Walker->node->at(i)) 66 min[i] = Walker->node->at(i); 67 67 } 68 68 set->GoToNext(); … … 72 72 // 2. find then number of cells per axis 73 73 for (int i=0;i<NDIM;i++) { 74 N[i] = (int)floor((max.x[i] - min.x[i])/RADIUS)+1;74 N[i] = static_cast<int>(floor((max[i] - min[i])/RADIUS)+1); 75 75 } 76 76 DoLog(2) && (Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl); … … 94 94 Walker = set->GetPoint(); 95 95 for (int i=0;i<NDIM;i++) { 96 n[i] = (int)floor((Walker->node->x[i] - min.x[i])/RADIUS);96 n[i] = static_cast<int>(floor((Walker->node->at(i) - min[i])/RADIUS)); 97 97 } 98 98 index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2]; … … 128 128 LinkedNodes::iterator Runner = set->begin(); 129 129 for (int i=0;i<NDIM;i++) { 130 max .x[i] = (*Runner)->node->x[i];131 min .x[i] = (*Runner)->node->x[i];130 max[i] = (*Runner)->node->at(i); 131 min[i] = (*Runner)->node->at(i); 132 132 } 133 133 for (LinkedNodes::iterator Runner = set->begin(); Runner != set->end(); Runner++) { 134 134 Walker = *Runner; 135 135 for (int i=0;i<NDIM;i++) { 136 if (max .x[i] < Walker->node->x[i])137 max .x[i] = Walker->node->x[i];138 if (min .x[i] > Walker->node->x[i])139 min .x[i] = Walker->node->x[i];136 if (max[i] < Walker->node->at(i)) 137 max[i] = Walker->node->at(i); 138 if (min[i] > Walker->node->at(i)) 139 min[i] = Walker->node->at(i); 140 140 } 141 141 } … … 144 144 // 2. find then number of cells per axis 145 145 for (int i=0;i<NDIM;i++) { 146 N[i] = (int)floor((max.x[i] - min.x[i])/RADIUS)+1;146 N[i] = static_cast<int>(floor((max[i] - min[i])/RADIUS)+1); 147 147 } 148 148 DoLog(2) && (Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl); … … 165 165 Walker = *Runner; 166 166 for (int i=0;i<NDIM;i++) { 167 n[i] = (int)floor((Walker->node->x[i] - min.x[i])/RADIUS);167 n[i] = static_cast<int>(floor((Walker->node->at(i) - min[i])/RADIUS)); 168 168 } 169 169 index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2]; … … 251 251 { 252 252 for (int i=0;i<NDIM;i++) 253 n[i] = (int)floor((x-> x[i] - min.x[i])/RADIUS);253 n[i] = (int)floor((x->at(i) - min[i])/RADIUS); 254 254 255 255 return CheckBounds(); … … 264 264 bool status = false; 265 265 for (int i=0;i<NDIM;i++) { 266 n[i] = (int)floor((Walker->node->x[i] - min.x[i])/RADIUS);266 n[i] = static_cast<int>(floor((Walker->node->at(i) - min[i])/RADIUS)); 267 267 } 268 268 index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2]; … … 340 340 { 341 341 for (int i=0;i<NDIM;i++) { 342 n[i] = (int)floor((x-> x[i] - min.x[i])/RADIUS);342 n[i] = (int)floor((x->at(i) - min[i])/RADIUS); 343 343 if (n[i] < 0) 344 344 n[i] = 0; … … 356 356 Vector center; // center of the closest cell 357 357 for (int i=0;i<NDIM;i++) 358 center .x[i] = min.x[i]+((double)n[i]+.5)*RADIUS;358 center[i] = min[i]+((double)n[i]+.5)*RADIUS; 359 359 360 360 int c[NDIM]; … … 364 364 // set up corner 365 365 for (int i=0;i<NDIM;i++) 366 corner .x[i] = min.x[i]+RADIUS*((double)n[i]+c[i]);366 corner[i] = min[i]+RADIUS*((double)n[i]+c[i]); 367 367 // set up distance vector 368 Distance.CopyVector(x); 369 Distance.SubtractVector(&corner); 368 Distance = (*x) - corner; 370 369 const double dist = Distance.NormSquared(); 371 370 // check whether distance is smaller … … 373 372 distanceSquared = dist; 374 373 // check whether distance vector goes inside or outside 375 tester.CopyVector(¢er); 376 tester.SubtractVector(&corner); 377 if (tester.ScalarProduct(&Distance) < 0) 374 tester = center -corner; 375 if (tester.ScalarProduct(Distance) < 0) 378 376 outside = false; 379 377 } … … 408 406 Walker = *Runner; 409 407 //Log() << Verbose(1) << "Current neighbour is at " << *Walker->node << "." << endl; 410 if ((center->DistanceSquared( Walker->node) - radiusSquared) < MYEPSILON) {408 if ((center->DistanceSquared(*Walker->node) - radiusSquared) < MYEPSILON) { 411 409 TesselList->push_back(Walker); 412 410 } -
src/molecule.cpp
r632bc3 r8cbb97 26 26 #include "vector.hpp" 27 27 #include "World.hpp" 28 #include "Plane.hpp" 29 #include "Exceptions/LinearDependenceException.hpp" 30 28 31 29 32 /************************************* Functions for class molecule *********************************/ … … 218 221 // Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl; 219 222 // create vector in direction of bond 220 InBondvector.CopyVector(&TopReplacement->x); 221 InBondvector.SubtractVector(&TopOrigin->x); 223 InBondvector = TopReplacement->x - TopOrigin->x; 222 224 bondlength = InBondvector.Norm(); 223 225 … … 231 233 Orthovector1.Zero(); 232 234 for (int i=NDIM;i--;) { 233 l = TopReplacement->x .x[i] - TopOrigin->x.x[i];235 l = TopReplacement->x[i] - TopOrigin->x[i]; 234 236 if (fabs(l) > BondDistance) { // is component greater than bond distance 235 Orthovector1 .x[i] = (l < 0) ? -1. : +1.;237 Orthovector1[i] = (l < 0) ? -1. : +1.; 236 238 } // (signs are correct, was tested!) 237 239 } 238 240 matrix = ReturnFullMatrixforSymmetric(cell_size); 239 241 Orthovector1.MatrixMultiplication(matrix); 240 InBondvector .SubtractVector(&Orthovector1); // subtract just the additional translation242 InBondvector -= Orthovector1; // subtract just the additional translation 241 243 Free(&matrix); 242 244 bondlength = InBondvector.Norm(); … … 263 265 FirstOtherAtom = World::getInstance().createAtom(); // new atom 264 266 FirstOtherAtom->type = elemente->FindElement(1); // element is Hydrogen 265 FirstOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity267 FirstOtherAtom->v = TopReplacement->v; // copy velocity 266 268 FirstOtherAtom->FixedIon = TopReplacement->FixedIon; 267 269 if (TopReplacement->type->Z == 1) { // neither rescale nor replace if it's already hydrogen … … 271 273 FirstOtherAtom->father = NULL; // if we replace hydrogen, we mark it as our father, otherwise we are just an added hydrogen with no father 272 274 } 273 InBondvector .Scale(&BondRescale); // rescale the distance vector to Hydrogen bond length274 FirstOtherAtom->x .CopyVector(&TopOrigin->x); // set coordination to origin ...275 FirstOtherAtom->x .AddVector(&InBondvector); // ... and add distance vector to replacement atom275 InBondvector *= BondRescale; // rescale the distance vector to Hydrogen bond length 276 FirstOtherAtom->x = TopOrigin->x; // set coordination to origin ... 277 FirstOtherAtom->x = InBondvector; // ... and add distance vector to replacement atom 276 278 AllWentWell = AllWentWell && AddAtom(FirstOtherAtom); 277 279 // Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: "; … … 305 307 306 308 // determine the plane of these two with the *origin 307 AllWentWell = AllWentWell && Orthovector1.MakeNormalVector(&TopOrigin->x, &FirstOtherAtom->x, &SecondOtherAtom->x); 309 try { 310 Orthovector1 =Plane(TopOrigin->x, FirstOtherAtom->x, SecondOtherAtom->x).getNormal(); 311 } 312 catch(LinearDependenceException &excp){ 313 Log() << Verbose(0) << excp; 314 // TODO: figure out what to do with the Orthovector in this case 315 AllWentWell = false; 316 } 308 317 } else { 309 Orthovector1.GetOneNormalVector( &InBondvector);318 Orthovector1.GetOneNormalVector(InBondvector); 310 319 } 311 320 //Log() << Verbose(3)<< "Orthovector1: "; … … 313 322 //Log() << Verbose(0) << endl; 314 323 // orthogonal vector and bond vector between origin and replacement form the new plane 315 Orthovector1.MakeNormal Vector(&InBondvector);324 Orthovector1.MakeNormalTo(InBondvector); 316 325 Orthovector1.Normalize(); 317 326 //Log() << Verbose(3) << "ReScaleCheck: " << Orthovector1.Norm() << " and " << InBondvector.Norm() << "." << endl; … … 322 331 FirstOtherAtom->type = elemente->FindElement(1); 323 332 SecondOtherAtom->type = elemente->FindElement(1); 324 FirstOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity333 FirstOtherAtom->v = TopReplacement->v; // copy velocity 325 334 FirstOtherAtom->FixedIon = TopReplacement->FixedIon; 326 SecondOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity335 SecondOtherAtom->v = TopReplacement->v; // copy velocity 327 336 SecondOtherAtom->FixedIon = TopReplacement->FixedIon; 328 337 FirstOtherAtom->father = NULL; // we are just an added hydrogen with no father … … 345 354 SecondOtherAtom->x.Zero(); 346 355 for(int i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondvector is bondangle = 0 direction) 347 FirstOtherAtom->x .x[i] = InBondvector.x[i] * cos(bondangle) + Orthovector1.x[i] * (sin(bondangle));348 SecondOtherAtom->x .x[i] = InBondvector.x[i] * cos(bondangle) + Orthovector1.x[i] * (-sin(bondangle));349 } 350 FirstOtherAtom->x .Scale(&BondRescale); // rescale by correct BondDistance351 SecondOtherAtom->x .Scale(&BondRescale);356 FirstOtherAtom->x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (sin(bondangle)); 357 SecondOtherAtom->x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle)); 358 } 359 FirstOtherAtom->x *= BondRescale; // rescale by correct BondDistance 360 SecondOtherAtom->x *= BondRescale; 352 361 //Log() << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl; 353 362 for(int i=NDIM;i--;) { // and make relative to origin atom 354 FirstOtherAtom->x .x[i] += TopOrigin->x.x[i];355 SecondOtherAtom->x .x[i] += TopOrigin->x.x[i];363 FirstOtherAtom->x[i] += TopOrigin->x[i]; 364 SecondOtherAtom->x[i] += TopOrigin->x[i]; 356 365 } 357 366 // ... and add to molecule … … 379 388 SecondOtherAtom->type = elemente->FindElement(1); 380 389 ThirdOtherAtom->type = elemente->FindElement(1); 381 FirstOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity390 FirstOtherAtom->v = TopReplacement->v; // copy velocity 382 391 FirstOtherAtom->FixedIon = TopReplacement->FixedIon; 383 SecondOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity392 SecondOtherAtom->v = TopReplacement->v; // copy velocity 384 393 SecondOtherAtom->FixedIon = TopReplacement->FixedIon; 385 ThirdOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity394 ThirdOtherAtom->v = TopReplacement->v; // copy velocity 386 395 ThirdOtherAtom->FixedIon = TopReplacement->FixedIon; 387 396 FirstOtherAtom->father = NULL; // we are just an added hydrogen with no father … … 390 399 391 400 // we need to vectors orthonormal the InBondvector 392 AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector( &InBondvector);401 AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(InBondvector); 393 402 // Log() << Verbose(3) << "Orthovector1: "; 394 403 // Orthovector1.Output(out); 395 404 // Log() << Verbose(0) << endl; 396 AllWentWell = AllWentWell && Orthovector2.MakeNormalVector(&InBondvector, &Orthovector1); 405 try{ 406 Orthovector2 = Plane(InBondvector, Orthovector1,0).getNormal(); 407 } 408 catch(LinearDependenceException &excp) { 409 Log() << Verbose(0) << excp; 410 AllWentWell = false; 411 } 397 412 // Log() << Verbose(3) << "Orthovector2: "; 398 413 // Orthovector2.Output(out); … … 411 426 factors[1] = f; 412 427 factors[2] = 0.; 413 FirstOtherAtom->x.LinearCombinationOfVectors( &InBondvector, &Orthovector1, &Orthovector2, factors);428 FirstOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); 414 429 factors[1] = -0.5*f; 415 430 factors[2] = g; 416 SecondOtherAtom->x.LinearCombinationOfVectors( &InBondvector, &Orthovector1, &Orthovector2, factors);431 SecondOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); 417 432 factors[2] = -g; 418 ThirdOtherAtom->x.LinearCombinationOfVectors( &InBondvector, &Orthovector1, &Orthovector2, factors);433 ThirdOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); 419 434 420 435 // rescale each to correct BondDistance … … 424 439 425 440 // and relative to *origin atom 426 FirstOtherAtom->x .AddVector(&TopOrigin->x);427 SecondOtherAtom->x .AddVector(&TopOrigin->x);428 ThirdOtherAtom->x .AddVector(&TopOrigin->x);441 FirstOtherAtom->x += TopOrigin->x; 442 SecondOtherAtom->x += TopOrigin->x; 443 ThirdOtherAtom->x += TopOrigin->x; 429 444 430 445 // ... and add to molecule … … 514 529 } 515 530 for(j=NDIM;j--;) { 516 Walker->x .x[j] = x[j];517 Walker->Trajectory.R.at(MDSteps-1) .x[j] = x[j];518 Walker->Trajectory.U.at(MDSteps-1) .x[j] = 0;519 Walker->Trajectory.F.at(MDSteps-1) .x[j] = 0;531 Walker->x[j] = x[j]; 532 Walker->Trajectory.R.at(MDSteps-1)[j] = x[j]; 533 Walker->Trajectory.U.at(MDSteps-1)[j] = 0; 534 Walker->Trajectory.F.at(MDSteps-1)[j] = 0; 520 535 } 521 536 AddAtom(Walker); // add to molecule … … 662 677 { 663 678 double * const cell_size = World::getInstance().getDomain(); 664 cell_size[0] = dim-> x[0];679 cell_size[0] = dim->at(0); 665 680 cell_size[1] = 0.; 666 cell_size[2] = dim-> x[1];681 cell_size[2] = dim->at(1); 667 682 cell_size[3] = 0.; 668 683 cell_size[4] = 0.; 669 cell_size[5] = dim-> x[2];684 cell_size[5] = dim->at(2); 670 685 }; 671 686 … … 757 772 for (int i=0;i<NDIM;i++) { 758 773 j += i+1; 759 result = result && ((x-> x[i] >= 0) && (x->x[i]< cell_size[j]));774 result = result && ((x->at(i) >= 0) && (x->at(i) < cell_size[j])); 760 775 } 761 776 //return result; … … 1007 1022 DeterminePeriodicCenter(CenterOfGravity); 1008 1023 OtherMolecule->DeterminePeriodicCenter(OtherCenterOfGravity); 1009 DoLog(5) && (Log() << Verbose(5) << "Center of Gravity: "); 1010 CenterOfGravity.Output(); 1011 DoLog(0) && (Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: "); 1012 OtherCenterOfGravity.Output(); 1013 DoLog(0) && (Log() << Verbose(0) << endl); 1014 if (CenterOfGravity.DistanceSquared(&OtherCenterOfGravity) > threshold*threshold) { 1024 DoLog(5) && (Log() << Verbose(5) << "Center of Gravity: " << CenterOfGravity << endl); 1025 DoLog(5) && (Log() << Verbose(5) << "Other Center of Gravity: " << OtherCenterOfGravity << endl); 1026 if (CenterOfGravity.DistanceSquared(OtherCenterOfGravity) > threshold*threshold) { 1015 1027 DoLog(4) && (Log() << Verbose(4) << "Centers of gravity don't match." << endl); 1016 1028 result = false; -
src/molecule.hpp
r632bc3 r8cbb97 144 144 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T), T t ) const; 145 145 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T) const, T t ) const; 146 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T&), T &t ) const; 147 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T&) const, T &t ) const; 146 148 template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const; 147 149 template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const; -
src/molecule_dynamics.cpp
r632bc3 r8cbb97 14 14 #include "molecule.hpp" 15 15 #include "parser.hpp" 16 #include "Plane.hpp" 16 17 17 18 /************************************* Functions for class molecule *********************************/ … … 38 39 // determine normalized trajectories direction vector (n1, n2) 39 40 Sprinter = Params.PermutationMap[Walker->nr]; // find first target point 40 trajectory1.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); 41 trajectory1.SubtractVector(&Walker->Trajectory.R.at(Params.startstep)); 41 trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep); 42 42 trajectory1.Normalize(); 43 43 Norm1 = trajectory1.Norm(); 44 44 Sprinter = Params.PermutationMap[Runner->nr]; // find second target point 45 trajectory2.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); 46 trajectory2.SubtractVector(&Runner->Trajectory.R.at(Params.startstep)); 45 trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep); 47 46 trajectory2.Normalize(); 48 47 Norm2 = trajectory1.Norm(); 49 48 // check whether either is zero() 50 49 if ((Norm1 < MYEPSILON) && (Norm2 < MYEPSILON)) { 51 tmp = Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.startstep));50 tmp = Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.startstep)); 52 51 } else if (Norm1 < MYEPSILON) { 53 52 Sprinter = Params.PermutationMap[Walker->nr]; // find first target point 54 trajectory1.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); // copy first offset 55 trajectory1.SubtractVector(&Runner->Trajectory.R.at(Params.startstep)); // subtract second offset 56 trajectory2.Scale( trajectory1.ScalarProduct(&trajectory2) ); // trajectory2 is scaled to unity, hence we don't need to divide by anything 57 trajectory1.SubtractVector(&trajectory2); // project the part in norm direction away 53 trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep); 54 trajectory2 *= trajectory1.ScalarProduct(trajectory2); // trajectory2 is scaled to unity, hence we don't need to divide by anything 55 trajectory1 -= trajectory2; // project the part in norm direction away 58 56 tmp = trajectory1.Norm(); // remaining norm is distance 59 57 } else if (Norm2 < MYEPSILON) { 60 58 Sprinter = Params.PermutationMap[Runner->nr]; // find second target point 61 trajectory2.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); // copy second offset 62 trajectory2.SubtractVector(&Walker->Trajectory.R.at(Params.startstep)); // subtract first offset 63 trajectory1.Scale( trajectory2.ScalarProduct(&trajectory1) ); // trajectory1 is scaled to unity, hence we don't need to divide by anything 64 trajectory2.SubtractVector(&trajectory1); // project the part in norm direction away 59 trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep); // copy second offset 60 trajectory1 *= trajectory2.ScalarProduct(trajectory1); // trajectory1 is scaled to unity, hence we don't need to divide by anything 61 trajectory2 -= trajectory1; // project the part in norm direction away 65 62 tmp = trajectory2.Norm(); // remaining norm is distance 66 } else if ((fabs(trajectory1.ScalarProduct( &trajectory2)/Norm1/Norm2) - 1.) < MYEPSILON) { // check whether they're linear dependent63 } else if ((fabs(trajectory1.ScalarProduct(trajectory2)/Norm1/Norm2) - 1.) < MYEPSILON) { // check whether they're linear dependent 67 64 // Log() << Verbose(3) << "Both trajectories of " << *Walker << " and " << *Runner << " are linear dependent: "; 68 65 // Log() << Verbose(0) << trajectory1; 69 66 // Log() << Verbose(0) << " and "; 70 67 // Log() << Verbose(0) << trajectory2; 71 tmp = Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.startstep));68 tmp = Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.startstep)); 72 69 // Log() << Verbose(0) << " with distance " << tmp << "." << endl; 73 70 } else { // determine distance by finding minimum distance … … 79 76 // Log() << Verbose(0) << trajectory2 << endl; 80 77 // determine normal vector for both 81 normal .MakeNormalVector(&trajectory1, &trajectory2);78 normal = Plane(trajectory1, trajectory2,0).getNormal(); 82 79 // print all vectors for debugging 83 80 // Log() << Verbose(0) << "Normal vector in between: "; … … 85 82 // setup matrix 86 83 for (int i=NDIM;i--;) { 87 gsl_matrix_set(A, 0, i, trajectory1 .x[i]);88 gsl_matrix_set(A, 1, i, trajectory2 .x[i]);89 gsl_matrix_set(A, 2, i, normal .x[i]);90 gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep) .x[i] - Runner->Trajectory.R.at(Params.startstep).x[i]));84 gsl_matrix_set(A, 0, i, trajectory1[i]); 85 gsl_matrix_set(A, 1, i, trajectory2[i]); 86 gsl_matrix_set(A, 2, i, normal[i]); 87 gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep)[i] - Runner->Trajectory.R.at(Params.startstep)[i])); 91 88 } 92 89 // solve the linear system by Householder transformations … … 96 93 // Log() << Verbose(0) << " with distance " << tmp << "." << endl; 97 94 // test whether we really have the intersection (by checking on c_1 and c_2) 98 TestVector.CopyVector(&Runner->Trajectory.R.at(Params.startstep));95 trajectory1.Scale(gsl_vector_get(x,0)); 99 96 trajectory2.Scale(gsl_vector_get(x,1)); 100 TestVector.AddVector(&trajectory2);101 97 normal.Scale(gsl_vector_get(x,2)); 102 TestVector.AddVector(&normal); 103 TestVector.SubtractVector(&Walker->Trajectory.R.at(Params.startstep)); 104 trajectory1.Scale(gsl_vector_get(x,0)); 105 TestVector.SubtractVector(&trajectory1); 98 TestVector = Runner->Trajectory.R.at(Params.startstep) + trajectory2 + normal 99 - (Walker->Trajectory.R.at(Params.startstep) + trajectory1); 106 100 if (TestVector.Norm() < MYEPSILON) { 107 101 // Log() << Verbose(2) << "Test: ok.\tDistance of " << tmp << " is correct." << endl; … … 172 166 // first term: distance to target 173 167 Runner = Params.PermutationMap[Walker->nr]; // find target point 174 tmp = (Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.endstep)));168 tmp = (Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.endstep))); 175 169 tmp *= Params.IsAngstroem ? 1. : 1./AtomicLengthToAngstroem; 176 170 result += Params.PenaltyConstants[0] * tmp; … … 231 225 while(Runner->next != mol->end) { 232 226 Runner = Runner->next; 233 Params.DistanceList[Walker->nr]->insert( DistancePair(Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.endstep)), Runner) );227 Params.DistanceList[Walker->nr]->insert( DistancePair(Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.endstep)), Runner) ); 234 228 } 235 229 } … … 514 508 Sprinter = mol->AddCopyAtom(Walker); 515 509 for (int n=NDIM;n--;) { 516 Sprinter->x .x[n] = Walker->Trajectory.R.at(startstep).x[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep).x[n] - Walker->Trajectory.R.at(startstep).x[n])*((double)step/(double)MaxSteps);510 Sprinter->x[n] = Walker->Trajectory.R.at(startstep)[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep)[n] - Walker->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps); 517 511 // add to Trajectories 518 512 //Log() << Verbose(3) << step << ">=" << MDSteps-1 << endl; 519 513 if (step < MaxSteps) { 520 Walker->Trajectory.R.at(step) .x[n] = Walker->Trajectory.R.at(startstep).x[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep).x[n] - Walker->Trajectory.R.at(startstep).x[n])*((double)step/(double)MaxSteps);521 Walker->Trajectory.U.at(step) .x[n] = 0.;522 Walker->Trajectory.F.at(step) .x[n] = 0.;514 Walker->Trajectory.R.at(step)[n] = Walker->Trajectory.R.at(startstep)[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep)[n] - Walker->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps); 515 Walker->Trajectory.U.at(step)[n] = 0.; 516 Walker->Trajectory.F.at(step)[n] = 0.; 523 517 } 524 518 } … … 582 576 for(int i=0;i<AtomCount;i++) 583 577 for(int d=0;d<NDIM;d++) { 584 Velocity .x[d] += Force.Matrix[0][i][d+5];578 Velocity[d] += Force.Matrix[0][i][d+5]; 585 579 } 586 580 for(int i=0;i<AtomCount;i++) 587 581 for(int d=0;d<NDIM;d++) { 588 Force.Matrix[0][i][d+5] -= Velocity .x[d]/(double)AtomCount;582 Force.Matrix[0][i][d+5] -= Velocity[d]/(double)AtomCount; 589 583 } 590 584 // solve a constrained potential if we are meant to -
src/molecule_fragmentation.cpp
r632bc3 r8cbb97 1673 1673 // remove bonds that are beyond bonddistance 1674 1674 for(int i=NDIM;i--;) 1675 Translationvector .x[i] = 0.;1675 Translationvector[i] = 0.; 1676 1676 // scan all bonds 1677 1677 Binder = first; … … 1680 1680 Binder = Binder->next; 1681 1681 for (int i=NDIM;i--;) { 1682 tmp = fabs(Binder->leftatom->x .x[i] - Binder->rightatom->x.x[i]);1682 tmp = fabs(Binder->leftatom->x[i] - Binder->rightatom->x[i]); 1683 1683 //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl; 1684 1684 if (tmp > BondDistance) { … … 1694 1694 // create translation vector from their periodically modified distance 1695 1695 for (int i=NDIM;i--;) { 1696 tmp = Binder->leftatom->x .x[i] - Binder->rightatom->x.x[i];1696 tmp = Binder->leftatom->x[i] - Binder->rightatom->x[i]; 1697 1697 if (fabs(tmp) > BondDistance) 1698 Translationvector .x[i] = (tmp < 0) ? +1. : -1.;1698 Translationvector[i] = (tmp < 0) ? +1. : -1.; 1699 1699 } 1700 1700 Translationvector.MatrixMultiplication(matrix); 1701 1701 //Log() << Verbose(3) << "Translation vector is "; 1702 Translationvector.Output(); 1703 DoLog(0) && (Log() << Verbose(0) << endl); 1702 Log() << Verbose(0) << Translationvector << endl; 1704 1703 // apply to all atoms of first component via BFS 1705 1704 for (int i=AtomCount;i--;) … … 1710 1709 //Log() << Verbose (3) << "Current Walker is: " << *Walker << "." << endl; 1711 1710 ColorList[Walker->nr] = black; // mark as explored 1712 Walker->x .AddVector(&Translationvector); // translate1711 Walker->x += Translationvector; // translate 1713 1712 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 1714 1713 if ((*Runner) != Binder) { -
src/molecule_geometry.cpp
r632bc3 r8cbb97 32 32 33 33 // go through all atoms 34 ActOnAllVectors( &Vector::SubtractVector, Center);34 ActOnAllVectors( &Vector::SubtractVector, *Center); 35 35 ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv); 36 36 … … 72 72 if (ptr != end) { //list not empty? 73 73 for (int i=NDIM;i--;) { 74 max-> x[i] = ptr->x.x[i];75 min-> x[i] = ptr->x.x[i];74 max->at(i) = ptr->x[i]; 75 min->at(i) = ptr->x[i]; 76 76 } 77 77 while (ptr->next != end) { // continue with second if present … … 79 79 //ptr->Output(1,1,out); 80 80 for (int i=NDIM;i--;) { 81 max-> x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i];82 min-> x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i];81 max->at(i) = (max->at(i) < ptr->x[i]) ? ptr->x[i] : max->at(i); 82 min->at(i) = (min->at(i) > ptr->x[i]) ? ptr->x[i] : min->at(i); 83 83 } 84 84 } … … 89 89 // Log() << Verbose(0) << endl; 90 90 min->Scale(-1.); 91 max->AddVector(min);91 (*max) += (*min); 92 92 Translate(min); 93 93 Center.Zero(); … … 112 112 ptr = ptr->next; 113 113 Num++; 114 Center .AddVector(&ptr->x);114 Center += ptr->x; 115 115 } 116 116 Center.Scale(-1./Num); // divide through total number (and sign for direction) … … 136 136 ptr = ptr->next; 137 137 Num += 1.; 138 tmp .CopyVector(&ptr->x);139 a->AddVector(&tmp);138 tmp = ptr->x; 139 (*a) += tmp; 140 140 } 141 141 a->Scale(1./Num); // divide through total mass (and sign for direction) … … 161 161 ptr = ptr->next; 162 162 Num += ptr->type->mass; 163 tmp.CopyVector(&ptr->x); 164 tmp.Scale(ptr->type->mass); // scale by mass 165 a->AddVector(&tmp); 163 tmp = ptr->type->mass * ptr->x; 164 (*a) += tmp; 166 165 } 167 166 a->Scale(-1./Num); // divide through total mass (and sign for direction) … … 189 188 void molecule::CenterAtVector(Vector *newcenter) 190 189 { 191 Center .CopyVector(newcenter);190 Center = *newcenter; 192 191 }; 193 192 … … 195 194 /** Scales all atoms by \a *factor. 196 195 * \param *factor pointer to scaling factor 196 * 197 * TODO: Is this realy what is meant, i.e. 198 * x=(x[0]*factor[0],x[1]*factor[1],x[2]*factor[2]) (current impl) 199 * or rather 200 * x=(**factor) * x (as suggested by comment) 197 201 */ 198 202 void molecule::Scale(const double ** const factor) … … 203 207 ptr = ptr->next; 204 208 for (int j=0;j<MDSteps;j++) 205 ptr->Trajectory.R.at(j).Scale (factor);206 ptr->x.Scale (factor);209 ptr->Trajectory.R.at(j).ScaleAll(*factor); 210 ptr->x.ScaleAll(*factor); 207 211 } 208 212 }; … … 218 222 ptr = ptr->next; 219 223 for (int j=0;j<MDSteps;j++) 220 ptr->Trajectory.R.at(j) .Translate(trans);221 ptr->x .Translate(trans);224 ptr->Trajectory.R.at(j) += (*trans); 225 ptr->x += (*trans); 222 226 } 223 227 }; … … 234 238 235 239 // go through all atoms 236 ActOnAllVectors( &Vector::SubtractVector, trans);240 ActOnAllVectors( &Vector::SubtractVector, *trans); 237 241 ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv); 238 242 … … 247 251 void molecule::Mirror(const Vector *n) 248 252 { 249 ActOnAllVectors( &Vector::Mirror, n );253 ActOnAllVectors( &Vector::Mirror, *n ); 250 254 }; 251 255 … … 271 275 if (Walker->type->Z != 1) { 272 276 #endif 273 Testvector .CopyVector(&Walker->x);277 Testvector = Walker->x; 274 278 Testvector.MatrixMultiplication(inversematrix); 275 279 Translationvector.Zero(); … … 277 281 if (Walker->nr < (*Runner)->GetOtherAtom(Walker)->nr) // otherwise we shift one to, the other fro and gain nothing 278 282 for (int j=0;j<NDIM;j++) { 279 tmp = Walker->x .x[j] - (*Runner)->GetOtherAtom(Walker)->x.x[j];283 tmp = Walker->x[j] - (*Runner)->GetOtherAtom(Walker)->x[j]; 280 284 if ((fabs(tmp)) > BondDistance) { 281 285 flag = false; 282 286 DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << Walker->Name << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl); 283 287 if (tmp > 0) 284 Translationvector .x[j] -= 1.;288 Translationvector[j] -= 1.; 285 289 else 286 Translationvector .x[j] += 1.;290 Translationvector[j] += 1.; 287 291 } 288 292 } 289 293 } 290 Testvector .AddVector(&Translationvector);294 Testvector += Translationvector; 291 295 Testvector.MatrixMultiplication(matrix); 292 Center.AddVector(&Testvector); 293 DoLog(1) && (Log() << Verbose(1) << "vector is: "); 294 Testvector.Output(); 295 DoLog(0) && (Log() << Verbose(0) << endl); 296 Center += Testvector; 297 Log() << Verbose(1) << "vector is: " << Testvector << endl; 296 298 #ifdef ADDHYDROGEN 297 299 // now also change all hydrogens 298 300 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 299 301 if ((*Runner)->GetOtherAtom(Walker)->type->Z == 1) { 300 Testvector .CopyVector(&(*Runner)->GetOtherAtom(Walker)->x);302 Testvector = (*Runner)->GetOtherAtom(Walker)->x; 301 303 Testvector.MatrixMultiplication(inversematrix); 302 Testvector .AddVector(&Translationvector);304 Testvector += Translationvector; 303 305 Testvector.MatrixMultiplication(matrix); 304 Center.AddVector(&Testvector); 305 DoLog(1) && (Log() << Verbose(1) << "Hydrogen vector is: "); 306 Testvector.Output(); 307 DoLog(0) && (Log() << Verbose(0) << endl); 306 Center += Testvector; 307 Log() << Verbose(1) << "Hydrogen vector is: " << Testvector << endl; 308 308 } 309 309 } … … 338 338 while (ptr->next != end) { 339 339 ptr = ptr->next; 340 Vector x; 341 x.CopyVector(&ptr->x); 340 Vector x = ptr->x; 342 341 //x.SubtractVector(CenterOfGravity); 343 InertiaTensor[0] += ptr->type->mass*(x .x[1]*x.x[1] + x.x[2]*x.x[2]);344 InertiaTensor[1] += ptr->type->mass*(-x .x[0]*x.x[1]);345 InertiaTensor[2] += ptr->type->mass*(-x .x[0]*x.x[2]);346 InertiaTensor[3] += ptr->type->mass*(-x .x[1]*x.x[0]);347 InertiaTensor[4] += ptr->type->mass*(x .x[0]*x.x[0] + x.x[2]*x.x[2]);348 InertiaTensor[5] += ptr->type->mass*(-x .x[1]*x.x[2]);349 InertiaTensor[6] += ptr->type->mass*(-x .x[2]*x.x[0]);350 InertiaTensor[7] += ptr->type->mass*(-x .x[2]*x.x[1]);351 InertiaTensor[8] += ptr->type->mass*(x .x[0]*x.x[0] + x.x[1]*x.x[1]);342 InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]); 343 InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]); 344 InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]); 345 InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]); 346 InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]); 347 InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]); 348 InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]); 349 InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]); 350 InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]); 352 351 } 353 352 // print InertiaTensor for debugging … … 390 389 while (ptr->next != end) { 391 390 ptr = ptr->next; 392 Vector x; 393 x.CopyVector(&ptr->x); 391 Vector x = ptr->x; 394 392 //x.SubtractVector(CenterOfGravity); 395 InertiaTensor[0] += ptr->type->mass*(x .x[1]*x.x[1] + x.x[2]*x.x[2]);396 InertiaTensor[1] += ptr->type->mass*(-x .x[0]*x.x[1]);397 InertiaTensor[2] += ptr->type->mass*(-x .x[0]*x.x[2]);398 InertiaTensor[3] += ptr->type->mass*(-x .x[1]*x.x[0]);399 InertiaTensor[4] += ptr->type->mass*(x .x[0]*x.x[0] + x.x[2]*x.x[2]);400 InertiaTensor[5] += ptr->type->mass*(-x .x[1]*x.x[2]);401 InertiaTensor[6] += ptr->type->mass*(-x .x[2]*x.x[0]);402 InertiaTensor[7] += ptr->type->mass*(-x .x[2]*x.x[1]);403 InertiaTensor[8] += ptr->type->mass*(x .x[0]*x.x[0] + x.x[1]*x.x[1]);393 InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]); 394 InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]); 395 InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]); 396 InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]); 397 InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]); 398 InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]); 399 InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]); 400 InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]); 401 InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]); 404 402 } 405 403 // print InertiaTensor for debugging … … 428 426 double alpha, tmp; 429 427 Vector z_axis; 430 z_axis .x[0] = 0.;431 z_axis .x[1] = 0.;432 z_axis .x[2] = 1.;428 z_axis[0] = 0.; 429 z_axis[1] = 0.; 430 z_axis[2] = 1.; 433 431 434 432 // rotate on z-x plane 435 433 DoLog(0) && (Log() << Verbose(0) << "Begin of Aligning all atoms." << endl); 436 alpha = atan(-n-> x[0]/n->x[2]);434 alpha = atan(-n->at(0)/n->at(2)); 437 435 DoLog(1) && (Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... "); 438 436 while (ptr->next != end) { 439 437 ptr = ptr->next; 440 tmp = ptr->x .x[0];441 ptr->x .x[0] = cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];442 ptr->x .x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];438 tmp = ptr->x[0]; 439 ptr->x[0] = cos(alpha) * tmp + sin(alpha) * ptr->x[2]; 440 ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2]; 443 441 for (int j=0;j<MDSteps;j++) { 444 tmp = ptr->Trajectory.R.at(j) .x[0];445 ptr->Trajectory.R.at(j) .x[0] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2];446 ptr->Trajectory.R.at(j) .x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2];442 tmp = ptr->Trajectory.R.at(j)[0]; 443 ptr->Trajectory.R.at(j)[0] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2]; 444 ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2]; 447 445 } 448 446 } 449 447 // rotate n vector 450 tmp = n->x[0]; 451 n->x[0] = cos(alpha) * tmp + sin(alpha) * n->x[2]; 452 n->x[2] = -sin(alpha) * tmp + cos(alpha) * n->x[2]; 453 DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: "); 454 n->Output(); 455 DoLog(0) && (Log() << Verbose(0) << endl); 448 tmp = n->at(0); 449 n->at(0) = cos(alpha) * tmp + sin(alpha) * n->at(2); 450 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2); 451 DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: " << n << endl); 456 452 457 453 // rotate on z-y plane 458 454 ptr = start; 459 alpha = atan(-n-> x[1]/n->x[2]);455 alpha = atan(-n->at(1)/n->at(2)); 460 456 DoLog(1) && (Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... "); 461 457 while (ptr->next != end) { 462 458 ptr = ptr->next; 463 tmp = ptr->x .x[1];464 ptr->x .x[1] = cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];465 ptr->x .x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];459 tmp = ptr->x[1]; 460 ptr->x[1] = cos(alpha) * tmp + sin(alpha) * ptr->x[2]; 461 ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2]; 466 462 for (int j=0;j<MDSteps;j++) { 467 tmp = ptr->Trajectory.R.at(j) .x[1];468 ptr->Trajectory.R.at(j) .x[1] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2];469 ptr->Trajectory.R.at(j) .x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2];463 tmp = ptr->Trajectory.R.at(j)[1]; 464 ptr->Trajectory.R.at(j)[1] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2]; 465 ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2]; 470 466 } 471 467 } 472 468 // rotate n vector (for consistency check) 473 tmp = n->x[1]; 474 n->x[1] = cos(alpha) * tmp + sin(alpha) * n->x[2]; 475 n->x[2] = -sin(alpha) * tmp + cos(alpha) * n->x[2]; 476 477 DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: "); 478 n->Output(); 479 DoLog(1) && (Log() << Verbose(1) << endl); 469 tmp = n->at(1); 470 n->at(1) = cos(alpha) * tmp + sin(alpha) * n->at(2); 471 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2); 472 473 474 DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: " << n << endl); 480 475 DoLog(0) && (Log() << Verbose(0) << "End of Aligning all atoms." << endl); 481 476 }; … … 495 490 496 491 // initialize vectors 497 a .x[0] = gsl_vector_get(x,0);498 a .x[1] = gsl_vector_get(x,1);499 a .x[2] = gsl_vector_get(x,2);500 b .x[0] = gsl_vector_get(x,3);501 b .x[1] = gsl_vector_get(x,4);502 b .x[2] = gsl_vector_get(x,5);492 a[0] = gsl_vector_get(x,0); 493 a[1] = gsl_vector_get(x,1); 494 a[2] = gsl_vector_get(x,2); 495 b[0] = gsl_vector_get(x,3); 496 b[1] = gsl_vector_get(x,4); 497 b[2] = gsl_vector_get(x,5); 503 498 // go through all atoms 504 499 while (ptr != par->mol->end) { 505 500 ptr = ptr->next; 506 501 if (ptr->type == ((struct lsq_params *)params)->type) { // for specific type 507 c.CopyVector(&ptr->x); // copy vector to temporary one 508 c.SubtractVector(&a); // subtract offset vector 509 t = c.ScalarProduct(&b); // get direction parameter 510 d.CopyVector(&b); // and create vector 511 d.Scale(&t); 512 c.SubtractVector(&d); // ... yielding distance vector 513 res += d.ScalarProduct((const Vector *)&d); // add squared distance 502 c = ptr->x - a; 503 t = c.ScalarProduct(b); // get direction parameter 504 d = t*b; // and create vector 505 c -= d; // ... yielding distance vector 506 res += d.ScalarProduct(d); // add squared distance 514 507 } 515 508 } -
src/molecule_graph.cpp
r632bc3 r8cbb97 18 18 #include "molecule.hpp" 19 19 #include "World.hpp" 20 #include "Helpers/fast_functions.hpp" 20 21 21 22 struct BFSAccounting … … 165 166 OtherWalker = AtomMap[(*OtherRunner)->nr]; 166 167 // Log() << Verbose(0) << "Current other Atom is " << *OtherWalker << "." << endl; 167 const double distance = OtherWalker->x.PeriodicDistanceSquared( &(Walker->x), cell_size);168 const double distance = OtherWalker->x.PeriodicDistanceSquared(Walker->x, cell_size); 168 169 // Log() << Verbose(1) << "Checking distance " << distance << " against typical bond length of " << bonddistance*bonddistance << "." << endl; 169 170 (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem); -
src/molecule_template.hpp
r632bc3 r8cbb97 55 55 } 56 56 }; 57 template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&), T &t ) const 58 { 59 atom *Walker = start; 60 while (Walker->next != end) { 61 Walker = Walker->next; 62 ((Walker->node)->*f)(t); 63 } 64 }; 65 template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&) const, T &t ) const 66 { 67 atom *Walker = start; 68 while (Walker->next != end) { 69 Walker = Walker->next; 70 ((Walker->node)->*f)(t); 71 } 72 }; 57 73 // two arguments 58 74 template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const -
src/moleculelist.cpp
r632bc3 r8cbb97 162 162 Walker = Walker->next; 163 163 counts[Walker->type->getNumber()]++; 164 if (Walker->x.DistanceSquared( &Origin) > size)165 size = Walker->x.DistanceSquared( &Origin);164 if (Walker->x.DistanceSquared(Origin) > size) 165 size = Walker->x.DistanceSquared(Origin); 166 166 } 167 167 // output Index, Name, number of atoms, chemical formula … … 502 502 if ((Runner->type->Z == 1) && (Runner->nr > Walker->nr) && (Binder->GetOtherAtom(Runner) != Binder->GetOtherAtom(Walker))) { // (hydrogens have only one bonding partner!) 503 503 // 4. evaluate the morse potential for each matrix component and add up 504 distance = Runner->x.Distance( &Walker->x);504 distance = Runner->x.Distance(Walker->x); 505 505 //Log() << Verbose(0) << "Fragment " << (*ListRunner)->name << ": " << *Runner << "<= " << distance << "=>" << *Walker << ":" << endl; 506 506 for (int k = 0; k < a; k++) { … … 687 687 for (int k = 0; k < NDIM; k++) { 688 688 j += k + 1; 689 BoxDimension .x[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);690 cell_size[j] = BoxDimension .x[k] * 2.;689 BoxDimension[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem); 690 cell_size[j] = BoxDimension[k] * 2.; 691 691 } 692 692 (*ListRunner)->Translate(&BoxDimension); … … 927 927 // center at set box dimensions 928 928 mol->CenterEdge(¢er); 929 World::getInstance().getDomain()[0] = center .x[0];929 World::getInstance().getDomain()[0] = center[0]; 930 930 World::getInstance().getDomain()[1] = 0; 931 World::getInstance().getDomain()[2] = center .x[1];931 World::getInstance().getDomain()[2] = center[1]; 932 932 World::getInstance().getDomain()[3] = 0; 933 933 World::getInstance().getDomain()[4] = 0; 934 World::getInstance().getDomain()[5] = center .x[2];934 World::getInstance().getDomain()[5] = center[2]; 935 935 insert(mol); 936 936 } -
src/tesselation.cpp
r632bc3 r8cbb97 17 17 #include "triangleintersectionlist.hpp" 18 18 #include "vector.hpp" 19 #include "vector_ops.hpp" 19 20 #include "verbose.hpp" 21 #include "Plane.hpp" 22 #include "Exceptions/LinearDependenceException.hpp" 20 23 21 24 class molecule; … … 234 237 // have a normal vector on the base line pointing outwards 235 238 //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl; 236 BaseLineCenter.CopyVector(endpoints[0]->node->node); 237 BaseLineCenter.AddVector(endpoints[1]->node->node); 238 BaseLineCenter.Scale(1. / 2.); 239 BaseLine.CopyVector(endpoints[0]->node->node); 240 BaseLine.SubtractVector(endpoints[1]->node->node); 239 BaseLineCenter = (1./2.)*((*endpoints[0]->node->node) + (*endpoints[1]->node->node)); 240 BaseLine = (*endpoints[0]->node->node) - (*endpoints[1]->node->node); 241 241 242 //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl; 242 243 … … 248 249 for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) { 249 250 //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl; 250 NormalCheck .AddVector(&runner->second->NormalVector);251 NormalCheck .Scale(sign);251 NormalCheck += runner->second->NormalVector; 252 NormalCheck *= sign; 252 253 sign = -sign; 253 254 if (runner->second->NormalVector.NormSquared() > MYEPSILON) 254 BaseLineNormal .CopyVector(&runner->second->NormalVector);// yes, copy second on top of first255 BaseLineNormal = runner->second->NormalVector; // yes, copy second on top of first 255 256 else { 256 257 DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl); … … 259 260 if (node != NULL) { 260 261 //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl; 261 helper[i].CopyVector(node->node->node); 262 helper[i].SubtractVector(&BaseLineCenter); 263 helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles! 262 helper[i] = (*node->node->node) - BaseLineCenter; 263 helper[i].MakeNormalTo(BaseLine); // we want to compare the triangle's heights' angles! 264 264 //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl; 265 265 i++; … … 409 409 Info FunctionInfo(__func__); 410 410 // get normal vector 411 NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node); 411 NormalVector = Plane(*(endpoints[0]->node->node), 412 *(endpoints[1]->node->node), 413 *(endpoints[2]->node->node)).getNormal(); 412 414 413 415 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 414 if (NormalVector.ScalarProduct( &OtherVector) > 0.)416 if (NormalVector.ScalarProduct(OtherVector) > 0.) 415 417 NormalVector.Scale(-1.); 416 418 DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl); … … 430 432 * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle. 431 433 */ 434 432 435 bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const 433 436 { … … 436 439 Vector helper; 437 440 438 if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) { 441 try { 442 *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x); 443 } 444 catch (LinearDependenceException &excp) { 445 Log() << Verbose(1) << excp; 439 446 DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl); 440 447 return false; … … 445 452 DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl); 446 453 447 if (Intersection->DistanceSquared( endpoints[0]->node->node) < MYEPSILON) {454 if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) { 448 455 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl); 449 456 return true; 450 } else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {457 } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) { 451 458 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl); 452 459 return true; 453 } else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {460 } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) { 454 461 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl); 455 462 return true; … … 458 465 int i = 0; 459 466 do { 460 if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node, endpoints[(i + 2) % 3]->node->node, Intersection, &NormalVector)) { 461 helper.CopyVector(endpoints[(i + 1) % 3]->node->node); 462 helper.SubtractVector(endpoints[i % 3]->node->node); 463 CrossPoint.SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector 464 const double s = CrossPoint.ScalarProduct(&helper) / helper.NormSquared(); 467 try { 468 CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node), 469 *(endpoints[(i+1)%3]->node->node), 470 *(endpoints[(i+2)%3]->node->node), 471 *Intersection); 472 helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 473 CrossPoint -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector 474 const double s = CrossPoint.ScalarProduct(helper)/helper.NormSquared(); 465 475 DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl); 466 if ((s < -MYEPSILON) || ((s -1.) > MYEPSILON)) {476 if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) { 467 477 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl); 468 i =4;478 i=4; 469 479 break; 470 480 } 471 481 i++; 472 } else482 } catch (LinearDependenceException &excp){ 473 483 break; 484 } 474 485 } while (i < 3); 475 486 if (i == 3) { … … 503 514 DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl); 504 515 GetCenter(&Direction); 505 if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) { 506 ClosestPoint->CopyVector(x); 516 try { 517 *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction); 518 } 519 catch (LinearDependenceException &excp) { 520 (*ClosestPoint) = (*x); 507 521 } 508 522 509 523 // 2. Calculate in plane part of line (x, intersection) 510 Vector InPlane; 511 InPlane.CopyVector(x); 512 InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point 513 InPlane.ProjectOntoPlane(&NormalVector); 514 InPlane.AddVector(ClosestPoint); 524 Vector InPlane = (*x) - (*ClosestPoint); // points from plane intersection to straight-down point 525 InPlane.ProjectOntoPlane(NormalVector); 526 InPlane += *ClosestPoint; 515 527 516 528 DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl); … … 526 538 for (int i = 0; i < 3; i++) { 527 539 // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point 528 Direction.CopyVector(endpoints[(i + 1) % 3]->node->node); 529 Direction.SubtractVector(endpoints[i % 3]->node->node); 540 Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 530 541 // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal); 531 CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node); 532 CrossDirection[i].CopyVector(&CrossPoint[i]); 533 CrossDirection[i].SubtractVector(&InPlane); 534 CrossPoint[i].SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector 535 const double s = CrossPoint[i].ScalarProduct(&Direction) / Direction.NormSquared(); 542 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 543 CrossDirection[i] = CrossPoint[i] - InPlane; 544 CrossPoint[i] -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector 545 const double s = CrossPoint[i].ScalarProduct(Direction)/Direction.NormSquared(); 536 546 DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl); 537 if ((s >= -MYEPSILON) && ((s -1.) <= MYEPSILON)) {538 CrossPoint[i].AddVector(endpoints[i % 3]->node->node);// make cross point absolute again547 if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) { 548 CrossPoint[i] += (*endpoints[i%3]->node->node); // make cross point absolute again 539 549 DoLog(2) && (Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i % 3]->node->node << " and " << *endpoints[(i + 1) % 3]->node->node << "." << endl); 540 const double distance = CrossPoint[i].DistanceSquared( x);550 const double distance = CrossPoint[i].DistanceSquared(*x); 541 551 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { 542 552 ShortestDistance = distance; 543 ClosestPoint->CopyVector(&CrossPoint[i]);553 (*ClosestPoint) = CrossPoint[i]; 544 554 } 545 555 } else … … 548 558 InsideFlag = true; 549 559 for (int i = 0; i < 3; i++) { 550 const double sign = CrossDirection[i].ScalarProduct( &CrossDirection[(i + 1) % 3]);551 const double othersign = CrossDirection[i].ScalarProduct( &CrossDirection[(i + 2) % 3]);552 ; 560 const double sign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 1) % 3]); 561 const double othersign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 2) % 3]); 562 553 563 if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign 554 564 InsideFlag = false; 555 565 } 556 566 if (InsideFlag) { 557 ClosestPoint->CopyVector(&InPlane);558 ShortestDistance = InPlane.DistanceSquared( x);567 (*ClosestPoint) = InPlane; 568 ShortestDistance = InPlane.DistanceSquared(*x); 559 569 } else { // also check endnodes 560 570 for (int i = 0; i < 3; i++) { 561 const double distance = x->DistanceSquared( endpoints[i]->node->node);571 const double distance = x->DistanceSquared(*endpoints[i]->node->node); 562 572 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { 563 573 ShortestDistance = distance; 564 ClosestPoint->CopyVector(endpoints[i]->node->node);574 (*ClosestPoint) = (*endpoints[i]->node->node); 565 575 } 566 576 } … … 667 677 center->Zero(); 668 678 for (int i = 0; i < 3; i++) 669 center->AddVector(endpoints[i]->node->node);679 (*center) += (*endpoints[i]->node->node); 670 680 center->Scale(1. / 3.); 671 681 DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl); … … 733 743 int counter = 0; 734 744 for (; Runner[2] != endpoints.end();) { 735 TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node); 745 TemporaryNormal = Plane(*((*Runner[0])->node->node), 746 *((*Runner[1])->node->node), 747 *((*Runner[2])->node->node)).getNormal(); 736 748 for (int i = 0; i < 3; i++) // increase each of them 737 749 Runner[i]++; 738 TotalNormal->AddVector(&TemporaryNormal);750 (*TotalNormal) += TemporaryNormal; 739 751 } 740 752 TotalNormal->Scale(1. / (double) counter); 741 753 742 754 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 743 if (TotalNormal->ScalarProduct( &OtherVector) > 0.)755 if (TotalNormal->ScalarProduct(OtherVector) > 0.) 744 756 TotalNormal->Scale(-1.); 745 757 DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl); … … 758 770 center->Zero(); 759 771 int counter = 0; 760 for 761 center->AddVector((*Runner)->node->node);772 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 773 (*center) += (*(*Runner)->node->node); 762 774 counter++; 763 775 } … … 1020 1032 BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI) 1021 1033 { 1022 1023 OptCenter .CopyVector(&OptCandidateCenter);1024 OtherOptCenter .CopyVector(&OtherOptCandidateCenter);1025 } 1026 ; 1034 Info FunctionInfo(__func__); 1035 OptCenter = OptCandidateCenter; 1036 OtherOptCenter = OtherOptCandidateCenter; 1037 }; 1038 1027 1039 1028 1040 /** Destructor for class CandidateForTesselation. … … 1055 1067 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) { 1056 1068 for (int i = 0; i < 2; i++) { 1057 const double distance = fabs((*VRunner)->DistanceSquared( BaseLine->endpoints[i]->node->node) - radiusSquared);1069 const double distance = fabs((*VRunner)->DistanceSquared(*BaseLine->endpoints[i]->node->node) - radiusSquared); 1058 1070 if (distance > HULLEPSILON) { 1059 1071 DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl); … … 1067 1079 const TesselPoint *Walker = *Runner; 1068 1080 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) { 1069 const double distance = fabs((*VRunner)->DistanceSquared( Walker->node) - radiusSquared);1081 const double distance = fabs((*VRunner)->DistanceSquared(*Walker->node) - radiusSquared); 1070 1082 if (distance > HULLEPSILON) { 1071 1083 DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl); … … 1085 1097 DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl); 1086 1098 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 1087 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance( &OtherOptCenter) << "." << endl);1099 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(OtherOptCenter) << "." << endl); 1088 1100 1089 1101 // remove baseline's endpoints and candidates … … 1107 1119 // check with animate_sphere.tcl VMD script 1108 1120 if (ThirdPoint != NULL) { 1109 DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter .x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2]<< endl);1121 DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl); 1110 1122 } else { 1111 1123 DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl); 1112 DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter .x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2]<< endl);1124 DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl); 1113 1125 } 1114 1126 } … … 1179 1191 int num = 0; 1180 1192 for (GoToFirst(); (!IsEnd()); GoToNext()) { 1181 Center->AddVector(GetPoint()->node);1193 (*Center) += (*GetPoint()->node); 1182 1194 num++; 1183 1195 } … … 1296 1308 C++; 1297 1309 for (; C != PointsOnBoundary.end(); C++) { 1298 tmp = A->second->node->node->DistanceSquared( B->second->node->node);1310 tmp = A->second->node->node->DistanceSquared(*B->second->node->node); 1299 1311 distance = tmp * tmp; 1300 tmp = A->second->node->node->DistanceSquared( C->second->node->node);1312 tmp = A->second->node->node->DistanceSquared(*C->second->node->node); 1301 1313 distance += tmp * tmp; 1302 tmp = B->second->node->node->DistanceSquared( C->second->node->node);1314 tmp = B->second->node->node->DistanceSquared(*C->second->node->node); 1303 1315 distance += tmp * tmp; 1304 1316 DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C))); … … 1319 1331 // 2. next, we have to check whether all points reside on only one side of the triangle 1320 1332 // 3. construct plane vector 1321 PlaneVector.MakeNormalVector(A->second->node->node, baseline->second.first->second->node->node, baseline->second.second->second->node->node); 1333 PlaneVector = Plane(*A->second->node->node, 1334 *baseline->second.first->second->node->node, 1335 *baseline->second.second->second->node->node).getNormal(); 1322 1336 DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl); 1323 1337 // 4. loop over all points … … 1329 1343 continue; 1330 1344 // 4a. project onto plane vector 1331 TrialVector .CopyVector(checker->second->node->node);1332 TrialVector.SubtractVector( A->second->node->node);1333 distance = TrialVector.ScalarProduct( &PlaneVector);1345 TrialVector = (*checker->second->node->node); 1346 TrialVector.SubtractVector(*A->second->node->node); 1347 distance = TrialVector.ScalarProduct(PlaneVector); 1334 1348 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 1335 1349 continue; … … 1346 1360 } 1347 1361 // 4d. Check whether the point is inside the triangle (check distance to each node 1348 tmp = checker->second->node->node->DistanceSquared( A->second->node->node);1362 tmp = checker->second->node->node->DistanceSquared(*A->second->node->node); 1349 1363 int innerpoint = 0; 1350 if ((tmp < A->second->node->node->DistanceSquared( baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))1364 if ((tmp < A->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(*baseline->second.second->second->node->node))) 1351 1365 innerpoint++; 1352 tmp = checker->second->node->node->DistanceSquared( baseline->second.first->second->node->node);1353 if ((tmp < baseline->second.first->second->node->node->DistanceSquared( A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))1366 tmp = checker->second->node->node->DistanceSquared(*baseline->second.first->second->node->node); 1367 if ((tmp < baseline->second.first->second->node->node->DistanceSquared(*A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(*baseline->second.second->second->node->node))) 1354 1368 innerpoint++; 1355 tmp = checker->second->node->node->DistanceSquared( baseline->second.second->second->node->node);1356 if ((tmp < baseline->second.second->second->node->node->DistanceSquared( baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(A->second->node->node)))1369 tmp = checker->second->node->node->DistanceSquared(*baseline->second.second->second->node->node); 1370 if ((tmp < baseline->second.second->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(*A->second->node->node))) 1357 1371 innerpoint++; 1358 1372 // 4e. If so, break 4. loop and continue with next candidate in 1. loop … … 1435 1449 // prepare some auxiliary vectors 1436 1450 Vector BaseLineCenter, BaseLine; 1437 BaseLineCenter.CopyVector(baseline->second->endpoints[0]->node->node); 1438 BaseLineCenter.AddVector(baseline->second->endpoints[1]->node->node); 1439 BaseLineCenter.Scale(1. / 2.); // points now to center of base line 1440 BaseLine.CopyVector(baseline->second->endpoints[0]->node->node); 1441 BaseLine.SubtractVector(baseline->second->endpoints[1]->node->node); 1451 BaseLineCenter = 0.5 * ((*baseline->second->endpoints[0]->node->node) + 1452 (*baseline->second->endpoints[1]->node->node)); 1453 BaseLine = (*baseline->second->endpoints[0]->node->node) - (*baseline->second->endpoints[1]->node->node); 1442 1454 1443 1455 // offset to center of triangle 1444 1456 CenterVector.Zero(); 1445 1457 for (int i = 0; i < 3; i++) 1446 CenterVector .AddVector(BTS->endpoints[i]->node->node);1458 CenterVector += (*BTS->endpoints[i]->node->node); 1447 1459 CenterVector.Scale(1. / 3.); 1448 1460 DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl); 1449 1461 1450 1462 // normal vector of triangle 1451 NormalVector.CopyVector(Center); 1452 NormalVector.SubtractVector(&CenterVector); 1463 NormalVector = (*Center) - CenterVector; 1453 1464 BTS->GetNormalVector(NormalVector); 1454 NormalVector .CopyVector(&BTS->NormalVector);1465 NormalVector = BTS->NormalVector; 1455 1466 DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl); 1456 1467 1457 1468 // vector in propagation direction (out of triangle) 1458 1469 // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection) 1459 PropagationVector.MakeNormalVector(&BaseLine, &NormalVector); 1460 TempVector.CopyVector(&CenterVector); 1461 TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 1470 PropagationVector = Plane(BaseLine, NormalVector,0).getNormal(); 1471 TempVector = CenterVector - (*baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 1462 1472 //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl; 1463 if (PropagationVector.ScalarProduct( &TempVector) > 0) // make sure normal propagation vector points outward from baseline1473 if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline 1464 1474 PropagationVector.Scale(-1.); 1465 1475 DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl); … … 1472 1482 1473 1483 // first check direction, so that triangles don't intersect 1474 VirtualNormalVector.CopyVector(target->second->node->node); 1475 VirtualNormalVector.SubtractVector(&BaseLineCenter); // points from center of base line to target 1476 VirtualNormalVector.ProjectOntoPlane(&NormalVector); 1477 TempAngle = VirtualNormalVector.Angle(&PropagationVector); 1484 VirtualNormalVector = (*target->second->node->node) - BaseLineCenter; 1485 VirtualNormalVector.ProjectOntoPlane(NormalVector); 1486 TempAngle = VirtualNormalVector.Angle(PropagationVector); 1478 1487 DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl); 1479 1488 if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees) … … 1502 1511 1503 1512 // check for linear dependence 1504 TempVector.CopyVector(baseline->second->endpoints[0]->node->node); 1505 TempVector.SubtractVector(target->second->node->node); 1506 helper.CopyVector(baseline->second->endpoints[1]->node->node); 1507 helper.SubtractVector(target->second->node->node); 1508 helper.ProjectOntoPlane(&TempVector); 1513 TempVector = (*baseline->second->endpoints[0]->node->node) - (*target->second->node->node); 1514 helper = (*baseline->second->endpoints[1]->node->node) - (*target->second->node->node); 1515 helper.ProjectOntoPlane(TempVector); 1509 1516 if (fabs(helper.NormSquared()) < MYEPSILON) { 1510 1517 DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl); … … 1514 1521 // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle 1515 1522 flag = true; 1516 VirtualNormalVector.MakeNormalVector(baseline->second->endpoints[0]->node->node, baseline->second->endpoints[1]->node->node, target->second->node->node); 1517 TempVector.CopyVector(baseline->second->endpoints[0]->node->node); 1518 TempVector.AddVector(baseline->second->endpoints[1]->node->node); 1519 TempVector.AddVector(target->second->node->node); 1520 TempVector.Scale(1. / 3.); 1521 TempVector.SubtractVector(Center); 1523 VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node), 1524 *(baseline->second->endpoints[1]->node->node), 1525 *(target->second->node->node)).getNormal(); 1526 TempVector = (1./3.) * ((*baseline->second->endpoints[0]->node->node) + 1527 (*baseline->second->endpoints[1]->node->node) + 1528 (*target->second->node->node)); 1529 TempVector -= (*Center); 1522 1530 // make it always point outward 1523 if (VirtualNormalVector.ScalarProduct( &TempVector) < 0)1531 if (VirtualNormalVector.ScalarProduct(TempVector) < 0) 1524 1532 VirtualNormalVector.Scale(-1.); 1525 1533 // calculate angle 1526 TempAngle = NormalVector.Angle( &VirtualNormalVector);1534 TempAngle = NormalVector.Angle(VirtualNormalVector); 1527 1535 DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl); 1528 1536 if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner … … 1532 1540 } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle) 1533 1541 // hence, check the angles to some normal direction from our base line but in this common plane of both targets... 1534 helper.CopyVector(target->second->node->node); 1535 helper.SubtractVector(&BaseLineCenter); 1536 helper.ProjectOntoPlane(&BaseLine); 1542 helper = (*target->second->node->node) - BaseLineCenter; 1543 helper.ProjectOntoPlane(BaseLine); 1537 1544 // ...the one with the smaller angle is the better candidate 1538 TempVector.CopyVector(target->second->node->node); 1539 TempVector.SubtractVector(&BaseLineCenter); 1540 TempVector.ProjectOntoPlane(&VirtualNormalVector); 1541 TempAngle = TempVector.Angle(&helper); 1542 TempVector.CopyVector(winner->second->node->node); 1543 TempVector.SubtractVector(&BaseLineCenter); 1544 TempVector.ProjectOntoPlane(&VirtualNormalVector); 1545 if (TempAngle < TempVector.Angle(&helper)) { 1546 TempAngle = NormalVector.Angle(&VirtualNormalVector); 1545 TempVector = (*target->second->node->node) - BaseLineCenter; 1546 TempVector.ProjectOntoPlane(VirtualNormalVector); 1547 TempAngle = TempVector.Angle(helper); 1548 TempVector = (*winner->second->node->node) - BaseLineCenter; 1549 TempVector.ProjectOntoPlane(VirtualNormalVector); 1550 if (TempAngle < TempVector.Angle(helper)) { 1551 TempAngle = NormalVector.Angle(VirtualNormalVector); 1547 1552 SmallestAngle = TempAngle; 1548 1553 winner = target; … … 1581 1586 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 1582 1587 BTS->GetCenter(&helper); 1583 helper .SubtractVector(Center);1584 helper .Scale(-1);1588 helper -= (*Center); 1589 helper *= -1; 1585 1590 BTS->GetNormalVector(helper); 1586 1591 TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS)); … … 1640 1645 DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl); 1641 1646 // we have the intersection, check whether in- or outside of boundary 1642 if ((Center->DistanceSquared( Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {1647 if ((Center->DistanceSquared(*Walker->node) - Center->DistanceSquared(Intersection)) < -MYEPSILON) { 1643 1648 // inside, next! 1644 1649 DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl); … … 1653 1658 OldPoints[i] = BTS->endpoints[i]; 1654 1659 } 1655 Normal .CopyVector(&BTS->NormalVector);1660 Normal = BTS->NormalVector; 1656 1661 // add Walker to boundary points 1657 1662 DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl); … … 1800 1805 // get open line 1801 1806 for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) { 1802 if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared( &Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches1807 if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches 1803 1808 DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl); 1804 1809 insertNewLine = false; … … 2039 2044 bool flag = true; 2040 2045 2041 DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter .x[0] << " " << CandidateLine.OtherOptCenter.x[1] << " " << CandidateLine.OtherOptCenter.x[2] << "} radius " << RADIUS << " resolution 30" << endl);2046 DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter[0] << " " << CandidateLine.OtherOptCenter[1] << " " << CandidateLine.OtherOptCenter[2] << "} radius " << RADIUS << " resolution 30" << endl); 2042 2047 // get all points inside the sphere 2043 2048 TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter); … … 2045 2050 DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl); 2046 2051 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 2047 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance( &CandidateLine.OtherOptCenter) << "." << endl);2052 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(CandidateLine.OtherOptCenter) << "." << endl); 2048 2053 2049 2054 // remove triangles's endpoints … … 2061 2066 DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl); 2062 2067 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 2063 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance( &CandidateLine.OtherOptCenter) << "." << endl);2068 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(CandidateLine.OtherOptCenter) << "." << endl); 2064 2069 } 2065 2070 delete (ListofPoints); … … 2215 2220 if (List != NULL) { 2216 2221 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 2217 if ((*Runner)->node-> x[i]> maxCoordinate[i]) {2222 if ((*Runner)->node->at(i) > maxCoordinate[i]) { 2218 2223 DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl); 2219 maxCoordinate[i] = (*Runner)->node-> x[i];2224 maxCoordinate[i] = (*Runner)->node->at(i); 2220 2225 MaxPoint[i] = (*Runner); 2221 2226 } … … 2235 2240 for (int k = 0; k < NDIM; k++) { 2236 2241 NormalVector.Zero(); 2237 NormalVector .x[k] = 1.;2242 NormalVector[k] = 1.; 2238 2243 BaseLine = new BoundaryLineSet(); 2239 2244 BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]); … … 2253 2258 2254 2259 // construct center of circle 2255 CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node); 2256 CircleCenter.AddVector(BaseLine->endpoints[1]->node->node); 2257 CircleCenter.Scale(0.5); 2260 CircleCenter = 0.5 * ((*BaseLine->endpoints[0]->node->node) + (*BaseLine->endpoints[1]->node->node)); 2258 2261 2259 2262 // construct normal vector of circle 2260 CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node); 2261 CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node); 2263 CirclePlaneNormal = (*BaseLine->endpoints[0]->node->node) - (*BaseLine->endpoints[1]->node->node); 2262 2264 2263 2265 double radius = CirclePlaneNormal.NormSquared(); 2264 2266 double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.); 2265 2267 2266 NormalVector.ProjectOntoPlane( &CirclePlaneNormal);2268 NormalVector.ProjectOntoPlane(CirclePlaneNormal); 2267 2269 NormalVector.Normalize(); 2268 2270 ShortestAngle = 2. * M_PI; // This will indicate the quadrant. 2269 2271 2270 SphereCenter.CopyVector(&NormalVector); 2271 SphereCenter.Scale(CircleRadius); 2272 SphereCenter.AddVector(&CircleCenter); 2272 SphereCenter = (CircleRadius * NormalVector) + CircleCenter; 2273 2273 // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized) 2274 2274 2275 2275 // look in one direction of baseline for initial candidate 2276 SearchDirection .MakeNormalVector(&CirclePlaneNormal, &NormalVector);// whether we look "left" first or "right" first is not important ...2276 SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal(); // whether we look "left" first or "right" first is not important ... 2277 2277 2278 2278 // adding point 1 and point 2 and add the line between them … … 2478 2478 2479 2479 // construct center of circle 2480 CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 2481 CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node); 2482 CircleCenter.Scale(0.5); 2480 CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) + 2481 (*CandidateLine.BaseLine->endpoints[1]->node->node)); 2483 2482 2484 2483 // construct normal vector of circle 2485 CirclePlaneNormal .CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);2486 CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);2484 CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) - 2485 (*CandidateLine.BaseLine->endpoints[1]->node->node); 2487 2486 2488 2487 // calculate squared radius of circle 2489 radius = CirclePlaneNormal.ScalarProduct( &CirclePlaneNormal);2488 radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal); 2490 2489 if (radius / 4. < RADIUS * RADIUS) { 2491 2490 // construct relative sphere center with now known CircleCenter 2492 RelativeSphereCenter.CopyVector(&T.SphereCenter); 2493 RelativeSphereCenter.SubtractVector(&CircleCenter); 2491 RelativeSphereCenter = T.SphereCenter - CircleCenter; 2494 2492 2495 2493 CircleRadius = RADIUS * RADIUS - radius / 4.; … … 2500 2498 2501 2499 // construct SearchDirection and an "outward pointer" 2502 SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal); 2503 helper.CopyVector(&CircleCenter); 2504 helper.SubtractVector(ThirdPoint->node->node); 2505 if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards! 2500 SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal(); 2501 helper = CircleCenter - (*ThirdPoint->node->node); 2502 if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards! 2506 2503 SearchDirection.Scale(-1.); 2507 2504 DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl); 2508 if (fabs(RelativeSphereCenter.ScalarProduct( &SearchDirection)) > HULLEPSILON) {2505 if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { 2509 2506 // rotated the wrong way! 2510 2507 DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl); … … 2643 2640 Finder->second->pointlist.push_back(Sprinter); 2644 2641 Finder->second->ShortestAngle = 0.; 2645 Finder->second->OptCenter .CopyVector(OptCenter);2642 Finder->second->OptCenter = *OptCenter; 2646 2643 } 2647 2644 } … … 2678 2675 // create normal vector 2679 2676 BTS->GetCenter(&Center); 2680 Center .SubtractVector(&CandidateLine.OptCenter);2681 BTS->SphereCenter .CopyVector(&CandidateLine.OptCenter);2677 Center -= CandidateLine.OptCenter; 2678 BTS->SphereCenter = CandidateLine.OptCenter; 2682 2679 BTS->GetNormalVector(Center); 2683 2680 // give some verbose output about the whole procedure … … 2712 2709 AddTesselationTriangle(); 2713 2710 2714 BTS->SphereCenter .CopyVector(&CandidateLine.OtherOptCenter);2711 BTS->SphereCenter = CandidateLine.OtherOptCenter; 2715 2712 // create normal vector in other direction 2716 BTS->GetNormalVector( &triangle->NormalVector);2713 BTS->GetNormalVector(triangle->NormalVector); 2717 2714 BTS->NormalVector.Scale(-1.); 2718 2715 // give some verbose output about the whole procedure … … 2757 2754 // create normal vector 2758 2755 BTS->GetCenter(&Center); 2759 Center.SubtractVector( OptCenter);2760 BTS->SphereCenter .CopyVector(OptCenter);2756 Center.SubtractVector(*OptCenter); 2757 BTS->SphereCenter = *OptCenter; 2761 2758 BTS->GetNormalVector(Center); 2762 2759 … … 2802 2799 Vector DistanceToIntersection[2], BaseLine; 2803 2800 double distance[2]; 2804 BaseLine.CopyVector(Base->endpoints[1]->node->node); 2805 BaseLine.SubtractVector(Base->endpoints[0]->node->node); 2801 BaseLine = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node); 2806 2802 for (int i = 0; i < 2; i++) { 2807 DistanceToIntersection[i].CopyVector(ClosestPoint); 2808 DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node); 2809 distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]); 2803 DistanceToIntersection[i] = (*ClosestPoint) - (*Base->endpoints[i]->node->node); 2804 distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]); 2810 2805 } 2811 2806 delete (ClosestPoint); … … 2883 2878 2884 2879 // get the distance vector from Base line to OtherBase line 2885 Vector Distance; 2886 Distance.CopyVector(ClosestPoint[1]); 2887 Distance.SubtractVector(ClosestPoint[0]); 2880 Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]); 2888 2881 2889 2882 // calculate volume … … 2906 2899 } 2907 2900 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2908 2909 BaseLineNormal .AddVector(&(runner->second->NormalVector));2901 DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl); 2902 BaseLineNormal += (runner->second->NormalVector); 2910 2903 } 2911 2904 BaseLineNormal.Scale(1. / 2.); 2912 2905 2913 if (Distance.ScalarProduct( &BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip2906 if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip 2914 2907 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl); 2915 2908 // calculate volume summand as a general tetraeder … … 2947 2940 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2948 2941 DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl); 2949 BaseLineNormal .AddVector(&(runner->second->NormalVector));2942 BaseLineNormal += (runner->second->NormalVector); 2950 2943 } 2951 2944 BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector() … … 3087 3080 double distance, scaleFactor; 3088 3081 3089 OrthogonalizedOben.CopyVector(&Oben); 3090 aCandidate.CopyVector(a->node); 3091 aCandidate.SubtractVector(Candidate->node); 3092 OrthogonalizedOben.ProjectOntoPlane(&aCandidate); 3082 OrthogonalizedOben = Oben; 3083 aCandidate = (*a->node) - (*Candidate->node); 3084 OrthogonalizedOben.ProjectOntoPlane(aCandidate); 3093 3085 OrthogonalizedOben.Normalize(); 3094 3086 distance = 0.5 * aCandidate.Norm(); … … 3096 3088 OrthogonalizedOben.Scale(scaleFactor); 3097 3089 3098 Center.CopyVector(Candidate->node); 3099 Center.AddVector(a->node); 3100 Center.Scale(0.5); 3101 Center.AddVector(&OrthogonalizedOben); 3102 3103 AngleCheck.CopyVector(&Center); 3104 AngleCheck.SubtractVector(a->node); 3090 Center = 0.5 * ((*Candidate->node) + (*a->node)); 3091 Center += OrthogonalizedOben; 3092 3093 AngleCheck = Center - (*a->node); 3105 3094 norm = aCandidate.Norm(); 3106 3095 // second point shall have smallest angle with respect to Oben vector 3107 3096 if (norm < RADIUS * 2.) { 3108 angle = AngleCheck.Angle( &Oben);3097 angle = AngleCheck.Angle(Oben); 3109 3098 if (angle < Storage[0]) { 3110 3099 //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]); … … 3182 3171 3183 3172 // copy old center 3184 CandidateLine.OldCenter .CopyVector(&OldSphereCenter);3173 CandidateLine.OldCenter = OldSphereCenter; 3185 3174 CandidateLine.ThirdPoint = ThirdPoint; 3186 3175 CandidateLine.pointlist.clear(); 3187 3176 3188 3177 // construct center of circle 3189 CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 3190 CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node); 3191 CircleCenter.Scale(0.5); 3178 CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) + 3179 (*CandidateLine.BaseLine->endpoints[1]->node->node)); 3192 3180 3193 3181 // construct normal vector of circle 3194 CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 3195 CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node); 3196 3197 RelativeOldSphereCenter.CopyVector(&OldSphereCenter); 3198 RelativeOldSphereCenter.SubtractVector(&CircleCenter); 3182 CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) - 3183 (*CandidateLine.BaseLine->endpoints[1]->node->node); 3184 3185 RelativeOldSphereCenter = OldSphereCenter - CircleCenter; 3199 3186 3200 3187 // calculate squared radius TesselPoint *ThirdPoint,f circle … … 3206 3193 3207 3194 // test whether old center is on the band's plane 3208 if (fabs(RelativeOldSphereCenter.ScalarProduct( &CirclePlaneNormal)) > HULLEPSILON) {3209 DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct( &CirclePlaneNormal)) << "!" << endl);3210 RelativeOldSphereCenter.ProjectOntoPlane( &CirclePlaneNormal);3195 if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) { 3196 DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) << "!" << endl); 3197 RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal); 3211 3198 } 3212 3199 radius = RelativeOldSphereCenter.NormSquared(); … … 3216 3203 // check SearchDirection 3217 3204 DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl); 3218 if (fabs(RelativeOldSphereCenter.ScalarProduct( &SearchDirection)) > HULLEPSILON) { // rotated the wrong way!3205 if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way! 3219 3206 DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl); 3220 3207 } … … 3254 3241 DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl); 3255 3242 3256 if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)) { 3243 try { 3244 NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node), 3245 *(CandidateLine.BaseLine->endpoints[1]->node->node), 3246 *(Candidate->node)).getNormal(); 3257 3247 DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl); 3258 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared( &NewPlaneCenter);3248 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(NewPlaneCenter); 3259 3249 DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl); 3260 3250 DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl); 3261 3251 DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl); 3262 3252 if (radius < RADIUS * RADIUS) { 3263 otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared( &NewPlaneCenter);3253 otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(NewPlaneCenter); 3264 3254 if (fabs(radius - otherradius) < HULLEPSILON) { 3265 3255 // construct both new centers 3266 NewSphereCenter .CopyVector(&NewPlaneCenter);3267 OtherNewSphereCenter .CopyVector(&NewPlaneCenter);3268 helper .CopyVector(&NewNormalVector);3256 NewSphereCenter = NewPlaneCenter; 3257 OtherNewSphereCenter= NewPlaneCenter; 3258 helper = NewNormalVector; 3269 3259 helper.Scale(sqrt(RADIUS * RADIUS - radius)); 3270 3260 DoLog(2) && (Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl); 3271 NewSphereCenter .AddVector(&helper);3261 NewSphereCenter += helper; 3272 3262 DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl); 3273 3263 // OtherNewSphereCenter is created by the same vector just in the other direction 3274 3264 helper.Scale(-1.); 3275 OtherNewSphereCenter .AddVector(&helper);3265 OtherNewSphereCenter += helper; 3276 3266 DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl); 3277 3278 3267 alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection); 3279 3268 Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection); 3280 3269 if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid 3281 if (OldSphereCenter.DistanceSquared( &NewSphereCenter) < OldSphereCenter.DistanceSquared(&OtherNewSphereCenter))3270 if (OldSphereCenter.DistanceSquared(NewSphereCenter) < OldSphereCenter.DistanceSquared(OtherNewSphereCenter)) 3282 3271 alpha = Otheralpha; 3283 3272 } else 3284 3273 alpha = min(alpha, Otheralpha); 3285 3286 3274 // if there is a better candidate, drop the current list and add the new candidate 3287 3275 // otherwise ignore the new candidate and keep the list 3288 3276 if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) { 3289 3277 if (fabs(alpha - Otheralpha) > MYEPSILON) { 3290 CandidateLine.OptCenter .CopyVector(&NewSphereCenter);3291 CandidateLine.OtherOptCenter .CopyVector(&OtherNewSphereCenter);3278 CandidateLine.OptCenter = NewSphereCenter; 3279 CandidateLine.OtherOptCenter = OtherNewSphereCenter; 3292 3280 } else { 3293 CandidateLine.OptCenter .CopyVector(&OtherNewSphereCenter);3294 CandidateLine.OtherOptCenter .CopyVector(&NewSphereCenter);3281 CandidateLine.OptCenter = OtherNewSphereCenter; 3282 CandidateLine.OtherOptCenter = NewSphereCenter; 3295 3283 } 3296 3284 // if there is an equal candidate, add it to the list without clearing the list … … 3319 3307 DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl); 3320 3308 } 3321 } else { 3322 DoLog(1) && (Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl); 3309 } 3310 catch (LinearDependenceException &excp){ 3311 Log() << Verbose(1) << excp; 3312 Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl; 3323 3313 } 3324 3314 } else { … … 3416 3406 FindPoint = PointsOnBoundary.find((*Runner)->nr); 3417 3407 if (FindPoint != PointsOnBoundary.end()) { 3418 points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared( x), FindPoint->second));3408 points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(*x), FindPoint->second)); 3419 3409 DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl); 3420 3410 } … … 3460 3450 for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) { 3461 3451 // calculate closest point on line to desired point 3462 helper.CopyVector((LineRunner->second)->endpoints[0]->node->node); 3463 helper.AddVector((LineRunner->second)->endpoints[1]->node->node); 3464 helper.Scale(0.5); 3465 Center.CopyVector(x); 3466 Center.SubtractVector(&helper); 3467 BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node); 3468 BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3469 Center.ProjectOntoPlane(&BaseLine); 3452 helper = 0.5 * ((*(LineRunner->second)->endpoints[0]->node->node) + 3453 (*(LineRunner->second)->endpoints[1]->node->node)); 3454 Center = (*x) - helper; 3455 BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) - 3456 (*(LineRunner->second)->endpoints[1]->node->node); 3457 Center.ProjectOntoPlane(BaseLine); 3470 3458 const double distance = Center.NormSquared(); 3471 3459 if ((ClosestLine == NULL) || (distance < MinDistance)) { 3472 3460 // additionally calculate intersection on line (whether it's on the line section or not) 3473 helper.CopyVector(x); 3474 helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node); 3475 helper.SubtractVector(&Center); 3476 const double lengthA = helper.ScalarProduct(&BaseLine); 3477 helper.CopyVector(x); 3478 helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3479 helper.SubtractVector(&Center); 3480 const double lengthB = helper.ScalarProduct(&BaseLine); 3461 helper = (*x) - (*(LineRunner->second)->endpoints[0]->node->node) - Center; 3462 const double lengthA = helper.ScalarProduct(BaseLine); 3463 helper = (*x) - (*(LineRunner->second)->endpoints[1]->node->node) - Center; 3464 const double lengthB = helper.ScalarProduct(BaseLine); 3481 3465 if (lengthB * lengthA < 0) { // if have different sign 3482 3466 ClosestLine = LineRunner->second; … … 3527 3511 for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) { 3528 3512 3529 BaseLine .CopyVector((LineRunner->second)->endpoints[0]->node->node);3530 BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);3513 BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) - 3514 (*(LineRunner->second)->endpoints[1]->node->node); 3531 3515 const double lengthBase = BaseLine.NormSquared(); 3532 3516 3533 BaseLineIntersection.CopyVector(x); 3534 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node); 3517 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[0]->node->node); 3535 3518 const double lengthEndA = BaseLineIntersection.NormSquared(); 3536 3519 3537 BaseLineIntersection.CopyVector(x); 3538 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3520 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node); 3539 3521 const double lengthEndB = BaseLineIntersection.NormSquared(); 3540 3522 … … 3554 3536 } else { // intersection is closer, calculate 3555 3537 // calculate closest point on line to desired point 3556 BaseLineIntersection.CopyVector(x); 3557 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3558 Center.CopyVector(&BaseLineIntersection); 3559 Center.ProjectOntoPlane(&BaseLine); 3560 BaseLineIntersection.SubtractVector(&Center); 3538 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node); 3539 Center = BaseLineIntersection; 3540 Center.ProjectOntoPlane(BaseLine); 3541 BaseLineIntersection -= Center; 3561 3542 const double distance = BaseLineIntersection.NormSquared(); 3562 3543 if (Center.NormSquared() > BaseLine.NormSquared()) { … … 3612 3593 for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) { 3613 3594 (*Runner)->GetCenter(&Center); 3614 helper.CopyVector(x); 3615 helper.SubtractVector(&Center); 3616 const double Alignment = helper.Angle(&(*Runner)->NormalVector); 3595 helper = (*x) - Center; 3596 const double Alignment = helper.Angle((*Runner)->NormalVector); 3617 3597 if (Alignment < MinAlignment) { 3618 3598 result = *Runner; … … 3681 3661 triangle->GetCenter(&Center); 3682 3662 DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl); 3683 DistanceToCenter.CopyVector(&Center); 3684 DistanceToCenter.SubtractVector(&Point); 3663 DistanceToCenter = Center - Point; 3685 3664 DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl); 3686 3665 3687 3666 // check whether we are on boundary 3688 if (fabs(DistanceToCenter.ScalarProduct( &triangle->NormalVector)) < MYEPSILON) {3667 if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) { 3689 3668 // calculate whether inside of triangle 3690 DistanceToCenter.CopyVector(&Point); 3691 Center.CopyVector(&Point); 3692 Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter 3693 DistanceToCenter.AddVector(&triangle->NormalVector); // points outside 3669 DistanceToCenter = Point + triangle->NormalVector; // points outside 3670 Center = Point - triangle->NormalVector; // points towards MolCenter 3694 3671 DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl); 3695 3672 if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) { … … 3706 3683 3707 3684 // then check direction to boundary 3708 if (DistanceToCenter.ScalarProduct( &triangle->NormalVector) > MYEPSILON) {3685 if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) { 3709 3686 DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl); 3710 3687 return -distance; … … 3840 3817 if ((triangles != NULL) && (!triangles->empty())) { 3841 3818 for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) 3842 PlaneNormal .AddVector(&(*Runner)->NormalVector);3819 PlaneNormal += (*Runner)->NormalVector; 3843 3820 } else { 3844 3821 DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl); … … 3851 3828 // construct one orthogonal vector 3852 3829 if (Reference != NULL) { 3853 AngleZero.CopyVector(Reference); 3854 AngleZero.SubtractVector(Point->node); 3855 AngleZero.ProjectOntoPlane(&PlaneNormal); 3830 AngleZero = (*Reference) - (*Point->node); 3831 AngleZero.ProjectOntoPlane(PlaneNormal); 3856 3832 } 3857 3833 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) { 3858 3834 DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl); 3859 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); 3860 AngleZero.SubtractVector(Point->node); 3861 AngleZero.ProjectOntoPlane(&PlaneNormal); 3835 AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node); 3836 AngleZero.ProjectOntoPlane(PlaneNormal); 3862 3837 if (AngleZero.NormSquared() < MYEPSILON) { 3863 3838 DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl); … … 3867 3842 DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl); 3868 3843 if (AngleZero.NormSquared() > MYEPSILON) 3869 OrthogonalVector .MakeNormalVector(&PlaneNormal, &AngleZero);3844 OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal(); 3870 3845 else 3871 OrthogonalVector.MakeNormal Vector(&PlaneNormal);3846 OrthogonalVector.MakeNormalTo(PlaneNormal); 3872 3847 DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl); 3873 3848 3874 3849 // go through all connected points and calculate angle 3875 3850 for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { 3876 helper.CopyVector((*listRunner)->node); 3877 helper.SubtractVector(Point->node); 3878 helper.ProjectOntoPlane(&PlaneNormal); 3851 helper = (*(*listRunner)->node) - (*Point->node); 3852 helper.ProjectOntoPlane(PlaneNormal); 3879 3853 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3880 3854 DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl); … … 3934 3908 int counter = 0; 3935 3909 while (TesselC != SetOfNeighbours->end()) { 3936 helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node); 3910 helper = Plane(*((*TesselA)->node), 3911 *((*TesselB)->node), 3912 *((*TesselC)->node)).getNormal(); 3937 3913 DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl); 3938 3914 counter++; … … 3940 3916 TesselB++; 3941 3917 TesselC++; 3942 PlaneNormal .AddVector(&helper);3918 PlaneNormal += helper; 3943 3919 } 3944 3920 //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size() … … 3955 3931 // construct one orthogonal vector 3956 3932 if (Reference != NULL) { 3957 AngleZero.CopyVector(Reference); 3958 AngleZero.SubtractVector(Point->node); 3959 AngleZero.ProjectOntoPlane(&PlaneNormal); 3960 } 3961 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) { 3933 AngleZero = (*Reference) - (*Point->node); 3934 AngleZero.ProjectOntoPlane(PlaneNormal); 3935 } 3936 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) { 3962 3937 DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl); 3963 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); 3964 AngleZero.SubtractVector(Point->node); 3965 AngleZero.ProjectOntoPlane(&PlaneNormal); 3938 AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node); 3939 AngleZero.ProjectOntoPlane(PlaneNormal); 3966 3940 if (AngleZero.NormSquared() < MYEPSILON) { 3967 3941 DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl); … … 3971 3945 DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl); 3972 3946 if (AngleZero.NormSquared() > MYEPSILON) 3973 OrthogonalVector .MakeNormalVector(&PlaneNormal, &AngleZero);3947 OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal(); 3974 3948 else 3975 OrthogonalVector.MakeNormal Vector(&PlaneNormal);3949 OrthogonalVector.MakeNormalTo(PlaneNormal); 3976 3950 DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl); 3977 3951 … … 3979 3953 pair<map<double, TesselPoint*>::iterator, bool> InserterTest; 3980 3954 for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { 3981 helper.CopyVector((*listRunner)->node); 3982 helper.SubtractVector(Point->node); 3983 helper.ProjectOntoPlane(&PlaneNormal); 3955 helper = (*(*listRunner)->node) - (*Point->node); 3956 helper.ProjectOntoPlane(PlaneNormal); 3984 3957 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3985 3958 if (angle > M_PI) // the correction is of no use here (and not desired) … … 4225 4198 4226 4199 // copy old location for the volume 4227 OldPoint .CopyVector(point->node->node);4200 OldPoint = (*point->node->node); 4228 4201 4229 4202 // get list of connected points … … 4253 4226 for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) { 4254 4227 DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl); 4255 NormalVector .SubtractVector(&Runner->second->NormalVector); // has to point inward4228 NormalVector -= Runner->second->NormalVector; // has to point inward 4256 4229 RemoveTesselationTriangle(Runner->second); 4257 4230 count++; … … 4288 4261 StartNode--; 4289 4262 //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl; 4290 Point.CopyVector((*StartNode)->node); 4291 Point.SubtractVector((*MiddleNode)->node); 4263 Point = (*(*StartNode)->node) - (*(*MiddleNode)->node); 4292 4264 StartNode = MiddleNode; 4293 4265 StartNode++; … … 4295 4267 StartNode = connectedPath->begin(); 4296 4268 //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl; 4297 Reference.CopyVector((*StartNode)->node); 4298 Reference.SubtractVector((*MiddleNode)->node); 4299 OrthogonalVector.CopyVector((*MiddleNode)->node); 4300 OrthogonalVector.SubtractVector(&OldPoint); 4301 OrthogonalVector.MakeNormalVector(&Reference); 4269 Reference = (*(*StartNode)->node) - (*(*MiddleNode)->node); 4270 OrthogonalVector = (*(*MiddleNode)->node) - OldPoint; 4271 OrthogonalVector.MakeNormalTo(Reference); 4302 4272 angle = GetAngle(Point, Reference, OrthogonalVector); 4303 4273 //if (angle < M_PI) // no wrong-sided triangles, please? … … 4752 4722 class BoundaryLineSet *BestLine = NULL; 4753 4723 for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) { 4754 BaseLine.CopyVector(Runner->second->endpoints[0]->node->node); 4755 BaseLine.SubtractVector(Runner->second->endpoints[1]->node->node); 4756 CenterToPoint.CopyVector(Runner->second->endpoints[0]->node->node); 4757 CenterToPoint.AddVector(Runner->second->endpoints[1]->node->node); 4758 CenterToPoint.Scale(0.5); 4759 CenterToPoint.SubtractVector(point->node); 4760 angle = CenterToPoint.Angle(&BaseLine); 4761 if (fabs(angle - M_PI / 2.) < fabs(BestAngle - M_PI / 2.)) { 4724 BaseLine = (*Runner->second->endpoints[0]->node->node) - 4725 (*Runner->second->endpoints[1]->node->node); 4726 CenterToPoint = 0.5 * ((*Runner->second->endpoints[0]->node->node) + 4727 (*Runner->second->endpoints[1]->node->node)); 4728 CenterToPoint -= (*point->node); 4729 angle = CenterToPoint.Angle(BaseLine); 4730 if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) { 4762 4731 BestAngle = angle; 4763 4732 BestLine = Runner->second; … … 4925 4894 for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++) 4926 4895 if (VectorWalker != VectorRunner) { // skip equals 4927 const double SCP = VectorWalker->second->ScalarProduct( VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles4896 const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles 4928 4897 DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl); 4929 4898 if (fabs(SCP + 1.) < ParallelEpsilon) { … … 5010 4979 TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator 5011 4980 /// 4a. Get NormalVector for one side (this is "front") 5012 NormalVector .CopyVector(&(*TriangleWalker)->NormalVector);4981 NormalVector = (*TriangleWalker)->NormalVector; 5013 4982 DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl); 5014 4983 TriangleWalker++; … … 5021 4990 TriangleSprinter++; 5022 4991 DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl); 5023 if (triangle->NormalVector.ScalarProduct( &NormalVector) < 0) { // if from other side, then delete and remove from list4992 if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list 5024 4993 DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl); 5025 4994 TriangleNrs.push(triangle->Nr); … … 5043 5012 AddTesselationTriangle(); // ... and add 5044 5013 TriangleNrs.pop(); 5045 BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector); 5046 BTS->NormalVector.Scale(-1.); 5014 BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector; 5047 5015 TriangleWalker++; 5048 5016 } -
src/tesselationhelpers.cpp
r632bc3 r8cbb97 14 14 #include "tesselationhelpers.hpp" 15 15 #include "vector.hpp" 16 #include "vector_ops.hpp" 16 17 #include "verbose.hpp" 17 18 … … 53 54 54 55 for(int i=0;i<3;i++) { 55 gsl_matrix_set(A, i, 0, a .x[i]);56 gsl_matrix_set(A, i, 1, b .x[i]);57 gsl_matrix_set(A, i, 2, c .x[i]);56 gsl_matrix_set(A, i, 0, a[i]); 57 gsl_matrix_set(A, i, 1, b[i]); 58 gsl_matrix_set(A, i, 2, c[i]); 58 59 } 59 60 m11 = DetGet(A, 1); 60 61 61 62 for(int i=0;i<3;i++) { 62 gsl_matrix_set(A, i, 0, a .x[i]*a.x[i] + b.x[i]*b.x[i] + c.x[i]*c.x[i]);63 gsl_matrix_set(A, i, 1, b .x[i]);64 gsl_matrix_set(A, i, 2, c .x[i]);63 gsl_matrix_set(A, i, 0, a[i]*a[i] + b[i]*b[i] + c[i]*c[i]); 64 gsl_matrix_set(A, i, 1, b[i]); 65 gsl_matrix_set(A, i, 2, c[i]); 65 66 } 66 67 m12 = DetGet(A, 1); 67 68 68 69 for(int i=0;i<3;i++) { 69 gsl_matrix_set(A, i, 0, a .x[i]*a.x[i] + b.x[i]*b.x[i] + c.x[i]*c.x[i]);70 gsl_matrix_set(A, i, 1, a .x[i]);71 gsl_matrix_set(A, i, 2, c .x[i]);70 gsl_matrix_set(A, i, 0, a[i]*a[i] + b[i]*b[i] + c[i]*c[i]); 71 gsl_matrix_set(A, i, 1, a[i]); 72 gsl_matrix_set(A, i, 2, c[i]); 72 73 } 73 74 m13 = DetGet(A, 1); 74 75 75 76 for(int i=0;i<3;i++) { 76 gsl_matrix_set(A, i, 0, a .x[i]*a.x[i] + b.x[i]*b.x[i] + c.x[i]*c.x[i]);77 gsl_matrix_set(A, i, 1, a .x[i]);78 gsl_matrix_set(A, i, 2, b .x[i]);77 gsl_matrix_set(A, i, 0, a[i]*a[i] + b[i]*b[i] + c[i]*c[i]); 78 gsl_matrix_set(A, i, 1, a[i]); 79 gsl_matrix_set(A, i, 2, b[i]); 79 80 } 80 81 m14 = DetGet(A, 1); … … 83 84 DoeLog(1) && (eLog()<< Verbose(1) << "three points are colinear." << endl); 84 85 85 center-> x[0]= 0.5 * m12/ m11;86 center-> x[1]= -0.5 * m13/ m11;87 center-> x[2]= 0.5 * m14/ m11;88 89 if (fabs(a.Distance( center) - RADIUS) > MYEPSILON)90 DoeLog(1) && (eLog()<< Verbose(1) << "The given center is further way by " << fabs(a.Distance( center) - RADIUS) << " from a than RADIUS." << endl);86 center->at(0) = 0.5 * m12/ m11; 87 center->at(1) = -0.5 * m13/ m11; 88 center->at(2) = 0.5 * m14/ m11; 89 90 if (fabs(a.Distance(*center) - RADIUS) > MYEPSILON) 91 DoeLog(1) && (eLog()<< Verbose(1) << "The given center is further way by " << fabs(a.Distance(*center) - RADIUS) << " from a than RADIUS." << endl); 91 92 92 93 gsl_matrix_free(A); … … 120 121 Vector OtherCenter; 121 122 Center->Zero(); 122 helper.CopyVector(&a); 123 helper.Scale(sin(2.*alpha)); 124 Center->AddVector(&helper); 125 helper.CopyVector(&b); 126 helper.Scale(sin(2.*beta)); 127 Center->AddVector(&helper); 128 helper.CopyVector(&c); 129 helper.Scale(sin(2.*gamma)); 130 Center->AddVector(&helper); 123 helper = sin(2.*alpha) * a; 124 (*Center) += helper; 125 helper = sin(2.*beta) * b; 126 (*Center) += helper; 127 helper = sin(2.*gamma) * c; 128 (*Center) += helper; 131 129 //*Center = a * sin(2.*alpha) + b * sin(2.*beta) + c * sin(2.*gamma) ; 132 130 Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma))); 133 NewUmkreismittelpunkt->CopyVector(Center);131 (*NewUmkreismittelpunkt) = (*Center); 134 132 DoLog(1) && (Log() << Verbose(1) << "Center of new circumference is " << *NewUmkreismittelpunkt << ".\n"); 135 133 // Here we calculated center of circumscribing circle, using barycentric coordinates 136 134 DoLog(1) && (Log() << Verbose(1) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n"); 137 135 138 TempNormal.CopyVector(&a); 139 TempNormal.SubtractVector(&b); 140 helper.CopyVector(&a); 141 helper.SubtractVector(&c); 142 TempNormal.VectorProduct(&helper); 136 TempNormal = a - b; 137 helper = a - c; 138 TempNormal.VectorProduct(helper); 143 139 if (fabs(HalfplaneIndicator) < MYEPSILON) 144 140 { 145 if ((TempNormal.ScalarProduct( AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(AlternativeDirection) >0 && AlternativeIndicator <0))141 if ((TempNormal.ScalarProduct(*AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(*AlternativeDirection) >0 && AlternativeIndicator <0)) 146 142 { 147 TempNormal .Scale(-1);143 TempNormal *= -1; 148 144 } 149 145 } 150 146 else 151 147 { 152 if (((TempNormal.ScalarProduct( Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(Direction)>0) && (HalfplaneIndicator<0)))148 if (((TempNormal.ScalarProduct(*Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(*Direction)>0) && (HalfplaneIndicator<0))) 153 149 { 154 TempNormal .Scale(-1);150 TempNormal *= -1; 155 151 } 156 152 } … … 161 157 TempNormal.Scale(Restradius); 162 158 DoLog(1) && (Log() << Verbose(1) << "Shift vector to sphere of circumference is " << TempNormal << ".\n"); 163 164 Center->AddVector(&TempNormal); 159 (*Center) += TempNormal; 165 160 DoLog(1) && (Log() << Verbose(1) << "Center of sphere of circumference is " << *Center << ".\n"); 166 161 GetSphere(&OtherCenter, a, b, c, RADIUS); … … 180 175 Vector helper; 181 176 double alpha, beta, gamma; 182 Vector SideA, SideB, SideC; 183 SideA.CopyVector(b); 184 SideA.SubtractVector(&c); 185 SideB.CopyVector(c); 186 SideB.SubtractVector(&a); 187 SideC.CopyVector(a); 188 SideC.SubtractVector(&b); 189 alpha = M_PI - SideB.Angle(&SideC); 190 beta = M_PI - SideC.Angle(&SideA); 191 gamma = M_PI - SideA.Angle(&SideB); 177 Vector SideA = b - c; 178 Vector SideB = c - a; 179 Vector SideC = a - b; 180 alpha = M_PI - SideB.Angle(SideC); 181 beta = M_PI - SideC.Angle(SideA); 182 gamma = M_PI - SideA.Angle(SideB); 192 183 //Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl; 193 184 if (fabs(M_PI - alpha - beta - gamma) > HULLEPSILON) { … … 196 187 197 188 Center->Zero(); 198 helper.CopyVector(a); 199 helper.Scale(sin(2.*alpha)); 200 Center->AddVector(&helper); 201 helper.CopyVector(b); 202 helper.Scale(sin(2.*beta)); 203 Center->AddVector(&helper); 204 helper.CopyVector(c); 205 helper.Scale(sin(2.*gamma)); 206 Center->AddVector(&helper); 189 helper = sin(2.*alpha) * a; 190 (*Center) += helper; 191 helper = sin(2.*beta) * b; 192 (*Center) += helper; 193 helper = sin(2.*gamma) * c; 194 (*Center) += helper; 207 195 Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma))); 208 196 }; … … 226 214 Vector helper; 227 215 double radius, alpha; 228 Vector RelativeOldSphereCenter; 229 Vector RelativeNewSphereCenter; 230 231 RelativeOldSphereCenter.CopyVector(&OldSphereCenter); 232 RelativeOldSphereCenter.SubtractVector(&CircleCenter); 233 RelativeNewSphereCenter.CopyVector(&NewSphereCenter); 234 RelativeNewSphereCenter.SubtractVector(&CircleCenter); 235 helper.CopyVector(&RelativeNewSphereCenter); 216 217 Vector RelativeOldSphereCenter = OldSphereCenter - CircleCenter; 218 Vector RelativeNewSphereCenter = NewSphereCenter - CircleCenter; 219 helper = RelativeNewSphereCenter; 236 220 // test whether new center is on the parameter circle's plane 237 if (fabs(helper.ScalarProduct( &CirclePlaneNormal)) > HULLEPSILON) {238 DoeLog(1) && (eLog()<< Verbose(1) << "Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct( &CirclePlaneNormal)) << "!" << endl);239 helper.ProjectOntoPlane( &CirclePlaneNormal);221 if (fabs(helper.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) { 222 DoeLog(1) && (eLog()<< Verbose(1) << "Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct(CirclePlaneNormal)) << "!" << endl); 223 helper.ProjectOntoPlane(CirclePlaneNormal); 240 224 } 241 225 radius = helper.NormSquared(); … … 243 227 if (fabs(radius - CircleRadius) > HULLEPSILON) 244 228 DoeLog(1) && (eLog()<< Verbose(1) << "The projected center of the new sphere has radius " << radius << " instead of " << CircleRadius << "." << endl); 245 alpha = helper.Angle( &RelativeOldSphereCenter);229 alpha = helper.Angle(RelativeOldSphereCenter); 246 230 // make the angle unique by checking the halfplanes/search direction 247 if (helper.ScalarProduct( &SearchDirection) < -HULLEPSILON) // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals231 if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON) // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals 248 232 alpha = 2.*M_PI - alpha; 249 233 DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << RelativeOldSphereCenter << " and resulting angle is " << alpha << "." << endl); 250 radius = helper.Distance( &RelativeOldSphereCenter);251 helper.ProjectOntoPlane( &NormalVector);234 radius = helper.Distance(RelativeOldSphereCenter); 235 helper.ProjectOntoPlane(NormalVector); 252 236 // check whether new center is somewhat away or at least right over the current baseline to prevent intersecting triangles 253 237 if ((radius > HULLEPSILON) || (helper.Norm() < HULLEPSILON)) { … … 279 263 struct Intersection *I = (struct Intersection *)params; 280 264 Vector intersection; 281 Vector SideA,SideB,HeightA, HeightB;282 265 for (int i=0;i<NDIM;i++) 283 intersection.x[i] = gsl_vector_get(x, i); 284 285 SideA.CopyVector(&(I->x1)); 286 SideA.SubtractVector(&I->x2); 287 HeightA.CopyVector(&intersection); 288 HeightA.SubtractVector(&I->x1); 289 HeightA.ProjectOntoPlane(&SideA); 290 291 SideB.CopyVector(&I->x3); 292 SideB.SubtractVector(&I->x4); 293 HeightB.CopyVector(&intersection); 294 HeightB.SubtractVector(&I->x3); 295 HeightB.ProjectOntoPlane(&SideB); 296 297 retval = HeightA.ScalarProduct(&HeightA) + HeightB.ScalarProduct(&HeightB); 266 intersection[i] = gsl_vector_get(x, i); 267 268 Vector SideA = I->x1 -I->x2 ; 269 Vector HeightA = intersection - I->x1; 270 HeightA.ProjectOntoPlane(SideA); 271 272 Vector SideB = I->x3 - I->x4; 273 Vector HeightB = intersection - I->x3; 274 HeightB.ProjectOntoPlane(SideB); 275 276 retval = HeightA.ScalarProduct(HeightA) + HeightB.ScalarProduct(HeightB); 298 277 //Log() << Verbose(1) << "MinIntersectDistance called, result: " << retval << endl; 299 278 … … 320 299 321 300 struct Intersection par; 322 par.x1 .CopyVector(&point1);323 par.x2 .CopyVector(&point2);324 par.x3 .CopyVector(&point3);325 par.x4 .CopyVector(&point4);301 par.x1 = point1; 302 par.x2 = point2; 303 par.x3 = point3; 304 par.x4 = point4; 326 305 327 306 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex; … … 336 315 /* Starting point */ 337 316 x = gsl_vector_alloc(NDIM); 338 gsl_vector_set(x, 0, point1 .x[0]);339 gsl_vector_set(x, 1, point1 .x[1]);340 gsl_vector_set(x, 2, point1 .x[2]);317 gsl_vector_set(x, 0, point1[0]); 318 gsl_vector_set(x, 1, point1[1]); 319 gsl_vector_set(x, 2, point1[2]); 341 320 342 321 /* Set initial step sizes to 1 */ … … 369 348 370 349 // check whether intersection is in between or not 371 Vector intersection , SideA, SideB, HeightA, HeightB;350 Vector intersection; 372 351 double t1, t2; 373 352 for (int i = 0; i < NDIM; i++) { 374 intersection.x[i] = gsl_vector_get(s->x, i); 375 } 376 377 SideA.CopyVector(&par.x2); 378 SideA.SubtractVector(&par.x1); 379 HeightA.CopyVector(&intersection); 380 HeightA.SubtractVector(&par.x1); 381 382 t1 = HeightA.ScalarProduct(&SideA)/SideA.ScalarProduct(&SideA); 383 384 SideB.CopyVector(&par.x4); 385 SideB.SubtractVector(&par.x3); 386 HeightB.CopyVector(&intersection); 387 HeightB.SubtractVector(&par.x3); 388 389 t2 = HeightB.ScalarProduct(&SideB)/SideB.ScalarProduct(&SideB); 353 intersection[i] = gsl_vector_get(s->x, i); 354 } 355 356 Vector SideA = par.x2 - par.x1; 357 Vector HeightA = intersection - par.x1; 358 359 t1 = HeightA.ScalarProduct(SideA)/SideA.ScalarProduct(SideA); 360 361 Vector SideB = par.x4 - par.x3; 362 Vector HeightB = intersection - par.x3; 363 364 t2 = HeightB.ScalarProduct(SideB)/SideB.ScalarProduct(SideB); 390 365 391 366 Log() << Verbose(1) << "Intersection " << intersection << " is at " … … 427 402 if (point.IsZero()) 428 403 return M_PI; 429 double phi = point.Angle( &reference);430 if (OrthogonalVector.ScalarProduct( &point) > 0) {404 double phi = point.Angle(reference); 405 if (OrthogonalVector.ScalarProduct(point) > 0) { 431 406 phi = 2.*M_PI - phi; 432 407 } … … 451 426 double volume; 452 427 453 TetraederVector[0] .CopyVector(a);454 TetraederVector[1] .CopyVector(b);455 TetraederVector[2] .CopyVector(c);428 TetraederVector[0] = a; 429 TetraederVector[1] = b; 430 TetraederVector[2] = c; 456 431 for (int j=0;j<3;j++) 457 TetraederVector[j].SubtractVector( &d);458 Point .CopyVector(&TetraederVector[0]);459 Point.VectorProduct( &TetraederVector[1]);460 volume = 1./6. * fabs(Point.ScalarProduct( &TetraederVector[2]));432 TetraederVector[j].SubtractVector(d); 433 Point = TetraederVector[0]; 434 Point.VectorProduct(TetraederVector[1]); 435 volume = 1./6. * fabs(Point.ScalarProduct(TetraederVector[2])); 461 436 return volume; 462 437 }; … … 582 557 if (List != NULL) { 583 558 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 584 helper.CopyVector(Point); 585 helper.SubtractVector((*Runner)->node); 559 helper = (*Point) - (*(*Runner)->node); 586 560 double currentNorm = helper. Norm(); 587 561 if (currentNorm < distance) { … … 637 611 if (List != NULL) { 638 612 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 639 helper.CopyVector(Point); 640 helper.SubtractVector((*Runner)->node); 613 helper = (*Point) - (*(*Runner)->node); 641 614 double currentNorm = helper.NormSquared(); 642 615 if (currentNorm < distance) { … … 677 650 Info FunctionInfo(__func__); 678 651 // construct the plane of the two baselines (i.e. take both their directional vectors) 679 Vector Normal; 680 Vector Baseline, OtherBaseline; 681 Baseline.CopyVector(Base->endpoints[1]->node->node); 682 Baseline.SubtractVector(Base->endpoints[0]->node->node); 683 OtherBaseline.CopyVector(OtherBase->endpoints[1]->node->node); 684 OtherBaseline.SubtractVector(OtherBase->endpoints[0]->node->node); 685 Normal.CopyVector(&Baseline); 686 Normal.VectorProduct(&OtherBaseline); 652 Vector Baseline = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node); 653 Vector OtherBaseline = (*OtherBase->endpoints[1]->node->node) - (*OtherBase->endpoints[0]->node->node); 654 Vector Normal = Baseline; 655 Normal.VectorProduct(OtherBaseline); 687 656 Normal.Normalize(); 688 657 DoLog(1) && (Log() << Verbose(1) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl); 689 658 690 659 // project one offset point of OtherBase onto this plane (and add plane offset vector) 691 Vector NewOffset; 692 NewOffset.CopyVector(OtherBase->endpoints[0]->node->node); 693 NewOffset.SubtractVector(Base->endpoints[0]->node->node); 694 NewOffset.ProjectOntoPlane(&Normal); 695 NewOffset.AddVector(Base->endpoints[0]->node->node); 696 Vector NewDirection; 697 NewDirection.CopyVector(&NewOffset); 698 NewDirection.AddVector(&OtherBaseline); 660 Vector NewOffset = (*OtherBase->endpoints[0]->node->node) - (*Base->endpoints[0]->node->node); 661 NewOffset.ProjectOntoPlane(Normal); 662 NewOffset += (*Base->endpoints[0]->node->node); 663 Vector NewDirection = NewOffset + OtherBaseline; 699 664 700 665 // calculate the intersection between this projected baseline and Base 701 666 Vector *Intersection = new Vector; 702 Intersection->GetIntersectionOfTwoLinesOnPlane(Base->endpoints[0]->node->node, Base->endpoints[1]->node->node, &NewOffset, &NewDirection, &Normal); 703 Normal.CopyVector(Intersection); 704 Normal.SubtractVector(Base->endpoints[0]->node->node); 705 DoLog(1) && (Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl); 667 *Intersection = GetIntersectionOfTwoLinesOnPlane(*(Base->endpoints[0]->node->node), 668 *(Base->endpoints[1]->node->node), 669 NewOffset, NewDirection); 670 Normal = (*Intersection) - (*Base->endpoints[0]->node->node); 671 DoLog(1) && (Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(Baseline)/Baseline.NormSquared()) << "." << endl); 706 672 707 673 return Intersection; … … 721 687 return -1; 722 688 } 723 distance = x->DistanceToPlane( &triangle->NormalVector,triangle->endpoints[0]->node->node);689 distance = x->DistanceToPlane(triangle->NormalVector, *triangle->endpoints[0]->node->node); 724 690 return distance; 725 691 }; … … 747 713 *vrmlfile << "Sphere {" << endl << " "; // 2 is sphere type 748 714 for (i=0;i<NDIM;i++) 749 *vrmlfile << Walker->node-> x[i]-center->x[i]<< " ";715 *vrmlfile << Walker->node->at(i)-center->at(i) << " "; 750 716 *vrmlfile << "\t0.1\t1. 1. 1." << endl; // radius 0.05 and white as colour 751 717 cloud->GoToNext(); … … 757 723 for (i=0;i<3;i++) { // print each node 758 724 for (int j=0;j<NDIM;j++) // and for each node all NDIM coordinates 759 *vrmlfile << TriangleRunner->second->endpoints[i]->node->node-> x[j]-center->x[j]<< " ";725 *vrmlfile << TriangleRunner->second->endpoints[i]->node->node->at(j)-center->at(j) << " "; 760 726 *vrmlfile << "\t"; 761 727 } … … 784 750 Vector *center = cloud->GetCenter(); 785 751 // make the circumsphere's center absolute again 786 helper.CopyVector(Tess->LastTriangle->endpoints[0]->node->node); 787 helper.AddVector(Tess->LastTriangle->endpoints[1]->node->node); 788 helper.AddVector(Tess->LastTriangle->endpoints[2]->node->node); 789 helper.Scale(1./3.); 790 helper.SubtractVector(center); 752 Vector helper = (1./3.) * ((*Tess->LastTriangle->endpoints[0]->node->node) + 753 (*Tess->LastTriangle->endpoints[1]->node->node) + 754 (*Tess->LastTriangle->endpoints[2]->node->node)); 755 helper -= (*center); 791 756 // and add to file plus translucency object 792 757 *rasterfile << "# current virtual sphere\n"; 793 758 *rasterfile << "8\n 25.0 0.6 -1.0 -1.0 -1.0 0.2 0 0 0 0\n"; 794 *rasterfile << "2\n " << helper .x[0] << " " << helper.x[1] << " " << helper.x[2] << "\t" << 5. << "\t1 0 0\n";759 *rasterfile << "2\n " << helper[0] << " " << helper[1] << " " << helper[2] << "\t" << 5. << "\t1 0 0\n"; 795 760 *rasterfile << "9\n terminating special property\n"; 796 761 delete(center); … … 820 785 *rasterfile << "2" << endl << " "; // 2 is sphere type 821 786 for (i=0;i<NDIM;i++) 822 *rasterfile << Walker->node-> x[i]-center->x[i]<< " ";787 *rasterfile << Walker->node->at(i)-center->at(i) << " "; 823 788 *rasterfile << "\t0.1\t1. 1. 1." << endl; // radius 0.05 and white as colour 824 789 cloud->GoToNext(); … … 831 796 for (i=0;i<3;i++) { // print each node 832 797 for (int j=0;j<NDIM;j++) // and for each node all NDIM coordinates 833 *rasterfile << TriangleRunner->second->endpoints[i]->node->node-> x[j]-center->x[j]<< " ";798 *rasterfile << TriangleRunner->second->endpoints[i]->node->node->at(j)-center->at(j) << " "; 834 799 *rasterfile << "\t"; 835 800 } … … 881 846 Walker = target->second->node; 882 847 LookupList[Walker->nr] = Counter++; 883 *tecplot << Walker->node-> x[0] << " " << Walker->node->x[1] << " " << Walker->node->x[2]<< " " << target->second->value << endl;848 *tecplot << Walker->node->at(0) << " " << Walker->node->at(1) << " " << Walker->node->at(2) << " " << target->second->value << endl; 884 849 } 885 850 *tecplot << endl; -
src/test/ActOnAlltest.hpp
r632bc3 r8cbb97 27 27 28 28 template <typename klasse, typename res, typename T> void ActOnAll( res (klasse::*f)(T), T t ); 29 template <typename klasse, typename res, typename T> void ActOnAll( res (klasse::*f)(T&), T &t ); 29 30 template <typename klasse, typename res, typename T, typename U> void ActOnAll( res (klasse::*f)(T, U), T t, U u ); 30 31 template <typename klasse, typename res, typename T, typename U, typename V> void ActOnAll( res (klasse::*f)(T, U, V), T t, U u, V v); … … 76 77 }; 77 78 79 template <typename klasse, typename res, typename T> void VectorList::ActOnAll( res (klasse::*f)(T&), T &t ) 80 { 81 for (ListOfVectors::iterator Runner = Vectors.begin(); Runner != Vectors.end(); Runner++) 82 ((*Runner)->*f)(t); 83 }; 84 78 85 template <typename klasse, typename res, typename T, typename U> void VectorList::ActOnAll( res (klasse::*f)(T, U), T t, U u ) 79 86 { -
src/triangleintersectionlist.cpp
r632bc3 r8cbb97 94 94 if (runner != IntersectionList.end()) { 95 95 // if we have found one, check Scalarproduct between the vector 96 Vector TestVector(Point); 97 TestVector.SubtractVector((*runner).second); 96 Vector TestVector = (*Point) - (*(*runner).second); 98 97 if (fabs(TestVector.NormSquared()) < MYEPSILON) // 99 98 return true; 100 const double sign = (*runner).first->NormalVector.ScalarProduct( &TestVector);99 const double sign = (*runner).first->NormalVector.ScalarProduct(TestVector); 101 100 if (sign < 0) { 102 101 return true; … … 147 146 if (DistanceList.empty()) 148 147 for (TriangleVectorMap::const_iterator runner = IntersectionList.begin(); runner != IntersectionList.end(); runner++) 149 DistanceList.insert( pair<double, BoundaryTriangleSet *> (Point->Distance( (*runner).second), (*runner).first) );148 DistanceList.insert( pair<double, BoundaryTriangleSet *> (Point->Distance(*(*runner).second), (*runner).first) ); 150 149 151 150 //for (DistanceTriangleMap::const_iterator runner = DistanceList.begin(); runner != DistanceList.end(); runner++) -
src/unittests/ActOnAllUnitTest.cpp
r632bc3 r8cbb97 56 56 57 57 // adding, subtracting 58 VL.ActOnAll( &Vector::AddVector, &test );58 VL.ActOnAll( &Vector::AddVector, test ); 59 59 CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); 60 VL.ActOnAll( &Vector::SubtractVector, &test );60 VL.ActOnAll( &Vector::SubtractVector, test ); 61 61 CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); 62 62 }; … … 70 70 71 71 // scaling by value 72 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, 2.);72 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, factor ); 73 73 CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); 74 74 75 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, 0.5 ); 76 CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); 77 78 // scaling by ref 79 VL.ActOnAll( (void (Vector::*)(const double * const)) &Vector::Scale, (const double * const)&factor ); 80 CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); 81 82 VL.ActOnAll( (void (Vector::*)(const double * const)) &Vector::Scale, (const double * const)&inverse ); 75 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, inverse ); 83 76 CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); 84 77 … … 90 83 inverses[i] = 1./factors[i]; 91 84 } 92 VL.ActOnAll ( (void (Vector::*)(const double ** const)) &Vector::Scale, (const double ** const)&factors );85 VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, factors ); 93 86 CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); 94 87 95 VL.ActOnAll ( (void (Vector::*)(const double ** const)) &Vector::Scale, (const double ** const)&inverses );88 VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, inverses ); 96 89 CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); 97 90 Free(factors); 98 91 Free(inverses); 99 92 }; 93 94 #if 0 95 96 // Unitttest deactivated for now... 97 // Reasons: 98 // Vector::MakeNormalVector has been removed and is now part of Plane class 99 // VectorList::ActOnAll is in the test directory and seems to be used only for unittests 100 // MakeNormal never depended on the input Vector except in the case of linear dependence (i.e. failure) 101 // 102 // TODO: Rethink what exactely is being tested at this point and introduce a new unittest for the 103 // tested behaviour. Most likely this should result in a thourough unittest of the plane class 100 104 101 105 /** UnitTest for VectorList::ActOnAll() and Vector::MakeNormalVector() … … 113 117 // check that x and y components are zero 114 118 for (ListOfVectors::iterator Runner = VL.Vectors.begin(); Runner != VL.Vectors.end(); Runner++) { 115 CPPUNIT_ASSERT_EQUAL( (*Runner)-> x[0], 0. );116 CPPUNIT_ASSERT_EQUAL( (*Runner)-> x[1], 0. );119 CPPUNIT_ASSERT_EQUAL( (*Runner)->at(0) , 0. ); 120 CPPUNIT_ASSERT_EQUAL( (*Runner)->at(1) , 0. ); 117 121 } 118 122 }; 123 124 #endif -
src/unittests/ActOnAllUnitTest.hpp
r632bc3 r8cbb97 20 20 CPPUNIT_TEST ( AddSubtractTest ); 21 21 CPPUNIT_TEST ( ScaleTest ); 22 #if 0 23 // test deactivated. See .cpp for reasons and workarounds 22 24 CPPUNIT_TEST ( NormalizeTest ); 25 #endif 23 26 CPPUNIT_TEST_SUITE_END(); 24 27 -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
r632bc3 r8cbb97 64 64 Walker = World::getInstance().createAtom(); 65 65 Walker->type = hydrogen; 66 Walker->node->Init(1., 0., 1. );66 *Walker->node = Vector(1., 0., 1. ); 67 67 TestMolecule->AddAtom(Walker); 68 68 Walker = World::getInstance().createAtom(); 69 69 Walker->type = hydrogen; 70 Walker->node->Init(0., 1., 1. );70 *Walker->node = Vector(0., 1., 1. ); 71 71 TestMolecule->AddAtom(Walker); 72 72 Walker = World::getInstance().createAtom(); 73 73 Walker->type = hydrogen; 74 Walker->node->Init(1., 1., 0. );74 *Walker->node = Vector(1., 1., 0. ); 75 75 TestMolecule->AddAtom(Walker); 76 76 Walker = World::getInstance().createAtom(); 77 77 Walker->type = hydrogen; 78 Walker->node->Init(0., 0., 0. );78 *Walker->node = Vector(0., 0., 0. ); 79 79 TestMolecule->AddAtom(Walker); 80 80 -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
r632bc3 r8cbb97 40 40 void AnalysisCorrelationToSurfaceUnitTest::setUp() 41 41 { 42 ASSERT_DO(Assert::Throw);42 //ASSERT_DO(Assert::Throw); 43 43 44 44 atom *Walker = NULL; … … 46 46 // init private all pointers to zero 47 47 TestList = NULL; 48 Test Molecule = NULL;48 TestSurfaceMolecule = NULL; 49 49 hydrogen = NULL; 50 50 tafel = NULL; … … 73 73 Walker = World::getInstance().createAtom(); 74 74 Walker->type = hydrogen; 75 Walker->node->Init(1., 0., 1. ); 76 TestSurfaceMolecule->AddAtom(Walker); 77 Walker = World::getInstance().createAtom(); 78 Walker->type = hydrogen; 79 Walker->node->Init(0., 1., 1. ); 80 TestSurfaceMolecule->AddAtom(Walker); 81 Walker = World::getInstance().createAtom(); 82 Walker->type = hydrogen; 83 Walker->node->Init(1., 1., 0. ); 84 TestSurfaceMolecule->AddAtom(Walker); 85 Walker = World::getInstance().createAtom(); 86 Walker->type = hydrogen; 87 Walker->node->Init(0., 0., 0. ); 75 *Walker->node = Vector(1., 0., 1. ); 76 77 TestSurfaceMolecule->AddAtom(Walker); 78 Walker = World::getInstance().createAtom(); 79 Walker->type = hydrogen; 80 *Walker->node = Vector(0., 1., 1. ); 81 TestSurfaceMolecule->AddAtom(Walker); 82 Walker = World::getInstance().createAtom(); 83 Walker->type = hydrogen; 84 *Walker->node = Vector(1., 1., 0. ); 85 TestSurfaceMolecule->AddAtom(Walker); 86 Walker = World::getInstance().createAtom(); 87 Walker->type = hydrogen; 88 *Walker->node = Vector(0., 0., 0. ); 88 89 TestSurfaceMolecule->AddAtom(Walker); 89 90 … … 101 102 102 103 // add outer atoms 103 Test Molecule = World::getInstance().createMolecule();104 Walker = World::getInstance().createAtom(); 105 Walker->type = carbon; 106 Walker->node->Init(4., 0., 4. );107 Test Molecule->AddAtom(Walker);108 Walker = World::getInstance().createAtom(); 109 Walker->type = carbon; 110 Walker->node->Init(0., 4., 4. );111 Test Molecule->AddAtom(Walker);112 Walker = World::getInstance().createAtom(); 113 Walker->type = carbon; 114 Walker->node->Init(4., 4., 0. );115 Test Molecule->AddAtom(Walker);104 TestSurfaceMolecule = World::getInstance().createMolecule(); 105 Walker = World::getInstance().createAtom(); 106 Walker->type = carbon; 107 *Walker->node = Vector(4., 0., 4. ); 108 TestSurfaceMolecule->AddAtom(Walker); 109 Walker = World::getInstance().createAtom(); 110 Walker->type = carbon; 111 *Walker->node = Vector(0., 4., 4. ); 112 TestSurfaceMolecule->AddAtom(Walker); 113 Walker = World::getInstance().createAtom(); 114 Walker->type = carbon; 115 *Walker->node = Vector(4., 4., 0. ); 116 TestSurfaceMolecule->AddAtom(Walker); 116 117 // add inner atoms 117 118 Walker = World::getInstance().createAtom(); 118 119 Walker->type = carbon; 119 Walker->node->Init(0.5, 0.5, 0.5 );120 Test Molecule->AddAtom(Walker);121 Test Molecule->ActiveFlag = true;122 TestList->insert(Test Molecule);120 *Walker->node = Vector(0.5, 0.5, 0.5 ); 121 TestSurfaceMolecule->AddAtom(Walker); 122 TestSurfaceMolecule->ActiveFlag = true; 123 TestList->insert(TestSurfaceMolecule); 123 124 124 125 // init maps … … 150 151 { 151 152 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->AtomCount ); 152 CPPUNIT_ASSERT_EQUAL( 4, TestMolecule->AtomCount );153 153 CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() ); 154 154 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() ); -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.hpp
r632bc3 r8cbb97 44 44 45 45 MoleculeListClass *TestList; 46 molecule *TestMolecule;47 46 molecule *TestSurfaceMolecule; 48 47 element *hydrogen; -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
r632bc3 r8cbb97 63 63 Walker = World::getInstance().createAtom(); 64 64 Walker->type = hydrogen; 65 Walker->node->Init(1., 0., 1. );65 *Walker->node = Vector(1., 0., 1. ); 66 66 TestMolecule->AddAtom(Walker); 67 67 Walker = World::getInstance().createAtom(); 68 68 Walker->type = hydrogen; 69 Walker->node->Init(0., 1., 1. );69 *Walker->node = Vector(0., 1., 1. ); 70 70 TestMolecule->AddAtom(Walker); 71 71 Walker = World::getInstance().createAtom(); 72 72 Walker->type = hydrogen; 73 Walker->node->Init(1., 1., 0. );73 *Walker->node = Vector(1., 1., 0. ); 74 74 TestMolecule->AddAtom(Walker); 75 75 Walker = World::getInstance().createAtom(); 76 76 Walker->type = hydrogen; 77 Walker->node->Init(0., 0., 0. );77 *Walker->node = Vector(0., 0., 0. ); 78 78 TestMolecule->AddAtom(Walker); 79 79 -
src/unittests/CountBondsUnitTest.cpp
r632bc3 r8cbb97 72 72 Walker = World::getInstance().createAtom(); 73 73 Walker->type = hydrogen; 74 Walker->node->Init(-0.2418, 0.9350, 0. );74 *Walker->node = Vector(-0.2418, 0.9350, 0. ); 75 75 TestMolecule1->AddAtom(Walker); 76 76 Walker = World::getInstance().createAtom(); 77 77 Walker->type = hydrogen; 78 Walker->node->Init(0.9658, 0., 0. );78 *Walker->node = Vector(0.9658, 0., 0. ); 79 79 TestMolecule1->AddAtom(Walker); 80 80 Walker = World::getInstance().createAtom(); 81 81 Walker->type = oxygen; 82 Walker->node->Init(0., 0., 0. );82 *Walker->node = Vector(0., 0., 0. ); 83 83 TestMolecule1->AddAtom(Walker); 84 84 … … 86 86 Walker = World::getInstance().createAtom(); 87 87 Walker->type = hydrogen; 88 Walker->node->Init(-0.2418, 0.9350, 0. );88 *Walker->node = Vector(-0.2418, 0.9350, 0. ); 89 89 TestMolecule2->AddAtom(Walker); 90 90 Walker = World::getInstance().createAtom(); 91 91 Walker->type = hydrogen; 92 Walker->node->Init(0.9658, 0., 0. );92 *Walker->node = Vector(0.9658, 0., 0. ); 93 93 TestMolecule2->AddAtom(Walker); 94 94 Walker = World::getInstance().createAtom(); 95 95 Walker->type = oxygen; 96 Walker->node->Init(0., 0., 0. );96 *Walker->node = Vector(0., 0., 0. ); 97 97 TestMolecule2->AddAtom(Walker); 98 98 … … 165 165 166 166 cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl; 167 Translator .Init(3,0,0);167 Translator = Vector(3,0,0); 168 168 TestMolecule2->Translate(&Translator); 169 169 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) ); 170 170 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen) ); 171 171 //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz"); 172 Translator .Init(-3,0,0);172 Translator = Vector(-3,0,0); 173 173 TestMolecule2->Translate(&Translator); 174 174 175 175 cout << "Case 2: offset of (0,3,0), hence angle are (14.5, 165.5, 90) < 30 (only three, because other 90 is missing due to first H01 only fulfilling H-bond criteria)." << endl; 176 Translator .Init(0,3,0);176 Translator = Vector(0,3,0); 177 177 TestMolecule2->Translate(&Translator); 178 178 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) ); 179 179 //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz"); 180 Translator .Init(0,-3,0);180 Translator = Vector(0,-3,0); 181 181 TestMolecule2->Translate(&Translator); 182 182 183 183 cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl; 184 Translator .Init(0,-3,0);184 Translator = Vector(0,-3,0); 185 185 TestMolecule2->Scale((const double ** const)&mirror); 186 186 TestMolecule2->Translate(&Translator); 187 187 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) ); 188 188 //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz"); 189 Translator .Init(0,3,0);189 Translator = Vector(0,3,0); 190 190 TestMolecule2->Translate(&Translator); 191 191 TestMolecule2->Scale((const double ** const)&mirror); 192 192 193 193 cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl; 194 Translator .Init(2,1,0);194 Translator = Vector(2,1,0); 195 195 TestMolecule2->Translate(&Translator); 196 196 CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) ); 197 197 //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz"); 198 Translator .Init(-2,-1,0);198 Translator = Vector(-2,-1,0); 199 199 TestMolecule2->Translate(&Translator); 200 200 201 201 cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl; 202 Translator .Init(0,0,3);202 Translator = Vector(0,0,3); 203 203 TestMolecule2->Translate(&Translator); 204 204 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) ); 205 205 //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz"); 206 Translator .Init(0,0,-3);206 Translator = Vector(0,0,-3); 207 207 TestMolecule2->Translate(&Translator); 208 208 209 209 cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl; 210 Translator .Init(-3,0,0);210 Translator = Vector(-3,0,0); 211 211 TestMolecule2->Scale((const double ** const)&mirror); 212 212 TestMolecule2->Translate(&Translator); 213 213 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) ); 214 214 //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz"); 215 Translator .Init(3,0,0);215 Translator = Vector(3,0,0); 216 216 TestMolecule2->Translate(&Translator); 217 217 TestMolecule2->Scale((const double ** const)&mirror); 218 218 219 219 cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl; 220 Translator .Init(3,0,0);220 Translator = Vector(3,0,0); 221 221 TestMolecule2->Scale((const double ** const)&mirror); 222 222 TestMolecule2->Translate(&Translator); 223 223 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) ); 224 224 //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz"); 225 Translator .Init(-3,0,0);225 Translator = Vector(-3,0,0); 226 226 TestMolecule2->Translate(&Translator); 227 227 TestMolecule2->Scale((const double ** const)&mirror); 228 228 229 229 cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl; 230 Translator .Init(0,3,0);230 Translator = Vector(0,3,0); 231 231 TestMolecule2->Scale((const double ** const)&mirror); 232 232 TestMolecule2->Translate(&Translator); 233 233 //OutputTestMolecule(TestMolecule2, "testmolecule2-8.xyz"); 234 234 CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) ); 235 Translator .Init(0,-3,0);235 Translator = Vector(0,-3,0); 236 236 TestMolecule2->Translate(&Translator); 237 237 TestMolecule2->Scale((const double ** const)&mirror); -
src/unittests/LinkedCellUnitTest.cpp
r632bc3 r8cbb97 61 61 Walker = World::getInstance().createAtom(); 62 62 Walker->type = hydrogen; 63 Walker->node->Init(x, y, z );63 *Walker->node = Vector(x, y, z ); 64 64 TestMolecule->AddAtom(Walker); 65 65 } … … 207 207 Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker"); 208 208 strcpy(Walker->Name, "test"); 209 Walker->x .Init(1,1,1);209 Walker->x= Vector(1,1,1); 210 210 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) ); 211 211 World::getInstance().destroyAtom(Walker); … … 215 215 Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker"); 216 216 strcpy(Walker->Name, "test"); 217 Walker->x .Init(0,-1,0);217 Walker->x = Vector(0,-1,0); 218 218 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) ); 219 219 World::getInstance().destroyAtom(Walker); … … 231 231 for (double y=0.5;y<3;y+=1.) 232 232 for (double z=0.5;z<3;z+=1.) { 233 tester .Init(x,y,z);233 tester = Vector(x,y,z); 234 234 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) ); 235 235 } … … 238 238 for (double y=1.;y<4;y+=1.) 239 239 for (double z=1.;z<4;z+=1.) { 240 tester .Init(x,y,z);240 tester= Vector(x,y,z); 241 241 cout << "Tester is at " << tester << "." << endl; 242 242 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) ); … … 246 246 for (double y=0.5-1e-10;y<5;y+=3.1) 247 247 for (double z=0.5-1e-10;z<5;z+=3.1) { 248 tester .Init(x,y,z);248 tester = Vector(x,y,z); 249 249 cout << "The following test is supposed to fail and produce an ERROR." << endl; 250 250 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) ); 251 251 } 252 252 // check nonsense vectors 253 tester .Init(-423598,3245978,29349);253 tester= Vector(-423598,3245978,29349); 254 254 cout << "The following test is supposed to fail and produce an ERROR." << endl; 255 255 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) ); … … 264 264 int lower[NDIM], upper[NDIM]; 265 265 266 tester .Init(0.5,0.5,0.5);266 tester= Vector(0.5,0.5,0.5); 267 267 LC->SetIndexToVector(&tester); 268 268 LC->GetNeighbourBounds(lower, upper); … … 284 284 285 285 // get all atoms 286 tester .Init(1.5,1.5,1.5);286 tester= Vector(1.5,1.5,1.5); 287 287 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 288 288 ListOfPoints = LC->GetallNeighbours(); … … 303 303 304 304 // get all atoms in one corner 305 tester .Init(0.5, 0.5, 0.5);305 tester= Vector(0.5, 0.5, 0.5); 306 306 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 307 307 ListOfPoints = LC->GetallNeighbours(); … … 311 311 while (Walker->next != TestMolecule->end) { 312 312 Walker = Walker->next; 313 if ((Walker->x .x[0] <2) && (Walker->x.x[1] <2) && (Walker->x.x[2] <2)) {313 if ((Walker->x[0] <2) && (Walker->x[1] <2) && (Walker->x[2] <2)) { 314 314 ListOfPoints->remove(Walker); 315 315 size--; … … 323 323 324 324 // get all atoms from one corner 325 tester .Init(0.5, 0.5, 0.5);325 tester = Vector(0.5, 0.5, 0.5); 326 326 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 327 327 ListOfPoints = LC->GetallNeighbours(3); … … 352 352 353 353 // get all points around central arom with radius 1. 354 tester .Init(1.5,1.5,1.5);354 tester= Vector(1.5,1.5,1.5); 355 355 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 356 356 ListOfPoints = LC->GetPointsInsideSphere(1., &tester); … … 360 360 while (Walker->next != TestMolecule->end) { 361 361 Walker = Walker->next; 362 if ((Walker->x.DistanceSquared( &tester) - 1.) < MYEPSILON ) {362 if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) { 363 363 ListOfPoints->remove(Walker); 364 364 size--; -
src/unittests/analysisbondsunittest.cpp
r632bc3 r8cbb97 69 69 Walker = World::getInstance().createAtom(); 70 70 Walker->type = hydrogen; 71 Walker->node->Init(1.5, 0., 1.5 );71 *Walker->node = Vector(1.5, 0., 1.5 ); 72 72 TestMolecule->AddAtom(Walker); 73 73 Walker = World::getInstance().createAtom(); 74 74 Walker->type = hydrogen; 75 Walker->node->Init(0., 1.5, 1.5 );75 *Walker->node = Vector(0., 1.5, 1.5 ); 76 76 TestMolecule->AddAtom(Walker); 77 77 Walker = World::getInstance().createAtom(); 78 78 Walker->type = hydrogen; 79 Walker->node->Init(1.5, 1.5, 0. );79 *Walker->node = Vector(1.5, 1.5, 0. ); 80 80 TestMolecule->AddAtom(Walker); 81 81 Walker = World::getInstance().createAtom(); 82 82 Walker->type = hydrogen; 83 Walker->node->Init(0., 0., 0. );83 *Walker->node = Vector(0., 0., 0. ); 84 84 TestMolecule->AddAtom(Walker); 85 85 Walker = World::getInstance().createAtom(); 86 86 Walker->type = carbon; 87 Walker->node->Init(0.5, 0.5, 0.5 );87 *Walker->node = Vector(0.5, 0.5, 0.5 ); 88 88 TestMolecule->AddAtom(Walker); 89 89 -
src/unittests/bondgraphunittest.cpp
r632bc3 r8cbb97 70 70 Walker = World::getInstance().createAtom(); 71 71 Walker->type = carbon; 72 Walker->node->Init(1., 0., 1. );72 *Walker->node = Vector(1., 0., 1. ); 73 73 TestMolecule->AddAtom(Walker); 74 74 75 Walker = World::getInstance().createAtom(); 75 76 Walker->type = carbon; 76 Walker->node->Init(0., 1., 1. );77 *Walker->node = Vector(0., 1., 1. ); 77 78 TestMolecule->AddAtom(Walker); 79 78 80 Walker = World::getInstance().createAtom(); 79 81 Walker->type = carbon; 80 Walker->node->Init(1., 1., 0. );82 *Walker->node = Vector(1., 1., 0. ); 81 83 TestMolecule->AddAtom(Walker); 84 82 85 Walker = World::getInstance().createAtom(); 83 86 Walker->type = carbon; 84 Walker->node->Init(0., 0., 0. );87 *Walker->node = Vector(0., 0., 0. ); 85 88 TestMolecule->AddAtom(Walker); 86 89 -
src/unittests/listofbondsunittest.cpp
r632bc3 r8cbb97 58 58 Walker = World::getInstance().createAtom(); 59 59 Walker->type = hydrogen; 60 Walker->node->Init(1., 0., 1. );61 TestMolecule->AddAtom(Walker); 62 Walker = World::getInstance().createAtom(); 63 Walker->type = hydrogen; 64 Walker->node->Init(0., 1., 1. );65 TestMolecule->AddAtom(Walker); 66 Walker = World::getInstance().createAtom(); 67 Walker->type = hydrogen; 68 Walker->node->Init(1., 1., 0. );69 TestMolecule->AddAtom(Walker); 70 Walker = World::getInstance().createAtom(); 71 Walker->type = hydrogen; 72 Walker->node->Init(0., 0., 0. );60 *Walker->node = Vector(1., 0., 1. ); 61 TestMolecule->AddAtom(Walker); 62 Walker = World::getInstance().createAtom(); 63 Walker->type = hydrogen; 64 *Walker->node = Vector(0., 1., 1. ); 65 TestMolecule->AddAtom(Walker); 66 Walker = World::getInstance().createAtom(); 67 Walker->type = hydrogen; 68 *Walker->node = Vector(1., 1., 0. ); 69 TestMolecule->AddAtom(Walker); 70 Walker = World::getInstance().createAtom(); 71 Walker->type = hydrogen; 72 *Walker->node = Vector(0., 0., 0. ); 73 73 TestMolecule->AddAtom(Walker); 74 74 -
src/unittests/tesselation_boundarytriangleunittest.cpp
r632bc3 r8cbb97 86 86 87 87 // simple test on y line 88 Point .Init(-1.,0.5,0.);89 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 90 Point .Init(0.,0.5,0.);91 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 92 Point .Init(-4.,0.5,0.);88 Point = Vector(-1.,0.5,0.); 89 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 90 Point = Vector(0.,0.5,0.); 91 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 92 Point = Vector(-4.,0.5,0.); 93 93 CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 94 Point .Init(0.,0.5,0.);94 Point = Vector(0.,0.5,0.); 95 95 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 96 96 97 97 // simple test on x line 98 Point .Init(0.5,-1.,0.);99 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 100 Point .Init(0.5,0.,0.);101 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 102 Point .Init(0.5,-6.,0.);98 Point = Vector(0.5,-1.,0.); 99 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 100 Point = Vector(0.5,0.,0.); 101 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 102 Point = Vector(0.5,-6.,0.); 103 103 CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 104 Point .Init(0.5,0.,0.);104 Point = Vector(0.5,0.,0.); 105 105 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 106 106 107 107 // simple test on slanted line 108 Point .Init(1.,1.,0.);108 Point = Vector(1.,1.,0.); 109 109 CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 110 Point .Init(0.5,0.5,0.);111 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 112 Point .Init(5.,5.,0.);110 Point = Vector(0.5,0.5,0.); 111 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 112 Point = Vector(5.,5.,0.); 113 113 CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 114 Point .Init(0.5,0.5,0.);114 Point = Vector(0.5,0.5,0.); 115 115 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 116 116 117 117 // simple test on first node 118 Point .Init(-1.,-1.,0.);118 Point = Vector(-1.,-1.,0.); 119 119 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 120 Point .Init(0.,0.,0.);120 Point = Vector(0.,0.,0.); 121 121 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 122 122 123 123 // simple test on second node 124 Point .Init(0.,2.,0.);125 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 126 Point .Init(0.,1.,0.);124 Point = Vector(0.,2.,0.); 125 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 126 Point = Vector(0.,1.,0.); 127 127 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 128 128 129 129 // simple test on third node 130 Point .Init(2.,0.,0.);131 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 132 Point .Init(1.,0.,0.);130 Point = Vector(2.,0.,0.); 131 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 132 Point = Vector(1.,0.,0.); 133 133 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 134 134 }; … … 142 142 143 143 // straight down/up 144 Point .Init(1./3.,1./3.,+5.);144 Point = Vector(1./3.,1./3.,+5.); 145 145 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 146 Point .Init(1./3.,1./3.,0.);147 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 148 Point .Init(1./3.,1./3.,-5.);146 Point = Vector(1./3.,1./3.,0.); 147 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 148 Point = Vector(1./3.,1./3.,-5.); 149 149 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 150 Point .Init(1./3.,1./3.,0.);150 Point = Vector(1./3.,1./3.,0.); 151 151 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 152 152 153 153 // simple test on y line 154 Point .Init(-1.,0.5,+2.);154 Point = Vector(-1.,0.5,+2.); 155 155 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 156 Point .Init(0.,0.5,0.);157 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 158 Point .Init(-1.,0.5,-3.);156 Point = Vector(0.,0.5,0.); 157 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 158 Point = Vector(-1.,0.5,-3.); 159 159 CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 160 Point .Init(0.,0.5,0.);160 Point = Vector(0.,0.5,0.); 161 161 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 162 162 163 163 // simple test on x line 164 Point .Init(0.5,-1.,+1.);164 Point = Vector(0.5,-1.,+1.); 165 165 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 166 Point .Init(0.5,0.,0.);167 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 168 Point .Init(0.5,-1.,-2.);166 Point = Vector(0.5,0.,0.); 167 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 168 Point = Vector(0.5,-1.,-2.); 169 169 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 170 Point .Init(0.5,0.,0.);170 Point = Vector(0.5,0.,0.); 171 171 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 172 172 173 173 // simple test on slanted line 174 Point .Init(1.,1.,+3.);174 Point = Vector(1.,1.,+3.); 175 175 CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 176 Point .Init(0.5,0.5,0.);177 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 178 Point .Init(1.,1.,-4.);176 Point = Vector(0.5,0.5,0.); 177 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 178 Point = Vector(1.,1.,-4.); 179 179 CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 180 Point .Init(0.5,0.5,0.);180 Point = Vector(0.5,0.5,0.); 181 181 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 182 182 183 183 // simple test on first node 184 Point .Init(-1.,-1.,5.);184 Point = Vector(-1.,-1.,5.); 185 185 CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 186 Point .Init(0.,0.,0.);186 Point = Vector(0.,0.,0.); 187 187 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 188 188 189 189 // simple test on second node 190 Point .Init(0.,2.,5.);190 Point = Vector(0.,2.,5.); 191 191 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 192 Point .Init(0.,1.,0.);192 Point = Vector(0.,1.,0.); 193 193 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 194 194 195 195 // simple test on third node 196 Point .Init(2.,0.,5.);196 Point = Vector(2.,0.,5.); 197 197 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 198 Point .Init(1.,0.,0.);199 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 200 }; 198 Point = Vector(1.,0.,0.); 199 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 200 }; -
src/unittests/vectorunittest.cpp
r632bc3 r8cbb97 17 17 #include "memoryusageobserver.hpp" 18 18 #include "vector.hpp" 19 #include "vector_ops.hpp" 19 20 #include "vectorunittest.hpp" 21 #include "Plane.hpp" 22 #include "Exceptions/LinearDependenceException.hpp" 20 23 21 24 #ifdef HAVE_TESTRUNNER … … 23 26 #endif /*HAVE_TESTRUNNER*/ 24 27 28 #include <iostream> 29 30 using namespace std; 31 25 32 /********************************************** Test classes **************************************/ 26 33 … … 31 38 void VectorTest::setUp() 32 39 { 33 zero .Init(0.,0.,0.);34 unit .Init(1.,0.,0.);35 otherunit .Init(0.,1.,0.);36 notunit .Init(0.,1.,1.);37 two .Init(2.,1.,0.);40 zero = Vector(0.,0.,0.); 41 unit = Vector(1.,0.,0.); 42 otherunit = Vector(0.,1.,0.); 43 notunit = Vector(0.,1.,1.); 44 two = Vector(2.,1.,0.); 38 45 }; 39 46 … … 66 73 double factor; 67 74 // copy vector 68 fixture .Init(2.,3.,4.);75 fixture = Vector(2.,3.,4.); 69 76 CPPUNIT_ASSERT_EQUAL( Vector(2.,3.,4.), fixture ); 70 77 // summation and scaling 71 fixture.CopyVector(&zero); 72 fixture.AddVector(&unit); 73 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 74 fixture.CopyVector(&zero); 75 fixture.SubtractVector(&unit); 78 fixture = zero + unit; 79 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 80 fixture = zero - unit; 76 81 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 77 82 CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() ); 78 fixture.CopyVector(&zero); 79 fixture.AddVector(&zero); 83 fixture = zero + zero; 80 84 CPPUNIT_ASSERT_EQUAL( true, fixture.IsZero() ); 81 fixture.CopyVector(¬unit); 82 fixture.SubtractVector(&otherunit); 83 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 84 fixture.CopyVector(&unit); 85 fixture.AddVector(&otherunit); 85 fixture = notunit - otherunit; 86 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 87 fixture = unit - otherunit; 86 88 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 87 fixture.CopyVector(¬unit); 88 fixture.SubtractVector(&unit); 89 fixture.SubtractVector(&otherunit); 89 fixture = notunit - unit - otherunit; 90 90 CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() ); 91 fixture.CopyVector(&unit); 92 fixture.Scale(0.98); 91 fixture = 0.98 * unit; 93 92 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 94 fixture.CopyVector(&unit); 95 fixture.Scale(1.); 96 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 97 fixture.CopyVector(&unit); 93 fixture = 1. * unit; 94 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 98 95 factor = 0.98; 99 fixture .Scale(factor);96 fixture = factor * unit; 100 97 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 101 fixture.CopyVector(&unit);102 98 factor = 1.; 103 fixture .Scale(factor);99 fixture = factor * unit; 104 100 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 105 101 }; … … 131 127 void VectorTest::EuclidianScalarProductTest() 132 128 { 133 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( &zero) );134 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( &unit) );135 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( &otherunit) );136 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( ¬unit) );137 CPPUNIT_ASSERT_EQUAL( 1., unit.ScalarProduct( &unit) );138 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct( &unit) );139 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct( &unit) );140 CPPUNIT_ASSERT_EQUAL( 1., otherunit.ScalarProduct( ¬unit) );141 CPPUNIT_ASSERT_EQUAL( 2., two.ScalarProduct( &unit) );142 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct( &otherunit) );143 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct( ¬unit) );129 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(zero) ); 130 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(unit) ); 131 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(otherunit) ); 132 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(notunit) ); 133 CPPUNIT_ASSERT_EQUAL( 1., unit.ScalarProduct(unit) ); 134 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(unit) ); 135 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(unit) ); 136 CPPUNIT_ASSERT_EQUAL( 1., otherunit.ScalarProduct(notunit) ); 137 CPPUNIT_ASSERT_EQUAL( 2., two.ScalarProduct(unit) ); 138 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(otherunit) ); 139 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(notunit) ); 144 140 } 145 141 … … 162 158 void VectorTest::EuclidianDistancesTest() 163 159 { 164 CPPUNIT_ASSERT_EQUAL( 1., zero.Distance( &unit) );165 CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance( &unit) );166 CPPUNIT_ASSERT_EQUAL( sqrt(2.), zero.Distance( ¬unit) );167 CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance( ¬unit) );168 CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance( ¬unit) );160 CPPUNIT_ASSERT_EQUAL( 1., zero.Distance(unit) ); 161 CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance(unit) ); 162 CPPUNIT_ASSERT_EQUAL( sqrt(2.), zero.Distance(notunit) ); 163 CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance(notunit) ); 164 CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance(notunit) ); 169 165 } 170 166 … … 173 169 void VectorTest::EuclidianAnglesTest() 174 170 { 175 CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle( &unit) );176 CPPUNIT_ASSERT_EQUAL( 0., unit.Angle( &unit) );177 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle( &unit)) < MYEPSILON );178 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle( ¬unit)) < MYEPSILON );179 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle( ¬unit)) < MYEPSILON );171 CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle(unit) ); 172 CPPUNIT_ASSERT_EQUAL( 0., unit.Angle(unit) ); 173 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle(unit)) < MYEPSILON ); 174 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle(notunit)) < MYEPSILON ); 175 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle(notunit)) < MYEPSILON ); 180 176 }; 181 177 … … 184 180 void VectorTest::ProjectionTest() 185 181 { 186 CPPUNIT_ASSERT_EQUAL( zero, zero.Projection( &unit) );187 CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection( &unit) );188 CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.), otherunit.Projection( &two) );189 CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.), two.Projection( &otherunit) );182 CPPUNIT_ASSERT_EQUAL( zero, zero.Projection(unit) ); 183 CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection(unit) ); 184 CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.), otherunit.Projection(two) ); 185 CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.), two.Projection(otherunit) ); 190 186 }; 191 187 … … 195 191 { 196 192 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 197 CPPUNIT_ASSERT_ EQUAL( true, fixture.GetIntersectionWithPlane(&unit, &zero, &zero, &two) );193 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unit, zero).GetIntersection(zero, two) ); 198 194 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 199 195 200 196 // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ??? 201 CPPUNIT_ASSERT_ EQUAL( true, fixture.GetIntersectionWithPlane(&otherunit, &two, &unit, ¬unit) );197 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(otherunit, two).GetIntersection( unit, notunit) ); 202 198 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture ); 203 199 204 200 // four vectors equal to zero 205 CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&zero, &zero, &zero, &zero, NULL) ); 201 CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(zero, zero, zero, zero), LinearDependenceException); 202 //CPPUNIT_ASSERT_EQUAL( zero, fixture ); 203 204 // four vectors equal to unit 205 CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, unit, unit, unit), LinearDependenceException); 206 //CPPUNIT_ASSERT_EQUAL( zero, fixture ); 207 208 // two equal lines 209 CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, two)); 210 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 211 212 // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ??? 213 CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, otherunit) ); 214 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 215 216 // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 217 CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, zero, zero, two) ); 206 218 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 207 219 208 // four vectors equal to unit 209 CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &unit, &unit, &unit, NULL) ); 220 // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ??? 221 CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, zero, otherunit) ); 222 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture ); 223 }; 224 225 /** UnitTest for vector rotations. 226 */ 227 void VectorTest::VectorRotationTest() 228 { 229 fixture = Vector(-1.,0.,0.); 230 231 // zero vector does not change 232 fixture = RotateVector(zero,unit, 1.); 210 233 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 211 234 212 // two equal lines 213 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &unit, &two, NULL) ); 235 fixture = RotateVector(zero, two, 1.); 236 CPPUNIT_ASSERT_EQUAL( zero, fixture); 237 238 // vector on axis does not change 239 fixture = RotateVector(unit,unit, 1.); 214 240 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 215 241 216 // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ???217 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &unit, &otherunit, NULL) );218 CPPUNIT_ASSERT_EQUAL( unit, fixture );219 220 // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ???221 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &zero, &zero, &two, NULL) );222 CPPUNIT_ASSERT_EQUAL( zero, fixture );223 224 // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ???225 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &zero, &otherunit, NULL) );226 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture );227 };228 229 /** UnitTest for vector rotations.230 */231 void VectorTest::VectorRotationTest()232 {233 fixture.Init(-1.,0.,0.);234 235 // zero vector does not change236 fixture.CopyVector(&zero);237 fixture.RotateVector(&unit, 1.);238 CPPUNIT_ASSERT_EQUAL( zero, fixture );239 240 fixture.RotateVector(&two, 1.);241 CPPUNIT_ASSERT_EQUAL( zero, fixture);242 243 // vector on axis does not change244 fixture.CopyVector(&unit);245 fixture.RotateVector(&unit, 1.);246 CPPUNIT_ASSERT_EQUAL( unit, fixture );247 248 fixture.RotateVector(&unit, 1.);249 CPPUNIT_ASSERT_EQUAL( unit, fixture );250 251 242 // rotations 252 fixture.CopyVector(&otherunit); 253 fixture.RotateVector(&unit, M_PI); 243 fixture = RotateVector(otherunit, unit, M_PI); 254 244 CPPUNIT_ASSERT_EQUAL( Vector(0.,-1.,0.), fixture ); 255 245 256 fixture.CopyVector(&otherunit); 257 fixture.RotateVector(&unit, 2. * M_PI); 246 fixture = RotateVector(otherunit, unit, 2. * M_PI); 258 247 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 259 248 260 fixture.CopyVector(&otherunit); 261 fixture.RotateVector(&unit, 0); 249 fixture = RotateVector(otherunit,unit, 0); 262 250 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 263 251 264 fixture.Init(0.,0.,1.); 265 fixture.RotateVector(¬unit, M_PI); 252 fixture = RotateVector(Vector(0.,0.,1.), notunit, M_PI); 266 253 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 267 254 } … … 283 270 parallelepiped[8] = 1; 284 271 285 fixture .CopyVector(zero);286 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 287 fixture .Init(2.5,2.5,2.5);272 fixture = zero; 273 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 274 fixture = Vector(2.5,2.5,2.5); 288 275 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 289 fixture .Init(1.,1.,1.);290 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 291 fixture .Init(3.5,3.5,3.5);292 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 293 fixture .Init(2.,2.,2.);276 fixture = Vector(1.,1.,1.); 277 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 278 fixture = Vector(3.5,3.5,3.5); 279 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 280 fixture = Vector(2.,2.,2.); 294 281 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 295 fixture .Init(2.,3.,2.);282 fixture = Vector(2.,3.,2.); 296 283 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 297 fixture .Init(-2.,2.,-1.);298 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 299 } 300 284 fixture = Vector(-2.,2.,-1.); 285 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 286 } 287 -
src/vector.cpp
r632bc3 r8cbb97 6 6 7 7 8 #include "defs.hpp"9 #include "helpers.hpp"10 #include "info.hpp"11 #include "gslmatrix.hpp"12 #include "leastsquaremin.hpp"13 #include "log.hpp"14 #include "memoryallocator.hpp"15 8 #include "vector.hpp" 16 9 #include "verbose.hpp" 17 10 #include "World.hpp" 18 19 #include <gsl/gsl_linalg.h> 20 #include <gsl/gsl_matrix.h> 21 #include <gsl/gsl_permutation.h> 22 #include <gsl/gsl_vector.h> 11 #include "Helpers/Assert.hpp" 12 #include "Helpers/fast_functions.hpp" 13 14 #include <iostream> 15 16 using namespace std; 17 23 18 24 19 /************************************ Functions for class vector ************************************/ … … 26 21 /** Constructor of class vector. 27 22 */ 28 Vector::Vector() { x[0] = x[1] = x[2] = 0.; }; 23 Vector::Vector() 24 { 25 x[0] = x[1] = x[2] = 0.; 26 }; 27 28 /** 29 * Copy constructor 30 */ 31 32 Vector::Vector(const Vector& src) 33 { 34 x[0] = src[0]; 35 x[1] = src[1]; 36 x[2] = src[2]; 37 } 29 38 30 39 /** Constructor of class vector. 31 40 */ 32 Vector::Vector(const Vector * const a)33 { 34 x[0] = a->x[0];35 x[1] = a->x[1];36 x[2] = a->x[2];37 }; 38 39 /** Constructor of class vector.40 * /41 Vector::Vector(const Vector &a) 42 {43 x[0] = a.x[0];44 x[1] = a.x[1];45 x[2] = a.x[2];46 };47 48 /** Constructor of class vector. 49 */50 Vector::Vector(const double x1, const double x2, const double x3) { x[0] = x1; x[1] = x2; x[2] = x3; }; 41 Vector::Vector(const double x1, const double x2, const double x3) 42 { 43 x[0] = x1; 44 x[1] = x2; 45 x[2] = x3; 46 }; 47 48 /** 49 * Assignment operator 50 */ 51 Vector& Vector::operator=(const Vector& src){ 52 // check for self assignment 53 if(&src!=this){ 54 x[0] = src[0]; 55 x[1] = src[1]; 56 x[2] = src[2]; 57 } 58 return *this; 59 } 51 60 52 61 /** Desctructor of class vector. … … 58 67 * \return \f$| x - y |^2\f$ 59 68 */ 60 double Vector::DistanceSquared(const Vector * consty) const69 double Vector::DistanceSquared(const Vector &y) const 61 70 { 62 71 double res = 0.; 63 72 for (int i=NDIM;i--;) 64 res += (x[i]-y ->x[i])*(x[i]-y->x[i]);73 res += (x[i]-y[i])*(x[i]-y[i]); 65 74 return (res); 66 75 }; … … 70 79 * \return \f$| x - y |\f$ 71 80 */ 72 double Vector::Distance(const Vector * const y) const 73 { 74 double res = 0.; 75 for (int i=NDIM;i--;) 76 res += (x[i]-y->x[i])*(x[i]-y->x[i]); 77 return (sqrt(res)); 81 double Vector::Distance(const Vector &y) const 82 { 83 return (sqrt(DistanceSquared(y))); 78 84 }; 79 85 … … 83 89 * \return \f$| x - y |\f$ 84 90 */ 85 double Vector::PeriodicDistance(const Vector * consty, const double * const cell_size) const91 double Vector::PeriodicDistance(const Vector &y, const double * const cell_size) const 86 92 { 87 93 double res = Distance(y), tmp, matrix[NDIM*NDIM]; 88 Vector Shiftedy, TranslationVector; 89 int N[NDIM]; 90 matrix[0] = cell_size[0]; 91 matrix[1] = cell_size[1]; 92 matrix[2] = cell_size[3]; 93 matrix[3] = cell_size[1]; 94 matrix[4] = cell_size[2]; 95 matrix[5] = cell_size[4]; 96 matrix[6] = cell_size[3]; 97 matrix[7] = cell_size[4]; 98 matrix[8] = cell_size[5]; 99 // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells 100 for (N[0]=-1;N[0]<=1;N[0]++) 101 for (N[1]=-1;N[1]<=1;N[1]++) 102 for (N[2]=-1;N[2]<=1;N[2]++) { 103 // create the translation vector 104 TranslationVector.Zero(); 105 for (int i=NDIM;i--;) 106 TranslationVector.x[i] = (double)N[i]; 107 TranslationVector.MatrixMultiplication(matrix); 108 // add onto the original vector to compare with 109 Shiftedy.CopyVector(y); 110 Shiftedy.AddVector(&TranslationVector); 111 // get distance and compare with minimum so far 112 tmp = Distance(&Shiftedy); 113 if (tmp < res) res = tmp; 114 } 115 return (res); 94 Vector Shiftedy, TranslationVector; 95 int N[NDIM]; 96 matrix[0] = cell_size[0]; 97 matrix[1] = cell_size[1]; 98 matrix[2] = cell_size[3]; 99 matrix[3] = cell_size[1]; 100 matrix[4] = cell_size[2]; 101 matrix[5] = cell_size[4]; 102 matrix[6] = cell_size[3]; 103 matrix[7] = cell_size[4]; 104 matrix[8] = cell_size[5]; 105 // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells 106 for (N[0]=-1;N[0]<=1;N[0]++) 107 for (N[1]=-1;N[1]<=1;N[1]++) 108 for (N[2]=-1;N[2]<=1;N[2]++) { 109 // create the translation vector 110 TranslationVector.Zero(); 111 for (int i=NDIM;i--;) 112 TranslationVector[i] = (double)N[i]; 113 TranslationVector.MatrixMultiplication(matrix); 114 // add onto the original vector to compare with 115 Shiftedy = y + TranslationVector; 116 // get distance and compare with minimum so far 117 tmp = Distance(Shiftedy); 118 if (tmp < res) res = tmp; 119 } 120 return (res); 116 121 }; 117 122 … … 121 126 * \return \f$| x - y |^2\f$ 122 127 */ 123 double Vector::PeriodicDistanceSquared(const Vector * consty, const double * const cell_size) const128 double Vector::PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const 124 129 { 125 130 double res = DistanceSquared(y), tmp, matrix[NDIM*NDIM]; 126 Vector Shiftedy, TranslationVector; 127 int N[NDIM]; 128 matrix[0] = cell_size[0]; 129 matrix[1] = cell_size[1]; 130 matrix[2] = cell_size[3]; 131 matrix[3] = cell_size[1]; 132 matrix[4] = cell_size[2]; 133 matrix[5] = cell_size[4]; 134 matrix[6] = cell_size[3]; 135 matrix[7] = cell_size[4]; 136 matrix[8] = cell_size[5]; 137 // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells 138 for (N[0]=-1;N[0]<=1;N[0]++) 139 for (N[1]=-1;N[1]<=1;N[1]++) 140 for (N[2]=-1;N[2]<=1;N[2]++) { 141 // create the translation vector 142 TranslationVector.Zero(); 143 for (int i=NDIM;i--;) 144 TranslationVector.x[i] = (double)N[i]; 145 TranslationVector.MatrixMultiplication(matrix); 146 // add onto the original vector to compare with 147 Shiftedy.CopyVector(y); 148 Shiftedy.AddVector(&TranslationVector); 149 // get distance and compare with minimum so far 150 tmp = DistanceSquared(&Shiftedy); 151 if (tmp < res) res = tmp; 152 } 153 return (res); 131 Vector Shiftedy, TranslationVector; 132 int N[NDIM]; 133 matrix[0] = cell_size[0]; 134 matrix[1] = cell_size[1]; 135 matrix[2] = cell_size[3]; 136 matrix[3] = cell_size[1]; 137 matrix[4] = cell_size[2]; 138 matrix[5] = cell_size[4]; 139 matrix[6] = cell_size[3]; 140 matrix[7] = cell_size[4]; 141 matrix[8] = cell_size[5]; 142 // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells 143 for (N[0]=-1;N[0]<=1;N[0]++) 144 for (N[1]=-1;N[1]<=1;N[1]++) 145 for (N[2]=-1;N[2]<=1;N[2]++) { 146 // create the translation vector 147 TranslationVector.Zero(); 148 for (int i=NDIM;i--;) 149 TranslationVector[i] = (double)N[i]; 150 TranslationVector.MatrixMultiplication(matrix); 151 // add onto the original vector to compare with 152 Shiftedy = y + TranslationVector; 153 // get distance and compare with minimum so far 154 tmp = DistanceSquared(Shiftedy); 155 if (tmp < res) res = tmp; 156 } 157 return (res); 154 158 }; 155 159 … … 160 164 void Vector::KeepPeriodic(const double * const matrix) 161 165 { 162 // int N[NDIM]; 163 // bool flag = false; 164 //vector Shifted, TranslationVector; 165 Vector TestVector; 166 // Log() << Verbose(1) << "Begin of KeepPeriodic." << endl; 167 // Log() << Verbose(2) << "Vector is: "; 168 // Output(out); 169 // Log() << Verbose(0) << endl; 170 TestVector.CopyVector(this); 171 TestVector.InverseMatrixMultiplication(matrix); 172 for(int i=NDIM;i--;) { // correct periodically 173 if (TestVector.x[i] < 0) { // get every coefficient into the interval [0,1) 174 TestVector.x[i] += ceil(TestVector.x[i]); 175 } else { 176 TestVector.x[i] -= floor(TestVector.x[i]); 166 // int N[NDIM]; 167 // bool flag = false; 168 //vector Shifted, TranslationVector; 169 // Log() << Verbose(1) << "Begin of KeepPeriodic." << endl; 170 // Log() << Verbose(2) << "Vector is: "; 171 // Output(out); 172 // Log() << Verbose(0) << endl; 173 InverseMatrixMultiplication(matrix); 174 for(int i=NDIM;i--;) { // correct periodically 175 if (at(i) < 0) { // get every coefficient into the interval [0,1) 176 at(i) += ceil(at(i)); 177 } else { 178 at(i) -= floor(at(i)); 179 } 177 180 } 178 } 179 TestVector.MatrixMultiplication(matrix); 180 CopyVector(&TestVector); 181 // Log() << Verbose(2) << "New corrected vector is: "; 182 // Output(out); 183 // Log() << Verbose(0) << endl; 184 // Log() << Verbose(1) << "End of KeepPeriodic." << endl; 181 MatrixMultiplication(matrix); 182 // Log() << Verbose(2) << "New corrected vector is: "; 183 // Output(out); 184 // Log() << Verbose(0) << endl; 185 // Log() << Verbose(1) << "End of KeepPeriodic." << endl; 185 186 }; 186 187 … … 189 190 * \return \f$\langle x, y \rangle\f$ 190 191 */ 191 double Vector::ScalarProduct(const Vector * consty) const192 double Vector::ScalarProduct(const Vector &y) const 192 193 { 193 194 double res = 0.; 194 195 for (int i=NDIM;i--;) 195 res += x[i]*y ->x[i];196 res += x[i]*y[i]; 196 197 return (res); 197 198 }; … … 204 205 * \return \f$ x \times y \f& 205 206 */ 206 void Vector::VectorProduct(const Vector * consty)207 void Vector::VectorProduct(const Vector &y) 207 208 { 208 209 Vector tmp; 209 tmp .x[0] = x[1]* (y->x[2]) - x[2]* (y->x[1]);210 tmp .x[1] = x[2]* (y->x[0]) - x[0]* (y->x[2]);211 tmp .x[2] = x[0]* (y->x[1]) - x[1]* (y->x[0]);212 this->CopyVector(&tmp);210 tmp[0] = x[1]* (y[2]) - x[2]* (y[1]); 211 tmp[1] = x[2]* (y[0]) - x[0]* (y[2]); 212 tmp[2] = x[0]* (y[1]) - x[1]* (y[0]); 213 (*this) = tmp; 213 214 }; 214 215 … … 218 219 * \return \f$\langle x, y \rangle\f$ 219 220 */ 220 void Vector::ProjectOntoPlane(const Vector * consty)221 void Vector::ProjectOntoPlane(const Vector &y) 221 222 { 222 223 Vector tmp; 223 tmp .CopyVector(y);224 tmp = y; 224 225 tmp.Normalize(); 225 tmp.Scale(ScalarProduct(&tmp)); 226 this->SubtractVector(&tmp); 227 }; 228 229 /** Calculates the intersection point between a line defined by \a *LineVector and \a *LineVector2 and a plane defined by \a *Normal and \a *PlaneOffset. 230 * According to [Bronstein] the vectorial plane equation is: 231 * -# \f$\stackrel{r}{\rightarrow} \cdot \stackrel{N}{\rightarrow} + D = 0\f$, 232 * where \f$\stackrel{r}{\rightarrow}\f$ is the vector to be testet, \f$\stackrel{N}{\rightarrow}\f$ is the plane's normal vector and 233 * \f$D = - \stackrel{a}{\rightarrow} \stackrel{N}{\rightarrow}\f$, the offset with respect to origin, if \f$\stackrel{a}{\rightarrow}\f$, 234 * is an offset vector onto the plane. The line is parametrized by \f$\stackrel{x}{\rightarrow} + k \stackrel{t}{\rightarrow}\f$, where 235 * \f$\stackrel{x}{\rightarrow}\f$ is the offset and \f$\stackrel{t}{\rightarrow}\f$ the directional vector (NOTE: No need to normalize 236 * the latter). Inserting the parametrized form into the plane equation and solving for \f$k\f$, which we insert then into the parametrization 237 * of the line yields the intersection point on the plane. 238 * \param *out output stream for debugging 239 * \param *PlaneNormal Plane's normal vector 240 * \param *PlaneOffset Plane's offset vector 241 * \param *Origin first vector of line 242 * \param *LineVector second vector of line 243 * \return true - \a this contains intersection point on return, false - line is parallel to plane (even if in-plane) 244 */ 245 bool Vector::GetIntersectionWithPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset, const Vector * const Origin, const Vector * const LineVector) 246 { 247 Info FunctionInfo(__func__); 248 double factor; 249 Vector Direction, helper; 250 251 // find intersection of a line defined by Offset and Direction with a plane defined by triangle 252 Direction.CopyVector(LineVector); 253 Direction.SubtractVector(Origin); 254 Direction.Normalize(); 255 DoLog(1) && (Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl); 256 //Log() << Verbose(1) << "INFO: PlaneNormal is " << *PlaneNormal << " and PlaneOffset is " << *PlaneOffset << "." << endl; 257 factor = Direction.ScalarProduct(PlaneNormal); 258 if (fabs(factor) < MYEPSILON) { // Uniqueness: line parallel to plane? 259 DoLog(1) && (Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl); 260 return false; 261 } 262 helper.CopyVector(PlaneOffset); 263 helper.SubtractVector(Origin); 264 factor = helper.ScalarProduct(PlaneNormal)/factor; 265 if (fabs(factor) < MYEPSILON) { // Origin is in-plane 266 DoLog(1) && (Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl); 267 CopyVector(Origin); 268 return true; 269 } 270 //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal)); 271 Direction.Scale(factor); 272 CopyVector(Origin); 273 DoLog(1) && (Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl); 274 AddVector(&Direction); 275 276 // test whether resulting vector really is on plane 277 helper.CopyVector(this); 278 helper.SubtractVector(PlaneOffset); 279 if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) { 280 DoLog(1) && (Log() << Verbose(1) << "GOOD: Intersection is " << *this << "." << endl); 281 return true; 282 } else { 283 DoeLog(2) && (eLog()<< Verbose(2) << "Intersection point " << *this << " is not on plane." << endl); 284 return false; 285 } 226 tmp.Scale(ScalarProduct(tmp)); 227 *this -= tmp; 286 228 }; 287 229 … … 290 232 * \param *PlaneNormal normal of plane 291 233 * \param *PlaneOffset offset of plane 234 * \return distance to plane 292 235 * \return distance vector onto to plane 293 236 */ 294 Vector Vector::GetDistanceVectorToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const 295 { 296 Vector temp; 297 298 // first create part that is orthonormal to PlaneNormal with withdraw 299 temp.CopyVector(this); 300 temp.SubtractVector(PlaneOffset); 301 temp.MakeNormalVector(PlaneNormal); 237 Vector Vector::GetDistanceVectorToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const 238 { 239 Vector temp = (*this) - PlaneOffset; 240 temp.MakeNormalTo(PlaneNormal); 302 241 temp.Scale(-1.); 303 242 // then add connecting vector from plane to point 304 temp.AddVector(this); 305 temp.SubtractVector(PlaneOffset); 243 temp += (*this)-PlaneOffset; 306 244 double sign = temp.ScalarProduct(PlaneNormal); 307 245 if (fabs(sign) > MYEPSILON) … … 314 252 return temp; 315 253 }; 254 316 255 317 256 /** Calculates the minimum distance of this vector to the plane. … … 322 261 * \return distance to plane 323 262 */ 324 double Vector::DistanceToPlane(const Vector * const PlaneNormal, const Vector * constPlaneOffset) const263 double Vector::DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const 325 264 { 326 265 return GetDistanceVectorToPlane(PlaneNormal,PlaneOffset).Norm(); 327 };328 329 /** Calculates the intersection of the two lines that are both on the same plane.330 * This is taken from Weisstein, Eric W. "Line-Line Intersection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineIntersection.html331 * \param *out output stream for debugging332 * \param *Line1a first vector of first line333 * \param *Line1b second vector of first line334 * \param *Line2a first vector of second line335 * \param *Line2b second vector of second line336 * \param *PlaneNormal normal of plane, is supplemental/arbitrary337 * \return true - \a this will contain the intersection on return, false - lines are parallel338 */339 bool Vector::GetIntersectionOfTwoLinesOnPlane(const Vector * const Line1a, const Vector * const Line1b, const Vector * const Line2a, const Vector * const Line2b, const Vector *PlaneNormal)340 {341 Info FunctionInfo(__func__);342 343 GSLMatrix *M = new GSLMatrix(4,4);344 345 M->SetAll(1.);346 for (int i=0;i<3;i++) {347 M->Set(0, i, Line1a->x[i]);348 M->Set(1, i, Line1b->x[i]);349 M->Set(2, i, Line2a->x[i]);350 M->Set(3, i, Line2b->x[i]);351 }352 353 //Log() << Verbose(1) << "Coefficent matrix is:" << endl;354 //ostream &output = Log() << Verbose(1);355 //for (int i=0;i<4;i++) {356 // for (int j=0;j<4;j++)357 // output << "\t" << M->Get(i,j);358 // output << endl;359 //}360 if (fabs(M->Determinant()) > MYEPSILON) {361 DoLog(1) && (Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl);362 return false;363 }364 delete(M);365 DoLog(1) && (Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl);366 367 368 // constuct a,b,c369 Vector a;370 Vector b;371 Vector c;372 Vector d;373 a.CopyVector(Line1b);374 a.SubtractVector(Line1a);375 b.CopyVector(Line2b);376 b.SubtractVector(Line2a);377 c.CopyVector(Line2a);378 c.SubtractVector(Line1a);379 d.CopyVector(Line2b);380 d.SubtractVector(Line1b);381 DoLog(1) && (Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl);382 if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) {383 Zero();384 DoLog(1) && (Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl);385 return false;386 }387 388 // check for parallelity389 Vector parallel;390 double factor = 0.;391 if (fabs(a.ScalarProduct(&b)*a.ScalarProduct(&b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) {392 parallel.CopyVector(Line1a);393 parallel.SubtractVector(Line2a);394 factor = parallel.ScalarProduct(&a)/a.Norm();395 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {396 CopyVector(Line2a);397 DoLog(1) && (Log() << Verbose(1) << "Lines conincide." << endl);398 return true;399 } else {400 parallel.CopyVector(Line1a);401 parallel.SubtractVector(Line2b);402 factor = parallel.ScalarProduct(&a)/a.Norm();403 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {404 CopyVector(Line2b);405 DoLog(1) && (Log() << Verbose(1) << "Lines conincide." << endl);406 return true;407 }408 }409 DoLog(1) && (Log() << Verbose(1) << "Lines are parallel." << endl);410 Zero();411 return false;412 }413 414 // obtain s415 double s;416 Vector temp1, temp2;417 temp1.CopyVector(&c);418 temp1.VectorProduct(&b);419 temp2.CopyVector(&a);420 temp2.VectorProduct(&b);421 DoLog(1) && (Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl);422 if (fabs(temp2.NormSquared()) > MYEPSILON)423 s = temp1.ScalarProduct(&temp2)/temp2.NormSquared();424 else425 s = 0.;426 DoLog(1) && (Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(&temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl);427 428 // construct intersection429 CopyVector(&a);430 Scale(s);431 AddVector(Line1a);432 DoLog(1) && (Log() << Verbose(1) << "Intersection is at " << *this << "." << endl);433 434 return true;435 266 }; 436 267 … … 438 269 * \param *y array to second vector 439 270 */ 440 void Vector::ProjectIt(const Vector * const y) 441 { 442 Vector helper(*y); 443 helper.Scale(-(ScalarProduct(y))); 444 AddVector(&helper); 271 void Vector::ProjectIt(const Vector &y) 272 { 273 (*this) += (-ScalarProduct(y))*y; 445 274 }; 446 275 … … 449 278 * \return Vector 450 279 */ 451 Vector Vector::Projection(const Vector * consty) const452 { 453 Vector helper (*y);454 helper.Scale((ScalarProduct(y)/y ->NormSquared()));280 Vector Vector::Projection(const Vector &y) const 281 { 282 Vector helper = y; 283 helper.Scale((ScalarProduct(y)/y.NormSquared())); 455 284 456 285 return helper; … … 462 291 double Vector::Norm() const 463 292 { 464 double res = 0.; 465 for (int i=NDIM;i--;) 466 res += this->x[i]*this->x[i]; 467 return (sqrt(res)); 293 return (sqrt(NormSquared())); 468 294 }; 469 295 … … 473 299 double Vector::NormSquared() const 474 300 { 475 return (ScalarProduct( this));301 return (ScalarProduct(*this)); 476 302 }; 477 303 … … 480 306 void Vector::Normalize() 481 307 { 482 double res = 0.; 483 for (int i=NDIM;i--;) 484 res += this->x[i]*this->x[i]; 485 if (fabs(res) > MYEPSILON) 486 res = 1./sqrt(res); 487 Scale(&res); 308 double factor = Norm(); 309 (*this) *= 1/factor; 488 310 }; 489 311 … … 492 314 void Vector::Zero() 493 315 { 494 for (int i=NDIM;i--;) 495 this->x[i] = 0.; 316 at(0)=at(1)=at(2)=0; 496 317 }; 497 318 … … 500 321 void Vector::One(const double one) 501 322 { 502 for (int i=NDIM;i--;) 503 this->x[i] = one; 504 }; 505 506 /** Initialises all components of this vector. 507 */ 508 void Vector::Init(const double x1, const double x2, const double x3) 509 { 510 x[0] = x1; 511 x[1] = x2; 512 x[2] = x3; 323 at(0)=at(1)=at(2)=one; 513 324 }; 514 325 … … 532 343 * @return true - vector is normalized, false - vector is not 533 344 */ 534 bool Vector::IsNormalTo(const Vector * constnormal) const345 bool Vector::IsNormalTo(const Vector &normal) const 535 346 { 536 347 if (ScalarProduct(normal) < MYEPSILON) … … 543 354 * @return true - vector is normalized, false - vector is not 544 355 */ 545 bool Vector::IsEqualTo(const Vector * consta) const356 bool Vector::IsEqualTo(const Vector &a) const 546 357 { 547 358 bool status = true; 548 359 for (int i=0;i<NDIM;i++) { 549 if (fabs(x[i] - a ->x[i]) > MYEPSILON)360 if (fabs(x[i] - a[i]) > MYEPSILON) 550 361 status = false; 551 362 } … … 557 368 * \return \f$\acos\bigl(frac{\langle x, y \rangle}{|x||y|}\bigr)\f$ 558 369 */ 559 double Vector::Angle(const Vector * consty) const560 { 561 double norm1 = Norm(), norm2 = y ->Norm();370 double Vector::Angle(const Vector &y) const 371 { 372 double norm1 = Norm(), norm2 = y.Norm(); 562 373 double angle = -1; 563 374 if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON)) … … 572 383 }; 573 384 574 /** Rotates the vector relative to the origin around the axis given by \a *axis by an angle of \a alpha. 575 * \param *axis rotation axis 576 * \param alpha rotation angle in radian 577 */ 578 void Vector::RotateVector(const Vector * const axis, const double alpha) 579 { 580 Vector a,y; 581 // normalise this vector with respect to axis 582 a.CopyVector(this); 583 a.ProjectOntoPlane(axis); 584 // construct normal vector 585 bool rotatable = y.MakeNormalVector(axis,&a); 586 // The normal vector cannot be created if there is linar dependency. 587 // Then the vector to rotate is on the axis and any rotation leads to the vector itself. 588 if (!rotatable) { 589 return; 590 } 591 y.Scale(Norm()); 592 // scale normal vector by sine and this vector by cosine 593 y.Scale(sin(alpha)); 594 a.Scale(cos(alpha)); 595 CopyVector(Projection(axis)); 596 // add scaled normal vector onto this vector 597 AddVector(&y); 598 // add part in axis direction 599 AddVector(&a); 600 }; 385 386 double& Vector::operator[](size_t i){ 387 ASSERT(i<=NDIM && i>=0,"Vector Index out of Range"); 388 return x[i]; 389 } 390 391 const double& Vector::operator[](size_t i) const{ 392 ASSERT(i<=NDIM && i>=0,"Vector Index out of Range"); 393 return x[i]; 394 } 395 396 double& Vector::at(size_t i){ 397 return (*this)[i]; 398 } 399 400 const double& Vector::at(size_t i) const{ 401 return (*this)[i]; 402 } 403 404 double* Vector::get(){ 405 return x; 406 } 601 407 602 408 /** Compares vector \a to vector \a b component-wise. … … 605 411 * \return a == b 606 412 */ 607 bool operator==(const Vector& a, const Vector& b) 608 { 609 bool status = true; 610 for (int i=0;i<NDIM;i++) 611 status = status && (fabs(a.x[i] - b.x[i]) < MYEPSILON); 612 return status; 413 bool Vector::operator==(const Vector& b) const 414 { 415 return IsEqualTo(b); 613 416 }; 614 417 … … 618 421 * \return lhs + a 619 422 */ 620 const Vector& operator+=(Vector& a,const Vector& b)621 { 622 a.AddVector(&b);623 return a;423 const Vector& Vector::operator+=(const Vector& b) 424 { 425 this->AddVector(b); 426 return *this; 624 427 }; 625 428 … … 629 432 * \return lhs - a 630 433 */ 631 const Vector& operator-=(Vector& a,const Vector& b)632 { 633 a.SubtractVector(&b);634 return a;434 const Vector& Vector::operator-=(const Vector& b) 435 { 436 this->SubtractVector(b); 437 return *this; 635 438 }; 636 439 … … 651 454 * \return a + b 652 455 */ 653 Vector const operator+(const Vector& a, const Vector& b)654 { 655 Vector x (a);656 x.AddVector( &b);456 Vector const Vector::operator+(const Vector& b) const 457 { 458 Vector x = *this; 459 x.AddVector(b); 657 460 return x; 658 461 }; … … 663 466 * \return a - b 664 467 */ 665 Vector const operator-(const Vector& a, const Vector& b)666 { 667 Vector x (a);668 x.SubtractVector( &b);468 Vector const Vector::operator-(const Vector& b) const 469 { 470 Vector x = *this; 471 x.SubtractVector(b); 669 472 return x; 670 473 }; … … 694 497 }; 695 498 696 /** Prints a 3dim vector.697 * prints no end of line.698 */699 void Vector::Output() const700 {701 DoLog(0) && (Log() << Verbose(0) << "(");702 for (int i=0;i<NDIM;i++) {703 DoLog(0) && (Log() << Verbose(0) << x[i]);704 if (i != 2)705 DoLog(0) && (Log() << Verbose(0) << ",");706 }707 DoLog(0) && (Log() << Verbose(0) << ")");708 };709 710 499 ostream& operator<<(ostream& ost, const Vector& m) 711 500 { 712 501 ost << "("; 713 502 for (int i=0;i<NDIM;i++) { 714 ost << m .x[i];503 ost << m[i]; 715 504 if (i != 2) 716 505 ost << ","; … … 720 509 }; 721 510 722 /** Scales each atom coordinate by an individual \a factor. 723 * \param *factor pointer to scaling factor 724 */ 725 void Vector::Scale(const double ** const factor) 511 512 void Vector::ScaleAll(const double *factor) 726 513 { 727 514 for (int i=NDIM;i--;) 728 x[i] *= (*factor)[i]; 729 }; 730 731 void Vector::Scale(const double * const factor) 732 { 733 for (int i=NDIM;i--;) 734 x[i] *= *factor; 735 }; 515 x[i] *= factor[i]; 516 }; 517 518 736 519 737 520 void Vector::Scale(const double factor) … … 739 522 for (int i=NDIM;i--;) 740 523 x[i] *= factor; 741 };742 743 /** Translate atom by given vector.744 * \param trans[] translation vector.745 */746 void Vector::Translate(const Vector * const trans)747 {748 for (int i=NDIM;i--;)749 x[i] += trans->x[i];750 524 }; 751 525 … … 773 547 void Vector::MatrixMultiplication(const double * const M) 774 548 { 775 Vector C;776 549 // do the matrix multiplication 777 C.x[0] = M[0]*x[0]+M[3]*x[1]+M[6]*x[2]; 778 C.x[1] = M[1]*x[0]+M[4]*x[1]+M[7]*x[2]; 779 C.x[2] = M[2]*x[0]+M[5]*x[1]+M[8]*x[2]; 780 // transfer the result into this 781 for (int i=NDIM;i--;) 782 x[i] = C.x[i]; 550 at(0) = M[0]*x[0]+M[3]*x[1]+M[6]*x[2]; 551 at(1) = M[1]*x[0]+M[4]*x[1]+M[7]*x[2]; 552 at(2) = M[2]*x[0]+M[5]*x[1]+M[8]*x[2]; 783 553 }; 784 554 … … 786 556 * \param *matrix NDIM_NDIM array 787 557 */ 788 void Vector::InverseMatrixMultiplication(const double * const A) 789 { 790 Vector C; 558 bool Vector::InverseMatrixMultiplication(const double * const A) 559 { 791 560 double B[NDIM*NDIM]; 792 561 double detA = RDET3(A); … … 807 576 808 577 // do the matrix multiplication 809 C.x[0] = B[0]*x[0]+B[3]*x[1]+B[6]*x[2]; 810 C.x[1] = B[1]*x[0]+B[4]*x[1]+B[7]*x[2]; 811 C.x[2] = B[2]*x[0]+B[5]*x[1]+B[8]*x[2]; 812 // transfer the result into this 813 for (int i=NDIM;i--;) 814 x[i] = C.x[i]; 578 at(0) = B[0]*x[0]+B[3]*x[1]+B[6]*x[2]; 579 at(1) = B[1]*x[0]+B[4]*x[1]+B[7]*x[2]; 580 at(2) = B[2]*x[0]+B[5]*x[1]+B[8]*x[2]; 581 582 return true; 815 583 } else { 816 DoeLog(1) && (eLog()<< Verbose(1) << "inverse of matrix does not exists: det A = " << detA << "." << endl);584 return false; 817 585 } 818 586 }; … … 826 594 * \param *factors three-component vector with the factor for each given vector 827 595 */ 828 void Vector::LinearCombinationOfVectors(const Vector * const x1, const Vector * const x2, const Vector * const x3, const double * const factors) 829 { 830 for(int i=NDIM;i--;) 831 x[i] = factors[0]*x1->x[i] + factors[1]*x2->x[i] + factors[2]*x3->x[i]; 596 void Vector::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors) 597 { 598 (*this) = (factors[0]*x1) + 599 (factors[1]*x2) + 600 (factors[2]*x3); 832 601 }; 833 602 … … 835 604 * \param n[] normal vector of mirror plane. 836 605 */ 837 void Vector::Mirror(const Vector * constn)606 void Vector::Mirror(const Vector &n) 838 607 { 839 608 double projection; 840 projection = ScalarProduct(n)/n ->ScalarProduct(n); // remove constancy from n (keep as logical one)609 projection = ScalarProduct(n)/n.NormSquared(); // remove constancy from n (keep as logical one) 841 610 // withdraw projected vector twice from original one 842 DoLog(1) && (Log() << Verbose(1) << "Vector: ");843 Output();844 DoLog(0) && (Log() << Verbose(0) << "\t");845 611 for (int i=NDIM;i--;) 846 x[i] -= 2.*projection*n->x[i]; 847 DoLog(0) && (Log() << Verbose(0) << "Projected vector: "); 848 Output(); 849 DoLog(0) && (Log() << Verbose(0) << endl); 850 }; 851 852 /** Calculates normal vector for three given vectors (being three points in space). 853 * Makes this vector orthonormal to the three given points, making up a place in 3d space. 854 * \param *y1 first vector 855 * \param *y2 second vector 856 * \param *y3 third vector 857 * \return true - success, vectors are linear independent, false - failure due to linear dependency 858 */ 859 bool Vector::MakeNormalVector(const Vector * const y1, const Vector * const y2, const Vector * const y3) 860 { 861 Vector x1, x2; 862 863 x1.CopyVector(y1); 864 x1.SubtractVector(y2); 865 x2.CopyVector(y3); 866 x2.SubtractVector(y2); 867 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) { 868 DoeLog(2) && (eLog()<< Verbose(2) << "Given vectors are linear dependent." << endl); 869 return false; 870 } 871 // Log() << Verbose(4) << "relative, first plane coordinates:"; 872 // x1.Output((ofstream *)&cout); 873 // Log() << Verbose(0) << endl; 874 // Log() << Verbose(4) << "second plane coordinates:"; 875 // x2.Output((ofstream *)&cout); 876 // Log() << Verbose(0) << endl; 877 878 this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]); 879 this->x[1] = (x1.x[2]*x2.x[0] - x1.x[0]*x2.x[2]); 880 this->x[2] = (x1.x[0]*x2.x[1] - x1.x[1]*x2.x[0]); 881 Normalize(); 882 883 return true; 884 }; 885 886 887 /** Calculates orthonormal vector to two given vectors. 888 * Makes this vector orthonormal to two given vectors. This is very similar to the other 889 * vector::MakeNormalVector(), only there three points whereas here two difference 890 * vectors are given. 891 * \param *x1 first vector 892 * \param *x2 second vector 893 * \return true - success, vectors are linear independent, false - failure due to linear dependency 894 */ 895 bool Vector::MakeNormalVector(const Vector * const y1, const Vector * const y2) 896 { 897 Vector x1,x2; 898 x1.CopyVector(y1); 899 x2.CopyVector(y2); 900 Zero(); 901 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) { 902 DoeLog(2) && (eLog()<< Verbose(2) << "Given vectors are linear dependent." << endl); 903 return false; 904 } 905 // Log() << Verbose(4) << "relative, first plane coordinates:"; 906 // x1.Output((ofstream *)&cout); 907 // Log() << Verbose(0) << endl; 908 // Log() << Verbose(4) << "second plane coordinates:"; 909 // x2.Output((ofstream *)&cout); 910 // Log() << Verbose(0) << endl; 911 912 this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]); 913 this->x[1] = (x1.x[2]*x2.x[0] - x1.x[0]*x2.x[2]); 914 this->x[2] = (x1.x[0]*x2.x[1] - x1.x[1]*x2.x[0]); 915 Normalize(); 916 917 return true; 612 at(i) -= 2.*projection*n[i]; 918 613 }; 919 614 … … 924 619 * \return true - success, false - vector is zero 925 620 */ 926 bool Vector::MakeNormal Vector(const Vector * consty1)621 bool Vector::MakeNormalTo(const Vector &y1) 927 622 { 928 623 bool result = false; 929 double factor = y1 ->ScalarProduct(this)/y1->NormSquared();624 double factor = y1.ScalarProduct(*this)/y1.NormSquared(); 930 625 Vector x1; 931 x1.CopyVector(y1); 932 x1.Scale(factor); 933 SubtractVector(&x1); 626 x1 = factor * y1; 627 SubtractVector(x1); 934 628 for (int i=NDIM;i--;) 935 629 result = result || (fabs(x[i]) > MYEPSILON); … … 944 638 * \return true - success, false - failure (null vector given) 945 639 */ 946 bool Vector::GetOneNormalVector(const Vector * constGivenVector)640 bool Vector::GetOneNormalVector(const Vector &GivenVector) 947 641 { 948 642 int Components[NDIM]; // contains indices of non-zero components … … 951 645 double norm; 952 646 953 DoLog(4) && (Log() << Verbose(4));954 GivenVector->Output();955 DoLog(0) && (Log() << Verbose(0) << endl);956 647 for (j=NDIM;j--;) 957 648 Components[j] = -1; 958 649 // find two components != 0 959 650 for (j=0;j<NDIM;j++) 960 if (fabs(GivenVector ->x[j]) > MYEPSILON)651 if (fabs(GivenVector[j]) > MYEPSILON) 961 652 Components[Last++] = j; 962 DoLog(4) && (Log() << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl);963 653 964 654 switch(Last) { 965 655 case 3: // threecomponent system 966 656 case 2: // two component system 967 norm = sqrt(1./(GivenVector ->x[Components[1]]*GivenVector->x[Components[1]]) + 1./(GivenVector->x[Components[0]]*GivenVector->x[Components[0]]));657 norm = sqrt(1./(GivenVector[Components[1]]*GivenVector[Components[1]]) + 1./(GivenVector[Components[0]]*GivenVector[Components[0]])); 968 658 x[Components[2]] = 0.; 969 659 // in skp both remaining parts shall become zero but with opposite sign and third is zero 970 x[Components[1]] = -1./GivenVector ->x[Components[1]] / norm;971 x[Components[0]] = 1./GivenVector ->x[Components[0]] / norm;660 x[Components[1]] = -1./GivenVector[Components[1]] / norm; 661 x[Components[0]] = 1./GivenVector[Components[0]] / norm; 972 662 return true; 973 663 break; … … 984 674 }; 985 675 986 /** Determines parameter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.987 * \param *A first plane vector988 * \param *B second plane vector989 * \param *C third plane vector990 * \return scaling parameter for this vector991 */992 double Vector::CutsPlaneAt(const Vector * const A, const Vector * const B, const Vector * const C) const993 {994 // Log() << Verbose(3) << "For comparison: ";995 // Log() << Verbose(0) << "A " << A->Projection(this) << "\t";996 // Log() << Verbose(0) << "B " << B->Projection(this) << "\t";997 // Log() << Verbose(0) << "C " << C->Projection(this) << "\t";998 // Log() << Verbose(0) << endl;999 return A->ScalarProduct(this);1000 };1001 1002 /** Creates a new vector as the one with least square distance to a given set of \a vectors.1003 * \param *vectors set of vectors1004 * \param num number of vectors1005 * \return true if success, false if failed due to linear dependency1006 */1007 bool Vector::LSQdistance(const Vector **vectors, int num)1008 {1009 int j;1010 1011 for (j=0;j<num;j++) {1012 DoLog(1) && (Log() << Verbose(1) << j << "th atom's vector: ");1013 (vectors[j])->Output();1014 DoLog(0) && (Log() << Verbose(0) << endl);1015 }1016 1017 int np = 3;1018 struct LSQ_params par;1019 1020 const gsl_multimin_fminimizer_type *T =1021 gsl_multimin_fminimizer_nmsimplex;1022 gsl_multimin_fminimizer *s = NULL;1023 gsl_vector *ss, *y;1024 gsl_multimin_function minex_func;1025 1026 size_t iter = 0, i;1027 int status;1028 double size;1029 1030 /* Initial vertex size vector */1031 ss = gsl_vector_alloc (np);1032 y = gsl_vector_alloc (np);1033 1034 /* Set all step sizes to 1 */1035 gsl_vector_set_all (ss, 1.0);1036 1037 /* Starting point */1038 par.vectors = vectors;1039 par.num = num;1040 1041 for (i=NDIM;i--;)1042 gsl_vector_set(y, i, (vectors[0]->x[i] - vectors[1]->x[i])/2.);1043 1044 /* Initialize method and iterate */1045 minex_func.f = &LSQ;1046 minex_func.n = np;1047 minex_func.params = (void *)∥1048 1049 s = gsl_multimin_fminimizer_alloc (T, np);1050 gsl_multimin_fminimizer_set (s, &minex_func, y, ss);1051 1052 do1053 {1054 iter++;1055 status = gsl_multimin_fminimizer_iterate(s);1056 1057 if (status)1058 break;1059 1060 size = gsl_multimin_fminimizer_size (s);1061 status = gsl_multimin_test_size (size, 1e-2);1062 1063 if (status == GSL_SUCCESS)1064 {1065 printf ("converged to minimum at\n");1066 }1067 1068 printf ("%5d ", (int)iter);1069 for (i = 0; i < (size_t)np; i++)1070 {1071 printf ("%10.3e ", gsl_vector_get (s->x, i));1072 }1073 printf ("f() = %7.3f size = %.3f\n", s->fval, size);1074 }1075 while (status == GSL_CONTINUE && iter < 100);1076 1077 for (i=(size_t)np;i--;)1078 this->x[i] = gsl_vector_get(s->x, i);1079 gsl_vector_free(y);1080 gsl_vector_free(ss);1081 gsl_multimin_fminimizer_free (s);1082 1083 return true;1084 };1085 1086 676 /** Adds vector \a *y componentwise. 1087 677 * \param *y vector 1088 678 */ 1089 void Vector::AddVector(const Vector * consty)1090 { 1091 for 1092 this->x[i] += y->x[i];679 void Vector::AddVector(const Vector &y) 680 { 681 for(int i=NDIM;i--;) 682 x[i] += y[i]; 1093 683 } 1094 684 … … 1096 686 * \param *y vector 1097 687 */ 1098 void Vector::SubtractVector(const Vector * const y) 1099 { 1100 for (int i=NDIM;i--;) 1101 this->x[i] -= y->x[i]; 1102 } 1103 1104 /** Copy vector \a *y componentwise. 1105 * \param *y vector 1106 */ 1107 void Vector::CopyVector(const Vector * const y) 1108 { 1109 // check for self assignment 1110 if(y!=this){ 1111 for (int i=NDIM;i--;) 1112 this->x[i] = y->x[i]; 1113 } 1114 } 1115 1116 /** Copy vector \a y componentwise. 1117 * \param y vector 1118 */ 1119 void Vector::CopyVector(const Vector &y) 1120 { 1121 // check for self assignment 1122 if(&y!=this) { 1123 for (int i=NDIM;i--;) 1124 this->x[i] = y.x[i]; 1125 } 1126 } 1127 1128 1129 /** Asks for position, checks for boundary. 1130 * \param cell_size unitary size of cubic cell, coordinates must be within 0...cell_size 1131 * \param check whether bounds shall be checked (true) or not (false) 1132 */ 1133 void Vector::AskPosition(const double * const cell_size, const bool check) 1134 { 1135 char coords[3] = {'x','y','z'}; 1136 int j = -1; 1137 for (int i=0;i<3;i++) { 1138 j += i+1; 1139 do { 1140 DoLog(0) && (Log() << Verbose(0) << coords[i] << "[0.." << cell_size[j] << "]: "); 1141 cin >> x[i]; 1142 } while (((x[i] < 0) || (x[i] >= cell_size[j])) && (check)); 1143 } 1144 }; 1145 1146 /** Solves a vectorial system consisting of two orthogonal statements and a norm statement. 1147 * This is linear system of equations to be solved, however of the three given (skp of this vector\ 1148 * with either of the three hast to be zero) only two are linear independent. The third equation 1149 * is that the vector should be of magnitude 1 (orthonormal). This all leads to a case-based solution 1150 * where very often it has to be checked whether a certain value is zero or not and thus forked into 1151 * another case. 1152 * \param *x1 first vector 1153 * \param *x2 second vector 1154 * \param *y third vector 1155 * \param alpha first angle 1156 * \param beta second angle 1157 * \param c norm of final vector 1158 * \return a vector with \f$\langle x1,x2 \rangle=A\f$, \f$\langle x1,y \rangle = B\f$ and with norm \a c. 1159 * \bug this is not yet working properly 1160 */ 1161 bool Vector::SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c) 1162 { 1163 double D1,D2,D3,E1,E2,F1,F2,F3,p,q=0., A, B1, B2, C; 1164 double ang; // angle on testing 1165 double sign[3]; 1166 int i,j,k; 1167 A = cos(alpha) * x1->Norm() * c; 1168 B1 = cos(beta + M_PI/2.) * y->Norm() * c; 1169 B2 = cos(beta) * x2->Norm() * c; 1170 C = c * c; 1171 DoLog(2) && (Log() << Verbose(2) << "A " << A << "\tB " << B1 << "\tC " << C << endl); 1172 int flag = 0; 1173 if (fabs(x1->x[0]) < MYEPSILON) { // check for zero components for the later flipping and back-flipping 1174 if (fabs(x1->x[1]) > MYEPSILON) { 1175 flag = 1; 1176 } else if (fabs(x1->x[2]) > MYEPSILON) { 1177 flag = 2; 1178 } else { 1179 return false; 1180 } 1181 } 1182 switch (flag) { 1183 default: 1184 case 0: 1185 break; 1186 case 2: 1187 flip(x1->x[0],x1->x[1]); 1188 flip(x2->x[0],x2->x[1]); 1189 flip(y->x[0],y->x[1]); 1190 //flip(x[0],x[1]); 1191 flip(x1->x[1],x1->x[2]); 1192 flip(x2->x[1],x2->x[2]); 1193 flip(y->x[1],y->x[2]); 1194 //flip(x[1],x[2]); 1195 case 1: 1196 flip(x1->x[0],x1->x[1]); 1197 flip(x2->x[0],x2->x[1]); 1198 flip(y->x[0],y->x[1]); 1199 //flip(x[0],x[1]); 1200 flip(x1->x[1],x1->x[2]); 1201 flip(x2->x[1],x2->x[2]); 1202 flip(y->x[1],y->x[2]); 1203 //flip(x[1],x[2]); 1204 break; 1205 } 1206 // now comes the case system 1207 D1 = -y->x[0]/x1->x[0]*x1->x[1]+y->x[1]; 1208 D2 = -y->x[0]/x1->x[0]*x1->x[2]+y->x[2]; 1209 D3 = y->x[0]/x1->x[0]*A-B1; 1210 DoLog(2) && (Log() << Verbose(2) << "D1 " << D1 << "\tD2 " << D2 << "\tD3 " << D3 << "\n"); 1211 if (fabs(D1) < MYEPSILON) { 1212 DoLog(2) && (Log() << Verbose(2) << "D1 == 0!\n"); 1213 if (fabs(D2) > MYEPSILON) { 1214 DoLog(3) && (Log() << Verbose(3) << "D2 != 0!\n"); 1215 x[2] = -D3/D2; 1216 E1 = A/x1->x[0] + x1->x[2]/x1->x[0]*D3/D2; 1217 E2 = -x1->x[1]/x1->x[0]; 1218 DoLog(3) && (Log() << Verbose(3) << "E1 " << E1 << "\tE2 " << E2 << "\n"); 1219 F1 = E1*E1 + 1.; 1220 F2 = -E1*E2; 1221 F3 = E1*E1 + D3*D3/(D2*D2) - C; 1222 DoLog(3) && (Log() << Verbose(3) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n"); 1223 if (fabs(F1) < MYEPSILON) { 1224 DoLog(4) && (Log() << Verbose(4) << "F1 == 0!\n"); 1225 DoLog(4) && (Log() << Verbose(4) << "Gleichungssystem linear\n"); 1226 x[1] = F3/(2.*F2); 1227 } else { 1228 p = F2/F1; 1229 q = p*p - F3/F1; 1230 DoLog(4) && (Log() << Verbose(4) << "p " << p << "\tq " << q << endl); 1231 if (q < 0) { 1232 DoLog(4) && (Log() << Verbose(4) << "q < 0" << endl); 1233 return false; 1234 } 1235 x[1] = p + sqrt(q); 1236 } 1237 x[0] = A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2]; 1238 } else { 1239 DoLog(2) && (Log() << Verbose(2) << "Gleichungssystem unterbestimmt\n"); 1240 return false; 1241 } 1242 } else { 1243 E1 = A/x1->x[0]+x1->x[1]/x1->x[0]*D3/D1; 1244 E2 = x1->x[1]/x1->x[0]*D2/D1 - x1->x[2]; 1245 DoLog(2) && (Log() << Verbose(2) << "E1 " << E1 << "\tE2 " << E2 << "\n"); 1246 F1 = E2*E2 + D2*D2/(D1*D1) + 1.; 1247 F2 = -(E1*E2 + D2*D3/(D1*D1)); 1248 F3 = E1*E1 + D3*D3/(D1*D1) - C; 1249 DoLog(2) && (Log() << Verbose(2) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n"); 1250 if (fabs(F1) < MYEPSILON) { 1251 DoLog(3) && (Log() << Verbose(3) << "F1 == 0!\n"); 1252 DoLog(3) && (Log() << Verbose(3) << "Gleichungssystem linear\n"); 1253 x[2] = F3/(2.*F2); 1254 } else { 1255 p = F2/F1; 1256 q = p*p - F3/F1; 1257 DoLog(3) && (Log() << Verbose(3) << "p " << p << "\tq " << q << endl); 1258 if (q < 0) { 1259 DoLog(3) && (Log() << Verbose(3) << "q < 0" << endl); 1260 return false; 1261 } 1262 x[2] = p + sqrt(q); 1263 } 1264 x[1] = (-D2 * x[2] - D3)/D1; 1265 x[0] = A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2]; 1266 } 1267 switch (flag) { // back-flipping 1268 default: 1269 case 0: 1270 break; 1271 case 2: 1272 flip(x1->x[0],x1->x[1]); 1273 flip(x2->x[0],x2->x[1]); 1274 flip(y->x[0],y->x[1]); 1275 flip(x[0],x[1]); 1276 flip(x1->x[1],x1->x[2]); 1277 flip(x2->x[1],x2->x[2]); 1278 flip(y->x[1],y->x[2]); 1279 flip(x[1],x[2]); 1280 case 1: 1281 flip(x1->x[0],x1->x[1]); 1282 flip(x2->x[0],x2->x[1]); 1283 flip(y->x[0],y->x[1]); 1284 //flip(x[0],x[1]); 1285 flip(x1->x[1],x1->x[2]); 1286 flip(x2->x[1],x2->x[2]); 1287 flip(y->x[1],y->x[2]); 1288 flip(x[1],x[2]); 1289 break; 1290 } 1291 // one z component is only determined by its radius (without sign) 1292 // thus check eight possible sign flips and determine by checking angle with second vector 1293 for (i=0;i<8;i++) { 1294 // set sign vector accordingly 1295 for (j=2;j>=0;j--) { 1296 k = (i & pot(2,j)) << j; 1297 DoLog(2) && (Log() << Verbose(2) << "k " << k << "\tpot(2,j) " << pot(2,j) << endl); 1298 sign[j] = (k == 0) ? 1. : -1.; 1299 } 1300 DoLog(2) && (Log() << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n"); 1301 // apply sign matrix 1302 for (j=NDIM;j--;) 1303 x[j] *= sign[j]; 1304 // calculate angle and check 1305 ang = x2->Angle (this); 1306 DoLog(1) && (Log() << Verbose(1) << i << "th angle " << ang << "\tbeta " << cos(beta) << " :\t"); 1307 if (fabs(ang - cos(beta)) < MYEPSILON) { 1308 break; 1309 } 1310 // unapply sign matrix (is its own inverse) 1311 for (j=NDIM;j--;) 1312 x[j] *= sign[j]; 1313 } 1314 return true; 1315 }; 688 void Vector::SubtractVector(const Vector &y) 689 { 690 for(int i=NDIM;i--;) 691 x[i] -= y[i]; 692 } 1316 693 1317 694 /** … … 1324 701 bool Vector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const 1325 702 { 1326 Vector a; 1327 a.CopyVector(this); 1328 a.SubtractVector(&offset); 703 Vector a = (*this)-offset; 1329 704 a.InverseMatrixMultiplication(parallelepiped); 1330 705 bool isInside = true; 1331 706 1332 707 for (int i=NDIM;i--;) 1333 isInside = isInside && ((a .x[i] <= 1) && (a.x[i] >= 0));708 isInside = isInside && ((a[i] <= 1) && (a[i] >= 0)); 1334 709 1335 710 return isInside; -
src/vector.hpp
r632bc3 r8cbb97 15 15 #include <gsl/gsl_multimin.h> 16 16 17 #include <memory> 18 17 19 #include "defs.hpp" 18 20 … … 23 25 */ 24 26 class Vector { 25 public: 26 double x[NDIM]; 27 protected: 28 // this struct is used to indicate calls to the Baseconstructor from inside vectors. 29 struct Baseconstructor{}; 30 public: 27 31 28 32 Vector(); 29 Vector(const Vector * const a);30 Vector(const Vector &a);31 33 Vector(const double x1, const double x2, const double x3); 32 ~Vector(); 34 Vector(const Vector& src); 35 virtual ~Vector(); 33 36 34 double Distance(const Vector * const y) const; 35 double DistanceSquared(const Vector * const y) const; 36 double DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const; 37 double PeriodicDistance(const Vector * const y, const double * const cell_size) const; 38 double PeriodicDistanceSquared(const Vector * const y, const double * const cell_size) const; 39 double ScalarProduct(const Vector * const y) const; 37 // Method implemented by forwarding to the Representation 38 39 double DistanceSquared(const Vector &y) const; 40 Vector GetDistanceVectorToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const; 41 double DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const; 42 double PeriodicDistance(const Vector &y, const double * const cell_size) const; 43 double PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const; 44 double ScalarProduct(const Vector &y) const; 45 double Angle(const Vector &y) const; 46 bool IsZero() const; 47 bool IsOne() const; 48 bool IsNormalTo(const Vector &normal) const; 49 bool IsEqualTo(const Vector &a) const; 50 51 void AddVector(const Vector &y); 52 void SubtractVector(const Vector &y); 53 void VectorProduct(const Vector &y); 54 void ProjectOntoPlane(const Vector &y); 55 void ProjectIt(const Vector &y); 56 Vector Projection(const Vector &y) const; 57 void Mirror(const Vector &x); 58 void ScaleAll(const double *factor); 59 void Scale(const double factor); 60 void MatrixMultiplication(const double * const M); 61 bool InverseMatrixMultiplication(const double * const M); 62 void KeepPeriodic(const double * const matrix); 63 bool GetOneNormalVector(const Vector &x1); 64 bool MakeNormalTo(const Vector &y1); 65 bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const; 66 void WrapPeriodically(const double * const M, const double * const Minv); 67 68 // Accessors ussually come in pairs... and sometimes even more than that 69 double& operator[](size_t i); 70 const double& operator[](size_t i) const; 71 double& at(size_t i); 72 const double& at(size_t i) const; 73 74 // Assignment operator 75 Vector &operator=(const Vector& src); 76 77 // Access to internal structure 78 double* get(); 79 80 // Methods that are derived directly from other methods 81 double Distance(const Vector &y) const; 40 82 double Norm() const; 41 83 double NormSquared() const; 42 double Angle(const Vector * const y) const; 43 bool IsZero() const; 44 bool IsOne() const; 45 bool IsNormalTo(const Vector * const normal) const; 46 bool IsEqualTo(const Vector * const a) const; 47 48 void AddVector(const Vector * const y); 49 void SubtractVector(const Vector * const y); 50 void CopyVector(const Vector * const y); 51 void CopyVector(const Vector &y); 52 void RotateVector(const Vector * const y, const double alpha); 53 void VectorProduct(const Vector * const y); 54 void ProjectOntoPlane(const Vector * const y); 55 void ProjectIt(const Vector * const y); 56 Vector Projection(const Vector * const y) const; 84 void Normalize(); 57 85 void Zero(); 58 86 void One(const double one); 59 void Init(const double x1, const double x2, const double x3); 60 void Normalize(); 61 void Translate(const Vector * const x); 62 void Mirror(const Vector * const x); 63 void Scale(const double ** const factor); 64 void Scale(const double * const factor); 65 void Scale(const double factor); 66 void MatrixMultiplication(const double * const M); 67 void InverseMatrixMultiplication(const double * const M); 68 void KeepPeriodic(const double * const matrix); 69 void LinearCombinationOfVectors(const Vector * const x1, const Vector * const x2, const Vector * const x3, const double * const factors); 70 double CutsPlaneAt(const Vector * const A, const Vector * const B, const Vector * const C) const; 71 Vector GetDistanceVectorToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const; 72 bool GetIntersectionWithPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset, const Vector * const Origin, const Vector * const LineVector); 73 bool GetIntersectionOfTwoLinesOnPlane(const Vector * const Line1a, const Vector * const Line1b, const Vector * const Line2a, const Vector * const Line2b, const Vector *Normal = NULL); 74 bool GetOneNormalVector(const Vector * const x1); 75 bool MakeNormalVector(const Vector * const y1); 76 bool MakeNormalVector(const Vector * const y1, const Vector * const y2); 77 bool MakeNormalVector(const Vector * const x1, const Vector * const x2, const Vector * const x3); 78 bool SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c); 79 bool LSQdistance(const Vector ** vectors, int dim); 80 void AskPosition(const double * const cell_size, const bool check); 81 void Output() const; 82 bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const; 83 void WrapPeriodically(const double * const M, const double * const Minv); 87 void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors); 88 89 // operators for mathematical operations 90 bool operator==(const Vector& b) const; 91 const Vector& operator+=(const Vector& b); 92 const Vector& operator-=(const Vector& b); 93 Vector const operator+(const Vector& b) const; 94 Vector const operator-(const Vector& b) const; 95 96 protected: 97 98 private: 99 double x[NDIM]; 84 100 85 101 }; 86 102 87 103 ostream & operator << (ostream& ost, const Vector &m); 88 bool operator==(const Vector& a, const Vector& b);89 const Vector& operator+=(Vector& a, const Vector& b);90 const Vector& operator-=(Vector& a, const Vector& b);91 104 const Vector& operator*=(Vector& a, const double m); 92 105 Vector const operator*(const Vector& a, const double m); 93 106 Vector const operator*(const double m, const Vector& a); 94 Vector const operator+(const Vector& a, const Vector& b);95 Vector const operator-(const Vector& a, const Vector& b);96 97 107 98 108 #endif /*VECTOR_HPP_*/
Note:
See TracChangeset
for help on using the changeset viewer.