Exemple #1
0
 int runge(double EPS, const char*filename)
{
    struct vect v; // основной вектор координат
	struct vect k[DIM]; // числа Рунгe

	//*инициализация чисел Рунге */
	for (int i=0;i<DIM;i++)
    	init(k + i,RK_NUM);
    
    /* Вектор функций и расчётные коэффициенты */
    double (*f[DIM]) (struct vect v, double t);
	struct vect a, p, pp; 
	struct vect b[RK_NUM];

	/* инициализация вектора функций и коэффициентов */
	Create_Vect_func(f); //
	RK_koeff(b,&a,&p,&pp);


    double h = H_0; // шаг
    double t = 0; // время
	
    double errflag = 0;

    
    FILE *file = fopen(filename, "w");

    if (file == NULL) errflag = -1;
    else{
        fprintf(file, "t \t x \t y\n");

        /* вводим начальные условия */
        initials(&v);
        printf("%d\n",a.length);
        print(v);
        		//runge_step(&h,v,t, f, b, a, k);// вводим начальные значения чисел Рунге
	    
	    //h = new_h(EPS,h,k,v); // обновляем шаг
        
        //new_k(h,k,x,y,u,v); // ежели он изменился -- обновим числа Рунге

        for (t = 0;t<=WORK_TIME+h;t+=h){
            // если мы в нужной точке T, 3T/4, T/2, T/4, то flag == 1 

        	/* обновим координаты */

    
    /*    	

    		fprintf(file, "%e", t);
            fprint(v,file);
            fprintf(file, "\n");
    */
            h = new_step( EPS,  h,  t,  v,  k,  a,  b,  p,  pp, f);
			
			/* обновляем числа Рунге */
    

//   printf("(!)\n" );
            fprintf(file, "%e", t);
            fprint(v,file);
            fprintf(file, "\n");


            runge_step(h,v,t, f, b, a, k);

            new_parametrs(h,t,&v,k,p);

            if (h<H_DEFAULT) {errflag = -3; break;} // на случай особых точек
        }
    }
    printf("final step = %e;\n", h);
    fclose(file);
    return errflag;
}
Exemple #2
0
static void
sH(void *userData, const char *name, const char **atts)
{
  charData_discard();
  if (!strcmp(name,"system"))
    {
      const char *det;
      const char *mev;
      char *endll;
      mev = findAttr(atts,"mev");
      curr_system = new_system();
      curr_system->n = (const char *)npool_copy((unsigned char *)findAttr(atts,"n"),context->cpool);
      curr_system->mev = new_count();
      curr_system->mev->num = strtoll(mev,&endll,10);
      curr_system->mev->den = (int)strtol(endll+1,&endll,10);
      curr_system->meu = (char *)npool_copy((unsigned char *)endll,
					    context->cpool);
      hash_add(context->systems,
	       (const unsigned char *)curr_system->n,curr_system);
      if ((det = findAttr(atts,"det")))
	hash_add(context->sysdets,
		 npool_copy((unsigned char*)det,context->cpool),
		 curr_system);
    }
  else if (!strcmp(name,"step"))
    {
      struct nsa_step *curr_step = new_step();
      const char *overt = findAttr(atts,"overt");
      const char *aev = findAttr(atts,"aev");
      const char *sex = findAttr(atts,"sex");
      char *slash;
      int overt_star;

      curr_step->ecf = (const char *)npool_copy((unsigned char *)findAttr(atts,"ecf"),context->cpool);
      curr_step->etr = (const char *)npool_copy((unsigned char *)findAttr(atts,"etr"),context->cpool);
      curr_step->atf = (const char *)npool_copy((unsigned char *)findAttr(atts,"atf"),context->cpool);
      curr_step->utf = (const char *)npool_copy((unsigned char *)findAttr(atts,"utf"),context->cpool);
      if (sex && *sex == 'a') /* horrible cheat! */
	curr_step->sex = nsa_sex_asz_axis;
      curr_step->sys = curr_system;
      list_add(curr_system->steps,curr_step);
      if (aev && *aev)
	{
	  curr_step->aev = new_count();
	  slash = strchr(aev,'/');
	  if (!slash)
	    {
	      fprintf(stderr,"nsa: system %s/step %s: bad AEV (should be n/1; actual='%s')\n",curr_system->n,curr_step->atf,aev);
	      curr_step->aev->num = 0;
	      curr_step->aev->den = 1;
	    }
	  else
	    {
	      curr_step->aev->num = strtoll(aev,NULL,10);
	      curr_step->aev->den = (int)strtol(slash+1,NULL,10);
	    }
	}
      curr_step->node = curr_system->steps->last;
      curr_step->sys = curr_system;
      if (!overt || !*overt || strcmp(overt,"no"))
	overt_star = 0;
      else
	overt_star = 1;
      /*	  sH_index_step(curr_step->ecf, curr_step); */
      /* sH_index_step(curr_step->etr, curr_step); */
      sH_index_step(curr_step->utf, curr_step, overt_star);
      if (curr_step->atf && strcmp(curr_step->utf,curr_step->atf))
	sH_index_step(curr_step->atf, curr_step, overt_star);
    }
  else if (!strcmp(name,"ok-com-heads"))
    {
      curr_comhead_sys = (const char *)npool_copy((unsigned char *)findAttr(atts,"sys"),context->cpool);
    }
  else if (!strcmp(name,"igi"))
    last_u = (char *)npool_copy((unsigned char *)findAttr(atts,"u"),context->cpool);
}