Changeset 8cbb97


Ignore:
Timestamp:
Apr 29, 2010, 1:55:21 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
d79639
Parents:
632bc3 (diff), 753f02 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'VectorRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Legacy/oldmenu.cpp
molecuilder/src/Makefile.am
molecuilder/src/analysis_correlation.cpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/ellipsoid.cpp
molecuilder/src/linkedcell.cpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/tesselationhelpers.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/vector.cpp
molecuilder/src/vector.hpp

Location:
src
Files:
9 added
45 edited

Legend:

Unmodified
Added
Removed
  • src/Legacy/oldmenu.cpp

    r632bc3 r8cbb97  
    2424#include "molecule.hpp"
    2525#include "periodentafel.hpp"
     26#include "vector_ops.hpp"
     27#include "Plane.hpp"
    2628
    2729#include "UIElements/UIFactory.hpp"
     
    5961  char choice;  // menu choice char
    6062  bool valid;
     63  bool aborted;
    6164
    6265  Log() << Verbose(0) << "===========ADD ATOM============================" << endl;
     
    7780      break;
    7881      case 'a': // absolute coordinates of atom
    79         Log() << Verbose(0) << "Enter absolute coordinates." << endl;
     82      {
     83        Dialog *dialog = UIFactory::getInstance().makeDialog();
    8084        first = World::getInstance().createAtom();
    81         first->x.AskPosition(World::getInstance().getDomain(), false);
    82         first->type = periode->AskElement();  // give type
    83         mol->AddAtom(first);  // add to molecule
     85        dialog->queryVector("Please enter coordinates: ",&first->x,World::getInstance().getDomain(), false);
     86        dialog->queryElement("Please choose element: ",&first->type);
     87        if(dialog->display()){
     88          mol->AddAtom(first);  // add to molecule
     89        }
     90        else{
     91          World::getInstance().destroyAtom(first);
     92        }
     93      }
     94      break;
     95
     96      case 'b': // relative coordinates of atom wrt to reference point
     97        first = World::getInstance().createAtom();
     98        valid = true;
     99        aborted = false;
     100        do {
     101          if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
     102          auto_ptr<Dialog> dialog(UIFactory::getInstance().makeDialog());
     103          dialog->queryVector("Enter reference coordinates.",&x,World::getInstance().getDomain(), true);
     104          dialog->queryVector("Enter relative coordinates.",&first->x,World::getInstance().getDomain(), false);
     105          if((aborted = !dialog->display())){
     106            continue;
     107          }
     108          first->x += x;
     109        } while (!aborted && !(valid = mol->CheckBounds((const Vector *)&first->x)));
     110        if(!aborted){
     111          first->type = periode->AskElement();  // give type
     112          mol->AddAtom(first);  // add to molecule
     113        }
     114        else{
     115          World::getInstance().destroyAtom(first);
     116        }
    84117        break;
    85118
    86       case 'b': // relative coordinates of atom wrt to reference point
     119      case 'c': // relative coordinates of atom wrt to already placed atom
     120      {
    87121        first = World::getInstance().createAtom();
    88122        valid = true;
    89123        do {
    90124          if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
    91           Log() << Verbose(0) << "Enter reference coordinates." << endl;
    92           x.AskPosition(World::getInstance().getDomain(), true);
    93           Log() << Verbose(0) << "Enter relative coordinates." << endl;
    94           first->x.AskPosition(World::getInstance().getDomain(), false);
    95           first->x.AddVector((const Vector *)&x);
    96           Log() << Verbose(0) << "\n";
    97         } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
    98         first->type = periode->AskElement();  // give type
    99         mol->AddAtom(first);  // add to molecule
    100         break;
    101 
    102       case 'c': // relative coordinates of atom wrt to already placed atom
    103         first = World::getInstance().createAtom();
    104         valid = true;
    105         do {
    106           if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
     125          auto_ptr<Dialog> dialog(UIFactory::getInstance().makeDialog());
    107126          second = mol->AskAtom("Enter atom number: ");
    108           Log() << Verbose(0) << "Enter relative coordinates." << endl;
    109           first->x.AskPosition(World::getInstance().getDomain(), false);
     127          dialog->queryVector("Enter relative coordinates.",&first->x,World::getInstance().getDomain(), false);
     128          dialog->display();
    110129          for (int i=NDIM;i--;) {
    111             first->x.x[i] += second->x.x[i];
     130            first->x[i] += second->x[i];
    112131          }
    113132        } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
    114133        first->type = periode->AskElement();  // give type
    115134        mol->AddAtom(first);  // add to molecule
    116         break;
     135      }
     136      break;
    117137
    118138    case 'd': // two atoms, two angles and a distance
     
    154174          */
    155175          // calc axis vector
    156           x.CopyVector(&second->x);
    157           x.SubtractVector(&third->x);
     176          x= second->x - third->x;
    158177          x.Normalize();
    159           Log() << Verbose(0) << "x: ",
    160           x.Output();
    161           Log() << Verbose(0) << endl;
    162           z.MakeNormalVector(&second->x,&third->x,&fourth->x);
    163           Log() << Verbose(0) << "z: ",
    164           z.Output();
    165           Log() << Verbose(0) << endl;
    166           y.MakeNormalVector(&x,&z);
    167           Log() << Verbose(0) << "y: ",
    168           y.Output();
    169           Log() << Verbose(0) << endl;
     178          Log() << Verbose(0) << "x: " << x << endl;
     179          z = Plane(second->x,third->x,fourth->x).getNormal();
     180          Log() << Verbose(0) << "z: " << z << endl;
     181          y = Plane(x,z,0).getNormal();
     182          Log() << Verbose(0) << "y: " << y << endl;
    170183
    171184          // rotate vector around first angle
    172           first->x.CopyVector(&x);
    173           first->x.RotateVector(&z,b - M_PI);
    174           Log() << Verbose(0) << "Rotated vector: ",
    175           first->x.Output();
    176           Log() << Verbose(0) << endl;
     185          first->x = x;
     186          first->x = RotateVector(first->x,z,b - M_PI);
     187          Log() << Verbose(0) << "Rotated vector: " << first->x << endl,
    177188          // remove the projection onto the rotation plane of the second angle
    178           n.CopyVector(&y);
    179           n.Scale(first->x.ScalarProduct(&y));
    180           Log() << Verbose(0) << "N1: ",
    181           n.Output();
    182           Log() << Verbose(0) << endl;
    183           first->x.SubtractVector(&n);
    184           Log() << Verbose(0) << "Subtracted vector: ",
    185           first->x.Output();
    186           Log() << Verbose(0) << endl;
    187           n.CopyVector(&z);
    188           n.Scale(first->x.ScalarProduct(&z));
    189           Log() << Verbose(0) << "N2: ",
    190           n.Output();
    191           Log() << Verbose(0) << endl;
    192           first->x.SubtractVector(&n);
    193           Log() << Verbose(0) << "2nd subtracted vector: ",
    194           first->x.Output();
    195           Log() << Verbose(0) << endl;
     189          n = y;
     190          n.Scale(first->x.ScalarProduct(y));
     191          Log() << Verbose(0) << "N1: " << n << endl;
     192          first->x -= n;
     193          Log() << Verbose(0) << "Subtracted vector: " << first->x << endl;
     194          n = z;
     195          n.Scale(first->x.ScalarProduct(z));
     196          Log() << Verbose(0) << "N2: " << n << endl;
     197          first->x -= n;
     198          Log() << Verbose(0) << "2nd subtracted vector: " << first->x << endl;
    196199
    197200          // rotate another vector around second angle
    198           n.CopyVector(&y);
    199           n.RotateVector(&x,c - M_PI);
    200           Log() << Verbose(0) << "2nd Rotated vector: ",
    201           n.Output();
    202           Log() << Verbose(0) << endl;
     201          n = y;
     202          n = RotateVector(n,x,c - M_PI);
     203          Log() << Verbose(0) << "2nd Rotated vector: " << n << endl;
    203204
    204205          // add the two linear independent vectors
    205           first->x.AddVector(&n);
     206          first->x += n;
    206207          first->x.Normalize();
    207208          first->x.Scale(a);
    208           first->x.AddVector(&second->x);
    209 
    210           Log() << Verbose(0) << "resulting coordinates: ";
    211           first->x.Output();
    212           Log() << Verbose(0) << endl;
     209          first->x += second->x;
     210
     211          Log() << Verbose(0) << "resulting coordinates: " << first->x << endl;
    213212        } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
    214213        first->type = periode->AskElement();  // give type
     
    233232        } while ((j != -1) && (i<128));
    234233        if (i >= 2) {
    235           first->x.LSQdistance((const Vector **)atoms, i);
    236 
    237           first->x.Output();
     234          LSQdistance(first->x,(const Vector **)atoms, i);
     235
     236          Log() << Verbose(0) << first->x;
    238237          first->type = periode->AskElement();  // give type
    239238          mol->AddAtom(first);  // add to molecule
     
    280279      for (int i=0;i<NDIM;i++) {
    281280        Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
    282         cin >> y.x[i];
     281        cin >> y[i];
    283282      }
    284283      mol->CenterEdge(&x);  // make every coordinate positive
    285       mol->Center.AddVector(&y); // translate by boundary
    286       helper.CopyVector(&y);
    287       helper.Scale(2.);
    288       helper.AddVector(&x);
     284      mol->Center += y; // translate by boundary
     285      helper = (2*y)+x;
    289286      mol->SetBoxDimension(&helper);  // update Box of atoms by boundary
    290287      break;
     
    293290      for (int i=0;i<NDIM;i++) {
    294291        Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
    295         cin >> x.x[i];
     292        cin >> x[i];
    296293      }
    297294      // update Box of atoms by boundary
     
    330327      third = mol->AskAtom("Enter third atom: ");
    331328
    332       n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
     329      n = Plane(first->x,second->x,third->x).getNormal();
    333330      break;
    334331    case 'b': // normal vector of mirror plane
    335       Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl;
    336       n.AskPosition(World::getInstance().getDomain(),0);
     332    {
     333      Dialog *dialog = UIFactory::getInstance().makeDialog();
     334      dialog->queryVector("Enter normal vector of mirror plane.",&n,World::getInstance().getDomain(),false);
     335      dialog->display();
     336      delete dialog;
    337337      n.Normalize();
    338       break;
     338    }
     339    break;
     340
    339341    case 'c': // three atoms defining mirror plane
    340342      first = mol->AskAtom("Enter first atom: ");
    341343      second = mol->AskAtom("Enter second atom: ");
    342344
    343       n.CopyVector((const Vector *)&first->x);
    344       n.SubtractVector((const Vector *)&second->x);
     345      n = first->x - second->x;
    345346      n.Normalize();
    346347      break;
     
    356357      mol->GetAlignvector(&param);
    357358      for (int i=NDIM;i--;) {
    358         x.x[i] = gsl_vector_get(param.x,i);
    359         n.x[i] = gsl_vector_get(param.x,i+NDIM);
     359        x[i] = gsl_vector_get(param.x,i);
     360        n[i] = gsl_vector_get(param.x,i+NDIM);
    360361      }
    361362      gsl_vector_free(param.x);
    362       Log() << Verbose(0) << "Offset vector: ";
    363       x.Output();
    364       Log() << Verbose(0) << endl;
     363      Log() << Verbose(0) << "Offset vector: " << x << endl;
    365364      n.Normalize();
    366365      break;
    367366  };
    368   Log() << Verbose(0) << "Alignment vector: ";
    369   n.Output();
    370   Log() << Verbose(0) << endl;
     367  Log() << Verbose(0) << "Alignment vector: " << n << endl;
    371368  mol->Align(&n);
    372369};
     
    397394      third = mol->AskAtom("Enter third atom: ");
    398395
    399       n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
     396      n = Plane(first->x,second->x,third->x).getNormal();
    400397      break;
    401398    case 'b': // normal vector of mirror plane
    402       Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl;
    403       n.AskPosition(World::getInstance().getDomain(),0);
     399    {
     400      Dialog *dialog = UIFactory::getInstance().makeDialog();
     401      dialog->queryVector("Enter normal vector of mirror plane.",&n,World::getInstance().getDomain(),false);
     402      dialog->display();
     403      delete dialog;
    404404      n.Normalize();
    405       break;
     405    }
     406    break;
     407
    406408    case 'c': // three atoms defining mirror plane
    407409      first = mol->AskAtom("Enter first atom: ");
    408410      second = mol->AskAtom("Enter second atom: ");
    409411
    410       n.CopyVector((const Vector *)&first->x);
    411       n.SubtractVector((const Vector *)&second->x);
     412      n = first->x - second->x;
    412413      n.Normalize();
    413414      break;
    414415  };
    415   Log() << Verbose(0) << "Normal vector: ";
    416   n.Output();
    417   Log() << Verbose(0) << endl;
     416  Log() << Verbose(0) << "Normal vector: " << n << endl;
    418417  mol->Mirror((const Vector *)&n);
    419418};
     
    455454        first = second;
    456455        second = first->next;
    457         if (first->x.DistanceSquared((const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
     456        if (first->x.DistanceSquared(second->x) > tmp1*tmp1) // distance to first above radius ...
    458457          mol->RemoveAtom(first);
    459458      }
     
    471470        first = second;
    472471        second = first->next;
    473         if ((first->x.x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ...
     472        if ((first->x[axis] < tmp1) || (first->x[axis] > tmp2)) {// out of boundary ...
    474473          //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl;
    475474          mol->RemoveAtom(first);
     
    522521        tmp1 = 0.;
    523522        if (first != second) {
    524           x.CopyVector((const Vector *)&first->x);
    525           x.SubtractVector((const Vector *)&second->x);
     523          x = first->x - second->x;
    526524          tmp1 = x.Norm();
    527525        }
     
    538536      for (int i=NDIM;i--;)
    539537        min[i] = 0.;
    540       x.CopyVector((const Vector *)&first->x);
    541       x.SubtractVector((const Vector *)&second->x);
     538      x = first->x - second->x;
    542539      tmp1 = x.Norm();
    543       Log() << Verbose(1) << "Distance vector is ";
    544       x.Output();
    545       Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
     540      Log() << Verbose(1) << "Distance vector is " << x << "." << "/n"
     541            << "Norm of distance is " << tmp1 << "." << endl;
    546542      break;
    547543
     
    552548      third  = mol->AskAtom("Enter last atom: ");
    553549      tmp1 = tmp2 = tmp3 = 0.;
    554       x.CopyVector((const Vector *)&first->x);
    555       x.SubtractVector((const Vector *)&second->x);
    556       y.CopyVector((const Vector *)&third->x);
    557       y.SubtractVector((const Vector *)&second->x);
     550      x = first->x - second->x;
     551      y = third->x - second->x;
    558552      Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
    559       Log() << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
     553      Log() << Verbose(0) << (acos(x.ScalarProduct(y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
    560554      break;
    561555    case 'd':
     
    676670        minBond = 0.;
    677671        for (int i=NDIM;i--;)
    678           minBond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
     672          minBond += (first->x[i]-second->x[i])*(first->x[i] - second->x[i]);
    679673        minBond = sqrt(minBond);
    680674        Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl;
     
    682676        cin >> bond;
    683677        for (int i=NDIM;i--;) {
    684           second->x.x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond);
     678          second->x[i] -= (second->x[i]-first->x[i])/minBond*(minBond-bond);
    685679        }
    686680        //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
     
    778772      x.Zero();
    779773      y.Zero();
    780       y.x[abs(axis)-1] = World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
     774      y[abs(axis)-1] = World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
    781775      for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
    782         x.AddVector(&y); // per factor one cell width further
     776        x += y; // per factor one cell width further
    783777        for (int k=count;k--;) { // go through every atom of the original cell
    784778          first = World::getInstance().createAtom(); // create a new body
    785           first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    786           first->x.AddVector(&x);     // translate the coordinates
     779          first->x = (*vectors[k]) + x;  // use coordinate of original atom
    787780          first->type = Elements[k];  // insert original element
    788781          mol->AddAtom(first);        // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
     
    796789      // correct cell size
    797790      if (axis < 0) { // if sign was negative, we have to translate everything
    798         x.Zero();
    799         x.AddVector(&y);
     791        x = y;
    800792        x.Scale(-(faktor-1));
    801793        mol->Translate(&x);
     
    893885        mol = *ListRunner;
    894886        Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
    895         Log() << Verbose(0) << "Enter translation vector." << endl;
    896         x.AskPosition(World::getInstance().getDomain(),0);
    897         mol->Center.AddVector((const Vector *)&x);
     887        Dialog *dialog = UIFactory::getInstance().makeDialog();
     888        dialog->queryVector("Enter translation vector.",&x,World::getInstance().getDomain(),false);
     889        if(dialog->display()){
     890          mol->Center += x;
     891        }
     892        delete dialog;
    898893     }
    899894     break;
  • src/Makefile.am

    r632bc3 r8cbb97  
     1# this includes source files that need to be present at multiple points
     2HELPERSOURCE =  Helpers/Assert.cpp \
     3                                Helpers/MemDebug.cpp
     4                       
    15ATOMSOURCE = 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
    26ATOMHEADER = 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
    37
    4 LINALGSOURCE = gslmatrix.cpp gslvector.cpp linearsystemofequations.cpp
    5 LINALGHEADER = gslmatrix.hpp gslvector.hpp linearsystemofequations.hpp
     8LINALGSOURCE = ${HELPERSOURCE} \
     9               gslmatrix.cpp \
     10                           gslvector.cpp \
     11                           linearsystemofequations.cpp \
     12                           vector.cpp
     13                           
     14LINALGHEADER = gslmatrix.hpp \
     15                           gslvector.hpp \
     16                           linearsystemofequations.hpp \
     17                           vector.hpp
     18                           
    619
    720ANALYSISSOURCE = analysis_bonds.cpp analysis_correlation.cpp
     
    7083
    7184
     85EXCEPTIONSOURCE = Exceptions/CustomException.cpp \
     86                                  Exceptions/LinearDependenceException.cpp
     87                                 
     88EXCEPTIONHEADER = Exceptions/CustomException.hpp \
     89                                  Exceptions/LinearDependenceException.hpp
     90
    7291SOURCE = ${ANALYSISSOURCE} \
    7392                 ${ATOMSOURCE} \
     
    7594                 ${UISOURCE} \
    7695                 ${DESCRIPTORSOURCE} \
     96                 ${HELPERSOURCE} \
    7797                 ${LEGACYSOURCE} \
     98                 ${EXCEPTIONSOURCE} \
    7899                 bond.cpp \
    79100                 bondgraph.cpp \
     
    85106                 graph.cpp \
    86107                 helpers.cpp \
    87                  Helpers/Assert.cpp \
    88                  Helpers/MemDebug.cpp \
    89108                 info.cpp \
    90109                 leastsquaremin.cpp \
     
    103122                 parser.cpp \
    104123                 periodentafel.cpp \
     124                 Plane.cpp \
    105125                 tesselation.cpp \
    106126                 tesselationhelpers.cpp \
    107127                 triangleintersectionlist.cpp \
    108                  vector.cpp \
    109128                 verbose.cpp \
     129                 vector_ops.cpp \
    110130                 World.cpp
    111131
    112132HEADER = \
    113   ${ANALYSISHEADER} \
    114   ${ATOMHEADER} \
    115   ${PATTERNHEADER} \
    116   ${UIHEADER} \
    117   ${DESCRIPTORHEADER} \
    118   ${LEGACYHEADER} \
    119   bond.hpp \
    120   bondgraph.hpp \
    121   boundary.hpp \
    122   config.hpp \
    123   defs.hpp \
    124   element.hpp \
    125   ellipsoid.hpp \
    126   errorlogger.hpp \
    127   graph.hpp \
    128   helpers.hpp \
    129   info.hpp \
    130   leastsquaremin.hpp \
    131   linkedcell.hpp \
    132   lists.hpp \
    133   log.hpp \
    134   logger.hpp \
    135   memoryallocator.hpp \
    136   memoryusageobserver.hpp \
    137   molecule.hpp \
    138   molecule_template.hpp \
    139   parser.hpp \
    140   periodentafel.hpp \
    141   stackclass.hpp \
    142   tesselation.hpp \
    143   tesselationhelpers.hpp \
    144   triangleintersectionlist.hpp \
    145   vector.hpp \
    146   verbose.hpp \
    147   World.hpp
     133          ${ANALYSISHEADER} \
     134          ${ATOMHEADER} \
     135          ${PATTERNHEADER} \
     136          ${UIHEADER} \
     137          ${DESCRIPTORHEADER} \
     138          ${EXCEPTIONHEADER} \
     139          ${LEGACYHEADER} \
     140          bond.hpp \
     141          bondgraph.hpp \
     142          boundary.hpp \
     143          config.hpp \
     144          defs.hpp \
     145          element.hpp \
     146          ellipsoid.hpp \
     147          errorlogger.hpp \
     148          graph.hpp \
     149          helpers.hpp \
     150          info.hpp \
     151          leastsquaremin.hpp \
     152          linkedcell.hpp \
     153          lists.hpp \
     154          log.hpp \
     155          logger.hpp \
     156          memoryallocator.hpp \
     157          memoryusageobserver.hpp \
     158          molecule.hpp \
     159          molecule_template.hpp \
     160          parser.hpp \
     161          periodentafel.hpp \
     162          Plane.hpp \
     163          stackclass.hpp \
     164          tesselation.hpp \
     165          tesselationhelpers.hpp \
     166          triangleintersectionlist.hpp \
     167          verbose.hpp \
     168          vector_ops.hpp \
     169          World.hpp
    148170
    149171BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB)
  • src/UIElements/TextDialog.cpp

    r632bc3 r8cbb97  
    154154
    155155bool TextDialog::VectorTextQuery::handle() {
    156  Log() << Verbose(0) << getTitle();
    157  tmp->AskPosition(cellSize,check);
    158  return true;
     156  Log() << Verbose(0) << getTitle();
     157
     158  char coords[3] = {'x','y','z'};
     159  int j = -1;
     160  for (int i=0;i<3;i++) {
     161    j += i+1;
     162    do {
     163      Log() << Verbose(0) << coords[i] << "[0.." << cellSize[j] << "]: ";
     164      cin >> (*tmp)[i];
     165    } while ((((*tmp)[i] < 0) || ((*tmp)[i] >= cellSize[j])) && (check));
     166  }
     167  return true;
    159168}
    160169
  • src/analysis_bonds.cpp

    r632bc3 r8cbb97  
    9393  Vector OOBond;
    9494
    95   OHBond.CopyVector(first);
    96   OHBond.SubtractVector(central);
    97   OOBond.CopyVector(second);
    98   OOBond.SubtractVector(central);
    99   const double angle = OHBond.Angle(&OOBond);
     95  OHBond = (*first) - (*central);
     96  OOBond = (*second) - (*central);
     97  const double angle = OHBond.Angle(OOBond);
    10098  return angle;
    10199};
     
    145143          if ((Walker->type->Z  == 8) && (Runner->type->Z  == 8)) {
    146144            // check distance
    147             const double distance = Runner->x.DistanceSquared(&Walker->x);
     145            const double distance = Runner->x.DistanceSquared(Walker->x);
    148146            if ((distance > MYEPSILON) && (distance < HBRIDGEDISTANCE*HBRIDGEDISTANCE)) { // distance >0 means  different atoms
    149147              // on other atom(Runner) we check for bond to interface element and
  • src/analysis_correlation.cpp

    r632bc3 r8cbb97  
    5757                if (Walker->nr < OtherWalker->nr)
    5858                  if ((type2 == NULL) || (OtherWalker->type == type2)) {
    59                     distance = Walker->node->PeriodicDistance(OtherWalker->node, World::getInstance().getDomain());
     59                    distance = Walker->node->PeriodicDistance(*OtherWalker->node, World::getInstance().getDomain());
    6060                    //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
    6161                    outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     
    106106        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    107107        if ((type1 == NULL) || (Walker->type == type1)) {
    108           periodicX.CopyVector(Walker->node);
     108          periodicX = *(Walker->node);
    109109          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    110110          // go through every range in xyz and get distance
     
    112112            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
    113113              for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
    114                 checkX.Init(n[0], n[1], n[2]);
    115                 checkX.AddVector(&periodicX);
     114                checkX = Vector(n[0], n[1], n[2]) + periodicX;
    116115                checkX.MatrixMultiplication(FullMatrix);
    117116                for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
     
    124123                      if (Walker->nr < OtherWalker->nr)
    125124                        if ((type2 == NULL) || (OtherWalker->type == type2)) {
    126                           periodicOtherX.CopyVector(OtherWalker->node);
     125                          periodicOtherX = *(OtherWalker->node);
    127126                          periodicOtherX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    128127                          // go through every range in xyz and get distance
     
    130129                            for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
    131130                              for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
    132                                 checkOtherX.Init(Othern[0], Othern[1], Othern[2]);
    133                                 checkOtherX.AddVector(&periodicOtherX);
     131                                checkOtherX = Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX;
    134132                                checkOtherX.MatrixMultiplication(FullMatrix);
    135                                 distance = checkX.Distance(&checkOtherX);
     133                                distance = checkX.Distance(checkOtherX);
    136134                                //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
    137135                                outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     
    176174        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    177175        if ((type == NULL) || (Walker->type == type)) {
    178           distance = Walker->node->PeriodicDistance(point, World::getInstance().getDomain());
     176          distance = Walker->node->PeriodicDistance(*point, World::getInstance().getDomain());
    179177          DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    180178          outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
     
    218216        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    219217        if ((type == NULL) || (Walker->type == type)) {
    220           periodicX.CopyVector(Walker->node);
     218          periodicX = *(Walker->node);
    221219          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    222220          // go through every range in xyz and get distance
     
    224222            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
    225223              for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
    226                 checkX.Init(n[0], n[1], n[2]);
    227                 checkX.AddVector(&periodicX);
     224                checkX = Vector(n[0], n[1], n[2]) + periodicX;
    228225                checkX.MatrixMultiplication(FullMatrix);
    229                 distance = checkX.Distance(point);
     226                distance = checkX.Distance(*point);
    230227                DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    231228                outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
     
    322319        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    323320        if ((type == NULL) || (Walker->type == type)) {
    324           periodicX.CopyVector(Walker->node);
     321          periodicX = *(Walker->node);
    325322          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    326323          // go through every range in xyz and get distance
     
    329326            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
    330327              for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
    331                 checkX.Init(n[0], n[1], n[2]);
    332                 checkX.AddVector(&periodicX);
     328                checkX = Vector(n[0], n[1], n[2]) + periodicX;
    333329                checkX.MatrixMultiplication(FullMatrix);
    334330                TriangleIntersectionList Intersections(&checkX,Surface,LC);
     
    402398    *file << runner->first;
    403399    for (int i=0;i<NDIM;i++)
    404       *file << "\t" << setprecision(8) << (runner->second.first->node->x[i] - runner->second.second->x[i]);
     400      *file << "\t" << setprecision(8) << (runner->second.first->node->at(i) - runner->second.second->at(i));
    405401    *file << endl;
    406402  }
  • src/atom.cpp

    r632bc3 r8cbb97  
    3333{
    3434  type = pointer->type;  // copy element of atom
    35   x.CopyVector(&pointer->x); // copy coordination
    36   v.CopyVector(&pointer->v); // copy velocity
     35  x = pointer->x; // copy coordination
     36  v = pointer->v; // copy velocity
    3737  FixedIon = pointer->FixedIon;
    3838  node = &x;
     
    4646  res->sort = &res->nr;
    4747  res->type = type;
    48   res->x.CopyVector(&this->x);
    49   res->v.CopyVector(&this->v);
     48  res->x = this->x;
     49  res->v = this->v;
    5050  res->FixedIon = FixedIon;
    5151  res->node = &x;
     
    130130  if (out != NULL) {
    131131    *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];
    133133    *out << "\t" << FixedIon;
    134134    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";
    136136    if (comment != NULL)
    137137      *out << " # " << comment << endl;
     
    155155  if (out != NULL) {
    156156    *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];
    158158    *out << "\t" << FixedIon;
    159159    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";
    161161    if (comment != NULL)
    162162      *out << " # " << comment << endl;
     
    175175{
    176176  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;
    178178    return true;
    179179  } else
     
    193193  if (out != NULL) {
    194194    *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];
    196196    *out << "\t" << FixedIon;
    197197    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";
    199199    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";
    201201    *out << "\t# Number in molecule " << nr << endl;
    202202    return true;
     
    214214  if (out != NULL) {
    215215    *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;
    219219    return true;
    220220  } else
     
    229229void atom::OutputMPQCLine(ofstream * const out, const Vector *center, int *AtomNo = NULL) const
    230230{
    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;
    232232  if (AtomNo != NULL)
    233233    *AtomNo++;
     
    252252double atom::DistanceSquaredToVector(const Vector &origin) const
    253253{
    254   return origin.DistanceSquared(&x);
     254  return origin.DistanceSquared(x);
    255255};
    256256
     
    261261double atom::DistanceToVector(const Vector &origin) const
    262262{
    263   return origin.Distance(&x);
     263  return origin.Distance(x);
    264264};
    265265
  • src/atom_trajectoryparticle.cpp

    r632bc3 r8cbb97  
    3434{
    3535  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];
    3737};
    3838
     
    4949  // set forces
    5050  for (int i=NDIM;i++;)
    51     Force->Matrix[0][nr][5+i] += 2.*constant*sqrt(Trajectory.R.at(startstep).Distance(&Sprinter->Trajectory.R.at(endstep)));
     51    Force->Matrix[0][nr][5+i] += 2.*constant*sqrt(Trajectory.R.at(startstep).Distance(Sprinter->Trajectory.R.at(endstep)));
    5252};
    5353
     
    6060{
    6161  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];
    6464  }
    6565};
     
    8989
    9090  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];
    9494  }
    9595};
     
    105105  //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
    106106  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^2
    110     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 =
    111111  }
    112112  // Update U
    113113  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 * t
     114    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
    116116  }
    117117  // Update R (and F)
     
    134134  *TotalMass += type->mass;  // sum up total mass
    135135  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;
    137137  }
    138138};
     
    145145void TrajectoryParticle::Thermostat_Woodcock(double ScaleTempFactor, int Step, double *ekin)
    146146{
    147   double *U = Trajectory.U.at(Step).x;
     147  Vector &U = Trajectory.U.at(Step);
    148148  if (FixedIon == 0) // even FixedIon moves, only not by other's forces
    149149    for (int d=0; d<NDIM; d++) {
     
    160160void TrajectoryParticle::Thermostat_Gaussian_init(int Step, double *G, double *E)
    161161{
    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);
    164164  if (FixedIon == 0) // even FixedIon moves, only not by other's forces
    165165    for (int d=0; d<NDIM; d++) {
     
    177177void TrajectoryParticle::Thermostat_Gaussian_least_constraint(int Step, double G_over_E, double *ekin, config *configuration)
    178178{
    179   double *U = Trajectory.U.at(Step).x;
     179  Vector &U = Trajectory.U.at(Step);
    180180  if (FixedIon == 0) // even FixedIon moves, only not by other's forces
    181181    for (int d=0; d<NDIM; d++) {
     
    194194{
    195195  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);
    197197  if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
    198198    // throw a dice to determine whether it gets hit by a heat bath particle
     
    218218void TrajectoryParticle::Thermostat_Berendsen(int Step, double ScaleTempFactor, double *ekin, config *configuration)
    219219{
    220   double *U = Trajectory.U.at(Step).x;
     220  Vector &U = Trajectory.U.at(Step);
    221221  if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
    222222    for (int d=0; d<NDIM; d++) {
     
    233233void TrajectoryParticle::Thermostat_NoseHoover_init(int Step, double *delta_alpha)
    234234{
    235   double *U = Trajectory.U.at(Step).x;
     235  Vector &U = Trajectory.U.at(Step);
    236236  if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
    237237    for (int d=0; d<NDIM; d++) {
     
    248248void TrajectoryParticle::Thermostat_NoseHoover_scale(int Step, double *ekin, config *configuration)
    249249{
    250   double *U = Trajectory.U.at(Step).x;
     250  Vector &U = Trajectory.U.at(Step);
    251251  if (FixedIon == 0) { // even FixedIon moves, only not by other's forces
    252252    for (int d=0; d<NDIM; d++) {
  • src/bond.cpp

    r632bc3 r8cbb97  
    119119double bond::GetDistance() const
    120120{
    121   return (leftatom->node->Distance(rightatom->node));
     121  return (leftatom->node->Distance(*rightatom->node));
    122122};
    123123
     
    127127double bond::GetDistanceSquared() const
    128128{
    129   return (leftatom->node->DistanceSquared(rightatom->node));
     129  return (leftatom->node->DistanceSquared(*rightatom->node));
    130130};
  • src/boundary.cpp

    r632bc3 r8cbb97  
    1919#include "tesselationhelpers.hpp"
    2020#include "World.hpp"
     21#include "Plane.hpp"
    2122
    2223#include<gsl/gsl_poly.h>
     
    7879              if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around
    7980                Neighbour = BoundaryPoints[axis].begin();
    80               DistanceVector.CopyVector(&runner->second.second->x);
    81               DistanceVector.SubtractVector(&Neighbour->second.second->x);
     81              DistanceVector = runner->second.second->x - Neighbour->second.second->x;
    8282              do { // seek for neighbour pair where it flips
    83                   OldComponent = DistanceVector.x[Othercomponent];
     83                  OldComponent = DistanceVector[Othercomponent];
    8484                  Neighbour++;
    8585                  if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around
    8686                    Neighbour = BoundaryPoints[axis].begin();
    87                   DistanceVector.CopyVector(&runner->second.second->x);
    88                   DistanceVector.SubtractVector(&Neighbour->second.second->x);
     87                  DistanceVector = runner->second.second->x - Neighbour->second.second->x;
    8988                  //Log() << Verbose(2) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl;
    9089                } while ((runner != Neighbour) && (fabs(OldComponent / fabs(
    91                   OldComponent) - DistanceVector.x[Othercomponent] / fabs(
    92                   DistanceVector.x[Othercomponent])) < MYEPSILON)); // as long as sign does not flip
     90                  OldComponent) - DistanceVector[Othercomponent] / fabs(
     91                  DistanceVector[Othercomponent])) < MYEPSILON)); // as long as sign does not flip
    9392              if (runner != Neighbour) {
    9493                  OtherNeighbour = Neighbour;
     
    9897                  //Log() << Verbose(1) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl;
    9998                  // now we have found the pair: Neighbour and OtherNeighbour
    100                   OtherVector.CopyVector(&runner->second.second->x);
    101                   OtherVector.SubtractVector(&OtherNeighbour->second.second->x);
     99                  OtherVector = runner->second.second->x - OtherNeighbour->second.second->x;
    102100                  //Log() << Verbose(1) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl;
    103101                  //Log() << Verbose(1) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl;
    104102                  // do linear interpolation between points (is exact) to extract exact intersection between Neighbour and OtherNeighbour
    105                   w1 = fabs(OtherVector.x[Othercomponent]);
    106                   w2 = fabs(DistanceVector.x[Othercomponent]);
    107                   tmp = fabs((w1 * DistanceVector.x[component] + w2
    108                       * OtherVector.x[component]) / (w1 + w2));
     103                  w1 = fabs(OtherVector[Othercomponent]);
     104                  w2 = fabs(DistanceVector[Othercomponent]);
     105                  tmp = fabs((w1 * DistanceVector[component] + w2
     106                      * OtherVector[component]) / (w1 + w2));
    109107                  // mark if it has greater diameter
    110108                  //Log() << Verbose(1) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl;
     
    160158    AngleReferenceVector.Zero();
    161159    AngleReferenceNormalVector.Zero();
    162     AxisVector.x[axis] = 1.;
    163     AngleReferenceVector.x[(axis + 1) % NDIM] = 1.;
    164     AngleReferenceNormalVector.x[(axis + 2) % NDIM] = 1.;
     160    AxisVector[axis] = 1.;
     161    AngleReferenceVector[(axis + 1) % NDIM] = 1.;
     162    AngleReferenceNormalVector[(axis + 2) % NDIM] = 1.;
    165163
    166164    DoLog(1) && (Log() << Verbose(1) << "Axisvector is " << AxisVector << " and AngleReferenceVector is " << AngleReferenceVector << ", and AngleReferenceNormalVector is " << AngleReferenceNormalVector << "." << endl);
     
    170168    while (Walker->next != mol->end) {
    171169      Walker = Walker->next;
    172       ProjectedVector.CopyVector(&Walker->x);
    173       ProjectedVector.SubtractVector(MolCenter);
    174       ProjectedVector.ProjectOntoPlane(&AxisVector);
     170      ProjectedVector = Walker->x - (*MolCenter);
     171      ProjectedVector.ProjectOntoPlane(AxisVector);
    175172
    176173      // correct for negative side
    177174      const double radius = ProjectedVector.NormSquared();
    178175      if (fabs(radius) > MYEPSILON)
    179         angle = ProjectedVector.Angle(&AngleReferenceVector);
     176        angle = ProjectedVector.Angle(AngleReferenceVector);
    180177      else
    181178        angle = 0.; // otherwise it's a vector in Axis Direction and unimportant for boundary issues
    182179
    183180      //Log() << Verbose(1) << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
    184       if (ProjectedVector.ScalarProduct(&AngleReferenceNormalVector) > 0) {
     181      if (ProjectedVector.ScalarProduct(AngleReferenceNormalVector) > 0) {
    185182        angle = 2. * M_PI - angle;
    186183      }
     
    197194          DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);
    198195        } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) {
    199           helper.CopyVector(&Walker->x);
    200           helper.SubtractVector(MolCenter);
     196          helper = Walker->x - (*MolCenter);
    201197          const double oldhelperNorm = helper.NormSquared();
    202           helper.CopyVector(&BoundaryTestPair.first->second.second->x);
    203           helper.SubtractVector(MolCenter);
     198          helper = BoundaryTestPair.first->second.second->x - (*MolCenter);
    204199          if (helper.NormSquared() < oldhelperNorm) {
    205200            BoundaryTestPair.first->second.second = Walker;
     
    251246        {
    252247          Vector SideA, SideB, SideC, SideH;
    253           SideA.CopyVector(&left->second.second->x);
    254           SideA.SubtractVector(MolCenter);
    255           SideA.ProjectOntoPlane(&AxisVector);
     248          SideA = left->second.second->x - (*MolCenter);
     249          SideA.ProjectOntoPlane(AxisVector);
    256250          //          Log() << Verbose(1) << "SideA: " << SideA << endl;
    257251
    258           SideB.CopyVector(&right->second.second->x);
    259           SideB.SubtractVector(MolCenter);
    260           SideB.ProjectOntoPlane(&AxisVector);
     252          SideB = right->second.second->x -(*MolCenter);
     253          SideB.ProjectOntoPlane(AxisVector);
    261254          //          Log() << Verbose(1) << "SideB: " << SideB << endl;
    262255
    263           SideC.CopyVector(&left->second.second->x);
    264           SideC.SubtractVector(&right->second.second->x);
    265           SideC.ProjectOntoPlane(&AxisVector);
     256          SideC = left->second.second->x - right->second.second->x;
     257          SideC.ProjectOntoPlane(AxisVector);
    266258          //          Log() << Verbose(1) << "SideC: " << SideC << endl;
    267259
    268           SideH.CopyVector(&runner->second.second->x);
    269           SideH.SubtractVector(MolCenter);
    270           SideH.ProjectOntoPlane(&AxisVector);
     260          SideH = runner->second.second->x -(*MolCenter);
     261          SideH.ProjectOntoPlane(AxisVector);
    271262          //          Log() << Verbose(1) << "SideH: " << SideH << endl;
    272263
     
    277268          const double h = SideH.Norm();
    278269          // calculate the angles
    279           const double alpha = SideA.Angle(&SideH);
    280           const double beta = SideA.Angle(&SideC);
    281           const double gamma = SideB.Angle(&SideH);
    282           const double delta = SideC.Angle(&SideH);
     270          const double alpha = SideA.Angle(SideH);
     271          const double beta = SideA.Angle(SideC);
     272          const double gamma = SideB.Angle(SideH);
     273          const double delta = SideC.Angle(SideH);
    283274          const double MinDistance = a * sin(beta) / (sin(delta)) * (((alpha < M_PI / 2.) || (gamma < M_PI / 2.)) ? 1. : -1.);
    284275          //Log() << Verbose(1) << " I calculated: a = " << a << ", h = " << h << ", beta(" << left->second.second->Name << "," << left->second.second->Name << "-" << right->second.second->Name << ") = " << beta << ", delta(" << left->second.second->Name << "," << runner->second.second->Name << ") = " << delta << ", Min = " << MinDistance << "." << endl;
     
    629620  for (TriangleMap::iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++)
    630621    { // go through every triangle, calculate volume of its pyramid with CoG as peak
    631       x.CopyVector(runner->second->endpoints[0]->node->node);
    632       x.SubtractVector(runner->second->endpoints[1]->node->node);
    633       y.CopyVector(runner->second->endpoints[0]->node->node);
    634       y.SubtractVector(runner->second->endpoints[2]->node->node);
    635       const double a = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(runner->second->endpoints[1]->node->node));
    636       const double b = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(runner->second->endpoints[2]->node->node));
    637       const double c = sqrt(runner->second->endpoints[2]->node->node->DistanceSquared(runner->second->endpoints[1]->node->node));
     622      x = (*runner->second->endpoints[0]->node->node) - (*runner->second->endpoints[1]->node->node);
     623      y = (*runner->second->endpoints[0]->node->node) - (*runner->second->endpoints[2]->node->node);
     624      const double a = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(*runner->second->endpoints[1]->node->node));
     625      const double b = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(*runner->second->endpoints[2]->node->node));
     626      const double c = sqrt(runner->second->endpoints[2]->node->node->DistanceSquared(*runner->second->endpoints[1]->node->node));
    638627      const double G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle
    639       x.MakeNormalVector(runner->second->endpoints[0]->node->node, runner->second->endpoints[1]->node->node, runner->second->endpoints[2]->node->node);
    640       x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(&x));
     628      x = Plane(*(runner->second->endpoints[0]->node->node),
     629                *(runner->second->endpoints[1]->node->node),
     630                *(runner->second->endpoints[2]->node->node)).getNormal();
     631      x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(x));
    641632      const double h = x.Norm(); // distance of CoG to triangle
    642633      const double PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak)
     
    752743    DoLog(0) && (Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl);
    753744    for (int i = 0; i < NDIM; i++)
    754       BoxLengths.x[i] = GreatestDiameter[i];
     745      BoxLengths[i] = GreatestDiameter[i];
    755746    mol->CenterEdge(&BoxLengths);
    756747  } else {
    757     BoxLengths.x[0] = (repetition[0] * GreatestDiameter[0] + repetition[1] * GreatestDiameter[1] + repetition[2] * GreatestDiameter[2]);
    758     BoxLengths.x[1] = (repetition[0] * repetition[1] * GreatestDiameter[0] * GreatestDiameter[1] + repetition[0] * repetition[2] * GreatestDiameter[0] * GreatestDiameter[2] + repetition[1] * repetition[2] * GreatestDiameter[1] * GreatestDiameter[2]);
    759     BoxLengths.x[2] = minimumvolume - cellvolume;
     748    BoxLengths[0] = (repetition[0] * GreatestDiameter[0] + repetition[1] * GreatestDiameter[1] + repetition[2] * GreatestDiameter[2]);
     749    BoxLengths[1] = (repetition[0] * repetition[1] * GreatestDiameter[0] * GreatestDiameter[1] + repetition[0] * repetition[2] * GreatestDiameter[0] * GreatestDiameter[2] + repetition[1] * repetition[2] * GreatestDiameter[1] * GreatestDiameter[2]);
     750    BoxLengths[2] = minimumvolume - cellvolume;
    760751    double x0 = 0.;
    761752    double x1 = 0.;
    762753    double x2 = 0.;
    763     if (gsl_poly_solve_cubic(BoxLengths.x[0], BoxLengths.x[1], BoxLengths.x[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return
     754    if (gsl_poly_solve_cubic(BoxLengths[0], BoxLengths[1], BoxLengths[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return
    764755      DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl);
    765756    else {
     
    770761    cellvolume = 1.;
    771762    for (int i = 0; i < NDIM; i++) {
    772       BoxLengths.x[i] = repetition[i] * (x0 + GreatestDiameter[i]);
    773       cellvolume *= BoxLengths.x[i];
     763      BoxLengths[i] = repetition[i] * (x0 + GreatestDiameter[i]);
     764      cellvolume *= BoxLengths[i];
    774765    }
    775766
     
    781772  // update Box of atoms by boundary
    782773  mol->SetBoxDimension(&BoxLengths);
    783   DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting cell dimensions are: " << BoxLengths.x[0] << " and " << BoxLengths.x[1] << " and " << BoxLengths.x[2] << " with total volume of " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);
     774  DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting cell dimensions are: " << BoxLengths[0] << " and " << BoxLengths[1] << " and " << BoxLengths[2] << " with total volume of " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);
    784775};
    785776
     
    844835
    845836  // calculate filler grid in [0,1]^3
    846   FillerDistance.Init(distance[0], distance[1], distance[2]);
     837  FillerDistance = Vector(distance[0], distance[1], distance[2]);
    847838  FillerDistance.InverseMatrixMultiplication(M);
    848839  for(int i=0;i<NDIM;i++)
    849     N[i] = (int) ceil(1./FillerDistance.x[i]);
     840    N[i] = (int) ceil(1./FillerDistance[i]);
    850841  DoLog(1) && (Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl);
    851842
     
    858849      for (n[2] = 0; n[2] < N[2]; n[2]++) {
    859850        // calculate position of current grid vector in untransformed box
    860         CurrentPosition.Init((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);
     851        CurrentPosition = Vector((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);
    861852        CurrentPosition.MatrixMultiplication(M);
    862853        // create molecule random translation vector ...
    863854        for (int i=0;i<NDIM;i++)
    864           FillerTranslations.x[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.);
     855          FillerTranslations[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.);
    865856        DoLog(2) && (Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "+" << FillerTranslations << "." << endl);
    866857
     
    874865          // create atomic random translation vector ...
    875866          for (int i=0;i<NDIM;i++)
    876             AtomTranslations.x[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.);
     867            AtomTranslations[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.);
    877868
    878869          // ... and rotation matrix
     
    894885
    895886          // ... and put at new position
    896           Inserter.CopyVector(&(Walker->x));
     887          Inserter = Walker->x;
    897888          if (DoRandomRotation)
    898889            Inserter.MatrixMultiplication(Rotations);
    899           Inserter.AddVector(&AtomTranslations);
    900           Inserter.AddVector(&FillerTranslations);
    901           Inserter.AddVector(&CurrentPosition);
     890          Inserter += AtomTranslations + FillerTranslations + CurrentPosition;
    902891
    903892          // check whether inserter is inside box
     
    905894          FillIt = true;
    906895          for (int i=0;i<NDIM;i++)
    907             FillIt = FillIt && (Inserter.x[i] >= -MYEPSILON) && ((Inserter.x[i]-1.) <= MYEPSILON);
     896            FillIt = FillIt && (Inserter[i] >= -MYEPSILON) && ((Inserter[i]-1.) <= MYEPSILON);
    908897          Inserter.MatrixMultiplication(M);
    909898
     
    921910            // copy atom ...
    922911            CopyAtoms[Walker->nr] = Walker->clone();
    923             CopyAtoms[Walker->nr]->x.CopyVector(&Inserter);
     912            CopyAtoms[Walker->nr]->x = Inserter;
    924913            Filling->AddAtom(CopyAtoms[Walker->nr]);
    925914            DoLog(4) && (Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl);
  • src/builder.cpp

    r632bc3 r8cbb97  
    17411741                  DoLog(2) && (Log() << Verbose(2) << "found element " << first->type->name << endl);
    17421742                for (int i=NDIM;i--;)
    1743                   first->x.x[i] = atof(argv[argptr+1+i]);
     1743                  first->x[i] = atof(argv[argptr+1+i]);
    17441744                if (first->type != NULL) {
    17451745                  mol->AddAtom(first);  // add to molecule
     
    20132013                first = World::getInstance().createAtom();
    20142014                first->type = periode->FindElement(1);
    2015                 first->x.Init(0.441, -0.143, 0.);
     2015                first->x = Vector(0.441, -0.143, 0.);
    20162016                filler->AddAtom(first);
    20172017                second = World::getInstance().createAtom();
    20182018                second->type = periode->FindElement(1);
    2019                 second->x.Init(-0.464, 1.137, 0.0);
     2019                second->x = Vector(-0.464, 1.137, 0.0);
    20202020                filler->AddAtom(second);
    20212021                third = World::getInstance().createAtom();
    20222022                third->type = periode->FindElement(8);
    2023                 third->x.Init(-0.464, 0.177, 0.);
     2023                third->x = Vector(-0.464, 0.177, 0.);
    20242024                filler->AddAtom(third);
    20252025                filler->AddBond(first, third, 1);
     
    21862186                    first = second;
    21872187                    second = first->next;
    2188                     if (first->x.DistanceSquared((const Vector *)&third->x) > tmp1*tmp1) // distance to first above radius ...
     2188                    if (first->x.DistanceSquared(third->x) > tmp1*tmp1) // distance to first above radius ...
    21892189                      mol->RemoveAtom(first);
    21902190                  }
     
    22062206                DoLog(1) && (Log() << Verbose(1) << "Translating all ions by given vector." << endl);
    22072207                for (int i=NDIM;i--;)
    2208                   x.x[i] = atof(argv[argptr+i]);
     2208                  x[i] = atof(argv[argptr+i]);
    22092209                mol->Translate((const Vector *)&x);
    22102210                argptr+=3;
     
    22222222                DoLog(1) && (Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl);
    22232223                for (int i=NDIM;i--;)
    2224                   x.x[i] = atof(argv[argptr+i]);
     2224                  x[i] = atof(argv[argptr+i]);
    22252225                mol->TranslatePeriodically((const Vector *)&x);
    22262226                argptr+=3;
     
    22452245                for (int i=0;i<NDIM;i++) {
    22462246                  j += i+1;
    2247                   x.x[i] = atof(argv[NDIM+i]);
     2247                  x[i] = atof(argv[NDIM+i]);
    22482248                  cell_size[j]*=factor[i];
    22492249                }
     
    23092309                for (int i=0;i<NDIM;i++) {
    23102310                  j += i+1;
    2311                   x.x[i] = atof(argv[argptr+i]);
    2312                   cell_size[j] += x.x[i]*2.;
     2311                  x[i] = atof(argv[argptr+i]);
     2312                  cell_size[j] += x[i]*2.;
    23132313                }
    23142314                mol->Translate((const Vector *)&x);
     
    24682468                    x.Zero();
    24692469                    y.Zero();
    2470                     y.x[abs(axis)-1] = cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
     2470                    y[abs(axis)-1] = cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
    24712471                    for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
    2472                       x.AddVector(&y); // per factor one cell width further
     2472                      x += y; // per factor one cell width further
    24732473                      for (int k=count;k--;) { // go through every atom of the original cell
    24742474                        first = World::getInstance().createAtom(); // create a new body
    2475                         first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    2476                         first->x.AddVector(&x);      // translate the coordinates
     2475                        first->x = (*vectors[k]) + x;
    24772476                        first->type = Elements[k];  // insert original element
    24782477                        mol->AddAtom(first);        // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
     
    24842483                    // correct cell size
    24852484                    if (axis < 0) { // if sign was negative, we have to translate everything
    2486                       x.Zero();
    2487                       x.AddVector(&y);
    2488                       x.Scale(-(faktor-1));
     2485                      x =(-(faktor-1)) * y;
    24892486                      mol->Translate(&x);
    24902487                    }
  • src/config.cpp

    r632bc3 r8cbb97  
    742742              neues = AtomList[i][j];
    743743            status = (status &&
    744                     ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) &&
    745                     ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) &&
    746                     ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) &&
     744                    ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x[0], 1, (repetition == 0) ? critical : optional) &&
     745                    ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x[1], 1, (repetition == 0) ? critical : optional) &&
     746                    ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x[2], 1, (repetition == 0) ? critical : optional) &&
    747747                    ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));
    748748            if (!status) break;
     
    758758            // put into trajectories list
    759759            for (int d=0;d<NDIM;d++)
    760               neues->Trajectory.R.at(repetition).x[d] = neues->x.x[d];
     760              neues->Trajectory.R.at(repetition)[d] = neues->x[d];
    761761
    762762            // parse velocities if present
    763             if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional))
    764               neues->v.x[0] = 0.;
    765             if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional))
    766               neues->v.x[1] = 0.;
    767             if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional))
    768               neues->v.x[2] = 0.;
     763            if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v[0], 1,optional))
     764              neues->v[0] = 0.;
     765            if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v[1], 1,optional))
     766              neues->v[1] = 0.;
     767            if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v[2], 1,optional))
     768              neues->v[2] = 0.;
    769769            for (int d=0;d<NDIM;d++)
    770               neues->Trajectory.U.at(repetition).x[d] = neues->v.x[d];
     770              neues->Trajectory.U.at(repetition)[d] = neues->v[d];
    771771
    772772            // parse forces if present
     
    778778              value[2] = 0.;
    779779            for (int d=0;d<NDIM;d++)
    780               neues->Trajectory.F.at(repetition).x[d] = value[d];
     780              neues->Trajectory.F.at(repetition)[d] = value[d];
    781781
    782782  //            Log() << Verbose(0) << "Parsed position of step " << (repetition) << ": (";
     
    821821            neues = AtomList[i][j];
    822822          // then parse for each atom the coordinates as often as present
    823           ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
    824           ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
    825           ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);
     823          ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x[0], repetition,critical);
     824          ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x[1], repetition,critical);
     825          ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x[2], repetition,critical);
    826826          ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
    827           if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))
    828             neues->v.x[0] = 0.;
    829           if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
    830             neues->v.x[1] = 0.;
    831           if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
    832             neues->v.x[2] = 0.;
     827          if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v[0], repetition,optional))
     828            neues->v[0] = 0.;
     829          if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v[1], repetition,optional))
     830            neues->v[1] = 0.;
     831          if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v[2], repetition,optional))
     832            neues->v[2] = 0.;
    833833          // here we don't care if forces are present (last in trajectories is always equal to current position)
    834834          neues->type = elementhash[i]; // find element type
     
    12931293        istringstream input2(zeile);
    12941294        atom *neues = World::getInstance().createAtom();
    1295         input2 >> neues->x.x[0]; // x
    1296         input2 >> neues->x.x[1]; // y
    1297         input2 >> neues->x.x[2]; // z
     1295        input2 >> neues->x[0]; // x
     1296        input2 >> neues->x[1]; // y
     1297        input2 >> neues->x[2]; // z
    12981298        input2 >> l;
    12991299        neues->type = elementhash[No]; // find element type
     
    15751575             'a'+(unsigned char)(AtomNo % 26),           /* letter for chain */
    15761576             MolNo,         /* residue sequence number */
    1577              Walker->node->x[0],                 /* position X in Angstroem */
    1578              Walker->node->x[1],                 /* position Y in Angstroem */
    1579              Walker->node->x[2],                 /* position Z in Angstroem */
     1577             Walker->node->at(0),                 /* position X in Angstroem */
     1578             Walker->node->at(1),                 /* position Y in Angstroem */
     1579             Walker->node->at(2),                 /* position Z in Angstroem */
    15801580             (double)Walker->type->Valence,         /* occupancy */
    15811581             (double)Walker->type->NoValenceOrbitals,          /* temperature factor */
     
    16291629           'a'+(unsigned char)(AtomNo % 26),           /* letter for chain */
    16301630           0,         /* residue sequence number */
    1631            Walker->node->x[0],                 /* position X in Angstroem */
    1632            Walker->node->x[1],                 /* position Y in Angstroem */
    1633            Walker->node->x[2],                 /* position Z in Angstroem */
     1631           Walker->node->at(0),                 /* position X in Angstroem */
     1632           Walker->node->at(1),                 /* position Y in Angstroem */
     1633           Walker->node->at(2),                 /* position Z in Angstroem */
    16341634           (double)Walker->type->Valence,         /* occupancy */
    16351635           (double)Walker->type->NoValenceOrbitals,          /* temperature factor */
     
    16831683    *output << mol->name << "\t";
    16841684    *output << 0 << "\t";
    1685     *output << Walker->node->x[0] << "\t" << Walker->node->x[1] << "\t" << Walker->node->x[2] << "\t";
    1686     *output << (double)Walker->type->Valence << "\t";
     1685    *output << Walker->node->at(0) << "\t" << Walker->node->at(1) << "\t" << Walker->node->at(2) << "\t";
     1686    *output << static_cast<double>(Walker->type->Valence) << "\t";
    16871687    *output << Walker->type->symbol << "\t";
    16881688    for (BondList::iterator runner = Walker->ListOfBonds.begin(); runner != Walker->ListOfBonds.end(); runner++)
     
    17591759        *output << (*MolWalker)->name << "\t";
    17601760        *output << MolCounter+1 << "\t";
    1761         *output << Walker->node->x[0] << "\t" << Walker->node->x[1] << "\t" << Walker->node->x[2] << "\t";
     1761        *output << Walker->node->at(0) << "\t" << Walker->node->at(1) << "\t" << Walker->node->at(2) << "\t";
    17621762        *output << (double)Walker->type->Valence << "\t";
    17631763        *output << Walker->type->symbol << "\t";
  • src/ellipsoid.cpp

    r632bc3 r8cbb97  
    4242
    4343  // 1. translate coordinate system so that ellipsoid center is in origin
    44   helper.CopyVector(&x);
    45   helper.SubtractVector(&EllipsoidCenter);
    46   RefPoint.CopyVector(&helper);
     44  RefPoint = helper = x - EllipsoidCenter;
    4745  //Log() << Verbose(4) << "Translated given point is at " << RefPoint << "." << endl;
    4846
     
    6159  Matrix[8] = cos(theta);
    6260  helper.MatrixMultiplication(Matrix);
    63   helper.Scale(InverseLength);
     61  helper.ScaleAll(InverseLength);
    6462  //Log() << Verbose(4) << "Transformed RefPoint is at " << helper << "." << endl;
    6563
     
    7270  theta = -EllipsoidAngle[1];
    7371  phi = -EllipsoidAngle[2];
    74   helper.Scale(EllipsoidLength);
     72  helper.ScaleAll(EllipsoidLength);
    7573  Matrix[0] = cos(psi)*cos(phi) - sin(psi)*cos(theta)*sin(phi);
    7674  Matrix[1] = -cos(psi)*sin(phi) - sin(psi)*cos(theta)*cos(phi);
     
    8684
    8785  // 5. determine distance between backtransformed point and x
    88   distance = RefPoint.DistanceSquared(&helper);
     86  distance = RefPoint.DistanceSquared(helper);
    8987  //Log() << Verbose(4) << "Squared distance between intersection and RefPoint is " << distance << "." << endl;
    9088
     
    116114  // put parameters into suitable ellipsoid form
    117115  for (int i=0;i<3;i++) {
    118     Center.x[i] = gsl_vector_get(x, i+0);
     116    Center[i] = gsl_vector_get(x, i+0);
    119117    EllipsoidLength[i] = gsl_vector_get(x, i+3);
    120118    EllipsoidAngle[i] = gsl_vector_get(x, i+6);
     
    160158    x = gsl_vector_alloc (9);
    161159    for (int i=0;i<3;i++) {
    162       gsl_vector_set (x, i+0, EllipsoidCenter->x[i]);
     160      gsl_vector_set (x, i+0, EllipsoidCenter->at(i));
    163161      gsl_vector_set (x, i+3, EllipsoidLength[i]);
    164162      gsl_vector_set (x, i+6, EllipsoidAngle[i]);
     
    195193      if (status == GSL_SUCCESS) {
    196194        for (int i=0;i<3;i++) {
    197           EllipsoidCenter->x[i] = gsl_vector_get (s->x,i+0);
     195          EllipsoidCenter->at(i) = gsl_vector_get (s->x,i+0);
    198196          EllipsoidLength[i] = gsl_vector_get (s->x, i+3);
    199197          EllipsoidAngle[i] = gsl_vector_get (s->x, i+6);
     
    304302                Candidate = (*Runner);
    305303                DoLog(2) && (Log() << Verbose(2) << "Current picked node is " << **Runner << " with index " << index << "." << endl);
    306                 x[PointsPicked++].CopyVector(Candidate->node);    // we have one more atom picked
     304                x[PointsPicked++] = *Candidate->node;    // we have one more atom picked
    307305                current++;    // next pre-picked atom
    308306              }
     
    350348      //Log() << Verbose(3) << "Current node is " << *Runner->second->node << " with " << value << " ... " << threshold << ": ";
    351349      if (value > threshold) {
    352         x[PointsPicked].CopyVector(Runner->second->node->node);
     350        x[PointsPicked] = (*Runner->second->node->node);
    353351        PointsPicked++;
    354352        //Log() << Verbose(0) << "IN." << endl;
     
    387385  Center.Zero();
    388386  for (PointMap::iterator Runner = T->PointsOnBoundary.begin(); Runner != T->PointsOnBoundary.end(); Runner++)
    389     Center.AddVector(Runner->second->node->node);
     387    Center += (*Runner->second->node->node);
    390388  Center.Scale(1./T->PointsOnBoundaryCount);
    391389  DoLog(1) && (Log() << Verbose(1) << "Center is at " << Center << "." << endl);
     
    405403    // calculate some sensible starting values for parameter fit
    406404    MaxDistance = 0.;
    407     MinDistance = x[0].ScalarProduct(&x[0]);
     405    MinDistance = x[0].ScalarProduct(x[0]);
    408406    for (int i=0;i<N;i++) {
    409       distance = x[i].ScalarProduct(&x[i]);
     407      distance = x[i].ScalarProduct(x[i]);
    410408      if (distance > MaxDistance)
    411409        MaxDistance = distance;
     
    414412    }
    415413    //Log() << Verbose(2) << "MinDistance " << MinDistance << ", MaxDistance " << MaxDistance << "." << endl;
    416     EllipsoidCenter.CopyVector(&Center);  // use Center of Gravity as initial center of ellipsoid
     414    EllipsoidCenter = Center;  // use Center of Gravity as initial center of ellipsoid
    417415    for (int i=0;i<3;i++)
    418416      EllipsoidAngle[i] = 0.;
     
    427425      output << number << "\t";
    428426      for (int i=0;i<3;i++)
    429         output << setprecision(9) << EllipsoidCenter.x[i] << "\t";
     427        output << setprecision(9) << EllipsoidCenter[i] << "\t";
    430428      for (int i=0;i<3;i++)
    431429        output << setprecision(9) << EllipsoidLength[i] << "\t";
  • src/gslmatrix.cpp

    r632bc3 r8cbb97  
    1010#include "gslmatrix.hpp"
    1111#include "helpers.hpp"
     12#include "Helpers/fast_functions.hpp"
    1213
    1314#include <cassert>
  • src/helpers.cpp

    r632bc3 r8cbb97  
    66
    77#include "helpers.hpp"
     8#include "Helpers/fast_functions.hpp"
    89#include "log.hpp"
    910#include "memoryusageobserver.hpp"
     
    4950  while (*b < lower_bound)
    5051    *b += step;
    51 };
    52 
    53 /** Returns the power of \a n with respect to \a base.
    54  * \param base basis
    55  * \param n power
    56  * \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;
    6552};
    6653
     
    175162};
    176163
    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
    206165
    207166/** Comparison function for GSL heapsort on distances in two molecules.
  • src/helpers.hpp

    r632bc3 r8cbb97  
    2424/********************************************** definitions *********************************/
    2525
    26 // some algebraic matrix stuff
    27 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 
    3126/********************************************** helpful functions *********************************/
    3227
     
    5348bool check_bounds(double *x, double *cell_size);
    5449void bound(double *b, double lower_bound, double upper_bound);
    55 int pot(int base, int n);
    5650int CountLinesinFile(ifstream &InputFile);
    5751char *FixedDigitNumber(const int FragmentNumber, const int digits);
     
    6458/********************************************** helpful template functions *********************************/
    6559
    66 /** Flips two values.
    67  * \param x first value
    68  * \param y second value
    69  */
    70 template <typename T> void flip(T &x, T &y)
    71 {
    72   T tmp;
    73   tmp = x;
    74   x = y;
    75   y = tmp;
    76 };
    7760
    7861/** returns greater of the two values.
  • src/leastsquaremin.cpp

    r632bc3 r8cbb97  
    2525  for (int i=num;i--;) {
    2626    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));
    2828  }
    2929
  • src/linearsystemofequations.cpp

    r632bc3 r8cbb97  
    5454{
    5555  assert ( columns == NDIM && "Vector class is always three-dimensional, unlike this LEqS!");
    56   b->SetFromDoubleArray(x->x);
     56  b->SetFromDoubleArray(x->get());
    5757};
    5858
     
    100100  // copy solution
    101101  for (size_t i=0;i<x->dimension;i++)
    102     v.x[i] = x->Get(i);
     102    v[i] = x->Get(i);
    103103  return status;
    104104};
  • src/linkedcell.cpp

    r632bc3 r8cbb97  
    5454  Walker = set->GetPoint();
    5555  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);
    5858  }
    5959  set->GoToFirst();
     
    6161    Walker = set->GetPoint();
    6262    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);
    6767    }
    6868    set->GoToNext();
     
    7272  // 2. find then number of cells per axis
    7373  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);
    7575  }
    7676  DoLog(2) && (Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl);
     
    9494    Walker = set->GetPoint();
    9595    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));
    9797    }
    9898    index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
     
    128128  LinkedNodes::iterator Runner = set->begin();
    129129  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);
    132132  }
    133133  for (LinkedNodes::iterator Runner = set->begin(); Runner != set->end(); Runner++) {
    134134    Walker = *Runner;
    135135    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);
    140140    }
    141141  }
     
    144144  // 2. find then number of cells per axis
    145145  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);
    147147  }
    148148  DoLog(2) && (Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl);
     
    165165    Walker = *Runner;
    166166    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));
    168168    }
    169169    index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
     
    251251{
    252252  for (int i=0;i<NDIM;i++)
    253     n[i] = (int)floor((x->x[i] - min.x[i])/RADIUS);
     253    n[i] = (int)floor((x->at(i) - min[i])/RADIUS);
    254254
    255255  return CheckBounds();
     
    264264  bool status = false;
    265265  for (int i=0;i<NDIM;i++) {
    266     n[i] = (int)floor((Walker->node->x[i] - min.x[i])/RADIUS);
     266    n[i] = static_cast<int>(floor((Walker->node->at(i) - min[i])/RADIUS));
    267267  }
    268268  index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
     
    340340{
    341341  for (int i=0;i<NDIM;i++) {
    342     n[i] = (int)floor((x->x[i] - min.x[i])/RADIUS);
     342    n[i] = (int)floor((x->at(i) - min[i])/RADIUS);
    343343    if (n[i] < 0)
    344344      n[i] = 0;
     
    356356  Vector center;  // center of the closest cell
    357357  for (int i=0;i<NDIM;i++)
    358     center.x[i] = min.x[i]+((double)n[i]+.5)*RADIUS;
     358    center[i] = min[i]+((double)n[i]+.5)*RADIUS;
    359359
    360360  int c[NDIM];
     
    364364        // set up corner
    365365        for (int i=0;i<NDIM;i++)
    366           corner.x[i] = min.x[i]+RADIUS*((double)n[i]+c[i]);
     366          corner[i] = min[i]+RADIUS*((double)n[i]+c[i]);
    367367        // set up distance vector
    368         Distance.CopyVector(x);
    369         Distance.SubtractVector(&corner);
     368        Distance = (*x) - corner;
    370369        const double dist = Distance.NormSquared();
    371370        // check whether distance is smaller
     
    373372          distanceSquared = dist;
    374373        // check whether distance vector goes inside or outside
    375         tester.CopyVector(&center);
    376         tester.SubtractVector(&corner);
    377         if (tester.ScalarProduct(&Distance) < 0)
     374        tester = center -corner;
     375        if (tester.ScalarProduct(Distance) < 0)
    378376          outside = false;
    379377      }
     
    408406      Walker = *Runner;
    409407      //Log() << Verbose(1) << "Current neighbour is at " << *Walker->node << "." << endl;
    410       if ((center->DistanceSquared(Walker->node) - radiusSquared) < MYEPSILON) {
     408      if ((center->DistanceSquared(*Walker->node) - radiusSquared) < MYEPSILON) {
    411409        TesselList->push_back(Walker);
    412410      }
  • src/molecule.cpp

    r632bc3 r8cbb97  
    2626#include "vector.hpp"
    2727#include "World.hpp"
     28#include "Plane.hpp"
     29#include "Exceptions/LinearDependenceException.hpp"
     30
    2831
    2932/************************************* Functions for class molecule *********************************/
     
    218221//  Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl;
    219222  // create vector in direction of bond
    220   InBondvector.CopyVector(&TopReplacement->x);
    221   InBondvector.SubtractVector(&TopOrigin->x);
     223  InBondvector = TopReplacement->x - TopOrigin->x;
    222224  bondlength = InBondvector.Norm();
    223225
     
    231233    Orthovector1.Zero();
    232234    for (int i=NDIM;i--;) {
    233       l = TopReplacement->x.x[i] - TopOrigin->x.x[i];
     235      l = TopReplacement->x[i] - TopOrigin->x[i];
    234236      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.;
    236238      } // (signs are correct, was tested!)
    237239    }
    238240    matrix = ReturnFullMatrixforSymmetric(cell_size);
    239241    Orthovector1.MatrixMultiplication(matrix);
    240     InBondvector.SubtractVector(&Orthovector1); // subtract just the additional translation
     242    InBondvector -= Orthovector1; // subtract just the additional translation
    241243    Free(&matrix);
    242244    bondlength = InBondvector.Norm();
     
    263265      FirstOtherAtom = World::getInstance().createAtom();    // new atom
    264266      FirstOtherAtom->type = elemente->FindElement(1);  // element is Hydrogen
    265       FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     267      FirstOtherAtom->v = TopReplacement->v; // copy velocity
    266268      FirstOtherAtom->FixedIon = TopReplacement->FixedIon;
    267269      if (TopReplacement->type->Z == 1) { // neither rescale nor replace if it's already hydrogen
     
    271273        FirstOtherAtom->father = NULL;  // if we replace hydrogen, we mark it as our father, otherwise we are just an added hydrogen with no father
    272274      }
    273       InBondvector.Scale(&BondRescale);   // rescale the distance vector to Hydrogen bond length
    274       FirstOtherAtom->x.CopyVector(&TopOrigin->x); // set coordination to origin ...
    275       FirstOtherAtom->x.AddVector(&InBondvector);  // ... and add distance vector to replacement atom
     275      InBondvector *= BondRescale;   // rescale the distance vector to Hydrogen bond length
     276      FirstOtherAtom->x = TopOrigin->x; // set coordination to origin ...
     277      FirstOtherAtom->x = InBondvector;  // ... and add distance vector to replacement atom
    276278      AllWentWell = AllWentWell && AddAtom(FirstOtherAtom);
    277279//      Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: ";
     
    305307
    306308        // 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        }
    308317      } else {
    309         Orthovector1.GetOneNormalVector(&InBondvector);
     318        Orthovector1.GetOneNormalVector(InBondvector);
    310319      }
    311320      //Log() << Verbose(3)<< "Orthovector1: ";
     
    313322      //Log() << Verbose(0) << endl;
    314323      // orthogonal vector and bond vector between origin and replacement form the new plane
    315       Orthovector1.MakeNormalVector(&InBondvector);
     324      Orthovector1.MakeNormalTo(InBondvector);
    316325      Orthovector1.Normalize();
    317326      //Log() << Verbose(3) << "ReScaleCheck: " << Orthovector1.Norm() << " and " << InBondvector.Norm() << "." << endl;
     
    322331      FirstOtherAtom->type = elemente->FindElement(1);
    323332      SecondOtherAtom->type = elemente->FindElement(1);
    324       FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     333      FirstOtherAtom->v = TopReplacement->v; // copy velocity
    325334      FirstOtherAtom->FixedIon = TopReplacement->FixedIon;
    326       SecondOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     335      SecondOtherAtom->v = TopReplacement->v; // copy velocity
    327336      SecondOtherAtom->FixedIon = TopReplacement->FixedIon;
    328337      FirstOtherAtom->father = NULL;  // we are just an added hydrogen with no father
     
    345354      SecondOtherAtom->x.Zero();
    346355      for(int i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondvector is bondangle = 0 direction)
    347         FirstOtherAtom->x.x[i] = InBondvector.x[i] * cos(bondangle) + Orthovector1.x[i] * (sin(bondangle));
    348         SecondOtherAtom->x.x[i] = InBondvector.x[i] * cos(bondangle) + Orthovector1.x[i] * (-sin(bondangle));
    349       }
    350       FirstOtherAtom->x.Scale(&BondRescale);  // rescale by correct BondDistance
    351       SecondOtherAtom->x.Scale(&BondRescale);
     356        FirstOtherAtom->x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (sin(bondangle));
     357        SecondOtherAtom->x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle));
     358      }
     359      FirstOtherAtom->x *= BondRescale;  // rescale by correct BondDistance
     360      SecondOtherAtom->x *= BondRescale;
    352361      //Log() << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl;
    353362      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];
    356365      }
    357366      // ... and add to molecule
     
    379388      SecondOtherAtom->type = elemente->FindElement(1);
    380389      ThirdOtherAtom->type = elemente->FindElement(1);
    381       FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     390      FirstOtherAtom->v = TopReplacement->v; // copy velocity
    382391      FirstOtherAtom->FixedIon = TopReplacement->FixedIon;
    383       SecondOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     392      SecondOtherAtom->v = TopReplacement->v; // copy velocity
    384393      SecondOtherAtom->FixedIon = TopReplacement->FixedIon;
    385       ThirdOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     394      ThirdOtherAtom->v = TopReplacement->v; // copy velocity
    386395      ThirdOtherAtom->FixedIon = TopReplacement->FixedIon;
    387396      FirstOtherAtom->father = NULL;  //  we are just an added hydrogen with no father
     
    390399
    391400      // we need to vectors orthonormal the InBondvector
    392       AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(&InBondvector);
     401      AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(InBondvector);
    393402//      Log() << Verbose(3) << "Orthovector1: ";
    394403//      Orthovector1.Output(out);
    395404//      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      }
    397412//      Log() << Verbose(3) << "Orthovector2: ";
    398413//      Orthovector2.Output(out);
     
    411426      factors[1] = f;
    412427      factors[2] = 0.;
    413       FirstOtherAtom->x.LinearCombinationOfVectors(&InBondvector, &Orthovector1, &Orthovector2, factors);
     428      FirstOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
    414429      factors[1] = -0.5*f;
    415430      factors[2] = g;
    416       SecondOtherAtom->x.LinearCombinationOfVectors(&InBondvector, &Orthovector1, &Orthovector2, factors);
     431      SecondOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
    417432      factors[2] = -g;
    418       ThirdOtherAtom->x.LinearCombinationOfVectors(&InBondvector, &Orthovector1, &Orthovector2, factors);
     433      ThirdOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
    419434
    420435      // rescale each to correct BondDistance
     
    424439
    425440      // and relative to *origin atom
    426       FirstOtherAtom->x.AddVector(&TopOrigin->x);
    427       SecondOtherAtom->x.AddVector(&TopOrigin->x);
    428       ThirdOtherAtom->x.AddVector(&TopOrigin->x);
     441      FirstOtherAtom->x += TopOrigin->x;
     442      SecondOtherAtom->x += TopOrigin->x;
     443      ThirdOtherAtom->x += TopOrigin->x;
    429444
    430445      // ... and add to molecule
     
    514529    }
    515530    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;
    520535    }
    521536    AddAtom(Walker);  // add to molecule
     
    662677{
    663678  double * const cell_size = World::getInstance().getDomain();
    664   cell_size[0] = dim->x[0];
     679  cell_size[0] = dim->at(0);
    665680  cell_size[1] = 0.;
    666   cell_size[2] = dim->x[1];
     681  cell_size[2] = dim->at(1);
    667682  cell_size[3] = 0.;
    668683  cell_size[4] = 0.;
    669   cell_size[5] = dim->x[2];
     684  cell_size[5] = dim->at(2);
    670685};
    671686
     
    757772  for (int i=0;i<NDIM;i++) {
    758773    j += i+1;
    759     result = result && ((x->x[i] >= 0) && (x->x[i] < cell_size[j]));
     774    result = result && ((x->at(i) >= 0) && (x->at(i) < cell_size[j]));
    760775  }
    761776  //return result;
     
    10071022    DeterminePeriodicCenter(CenterOfGravity);
    10081023    OtherMolecule->DeterminePeriodicCenter(OtherCenterOfGravity);
    1009     DoLog(5) && (Log() << Verbose(5) << "Center of Gravity: ");
    1010     CenterOfGravity.Output();
    1011     DoLog(0) && (Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: ");
    1012     OtherCenterOfGravity.Output();
    1013     DoLog(0) && (Log() << Verbose(0) << endl);
    1014     if (CenterOfGravity.DistanceSquared(&OtherCenterOfGravity) > threshold*threshold) {
     1024    DoLog(5) && (Log() << Verbose(5) << "Center of Gravity: " << CenterOfGravity << endl);
     1025    DoLog(5) && (Log() << Verbose(5) << "Other Center of Gravity: " << OtherCenterOfGravity << endl);
     1026    if (CenterOfGravity.DistanceSquared(OtherCenterOfGravity) > threshold*threshold) {
    10151027      DoLog(4) && (Log() << Verbose(4) << "Centers of gravity don't match." << endl);
    10161028      result = false;
  • src/molecule.hpp

    r632bc3 r8cbb97  
    144144  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T), T t ) const;
    145145  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T) const, T t ) const;
     146  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T&), T &t ) const;
     147  template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T&) const, T &t ) const;
    146148  template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const;
    147149  template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const;
  • src/molecule_dynamics.cpp

    r632bc3 r8cbb97  
    1414#include "molecule.hpp"
    1515#include "parser.hpp"
     16#include "Plane.hpp"
    1617
    1718/************************************* Functions for class molecule *********************************/
     
    3839    // determine normalized trajectories direction vector (n1, n2)
    3940    Sprinter = Params.PermutationMap[Walker->nr];   // find first target point
    40     trajectory1.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep));
    41     trajectory1.SubtractVector(&Walker->Trajectory.R.at(Params.startstep));
     41    trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep);
    4242    trajectory1.Normalize();
    4343    Norm1 = trajectory1.Norm();
    4444    Sprinter = Params.PermutationMap[Runner->nr];   // find second target point
    45     trajectory2.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep));
    46     trajectory2.SubtractVector(&Runner->Trajectory.R.at(Params.startstep));
     45    trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep);
    4746    trajectory2.Normalize();
    4847    Norm2 = trajectory1.Norm();
    4948    // check whether either is zero()
    5049    if ((Norm1 < MYEPSILON) && (Norm2 < MYEPSILON)) {
    51       tmp = Walker->Trajectory.R.at(Params.startstep).Distance(&Runner->Trajectory.R.at(Params.startstep));
     50      tmp = Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.startstep));
    5251    } else if (Norm1 < MYEPSILON) {
    5352      Sprinter = Params.PermutationMap[Walker->nr];   // find first target point
    54       trajectory1.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep));  // copy first offset
    55       trajectory1.SubtractVector(&Runner->Trajectory.R.at(Params.startstep));  // subtract second offset
    56       trajectory2.Scale( trajectory1.ScalarProduct(&trajectory2) ); // trajectory2 is scaled to unity, hence we don't need to divide by anything
    57       trajectory1.SubtractVector(&trajectory2);   // project the part in norm direction away
     53      trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep);
     54      trajectory2 *= trajectory1.ScalarProduct(trajectory2); // trajectory2 is scaled to unity, hence we don't need to divide by anything
     55      trajectory1 -= trajectory2;   // project the part in norm direction away
    5856      tmp = trajectory1.Norm();  // remaining norm is distance
    5957    } else if (Norm2 < MYEPSILON) {
    6058      Sprinter = Params.PermutationMap[Runner->nr];   // find second target point
    61       trajectory2.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep));  // copy second offset
    62       trajectory2.SubtractVector(&Walker->Trajectory.R.at(Params.startstep));  // subtract first offset
    63       trajectory1.Scale( trajectory2.ScalarProduct(&trajectory1) ); // trajectory1 is scaled to unity, hence we don't need to divide by anything
    64       trajectory2.SubtractVector(&trajectory1);   // project the part in norm direction away
     59      trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep);  // copy second offset
     60      trajectory1 *= trajectory2.ScalarProduct(trajectory1); // trajectory1 is scaled to unity, hence we don't need to divide by anything
     61      trajectory2 -= trajectory1;   // project the part in norm direction away
    6562      tmp = trajectory2.Norm();  // remaining norm is distance
    66     } else if ((fabs(trajectory1.ScalarProduct(&trajectory2)/Norm1/Norm2) - 1.) < MYEPSILON) { // check whether they're linear dependent
     63    } else if ((fabs(trajectory1.ScalarProduct(trajectory2)/Norm1/Norm2) - 1.) < MYEPSILON) { // check whether they're linear dependent
    6764  //        Log() << Verbose(3) << "Both trajectories of " << *Walker << " and " << *Runner << " are linear dependent: ";
    6865  //        Log() << Verbose(0) << trajectory1;
    6966  //        Log() << Verbose(0) << " and ";
    7067  //        Log() << Verbose(0) << trajectory2;
    71       tmp = Walker->Trajectory.R.at(Params.startstep).Distance(&Runner->Trajectory.R.at(Params.startstep));
     68      tmp = Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.startstep));
    7269  //        Log() << Verbose(0) << " with distance " << tmp << "." << endl;
    7370    } else { // determine distance by finding minimum distance
     
    7976  //        Log() << Verbose(0) << trajectory2 << endl;
    8077      // determine normal vector for both
    81       normal.MakeNormalVector(&trajectory1, &trajectory2);
     78      normal = Plane(trajectory1, trajectory2,0).getNormal();
    8279      // print all vectors for debugging
    8380  //        Log() << Verbose(0) << "Normal vector in between: ";
     
    8582      // setup matrix
    8683      for (int i=NDIM;i--;) {
    87         gsl_matrix_set(A, 0, i, trajectory1.x[i]);
    88         gsl_matrix_set(A, 1, i, trajectory2.x[i]);
    89         gsl_matrix_set(A, 2, i, normal.x[i]);
    90         gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep).x[i] - Runner->Trajectory.R.at(Params.startstep).x[i]));
     84        gsl_matrix_set(A, 0, i, trajectory1[i]);
     85        gsl_matrix_set(A, 1, i, trajectory2[i]);
     86        gsl_matrix_set(A, 2, i, normal[i]);
     87        gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep)[i] - Runner->Trajectory.R.at(Params.startstep)[i]));
    9188      }
    9289      // solve the linear system by Householder transformations
     
    9693  //        Log() << Verbose(0) << " with distance " << tmp << "." << endl;
    9794      // test whether we really have the intersection (by checking on c_1 and c_2)
    98       TestVector.CopyVector(&Runner->Trajectory.R.at(Params.startstep));
     95      trajectory1.Scale(gsl_vector_get(x,0));
    9996      trajectory2.Scale(gsl_vector_get(x,1));
    100       TestVector.AddVector(&trajectory2);
    10197      normal.Scale(gsl_vector_get(x,2));
    102       TestVector.AddVector(&normal);
    103       TestVector.SubtractVector(&Walker->Trajectory.R.at(Params.startstep));
    104       trajectory1.Scale(gsl_vector_get(x,0));
    105       TestVector.SubtractVector(&trajectory1);
     98      TestVector = Runner->Trajectory.R.at(Params.startstep) + trajectory2 + normal
     99                   - (Walker->Trajectory.R.at(Params.startstep) + trajectory1);
    106100      if (TestVector.Norm() < MYEPSILON) {
    107101  //          Log() << Verbose(2) << "Test: ok.\tDistance of " << tmp << " is correct." << endl;
     
    172166    // first term: distance to target
    173167    Runner = Params.PermutationMap[Walker->nr];   // find target point
    174     tmp = (Walker->Trajectory.R.at(Params.startstep).Distance(&Runner->Trajectory.R.at(Params.endstep)));
     168    tmp = (Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.endstep)));
    175169    tmp *= Params.IsAngstroem ? 1. : 1./AtomicLengthToAngstroem;
    176170    result += Params.PenaltyConstants[0] * tmp;
     
    231225    while(Runner->next != mol->end) {
    232226      Runner = Runner->next;
    233       Params.DistanceList[Walker->nr]->insert( DistancePair(Walker->Trajectory.R.at(Params.startstep).Distance(&Runner->Trajectory.R.at(Params.endstep)), Runner) );
     227      Params.DistanceList[Walker->nr]->insert( DistancePair(Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.endstep)), Runner) );
    234228    }
    235229  }
     
    514508      Sprinter = mol->AddCopyAtom(Walker);
    515509      for (int n=NDIM;n--;) {
    516         Sprinter->x.x[n] = Walker->Trajectory.R.at(startstep).x[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep).x[n] - Walker->Trajectory.R.at(startstep).x[n])*((double)step/(double)MaxSteps);
     510        Sprinter->x[n] = Walker->Trajectory.R.at(startstep)[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep)[n] - Walker->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps);
    517511        // add to Trajectories
    518512        //Log() << Verbose(3) << step << ">=" << MDSteps-1 << endl;
    519513        if (step < MaxSteps) {
    520           Walker->Trajectory.R.at(step).x[n] = Walker->Trajectory.R.at(startstep).x[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep).x[n] - Walker->Trajectory.R.at(startstep).x[n])*((double)step/(double)MaxSteps);
    521           Walker->Trajectory.U.at(step).x[n] = 0.;
    522           Walker->Trajectory.F.at(step).x[n] = 0.;
     514          Walker->Trajectory.R.at(step)[n] = Walker->Trajectory.R.at(startstep)[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep)[n] - Walker->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps);
     515          Walker->Trajectory.U.at(step)[n] = 0.;
     516          Walker->Trajectory.F.at(step)[n] = 0.;
    523517        }
    524518      }
     
    582576    for(int i=0;i<AtomCount;i++)
    583577      for(int d=0;d<NDIM;d++) {
    584         Velocity.x[d] += Force.Matrix[0][i][d+5];
     578        Velocity[d] += Force.Matrix[0][i][d+5];
    585579      }
    586580    for(int i=0;i<AtomCount;i++)
    587581      for(int d=0;d<NDIM;d++) {
    588         Force.Matrix[0][i][d+5] -= Velocity.x[d]/(double)AtomCount;
     582        Force.Matrix[0][i][d+5] -= Velocity[d]/(double)AtomCount;
    589583      }
    590584    // solve a constrained potential if we are meant to
  • src/molecule_fragmentation.cpp

    r632bc3 r8cbb97  
    16731673    // remove bonds that are beyond bonddistance
    16741674    for(int i=NDIM;i--;)
    1675       Translationvector.x[i] = 0.;
     1675      Translationvector[i] = 0.;
    16761676    // scan all bonds
    16771677    Binder = first;
     
    16801680      Binder = Binder->next;
    16811681      for (int i=NDIM;i--;) {
    1682         tmp = fabs(Binder->leftatom->x.x[i] - Binder->rightatom->x.x[i]);
     1682        tmp = fabs(Binder->leftatom->x[i] - Binder->rightatom->x[i]);
    16831683        //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl;
    16841684        if (tmp > BondDistance) {
     
    16941694      // create translation vector from their periodically modified distance
    16951695      for (int i=NDIM;i--;) {
    1696         tmp = Binder->leftatom->x.x[i] - Binder->rightatom->x.x[i];
     1696        tmp = Binder->leftatom->x[i] - Binder->rightatom->x[i];
    16971697        if (fabs(tmp) > BondDistance)
    1698           Translationvector.x[i] = (tmp < 0) ? +1. : -1.;
     1698          Translationvector[i] = (tmp < 0) ? +1. : -1.;
    16991699      }
    17001700      Translationvector.MatrixMultiplication(matrix);
    17011701      //Log() << Verbose(3) << "Translation vector is ";
    1702       Translationvector.Output();
    1703       DoLog(0) && (Log() << Verbose(0) << endl);
     1702      Log() << Verbose(0) << Translationvector <<  endl;
    17041703      // apply to all atoms of first component via BFS
    17051704      for (int i=AtomCount;i--;)
     
    17101709        //Log() << Verbose (3) << "Current Walker is: " << *Walker << "." << endl;
    17111710        ColorList[Walker->nr] = black;    // mark as explored
    1712         Walker->x.AddVector(&Translationvector); // translate
     1711        Walker->x += Translationvector; // translate
    17131712        for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    17141713          if ((*Runner) != Binder) {
  • src/molecule_geometry.cpp

    r632bc3 r8cbb97  
    3232
    3333  // go through all atoms
    34   ActOnAllVectors( &Vector::SubtractVector, Center);
     34  ActOnAllVectors( &Vector::SubtractVector, *Center);
    3535  ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    3636
     
    7272  if (ptr != end) {   //list not empty?
    7373    for (int i=NDIM;i--;) {
    74       max->x[i] = ptr->x.x[i];
    75       min->x[i] = ptr->x.x[i];
     74      max->at(i) = ptr->x[i];
     75      min->at(i) = ptr->x[i];
    7676    }
    7777    while (ptr->next != end) {  // continue with second if present
     
    7979      //ptr->Output(1,1,out);
    8080      for (int i=NDIM;i--;) {
    81         max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i];
    82         min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i];
     81        max->at(i) = (max->at(i) < ptr->x[i]) ? ptr->x[i] : max->at(i);
     82        min->at(i) = (min->at(i) > ptr->x[i]) ? ptr->x[i] : min->at(i);
    8383      }
    8484    }
     
    8989//    Log() << Verbose(0) << endl;
    9090    min->Scale(-1.);
    91     max->AddVector(min);
     91    (*max) += (*min);
    9292    Translate(min);
    9393    Center.Zero();
     
    112112      ptr = ptr->next;
    113113      Num++;
    114       Center.AddVector(&ptr->x);
     114      Center += ptr->x;
    115115    }
    116116    Center.Scale(-1./Num); // divide through total number (and sign for direction)
     
    136136      ptr = ptr->next;
    137137      Num += 1.;
    138       tmp.CopyVector(&ptr->x);
    139       a->AddVector(&tmp);
     138      tmp = ptr->x;
     139      (*a) += tmp;
    140140    }
    141141    a->Scale(1./Num); // divide through total mass (and sign for direction)
     
    161161      ptr = ptr->next;
    162162      Num += ptr->type->mass;
    163       tmp.CopyVector(&ptr->x);
    164       tmp.Scale(ptr->type->mass);  // scale by mass
    165       a->AddVector(&tmp);
     163      tmp = ptr->type->mass * ptr->x;
     164      (*a) += tmp;
    166165    }
    167166    a->Scale(-1./Num); // divide through total mass (and sign for direction)
     
    189188void molecule::CenterAtVector(Vector *newcenter)
    190189{
    191   Center.CopyVector(newcenter);
     190  Center = *newcenter;
    192191};
    193192
     
    195194/** Scales all atoms by \a *factor.
    196195 * \param *factor pointer to scaling factor
     196 *
     197 * TODO: Is this realy what is meant, i.e.
     198 * x=(x[0]*factor[0],x[1]*factor[1],x[2]*factor[2]) (current impl)
     199 * or rather
     200 * x=(**factor) * x (as suggested by comment)
    197201 */
    198202void molecule::Scale(const double ** const factor)
     
    203207    ptr = ptr->next;
    204208    for (int j=0;j<MDSteps;j++)
    205       ptr->Trajectory.R.at(j).Scale(factor);
    206     ptr->x.Scale(factor);
     209      ptr->Trajectory.R.at(j).ScaleAll(*factor);
     210    ptr->x.ScaleAll(*factor);
    207211  }
    208212};
     
    218222    ptr = ptr->next;
    219223    for (int j=0;j<MDSteps;j++)
    220       ptr->Trajectory.R.at(j).Translate(trans);
    221     ptr->x.Translate(trans);
     224      ptr->Trajectory.R.at(j) += (*trans);
     225    ptr->x += (*trans);
    222226  }
    223227};
     
    234238
    235239  // go through all atoms
    236   ActOnAllVectors( &Vector::SubtractVector, trans);
     240  ActOnAllVectors( &Vector::SubtractVector, *trans);
    237241  ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    238242
     
    247251void molecule::Mirror(const Vector *n)
    248252{
    249   ActOnAllVectors( &Vector::Mirror, n );
     253  ActOnAllVectors( &Vector::Mirror, *n );
    250254};
    251255
     
    271275      if (Walker->type->Z != 1) {
    272276#endif
    273         Testvector.CopyVector(&Walker->x);
     277        Testvector = Walker->x;
    274278        Testvector.MatrixMultiplication(inversematrix);
    275279        Translationvector.Zero();
     
    277281         if (Walker->nr < (*Runner)->GetOtherAtom(Walker)->nr) // otherwise we shift one to, the other fro and gain nothing
    278282            for (int j=0;j<NDIM;j++) {
    279               tmp = Walker->x.x[j] - (*Runner)->GetOtherAtom(Walker)->x.x[j];
     283              tmp = Walker->x[j] - (*Runner)->GetOtherAtom(Walker)->x[j];
    280284              if ((fabs(tmp)) > BondDistance) {
    281285                flag = false;
    282286                DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << Walker->Name << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl);
    283287                if (tmp > 0)
    284                   Translationvector.x[j] -= 1.;
     288                  Translationvector[j] -= 1.;
    285289                else
    286                   Translationvector.x[j] += 1.;
     290                  Translationvector[j] += 1.;
    287291              }
    288292            }
    289293        }
    290         Testvector.AddVector(&Translationvector);
     294        Testvector += Translationvector;
    291295        Testvector.MatrixMultiplication(matrix);
    292         Center.AddVector(&Testvector);
    293         DoLog(1) && (Log() << Verbose(1) << "vector is: ");
    294         Testvector.Output();
    295         DoLog(0) && (Log() << Verbose(0) << endl);
     296        Center += Testvector;
     297        Log() << Verbose(1) << "vector is: " << Testvector << endl;
    296298#ifdef ADDHYDROGEN
    297299        // now also change all hydrogens
    298300        for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    299301          if ((*Runner)->GetOtherAtom(Walker)->type->Z == 1) {
    300             Testvector.CopyVector(&(*Runner)->GetOtherAtom(Walker)->x);
     302            Testvector = (*Runner)->GetOtherAtom(Walker)->x;
    301303            Testvector.MatrixMultiplication(inversematrix);
    302             Testvector.AddVector(&Translationvector);
     304            Testvector += Translationvector;
    303305            Testvector.MatrixMultiplication(matrix);
    304             Center.AddVector(&Testvector);
    305             DoLog(1) && (Log() << Verbose(1) << "Hydrogen vector is: ");
    306             Testvector.Output();
    307             DoLog(0) && (Log() << Verbose(0) << endl);
     306            Center += Testvector;
     307            Log() << Verbose(1) << "Hydrogen vector is: " << Testvector << endl;
    308308          }
    309309        }
     
    338338  while (ptr->next != end) {
    339339    ptr = ptr->next;
    340     Vector x;
    341     x.CopyVector(&ptr->x);
     340    Vector x = ptr->x;
    342341    //x.SubtractVector(CenterOfGravity);
    343     InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]);
    344     InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]);
    345     InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]);
    346     InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]);
    347     InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]);
    348     InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]);
    349     InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]);
    350     InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]);
    351     InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]);
     342    InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]);
     343    InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]);
     344    InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]);
     345    InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]);
     346    InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]);
     347    InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]);
     348    InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]);
     349    InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]);
     350    InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]);
    352351  }
    353352  // print InertiaTensor for debugging
     
    390389    while (ptr->next != end) {
    391390      ptr = ptr->next;
    392       Vector x;
    393       x.CopyVector(&ptr->x);
     391      Vector x = ptr->x;
    394392      //x.SubtractVector(CenterOfGravity);
    395       InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]);
    396       InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]);
    397       InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]);
    398       InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]);
    399       InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]);
    400       InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]);
    401       InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]);
    402       InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]);
    403       InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]);
     393      InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]);
     394      InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]);
     395      InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]);
     396      InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]);
     397      InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]);
     398      InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]);
     399      InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]);
     400      InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]);
     401      InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]);
    404402    }
    405403    // print InertiaTensor for debugging
     
    428426  double alpha, tmp;
    429427  Vector z_axis;
    430   z_axis.x[0] = 0.;
    431   z_axis.x[1] = 0.;
    432   z_axis.x[2] = 1.;
     428  z_axis[0] = 0.;
     429  z_axis[1] = 0.;
     430  z_axis[2] = 1.;
    433431
    434432  // rotate on z-x plane
    435433  DoLog(0) && (Log() << Verbose(0) << "Begin of Aligning all atoms." << endl);
    436   alpha = atan(-n->x[0]/n->x[2]);
     434  alpha = atan(-n->at(0)/n->at(2));
    437435  DoLog(1) && (Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... ");
    438436  while (ptr->next != end) {
    439437    ptr = ptr->next;
    440     tmp = ptr->x.x[0];
    441     ptr->x.x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];
    442     ptr->x.x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];
     438    tmp = ptr->x[0];
     439    ptr->x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->x[2];
     440    ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2];
    443441    for (int j=0;j<MDSteps;j++) {
    444       tmp = ptr->Trajectory.R.at(j).x[0];
    445       ptr->Trajectory.R.at(j).x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2];
    446       ptr->Trajectory.R.at(j).x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2];
     442      tmp = ptr->Trajectory.R.at(j)[0];
     443      ptr->Trajectory.R.at(j)[0] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];
     444      ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2];
    447445    }
    448446  }
    449447  // rotate n vector
    450   tmp = n->x[0];
    451   n->x[0] =  cos(alpha) * tmp +  sin(alpha) * n->x[2];
    452   n->x[2] = -sin(alpha) * tmp +  cos(alpha) * n->x[2];
    453   DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: ");
    454   n->Output();
    455   DoLog(0) && (Log() << Verbose(0) << endl);
     448  tmp = n->at(0);
     449  n->at(0) =  cos(alpha) * tmp +  sin(alpha) * n->at(2);
     450  n->at(2) = -sin(alpha) * tmp +  cos(alpha) * n->at(2);
     451  DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: " << n << endl);
    456452
    457453  // rotate on z-y plane
    458454  ptr = start;
    459   alpha = atan(-n->x[1]/n->x[2]);
     455  alpha = atan(-n->at(1)/n->at(2));
    460456  DoLog(1) && (Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... ");
    461457  while (ptr->next != end) {
    462458    ptr = ptr->next;
    463     tmp = ptr->x.x[1];
    464     ptr->x.x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];
    465     ptr->x.x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];
     459    tmp = ptr->x[1];
     460    ptr->x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->x[2];
     461    ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2];
    466462    for (int j=0;j<MDSteps;j++) {
    467       tmp = ptr->Trajectory.R.at(j).x[1];
    468       ptr->Trajectory.R.at(j).x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2];
    469       ptr->Trajectory.R.at(j).x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2];
     463      tmp = ptr->Trajectory.R.at(j)[1];
     464      ptr->Trajectory.R.at(j)[1] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];
     465      ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2];
    470466    }
    471467  }
    472468  // rotate n vector (for consistency check)
    473   tmp = n->x[1];
    474   n->x[1] =  cos(alpha) * tmp +  sin(alpha) * n->x[2];
    475   n->x[2] = -sin(alpha) * tmp +  cos(alpha) * n->x[2];
    476 
    477   DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: ");
    478   n->Output();
    479   DoLog(1) && (Log() << Verbose(1) << endl);
     469  tmp = n->at(1);
     470  n->at(1) =  cos(alpha) * tmp +  sin(alpha) * n->at(2);
     471  n->at(2) = -sin(alpha) * tmp +  cos(alpha) * n->at(2);
     472
     473
     474  DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: " << n << endl);
    480475  DoLog(0) && (Log() << Verbose(0) << "End of Aligning all atoms." << endl);
    481476};
     
    495490
    496491  // initialize vectors
    497   a.x[0] = gsl_vector_get(x,0);
    498   a.x[1] = gsl_vector_get(x,1);
    499   a.x[2] = gsl_vector_get(x,2);
    500   b.x[0] = gsl_vector_get(x,3);
    501   b.x[1] = gsl_vector_get(x,4);
    502   b.x[2] = gsl_vector_get(x,5);
     492  a[0] = gsl_vector_get(x,0);
     493  a[1] = gsl_vector_get(x,1);
     494  a[2] = gsl_vector_get(x,2);
     495  b[0] = gsl_vector_get(x,3);
     496  b[1] = gsl_vector_get(x,4);
     497  b[2] = gsl_vector_get(x,5);
    503498  // go through all atoms
    504499  while (ptr != par->mol->end) {
    505500    ptr = ptr->next;
    506501    if (ptr->type == ((struct lsq_params *)params)->type) { // for specific type
    507       c.CopyVector(&ptr->x);  // copy vector to temporary one
    508       c.SubtractVector(&a);   // subtract offset vector
    509       t = c.ScalarProduct(&b);           // get direction parameter
    510       d.CopyVector(&b);       // and create vector
    511       d.Scale(&t);
    512       c.SubtractVector(&d);   // ... yielding distance vector
    513       res += d.ScalarProduct((const Vector *)&d);        // add squared distance
     502      c = ptr->x - a;
     503      t = c.ScalarProduct(b);           // get direction parameter
     504      d = t*b;       // and create vector
     505      c -= d;   // ... yielding distance vector
     506      res += d.ScalarProduct(d);        // add squared distance
    514507    }
    515508  }
  • src/molecule_graph.cpp

    r632bc3 r8cbb97  
    1818#include "molecule.hpp"
    1919#include "World.hpp"
     20#include "Helpers/fast_functions.hpp"
    2021
    2122struct BFSAccounting
     
    165166                          OtherWalker = AtomMap[(*OtherRunner)->nr];
    166167//                          Log() << Verbose(0) << "Current other Atom is " << *OtherWalker << "." << endl;
    167                           const double distance = OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size);
     168                          const double distance = OtherWalker->x.PeriodicDistanceSquared(Walker->x, cell_size);
    168169//                          Log() << Verbose(1) << "Checking distance " << distance << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
    169170                          (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
  • src/molecule_template.hpp

    r632bc3 r8cbb97  
    5555  }
    5656};
     57template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&), T &t ) const
     58{
     59  atom *Walker = start;
     60  while (Walker->next != end) {
     61    Walker = Walker->next;
     62    ((Walker->node)->*f)(t);
     63  }
     64};
     65template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&) const, T &t ) const
     66{
     67  atom *Walker = start;
     68  while (Walker->next != end) {
     69    Walker = Walker->next;
     70    ((Walker->node)->*f)(t);
     71  }
     72};
    5773// two arguments
    5874template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const
  • src/moleculelist.cpp

    r632bc3 r8cbb97  
    162162        Walker = Walker->next;
    163163        counts[Walker->type->getNumber()]++;
    164         if (Walker->x.DistanceSquared(&Origin) > size)
    165           size = Walker->x.DistanceSquared(&Origin);
     164        if (Walker->x.DistanceSquared(Origin) > size)
     165          size = Walker->x.DistanceSquared(Origin);
    166166      }
    167167      // output Index, Name, number of atoms, chemical formula
     
    502502          if ((Runner->type->Z == 1) && (Runner->nr > Walker->nr) && (Binder->GetOtherAtom(Runner) != Binder->GetOtherAtom(Walker))) { // (hydrogens have only one bonding partner!)
    503503            // 4. evaluate the morse potential for each matrix component and add up
    504             distance = Runner->x.Distance(&Walker->x);
     504            distance = Runner->x.Distance(Walker->x);
    505505            //Log() << Verbose(0) << "Fragment " << (*ListRunner)->name << ": " << *Runner << "<= " << distance << "=>" << *Walker << ":" << endl;
    506506            for (int k = 0; k < a; k++) {
     
    687687    for (int k = 0; k < NDIM; k++) {
    688688      j += k + 1;
    689       BoxDimension.x[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);
    690       cell_size[j] = BoxDimension.x[k] * 2.;
     689      BoxDimension[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);
     690      cell_size[j] = BoxDimension[k] * 2.;
    691691    }
    692692    (*ListRunner)->Translate(&BoxDimension);
     
    927927  // center at set box dimensions
    928928  mol->CenterEdge(&center);
    929   World::getInstance().getDomain()[0] = center.x[0];
     929  World::getInstance().getDomain()[0] = center[0];
    930930  World::getInstance().getDomain()[1] = 0;
    931   World::getInstance().getDomain()[2] = center.x[1];
     931  World::getInstance().getDomain()[2] = center[1];
    932932  World::getInstance().getDomain()[3] = 0;
    933933  World::getInstance().getDomain()[4] = 0;
    934   World::getInstance().getDomain()[5] = center.x[2];
     934  World::getInstance().getDomain()[5] = center[2];
    935935  insert(mol);
    936936}
  • src/tesselation.cpp

    r632bc3 r8cbb97  
    1717#include "triangleintersectionlist.hpp"
    1818#include "vector.hpp"
     19#include "vector_ops.hpp"
    1920#include "verbose.hpp"
     21#include "Plane.hpp"
     22#include "Exceptions/LinearDependenceException.hpp"
    2023
    2124class molecule;
     
    234237  // have a normal vector on the base line pointing outwards
    235238  //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
    236   BaseLineCenter.CopyVector(endpoints[0]->node->node);
    237   BaseLineCenter.AddVector(endpoints[1]->node->node);
    238   BaseLineCenter.Scale(1. / 2.);
    239   BaseLine.CopyVector(endpoints[0]->node->node);
    240   BaseLine.SubtractVector(endpoints[1]->node->node);
     239  BaseLineCenter = (1./2.)*((*endpoints[0]->node->node) + (*endpoints[1]->node->node));
     240  BaseLine = (*endpoints[0]->node->node) - (*endpoints[1]->node->node);
     241
    241242  //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
    242243
     
    248249  for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    249250    //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    250     NormalCheck.AddVector(&runner->second->NormalVector);
    251     NormalCheck.Scale(sign);
     251    NormalCheck += runner->second->NormalVector;
     252    NormalCheck *= sign;
    252253    sign = -sign;
    253254    if (runner->second->NormalVector.NormSquared() > MYEPSILON)
    254       BaseLineNormal.CopyVector(&runner->second->NormalVector); // yes, copy second on top of first
     255      BaseLineNormal = runner->second->NormalVector;  // yes, copy second on top of first
    255256    else {
    256257      DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
     
    259260    if (node != NULL) {
    260261      //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
    261       helper[i].CopyVector(node->node->node);
    262       helper[i].SubtractVector(&BaseLineCenter);
    263       helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles!
     262      helper[i] = (*node->node->node) - BaseLineCenter;
     263      helper[i].MakeNormalTo(BaseLine);  // we want to compare the triangle's heights' angles!
    264264      //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    265265      i++;
     
    409409  Info FunctionInfo(__func__);
    410410  // get normal vector
    411   NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
     411  NormalVector = Plane(*(endpoints[0]->node->node),
     412                       *(endpoints[1]->node->node),
     413                       *(endpoints[2]->node->node)).getNormal();
    412414
    413415  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    414   if (NormalVector.ScalarProduct(&OtherVector) > 0.)
     416  if (NormalVector.ScalarProduct(OtherVector) > 0.)
    415417    NormalVector.Scale(-1.);
    416418  DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl);
     
    430432 * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
    431433 */
     434
    432435bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const
    433436{
     
    436439  Vector helper;
    437440
    438   if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) {
     441  try {
     442    *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x);
     443  }
     444  catch (LinearDependenceException &excp) {
     445    Log() << Verbose(1) << excp;
    439446    DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
    440447    return false;
     
    445452  DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl);
    446453
    447   if (Intersection->DistanceSquared(endpoints[0]->node->node) < MYEPSILON) {
     454  if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) {
    448455    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl);
    449456    return true;
    450   } else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
     457  }   else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) {
    451458    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl);
    452459    return true;
    453   } else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
     460  }   else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) {
    454461    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl);
    455462    return true;
     
    458465  int i = 0;
    459466  do {
    460     if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node, endpoints[(i + 2) % 3]->node->node, Intersection, &NormalVector)) {
    461       helper.CopyVector(endpoints[(i + 1) % 3]->node->node);
    462       helper.SubtractVector(endpoints[i % 3]->node->node);
    463       CrossPoint.SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector
    464       const double s = CrossPoint.ScalarProduct(&helper) / helper.NormSquared();
     467    try {
     468      CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node),
     469                                                    *(endpoints[(i+1)%3]->node->node),
     470                                                    *(endpoints[(i+2)%3]->node->node),
     471                                                    *Intersection);
     472      helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
     473      CrossPoint -= (*endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     474      const double s = CrossPoint.ScalarProduct(helper)/helper.NormSquared();
    465475      DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl);
    466       if ((s < -MYEPSILON) || ((s - 1.) > MYEPSILON)) {
     476      if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) {
    467477        DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl);
    468         i = 4;
     478        i=4;
    469479        break;
    470480      }
    471481      i++;
    472     } else
     482    } catch (LinearDependenceException &excp){
    473483      break;
     484    }
    474485  } while (i < 3);
    475486  if (i == 3) {
     
    503514  DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl);
    504515  GetCenter(&Direction);
    505   if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) {
    506     ClosestPoint->CopyVector(x);
     516  try {
     517    *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction);
     518  }
     519  catch (LinearDependenceException &excp) {
     520    (*ClosestPoint) = (*x);
    507521  }
    508522
    509523  // 2. Calculate in plane part of line (x, intersection)
    510   Vector InPlane;
    511   InPlane.CopyVector(x);
    512   InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point
    513   InPlane.ProjectOntoPlane(&NormalVector);
    514   InPlane.AddVector(ClosestPoint);
     524  Vector InPlane = (*x) - (*ClosestPoint); // points from plane intersection to straight-down point
     525  InPlane.ProjectOntoPlane(NormalVector);
     526  InPlane += *ClosestPoint;
    515527
    516528  DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl);
     
    526538  for (int i = 0; i < 3; i++) {
    527539    // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point
    528     Direction.CopyVector(endpoints[(i + 1) % 3]->node->node);
    529     Direction.SubtractVector(endpoints[i % 3]->node->node);
     540    Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node);
    530541    // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
    531     CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node);
    532     CrossDirection[i].CopyVector(&CrossPoint[i]);
    533     CrossDirection[i].SubtractVector(&InPlane);
    534     CrossPoint[i].SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector
    535     const double s = CrossPoint[i].ScalarProduct(&Direction) / Direction.NormSquared();
     542    CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node));
     543    CrossDirection[i] = CrossPoint[i] - InPlane;
     544    CrossPoint[i] -= (*endpoints[i%3]->node->node);  // cross point was returned as absolute vector
     545    const double s = CrossPoint[i].ScalarProduct(Direction)/Direction.NormSquared();
    536546    DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl);
    537     if ((s >= -MYEPSILON) && ((s - 1.) <= MYEPSILON)) {
    538       CrossPoint[i].AddVector(endpoints[i % 3]->node->node); // make cross point absolute again
     547    if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) {
     548          CrossPoint[i] += (*endpoints[i%3]->node->node); // make cross point absolute again
    539549      DoLog(2) && (Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i % 3]->node->node << " and " << *endpoints[(i + 1) % 3]->node->node << "." << endl);
    540       const double distance = CrossPoint[i].DistanceSquared(x);
     550      const double distance = CrossPoint[i].DistanceSquared(*x);
    541551      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
    542552        ShortestDistance = distance;
    543         ClosestPoint->CopyVector(&CrossPoint[i]);
     553        (*ClosestPoint) = CrossPoint[i];
    544554      }
    545555    } else
     
    548558  InsideFlag = true;
    549559  for (int i = 0; i < 3; i++) {
    550     const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 1) % 3]);
    551     const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 2) % 3]);
    552     ;
     560    const double sign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 1) % 3]);
     561    const double othersign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 2) % 3]);
     562
    553563    if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign
    554564      InsideFlag = false;
    555565  }
    556566  if (InsideFlag) {
    557     ClosestPoint->CopyVector(&InPlane);
    558     ShortestDistance = InPlane.DistanceSquared(x);
     567    (*ClosestPoint) = InPlane;
     568    ShortestDistance = InPlane.DistanceSquared(*x);
    559569  } else { // also check endnodes
    560570    for (int i = 0; i < 3; i++) {
    561       const double distance = x->DistanceSquared(endpoints[i]->node->node);
     571      const double distance = x->DistanceSquared(*endpoints[i]->node->node);
    562572      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
    563573        ShortestDistance = distance;
    564         ClosestPoint->CopyVector(endpoints[i]->node->node);
     574        (*ClosestPoint) = (*endpoints[i]->node->node);
    565575      }
    566576    }
     
    667677  center->Zero();
    668678  for (int i = 0; i < 3; i++)
    669     center->AddVector(endpoints[i]->node->node);
     679    (*center) += (*endpoints[i]->node->node);
    670680  center->Scale(1. / 3.);
    671681  DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl);
     
    733743  int counter = 0;
    734744  for (; Runner[2] != endpoints.end();) {
    735     TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node);
     745    TemporaryNormal = Plane(*((*Runner[0])->node->node),
     746                            *((*Runner[1])->node->node),
     747                            *((*Runner[2])->node->node)).getNormal();
    736748    for (int i = 0; i < 3; i++) // increase each of them
    737749      Runner[i]++;
    738     TotalNormal->AddVector(&TemporaryNormal);
     750    (*TotalNormal) += TemporaryNormal;
    739751  }
    740752  TotalNormal->Scale(1. / (double) counter);
    741753
    742754  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
    743   if (TotalNormal->ScalarProduct(&OtherVector) > 0.)
     755  if (TotalNormal->ScalarProduct(OtherVector) > 0.)
    744756    TotalNormal->Scale(-1.);
    745757  DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl);
     
    758770  center->Zero();
    759771  int counter = 0;
    760   for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
    761     center->AddVector((*Runner)->node->node);
     772  for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     773    (*center) += (*(*Runner)->node->node);
    762774    counter++;
    763775  }
     
    10201032  BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
    10211033{
    1022   Info FunctionInfo(__func__);
    1023   OptCenter.CopyVector(&OptCandidateCenter);
    1024   OtherOptCenter.CopyVector(&OtherOptCandidateCenter);
    1025 }
    1026 ;
     1034        Info FunctionInfo(__func__);
     1035  OptCenter = OptCandidateCenter;
     1036  OtherOptCenter = OtherOptCandidateCenter;
     1037};
     1038
    10271039
    10281040/** Destructor for class CandidateForTesselation.
     
    10551067  for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
    10561068    for (int i = 0; i < 2; i++) {
    1057       const double distance = fabs((*VRunner)->DistanceSquared(BaseLine->endpoints[i]->node->node) - radiusSquared);
     1069      const double distance = fabs((*VRunner)->DistanceSquared(*BaseLine->endpoints[i]->node->node) - radiusSquared);
    10581070      if (distance > HULLEPSILON) {
    10591071        DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
     
    10671079    const TesselPoint *Walker = *Runner;
    10681080    for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
    1069       const double distance = fabs((*VRunner)->DistanceSquared(Walker->node) - radiusSquared);
     1081      const double distance = fabs((*VRunner)->DistanceSquared(*Walker->node) - radiusSquared);
    10701082      if (distance > HULLEPSILON) {
    10711083        DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
     
    10851097    DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl);
    10861098    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    1087       DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&OtherOptCenter) << "." << endl);
     1099      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(OtherOptCenter) << "." << endl);
    10881100
    10891101    // remove baseline's endpoints and candidates
     
    11071119    // check with animate_sphere.tcl VMD script
    11081120    if (ThirdPoint != NULL) {
    1109       DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl);
     1121      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
    11101122    } else {
    11111123      DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl);
    1112       DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl);
     1124      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
    11131125    }
    11141126  }
     
    11791191  int num = 0;
    11801192  for (GoToFirst(); (!IsEnd()); GoToNext()) {
    1181     Center->AddVector(GetPoint()->node);
     1193    (*Center) += (*GetPoint()->node);
    11821194    num++;
    11831195  }
     
    12961308      C++;
    12971309      for (; C != PointsOnBoundary.end(); C++) {
    1298         tmp = A->second->node->node->DistanceSquared(B->second->node->node);
     1310        tmp = A->second->node->node->DistanceSquared(*B->second->node->node);
    12991311        distance = tmp * tmp;
    1300         tmp = A->second->node->node->DistanceSquared(C->second->node->node);
     1312        tmp = A->second->node->node->DistanceSquared(*C->second->node->node);
    13011313        distance += tmp * tmp;
    1302         tmp = B->second->node->node->DistanceSquared(C->second->node->node);
     1314        tmp = B->second->node->node->DistanceSquared(*C->second->node->node);
    13031315        distance += tmp * tmp;
    13041316        DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
     
    13191331    // 2. next, we have to check whether all points reside on only one side of the triangle
    13201332    // 3. construct plane vector
    1321     PlaneVector.MakeNormalVector(A->second->node->node, baseline->second.first->second->node->node, baseline->second.second->second->node->node);
     1333    PlaneVector = Plane(*A->second->node->node,
     1334                        *baseline->second.first->second->node->node,
     1335                        *baseline->second.second->second->node->node).getNormal();
    13221336    DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl);
    13231337    // 4. loop over all points
     
    13291343        continue;
    13301344      // 4a. project onto plane vector
    1331       TrialVector.CopyVector(checker->second->node->node);
    1332       TrialVector.SubtractVector(A->second->node->node);
    1333       distance = TrialVector.ScalarProduct(&PlaneVector);
     1345      TrialVector = (*checker->second->node->node);
     1346      TrialVector.SubtractVector(*A->second->node->node);
     1347      distance = TrialVector.ScalarProduct(PlaneVector);
    13341348      if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
    13351349        continue;
     
    13461360      }
    13471361      // 4d. Check whether the point is inside the triangle (check distance to each node
    1348       tmp = checker->second->node->node->DistanceSquared(A->second->node->node);
     1362      tmp = checker->second->node->node->DistanceSquared(*A->second->node->node);
    13491363      int innerpoint = 0;
    1350       if ((tmp < A->second->node->node->DistanceSquared(baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))
     1364      if ((tmp < A->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(*baseline->second.second->second->node->node)))
    13511365        innerpoint++;
    1352       tmp = checker->second->node->node->DistanceSquared(baseline->second.first->second->node->node);
    1353       if ((tmp < baseline->second.first->second->node->node->DistanceSquared(A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))
     1366      tmp = checker->second->node->node->DistanceSquared(*baseline->second.first->second->node->node);
     1367      if ((tmp < baseline->second.first->second->node->node->DistanceSquared(*A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(*baseline->second.second->second->node->node)))
    13541368        innerpoint++;
    1355       tmp = checker->second->node->node->DistanceSquared(baseline->second.second->second->node->node);
    1356       if ((tmp < baseline->second.second->second->node->node->DistanceSquared(baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(A->second->node->node)))
     1369      tmp = checker->second->node->node->DistanceSquared(*baseline->second.second->second->node->node);
     1370      if ((tmp < baseline->second.second->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(*A->second->node->node)))
    13571371        innerpoint++;
    13581372      // 4e. If so, break 4. loop and continue with next candidate in 1. loop
     
    14351449        // prepare some auxiliary vectors
    14361450        Vector BaseLineCenter, BaseLine;
    1437         BaseLineCenter.CopyVector(baseline->second->endpoints[0]->node->node);
    1438         BaseLineCenter.AddVector(baseline->second->endpoints[1]->node->node);
    1439         BaseLineCenter.Scale(1. / 2.); // points now to center of base line
    1440         BaseLine.CopyVector(baseline->second->endpoints[0]->node->node);
    1441         BaseLine.SubtractVector(baseline->second->endpoints[1]->node->node);
     1451        BaseLineCenter = 0.5 * ((*baseline->second->endpoints[0]->node->node) +
     1452                                (*baseline->second->endpoints[1]->node->node));
     1453        BaseLine = (*baseline->second->endpoints[0]->node->node) - (*baseline->second->endpoints[1]->node->node);
    14421454
    14431455        // offset to center of triangle
    14441456        CenterVector.Zero();
    14451457        for (int i = 0; i < 3; i++)
    1446           CenterVector.AddVector(BTS->endpoints[i]->node->node);
     1458          CenterVector += (*BTS->endpoints[i]->node->node);
    14471459        CenterVector.Scale(1. / 3.);
    14481460        DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl);
    14491461
    14501462        // normal vector of triangle
    1451         NormalVector.CopyVector(Center);
    1452         NormalVector.SubtractVector(&CenterVector);
     1463        NormalVector = (*Center) - CenterVector;
    14531464        BTS->GetNormalVector(NormalVector);
    1454         NormalVector.CopyVector(&BTS->NormalVector);
     1465        NormalVector = BTS->NormalVector;
    14551466        DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl);
    14561467
    14571468        // vector in propagation direction (out of triangle)
    14581469        // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
    1459         PropagationVector.MakeNormalVector(&BaseLine, &NormalVector);
    1460         TempVector.CopyVector(&CenterVector);
    1461         TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
     1470        PropagationVector = Plane(BaseLine, NormalVector,0).getNormal();
     1471        TempVector = CenterVector - (*baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
    14621472        //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
    1463         if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
     1473        if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline
    14641474          PropagationVector.Scale(-1.);
    14651475        DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl);
     
    14721482
    14731483            // first check direction, so that triangles don't intersect
    1474             VirtualNormalVector.CopyVector(target->second->node->node);
    1475             VirtualNormalVector.SubtractVector(&BaseLineCenter); // points from center of base line to target
    1476             VirtualNormalVector.ProjectOntoPlane(&NormalVector);
    1477             TempAngle = VirtualNormalVector.Angle(&PropagationVector);
     1484            VirtualNormalVector = (*target->second->node->node) - BaseLineCenter;
     1485            VirtualNormalVector.ProjectOntoPlane(NormalVector);
     1486            TempAngle = VirtualNormalVector.Angle(PropagationVector);
    14781487            DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl);
    14791488            if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees)
     
    15021511
    15031512            // check for linear dependence
    1504             TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
    1505             TempVector.SubtractVector(target->second->node->node);
    1506             helper.CopyVector(baseline->second->endpoints[1]->node->node);
    1507             helper.SubtractVector(target->second->node->node);
    1508             helper.ProjectOntoPlane(&TempVector);
     1513            TempVector = (*baseline->second->endpoints[0]->node->node) - (*target->second->node->node);
     1514            helper = (*baseline->second->endpoints[1]->node->node) - (*target->second->node->node);
     1515            helper.ProjectOntoPlane(TempVector);
    15091516            if (fabs(helper.NormSquared()) < MYEPSILON) {
    15101517              DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl);
     
    15141521            // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle
    15151522            flag = true;
    1516             VirtualNormalVector.MakeNormalVector(baseline->second->endpoints[0]->node->node, baseline->second->endpoints[1]->node->node, target->second->node->node);
    1517             TempVector.CopyVector(baseline->second->endpoints[0]->node->node);
    1518             TempVector.AddVector(baseline->second->endpoints[1]->node->node);
    1519             TempVector.AddVector(target->second->node->node);
    1520             TempVector.Scale(1. / 3.);
    1521             TempVector.SubtractVector(Center);
     1523            VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node),
     1524                                        *(baseline->second->endpoints[1]->node->node),
     1525                                        *(target->second->node->node)).getNormal();
     1526            TempVector = (1./3.) * ((*baseline->second->endpoints[0]->node->node) +
     1527                                    (*baseline->second->endpoints[1]->node->node) +
     1528                                    (*target->second->node->node));
     1529            TempVector -= (*Center);
    15221530            // make it always point outward
    1523             if (VirtualNormalVector.ScalarProduct(&TempVector) < 0)
     1531            if (VirtualNormalVector.ScalarProduct(TempVector) < 0)
    15241532              VirtualNormalVector.Scale(-1.);
    15251533            // calculate angle
    1526             TempAngle = NormalVector.Angle(&VirtualNormalVector);
     1534            TempAngle = NormalVector.Angle(VirtualNormalVector);
    15271535            DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl);
    15281536            if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
     
    15321540            } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
    15331541              // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
    1534               helper.CopyVector(target->second->node->node);
    1535               helper.SubtractVector(&BaseLineCenter);
    1536               helper.ProjectOntoPlane(&BaseLine);
     1542              helper = (*target->second->node->node) - BaseLineCenter;
     1543              helper.ProjectOntoPlane(BaseLine);
    15371544              // ...the one with the smaller angle is the better candidate
    1538               TempVector.CopyVector(target->second->node->node);
    1539               TempVector.SubtractVector(&BaseLineCenter);
    1540               TempVector.ProjectOntoPlane(&VirtualNormalVector);
    1541               TempAngle = TempVector.Angle(&helper);
    1542               TempVector.CopyVector(winner->second->node->node);
    1543               TempVector.SubtractVector(&BaseLineCenter);
    1544               TempVector.ProjectOntoPlane(&VirtualNormalVector);
    1545               if (TempAngle < TempVector.Angle(&helper)) {
    1546                 TempAngle = NormalVector.Angle(&VirtualNormalVector);
     1545              TempVector = (*target->second->node->node) - BaseLineCenter;
     1546              TempVector.ProjectOntoPlane(VirtualNormalVector);
     1547              TempAngle = TempVector.Angle(helper);
     1548              TempVector = (*winner->second->node->node) - BaseLineCenter;
     1549              TempVector.ProjectOntoPlane(VirtualNormalVector);
     1550              if (TempAngle < TempVector.Angle(helper)) {
     1551                TempAngle = NormalVector.Angle(VirtualNormalVector);
    15471552                SmallestAngle = TempAngle;
    15481553                winner = target;
     
    15811586          BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    15821587          BTS->GetCenter(&helper);
    1583           helper.SubtractVector(Center);
    1584           helper.Scale(-1);
     1588          helper -= (*Center);
     1589          helper *= -1;
    15851590          BTS->GetNormalVector(helper);
    15861591          TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
     
    16401645      DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl);
    16411646      // we have the intersection, check whether in- or outside of boundary
    1642       if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {
     1647      if ((Center->DistanceSquared(*Walker->node) - Center->DistanceSquared(Intersection)) < -MYEPSILON) {
    16431648        // inside, next!
    16441649        DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl);
     
    16531658          OldPoints[i] = BTS->endpoints[i];
    16541659        }
    1655         Normal.CopyVector(&BTS->NormalVector);
     1660        Normal = BTS->NormalVector;
    16561661        // add Walker to boundary points
    16571662        DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl);
     
    18001805        // get open line
    18011806        for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) {
    1802           if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(&Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
     1807          if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
    18031808            DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl);
    18041809            insertNewLine = false;
     
    20392044  bool flag = true;
    20402045
    2041   DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter.x[0] << " " << CandidateLine.OtherOptCenter.x[1] << " " << CandidateLine.OtherOptCenter.x[2] << "} radius " << RADIUS << " resolution 30" << endl);
     2046  DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter[0] << " " << CandidateLine.OtherOptCenter[1] << " " << CandidateLine.OtherOptCenter[2] << "} radius " << RADIUS << " resolution 30" << endl);
    20422047  // get all points inside the sphere
    20432048  TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter);
     
    20452050  DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
    20462051  for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    2047     DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl);
     2052    DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(CandidateLine.OtherOptCenter) << "." << endl);
    20482053
    20492054  // remove triangles's endpoints
     
    20612066    DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
    20622067    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
    2063       DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl);
     2068      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(CandidateLine.OtherOptCenter) << "." << endl);
    20642069  }
    20652070  delete (ListofPoints);
     
    22152220        if (List != NULL) {
    22162221          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    2217             if ((*Runner)->node->x[i] > maxCoordinate[i]) {
     2222            if ((*Runner)->node->at(i) > maxCoordinate[i]) {
    22182223              DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl);
    2219               maxCoordinate[i] = (*Runner)->node->x[i];
     2224              maxCoordinate[i] = (*Runner)->node->at(i);
    22202225              MaxPoint[i] = (*Runner);
    22212226            }
     
    22352240  for (int k = 0; k < NDIM; k++) {
    22362241    NormalVector.Zero();
    2237     NormalVector.x[k] = 1.;
     2242    NormalVector[k] = 1.;
    22382243    BaseLine = new BoundaryLineSet();
    22392244    BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
     
    22532258
    22542259    // construct center of circle
    2255     CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node);
    2256     CircleCenter.AddVector(BaseLine->endpoints[1]->node->node);
    2257     CircleCenter.Scale(0.5);
     2260    CircleCenter = 0.5 * ((*BaseLine->endpoints[0]->node->node) + (*BaseLine->endpoints[1]->node->node));
    22582261
    22592262    // construct normal vector of circle
    2260     CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node);
    2261     CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node);
     2263    CirclePlaneNormal = (*BaseLine->endpoints[0]->node->node) - (*BaseLine->endpoints[1]->node->node);
    22622264
    22632265    double radius = CirclePlaneNormal.NormSquared();
    22642266    double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.);
    22652267
    2266     NormalVector.ProjectOntoPlane(&CirclePlaneNormal);
     2268    NormalVector.ProjectOntoPlane(CirclePlaneNormal);
    22672269    NormalVector.Normalize();
    22682270    ShortestAngle = 2. * M_PI; // This will indicate the quadrant.
    22692271
    2270     SphereCenter.CopyVector(&NormalVector);
    2271     SphereCenter.Scale(CircleRadius);
    2272     SphereCenter.AddVector(&CircleCenter);
     2272    SphereCenter = (CircleRadius * NormalVector) +  CircleCenter;
    22732273    // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
    22742274
    22752275    // look in one direction of baseline for initial candidate
    2276     SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector); // whether we look "left" first or "right" first is not important ...
     2276    SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal(); // whether we look "left" first or "right" first is not important ...
    22772277
    22782278    // adding point 1 and point 2 and add the line between them
     
    24782478
    24792479  // construct center of circle
    2480   CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2481   CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    2482   CircleCenter.Scale(0.5);
     2480  CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
     2481                        (*CandidateLine.BaseLine->endpoints[1]->node->node));
    24832482
    24842483  // construct normal vector of circle
    2485   CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    2486   CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
     2484  CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
     2485                      (*CandidateLine.BaseLine->endpoints[1]->node->node);
    24872486
    24882487  // calculate squared radius of circle
    2489   radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
     2488  radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal);
    24902489  if (radius / 4. < RADIUS * RADIUS) {
    24912490    // construct relative sphere center with now known CircleCenter
    2492     RelativeSphereCenter.CopyVector(&T.SphereCenter);
    2493     RelativeSphereCenter.SubtractVector(&CircleCenter);
     2491    RelativeSphereCenter = T.SphereCenter - CircleCenter;
    24942492
    24952493    CircleRadius = RADIUS * RADIUS - radius / 4.;
     
    25002498
    25012499    // construct SearchDirection and an "outward pointer"
    2502     SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
    2503     helper.CopyVector(&CircleCenter);
    2504     helper.SubtractVector(ThirdPoint->node->node);
    2505     if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
     2500    SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal();
     2501    helper = CircleCenter - (*ThirdPoint->node->node);
     2502    if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
    25062503      SearchDirection.Scale(-1.);
    25072504    DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
    2508     if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
     2505    if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) {
    25092506      // rotated the wrong way!
    25102507      DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
     
    26432640        Finder->second->pointlist.push_back(Sprinter);
    26442641        Finder->second->ShortestAngle = 0.;
    2645         Finder->second->OptCenter.CopyVector(OptCenter);
     2642        Finder->second->OptCenter = *OptCenter;
    26462643      }
    26472644    }
     
    26782675  // create normal vector
    26792676  BTS->GetCenter(&Center);
    2680   Center.SubtractVector(&CandidateLine.OptCenter);
    2681   BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
     2677  Center -= CandidateLine.OptCenter;
     2678  BTS->SphereCenter = CandidateLine.OptCenter;
    26822679  BTS->GetNormalVector(Center);
    26832680  // give some verbose output about the whole procedure
     
    27122709  AddTesselationTriangle();
    27132710
    2714   BTS->SphereCenter.CopyVector(&CandidateLine.OtherOptCenter);
     2711  BTS->SphereCenter = CandidateLine.OtherOptCenter;
    27152712  // create normal vector in other direction
    2716   BTS->GetNormalVector(&triangle->NormalVector);
     2713  BTS->GetNormalVector(triangle->NormalVector);
    27172714  BTS->NormalVector.Scale(-1.);
    27182715  // give some verbose output about the whole procedure
     
    27572754  // create normal vector
    27582755  BTS->GetCenter(&Center);
    2759   Center.SubtractVector(OptCenter);
    2760   BTS->SphereCenter.CopyVector(OptCenter);
     2756  Center.SubtractVector(*OptCenter);
     2757  BTS->SphereCenter = *OptCenter;
    27612758  BTS->GetNormalVector(Center);
    27622759
     
    28022799  Vector DistanceToIntersection[2], BaseLine;
    28032800  double distance[2];
    2804   BaseLine.CopyVector(Base->endpoints[1]->node->node);
    2805   BaseLine.SubtractVector(Base->endpoints[0]->node->node);
     2801  BaseLine = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node);
    28062802  for (int i = 0; i < 2; i++) {
    2807     DistanceToIntersection[i].CopyVector(ClosestPoint);
    2808     DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node);
    2809     distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]);
     2803    DistanceToIntersection[i] = (*ClosestPoint) - (*Base->endpoints[i]->node->node);
     2804    distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]);
    28102805  }
    28112806  delete (ClosestPoint);
     
    28832878
    28842879  // get the distance vector from Base line to OtherBase line
    2885   Vector Distance;
    2886   Distance.CopyVector(ClosestPoint[1]);
    2887   Distance.SubtractVector(ClosestPoint[0]);
     2880  Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]);
    28882881
    28892882  // calculate volume
     
    29062899    }
    29072900    for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2908       DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
    2909       BaseLineNormal.AddVector(&(runner->second->NormalVector));
     2901    DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
     2902      BaseLineNormal += (runner->second->NormalVector);
    29102903    }
    29112904    BaseLineNormal.Scale(1. / 2.);
    29122905
    2913     if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
     2906    if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
    29142907      DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl);
    29152908      // calculate volume summand as a general tetraeder
     
    29472940  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    29482941    DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
    2949     BaseLineNormal.AddVector(&(runner->second->NormalVector));
     2942    BaseLineNormal += (runner->second->NormalVector);
    29502943  }
    29512944  BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
     
    30873080              double distance, scaleFactor;
    30883081
    3089               OrthogonalizedOben.CopyVector(&Oben);
    3090               aCandidate.CopyVector(a->node);
    3091               aCandidate.SubtractVector(Candidate->node);
    3092               OrthogonalizedOben.ProjectOntoPlane(&aCandidate);
     3082              OrthogonalizedOben = Oben;
     3083              aCandidate = (*a->node) - (*Candidate->node);
     3084              OrthogonalizedOben.ProjectOntoPlane(aCandidate);
    30933085              OrthogonalizedOben.Normalize();
    30943086              distance = 0.5 * aCandidate.Norm();
     
    30963088              OrthogonalizedOben.Scale(scaleFactor);
    30973089
    3098               Center.CopyVector(Candidate->node);
    3099               Center.AddVector(a->node);
    3100               Center.Scale(0.5);
    3101               Center.AddVector(&OrthogonalizedOben);
    3102 
    3103               AngleCheck.CopyVector(&Center);
    3104               AngleCheck.SubtractVector(a->node);
     3090              Center = 0.5 * ((*Candidate->node) + (*a->node));
     3091              Center += OrthogonalizedOben;
     3092
     3093              AngleCheck = Center - (*a->node);
    31053094              norm = aCandidate.Norm();
    31063095              // second point shall have smallest angle with respect to Oben vector
    31073096              if (norm < RADIUS * 2.) {
    3108                 angle = AngleCheck.Angle(&Oben);
     3097                angle = AngleCheck.Angle(Oben);
    31093098                if (angle < Storage[0]) {
    31103099                  //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
     
    31823171
    31833172  // copy old center
    3184   CandidateLine.OldCenter.CopyVector(&OldSphereCenter);
     3173  CandidateLine.OldCenter = OldSphereCenter;
    31853174  CandidateLine.ThirdPoint = ThirdPoint;
    31863175  CandidateLine.pointlist.clear();
    31873176
    31883177  // construct center of circle
    3189   CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    3190   CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    3191   CircleCenter.Scale(0.5);
     3178  CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) +
     3179                        (*CandidateLine.BaseLine->endpoints[1]->node->node));
    31923180
    31933181  // construct normal vector of circle
    3194   CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
    3195   CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    3196 
    3197   RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
    3198   RelativeOldSphereCenter.SubtractVector(&CircleCenter);
     3182  CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) -
     3183                      (*CandidateLine.BaseLine->endpoints[1]->node->node);
     3184
     3185  RelativeOldSphereCenter = OldSphereCenter - CircleCenter;
    31993186
    32003187  // calculate squared radius TesselPoint *ThirdPoint,f circle
     
    32063193
    32073194    // test whether old center is on the band's plane
    3208     if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
    3209       DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl);
    3210       RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
     3195    if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) {
     3196      DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) << "!" << endl);
     3197      RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal);
    32113198    }
    32123199    radius = RelativeOldSphereCenter.NormSquared();
     
    32163203      // check SearchDirection
    32173204      DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
    3218       if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
     3205      if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
    32193206        DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);
    32203207      }
     
    32543241                  DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl);
    32553242
    3256                   if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)) {
     3243                  try {
     3244                    NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node),
     3245                                            *(CandidateLine.BaseLine->endpoints[1]->node->node),
     3246                                            *(Candidate->node)).getNormal();
    32573247                    DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl);
    3258                     radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter);
     3248                    radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(NewPlaneCenter);
    32593249                    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
    32603250                    DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
    32613251                    DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl);
    32623252                    if (radius < RADIUS * RADIUS) {
    3263                       otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter);
     3253                      otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(NewPlaneCenter);
    32643254                      if (fabs(radius - otherradius) < HULLEPSILON) {
    32653255                        // construct both new centers
    3266                         NewSphereCenter.CopyVector(&NewPlaneCenter);
    3267                         OtherNewSphereCenter.CopyVector(&NewPlaneCenter);
    3268                         helper.CopyVector(&NewNormalVector);
     3256                        NewSphereCenter = NewPlaneCenter;
     3257                        OtherNewSphereCenter= NewPlaneCenter;
     3258                        helper = NewNormalVector;
    32693259                        helper.Scale(sqrt(RADIUS * RADIUS - radius));
    32703260                        DoLog(2) && (Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl);
    3271                         NewSphereCenter.AddVector(&helper);
     3261                        NewSphereCenter += helper;
    32723262                        DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl);
    32733263                        // OtherNewSphereCenter is created by the same vector just in the other direction
    32743264                        helper.Scale(-1.);
    3275                         OtherNewSphereCenter.AddVector(&helper);
     3265                        OtherNewSphereCenter += helper;
    32763266                        DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl);
    3277 
    32783267                        alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    32793268                        Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    32803269                        if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid
    3281                           if (OldSphereCenter.DistanceSquared(&NewSphereCenter) < OldSphereCenter.DistanceSquared(&OtherNewSphereCenter))
     3270                          if (OldSphereCenter.DistanceSquared(NewSphereCenter) < OldSphereCenter.DistanceSquared(OtherNewSphereCenter))
    32823271                            alpha = Otheralpha;
    32833272                        } else
    32843273                          alpha = min(alpha, Otheralpha);
    3285 
    32863274                        // if there is a better candidate, drop the current list and add the new candidate
    32873275                        // otherwise ignore the new candidate and keep the list
    32883276                        if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
    32893277                          if (fabs(alpha - Otheralpha) > MYEPSILON) {
    3290                             CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
    3291                             CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     3278                            CandidateLine.OptCenter = NewSphereCenter;
     3279                            CandidateLine.OtherOptCenter = OtherNewSphereCenter;
    32923280                          } else {
    3293                             CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
    3294                             CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     3281                            CandidateLine.OptCenter = OtherNewSphereCenter;
     3282                            CandidateLine.OtherOptCenter = NewSphereCenter;
    32953283                          }
    32963284                          // if there is an equal candidate, add it to the list without clearing the list
     
    33193307                      DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl);
    33203308                    }
    3321                   } else {
    3322                     DoLog(1) && (Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl);
     3309                  }
     3310                  catch (LinearDependenceException &excp){
     3311                    Log() << Verbose(1) << excp;
     3312                    Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
    33233313                  }
    33243314                } else {
     
    34163406            FindPoint = PointsOnBoundary.find((*Runner)->nr);
    34173407            if (FindPoint != PointsOnBoundary.end()) {
    3418               points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(x), FindPoint->second));
     3408              points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(*x), FindPoint->second));
    34193409              DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl);
    34203410            }
     
    34603450    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
    34613451      // calculate closest point on line to desired point
    3462       helper.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3463       helper.AddVector((LineRunner->second)->endpoints[1]->node->node);
    3464       helper.Scale(0.5);
    3465       Center.CopyVector(x);
    3466       Center.SubtractVector(&helper);
    3467       BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3468       BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3469       Center.ProjectOntoPlane(&BaseLine);
     3452      helper = 0.5 * ((*(LineRunner->second)->endpoints[0]->node->node) +
     3453                      (*(LineRunner->second)->endpoints[1]->node->node));
     3454      Center = (*x) - helper;
     3455      BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
     3456                 (*(LineRunner->second)->endpoints[1]->node->node);
     3457      Center.ProjectOntoPlane(BaseLine);
    34703458      const double distance = Center.NormSquared();
    34713459      if ((ClosestLine == NULL) || (distance < MinDistance)) {
    34723460        // additionally calculate intersection on line (whether it's on the line section or not)
    3473         helper.CopyVector(x);
    3474         helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
    3475         helper.SubtractVector(&Center);
    3476         const double lengthA = helper.ScalarProduct(&BaseLine);
    3477         helper.CopyVector(x);
    3478         helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3479         helper.SubtractVector(&Center);
    3480         const double lengthB = helper.ScalarProduct(&BaseLine);
     3461        helper = (*x) - (*(LineRunner->second)->endpoints[0]->node->node) - Center;
     3462        const double lengthA = helper.ScalarProduct(BaseLine);
     3463        helper = (*x) - (*(LineRunner->second)->endpoints[1]->node->node) - Center;
     3464        const double lengthB = helper.ScalarProduct(BaseLine);
    34813465        if (lengthB * lengthA < 0) { // if have different sign
    34823466          ClosestLine = LineRunner->second;
     
    35273511    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
    35283512
    3529       BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
    3530       BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3513      BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) -
     3514                 (*(LineRunner->second)->endpoints[1]->node->node);
    35313515      const double lengthBase = BaseLine.NormSquared();
    35323516
    3533       BaseLineIntersection.CopyVector(x);
    3534       BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
     3517      BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[0]->node->node);
    35353518      const double lengthEndA = BaseLineIntersection.NormSquared();
    35363519
    3537       BaseLineIntersection.CopyVector(x);
    3538       BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3520      BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
    35393521      const double lengthEndB = BaseLineIntersection.NormSquared();
    35403522
     
    35543536      } else { // intersection is closer, calculate
    35553537        // calculate closest point on line to desired point
    3556         BaseLineIntersection.CopyVector(x);
    3557         BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
    3558         Center.CopyVector(&BaseLineIntersection);
    3559         Center.ProjectOntoPlane(&BaseLine);
    3560         BaseLineIntersection.SubtractVector(&Center);
     3538        BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node);
     3539        Center = BaseLineIntersection;
     3540        Center.ProjectOntoPlane(BaseLine);
     3541        BaseLineIntersection -= Center;
    35613542        const double distance = BaseLineIntersection.NormSquared();
    35623543        if (Center.NormSquared() > BaseLine.NormSquared()) {
     
    36123593  for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
    36133594    (*Runner)->GetCenter(&Center);
    3614     helper.CopyVector(x);
    3615     helper.SubtractVector(&Center);
    3616     const double Alignment = helper.Angle(&(*Runner)->NormalVector);
     3595    helper = (*x) - Center;
     3596    const double Alignment = helper.Angle((*Runner)->NormalVector);
    36173597    if (Alignment < MinAlignment) {
    36183598      result = *Runner;
     
    36813661  triangle->GetCenter(&Center);
    36823662  DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl);
    3683   DistanceToCenter.CopyVector(&Center);
    3684   DistanceToCenter.SubtractVector(&Point);
     3663  DistanceToCenter = Center - Point;
    36853664  DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl);
    36863665
    36873666  // check whether we are on boundary
    3688   if (fabs(DistanceToCenter.ScalarProduct(&triangle->NormalVector)) < MYEPSILON) {
     3667  if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) {
    36893668    // calculate whether inside of triangle
    3690     DistanceToCenter.CopyVector(&Point);
    3691     Center.CopyVector(&Point);
    3692     Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter
    3693     DistanceToCenter.AddVector(&triangle->NormalVector); // points outside
     3669    DistanceToCenter = Point + triangle->NormalVector; // points outside
     3670    Center = Point - triangle->NormalVector; // points towards MolCenter
    36943671    DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl);
    36953672    if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
     
    37063683
    37073684    // then check direction to boundary
    3708     if (DistanceToCenter.ScalarProduct(&triangle->NormalVector) > MYEPSILON) {
     3685    if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) {
    37093686      DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl);
    37103687      return -distance;
     
    38403817  if ((triangles != NULL) && (!triangles->empty())) {
    38413818    for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    3842       PlaneNormal.AddVector(&(*Runner)->NormalVector);
     3819      PlaneNormal += (*Runner)->NormalVector;
    38433820  } else {
    38443821    DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);
     
    38513828  // construct one orthogonal vector
    38523829  if (Reference != NULL) {
    3853     AngleZero.CopyVector(Reference);
    3854     AngleZero.SubtractVector(Point->node);
    3855     AngleZero.ProjectOntoPlane(&PlaneNormal);
     3830    AngleZero = (*Reference) - (*Point->node);
     3831    AngleZero.ProjectOntoPlane(PlaneNormal);
    38563832  }
    38573833  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
    38583834    DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
    3859     AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    3860     AngleZero.SubtractVector(Point->node);
    3861     AngleZero.ProjectOntoPlane(&PlaneNormal);
     3835    AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
     3836    AngleZero.ProjectOntoPlane(PlaneNormal);
    38623837    if (AngleZero.NormSquared() < MYEPSILON) {
    38633838      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
     
    38673842  DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
    38683843  if (AngleZero.NormSquared() > MYEPSILON)
    3869     OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
     3844    OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
    38703845  else
    3871     OrthogonalVector.MakeNormalVector(&PlaneNormal);
     3846    OrthogonalVector.MakeNormalTo(PlaneNormal);
    38723847  DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
    38733848
    38743849  // go through all connected points and calculate angle
    38753850  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    3876     helper.CopyVector((*listRunner)->node);
    3877     helper.SubtractVector(Point->node);
    3878     helper.ProjectOntoPlane(&PlaneNormal);
     3851    helper = (*(*listRunner)->node) - (*Point->node);
     3852    helper.ProjectOntoPlane(PlaneNormal);
    38793853    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    38803854    DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl);
     
    39343908  int counter = 0;
    39353909  while (TesselC != SetOfNeighbours->end()) {
    3936     helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node);
     3910    helper = Plane(*((*TesselA)->node),
     3911                   *((*TesselB)->node),
     3912                   *((*TesselC)->node)).getNormal();
    39373913    DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl);
    39383914    counter++;
     
    39403916    TesselB++;
    39413917    TesselC++;
    3942     PlaneNormal.AddVector(&helper);
     3918    PlaneNormal += helper;
    39433919  }
    39443920  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
     
    39553931  // construct one orthogonal vector
    39563932  if (Reference != NULL) {
    3957     AngleZero.CopyVector(Reference);
    3958     AngleZero.SubtractVector(Point->node);
    3959     AngleZero.ProjectOntoPlane(&PlaneNormal);
    3960   }
    3961   if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
     3933    AngleZero = (*Reference) - (*Point->node);
     3934    AngleZero.ProjectOntoPlane(PlaneNormal);
     3935  }
     3936  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
    39623937    DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
    3963     AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    3964     AngleZero.SubtractVector(Point->node);
    3965     AngleZero.ProjectOntoPlane(&PlaneNormal);
     3938    AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node);
     3939    AngleZero.ProjectOntoPlane(PlaneNormal);
    39663940    if (AngleZero.NormSquared() < MYEPSILON) {
    39673941      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
     
    39713945  DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
    39723946  if (AngleZero.NormSquared() > MYEPSILON)
    3973     OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
     3947    OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
    39743948  else
    3975     OrthogonalVector.MakeNormalVector(&PlaneNormal);
     3949    OrthogonalVector.MakeNormalTo(PlaneNormal);
    39763950  DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
    39773951
     
    39793953  pair<map<double, TesselPoint*>::iterator, bool> InserterTest;
    39803954  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    3981     helper.CopyVector((*listRunner)->node);
    3982     helper.SubtractVector(Point->node);
    3983     helper.ProjectOntoPlane(&PlaneNormal);
     3955    helper = (*(*listRunner)->node) - (*Point->node);
     3956    helper.ProjectOntoPlane(PlaneNormal);
    39843957    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    39853958    if (angle > M_PI) // the correction is of no use here (and not desired)
     
    42254198
    42264199  // copy old location for the volume
    4227   OldPoint.CopyVector(point->node->node);
     4200  OldPoint = (*point->node->node);
    42284201
    42294202  // get list of connected points
     
    42534226  for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
    42544227    DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl);
    4255     NormalVector.SubtractVector(&Runner->second->NormalVector); // has to point inward
     4228    NormalVector -= Runner->second->NormalVector; // has to point inward
    42564229    RemoveTesselationTriangle(Runner->second);
    42574230    count++;
     
    42884261          StartNode--;
    42894262          //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl;
    4290           Point.CopyVector((*StartNode)->node);
    4291           Point.SubtractVector((*MiddleNode)->node);
     4263          Point = (*(*StartNode)->node) - (*(*MiddleNode)->node);
    42924264          StartNode = MiddleNode;
    42934265          StartNode++;
     
    42954267            StartNode = connectedPath->begin();
    42964268          //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl;
    4297           Reference.CopyVector((*StartNode)->node);
    4298           Reference.SubtractVector((*MiddleNode)->node);
    4299           OrthogonalVector.CopyVector((*MiddleNode)->node);
    4300           OrthogonalVector.SubtractVector(&OldPoint);
    4301           OrthogonalVector.MakeNormalVector(&Reference);
     4269          Reference = (*(*StartNode)->node) - (*(*MiddleNode)->node);
     4270          OrthogonalVector = (*(*MiddleNode)->node) - OldPoint;
     4271          OrthogonalVector.MakeNormalTo(Reference);
    43024272          angle = GetAngle(Point, Reference, OrthogonalVector);
    43034273          //if (angle < M_PI)  // no wrong-sided triangles, please?
     
    47524722  class BoundaryLineSet *BestLine = NULL;
    47534723  for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) {
    4754     BaseLine.CopyVector(Runner->second->endpoints[0]->node->node);
    4755     BaseLine.SubtractVector(Runner->second->endpoints[1]->node->node);
    4756     CenterToPoint.CopyVector(Runner->second->endpoints[0]->node->node);
    4757     CenterToPoint.AddVector(Runner->second->endpoints[1]->node->node);
    4758     CenterToPoint.Scale(0.5);
    4759     CenterToPoint.SubtractVector(point->node);
    4760     angle = CenterToPoint.Angle(&BaseLine);
    4761     if (fabs(angle - M_PI / 2.) < fabs(BestAngle - M_PI / 2.)) {
     4724    BaseLine = (*Runner->second->endpoints[0]->node->node) -
     4725               (*Runner->second->endpoints[1]->node->node);
     4726    CenterToPoint = 0.5 * ((*Runner->second->endpoints[0]->node->node) +
     4727                           (*Runner->second->endpoints[1]->node->node));
     4728    CenterToPoint -= (*point->node);
     4729    angle = CenterToPoint.Angle(BaseLine);
     4730    if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
    47624731      BestAngle = angle;
    47634732      BestLine = Runner->second;
     
    49254894      for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
    49264895        if (VectorWalker != VectorRunner) { // skip equals
    4927           const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
     4896          const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
    49284897          DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl);
    49294898          if (fabs(SCP + 1.) < ParallelEpsilon) {
     
    50104979    TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
    50114980    /// 4a. Get NormalVector for one side (this is "front")
    5012     NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
     4981    NormalVector = (*TriangleWalker)->NormalVector;
    50134982    DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl);
    50144983    TriangleWalker++;
     
    50214990      TriangleSprinter++;
    50224991      DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl);
    5023       if (triangle->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list
     4992      if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list
    50244993        DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl);
    50254994        TriangleNrs.push(triangle->Nr);
     
    50435012      AddTesselationTriangle(); // ... and add
    50445013      TriangleNrs.pop();
    5045       BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
    5046       BTS->NormalVector.Scale(-1.);
     5014      BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector;
    50475015      TriangleWalker++;
    50485016    }
  • src/tesselationhelpers.cpp

    r632bc3 r8cbb97  
    1414#include "tesselationhelpers.hpp"
    1515#include "vector.hpp"
     16#include "vector_ops.hpp"
    1617#include "verbose.hpp"
    1718
     
    5354
    5455  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]);
    5859  }
    5960  m11 = DetGet(A, 1);
    6061
    6162  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]);
    6566  }
    6667  m12 = DetGet(A, 1);
    6768
    6869  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]);
    7273  }
    7374  m13 = DetGet(A, 1);
    7475
    7576  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]);
    7980  }
    8081  m14 = DetGet(A, 1);
     
    8384    DoeLog(1) && (eLog()<< Verbose(1) << "three points are colinear." << endl);
    8485
    85   center->x[0] =  0.5 * m12/ m11;
    86   center->x[1] = -0.5 * m13/ m11;
    87   center->x[2] =  0.5 * m14/ m11;
    88 
    89   if (fabs(a.Distance(center) - RADIUS) > MYEPSILON)
    90     DoeLog(1) && (eLog()<< Verbose(1) << "The given center is further way by " << fabs(a.Distance(center) - RADIUS) << " from a than RADIUS." << endl);
     86  center->at(0) =  0.5 * m12/ m11;
     87  center->at(1) = -0.5 * m13/ m11;
     88  center->at(2) =  0.5 * m14/ m11;
     89
     90  if (fabs(a.Distance(*center) - RADIUS) > MYEPSILON)
     91    DoeLog(1) && (eLog()<< Verbose(1) << "The given center is further way by " << fabs(a.Distance(*center) - RADIUS) << " from a than RADIUS." << endl);
    9192
    9293  gsl_matrix_free(A);
     
    120121  Vector OtherCenter;
    121122  Center->Zero();
    122   helper.CopyVector(&a);
    123   helper.Scale(sin(2.*alpha));
    124   Center->AddVector(&helper);
    125   helper.CopyVector(&b);
    126   helper.Scale(sin(2.*beta));
    127   Center->AddVector(&helper);
    128   helper.CopyVector(&c);
    129   helper.Scale(sin(2.*gamma));
    130   Center->AddVector(&helper);
     123  helper = sin(2.*alpha) * a;
     124  (*Center) += helper;
     125  helper = sin(2.*beta) * b;
     126  (*Center) += helper;
     127  helper = sin(2.*gamma) * c;
     128  (*Center) += helper;
    131129  //*Center = a * sin(2.*alpha) + b * sin(2.*beta) + c * sin(2.*gamma) ;
    132130  Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma)));
    133   NewUmkreismittelpunkt->CopyVector(Center);
     131  (*NewUmkreismittelpunkt) = (*Center);
    134132  DoLog(1) && (Log() << Verbose(1) << "Center of new circumference is " << *NewUmkreismittelpunkt << ".\n");
    135133  // Here we calculated center of circumscribing circle, using barycentric coordinates
    136134  DoLog(1) && (Log() << Verbose(1) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n");
    137135
    138   TempNormal.CopyVector(&a);
    139   TempNormal.SubtractVector(&b);
    140   helper.CopyVector(&a);
    141   helper.SubtractVector(&c);
    142   TempNormal.VectorProduct(&helper);
     136  TempNormal = a - b;
     137  helper = a - c;
     138  TempNormal.VectorProduct(helper);
    143139  if (fabs(HalfplaneIndicator) < MYEPSILON)
    144140    {
    145       if ((TempNormal.ScalarProduct(AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(AlternativeDirection) >0 && AlternativeIndicator <0))
     141      if ((TempNormal.ScalarProduct(*AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(*AlternativeDirection) >0 && AlternativeIndicator <0))
    146142        {
    147           TempNormal.Scale(-1);
     143          TempNormal *= -1;
    148144        }
    149145    }
    150146  else
    151147    {
    152       if (((TempNormal.ScalarProduct(Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(Direction)>0) && (HalfplaneIndicator<0)))
     148      if (((TempNormal.ScalarProduct(*Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(*Direction)>0) && (HalfplaneIndicator<0)))
    153149        {
    154           TempNormal.Scale(-1);
     150          TempNormal *= -1;
    155151        }
    156152    }
     
    161157  TempNormal.Scale(Restradius);
    162158  DoLog(1) && (Log() << Verbose(1) << "Shift vector to sphere of circumference is " << TempNormal << ".\n");
    163 
    164   Center->AddVector(&TempNormal);
     159  (*Center) += TempNormal;
    165160  DoLog(1) && (Log() << Verbose(1) << "Center of sphere of circumference is " << *Center << ".\n");
    166161  GetSphere(&OtherCenter, a, b, c, RADIUS);
     
    180175  Vector helper;
    181176  double alpha, beta, gamma;
    182   Vector SideA, SideB, SideC;
    183   SideA.CopyVector(b);
    184   SideA.SubtractVector(&c);
    185   SideB.CopyVector(c);
    186   SideB.SubtractVector(&a);
    187   SideC.CopyVector(a);
    188   SideC.SubtractVector(&b);
    189   alpha = M_PI - SideB.Angle(&SideC);
    190   beta = M_PI - SideC.Angle(&SideA);
    191   gamma = M_PI - SideA.Angle(&SideB);
     177  Vector SideA = b - c;
     178  Vector SideB = c - a;
     179  Vector SideC = a - b;
     180  alpha = M_PI - SideB.Angle(SideC);
     181  beta = M_PI - SideC.Angle(SideA);
     182  gamma = M_PI - SideA.Angle(SideB);
    192183  //Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl;
    193184  if (fabs(M_PI - alpha - beta - gamma) > HULLEPSILON) {
     
    196187
    197188  Center->Zero();
    198   helper.CopyVector(a);
    199   helper.Scale(sin(2.*alpha));
    200   Center->AddVector(&helper);
    201   helper.CopyVector(b);
    202   helper.Scale(sin(2.*beta));
    203   Center->AddVector(&helper);
    204   helper.CopyVector(c);
    205   helper.Scale(sin(2.*gamma));
    206   Center->AddVector(&helper);
     189  helper = sin(2.*alpha) * a;
     190  (*Center) += helper;
     191  helper = sin(2.*beta) * b;
     192  (*Center) += helper;
     193  helper = sin(2.*gamma) * c;
     194  (*Center) += helper;
    207195  Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma)));
    208196};
     
    226214  Vector helper;
    227215  double radius, alpha;
    228   Vector RelativeOldSphereCenter;
    229   Vector RelativeNewSphereCenter;
    230 
    231   RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
    232   RelativeOldSphereCenter.SubtractVector(&CircleCenter);
    233   RelativeNewSphereCenter.CopyVector(&NewSphereCenter);
    234   RelativeNewSphereCenter.SubtractVector(&CircleCenter);
    235   helper.CopyVector(&RelativeNewSphereCenter);
     216
     217  Vector RelativeOldSphereCenter = OldSphereCenter - CircleCenter;
     218  Vector RelativeNewSphereCenter = NewSphereCenter - CircleCenter;
     219  helper = RelativeNewSphereCenter;
    236220  // test whether new center is on the parameter circle's plane
    237   if (fabs(helper.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
    238     DoeLog(1) && (eLog()<< Verbose(1) << "Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct(&CirclePlaneNormal))  << "!" << endl);
    239     helper.ProjectOntoPlane(&CirclePlaneNormal);
     221  if (fabs(helper.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) {
     222    DoeLog(1) && (eLog()<< Verbose(1) << "Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct(CirclePlaneNormal))  << "!" << endl);
     223    helper.ProjectOntoPlane(CirclePlaneNormal);
    240224  }
    241225  radius = helper.NormSquared();
     
    243227  if (fabs(radius - CircleRadius) > HULLEPSILON)
    244228    DoeLog(1) && (eLog()<< Verbose(1) << "The projected center of the new sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
    245   alpha = helper.Angle(&RelativeOldSphereCenter);
     229  alpha = helper.Angle(RelativeOldSphereCenter);
    246230  // make the angle unique by checking the halfplanes/search direction
    247   if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)  // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals
     231  if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)  // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals
    248232    alpha = 2.*M_PI - alpha;
    249233  DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << RelativeOldSphereCenter << " and resulting angle is " << alpha << "." << endl);
    250   radius = helper.Distance(&RelativeOldSphereCenter);
    251   helper.ProjectOntoPlane(&NormalVector);
     234  radius = helper.Distance(RelativeOldSphereCenter);
     235  helper.ProjectOntoPlane(NormalVector);
    252236  // check whether new center is somewhat away or at least right over the current baseline to prevent intersecting triangles
    253237  if ((radius > HULLEPSILON) || (helper.Norm() < HULLEPSILON)) {
     
    279263  struct Intersection *I = (struct Intersection *)params;
    280264  Vector intersection;
    281   Vector SideA,SideB,HeightA, HeightB;
    282265  for (int i=0;i<NDIM;i++)
    283     intersection.x[i] = gsl_vector_get(x, i);
    284 
    285   SideA.CopyVector(&(I->x1));
    286   SideA.SubtractVector(&I->x2);
    287   HeightA.CopyVector(&intersection);
    288   HeightA.SubtractVector(&I->x1);
    289   HeightA.ProjectOntoPlane(&SideA);
    290 
    291   SideB.CopyVector(&I->x3);
    292   SideB.SubtractVector(&I->x4);
    293   HeightB.CopyVector(&intersection);
    294   HeightB.SubtractVector(&I->x3);
    295   HeightB.ProjectOntoPlane(&SideB);
    296 
    297   retval = HeightA.ScalarProduct(&HeightA) + HeightB.ScalarProduct(&HeightB);
     266    intersection[i] = gsl_vector_get(x, i);
     267
     268  Vector SideA = I->x1 -I->x2 ;
     269  Vector HeightA = intersection - I->x1;
     270  HeightA.ProjectOntoPlane(SideA);
     271
     272  Vector SideB = I->x3 - I->x4;
     273  Vector HeightB = intersection - I->x3;
     274  HeightB.ProjectOntoPlane(SideB);
     275
     276  retval = HeightA.ScalarProduct(HeightA) + HeightB.ScalarProduct(HeightB);
    298277  //Log() << Verbose(1) << "MinIntersectDistance called, result: " << retval << endl;
    299278
     
    320299
    321300  struct Intersection par;
    322     par.x1.CopyVector(&point1);
    323     par.x2.CopyVector(&point2);
    324     par.x3.CopyVector(&point3);
    325     par.x4.CopyVector(&point4);
     301    par.x1 = point1;
     302    par.x2 = point2;
     303    par.x3 = point3;
     304    par.x4 = point4;
    326305
    327306    const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex;
     
    336315    /* Starting point */
    337316    x = gsl_vector_alloc(NDIM);
    338     gsl_vector_set(x, 0, point1.x[0]);
    339     gsl_vector_set(x, 1, point1.x[1]);
    340     gsl_vector_set(x, 2, point1.x[2]);
     317    gsl_vector_set(x, 0, point1[0]);
     318    gsl_vector_set(x, 1, point1[1]);
     319    gsl_vector_set(x, 2, point1[2]);
    341320
    342321    /* Set initial step sizes to 1 */
     
    369348
    370349    // check whether intersection is in between or not
    371   Vector intersection, SideA, SideB, HeightA, HeightB;
     350  Vector intersection;
    372351  double t1, t2;
    373352  for (int i = 0; i < NDIM; i++) {
    374     intersection.x[i] = gsl_vector_get(s->x, i);
    375   }
    376 
    377   SideA.CopyVector(&par.x2);
    378   SideA.SubtractVector(&par.x1);
    379   HeightA.CopyVector(&intersection);
    380   HeightA.SubtractVector(&par.x1);
    381 
    382   t1 = HeightA.ScalarProduct(&SideA)/SideA.ScalarProduct(&SideA);
    383 
    384   SideB.CopyVector(&par.x4);
    385   SideB.SubtractVector(&par.x3);
    386   HeightB.CopyVector(&intersection);
    387   HeightB.SubtractVector(&par.x3);
    388 
    389   t2 = HeightB.ScalarProduct(&SideB)/SideB.ScalarProduct(&SideB);
     353    intersection[i] = gsl_vector_get(s->x, i);
     354  }
     355
     356  Vector SideA = par.x2 - par.x1;
     357  Vector HeightA = intersection - par.x1;
     358
     359  t1 = HeightA.ScalarProduct(SideA)/SideA.ScalarProduct(SideA);
     360
     361  Vector SideB = par.x4 - par.x3;
     362  Vector HeightB = intersection - par.x3;
     363
     364  t2 = HeightB.ScalarProduct(SideB)/SideB.ScalarProduct(SideB);
    390365
    391366  Log() << Verbose(1) << "Intersection " << intersection << " is at "
     
    427402  if (point.IsZero())
    428403    return M_PI;
    429   double phi = point.Angle(&reference);
    430   if (OrthogonalVector.ScalarProduct(&point) > 0) {
     404  double phi = point.Angle(reference);
     405  if (OrthogonalVector.ScalarProduct(point) > 0) {
    431406    phi = 2.*M_PI - phi;
    432407  }
     
    451426  double volume;
    452427
    453   TetraederVector[0].CopyVector(a);
    454   TetraederVector[1].CopyVector(b);
    455   TetraederVector[2].CopyVector(c);
     428  TetraederVector[0] = a;
     429  TetraederVector[1] = b;
     430  TetraederVector[2] = c;
    456431  for (int j=0;j<3;j++)
    457     TetraederVector[j].SubtractVector(&d);
    458   Point.CopyVector(&TetraederVector[0]);
    459   Point.VectorProduct(&TetraederVector[1]);
    460   volume = 1./6. * fabs(Point.ScalarProduct(&TetraederVector[2]));
     432    TetraederVector[j].SubtractVector(d);
     433  Point = TetraederVector[0];
     434  Point.VectorProduct(TetraederVector[1]);
     435  volume = 1./6. * fabs(Point.ScalarProduct(TetraederVector[2]));
    461436  return volume;
    462437};
     
    582557        if (List != NULL) {
    583558          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    584             helper.CopyVector(Point);
    585             helper.SubtractVector((*Runner)->node);
     559            helper = (*Point) - (*(*Runner)->node);
    586560            double currentNorm = helper. Norm();
    587561            if (currentNorm < distance) {
     
    637611        if (List != NULL) {
    638612          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    639             helper.CopyVector(Point);
    640             helper.SubtractVector((*Runner)->node);
     613            helper = (*Point) - (*(*Runner)->node);
    641614            double currentNorm = helper.NormSquared();
    642615            if (currentNorm < distance) {
     
    677650        Info FunctionInfo(__func__);
    678651  // construct the plane of the two baselines (i.e. take both their directional vectors)
    679   Vector Normal;
    680   Vector Baseline, OtherBaseline;
    681   Baseline.CopyVector(Base->endpoints[1]->node->node);
    682   Baseline.SubtractVector(Base->endpoints[0]->node->node);
    683   OtherBaseline.CopyVector(OtherBase->endpoints[1]->node->node);
    684   OtherBaseline.SubtractVector(OtherBase->endpoints[0]->node->node);
    685   Normal.CopyVector(&Baseline);
    686   Normal.VectorProduct(&OtherBaseline);
     652  Vector Baseline = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node);
     653  Vector OtherBaseline = (*OtherBase->endpoints[1]->node->node) - (*OtherBase->endpoints[0]->node->node);
     654  Vector Normal = Baseline;
     655  Normal.VectorProduct(OtherBaseline);
    687656  Normal.Normalize();
    688657  DoLog(1) && (Log() << Verbose(1) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl);
    689658
    690659  // project one offset point of OtherBase onto this plane (and add plane offset vector)
    691   Vector NewOffset;
    692   NewOffset.CopyVector(OtherBase->endpoints[0]->node->node);
    693   NewOffset.SubtractVector(Base->endpoints[0]->node->node);
    694   NewOffset.ProjectOntoPlane(&Normal);
    695   NewOffset.AddVector(Base->endpoints[0]->node->node);
    696   Vector NewDirection;
    697   NewDirection.CopyVector(&NewOffset);
    698   NewDirection.AddVector(&OtherBaseline);
     660  Vector NewOffset = (*OtherBase->endpoints[0]->node->node) - (*Base->endpoints[0]->node->node);
     661  NewOffset.ProjectOntoPlane(Normal);
     662  NewOffset += (*Base->endpoints[0]->node->node);
     663  Vector NewDirection = NewOffset + OtherBaseline;
    699664
    700665  // calculate the intersection between this projected baseline and Base
    701666  Vector *Intersection = new Vector;
    702   Intersection->GetIntersectionOfTwoLinesOnPlane(Base->endpoints[0]->node->node, Base->endpoints[1]->node->node, &NewOffset, &NewDirection, &Normal);
    703   Normal.CopyVector(Intersection);
    704   Normal.SubtractVector(Base->endpoints[0]->node->node);
    705   DoLog(1) && (Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl);
     667  *Intersection = GetIntersectionOfTwoLinesOnPlane(*(Base->endpoints[0]->node->node),
     668                                                   *(Base->endpoints[1]->node->node),
     669                                                     NewOffset, NewDirection);
     670  Normal = (*Intersection) - (*Base->endpoints[0]->node->node);
     671  DoLog(1) && (Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(Baseline)/Baseline.NormSquared()) << "." << endl);
    706672
    707673  return Intersection;
     
    721687    return -1;
    722688  }
    723   distance = x->DistanceToPlane(&triangle->NormalVector, triangle->endpoints[0]->node->node);
     689  distance = x->DistanceToPlane(triangle->NormalVector, *triangle->endpoints[0]->node->node);
    724690  return distance;
    725691};
     
    747713      *vrmlfile << "Sphere {" << endl << "  "; // 2 is sphere type
    748714      for (i=0;i<NDIM;i++)
    749         *vrmlfile << Walker->node->x[i]-center->x[i] << " ";
     715        *vrmlfile << Walker->node->at(i)-center->at(i) << " ";
    750716      *vrmlfile << "\t0.1\t1. 1. 1." << endl; // radius 0.05 and white as colour
    751717      cloud->GoToNext();
     
    757723      for (i=0;i<3;i++) { // print each node
    758724        for (int j=0;j<NDIM;j++)  // and for each node all NDIM coordinates
    759           *vrmlfile << TriangleRunner->second->endpoints[i]->node->node->x[j]-center->x[j] << " ";
     725          *vrmlfile << TriangleRunner->second->endpoints[i]->node->node->at(j)-center->at(j) << " ";
    760726        *vrmlfile << "\t";
    761727      }
     
    784750    Vector *center = cloud->GetCenter();
    785751    // make the circumsphere's center absolute again
    786     helper.CopyVector(Tess->LastTriangle->endpoints[0]->node->node);
    787     helper.AddVector(Tess->LastTriangle->endpoints[1]->node->node);
    788     helper.AddVector(Tess->LastTriangle->endpoints[2]->node->node);
    789     helper.Scale(1./3.);
    790     helper.SubtractVector(center);
     752    Vector helper = (1./3.) * ((*Tess->LastTriangle->endpoints[0]->node->node) +
     753                               (*Tess->LastTriangle->endpoints[1]->node->node) +
     754                               (*Tess->LastTriangle->endpoints[2]->node->node));
     755    helper -= (*center);
    791756    // and add to file plus translucency object
    792757    *rasterfile << "# current virtual sphere\n";
    793758    *rasterfile << "8\n  25.0    0.6     -1.0 -1.0 -1.0     0.2        0 0 0 0\n";
    794     *rasterfile << "2\n  " << helper.x[0] << " " << helper.x[1] << " " << helper.x[2] << "\t" << 5. << "\t1 0 0\n";
     759    *rasterfile << "2\n  " << helper[0] << " " << helper[1] << " " << helper[2] << "\t" << 5. << "\t1 0 0\n";
    795760    *rasterfile << "9\n  terminating special property\n";
    796761    delete(center);
     
    820785      *rasterfile << "2" << endl << "  ";  // 2 is sphere type
    821786      for (i=0;i<NDIM;i++)
    822         *rasterfile << Walker->node->x[i]-center->x[i] << " ";
     787        *rasterfile << Walker->node->at(i)-center->at(i) << " ";
    823788      *rasterfile << "\t0.1\t1. 1. 1." << endl; // radius 0.05 and white as colour
    824789      cloud->GoToNext();
     
    831796      for (i=0;i<3;i++) {  // print each node
    832797        for (int j=0;j<NDIM;j++)  // and for each node all NDIM coordinates
    833           *rasterfile << TriangleRunner->second->endpoints[i]->node->node->x[j]-center->x[j] << " ";
     798          *rasterfile << TriangleRunner->second->endpoints[i]->node->node->at(j)-center->at(j) << " ";
    834799        *rasterfile << "\t";
    835800      }
     
    881846      Walker = target->second->node;
    882847      LookupList[Walker->nr] = Counter++;
    883       *tecplot << Walker->node->x[0] << " " << Walker->node->x[1] << " " << Walker->node->x[2] << " " << target->second->value << endl;
     848      *tecplot << Walker->node->at(0) << " " << Walker->node->at(1) << " " << Walker->node->at(2) << " " << target->second->value << endl;
    884849    }
    885850    *tecplot << endl;
  • src/test/ActOnAlltest.hpp

    r632bc3 r8cbb97  
    2727
    2828  template <typename klasse, typename res, typename T> void ActOnAll( res (klasse::*f)(T), T t );
     29  template <typename klasse, typename res, typename T> void ActOnAll( res (klasse::*f)(T&), T &t );
    2930  template <typename klasse, typename res, typename T, typename U> void ActOnAll( res (klasse::*f)(T, U), T t, U u );
    3031  template <typename klasse, typename res, typename T, typename U, typename V> void ActOnAll( res (klasse::*f)(T, U, V), T t, U u, V v);
     
    7677};
    7778
     79template <typename klasse, typename res, typename T> void VectorList::ActOnAll( res (klasse::*f)(T&), T &t )
     80{
     81  for (ListOfVectors::iterator Runner = Vectors.begin(); Runner != Vectors.end(); Runner++)
     82    ((*Runner)->*f)(t);
     83};
     84
    7885template <typename klasse, typename res, typename T, typename U> void VectorList::ActOnAll( res (klasse::*f)(T, U), T t, U u )
    7986{
  • src/triangleintersectionlist.cpp

    r632bc3 r8cbb97  
    9494  if (runner != IntersectionList.end()) {
    9595    // if we have found one, check Scalarproduct between the vector
    96     Vector TestVector(Point);
    97     TestVector.SubtractVector((*runner).second);
     96    Vector TestVector = (*Point) - (*(*runner).second);
    9897    if (fabs(TestVector.NormSquared()) < MYEPSILON) //
    9998      return true;
    100     const double sign = (*runner).first->NormalVector.ScalarProduct(&TestVector);
     99    const double sign = (*runner).first->NormalVector.ScalarProduct(TestVector);
    101100    if (sign < 0) {
    102101      return true;
     
    147146  if (DistanceList.empty())
    148147    for (TriangleVectorMap::const_iterator runner = IntersectionList.begin(); runner != IntersectionList.end(); runner++)
    149       DistanceList.insert( pair<double, BoundaryTriangleSet *> (Point->Distance((*runner).second), (*runner).first) );
     148      DistanceList.insert( pair<double, BoundaryTriangleSet *> (Point->Distance(*(*runner).second), (*runner).first) );
    150149
    151150  //for (DistanceTriangleMap::const_iterator runner = DistanceList.begin(); runner != DistanceList.end(); runner++)
  • src/unittests/ActOnAllUnitTest.cpp

    r632bc3 r8cbb97  
    5656
    5757  // adding, subtracting
    58   VL.ActOnAll( &Vector::AddVector, &test );
     58  VL.ActOnAll( &Vector::AddVector, test );
    5959  CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
    60   VL.ActOnAll( &Vector::SubtractVector, &test );
     60  VL.ActOnAll( &Vector::SubtractVector, test );
    6161  CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
    6262};
     
    7070
    7171  // scaling by value
    72   VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, 2. );
     72  VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, factor );
    7373  CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
    7474
    75   VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, 0.5 );
    76   CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
    77 
    78   // scaling by ref
    79   VL.ActOnAll( (void (Vector::*)(const double * const)) &Vector::Scale, (const double * const)&factor );
    80   CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
    81 
    82   VL.ActOnAll( (void (Vector::*)(const double * const)) &Vector::Scale, (const double * const)&inverse );
     75  VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, inverse );
    8376  CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
    8477
     
    9083    inverses[i] = 1./factors[i];
    9184  }
    92   VL.ActOnAll( (void (Vector::*)(const double ** const)) &Vector::Scale, (const double ** const)&factors );
     85  VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, factors );
    9386  CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
    9487
    95   VL.ActOnAll( (void (Vector::*)(const double ** const)) &Vector::Scale, (const double ** const)&inverses );
     88  VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, inverses );
    9689  CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
    9790  Free(factors);
    9891  Free(inverses);
    9992};
     93
     94#if 0
     95
     96// Unitttest deactivated for now...
     97// Reasons:
     98//    Vector::MakeNormalVector has been removed and is now part of Plane class
     99//    VectorList::ActOnAll is in the test directory and seems to be used only for unittests
     100//    MakeNormal never depended on the input Vector except in the case of linear dependence (i.e. failure)
     101//
     102// TODO: Rethink what exactely is being tested at this point and introduce a new unittest for the
     103//       tested behaviour. Most likely this should result in a thourough unittest of the plane class
    100104
    101105/** UnitTest for VectorList::ActOnAll() and Vector::MakeNormalVector()
     
    113117  // check that x and y components are zero
    114118  for (ListOfVectors::iterator Runner = VL.Vectors.begin(); Runner != VL.Vectors.end(); Runner++) {
    115     CPPUNIT_ASSERT_EQUAL( (*Runner)->x[0] , 0. );
    116     CPPUNIT_ASSERT_EQUAL( (*Runner)->x[1] , 0. );
     119    CPPUNIT_ASSERT_EQUAL( (*Runner)->at(0) , 0. );
     120    CPPUNIT_ASSERT_EQUAL( (*Runner)->at(1) , 0. );
    117121  }
    118122};
     123
     124#endif
  • src/unittests/ActOnAllUnitTest.hpp

    r632bc3 r8cbb97  
    2020    CPPUNIT_TEST ( AddSubtractTest );
    2121    CPPUNIT_TEST ( ScaleTest );
     22#if 0
     23    // test deactivated. See .cpp for reasons and workarounds
    2224    CPPUNIT_TEST ( NormalizeTest );
     25#endif
    2326    CPPUNIT_TEST_SUITE_END();
    2427
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    r632bc3 r8cbb97  
    6464  Walker = World::getInstance().createAtom();
    6565  Walker->type = hydrogen;
    66   Walker->node->Init(1., 0., 1. );
     66  *Walker->node = Vector(1., 0., 1. );
    6767  TestMolecule->AddAtom(Walker);
    6868  Walker = World::getInstance().createAtom();
    6969  Walker->type = hydrogen;
    70   Walker->node->Init(0., 1., 1. );
     70  *Walker->node = Vector(0., 1., 1. );
    7171  TestMolecule->AddAtom(Walker);
    7272  Walker = World::getInstance().createAtom();
    7373  Walker->type = hydrogen;
    74   Walker->node->Init(1., 1., 0. );
     74  *Walker->node = Vector(1., 1., 0. );
    7575  TestMolecule->AddAtom(Walker);
    7676  Walker = World::getInstance().createAtom();
    7777  Walker->type = hydrogen;
    78   Walker->node->Init(0., 0., 0. );
     78  *Walker->node = Vector(0., 0., 0. );
    7979  TestMolecule->AddAtom(Walker);
    8080
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r632bc3 r8cbb97  
    4040void AnalysisCorrelationToSurfaceUnitTest::setUp()
    4141{
    42   ASSERT_DO(Assert::Throw);
     42  //ASSERT_DO(Assert::Throw);
    4343
    4444  atom *Walker = NULL;
     
    4646  // init private all pointers to zero
    4747  TestList = NULL;
    48   TestMolecule = NULL;
     48  TestSurfaceMolecule = NULL;
    4949  hydrogen = NULL;
    5050  tafel = NULL;
     
    7373  Walker = World::getInstance().createAtom();
    7474  Walker->type = hydrogen;
    75   Walker->node->Init(1., 0., 1. );
    76   TestSurfaceMolecule->AddAtom(Walker);
    77   Walker = World::getInstance().createAtom();
    78   Walker->type = hydrogen;
    79   Walker->node->Init(0., 1., 1. );
    80   TestSurfaceMolecule->AddAtom(Walker);
    81   Walker = World::getInstance().createAtom();
    82   Walker->type = hydrogen;
    83   Walker->node->Init(1., 1., 0. );
    84   TestSurfaceMolecule->AddAtom(Walker);
    85   Walker = World::getInstance().createAtom();
    86   Walker->type = hydrogen;
    87   Walker->node->Init(0., 0., 0. );
     75  *Walker->node = Vector(1., 0., 1. );
     76
     77  TestSurfaceMolecule->AddAtom(Walker);
     78  Walker = World::getInstance().createAtom();
     79  Walker->type = hydrogen;
     80  *Walker->node = Vector(0., 1., 1. );
     81  TestSurfaceMolecule->AddAtom(Walker);
     82  Walker = World::getInstance().createAtom();
     83  Walker->type = hydrogen;
     84  *Walker->node = Vector(1., 1., 0. );
     85  TestSurfaceMolecule->AddAtom(Walker);
     86  Walker = World::getInstance().createAtom();
     87  Walker->type = hydrogen;
     88  *Walker->node = Vector(0., 0., 0. );
    8889  TestSurfaceMolecule->AddAtom(Walker);
    8990
     
    101102
    102103  // add outer atoms
    103   TestMolecule = World::getInstance().createMolecule();
    104   Walker = World::getInstance().createAtom();
    105   Walker->type = carbon;
    106   Walker->node->Init(4., 0., 4. );
    107   TestMolecule->AddAtom(Walker);
    108   Walker = World::getInstance().createAtom();
    109   Walker->type = carbon;
    110   Walker->node->Init(0., 4., 4. );
    111   TestMolecule->AddAtom(Walker);
    112   Walker = World::getInstance().createAtom();
    113   Walker->type = carbon;
    114   Walker->node->Init(4., 4., 0. );
    115   TestMolecule->AddAtom(Walker);
     104  TestSurfaceMolecule = World::getInstance().createMolecule();
     105  Walker = World::getInstance().createAtom();
     106  Walker->type = carbon;
     107  *Walker->node = Vector(4., 0., 4. );
     108  TestSurfaceMolecule->AddAtom(Walker);
     109  Walker = World::getInstance().createAtom();
     110  Walker->type = carbon;
     111  *Walker->node = Vector(0., 4., 4. );
     112  TestSurfaceMolecule->AddAtom(Walker);
     113  Walker = World::getInstance().createAtom();
     114  Walker->type = carbon;
     115  *Walker->node = Vector(4., 4., 0. );
     116  TestSurfaceMolecule->AddAtom(Walker);
    116117  // add inner atoms
    117118  Walker = World::getInstance().createAtom();
    118119  Walker->type = carbon;
    119   Walker->node->Init(0.5, 0.5, 0.5 );
    120   TestMolecule->AddAtom(Walker);
    121   TestMolecule->ActiveFlag = true;
    122   TestList->insert(TestMolecule);
     120  *Walker->node = Vector(0.5, 0.5, 0.5 );
     121  TestSurfaceMolecule->AddAtom(Walker);
     122  TestSurfaceMolecule->ActiveFlag = true;
     123  TestList->insert(TestSurfaceMolecule);
    123124
    124125  // init maps
     
    150151{
    151152  CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->AtomCount );
    152   CPPUNIT_ASSERT_EQUAL( 4, TestMolecule->AtomCount );
    153153  CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() );
    154154  CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.hpp

    r632bc3 r8cbb97  
    4444
    4545      MoleculeListClass *TestList;
    46       molecule *TestMolecule;
    4746      molecule *TestSurfaceMolecule;
    4847      element *hydrogen;
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    r632bc3 r8cbb97  
    6363  Walker = World::getInstance().createAtom();
    6464  Walker->type = hydrogen;
    65   Walker->node->Init(1., 0., 1. );
     65  *Walker->node = Vector(1., 0., 1. );
    6666  TestMolecule->AddAtom(Walker);
    6767  Walker = World::getInstance().createAtom();
    6868  Walker->type = hydrogen;
    69   Walker->node->Init(0., 1., 1. );
     69  *Walker->node = Vector(0., 1., 1. );
    7070  TestMolecule->AddAtom(Walker);
    7171  Walker = World::getInstance().createAtom();
    7272  Walker->type = hydrogen;
    73   Walker->node->Init(1., 1., 0. );
     73  *Walker->node = Vector(1., 1., 0. );
    7474  TestMolecule->AddAtom(Walker);
    7575  Walker = World::getInstance().createAtom();
    7676  Walker->type = hydrogen;
    77   Walker->node->Init(0., 0., 0. );
     77  *Walker->node = Vector(0., 0., 0. );
    7878  TestMolecule->AddAtom(Walker);
    7979
  • src/unittests/CountBondsUnitTest.cpp

    r632bc3 r8cbb97  
    7272  Walker = World::getInstance().createAtom();
    7373  Walker->type = hydrogen;
    74   Walker->node->Init(-0.2418, 0.9350, 0. );
     74  *Walker->node = Vector(-0.2418, 0.9350, 0. );
    7575  TestMolecule1->AddAtom(Walker);
    7676  Walker = World::getInstance().createAtom();
    7777  Walker->type = hydrogen;
    78   Walker->node->Init(0.9658, 0., 0. );
     78  *Walker->node = Vector(0.9658, 0., 0. );
    7979  TestMolecule1->AddAtom(Walker);
    8080  Walker = World::getInstance().createAtom();
    8181  Walker->type = oxygen;
    82   Walker->node->Init(0., 0., 0. );
     82  *Walker->node = Vector(0., 0., 0. );
    8383  TestMolecule1->AddAtom(Walker);
    8484
     
    8686  Walker = World::getInstance().createAtom();
    8787  Walker->type = hydrogen;
    88   Walker->node->Init(-0.2418, 0.9350, 0. );
     88  *Walker->node = Vector(-0.2418, 0.9350, 0. );
    8989  TestMolecule2->AddAtom(Walker);
    9090  Walker = World::getInstance().createAtom();
    9191  Walker->type = hydrogen;
    92   Walker->node->Init(0.9658, 0., 0. );
     92  *Walker->node = Vector(0.9658, 0., 0. );
    9393  TestMolecule2->AddAtom(Walker);
    9494  Walker = World::getInstance().createAtom();
    9595  Walker->type = oxygen;
    96   Walker->node->Init(0., 0., 0. );
     96  *Walker->node = Vector(0., 0., 0. );
    9797  TestMolecule2->AddAtom(Walker);
    9898
     
    165165
    166166  cout << "Case 1: offset of (3,0,0), hence angles are (104.5, 0, 75.5, 180) < 30." << endl;
    167   Translator.Init(3,0,0);
     167  Translator  = Vector(3,0,0);
    168168  TestMolecule2->Translate(&Translator);
    169169  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
    170170  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, oxygen) );
    171171  //OutputTestMolecule(TestMolecule2, "testmolecule2-1.xyz");
    172   Translator.Init(-3,0,0);
     172  Translator = Vector(-3,0,0);
    173173  TestMolecule2->Translate(&Translator);
    174174
    175175  cout << "Case 2: offset of (0,3,0), hence angle are (14.5, 165.5, 90) < 30 (only three, because other 90 is missing due to first H01 only fulfilling H-bond criteria)." << endl;
    176   Translator.Init(0,3,0);
     176  Translator = Vector(0,3,0);
    177177  TestMolecule2->Translate(&Translator);
    178178  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
    179179  //OutputTestMolecule(TestMolecule2, "testmolecule2-2.xyz");
    180   Translator.Init(0,-3,0);
     180  Translator = Vector(0,-3,0);
    181181  TestMolecule2->Translate(&Translator);
    182182
    183183  cout << "Case 3: offset of (0,-3,0) and mirror, hence angle are (165.5, 90, 165.5, 90) > 30." << endl;
    184   Translator.Init(0,-3,0);
     184  Translator = Vector(0,-3,0);
    185185  TestMolecule2->Scale((const double ** const)&mirror);
    186186  TestMolecule2->Translate(&Translator);
    187187  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    188188  //OutputTestMolecule(TestMolecule2, "testmolecule2-3.xyz");
    189   Translator.Init(0,3,0);
     189  Translator = Vector(0,3,0);
    190190  TestMolecule2->Translate(&Translator);
    191191  TestMolecule2->Scale((const double ** const)&mirror);
    192192
    193193  cout << "Case 4: offset of (2,1,0), hence angle are (78, 26.6, 102, 153.4) < 30." << endl;
    194   Translator.Init(2,1,0);
     194  Translator = Vector(2,1,0);
    195195  TestMolecule2->Translate(&Translator);
    196196  CPPUNIT_ASSERT_EQUAL( 1 , CountHydrogenBridgeBonds(molecules, NULL) );
    197197  //OutputTestMolecule(TestMolecule2, "testmolecule2-4.xyz");
    198   Translator.Init(-2,-1,0);
     198  Translator = Vector(-2,-1,0);
    199199  TestMolecule2->Translate(&Translator);
    200200
    201201  cout << "Case 5: offset of (0,0,3), hence angle are (90, 90, 90, 90) > 30." << endl;
    202   Translator.Init(0,0,3);
     202  Translator = Vector(0,0,3);
    203203  TestMolecule2->Translate(&Translator);
    204204  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    205205  //OutputTestMolecule(TestMolecule2, "testmolecule2-5.xyz");
    206   Translator.Init(0,0,-3);
     206  Translator = Vector(0,0,-3);
    207207  TestMolecule2->Translate(&Translator);
    208208
    209209  cout << "Case 6: offset of (-3,0,0) and mirror, hence angle are (75.5, 180, 104.5, 180) > 30." << endl;
    210   Translator.Init(-3,0,0);
     210  Translator = Vector(-3,0,0);
    211211  TestMolecule2->Scale((const double ** const)&mirror);
    212212  TestMolecule2->Translate(&Translator);
    213213  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    214214  //OutputTestMolecule(TestMolecule2, "testmolecule2-6.xyz");
    215   Translator.Init(3,0,0);
     215  Translator = Vector(3,0,0);
    216216  TestMolecule2->Translate(&Translator);
    217217  TestMolecule2->Scale((const double ** const)&mirror);
    218218
    219219  cout << "Case 7: offset of (3,0,0) and mirror, hence angles are (104.5, 0, 104.5, 0) < 30, but interfering hydrogens." << endl;
    220   Translator.Init(3,0,0);
     220  Translator = Vector(3,0,0);
    221221  TestMolecule2->Scale((const double ** const)&mirror);
    222222  TestMolecule2->Translate(&Translator);
    223223  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    224224  //OutputTestMolecule(TestMolecule2, "testmolecule2-7.xyz");
    225   Translator.Init(-3,0,0);
     225  Translator = Vector(-3,0,0);
    226226  TestMolecule2->Translate(&Translator);
    227227  TestMolecule2->Scale((const double ** const)&mirror);
    228228
    229229  cout << "Case 8: offset of (0,3,0), hence angle are (14.5, 90, 14.5, 90) < 30, but interfering hydrogens." << endl;
    230   Translator.Init(0,3,0);
     230  Translator = Vector(0,3,0);
    231231  TestMolecule2->Scale((const double ** const)&mirror);
    232232  TestMolecule2->Translate(&Translator);
    233233  //OutputTestMolecule(TestMolecule2, "testmolecule2-8.xyz");
    234234  CPPUNIT_ASSERT_EQUAL( 0 , CountHydrogenBridgeBonds(molecules, NULL) );
    235   Translator.Init(0,-3,0);
     235  Translator = Vector(0,-3,0);
    236236  TestMolecule2->Translate(&Translator);
    237237  TestMolecule2->Scale((const double ** const)&mirror);
  • src/unittests/LinkedCellUnitTest.cpp

    r632bc3 r8cbb97  
    6161        Walker = World::getInstance().createAtom();
    6262        Walker->type = hydrogen;
    63         Walker->node->Init(x, y, z );
     63        *Walker->node = Vector(x, y, z );
    6464        TestMolecule->AddAtom(Walker);
    6565      }
     
    207207  Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker");
    208208  strcpy(Walker->Name, "test");
    209   Walker->x.Init(1,1,1);
     209  Walker->x= Vector(1,1,1);
    210210  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    211211  World::getInstance().destroyAtom(Walker);
     
    215215  Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker");
    216216  strcpy(Walker->Name, "test");
    217   Walker->x.Init(0,-1,0);
     217  Walker->x = Vector(0,-1,0);
    218218  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    219219  World::getInstance().destroyAtom(Walker);
     
    231231    for (double y=0.5;y<3;y+=1.)
    232232      for (double z=0.5;z<3;z+=1.) {
    233         tester.Init(x,y,z);
     233        tester = Vector(x,y,z);
    234234        CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
    235235      }
     
    238238    for (double y=1.;y<4;y+=1.)
    239239      for (double z=1.;z<4;z+=1.) {
    240         tester.Init(x,y,z);
     240        tester= Vector(x,y,z);
    241241        cout << "Tester is at " << tester << "." << endl;
    242242        CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
     
    246246    for (double y=0.5-1e-10;y<5;y+=3.1)
    247247      for (double z=0.5-1e-10;z<5;z+=3.1) {
    248         tester.Init(x,y,z);
     248        tester = Vector(x,y,z);
    249249        cout << "The following test is supposed to fail and produce an ERROR." << endl;
    250250        CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
    251251      }
    252252  // check nonsense vectors
    253   tester.Init(-423598,3245978,29349);
     253  tester= Vector(-423598,3245978,29349);
    254254  cout << "The following test is supposed to fail and produce an ERROR." << endl;
    255255  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
     
    264264  int lower[NDIM], upper[NDIM];
    265265
    266   tester.Init(0.5,0.5,0.5);
     266  tester= Vector(0.5,0.5,0.5);
    267267  LC->SetIndexToVector(&tester);
    268268  LC->GetNeighbourBounds(lower, upper);
     
    284284
    285285  // get all atoms
    286   tester.Init(1.5,1.5,1.5);
     286  tester= Vector(1.5,1.5,1.5);
    287287  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    288288  ListOfPoints = LC->GetallNeighbours();
     
    303303
    304304  // get all atoms in one corner
    305   tester.Init(0.5, 0.5, 0.5);
     305  tester= Vector(0.5, 0.5, 0.5);
    306306  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    307307  ListOfPoints = LC->GetallNeighbours();
     
    311311  while (Walker->next != TestMolecule->end) {
    312312    Walker = Walker->next;
    313     if ((Walker->x.x[0] <2) && (Walker->x.x[1] <2) && (Walker->x.x[2] <2)) {
     313    if ((Walker->x[0] <2) && (Walker->x[1] <2) && (Walker->x[2] <2)) {
    314314      ListOfPoints->remove(Walker);
    315315      size--;
     
    323323
    324324  // get all atoms from one corner
    325   tester.Init(0.5, 0.5, 0.5);
     325  tester = Vector(0.5, 0.5, 0.5);
    326326  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    327327  ListOfPoints = LC->GetallNeighbours(3);
     
    352352
    353353  // get all points around central arom with radius 1.
    354   tester.Init(1.5,1.5,1.5);
     354  tester= Vector(1.5,1.5,1.5);
    355355  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    356356  ListOfPoints = LC->GetPointsInsideSphere(1., &tester);
     
    360360  while (Walker->next != TestMolecule->end) {
    361361    Walker = Walker->next;
    362     if ((Walker->x.DistanceSquared(&tester) - 1.) < MYEPSILON ) {
     362    if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) {
    363363      ListOfPoints->remove(Walker);
    364364      size--;
  • src/unittests/analysisbondsunittest.cpp

    r632bc3 r8cbb97  
    6969  Walker = World::getInstance().createAtom();
    7070  Walker->type = hydrogen;
    71   Walker->node->Init(1.5, 0., 1.5 );
     71  *Walker->node = Vector(1.5, 0., 1.5 );
    7272  TestMolecule->AddAtom(Walker);
    7373  Walker = World::getInstance().createAtom();
    7474  Walker->type = hydrogen;
    75   Walker->node->Init(0., 1.5, 1.5 );
     75  *Walker->node = Vector(0., 1.5, 1.5 );
    7676  TestMolecule->AddAtom(Walker);
    7777  Walker = World::getInstance().createAtom();
    7878  Walker->type = hydrogen;
    79   Walker->node->Init(1.5, 1.5, 0. );
     79  *Walker->node = Vector(1.5, 1.5, 0. );
    8080  TestMolecule->AddAtom(Walker);
    8181  Walker = World::getInstance().createAtom();
    8282  Walker->type = hydrogen;
    83   Walker->node->Init(0., 0., 0. );
     83  *Walker->node = Vector(0., 0., 0. );
    8484  TestMolecule->AddAtom(Walker);
    8585  Walker = World::getInstance().createAtom();
    8686  Walker->type = carbon;
    87   Walker->node->Init(0.5, 0.5, 0.5 );
     87  *Walker->node = Vector(0.5, 0.5, 0.5 );
    8888  TestMolecule->AddAtom(Walker);
    8989
  • src/unittests/bondgraphunittest.cpp

    r632bc3 r8cbb97  
    7070  Walker = World::getInstance().createAtom();
    7171  Walker->type = carbon;
    72   Walker->node->Init(1., 0., 1. );
     72  *Walker->node = Vector(1., 0., 1. );
    7373  TestMolecule->AddAtom(Walker);
     74
    7475  Walker = World::getInstance().createAtom();
    7576  Walker->type = carbon;
    76   Walker->node->Init(0., 1., 1. );
     77  *Walker->node = Vector(0., 1., 1. );
    7778  TestMolecule->AddAtom(Walker);
     79
    7880  Walker = World::getInstance().createAtom();
    7981  Walker->type = carbon;
    80   Walker->node->Init(1., 1., 0. );
     82  *Walker->node = Vector(1., 1., 0. );
    8183  TestMolecule->AddAtom(Walker);
     84
    8285  Walker = World::getInstance().createAtom();
    8386  Walker->type = carbon;
    84   Walker->node->Init(0., 0., 0. );
     87  *Walker->node = Vector(0., 0., 0. );
    8588  TestMolecule->AddAtom(Walker);
    8689
  • src/unittests/listofbondsunittest.cpp

    r632bc3 r8cbb97  
    5858  Walker = World::getInstance().createAtom();
    5959  Walker->type = hydrogen;
    60   Walker->node->Init(1., 0., 1. );
    61   TestMolecule->AddAtom(Walker);
    62   Walker = World::getInstance().createAtom();
    63   Walker->type = hydrogen;
    64   Walker->node->Init(0., 1., 1. );
    65   TestMolecule->AddAtom(Walker);
    66   Walker = World::getInstance().createAtom();
    67   Walker->type = hydrogen;
    68   Walker->node->Init(1., 1., 0. );
    69   TestMolecule->AddAtom(Walker);
    70   Walker = World::getInstance().createAtom();
    71   Walker->type = hydrogen;
    72   Walker->node->Init(0., 0., 0. );
     60  *Walker->node = Vector(1., 0., 1. );
     61  TestMolecule->AddAtom(Walker);
     62  Walker = World::getInstance().createAtom();
     63  Walker->type = hydrogen;
     64  *Walker->node = Vector(0., 1., 1. );
     65  TestMolecule->AddAtom(Walker);
     66  Walker = World::getInstance().createAtom();
     67  Walker->type = hydrogen;
     68  *Walker->node = Vector(1., 1., 0. );
     69  TestMolecule->AddAtom(Walker);
     70  Walker = World::getInstance().createAtom();
     71  Walker->type = hydrogen;
     72  *Walker->node = Vector(0., 0., 0. );
    7373  TestMolecule->AddAtom(Walker);
    7474
  • src/unittests/tesselation_boundarytriangleunittest.cpp

    r632bc3 r8cbb97  
    8686
    8787  // simple test on y line
    88   Point.Init(-1.,0.5,0.);
    89   CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    90   Point.Init(0.,0.5,0.);
    91   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    92   Point.Init(-4.,0.5,0.);
     88  Point = Vector(-1.,0.5,0.);
     89  CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
     90  Point = Vector(0.,0.5,0.);
     91  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
     92  Point = Vector(-4.,0.5,0.);
    9393  CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    94   Point.Init(0.,0.5,0.);
     94  Point = Vector(0.,0.5,0.);
    9595  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    9696
    9797  // simple test on x line
    98   Point.Init(0.5,-1.,0.);
    99   CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    100   Point.Init(0.5,0.,0.);
    101   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    102   Point.Init(0.5,-6.,0.);
     98  Point = Vector(0.5,-1.,0.);
     99  CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
     100  Point = Vector(0.5,0.,0.);
     101  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
     102  Point = Vector(0.5,-6.,0.);
    103103  CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    104   Point.Init(0.5,0.,0.);
     104  Point = Vector(0.5,0.,0.);
    105105  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    106106
    107107  // simple test on slanted line
    108   Point.Init(1.,1.,0.);
     108  Point = Vector(1.,1.,0.);
    109109  CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    110   Point.Init(0.5,0.5,0.);
    111   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    112   Point.Init(5.,5.,0.);
     110  Point = Vector(0.5,0.5,0.);
     111  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
     112  Point = Vector(5.,5.,0.);
    113113  CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    114   Point.Init(0.5,0.5,0.);
     114  Point = Vector(0.5,0.5,0.);
    115115  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    116116
    117117  // simple test on first node
    118   Point.Init(-1.,-1.,0.);
     118  Point = Vector(-1.,-1.,0.);
    119119  CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    120   Point.Init(0.,0.,0.);
     120  Point = Vector(0.,0.,0.);
    121121  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    122122
    123123  // simple test on second node
    124   Point.Init(0.,2.,0.);
    125   CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    126   Point.Init(0.,1.,0.);
     124  Point = Vector(0.,2.,0.);
     125  CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
     126  Point = Vector(0.,1.,0.);
    127127  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    128128
    129129  // simple test on third node
    130   Point.Init(2.,0.,0.);
    131   CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    132   Point.Init(1.,0.,0.);
     130  Point = Vector(2.,0.,0.);
     131  CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
     132  Point = Vector(1.,0.,0.);
    133133  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    134134};
     
    142142
    143143  // straight down/up
    144   Point.Init(1./3.,1./3.,+5.);
     144  Point = Vector(1./3.,1./3.,+5.);
    145145  CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    146   Point.Init(1./3.,1./3.,0.);
    147   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    148   Point.Init(1./3.,1./3.,-5.);
     146  Point = Vector(1./3.,1./3.,0.);
     147  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
     148  Point = Vector(1./3.,1./3.,-5.);
    149149  CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    150   Point.Init(1./3.,1./3.,0.);
     150  Point = Vector(1./3.,1./3.,0.);
    151151  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    152152
    153153  // simple test on y line
    154   Point.Init(-1.,0.5,+2.);
     154  Point = Vector(-1.,0.5,+2.);
    155155  CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    156   Point.Init(0.,0.5,0.);
    157   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    158   Point.Init(-1.,0.5,-3.);
     156  Point = Vector(0.,0.5,0.);
     157  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
     158  Point = Vector(-1.,0.5,-3.);
    159159  CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    160   Point.Init(0.,0.5,0.);
     160  Point = Vector(0.,0.5,0.);
    161161  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    162162
    163163  // simple test on x line
    164   Point.Init(0.5,-1.,+1.);
     164  Point = Vector(0.5,-1.,+1.);
    165165  CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    166   Point.Init(0.5,0.,0.);
    167   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    168   Point.Init(0.5,-1.,-2.);
     166  Point = Vector(0.5,0.,0.);
     167  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
     168  Point = Vector(0.5,-1.,-2.);
    169169  CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    170   Point.Init(0.5,0.,0.);
     170  Point = Vector(0.5,0.,0.);
    171171  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    172172
    173173  // simple test on slanted line
    174   Point.Init(1.,1.,+3.);
     174  Point = Vector(1.,1.,+3.);
    175175  CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    176   Point.Init(0.5,0.5,0.);
    177   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    178   Point.Init(1.,1.,-4.);
     176  Point = Vector(0.5,0.5,0.);
     177  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
     178  Point = Vector(1.,1.,-4.);
    179179  CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    180   Point.Init(0.5,0.5,0.);
     180  Point = Vector(0.5,0.5,0.);
    181181  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    182182
    183183  // simple test on first node
    184   Point.Init(-1.,-1.,5.);
     184  Point = Vector(-1.,-1.,5.);
    185185  CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    186   Point.Init(0.,0.,0.);
     186  Point = Vector(0.,0.,0.);
    187187  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    188188
    189189  // simple test on second node
    190   Point.Init(0.,2.,5.);
     190  Point = Vector(0.,2.,5.);
    191191  CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    192   Point.Init(0.,1.,0.);
     192  Point = Vector(0.,1.,0.);
    193193  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    194194
    195195  // simple test on third node
    196   Point.Init(2.,0.,5.);
     196  Point = Vector(2.,0.,5.);
    197197  CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
    198   Point.Init(1.,0.,0.);
    199   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    200 };
     198  Point = Vector(1.,0.,0.);
     199  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
     200};
  • src/unittests/vectorunittest.cpp

    r632bc3 r8cbb97  
    1717#include "memoryusageobserver.hpp"
    1818#include "vector.hpp"
     19#include "vector_ops.hpp"
    1920#include "vectorunittest.hpp"
     21#include "Plane.hpp"
     22#include "Exceptions/LinearDependenceException.hpp"
    2023
    2124#ifdef HAVE_TESTRUNNER
     
    2326#endif /*HAVE_TESTRUNNER*/
    2427
     28#include <iostream>
     29
     30using namespace std;
     31
    2532/********************************************** Test classes **************************************/
    2633
     
    3138void VectorTest::setUp()
    3239{
    33   zero.Init(0.,0.,0.);
    34   unit.Init(1.,0.,0.);
    35   otherunit.Init(0.,1.,0.);
    36   notunit.Init(0.,1.,1.);
    37   two.Init(2.,1.,0.);
     40  zero  = Vector(0.,0.,0.);
     41  unit = Vector(1.,0.,0.);
     42  otherunit = Vector(0.,1.,0.);
     43  notunit = Vector(0.,1.,1.);
     44  two = Vector(2.,1.,0.);
    3845};
    3946
     
    6673  double factor;
    6774  // copy vector
    68   fixture.Init(2.,3.,4.);
     75  fixture = Vector(2.,3.,4.);
    6976  CPPUNIT_ASSERT_EQUAL( Vector(2.,3.,4.), fixture );
    7077  // summation and scaling
    71   fixture.CopyVector(&zero);
    72   fixture.AddVector(&unit);
    73   CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    74   fixture.CopyVector(&zero);
    75   fixture.SubtractVector(&unit);
     78  fixture = zero + unit;
     79  CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
     80  fixture = zero - unit;
    7681  CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    7782  CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() );
    78   fixture.CopyVector(&zero);
    79   fixture.AddVector(&zero);
     83  fixture = zero + zero;
    8084  CPPUNIT_ASSERT_EQUAL( true, fixture.IsZero() );
    81   fixture.CopyVector(&notunit);
    82   fixture.SubtractVector(&otherunit);
    83   CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    84   fixture.CopyVector(&unit);
    85   fixture.AddVector(&otherunit);
     85  fixture = notunit - otherunit;
     86  CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
     87  fixture = unit - otherunit;
    8688  CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() );
    87   fixture.CopyVector(&notunit);
    88   fixture.SubtractVector(&unit);
    89   fixture.SubtractVector(&otherunit);
     89  fixture = notunit - unit - otherunit;
    9090  CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() );
    91   fixture.CopyVector(&unit);
    92   fixture.Scale(0.98);
     91  fixture = 0.98 * unit;
    9392  CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() );
    94   fixture.CopyVector(&unit);
    95   fixture.Scale(1.);
    96   CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    97   fixture.CopyVector(&unit);
     93  fixture = 1. * unit;
     94  CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    9895  factor = 0.98;
    99   fixture.Scale(factor);
     96  fixture = factor * unit;
    10097  CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() );
    101   fixture.CopyVector(&unit);
    10298  factor = 1.;
    103   fixture.Scale(factor);
     99  fixture = factor * unit;
    104100  CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() );
    105101};
     
    131127void VectorTest::EuclidianScalarProductTest()
    132128{
    133   CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&zero) );
    134   CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&unit) );
    135   CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&otherunit) );
    136   CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(&notunit) );
    137   CPPUNIT_ASSERT_EQUAL( 1., unit.ScalarProduct(&unit) );
    138   CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(&unit) );
    139   CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(&unit) );
    140   CPPUNIT_ASSERT_EQUAL( 1., otherunit.ScalarProduct(&notunit) );
    141   CPPUNIT_ASSERT_EQUAL( 2., two.ScalarProduct(&unit) );
    142   CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(&otherunit) );
    143   CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(&notunit) );
     129  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(zero) );
     130  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(unit) );
     131  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(otherunit) );
     132  CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(notunit) );
     133  CPPUNIT_ASSERT_EQUAL( 1., unit.ScalarProduct(unit) );
     134  CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(unit) );
     135  CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(unit) );
     136  CPPUNIT_ASSERT_EQUAL( 1., otherunit.ScalarProduct(notunit) );
     137  CPPUNIT_ASSERT_EQUAL( 2., two.ScalarProduct(unit) );
     138  CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(otherunit) );
     139  CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(notunit) );
    144140}
    145141
     
    162158void VectorTest::EuclidianDistancesTest()
    163159{
    164   CPPUNIT_ASSERT_EQUAL( 1., zero.Distance(&unit) );
    165   CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance(&unit) );
    166   CPPUNIT_ASSERT_EQUAL( sqrt(2.), zero.Distance(&notunit) );
    167   CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance(&notunit) );
    168   CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance(&notunit) );
     160  CPPUNIT_ASSERT_EQUAL( 1., zero.Distance(unit) );
     161  CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance(unit) );
     162  CPPUNIT_ASSERT_EQUAL( sqrt(2.), zero.Distance(notunit) );
     163  CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance(notunit) );
     164  CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance(notunit) );
    169165}
    170166
     
    173169void VectorTest::EuclidianAnglesTest()
    174170{
    175   CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle(&unit) );
    176   CPPUNIT_ASSERT_EQUAL( 0., unit.Angle(&unit) );
    177   CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle(&unit)) < MYEPSILON );
    178   CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle(&notunit)) < MYEPSILON );
    179   CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle(&notunit)) < MYEPSILON );
     171  CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle(unit) );
     172  CPPUNIT_ASSERT_EQUAL( 0., unit.Angle(unit) );
     173  CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle(unit)) < MYEPSILON );
     174  CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle(notunit)) < MYEPSILON );
     175  CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle(notunit)) < MYEPSILON );
    180176};
    181177
     
    184180void VectorTest::ProjectionTest()
    185181{
    186   CPPUNIT_ASSERT_EQUAL( zero, zero.Projection(&unit) );
    187   CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection(&unit) );
    188   CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.),  otherunit.Projection(&two) );
    189   CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.),  two.Projection(&otherunit) );
     182  CPPUNIT_ASSERT_EQUAL( zero, zero.Projection(unit) );
     183  CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection(unit) );
     184  CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.),  otherunit.Projection(two) );
     185  CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.),  two.Projection(otherunit) );
    190186};
    191187
     
    195191{
    196192  // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ???
    197   CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionWithPlane(&unit, &zero, &zero, &two) );
     193  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unit, zero).GetIntersection(zero, two) );
    198194  CPPUNIT_ASSERT_EQUAL( zero, fixture );
    199195
    200196  // 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, &notunit) );
     197  CPPUNIT_ASSERT_NO_THROW(fixture = Plane(otherunit, two).GetIntersection( unit, notunit) );
    202198  CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture );
    203199
    204200  // four vectors equal to zero
    205   CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&zero, &zero, &zero, &zero, NULL) );
     201  CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(zero, zero, zero, zero), LinearDependenceException);
     202  //CPPUNIT_ASSERT_EQUAL( zero, fixture );
     203
     204  // four vectors equal to unit
     205  CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, unit, unit, unit), LinearDependenceException);
     206  //CPPUNIT_ASSERT_EQUAL( zero, fixture );
     207
     208  // two equal lines
     209  CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, two));
     210  CPPUNIT_ASSERT_EQUAL( unit, fixture );
     211
     212  // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ???
     213  CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, otherunit) );
     214  CPPUNIT_ASSERT_EQUAL( unit, fixture );
     215
     216  // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ???
     217  CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, zero, zero, two) );
    206218  CPPUNIT_ASSERT_EQUAL( zero, fixture );
    207219
    208   // four vectors equal to unit
    209   CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &unit, &unit, &unit, NULL) );
     220  // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ???
     221  CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, zero, otherunit) );
     222  CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture );
     223};
     224
     225/** UnitTest for vector rotations.
     226 */
     227void VectorTest::VectorRotationTest()
     228{
     229  fixture = Vector(-1.,0.,0.);
     230
     231  // zero vector does not change
     232  fixture = RotateVector(zero,unit, 1.);
    210233  CPPUNIT_ASSERT_EQUAL( zero, fixture );
    211234
    212   // two equal lines
    213   CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane(&unit, &two, &unit, &two, NULL) );
     235  fixture = RotateVector(zero, two, 1.);
     236  CPPUNIT_ASSERT_EQUAL( zero,  fixture);
     237
     238  // vector on axis does not change
     239  fixture = RotateVector(unit,unit, 1.);
    214240  CPPUNIT_ASSERT_EQUAL( unit, fixture );
    215241
    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 change
    236   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 change
    244   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 
    251242  // rotations
    252   fixture.CopyVector(&otherunit);
    253   fixture.RotateVector(&unit, M_PI);
     243  fixture = RotateVector(otherunit, unit, M_PI);
    254244  CPPUNIT_ASSERT_EQUAL( Vector(0.,-1.,0.), fixture );
    255245
    256   fixture.CopyVector(&otherunit);
    257   fixture.RotateVector(&unit, 2. * M_PI);
     246  fixture = RotateVector(otherunit, unit, 2. * M_PI);
    258247  CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    259248
    260   fixture.CopyVector(&otherunit);
    261   fixture.RotateVector(&unit, 0);
     249  fixture = RotateVector(otherunit,unit, 0);
    262250  CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    263251
    264   fixture.Init(0.,0.,1.);
    265   fixture.RotateVector(&notunit, M_PI);
     252  fixture = RotateVector(Vector(0.,0.,1.), notunit, M_PI);
    266253  CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    267254}
     
    283270  parallelepiped[8] = 1;
    284271
    285   fixture.CopyVector(zero);
    286   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    287   fixture.Init(2.5,2.5,2.5);
     272  fixture = zero;
     273  CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
     274  fixture = Vector(2.5,2.5,2.5);
    288275  CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    289   fixture.Init(1.,1.,1.);
    290   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    291   fixture.Init(3.5,3.5,3.5);
    292   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    293   fixture.Init(2.,2.,2.);
     276  fixture = Vector(1.,1.,1.);
     277  CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
     278  fixture = Vector(3.5,3.5,3.5);
     279  CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
     280  fixture = Vector(2.,2.,2.);
    294281  CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    295   fixture.Init(2.,3.,2.);
     282  fixture = Vector(2.,3.,2.);
    296283  CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    297   fixture.Init(-2.,2.,-1.);
    298   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    299 }
    300 
     284  fixture = Vector(-2.,2.,-1.);
     285  CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
     286}
     287
  • src/vector.cpp

    r632bc3 r8cbb97  
    66
    77
    8 #include "defs.hpp"
    9 #include "helpers.hpp"
    10 #include "info.hpp"
    11 #include "gslmatrix.hpp"
    12 #include "leastsquaremin.hpp"
    13 #include "log.hpp"
    14 #include "memoryallocator.hpp"
    158#include "vector.hpp"
    169#include "verbose.hpp"
    1710#include "World.hpp"
    18 
    19 #include <gsl/gsl_linalg.h>
    20 #include <gsl/gsl_matrix.h>
    21 #include <gsl/gsl_permutation.h>
    22 #include <gsl/gsl_vector.h>
     11#include "Helpers/Assert.hpp"
     12#include "Helpers/fast_functions.hpp"
     13
     14#include <iostream>
     15
     16using namespace std;
     17
    2318
    2419/************************************ Functions for class vector ************************************/
     
    2621/** Constructor of class vector.
    2722 */
    28 Vector::Vector() { x[0] = x[1] = x[2] = 0.; };
     23Vector::Vector()
     24{
     25  x[0] = x[1] = x[2] = 0.;
     26};
     27
     28/**
     29 * Copy constructor
     30 */
     31
     32Vector::Vector(const Vector& src)
     33{
     34  x[0] = src[0];
     35  x[1] = src[1];
     36  x[2] = src[2];
     37}
    2938
    3039/** Constructor of class vector.
    3140 */
    32 Vector::Vector(const Vector * const a)
    33 {
    34   x[0] = a->x[0];
    35   x[1] = a->x[1];
    36   x[2] = a->x[2];
    37 };
    38 
    39 /** Constructor of class vector.
    40  */
    41 Vector::Vector(const Vector &a)
    42 {
    43   x[0] = a.x[0];
    44   x[1] = a.x[1];
    45   x[2] = a.x[2];
    46 };
    47 
    48 /** Constructor of class vector.
    49  */
    50 Vector::Vector(const double x1, const double x2, const double x3) { x[0] = x1; x[1] = x2; x[2] = x3; };
     41Vector::Vector(const double x1, const double x2, const double x3)
     42{
     43  x[0] = x1;
     44  x[1] = x2;
     45  x[2] = x3;
     46};
     47
     48/**
     49 * Assignment operator
     50 */
     51Vector& Vector::operator=(const Vector& src){
     52  // check for self assignment
     53  if(&src!=this){
     54    x[0] = src[0];
     55    x[1] = src[1];
     56    x[2] = src[2];
     57  }
     58  return *this;
     59}
    5160
    5261/** Desctructor of class vector.
     
    5867 * \return \f$| x - y |^2\f$
    5968 */
    60 double Vector::DistanceSquared(const Vector * const y) const
     69double Vector::DistanceSquared(const Vector &y) const
    6170{
    6271  double res = 0.;
    6372  for (int i=NDIM;i--;)
    64     res += (x[i]-y->x[i])*(x[i]-y->x[i]);
     73    res += (x[i]-y[i])*(x[i]-y[i]);
    6574  return (res);
    6675};
     
    7079 * \return \f$| x - y |\f$
    7180 */
    72 double Vector::Distance(const Vector * const y) const
    73 {
    74   double res = 0.;
    75   for (int i=NDIM;i--;)
    76     res += (x[i]-y->x[i])*(x[i]-y->x[i]);
    77   return (sqrt(res));
     81double Vector::Distance(const Vector &y) const
     82{
     83  return (sqrt(DistanceSquared(y)));
    7884};
    7985
     
    8389 * \return \f$| x - y |\f$
    8490 */
    85 double Vector::PeriodicDistance(const Vector * const y, const double * const cell_size) const
     91double Vector::PeriodicDistance(const Vector &y, const double * const cell_size) const
    8692{
    8793  double res = Distance(y), tmp, matrix[NDIM*NDIM];
    88   Vector Shiftedy, TranslationVector;
    89   int N[NDIM];
    90   matrix[0] = cell_size[0];
    91   matrix[1] = cell_size[1];
    92   matrix[2] = cell_size[3];
    93   matrix[3] = cell_size[1];
    94   matrix[4] = cell_size[2];
    95   matrix[5] = cell_size[4];
    96   matrix[6] = cell_size[3];
    97   matrix[7] = cell_size[4];
    98   matrix[8] = cell_size[5];
    99   // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells
    100   for (N[0]=-1;N[0]<=1;N[0]++)
    101     for (N[1]=-1;N[1]<=1;N[1]++)
    102       for (N[2]=-1;N[2]<=1;N[2]++) {
    103         // create the translation vector
    104         TranslationVector.Zero();
    105         for (int i=NDIM;i--;)
    106           TranslationVector.x[i] = (double)N[i];
    107         TranslationVector.MatrixMultiplication(matrix);
    108         // add onto the original vector to compare with
    109         Shiftedy.CopyVector(y);
    110         Shiftedy.AddVector(&TranslationVector);
    111         // get distance and compare with minimum so far
    112         tmp = Distance(&Shiftedy);
    113         if (tmp < res) res = tmp;
    114       }
    115   return (res);
     94    Vector Shiftedy, TranslationVector;
     95    int N[NDIM];
     96    matrix[0] = cell_size[0];
     97    matrix[1] = cell_size[1];
     98    matrix[2] = cell_size[3];
     99    matrix[3] = cell_size[1];
     100    matrix[4] = cell_size[2];
     101    matrix[5] = cell_size[4];
     102    matrix[6] = cell_size[3];
     103    matrix[7] = cell_size[4];
     104    matrix[8] = cell_size[5];
     105    // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells
     106    for (N[0]=-1;N[0]<=1;N[0]++)
     107      for (N[1]=-1;N[1]<=1;N[1]++)
     108        for (N[2]=-1;N[2]<=1;N[2]++) {
     109          // create the translation vector
     110          TranslationVector.Zero();
     111          for (int i=NDIM;i--;)
     112            TranslationVector[i] = (double)N[i];
     113          TranslationVector.MatrixMultiplication(matrix);
     114          // add onto the original vector to compare with
     115          Shiftedy = y + TranslationVector;
     116          // get distance and compare with minimum so far
     117          tmp = Distance(Shiftedy);
     118          if (tmp < res) res = tmp;
     119        }
     120    return (res);
    116121};
    117122
     
    121126 * \return \f$| x - y |^2\f$
    122127 */
    123 double Vector::PeriodicDistanceSquared(const Vector * const y, const double * const cell_size) const
     128double Vector::PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const
    124129{
    125130  double res = DistanceSquared(y), tmp, matrix[NDIM*NDIM];
    126   Vector Shiftedy, TranslationVector;
    127   int N[NDIM];
    128   matrix[0] = cell_size[0];
    129   matrix[1] = cell_size[1];
    130   matrix[2] = cell_size[3];
    131   matrix[3] = cell_size[1];
    132   matrix[4] = cell_size[2];
    133   matrix[5] = cell_size[4];
    134   matrix[6] = cell_size[3];
    135   matrix[7] = cell_size[4];
    136   matrix[8] = cell_size[5];
    137   // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells
    138   for (N[0]=-1;N[0]<=1;N[0]++)
    139     for (N[1]=-1;N[1]<=1;N[1]++)
    140       for (N[2]=-1;N[2]<=1;N[2]++) {
    141         // create the translation vector
    142         TranslationVector.Zero();
    143         for (int i=NDIM;i--;)
    144           TranslationVector.x[i] = (double)N[i];
    145         TranslationVector.MatrixMultiplication(matrix);
    146         // add onto the original vector to compare with
    147         Shiftedy.CopyVector(y);
    148         Shiftedy.AddVector(&TranslationVector);
    149         // get distance and compare with minimum so far
    150         tmp = DistanceSquared(&Shiftedy);
    151         if (tmp < res) res = tmp;
    152       }
    153   return (res);
     131    Vector Shiftedy, TranslationVector;
     132    int N[NDIM];
     133    matrix[0] = cell_size[0];
     134    matrix[1] = cell_size[1];
     135    matrix[2] = cell_size[3];
     136    matrix[3] = cell_size[1];
     137    matrix[4] = cell_size[2];
     138    matrix[5] = cell_size[4];
     139    matrix[6] = cell_size[3];
     140    matrix[7] = cell_size[4];
     141    matrix[8] = cell_size[5];
     142    // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells
     143    for (N[0]=-1;N[0]<=1;N[0]++)
     144      for (N[1]=-1;N[1]<=1;N[1]++)
     145        for (N[2]=-1;N[2]<=1;N[2]++) {
     146          // create the translation vector
     147          TranslationVector.Zero();
     148          for (int i=NDIM;i--;)
     149            TranslationVector[i] = (double)N[i];
     150          TranslationVector.MatrixMultiplication(matrix);
     151          // add onto the original vector to compare with
     152          Shiftedy = y + TranslationVector;
     153          // get distance and compare with minimum so far
     154          tmp = DistanceSquared(Shiftedy);
     155          if (tmp < res) res = tmp;
     156        }
     157    return (res);
    154158};
    155159
     
    160164void Vector::KeepPeriodic(const double * const matrix)
    161165{
    162 //  int N[NDIM];
    163 //  bool flag = false;
    164   //vector Shifted, TranslationVector;
    165   Vector TestVector;
    166 //  Log() << Verbose(1) << "Begin of KeepPeriodic." << endl;
    167 //  Log() << Verbose(2) << "Vector is: ";
    168 //  Output(out);
    169 //  Log() << Verbose(0) << endl;
    170   TestVector.CopyVector(this);
    171   TestVector.InverseMatrixMultiplication(matrix);
    172   for(int i=NDIM;i--;) { // correct periodically
    173     if (TestVector.x[i] < 0) {  // get every coefficient into the interval [0,1)
    174       TestVector.x[i] += ceil(TestVector.x[i]);
    175     } else {
    176       TestVector.x[i] -= floor(TestVector.x[i]);
     166  //  int N[NDIM];
     167  //  bool flag = false;
     168    //vector Shifted, TranslationVector;
     169  //  Log() << Verbose(1) << "Begin of KeepPeriodic." << endl;
     170  //  Log() << Verbose(2) << "Vector is: ";
     171  //  Output(out);
     172  //  Log() << Verbose(0) << endl;
     173    InverseMatrixMultiplication(matrix);
     174    for(int i=NDIM;i--;) { // correct periodically
     175      if (at(i) < 0) {  // get every coefficient into the interval [0,1)
     176        at(i) += ceil(at(i));
     177      } else {
     178        at(i) -= floor(at(i));
     179      }
    177180    }
    178   }
    179   TestVector.MatrixMultiplication(matrix);
    180   CopyVector(&TestVector);
    181 //  Log() << Verbose(2) << "New corrected vector is: ";
    182 //  Output(out);
    183 //  Log() << Verbose(0) << endl;
    184 //  Log() << Verbose(1) << "End of KeepPeriodic." << endl;
     181    MatrixMultiplication(matrix);
     182  //  Log() << Verbose(2) << "New corrected vector is: ";
     183  //  Output(out);
     184  //  Log() << Verbose(0) << endl;
     185  //  Log() << Verbose(1) << "End of KeepPeriodic." << endl;
    185186};
    186187
     
    189190 * \return \f$\langle x, y \rangle\f$
    190191 */
    191 double Vector::ScalarProduct(const Vector * const y) const
     192double Vector::ScalarProduct(const Vector &y) const
    192193{
    193194  double res = 0.;
    194195  for (int i=NDIM;i--;)
    195     res += x[i]*y->x[i];
     196    res += x[i]*y[i];
    196197  return (res);
    197198};
     
    204205 *  \return \f$ x \times y \f&
    205206 */
    206 void Vector::VectorProduct(const Vector * const y)
     207void Vector::VectorProduct(const Vector &y)
    207208{
    208209  Vector tmp;
    209   tmp.x[0] = x[1]* (y->x[2]) - x[2]* (y->x[1]);
    210   tmp.x[1] = x[2]* (y->x[0]) - x[0]* (y->x[2]);
    211   tmp.x[2] = x[0]* (y->x[1]) - x[1]* (y->x[0]);
    212   this->CopyVector(&tmp);
     210  tmp[0] = x[1]* (y[2]) - x[2]* (y[1]);
     211  tmp[1] = x[2]* (y[0]) - x[0]* (y[2]);
     212  tmp[2] = x[0]* (y[1]) - x[1]* (y[0]);
     213  (*this) = tmp;
    213214};
    214215
     
    218219 * \return \f$\langle x, y \rangle\f$
    219220 */
    220 void Vector::ProjectOntoPlane(const Vector * const y)
     221void Vector::ProjectOntoPlane(const Vector &y)
    221222{
    222223  Vector tmp;
    223   tmp.CopyVector(y);
     224  tmp = y;
    224225  tmp.Normalize();
    225   tmp.Scale(ScalarProduct(&tmp));
    226   this->SubtractVector(&tmp);
    227 };
    228 
    229 /** Calculates the intersection point between a line defined by \a *LineVector and \a *LineVector2 and a plane defined by \a *Normal and \a *PlaneOffset.
    230  * According to [Bronstein] the vectorial plane equation is:
    231  *   -# \f$\stackrel{r}{\rightarrow} \cdot \stackrel{N}{\rightarrow} + D = 0\f$,
    232  * where \f$\stackrel{r}{\rightarrow}\f$ is the vector to be testet, \f$\stackrel{N}{\rightarrow}\f$ is the plane's normal vector and
    233  * \f$D = - \stackrel{a}{\rightarrow} \stackrel{N}{\rightarrow}\f$, the offset with respect to origin, if \f$\stackrel{a}{\rightarrow}\f$,
    234  * is an offset vector onto the plane. The line is parametrized by \f$\stackrel{x}{\rightarrow} + k \stackrel{t}{\rightarrow}\f$, where
    235  * \f$\stackrel{x}{\rightarrow}\f$ is the offset and \f$\stackrel{t}{\rightarrow}\f$ the directional vector (NOTE: No need to normalize
    236  * the latter). Inserting the parametrized form into the plane equation and solving for \f$k\f$, which we insert then into the parametrization
    237  * of the line yields the intersection point on the plane.
    238  * \param *out output stream for debugging
    239  * \param *PlaneNormal Plane's normal vector
    240  * \param *PlaneOffset Plane's offset vector
    241  * \param *Origin first vector of line
    242  * \param *LineVector second vector of line
    243  * \return true -  \a this contains intersection point on return, false - line is parallel to plane (even if in-plane)
    244  */
    245 bool Vector::GetIntersectionWithPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset, const Vector * const Origin, const Vector * const LineVector)
    246 {
    247   Info FunctionInfo(__func__);
    248   double factor;
    249   Vector Direction, helper;
    250 
    251   // find intersection of a line defined by Offset and Direction with a  plane defined by triangle
    252   Direction.CopyVector(LineVector);
    253   Direction.SubtractVector(Origin);
    254   Direction.Normalize();
    255   DoLog(1) && (Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl);
    256   //Log() << Verbose(1) << "INFO: PlaneNormal is " << *PlaneNormal << " and PlaneOffset is " << *PlaneOffset << "." << endl;
    257   factor = Direction.ScalarProduct(PlaneNormal);
    258   if (fabs(factor) < MYEPSILON) { // Uniqueness: line parallel to plane?
    259     DoLog(1) && (Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl);
    260     return false;
    261   }
    262   helper.CopyVector(PlaneOffset);
    263   helper.SubtractVector(Origin);
    264   factor = helper.ScalarProduct(PlaneNormal)/factor;
    265   if (fabs(factor) < MYEPSILON) { // Origin is in-plane
    266     DoLog(1) && (Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl);
    267     CopyVector(Origin);
    268     return true;
    269   }
    270   //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal));
    271   Direction.Scale(factor);
    272   CopyVector(Origin);
    273   DoLog(1) && (Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl);
    274   AddVector(&Direction);
    275 
    276   // test whether resulting vector really is on plane
    277   helper.CopyVector(this);
    278   helper.SubtractVector(PlaneOffset);
    279   if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) {
    280     DoLog(1) && (Log() << Verbose(1) << "GOOD: Intersection is " << *this << "." << endl);
    281     return true;
    282   } else {
    283     DoeLog(2) && (eLog()<< Verbose(2) << "Intersection point " << *this << " is not on plane." << endl);
    284     return false;
    285   }
     226  tmp.Scale(ScalarProduct(tmp));
     227  *this -= tmp;
    286228};
    287229
     
    290232 * \param *PlaneNormal normal of plane
    291233 * \param *PlaneOffset offset of plane
     234 * \return distance to plane
    292235 * \return distance vector onto to plane
    293236 */
    294 Vector Vector::GetDistanceVectorToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const
    295 {
    296   Vector temp;
    297 
    298   // first create part that is orthonormal to PlaneNormal with withdraw
    299   temp.CopyVector(this);
    300   temp.SubtractVector(PlaneOffset);
    301   temp.MakeNormalVector(PlaneNormal);
     237Vector Vector::GetDistanceVectorToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const
     238{
     239  Vector temp = (*this) - PlaneOffset;
     240  temp.MakeNormalTo(PlaneNormal);
    302241  temp.Scale(-1.);
    303242  // then add connecting vector from plane to point
    304   temp.AddVector(this);
    305   temp.SubtractVector(PlaneOffset);
     243  temp += (*this)-PlaneOffset;
    306244  double sign = temp.ScalarProduct(PlaneNormal);
    307245  if (fabs(sign) > MYEPSILON)
     
    314252  return temp;
    315253};
     254
    316255
    317256/** Calculates the minimum distance of this vector to the plane.
     
    322261 * \return distance to plane
    323262 */
    324 double Vector::DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const
     263double Vector::DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const
    325264{
    326265  return GetDistanceVectorToPlane(PlaneNormal,PlaneOffset).Norm();
    327 };
    328 
    329 /** Calculates the intersection of the two lines that are both on the same plane.
    330  * This is taken from Weisstein, Eric W. "Line-Line Intersection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineIntersection.html
    331  * \param *out output stream for debugging
    332  * \param *Line1a first vector of first line
    333  * \param *Line1b second vector of first line
    334  * \param *Line2a first vector of second line
    335  * \param *Line2b second vector of second line
    336  * \param *PlaneNormal normal of plane, is supplemental/arbitrary
    337  * \return true - \a this will contain the intersection on return, false - lines are parallel
    338  */
    339 bool Vector::GetIntersectionOfTwoLinesOnPlane(const Vector * const Line1a, const Vector * const Line1b, const Vector * const Line2a, const Vector * const Line2b, const Vector *PlaneNormal)
    340 {
    341   Info FunctionInfo(__func__);
    342 
    343   GSLMatrix *M = new GSLMatrix(4,4);
    344 
    345   M->SetAll(1.);
    346   for (int i=0;i<3;i++) {
    347     M->Set(0, i, Line1a->x[i]);
    348     M->Set(1, i, Line1b->x[i]);
    349     M->Set(2, i, Line2a->x[i]);
    350     M->Set(3, i, Line2b->x[i]);
    351   }
    352  
    353   //Log() << Verbose(1) << "Coefficent matrix is:" << endl;
    354   //ostream &output = Log() << Verbose(1);
    355   //for (int i=0;i<4;i++) {
    356   //  for (int j=0;j<4;j++)
    357   //    output << "\t" << M->Get(i,j);
    358   //  output << endl;
    359   //}
    360   if (fabs(M->Determinant()) > MYEPSILON) {
    361     DoLog(1) && (Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl);
    362     return false;
    363   }
    364   delete(M);
    365   DoLog(1) && (Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl);
    366 
    367 
    368   // constuct a,b,c
    369   Vector a;
    370   Vector b;
    371   Vector c;
    372   Vector d;
    373   a.CopyVector(Line1b);
    374   a.SubtractVector(Line1a);
    375   b.CopyVector(Line2b);
    376   b.SubtractVector(Line2a);
    377   c.CopyVector(Line2a);
    378   c.SubtractVector(Line1a);
    379   d.CopyVector(Line2b);
    380   d.SubtractVector(Line1b);
    381   DoLog(1) && (Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl);
    382   if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) {
    383    Zero();
    384    DoLog(1) && (Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl);
    385    return false;
    386   }
    387 
    388   // check for parallelity
    389   Vector parallel;
    390   double factor = 0.;
    391   if (fabs(a.ScalarProduct(&b)*a.ScalarProduct(&b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) {
    392     parallel.CopyVector(Line1a);
    393     parallel.SubtractVector(Line2a);
    394     factor = parallel.ScalarProduct(&a)/a.Norm();
    395     if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {
    396       CopyVector(Line2a);
    397       DoLog(1) && (Log() << Verbose(1) << "Lines conincide." << endl);
    398       return true;
    399     } else {
    400       parallel.CopyVector(Line1a);
    401       parallel.SubtractVector(Line2b);
    402       factor = parallel.ScalarProduct(&a)/a.Norm();
    403       if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {
    404         CopyVector(Line2b);
    405         DoLog(1) && (Log() << Verbose(1) << "Lines conincide." << endl);
    406         return true;
    407       }
    408     }
    409     DoLog(1) && (Log() << Verbose(1) << "Lines are parallel." << endl);
    410     Zero();
    411     return false;
    412   }
    413 
    414   // obtain s
    415   double s;
    416   Vector temp1, temp2;
    417   temp1.CopyVector(&c);
    418   temp1.VectorProduct(&b);
    419   temp2.CopyVector(&a);
    420   temp2.VectorProduct(&b);
    421   DoLog(1) && (Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl);
    422   if (fabs(temp2.NormSquared()) > MYEPSILON)
    423     s = temp1.ScalarProduct(&temp2)/temp2.NormSquared();
    424   else
    425     s = 0.;
    426   DoLog(1) && (Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(&temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl);
    427 
    428   // construct intersection
    429   CopyVector(&a);
    430   Scale(s);
    431   AddVector(Line1a);
    432   DoLog(1) && (Log() << Verbose(1) << "Intersection is at " << *this << "." << endl);
    433 
    434   return true;
    435266};
    436267
     
    438269 * \param *y array to second vector
    439270 */
    440 void Vector::ProjectIt(const Vector * const y)
    441 {
    442   Vector helper(*y);
    443   helper.Scale(-(ScalarProduct(y)));
    444   AddVector(&helper);
     271void Vector::ProjectIt(const Vector &y)
     272{
     273  (*this) += (-ScalarProduct(y))*y;
    445274};
    446275
     
    449278 * \return Vector
    450279 */
    451 Vector Vector::Projection(const Vector * const y) const
    452 {
    453   Vector helper(*y);
    454   helper.Scale((ScalarProduct(y)/y->NormSquared()));
     280Vector Vector::Projection(const Vector &y) const
     281{
     282  Vector helper = y;
     283  helper.Scale((ScalarProduct(y)/y.NormSquared()));
    455284
    456285  return helper;
     
    462291double Vector::Norm() const
    463292{
    464   double res = 0.;
    465   for (int i=NDIM;i--;)
    466     res += this->x[i]*this->x[i];
    467   return (sqrt(res));
     293  return (sqrt(NormSquared()));
    468294};
    469295
     
    473299double Vector::NormSquared() const
    474300{
    475   return (ScalarProduct(this));
     301  return (ScalarProduct(*this));
    476302};
    477303
     
    480306void Vector::Normalize()
    481307{
    482   double res = 0.;
    483   for (int i=NDIM;i--;)
    484     res += this->x[i]*this->x[i];
    485   if (fabs(res) > MYEPSILON)
    486     res = 1./sqrt(res);
    487   Scale(&res);
     308  double factor = Norm();
     309  (*this) *= 1/factor;
    488310};
    489311
     
    492314void Vector::Zero()
    493315{
    494   for (int i=NDIM;i--;)
    495     this->x[i] = 0.;
     316  at(0)=at(1)=at(2)=0;
    496317};
    497318
     
    500321void Vector::One(const double one)
    501322{
    502   for (int i=NDIM;i--;)
    503     this->x[i] = one;
    504 };
    505 
    506 /** Initialises all components of this vector.
    507  */
    508 void Vector::Init(const double x1, const double x2, const double x3)
    509 {
    510   x[0] = x1;
    511   x[1] = x2;
    512   x[2] = x3;
     323  at(0)=at(1)=at(2)=one;
    513324};
    514325
     
    532343 * @return true - vector is normalized, false - vector is not
    533344 */
    534 bool Vector::IsNormalTo(const Vector * const normal) const
     345bool Vector::IsNormalTo(const Vector &normal) const
    535346{
    536347  if (ScalarProduct(normal) < MYEPSILON)
     
    543354 * @return true - vector is normalized, false - vector is not
    544355 */
    545 bool Vector::IsEqualTo(const Vector * const a) const
     356bool Vector::IsEqualTo(const Vector &a) const
    546357{
    547358  bool status = true;
    548359  for (int i=0;i<NDIM;i++) {
    549     if (fabs(x[i] - a->x[i]) > MYEPSILON)
     360    if (fabs(x[i] - a[i]) > MYEPSILON)
    550361      status = false;
    551362  }
     
    557368 * \return \f$\acos\bigl(frac{\langle x, y \rangle}{|x||y|}\bigr)\f$
    558369 */
    559 double Vector::Angle(const Vector * const y) const
    560 {
    561   double norm1 = Norm(), norm2 = y->Norm();
     370double Vector::Angle(const Vector &y) const
     371{
     372  double norm1 = Norm(), norm2 = y.Norm();
    562373  double angle = -1;
    563374  if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON))
     
    572383};
    573384
    574 /** Rotates the vector relative to the origin around the axis given by \a *axis by an angle of \a alpha.
    575  * \param *axis rotation axis
    576  * \param alpha rotation angle in radian
    577  */
    578 void Vector::RotateVector(const Vector * const axis, const double alpha)
    579 {
    580   Vector a,y;
    581   // normalise this vector with respect to axis
    582   a.CopyVector(this);
    583   a.ProjectOntoPlane(axis);
    584   // construct normal vector
    585   bool rotatable = y.MakeNormalVector(axis,&a);
    586   // The normal vector cannot be created if there is linar dependency.
    587   // Then the vector to rotate is on the axis and any rotation leads to the vector itself.
    588   if (!rotatable) {
    589     return;
    590   }
    591   y.Scale(Norm());
    592   // scale normal vector by sine and this vector by cosine
    593   y.Scale(sin(alpha));
    594   a.Scale(cos(alpha));
    595   CopyVector(Projection(axis));
    596   // add scaled normal vector onto this vector
    597   AddVector(&y);
    598   // add part in axis direction
    599   AddVector(&a);
    600 };
     385
     386double& Vector::operator[](size_t i){
     387  ASSERT(i<=NDIM && i>=0,"Vector Index out of Range");
     388  return x[i];
     389}
     390
     391const double& Vector::operator[](size_t i) const{
     392  ASSERT(i<=NDIM && i>=0,"Vector Index out of Range");
     393  return x[i];
     394}
     395
     396double& Vector::at(size_t i){
     397  return (*this)[i];
     398}
     399
     400const double& Vector::at(size_t i) const{
     401  return (*this)[i];
     402}
     403
     404double* Vector::get(){
     405  return x;
     406}
    601407
    602408/** Compares vector \a to vector \a b component-wise.
     
    605411 * \return a == b
    606412 */
    607 bool operator==(const Vector& a, const Vector& b)
    608 {
    609   bool status = true;
    610   for (int i=0;i<NDIM;i++)
    611     status = status && (fabs(a.x[i] - b.x[i]) < MYEPSILON);
    612   return status;
     413bool Vector::operator==(const Vector& b) const
     414{
     415  return IsEqualTo(b);
    613416};
    614417
     
    618421 * \return lhs + a
    619422 */
    620 const Vector& operator+=(Vector& a, const Vector& b)
    621 {
    622   a.AddVector(&b);
    623   return a;
     423const Vector& Vector::operator+=(const Vector& b)
     424{
     425  this->AddVector(b);
     426  return *this;
    624427};
    625428
     
    629432 * \return lhs - a
    630433 */
    631 const Vector& operator-=(Vector& a, const Vector& b)
    632 {
    633   a.SubtractVector(&b);
    634   return a;
     434const Vector& Vector::operator-=(const Vector& b)
     435{
     436  this->SubtractVector(b);
     437  return *this;
    635438};
    636439
     
    651454 * \return a + b
    652455 */
    653 Vector const operator+(const Vector& a, const Vector& b)
    654 {
    655   Vector x(a);
    656   x.AddVector(&b);
     456Vector const Vector::operator+(const Vector& b) const
     457{
     458  Vector x = *this;
     459  x.AddVector(b);
    657460  return x;
    658461};
     
    663466 * \return a - b
    664467 */
    665 Vector const operator-(const Vector& a, const Vector& b)
    666 {
    667   Vector x(a);
    668   x.SubtractVector(&b);
     468Vector const Vector::operator-(const Vector& b) const
     469{
     470  Vector x = *this;
     471  x.SubtractVector(b);
    669472  return x;
    670473};
     
    694497};
    695498
    696 /** Prints a 3dim vector.
    697  * prints no end of line.
    698  */
    699 void Vector::Output() const
    700 {
    701   DoLog(0) && (Log() << Verbose(0) << "(");
    702   for (int i=0;i<NDIM;i++) {
    703     DoLog(0) && (Log() << Verbose(0) << x[i]);
    704     if (i != 2)
    705       DoLog(0) && (Log() << Verbose(0) << ",");
    706   }
    707   DoLog(0) && (Log() << Verbose(0) << ")");
    708 };
    709 
    710499ostream& operator<<(ostream& ost, const Vector& m)
    711500{
    712501  ost << "(";
    713502  for (int i=0;i<NDIM;i++) {
    714     ost << m.x[i];
     503    ost << m[i];
    715504    if (i != 2)
    716505      ost << ",";
     
    720509};
    721510
    722 /** Scales each atom coordinate by an individual \a factor.
    723  * \param *factor pointer to scaling factor
    724  */
    725 void Vector::Scale(const double ** const factor)
     511
     512void Vector::ScaleAll(const double *factor)
    726513{
    727514  for (int i=NDIM;i--;)
    728     x[i] *= (*factor)[i];
    729 };
    730 
    731 void Vector::Scale(const double * const factor)
    732 {
    733   for (int i=NDIM;i--;)
    734     x[i] *= *factor;
    735 };
     515    x[i] *= factor[i];
     516};
     517
     518
    736519
    737520void Vector::Scale(const double factor)
     
    739522  for (int i=NDIM;i--;)
    740523    x[i] *= factor;
    741 };
    742 
    743 /** Translate atom by given vector.
    744  * \param trans[] translation vector.
    745  */
    746 void Vector::Translate(const Vector * const trans)
    747 {
    748   for (int i=NDIM;i--;)
    749     x[i] += trans->x[i];
    750524};
    751525
     
    773547void Vector::MatrixMultiplication(const double * const M)
    774548{
    775   Vector C;
    776549  // do the matrix multiplication
    777   C.x[0] = M[0]*x[0]+M[3]*x[1]+M[6]*x[2];
    778   C.x[1] = M[1]*x[0]+M[4]*x[1]+M[7]*x[2];
    779   C.x[2] = M[2]*x[0]+M[5]*x[1]+M[8]*x[2];
    780   // transfer the result into this
    781   for (int i=NDIM;i--;)
    782     x[i] = C.x[i];
     550  at(0) = M[0]*x[0]+M[3]*x[1]+M[6]*x[2];
     551  at(1) = M[1]*x[0]+M[4]*x[1]+M[7]*x[2];
     552  at(2) = M[2]*x[0]+M[5]*x[1]+M[8]*x[2];
    783553};
    784554
     
    786556 * \param *matrix NDIM_NDIM array
    787557 */
    788 void Vector::InverseMatrixMultiplication(const double * const A)
    789 {
    790   Vector C;
     558bool Vector::InverseMatrixMultiplication(const double * const A)
     559{
    791560  double B[NDIM*NDIM];
    792561  double detA = RDET3(A);
     
    807576
    808577    // do the matrix multiplication
    809     C.x[0] = B[0]*x[0]+B[3]*x[1]+B[6]*x[2];
    810     C.x[1] = B[1]*x[0]+B[4]*x[1]+B[7]*x[2];
    811     C.x[2] = B[2]*x[0]+B[5]*x[1]+B[8]*x[2];
    812     // transfer the result into this
    813     for (int i=NDIM;i--;)
    814       x[i] = C.x[i];
     578    at(0) = B[0]*x[0]+B[3]*x[1]+B[6]*x[2];
     579    at(1) = B[1]*x[0]+B[4]*x[1]+B[7]*x[2];
     580    at(2) = B[2]*x[0]+B[5]*x[1]+B[8]*x[2];
     581
     582    return true;
    815583  } else {
    816     DoeLog(1) && (eLog()<< Verbose(1) << "inverse of matrix does not exists: det A = " << detA << "." << endl);
     584    return false;
    817585  }
    818586};
     
    826594 * \param *factors three-component vector with the factor for each given vector
    827595 */
    828 void Vector::LinearCombinationOfVectors(const Vector * const x1, const Vector * const x2, const Vector * const x3, const double * const factors)
    829 {
    830   for(int i=NDIM;i--;)
    831     x[i] = factors[0]*x1->x[i] + factors[1]*x2->x[i] + factors[2]*x3->x[i];
     596void Vector::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors)
     597{
     598  (*this) = (factors[0]*x1) +
     599            (factors[1]*x2) +
     600            (factors[2]*x3);
    832601};
    833602
     
    835604 * \param n[] normal vector of mirror plane.
    836605 */
    837 void Vector::Mirror(const Vector * const n)
     606void Vector::Mirror(const Vector &n)
    838607{
    839608  double projection;
    840   projection = ScalarProduct(n)/n->ScalarProduct(n);    // remove constancy from n (keep as logical one)
     609  projection = ScalarProduct(n)/n.NormSquared();    // remove constancy from n (keep as logical one)
    841610  // withdraw projected vector twice from original one
    842   DoLog(1) && (Log() << Verbose(1) << "Vector: ");
    843   Output();
    844   DoLog(0) && (Log() << Verbose(0) << "\t");
    845611  for (int i=NDIM;i--;)
    846     x[i] -= 2.*projection*n->x[i];
    847   DoLog(0) && (Log() << Verbose(0) << "Projected vector: ");
    848   Output();
    849   DoLog(0) && (Log() << Verbose(0) << endl);
    850 };
    851 
    852 /** Calculates normal vector for three given vectors (being three points in space).
    853  * Makes this vector orthonormal to the three given points, making up a place in 3d space.
    854  * \param *y1 first vector
    855  * \param *y2 second vector
    856  * \param *y3 third vector
    857  * \return true - success, vectors are linear independent, false - failure due to linear dependency
    858  */
    859 bool Vector::MakeNormalVector(const Vector * const y1, const Vector * const y2, const Vector * const y3)
    860 {
    861   Vector x1, x2;
    862 
    863   x1.CopyVector(y1);
    864   x1.SubtractVector(y2);
    865   x2.CopyVector(y3);
    866   x2.SubtractVector(y2);
    867   if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    868     DoeLog(2) && (eLog()<< Verbose(2) << "Given vectors are linear dependent." << endl);
    869     return false;
    870   }
    871 //  Log() << Verbose(4) << "relative, first plane coordinates:";
    872 //  x1.Output((ofstream *)&cout);
    873 //  Log() << Verbose(0) << endl;
    874 //  Log() << Verbose(4) << "second plane coordinates:";
    875 //  x2.Output((ofstream *)&cout);
    876 //  Log() << Verbose(0) << endl;
    877 
    878   this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]);
    879   this->x[1] = (x1.x[2]*x2.x[0] - x1.x[0]*x2.x[2]);
    880   this->x[2] = (x1.x[0]*x2.x[1] - x1.x[1]*x2.x[0]);
    881   Normalize();
    882 
    883   return true;
    884 };
    885 
    886 
    887 /** Calculates orthonormal vector to two given vectors.
    888  * Makes this vector orthonormal to two given vectors. This is very similar to the other
    889  * vector::MakeNormalVector(), only there three points whereas here two difference
    890  * vectors are given.
    891  * \param *x1 first vector
    892  * \param *x2 second vector
    893  * \return true - success, vectors are linear independent, false - failure due to linear dependency
    894  */
    895 bool Vector::MakeNormalVector(const Vector * const y1, const Vector * const y2)
    896 {
    897   Vector x1,x2;
    898   x1.CopyVector(y1);
    899   x2.CopyVector(y2);
    900   Zero();
    901   if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    902     DoeLog(2) && (eLog()<< Verbose(2) << "Given vectors are linear dependent." << endl);
    903     return false;
    904   }
    905 //  Log() << Verbose(4) << "relative, first plane coordinates:";
    906 //  x1.Output((ofstream *)&cout);
    907 //  Log() << Verbose(0) << endl;
    908 //  Log() << Verbose(4) << "second plane coordinates:";
    909 //  x2.Output((ofstream *)&cout);
    910 //  Log() << Verbose(0) << endl;
    911 
    912   this->x[0] = (x1.x[1]*x2.x[2] - x1.x[2]*x2.x[1]);
    913   this->x[1] = (x1.x[2]*x2.x[0] - x1.x[0]*x2.x[2]);
    914   this->x[2] = (x1.x[0]*x2.x[1] - x1.x[1]*x2.x[0]);
    915   Normalize();
    916 
    917   return true;
     612    at(i) -= 2.*projection*n[i];
    918613};
    919614
     
    924619 * \return true - success, false - vector is zero
    925620 */
    926 bool Vector::MakeNormalVector(const Vector * const y1)
     621bool Vector::MakeNormalTo(const Vector &y1)
    927622{
    928623  bool result = false;
    929   double factor = y1->ScalarProduct(this)/y1->NormSquared();
     624  double factor = y1.ScalarProduct(*this)/y1.NormSquared();
    930625  Vector x1;
    931   x1.CopyVector(y1);
    932   x1.Scale(factor);
    933   SubtractVector(&x1);
     626  x1 = factor * y1;
     627  SubtractVector(x1);
    934628  for (int i=NDIM;i--;)
    935629    result = result || (fabs(x[i]) > MYEPSILON);
     
    944638 * \return true - success, false - failure (null vector given)
    945639 */
    946 bool Vector::GetOneNormalVector(const Vector * const GivenVector)
     640bool Vector::GetOneNormalVector(const Vector &GivenVector)
    947641{
    948642  int Components[NDIM]; // contains indices of non-zero components
     
    951645  double norm;
    952646
    953   DoLog(4) && (Log() << Verbose(4));
    954   GivenVector->Output();
    955   DoLog(0) && (Log() << Verbose(0) << endl);
    956647  for (j=NDIM;j--;)
    957648    Components[j] = -1;
    958649  // find two components != 0
    959650  for (j=0;j<NDIM;j++)
    960     if (fabs(GivenVector->x[j]) > MYEPSILON)
     651    if (fabs(GivenVector[j]) > MYEPSILON)
    961652      Components[Last++] = j;
    962   DoLog(4) && (Log() << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl);
    963653
    964654  switch(Last) {
    965655    case 3:  // threecomponent system
    966656    case 2:  // two component system
    967       norm = sqrt(1./(GivenVector->x[Components[1]]*GivenVector->x[Components[1]]) + 1./(GivenVector->x[Components[0]]*GivenVector->x[Components[0]]));
     657      norm = sqrt(1./(GivenVector[Components[1]]*GivenVector[Components[1]]) + 1./(GivenVector[Components[0]]*GivenVector[Components[0]]));
    968658      x[Components[2]] = 0.;
    969659      // in skp both remaining parts shall become zero but with opposite sign and third is zero
    970       x[Components[1]] = -1./GivenVector->x[Components[1]] / norm;
    971       x[Components[0]] = 1./GivenVector->x[Components[0]] / norm;
     660      x[Components[1]] = -1./GivenVector[Components[1]] / norm;
     661      x[Components[0]] = 1./GivenVector[Components[0]] / norm;
    972662      return true;
    973663      break;
     
    984674};
    985675
    986 /** Determines parameter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.
    987  * \param *A first plane vector
    988  * \param *B second plane vector
    989  * \param *C third plane vector
    990  * \return scaling parameter for this vector
    991  */
    992 double Vector::CutsPlaneAt(const Vector * const A, const Vector * const B, const Vector * const C) const
    993 {
    994 //  Log() << Verbose(3) << "For comparison: ";
    995 //  Log() << Verbose(0) << "A " << A->Projection(this) << "\t";
    996 //  Log() << Verbose(0) << "B " << B->Projection(this) << "\t";
    997 //  Log() << Verbose(0) << "C " << C->Projection(this) << "\t";
    998 //  Log() << Verbose(0) << endl;
    999   return A->ScalarProduct(this);
    1000 };
    1001 
    1002 /** Creates a new vector as the one with least square distance to a given set of \a vectors.
    1003  * \param *vectors set of vectors
    1004  * \param num number of vectors
    1005  * \return true if success, false if failed due to linear dependency
    1006  */
    1007 bool Vector::LSQdistance(const Vector **vectors, int num)
    1008 {
    1009   int j;
    1010 
    1011   for (j=0;j<num;j++) {
    1012     DoLog(1) && (Log() << Verbose(1) << j << "th atom's vector: ");
    1013     (vectors[j])->Output();
    1014     DoLog(0) && (Log() << Verbose(0) << endl);
    1015   }
    1016 
    1017   int np = 3;
    1018   struct LSQ_params par;
    1019 
    1020    const gsl_multimin_fminimizer_type *T =
    1021      gsl_multimin_fminimizer_nmsimplex;
    1022    gsl_multimin_fminimizer *s = NULL;
    1023    gsl_vector *ss, *y;
    1024    gsl_multimin_function minex_func;
    1025 
    1026    size_t iter = 0, i;
    1027    int status;
    1028    double size;
    1029 
    1030    /* Initial vertex size vector */
    1031    ss = gsl_vector_alloc (np);
    1032    y = gsl_vector_alloc (np);
    1033 
    1034    /* Set all step sizes to 1 */
    1035    gsl_vector_set_all (ss, 1.0);
    1036 
    1037    /* Starting point */
    1038    par.vectors = vectors;
    1039    par.num = num;
    1040 
    1041    for (i=NDIM;i--;)
    1042     gsl_vector_set(y, i, (vectors[0]->x[i] - vectors[1]->x[i])/2.);
    1043 
    1044    /* Initialize method and iterate */
    1045    minex_func.f = &LSQ;
    1046    minex_func.n = np;
    1047    minex_func.params = (void *)&par;
    1048 
    1049    s = gsl_multimin_fminimizer_alloc (T, np);
    1050    gsl_multimin_fminimizer_set (s, &minex_func, y, ss);
    1051 
    1052    do
    1053      {
    1054        iter++;
    1055        status = gsl_multimin_fminimizer_iterate(s);
    1056 
    1057        if (status)
    1058          break;
    1059 
    1060        size = gsl_multimin_fminimizer_size (s);
    1061        status = gsl_multimin_test_size (size, 1e-2);
    1062 
    1063        if (status == GSL_SUCCESS)
    1064          {
    1065            printf ("converged to minimum at\n");
    1066          }
    1067 
    1068        printf ("%5d ", (int)iter);
    1069        for (i = 0; i < (size_t)np; i++)
    1070          {
    1071            printf ("%10.3e ", gsl_vector_get (s->x, i));
    1072          }
    1073        printf ("f() = %7.3f size = %.3f\n", s->fval, size);
    1074      }
    1075    while (status == GSL_CONTINUE && iter < 100);
    1076 
    1077   for (i=(size_t)np;i--;)
    1078     this->x[i] = gsl_vector_get(s->x, i);
    1079    gsl_vector_free(y);
    1080    gsl_vector_free(ss);
    1081    gsl_multimin_fminimizer_free (s);
    1082 
    1083   return true;
    1084 };
    1085 
    1086676/** Adds vector \a *y componentwise.
    1087677 * \param *y vector
    1088678 */
    1089 void Vector::AddVector(const Vector * const y)
    1090 {
    1091   for (int i=NDIM;i--;)
    1092     this->x[i] += y->x[i];
     679void Vector::AddVector(const Vector &y)
     680{
     681  for(int i=NDIM;i--;)
     682    x[i] += y[i];
    1093683}
    1094684
     
    1096686 * \param *y vector
    1097687 */
    1098 void Vector::SubtractVector(const Vector * const y)
    1099 {
    1100   for (int i=NDIM;i--;)
    1101     this->x[i] -= y->x[i];
    1102 }
    1103 
    1104 /** Copy vector \a *y componentwise.
    1105  * \param *y vector
    1106  */
    1107 void Vector::CopyVector(const Vector * const y)
    1108 {
    1109   // check for self assignment
    1110   if(y!=this){
    1111     for (int i=NDIM;i--;)
    1112       this->x[i] = y->x[i];
    1113   }
    1114 }
    1115 
    1116 /** Copy vector \a y componentwise.
    1117  * \param y vector
    1118  */
    1119 void Vector::CopyVector(const Vector &y)
    1120 {
    1121   // check for self assignment
    1122   if(&y!=this) {
    1123     for (int i=NDIM;i--;)
    1124       this->x[i] = y.x[i];
    1125   }
    1126 }
    1127 
    1128 
    1129 /** Asks for position, checks for boundary.
    1130  * \param cell_size unitary size of cubic cell, coordinates must be within 0...cell_size
    1131  * \param check whether bounds shall be checked (true) or not (false)
    1132  */
    1133 void Vector::AskPosition(const double * const cell_size, const bool check)
    1134 {
    1135   char coords[3] = {'x','y','z'};
    1136   int j = -1;
    1137   for (int i=0;i<3;i++) {
    1138     j += i+1;
    1139     do {
    1140       DoLog(0) && (Log() << Verbose(0) << coords[i] << "[0.." << cell_size[j] << "]: ");
    1141       cin >> x[i];
    1142     } while (((x[i] < 0) || (x[i] >= cell_size[j])) && (check));
    1143   }
    1144 };
    1145 
    1146 /** Solves a vectorial system consisting of two orthogonal statements and a norm statement.
    1147  * This is linear system of equations to be solved, however of the three given (skp of this vector\
    1148  * with either of the three hast to be zero) only two are linear independent. The third equation
    1149  * is that the vector should be of magnitude 1 (orthonormal). This all leads to a case-based solution
    1150  * where very often it has to be checked whether a certain value is zero or not and thus forked into
    1151  * another case.
    1152  * \param *x1 first vector
    1153  * \param *x2 second vector
    1154  * \param *y third vector
    1155  * \param alpha first angle
    1156  * \param beta second angle
    1157  * \param c norm of final vector
    1158  * \return a vector with \f$\langle x1,x2 \rangle=A\f$, \f$\langle x1,y \rangle = B\f$ and with norm \a c.
    1159  * \bug this is not yet working properly
    1160  */
    1161 bool Vector::SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c)
    1162 {
    1163   double D1,D2,D3,E1,E2,F1,F2,F3,p,q=0., A, B1, B2, C;
    1164   double ang; // angle on testing
    1165   double sign[3];
    1166   int i,j,k;
    1167   A = cos(alpha) * x1->Norm() * c;
    1168   B1 = cos(beta + M_PI/2.) * y->Norm() * c;
    1169   B2 = cos(beta) * x2->Norm() * c;
    1170   C = c * c;
    1171   DoLog(2) && (Log() << Verbose(2) << "A " << A << "\tB " << B1 << "\tC " << C << endl);
    1172   int flag = 0;
    1173   if (fabs(x1->x[0]) < MYEPSILON) { // check for zero components for the later flipping and back-flipping
    1174     if (fabs(x1->x[1]) > MYEPSILON) {
    1175       flag = 1;
    1176     } else if (fabs(x1->x[2]) > MYEPSILON) {
    1177        flag = 2;
    1178     } else {
    1179       return false;
    1180     }
    1181   }
    1182   switch (flag) {
    1183     default:
    1184     case 0:
    1185       break;
    1186     case 2:
    1187       flip(x1->x[0],x1->x[1]);
    1188       flip(x2->x[0],x2->x[1]);
    1189       flip(y->x[0],y->x[1]);
    1190       //flip(x[0],x[1]);
    1191       flip(x1->x[1],x1->x[2]);
    1192       flip(x2->x[1],x2->x[2]);
    1193       flip(y->x[1],y->x[2]);
    1194       //flip(x[1],x[2]);
    1195     case 1:
    1196       flip(x1->x[0],x1->x[1]);
    1197       flip(x2->x[0],x2->x[1]);
    1198       flip(y->x[0],y->x[1]);
    1199       //flip(x[0],x[1]);
    1200       flip(x1->x[1],x1->x[2]);
    1201       flip(x2->x[1],x2->x[2]);
    1202       flip(y->x[1],y->x[2]);
    1203       //flip(x[1],x[2]);
    1204       break;
    1205   }
    1206   // now comes the case system
    1207   D1 = -y->x[0]/x1->x[0]*x1->x[1]+y->x[1];
    1208   D2 = -y->x[0]/x1->x[0]*x1->x[2]+y->x[2];
    1209   D3 = y->x[0]/x1->x[0]*A-B1;
    1210   DoLog(2) && (Log() << Verbose(2) << "D1 " << D1 << "\tD2 " << D2 << "\tD3 " << D3 << "\n");
    1211   if (fabs(D1) < MYEPSILON) {
    1212     DoLog(2) && (Log() << Verbose(2) << "D1 == 0!\n");
    1213     if (fabs(D2) > MYEPSILON) {
    1214       DoLog(3) && (Log() << Verbose(3) << "D2 != 0!\n");
    1215       x[2] = -D3/D2;
    1216       E1 = A/x1->x[0] + x1->x[2]/x1->x[0]*D3/D2;
    1217       E2 = -x1->x[1]/x1->x[0];
    1218       DoLog(3) && (Log() << Verbose(3) << "E1 " << E1 << "\tE2 " << E2 << "\n");
    1219       F1 = E1*E1 + 1.;
    1220       F2 = -E1*E2;
    1221       F3 = E1*E1 + D3*D3/(D2*D2) - C;
    1222       DoLog(3) && (Log() << Verbose(3) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n");
    1223       if (fabs(F1) < MYEPSILON) {
    1224         DoLog(4) && (Log() << Verbose(4) << "F1 == 0!\n");
    1225         DoLog(4) && (Log() << Verbose(4) << "Gleichungssystem linear\n");
    1226         x[1] = F3/(2.*F2);
    1227       } else {
    1228         p = F2/F1;
    1229         q = p*p - F3/F1;
    1230         DoLog(4) && (Log() << Verbose(4) << "p " << p << "\tq " << q << endl);
    1231         if (q < 0) {
    1232           DoLog(4) && (Log() << Verbose(4) << "q < 0" << endl);
    1233           return false;
    1234         }
    1235         x[1] = p + sqrt(q);
    1236       }
    1237       x[0] =  A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2];
    1238     } else {
    1239       DoLog(2) && (Log() << Verbose(2) << "Gleichungssystem unterbestimmt\n");
    1240       return false;
    1241     }
    1242   } else {
    1243     E1 = A/x1->x[0]+x1->x[1]/x1->x[0]*D3/D1;
    1244     E2 = x1->x[1]/x1->x[0]*D2/D1 - x1->x[2];
    1245     DoLog(2) && (Log() << Verbose(2) << "E1 " << E1 << "\tE2 " << E2 << "\n");
    1246     F1 = E2*E2 + D2*D2/(D1*D1) + 1.;
    1247     F2 = -(E1*E2 + D2*D3/(D1*D1));
    1248     F3 = E1*E1 + D3*D3/(D1*D1) - C;
    1249     DoLog(2) && (Log() << Verbose(2) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n");
    1250     if (fabs(F1) < MYEPSILON) {
    1251       DoLog(3) && (Log() << Verbose(3) << "F1 == 0!\n");
    1252       DoLog(3) && (Log() << Verbose(3) << "Gleichungssystem linear\n");
    1253       x[2] = F3/(2.*F2);
    1254     } else {
    1255       p = F2/F1;
    1256       q = p*p - F3/F1;
    1257       DoLog(3) && (Log() << Verbose(3) << "p " << p << "\tq " << q << endl);
    1258       if (q < 0) {
    1259         DoLog(3) && (Log() << Verbose(3) << "q < 0" << endl);
    1260         return false;
    1261       }
    1262       x[2] = p + sqrt(q);
    1263     }
    1264     x[1] = (-D2 * x[2] - D3)/D1;
    1265     x[0] = A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2];
    1266   }
    1267   switch (flag) { // back-flipping
    1268     default:
    1269     case 0:
    1270       break;
    1271     case 2:
    1272       flip(x1->x[0],x1->x[1]);
    1273       flip(x2->x[0],x2->x[1]);
    1274       flip(y->x[0],y->x[1]);
    1275       flip(x[0],x[1]);
    1276       flip(x1->x[1],x1->x[2]);
    1277       flip(x2->x[1],x2->x[2]);
    1278       flip(y->x[1],y->x[2]);
    1279       flip(x[1],x[2]);
    1280     case 1:
    1281       flip(x1->x[0],x1->x[1]);
    1282       flip(x2->x[0],x2->x[1]);
    1283       flip(y->x[0],y->x[1]);
    1284       //flip(x[0],x[1]);
    1285       flip(x1->x[1],x1->x[2]);
    1286       flip(x2->x[1],x2->x[2]);
    1287       flip(y->x[1],y->x[2]);
    1288       flip(x[1],x[2]);
    1289       break;
    1290   }
    1291   // one z component is only determined by its radius (without sign)
    1292   // thus check eight possible sign flips and determine by checking angle with second vector
    1293   for (i=0;i<8;i++) {
    1294     // set sign vector accordingly
    1295     for (j=2;j>=0;j--) {
    1296       k = (i & pot(2,j)) << j;
    1297       DoLog(2) && (Log() << Verbose(2) << "k " << k << "\tpot(2,j) " << pot(2,j) << endl);
    1298       sign[j] = (k == 0) ? 1. : -1.;
    1299     }
    1300     DoLog(2) && (Log() << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n");
    1301     // apply sign matrix
    1302     for (j=NDIM;j--;)
    1303       x[j] *= sign[j];
    1304     // calculate angle and check
    1305     ang = x2->Angle (this);
    1306     DoLog(1) && (Log() << Verbose(1) << i << "th angle " << ang << "\tbeta " << cos(beta) << " :\t");
    1307     if (fabs(ang - cos(beta)) < MYEPSILON) {
    1308       break;
    1309     }
    1310     // unapply sign matrix (is its own inverse)
    1311     for (j=NDIM;j--;)
    1312       x[j] *= sign[j];
    1313   }
    1314   return true;
    1315 };
     688void Vector::SubtractVector(const Vector &y)
     689{
     690  for(int i=NDIM;i--;)
     691    x[i] -= y[i];
     692}
    1316693
    1317694/**
     
    1324701bool Vector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const
    1325702{
    1326   Vector a;
    1327   a.CopyVector(this);
    1328   a.SubtractVector(&offset);
     703  Vector a = (*this)-offset;
    1329704  a.InverseMatrixMultiplication(parallelepiped);
    1330705  bool isInside = true;
    1331706
    1332707  for (int i=NDIM;i--;)
    1333     isInside = isInside && ((a.x[i] <= 1) && (a.x[i] >= 0));
     708    isInside = isInside && ((a[i] <= 1) && (a[i] >= 0));
    1334709
    1335710  return isInside;
  • src/vector.hpp

    r632bc3 r8cbb97  
    1515#include <gsl/gsl_multimin.h>
    1616
     17#include <memory>
     18
    1719#include "defs.hpp"
    1820
     
    2325 */
    2426class Vector {
    25   public:
    26     double x[NDIM];
     27protected:
     28  // this struct is used to indicate calls to the Baseconstructor from inside vectors.
     29  struct Baseconstructor{};
     30public:
    2731
    2832  Vector();
    29   Vector(const Vector * const a);
    30   Vector(const Vector &a);
    3133  Vector(const double x1, const double x2, const double x3);
    32   ~Vector();
     34  Vector(const Vector& src);
     35  virtual ~Vector();
    3336
    34   double Distance(const Vector * const y) const;
    35   double DistanceSquared(const Vector * const y) const;
    36   double DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const;
    37   double PeriodicDistance(const Vector * const y, const double * const cell_size) const;
    38   double PeriodicDistanceSquared(const Vector * const y, const double * const cell_size) const;
    39   double ScalarProduct(const Vector * const y) const;
     37  // Method implemented by forwarding to the Representation
     38
     39  double DistanceSquared(const Vector &y) const;
     40  Vector GetDistanceVectorToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const;
     41  double DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const;
     42  double PeriodicDistance(const Vector &y, const double * const cell_size) const;
     43  double PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const;
     44  double ScalarProduct(const Vector &y) const;
     45  double Angle(const Vector &y) const;
     46  bool IsZero() const;
     47  bool IsOne() const;
     48  bool IsNormalTo(const Vector &normal) const;
     49  bool IsEqualTo(const Vector &a) const;
     50
     51  void AddVector(const Vector &y);
     52  void SubtractVector(const Vector &y);
     53  void VectorProduct(const Vector &y);
     54  void ProjectOntoPlane(const Vector &y);
     55  void ProjectIt(const Vector &y);
     56  Vector Projection(const Vector &y) const;
     57  void Mirror(const Vector &x);
     58  void ScaleAll(const double *factor);
     59  void Scale(const double factor);
     60  void MatrixMultiplication(const double * const M);
     61  bool InverseMatrixMultiplication(const double * const M);
     62  void KeepPeriodic(const double * const matrix);
     63  bool GetOneNormalVector(const Vector &x1);
     64  bool MakeNormalTo(const Vector &y1);
     65  bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const;
     66  void WrapPeriodically(const double * const M, const double * const Minv);
     67
     68  // Accessors ussually come in pairs... and sometimes even more than that
     69  double& operator[](size_t i);
     70  const double& operator[](size_t i) const;
     71  double& at(size_t i);
     72  const double& at(size_t i) const;
     73
     74  // Assignment operator
     75  Vector &operator=(const Vector& src);
     76
     77  // Access to internal structure
     78  double* get();
     79
     80  // Methods that are derived directly from other methods
     81  double Distance(const Vector &y) const;
    4082  double Norm() const;
    4183  double NormSquared() const;
    42   double Angle(const Vector * const y) const;
    43   bool IsZero() const;
    44   bool IsOne() const;
    45   bool IsNormalTo(const Vector * const normal) const;
    46   bool IsEqualTo(const Vector * const a) const;
    47 
    48   void AddVector(const Vector * const y);
    49   void SubtractVector(const Vector * const y);
    50   void CopyVector(const Vector * const y);
    51   void CopyVector(const Vector &y);
    52   void RotateVector(const Vector * const y, const double alpha);
    53   void VectorProduct(const Vector * const y);
    54   void ProjectOntoPlane(const Vector * const y);
    55   void ProjectIt(const Vector * const y);
    56   Vector Projection(const Vector * const y) const;
     84  void Normalize();
    5785  void Zero();
    5886  void One(const double one);
    59   void Init(const double x1, const double x2, const double x3);
    60   void Normalize();
    61   void Translate(const Vector * const x);
    62   void Mirror(const Vector * const x);
    63   void Scale(const double ** const factor);
    64   void Scale(const double * const factor);
    65   void Scale(const double factor);
    66   void MatrixMultiplication(const double * const M);
    67   void InverseMatrixMultiplication(const double * const M);
    68   void KeepPeriodic(const double * const matrix);
    69   void LinearCombinationOfVectors(const Vector * const x1, const Vector * const x2, const Vector * const x3, const double * const factors);
    70   double CutsPlaneAt(const Vector * const A, const Vector * const B, const Vector * const C) const;
    71   Vector GetDistanceVectorToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const;
    72   bool GetIntersectionWithPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset, const Vector * const Origin, const Vector * const LineVector);
    73   bool GetIntersectionOfTwoLinesOnPlane(const Vector * const Line1a, const Vector * const Line1b, const Vector * const Line2a, const Vector * const Line2b, const Vector *Normal = NULL);
    74   bool GetOneNormalVector(const Vector * const x1);
    75   bool MakeNormalVector(const Vector * const y1);
    76   bool MakeNormalVector(const Vector * const y1, const Vector * const y2);
    77   bool MakeNormalVector(const Vector * const x1, const Vector * const x2, const Vector * const x3);
    78   bool SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c);
    79   bool LSQdistance(const Vector ** vectors, int dim);
    80   void AskPosition(const double * const cell_size, const bool check);
    81   void Output() const;
    82   bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const;
    83   void WrapPeriodically(const double * const M, const double * const Minv);
     87  void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors);
     88
     89  // operators for mathematical operations
     90  bool operator==(const Vector& b) const;
     91  const Vector& operator+=(const Vector& b);
     92  const Vector& operator-=(const Vector& b);
     93  Vector const operator+(const Vector& b) const;
     94  Vector const operator-(const Vector& b) const;
     95
     96protected:
     97
     98private:
     99  double x[NDIM];
    84100
    85101};
    86102
    87103ostream & operator << (ostream& ost, const Vector &m);
    88 bool operator==(const Vector& a, const Vector& b);
    89 const Vector& operator+=(Vector& a, const Vector& b);
    90 const Vector& operator-=(Vector& a, const Vector& b);
    91104const Vector& operator*=(Vector& a, const double m);
    92105Vector const operator*(const Vector& a, const double m);
    93106Vector const operator*(const double m, const Vector& a);
    94 Vector const operator+(const Vector& a, const Vector& b);
    95 Vector const operator-(const Vector& a, const Vector& b);
    96 
    97107
    98108#endif /*VECTOR_HPP_*/
Note: See TracChangeset for help on using the changeset viewer.