Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/atom.cpp

    rd74077 rdddbfe  
    1313#include "lists.hpp"
    1414#include "parser.hpp"
    15 #include "vector.hpp"
     15#include "LinearAlgebra/Vector.hpp"
    1616#include "World.hpp"
    1717#include "molecule.hpp"
     
    1919
    2020#include <iomanip>
     21#include <iostream>
    2122
    2223/************************************* Functions for class atom *************************************/
     
    2728atom::atom() :
    2829  father(this), sort(&nr), mol(0)
    29 {};
     30{
     31  node = &x;  // TesselPoint::x can only be referenced from here
     32};
    3033
    3134/** Constructor of class atom.
     
    3437    ParticleInfo(pointer),father(pointer), sort(&nr)
    3538{
    36   setType(pointer->getType());  // copy element of atom
    37   setPosition(pointer->getPosition()); // copy coordination
    38   AtomicVelocity = pointer->AtomicVelocity; // copy velocity
     39  type = pointer->type;  // copy element of atom
     40  x = pointer->x; // copy coordination
     41  v = pointer->v; // copy velocity
    3942  FixedIon = pointer->FixedIon;
     43  node = &x;
    4044  mol = 0;
    4145};
     
    4549  res->father = this;
    4650  res->sort = &res->nr;
    47   res->setType(getType());
    48   res->setPosition(this->getPosition());
    49   res->AtomicVelocity = this->AtomicVelocity;
     51  res->type = type;
     52  res->x = this->x;
     53  res->v = this->v;
    5054  res->FixedIon = FixedIon;
     55  res->node = &x;
    5156  res->mol = 0;
    5257  World::getInstance().registerAtom(res);
     
    105110};
    106111
     112bool atom::isFather(const atom *ptr){
     113  return ptr==father;
     114}
     115
    107116/** Checks whether atom is within the given box.
    108117 * \param offset offset to box origin
     
    112121bool atom::IsInShape(const Shape& shape) const
    113122{
    114   return shape.isInside(getPosition());
     123  return shape.isInside(*node);
    115124};
    116125
     
    137146  if (out != NULL) {
    138147    *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t"  << fixed << setprecision(9) << showpoint;
    139     *out << at(0) << "\t" << at(1) << "\t" << at(2);
     148    *out << x[0] << "\t" << x[1] << "\t" << x[2];
    140149    *out << "\t" << FixedIon;
    141     if (AtomicVelocity.Norm() > MYEPSILON)
    142       *out << "\t" << scientific << setprecision(6) << AtomicVelocity[0] << "\t" << AtomicVelocity[1] << "\t" << AtomicVelocity[2] << "\t";
     150    if (v.Norm() > MYEPSILON)
     151      *out << "\t" << scientific << setprecision(6) << v[0] << "\t" << v[1] << "\t" << v[2] << "\t";
    143152    if (comment != NULL)
    144153      *out << " # " << comment << endl;
     
    157166  * \return true - \a *out present, false - \a *out is NULL
    158167 */
    159 bool atom::OutputArrayIndexed(ostream * const out, const int *ElementNo, int *AtomNo, const char *comment) const
    160 {
    161   AtomNo[getType()->Z]++;  // increment number
    162   if (out != NULL) {
    163     *out << "Ion_Type" << ElementNo[getType()->Z] << "_" << AtomNo[getType()->Z] << "\t"  << fixed << setprecision(9) << showpoint;
    164     *out << at(0) << "\t" << at(1) << "\t" << at(2);
     168bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
     169{
     170  AtomNo[type->Z]++;  // increment number
     171  if (out != NULL) {
     172    cout << "Looking for atom with element " << *type << endl;
     173    ASSERT(elementLookup.there.find(type)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
     174    *out << "Ion_Type" << elementLookup.there.find(type)->second << "_" << AtomNo[type->Z] << "\t"  << fixed << setprecision(9) << showpoint;
     175    *out << x[0] << "\t" << x[1] << "\t" << x[2];
    165176    *out << "\t" << FixedIon;
    166     if (AtomicVelocity.Norm() > MYEPSILON)
    167       *out << "\t" << scientific << setprecision(6) << AtomicVelocity[0] << "\t" << AtomicVelocity[1] << "\t" << AtomicVelocity[2] << "\t";
     177    if (v.Norm() > MYEPSILON)
     178      *out << "\t" << scientific << setprecision(6) << v[0] << "\t" << v[1] << "\t" << v[2] << "\t";
    168179    if (comment != NULL)
    169180      *out << " # " << comment << endl;
     
    182193{
    183194  if (out != NULL) {
    184     *out << getType()->symbol << "\t" << at(0) << "\t" << at(1) << "\t" << at(2) << "\t" << endl;
     195    *out << type->symbol << "\t" << x[0] << "\t" << x[1] << "\t" << x[2] << "\t" << endl;
    185196    return true;
    186197  } else
     
    197208bool atom::OutputTrajectory(ofstream * const out, const int *ElementNo, int *AtomNo, const int step) const
    198209{
    199   AtomNo[getType()->Z]++;
    200   if (out != NULL) {
    201     *out << "Ion_Type" << ElementNo[getType()->Z] << "_" << AtomNo[getType()->Z] << "\t"  << fixed << setprecision(9) << showpoint;
     210  AtomNo[type->Z]++;
     211  if (out != NULL) {
     212    *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t"  << fixed << setprecision(9) << showpoint;
    202213    *out << Trajectory.R.at(step)[0] << "\t" << Trajectory.R.at(step)[1] << "\t" << Trajectory.R.at(step)[2];
    203214    *out << "\t" << FixedIon;
     
    220231{
    221232  if (out != NULL) {
    222     *out << getType()->symbol << "\t";
     233    *out << type->symbol << "\t";
    223234    *out << Trajectory.R.at(step)[0] << "\t";
    224235    *out << Trajectory.R.at(step)[1] << "\t";
     
    236247void atom::OutputMPQCLine(ostream * const out, const Vector *center, int *AtomNo = NULL) const
    237248{
    238   Vector recentered(getPosition());
    239   recentered -= *center;
    240   *out << "\t\t" << getType()->symbol << " [ " << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " ]" << endl;
     249  *out << "\t\t" << type->symbol << " [ " << x[0]-center->at(0) << "\t" << x[1]-center->at(1) << "\t" << x[2]-center->at(2) << " ]" << endl;
    241250  if (AtomNo != NULL)
    242251    *AtomNo++;
     
    261270double atom::DistanceSquaredToVector(const Vector &origin) const
    262271{
    263   return DistanceSquared(origin);
     272  return origin.DistanceSquared(x);
    264273};
    265274
     
    270279double atom::DistanceToVector(const Vector &origin) const
    271280{
    272   return distance(origin);
     281  return origin.distance(x);
    273282};
    274283
     
    285294};
    286295
    287 std::ostream & atom::operator << (std::ostream &ost) const
    288 {
    289   ParticleInfo::operator<<(ost);
    290   ost << "," << getPosition();
    291   return ost;
    292 }
    293 
    294 std::ostream & operator << (std::ostream &ost, const atom &a)
    295 {
    296   a.ParticleInfo::operator<<(ost);
    297   ost << "," << a.getPosition();
    298   return ost;
    299 }
    300296
    301297bool operator < (atom &a, atom &b)
     
    337333  mol = _mol;
    338334  if(!mol->containsAtom(this)){
    339     mol->AddAtom(this);
     335    mol->insert(this);
    340336  }
    341337}
Note: See TracChangeset for help on using the changeset viewer.