Beispiel #1
0
PyObject* ClearSolution( void ) {
    PyObject *OutObj = NULL;
    
    if (!CleanupSolution(gIData)) {
        OutObj = Py_BuildValue("(i)", 0);
        assert(OutObj);
    } else {
        OutObj = Py_BuildValue("(i)", 1);
        assert(OutObj);
    }
    
    return OutObj;
}
int CleanupAll(AutoData *Data) {
    int result = 1;
    
    if (Data != NULL) {
        result = result && (CleanupParams(Data));
        result = result && (CleanupSolution(Data));
        result = result && (CleanupSpecialPoints(Data));
        
        FREE(Data);
        Data = NULL;
    }
    
    return result;
}
Beispiel #3
0
PyObject* Reset( void ) {
    int result = 1;
    PyObject *OutObj = NULL;

    result = result && (CleanupSolution(gIData));
    result = result && (CleanupSpecialPoints(gIData));
    
    DefaultData(gIData);
    
    OutObj = Py_BuildValue("(i)", result);
    assert(OutObj);
    
    return OutObj;
}
Beispiel #4
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;
}
Beispiel #5
0
Datei: ab.c Projekt: 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;
}