Exemplo n.º 1
0
Arquivo: ab.c Projeto: F-A/pydstool
int main(int argc, char *argv[])
{
    AutoData *Data;
    doublereal u[3] = {0., 0., 0.};
    integer ipar[3] = {0, 1, 2};
    doublereal par[3] = {0., 14., 2.};
    
    Data = (AutoData *)MALLOC(sizeof(AutoData));

    BlankData(Data);
    DefaultData(Data);
    
    // Equilibrium points
    CreateSpecialPoint(Data,3,1,u,3,ipar,par,NULL,NULL,NULL,NULL);     // 9 = Beginning point, 1 = branch label
    Data->iap.irs = 1;      // Start from this point
    
    Data->print_input = 0;
    Data->print_output = 0;
    printf("\nEquilibrium points...\n");
    AUTO(Data);
    
    system("touch d.ab");
    system("cat fort.9 >> d.ab");
    system("rm fort.9");
    
    // Periodic orbits
    CleanupSolution(Data);
    DefaultData(Data);
    
    Data->iap.ips = 2;      // BVP
    Data->iap.irs = 4;      // Label of Hopf point
    Data->iap.ilp = 0;      // No detection of folds
    Data->iap.nicp = 2;     // Number of free parameters
    Data->iap.nmx = 150;    // Number of points on branch
    Data->iap.npr = 30;     // Output point and cycle after every npr steps
    Data->rap.dsmax = 0.5;  // Maximum arclength stepsize

    Data->icp = (integer *)REALLOC(Data->icp,Data->iap.nicp*sizeof(integer));
    Data->icp[1] = 10;      // Adds period to free parameters
    
    printf("\nPeriodic orbits...\n");
    AUTO(Data);
    
    system("touch d.ab");
    system("cat fort.9 >> d.ab");
    system("rm fort.9");
    
    // Fold points
    CleanupSolution(Data);
    DefaultData(Data);
    
    Data->iap.irs = 2;        // Label of limit point
    Data->iap.nicp = 2;       // Number of free parameters
    Data->iap.isp = 1;        // Turn on detection of branch points
    Data->iap.isw = 2;        // Controls branch switching (?)
    Data->rap.dsmax = 0.5;    // Maximum arclength stepsize
    Data->icp[1] = 2;         // 3rd parameter is free
    
    printf("\nFold points...\n");
    AUTO(Data);
    
    system("touch d.ab");
    system("cat fort.9 >> d.ab");
    system("rm fort.9");

    // Fold points (reverse)
    CleanupSolution(Data);
    DefaultData(Data);
    
    Data->iap.irs = 2;       // Label of limit point
    Data->iap.nicp = 2;      // Number of free parameters
    Data->iap.isp = 1;       // Turn on detection of branch points
    Data->iap.isw = 2;       // Controls branch switching (?)
    Data->rap.dsmax = 0.5;   // Maximum arclength stepsize
    Data->icp[1] = 2;        // 3rd parameter is free
    Data->rap.ds = -0.01;    // Stepsize (reverse)
    
    printf("\nFold points (reverse)...\n");
    AUTO(Data);
    
    system("touch d.ab");
    system("cat fort.9 >> d.ab");
    system("rm fort.9");

    // Hopf points (reverse)
    CleanupSolution(Data);
    DefaultData(Data);
    
    Data->iap.irs = 4;       // Label of hopf point
    Data->iap.nicp = 2;      // Number of free parameters
    Data->iap.isw = 2;       // Controls branch switching (?)
    Data->rap.dsmax = 0.5;   // Maximum arclength stepsize
    Data->icp[1] = 2;        // 3rd parameter is free
    Data->rap.ds = -0.01;    // Stepsize (reverse)
    
    printf("\nHopf points (reverse)...\n");
    AUTO(Data);
    
    system("touch d.ab");
    system("cat fort.9 >> d.ab");
    system("rm fort.9");
    
    CleanupAll(Data);
    
    return 0;
}
Exemplo n.º 2
0
// Assumes there has been a call to SetData before this.
int SetInitPoint(double *u, int npar, int *ipar, double *par, int *icp, int nups,
                       double *ups, double *udotps, double *rldot, int adaptcycle) {
    /* Still think I should get rid of typemap(freearg) and send address to pointer in
    prepare_cycle so I can realloc if necessary and not have to use this my_... crap */
    integer itp;
    integer i, j;
    integer SUCCESS = 1;
    double *my_ups = ups;
    double *my_udotps = udotps;
    double *my_rldot = rldot;

    if (ups == NULL)
        itp = 3;
    else {
        itp = 9;
        
        if (adaptcycle || udotps == NULL || rldot == NULL) {
            // NOTE: AUTO allocates (ntst+1)*ncol points, but only displays ntpl=ntst*ncol+1
            my_ups = (double *)MALLOC(gIData->iap.ncol*(gIData->iap.ntst+1)*(gIData->iap.ndim+1)*sizeof(double));
            my_udotps = (double *)MALLOC(gIData->iap.ncol*(gIData->iap.ntst+1)*gIData->iap.ndim*sizeof(double));
            my_rldot = (double *)MALLOC(gIData->iap.nicp*sizeof(double));
            prepare_cycle(gIData, ups, nups, my_ups, my_udotps, my_rldot);
        }
    }
    
    if (!CreateSpecialPoint(gIData, itp, 1, u, npar, ipar, par, icp, my_ups, my_udotps, my_rldot)) {
        fprintf(stderr,"*** Warning [interface.c]: Problem in CreateSpecialPoint.\n");
        fflush(stderr);
        SUCCESS = 0;
    }
    
    if ((SUCCESS) && (itp == 9) && (adaptcycle || udotps == NULL || rldot == NULL)) {
        integer nmx, npr, verbosity;
        double ds, dsmin, dsmax;
        
        // Adjust rldot and sp.nfpr = 1 (AUTO detects this to get udotps and rldot for
        //  starting point)
        gIData->sp[0].nfpr = 1;

        // Remove from here till } once findPeriodicOrbit is created
        FREE(my_ups);
        FREE(my_udotps);
        FREE(my_rldot);
        
        // Make sure initial point is on curve...
        nmx = gIData->iap.nmx;
        npr = gIData->iap.npr;
        ds = gIData->rap.ds;
        dsmin = gIData->rap.dsmin;
        dsmax = gIData->rap.dsmax;
        verbosity = gIData->verbosity;
        
        gIData->iap.nmx = 3;
        gIData->iap.npr = 3;
        gIData->rap.ds = min(1e-4, gIData->rap.ds);
        gIData->rap.dsmin = min(1e-4, gIData->rap.dsmin);
        gIData->rap.dsmax = min(1e-4, gIData->rap.dsmax);
        gIData->verbosity = 0;
        
        AUTO(gIData);
        CleanupSolution(gIData);
        
        gIData->iap.nmx = nmx;
        gIData->iap.npr = npr;
        gIData->rap.ds = ds;
        gIData->rap.dsmin = dsmin;
        gIData->rap.dsmax = dsmax;
        gIData->verbosity = verbosity;
        
        // Check for NaNs
        for (i=0; i<gIData->sp[0].nar; i++) {
            if (isnan(gIData->sp[1].u[i])) {
                fprintf(stderr,"*** Warning [interface.c]: NaNs in auto solution.\n");
                fflush(stderr);
                SUCCESS = 0;
                break;
            }
        }
        
        if (SUCCESS) {
            for (i=0; i<gIData->sp[0].nar; i++)
                gIData->sp[0].u[i] = gIData->sp[1].u[i];
            
            for (i=0; i<gIData->iap.ntst*gIData->iap.ncol+1; i++)
                for (j=0; j<gIData->iap.ndim+1; j++)
                    gIData->sp[0].ups[i][j] = gIData->sp[1].ups[i][j];
            
            for (i=0; i<gIData->iap.ntst*gIData->iap.ncol+1; i++)
                for (j=0; j<gIData->iap.ndim; j++)
                    gIData->sp[0].udotps[i][j] = gIData->sp[1].udotps[i][j];
            
            for (i=0; i<gIData->iap.nicp; i++)
                gIData->sp[0].rldot[i] = gIData->sp[1].rldot[i];
        }
        
        gIData->sp[0].nfpr = gIData->iap.nicp;
        
        FREE(gIData->sp[1].icp);
        FREE(gIData->sp[1].u);
        FREE(gIData->sp[1].rldot);
        FREE_DMATRIX(gIData->sp[1].ups);
        FREE_DMATRIX(gIData->sp[1].udotps);
        if (gIData->sflow) {
            FREE_DMATRIX_3D(gIData->sp[1].a1);
            FREE_DMATRIX_3D(gIData->sp[1].a2);
        }
        gIData->sp[1].icp = NULL;
        gIData->sp[1].u = NULL;
        gIData->sp[1].rldot = NULL;
        gIData->sp[1].ups = NULL;
        gIData->sp[1].udotps = NULL;
        gIData->sp[1].a1 = NULL;
        gIData->sp[1].a2 = NULL;
        
        gIData->num_sp = 1;
        gIData->sp_len = 1;
        
        gIData->sp = (AutoSPData *)REALLOC(gIData->sp, (gIData->num_sp)*sizeof(AutoSPData));
    }
    
    return SUCCESS;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    AutoData *Data;
    doublereal *cycle;
    doublereal *ups, *udotps, *rldot;
    doublereal period;
    integer i, j;
    doublereal u[3] = {0., 0., 0.};
    integer ipar[4] = {0, 1, 2, 10};
    doublereal par[4] = {280., 2.6666666666666665, 10., 0.4332};
    
    Data = (AutoData *)MALLOC(sizeof(AutoData));
    
    BlankData(Data);
    DefaultData(Data);
    Data->iap.irs = 1;
    Data->iap.ips = 2;
    Data->iap.ilp = 0;
    Data->iap.ndim = 3;
    Data->iap.nicp = 2;
    Data->iap.ntst = 20;
    Data->iap.ncol = 4;
    Data->iap.isp = 2;
    Data->rap.ds = -0.5;
    Data->rap.dsmin = 0.01;
    Data->rap.dsmax = 25.0;
    Data->rap.epsl = 1e-7;
    Data->rap.epsu = 1e-7;
    Data->rap.epss = 0.0001;
    Data->iap.nmx = 50;
    Data->rap.rl0 = 200.;
    Data->rap.rl1 = 400.;
    
    // Load data from lor.dat
    FILE *fp = fopen("lor.dat","r");
    if (fp == NULL) {
        fprintf(stdout,"Error:  Could not open lor.dat\n");
        exit(1);
    }
    cycle = (doublereal *)MALLOC(4*117*sizeof(doublereal));
    for (j=0; j<117; j++) {
        fscanf(fp,"%lf",&cycle[4*j]);
        for (i=0; i<3; i++) {
            fscanf(fp,"%lf",&cycle[1+i+j*4]);
        }
    }
    fclose(fp);
    
    // Tweak times
    period = cycle[4*116] - cycle[0];
    for (i=116; i>=0; i--)
        cycle[4*i] = (cycle[4*i] - cycle[0])/period;
    
    ups = (doublereal *)MALLOC((Data->iap.ncol*Data->iap.ntst+1)*(Data->iap.ndim+1)*sizeof(doublereal));
    udotps = (doublereal *)MALLOC((Data->iap.ncol*Data->iap.ntst+1)*Data->iap.ndim*sizeof(doublereal));
    rldot = (doublereal *)MALLOC(Data->iap.nicp*sizeof(doublereal));
    prepare_cycle(Data,cycle, 117, ups, udotps, rldot);
        
    Data->icp = (integer *)REALLOC(Data->icp,Data->iap.nicp*sizeof(integer));
    Data->icp[1] = 10;
    
    // Create special point
    CreateSpecialPoint(Data,9,1,u,4,ipar,par,Data->icp,ups,udotps,rldot);
    
    AUTO(Data);
    
    CleanupAll(Data);
    return 0;
}