Skip to content

Commit

Permalink
Change Molecule constructor to require passing all parameters
Browse files Browse the repository at this point in the history
Remove the default parameters for the Molecule constructor to prevent
unintentional incorrect initialization of molecules. Fix all related
places in the code with the appropriate initialization values.

Signed-off-by: Christoph Niethammer <[email protected]>
  • Loading branch information
cniethammer committed Apr 16, 2024
1 parent 561259f commit be75df9
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 25 deletions.
3 changes: 1 addition & 2 deletions src/io/ASCIIReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,7 @@ ASCIIReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domain
Log::global_log->debug() << "broadcasting(sending/receiving) particles with buffer_position " << particle_buff_pos << std::endl;
MPI_Bcast(particle_buff, PARTICLE_BUFFER_SIZE, mpi_Particle, 0, MPI_COMM_WORLD); // TODO: MPI_COMM_WORLD
for (int j = 0; j < particle_buff_pos; j++) {
Molecule m;
ParticleData::ParticleDataToMolecule(particle_buff[j], m);
Molecule m = ParticleData::ParticleDataToMolecule(particle_buff[j]);
// only add particle if it is inside of the own domain!
if(particleContainer->isInBoundingBox(m.r_arr().data())) {
particleContainer->addParticle(m, true, false);
Expand Down
3 changes: 1 addition & 2 deletions src/io/BinaryReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ BinaryReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domai
MPI_Bcast(particle_buff, PARTICLE_BUFFER_SIZE, mpi_Particle, 0,
MPI_COMM_WORLD); // TODO: MPI_COMM_WORLD
for (int j = 0; j < particle_buff_pos; j++) {
Molecule m;
ParticleData::ParticleDataToMolecule(particle_buff[j], m);
Molecule m = ParticleData::ParticleDataToMolecule(particle_buff[j]);
// only add particle if it is inside of the own domain!
if(particleContainer->isInBoundingBox(m.r_arr().data())) {
particleContainer->addParticle(m, true, false);
Expand Down
3 changes: 1 addition & 2 deletions src/io/MPI_IOReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,9 @@ MPI_IOReader::readPhaseSpace(ParticleContainer* particleContainer, Domain* domai

if (globalNumParticlesPerCell[index] > 0) {

Molecule m;
for (int l = 0; l < globalNumParticlesPerCell[index]; l++) {

ParticleData::ParticleDataToMolecule(data[l], m);
Molecule m = ParticleData::ParticleDataToMolecule(data[l]);

// only add particle if it is inside of the own domain!
if(particleContainer->isInBoundingBox(m.r_arr().data())) {
Expand Down
2 changes: 1 addition & 1 deletion src/io/ObjectGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ ObjectGenerator::readPhaseSpace(ParticleContainer* particleContainer, Domain* do
_filler->setObject(boundedObject);
_filler->init();

Molecule molecule;
Molecule molecule(0, nullptr, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
unsigned long moleculeID = _moleculeIdPool->getNewMoleculeId();
while(_filler->getMolecule(&molecule) > 0) {
molecule.setid(moleculeID);
Expand Down
4 changes: 2 additions & 2 deletions src/io/PerCellGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void PerCellGenerator::fillContainer(ParticleContainer *particleContainer, Compo
std::array pos = {uniform_dists[0](randomEngine), uniform_dists[1](randomEngine),
uniform_dists[2](randomEngine)};

Molecule m(id, component, pos[0], pos[1], pos[2], 0., 0., 0.);
Molecule m(id, component, pos[0], pos[1], pos[2], 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.);
if (isHalo) {
particleContainer->addHaloParticle(m, true);
} else {
Expand Down Expand Up @@ -160,7 +160,7 @@ void PerCellGenerator::generateTwoParticles(ParticleContainer *particleContainer
for (auto id = 0; id < 2; ++id) {
std::array pos = {uniform_dists[0](randomEngine), uniform_dists[1](randomEngine),
uniform_dists[2](randomEngine)};
Molecule m(id, component, pos[0], pos[1], pos[2], 0., 0., 0.);
Molecule m(id, component, pos[0], pos[1], pos[2], 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.);
particleContainer->addParticle(m, true);
}
}
10 changes: 5 additions & 5 deletions src/molecules/FullMolecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class FullMolecule : public MoleculeInterface {
// but if it is left away, all pointer data is not initialized (which is not
// neccessarily bad), but then assertions fail (e.g. in the destructor) and we can't
// use it's instances.
FullMolecule(unsigned long id = 0, Component *component = nullptr,
double rx = 0., double ry = 0., double rz = 0.,
double vx = 0., double vy = 0., double vz = 0.,
double qw = 0., double qx = 0., double qy = 0., double qz = 0.,
double Dx = 0., double Dy = 0., double Dz = 0.
FullMolecule(unsigned long id, Component *component,
double rx, double ry, double rz,
double vx, double vy, double vz,
double qw, double qx, double qy, double qz,
double Dx, double Dy, double Dz
);
FullMolecule(const FullMolecule& m);

Expand Down
10 changes: 5 additions & 5 deletions src/molecules/MoleculeRMM.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class MoleculeRMM : public MoleculeInterface {
};

public:
MoleculeRMM(unsigned long id = 0, Component *component = nullptr,
double rx = 0., double ry = 0., double rz = 0.,
double vx = 0., double vy = 0., double vz = 0.,
double qw = 0., double qx = 0., double qy = 0., double qz = 0.,
double Dx = 0., double Dy = 0., double Dz = 0.
MoleculeRMM(unsigned long id, Component *component,
double rx, double ry, double rz,
double vx, double vy, double vz,
double qw, double qx, double qy, double qz,
double Dx, double Dy, double Dz
) {
_state = STORAGE_AOS;
_r[0] = rx;
Expand Down
4 changes: 2 additions & 2 deletions src/parallel/ParticleDataFull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void ParticleDataFull::MoleculeToParticleData(ParticleDataFull &particleStruct,
particleStruct.D[2] = molecule.D(2);
}

void ParticleDataFull::ParticleDataToMolecule(const ParticleDataFull &particleStruct, Molecule &molecule) {
Molecule ParticleDataFull::ParticleDataToMolecule(const ParticleDataFull &particleStruct) {
Component* component = _simulation.getEnsemble()->getComponent(particleStruct.cid);
molecule = Molecule(particleStruct.id, component,
return Molecule(particleStruct.id, component,
particleStruct.r[0], particleStruct.r[1], particleStruct.r[2],
particleStruct.v[0], particleStruct.v[1], particleStruct.v[2],
particleStruct.q[0], particleStruct.q[1], particleStruct.q[2], particleStruct.q[3],
Expand Down
2 changes: 1 addition & 1 deletion src/parallel/ParticleDataFull.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ParticleDataFull {
static void MoleculeToParticleData(ParticleDataFull &particleStruct, Molecule &molecule);

//! @brief copy data from object of class ParticleDataFull to object of class Molecule
static void ParticleDataToMolecule(const ParticleDataFull &particleStruct, Molecule &molecule);
static Molecule ParticleDataToMolecule(const ParticleDataFull &particleStruct);

double r[3]; //! position
double v[3]; //! velocity
Expand Down
2 changes: 1 addition & 1 deletion src/parallel/ParticleDataRMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void ParticleDataRMM::MoleculeToParticleData(ParticleDataRMM &particleStruct, Mo
particleStruct.v[2] = molecule.v(2);
}

void ParticleDataRMM::ParticleDataToMolecule(const ParticleDataRMM &particleStruct, Molecule &molecule) {
Molecule ParticleDataRMM::ParticleDataToMolecule(const ParticleDataRMM &particleStruct) {
Component* component = _simulation.getEnsemble()->getComponent(0);
molecule = Molecule(particleStruct.id, component,
particleStruct.r[0], particleStruct.r[1], particleStruct.r[2],
Expand Down
2 changes: 1 addition & 1 deletion src/parallel/ParticleDataRMM.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ParticleDataRMM {
static void MoleculeToParticleData(ParticleDataRMM &particleStruct, Molecule &molecule);

//! @brief copy data from object of class class ParticleDataRMM to object of class Molecule
static void ParticleDataToMolecule(const ParticleDataRMM &particleStruct, Molecule &molecule);
static Molecule ParticleDataToMolecule(const ParticleDataRMM &particleStruct);

unsigned long id;
vcp_real_calc r[3];
Expand Down
4 changes: 3 additions & 1 deletion src/particleContainer/adapter/CellDataSoARMM.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class CellDataSoARMM : public CellDataSoABase {
return Molecule (
getMolUid(index), nullptr,
getMolR(0,index), getMolR(1,index), getMolR(2,index),
getMolV(0,index), getMolV(1,index), getMolV(2,index));
getMolV(0,index), getMolV(1,index), getMolV(2,index),
1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0);
}

void readImmutableMolecule(size_t index, MoleculeInterface& m) const {
Expand Down

0 comments on commit be75df9

Please sign in to comment.