--- trunk/src/rnemd/RNEMD.cpp 2014/04/05 20:56:01 1979 +++ trunk/src/rnemd/RNEMD.cpp 2015/03/05 15:40:58 2068 @@ -291,7 +291,18 @@ namespace OpenMD { kineticFlux_ = 0.0; } if (hasMomentumFluxVector) { - momentumFluxVector_ = rnemdParams->getMomentumFluxVector(); + std::vector mf = rnemdParams->getMomentumFluxVector(); + if (mf.size() != 3) { + sprintf(painCave.errMsg, + "RNEMD: Incorrect number of parameters specified for momentumFluxVector.\n" + "\tthere should be 3 parameters, but %lu were specified.\n", + mf.size()); + painCave.isFatal = 1; + simError(); + } + momentumFluxVector_.x() = mf[0]; + momentumFluxVector_.y() = mf[1]; + momentumFluxVector_.z() = mf[2]; } else { momentumFluxVector_ = V3Zero; if (hasMomentumFlux) { @@ -316,271 +327,292 @@ namespace OpenMD { break; } } - if (hasAngularMomentumFluxVector) { - angularMomentumFluxVector_ = rnemdParams->getAngularMomentumFluxVector(); - } else { - angularMomentumFluxVector_ = V3Zero; - if (hasAngularMomentumFlux) { - RealType angularMomentumFlux = rnemdParams->getAngularMomentumFlux(); - switch (rnemdFluxType_) { - case rnemdLx: - angularMomentumFluxVector_.x() = angularMomentumFlux; - break; - case rnemdLy: - angularMomentumFluxVector_.y() = angularMomentumFlux; - break; - case rnemdLz: - angularMomentumFluxVector_.z() = angularMomentumFlux; - break; - case rnemdKeLx: - angularMomentumFluxVector_.x() = angularMomentumFlux; - break; - case rnemdKeLy: - angularMomentumFluxVector_.y() = angularMomentumFlux; - break; - case rnemdKeLz: - angularMomentumFluxVector_.z() = angularMomentumFlux; - break; - default: - break; - } - } - } - - if (hasCoordinateOrigin) { - coordinateOrigin_ = rnemdParams->getCoordinateOrigin(); - } else { - coordinateOrigin_ = V3Zero; - } - - // do some sanity checking - - int selectionCount = seleMan_.getSelectionCount(); - - int nIntegrable = info->getNGlobalIntegrableObjects(); - - if (selectionCount > nIntegrable) { - sprintf(painCave.errMsg, - "RNEMD: The current objectSelection,\n" - "\t\t%s\n" - "\thas resulted in %d selected objects. However,\n" - "\tthe total number of integrable objects in the system\n" - "\tis only %d. This is almost certainly not what you want\n" - "\tto do. A likely cause of this is forgetting the _RB_0\n" - "\tselector in the selection script!\n", - rnemdObjectSelection_.c_str(), - selectionCount, nIntegrable); - painCave.isFatal = 0; - painCave.severity = OPENMD_WARNING; - simError(); + } + if (hasAngularMomentumFluxVector) { + std::vector amf = rnemdParams->getAngularMomentumFluxVector(); + if (amf.size() != 3) { + sprintf(painCave.errMsg, + "RNEMD: Incorrect number of parameters specified for angularMomentumFluxVector.\n" + "\tthere should be 3 parameters, but %lu were specified.\n", + amf.size()); + painCave.isFatal = 1; + simError(); } - - areaAccumulator_ = new Accumulator(); - - nBins_ = rnemdParams->getOutputBins(); - binWidth_ = rnemdParams->getOutputBinWidth(); - - data_.resize(RNEMD::ENDINDEX); - OutputData z; - z.units = "Angstroms"; - z.title = "Z"; - z.dataType = "RealType"; - z.accumulator.reserve(nBins_); - for (int i = 0; i < nBins_; i++) - z.accumulator.push_back( new Accumulator() ); - data_[Z] = z; - outputMap_["Z"] = Z; - - OutputData r; - r.units = "Angstroms"; - r.title = "R"; - r.dataType = "RealType"; - r.accumulator.reserve(nBins_); - for (int i = 0; i < nBins_; i++) - r.accumulator.push_back( new Accumulator() ); - data_[R] = r; - outputMap_["R"] = R; - - OutputData temperature; - temperature.units = "K"; - temperature.title = "Temperature"; - temperature.dataType = "RealType"; - temperature.accumulator.reserve(nBins_); - for (int i = 0; i < nBins_; i++) - temperature.accumulator.push_back( new Accumulator() ); - data_[TEMPERATURE] = temperature; - outputMap_["TEMPERATURE"] = TEMPERATURE; - - OutputData velocity; - velocity.units = "angstroms/fs"; - velocity.title = "Velocity"; - velocity.dataType = "Vector3d"; - velocity.accumulator.reserve(nBins_); - for (int i = 0; i < nBins_; i++) - velocity.accumulator.push_back( new VectorAccumulator() ); - data_[VELOCITY] = velocity; - outputMap_["VELOCITY"] = VELOCITY; - - OutputData angularVelocity; - angularVelocity.units = "angstroms^2/fs"; - angularVelocity.title = "AngularVelocity"; - angularVelocity.dataType = "Vector3d"; - angularVelocity.accumulator.reserve(nBins_); - for (int i = 0; i < nBins_; i++) - angularVelocity.accumulator.push_back( new VectorAccumulator() ); - data_[ANGULARVELOCITY] = angularVelocity; - outputMap_["ANGULARVELOCITY"] = ANGULARVELOCITY; - - OutputData density; - density.units = "g cm^-3"; - density.title = "Density"; - density.dataType = "RealType"; - density.accumulator.reserve(nBins_); - for (int i = 0; i < nBins_; i++) - density.accumulator.push_back( new Accumulator() ); - data_[DENSITY] = density; - outputMap_["DENSITY"] = DENSITY; - - if (hasOutputFields) { - parseOutputFileFormat(rnemdParams->getOutputFields()); - } else { - if (usePeriodicBoundaryConditions_) - outputMask_.set(Z); - else - outputMask_.set(R); + angularMomentumFluxVector_.x() = amf[0]; + angularMomentumFluxVector_.y() = amf[1]; + angularMomentumFluxVector_.z() = amf[2]; + } else { + angularMomentumFluxVector_ = V3Zero; + if (hasAngularMomentumFlux) { + RealType angularMomentumFlux = rnemdParams->getAngularMomentumFlux(); switch (rnemdFluxType_) { - case rnemdKE: - case rnemdRotKE: - case rnemdFullKE: - outputMask_.set(TEMPERATURE); - break; - case rnemdPx: - case rnemdPy: - outputMask_.set(VELOCITY); - break; - case rnemdPz: - case rnemdPvector: - outputMask_.set(VELOCITY); - outputMask_.set(DENSITY); - break; case rnemdLx: + angularMomentumFluxVector_.x() = angularMomentumFlux; + break; case rnemdLy: + angularMomentumFluxVector_.y() = angularMomentumFlux; + break; case rnemdLz: - case rnemdLvector: - outputMask_.set(ANGULARVELOCITY); + angularMomentumFluxVector_.z() = angularMomentumFlux; break; case rnemdKeLx: + angularMomentumFluxVector_.x() = angularMomentumFlux; + break; case rnemdKeLy: + angularMomentumFluxVector_.y() = angularMomentumFlux; + break; case rnemdKeLz: - case rnemdKeLvector: - outputMask_.set(TEMPERATURE); - outputMask_.set(ANGULARVELOCITY); + angularMomentumFluxVector_.z() = angularMomentumFlux; break; - case rnemdKePx: - case rnemdKePy: - outputMask_.set(TEMPERATURE); - outputMask_.set(VELOCITY); - break; - case rnemdKePvector: - outputMask_.set(TEMPERATURE); - outputMask_.set(VELOCITY); - outputMask_.set(DENSITY); - break; default: break; } - } - - if (hasOutputFileName) { - rnemdFileName_ = rnemdParams->getOutputFileName(); - } else { - rnemdFileName_ = getPrefix(info->getFinalConfigFileName()) + ".rnemd"; - } + } + } - exchangeTime_ = rnemdParams->getExchangeTime(); - - Snapshot* currentSnap_ = info->getSnapshotManager()->getCurrentSnapshot(); - // total exchange sums are zeroed out at the beginning: - - kineticExchange_ = 0.0; - momentumExchange_ = V3Zero; - angularMomentumExchange_ = V3Zero; - - std::ostringstream selectionAstream; - std::ostringstream selectionBstream; + if (hasCoordinateOrigin) { + std::vector co = rnemdParams->getCoordinateOrigin(); + if (co.size() != 3) { + sprintf(painCave.errMsg, + "RNEMD: Incorrect number of parameters specified for coordinateOrigin.\n" + "\tthere should be 3 parameters, but %lu were specified.\n", + co.size()); + painCave.isFatal = 1; + simError(); + } + coordinateOrigin_.x() = co[0]; + coordinateOrigin_.y() = co[1]; + coordinateOrigin_.z() = co[2]; + } else { + coordinateOrigin_ = V3Zero; + } - if (hasSelectionA_) { - selectionA_ = rnemdParams->getSelectionA(); - } else { - if (usePeriodicBoundaryConditions_) { - Mat3x3d hmat = currentSnap_->getHmat(); - - if (hasSlabWidth) - slabWidth_ = rnemdParams->getSlabWidth(); - else - slabWidth_ = hmat(2,2) / 10.0; - - if (hasSlabACenter) - slabACenter_ = rnemdParams->getSlabACenter(); - else - slabACenter_ = 0.0; - - selectionAstream << "select wrappedz > " - << slabACenter_ - 0.5*slabWidth_ - << " && wrappedz < " - << slabACenter_ + 0.5*slabWidth_; - selectionA_ = selectionAstream.str(); - } else { - if (hasSphereARadius) - sphereARadius_ = rnemdParams->getSphereARadius(); - else { - // use an initial guess to the size of the inner slab to be 1/10 the - // radius of an approximately spherical hull: - Thermo thermo(info); - RealType hVol = thermo.getHullVolume(); - sphereARadius_ = 0.1 * pow((3.0 * hVol / (4.0 * M_PI)), 1.0/3.0); - } - selectionAstream << "select r < " << sphereARadius_; - selectionA_ = selectionAstream.str(); - } + // do some sanity checking + + int selectionCount = seleMan_.getSelectionCount(); + int nIntegrable = info->getNGlobalIntegrableObjects(); + if (selectionCount > nIntegrable) { + sprintf(painCave.errMsg, + "RNEMD: The current objectSelection,\n" + "\t\t%s\n" + "\thas resulted in %d selected objects. However,\n" + "\tthe total number of integrable objects in the system\n" + "\tis only %d. This is almost certainly not what you want\n" + "\tto do. A likely cause of this is forgetting the _RB_0\n" + "\tselector in the selection script!\n", + rnemdObjectSelection_.c_str(), + selectionCount, nIntegrable); + painCave.isFatal = 0; + painCave.severity = OPENMD_WARNING; + simError(); + } + + areaAccumulator_ = new Accumulator(); + + nBins_ = rnemdParams->getOutputBins(); + binWidth_ = rnemdParams->getOutputBinWidth(); + + data_.resize(RNEMD::ENDINDEX); + OutputData z; + z.units = "Angstroms"; + z.title = "Z"; + z.dataType = "RealType"; + z.accumulator.reserve(nBins_); + for (int i = 0; i < nBins_; i++) + z.accumulator.push_back( new Accumulator() ); + data_[Z] = z; + outputMap_["Z"] = Z; + + OutputData r; + r.units = "Angstroms"; + r.title = "R"; + r.dataType = "RealType"; + r.accumulator.reserve(nBins_); + for (int i = 0; i < nBins_; i++) + r.accumulator.push_back( new Accumulator() ); + data_[R] = r; + outputMap_["R"] = R; + + OutputData temperature; + temperature.units = "K"; + temperature.title = "Temperature"; + temperature.dataType = "RealType"; + temperature.accumulator.reserve(nBins_); + for (int i = 0; i < nBins_; i++) + temperature.accumulator.push_back( new Accumulator() ); + data_[TEMPERATURE] = temperature; + outputMap_["TEMPERATURE"] = TEMPERATURE; + + OutputData velocity; + velocity.units = "angstroms/fs"; + velocity.title = "Velocity"; + velocity.dataType = "Vector3d"; + velocity.accumulator.reserve(nBins_); + for (int i = 0; i < nBins_; i++) + velocity.accumulator.push_back( new VectorAccumulator() ); + data_[VELOCITY] = velocity; + outputMap_["VELOCITY"] = VELOCITY; + + OutputData angularVelocity; + angularVelocity.units = "angstroms^2/fs"; + angularVelocity.title = "AngularVelocity"; + angularVelocity.dataType = "Vector3d"; + angularVelocity.accumulator.reserve(nBins_); + for (int i = 0; i < nBins_; i++) + angularVelocity.accumulator.push_back( new VectorAccumulator() ); + data_[ANGULARVELOCITY] = angularVelocity; + outputMap_["ANGULARVELOCITY"] = ANGULARVELOCITY; + + OutputData density; + density.units = "g cm^-3"; + density.title = "Density"; + density.dataType = "RealType"; + density.accumulator.reserve(nBins_); + for (int i = 0; i < nBins_; i++) + density.accumulator.push_back( new Accumulator() ); + data_[DENSITY] = density; + outputMap_["DENSITY"] = DENSITY; + + if (hasOutputFields) { + parseOutputFileFormat(rnemdParams->getOutputFields()); + } else { + if (usePeriodicBoundaryConditions_) + outputMask_.set(Z); + else + outputMask_.set(R); + switch (rnemdFluxType_) { + case rnemdKE: + case rnemdRotKE: + case rnemdFullKE: + outputMask_.set(TEMPERATURE); + break; + case rnemdPx: + case rnemdPy: + outputMask_.set(VELOCITY); + break; + case rnemdPz: + case rnemdPvector: + outputMask_.set(VELOCITY); + outputMask_.set(DENSITY); + break; + case rnemdLx: + case rnemdLy: + case rnemdLz: + case rnemdLvector: + outputMask_.set(ANGULARVELOCITY); + break; + case rnemdKeLx: + case rnemdKeLy: + case rnemdKeLz: + case rnemdKeLvector: + outputMask_.set(TEMPERATURE); + outputMask_.set(ANGULARVELOCITY); + break; + case rnemdKePx: + case rnemdKePy: + outputMask_.set(TEMPERATURE); + outputMask_.set(VELOCITY); + break; + case rnemdKePvector: + outputMask_.set(TEMPERATURE); + outputMask_.set(VELOCITY); + outputMask_.set(DENSITY); + break; + default: + break; } + } - if (hasSelectionB_) { - selectionB_ = rnemdParams->getSelectionB(); - - } else { - if (usePeriodicBoundaryConditions_) { - Mat3x3d hmat = currentSnap_->getHmat(); - - if (hasSlabWidth) - slabWidth_ = rnemdParams->getSlabWidth(); - else - slabWidth_ = hmat(2,2) / 10.0; - - if (hasSlabBCenter) - slabBCenter_ = rnemdParams->getSlabBCenter(); - else - slabBCenter_ = hmat(2,2) / 2.0; + if (hasOutputFileName) { + rnemdFileName_ = rnemdParams->getOutputFileName(); + } else { + rnemdFileName_ = getPrefix(info->getFinalConfigFileName()) + ".rnemd"; + } + + exchangeTime_ = rnemdParams->getExchangeTime(); + + Snapshot* currentSnap_ = info->getSnapshotManager()->getCurrentSnapshot(); + // total exchange sums are zeroed out at the beginning: + + kineticExchange_ = 0.0; + momentumExchange_ = V3Zero; + angularMomentumExchange_ = V3Zero; + + std::ostringstream selectionAstream; + std::ostringstream selectionBstream; + + if (hasSelectionA_) { + selectionA_ = rnemdParams->getSelectionA(); + } else { + if (usePeriodicBoundaryConditions_) { + Mat3x3d hmat = currentSnap_->getHmat(); - selectionBstream << "select wrappedz > " - << slabBCenter_ - 0.5*slabWidth_ - << " && wrappedz < " - << slabBCenter_ + 0.5*slabWidth_; + if (hasSlabWidth) + slabWidth_ = rnemdParams->getSlabWidth(); + else + slabWidth_ = hmat(2,2) / 10.0; + + if (hasSlabACenter) + slabACenter_ = rnemdParams->getSlabACenter(); + else + slabACenter_ = 0.0; + + selectionAstream << "select wrappedz > " + << slabACenter_ - 0.5*slabWidth_ + << " && wrappedz < " + << slabACenter_ + 0.5*slabWidth_; + selectionA_ = selectionAstream.str(); + } else { + if (hasSphereARadius) + sphereARadius_ = rnemdParams->getSphereARadius(); + else { + // use an initial guess to the size of the inner slab to be 1/10 the + // radius of an approximately spherical hull: + Thermo thermo(info); + RealType hVol = thermo.getHullVolume(); + sphereARadius_ = 0.1 * pow((3.0 * hVol / (4.0 * M_PI)), 1.0/3.0); + } + selectionAstream << "select r < " << sphereARadius_; + selectionA_ = selectionAstream.str(); + } + } + + if (hasSelectionB_) { + selectionB_ = rnemdParams->getSelectionB(); + + } else { + if (usePeriodicBoundaryConditions_) { + Mat3x3d hmat = currentSnap_->getHmat(); + + if (hasSlabWidth) + slabWidth_ = rnemdParams->getSlabWidth(); + else + slabWidth_ = hmat(2,2) / 10.0; + + if (hasSlabBCenter) + slabBCenter_ = rnemdParams->getSlabBCenter(); + else + slabBCenter_ = hmat(2,2) / 2.0; + + selectionBstream << "select wrappedz > " + << slabBCenter_ - 0.5*slabWidth_ + << " && wrappedz < " + << slabBCenter_ + 0.5*slabWidth_; + selectionB_ = selectionBstream.str(); + } else { + if (hasSphereBRadius_) { + sphereBRadius_ = rnemdParams->getSphereBRadius(); + selectionBstream << "select r > " << sphereBRadius_; selectionB_ = selectionBstream.str(); } else { - if (hasSphereBRadius_) { - sphereBRadius_ = rnemdParams->getSphereBRadius(); - selectionBstream << "select r > " << sphereBRadius_; - selectionB_ = selectionBstream.str(); - } else { - selectionB_ = "select hull"; - BisHull_ = true; - hasSelectionB_ = true; - } + selectionB_ = "select hull"; + BisHull_ = true; + hasSelectionB_ = true; } } } - + + // object evaluator: evaluator_.loadScriptString(rnemdObjectSelection_); seleMan_.setSelectionSet(evaluator_.evaluate()); @@ -622,13 +654,13 @@ namespace OpenMD { StuntDouble* sd; - RealType min_val; + RealType min_val(0.0); int min_found = 0; - StuntDouble* min_sd; + StuntDouble* min_sd = NULL; - RealType max_val; + RealType max_val(0.0); int max_found = 0; - StuntDouble* max_sd; + StuntDouble* max_sd = NULL; for (sd = seleManA_.beginSelected(selei); sd != NULL; sd = seleManA_.nextSelected(selei)) { @@ -857,13 +889,13 @@ namespace OpenMD { Vector3d min_vel; Vector3d max_vel = max_sd->getVel(); - MPI_Status* status; + MPI_Status status; // point-to-point swap of the velocity vector MPI_Sendrecv(max_vel.getArrayPointer(), 3, MPI_REALTYPE, min_vals.rank, 0, min_vel.getArrayPointer(), 3, MPI_REALTYPE, - min_vals.rank, 0, MPI_COMM_WORLD, status); + min_vals.rank, 0, MPI_COMM_WORLD, &status); switch(rnemdFluxType_) { case rnemdKE : @@ -878,7 +910,7 @@ namespace OpenMD { MPI_REALTYPE, min_vals.rank, 1, min_angMom.getArrayPointer(), 3, MPI_REALTYPE, min_vals.rank, 1, - MPI_COMM_WORLD, status); + MPI_COMM_WORLD, &status); max_sd->setJ(min_angMom); } @@ -903,13 +935,13 @@ namespace OpenMD { Vector3d max_vel; Vector3d min_vel = min_sd->getVel(); - MPI_Status* status; + MPI_Status status; // point-to-point swap of the velocity vector MPI_Sendrecv(min_vel.getArrayPointer(), 3, MPI_REALTYPE, max_vals.rank, 0, max_vel.getArrayPointer(), 3, MPI_REALTYPE, - max_vals.rank, 0, MPI_COMM_WORLD, status); + max_vals.rank, 0, MPI_COMM_WORLD, &status); switch(rnemdFluxType_) { case rnemdKE : @@ -924,7 +956,7 @@ namespace OpenMD { MPI_REALTYPE, max_vals.rank, 1, max_angMom.getArrayPointer(), 3, MPI_REALTYPE, max_vals.rank, 1, - MPI_COMM_WORLD, status); + MPI_COMM_WORLD, &status); min_sd->setJ(max_angMom); } @@ -988,7 +1020,6 @@ namespace OpenMD { int selej; Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); - RealType time = currentSnap_->getTime(); Mat3x3d hmat = currentSnap_->getHmat(); StuntDouble* sd; @@ -1436,7 +1467,6 @@ namespace OpenMD { int selej; Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); - RealType time = currentSnap_->getTime(); Mat3x3d hmat = currentSnap_->getHmat(); StuntDouble* sd; @@ -1743,7 +1773,6 @@ namespace OpenMD { areaA = evaluatorA_.getSurfaceArea(); else { - cerr << "selection A did not have surface area, recomputing\n"; int isd; StuntDouble* sd; vector aSites; @@ -1781,10 +1810,9 @@ namespace OpenMD { } if (hasSelectionB_) { - if (evaluatorB_.hasSurfaceArea()) + if (evaluatorB_.hasSurfaceArea()) { areaB = evaluatorB_.getSurfaceArea(); - else { - cerr << "selection B did not have surface area, recomputing\n"; + } else { int isd; StuntDouble* sd; @@ -1875,7 +1903,7 @@ namespace OpenMD { void RNEMD::collectData() { if (!doRNEMD_) return; Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); - + // collectData can be called more frequently than the doRNEMD, so use the // computed area from the last exchange time: RealType area = getDividingArea(); @@ -1990,7 +2018,7 @@ namespace OpenMD { } } } - + #ifdef IS_MPI for (int i = 0; i < nBins_; i++) { @@ -2097,7 +2125,7 @@ namespace OpenMD { painCave.severity = OPENMD_ERROR; simError(); } - } + } } void RNEMD::writeOutputFile() {