/*! \fn MFImplicitMF MFIMFCreateSphere(double x,double y,double z,double R, MFErrorHandler e); * \brief Creates an implicitly defined manifold for a 2-sphere embedded in 3-space, centered at (x,y,z) with * radius R. * * \param x The x coordinate of the center of the sphere * \param y The y coordinate of the center of the sphere * \param z The z coordinate of the center of the sphere * \param R The radius. * \param e An error handler. * \returns An implicitly defined manifold. */ MFImplicitMF MFIMFCreateSphere(double x,double y,double z,double R, MFErrorHandler e) { static char RoutineName[]={"MFIMFCreateSphere"}; MFImplicitMF sphere; MFNSpace space; double *data; sphere=MFIMFCreateBaseClass(3,2,"Sphere",e); space=MFCreateNSpace(3,e); MFIMFSetSpace(sphere,space,e); MFFreeNSpace(space,e); data=(double*)malloc(4*sizeof(double)); #ifndef MFNPOSAFETYNET if(data==NULL) { sprintf(MFSphereMFErrorHandlerMsg,"Out of memory, trying to allocate %d bytes",4*sizeof(double)); MFSetError(e,12,RoutineName,MFSphereMFErrorHandlerMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); free(sphere); return NULL; } #endif data[0]=x; data[1]=y; data[2]=z; data[3]=R; MFIMFSetData(sphere,(void*)data,e); MFIMFSetFreeData(sphere,MFFreeSphereData,e); MFIMFSetProject(sphere,MFProjectSphere,e); MFIMFSetTangent(sphere,MFTangentSphere,e); MFIMFSetR(sphere,-1.,e); MFIMFSetScale(sphere,MFScaleSphere,e); MFIMFSetWriteData(sphere,MFWriteSphereData,e); MFIMFSetProjectForSave(sphere,MFSphereProjectToSave,e); MFIMFSetProjectForDraw(sphere,MFSphereProjectToDraw,e); MFIMFSetProjectForBB(sphere,MFSphereProjectForBB,e); MFIMFSetVectorFactory(sphere,MFNVectorFactory,e); MFIMFSetMatrixFactory(sphere,MFNKMatrixFactory,e); return sphere; }
/*! \fn MFImplicitMF MFIMFCreateCircle(double x,double y,double R, MFErrorHandler e); * \brief Creates an implicitly defined manifold for a circle embedded in the plane, centered at (x,y) with * radius R. * * \param x The x coordinate of the center of the circle * \param y The y coordinate of the center of the circle * \param R The radius. * \param e An error handler. * \returns An implicitly defined manifold. */ MFImplicitMF MFIMFCreateCircle(double x,double y,double R, MFErrorHandler e) { static char RoutineName[]={"MFIMFCreateCircle"}; MFImplicitMF circle; MFNSpace space; double *data; circle=MFIMFCreateBaseClass(2,1,"Circle",e); space=MFCreateNSpace(2,e); MFIMFSetSpace(circle,space,e); MFFreeNSpace(space,e); data=(double*)malloc(3*sizeof(double)); #ifndef MFNOSAFETYNET if(data==NULL) { sprintf(MFCircleMFErrorHandlerMsg,"Out of memory, trying to allocate %d bytes",3*sizeof(double)); MFSetError(e,12,RoutineName,MFCircleMFErrorHandlerMsg,__LINE__,__FILE__); free(circle); return NULL; } #endif data[0]=x; data[1]=y; data[2]=R; MFIMFSetData(circle,data,e); MFIMFSetFreeData(circle,MFFreeCircleData,e); MFIMFSetProject(circle,MFProjectCircle,e); MFIMFSetTangent(circle,MFTangentCircle,e); MFIMFSetScale(circle,MFScaleCircle,e); MFIMFSetWriteData(circle,MFWriteCircleData,e); MFIMFSetProjectForSave(circle,MFCircleProjectToSave,e); MFIMFSetProjectForDraw(circle,MFCircleProjectToDraw,e); MFIMFSetProjectForBB(circle,MFCircleProjectForBB,e); MFIMFSetVectorFactory(circle,MFNVectorFactory,e); MFIMFSetMatrixFactory(circle,MFNKMatrixFactory,e); return circle; }
MFImplicitMF MFIMFCreateLOCA(LOCAData* data) { MFImplicitMF loca; MFNSpace space; loca=MFIMFCreateBaseClass(-1, data->np, "LOCA", data->mfErrorHandler); space=MFCreateLOCANSpace(data); MFIMFSetSpace(loca,space, data->mfErrorHandler); MFFreeNSpace(space, data->mfErrorHandler); MFIMFSetData(loca,(void*)data, data->mfErrorHandler); data->space=space; MFRefNSpace(space, data->mfErrorHandler); MFIMFSetFreeData(loca,MFLOCAFreeData, data->mfErrorHandler); MFIMFSetProject(loca,MFProjectLOCA, data->mfErrorHandler); MFIMFSetTangent(loca,MFTangentLOCA, data->mfErrorHandler); MFIMFSetScale(loca,MFScaleLOCA, data->mfErrorHandler); MFIMFSetProjectForSave(loca,MFLOCAProjectToDraw, data->mfErrorHandler); MFIMFSetProjectForDraw(loca,MFLOCAProjectToDraw, data->mfErrorHandler); MFIMFSetProjectForBB(loca,MFLOCAProjectToDraw, data->mfErrorHandler); return loca; }
/*! \fn MFAtlas IMFComputeInvariantManifold(IMFFlow F,MFKVector p0,char *name, MFAtlas c,MFNRegion Omega, double eps, double dt, double tmax, int maxInterp, int maxCharts, double Rmax, MFErrorHandler e); * \brief Computes an atlas of charts that cover the image of a manifold under a flow. A streamsurface. * * \param L The flow. * \param name A name to used for paging files and so forth. * \param u0 The fixed point. * \param p0 The parameters of the flow for the fixed point. * \param c The manifold of initial conditions. * \param Omega A region to bound the computation. * \param eps The tolerance on the size of the quadratic terms over a balls. Controls the stepsize. * \param dt The initial timestep to use along a fat trajectory. * \param tmax The upper limit on trajectory length. * \param maxInterp The upper limit on the number of interpolation performed. * \param maxCharts The upper limit on the number of charts in the atlas. * \param RMax An upper limit to impose on the radius of the balls along the fat trajectories. * \param e An MFErrorHandler to handle exceptions and errors. * \returns A new Atlas */ MFAtlas IMFComputeInvariantManifold(IMFFlow F,MFKVector p0,char *name, MFAtlas c,MFNRegion Omega, double eps, double dt, double tmax, int maxInterp, int maxCharts, double Rmax,MFErrorHandler e) { static char RoutineName[]= {"IMFComputeInvariantManifold"}; double s0[2],s1[2]; double *ddu; double *du; MFKVector s; MFNVector ug,v; MFNKMatrix Phi; MFNKMatrix Psi; int i; int ii,jj; IMFExpansion cE,U; MFContinuationMethod H; MFAtlas A; MFAtlas I; MFImplicitMF M; double R,r; char sname[1024]; FILE *fid; MFNKMatrix TS; MFNVector ui; double t; int chart; MFNVector sigma; MFKVector zero; double *u0; int n,k; int verbose=0; if(verbose) { printf("in %s\n",RoutineName); fflush(stdout); } n=MFAtlasN(c,e); k=MFAtlasK(c,e); M=IMFCreateFlat(n,k+1,e); MFIMFSetProjectForDraw(M,MFIMFGetProjectForDraw(MFAtlasMF(c,e),e),e); MFIMFSetProjectForSave(M,MFIMFGetProjectForSave(MFAtlasMF(c,e),e),e); MFIMFSetProjectForBB (M,MFIMFGetProjectForBB (MFAtlasMF(c,e),e),e); MFIMFSetR(M,Rmax/2,e); I=MFCreateAtlas(M,e); printf("%s, Create Atlas I=0x%8.8x\n",RoutineName,I); fflush(stdout); H=MFCreateMultifariosMethod(e); MFMultifarioSetIntegerParameter(H,"page",0,e); MFMultifarioSetIntegerParameter(H,"maxCharts",-1,e); MFMultifarioSetIntegerParameter(H,"dumpToPlotFile",1,e); MFMultifarioSetFilename(H,name,e); u0=(double*)malloc(n*sizeof(double)); #ifndef MFNOSAFETYNET if(u0==NULL) { sprintf(MFNSpaceErrorMsg,"Out of memory trying to allocate %d bytes\n",n*k*sizeof(double)); MFSetError(e,12,RoutineName,MFNSpaceErrorMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); return NULL; } #endif du=(double*)malloc(n*k*sizeof(double)); #ifndef MFNOSAFETYNET if(du==NULL) { sprintf(MFNSpaceErrorMsg,"Out of memory trying to allocate %d bytes\n",n*k*sizeof(double)); MFSetError(e,12,RoutineName,MFNSpaceErrorMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); return NULL; } #endif ddu=(double*)malloc(n*k*k*sizeof(double)); #ifndef MFNOSAFETYNET if(ddu==NULL) { sprintf(MFNSpaceErrorMsg,"Out of memory trying to allocate %d bytes\n",n*sizeof(double)); MFSetError(e,12,RoutineName,MFNSpaceErrorMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); return NULL; } #endif zero=MFCreateKVector(k-1,e); s0[0]=-r; s1[0]= r; s0[1]=-r; s1[1]= r; for(i=0; i<n*k*k; i++)ddu[i]=0.; for(i=0; i<MFAtlasNumberOfCharts(c,e); i++) { if(verbose) { printf(" chart %d on the initial manifold\n",i); fflush(stdout); } if(MFNV_CStar(MFAtlasChartCenter(c,i,e),e)!=NULL) { for(ii=0; ii<n; ii++) u0[ii]=MFNV_CStar(MFAtlasChartCenter(c,i,e),e)[ii]; } else { for(ii=0; ii<n; ii++) u0[ii]=MFNV_C(MFAtlasChartCenter(c,i,e),ii,e); } Phi=MFAtlasChartTangentSpace(c,i,e); if(MFNKM_CStar(Phi,e)!=NULL) { for(ii=0; ii<n*k; ii++) du[ii]=MFNKM_CStar(Phi,e)[ii]; } else { for(ii=0; ii<n; ii++) for(jj=0; jj<k; jj++) du[ii+n*jj]=MFNKMGetC(Phi,ii,jj,e); } cE=IMFCreateExpansion(n,k,e); /* Assumes it's a straight line */ /* Assumes Phi is a dense matrix */ IMFExpansionSetDerivatives(cE,u0,du,ddu,NULL,e); U=IMFInflateExpansionWithFlow(cE,F,p0,e); ui=IMFCreateExpansionNVector(U,0.,MFAtlasCenterOfChart(c,i,e),-1,1,e); if(0&&i==0) /* Why??? */ { TS=IMFExpansionTS(cE,e); R=MFAtlasChartRadius(c,i,e); MFAtlasAddChartWithAll(I,ui,TS,R,e); } IMFExpansionNVSetChart0(ui,i,e); IMFExpansionNVSetS0(ui,zero,e); printf("*) Point on c\n"); fflush(stdout); MFPrintNVector(stdout,ui,e); printf(" Extend along fat traj\n"); fflush(stdout); IMFExtendAtlasAlongFatTraj(I,F,name,ui,p0,dt,0.,tmax,eps,Omega,maxCharts,maxCharts,Rmax,0,e); printf(" done fat traj\n"); fflush(stdout); if(0&&MFAtlasNumberOfCharts(I,e)%1000==0)MFAtlasPageOutChartsNotNearBoundary(I,1,0,name,e); MFFreeNVector(ui,e); IMFFreeExpansion(cE,e); IMFFreeExpansion(U,e); } printf("*** Done covering c\n"); fflush(stdout); #ifdef DOINTERPOLATIONPT sprintf(sname,"%s.intpt",name); IMFInterp=fopen(sname,"w"); IMFNInterp=0; #endif i=0; while(i<maxInterp&& (ui=IMFGetInterpolationPoint(I,F,p0,A,tmax,NULL,e))!=NULL && MFAtlasNumberOfCharts(I,e)<maxCharts) { printf("*** Interpolated Point %d\n",i); fflush(stdout); #ifdef DOINTERPOLATIONPT for(j=0; j<3; j++)fprintf(IMFInterp," %lf",IMFExpansionU(IMFExpansionNVGetE(ui,e))[j],e); fprintf(IMFInterp,"\n"); fflush(IMFInterp); IMFNInterp++; #endif IMFExtendAtlasAlongFatTraj(I,F,name,ui,p0,dt,IMFExpansionNVGetT(ui,e),tmax,eps,Omega,maxCharts,maxCharts,Rmax,0,e); if(0&&MFAtlasNumberOfCharts(I,e)%1000==0)MFAtlasPageOutChartsNotNearBoundary(I,1,0,name,e); MFFreeNVector(ui,e); i++; } if(i<maxInterp) { printf("*** No more interpolation points, total was %d\n",i); fflush(stdout); } else { printf("*** Max number of interpolation points reached, %d\n",i); fflush(stdout); } MFFlushAtlas(H,I,e); MFCloseAtlas(H,I,e); MFFreeContinuationMethod(H,e); MFFreeImplicitMF(M,e); free(u0); free(du); free(ddu); #ifdef DOINTERPOLATIONPT if(IMFInterp!=NULL) { fclose(IMFInterp); sprintf(sname,"i%s.dx",name); IMFInterp=fopen(sname,"w"); sprintf(sname,"%s.intpt",name); if(IMFNInterp>0) { fprintf(IMFInterp,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file %s.dx\n",sname,IMFNInterp); } else { fprintf(IMFInterp,"object \"Vertices\" class array type float rank 1 shape 3 items 1 data follows\n"); fprintf(IMFInterp," 0. 0. 0.\n"); } fprintf(IMFInterper,"object \"interpolated points\" class field\n"); fprintf(IMFInterper,"component \"positions\" value \"Vertices\"\n"); fclose(IMFInterper); } #endif #ifdef DOINTERPANIM if(IMFInterper!=NULL) { fclose(IMFInterper); IMFInterper=fopen("gInterp1.dx","w"); if(IMFNInterper>0) { fprintf(IMFInterper,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file Interp1.dx\n",IMFNInterper); } else { fprintf(IMFInterper,"object \"Vertices\" class array type float rank 1 shape 3 items 1 data follows\n"); fprintf(IMFInterper," 0. 0. 0.\n"); } fprintf(IMFInterper,"object \"interpolated points\" class field\n"); fprintf(IMFInterper,"component \"positions\" value \"Vertices\"\n"); fclose(IMFInterper); } if(IMFInterpee!=NULL) { fclose(IMFInterpee); IMFInterpee=fopen("gInterp2.dx","w"); if(IMFNInterpee>0) { fprintf(IMFInterpee,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file Interp2.dx\n",IMFNInterpee); fprintf(IMFInterpee,"object \"Lines\" class array type int rank 1 shape 2 items %d data follows\n",IMFNInterpee/2); for(i=0; i<IMFNInterpee; i+=2) fprintf(IMFInterpee," %d %d\n",i,i+1); } else { fprintf(IMFInterpee,"object \"Vertices\" class array type float rank 1 shape 3 items 2 data follows\n"); fprintf(IMFInterpee," 0. 0. 0.\n"); fprintf(IMFInterpee," 0. 0. 0.001\n"); fprintf(IMFInterpee,"object \"Lines\" class array type int rank 1 shape 2 items 1 data follows\n"); fprintf(IMFInterpee," %d %d\n",0,1); } fprintf(IMFInterpee,"attribute \"ref\" string \"positions\"\n"); fprintf(IMFInterpee,"attribute \"element type\" string \"lines\"\n"); fprintf(IMFInterpee,"object \"interpolation points\" class field\n"); fprintf(IMFInterpee,"component \"positions\" value \"Vertices\"\n"); fprintf(IMFInterpee,"component \"connections\" value \"Lines\"\n"); fclose(IMFInterpee); } if(IMFInterpT!=NULL) { fclose(IMFInterpT); IMFInterpT=fopen("gInterp3.dx","w"); if(IMFNInterpT>0) { fprintf(IMFInterpT,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file Interp3.dx\n",IMFNInterpT ); fprintf(IMFInterpT,"object \"Lines\" class array type int rank 1 shape 2 items %d data follows\n",IMFNInterpT-1); for(i=0; i<IMFNInterpT-1; i++) fprintf(IMFInterpT," %d %d\n",i,i+1); } else { fprintf(IMFInterpT,"object \"Vertices\" class array type float rank 1 shape 3 items 2 data follows\n"); fprintf(IMFInterpT," 0. 0. 0.\n"); fprintf(IMFInterpT," 0. 0. 0.001\n"); fprintf(IMFInterpT,"object \"Lines\" class array type int rank 1 shape 2 items 1 data follows\n"); fprintf(IMFInterpT," %d %d\n",0,1); } fprintf(IMFInterpT,"attribute \"ref\" string \"positions\"\n"); fprintf(IMFInterpT,"attribute \"element type\" string \"lines\"\n"); fprintf(IMFInterpT,"object \"interpolation points\" class field\n"); fprintf(IMFInterpT,"component \"positions\" value \"Vertices\"\n"); fprintf(IMFInterpT,"component \"connections\" value \"Lines\"\n"); fclose(IMFInterpT); } if(IMFCircle!=NULL) { fclose(IMFCircle); IMFCircle=fopen("gIMFCircle.dx","w"); fprintf(IMFCircle,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file IMFCircle.dx\n",IMFNCircle); fprintf(IMFCircle,"object \"Lines\" class array type int rank 1 shape 2 items %d data follows\n",IMFNCircle/2); for(i=0; i<IMFNCircle; i+=2) fprintf(IMFCircle," %d %d\n",i,i+1); fprintf(IMFCircle,"attribute \"ref\" string \"positions\"\n"); fprintf(IMFCircle,"attribute \"element type\" string \"lines\"\n"); fprintf(IMFCircle,"object \"interpolation points\" class field\n"); fprintf(IMFCircle,"component \"positions\" value \"Vertices\"\n"); fprintf(IMFCircle,"component \"connections\" value \"Lines\"\n"); fclose(IMFCircle); } #endif #ifdef DOTRAJ if(IMFTraj!=NULL) { printf("dump trajectory file\n"); fflush(stdout); fclose(IMFTraj); IMFTraj=fopen("gIMFTraj.dx","w"); fprintf(IMFTraj,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file IMFTraj.dx\n",IMFNTraj); fprintf(IMFTraj,"object \"Lines\" class array type int rank 1 shape 2 items %d data follows\n",IMFNTraj/2); for(i=0; i<IMFNTraj; i+=2) fprintf(IMFTraj," %d %d\n",i,i+1); fprintf(IMFTraj,"attribute \"ref\" string \"positions\"\n"); fprintf(IMFTraj,"attribute \"element type\" string \"lines\"\n"); fprintf(IMFTraj,"object \"trajectories\" class field\n"); fprintf(IMFTraj,"component \"positions\" value \"Vertices\"\n"); fprintf(IMFTraj,"component \"connections\" value \"Lines\"\n"); fclose(IMFTraj); } #endif printf("done %s\n",RoutineName); fflush(stdout); return I; }