示例#1
0
main(int argc, char* argv[]){ 
    static vec u(K+1);
    int k,n;
    std::string op=argv[1]; // command line argument
	val dx=1.0/K, dt=T/N, dx4=dx*dx*dx*dx, xk, tn; // discretization variables

    // Initialize
    for(k=0;k<=K;k++){
        xk=k*dx;
        u(k)=f(xk);
    }
    if(op=="plot") printf("set terminal x11 noraise\nset yrange [-5:5]\nset style data lines\n\n");

    val rho=NU*dt/dx4;    // rho = nu*dt/dx^4
    vec temp(K+1);
    temp=u;

    for(n=0;n<=N;n++){
		tn=n*dt;
        u=temp;
        for(k=0;k<=K;k++){   
            xk=k*dx;
            temp(k) = u(k) - rho*delta4(u,k);    
            //printu(u,tn,xk,K);
        }
        if(op=="plot0") plot0(u, tn, K-1, N);
        if(op=="plot1") plot1(u, tn, K-1, N);
        if(op=="plot3d") plot3d(u, tn, K-1, N);
        if(op=="approx") output(tn, 0.5, u(K/2), K-1, N);
    }

    return 0;
}
示例#2
0
文件: A2.cpp 项目: nMerlin/CP
//main
int main () {
	int N = 100;
	std::string pfad = "./";
	
	plot (std::bind(&fraunhofer,std::placeholders::_1,N),pfad,"Iq",51,0,5);
	plot3d (std::bind(&fraunhofer_viertel,std::placeholders::_1,std::placeholders::_2,N),pfad,"Iqxqy",61,-6,6);
}
示例#3
0
文件: A3.cpp 项目: nMerlin/CP
//Funktion nimmt gewünschte Anfangsbedingungen und erstellt passende Plots für Aufgabe 3c
void A3c(std::vector<double> y, std::string name, double h) {
	int N = ceil(100/h);
	std::vector<double> LR;

	std::ofstream a3_r(("./" + name + "_r.dat").c_str());
	std::ofstream a3_LR_x(("./" + name + "_LR_x.dat").c_str());
	std::ofstream a3_LR_y(("./" + name + "_LR_y.dat").c_str());
	std::ofstream a3_LR_z(("./" + name + "_LR_z.dat").c_str());
	std::ofstream a3_LR(("./" + name + "_LR.dat").c_str());
	
	for (int i = 0; i < N; i++) {
		y = Runge_Kutta(&F2,y,h,h*i);
		
		LR = LenzRunge(y);
		
		a3_r << y[0] << " " << y[1] << " " << y[2] << std::endl;
		a3_LR_x << i*h << " " << LR[0] << std::endl;
		a3_LR_y << i*h << " " << LR[1] << std::endl;
		a3_LR_z << i*h << " " << LR[2] << std::endl;
		a3_LR << 0 << " " << 0 << " " << 0 << " " << LR[0] << " " << LR[1] << " " << LR[2] << std::endl;
	}
	
	a3_r.close();
	a3_LR_x.close();
	a3_LR_y.close();
	a3_LR_z.close();
	a3_LR.close();
	
	//plot3d("./",name+"_r");
	//plot("./",name+"_LR_x");
	//plot("./",name+"_LR_y");
	//plot("./",name+"_LR_z");
	plot3d("./",name+"_r");
}
示例#4
0
文件: A3.cpp 项目: nMerlin/CP
//Funktion nimmt gewünschte Anfangsbedingungen und erstellt passende Plots für Aufgabe 2a
void A3a(std::vector<double> y, std::string name, double h) {
	int N = ceil(100/h);
	//int size_y = y.size();
	std::ofstream a3_r(("./" + name + "_r.dat").c_str());
	
	for (int i = 0; i < N; i++) {
		y = Runge_Kutta(&F2,y,h,h*i);
		a3_r << y[0] << " " << y[1] << " " << y[2] << std::endl;
	}
	
	a3_r.close();
	
	plot3d("./",name+"_r");
}
示例#5
0
main(int argc, char* argv[]){ 
    int k,n,i,j;
    std::string op=argv[1]; // command line argument
	val dx=1.0/K, dt=T/N, dx4=dx*dx*dx*dx, xk, tn; // discretization variables
    val rho=NU*dt/dx4;    // rho = nu*dt/dx^4
    static vec u(K-1), v(K+1);
    
    // We allocate 2 lower & 4 upper diagonal, according to the example
    static banded_matrix<val> U(K-1, K-1, 2, 4);
    vector<fortran_int_t> p(K-1);
    
    // Initialize matrix
    for(i=0; i<U.size1(); i++){
            U(i,i)=1.0+6.0*rho; 
            k=std::max(i-1,1);
            U(k,k-1)=U(k-1,k)=-4.0*rho;
            U(k,k+1)=U(k+1,k)=-4.0*rho;
            k=std::max(i-2,2);
            U(k,k-2)=U(k-2,k)=1.0*rho;
            U(k,k+2)=U(k+2,k)=1.0*rho;
        }
    // Boundary Conditions
    U(0,0)-=1.0*rho;
    U(K-2,K-2)-=1.0*rho;
    if(op=="matrix"){ printf("Pentadiagonal Matrix\n"); matprintf(U);}

    // Initial conditions
    for(k=0;k<=K;k++){
        xk=k*dx;
        v(k)=f(xk);
    }
    u=subrange(v,1,K);
    //printf("Original Vector\n"); vecprintf(u,dx);

    lapack::gbtrf(U, p); // LU-decompostion
    for(n=0;n<=N;n++){
        tn=n*dt;
        lapack::gbtrs(U, p, u); // Solve
        if(op=="plot0") plot0(u, tn, K-1, N);
        if(op=="plot1") plot1(u, tn, K-1, N);
        if(op=="plot3d" && (n-1)%NMOD==0) plot3d(u, tn, K-1, N);
        if(op=="approx") output(tn, 0.5, u(K/2-1), K-1, N);
    }
    return 0;
}
示例#6
0
文件: A3.cpp 项目: nMerlin/CP
//Erwartet mit y geeignete 3D-Anfangsbedingungen und erstellt Plots für Energie und Drehimpuls
void A3b(std::vector<double> y, std::string name, double h) {
	int N = ceil(100/h);	//100 ist die Gesamtzeit
	double E_kin, E_pot, E_ges;
	double _L;
	//int size_y = y.size();
	std::ofstream a3_r(("./" + name + "_r.dat").c_str());
	std::ofstream a3_ekin(("./" + name + "_ekin.dat").c_str());
	std::ofstream a3_epot(("./" + name + "_epot.dat").c_str());
	std::ofstream a3_eges(("./" + name + "_eges.dat").c_str());
	std::ofstream a3_L(("./" + name + "_L.dat").c_str());
	
	for (int i = 0; i < N; i++) {
		y = Runge_Kutta(&F2,y,h,h*i);
		E_kin = 0.5*(y[3]*y[3]+y[4]*y[4]+y[5]*y[5]);
		E_pot = -1/sqrt(y[0]*y[0]+y[1]*y[1]+y[2]*y[2]);
		E_ges = E_kin + E_pot;
		_L = betrag(L(y));
		a3_r << y[0] << " " << y[1] << " " << y[2] << std::endl;
		a3_ekin << h*i << " " << E_kin << std::endl;
		a3_epot << h*i << " " << E_pot << std::endl;
		a3_eges << h*i << " " << E_ges << std::endl;
		a3_L << h*i << " " << _L << std::endl;
	}
	
	a3_r.close();
	a3_ekin.close();
	a3_epot.close();
	a3_eges.close();
	a3_L.close();
	
	plot3d("./",name+"_r");
	plot("./",name+"_ekin");
	plot("./",name+"_epot");
	plot("./",name+"_eges");
	plot("./",name+"_L");
}
示例#7
0
int
main(int argc, char *argv[])
{
  int i, j, k;
  PLFLT *x, *y, **z;
  PLFLT xx, yy;
  int nlevel = LEVELS;
  PLFLT clevel[LEVELS];
  PLFLT zmin, zmax, step;

  /* Parse and process command line arguments */

  (void) plparseopts(&argc, argv, PL_PARSE_FULL);

  /* Initialize plplot */

  plinit();

  x = (PLFLT *) calloc(XPTS, sizeof(PLFLT));
  y = (PLFLT *) calloc(YPTS, sizeof(PLFLT));

  plAlloc2dGrid(&z, XPTS, YPTS);
  for (i = 0; i < XPTS; i++) {
    x[i] = 3. * (double) (i - (XPTS / 2)) / (double) (XPTS / 2);
  }

  for (i = 0; i < YPTS; i++)
    y[i] = 3.* (double) (i - (YPTS / 2)) / (double) (YPTS / 2);

  for (i = 0; i < XPTS; i++) {
    xx = x[i];
    for (j = 0; j < YPTS; j++) {
      yy = y[j];
      z[i][j] = 3. * (1.-xx)*(1.-xx) * exp(-(xx*xx) - (yy+1.)*(yy+1.)) -
	10. * (xx/5. - pow(xx,3.) - pow(yy,5.)) * exp(-xx*xx-yy*yy) -
	1./3. * exp(-(xx+1)*(xx+1) - (yy*yy));
		 
      if(0) { /* Jungfraujoch/Interlaken */
	if (z[i][j] < -1.)
	  z[i][j] = -1.;
      }
    }
  }

  plMinMax2dGrid(z, XPTS, YPTS, &zmax, &zmin);  
  step = (zmax - zmin)/(nlevel+1);
  for (i=0; i<nlevel; i++)
    clevel[i] = zmin + step + step*i;

  cmap1_init();
  for (k = 0; k < 2; k++) {
    for (i=0; i<4; i++) {
      pladv(0);
      plcol0(1);
      plvpor(0.0, 1.0, 0.0, 0.9);
      plwind(-1.0, 1.0, -1.0, 1.5);
      plw3d(1.0, 1.0, 1.2, -3.0, 3.0, -3.0, 3.0, zmin, zmax, alt[k], az[k]);
      plbox3("bnstu", "x axis", 0.0, 0,
	     "bnstu", "y axis", 0.0, 0,
	     "bcdmnstuv", "z axis", 0.0, 4);

      plcol0(2);

      /* wireframe plot */
      if (i==0)
	plmesh(x, y, z, XPTS, YPTS, opt[k]);

      /* magnitude colored wireframe plot */
      else if (i==1)
	plmesh(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR);

      /* magnitude colored wireframe plot with sides */
      else if (i==2)
	plot3d(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR, 1);

      /* magnitude colored wireframe plot with base contour */
      else if (i==3)
	plmeshc(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR | BASE_CONT,
		clevel, nlevel);

      plcol0(3);
      plmtex("t", 1.0, 0.5, 0.5, title[k]);
    }
  }

/* Clean up */
  
  free((void *) x);
  free((void *) y);
  plFree2dGrid(z, XPTS, YPTS);

  plend();

  exit(0);
}