int main() { enString mystr("Gigel"); std::cout << mystr << '\n'; std::printf("%s\n", mystr); }
fstring FixFuxedUpColladaPaths( fstring uri ) { fstring _uri = uri; _uri.replace(FC('\\'), FC('/')); //////////////////////////////////////////////// fstring mystr( _uri.c_str() ); fstring srchstr("file:///"); size_t ipos= mystr.find(srchstr); if( ipos != fstring::npos ) { mystr.erase(7, 8 ); _uri = fstring(mystr.c_str()); } mystr = fstring( _uri.c_str() ); if( mystr.length() > 3 ) { char ch0 = mystr.c_str()[0]; char ch1 = mystr.c_str()[1]; char ch2 = mystr.c_str()[2]; if( ch0 == '/' && isalpha(ch1) && isalpha(ch2) ) { mystr = mystr.substr( 1, mystr.length()-1 ); _uri = fstring(mystr.c_str()); } } //////////////////////////////////////////////// return _uri; }
char *ft_itoa(int n) { char *chaine; int count; int myn; int negativ; negativ = 0; count = 0; myn = n; if (n == 0 || n == -2147483648) return (myreturn(n)); if (n < 0) { negativ = 1; n = -n; count++; myn = n; } count = ft_count(n, count); chaine = (char *)malloc(sizeof(char) * (count + 1)); if (chaine == NULL) return (NULL); mystr(chaine, negativ, count, myn); chaine[count] = '\0'; return (chaine); }
TMathFuncType MathFunction::StringToMathFuncType(const mystr& funcname) { for (int i=0; i < MathFuncStringListLength; i++) { if (mystr(MathFuncStringList[i]) == funcname) { return (TMathFuncType)i; } } return TMFempty; }
int Mass1D::CheckConsistency(mystr& errorstr) //rv==0 --> OK, rv==1 --> can not compute, rv==2 --> can not draw and not compute { int rv = Element::CheckConsistency(errorstr); if (rv) return rv; if(!mass) { rv = 1; errorstr = mystr("No mass is defined for the Mass1D!\n"); } return rv; }
mystr Sensitivity::GetHeaderString() const //returns header for output file { mystr str("%HOTINT_Sensitivity_Analysis_Solution_File\n"); if(mbs->GetModelFunctionsIndex0()!=-1) { str = str + "%" + mbs->GetModelsLibrary()->GetModelInterface(mbs->GetModelFunctionsIndex0())->GetMBSModelName() + "\n"; } time_t t; time(&t); struct tm *ts; ts = localtime(&t); // get current date and time str = str + "%" + asctime(ts); str = str + "%Comment: " + mbs->GetSolSet().sol_file_header_comment + "\n"; str = str + "%Compute sensitivity of sensor values with respect to parameters\n"; mystr colnumbers, colnames; // sensors str = str + "%Sensors: (rows of sensitivity matrix)\n"; colnames = "%"; colnumbers = "%"; for(int i=1; i<=sensor_names.Length();i++) { colnames = colnames + *sensor_names(i) + mystr(" "); colnumbers = colnumbers + mystr(i); for(int j=colnumbers.Length(); j<colnames.Length(); j++) { colnumbers = colnumbers + " "; } } str = str + colnumbers + mystr("\n"); str = str + colnames + mystr("\n"); // parameters str = str + "%Parameters: (columns of sensitivity matrix)\n"; colnumbers = "%"; colnames = "%"; for(int i=1; i<=param_names.Length();i++) { colnames = colnames + *param_names(i) + mystr(" "); colnumbers = colnumbers + mystr(i); for(int j=colnumbers.Length(); j<colnames.Length(); j++) { colnumbers = colnumbers + " "; } } str = str + colnumbers + mystr("\n"); str = str + colnames + mystr("\n"); return str; }
void MRouter::addDownNode(MemObj *dpm) /* add down node {{{1 */ { down_node.push_back(dpm); #if GOOGLE_GRAPH_API //Generating memory_arch.html. std::string mystr("[{v:'"); mystr += self_mobj->getName(); mystr += "',f: '"; mystr += self_mobj->getName(); mystr += "<div style=\"font-size:9; color:red; font-style:italic\">"; mystr += self_mobj->getSection(); mystr += "</div>'}, '"; mystr += dpm->getName(); mystr += "', '"; mystr += self_mobj->getSection(); mystr += "']"; //MSG("xxx>%s",mystr.c_str()); arch.addObj(mystr); #else std::string mystr(""); mystr += "\""; mystr += self_mobj->getName(); mystr += "\""; //mystr += self_mobj->getSection(); //mystr += "\""; mystr += " -> "; mystr += "\""; mystr += dpm->getName(); mystr += "\""; arch.addObj(mystr); #endif //down_mobj = upm; }
bool OnInit() { char **my_argv = new char*[argc]; for (int i=0;i<argc;++i) { wxString mystr(argv[i]); my_argv[i] = new char[mystr.size()+1]; strcpy(my_argv[i], mystr.To8BitData()); } param *p = param::instance(); initialize_parameters(p); if(!p->parse(argc,my_argv)) return false; m_confg_visitor = new simulated_annealing::wx::configuration_visitor((wxFrame *)NULL, wxID_ANY, _("librjmcmc: rectangular building footprint extraction"), wxDefaultPosition, wxSize(600,600) ); m_confg_visitor->SetIcon(wxICON(IGN)); m_param_visitor = new simulated_annealing::wx::parameters_visitor(m_confg_visitor); m_chart_visitor = new simulated_annealing::wx::chart_visitor(m_confg_visitor); m_visitor = new visitor(&m_log_visitor,m_confg_visitor,m_param_visitor,m_chart_visitor); m_confg_visitor->controler(this); return true; }
int main() { char a[128] = "These"; char b[128] = "are"; char c[128] = "the"; char d[128] = "test"; char e[128] = "cases"; char f[128] = "car"; char g[128] = "aren"; char h[128] = "abcdefghijklmnopqrstuvwxyzzzzzzzzzzzz"; char i[128] = "cases"; char j[128] = "casesss"; char k[128] = "arent"; char l[128] = "longwords"; char m[128] = "neededlongwords"; char n[128] = "lastlongwordormaybenot"; char s[128]; char t[128]; char u[128]; char v[128]; char w[128]; char x[128]; char y[128]; char z[128]; printf("---mylen Testing---\n"); printf("Test One:\n These - - - Length: 5\n Run: %d\n", mylen(a)); printf("Test Two:\n are - - - Length: 3\n Run: %d\n", mylen(b)); printf("Test Three:\n abcdefghijklmnopqrstuvwxyz - - - Length: 26\n Run: %d\n", mylen(h)); printf("\n"); printf("---mycmp Testing---\n"); printf("Test One:\n Word 1: cases - Word 2: car\n Run: %d\n", mycmp(e, f)); printf("Test Two:\n Word 1: cases - Word 2: cases\n Run: %d\n", mycmp(e, i)); printf("Test Three:\n Word 1: are - Word 2: the\n Run: %d\n", mycmp(b, c)); printf("Test Four:\n Word 1: casesss - Word 2: cases\n Run: %d\n", mycmp(j, e)); printf("Test Five:\n Word 1: aren - Word 2: arent\n Run: %d\n", mycmp(g, k)); printf("\n"); printf("---mycpy Testing---\n"); printf("Before Copying:\n"); printf(" x: %s\n y: %s\n z: %s\n", x, y, z); printf("Copying:\n %s --> x\n %s --> y\n %s --> z\n", h, i, j); mycpy(x, h); mycpy(y, i); mycpy(z, j); printf("After Copying:\n"); printf(" x: %s\n y: %s\n z: %s\n", x, y, z); printf("\n"); printf("---mycpyn Testing---\n"); printf("Before Copying:\n"); printf(" s: %s\n t: %s\n u: %s\n", s, t, u); printf("Copying:\n %s - 6 --> s\n %s - 7 --> t\n %s - 10 --> u\n", l, m, n); mycpyn(s, l, 6); mycpyn(t, m, 7); mycpyn(u, n, 10); printf("After Copying:\n"); printf(" s: %s\n t: %s\n u: %s\n", s, t, u); printf("\n"); printf("---mycat Testing---\n"); printf("Before Catting:\n"); printf(" s: %s\n m: %s\n h: %s\n", s, m, h); printf("Catting:\n %s --> s\n %s --> m\n %s --> h\n", h, c, d); mycat(s, h); mycat(m, c); mycat(h, d); printf("After Catting:\n"); printf(" s: %s\n m: %s\n h: %s\n", s, m, h); printf("\n"); printf("---mycatn Testing---\n"); printf("Before Catting:\n"); printf(" s: %s\n m: %s\n h: %s\n", s, m, h); printf("Catting:\n %s - 8 --> s\n %s - 3 --> m\n %s - 2 --> h\n", h, c, d); mycatn(s, h, 8); mycatn(m, c, 3); mycatn(h, d, 2); printf("After Catting:\n"); printf(" s: %s\n m: %s\n h: %s\n", s, m, h); printf("\n"); printf("---mychr Testing---\n"); printf("Test One:\n Searching in: %s\n Searching for: %c\n", e, 'e'); printf(" Pointer: %p - Points at: %c\n", mychr(e,'e'), *mychr(e,'e')); printf("Test Two:\n Searching in: %s\n Searching for: %c\n", h, 't'); printf(" Pointer: %p - Points at: %c\n", mychr(h,'t'), *mychr(h,'t')); printf("\n"); printf("---mystr Testing---\n"); printf("Test One:\n Searching in: %s\n Searching for: %s\n", n, "long"); printf(" Pointer: %p - Points at: %s\n", mystr(n,"long"), *mystr(n,"long")); return 0; }
/************************************************************************************************** * inicia o pserve para receber as imagens e plota na ui **************************************************************************************************/ void MainWindow::start_pserve() { contagem=0; pixeis_lidos=0; QProcess *myProcess = new QProcess; QStringList arguments_pserve; process_pserve = Current_Path+"/pserve"; arguments_pserve<<Count_L<<NImage<<Save_Path; myProcess->setProcessChannelMode(QProcess::MergedChannels); myProcess->start(process_pserve,arguments_pserve); myProcess->waitForStarted(); QPixmap pixmap; float contagem_anterior; /************************************************************************************************** * le uma imagem **************************************************************************************************/ if(NImage.toInt()==1) { if(Count_L.toInt()==0) // 1 bit { contagem=0; pixeis_lidos=0; myProcess->waitForFinished((Time.toFloat()*1000)+100); QImage image(256,256,QImage::Format_Indexed8); if(image.load(Save_Path+"1.ppm","pbm")==true) { image.invertPixels(); for(int a=0;a<=255;a++) { for(int b=0;b<=255;b++) { contagem=contagem+(1-image.pixelIndex(b,a)); pixeis_lidos=contagem; } } } else { image.fill(Qt::black); ui->textBrowser->append("Error Reading Image!!!"); } pixmap = QPixmap::fromImage(image,Qt::ColorOnly); } else if(Count_L.toInt()==1) // 12 bits { contagem=0; pixeis_lidos=0; myProcess->waitForFinished((Time.toFloat()*1000)+1000); QImage image(256,256,QImage::Format_RGB16); QByteArray teste; QFile filestr(Save_Path+"1.ppm"); if(filestr.open(QIODevice::ReadOnly)==true) { teste=filestr.readAll(); QString colorstr(teste); QStringList colors = colorstr.split(QRegExp("\\s+")); colors.removeLast(); colors.removeFirst(); colors.removeFirst(); colors.removeFirst(); colors.removeFirst(); QVector<QRgb> colortable; Lookup_Tables ctable; colortable=ctable.colorPalete1280(); image.setColorTable(colortable); int cont=0; for(int a=0;a<=255;a++) { for(int b=0;b<=255;b++) { if(qCeil(colors.at(cont).toInt()/3.2)>=1280) { image.setPixel(b,a, image.colorTable().at(1279)); } else { image.setPixel(b,a, image.colorTable().at(qCeil(colors.at(cont).toUInt()/3.2))); } contagem_anterior=contagem; contagem=contagem+colors.at(cont).toFloat(); cont++; if(contagem_anterior!=contagem) { pixeis_lidos++; } } } } else { image.fill(Qt::black); ui->textBrowser->append("Error Reading Image!!!"); } pixmap = QPixmap::fromImage(image,Qt::ColorOnly); } else if(Count_L.toInt()==2) // 6 bits { contagem=0; pixeis_lidos=0; myProcess->waitForFinished((Time.toFloat()*1000)+500); QImage image(256,256,QImage::Format_Indexed8); if(image.load(Save_Path+"1.ppm","pbm")==true) { QVector<QRgb> colortable; Lookup_Tables ctable; colortable=ctable.colorPalete64(); image.setColorTable(colortable); } else { image.fill(Qt::black); ui->textBrowser->append("Error Reading Image!!!"); } pixmap = QPixmap::fromImage(image,Qt::ColorOnly); for(int a=0;a<=255;a++) { for(int b=0;b<=255;b++) { contagem_anterior=contagem; contagem=contagem+image.pixelIndex(b,a); if(contagem_anterior!=contagem) { pixeis_lidos++; } } } } else if(Count_L.toInt()==3) // 24 bits { contagem=0; pixeis_lidos=0; myProcess->waitForFinished((Time.toFloat()*1000)+1500); QImage image(256,256,QImage::Format_RGB32); QByteArray teste; QFile filestr(Save_Path+"1.ppm"); if(filestr.open(QIODevice::ReadOnly)==true) { teste=filestr.readAll(); QString colorstr(teste); QStringList colors = colorstr.split(QRegExp("\\s+")); colors.removeLast(); colors.removeFirst(); colors.removeFirst(); colors.removeFirst(); colors.removeFirst(); QVector<QRgb> colortable; Lookup_Tables ctable; colortable=ctable.colorPalete1280(); image.setColorTable(colortable); int cont=0; for(int a=0;a<=255;a++) { for(int b=0;b<=255;b++) { if(qCeil(colors.at(cont).toInt()/100)>=1536) { image.setPixel(b,a, image.colorTable().at(1535)); } else { image.setPixel(b,a, image.colorTable().at(qCeil(colors.at(cont).toUInt()/100))); } contagem_anterior=contagem; contagem=contagem+colors.at(cont).toFloat(); cont++; if(contagem_anterior!=contagem) { pixeis_lidos++; } } } } else { image.fill(Qt::black); ui->textBrowser->append("Error Reading Image!!!"); } pixmap = QPixmap::fromImage(image,Qt::ColorOnly); } pixmap=pixmap.scaled(512,512); scene= new QGraphicsScene(this); scene->addPixmap(pixmap); ui->Plot_Window->setScene(scene); QByteArray text_response=myProcess->readAll(); QString mystr(text_response); ui->textBrowser->setText(mystr); ui->textBrowser->append("Total Count = "+QString::number(contagem)); ui->textBrowser->append("Pixel Read = "+QString::number(pixeis_lidos)); } /************************************************************************************************** * le +1 imagem **************************************************************************************************/ else { Save_Dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); Save_Dir.setSorting(QDir::Time); QString lee(Image_Name); int cont =0; lee.append(QString::number(cont)); for(int a=0;a<=(NImage.toInt()-1);a++) { if(Count_L.toInt()==0) // 1 bit { if(a==(NImage.toInt()-1)) { myProcess->waitForFinished(NImage.toInt()*((Gap.toInt()*1000)+(Time.toFloat()*1000)+300)); } else if(a==0) { QThread::msleep((Time.toFloat()*1000)+300); } else { QThread::msleep((Gap.toInt()*1000)+(Time.toFloat()*1000)+300); } cont++; lee.replace(lee.size()-1,1,QString::number(cont)); QImage image(256,256,QImage::Format_Indexed8); image.load(Save_Dir.absolutePath()+"/"+lee+".ppm","pbm"); image.invertPixels(); pixmap = QPixmap::fromImage(image,Qt::ColorOnly); pixmap=pixmap.scaled(512,512); scene= new QGraphicsScene(this); scene->addPixmap(pixmap); scene->update(); ui->Plot_Window->setScene(scene); ui->Plot_Window->update(); QByteArray text_response=myProcess->readAll(); QString mystr(text_response); ui->textBrowser->setText(mystr); ui->textBrowser->update(); QCoreApplication::processEvents(QEventLoop::AllEvents); } else if(Count_L.toInt()==1) // 12 bits { if(a==(NImage.toInt()-1)) { myProcess->waitForFinished(NImage.toInt()*((Gap.toInt()*1000)+(Time.toFloat()*1000)+1000)); } else if(a==0) { QThread::msleep((Time.toFloat()*1000)+1000); } else { QThread::msleep((Gap.toInt()*1000)+(Time.toFloat()*1000)+1000); } QByteArray text_response=myProcess->readAll(); QString mystr(text_response); ui->textBrowser->setText(mystr); cont++; lee.replace(lee.size()-1,1,QString::number(cont)); QImage image(256,256,QImage::Format_RGB16); QByteArray teste; QFile filestr(Save_Dir.absolutePath()+"/"+lee+".ppm"); filestr.open(QIODevice::ReadOnly); teste=filestr.readAll(); QString colorstr(teste); QStringList colors = colorstr.split(QRegExp("\\s+")); colors.removeLast(); colors.removeFirst(); colors.removeFirst(); colors.removeFirst(); colors.removeFirst(); QVector<QRgb> colortable; Lookup_Tables ctable; colortable=ctable.colorPalete1280(); image.setColorTable(colortable); int cont=0; for(int a=0;a<=255;a++) { for(int b=0;b<=255;b++) { if(qCeil(colors.at(cont).toInt()/3.2)>=1280) { image.setPixel(b,a, image.colorTable().at(1279)); } else { image.setPixel(b,a, image.colorTable().at(qCeil(colors.at(cont).toUInt()/3.2))); } cont++; } } pixmap = QPixmap::fromImage(image,Qt::ColorOnly); pixmap=pixmap.scaled(512,512); scene= new QGraphicsScene(this); scene->addPixmap(pixmap); scene->update(); ui->Plot_Window->setScene(scene); ui->Plot_Window->update(); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } else if(Count_L.toInt()==2) // 6 bits { if(a==(NImage.toInt()-1)) { myProcess->waitForFinished(NImage.toInt()*((Gap.toInt()*1000)+(Time.toFloat()*1000)+500)); } else if(a==0) { QThread::msleep((Time.toFloat()*1000)+500); } else { QThread::msleep((Gap.toInt()*1000)+(Time.toFloat()*1000)+500); } QByteArray text_response=myProcess->readAll(); QString mystr(text_response); ui->textBrowser->setText(mystr); cont++; //QFileInfoList list = Save_Dir.entryInfoList(); //QFileInfo fileinfo = list.at(0); //image1 = fileinfo.fileName(); lee.replace(lee.size()-1,1,QString::number(cont)); //qDebug()<<Save_Dir.absolutePath()+"/"+lee+".ppm"; QImage image(256,256,QImage::Format_Indexed8); image.load(Save_Dir.absolutePath()+"/"+lee+".ppm","pgm"); QVector<QRgb> colortable; Lookup_Tables ctable; colortable=ctable.colorPalete64(); image.setColorTable(colortable); pixmap=pixmap.scaled(512,512); pixmap = QPixmap::fromImage(image,Qt::ColorOnly); scene= new QGraphicsScene(this); scene->addPixmap(pixmap); scene->update(); ui->Plot_Window->setScene(scene); ui->Plot_Window->update(); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } else if(Count_L.toInt()==3) // 24 bits { if(a==(NImage.toInt()-1)) { myProcess->waitForFinished(NImage.toInt()*((Gap.toInt()*1000)+(Time.toFloat()*1000)+1500)); } else if(a==0) { QThread::msleep((Time.toFloat()*1000)+1500); } else { QThread::msleep((NImage.toInt()*1000)+(Time.toFloat()*1000)+1500); } QByteArray text_response=myProcess->readAll(); QString mystr(text_response); ui->textBrowser->setText(mystr); cont++; lee.replace(lee.size()-1,1,QString::number(cont)); QImage image(256,256,QImage::Format_RGB32); QByteArray teste; QFile filestr(Save_Dir.absolutePath()+"/"+lee+".ppm"); filestr.open(QIODevice::ReadOnly); teste=filestr.readAll(); QString colorstr(teste); QStringList colors = colorstr.split(QRegExp("\\s+")); colors.removeLast(); colors.removeFirst(); colors.removeFirst(); colors.removeFirst(); colors.removeFirst(); QVector<QRgb> colortable; Lookup_Tables ctable; colortable=ctable.colorPalete1280(); image.setColorTable(colortable); int cont=0; for(int a=0;a<=255;a++) { for(int b=0;b<=255;b++) { if(qCeil(colors.at(cont).toInt()/100)>=1536) { image.setPixel(b,a, image.colorTable().at(1535)); } else { image.setPixel(b,a, image.colorTable().at(qCeil(colors.at(cont).toUInt()/100))); } cont++; } } pixmap = QPixmap::fromImage(image,Qt::ColorOnly); pixmap=pixmap.scaled(512,512); scene= new QGraphicsScene(this); scene->addPixmap(pixmap); scene->update(); ui->Plot_Window->setScene(scene); ui->Plot_Window->update(); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } } } }
void Sensitivity::Init() { mbs->OpenFiles(0); //open files already here, do not append ElementDataContainer* edc = mbs->GetMBS_EDC_Options(); mystr method = edc->TreeGetString("SolverOptions.Sensitivity.method"); // choose type of analysis if(method.Compare(mystr("Forward"))) { type_diff = 1; // 1 ... df/dx =~ (f(x+dx)-f(x))/dx forward differentiation } else if(method.Compare(mystr("Backward"))) { type_diff = -1; // -1 ... df/dx =~ (f(x)-f(x-dx))/dx backward differentiation } else { type_diff = 0; // 0 ... df/dx =~ (f(x+dx/2)-f(x-dx/2))/dx central differentiation } // get parameter names if(edc->TreeGetInt("SolverOptions.Sensitivity.use_optimization_parameters")) { number_of_params = edc->TreeGetInt("SolverOptions.Optimization.Parameters.number_of_params"); for (int col=1; col <= number_of_params; col++) { mystr str = edc->TreeGetString(mystr("SolverOptions.Optimization.Parameters.param_name")+mystr(col)); param_names(col) = new mystr(str); } } else { number_of_params = edc->TreeGetInt("SolverOptions.Sensitivity.Parameters.number_of_params"); for (int col=1; col <= number_of_params; col++) { mystr str = edc->TreeGetString(mystr("SolverOptions.Sensitivity.Parameters.param_name")+mystr(col)); param_names(col) = new mystr(str); } } abs_diff_val = edc->TreeGetDouble("SolverOptions.Sensitivity.num_diff_parameter_absolute"); rel_diff_val = edc->TreeGetDouble("SolverOptions.Sensitivity.num_diff_parameter_relative"); NCompSensors = 0; // sensor with computation value (case use_final_sensor_values == 0) for(int i = 1; i<=mbs->NSensors();i++) { mystr str = ""; if(mbs->GetMBS_EDC_Options()->TreeGetInt("SolverOptions.Sensitivity.use_final_sensor_values",0)) { str = mbs->GetSensor(i).GetSensorName(); sensor_names(i) = new mystr(str); // store names for header } else { if(mbs->GetSensor(i).HasSensorProcessingEvaluationData()) { str = mbs->GetSensor(i).GetSensorName(); NCompSensors++; sensor_names(NCompSensors) = new mystr(str); // store names for header } } } mbs->SolParFile() << GetHeaderString(); // write header into output file (use sensor_names and parameter_names) }
// main part of Sensitivity int Sensitivity::PerformSensitivityAnalysis() { Init(); // initialize variables // fill vector x with model parameters Vector x = 1.0 * GetModelParameters(); // dx=K*x + D //Vector factors(1.0, 2.0, 3.0, 4.0, 5.0, 6.0); //test of parameter sensitivity w.r.t. other parameter set: //Vector factors(1.0); // sensitivity w.r.t. nominal parameters int indexf_max = 0; // number of sensors of sensitivity analysis //test[for(int nFactor = 1; nFactor <= factors.Length(); nFactor++) //{ //test] x = factors(nFactor) * x; // multiply nominal parameters with factor (for sensitivity analysis with modified parameter set - useful, if nominal parameters "x" are in (local) minima) dx = rel_diff_val * x + abs_diff_val * Vector(number_of_params, 0, 1); // do sensitivity computation //testmbs->SolParFile() << "\n%Evaluate sensitivity for nominal parameters multiplied with factor " << factors(nFactor) << "\n"; for(int jPar = 1; jPar <= number_of_params; jPar++) { //++++++++++++++++++++++++++++++++++++ //b: difference quotient variables // dfi/dxj =~ (fi(x2j)-fi(x1j))/dxj double dxj = dx(jPar); Vector x1j = x; Vector x2j = x; if(type_diff == 1) // 1 ... df/dx =~ (f(x+dx)-f(x))/dx, forward differentiation { //f2j = f(x+dx), f1j = f(x) x2j(jPar) += dxj; x1j(jPar) += 0.; } else if(type_diff == -1) // -1 ... df/dx =~ (f(x)-f(x-dx))/dx backward differentiation { //f2j = f(x), f1j = f(x-dx) x2j(jPar) += 0.; x1j(jPar) -= dxj; } else //type_diff == 0 ... df/dx =~ (f(x+dx/2)-f(x-dx/2))/dx, central differentiation { //f2j = f(x+dx/2), f1j = f(x-dx/2) x2j(jPar) += 0.5 * dxj; x1j(jPar) -= 0.5 * dxj; } //e: difference quotient variables //++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++ //b: compute f2j SetParameters(&x2j); mbs->CloseFiles(); //because it is opened in following function //***** //repeatedly call computation: mbs->UO(UO_LVL_multsim) << mystr("\n****************************"); mbs->UO(UO_LVL_multsim) << mystr("\nStart Simulation f(x2): \n\n"); mbs->RepeatedlyPerformComputation(1); //do not write into solpar file mbs->OpenFiles(1); //append //***** Vector f2i; GetFunctionValues(f2i); // get function values from sensors //e: compute f2i //++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++ //b: compute f1i SetParameters(&x1j); mbs->CloseFiles(); //because it is opened in following function //***** //repeatedly call computation: mbs->UO(UO_LVL_multsim) << mystr("\nStart Simulation f(x1): \n\n"); mbs->RepeatedlyPerformComputation(1); //do not write into solpar file mbs->OpenFiles(1); //append //***** Vector f1i; GetFunctionValues(f1i); // get function values from sensors assert(f2i.Length() == f1i.Length()); //e: compute f2j //++++++++++++++++++++++++++++++++++++ if(dxj == 0.) { mbs->UO(UO_LVL_warn) << "Warning: dx" << jPar << " is zero. Check, Sensitivity.num_diff_parameter_absolute and Sensitivity.num_diff_parameter_relative.\n"; dxj = 1.; } if(f1i.Length() == 0) { mbs->UO(UO_LVL_err).InstantMessageText("error: no matching sensitivity values from sensor found. Sensitivity analysis stopped.\n"); return 1; // error } if (mbs->StopCalculation()) break; indexf_max = f2i.Length(); // length of vectors f2i and f1i if(jPar == 1)//test && nFactor == 1) { //test S.SetSize(indexf_max, number_of_params*factors.Length()); // initialize size S.SetSize(indexf_max, number_of_params); // initialize size S.SetAll(0.); //test Smax.SetSize(indexf_max, number_of_params); // initialize size //test Smax.SetAll(0.); } int indexf = 1; // index of vectors f2i and f1i for(int i = 1; i <= mbs->NSensors(); i++) { if(mbs->GetMBS_EDC_Options()->TreeGetInt("SolverOptions.Sensitivity.use_final_sensor_values",0) || mbs->GetSensor(i).HasSensorProcessingEvaluationData()) { // compute sensitivity matrix df_i/dparameter_j double sensitivity = fabs((f2i(indexf) - f1i(indexf))/dxj); S(indexf, jPar) = sensitivity; //case: only one analysis --> Smax, nFactor, factors can be deleted in this case (Smax --> S)!! /*test[ S(indexf, jPar + (nFactor-1)*number_of_params) = sensitivity; // multiple sensitivity analysis possible (for tests) if(Smax(indexf, jPar) < sensitivity) { mbs->UO(UO_LVL_0) << "Smax(" << indexf << ", " << jPar << ") = " << sensitivity << "\n"; Smax(indexf, jPar) = sensitivity; } test]*/ mbs->UO(UO_LVL_0) << "sensor: " + mbs->GetSensor(i).GetSensorName() + mystr("\nparameter :") + (*param_names(jPar)) + mystr("\nsensitivity: (") + mystr(f2i(indexf)) + mystr("-") + mystr(f1i(indexf)) + mystr(")/") + mystr(dxj) + mystr("=") + mystr(sensitivity) + mystr("\n"); mbs->UO(UO_LVL_0) << "\nS = df" << indexf << "/dp" << jPar << " = (" << mystr(f2i(indexf)) + mystr("-") + mystr(f1i(indexf)) + mystr(")/") + mystr(dxj) + mystr("=") << sensitivity << "\n\n"; //old: --> output is transposed!!! mbs->SolParFile() << mystr(mystr("d_sens") + mystr(indexf) + mystr("/d_par") + mystr(jPar) + mystr("=") + mystr(sensitivity) + mystr("\t")); indexf++; } } if (mbs->StopCalculation()) break; } // end for mbs->SolParFile() << "%Sensitivity matrix: d_sensorValue(row)/d_parameter(column)\n"; mbs->UO(UO_LVL_0) << "%Sensitivity matrix: d_sensorValue(row)/d_parameter(column):\n"; if(S.GetMatPtr()) { for(int row = 1; row <= sensor_names.Length(); row++) { for(int col = 1; col <= param_names.Length(); col++) { mbs->UO(UO_LVL_0) << S(row, col) << "\t"; mbs->SolParFile() << S(row, col) << "\t"; } mbs->SolParFile() << "\n"; mbs->UO(UO_LVL_0) << "\n"; } } //old:[ if(factors.Length() > 1) //{ // mbs->SolParFile() << "\n%==========================\n"; // mbs->SolParFile() << "%maximal sensitivity values: \n"; // for(int jPar = 1; jPar <= number_of_params; jPar++) // { // for(int indexf = 1; indexf <= indexf_max; indexf++) // { // mbs->SolParFile() << mystr(mystr("d_sens") + mystr(indexf) + mystr("/d_par") + mystr(jPar) + mystr("=") + mystr(Smax(indexf, jPar)) + mystr("\t")); // } // mbs->SolParFile() << "\n"; // } //} //mbs->SolParFile() << "%==========================\n"; //old:] mbs->SolParFile() << flush; mbs->Get_pCFB()->FinishedComputation(); return 0; }
mystr FieldVariableDescriptor::GetTextualIdentifier() const { return mystr(GetTextualIdentifierWithoutComponents()) + mystr(componentsDelimiter) + GetTextualIdentifierComponentsOnly(); }
MemObj *MemorySystem::buildMemoryObj(const char *device_type, const char *dev_section, const char *dev_name) /* build the correct memory object {{{1 */ { // Returns new created MemoryObj or NULL in known-error mode MemObj *mdev=0; uint32_t devtype = 0; //CCache std::string mystr(""); // You may insert here the further specializations you may need if (!strcasecmp(device_type, "cache") || !strcasecmp(device_type, "icache")) { mdev = new CCache(this, dev_section, dev_name); devtype = 0; } else if (!strcasecmp(device_type, "nicecache")) { mdev = new NICECache(this, dev_section, dev_name); devtype = 1; } else if (!strcasecmp(device_type, "SL0")) { //mdev = new SL0Cache(this, dev_section, dev_name); I(0); devtype = 2; } else if (!strcasecmp(device_type, "VPC")) { //mdev = new VPC(this, dev_section, dev_name); I(0); devtype = 3; } else if (!strcasecmp(device_type, "ghb")) { //mdev = new GHB(this, dev_section, dev_name); I(0); devtype = 4; } else if (!strcasecmp(device_type, "stridePrefetcher")) { mdev = new StridePrefetcher(this, dev_section, dev_name); devtype = 5; } else if (!strcasecmp(device_type, "markovPrefetcher")) { mdev = new MarkovPrefetcher(this, dev_section, dev_name); devtype = 6; /* } else if (!strcasecmp(device_type, "taggedPrefetcher")) { mdev = new TaggedPrefetcher(this, dev_section, dev_name); devtype = 7; */ } else if (!strcasecmp(device_type, "bus")) { mdev = new Bus(this, dev_section, dev_name); devtype = 8; } else if (!strcasecmp(device_type, "tlb")) { mdev = new TLB(this, dev_section, dev_name); devtype = 9; } else if (!strcasecmp(device_type, "splitter")) { //mdev = new Splitter(this, dev_section, dev_name); I(0); devtype = 10; } else if (!strcasecmp(device_type, "memxbar")) { mdev = new MemXBar(this, dev_section, dev_name); devtype = 11; } else if (!strcasecmp(device_type, "unmemxbar")) { mdev = new UnMemXBar(this, dev_section, dev_name); devtype = 12; } else if (!strcasecmp(device_type, "memcontroller")) { mdev = new MemController(this, dev_section, dev_name); devtype = 13; } else if (!strcasecmp(device_type, "void")) { return NULL; } else { // Check the lower level because it may have it return GMemorySystem::buildMemoryObj(device_type, dev_section, dev_name); } #if GOOGLE_GRAPH_API #else mystr += "\n\""; mystr += mdev->getName(); switch(devtype){ case 0: //CCache case 1: //NiceCache case 2: //SL0 case 3: //VPC mystr += "\"[shape=record,sides=5,peripheries=2,color=darkseagreen,style=filled]"; //Fetch the CCache related parameters : Size, bsize, name, inclusive, ports break; case 4: //GHB case 5: //stridePrefetcher case 6: //markovPrefetcher case 7: //taggedPrefetcher mystr += "\"[shape=record,sides=5,peripheries=1,color=lightcoral,style=filled]"; break; case 8://bus mystr += "\"[shape=record,sides=5,peripheries=1,color=lightpink,style=filled]"; break; case 10: //Splitter case 11: //MemXBar mystr += "\"[shape=record,sides=5,peripheries=1,color=thistle,style=filled]"; break; case 12: //memcontroller mystr += "\"[shape=record,sides=5,peripheries=1,color=skyblue,style=filled]"; break; default: mystr += "\"[shape=record,sides=5,peripheries=3,color=white,style=filled]"; break; } arch.addObj(mystr); #endif I(mdev); addMemObjName(mdev->getName()); #ifdef DEBUG LOG("Added: %s", mdev->getName()); #endif return mdev; }