- Timestamp:
- Apr 7, 2010, 3:45:38 PM (16 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, Candidate_v1.7.0, Candidate_v1.7.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:
- 72e7fa
- Parents:
- f9352d
- Location:
- src
- Files:
-
- 9 added
- 29 edited
-
Exceptions/CustomException.cpp (added)
-
Exceptions/CustomException.hpp (added)
-
Exceptions/LinearDependenceException.cpp (added)
-
Exceptions/LinearDependenceException.hpp (added)
-
Helpers/fast_functions.hpp (added)
-
Legacy/oldmenu.cpp (modified) (20 diffs)
-
Makefile.am (modified) (5 diffs)
-
Plane.cpp (added)
-
Plane.hpp (added)
-
UIElements/TextDialog.cpp (modified) (1 diff)
-
analysis_correlation.cpp (modified) (1 diff)
-
atom.cpp (modified) (6 diffs)
-
atom_trajectoryparticle.cpp (modified) (12 diffs)
-
boundary.cpp (modified) (12 diffs)
-
builder.cpp (modified) (6 diffs)
-
config.cpp (modified) (9 diffs)
-
ellipsoid.cpp (modified) (4 diffs)
-
gslmatrix.cpp (modified) (1 diff)
-
helpers.cpp (modified) (3 diffs)
-
helpers.hpp (modified) (3 diffs)
-
leastsquaremin.cpp (modified) (1 diff)
-
linearsystemofequations.cpp (modified) (2 diffs)
-
linkedcell.cpp (modified) (9 diffs)
-
molecule.cpp (modified) (11 diffs)
-
molecule_dynamics.cpp (modified) (5 diffs)
-
molecule_fragmentation.cpp (modified) (3 diffs)
-
molecule_geometry.cpp (modified) (9 diffs)
-
molecule_graph.cpp (modified) (1 diff)
-
moleculelist.cpp (modified) (2 diffs)
-
tesselation.cpp (modified) (22 diffs)
-
tesselationhelpers.cpp (modified) (13 diffs)
-
unittests/ActOnAllUnitTest.cpp (modified) (2 diffs)
-
unittests/ActOnAllUnitTest.hpp (modified) (1 diff)
-
unittests/vectorunittest.cpp (modified) (2 diffs)
-
vector.cpp (modified) (17 diffs)
-
vector.hpp (modified) (3 diffs)
-
vector_ops.cpp (added)
-
vector_ops.hpp (added)
Legend:
- Unmodified
- Added
- Removed
-
src/Legacy/oldmenu.cpp
rf9352d r0a4f7f 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" … … 77 79 break; 78 80 case 'a': // absolute coordinates of atom 79 Log() << Verbose(0) << "Enter absolute coordinates." << endl;81 { 80 82 first = World::getInstance().createAtom(); 81 first->x.AskPosition(mol->cell_size, false); 82 first->type = periode->AskElement(); // give type 83 mol->AddAtom(first); // add to molecule 84 break; 83 Dialog *dialog = UIFactory::getInstance().makeDialog(); 84 dialog->queryVector("Enter absolute coordinates.",&first->x,mol->cell_size, false); 85 dialog->queryElement("Choose element for this atom",&first->type); 86 if(dialog->display()){ 87 mol->AddAtom(first); // add to molecule 88 } 89 else{ 90 // dialog was canceled... destroy the atom that was used 91 World::getInstance().destroyAtom(first); 92 } 93 delete dialog; 94 } 95 break; 85 96 86 97 case 'b': // relative coordinates of atom wrt to reference point … … 88 99 valid = true; 89 100 do { 101 Dialog *dialog = UIFactory::getInstance().makeDialog(); 90 102 if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; 91 Log() << Verbose(0) << "Enter reference coordinates." << endl; 92 x.AskPosition(mol->cell_size, true); 93 Log() << Verbose(0) << "Enter relative coordinates." << endl; 94 first->x.AskPosition(mol->cell_size, false); 95 first->x.AddVector((const Vector *)&x); 96 Log() << Verbose(0) << "\n"; 97 } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); 103 dialog->queryVector("Enter reference coordinates.",&x,mol->cell_size,true); 104 dialog->queryVector("Enter relative coordinates.",&first->x,mol->cell_size,false); 105 first->x.AddVector(&x); 106 dialog->display(); 107 delete dialog; 108 } while (!(valid = mol->CheckBounds(&first->x))); 98 109 first->type = periode->AskElement(); // give type 99 110 mol->AddAtom(first); // add to molecule … … 101 112 102 113 case 'c': // relative coordinates of atom wrt to already placed atom 114 { 103 115 first = World::getInstance().createAtom(); 104 116 valid = true; … … 106 118 if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; 107 119 second = mol->AskAtom("Enter atom number: "); 108 Log() << Verbose(0) << "Enter relative coordinates." << endl; 109 first->x.AskPosition(mol->cell_size, false); 120 Dialog *dialog = UIFactory::getInstance().makeDialog(); 121 dialog->queryVector("Enter relative coordinates.",&first->x,mol->cell_size,false); 122 dialog->display(); 110 123 for (int i=NDIM;i--;) { 111 first->x .x[i] += second->x.x[i];124 first->x[i] += second->x[i]; 112 125 } 113 126 } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); 114 127 first->type = periode->AskElement(); // give type 115 128 mol->AddAtom(first); // add to molecule 116 break; 129 } 130 break; 117 131 118 132 case 'd': // two atoms, two angles and a distance … … 157 171 x.SubtractVector(&third->x); 158 172 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; 173 Log() << Verbose(0) << "x: " << x << endl; 174 z = Plane(second->x,third->x,fourth->x).getNormal(); 175 Log() << Verbose(0) << "z: " << z << endl; 176 y = Plane(x,z,0).getNormal(); 177 Log() << Verbose(0) << "y: " << y << endl; 170 178 171 179 // rotate vector around first angle 172 180 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; 181 first->x = RotateVector(first->x,z,b - M_PI); 182 Log() << Verbose(0) << "Rotated vector: " << first->x << endl, 177 183 // remove the projection onto the rotation plane of the second angle 178 184 n.CopyVector(&y); 179 185 n.Scale(first->x.ScalarProduct(&y)); 180 Log() << Verbose(0) << "N1: ", 181 n.Output(); 182 Log() << Verbose(0) << endl; 186 Log() << Verbose(0) << "N1: " << n << endl; 183 187 first->x.SubtractVector(&n); 184 Log() << Verbose(0) << "Subtracted vector: ", 185 first->x.Output(); 186 Log() << Verbose(0) << endl; 188 Log() << Verbose(0) << "Subtracted vector: " << first->x << endl; 187 189 n.CopyVector(&z); 188 190 n.Scale(first->x.ScalarProduct(&z)); 189 Log() << Verbose(0) << "N2: ", 190 n.Output(); 191 Log() << Verbose(0) << endl; 191 Log() << Verbose(0) << "N2: " << n << endl; 192 192 first->x.SubtractVector(&n); 193 Log() << Verbose(0) << "2nd subtracted vector: ", 194 first->x.Output(); 195 Log() << Verbose(0) << endl; 193 Log() << Verbose(0) << "2nd subtracted vector: " << first->x << endl; 196 194 197 195 // rotate another vector around second angle 198 196 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; 197 n = RotateVector(n,x,c - M_PI); 198 Log() << Verbose(0) << "2nd Rotated vector: " << n << endl; 203 199 204 200 // add the two linear independent vectors … … 208 204 first->x.AddVector(&second->x); 209 205 210 Log() << Verbose(0) << "resulting coordinates: "; 211 first->x.Output(); 212 Log() << Verbose(0) << endl; 206 Log() << Verbose(0) << "resulting coordinates: " << first->x << endl; 213 207 } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); 214 208 first->type = periode->AskElement(); // give type … … 233 227 } while ((j != -1) && (i<128)); 234 228 if (i >= 2) { 235 first->x.LSQdistance((const Vector **)atoms, i);236 237 first->x.Output();229 LSQdistance(first->x,(const Vector **)atoms, i); 230 231 Log() << Verbose(0) << first->x; 238 232 first->type = periode->AskElement(); // give type 239 233 mol->AddAtom(first); // add to molecule … … 280 274 for (int i=0;i<NDIM;i++) { 281 275 Log() << Verbose(0) << "Enter axis " << i << " boundary: "; 282 cin >> y .x[i];276 cin >> y[i]; 283 277 } 284 278 mol->CenterEdge(&x); // make every coordinate positive … … 293 287 for (int i=0;i<NDIM;i++) { 294 288 Log() << Verbose(0) << "Enter axis " << i << " boundary: "; 295 cin >> x .x[i];289 cin >> x[i]; 296 290 } 297 291 // update Box of atoms by boundary … … 330 324 third = mol->AskAtom("Enter third atom: "); 331 325 332 n .MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);326 n = Plane(first->x,second->x,third->x).getNormal(); 333 327 break; 334 328 case 'b': // normal vector of mirror plane 335 Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl; 336 n.AskPosition(mol->cell_size,0); 329 { 330 Dialog *dialog = UIFactory::getInstance().makeDialog(); 331 dialog->queryVector("Enter normal vector of mirror plane.",&n,mol->cell_size,false); 332 dialog->display(); 333 delete dialog; 337 334 n.Normalize(); 338 break; 335 } 336 break; 337 339 338 case 'c': // three atoms defining mirror plane 340 339 first = mol->AskAtom("Enter first atom: "); … … 356 355 mol->GetAlignvector(¶m); 357 356 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);357 x[i] = gsl_vector_get(param.x,i); 358 n[i] = gsl_vector_get(param.x,i+NDIM); 360 359 } 361 360 gsl_vector_free(param.x); 362 Log() << Verbose(0) << "Offset vector: "; 363 x.Output(); 364 Log() << Verbose(0) << endl; 361 Log() << Verbose(0) << "Offset vector: " << x << endl; 365 362 n.Normalize(); 366 363 break; 367 364 }; 368 Log() << Verbose(0) << "Alignment vector: "; 369 n.Output(); 370 Log() << Verbose(0) << endl; 365 Log() << Verbose(0) << "Alignment vector: " << n << endl; 371 366 mol->Align(&n); 372 367 }; … … 397 392 third = mol->AskAtom("Enter third atom: "); 398 393 399 n .MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);394 n = Plane(first->x,second->x,third->x).getNormal(); 400 395 break; 401 396 case 'b': // normal vector of mirror plane 402 Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl; 403 n.AskPosition(mol->cell_size,0); 397 { 398 Dialog *dialog = UIFactory::getInstance().makeDialog(); 399 dialog->queryVector("Enter normal vector of mirror plane.",&n,mol->cell_size,false); 400 dialog->display(); 401 delete dialog; 404 402 n.Normalize(); 405 break; 403 } 404 break; 405 406 406 case 'c': // three atoms defining mirror plane 407 407 first = mol->AskAtom("Enter first atom: "); … … 413 413 break; 414 414 }; 415 Log() << Verbose(0) << "Normal vector: "; 416 n.Output(); 417 Log() << Verbose(0) << endl; 415 Log() << Verbose(0) << "Normal vector: " << n << endl; 418 416 mol->Mirror((const Vector *)&n); 419 417 }; … … 471 469 first = second; 472 470 second = first->next; 473 if ((first->x .x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ...471 if ((first->x[axis] < tmp1) || (first->x[axis] > tmp2)) {// out of boundary ... 474 472 //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl; 475 473 mol->RemoveAtom(first); … … 541 539 x.SubtractVector((const Vector *)&second->x); 542 540 tmp1 = x.Norm(); 543 Log() << Verbose(1) << "Distance vector is "; 544 x.Output(); 545 Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl; 541 Log() << Verbose(1) << "Distance vector is " << x << "." << "/n" 542 << "Norm of distance is " << tmp1 << "." << endl; 546 543 break; 547 544 … … 676 673 minBond = 0.; 677 674 for (int i=NDIM;i--;) 678 minBond += (first->x .x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);675 minBond += (first->x[i]-second->x[i])*(first->x[i] - second->x[i]); 679 676 minBond = sqrt(minBond); 680 677 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 679 cin >> bond; 683 680 for (int i=NDIM;i--;) { 684 second->x .x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond);681 second->x[i] -= (second->x[i]-first->x[i])/minBond*(minBond-bond); 685 682 } 686 683 //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: "; … … 778 775 x.Zero(); 779 776 y.Zero(); 780 y .x[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude777 y[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude 781 778 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times 782 779 x.AddVector(&y); // per factor one cell width further … … 893 890 mol = *ListRunner; 894 891 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; 895 Log() << Verbose(0) << "Enter translation vector." << endl; 896 x.AskPosition(mol->cell_size,0); 892 Dialog *dialog = UIFactory::getInstance().makeDialog(); 893 dialog->queryVector("Enter translation vector.",&x,mol->cell_size,false); 894 dialog->display(); 895 delete dialog; 897 896 mol->Center.AddVector((const Vector *)&x); 898 897 } -
src/Makefile.am
rf9352d r0a4f7f 1 # this includes source files that need to be present at multiple points 2 HELPERSOURCE = Helpers/Assert.cpp 3 1 4 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 5 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 6 4 LINALGSOURCE = gslmatrix.cpp gslvector.cpp linearsystemofequations.cpp 5 LINALGHEADER = gslmatrix.hpp gslvector.hpp linearsystemofequations.hpp 7 LINALGSOURCE = ${HELPERSOURCE} \ 8 gslmatrix.cpp \ 9 gslvector.cpp \ 10 linearsystemofequations.cpp \ 11 vector.cpp 12 13 LINALGHEADER = gslmatrix.hpp \ 14 gslvector.hpp \ 15 linearsystemofequations.hpp \ 16 vector.hpp 17 6 18 7 19 ANALYSISSOURCE = analysis_bonds.cpp analysis_correlation.cpp … … 70 82 71 83 84 EXCEPTIONSOURCE = Exceptions/CustomException.cpp \ 85 Exceptions/LinearDependenceException.cpp 86 87 EXCEPTIONHEADER = Exceptions/CustomException.hpp \ 88 Exceptions/LinearDependenceException.hpp 89 72 90 SOURCE = ${ANALYSISSOURCE} \ 73 91 ${ATOMSOURCE} \ … … 75 93 ${UISOURCE} \ 76 94 ${DESCRIPTORSOURCE} \ 95 ${HELPERSOURCE} \ 77 96 ${LEGACYSOURCE} \ 97 ${EXCEPTIONSOURCE} \ 78 98 bond.cpp \ 79 99 bondgraph.cpp \ … … 85 105 graph.cpp \ 86 106 helpers.cpp \ 87 Helpers/Assert.cpp \88 107 info.cpp \ 89 108 leastsquaremin.cpp \ … … 102 121 parser.cpp \ 103 122 periodentafel.cpp \ 123 Plane.cpp \ 104 124 tesselation.cpp \ 105 125 tesselationhelpers.cpp \ 106 vector.cpp \107 126 verbose.cpp \ 127 vector_ops.cpp \ 108 128 World.cpp 109 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PATTERNHEADER} ${UIHEADER} ${DESCRIPTORHEADER} ${LEGACYHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp World.hpp 129 130 HEADER = ${ANALYSISHEADER} \ 131 ${ATOMHEADER} \ 132 ${PATTERNHEADER} \ 133 ${UIHEADER} \ 134 ${DESCRIPTORHEADER} \ 135 ${LEGACYHEADER} \ 136 ${EXCEPTIONHEADER} \ 137 bond.hpp \ 138 bondgraph.hpp \ 139 boundary.hpp \ 140 config.hpp \ 141 defs.hpp \ 142 element.hpp \ 143 ellipsoid.hpp \ 144 errorlogger.hpp \ 145 graph.hpp \ 146 info.hpp \ 147 leastsquaremin.hpp \ 148 linkedcell.hpp \ 149 lists.hpp \ 150 log.hpp \ 151 logger.hpp \ 152 memoryallocator.hpp \ 153 memoryusageobserver.hpp \ 154 molecule.hpp \ 155 molecule_template.hpp \ 156 parser.hpp \ 157 periodentafel.hpp \ 158 Plane.hpp \ 159 stackclass.hpp \ 160 tesselation.hpp \ 161 tesselationhelpers.hpp \ 162 verbose.hpp \ 163 vector_ops.hpp \ 164 World.hpp 110 165 111 166 BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB) -
src/UIElements/TextDialog.cpp
rf9352d r0a4f7f 119 119 120 120 bool TextDialog::VectorTextQuery::handle() { 121 Log() << Verbose(0) << getTitle(); 122 tmp->AskPosition(cellSize,check); 123 return true; 121 Log() << Verbose(0) << getTitle(); 122 123 char coords[3] = {'x','y','z'}; 124 int j = -1; 125 for (int i=0;i<3;i++) { 126 j += i+1; 127 do { 128 Log() << Verbose(0) << coords[i] << "[0.." << cellSize[j] << "]: "; 129 cin >> (*tmp)[i]; 130 } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= cellSize[j])) && (check)); 131 } 132 return true; 124 133 } 125 134 -
src/analysis_correlation.cpp
rf9352d r0a4f7f 400 400 *file << runner->first; 401 401 for (int i=0;i<NDIM;i++) 402 *file << "\t" << (runner->second.first->node-> x[i] - runner->second.second->x[i]);402 *file << "\t" << (runner->second.first->node->at(i) - runner->second.second->at(i)); 403 403 *file << endl; 404 404 } -
src/atom.cpp
rf9352d r0a4f7f 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++; -
src/atom_trajectoryparticle.cpp
rf9352d r0a4f7f 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 … … 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/boundary.cpp
rf9352d r0a4f7f 18 18 #include "tesselation.hpp" 19 19 #include "tesselationhelpers.hpp" 20 #include "Plane.hpp" 20 21 21 22 #include<gsl/gsl_poly.h> … … 80 81 DistanceVector.SubtractVector(&Neighbour->second.second->x); 81 82 do { // seek for neighbour pair where it flips 82 OldComponent = DistanceVector .x[Othercomponent];83 OldComponent = DistanceVector[Othercomponent]; 83 84 Neighbour++; 84 85 if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around … … 88 89 //Log() << Verbose(2) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl; 89 90 } while ((runner != Neighbour) && (fabs(OldComponent / fabs( 90 OldComponent) - DistanceVector .x[Othercomponent] / fabs(91 DistanceVector .x[Othercomponent])) < MYEPSILON)); // as long as sign does not flip91 OldComponent) - DistanceVector[Othercomponent] / fabs( 92 DistanceVector[Othercomponent])) < MYEPSILON)); // as long as sign does not flip 92 93 if (runner != Neighbour) { 93 94 OtherNeighbour = Neighbour; … … 102 103 //Log() << Verbose(1) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl; 103 104 // do linear interpolation between points (is exact) to extract exact intersection between Neighbour and OtherNeighbour 104 w1 = fabs(OtherVector .x[Othercomponent]);105 w2 = fabs(DistanceVector .x[Othercomponent]);106 tmp = fabs((w1 * DistanceVector .x[component] + w2107 * OtherVector .x[component]) / (w1 + w2));105 w1 = fabs(OtherVector[Othercomponent]); 106 w2 = fabs(DistanceVector[Othercomponent]); 107 tmp = fabs((w1 * DistanceVector[component] + w2 108 * OtherVector[component]) / (w1 + w2)); 108 109 // mark if it has greater diameter 109 110 //Log() << Verbose(1) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl; … … 159 160 AngleReferenceVector.Zero(); 160 161 AngleReferenceNormalVector.Zero(); 161 AxisVector .x[axis] = 1.;162 AngleReferenceVector .x[(axis + 1) % NDIM] = 1.;163 AngleReferenceNormalVector .x[(axis + 2) % NDIM] = 1.;162 AxisVector[axis] = 1.; 163 AngleReferenceVector[(axis + 1) % NDIM] = 1.; 164 AngleReferenceNormalVector[(axis + 2) % NDIM] = 1.; 164 165 165 166 Log() << Verbose(1) << "Axisvector is " << AxisVector << " and AngleReferenceVector is " << AngleReferenceVector << ", and AngleReferenceNormalVector is " << AngleReferenceNormalVector << "." << endl; … … 636 637 const double c = sqrt(runner->second->endpoints[2]->node->node->DistanceSquared(runner->second->endpoints[1]->node->node)); 637 638 const double G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle 638 x.MakeNormalVector(runner->second->endpoints[0]->node->node, runner->second->endpoints[1]->node->node, runner->second->endpoints[2]->node->node); 639 x = Plane(*(runner->second->endpoints[0]->node->node), 640 *(runner->second->endpoints[1]->node->node), 641 *(runner->second->endpoints[2]->node->node)).getNormal(); 639 642 x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(&x)); 640 643 const double h = x.Norm(); // distance of CoG to triangle … … 751 754 Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl; 752 755 for (int i = 0; i < NDIM; i++) 753 BoxLengths .x[i] = GreatestDiameter[i];756 BoxLengths[i] = GreatestDiameter[i]; 754 757 mol->CenterEdge(&BoxLengths); 755 758 } else { 756 BoxLengths .x[0] = (repetition[0] * GreatestDiameter[0] + repetition[1] * GreatestDiameter[1] + repetition[2] * GreatestDiameter[2]);757 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]);758 BoxLengths .x[2] = minimumvolume - cellvolume;759 BoxLengths[0] = (repetition[0] * GreatestDiameter[0] + repetition[1] * GreatestDiameter[1] + repetition[2] * GreatestDiameter[2]); 760 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]); 761 BoxLengths[2] = minimumvolume - cellvolume; 759 762 double x0 = 0.; 760 763 double x1 = 0.; 761 764 double x2 = 0.; 762 if (gsl_poly_solve_cubic(BoxLengths .x[0], BoxLengths.x[1], BoxLengths.x[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return765 if (gsl_poly_solve_cubic(BoxLengths[0], BoxLengths[1], BoxLengths[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return 763 766 Log() << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl; 764 767 else { … … 769 772 cellvolume = 1.; 770 773 for (int i = 0; i < NDIM; i++) { 771 BoxLengths .x[i] = repetition[i] * (x0 + GreatestDiameter[i]);772 cellvolume *= BoxLengths .x[i];774 BoxLengths[i] = repetition[i] * (x0 + GreatestDiameter[i]); 775 cellvolume *= BoxLengths[i]; 773 776 } 774 777 … … 780 783 // update Box of atoms by boundary 781 784 mol->SetBoxDimension(&BoxLengths); 782 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;785 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; 783 786 }; 784 787 … … 839 842 FillerDistance.InverseMatrixMultiplication(M); 840 843 for(int i=0;i<NDIM;i++) 841 N[i] = (int) ceil(1./FillerDistance.x[i]);844 N[i] = static_cast<int>(ceil(1./FillerDistance[i])); 842 845 Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl; 843 846 … … 880 883 // create molecule random translation vector ... 881 884 for (int i=0;i<NDIM;i++) 882 FillerTranslations .x[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.);885 FillerTranslations[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.); 883 886 Log() << Verbose(2) << "INFO: Translating this filler by " << FillerTranslations << "." << endl; 884 887 … … 892 895 // create atomic random translation vector ... 893 896 for (int i=0;i<NDIM;i++) 894 AtomTranslations .x[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.);897 AtomTranslations[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.); 895 898 896 899 // ... and rotation matrix -
src/builder.cpp
rf9352d r0a4f7f 1487 1487 Log() << Verbose(2) << "found element " << first->type->name << endl; 1488 1488 for (int i=NDIM;i--;) 1489 first->x .x[i] = atof(argv[argptr+1+i]);1489 first->x[i] = atof(argv[argptr+1+i]); 1490 1490 if (first->type != NULL) { 1491 1491 mol->AddAtom(first); // add to molecule … … 1837 1837 Log() << Verbose(1) << "Translating all ions by given vector." << endl; 1838 1838 for (int i=NDIM;i--;) 1839 x .x[i] = atof(argv[argptr+i]);1839 x[i] = atof(argv[argptr+i]); 1840 1840 mol->Translate((const Vector *)&x); 1841 1841 argptr+=3; … … 1853 1853 Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl; 1854 1854 for (int i=NDIM;i--;) 1855 x .x[i] = atof(argv[argptr+i]);1855 x[i] = atof(argv[argptr+i]); 1856 1856 mol->TranslatePeriodically((const Vector *)&x); 1857 1857 argptr+=3; … … 1875 1875 for (int i=0;i<NDIM;i++) { 1876 1876 j += i+1; 1877 x .x[i] = atof(argv[NDIM+i]);1877 x[i] = atof(argv[NDIM+i]); 1878 1878 mol->cell_size[j]*=factor[i]; 1879 1879 } … … 1936 1936 for (int i=0;i<NDIM;i++) { 1937 1937 j += i+1; 1938 x .x[i] = atof(argv[argptr+i]);1939 mol->cell_size[j] += x .x[i]*2.;1938 x[i] = atof(argv[argptr+i]); 1939 mol->cell_size[j] += x[i]*2.; 1940 1940 } 1941 1941 mol->Translate((const Vector *)&x); … … 2094 2094 x.Zero(); 2095 2095 y.Zero(); 2096 y .x[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude2096 y[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude 2097 2097 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times 2098 2098 x.AddVector(&y); // per factor one cell width further -
src/config.cpp
rf9352d r0a4f7f 740 740 neues = AtomList[i][j]; 741 741 status = (status && 742 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x .x[0], 1, (repetition == 0) ? critical : optional) &&743 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x .x[1], 1, (repetition == 0) ? critical : optional) &&744 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x .x[2], 1, (repetition == 0) ? critical : optional) &&742 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x[0], 1, (repetition == 0) ? critical : optional) && 743 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x[1], 1, (repetition == 0) ? critical : optional) && 744 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x[2], 1, (repetition == 0) ? critical : optional) && 745 745 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional)); 746 746 if (!status) break; … … 756 756 // put into trajectories list 757 757 for (int d=0;d<NDIM;d++) 758 neues->Trajectory.R.at(repetition) .x[d] = neues->x.x[d];758 neues->Trajectory.R.at(repetition)[d] = neues->x[d]; 759 759 760 760 // parse velocities if present 761 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v .x[0], 1,optional))762 neues->v .x[0] = 0.;763 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v .x[1], 1,optional))764 neues->v .x[1] = 0.;765 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v .x[2], 1,optional))766 neues->v .x[2] = 0.;761 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v[0], 1,optional)) 762 neues->v[0] = 0.; 763 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v[1], 1,optional)) 764 neues->v[1] = 0.; 765 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v[2], 1,optional)) 766 neues->v[2] = 0.; 767 767 for (int d=0;d<NDIM;d++) 768 neues->Trajectory.U.at(repetition) .x[d] = neues->v.x[d];768 neues->Trajectory.U.at(repetition)[d] = neues->v[d]; 769 769 770 770 // parse forces if present … … 776 776 value[2] = 0.; 777 777 for (int d=0;d<NDIM;d++) 778 neues->Trajectory.F.at(repetition) .x[d] = value[d];778 neues->Trajectory.F.at(repetition)[d] = value[d]; 779 779 780 780 // Log() << Verbose(0) << "Parsed position of step " << (repetition) << ": ("; … … 819 819 neues = AtomList[i][j]; 820 820 // then parse for each atom the coordinates as often as present 821 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x .x[0], repetition,critical);822 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x .x[1], repetition,critical);823 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x .x[2], repetition,critical);821 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x[0], repetition,critical); 822 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x[1], repetition,critical); 823 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x[2], repetition,critical); 824 824 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical); 825 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v .x[0], repetition,optional))826 neues->v .x[0] = 0.;827 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v .x[1], repetition,optional))828 neues->v .x[1] = 0.;829 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v .x[2], repetition,optional))830 neues->v .x[2] = 0.;825 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v[0], repetition,optional)) 826 neues->v[0] = 0.; 827 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v[1], repetition,optional)) 828 neues->v[1] = 0.; 829 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v[2], repetition,optional)) 830 neues->v[2] = 0.; 831 831 // here we don't care if forces are present (last in trajectories is always equal to current position) 832 832 neues->type = elementhash[i]; // find element type … … 1289 1289 istringstream input2(zeile); 1290 1290 atom *neues = World::getInstance().createAtom(); 1291 input2 >> neues->x .x[0]; // x1292 input2 >> neues->x .x[1]; // y1293 input2 >> neues->x .x[2]; // z1291 input2 >> neues->x[0]; // x 1292 input2 >> neues->x[1]; // y 1293 input2 >> neues->x[2]; // z 1294 1294 input2 >> l; 1295 1295 neues->type = elementhash[No]; // find element type … … 1570 1570 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */ 1571 1571 MolNo, /* residue sequence number */ 1572 Walker->node-> x[0], /* position X in Angstroem */1573 Walker->node-> x[1], /* position Y in Angstroem */1574 Walker->node-> x[2], /* position Z in Angstroem */1572 Walker->node->at(0), /* position X in Angstroem */ 1573 Walker->node->at(1), /* position Y in Angstroem */ 1574 Walker->node->at(2), /* position Z in Angstroem */ 1575 1575 (double)Walker->type->Valence, /* occupancy */ 1576 1576 (double)Walker->type->NoValenceOrbitals, /* temperature factor */ … … 1624 1624 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */ 1625 1625 0, /* residue sequence number */ 1626 Walker->node-> x[0], /* position X in Angstroem */1627 Walker->node-> x[1], /* position Y in Angstroem */1628 Walker->node-> x[2], /* position Z in Angstroem */1626 Walker->node->at(0), /* position X in Angstroem */ 1627 Walker->node->at(1), /* position Y in Angstroem */ 1628 Walker->node->at(2), /* position Z in Angstroem */ 1629 1629 (double)Walker->type->Valence, /* occupancy */ 1630 1630 (double)Walker->type->NoValenceOrbitals, /* temperature factor */ … … 1677 1677 *output << mol->name << "\t"; 1678 1678 *output << 0 << "\t"; 1679 *output << Walker->node-> x[0] << "\t" << Walker->node->x[1] << "\t" << Walker->node->x[2]<< "\t";1680 *output << (double)Walker->type->Valence<< "\t";1679 *output << Walker->node->at(0) << "\t" << Walker->node->at(1) << "\t" << Walker->node->at(2) << "\t"; 1680 *output << static_cast<double>(Walker->type->Valence) << "\t"; 1681 1681 *output << Walker->type->symbol << "\t"; 1682 1682 for (BondList::iterator runner = Walker->ListOfBonds.begin(); runner != Walker->ListOfBonds.end(); runner++) … … 1752 1752 *output << (*MolWalker)->name << "\t"; 1753 1753 *output << MolCounter << "\t"; 1754 *output << Walker->node-> x[0] << "\t" << Walker->node->x[1] << "\t" << Walker->node->x[2]<< "\t";1754 *output << Walker->node->at(0) << "\t" << Walker->node->at(1) << "\t" << Walker->node->at(2) << "\t"; 1755 1755 *output << (double)Walker->type->Valence << "\t"; 1756 1756 *output << Walker->type->symbol << "\t"; -
src/ellipsoid.cpp
rf9352d r0a4f7f 116 116 // put parameters into suitable ellipsoid form 117 117 for (int i=0;i<3;i++) { 118 Center .x[i] = gsl_vector_get(x, i+0);118 Center[i] = gsl_vector_get(x, i+0); 119 119 EllipsoidLength[i] = gsl_vector_get(x, i+3); 120 120 EllipsoidAngle[i] = gsl_vector_get(x, i+6); … … 160 160 x = gsl_vector_alloc (9); 161 161 for (int i=0;i<3;i++) { 162 gsl_vector_set (x, i+0, EllipsoidCenter-> x[i]);162 gsl_vector_set (x, i+0, EllipsoidCenter->at(i)); 163 163 gsl_vector_set (x, i+3, EllipsoidLength[i]); 164 164 gsl_vector_set (x, i+6, EllipsoidAngle[i]); … … 195 195 if (status == GSL_SUCCESS) { 196 196 for (int i=0;i<3;i++) { 197 EllipsoidCenter-> x[i]= gsl_vector_get (s->x,i+0);197 EllipsoidCenter->at(i) = gsl_vector_get (s->x,i+0); 198 198 EllipsoidLength[i] = gsl_vector_get (s->x, i+3); 199 199 EllipsoidAngle[i] = gsl_vector_get (s->x, i+6); … … 427 427 output << number << "\t"; 428 428 for (int i=0;i<3;i++) 429 output << setprecision(9) << EllipsoidCenter .x[i] << "\t";429 output << setprecision(9) << EllipsoidCenter[i] << "\t"; 430 430 for (int i=0;i<3;i++) 431 431 output << setprecision(9) << EllipsoidLength[i] << "\t"; -
src/gslmatrix.cpp
rf9352d r0a4f7f 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
rf9352d r0a4f7f 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
rf9352d r0a4f7f 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
rf9352d r0a4f7f 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
rf9352d r0a4f7f 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
rf9352d r0a4f7f 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 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 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]; … … 252 252 bool status = false; 253 253 for (int i=0;i<NDIM;i++) { 254 n[i] = (int)floor((Walker->node->x[i] - min.x[i])/RADIUS);254 n[i] = static_cast<int>(floor((Walker->node->at(i) - min[i])/RADIUS)); 255 255 } 256 256 index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2]; … … 293 293 bool status = true; 294 294 for (int i=0;i<NDIM;i++) { 295 n[i] = (int)floor((x->x[i] - min.x[i])/RADIUS);296 if (max .x[i] < x->x[i])295 n[i] = static_cast<int>(floor((x->at(i) - min[i])/RADIUS)); 296 if (max[i] < x->at(i)) 297 297 status = false; 298 if (min .x[i] > x->x[i])298 if (min[i] > x->at(i)) 299 299 status = false; 300 300 } -
src/molecule.cpp
rf9352d r0a4f7f 25 25 #include "tesselation.hpp" 26 26 #include "vector.hpp" 27 #include "Plane.hpp" 28 #include "Exceptions/LinearDependenceException.hpp" 27 29 28 30 /************************************* Functions for class molecule *********************************/ … … 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 } … … 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 318 Orthovector1.GetOneNormalVector(&InBondvector); … … 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; … … 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));356 FirstOtherAtom->x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (sin(bondangle)); 357 SecondOtherAtom->x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle)); 349 358 } 350 359 FirstOtherAtom->x.Scale(&BondRescale); // rescale by correct BondDistance … … 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 … … 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); … … 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 … … 661 676 void molecule::SetBoxDimension(Vector *dim) 662 677 { 663 cell_size[0] = dim-> x[0];678 cell_size[0] = dim->at(0); 664 679 cell_size[1] = 0.; 665 cell_size[2] = dim-> x[1];680 cell_size[2] = dim->at(1); 666 681 cell_size[3] = 0.; 667 682 cell_size[4] = 0.; 668 cell_size[5] = dim-> x[2];683 cell_size[5] = dim->at(2); 669 684 }; 670 685 … … 755 770 for (int i=0;i<NDIM;i++) { 756 771 j += i+1; 757 result = result && ((x-> x[i] >= 0) && (x->x[i]< cell_size[j]));772 result = result && ((x->at(i) >= 0) && (x->at(i) < cell_size[j])); 758 773 } 759 774 //return result; … … 1005 1020 DeterminePeriodicCenter(CenterOfGravity); 1006 1021 OtherMolecule->DeterminePeriodicCenter(OtherCenterOfGravity); 1007 Log() << Verbose(5) << "Center of Gravity: "; 1008 CenterOfGravity.Output(); 1009 Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: "; 1010 OtherCenterOfGravity.Output(); 1011 Log() << Verbose(0) << endl; 1022 Log() << Verbose(5) << "Center of Gravity: " << CenterOfGravity << endl; 1023 Log() << Verbose(5) << "Other Center of Gravity: " << OtherCenterOfGravity << endl; 1012 1024 if (CenterOfGravity.DistanceSquared(&OtherCenterOfGravity) > threshold*threshold) { 1013 1025 Log() << Verbose(4) << "Centers of gravity don't match." << endl; -
src/molecule_dynamics.cpp
rf9352d r0a4f7f 14 14 #include "molecule.hpp" 15 15 #include "parser.hpp" 16 #include "Plane.hpp" 16 17 17 18 /************************************* Functions for class molecule *********************************/ … … 79 80 // Log() << Verbose(0) << trajectory2 << endl; 80 81 // determine normal vector for both 81 normal .MakeNormalVector(&trajectory1, &trajectory2);82 normal = Plane(trajectory1, trajectory2,0).getNormal(); 82 83 // print all vectors for debugging 83 84 // Log() << Verbose(0) << "Normal vector in between: "; … … 85 86 // setup matrix 86 87 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]));88 gsl_matrix_set(A, 0, i, trajectory1[i]); 89 gsl_matrix_set(A, 1, i, trajectory2[i]); 90 gsl_matrix_set(A, 2, i, normal[i]); 91 gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep)[i] - Runner->Trajectory.R.at(Params.startstep)[i])); 91 92 } 92 93 // solve the linear system by Householder transformations … … 514 515 Sprinter = mol->AddCopyAtom(Walker); 515 516 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);517 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 518 // add to Trajectories 518 519 //Log() << Verbose(3) << step << ">=" << MDSteps-1 << endl; 519 520 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.;521 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); 522 Walker->Trajectory.U.at(step)[n] = 0.; 523 Walker->Trajectory.F.at(step)[n] = 0.; 523 524 } 524 525 } … … 582 583 for(int i=0;i<AtomCount;i++) 583 584 for(int d=0;d<NDIM;d++) { 584 Velocity .x[d] += Force.Matrix[0][i][d+5];585 Velocity[d] += Force.Matrix[0][i][d+5]; 585 586 } 586 587 for(int i=0;i<AtomCount;i++) 587 588 for(int d=0;d<NDIM;d++) { 588 Force.Matrix[0][i][d+5] -= Velocity .x[d]/(double)AtomCount;589 Force.Matrix[0][i][d+5] -= Velocity[d]/(double)AtomCount; 589 590 } 590 591 // solve a constrained potential if we are meant to -
src/molecule_fragmentation.cpp
rf9352d r0a4f7f 1669 1669 // remove bonds that are beyond bonddistance 1670 1670 for(int i=NDIM;i--;) 1671 Translationvector .x[i] = 0.;1671 Translationvector[i] = 0.; 1672 1672 // scan all bonds 1673 1673 Binder = first; … … 1676 1676 Binder = Binder->next; 1677 1677 for (int i=NDIM;i--;) { 1678 tmp = fabs(Binder->leftatom->x .x[i] - Binder->rightatom->x.x[i]);1678 tmp = fabs(Binder->leftatom->x[i] - Binder->rightatom->x[i]); 1679 1679 //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl; 1680 1680 if (tmp > BondDistance) { … … 1690 1690 // create translation vector from their periodically modified distance 1691 1691 for (int i=NDIM;i--;) { 1692 tmp = Binder->leftatom->x .x[i] - Binder->rightatom->x.x[i];1692 tmp = Binder->leftatom->x[i] - Binder->rightatom->x[i]; 1693 1693 if (fabs(tmp) > BondDistance) 1694 Translationvector .x[i] = (tmp < 0) ? +1. : -1.;1694 Translationvector[i] = (tmp < 0) ? +1. : -1.; 1695 1695 } 1696 1696 Translationvector.MatrixMultiplication(matrix); 1697 1697 //Log() << Verbose(3) << "Translation vector is "; 1698 Translationvector.Output(); 1699 Log() << Verbose(0) << endl; 1698 Log() << Verbose(0) << Translationvector << endl; 1700 1699 // apply to all atoms of first component via BFS 1701 1700 for (int i=AtomCount;i--;) -
src/molecule_geometry.cpp
rf9352d r0a4f7f 69 69 if (ptr != end) { //list not empty? 70 70 for (int i=NDIM;i--;) { 71 max-> x[i] = ptr->x.x[i];72 min-> x[i] = ptr->x.x[i];71 max->at(i) = ptr->x[i]; 72 min->at(i) = ptr->x[i]; 73 73 } 74 74 while (ptr->next != end) { // continue with second if present … … 76 76 //ptr->Output(1,1,out); 77 77 for (int i=NDIM;i--;) { 78 max-> x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i];79 min-> x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i];78 max->at(i) = (max->at(i) < ptr->x[i]) ? ptr->x[i] : max->at(i); 79 min->at(i) = (min->at(i) > ptr->x[i]) ? ptr->x[i] : min->at(i); 80 80 } 81 81 } … … 272 272 if (Walker->nr < (*Runner)->GetOtherAtom(Walker)->nr) // otherwise we shift one to, the other fro and gain nothing 273 273 for (int j=0;j<NDIM;j++) { 274 tmp = Walker->x .x[j] - (*Runner)->GetOtherAtom(Walker)->x.x[j];274 tmp = Walker->x[j] - (*Runner)->GetOtherAtom(Walker)->x[j]; 275 275 if ((fabs(tmp)) > BondDistance) { 276 276 flag = false; 277 277 Log() << Verbose(0) << "Hit: atom " << Walker->Name << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl; 278 278 if (tmp > 0) 279 Translationvector .x[j] -= 1.;279 Translationvector[j] -= 1.; 280 280 else 281 Translationvector .x[j] += 1.;281 Translationvector[j] += 1.; 282 282 } 283 283 } … … 286 286 Testvector.MatrixMultiplication(matrix); 287 287 Center.AddVector(&Testvector); 288 Log() << Verbose(1) << "vector is: "; 289 Testvector.Output(); 290 Log() << Verbose(0) << endl; 288 Log() << Verbose(1) << "vector is: " << Testvector << endl; 291 289 #ifdef ADDHYDROGEN 292 290 // now also change all hydrogens … … 298 296 Testvector.MatrixMultiplication(matrix); 299 297 Center.AddVector(&Testvector); 300 Log() << Verbose(1) << "Hydrogen vector is: "; 301 Testvector.Output(); 302 Log() << Verbose(0) << endl; 298 Log() << Verbose(1) << "Hydrogen vector is: " << Testvector << endl; 303 299 } 304 300 } … … 336 332 x.CopyVector(&ptr->x); 337 333 //x.SubtractVector(CenterOfGravity); 338 InertiaTensor[0] += ptr->type->mass*(x .x[1]*x.x[1] + x.x[2]*x.x[2]);339 InertiaTensor[1] += ptr->type->mass*(-x .x[0]*x.x[1]);340 InertiaTensor[2] += ptr->type->mass*(-x .x[0]*x.x[2]);341 InertiaTensor[3] += ptr->type->mass*(-x .x[1]*x.x[0]);342 InertiaTensor[4] += ptr->type->mass*(x .x[0]*x.x[0] + x.x[2]*x.x[2]);343 InertiaTensor[5] += ptr->type->mass*(-x .x[1]*x.x[2]);344 InertiaTensor[6] += ptr->type->mass*(-x .x[2]*x.x[0]);345 InertiaTensor[7] += ptr->type->mass*(-x .x[2]*x.x[1]);346 InertiaTensor[8] += ptr->type->mass*(x .x[0]*x.x[0] + x.x[1]*x.x[1]);334 InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]); 335 InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]); 336 InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]); 337 InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]); 338 InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]); 339 InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]); 340 InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]); 341 InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]); 342 InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]); 347 343 } 348 344 // print InertiaTensor for debugging … … 388 384 x.CopyVector(&ptr->x); 389 385 //x.SubtractVector(CenterOfGravity); 390 InertiaTensor[0] += ptr->type->mass*(x .x[1]*x.x[1] + x.x[2]*x.x[2]);391 InertiaTensor[1] += ptr->type->mass*(-x .x[0]*x.x[1]);392 InertiaTensor[2] += ptr->type->mass*(-x .x[0]*x.x[2]);393 InertiaTensor[3] += ptr->type->mass*(-x .x[1]*x.x[0]);394 InertiaTensor[4] += ptr->type->mass*(x .x[0]*x.x[0] + x.x[2]*x.x[2]);395 InertiaTensor[5] += ptr->type->mass*(-x .x[1]*x.x[2]);396 InertiaTensor[6] += ptr->type->mass*(-x .x[2]*x.x[0]);397 InertiaTensor[7] += ptr->type->mass*(-x .x[2]*x.x[1]);398 InertiaTensor[8] += ptr->type->mass*(x .x[0]*x.x[0] + x.x[1]*x.x[1]);386 InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]); 387 InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]); 388 InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]); 389 InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]); 390 InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]); 391 InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]); 392 InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]); 393 InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]); 394 InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]); 399 395 } 400 396 // print InertiaTensor for debugging … … 423 419 double alpha, tmp; 424 420 Vector z_axis; 425 z_axis .x[0] = 0.;426 z_axis .x[1] = 0.;427 z_axis .x[2] = 1.;421 z_axis[0] = 0.; 422 z_axis[1] = 0.; 423 z_axis[2] = 1.; 428 424 429 425 // rotate on z-x plane 430 426 Log() << Verbose(0) << "Begin of Aligning all atoms." << endl; 431 alpha = atan(-n-> x[0]/n->x[2]);427 alpha = atan(-n->at(0)/n->at(2)); 432 428 Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... "; 433 429 while (ptr->next != end) { 434 430 ptr = ptr->next; 435 tmp = ptr->x .x[0];436 ptr->x .x[0] = cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];437 ptr->x .x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];431 tmp = ptr->x[0]; 432 ptr->x[0] = cos(alpha) * tmp + sin(alpha) * ptr->x[2]; 433 ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2]; 438 434 for (int j=0;j<MDSteps;j++) { 439 tmp = ptr->Trajectory.R.at(j) .x[0];440 ptr->Trajectory.R.at(j) .x[0] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2];441 ptr->Trajectory.R.at(j) .x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2];435 tmp = ptr->Trajectory.R.at(j)[0]; 436 ptr->Trajectory.R.at(j)[0] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2]; 437 ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2]; 442 438 } 443 439 } 444 440 // rotate n vector 445 tmp = n->x[0]; 446 n->x[0] = cos(alpha) * tmp + sin(alpha) * n->x[2]; 447 n->x[2] = -sin(alpha) * tmp + cos(alpha) * n->x[2]; 448 Log() << Verbose(1) << "alignment vector after first rotation: "; 449 n->Output(); 450 Log() << Verbose(0) << endl; 441 tmp = n->at(0); 442 n->at(0) = cos(alpha) * tmp + sin(alpha) * n->at(2); 443 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2); 444 Log() << Verbose(1) << "alignment vector after first rotation: " << n << endl; 451 445 452 446 // rotate on z-y plane 453 447 ptr = start; 454 alpha = atan(-n-> x[1]/n->x[2]);448 alpha = atan(-n->at(1)/n->at(2)); 455 449 Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... "; 456 450 while (ptr->next != end) { 457 451 ptr = ptr->next; 458 tmp = ptr->x .x[1];459 ptr->x .x[1] = cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];460 ptr->x .x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];452 tmp = ptr->x[1]; 453 ptr->x[1] = cos(alpha) * tmp + sin(alpha) * ptr->x[2]; 454 ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2]; 461 455 for (int j=0;j<MDSteps;j++) { 462 tmp = ptr->Trajectory.R.at(j) .x[1];463 ptr->Trajectory.R.at(j) .x[1] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2];464 ptr->Trajectory.R.at(j) .x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2];456 tmp = ptr->Trajectory.R.at(j)[1]; 457 ptr->Trajectory.R.at(j)[1] = cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2]; 458 ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2]; 465 459 } 466 460 } 467 461 // rotate n vector (for consistency check) 468 tmp = n->x[1]; 469 n->x[1] = cos(alpha) * tmp + sin(alpha) * n->x[2]; 470 n->x[2] = -sin(alpha) * tmp + cos(alpha) * n->x[2]; 471 472 Log() << Verbose(1) << "alignment vector after second rotation: "; 473 n->Output(); 474 Log() << Verbose(1) << endl; 462 tmp = n->at(1); 463 n->at(1) = cos(alpha) * tmp + sin(alpha) * n->at(2); 464 n->at(2) = -sin(alpha) * tmp + cos(alpha) * n->at(2); 465 466 Log() << Verbose(1) << "alignment vector after second rotation: " << n << endl; 475 467 Log() << Verbose(0) << "End of Aligning all atoms." << endl; 476 468 }; … … 490 482 491 483 // initialize vectors 492 a .x[0] = gsl_vector_get(x,0);493 a .x[1] = gsl_vector_get(x,1);494 a .x[2] = gsl_vector_get(x,2);495 b .x[0] = gsl_vector_get(x,3);496 b .x[1] = gsl_vector_get(x,4);497 b .x[2] = gsl_vector_get(x,5);484 a[0] = gsl_vector_get(x,0); 485 a[1] = gsl_vector_get(x,1); 486 a[2] = gsl_vector_get(x,2); 487 b[0] = gsl_vector_get(x,3); 488 b[1] = gsl_vector_get(x,4); 489 b[2] = gsl_vector_get(x,5); 498 490 // go through all atoms 499 491 while (ptr != par->mol->end) { -
src/molecule_graph.cpp
rf9352d r0a4f7f 17 17 #include "memoryallocator.hpp" 18 18 #include "molecule.hpp" 19 #include "Helpers/fast_functions.hpp" 19 20 20 21 struct BFSAccounting -
src/moleculelist.cpp
rf9352d r0a4f7f 681 681 for (int k = 0; k < NDIM; k++) { 682 682 j += k + 1; 683 BoxDimension .x[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);684 (*ListRunner)->cell_size[j] += BoxDimension .x[k] * 2.;683 BoxDimension[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem); 684 (*ListRunner)->cell_size[j] += BoxDimension[k] * 2.; 685 685 } 686 686 (*ListRunner)->Translate(&BoxDimension); … … 908 908 // center at set box dimensions 909 909 mol->CenterEdge(¢er); 910 mol->cell_size[0] = center .x[0];910 mol->cell_size[0] = center[0]; 911 911 mol->cell_size[1] = 0; 912 mol->cell_size[2] = center .x[1];912 mol->cell_size[2] = center[1]; 913 913 mol->cell_size[3] = 0; 914 914 mol->cell_size[4] = 0; 915 mol->cell_size[5] = center .x[2];915 mol->cell_size[5] = center[2]; 916 916 insert(mol); 917 917 } -
src/tesselation.cpp
rf9352d r0a4f7f 15 15 #include "tesselationhelpers.hpp" 16 16 #include "vector.hpp" 17 #include "vector_ops.hpp" 17 18 #include "verbose.hpp" 19 #include "Plane.hpp" 20 #include "Exceptions/LinearDependenceException.hpp" 18 21 19 22 class molecule; … … 258 261 helper[i].CopyVector(node->node->node); 259 262 helper[i].SubtractVector(&BaseLineCenter); 260 helper[i].MakeNormal Vector(&BaseLine); // we want to compare the triangle's heights' angles!263 helper[i].MakeNormalTo(BaseLine); // we want to compare the triangle's heights' angles! 261 264 //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl; 262 265 i++; … … 402 405 Info FunctionInfo(__func__); 403 406 // get normal vector 404 NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node); 407 NormalVector = Plane(*(endpoints[0]->node->node), 408 *(endpoints[1]->node->node), 409 *(endpoints[2]->node->node)).getNormal(); 405 410 406 411 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) … … 428 433 Vector helper; 429 434 430 if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) { 435 try { 436 *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x); 437 } 438 catch (LinearDependenceException &excp) { 439 Log() << Verbose(1) << excp; 431 440 eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl; 432 441 return false; … … 450 459 int i=0; 451 460 do { 452 if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection, &NormalVector)) { 461 try { 462 CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node), 463 *(endpoints[(i+1)%3]->node->node), 464 *(endpoints[(i+2)%3]->node->node), 465 *Intersection); 453 466 helper.CopyVector(endpoints[(i+1)%3]->node->node); 454 467 helper.SubtractVector(endpoints[i%3]->node->node); … … 462 475 } 463 476 i++; 464 } else477 } catch (LinearDependenceException &excp){ 465 478 break; 479 } 466 480 } while (i<3); 467 481 if (i==3) { … … 492 506 Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl; 493 507 GetCenter(&Direction); 494 if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) { 508 try { 509 *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction); 510 } 511 catch (LinearDependenceException &excp) { 495 512 ClosestPoint->CopyVector(x); 496 513 } … … 518 535 Direction.SubtractVector(endpoints[i%3]->node->node); 519 536 // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal); 520 CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node); 537 538 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 539 521 540 CrossDirection[i].CopyVector(&CrossPoint[i]); 522 541 CrossDirection[i].SubtractVector(&InPlane); … … 731 750 int counter=0; 732 751 for (; Runner[2] != endpoints.end(); ) { 733 TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node); 752 TemporaryNormal = Plane(*((*Runner[0])->node->node), 753 *((*Runner[1])->node->node), 754 *((*Runner[2])->node->node)).getNormal(); 734 755 for (int i=0;i<3;i++) // increase each of them 735 756 Runner[i]++; … … 1220 1241 // 2. next, we have to check whether all points reside on only one side of the triangle 1221 1242 // 3. construct plane vector 1222 PlaneVector .MakeNormalVector(A->second->node->node,1223 baseline->second.first->second->node->node,1224 baseline->second.second->second->node->node);1243 PlaneVector = Plane(*(A->second->node->node), 1244 *(baseline->second.first->second->node->node), 1245 *(baseline->second.second->second->node->node)).getNormal(); 1225 1246 Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl; 1226 1247 // 4. loop over all points … … 1391 1412 // vector in propagation direction (out of triangle) 1392 1413 // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection) 1393 PropagationVector .MakeNormalVector(&BaseLine, &NormalVector);1414 PropagationVector = Plane(BaseLine, NormalVector,0).getNormal(); 1394 1415 TempVector.CopyVector(&CenterVector); 1395 1416 TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! … … 1448 1469 // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle 1449 1470 flag = true; 1450 VirtualNormalVector.MakeNormalVector(baseline->second->endpoints[0]->node->node, baseline->second->endpoints[1]->node->node, target->second->node->node); 1471 VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node), 1472 *(baseline->second->endpoints[1]->node->node), 1473 *(target->second->node->node)).getNormal(); 1451 1474 TempVector.CopyVector(baseline->second->endpoints[0]->node->node); 1452 1475 TempVector.AddVector(baseline->second->endpoints[1]->node->node); … … 2063 2086 if (List != NULL) { 2064 2087 for (LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) { 2065 if ((*Runner)->node-> x[i]> maxCoordinate[i]) {2088 if ((*Runner)->node->at(i) > maxCoordinate[i]) { 2066 2089 Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl; 2067 maxCoordinate[i] = (*Runner)->node-> x[i];2090 maxCoordinate[i] = (*Runner)->node->at(i); 2068 2091 MaxPoint[i] = (*Runner); 2069 2092 } … … 2083 2106 for (int k=0;k<NDIM;k++) { 2084 2107 NormalVector.Zero(); 2085 NormalVector .x[k] = 1.;2108 NormalVector[k] = 1.; 2086 2109 BaseLine.endpoints[0] = new BoundaryPointSet(MaxPoint[k]); 2087 2110 Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl; … … 2117 2140 2118 2141 // look in one direction of baseline for initial candidate 2119 SearchDirection .MakeNormalVector(&CirclePlaneNormal, &NormalVector); // whether we look "left" first or "right" first is not important ...2142 SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal(); // whether we look "left" first or "right" first is not important ... 2120 2143 2121 2144 // adding point 1 and point 2 and add the line between them … … 2336 2359 2337 2360 // construct SearchDirection and an "outward pointer" 2338 SearchDirection .MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);2361 SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal(); 2339 2362 helper.CopyVector(&CircleCenter); 2340 2363 helper.SubtractVector(ThirdNode->node); … … 2979 3002 Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl; 2980 3003 2981 if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) 2982 && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON) 2983 ) { 3004 try { 3005 NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node), 3006 *(CandidateLine.BaseLine->endpoints[1]->node->node), 3007 *(Candidate->node)).getNormal(); 3008 3009 if(!fabs(NewNormalVector.NormSquared()) > HULLEPSILON) 3010 throw LinearDependenceException(__FILE__,__LINE__); 3011 2984 3012 Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl; 2985 3013 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter); … … 3043 3071 Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl; 3044 3072 } 3045 } else { 3073 } 3074 catch (LinearDependenceException &excp){ 3075 Log() << Verbose(1) << excp; 3046 3076 Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl; 3047 3077 } … … 3565 3595 Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl; 3566 3596 if (AngleZero.NormSquared() > MYEPSILON) 3567 OrthogonalVector .MakeNormalVector(&PlaneNormal, &AngleZero);3597 OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal(); 3568 3598 else 3569 OrthogonalVector.MakeNormal Vector(&PlaneNormal);3599 OrthogonalVector.MakeNormalTo(PlaneNormal); 3570 3600 Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl; 3571 3601 … … 3633 3663 int counter = 0; 3634 3664 while (TesselC != SetOfNeighbours->end()) { 3635 helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node); 3665 helper = Plane(*((*TesselA)->node), 3666 *((*TesselB)->node), 3667 *((*TesselC)->node)).getNormal(); 3636 3668 Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl; 3637 3669 counter++; … … 3670 3702 Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl; 3671 3703 if (AngleZero.NormSquared() > MYEPSILON) 3672 OrthogonalVector .MakeNormalVector(&PlaneNormal, &AngleZero);3704 OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal(); 3673 3705 else 3674 OrthogonalVector.MakeNormal Vector(&PlaneNormal);3706 OrthogonalVector.MakeNormalTo(PlaneNormal); 3675 3707 Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl; 3676 3708 … … 4002 4034 OrthogonalVector.CopyVector((*MiddleNode)->node); 4003 4035 OrthogonalVector.SubtractVector(&OldPoint); 4004 OrthogonalVector.MakeNormal Vector(&Reference);4036 OrthogonalVector.MakeNormalTo(Reference); 4005 4037 angle = GetAngle(Point, Reference, OrthogonalVector); 4006 4038 //if (angle < M_PI) // no wrong-sided triangles, please? -
src/tesselationhelpers.cpp
rf9352d r0a4f7f 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 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;86 center->at(0) = 0.5 * m12/ m11; 87 center->at(1) = -0.5 * m13/ m11; 88 center->at(2) = 0.5 * m14/ m11; 88 89 89 90 if (fabs(a.Distance(center) - RADIUS) > MYEPSILON) … … 281 282 Vector SideA,SideB,HeightA, HeightB; 282 283 for (int i=0;i<NDIM;i++) 283 intersection .x[i] = gsl_vector_get(x, i);284 intersection[i] = gsl_vector_get(x, i); 284 285 285 286 SideA.CopyVector(&(I->x1)); … … 336 337 /* Starting point */ 337 338 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]);339 gsl_vector_set(x, 0, point1[0]); 340 gsl_vector_set(x, 1, point1[1]); 341 gsl_vector_set(x, 2, point1[2]); 341 342 342 343 /* Set initial step sizes to 1 */ … … 372 373 double t1, t2; 373 374 for (int i = 0; i < NDIM; i++) { 374 intersection .x[i] = gsl_vector_get(s->x, i);375 intersection[i] = gsl_vector_get(s->x, i); 375 376 } 376 377 … … 700 701 // calculate the intersection between this projected baseline and Base 701 702 Vector *Intersection = new Vector; 702 Intersection->GetIntersectionOfTwoLinesOnPlane(Base->endpoints[0]->node->node, Base->endpoints[1]->node->node, &NewOffset, &NewDirection, &Normal); 703 *Intersection = GetIntersectionOfTwoLinesOnPlane(*(Base->endpoints[0]->node->node), 704 *(Base->endpoints[1]->node->node), 705 NewOffset, NewDirection); 703 706 Normal.CopyVector(Intersection); 704 707 Normal.SubtractVector(Base->endpoints[0]->node->node); … … 747 750 *vrmlfile << "Sphere {" << endl << " "; // 2 is sphere type 748 751 for (i=0;i<NDIM;i++) 749 *vrmlfile << Walker->node-> x[i]-center->x[i]<< " ";752 *vrmlfile << Walker->node->at(i)-center->at(i) << " "; 750 753 *vrmlfile << "\t0.1\t1. 1. 1." << endl; // radius 0.05 and white as colour 751 754 cloud->GoToNext(); … … 757 760 for (i=0;i<3;i++) { // print each node 758 761 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]<< " ";762 *vrmlfile << TriangleRunner->second->endpoints[i]->node->node->at(j)-center->at(j) << " "; 760 763 *vrmlfile << "\t"; 761 764 } … … 792 795 *rasterfile << "# current virtual sphere\n"; 793 796 *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";797 *rasterfile << "2\n " << helper[0] << " " << helper[1] << " " << helper[2] << "\t" << 5. << "\t1 0 0\n"; 795 798 *rasterfile << "9\n terminating special property\n"; 796 799 delete(center); … … 820 823 *rasterfile << "2" << endl << " "; // 2 is sphere type 821 824 for (i=0;i<NDIM;i++) 822 *rasterfile << Walker->node-> x[i]-center->x[i]<< " ";825 *rasterfile << Walker->node->at(i)-center->at(i) << " "; 823 826 *rasterfile << "\t0.1\t1. 1. 1." << endl; // radius 0.05 and white as colour 824 827 cloud->GoToNext(); … … 831 834 for (i=0;i<3;i++) { // print each node 832 835 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]<< " ";836 *rasterfile << TriangleRunner->second->endpoints[i]->node->node->at(j)-center->at(j) << " "; 834 837 *rasterfile << "\t"; 835 838 } … … 877 880 Walker = target->second->node; 878 881 LookupList[Walker->nr] = Counter++; 879 *tecplot << Walker->node-> x[0] << " " << Walker->node->x[1] << " " << Walker->node->x[2]<< " " << target->second->value << endl;882 *tecplot << Walker->node->at(0) << " " << Walker->node->at(1) << " " << Walker->node->at(2) << " " << target->second->value << endl; 880 883 } 881 884 *tecplot << endl; -
src/unittests/ActOnAllUnitTest.cpp
rf9352d r0a4f7f 99 99 }; 100 100 101 #if 0 102 103 // Unitttest deactivated for now... 104 // Reasons: 105 // Vector::MakeNormalVector has been removed and is now part of Plane class 106 // VectorList::ActOnAll is in the test directory and seems to be used only for unittests 107 // MakeNormal never depended on the input Vector except in the case of linear dependence (i.e. failure) 108 // 109 // TODO: Rethink what exactely is being tested at this point and introduce a new unittest for the 110 // tested behaviour. Most likely this should result in a thourough unittest of the plane class 111 101 112 /** UnitTest for VectorList::ActOnAll() and Vector::MakeNormalVector() 102 113 */ … … 113 124 // check that x and y components are zero 114 125 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. );126 CPPUNIT_ASSERT_EQUAL( (*Runner)->at(0) , 0. ); 127 CPPUNIT_ASSERT_EQUAL( (*Runner)->at(1) , 0. ); 117 128 } 118 129 }; 130 131 #endif -
src/unittests/ActOnAllUnitTest.hpp
rf9352d r0a4f7f 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/vectorunittest.cpp
rf9352d r0a4f7f 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 … … 195 198 { 196 199 // 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) );200 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unit, zero).GetIntersection(zero, two) ); 198 201 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 199 202 200 203 // 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) );204 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(otherunit, two).GetIntersection( unit, notunit) ); 202 205 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture ); 203 206 204 207 // four vectors equal to zero 205 CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&zero, &zero, &zero, &zero, NULL) ); 208 CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(zero, zero, zero, zero), LinearDependenceException); 209 //CPPUNIT_ASSERT_EQUAL( zero, fixture ); 210 211 // four vectors equal to unit 212 CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, unit, unit, unit), LinearDependenceException); 213 //CPPUNIT_ASSERT_EQUAL( zero, fixture ); 214 215 // two equal lines 216 CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, two)); 217 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 218 219 // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ??? 220 CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, otherunit) ); 221 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 222 223 // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 224 CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, zero, zero, two) ); 206 225 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 207 226 208 // four vectors equal to unit 209 CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &unit, &unit, &unit, NULL) ); 227 // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ??? 228 CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, zero, otherunit) ); 229 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture ); 230 }; 231 232 /** UnitTest for vector rotations. 233 */ 234 void VectorTest::VectorRotationTest() 235 { 236 fixture.Init(-1.,0.,0.); 237 238 // zero vector does not change 239 fixture = RotateVector(zero,unit, 1.); 210 240 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 211 241 212 // two equal lines 213 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &unit, &two, NULL) ); 242 fixture = RotateVector(zero, two, 1.); 243 CPPUNIT_ASSERT_EQUAL( zero, fixture); 244 245 // vector on axis does not change 246 fixture = RotateVector(unit,unit, 1.); 214 247 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 215 248 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 249 // rotations 252 fixture.CopyVector(&otherunit); 253 fixture.RotateVector(&unit, M_PI); 250 fixture = RotateVector(otherunit, unit, M_PI); 254 251 CPPUNIT_ASSERT_EQUAL( Vector(0.,-1.,0.), fixture ); 255 252 256 fixture.CopyVector(&otherunit); 257 fixture.RotateVector(&unit, 2. * M_PI); 253 fixture = RotateVector(otherunit, unit, 2. * M_PI); 258 254 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 259 255 260 fixture.CopyVector(&otherunit); 261 fixture.RotateVector(&unit, 0); 256 fixture = RotateVector(otherunit,unit, 0); 262 257 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 263 258 264 fixture.Init(0.,0.,1.); 265 fixture.RotateVector(¬unit, M_PI); 259 fixture = RotateVector(Vector(0.,0.,1.), notunit, M_PI); 266 260 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 267 261 } -
src/vector.cpp
rf9352d r0a4f7f 7 7 8 8 #include "defs.hpp" 9 #include "helpers.hpp"10 #include "info.hpp"11 9 #include "gslmatrix.hpp" 12 10 #include "leastsquaremin.hpp" 13 #include "log.hpp"14 11 #include "memoryallocator.hpp" 15 12 #include "vector.hpp" 16 #include "verbose.hpp" 13 #include "Helpers/fast_functions.hpp" 14 #include "Helpers/Assert.hpp" 15 #include "Plane.hpp" 16 #include "Exceptions/LinearDependenceException.hpp" 17 17 18 18 #include <gsl/gsl_linalg.h> … … 25 25 /** Constructor of class vector. 26 26 */ 27 Vector::Vector() { x[0] = x[1] = x[2] = 0.; }; 27 Vector::Vector() 28 { 29 x[0] = x[1] = x[2] = 0.; 30 }; 28 31 29 32 /** Constructor of class vector. 30 33 */ 31 Vector::Vector(const double x1, const double x2, const double x3) { x[0] = x1; x[1] = x2; x[2] = x3; }; 34 Vector::Vector(const double x1, const double x2, const double x3) 35 { 36 x[0] = x1; 37 x[1] = x2; 38 x[2] = x3; 39 }; 40 41 /** 42 * Copy constructor 43 */ 44 Vector::Vector(const Vector& src) 45 { 46 x[0] = src[0]; 47 x[1] = src[1]; 48 x[2] = src[2]; 49 } 50 51 /** 52 * Assignment operator 53 */ 54 Vector& Vector::operator=(const Vector& src){ 55 // check for self assignment 56 if(&src!=this){ 57 x[0] = src[0]; 58 x[1] = src[1]; 59 x[2] = src[2]; 60 } 61 return *this; 62 } 32 63 33 64 /** Desctructor of class vector. … … 208 239 }; 209 240 210 /** Calculates the intersection point between a line defined by \a *LineVector and \a *LineVector2 and a plane defined by \a *Normal and \a *PlaneOffset.211 * According to [Bronstein] the vectorial plane equation is:212 * -# \f$\stackrel{r}{\rightarrow} \cdot \stackrel{N}{\rightarrow} + D = 0\f$,213 * where \f$\stackrel{r}{\rightarrow}\f$ is the vector to be testet, \f$\stackrel{N}{\rightarrow}\f$ is the plane's normal vector and214 * \f$D = - \stackrel{a}{\rightarrow} \stackrel{N}{\rightarrow}\f$, the offset with respect to origin, if \f$\stackrel{a}{\rightarrow}\f$,215 * is an offset vector onto the plane. The line is parametrized by \f$\stackrel{x}{\rightarrow} + k \stackrel{t}{\rightarrow}\f$, where216 * \f$\stackrel{x}{\rightarrow}\f$ is the offset and \f$\stackrel{t}{\rightarrow}\f$ the directional vector (NOTE: No need to normalize217 * the latter). Inserting the parametrized form into the plane equation and solving for \f$k\f$, which we insert then into the parametrization218 * of the line yields the intersection point on the plane.219 * \param *out output stream for debugging220 * \param *PlaneNormal Plane's normal vector221 * \param *PlaneOffset Plane's offset vector222 * \param *Origin first vector of line223 * \param *LineVector second vector of line224 * \return true - \a this contains intersection point on return, false - line is parallel to plane (even if in-plane)225 */226 bool Vector::GetIntersectionWithPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset, const Vector * const Origin, const Vector * const LineVector)227 {228 Info FunctionInfo(__func__);229 double factor;230 Vector Direction, helper;231 232 // find intersection of a line defined by Offset and Direction with a plane defined by triangle233 Direction.CopyVector(LineVector);234 Direction.SubtractVector(Origin);235 Direction.Normalize();236 Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl;237 //Log() << Verbose(1) << "INFO: PlaneNormal is " << *PlaneNormal << " and PlaneOffset is " << *PlaneOffset << "." << endl;238 factor = Direction.ScalarProduct(PlaneNormal);239 if (fabs(factor) < MYEPSILON) { // Uniqueness: line parallel to plane?240 Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl;241 return false;242 }243 helper.CopyVector(PlaneOffset);244 helper.SubtractVector(Origin);245 factor = helper.ScalarProduct(PlaneNormal)/factor;246 if (fabs(factor) < MYEPSILON) { // Origin is in-plane247 Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl;248 CopyVector(Origin);249 return true;250 }251 //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal));252 Direction.Scale(factor);253 CopyVector(Origin);254 Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl;255 AddVector(&Direction);256 257 // test whether resulting vector really is on plane258 helper.CopyVector(this);259 helper.SubtractVector(PlaneOffset);260 if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) {261 Log() << Verbose(1) << "GOOD: Intersection is " << *this << "." << endl;262 return true;263 } else {264 eLog() << Verbose(2) << "Intersection point " << *this << " is not on plane." << endl;265 return false;266 }267 };268 269 241 /** Calculates the minimum distance of this vector to the plane. 270 242 * \param *out output stream for debugging … … 280 252 temp.CopyVector(this); 281 253 temp.SubtractVector(PlaneOffset); 282 temp.MakeNormal Vector(PlaneNormal);254 temp.MakeNormalTo(*PlaneNormal); 283 255 temp.Scale(-1.); 284 256 // then add connecting vector from plane to point … … 292 264 293 265 return (temp.Norm()*sign); 294 };295 296 /** Calculates the intersection of the two lines that are both on the same plane.297 * This is taken from Weisstein, Eric W. "Line-Line Intersection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineIntersection.html298 * \param *out output stream for debugging299 * \param *Line1a first vector of first line300 * \param *Line1b second vector of first line301 * \param *Line2a first vector of second line302 * \param *Line2b second vector of second line303 * \param *PlaneNormal normal of plane, is supplemental/arbitrary304 * \return true - \a this will contain the intersection on return, false - lines are parallel305 */306 bool Vector::GetIntersectionOfTwoLinesOnPlane(const Vector * const Line1a, const Vector * const Line1b, const Vector * const Line2a, const Vector * const Line2b, const Vector *PlaneNormal)307 {308 Info FunctionInfo(__func__);309 310 GSLMatrix *M = new GSLMatrix(4,4);311 312 M->SetAll(1.);313 for (int i=0;i<3;i++) {314 M->Set(0, i, Line1a->x[i]);315 M->Set(1, i, Line1b->x[i]);316 M->Set(2, i, Line2a->x[i]);317 M->Set(3, i, Line2b->x[i]);318 }319 320 //Log() << Verbose(1) << "Coefficent matrix is:" << endl;321 //for (int i=0;i<4;i++) {322 // for (int j=0;j<4;j++)323 // cout << "\t" << M->Get(i,j);324 // cout << endl;325 //}326 if (fabs(M->Determinant()) > MYEPSILON) {327 Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl;328 return false;329 }330 delete(M);331 Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl;332 333 334 // constuct a,b,c335 Vector a;336 Vector b;337 Vector c;338 Vector d;339 a.CopyVector(Line1b);340 a.SubtractVector(Line1a);341 b.CopyVector(Line2b);342 b.SubtractVector(Line2a);343 c.CopyVector(Line2a);344 c.SubtractVector(Line1a);345 d.CopyVector(Line2b);346 d.SubtractVector(Line1b);347 Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl;348 if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) {349 Zero();350 Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl;351 return false;352 }353 354 // check for parallelity355 Vector parallel;356 double factor = 0.;357 if (fabs(a.ScalarProduct(&b)*a.ScalarProduct(&b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) {358 parallel.CopyVector(Line1a);359 parallel.SubtractVector(Line2a);360 factor = parallel.ScalarProduct(&a)/a.Norm();361 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {362 CopyVector(Line2a);363 Log() << Verbose(1) << "Lines conincide." << endl;364 return true;365 } else {366 parallel.CopyVector(Line1a);367 parallel.SubtractVector(Line2b);368 factor = parallel.ScalarProduct(&a)/a.Norm();369 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {370 CopyVector(Line2b);371 Log() << Verbose(1) << "Lines conincide." << endl;372 return true;373 }374 }375 Log() << Verbose(1) << "Lines are parallel." << endl;376 Zero();377 return false;378 }379 380 // obtain s381 double s;382 Vector temp1, temp2;383 temp1.CopyVector(&c);384 temp1.VectorProduct(&b);385 temp2.CopyVector(&a);386 temp2.VectorProduct(&b);387 Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl;388 if (fabs(temp2.NormSquared()) > MYEPSILON)389 s = temp1.ScalarProduct(&temp2)/temp2.NormSquared();390 else391 s = 0.;392 Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(&temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl;393 394 // construct intersection395 CopyVector(&a);396 Scale(s);397 AddVector(Line1a);398 Log() << Verbose(1) << "Intersection is at " << *this << "." << endl;399 400 return true;401 266 }; 402 267 … … 538 403 }; 539 404 540 /** Rotates the vector relative to the origin around the axis given by \a *axis by an angle of \a alpha. 541 * \param *axis rotation axis 542 * \param alpha rotation angle in radian 543 */ 544 void Vector::RotateVector(const Vector * const axis, const double alpha) 545 { 546 Vector a,y; 547 // normalise this vector with respect to axis 548 a.CopyVector(this); 549 a.ProjectOntoPlane(axis); 550 // construct normal vector 551 bool rotatable = y.MakeNormalVector(axis,&a); 552 // The normal vector cannot be created if there is linar dependency. 553 // Then the vector to rotate is on the axis and any rotation leads to the vector itself. 554 if (!rotatable) { 555 return; 556 } 557 y.Scale(Norm()); 558 // scale normal vector by sine and this vector by cosine 559 y.Scale(sin(alpha)); 560 a.Scale(cos(alpha)); 561 CopyVector(Projection(axis)); 562 // add scaled normal vector onto this vector 563 AddVector(&y); 564 // add part in axis direction 565 AddVector(&a); 566 }; 405 406 double& Vector::operator[](size_t i){ 407 ASSERT(i<=NDIM && i>=0,"Vector Index out of Range"); 408 return x[i]; 409 } 410 411 const double& Vector::operator[](size_t i) const{ 412 ASSERT(i<=NDIM && i>=0,"Vector Index out of Range"); 413 return x[i]; 414 } 415 416 double& Vector::at(size_t i){ 417 return (*this)[i]; 418 } 419 420 const double& Vector::at(size_t i) const{ 421 return (*this)[i]; 422 } 423 424 double* Vector::get(){ 425 return x; 426 } 567 427 568 428 /** Compares vector \a to vector \a b component-wise. … … 575 435 bool status = true; 576 436 for (int i=0;i<NDIM;i++) 577 status = status && (fabs(a .x[i] - b.x[i]) < MYEPSILON);437 status = status && (fabs(a[i] - b[i]) < MYEPSILON); 578 438 return status; 579 439 }; … … 660 520 }; 661 521 662 /** Prints a 3dim vector.663 * prints no end of line.664 */665 void Vector::Output() const666 {667 Log() << Verbose(0) << "(";668 for (int i=0;i<NDIM;i++) {669 Log() << Verbose(0) << x[i];670 if (i != 2)671 Log() << Verbose(0) << ",";672 }673 Log() << Verbose(0) << ")";674 };675 676 522 ostream& operator<<(ostream& ost, const Vector& m) 677 523 { 678 524 ost << "("; 679 525 for (int i=0;i<NDIM;i++) { 680 ost << m .x[i];526 ost << m[i]; 681 527 if (i != 2) 682 528 ost << ","; … … 752 598 * \param *matrix NDIM_NDIM array 753 599 */ 754 voidVector::InverseMatrixMultiplication(const double * const A)600 bool Vector::InverseMatrixMultiplication(const double * const A) 755 601 { 756 602 Vector C; … … 779 625 for (int i=NDIM;i--;) 780 626 x[i] = C.x[i]; 627 return true; 781 628 } else { 782 eLog() << Verbose(1) << "inverse of matrix does not exists: det A = " << detA << "." << endl;629 return false; 783 630 } 784 631 }; … … 806 653 projection = ScalarProduct(n)/n->ScalarProduct(n); // remove constancy from n (keep as logical one) 807 654 // withdraw projected vector twice from original one 808 Log() << Verbose(1) << "Vector: ";809 Output();810 Log() << Verbose(0) << "\t";811 655 for (int i=NDIM;i--;) 812 656 x[i] -= 2.*projection*n->x[i]; 813 Log() << Verbose(0) << "Projected vector: "; 814 Output(); 815 Log() << Verbose(0) << endl; 816 }; 817 818 /** Calculates normal vector for three given vectors (being three points in space). 819 * Makes this vector orthonormal to the three given points, making up a place in 3d space. 820 * \param *y1 first vector 821 * \param *y2 second vector 822 * \param *y3 third vector 823 * \return true - success, vectors are linear independent, false - failure due to linear dependency 824 */ 825 bool Vector::MakeNormalVector(const Vector * const y1, const Vector * const y2, const Vector * const y3) 826 { 827 Vector x1, x2; 828 829 x1.CopyVector(y1); 830 x1.SubtractVector(y2); 831 x2.CopyVector(y3); 832 x2.SubtractVector(y2); 833 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) { 834 eLog() << Verbose(2) << "Given vectors are linear dependent." << endl; 835 return false; 836 } 837 // Log() << Verbose(4) << "relative, first plane coordinates:"; 838 // x1.Output((ofstream *)&cout); 839 // Log() << Verbose(0) << endl; 840 // Log() << Verbose(4) << "second plane coordinates:"; 841 // x2.Output((ofstream *)&cout); 842 // Log() << Verbose(0) << endl; 843 844 this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]); 845 this->x[1] = (x1.x[2]*x2.x[0] - x1.x[0]*x2.x[2]); 846 this->x[2] = (x1.x[0]*x2.x[1] - x1.x[1]*x2.x[0]); 847 Normalize(); 848 849 return true; 850 }; 851 852 853 /** Calculates orthonormal vector to two given vectors. 854 * Makes this vector orthonormal to two given vectors. This is very similar to the other 855 * vector::MakeNormalVector(), only there three points whereas here two difference 856 * vectors are given. 857 * \param *x1 first vector 858 * \param *x2 second vector 859 * \return true - success, vectors are linear independent, false - failure due to linear dependency 860 */ 861 bool Vector::MakeNormalVector(const Vector * const y1, const Vector * const y2) 862 { 863 Vector x1,x2; 864 x1.CopyVector(y1); 865 x2.CopyVector(y2); 866 Zero(); 867 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) { 868 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 /** Calculates orthonormal vector to one given vectors. 657 }; 658 659 660 /** Calculates orthonormal vector to one given vector. 887 661 * Just subtracts the projection onto the given vector from this vector. 888 662 * The removed part of the vector is Vector::Projection() … … 890 664 * \return true - success, false - vector is zero 891 665 */ 892 bool Vector::MakeNormal Vector(const Vector * consty1)666 bool Vector::MakeNormalTo(const Vector &y1) 893 667 { 894 668 bool result = false; 895 double factor = y1 ->ScalarProduct(this)/y1->NormSquared();669 double factor = y1.ScalarProduct(this)/y1.NormSquared(); 896 670 Vector x1; 897 x1.CopyVector( y1);671 x1.CopyVector(&y1); 898 672 x1.Scale(factor); 899 673 SubtractVector(&x1); … … 917 691 double norm; 918 692 919 Log() << Verbose(4);920 GivenVector->Output();921 Log() << Verbose(0) << endl;922 693 for (j=NDIM;j--;) 923 694 Components[j] = -1; … … 926 697 if (fabs(GivenVector->x[j]) > MYEPSILON) 927 698 Components[Last++] = j; 928 Log() << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl;929 699 930 700 switch(Last) { … … 966 736 }; 967 737 968 /** Creates a new vector as the one with least square distance to a given set of \a vectors.969 * \param *vectors set of vectors970 * \param num number of vectors971 * \return true if success, false if failed due to linear dependency972 */973 bool Vector::LSQdistance(const Vector **vectors, int num)974 {975 int j;976 977 for (j=0;j<num;j++) {978 Log() << Verbose(1) << j << "th atom's vector: ";979 (vectors[j])->Output();980 Log() << Verbose(0) << endl;981 }982 983 int np = 3;984 struct LSQ_params par;985 986 const gsl_multimin_fminimizer_type *T =987 gsl_multimin_fminimizer_nmsimplex;988 gsl_multimin_fminimizer *s = NULL;989 gsl_vector *ss, *y;990 gsl_multimin_function minex_func;991 992 size_t iter = 0, i;993 int status;994 double size;995 996 /* Initial vertex size vector */997 ss = gsl_vector_alloc (np);998 y = gsl_vector_alloc (np);999 1000 /* Set all step sizes to 1 */1001 gsl_vector_set_all (ss, 1.0);1002 1003 /* Starting point */1004 par.vectors = vectors;1005 par.num = num;1006 1007 for (i=NDIM;i--;)1008 gsl_vector_set(y, i, (vectors[0]->x[i] - vectors[1]->x[i])/2.);1009 1010 /* Initialize method and iterate */1011 minex_func.f = &LSQ;1012 minex_func.n = np;1013 minex_func.params = (void *)∥1014 1015 s = gsl_multimin_fminimizer_alloc (T, np);1016 gsl_multimin_fminimizer_set (s, &minex_func, y, ss);1017 1018 do1019 {1020 iter++;1021 status = gsl_multimin_fminimizer_iterate(s);1022 1023 if (status)1024 break;1025 1026 size = gsl_multimin_fminimizer_size (s);1027 status = gsl_multimin_test_size (size, 1e-2);1028 1029 if (status == GSL_SUCCESS)1030 {1031 printf ("converged to minimum at\n");1032 }1033 1034 printf ("%5d ", (int)iter);1035 for (i = 0; i < (size_t)np; i++)1036 {1037 printf ("%10.3e ", gsl_vector_get (s->x, i));1038 }1039 printf ("f() = %7.3f size = %.3f\n", s->fval, size);1040 }1041 while (status == GSL_CONTINUE && iter < 100);1042 1043 for (i=(size_t)np;i--;)1044 this->x[i] = gsl_vector_get(s->x, i);1045 gsl_vector_free(y);1046 gsl_vector_free(ss);1047 gsl_multimin_fminimizer_free (s);1048 1049 return true;1050 };1051 738 1052 739 /** Adds vector \a *y componentwise. … … 1092 779 } 1093 780 1094 1095 /** Asks for position, checks for boundary. 1096 * \param cell_size unitary size of cubic cell, coordinates must be within 0...cell_size 1097 * \param check whether bounds shall be checked (true) or not (false) 1098 */ 1099 void Vector::AskPosition(const double * const cell_size, const bool check) 1100 { 1101 char coords[3] = {'x','y','z'}; 1102 int j = -1; 1103 for (int i=0;i<3;i++) { 1104 j += i+1; 1105 do { 1106 Log() << Verbose(0) << coords[i] << "[0.." << cell_size[j] << "]: "; 1107 cin >> x[i]; 1108 } while (((x[i] < 0) || (x[i] >= cell_size[j])) && (check)); 1109 } 1110 }; 1111 781 // this function is completely unused so it is deactivated until new uses arrive and a new 782 // place can be found 783 #if 0 1112 784 /** Solves a vectorial system consisting of two orthogonal statements and a norm statement. 1113 785 * This is linear system of equations to be solved, however of the three given (skp of this vector\ … … 1281 953 }; 1282 954 955 #endif 956 1283 957 /** 1284 958 * Checks whether this vector is within the parallelepiped defined by the given three vectors and -
src/vector.hpp
rf9352d r0a4f7f 24 24 class Vector { 25 25 public: 26 double x[NDIM];27 26 28 27 Vector(); 29 28 Vector(const double x1, const double x2, const double x3); 29 Vector(const Vector& src); 30 30 ~Vector(); 31 31 … … 48 48 void CopyVector(const Vector * const y); 49 49 void CopyVector(const Vector &y); 50 void RotateVector(const Vector * const y, const double alpha);51 50 void VectorProduct(const Vector * const y); 52 51 void ProjectOntoPlane(const Vector * const y); … … 63 62 void Scale(const double factor); 64 63 void MatrixMultiplication(const double * const M); 65 voidInverseMatrixMultiplication(const double * const M);64 bool InverseMatrixMultiplication(const double * const M); 66 65 void KeepPeriodic(const double * const matrix); 67 66 void LinearCombinationOfVectors(const Vector * const x1, const Vector * const x2, const Vector * const x3, const double * const factors); 68 67 double CutsPlaneAt(const Vector * const A, const Vector * const B, const Vector * const C) const; 69 bool GetIntersectionWithPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset, const Vector * const Origin, const Vector * const LineVector);70 bool GetIntersectionOfTwoLinesOnPlane(const Vector * const Line1a, const Vector * const Line1b, const Vector * const Line2a, const Vector * const Line2b, const Vector *Normal = NULL);71 68 bool GetOneNormalVector(const Vector * const x1); 72 bool MakeNormalVector(const Vector * const y1); 73 bool MakeNormalVector(const Vector * const y1, const Vector * const y2); 74 bool MakeNormalVector(const Vector * const x1, const Vector * const x2, const Vector * const x3); 75 bool SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c); 76 bool LSQdistance(const Vector ** vectors, int dim); 77 void AskPosition(const double * const cell_size, const bool check); 78 void Output() const; 69 bool MakeNormalTo(const Vector &y1); 70 //bool SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c); 79 71 bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const; 80 72 void WrapPeriodically(const double * const M, const double * const Minv); 73 74 // Accessors ussually come in pairs... and sometimes even more than that 75 double& operator[](size_t i); 76 const double& operator[](size_t i) const; 77 double& at(size_t i); 78 const double& at(size_t i) const; 79 80 // Assignment operator 81 Vector &operator=(const Vector& src); 82 83 // Access to internal structure 84 double* get(); 85 86 private: 87 double x[NDIM]; 81 88 82 89 };
Note:
See TracChangeset
for help on using the changeset viewer.
