/* m__pd.c Any Point-->Perod doubling Curve for maps using Keller's standard augmented system */ #include "common.h" #include "corefunc.h" #include "stagen.h" #include "_util.h" #include "_linalg.h" #include "m__pd.h" #include "_conti.h" /* continuer's (i.e. generator's) data */ /* Numbers of visible name classes; the order must be the same as in /names section */ #define CL_TIME 1 #define CL_PHASE 2 #define CL_PAR 3 #define CL_TEST 4 #define CL_UTEST 5 #define CL_STDFUN 6 #define CL_MULT 7 #define _eps staData->eps #define _dx staData->dx #define PI 4.0*atan(1.0) #define PID2 2.0*atan(1.0) Local(StagenDataPtr) stagenData=NULL; /* global copy of Starter's parameter passed by content */ Local(m__pd_DataPtr) staData=NULL; /* global copy of our own data area */ Local(StdLinAlgDataPtr) staFunc=NULL; /* global copy of pointer standard linear algebra struct */ Local(UtilitiesDataPtr) staUtil=NULL; /* global copy of pointer to utility functions struct */ Local(Int2Ptr) active; /* index of active parameter(s) */ Local(Int2) nappend; /* number of appended user functions */ Local(Int2) npar,nphase; /* dims of par and phase spaces */ Local(Vector) x0=NULL; /* approximate first point */ Local(Vector) x1=NULL; /* current point */ Local(Vector) v0=NULL; /* approximate tangent vector at first point */ Local(FloatHiPtr) X=NULL; /* current set of phases used by Decoder */ Local(FloatHiPtr) P=NULL; /* current set of params used by Decoder */ Local(FloatHiPtr) M=NULL; /* current set of multipliers */ Local(Boolean) SymbNumer1,SymbNumer2; /* TRUE for symbolic differentiation of the correcponding order*/ Local(VAR) zero=0; Local(Vector) StdFun=NULL; Local(int) itmap; Local(FloatHiPtr) F,DF,DFF,D2,DD2,D3F,DD3F; /* work space for supdiff */ #define _itmap staData->itmap /* number of superpositions */ #include "_supdiff.c" /* Working space for defining and test functions */ Local(Matrix) A0,A,B,C,C1,C2,BP=NULL,AA=NULL; Local(Vector) vn,xp,xp1,V,W,F0,F1,F2,a,Vp,x01,v01,x11; Local(Vector) Re=NULL,Im=NULL,Mod=NULL,Arg=NULL; Local(VAR) test[4],dx,ddx,dddx; #define BifVector stagenData->BifDataOutPtr #define ActiveUTestFuns staData->ActiveUserTest #define nUTest stagenData->udFuncNum /* Initialize function common for Starter and Decoder */ Local(Int2) Init(StagenDataPtr stagenptr) { Int2 i; /* Set local pointers to data area and functions array */ stagenData=stagenptr; staData=(m__pd_DataPtr)stagenptr->StaPtr; /* Use standard linear algebra */ staFunc=(StdLinAlgDataPtr)stagenptr->StdLinAlg; staUtil=(UtilitiesDataPtr)stagenptr->Utilities; /* Get dimensions of Phase and Par spaces */ npar=*stagenptr->ClassDim[CL_PAR]; nphase=*stagenptr->ClassDim[CL_PHASE]; itmap=_itmap; if (itmap<=0) { staUtil->ErrMessage("Superposition must be positive."); return 6; } /* Call udf SetInitPoint function, if any */ if (!stagenData->ContDataGenLen && FuncParActive(staData->SetInitPoint)) { /* there is UDF to set InitPoint */ Int2 Index_X,Index_P; Index_X=stagenptr->ParIndex(staData,X); Index_P=stagenptr->ParIndex(staData,P); FuncParCall(staData->SetInitPoint)(staData); stagenptr->UpdatePar(Index_X); stagenptr->UpdatePar(Index_P); } /* Do all the checks related to active parameters and find them */ for (i=0,nappend=0; iCheckParameters(staData->Active,npar,active,2+nappend)) { active=MemFree(active); return 1; } /* Checks related to analytical/numerical differentiation of RHS */ if (!stagenData->Der1 && staData->dx <= 0) { staUtil->ErrMessage("Analytical Jacoby matrix is undefined.\nRecompile system or set positive 'Increment'"); active=MemFree(active); return 2; } if ((staData->ActiveSing[0] || staData->ActiveSing[1] || staData->ActiveSing[2]) && !stagenData->Der2 && staData->dx <= 0) { staUtil->ErrMessage("Analytical Hessian matrix is undefined.\nRecompile system or set positive 'Increment'"); active=MemFree(active); return 3; } /* Create a copy parameters */ Der2num=ind2_(nphase+npar-1,nphase+npar-1)+1; Der3num=ind3_(nphase+npar-1,nphase+npar-1,nphase+npar-1)+1; if (!P) { P=MemNew(sizeof(FloatHi)*npar); MemCopy(P,staData->P,sizeof(FloatHi)*npar); /* Allocate memory for copy of phase vars used by Decoder */ X=MemNew(sizeof(FloatHi)*nphase); /* Allocate memory for eigenvalues */ M=MemNew(sizeof(FloatHi)*4*nphase); Re=staFunc->CreateVector(nphase); Im=staFunc->CreateVector(nphase); Mod=staFunc->CreateVector(nphase); Arg=staFunc->CreateVector(nphase); /* Allocate memory for the initial point and tangent vector */ x0=staFunc->CreateVector(2*nphase+2+nappend); x1=staFunc->CreateVector(2*nphase+2+nappend); v0=staFunc->CreateVector(2*nphase+2+nappend); x01=staFunc->CreateVector(2*nphase+2+nappend); x11=staFunc->CreateVector(2*nphase+2+nappend); v01=staFunc->CreateVector(2*nphase+2+nappend); StdFun=staFunc->CreateVector(1+2*nphase); /* L2_NORM, MIN&MAX */ /* Allocate memory for working space used in defining and test functions */ A0=staFunc->CreateMatrix(nphase,nphase+2+nappend); AA=staFunc->CreateMatrix(nphase,nphase); A=staFunc->CreateMatrix(nphase,nphase); B=staFunc->CreateMatrix(nphase,nphase); C=staFunc->CreateMatrix(nphase+nappend,2*nphase+2+nappend); C1=staFunc->CreateMatrix(nphase,2*nphase+2+nappend); C2=staFunc->CreateMatrix(nphase,2*nphase+2+nappend); if (nphase >= 2) BP=staFunc->CreateMatrix(nphase*(nphase-1)/2,nphase*(nphase-1)/2); vn=staFunc->CreateVector(nphase); xp=staFunc->CreateVector(nphase+2+nappend); xp1=staFunc->CreateVector(nphase+2+nappend); V=staFunc->CreateVector(nphase); W=staFunc->CreateVector(nphase); F0=staFunc->CreateVector(nphase); F1=staFunc->CreateVector(nphase); F2=staFunc->CreateVector(nphase); a=staFunc->CreateVector(nphase); Vp=staFunc->CreateVector(nphase+2+nappend); BifVector=MemNew(sizeof(FloatHi)*(3*nphase+2)); F=MemNew(sizeof(FloatHi)*nphase); DF=MemNew(sizeof(FloatHi)*nphase*(nphase+npar)); DFF=MemNew(sizeof(FloatHi)*nphase*(nphase+npar)); if (staData->ActiveSing[0]+staData->ActiveSing[1]) { D2=MemNew(sizeof(FloatHi)*nphase*Der2num); DD2=MemNew(sizeof(FloatHi)*nphase*Der2num); if (staData->ActiveSing[0]) { D3F=MemNew(sizeof(FloatHi)*nphase*Der3num); DD3F=MemNew(sizeof(FloatHi)*nphase*Der3num); } } } dx=_dx; ddx=pow(dx,3.0/4.0); dddx=pow(dx,3.0/6.0); ((ContDataPtr)stagenptr->GenPtr)->ActiveSing=staData->ActiveSing; ((ContDataPtr)stagenptr->GenPtr)->ActiveUserTest=staData->ActiveUserTest; ((ContDataPtr)stagenptr->GenPtr)->TypeTestFuns=staData->TypeTestFunc; ((ContDataPtr)stagenptr->GenPtr)->ZeroTestFuns=staData->ZeroTestFunc; return 0; } Local(void) Term (Boolean OK) { if (OK&&P&&(stagenData->Reason==RF_CLEAN)) { stagenData->BifDataOutLen=sizeof(VAR)*(nphase+1); BifVector[0]=itmap; MemCopy(BifVector+1,x1+nphase+2+nappend,sizeof(FloatHi)*nphase); stagenData->ProcessPoint(stagenData->ProcFuncNum, x1, "Last point"); } else { stagenData->BifDataOutLen=0; } x0=staFunc->DestroyVector(x0); x1=staFunc->DestroyVector(x1); v0=staFunc->DestroyVector(v0); active=MemFree(active); if (P) { P=MemFree(P); X=MemFree(X); M=MemFree(M); Re=staFunc->DestroyVector(Re); Im=staFunc->DestroyVector(Im); Mod=staFunc->DestroyVector(Mod); Arg=staFunc->DestroyVector(Arg); StdFun=staFunc->DestroyVector(StdFun); A=staFunc->DestroyMatrix(A); AA=staFunc->DestroyMatrix(AA); A0=staFunc->DestroyMatrix(A0); B=staFunc->DestroyMatrix(B); C=staFunc->DestroyMatrix(C); C1=staFunc->DestroyMatrix(C1); C2=staFunc->DestroyMatrix(C2); BP=staFunc->DestroyMatrix(BP); vn=staFunc->DestroyVector(vn); xp=staFunc->DestroyVector(xp); xp1=staFunc->DestroyVector(xp1); x01=staFunc->DestroyVector(x01); x11=staFunc->DestroyVector(x11); v01=staFunc->DestroyVector(v01); V=staFunc->DestroyVector(V); W=staFunc->DestroyVector(W); F0=staFunc->DestroyVector(F0); F1=staFunc->DestroyVector(F1); F2=staFunc->DestroyVector(F2); a=staFunc->DestroyVector(a); Vp=staFunc->DestroyVector(Vp); BifVector=MemFree(BifVector); F=MemFree(F); DF=MemFree(DF); DFF=MemFree(DFF); if (staData->ActiveSing[0]+staData->ActiveSing[1]) { D2=MemFree(D2); DD2=MemFree(DD2); if (staData->ActiveSing[0]) { D3F=MemFree(D3F); DD3F=MemFree(DD3F); } } } } Local(Int2) JacRHS (Vector x, Matrix J); Local(Int2) JacDefFixed (Vector x, Matrix J); Entry(Int2) mpd_JacDefFlip (Vector x, Matrix J); /**************************************/ /* Any point on PD curve ->pd Starter */ Entry(Int2) mpd_Starter(StagenDataPtr stagenptr) { Int2 i,Ret; Vector v1,v2; Matrix D,DE; if (!stagenptr) { /* this is request to terminate */ Term(TRUE); return 0; } if (Init(stagenptr)) return 1; /* initialize local variables */ SymbNumer1=stagenData->Der1!=NULL && staData->dx!=0; SymbNumer2=stagenData->Der2!=NULL && staData->dx!=0; /* Create the first point for generator */ if (stagenData->BifDataInOk) _itmap=stagenData->BifDataInPtr[0]; if (!stagenptr->ContDataGenLen) { /* extension */ v1=staFunc->CreateVector(2*nphase+2+nappend); v2=staFunc->CreateVector(2*nphase+2+nappend); D=staFunc->CreateMatrix(2*nphase+1+nappend,2*nphase+2+nappend); DE=staFunc->CreateMatrix(2*nphase+2+nappend,2*nphase+2+nappend); MemCopy(x0,staData->X,sizeof(FloatHi)*nphase); for (i=0; i<2+nappend; i++) x0[nphase+i]=staData->P[active[i]]; if (stagenData->BifDataInOk) { /* V exists */ MemCopy(x0+nphase+2+nappend,stagenData->BifDataInPtr+1,sizeof(FloatHi)*nphase); } else { /* V has to be computed */ Ret=JacRHS(x0,C1); staFunc->CopyMatrixBlock(C1,0,0,B,0,0,nphase,nphase); for (i=0;iSngSolve(B,_eps,V) != nphase-1) { staUtil->ErrMessage("Unable to find a flip eigenvector"); v1=staFunc->DestroyVector(v1); v2=staFunc->DestroyVector(v2); D=staFunc->DestroyMatrix(D); DE=staFunc->DestroyMatrix(DE); Term(FALSE); return 1; } staFunc->NormalizeVector(V); staFunc->CopyVectorElements(V,0,x0,nphase+2+nappend,nphase); }; /* Compute a tangent vector to the period doubling curve */ Ret=mpd_JacDefFlip (x0,D); for (i=0; i<2*nphase+2+nappend; i++) { v1[i]=1.0; staFunc->AppendMatrixVector(D,v1,DE); Ret=staFunc->Decomp(DE); if (Ret == 0) { v2[2*nphase+1+nappend]=stagenData->Forward ? 1 : -1; staFunc->Solve(DE,v2); staFunc->CopyVector(v2,v0); break; }; v1[i]=0.0; } if (Ret) { staUtil->ErrMessage ("Unable to find a tangent vector to the period doubling curve"); v1=staFunc->DestroyVector(v1); v2=staFunc->DestroyVector(v2); D=staFunc->DestroyMatrix(D); DE=staFunc->DestroyMatrix(DE); Term(FALSE); return 1; } staFunc->NormalizeVector(v0); v1=staFunc->DestroyVector(v1); v2=staFunc->DestroyVector(v2); D=staFunc->DestroyMatrix(D); DE=staFunc->DestroyMatrix(DE); } /* Initialize continuation */ ((ContDataPtr)stagenptr->GenPtr)->X0=x0; ((ContDataPtr)stagenptr->GenPtr)->V0=v0; ((ContDataPtr)stagenptr->GenPtr)->ActiveSing=staData->ActiveSing; ((ContDataPtr)stagenptr->GenPtr)->ActiveUserTest=staData->ActiveUserTest; ((ContDataPtr)stagenptr->GenPtr)->TypeTestFuns=staData->TypeTestFunc; ((ContDataPtr)stagenptr->GenPtr)->ZeroTestFuns=staData->ZeroTestFunc; /* That's all */ return 0; } /*************************/ /* FF Point ->pd Starter */ Entry(Int2) mf_pd_Starter(StagenDataPtr stagenptr) { Int2 i,Ret; Vector v1,v2; Matrix D,DE; if (!stagenptr) { /* this is request to terminate */ Term(TRUE); return 0; } if (Init(stagenptr)) return 1; /* initialize local variables */ SymbNumer1=stagenData->Der1!=NULL && staData->dx!=0; SymbNumer2=stagenData->Der2!=NULL && staData->dx!=0; /* Create the first point for generator */ if (stagenData->BifDataInOk) _itmap=stagenData->BifDataInPtr[0]; if (!stagenptr->ContDataGenLen) { /* extension */ v1=staFunc->CreateVector(2*nphase+2+nappend); v2=staFunc->CreateVector(2*nphase+2+nappend); D=staFunc->CreateMatrix(2*nphase+1+nappend,2*nphase+2+nappend); DE=staFunc->CreateMatrix(2*nphase+2+nappend,2*nphase+2+nappend); MemCopy(x0,staData->X,sizeof(FloatHi)*nphase); for (i=0; i<2+nappend; i++) x0[nphase+i]=staData->P[active[i]]; if (stagenData->BifDataInOk) { /* V exists */ MemCopy(x0+nphase+2+nappend,stagenData->BifDataInPtr+nphase+1,sizeof(FloatHi)*nphase); } else { /* V has to be computed */ Ret=JacRHS(x0,C1); staFunc->CopyMatrixBlock(C1,0,0,B,0,0,nphase,nphase); for (i=0;iSngSolve(B,_eps,V) != nphase-1) { staUtil->ErrMessage("Unable to find a flip eigenvector"); v1=staFunc->DestroyVector(v1); v2=staFunc->DestroyVector(v2); D=staFunc->DestroyMatrix(D); DE=staFunc->DestroyMatrix(DE); Term(FALSE); return 1; } staFunc->NormalizeVector(V); staFunc->CopyVectorElements(V,0,x0,nphase+2+nappend,nphase); }; /* Compute a tangent vector to the period doubling curve */ Ret=mpd_JacDefFlip (x0,D); for (i=0; i<2*nphase+2+nappend; i++) { v1[i]=1.0; staFunc->AppendMatrixVector(D,v1,DE); Ret=staFunc->Decomp(DE); if (Ret == 0) { v2[2*nphase+1+nappend]=stagenData->Forward ? 1 : -1; staFunc->Solve(DE,v2); staFunc->CopyVector(v2,v0); break; }; v1[i]=0.0; } if (Ret) { staUtil->ErrMessage ("Unable to find a tangent vector to the period doubling curve"); v1=staFunc->DestroyVector(v1); v2=staFunc->DestroyVector(v2); D=staFunc->DestroyMatrix(D); DE=staFunc->DestroyMatrix(DE); Term(FALSE); return 1; } staFunc->NormalizeVector(v0); v1=staFunc->DestroyVector(v1); v2=staFunc->DestroyVector(v2); D=staFunc->DestroyMatrix(D); DE=staFunc->DestroyMatrix(DE); } /* Initialize continuation */ ((ContDataPtr)stagenptr->GenPtr)->X0=x0; ((ContDataPtr)stagenptr->GenPtr)->V0=v0; ((ContDataPtr)stagenptr->GenPtr)->ActiveSing=staData->ActiveSing; ((ContDataPtr)stagenptr->GenPtr)->ActiveUserTest=staData->ActiveUserTest; ((ContDataPtr)stagenptr->GenPtr)->TypeTestFuns=staData->TypeTestFunc; ((ContDataPtr)stagenptr->GenPtr)->ZeroTestFuns=staData->ZeroTestFunc; /* That's all */ return 0; } typedef EntryPtr(Int2,TestFuncPtr,(Vector xx, Vector vv, FloatHiPtr TV)); typedef EntryPtr(Int2,ProcFuncPtr,(Int2 Ind, Vector xx, Vector vv, CharPtr *msg)); /************************/ /* Some common routines */ Local(void) CopyToX(Vector vp) { MemCopy(X,vp,sizeof(FloatHi)*nphase); } Local(void) CopyToP(Vector vp) { Int2 i; for (i=0; i<2+nappend; i++) P[active[i]]=vp[nphase+i]; } Local(void) CopyToM(void) { MemCopy(M,Mod,sizeof(VAR)*nphase); MemCopy(M+nphase,Arg,sizeof(VAR)*nphase); MemCopy(M+2*nphase,Re,sizeof(VAR)*nphase); MemCopy(M+3*nphase,Im,sizeof(VAR)*nphase); } /***********/ /* Decoder */ Entry(Int2) mpd_Decoder(VoidPtr vpoint, FloatHiPtr PNTR indirect, Int2 oper) { switch (oper) { case DECODER_INIT: /* point is a pointer to StagenData structure */ case DECODER_TERM: break; case DECODER_DIM: /* returns number of M-points in given G-point */ return 1; default: /* extract next M-point from G-point pointed by vpoint */ /* vpoint is a Vector */ indirect[CL_TIME]=&zero; indirect[CL_PHASE]=X; CopyToX(vpoint); indirect[CL_PAR]=P; CopyToP(vpoint); indirect[CL_MULT]=M; CopyToM(); indirect[CL_TEST]=test; indirect[CL_STDFUN]=StdFun; } return 0; } /***************************/ /* User-defined functions */ Entry(Int2) mpd_DefUser (Vector x, Vector y) { Int2 i,j; for (i=j=0; iudFunc)(x,i,&y[j]); j++; } return 0; } /*******/ /* RHS */ Entry(Int2) mpd_DefRHS (Vector x, Vector y) { Int2 i; CopyToP(x); staFunc->CopyVectorElements(x,0,y,0,nphase); for (i=1; i<=_itmap; i++) { CopyToX(y); stagenData->Rhs(X,P,&zero,y); } return 0; } /**************************************/ /* Defining function for fixed points */ Local(Int2) DefFixed (Vector x, Vector y) { Int2 i; mpd_DefRHS(x,y); for (i=0; iCopyVectorElements(x,0,xp,0,nphase+2+nappend); if (SymbNumer1) { SymJac(xp,Jac); } else { if (staFunc->Der(mpd_DefRHS, nphase, xp, dx, Jac)) return 1; } return 0; } /****************************************************/ /* Jacobian of defining conditions for fixed points */ Local(Int2) JacDefFixed (Vector x, Matrix Jac) { Int2 i; staFunc->ClearMatrix(Jac); JacRHS(x, Jac); for (i=0; iDer(mpd_DefUser, nappend, x, dx, Jac+nphase); return 0; } /**********************************************/ /* Defining conditions for null-vector of A+I */ Entry(Int2) mpd_DefKer (Vector x, Vector y) { Int2 i; if (JacRHS(x,C2)) return 1; /* A,C1,W - global */ staFunc->CopyMatrixBlock(C2,0,0,A,0,0,nphase,nphase); for (i=0;iCopyVectorElements(x, nphase+2+nappend, W, 0, nphase); staFunc->MultiplyMatrixVector(A,W,y); return 0; } /***************************************************/ /* Jacobian of defining conditions for null-vector */ Local(Int2) JacDefKer (Vector x, Matrix Jac) { int i,j,k; double s; staFunc->ClearMatrix(Jac); if (SymbNumer2) { /* creation of DefKer Jacobian matrix Jac using symbolic second derivatives */ CopyToX(x); CopyToP(x); H=SymHess(x); for (i=0; iCopyMatrixBlock(C2,0,0,Jac,0,nphase+2+nappend,nphase,nphase); } else { if (staFunc->Der(mpd_DefKer, nphase, x, dx, Jac)) return 1; } return(0); } /********************************************/ /* Defining functions for period doubling curve */ Entry(Int2) mpd_DefFlip (Vector x, Vector y) { if (DefFixed(x,y)) return 1; if (mpd_DefKer(x,vn)) return 2; staFunc->CopyVectorElements(vn,0,y,nphase+nappend,nphase); staFunc->CopyVectorElements(x,nphase+2+nappend,vn,0,nphase); y[2*nphase+nappend]=staFunc->ScalProd(vn,vn)-1.0; return 0; } /********************************************************/ /* Jacobian of defining functions for period doubling curve */ Entry(Int2) mpd_JacDefFlip (Vector x, Matrix Jac) { int i; staFunc->ClearMatrix(Jac); if (JacDefFixed(x,C)) return 1; staFunc->CopyMatrixBlock(C,0,0,Jac,0,0,nphase+nappend,2*nphase+2+nappend); if (JacDefKer(x,C1)) return 1; staFunc->CopyMatrixBlock(C1,0,0,Jac,nphase+nappend,0,nphase,2*nphase+2+nappend); for (i=0; iBifDataOutLen=sizeof(VAR); return 0; } /* Assert: v1==NULL, msg==NULL, Ind==0 */ MemCopy(x1,x,sizeof(FloatHi)*(2*nphase+2+nappend)); /* for the last point */ /* L2_NORM and Min&Max */ for (i=0,s=0; ieigcomp) { if (JacRHS(x, A0)) return (1); staFunc->CopyMatrixBlock(A0,0,0,AA,0,0,nphase,nphase); staFunc->EigenValues(AA,Re,Im); for (i=0; i 0.5) { Arg[i]=atan(fabs(Im[i]/Re[i])); } else { if (Re[i]!=0.0) { Arg[i]=PID2-atan(fabs(Re[i]/Im[i])); } else { Arg[i]=PID2; } } } if (Re[i] < 0) Arg[i]=PI-Arg[i]; if (Im[i] < 0) Arg[i]=-Arg[i]; Arg[i]*=SCALE; } } return 0; } /*********************************/ /* Test and processing functions */ Local(Char) buf[120]; /* cubic coefficient */ Entry(Int2) mpd_TestDegen(Vector x, Vector v, FloatHiPtr res) { Int2 i,j,k,l,Ret=0; VAR b,c; /* extract coordinates, parameters, and the flip eigenvector */ staFunc->CopyVectorElements(x,nphase+2+nappend,V,0,nphase); /* compose Jacobian matrix */ JacRHS(x,C1); staFunc->CopyMatrixBlock(C1,0,0,AA,0,0,nphase,nphase); /* compute adjoint eigenvector */ staFunc->TransposeMatrix(AA,B); for (i=0; iSngSolve(B,_eps,W) != nphase-1) { Ret=1; *res=1; goto final; }; staFunc->NormalizeVectorRelative(W,V); /* compute the coefficient in the normal form x'=-x+cx^3 */ staFunc->ClearVector(v0); staFunc->CopyVectorElements(V,0,v01,0,nphase); staFunc->CopyVector(x,x01); /* compute vector a=B(V,V) */ if (stagenData->Der2) { H=SymHess(x); for (i=0; iAddScaledVector(x01,v01,ddx,x11); mpd_DefRHS(x11,a); mpd_DefRHS(x01,F0); staFunc->AddScaledVector(a,F0,-2.0,a); staFunc->AddScaledVector(x01,v01,-ddx,x11); mpd_DefRHS(x11,F0); staFunc->AddScaledVector(a,F0,1.0,a); staFunc->MultiplyVectorScalar(a,1.0/ddx/ddx,a); }; /* solve the system for a */ staFunc->CopyMatrix(AA,B); for (i=0; iDecomp(B); if (Ret) { *res=1.0; goto final; } staFunc->Solve(B,a); /* compute F0=B(V,a) and b= */ if (stagenData->Der2) { for (i=0; iAddScaledVector(V,a,1.0,F1); staFunc->CopyVectorElements(F1,0,v01,0,nphase); staFunc->AddScaledVector(x01,v01,0.5*ddx,x11); mpd_DefRHS(x11,F1); staFunc->AddScaledVector(x01,v01,-0.5*ddx,x11); mpd_DefRHS(x11,F0); staFunc->AddScaledVector(F1,F0,1.0,F2); staFunc->AddScaledVector(V,a,-1.0,F1); staFunc->CopyVectorElements(F1,0,v01,0,nphase); staFunc->AddScaledVector(x01,v01,0.5*ddx,x11); mpd_DefRHS(x11,F1); staFunc->AddScaledVector(x01,v01,-0.5*ddx,x11); mpd_DefRHS(x11,F0); staFunc->AddScaledVector(F1,F0,1.0,F1); staFunc->AddScaledVector(F2,F1,-1.0,F0); staFunc->MultiplyVectorScalar(F0,1.0/ddx/ddx,F0); } b=staFunc->ScalProd(W,F0); /* compute c */ if (stagenData->Der3) { D3=SymD3(x); for (c=0.0,i=0; iCopyVectorElements(V,0,v01,0,nphase); staFunc->AddScaledVector(x01,v01,3*dddx/2,x11); mpd_DefRHS(x11,F1); c=staFunc->ScalProd(W,F1); staFunc->AddScaledVector(x01,v01,dddx/2,x11); mpd_DefRHS(x11,F1); c-=3.0*staFunc->ScalProd(W,F1); staFunc->AddScaledVector(x01,v01,-dddx/2,x11); mpd_DefRHS(x11,F1); c+=3.0*staFunc->ScalProd(W,F1); staFunc->AddScaledVector(x01,v01,-3*dddx/2,x11); mpd_DefRHS(x11,F1); c-=staFunc->ScalProd(W,F1); c/=(dddx*dddx*dddx); } *res=-b/2+c/6; final: test[0]=*res; return Ret; } Entry(Int2) mpd_ProcDegen(Int2 Ind, Vector x, Vector v, CharPtr *msg) { Int2 i; stagenData->BifDataOutLen=0; if (Ind) sprintf(buf,"Degenerate flip (?)"); else { /* provide bifurcation data for DF ->* starters */ BifVector[0]=(VAR)_itmap; MemCopy(BifVector+1,x+nphase+2+nappend,sizeof(FloatHi)*nphase); stagenData->BifDataOutLen=sizeof(FloatHi)*(nphase+1); sprintf(buf,"Degenerate flip"); } *msg=buf; return 0; } /* product */ Entry(Int2) mpd_TestRes12(Vector x, Vector v, FloatHiPtr res) { Int2 i, Ret; Ret=0; *res=1.0; if (nphase < 2) goto end; staFunc->CopyVectorElements(x,nphase+2+nappend,V,0,nphase); /* compose Jacobian matrix */ if (JacRHS(x,C1)) { Ret=1; goto end; } staFunc->CopyMatrixBlock(C1,0,0,A,0,0,nphase,nphase); for(i=0; iTransposeMatrix(A,B); if (staFunc->SngSolve(B,_eps,W) != nphase-1) { *res=0; } else { staFunc->NormalizeVector(W); *res=staFunc->ScalProd(V,W); } end: test[1]=*res; return Ret; } Entry(Int2) mpd_ProcRes12(Int2 Ind, Vector x, Vector v, CharPtr *msg) { stagenData->BifDataOutLen=0; if (Ind) sprintf(buf,"1:2 Resonance (?)"); else { Vector v1; Matrix D; Int2 i,j,k; double a20,b20,b11,f0,f1,f2,f3,f4,f5,d,u; v1=staFunc->CreateVector(2*nphase); D=staFunc->CreateMatrix(2*nphase,2*nphase); /* compute (generalized) eigenvectors: A*V=-V, A*W=-W+V */ if (JacRHS (x,C1)) return 1; staFunc->CopyMatrixBlock(C1,0,0,A,0,0,nphase,nphase); for (i=0; iCopyMatrixBlock(A,0,0,D,0,0,nphase,nphase); staFunc->CopyMatrixBlock(A,0,0,D,nphase,nphase,nphase,nphase); for (i=0; iSngSolve(D,_eps,v1); if (i != 2*nphase-2) { sprintf(buf,"1:2 Resonance: eigenvectors (?)"); goto final; } staFunc->CopyVectorElements(v1,0,V,0,nphase); d=sqrt(staFunc->ScalProd(V,V)); staFunc->NormalizeVector(V); staFunc->CopyVectorElements(x,nphase+2+nappend,W,0,nphase); u=staFunc->ScalProd(V,W); staFunc->MultiplyVectorScalar(V,u,V); /* eigenvector as continued */ staFunc->CopyVectorElements(v1,nphase,W,0,nphase); staFunc->MultiplyVectorScalar(W,u/d,W); /* generalized eigenvector */ staFunc->AddScaledVector(W,V,-staFunc->ScalProd(V,W),W); /* staFunc->PrintVector(V,"Proc R2 on flip: V="); staFunc->PrintVector(W,"Proc R2 on flip: W="); */ /* provide bifurcation data for R2->* starters */ /* BifVector[0]: _itmap */ /* BifVector[1] to [nphase]: eigenvector V (A*V=-V, =1) */ /* BifVector[nphase+1] to [2*nphase]: generalized null-vector W (A*W=-W+V, =0) */ /* BifVector[2*nphase+1]: cos(theta) */ BifVector[0]=(VAR)_itmap; MemCopy(BifVector+1,V,sizeof(FloatHi)*nphase); MemCopy(BifVector+nphase+1,W,sizeof(FloatHi)*nphase); BifVector[2*nphase+1]=-1.0; stagenData->BifDataOutLen=sizeof(FloatHi)*(2*nphase+2); sprintf(buf,"1:2 Resonance"); final:; D=staFunc->DestroyMatrix(D); v1=staFunc->DestroyVector(v1); } *msg=buf; return 0; } /* unit-product test function */ Entry(Int2) mpd_TestFlipNS(Vector x, Vector v, FloatHiPtr res) { int i,j,p,q,r,s,m; *res=1.0; if (nphase < 2) goto end; if (JacRHS(x,C1)) return 1; staFunc->CopyMatrixBlock(C1,0,0,A,0,0,nphase,nphase); m=nphase*(nphase-1)/2; staFunc->ClearMatrix(BP); i=-1; for (p=1; pDecomp(BP)) { *res=0.0; } else { staFunc->GetMatrixData(BP,res,NULL); } end: test[2]=*res; return 0; } Entry(Int2) mpd_ProcFlipNS(Int2 Ind, Vector x, Vector v, CharPtr *msg) { stagenData->BifDataOutLen=0; if (Ind) { sprintf(buf,"Flip + Neimark-Sacker or neutral saddle (?)"); } else { /* provide bifurcation data for FN->* starters */ /* BifVector[0]: _itmap */ /* BifVector[1] to [nphase]: flip vector */ /* BifVector[nphase+1] to [3*nphase]: NS vectors */ /* BifVector[3*nphase+1]: kappa */ BifVector[0]=(VAR)_itmap; MemCopy(BifVector+1,x+nphase+2,sizeof(FloatHi)*nphase); { Int2 i,j,k,l,imin,jmin,Ret; VAR d,s,s1,r,r1,h,beta,gamma,phi,lambda,lambda1,omega,lambda2,omega2,theta; Matrix AT,BB; Vector V,Qr,Qi,Pr,Pi; AT=staFunc->CreateMatrix(nphase,nphase); BB=staFunc->CreateMatrix(2*nphase,2*nphase); V=staFunc->CreateVector(2*nphase); Qr=staFunc->CreateVector(nphase); Qi=staFunc->CreateVector(nphase); Pr=staFunc->CreateVector(nphase); Pi=staFunc->CreateVector(nphase); /* compose Jacobian matrix */ JacRHS(x,C1); staFunc->CopyMatrixBlock(C1,0,0,AA,0,0,nphase,nphase); staFunc->EigenValues(AA,Re,Im); for (i=0; iCopyMatrixBlock(C1,0,0,AA,0,0,nphase,nphase); for (i=0; iSngSolve(AA,_eps,Qr) != nphase-1) { sprintf(buf,"Flip + neutral saddle (?) (cannot find ns-eigenvector)"); goto final; } staFunc->CopyMatrixBlock(C1,0,0,AA,0,0,nphase,nphase); for (i=0; iSngSolve(AA,_eps,Qi) != nphase-1) { sprintf(buf,"Flip + neutral saddle (?) (cannot find ns-eigenvector)"); goto final; } staFunc->NormalizeVector(Qr); staFunc->NormalizeVectorRelative(Qi,Qr); /* ensures smallest possible angle */ staFunc->NormalizeVector(Qi); /* provide bifurcation data for FN->* starter */ staFunc->AddScaledVector(Qr,Qi,1.0,Pr); staFunc->NormalizeVector(Pr); MemCopy(BifVector+nphase+1,Pr,sizeof(FloatHi)*nphase); staFunc->AddScaledVector(Qr,Qi,-1.0,Pr); staFunc->NormalizeVector(Pr); MemCopy(BifVector+2*nphase+1,Pr,sizeof(FloatHi)*nphase); BifVector[3*nphase+1]=(lambda+lambda1)/2.0; /* kappa */ stagenData->BifDataOutLen=sizeof(FloatHi)*(3*nphase+1+1); sprintf(buf,"Flip + neutral saddle: lambda=%g",lambda); } else { /* Flip + Neimark-Sacker */ if (fabs(Re[imin]) > 0.5) { theta=atan(fabs(Im[imin]/Re[imin])); } else { theta=PID2-atan(fabs(Re[imin]/Im[imin])); } if (Re[imin] < 0) theta=PI-theta; if (Im[imin] < 0) theta=-theta; lambda=cos(theta); omega=sin(theta); lambda2=cos(2*theta); omega2=sin(2*theta); /* compute real and imaginary part of the eigenvector */ staFunc->CopyMatrixBlock(C1,0,0,BB,0,0,nphase,nphase); staFunc->CopyMatrixBlock(C1,0,0,BB,nphase,nphase,nphase,nphase); for (i=0; iSngSolve(BB,_eps,V) != 2*nphase-2) { sprintf(buf,"Flip + Neimark-Sacker (?) (singular BB)"); goto final; } staFunc->CopyVectorElements(V,0,Qr,0,nphase); staFunc->CopyVectorElements(V,nphase,Qi,0,nphase); /* normalize real and imaginary parts =1, =0 */ d=staFunc->ScalProd(Qr,Qr); s=staFunc->ScalProd(Qi,Qi); r=staFunc->ScalProd(Qr,Qi); if (r!=0) { beta=sqrt(fabs(4.0*r*r+(s-d)*(s-d))); if (2.0*fabs(2.0*r) > beta) { phi=PID2-atan(fabs((s-d)/(2.0*r))); } else { phi=atan(fabs(2.0*r/(s-d))); } if (r < 0) phi=PI-phi; if ((s-d) < 0) phi=-phi; phi/=2.0; for (i=0; iCopyVectorElements(V,0,Qr,0,nphase); d=staFunc->ScalProd(Qr,Qr); gamma=1/sqrt(d); staFunc->MultiplyVectorScalar(V,gamma,V); staFunc->CopyVectorElements(V,0,Qr,0,nphase); staFunc->CopyVectorElements(V,nphase,Qi,0,nphase); /* staFunc->PrintVector(Qr,"Qr="); staFunc->PrintVector(Qi,"Qi="); */ /* provide bifurcation data for ns->* starters */ MemCopy(BifVector+nphase+1,V,sizeof(FloatHi)*2*nphase); BifVector[3*nphase+1]=cos(theta); /* kappa */ stagenData->BifDataOutLen=sizeof(FloatHi)*(3*nphase+1+1); sprintf(buf,"Flip + Neimark-Sacker: theta=%g",theta); } final:; AT=staFunc->DestroyMatrix(AT); BB=staFunc->DestroyMatrix(BB); V=staFunc->DestroyVector(V); Qr=staFunc->DestroyVector(Qr); Qi=staFunc->DestroyVector(Qi); Pr=staFunc->DestroyVector(Pr); Pi=staFunc->DestroyVector(Pi); } } *msg=buf; return 0; } /* det(A-I) */ Entry(Int2) mpd_TestFlipFold(Vector x, Vector v, FloatHiPtr res) { Int2 i, Ret=0; *res=1.0; if (nphase < 2) goto end; /* compose Jacobian matrix */ staFunc->CopyVectorElements(x,nphase+2+nappend,V,0,nphase); if (JacRHS(x,C1)) { Ret=1; goto end; } staFunc->CopyMatrixBlock(C1,0,0,A,0,0,nphase,nphase); for (i=0; iDecomp(A)) { *res=0.0; } else { staFunc->GetMatrixData(A,res,NULL); } end: test[3]=*res; return Ret; } Entry(Int2) mpd_ProcFlipFold(Int2 Ind, Vector x, Vector v, CharPtr *msg) { Int2 i; stagenData->BifDataOutLen=0; if (Ind) sprintf(buf,"Fold-Flip (?)"); else { /* provide bifurcation data for FF -> * starters */ if (JacRHS (x,C1)) return 1; staFunc->CopyMatrixBlock(C1,0,0,AA,0,0,nphase,nphase); for (i=0; iSngSolve(AA,_eps,V) != nphase-1) { sprintf(buf,"Fold + flip: fold vector (?)"); *msg=buf; return 0; } staFunc->NormalizeVector(V); /* BifVector[0]: _itmap */ /* BifVector[1] to [nphase]: fold eigenvector from continuation */ /* BifVector[nphase+1] to [2*nphase]: flip eigenvector V computed */ BifVector[0]=(VAR)_itmap; MemCopy(BifVector+1,V,sizeof(FloatHi)*nphase); MemCopy(BifVector+nphase+1,x+nphase+2,sizeof(FloatHi)*nphase); stagenData->BifDataOutLen=sizeof(FloatHi)*(2*nphase+1); sprintf(buf,"Fold + Flip"); } *msg=buf; return 0; } /**********************/ /* Trivial Adaptation */ Entry(Int2) mpd_Adapter(Vector X, Vector V) { return 0; }