void Problem2Backward2D::layerInfo(const DoubleMatrix &p, unsigned int ln) const { C_UNUSED(p); C_UNUSED(ln); // if (p.min()<MinB) MinB = p.min(); // if (p.max()>MaxB) MaxB = p.max(); // printf("%f %f\n", MinB, MaxB); // QPixmap px; // visualizeMatrixHeat(p, p.min(), p.max(), px); // px.save(QString("pics/p/p%1.png").arg(ln), "PNG"); // if (ln==timeDimension().sizeN()) // { //// IPrinter::printSeperatorLine("P100"); //// IPrinter::printMatrix(p); //// IPrinter::printSeperatorLine(); // QPixmap px; // visualizeMatrixHeat(p, p.min(), p.max(), px); // px.save(QString("p%1").arg(ln), "PNG"); // } // if (ln==0) // { //// IPrinter::printSeperatorLine("P0"); //// IPrinter::printMatrix(p); //// IPrinter::printSeperatorLine(); // QPixmap px; // visualizeMatrixHeat(p, p.min(), p.max(), px); // px.save("p0.png", "PNG"); // } }
double HeatControl2Delta::bf(unsigned int i, unsigned int j, unsigned int k) const { C_UNUSED(i); C_UNUSED(j); C_UNUSED(k); return 0.0; }
void HeatControl2Delta::print(unsigned int i, const DoubleVector& x, const DoubleVector &g, double fx, GradientMethod::MethodResult result) const { C_UNUSED(alpha); C_UNUSED(fx); C_UNUSED(result); HeatControl2Delta *hc = const_cast<HeatControl2Delta*>(this); printf("J[%d]: %.16f\n", i, hc->fx(x)); //printf("Norm: %.16f Alpha: %.16f %.16f\n", hc->norm(x), hc->alpha, alpha); printf("eo: [%12.8f, %12.8f] [%12.8f, %12.8f] [%12.8f, %12.8f]\n", O[0], O[1], O[2], O[3], O[4], O[5]); printf("e1: [%12.8f, %12.8f] [%12.8f, %12.8f] [%12.8f, %12.8f]\n", x[0], x[1], x[2], x[3], x[4], x[5]); printf("g1: [%12.8f, %12.8f] [%12.8f, %12.8f] [%12.8f, %12.8f]\n", g[0], g[1], g[2], g[3], g[4], g[5]); #ifdef POWER_OPTIMIZE IPrinter::printVector(x, "f1:", 10, 2*L+0*(M+1), 2*L+0*(M+1) + M); IPrinter::printVector(x, "f2:", 10, 2*L+1*(M+1), 2*L+1*(M+1) + M); IPrinter::printVector(x, "f3:", 10, 2*L+2*(M+1), 2*L+2*(M+1) + M); #endif // DoubleMatrix u; // hc->calculateU(x, u); // char filename1[100]; // char filename2[100]; // int count1 = sprintf(filename1, "optimal%d.txt", i); // filename1[count1] = '\0'; // int count2 = sprintf(filename2, "optimal%d.png", i); // filename2[count2] = '\0'; // hc->write(filename2, u); // system("imager.exe -w 101 -h 101 -i optimal1.txt -o optimal3.png"); // DoubleVector f(hc->M+1); // for (unsigned int k=0; k<=M; k++) f[k] = x[2*hc->L+0*(M+1)+k]; // Printer::printVector(f, 10, "g1"); // for (unsigned int k=0; k<=M; k++) f[k] = x[2*hc->L+1*(M+1)+k]; // Printer::printVector(f, 10, "g2"); // for (unsigned int k=0; k<=M; k++) f[k] = x[2*hc->L+2*(M+1)+k]; // Printer::printVector(f, 10, "g3"); // DoubleVector fg(hc->M+1); // for (unsigned int k=0; k<=M; k++) fg[k] = g[2*hc->L+0*(M+1)+k]; // Printer::printVector(fg, 10, "fg1"); // for (unsigned int k=0; k<=M; k++) fg[k] = g[2*hc->L+1*(M+1)+k]; // Printer::printVector(fg, 10, "fg2"); // for (unsigned int k=0; k<=M; k++) fg[k] = g[2*hc->L+2*(M+1)+k]; // Printer::printVector(fg, 10, "fg3"); puts("+------------------------------------------------------------------------------------------------------------------------------------------------------------------+"); // hc->calculateU(e, hc->uT); // char buffer [12]; // int n=sprintf (buffer, "file%d.txt", i); // hc->write(buffer, hc->uT); }
void HeatControl2Delta::calculateGF(const DoubleVector &x, const DoubleMatrix& psi, DoubleVector& g, unsigned int k) { C_UNUSED(k); for (unsigned k=0; k<=M; k++) { if (alpha < 1.0) { g[2*L+0*(M+1)+k] = 0.0; g[2*L+1*(M+1)+k] = 0.0; g[2*L+2*(M+1)+k] = 0.0; } else { double p[L]; p[0]=p[1]=p[2]=0.0; for (unsigned int j=0; j<=N2; j++) { for (unsigned int i=0; i<=N1; i++) { if (fabs(x[0]-i*h1)<h1 && fabs(x[1]-j*h2)<h2) p[0] += psi[j][i]*((h1-fabs(x[0]-i*h1))/h1)*((h2-fabs(x[1]-j*h2))/h2); if (fabs(x[2]-i*h1)<h1 && fabs(x[3]-j*h2)<h2) p[1] += psi[j][i]*((h1-fabs(x[2]-i*h1))/h1)*((h2-fabs(x[3]-j*h2))/h2); if (fabs(x[4]-i*h1)<h1 && fabs(x[5]-j*h2)<h2) p[2] += psi[j][i]*((h1-fabs(x[4]-i*h1))/h1)*((h2-fabs(x[5]-j*h2))/h2); } } g[2*L+0*(M+1)+k] = -p[0] + 2.0*alpha*(x[2*L+0*(M+1)+k] - v1(k*ht)); g[2*L+1*(M+1)+k] = -p[1] + 2.0*alpha*(x[2*L+1*(M+1)+k] - v2(k*ht)); g[2*L+2*(M+1)+k] = -p[2] + 2.0*alpha*(x[2*L+2*(M+1)+k] - v3(k*ht)); } } }
void Problem2Forward2D::layerInfo(const DoubleMatrix &u, unsigned int ln) const { C_UNUSED(u); C_UNUSED(ln); // if (u.min()<Min) Min = u.min(); // if (u.max()>Max) Max = u.max(); // printf("%f %f\n", Min, Max); // QPixmap px; // visualizeMatrixHeat(u, 0.2, 15.344541, px); // px.save(QString("pics/u/u%1.png").arg(ln), "PNG"); // QPixmap pixmap; // visualizeMatrixHeat(u, u.min(), u.max(), pixmap, u.cols(), u.rows()); // pixmap.save(QString("image%1.png").arg(n), "PNG"); }
void HeatControl2Delta::calculateG2(const DoubleVector &x, DoubleVector& g1) { C_UNUSED(x); C_UNUSED(g1); // double h = 0.01; // DoubleVector E(2*L); // DoubleVector g(2*L); // double f0 = fx(x); // for (unsigned int i=0; i<x.size(); i++) // { // E = x; // E[i] += h; // double f1 = fx(E); // g[i] = (f1-f0)/h; // } // printf("e2: %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n", x[0], x[1], x[2], x[3], x[4], x[5]); // printf("g2: %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n", g[0], g[1], g[2], g[3], g[4], g[5]); }
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { C_UNUSED(hInstance); C_UNUSED(hPrevInstance); C_UNUSED(lpCmdLine); C_UNUSED(nCmdShow); #else int main() { #endif printf("Hello world, C\n"); #ifdef __cplusplus MyClass instance; return instance.returnValue(); #else return 0; #endif }
void DiscreteHeat::print(unsigned int i, const DoubleVector &f, const DoubleVector &g, double alpha, RnFunction *fn) const { C_UNUSED(g); C_UNUSED(alpha); printf("J[%d]: %.12f\n", i, fn->fx(f)); }
void DiscreteHeat::calculateP(const DoubleVector &f, const DoubleVector &u, DoubleMatrix &psi, DoubleVector &g) { C_UNUSED(f); C_UNUSED(g); double lamda = -(a*ht)/(hx*hx); double k = 1.0-2.0*lamda; psi.clear(); psi.resize(M+1, N+1); DoubleVector a1(N-1); DoubleVector b1(N-1); DoubleVector c1(N-1); DoubleVector d1(N-1); DoubleVector x1(N-1); for (unsigned int m=0; m<=M; m++) { unsigned int j = M-m; if (j==M) { for (unsigned int i=1; i<=N-1; i++) { a1[i-1] = lamda; b1[i-1] = k; c1[i-1] = lamda; d1[i-1] = -2.0*hx*(u[i]-U[i]); } a1[0] = 0.0; c1[N-2] = 0.0; tomasAlgorithm(a1.data(), b1.data(), c1.data(), d1.data(), x1.data(), x1.size()); for (unsigned int i=1; i<=N-1; i++) { psi[j][i] = x1[i-1]; } psi[j][0] = -lamda*psi[j][1] -2.0*hx*0.5*(u[0]-U[0]); psi[j][N] = -lamda*psi[j][N-1] -2.0*hx*0.5*(u[N]-U[N]); } else if (j==0) { psi[j][0] = -lamda*psi[j][1]; psi[j][N] = -lamda*psi[j][N-1]; for (unsigned int i=1; i<=N-1; i++) { psi[j][i] = psi[j+1][i]; } } else { for (unsigned int i=1; i<=N-1; i++) { a1[i-1] = lamda; b1[i-1] = k; c1[i-1] = lamda; d1[i-1] = +psi[j+1][i]; } a1[0] = 0.0; c1[N-2] = 0.0; tomasAlgorithm(a1.data(), b1.data(), c1.data(), d1.data(), x1.data(), x1.size()); for (unsigned int i=1; i<=N-1; i++) { psi[j][i] = x1[i-1]; } psi[j][0] = -lamda*psi[j][1]; psi[j][N] = -lamda*psi[j][N-1]; } } a1.clear(); b1.clear(); c1.clear(); d1.clear(); x1.clear(); }
double DiscreteHeat::fxt(double x, double t) { C_UNUSED(x); return 2.0*t - 2.0*a; }