ChebyshevRate::ChebyshevRate(double Tmin, double Tmax, double Pmin, double Pmax, const Array2D& coeffs) : Tmin_(Tmin) , Tmax_(Tmax) , Pmin_(Pmin) , Pmax_(Pmax) , nP_(coeffs.nColumns()) , nT_(coeffs.nRows()) , chebCoeffs_(coeffs.nColumns() * coeffs.nRows(), 0.0) , dotProd_(coeffs.nRows()) { double logPmin = std::log10(Pmin); double logPmax = std::log10(Pmax); double TminInv = 1.0 / Tmin; double TmaxInv = 1.0 / Tmax; TrNum_ = - TminInv - TmaxInv; TrDen_ = 1.0 / (TmaxInv - TminInv); PrNum_ = - logPmin - logPmax; PrDen_ = 1.0 / (logPmax - logPmin); for (size_t t = 0; t < nT_; t++) { for (size_t p = 0; p < nP_; p++) { chebCoeffs_[nP_*t + p] = coeffs(t,p); } } }
/* * @param s output stream * @param title plot title * @param names vector of variable names * @param data N x M data array. * data(n,m) is the m^th value of the n^th variable. */ void outputExcel(std::ostream &s, const std::string &title, const std::vector<std::string>& names, const Array2D& data) { int i,j; int npts = static_cast<int>(data.nColumns()); int nv = static_cast<int>(data.nRows()); s << title + "," << endl; for (i = 0; i < nv; i++) { s << names[i] << ","; } s << endl; for (i = 0; i < npts; i++) { for (j = 0; j < nv; j++) { s << data(j,i) << ","; } s << endl; } }
/* * @param s output stream * @param title plot title * @param names vector of variable names * @param data N x M data array. * data(n,m) is the m^th value of the n^th variable. */ void outputTEC(std::ostream &s, const std::string &title, const std::vector<std::string>& names, const Array2D& data) { int i,j; int npts = static_cast<int>(data.nColumns()); int nv = static_cast<int>(data.nRows()); s << "TITLE = \"" + title + "\"" << endl; s << "VARIABLES = " << endl; for (i = 0; i < nv; i++) { s << "\"" << names[i] << "\"" << endl; } s << "ZONE T=\"zone1\"" << endl; s << " I=" << npts << ",J=1,K=1,F=POINT" << endl; s << "DT=( "; for (i = 0; i < nv; i++) s << " SINGLE"; s << " )" << endl; for (i = 0; i < npts; i++) { for (j = 0; j < nv; j++) { s << data(j,i) << " "; } s << endl; } }
void getMatrixValues(const XML_Node& node, const std::vector<std::string>& keyStringRow, const std::vector<std::string>& keyStringCol, Array2D& retnValues, const bool convert, const bool matrixSymmetric) { if (keyStringRow.size() > retnValues.nRows()) { throw CanteraError("getMatrixValues", "size of key1 greater than numrows"); } else if (keyStringCol.size() > retnValues.nColumns()) { throw CanteraError("getMatrixValues", "size of key2 greater than num cols"); } else if (matrixSymmetric && retnValues.nRows() != retnValues.nColumns()) { throw CanteraError("getMatrixValues", "nrow != ncol for a symmetric matrix"); } /* * Get the attributes field, units, from the XML node * and determine the conversion factor, funit. */ doublereal funit = 1.0; if (convert && node["units"] != "") { funit = toSI(node["units"]); } vector<string> v; getStringArray(node, v); for (size_t i = 0; i < v.size(); i++) { size_t icolon = v[i].find(":"); if (icolon == string::npos) { throw CanteraError("getMatrixValues","Missing two colons (" +v[i]+")"); } string key1 = v[i].substr(0,icolon); string rmm = v[i].substr(icolon+1, v[i].size()); icolon = rmm.find(":"); if (icolon == string::npos) { throw CanteraError("getMatrixValues","Missing one colon (" +v[i]+")"); } size_t irow = find(keyStringRow.begin(), keyStringRow.end(), key1) - keyStringRow.begin(); if (irow == keyStringRow.size()) { throw CanteraError("getMatrixValues","Row not matched by string: " + key1); } string key2 = rmm.substr(0,icolon); size_t icol = find(keyStringCol.begin(), keyStringCol.end(), key2) - keyStringCol.begin(); if (icol == keyStringCol.size()) { throw CanteraError("getMatrixValues","Col not matched by string: " + key2); } double dval = fpValueCheck(rmm.substr(icolon+1, rmm.size())) * funit; /* * Finally, insert the value; */ retnValues(irow, icol) = dval; if (matrixSymmetric) { retnValues(icol, irow) = dval; } } }