void CompositionProfile::sample(long iStep) { Vector blengths; // Lengths of simulation box blengths = system().boundary().lengths(); if (isAtInterval(iStep)) { Vector position; double product; System::ConstMoleculeIterator molIter; Molecule::ConstAtomIterator atomIter; int nSpecies, iSpecies, typeId; // Loop over all atoms nSpecies = system().simulation().nSpecies(); for (iSpecies = 0; iSpecies < nSpecies; ++iSpecies) { system().begin(iSpecies, molIter); for ( ; molIter.notEnd(); ++molIter) { molIter->begin(atomIter); for ( ; atomIter.notEnd(); ++atomIter) { position = atomIter->position(); typeId = atomIter->typeId(); for (int i = 0; i < Dimension; ++i) { position[i] /= blengths[i]; } // Loop over direction vectors for (int i = 0; i < nDirection_; ++i) { product = position.dot(waveVectors_[i]); product /= waveVectors_[i].abs(); accumulators_[i+typeId*nDirection_].sample(product); } } } } ++nSample_; } }
void CompositionProfile::sample(long iStep) { Vector blengths; // Lengths of simulation box blengths = system().boundary().lengths(); if (isAtInterval(iStep)) { Vector position; double product; System::ConstMoleculeIterator molIter; Molecule::ConstAtomIterator atomIter; int nSpecies, iSpecies, typeId; // Clear accumulators for the current timestep for (int i = 0; i < nDirection_; ++i) { for (int j = 0; j < nAtomType_; ++j){ currentAccumulators_[i+j*nDirection_].clear(); } } // Select open mode for output files std::ios_base::openmode mode = std::ios_base::out; if (!isFirstStep_) { mode = std::ios_base::out | std::ios_base::app; } // Open log files for (int i = 0; i < nDirection_; ++i) { for (int j = 0; j < nAtomType_; ++j){ std::ostringstream oss; oss << outputFileName(); for (int k = 0; k < Dimension; ++k) { oss << "_" << intVectors_[i][k]; } oss << "_type" << j << ".log"; fileMaster().openOutputFile(oss.str(), logFiles_[i+j*nDirection_], mode); } } // Loop over all atoms nSpecies = system().simulation().nSpecies(); for (iSpecies = 0; iSpecies < nSpecies; ++iSpecies) { system().begin(iSpecies, molIter); for ( ; molIter.notEnd(); ++molIter) { molIter->begin(atomIter); for ( ; atomIter.notEnd(); ++atomIter) { position = atomIter->position(); typeId = atomIter->typeId(); for (int i = 0; i < Dimension; ++i) { position[i] /= blengths[i]; } // Loop over direction vectors for (int i = 0; i < nDirection_; ++i) { product = position.dot(waveVectors_[i]); product /= waveVectors_[i].abs(); accumulators_[i+typeId*nDirection_].sample(product); currentAccumulators_[i+typeId*nDirection_].sample(product); } } } } ++nSample_; // Output to log files for (int i = 0; i < nDirection_; ++i) { for (int j = 0; j < nAtomType_; ++j){ currentAccumulators_[i+j*nDirection_].output(logFiles_[i+j*nDirection_]); logFiles_[i+j*nDirection_] << std::endl; } } // Close log files for (int i = 0; i < nDirection_; ++i) { for (int j = 0; j < nAtomType_; ++j){ logFiles_[i+j*nDirection_].close(); } } isFirstStep_ = false; } }
/* * Increment Structure Factor */ void IntraStructureFactor::sample(long iStep) { if (isAtInterval(iStep)) { Vector position; std::complex<double> rho[2]; std::complex<double> expFactor; double volume = system().boundary().volume(); double product, dS; System::ConstMoleculeIterator molIter; Molecule::ConstAtomIterator atomIter; int typeId, i, j, k; makeWaveVectors(); // Set all Deltas to zero for (i = 0; i < nWave_; ++i) { for (int pairId = 0; pairId < nAtomTypeIdPair_; ++pairId) { structureFactorDelta_(i, pairId) = 0; } } // Loop over molecules in species system().begin(speciesId_, molIter); for ( ; molIter.notEnd(); ++molIter) { // Set all Fourier modes to zero for (i = 0; i < nWave_; ++i) { for (typeId = 0; typeId <= nAtomType_; ++typeId) { fourierModes_(i, typeId) = 0; } } // Loop over all atoms in one molecule molIter->begin(atomIter); for ( ; atomIter.notEnd(); ++atomIter) { position = atomIter->position(); typeId = atomIter->typeId(); // Loop over wavevectors for (i = 0; i < nWave_; ++i) { product = position.dot(waveVectors_[i]); expFactor = exp( product*Constants::Im ); fourierModes_(i, typeId) += expFactor; fourierModes_(i, nAtomType_) += expFactor; } } // Increment structure factors for (i = 0; i < nWave_; ++i) { for (j = 0; j < nAtomTypeIdPair_; ++j) { for (k = 0; k < 2; ++k) { typeId = atomTypeIdPairs_[j][k]; if (typeId >= 0) { rho[k] = fourierModes_(i, typeId); } else { rho[k] = fourierModes_(i, nAtomType_); } } rho[0] = std::conj(rho[0]); dS = std::real(rho[0]*rho[1])/volume; structureFactors_(i, j) += dS; structureFactorDelta_(i,j) += dS; } } } ++nSample_; } }
/* * Increment structure factors for all wavevectors and modes. */ void StructureFactor::sample(long iStep) { if (isAtInterval(iStep)) { fileMaster().openOutputFile(outputFileName("_max.dat"), outputFile_, !isFirstStep_); isFirstStep_ = false; Vector position; std::complex<double> expFactor; double product; System::ConstMoleculeIterator molIter; Molecule::ConstAtomIterator atomIter; int nSpecies, iSpecies, typeId, i, j; makeWaveVectors(); // Set all Fourier modes to zero for (i = 0; i < nWave_; ++i) { for (j = 0; j < nMode_; ++j) { fourierModes_(i, j) = std::complex<double>(0.0, 0.0); } } // Loop over all atoms nSpecies = system().simulation().nSpecies(); for (iSpecies = 0; iSpecies < nSpecies; ++iSpecies) { system().begin(iSpecies, molIter); for ( ; molIter.notEnd(); ++molIter) { molIter->begin(atomIter); for ( ; atomIter.notEnd(); ++atomIter) { position = atomIter->position(); typeId = atomIter->typeId(); // Loop over wavevectors for (i = 0; i < nWave_; ++i) { product = position.dot(waveVectors_[i]); expFactor = exp( product*Constants::Im ); for (j = 0; j < nMode_; ++j) { fourierModes_(i, j) += modes_(j, typeId)*expFactor; } } } } } // Increment structure factors double volume = system().boundary().volume(); double norm; for (j = 0; j < nMode_; ++j) { double maxValue = 0.0; IntVector maxIntVector; double maxQ; for (i = 0; i < nWave_; ++i) { norm = std::norm(fourierModes_(i, j)); if (double(norm/volume) >= maxValue) { maxValue = double(norm/volume); maxIntVector = waveIntVectors_[i]; maxQ = waveVectors_[i].abs(); } structureFactors_(i, j) += norm/volume; } // Output current maximum S(q) outputFile_ << maxIntVector; outputFile_ << Dbl(maxQ,20,8); outputFile_ << Dbl(maxValue,20,8); outputFile_ << std::endl; } ++nSample_; outputFile_ << std::endl; outputFile_.close(); } }
/// Increment Structure Factor void GPUStructureFactorGrid::sample(long iStep) { if (isAtInterval(iStep)) { Vector position; System::ConstMoleculeIterator molIter; Molecule::ConstAtomIterator atomIter; int nSpecies, iSpecies, typeId, i, j; makeWaveVectors(); // allocate temporary arrays int nType = system().simulation().nAtomType(); float3 *h_wave_vectors = new float3[nWave_]; float3 *h_pos = new float3[system().simulation().atomCapacity()]; int *h_type = new int[system().simulation().atomCapacity()]; float *h_mode = new float[nMode_*nType]; float *h_sq = new float[nMode_*nWave_]; // Load wave vectors for (int i = 0; i < nWave_; i++) h_wave_vectors[i] = make_float3((float) waveVectors_[i][0], (float) waveVectors_[i][1], (float) waveVectors_[i][2]); // Load atoms into temporary storage nSpecies = system().simulation().nSpecies(); int nAtom = 0; for (iSpecies = 0; iSpecies < nSpecies; ++iSpecies) { system().begin(iSpecies, molIter); for ( ; molIter.notEnd(); ++molIter) { molIter->begin(atomIter); for ( ; atomIter.notEnd(); ++atomIter) { position = atomIter->position(); typeId = atomIter->typeId(); h_pos[nAtom] = make_float3(position[0],position[1],position[2]); h_type[nAtom] = typeId; nAtom++; } } } // Load modes for (i = 0; i < nMode_; ++i) { for (j = 0; j < nType; ++j) { h_mode[nType*i + j] = modes_(i, j); } } // Calculate structure factors int res = gpu_sample_structure_factor(nWave_, h_wave_vectors, nAtom, h_pos, h_type, nType, nMode_, h_mode, h_sq, system().boundary().volume() ); if (res) UTIL_THROW("Error updating structure factor."); // increment structure factors for (j = 0; j < nMode_; ++j) { double maxValue = 0.0; IntVector maxIntVector; double maxQ; for (i = 0; i < nWave_; ++i) { if ((double) h_sq[j*nWave_+i] >= maxValue) { maxValue = (double) h_sq[j*nWave_+i]; maxIntVector = waveIntVectors_[i]; maxQ = waveVectors_[i].abs(); } structureFactors_(i, j) += (double) h_sq[j*nWave_ + i]; } //maximumValue_[j].insert(maximumValue_[j].end(), 1, maxValue); //maximumWaveIntVector_[j].insert(maximumWaveIntVector_[j].end(), 1, maxIntVector); //maximumQ_[j].insert(maximumQ_[j].end(), 1, maxQ); } delete [] h_wave_vectors; delete [] h_pos; delete [] h_mode; delete [] h_type; delete [] h_sq; ++nSample_; } }
/* * Write the configuration file. */ void McMdConfigIo::write(std::ostream &out) { using std::endl; // Write Boundary dimensions out << "BOUNDARY" << endl << endl; out << boundary() << endl; // Write atomic positions System::ConstMoleculeIterator molIter; Molecule::ConstAtomIterator atomIter; Species* speciesPtr; int iSpecies, iMolecule; out << endl << "MOLECULES" << endl; for (iSpecies = 0; iSpecies < simulation().nSpecies(); ++iSpecies) { out << endl; out << "species " << iSpecies << endl; out << "nMolecule " << system().nMolecule(iSpecies) << endl; speciesPtr = &simulation().species(iSpecies); iMolecule = 0; system().begin(iSpecies, molIter); for ( ; molIter.notEnd(); ++molIter) { out << endl; out << "molecule " << iMolecule << endl; if (speciesPtr->isMutable()) { speciesPtr->mutator().writeMoleculeState(out, *molIter); } for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) { //out << atomIter->position() << endl; writeAtom(out, *atomIter); } ++iMolecule; } } #ifdef INTER_TETHER { // Scope for local variables // Write Tethers Tether* tetherPtr; Atom* atomPtr; Molecule* molPtr; int iTether, nTether, iAtom; out << std::endl; out << "TETHERS" << endl << endl; nTether = system().tetherMaster().nTether(); out << Label("nTether") << nTether << std::endl; for (iTether = 0; iTether < nTether; ++iTether) { tetherPtr = &(system().tetherMaster().tether(iTether)); atomPtr = &tetherPtr->atom(); molPtr = &atomPtr->molecule(); iAtom = atomPtr->indexInMolecule(); iMolecule = system().moleculeId(*molPtr); iSpecies = molPtr->species().id(); out << Int(iSpecies,5) << Int(iMolecule,9) << Int(iAtom,6) << tetherPtr->anchor() << std::endl; } } #endif #ifdef MCMD_LINK { // Scope for local variables // Write Links Link* linkPtr; Atom* atomPtr; Molecule* molPtr; int iLink, nLink, iAtom; out << std::endl; out << "LINKS" << endl << endl; nLink = system().linkMaster().nLink(); out << Label("nLink") << nLink << std::endl; for (iLink = 0; iLink < nLink; ++iLink) { linkPtr = &(system().linkMaster().link(iLink)); // Output species, molecule, atom ids for atom 0 atomPtr = &(linkPtr->atom0()); molPtr = &atomPtr->molecule(); iAtom = atomPtr->indexInMolecule(); iMolecule = system().moleculeId(*molPtr); iSpecies = molPtr->species().id(); out << Int(iSpecies,8) << Int(iMolecule,8) << Int(iAtom,8); out << " "; // Output species, molecule, atom ids for atom 1 atomPtr = &(linkPtr->atom1()); molPtr = &atomPtr->molecule(); iAtom = atomPtr->indexInMolecule(); iMolecule = system().moleculeId(*molPtr); iSpecies = molPtr->species().id(); out << Int(iSpecies,8) << Int(iMolecule,8) << Int(iAtom,8); out << " "; out << Int(linkPtr->typeId(),8) << std::endl; } } #endif }