/** * returns the spherical Bessel function of the second kind * needed for continuum states \param l = order of the function (orbital angular momentum) \param rho = independent variable (rho = k * r) */ double sphericalB::y(int l, double rho) { switch (l) { case 0: return y0(rho); case 1: return y1(rho); case 2: return y2(rho); case 3: return y3(rho); case 4: return y4(rho); case 5: return y5(rho); case 6: return y6(rho); case 7: return y7(rho); default: cout << "no l>6 programed in sphericalB" << endl; return 0.; } }
int runOperatorTests(Epetra_Operator & A, bool verbose) { int ierr = 0; double residual; EPETRA_CHK_ERR(EpetraExt::OperatorToMatrixMarketFile("Test_A1.mm", A, "Official EpetraExt test operator", "This is the official EpetraExt test operator generated by the EpetraExt regression tests")); EPETRA_CHK_ERR(EpetraExt::OperatorToMatlabFile("Test_A1.dat", A)); A.OperatorRangeMap().Comm().Barrier(); A.OperatorRangeMap().Comm().Barrier(); Epetra_CrsMatrix * A1; Epetra_CrsMatrix * A2; EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToCrsMatrix("Test_A1.mm", A.OperatorRangeMap(), A1)); EPETRA_CHK_ERR(EpetraExt::MatlabFileToCrsMatrix("Test_A1.dat", A.OperatorRangeMap().Comm(), A2)); residual = A.NormInf(); double rAInf = residual; if (verbose) std::cout << "Inf Norm of Operator A = " << residual << std::endl; residual = A1->NormInf(); double rA1Inf = residual; if (verbose) std::cout << "Inf Norm of Matrix A1 = " << residual << std::endl; ierr += checkValues(rA1Inf,rAInf,"Inf Norm of A", verbose); Epetra_Vector x(A.OperatorDomainMap()); x.Random(); Epetra_Vector y1(A.OperatorRangeMap()); Epetra_Vector y2(A.OperatorRangeMap()); Epetra_Vector y3(A.OperatorRangeMap()); A.Apply(x,y1); A1->Multiply(false, x, y2); A2->Multiply(false, x, y3); y1.Norm2(&residual); double rAx1 = residual; if (verbose) std::cout << "Norm of A*x = " << residual << std::endl; y2.Norm2(&residual); double rAx2 = residual; if (verbose) std::cout << "Norm of A1*x = " << residual << std::endl; ierr += checkValues(rAx1,rAx2,"Norm of A1*x", verbose); y3.Norm2(&residual); double rAx3 = residual; if (verbose) std::cout << "Norm of A2*x = " << residual << std::endl; ierr += checkValues(rAx1,rAx3,"Norm of A2*x", verbose); delete A1; delete A2; return(ierr); }
extern "C" SEXP mypnorm(SEXP xx) { Rcpp::NumericVector x(xx); int n = x.size(); Rcpp::NumericVector y1(n), y2(n), y3(n); for (int i=0; i<n; i++) { y1[i] = ::Rf_pnorm5(x[i], 0.0, 1.0, 1, 0); y2[i] = R::pnorm(x[i], 0.0, 1.0, 1, 0); } y3 = Rcpp::pnorm(x); return Rcpp::DataFrame::create(Rcpp::Named("Rf_") = y1, Rcpp::Named("R") = y2, Rcpp::Named("sugar") = y3); }
void fwd_test() { test::test_type1<int> x1(3); test::test_type1<std::string> y1("Black"); test::test_type2<int> x2(25, 16); test::test_type2<std::string> y2("White", "Green"); std::vector<int> empty; std::vector<std::string> empty2; test::test_type3<int> x3(empty.begin(), empty.end()); test::test_type3<std::string> y3(empty2.begin(), empty2.end()); // Prevent gcc warnings: unused(x1); unused(x2); unused(x3); unused(y1); unused(y2); unused(y3); }
void MathPlot::setupMultiAxisDemo(QCustomPlot *customPlot) { customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // period as decimal separator and comma as thousand separator customPlot->legend->setVisible(true); QFont legendFont = font(); // start out with MainWindow's font.. legendFont.setPointSize(9); // and make a bit smaller for legend customPlot->legend->setFont(legendFont); customPlot->legend->setBrush(QBrush(QColor(255,255,255,230))); // by default, the legend is in the inset layout of the main axis rect. So this is how we access it to change legend placement: customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignBottom|Qt::AlignRight); // setup for graph 0: key axis left, value axis bottom // will contain left maxwell-like function customPlot->addGraph(customPlot->yAxis, customPlot->xAxis); customPlot->graph(0)->setPen(QPen(QColor(255, 100, 0))); customPlot->graph(0)->setBrush(QBrush(QPixmap("://skin/images/balboa.jpg"))); // fill with texture of specified image customPlot->graph(0)->setLineStyle(QCPGraph::lsLine); customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5)); customPlot->graph(0)->setName("Left maxwell function"); // setup for graph 1: key axis bottom, value axis left (those are the default axes) // will contain bottom maxwell-like function customPlot->addGraph(); customPlot->graph(1)->setPen(QPen(Qt::red)); customPlot->graph(1)->setBrush(QBrush(QPixmap("://skin/images/balboa.jpg"))); // same fill as we used for graph 0 customPlot->graph(1)->setLineStyle(QCPGraph::lsStepCenter); customPlot->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::white, 7)); customPlot->graph(1)->setErrorType(QCPGraph::etValue); customPlot->graph(1)->setName("Bottom maxwell function"); // setup for graph 2: key axis top, value axis right // will contain high frequency sine with low frequency beating: customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis2); customPlot->graph(2)->setPen(QPen(Qt::blue)); customPlot->graph(2)->setName("High frequency sine"); // setup for graph 3: same axes as graph 2 // will contain low frequency beating envelope of graph 2 customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis2); QPen blueDotPen; blueDotPen.setColor(QColor(30, 40, 255, 150)); blueDotPen.setStyle(Qt::DotLine); blueDotPen.setWidthF(4); customPlot->graph(3)->setPen(blueDotPen); customPlot->graph(3)->setName("Sine envelope"); // setup for graph 4: key axis right, value axis top // will contain parabolically distributed data points with some random perturbance customPlot->addGraph(customPlot->yAxis2, customPlot->xAxis2); customPlot->graph(4)->setPen(QColor(50, 50, 50, 255)); customPlot->graph(4)->setLineStyle(QCPGraph::lsNone); customPlot->graph(4)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 4)); customPlot->graph(4)->setName("Some random data around\na quadratic function"); // generate data, just playing with numbers, not much to learn here: QVector<double> x0(25), y0(25); QVector<double> x1(15), y1(15), y1err(15); QVector<double> x2(250), y2(250); QVector<double> x3(250), y3(250); QVector<double> x4(250), y4(250); for (int i=0; i<25; ++i) // data for graph 0 { x0[i] = 3*i/25.0; y0[i] = exp(-x0[i]*x0[i]*0.8)*(x0[i]*x0[i]+x0[i]); } for (int i=0; i<15; ++i) // data for graph 1 { x1[i] = 3*i/15.0;; y1[i] = exp(-x1[i]*x1[i])*(x1[i]*x1[i])*2.6; y1err[i] = y1[i]*0.25; } for (int i=0; i<250; ++i) // data for graphs 2, 3 and 4 { x2[i] = i/250.0*3*M_PI; x3[i] = x2[i]; x4[i] = i/250.0*100-50; y2[i] = sin(x2[i]*12)*cos(x2[i])*10; y3[i] = cos(x3[i])*10; y4[i] = 0.01*x4[i]*x4[i] + 1.5*(rand()/(double)RAND_MAX-0.5) + 1.5*M_PI; } // pass data points to graphs: customPlot->graph(0)->setData(x0, y0); customPlot->graph(1)->setDataValueError(x1, y1, y1err); customPlot->graph(2)->setData(x2, y2); customPlot->graph(3)->setData(x3, y3); customPlot->graph(4)->setData(x4, y4); // activate top and right axes, which are invisible by default: customPlot->xAxis2->setVisible(true); customPlot->yAxis2->setVisible(true); // set ranges appropriate to show data: customPlot->xAxis->setRange(0, 2.7); customPlot->yAxis->setRange(0, 2.6); customPlot->xAxis2->setRange(0, 3.0*M_PI); customPlot->yAxis2->setRange(-70, 35); // set pi ticks on top axis: QVector<double> piTicks; QVector<QString> piLabels; piTicks << 0 << 0.5*M_PI << M_PI << 1.5*M_PI << 2*M_PI << 2.5*M_PI << 3*M_PI; piLabels << "0" << QString::fromUtf8("½π") << QString::fromUtf8("π") << QString::fromUtf8("1½π") << QString::fromUtf8("2π") << QString::fromUtf8("2½π") << QString::fromUtf8("3π"); customPlot->xAxis2->setAutoTicks(false); customPlot->xAxis2->setAutoTickLabels(false); customPlot->xAxis2->setTickVector(piTicks); customPlot->xAxis2->setTickVectorLabels(piLabels); // add title layout element: customPlot->plotLayout()->insertRow(0); customPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(customPlot, "Way too many graphs in one plot")); // set labels: customPlot->xAxis->setLabel("Bottom axis with outward ticks"); customPlot->yAxis->setLabel("Left axis label"); customPlot->xAxis2->setLabel("Top axis label"); customPlot->yAxis2->setLabel("Right axis label"); // make ticks on bottom axis go outward: customPlot->xAxis->setTickLength(0, 5); customPlot->xAxis->setSubTickLength(0, 3); // make ticks on right axis go inward and outward: customPlot->yAxis2->setTickLength(3, 3); customPlot->yAxis2->setSubTickLength(1, 1); }
//--------------------------------------------------------- DMat& NDG2D::ConformingHrefine2D(IMat& edgerefineflag, const DMat& Qin) //--------------------------------------------------------- { #if (0) OutputNodes(false); // volume nodes //OutputNodes(true); // face nodes #endif // function newQ = ConformingHrefine2D(edgerefineflag, Q) // Purpose: apply edge splits as requested by edgerefineflag IVec v1("v1"), v2("v2"), v3("v3"), tvi; DVec x1("x1"), x2("x2"), x3("x3"), y1("y1"), y2("y2"), y3("y3"); DVec a1("a1"), a2("a2"), a3("a3"); // count vertices assert (VX.size() == Nv); // find vertex triplets for elements to be refined v1 = EToV(All,1); v2 = EToV(All,2); v3 = EToV(All,3); x1 = VX(v1); x2 = VX(v2); x3 = VX(v3); y1 = VY(v1); y2 = VY(v2); y3 = VY(v3); // find angles at each element vertex (in radians) VertexAngles(x1,x2,x3,y1,y2,y3, a1,a2,a3); // absolute value of angle size a1.set_abs(); a2.set_abs(); a3.set_abs(); int k=0,k1=0,f1=0,k2=0,f2=0, e1=0,e2=0,e3=0, b1=0,b2=0,b3=0, ref=0; IVec m1,m2,m3; DVec mx1, my1, mx2, my2, mx3, my3; // create new vertices at edge centers of marked elements // (use unique numbering derived from unique edge number)) m1 = max(IVec(Nv*(v1-1)+v2+1), IVec(Nv*(v2-1)+v1+1)); mx1=0.5*(x1+x2); my1=0.5*(y1+y2); m2 = max(IVec(Nv*(v2-1)+v3+1), IVec(Nv*(v3-1)+v2+1)); mx2=0.5*(x2+x3); my2=0.5*(y2+y3); m3 = max(IVec(Nv*(v1-1)+v3+1), IVec(Nv*(v3-1)+v1+1)); mx3=0.5*(x3+x1); my3=0.5*(y3+y1); // ensure that both elements sharing an edge are split for (k1=1; k1<=K; ++k1) { for (f1=1; f1<=Nfaces; ++f1) { if (edgerefineflag(k1,f1)) { k2 = EToE(k1,f1); f2 = EToF(k1,f1); edgerefineflag(k2,f2) = 1; } } } // store old data IMat oldEToV = EToV; DVec oldVX = VX, oldVY = VY; // count the number of elements in the refined mesh int newK = countrefinefaces(edgerefineflag); EToV.resize(newK, Nfaces, true, 0); IMat newBCType(newK,3, "newBCType"); // kold = []; IVec kold(newK, "kold"); Index1D KI,KIo; int sk=1, skstart=0, skend=0; for (k=1; k<=K; ++k) { skstart = sk; e1 = edgerefineflag(k,1); b1 = BCType(k,1); e2 = edgerefineflag(k,2); b2 = BCType(k,2); e3 = edgerefineflag(k,3); b3 = BCType(k,3); ref = e1 + 2*e2 + 4*e3; switch (ref) { case 0: EToV(sk, All) = IVec(v1(k),v2(k),v3(k)); newBCType(sk,All) = IVec(b1, b2, b3); ++sk; break; case 1: EToV(sk, All) = IVec(v1(k),m1(k),v3(k)); newBCType(sk,All) = IVec(b1, 0, b3); ++sk; EToV(sk, All) = IVec(m1(k),v2(k),v3(k)); newBCType(sk,All) = IVec(b1, b2, 0); ++sk; break; case 2: EToV(sk, All) = IVec(v2(k),m2(k),v1(k)); newBCType(sk,All) = IVec(b2, 0, b1); ++sk; EToV(sk, All) = IVec(m2(k),v3(k),v1(k)); newBCType(sk,All) = IVec(b2, b3, 0); ++sk; break; case 4: EToV(sk, All) = IVec(v3(k),m3(k),v2(k)); newBCType(sk,All) = IVec(b3, 0, b2); ++sk; EToV(sk, All) = IVec(m3(k),v1(k),v2(k)); newBCType(sk,All) = IVec(b3, b1, 0); ++sk; break; case 3: EToV(sk, All) = IVec(m1(k),v2(k),m2(k)); newBCType(sk,All) = IVec(b1, b2, 0); ++sk; if (a1(k) > a3(k)) { // split largest angle EToV(sk, All) = IVec(v1(k),m1(k),m2(k)); newBCType(sk,All) = IVec(b1, 0, 0); ++sk; EToV(sk, All) = IVec(v1(k),m2(k),v3(k)); newBCType(sk,All) = IVec( 0, b2, b3); ++sk; } else { EToV(sk, All) = IVec(v3(k),m1(k),m2(k)); newBCType(sk,All) = IVec( 0, 0, b2); ++sk; EToV(sk, All) = IVec(v3(k),v1(k),m1(k)); newBCType(sk,All) = IVec(b3, b1, 0); ++sk; } break; case 5: EToV(sk, All) = IVec(v1(k),m1(k),m3(k)); newBCType(sk,All) = IVec(b1, 0, b3); ++sk; if (a2(k) > a3(k)) { // split largest angle EToV(sk, All) = IVec(v2(k),m3(k),m1(k)); newBCType(sk,All) = IVec( 0, 0, b1); ++sk; EToV(sk, All) = IVec(v2(k),v3(k),m3(k)); newBCType(sk,All) = IVec(b2, b3, 0); ++sk; } else { EToV(sk, All) = IVec(v3(k),m3(k),m1(k)); newBCType(sk,All) = IVec(b3, 0, 0); ++sk; EToV(sk, All) = IVec(v3(k),m1(k),v2(k)); newBCType(sk,All) = IVec( 0, b1, b2); ++sk; } break; case 6: EToV(sk, All) = IVec(v3(k),m3(k),m2(k)); newBCType(sk,All) = IVec(b3, 0, b2); ++sk; if (a1(k) > a2(k)) { // split largest angle EToV(sk, All) = IVec(v1(k),m2(k),m3(k)); newBCType(sk,All) = IVec( 0, 0, b3); ++sk; EToV(sk, All) = IVec(v1(k),v2(k),m2(k)); newBCType(sk,All) = IVec(b1, b2, 0); ++sk; } else { EToV(sk, All) = IVec(v2(k),m2(k),m3(k)); newBCType(sk,All) = IVec(b2, 0, 0); ++sk; EToV(sk, All) = IVec(v2(k),m3(k),v1(k)); newBCType(sk,All) = IVec( 0 , b3, b1); ++sk; } break; default: // split all EToV(sk, All) = IVec(m1(k),m2(k),m3(k)); newBCType(sk, All) = IVec( 0, 0, 0); ++sk; EToV(sk, All) = IVec(v1(k),m1(k),m3(k)); newBCType(sk, All) = IVec(b1, 0, b3); ++sk; EToV(sk, All) = IVec(v2(k),m2(k),m1(k)); newBCType(sk, All) = IVec(b2, 0, b1); ++sk; EToV(sk, All) = IVec(v3(k),m3(k),m2(k)); newBCType(sk, All) = IVec(b3, 0, b2); ++sk; break; } skend = sk; // kold = [kold; k*ones(skend-skstart, 1)]; // element k is to be refined into (1:4) child elements. // store parent element numbers in array "kold" to help // with accessing parent vertex data during refinement. KI.reset(skstart, skend-1); // ids of child elements kold(KI) = k; // mark as children of element k } // Finished with edgerefineflag. Delete if OBJ_temp if (edgerefineflag.get_mode() == OBJ_temp) { delete (&edgerefineflag); } // renumber new nodes contiguously // ids = unique([v1;v2;v3;m1;m2;m3]); bool unique=true; IVec IDS, ids; IDS = concat( concat(v1,v2,v3), concat(m1,m2,m3) ); ids = sort(IDS, unique); Nv = ids.size(); int max_id = EToV.max_val(); umMSG(1, "max id in EToV is %d\n", max_id); // M N nnz vals triplet CSi newids(max_id,1, Nv, 1, 1 ); // newids = sparse(max(max(EToV)),1); int i=0, j=1; for (i=1; i<=Nv; ++i) { // newids(ids)= (1:Nv); newids.set1(ids(i),j, i); // load 1-based triplets } // row col x newids.compress(); // convert to csc form // Matlab ----------------------------------------------- // v1 = newids(v1); v2 = newids(v2); v3 = newids(v3); // m1 = newids(m1); m2 = newids(m2); m3 = newids(m3); //------------------------------------------------------- int KVi=v1.size(), KMi=m1.size(); // read from copies, overwrite originals // 1. reload ids for new vertices tvi = v1; for (i=1;i<=KVi;++i) {v1(i) = newids(tvi(i), 1);} tvi = v2; for (i=1;i<=KVi;++i) {v2(i) = newids(tvi(i), 1);} tvi = v3; for (i=1;i<=KVi;++i) {v3(i) = newids(tvi(i), 1);} // 2. load ids for new (midpoint) vertices tvi = m1; for (i=1;i<=KMi;++i) {m1(i) = newids(tvi(i), 1);} tvi = m2; for (i=1;i<=KMi;++i) {m2(i) = newids(tvi(i), 1);} tvi = m3; for (i=1;i<=KMi;++i) {m3(i) = newids(tvi(i), 1);} VX.resize(Nv); VY.resize(Nv); VX(v1) = x1; VX(v2) = x2; VX(v3) = x3; VY(v1) = y1; VY(v2) = y2; VY(v3) = y3; VX(m1) = mx1; VX(m2) = mx2; VX(m3) = mx3; VY(m1) = my1; VY(m2) = my2; VY(m3) = my3; if (newK != (sk-1)) { umERROR("NDG2D::ConformingHrefine2D", "Inconsistent element count: expect %d, but sk = %d", newK, (sk-1)); } else { K = newK; // sk-1; } // dumpIMat(EToV, "EToV (before)"); // EToV = newids(EToV); for (j=1; j<=3; ++j) { for (k=1; k<=K; ++k) { EToV(k,j) = newids(EToV(k,j), 1); } } #if (0) dumpIMat(EToV, "EToV (after)"); // umERROR("Checking ids", "Nigel, check EToV"); #endif BCType = newBCType; Nv = VX.size(); // xold = x; yold = y; StartUp2D(); #if (1) OutputNodes(false); // volume nodes //OutputNodes(true); // face nodes //umERROR("Exiting early", "Check adapted {volume,face} nodes"); #endif // allocate return object int Nfields = Qin.num_cols(); DMat* tmpQ = new DMat(Np*K, Nfields, "newQ", OBJ_temp); DMat& newQ = *tmpQ; // use a reference for syntax // quick return, if no interpolation is required if (Qin.size()<1) { return newQ; } DVec rOUT(Np),sOUT(Np),xout,yout,xy1(2),xy2(2),xy3(2),tmp(2),rhs; int ko=0,kv1=0,kv2=0,kv3=0,n=0; DMat A(2,2), interp; DMat oldQ = const_cast<DMat&>(Qin); for (k=1; k<=K; ++k) { ko = kold(k); xout = x(All,k); yout = y(All,k); kv1=oldEToV(ko,1); kv2=oldEToV(ko,2); kv3=oldEToV(ko,3); xy1.set(oldVX(kv1), oldVY(kv1)); xy2.set(oldVX(kv2), oldVY(kv2)); xy3.set(oldVX(kv3), oldVY(kv3)); A.set_col(1, xy2-xy1); A.set_col(2, xy3-xy1); for (i=1; i<=Np; ++i) { tmp.set(xout(i), yout(i)); rhs = 2.0*tmp - xy2 - xy3; tmp = A|rhs; rOUT(i) = tmp(1); sOUT(i) = tmp(2); } KI.reset (Np*(k -1)+1, Np*k ); // nodes in new element k KIo.reset(Np*(ko-1)+1, Np*ko); // nodes in old element ko interp = Vandermonde2D(N, rOUT, sOUT)*invV; for (n=1; n<=Nfields; ++n) { //newQ(:,k,n)= interp* Q(:,ko,n); //DVec tm1 = interp*oldQ(KIo,n); //dumpDVec(tm1, "tm1"); newQ(KI,n) = interp*oldQ(KIo,n); } } return newQ; }
int four_quads(const Epetra_Comm& Comm, bool preconstruct_graph, bool verbose) { if (verbose) { cout << "******************* four_quads ***********************"<<endl; } //This function assembles a matrix representing a finite-element mesh //of four 2-D quad elements. There are 9 nodes in the problem. The //same problem is assembled no matter how many processors are being used //(within reason). It may not work if more than 9 processors are used. // // *------*------* // 6| 7| 8| // | E2 | E3 | // *------*------* // 3| 4| 5| // | E0 | E1 | // *------*------* // 0 1 2 // //Nodes are denoted by * with node-numbers below and left of each node. //E0, E1 and so on are element-numbers. // //Each processor will contribute a sub-matrix of size 4x4, filled with 1's, //for each element. Thus, the coefficient value at position 0,0 should end up //being 1.0*numProcs, the value at position 4,4 should be 1.0*4*numProcs, etc. // //Depending on the number of processors being used, the locations of the //specific matrix positions (in terms of which processor owns them) will vary. // int numProcs = Comm.NumProc(); int numNodes = 9; int numElems = 4; int numNodesPerElem = 4; int blockSize = 1; int indexBase = 0; //Create a map using epetra-defined linear distribution. Epetra_BlockMap map(numNodes, blockSize, indexBase, Comm); Epetra_CrsGraph* graph = NULL; int* nodes = new int[numNodesPerElem]; int i, j, k, err = 0; if (preconstruct_graph) { graph = new Epetra_CrsGraph(Copy, map, 1); //we're going to fill the graph with indices, but remember it will only //accept indices in rows for which map.MyGID(row) is true. for(i=0; i<numElems; ++i) { switch(i) { case 0: nodes[0] = 0; nodes[1] = 1; nodes[2] = 4; nodes[3] = 3; break; case 1: nodes[0] = 1; nodes[1] = 2; nodes[2] = 5; nodes[3] = 4; break; case 2: nodes[0] = 3; nodes[1] = 4; nodes[2] = 7; nodes[3] = 6; break; case 3: nodes[0] = 4; nodes[1] = 5; nodes[2] = 8; nodes[3] = 7; break; } for(j=0; j<numNodesPerElem; ++j) { if (map.MyGID(nodes[j])) { err = graph->InsertGlobalIndices(nodes[j], numNodesPerElem, nodes); if (err<0) return(err); } } } EPETRA_CHK_ERR( graph->FillComplete() ); } Epetra_FEVbrMatrix* A = NULL; if (preconstruct_graph) { A = new Epetra_FEVbrMatrix(Copy, *graph); } else { A = new Epetra_FEVbrMatrix(Copy, map, 1); } //EPETRA_CHK_ERR( A->PutScalar(0.0) ); double* values_1d = new double[numNodesPerElem*numNodesPerElem]; double** values_2d = new double*[numNodesPerElem]; for(i=0; i<numNodesPerElem*numNodesPerElem; ++i) values_1d[i] = 1.0; int offset = 0; for(i=0; i<numNodesPerElem; ++i) { values_2d[i] = &(values_1d[offset]); offset += numNodesPerElem; } for(i=0; i<numElems; ++i) { switch(i) { case 0: nodes[0] = 0; nodes[1] = 1; nodes[2] = 4; nodes[3] = 3; break; case 1: nodes[0] = 1; nodes[1] = 2; nodes[2] = 5; nodes[3] = 4; break; case 2: nodes[0] = 3; nodes[1] = 4; nodes[2] = 7; nodes[3] = 6; break; case 3: nodes[0] = 4; nodes[1] = 5; nodes[2] = 8; nodes[3] = 7; break; } for(j=0; j<numNodesPerElem; ++j) { if (preconstruct_graph) { err = A->BeginSumIntoGlobalValues(nodes[j], numNodesPerElem, nodes); if (err<0) return(err); } else { err = A->BeginInsertGlobalValues(nodes[j], numNodesPerElem, nodes); if (err<0) return(err); } for(k=0; k<numNodesPerElem; ++k) { err = A->SubmitBlockEntry(values_1d, blockSize, blockSize, blockSize); if (err<0) return(err); } err = A->EndSubmitEntries(); if (err<0) return(err); } } EPETRA_CHK_ERR( A->GlobalAssemble() ); Epetra_FEVbrMatrix* Acopy = new Epetra_FEVbrMatrix(*A); if (verbose) { cout << "A:"<<*A << endl; cout << "Acopy:"<<*Acopy<<endl; } Epetra_Vector x(A->RowMap()), y(A->RowMap()); x.PutScalar(1.0); y.PutScalar(0.0); Epetra_Vector x2(Acopy->RowMap()), y2(Acopy->RowMap()); x2.PutScalar(1.0); y2.PutScalar(0.0); A->Multiply(false, x, y); Acopy->Multiply(false, x2, y2); double ynorm2, y2norm2; y.Norm2(&ynorm2); y2.Norm2(&y2norm2); if (ynorm2 != y2norm2) { cerr << "norm2(A*ones) != norm2(*Acopy*ones)"<<endl; return(-99); } Epetra_FEVbrMatrix* Acopy2 = new Epetra_FEVbrMatrix(Copy, A->RowMap(), A->ColMap(), 1); *Acopy2 = *Acopy; Epetra_Vector x3(Acopy->RowMap()), y3(Acopy->RowMap()); x3.PutScalar(1.0); y3.PutScalar(0.0); Acopy2->Multiply(false, x3, y3); double y3norm2; y3.Norm2(&y3norm2); if (y3norm2 != y2norm2) { cerr << "norm2(Acopy*ones) != norm2(Acopy2*ones)"<<endl; return(-999); } int len = 20; int* indices = new int[len]; double* values = new double[len]; int numIndices; if (map.MyGID(0)) { int lid = map.LID(0); EPETRA_CHK_ERR( A->ExtractMyRowCopy(lid, len, numIndices, values, indices) ); if (numIndices != 4) { return(-1); } if (indices[0] != lid) { return(-2); } if (values[0] != 1.0*numProcs) { cout << "ERROR: values[0] ("<<values[0]<<") should be "<<numProcs<<endl; return(-3); } } if (map.MyGID(4)) { int lid = map.LID(4); EPETRA_CHK_ERR( A->ExtractMyRowCopy(lid, len, numIndices, values, indices) ); if (numIndices != 9) { return(-4); } int lcid = A->LCID(4); // if (indices[lcid] != 4) { // cout << "ERROR: indices[4] ("<<indices[4]<<") should be " // <<A->LCID(4)<<endl; // return(-5); // } if (values[lcid] != 4.0*numProcs) { cout << "ERROR: values["<<lcid<<"] ("<<values[lcid]<<") should be " <<4*numProcs<<endl; return(-6); } } delete [] values_2d; delete [] values_1d; delete [] nodes; delete [] indices; delete [] values; delete A; delete Acopy2; delete Acopy; delete graph; return(0); }
int four_quads(const Epetra_Comm& Comm, bool preconstruct_graph, bool verbose) { if (verbose) { std::cout << "******************* four_quads ***********************"<<std::endl; } //This function assembles a matrix representing a finite-element //mesh of four 2-D quad elements. There are 9 nodes in the problem. The //same problem is assembled no matter how many processors are being used //(within reason). It may not work if more than 9 processors are used. // // *------*------* // 6| 7| 8| // | E2 | E3 | // *------*------* // 3| 4| 5| // | E0 | E1 | // *------*------* // 0 1 2 // //Nodes are denoted by * with node-numbers below and left of each node. //E0, E1 and so on are element-numbers. // //Each processor will contribute a sub-matrix of size 4x4, filled with 1's, //for each element. Thus, the coefficient value at position 0,0 should end up //being 1.0*numProcs, the value at position 4,4 should be 1.0*4*numProcs, etc. // //Depending on the number of processors being used, the locations of the //specific matrix positions (in terms of which processor owns them) will vary. // int numProcs = Comm.NumProc(); long long numNodes = 9; int numElems = 4; int numNodesPerElem = 4; int indexBase = 0; //Create a map using epetra-defined linear distribution. Epetra_Map map(numNodes, indexBase, Comm); Epetra_FECrsGraph* graph = NULL; long long* nodes = new long long[numNodesPerElem]; int i, err = 0; if (preconstruct_graph) { graph = new Epetra_FECrsGraph(Copy, map, 1); //we're going to fill the graph with indices, by passing our //connectivity lists. //FECrsGraph should accept indices in all rows, regardless of //whether map.MyGID(row) is true. for(i=0; i<numElems; ++i) { switch(i) { case 0: nodes[0] = 0; nodes[1] = 1; nodes[2] = 4; nodes[3] = 3; break; case 1: nodes[0] = 1; nodes[1] = 2; nodes[2] = 5; nodes[3] = 4; break; case 2: nodes[0] = 3; nodes[1] = 4; nodes[2] = 7; nodes[3] = 6; break; case 3: nodes[0] = 4; nodes[1] = 5; nodes[2] = 8; nodes[3] = 7; break; } err = graph->InsertGlobalIndices(numNodesPerElem, nodes, numNodesPerElem, nodes); if (err < 0) { std::cerr << "ERROR, FECrsGraph error in InsertGlobalIndices, err=" << err << std::endl; return(-1); } } EPETRA_CHK_ERR( graph->GlobalAssemble() ); } Epetra_FECrsMatrix* A = NULL; if (preconstruct_graph) { A = new Epetra_FECrsMatrix(Copy, *graph); } else { A = new Epetra_FECrsMatrix(Copy, map, 1); } EPETRA_CHK_ERR( A->PutScalar(0.0) ); double* values_1d = new double[numNodesPerElem*numNodesPerElem]; double** values_2d = new double*[numNodesPerElem]; for(i=0; i<numNodesPerElem*numNodesPerElem; ++i) values_1d[i] = 1.0; int offset = 0; for(i=0; i<numNodesPerElem; ++i) { values_2d[i] = &(values_1d[offset]); offset += numNodesPerElem; } int format = Epetra_FECrsMatrix::ROW_MAJOR; Epetra_LongLongSerialDenseVector epetra_nodes(View, nodes, numNodesPerElem); Epetra_SerialDenseMatrix epetra_values(View, values_1d, numNodesPerElem, numNodesPerElem, numNodesPerElem); for(i=0; i<numElems; ++i) { switch(i) { case 0: nodes[0] = 0; nodes[1] = 1; nodes[2] = 4; nodes[3] = 3; if (preconstruct_graph) { err = A->SumIntoGlobalValues(epetra_nodes, epetra_values, format); if (err<0) return(err); } else { err = A->InsertGlobalValues(epetra_nodes, epetra_values, format); if (err<0) return(err); } break; case 1: nodes[0] = 1; nodes[1] = 2; nodes[2] = 5; nodes[3] = 4; if (preconstruct_graph) { err = A->SumIntoGlobalValues(numNodesPerElem, nodes, values_2d, format); if (err<0) return(err); } else { err = A->InsertGlobalValues(numNodesPerElem, nodes, values_2d, format); if (err<0) return(err); } break; case 2: nodes[0] = 3; nodes[1] = 4; nodes[2] = 7; nodes[3] = 6; if (preconstruct_graph) { err = A->SumIntoGlobalValues(numNodesPerElem, nodes, numNodesPerElem, nodes, values_1d, format); if (err<0) return(err); } else { err = A->InsertGlobalValues(numNodesPerElem, nodes, numNodesPerElem, nodes, values_1d, format); if (err<0) return(err); } break; case 3: nodes[0] = 4; nodes[1] = 5; nodes[2] = 8; nodes[3] = 7; if (preconstruct_graph) { err = A->SumIntoGlobalValues(numNodesPerElem, nodes, numNodesPerElem, nodes, values_2d, format); if (err<0) return(err); } else { err = A->InsertGlobalValues(numNodesPerElem, nodes, numNodesPerElem, nodes, values_2d, format); if (err<0) return(err); } break; } } err = A->GlobalAssemble(); if (err < 0) { return(err); } Epetra_Vector x(A->RowMap()), y(A->RowMap()); x.PutScalar(1.0); y.PutScalar(0.0); Epetra_FECrsMatrix Acopy(*A); Epetra_Vector x2(Acopy.RowMap()), y2(Acopy.RowMap()); x2.PutScalar(1.0); y2.PutScalar(0.0); A->Multiply(false, x, y); Acopy.Multiply(false, x2, y2); double ynorm2, y2norm2; y.Norm2(&ynorm2); y2.Norm2(&y2norm2); if (ynorm2 != y2norm2) { std::cerr << "norm2(A*ones) != norm2(Acopy*ones)"<<std::endl; return(-99); } err = Acopy.GlobalAssemble(); if (err < 0) { return(err); } if (verbose) { std::cout << "A:"<<std::endl<<*A << std::endl; std::cout << "Acopy:"<<std::endl<<Acopy << std::endl; } Epetra_FECrsMatrix Acopy2(Copy, A->RowMap(), A->ColMap(), 1); Acopy2 = Acopy; Epetra_Vector x3(Acopy.RowMap()), y3(Acopy.RowMap()); x3.PutScalar(1.0); y3.PutScalar(0.0); Acopy2.Multiply(false, x3, y3); double y3norm2; y3.Norm2(&y3norm2); if (y3norm2 != y2norm2) { std::cerr << "norm2(Acopy*ones) != norm2(Acopy2*ones)"<<std::endl; return(-999); } int len = 20; long long* indices = new long long[len]; double* values = new double[len]; int numIndices; if (map.MyGID(0)) { EPETRA_CHK_ERR( A->ExtractGlobalRowCopy(0, len, numIndices, values, indices) ); if (numIndices != 4) { return(-1); } if (indices[0] != 0) { return(-2); } if (values[0] != 1.0*numProcs) { std::cout << "ERROR: values[0] ("<<values[0]<<") should be "<<numProcs<<std::endl; return(-3); } } if (map.MyGID(4)) { EPETRA_CHK_ERR( A->ExtractGlobalRowCopy(4, len, numIndices, values, indices) ); if (numIndices != 9) { return(-4); } int lcid = A->LCID(4); if (lcid<0) { return(-5); } if (values[lcid] != 4.0*numProcs) { std::cout << "ERROR: values["<<lcid<<"] ("<<values[lcid]<<") should be " <<4*numProcs<<std::endl; return(-6); } } // now let's do the checks for Acopy... if (map.MyGID(0)) { EPETRA_CHK_ERR( Acopy.ExtractGlobalRowCopy(0, len, numIndices, values, indices) ); if (numIndices != 4) { return(-1); } if (indices[0] != 0) { return(-2); } if (values[0] != 1.0*numProcs) { std::cout << "ERROR: Acopy.values[0] ("<<values[0]<<") should be "<<numProcs<<std::endl; return(-3); } } if (map.MyGID(4)) { EPETRA_CHK_ERR( Acopy.ExtractGlobalRowCopy(4, len, numIndices, values, indices) ); if (numIndices != 9) { return(-4); } int lcid = A->LCID(4); if (lcid<0) { return(-5); } if (values[lcid] != 4.0*numProcs) { std::cout << "ERROR: Acopy.values["<<lcid<<"] ("<<values[lcid]<<") should be " <<4*numProcs<<std::endl; return(-6); } } // now let's do the checks for Acopy2... if (map.MyGID(0)) { EPETRA_CHK_ERR( Acopy2.ExtractGlobalRowCopy(0, len, numIndices, values, indices) ); if (numIndices != 4) { return(-1); } if (indices[0] != 0) { return(-2); } if (values[0] != 1.0*numProcs) { std::cout << "ERROR: Acopy2.values[0] ("<<values[0]<<") should be "<<numProcs<<std::endl; return(-3); } } if (map.MyGID(4)) { EPETRA_CHK_ERR( Acopy2.ExtractGlobalRowCopy(4, len, numIndices, values, indices) ); if (numIndices != 9) { return(-4); } int lcid = A->LCID(4); if (lcid<0) { return(-5); } if (values[lcid] != 4.0*numProcs) { std::cout << "ERROR: Acopy2.values["<<lcid<<"] ("<<values[lcid]<<") should be " <<4*numProcs<<std::endl; return(-6); } } delete [] values_2d; delete [] values_1d; delete [] nodes; delete [] indices; delete [] values; delete A; delete graph; return(0); }
void Highscore::addGraphOneBestToOneActual(QCustomPlot *plot, Run rL, Run rB) { plot->legend->setVisible(true); plot->legend->setFont(QFont("Helvetica",9)); plot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); int typePointsCount = rB.typePoints.size(); int xMin = -1; int xMax = typePointsCount+1; int yMin = 0; double yMax = 0; int yMaxErr = 0; QVector<double> x(typePointsCount), y(typePointsCount), y2(typePointsCount*11), x2(typePointsCount*11); for(int i = 0; i<typePointsCount; i++) { y[i] = 1/ (rB.typePoints.at(i).timeInMilliSeconds/60000.0); x[i] = i; yMax = std::max(y[i],yMax); for(double j = 0; j<11; j++) { y2[11*i+j] = rB.typePoints.at(i).error; x2[11*i+j] = (i-0.02)+(0.004*j)+0.04; } yMaxErr = std::max(rB.typePoints.at(i).error,yMaxErr); } plot->addGraph(plot->xAxis, plot->yAxis); plot->graph(0)->setName("Anschläge / Minute"); plot->graph(0)->setData(x,y); plot->graph(0)->setLineStyle((QCPGraph::LineStyle)(1)); plot->graph(0)->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1))); QPen graphPen; graphPen.setColor(QColor(200, 50, 0, 85)); graphPen.setWidthF(2); plot->graph(0)->setPen(graphPen); plot->addGraph(plot->xAxis, plot->yAxis2); plot->graph(1)->setName("Fehler"); plot->graph(1)->setData(x2,y2); plot->graph(1)->setLineStyle((QCPGraph::LineStyle)(5)); QPen graphPen1; graphPen1.setColor(QColor(200, 50, 0, 100)); graphPen1.setWidthF(3); plot->graph(1)->setPen(graphPen1); //plot->graph(0)->setBrush(QBrush(QColor(255,200,20,70))); typePointsCount = rL.typePoints.size(); xMin = -1; xMax = typePointsCount+1; QVector<double> x3(typePointsCount), y3(typePointsCount), y4(typePointsCount*11), x4(typePointsCount*11); for(int i = 0; i<typePointsCount; i++) { y3[i] = 1/ (rL.typePoints.at(i).timeInMilliSeconds/60000.0); x3[i] = i; yMax = std::max(y3[i],yMax); for(double j = 0; j<11; j++) { y4[11*i+j] = rL.typePoints.at(i).error; x4[11*i+j] = (i-0.02)+(0.004*j)-0.04; } yMaxErr = std::max(rL.typePoints.at(i).error,yMaxErr); } plot->addGraph(plot->xAxis, plot->yAxis); plot->graph(2)->setName("Anschläge / Minute"); plot->graph(2)->setData(x3,y3); plot->graph(2)->setLineStyle((QCPGraph::LineStyle)(1)); plot->graph(2)->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1))); QPen graphPen2; graphPen2.setColor(QColor(130, 30, 0, 85)); graphPen2.setWidthF(2); plot->graph(2)->setPen(graphPen2); plot->addGraph(plot->xAxis, plot->yAxis2); plot->graph(3)->setName("Fehler"); plot->graph(3)->setData(x4,y4); plot->graph(3)->setLineStyle((QCPGraph::LineStyle)(5)); QPen graphPen3; graphPen3.setColor(QColor(130, 30, 0, 100)); graphPen3.setWidthF(3); plot->graph(3)->setPen(graphPen3); plot->yAxis2->setVisible(true); plot->xAxis2->setVisible(true); plot->xAxis->setVisible(true); plot->xAxis->setLabel("Durchlauf"); plot->yAxis->setLabel("Anschläge pro Minute"); plot->yAxis2->setLabel("Fehler"); plot->xAxis->setRange(xMin, xMax); plot->yAxis->setRange(yMin, yMax+1); plot->yAxis2->setRange(yMin,yMaxErr*1.5 ); plot->xAxis2->setRange(xMin, xMax); plot->xAxis->setAutoTickStep(false); plot->xAxis->setTickStep(1); plot->xAxis->setSubTickCount(1); plot->xAxis2->setTickLength(0, 0); plot->xAxis2->setSubTickLength(0, 0); plot->xAxis2->setTickStep(false); plot->xAxis2->setAutoTickLabels(false); plot->xAxis2->setTickLabels(false); plot->yAxis2->setAutoTickStep(false); plot->yAxis2->setTickStep(1); plot->yAxis2->setSubTickCount(0); plot->yAxis2->setTickLength(3, 3); plot->yAxis2->setSubTickLength(0, 0); //plot->graph(0)->setBrush(QBrush(QColor(255,200,20,70))); }
bool testsblas(bool silent) { bool result; ap::real_2d_array a; ap::real_2d_array ua; ap::real_2d_array la; ap::real_1d_array x; ap::real_1d_array y1; ap::real_1d_array y2; ap::real_1d_array y3; int n; int maxn; int i; int j; int i1; int i2; int gpass; bool waserrors; double mverr; double threshold; double alpha; double v; mverr = 0; waserrors = false; maxn = 10; threshold = 1000*ap::machineepsilon; // // Test MV // for(n = 2; n <= maxn; n++) { a.setbounds(1, n, 1, n); ua.setbounds(1, n, 1, n); la.setbounds(1, n, 1, n); x.setbounds(1, n); y1.setbounds(1, n); y2.setbounds(1, n); y3.setbounds(1, n); // // fill A, UA, LA // for(i = 1; i <= n; i++) { a(i,i) = 2*ap::randomreal()-1; for(j = i+1; j <= n; j++) { a(i,j) = 2*ap::randomreal()-1; a(j,i) = a(i,j); } } for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) { ua(i,j) = 0; } } for(i = 1; i <= n; i++) { for(j = i; j <= n; j++) { ua(i,j) = a(i,j); } } for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) { la(i,j) = 0; } } for(i = 1; i <= n; i++) { for(j = 1; j <= i; j++) { la(i,j) = a(i,j); } } // // test on different I1, I2 // for(i1 = 1; i1 <= n; i1++) { for(i2 = i1; i2 <= n; i2++) { // // Fill X, choose Alpha // for(i = 1; i <= i2-i1+1; i++) { x(i) = 2*ap::randomreal()-1; } alpha = 2*ap::randomreal()-1; // // calculate A*x, UA*x, LA*x // for(i = i1; i <= i2; i++) { v = ap::vdotproduct(&a(i, i1), 1, &x(1), 1, ap::vlen(i1,i2)); y1(i-i1+1) = alpha*v; } symmetricmatrixvectormultiply(ua, true, i1, i2, x, alpha, y2); symmetricmatrixvectormultiply(la, false, i1, i2, x, alpha, y3); // // Calculate error // ap::vsub(&y2(1), 1, &y1(1), 1, ap::vlen(1,i2-i1+1)); v = ap::vdotproduct(&y2(1), 1, &y2(1), 1, ap::vlen(1,i2-i1+1)); mverr = ap::maxreal(mverr, sqrt(v)); ap::vsub(&y3(1), 1, &y1(1), 1, ap::vlen(1,i2-i1+1)); v = ap::vdotproduct(&y3(1), 1, &y3(1), 1, ap::vlen(1,i2-i1+1)); mverr = ap::maxreal(mverr, sqrt(v)); } } } // // report // waserrors = ap::fp_greater(mverr,threshold); if( !silent ) { printf("TESTING SYMMETRIC BLAS\n"); printf("MV error: %5.3le\n", double(mverr)); printf("Threshold: %5.3le\n", double(threshold)); if( waserrors ) { printf("TEST FAILED\n"); } else { printf("TEST PASSED\n"); } printf("\n\n"); } result = !waserrors; return result; }
bool testhblas(bool silent) { bool result; ap::complex_2d_array a; ap::complex_2d_array ua; ap::complex_2d_array la; ap::complex_1d_array x; ap::complex_1d_array y1; ap::complex_1d_array y2; ap::complex_1d_array y3; int n; int maxn; int i; int j; int i1; int i2; int gpass; bool waserrors; double mverr; double threshold; ap::complex alpha; ap::complex v; int i_; int i1_; mverr = 0; waserrors = false; maxn = 10; threshold = 1000*ap::machineepsilon; // // Test MV // for(n = 2; n <= maxn; n++) { a.setbounds(1, n, 1, n); ua.setbounds(1, n, 1, n); la.setbounds(1, n, 1, n); x.setbounds(1, n); y1.setbounds(1, n); y2.setbounds(1, n); y3.setbounds(1, n); // // fill A, UA, LA // for(i = 1; i <= n; i++) { a(i,i).x = 2*ap::randomreal()-1; a(i,i).y = 0; for(j = i+1; j <= n; j++) { a(i,j).x = 2*ap::randomreal()-1; a(i,j).y = 2*ap::randomreal()-1; a(j,i) = ap::conj(a(i,j)); } } for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) { ua(i,j) = 0; } } for(i = 1; i <= n; i++) { for(j = i; j <= n; j++) { ua(i,j) = a(i,j); } } for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) { la(i,j) = 0; } } for(i = 1; i <= n; i++) { for(j = 1; j <= i; j++) { la(i,j) = a(i,j); } } // // test on different I1, I2 // for(i1 = 1; i1 <= n; i1++) { for(i2 = i1; i2 <= n; i2++) { // // Fill X, choose Alpha // for(i = 1; i <= i2-i1+1; i++) { x(i).x = 2*ap::randomreal()-1; x(i).y = 2*ap::randomreal()-1; } alpha.x = 2*ap::randomreal()-1; alpha.y = 2*ap::randomreal()-1; // // calculate A*x, UA*x, LA*x // for(i = i1; i <= i2; i++) { i1_ = (1)-(i1); v = 0.0; for(i_=i1; i_<=i2;i_++) { v += a(i,i_)*x(i_+i1_); } y1(i-i1+1) = alpha*v; } hermitianmatrixvectormultiply(ua, true, i1, i2, x, alpha, y2); hermitianmatrixvectormultiply(la, false, i1, i2, x, alpha, y3); // // Calculate error // for(i_=1; i_<=i2-i1+1;i_++) { y2(i_) = y2(i_) - y1(i_); } v = 0.0; for(i_=1; i_<=i2-i1+1;i_++) { v += y2(i_)*ap::conj(y2(i_)); } mverr = ap::maxreal(mverr, sqrt(ap::abscomplex(v))); for(i_=1; i_<=i2-i1+1;i_++) { y3(i_) = y3(i_) - y1(i_); } v = 0.0; for(i_=1; i_<=i2-i1+1;i_++) { v += y3(i_)*ap::conj(y3(i_)); } mverr = ap::maxreal(mverr, sqrt(ap::abscomplex(v))); } } } // // report // waserrors = ap::fp_greater(mverr,threshold); if( !silent ) { printf("TESTING HERMITIAN BLAS\n"); printf("MV error: %5.3le\n", double(mverr)); printf("Threshold: %5.3le\n", double(threshold)); if( waserrors ) { printf("TEST FAILED\n"); } else { printf("TEST PASSED\n"); } printf("\n\n"); } result = !waserrors; return result; }
void MainWindow::timeout() { info->update(); QString value; QVector<double> x(101), y(101), y1(101), y2(101), y3(101), yRam(101); for (int i=0; i < 100; ++i) { x[i] = i; y[i] = info->get_cpu0_y()[i]; y1[i] = info->get_cpu1_y()[i]; y2[i] = info->get_cpu2_y()[i]; y3[i] = info->get_cpu3_y()[i]; yRam[i] = info->get_ram_y()[i]; } customPlot->graph(0)->setPen(QPen(Qt::red)); customPlot->graph(0)->setData(x, y); customPlot->graph(1)->setPen(QPen(Qt::green)); customPlot->graph(1)->setData(x, y1); customPlot->graph(2)->setPen(QPen(Qt::blue)); customPlot->graph(2)->setData(x, y2); customPlot->graph(3)->setPen(QPen(Qt::black)); customPlot->graph(3)->setData(x, y3); customRam->graph(0)->setPen(QPen(Qt::blue)); customRam->graph(0)->setData(x, yRam); customPlot->xAxis->setRange(0, 100); customPlot->yAxis->setRange(0, 100); customRam->xAxis->setRange(0, 100); customRam->yAxis->setRange(0, 100); host->setText("HostName: "); host->setGeometry(QRect(10, 20, 150, 20)); host_->setText(info->getHostName().data()); host_->setGeometry(QRect(180, 20, 150, 20)); user->setText("UserName: "******"Kernel: "); kernel->setGeometry(QRect(10, 60, 150, 60)); kernel_->setText(info->getKernel().data()); kernel_->setGeometry(QRect(180, 60, 150, 60)); OS->setText("OS: "); OS->setGeometry(QRect(10, 80, 150, 80)); OS_->setText(info->getOs().data()); OS_->setGeometry(QRect(180, 80, 150, 80)); version->setText("Version: "); version->setGeometry(QRect(10, 100, 150, 100)); version_->setText(info->getVersion().data()); version_->setGeometry(QRect(180, 100, 150, 100)); date->setText("Date: "); date->setGeometry(QRect(10, 120, 150, 120)); date_->setText(info->getDate().data()); date_->setGeometry(QRect(180, 130, 200, 120)); cpu_model->setText("CPU_Model: "); cpu_model->setGeometry(QRect(400, 20, 150, 20)); std::string s = info->getModelCPU().data(); std::string d = " "; s.replace(s.find(d), 13, " "); cpu_model_->setText(s.data()); cpu_model_->setGeometry(QRect(500, 20, 280, 20)); cpu_all->setText("CPU_All"); cpu_all->setGeometry(QRect(400, 40, 150, 40)); float f = 0; std::vector<double> tmp = info->getVectorCPU(); for (unsigned int i = 0; i < tmp.size(); i++) f += tmp[i]; f /= tmp.size(); value = value.sprintf("%7.2f %%", f); cpu_all_->setText(value); cpu_all_->setGeometry(QRect(580, 40, 150, 40)); core0->setText("CPU_Core0: "); core0->setGeometry(QRect(400, 60, 150, 60)); value = value.sprintf("%7.2f %%", info->getVectorCPU()[0]); core0_->setText(value); core0_->setGeometry(QRect(580, 60, 150, 60)); core1->setText("CPU_Core1: "); core1->setGeometry(QRect(400, 80, 150, 80)); value = value.sprintf("%7.2f %%", info->getVectorCPU()[1]); core1_->setText(value); core1_->setGeometry(QRect(580, 80, 150, 80)); core2->setText("CPU_Core2: "); core2->setGeometry(QRect(400, 100, 150, 100)); value = value.sprintf("%7.2f %%", info->getVectorCPU()[2]); core2_->setText(value); core2_->setGeometry(QRect(580, 100, 150, 100)); core3->setText("CPU_Core3: "); core3->setGeometry(QRect(400, 120, 150, 120)); value = value.sprintf("%7.2f %%", info->getVectorCPU()[3]); core3_->setText(value); core3_->setGeometry(QRect(580, 120, 150, 120)); ram_max->setText("Ram Max: "); ram_max->setGeometry(QRect(800, 20, 150, 20)); value = value.sprintf("%7.2f GB", static_cast<float>(info->getRamMax()) / 1024 / 1024 / 1024); ram_max_->setText(value); ram_max_->setGeometry(QRect(920, 20, 150, 20)); ram_cur->setText("Ram Current: "); ram_cur->setGeometry(QRect(800, 40, 150, 40)); value = value.sprintf("%7.2f GB", static_cast<float>(info->getRamCurrent()) / 1024 / 1024 / 1024); ram_cur_->setText(value); ram_cur_->setGeometry(QRect(920, 40, 150, 40)); ram_p->setText("Ram %: "); ram_p->setGeometry(QRect(800, 60, 150, 60)); value = value.sprintf("%7.2f %%", info->getRamPercantCurrent()); ram_p_->setText(value); ram_p_->setGeometry(QRect(920, 60, 150, 60)); customPlot->replot(); customRam->replot(); }
void Form::setupStyledDemo(QCustomPlot *customPlot) { demoName = "Style Demo"; // prepare data: QVector<double> x1(20), y1(20); QVector<double> x2(100), y2(100); QVector<double> x3(20), y3(20); QVector<double> x4(20), y4(20); /* // add the text label at the top: QCPItemText *textLabel = new QCPItemText(customPlot); customPlot->addItem(textLabel); textLabel->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter); textLabel->position->setType(QCPItemPosition::ptAxisRectRatio); textLabel->position->setCoords(0.5, 0); // place position at center/top of axis rect textLabel->setText("Text Item Demo"); textLabel->setFont(QFont(font().family(), 16)); // make font a bit larger textLabel->setPen(QPen(Qt::black)); // show black border around text // add the arrow: QCPItemLine *arrow = new QCPItemLine(customPlot); customPlot->addItem(arrow); arrow->start->setParentAnchor(textLabel->bottom); arrow->end->setCoords(4, 1.6); // point to (4, 1.6) in x-y-plot coordinates arrow->setHead(QCPLineEnding::esSpikeArrow); */ for (int i=0; i<x1.size(); ++i) { x1[i] = i/(double)x1.size()*10; y1[i] = qCos(x1[i]*0.8+qSin(x1[i]*0.16+1.0))*qSin(x1[i]*0.54)+1.4; } for (int i=0; i<x2.size(); ++i) { x2[i] = i/(double)x2.size()*10; y2[i] = qCos(x2[i]*0.85+qSin(x2[i]*0.165+1.1))*qSin(x2[i]*0.50)+1.7; } for (int i=0; i<x3.size(); ++i) { x3[i] = i/(double)x3.size()*10; y3[i] = 0.05+3*(0.5+qCos(x3[i]*x3[i]*0.2+2)*0.5)/(double)(x3[i]+0.7)+qrand()/(double)RAND_MAX*0.01; } // create and configure plottables: QCPGraph *graph1 = customPlot->addGraph(); graph1->setData(x1, y1); graph1->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, QPen(Qt::black, 1.5), QBrush(Qt::white), 9)); graph1->setPen(QPen(QColor(120, 120, 120), 2)); QCPGraph *graph2 = customPlot->addGraph(); graph2->setData(x2, y2); graph2->setPen(Qt::NoPen); graph2->setBrush(QColor(200, 200, 200, 20)); //graph2->setChannelFillGraph(graph1); QCPBars *bars1 = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(bars1); bars1->setWidth(9/(double)x3.size()); bars1->setData(x3, y3); bars1->setPen(Qt::NoPen); bars1->setBrush(QColor(10, 140, 70, 160)); // set some pens, brushes and backgrounds: customPlot->xAxis->setBasePen(QPen(Qt::white, 1)); customPlot->yAxis->setBasePen(QPen(Qt::white, 1)); customPlot->xAxis->setTickPen(QPen(Qt::white, 1)); customPlot->yAxis->setTickPen(QPen(Qt::white, 1)); customPlot->xAxis->setSubTickPen(QPen(Qt::white, 1)); customPlot->yAxis->setSubTickPen(QPen(Qt::white, 1)); customPlot->xAxis->setTickLabelColor(Qt::white); customPlot->yAxis->setTickLabelColor(Qt::white); customPlot->xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine)); customPlot->yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine)); customPlot->xAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine)); customPlot->yAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine)); customPlot->xAxis->grid()->setSubGridVisible(true); customPlot->yAxis->grid()->setSubGridVisible(true); customPlot->xAxis->grid()->setZeroLinePen(Qt::NoPen); customPlot->yAxis->grid()->setZeroLinePen(Qt::NoPen); customPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow); customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow); QLinearGradient plotGradient; plotGradient.setStart(0, 0); plotGradient.setFinalStop(0, 350); plotGradient.setColorAt(0, QColor(80, 8, 80)); plotGradient.setColorAt(1, QColor(50, 50, 50)); customPlot->setBackground(plotGradient); QLinearGradient axisRectGradient; axisRectGradient.setStart(0, 0); axisRectGradient.setFinalStop(0, 350); axisRectGradient.setColorAt(0, QColor(80, 80, 80)); axisRectGradient.setColorAt(1, QColor(30, 100, 0)); customPlot->axisRect()->setBackground(axisRectGradient); customPlot->rescaleAxes(); customPlot->yAxis->setRange(0, 2); }