Receiver SessionImpl::getReceiver(const std::string& name) const { qpid::sys::Mutex::ScopedLock l(lock); Receivers::const_iterator i = receivers.find(name); if (i == receivers.end()) { throw KeyError(name); } else { return i->second; } }
Value const &DictionaryValue::element(Value const &index) const { Elements::const_iterator i = _elements.find(ValueRef(&index)); if (i == _elements.end()) { throw KeyError("DictionaryValue::element", "Key '" + index.asText() + "' does not exist in the dictionary"); } return *i->second; }
void DictionaryValue::subtract(Value const &subtrahend) { Elements::iterator i = _elements.find(ValueRef(&subtrahend)); if (i == _elements.end()) { throw KeyError("DictionaryValue::subtract", "Key '" + subtrahend.asText() + "' does not exist in the dictionary"); } delete i->second; _elements.erase(i); }
Real EnergyTracker::getItem_py(const std::string& name){ int id=-1; findId(name,id,/*flags*/0,/*newIfNotFound*/false); if (id<0) KeyError("Unknown energy name '"+name+"'."); return energies.get(id); }
int main(int argc, char* argv[]) { // enable -constant ... if someone really wants it // enable -zeroTime to prevent accidentally trashing the initial fields Foam::timeSelector::addOptions(false, false); Foam::argList::noParallel(); Foam::argList::validOptions.set("format", "outputFormat"); # include "setRootCase.H" # include "createTime.H" // select a subset based on the command-line options instantList timeDirs = timeSelector::select ( runTime.times(), args ); if (timeDirs.empty()) { FatalErrorIn(args.executable()) << "No times selected" << exit(FatalError); } const string& format = args.optionFound("format") ? args.option("format") : "ascii"; // Loop over all times forAll (timeDirs, timeI) { // Set time for global database runTime.setTime(timeDirs[timeI], timeI); Info << "Time = " << runTime.timeName() << endl << endl; // Get list of objects from processor0 database fileNameList objNames = readDir(runTime.timePath(), fileName::FILE); fileNameList systemNames; for (label objI = 0, sysI = 0; objI < objNames.size(); ++objI) { if (objNames[objI].ext() == "system") { systemNames.setSize(systemNames.size() + 1); systemNames[sysI] = objNames[objI]; sysI++; } } forAll (systemNames, sysI) { fileName systemFile = systemNames[sysI]; Info << "Convert object " << systemNames[sysI] << endl; Foam::IFstream infile(runTime.timePath()/systemNames[sysI]); const Foam::dictionary sysDict(infile); // Read the source vector Foam::scalarField source; if (!sysDict.readIfPresent("source", source, false, false)) KeyError(systemFile, "source"); // Get the matrix sub dictionary if (!sysDict.isDict("matrix")) KeyError(systemFile, "matrix"); const Foam::dictionary& matDict = sysDict.subDict("matrix"); // Read the diagonal array - always present Foam::scalarField diag; if (!matDict.readIfPresent("diag", diag, false, false)) KeyError(systemFile, "diag"); // Upper and lower are optional Foam::scalarField upper; bool hasUpper = matDict.readIfPresent("upper", upper, false, false); Foam::scalarField lower; bool hasLower = matDict.readIfPresent("lower", lower, false, false); // Non-diagonal matrices must have the addressing arrays. Foam::labelList upperAddr; Foam::labelList lowerAddr; if (hasLower || hasUpper) { if (!matDict.readIfPresent("upperAddr", upperAddr, false, false)) KeyError(systemFile, "upperAddr"); if (!matDict.readIfPresent("lowerAddr", lowerAddr, false, false)) KeyError(systemFile, "lowerAddr"); } // Write the vector { Foam::fileName fileName = runTime.timePath() / systemFile.lessExt() + ".vec"; if (format == "ascii") { std::ofstream file(fileName.c_str(), std::ios_base::out|std::ios_base::trunc); for (Foam::scalarField::const_iterator ptr = source.begin(); ptr != source.end(); ++ptr) { file << *ptr << std::endl; } } else if (format == "binary") { std::ofstream file(fileName.c_str(), std::ios_base::trunc | std::ios_base::binary); WriteVecBinary(source, file); } else if (format == "numpy") { std::ofstream file(fileName.c_str(), std::ios_base::trunc | std::ios_base::binary); std::string header = MakeNumpyHeader(numpy_traits<flt>::dtype(), source.size()); file.write(header.c_str(), header.size()); WriteVecBinary(source, file); } else { // ERROR FatalErrorIn(args.executable()) << "Unknown format: " << format << exit(FatalError); } } // Write the matrix as "row col val" triples { Foam::fileName fileName = runTime.timePath() / systemFile.lessExt() + ".coo"; if (format == "ascii") { //Open the file. Foam::OFstream file(fileName); file << "# row col val" << Foam::endl; // Diagonal first Foam::scalarField::const_iterator ptr = diag.cbegin(), end = diag.cend(); for (int i = 0; ptr != end; ++ptr, ++i) { file << i << " " << i << " " << *ptr << Foam::endl; } // Only do more output if non-diagonal if (hasUpper || hasLower) { Foam::scalarField::const_iterator upPtr, upEnd; if (hasUpper) { upPtr = upper.cbegin(); upEnd = upper.cend(); } else { upPtr = lower.cbegin(); upEnd = lower.cend(); } Foam::scalarField::const_iterator loPtr, loEnd; if (hasLower) { loPtr = lower.cbegin(); loEnd = lower.cend(); } else { loPtr = upper.cbegin(); loEnd = upper.cend(); } // Get the indexing arrays Foam::labelList::const_iterator upAddrPtr = upperAddr.begin(); Foam::labelList::const_iterator loAddrPtr = lowerAddr.begin(); // Send to the file for(; loPtr != loEnd; ++loPtr, ++upPtr, ++upAddrPtr, ++loAddrPtr) { file << *upAddrPtr << " " << *loAddrPtr << " " << *loPtr << Foam::endl; file << *loAddrPtr << " " << *upAddrPtr << " " << *upPtr << Foam::endl; } } } else if (format == "binary") { std::ofstream file(fileName.c_str(), std::ios_base::trunc | std::ios_base::binary); WriteCooBinary(diag, upper, lower, upperAddr, lowerAddr, file); } else if (format == "numpy") { size_t nRecords = diag.size(); if (hasUpper || hasLower) nRecords += 2 * upperAddr.size(); std::ostringstream dtype; dtype << "[" << "('row', " << numpy_traits<idx>::dtype() << "), " << "('col', " << numpy_traits<idx>::dtype() << "), " << "('val', " << numpy_traits<flt>::dtype() << ")" << "]"; std::string header = MakeNumpyHeader(dtype.str(), nRecords); std::ofstream file(fileName.c_str(), std::ios_base::trunc | std::ios_base::binary); file.write(header.c_str(), header.size()); WriteCooBinary(diag, upper, lower, upperAddr, lowerAddr, file); } else { // ERROR FatalErrorIn(args.executable()) << "Unknown format: " << format << exit(FatalError); } } // End write COO } // End for args