Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1767 structure of arrays #1770

Draft
wants to merge 17 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/energy/energy_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ template <ProblemType problem, Population population> static void BM_CalculateEn
{
Problem<problem, population> problemDef;
auto energyKernel = createEnergyKernel(problemDef);
auto &i = problemDef.cfg_->atom(0);
auto i = problemDef.cfg_->atom(0);
for (auto _ : state)
energyKernel->totalEnergy(i);
}
Expand Down
2 changes: 2 additions & 0 deletions src/classes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_library(
atomType.cpp
atomTypeData.cpp
atomTypeMix.cpp
atomVector.cpp
box.cpp
boxCubic.cpp
boxMonoclinicAlpha.cpp
Expand Down Expand Up @@ -73,6 +74,7 @@ add_library(
atomTypeData.h
atomType.h
atomTypeMix.h
atomVector.h
box.h
braggReflection.h
cell.h
Expand Down
152 changes: 74 additions & 78 deletions src/classes/atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,109 +2,105 @@
// Copyright (c) 2024 Team Dissolve and contributors

#include "classes/atom.h"
#include "classes/atomType.h"
#include "classes/molecule.h"
#include "classes/speciesAtom.h"
#include <utility>
#include "classes/atomVector.h"

// Set coordinates
void Atom::set(const Vec3<double> r) { r_ = r; }

// Set coordinates
void Atom::set(double rx, double ry, double rz) { r_.set(rx, ry, rz); }

// Return coordinates
const Vec3<double> &Atom::r() const { return r_; }

// Return x-coordinate
double Atom::x() const { return r_.x; }

// Return y-coordinate
double Atom::y() const { return r_.y; }

// Return z-coordinate
double Atom::z() const { return r_.z; }
/*
* Atom Ref Implementation
*/

// Set local AtomType index
void Atom::setLocalTypeIndex(int id) { localTypeIndex_ = id; }
Atom::Atom() : index_(0), origin_(nullptr) {}
Atom::Atom(const Atom &ref) : index_(ref.index_), origin_(ref.origin_) {}
Atom::Atom(const std::size_t index, const AtomVector &source) : index_(index), origin_(const_cast<AtomVector *>(&source))
{
}

// Return local AtomType index
int Atom::localTypeIndex() const { return localTypeIndex_; }
Atom Atom::operator[](std::size_t offset) { return Atom(index_ + offset, *origin_); }

// Set master AtomType index
void Atom::setMasterTypeIndex(int id) { masterTypeIndex_ = id; }
bool Atom::operator==(const Atom &other) const { return index_ == other.index_; }
bool Atom::operator!=(const Atom &other) const { return index_ != other.index_ || origin_ != other.origin_; }

// Return master AtomType index
int Atom::masterTypeIndex() const { return masterTypeIndex_; }

// Return global index of the atom
int Atom::globalIndex() const
Atom &Atom::operator++()
{
assert(molecule_);
return molecule_->globalAtomIndex(this);
++index_;
return *this;
}

/*
* Location
*/
Atom Atom::operator++(int)
{
auto original = index_++;
return Atom(original, *origin_);
}

// Set SpeciesAtom that this Atom represents
void Atom::setSpeciesAtom(const SpeciesAtom *spAtom) { speciesAtom_ = spAtom; }
std::size_t Atom::operator-(const Atom &other) const { return index_ - other.index_; }

// Return SpeciesAtom that this Atom represents
const SpeciesAtom *Atom::speciesAtom() const { return speciesAtom_; }
int Atom::globalAtomIndex() const { return index_; }

// Set SpeciesAtom that this Atom represents
void Atom::setSpeciesAtom(const SpeciesAtom *spAtom) { origin_->speciesAtom_[index_] = spAtom; }
// Set Molecule in which this Atom exists
void Atom::setMolecule(std::shared_ptr<Molecule> mol) { molecule_ = std::move(mol); }
void Atom::setMolecule(std::shared_ptr<Molecule> mol) { origin_->molecule_[index_] = mol; }
// Set local AtomType index
void Atom::setLocalTypeIndex(int id) { origin_->localTypeIndex_[index_] = id; }
// Return local AtomType index
int Atom::localTypeIndex() const { return origin_->localTypeIndex_[index_]; }
// Return master AtomType index
int Atom::masterTypeIndex() const { return origin_->masterTypeIndex_[index_]; }
// Set master AtomType index
void Atom::setMasterTypeIndex(int id) { origin_->masterTypeIndex_[index_] = id; }
// Add targeted potential to this atom
void Atom::addTargetedPotential(const ExternalPotential *potential)
{
origin_->targetedPotentials_[index_].emplace_back(potential);
}
// Clear all targeted potentials from this Atom
void Atom::clearTargetedPotentials() { origin_->targetedPotentials_[index_].clear(); }
// Return list of targeted potentials for this atom
const std::vector<const ExternalPotential *> &Atom::targetedPotentials() const
{
return origin_->targetedPotentials_[index_];
}
// Return coordinates
const Vec3<double> &Atom::r() const { return origin_->rs_[index_]; }

// Return Molecule in which this Atom exists
const std::shared_ptr<Molecule> &Atom::molecule() const { return molecule_; }
// Set coordinates
void Atom::setCoordinates(const Vec3<double> &newr) { origin_->rs_[index_] = newr; }

// Set cell in which the atom exists
void Atom::setCell(Cell *cell) { cell_ = cell; }
void Atom::setCell(Cell *cell) { origin_->cell_[index_] = cell; }

// Return cell in which the atom exists
Cell *Atom::cell() const { return cell_; }
Cell *Atom::cell() const { return origin_->cell_[index_]; }

/*
* Coordinate Manipulation
*/
Atom &Atom::operator*() { return *this; }
const Atom &Atom::operator*() const { return *this; }

// Set coordinates
void Atom::setCoordinates(const Vec3<double> &newr) { r_ = newr; }
// Return SpeciesAtom that this Atom represents
const SpeciesAtom *Atom::speciesAtom() const { return origin_->speciesAtom_[index_]; }

// Set coordinates
void Atom::setCoordinates(double dx, double dy, double dz) { setCoordinates(Vec3<double>(dx, dy, dz)); }

void Atom::setCoordinates(double dx, double dy, double dz) { origin_->rs_[index_] = Vec3<double>(dx, dy, dz); }
// Translate coordinates
void Atom::translateCoordinates(const Vec3<double> &delta) { setCoordinates(r_ + delta); }

void Atom::translateCoordinates(const Vec3<double> &delta) { origin_->rs_[index_] += delta; }
// Translate coordinates
void Atom::translateCoordinates(double dx, double dy, double dz) { setCoordinates(r_ + Vec3<double>(dx, dy, dz)); }

/*
* Intramolecular Information
*/

void Atom::translateCoordinates(double dx, double dy, double dz) { origin_->rs_[index_] += Vec3<double>(dx, dy, dz); }
// Return scaling type and factors (electrostatic, van der Waals) to employ with specified Atom
SpeciesAtom::ScaledInteractionDefinition Atom::scaling(const Atom *j) const
{
assert(speciesAtom_ != nullptr);
assert(j != nullptr);
assert(j->speciesAtom() != nullptr);
SpeciesAtom::ScaledInteractionDefinition Atom::scaling(const Atom j) const {
assert(origin_->speciesAtom_[index_] != nullptr);
assert(j.speciesAtom() != nullptr);

return speciesAtom_->scaling(j->speciesAtom());
return origin_->speciesAtom_[index_]->scaling(j.speciesAtom());
}
// Set coordinates
void Atom::set(const Vec3<double> r) { origin_->rs_[index_] = r; }
// Set coordinates
void Atom::set(double rx, double ry, double rz) { origin_->rs_[index_].set(rx, ry, rz); }
// Return x-coordinate
double Atom::x() const { return origin_->rs_[index_].x; }
// Return y-coordinate
double Atom::y() const { return origin_->rs_[index_].y; }
// Return z-coordinate
double Atom::z() const { return origin_->rs_[index_].z; }

/*
* Targeted Potentials
*/

// Add targeted potential to this atom
void Atom::addTargetedPotential(const ExternalPotential *potential) { targetedPotentials_.emplace_back(potential); }

// Clear all targeted potentials from this Atom
void Atom::clearTargetedPotentials() { targetedPotentials_.clear(); }

// Return list of targeted potentials for this atom
const std::vector<const ExternalPotential *> &Atom::targetedPotentials() const { return targetedPotentials_; }
// Return Molecule in which this Atom exists
const std::shared_ptr<Molecule> &Atom::molecule() const { return origin_->molecule_[index_]; }
124 changes: 50 additions & 74 deletions src/classes/atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,43 @@
#pragma once

#include "classes/speciesAtom.h"
#include "kernels/potentials/base.h"
#include "templates/vector3.h"
#include <iterator>
#include <memory>
#include <vector>

// Forward Declarations
class Cell;
class ExternalPotential;
class Molecule;
class AtomVector;

// Atom Definition
class Atom
class Atom : public std::iterator<std::random_access_iterator_tag, Atom>
{
/*
* Properties
*/
private:
// Coordinates
Vec3<double> r_;
// Assigned AtomType index, local to Configuration (for partial indexing etc.)
int localTypeIndex_{-1};
// Assigned master AtomType index (for pair potential indexing)
int masterTypeIndex_{-1};
std::size_t index_{0};
AtomVector *origin_{nullptr};

public:
// Set coordinates
void set(const Vec3<double> r);
// Set coordinates
void set(double rx, double ry, double rz);
// Return coordinates
const Vec3<double> &r() const;
// Return x-coordinate
double x() const;
// Return y-coordinate
double y() const;
// Return z-coordinate
double z() const;
Atom();
Atom(const Atom &ref);
Atom(const std::size_t index, const AtomVector &source);
Atom &operator*();
const Atom &operator*() const;
bool operator==(const Atom &other) const;
bool operator!=(const Atom &other) const;
Atom operator[](std::size_t);
Atom &operator++();
Atom operator++(int);
std::size_t operator-(const Atom &other) const;
int globalAtomIndex() const;

// Return SpeciesAtom that this Atom represents
const SpeciesAtom *speciesAtom() const;
// Set SpeciesAtom that this Atom represents
void setSpeciesAtom(const SpeciesAtom *spAtom);
// Return Molecule in which this Atom exists
const std::shared_ptr<Molecule> &molecule() const;
// Set Molecule in which this Atom exists
void setMolecule(std::shared_ptr<Molecule> mol);
// Set local AtomType index
void setLocalTypeIndex(int id);
// Return local AtomType index
Expand All @@ -48,33 +49,14 @@ class Atom
void setMasterTypeIndex(int id);
// Return master AtomType index
int masterTypeIndex() const;
// Return global index of the atom
int globalIndex() const;

/*
* Location
*/
private:
// SpeciesAtom that this Atom represents
const SpeciesAtom *speciesAtom_{nullptr};
// Molecule in which this Atom exists
std::shared_ptr<Molecule> molecule_{nullptr};
// Cell in which the atom exists
Cell *cell_{nullptr};

public:
// Set SpeciesAtom that this Atom represents
void setSpeciesAtom(const SpeciesAtom *spAtom);
// Return SpeciesAtom that this Atom represents
const SpeciesAtom *speciesAtom() const;
// Set Molecule in which this Atom exists
void setMolecule(std::shared_ptr<Molecule> mol);
// Return Molecule in which this Atom exists
const std::shared_ptr<Molecule> &molecule() const;
// Set cell in which the atom exists
void setCell(Cell *cell);
// Return cell in which the atom exists
Cell *cell() const;
// Add targeted potential to this atom
void addTargetedPotential(const ExternalPotential *potential);
// Clear all targeted potentials from this Atom
void clearTargetedPotentials();
// Return list of targeted potentials for this atom
const std::vector<const ExternalPotential *> &targetedPotentials() const;
// Return coordinates
const Vec3<double> &r() const;

/*
* Coordinate Manipulation
Expand All @@ -88,26 +70,20 @@ class Atom
void translateCoordinates(const Vec3<double> &delta);
// Translate coordinates
void translateCoordinates(double dx, double dy, double dz);

/*
* Intramolecular Information
*/
public:
// Set cell in which the atom exists
void setCell(Cell *cell);
// Return cell in which the atom exists
Cell *cell() const;
// Return scaling type and factors (electrostatic, van der Waals) to employ with specified Atom
SpeciesAtom::ScaledInteractionDefinition scaling(const Atom *j) const;

/*
* Targeted External Potentials
*/
private:
// Vector of targeted potentials affecting this atom
std::vector<const ExternalPotential *> targetedPotentials_;

public:
// Add targeted potential to this atom
void addTargetedPotential(const ExternalPotential *potential);
// Clear all targeted potentials from this Atom
void clearTargetedPotentials();
// Return list of targeted potentials for this atom
const std::vector<const ExternalPotential *> &targetedPotentials() const;
SpeciesAtom::ScaledInteractionDefinition scaling(const Atom j) const;
// Set coordinates
void set(const Vec3<double> r);
// Set coordinates
void set(double rx, double ry, double rz);
// Return x-coordinate
double x() const;
// Return y-coordinate
double y() const;
// Return z-coordinate
double z() const;
};