Example #1
0
int
main (int argn, char **argc)
{
  double x, y;
  FILE *file;
  file = fopen (argc[1], "r");
  fscanf (file, "%*s%lf%*s%lf", &x, &y);
  fclose (file);
  file = fopen (argc[2], "w");
  fprintf (file, "%.14le", Rosenbrock (x - M_PI_4, y - M_PI_4));
  fclose (file);
  return 0;
}
Example #2
0
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void INTEGRATE( KPP_REAL TIN, KPP_REAL TOUT )
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
{
   static KPP_REAL  RPAR[20];
   static int  i, IERR, IPAR[20];
   static int Ns=0, Na=0, Nr=0, Ng=0;

   for ( i = 0; i < 20; i++ ) {
     IPAR[i] = 0;
     RPAR[i] = ZERO;
   } /* for */
   
   
   IPAR[0] = 0;    /* non-autonomous */
   IPAR[1] = 1;    /* vector tolerances */
   RPAR[2] = STEPMIN; /* starting step */
   IPAR[3] = 5;    /* choice of the method */

   IERR = Rosenbrock(VAR, TIN, TOUT,
           ATOL, RTOL,
           &FunTemplate, &JacTemplate,
           RPAR, IPAR);

	     
   Ns=Ns+IPAR[12];
   Na=Na+IPAR[13];
   Nr=Nr+IPAR[14];
   Ng=Ng+IPAR[17];
   printf("\n Step=%d  Acc=%d  Rej=%d  Singular=%d\n",
         Ns,Na,Nr,Ng);


   if (IERR < 0)
     printf("\n Rosenbrock: Unsucessful step at T=%g: IERR=%d\n",
         TIN,IERR);
   
   TIN = RPAR[10];      /* Exit time */
   STEPMIN = RPAR[11];  /* Last step */
   
} /* INTEGRATE */
Example #3
0
/**
 * Runs KPP-generated SAPRC'99 chemical process in vector data buffer
 */
void saprc99_buffer(uint32_t i)
{
    /* Iterators */
    uint32_t j, k;
    
    /* Integration method statistics.
     * (Used to detect limit violation.) */
    static int stats[8];    
    
    /* Integration method parameters */
    real_t RPAR[20];
    int    IPAR[20];
    int    IERR = 0;
    
    /* Initalize parameters */
    for(j=0; j<20; j++)
    {
        IPAR[j] = 0;
        RPAR[j] = 0.0;
    }
    IPAR[0] = 0;        /* non-autonomous */
    IPAR[1] = 1;        /* scalar tolerances */
    RPAR[2] = STEPMIN;  /* starting step */
    IPAR[3] = 5;        /* method selection: Rodas4 */
    
    wait_for_dma(i);
    
    for(j=0; j<VECTOR_LENGTH; j++)
    {
        /* Deinterlace data */
        for(k=0; k<NSPEC; k++)
        {
            conc[1].data[k] = conc[0].data[k*VECTOR_LENGTH+j];
        }
        
        /* Point method at current data */
        C   = &(conc[1].data[0]);
        VAR = &(conc[1].data[0]);
        FIX = &(conc[1].data[NFIXST]);
        
        /* Reset statistics for each integration */
        for(k=0; k<8; k++)
        {
            IPAR[10+k] = stats[k];
        }
        IPAR[12] = 0;
        
        /* Integrate */
        #if DO_CHEMISTRY == 1   /* Need this here for linker */
        IERR = Rosenbrock(VAR, TIME, TIME+DT, ATOL, RTOL, RPAR, IPAR);
        #endif
        
        if(IERR < 0)
        {
            printf("\n Rosenbrock: Unsucessful step at T=%g: IERR=%d\n", TIME, IERR);
            set_status(SPE_STATUS_STOPPED);
            exit(1);
        }
         
        /* Reinterlace data */
        for(k=0; k<NSPEC; k++)
        {
            conc[0].data[k*VECTOR_LENGTH+j] = conc[1].data[k];
        }
    }
    
    /* Record final statistics */
    for(k=0; k<8; k++)
    {
        stats[k] = IPAR[10+k];
    }
    
    /* Record last step for next method invocation */
    STEPMIN = RPAR[11];
}
Example #4
0
/**
 * Runs KPP-generated SAPRC'99 chemical process in vector data buffer
 */
void saprc99_buffer(uint32_t i)
{
    /* Iterators */
    uint32_t j, k;
    
    /* Integration method parameters */
    static real_t RPAR[20];
    static int    IPAR[20];
    static int    IERR;
    
    /* Integration method statistics */
    static int Ns=0, Na=0, Nr=0, Ng=0;
    
    /* Initalize parameters */
    for(j=0; j<20; j++)
    {
        IPAR[i] = 0;
        RPAR[i] = 0.0;
    }
    IPAR[0] = 0;        /* non-autonomous */
    IPAR[1] = 1;        /* scalar tolerances */
    RPAR[2] = STEPMIN;  /* starting step */
    IPAR[3] = 5;        /* method selection: Rodas4 */
    
    wait_for_dma(i);
    
    for(j=0; j<VECTOR_LENGTH; j++)
    {
        /* Deinterlace data */
        for(k=0; k<NSPEC; k++)
        {
            conc[1].data[k] = conc[0].data[k*VECTOR_LENGTH+j];
        }
        
        /* Point method at current data */
        C   = &(conc[1].data[0]);
        VAR = &(conc[1].data[0]);
        FIX = &(conc[1].data[NFIXST]);
        
        /* Integrate */
        IERR = Rosenbrock(VAR, TIME, TIME+DT, ATOL, RTOL, RPAR, IPAR);
        
        if(IERR < 0)
        {
            printf("\n Rosenbrock: Unsucessful step at T=%g: IERR=%d\n", TIME, IERR);
        }
         
        /* Reinterlace data */
        for(k=0; k<NSPEC; k++)
        {
            conc[0].data[k*VECTOR_LENGTH+j] = conc[1].data[k];
        }
    }
    
    /* Record statistics */
    Ns += IPAR[12];
    Na += IPAR[13];
    Nr += IPAR[14];
    Ng += IPAR[17];
    
    /* Record last step for next method invocation */
    STEPMIN = RPAR[11];
}