/* * Read parameter speciesId. */ void EndSwapMove::readParameters(std::istream& in) { readProbability(in); read<int>(in, "speciesId", speciesId_); Species* speciesPtr = &(simulation().species(speciesId_)); int nAtom = speciesPtr->nAtom(); // Preconditions if (speciesPtr->isMutable()) { UTIL_THROW("EndSwapMove on mutable Species"); } Linear* linearPtr = dynamic_cast<Linear*>(speciesPtr); if (linearPtr == 0) { UTIL_THROW("EndSwapMove on Species that is not a Linear"); } // Allocate memory atomTypeIds_.allocate(nAtom); positions_.allocate(nAtom); // Set array of atom type ids for (int i = 0; i < nAtom; ++i) { atomTypeIds_[i] = speciesPtr->atomTypeId(i); } }
/* * Load state from a binary file archive. */ void McMuExchange::loadParameters(Serializable::IArchive& ar) { loadInterval(ar); loadOutputFileName(ar); loadParameter(ar, "speciesId", speciesId_); ar >> nAtom_; Species* speciesPtr; speciesPtr = &(system().simulation().species(speciesId_)); if (nAtom_ != speciesPtr->nAtom()) { UTIL_THROW("Inconsistent values of nAtom on loading"); } newTypeIds_.allocate(nAtom_); loadDArray(ar, "newTypeIds", newTypeIds_, nAtom_); flipAtomIds_.allocate(nAtom_); isAtomFlipped_.allocate(nAtom_); for (int i = 0; i < nAtom_; ++i) { if (newTypeIds_[i] != speciesPtr->atomTypeId(i)) { flipAtomIds_.append(i); isAtomFlipped_[i] = 1; } else { isAtomFlipped_[i] = 0; } } accumulators_.allocate(speciesPtr->capacity()); ar >> nMolecule_; for (int i = 0; i < nMolecule_; ++i) { ar >> accumulators_[i]; } isInitialized_ = true; }
/* * Initialize all Molecule and Atom objects for one Species (private). * * This function creates associations between Species, Molecule, and * Atom objects for all molecules of one species, and sets atom typeIds. * * For each molecule, it sets the id, species pointer, nAtom, and the * firstAtom pointer. The molecule id is only unique within each species. * * For each atom, it sets the molecule pointer and an integer typeId. * * This method also pushes all molecules of the species onto the * reservoir, pushing them in order of decreasing molecule id. */ void Simulation::initializeSpecies(int iSpecies) { Species* speciesPtr; Molecule* moleculePtr; Atom* atomPtr; int iMol, iAtom; int capacity, nAtom; speciesPtr = &species(iSpecies); capacity = speciesPtr->capacity(); nAtom = speciesPtr->nAtom(); // Initialize pointers before loop moleculePtr = &molecules_[firstMoleculeIds_[iSpecies]]; atomPtr = &atoms_[firstAtomIds_[iSpecies]]; // Loop over all molecules in Species for (iMol = 0; iMol < capacity; ++iMol) { // Initialize a Molecule moleculePtr->setId(iMol); moleculePtr->setSpecies(*speciesPtr); moleculePtr->setNAtom(nAtom); moleculePtr->setFirstAtom(*atomPtr); // Loop over atoms in a molecule, set molecule and atom TypeId for (iAtom = 0; iAtom < nAtom; ++iAtom) { atomPtr->setMolecule(*moleculePtr); atomPtr->setTypeId(speciesPtr->atomTypeId(iAtom)); ++atomPtr; } ++moleculePtr; } // Push all molecules of this species onto the reservoir stack // Push on in reverse order, so that they pop off in sequence moleculePtr = &molecules_[firstMoleculeIds_[iSpecies] + capacity - 1]; for (iMol = 0; iMol < capacity; ++iMol) { speciesPtr->reservoir().push(*moleculePtr); --moleculePtr; } }