/*------------------------------------------------------------------*/ int main(int argc, char *Inputfile[]) { REAL xlength,ylength,delx,dely,t_end,delt,tau,t; REAL del_trace,del_inj,del_streak,del_vec; REAL pos1x,pos2x,pos1y,pos2y; int imax,jmax,wW,wE,wN,wS,itermax,itersor=0,write,N; REAL Re,Pr,GX,GY,UI,VI,TI,beta; REAL eps,omg,gamma,res; int p_bound; REAL **U,**V,**P,**PSI,**ZETA,**RHS,**F,**G, **TEMP, **HEAT; int **FLAG; int ppc,ifull=0,isurf=0,ibound=0; char problem[30]; char vecfile[30],tracefile[30],streakfile[30]; char infile[30],outfile[30]; struct particleline *Particlelines; int init_case, cycle; int a,j,i,pass,imeas,jmeas; REAL area,oldarea; time_t start = time(NULL); REAL xmeas,ymeas; xmeas = 3; //Here you can enter a point to ymeas = 12; //measure the P and V of over time. /* READ the parameters of the problem. */ /* Stop if problem type or inputfile are not defined */ /*----------------------------------------------------*/ if( READ_PARAMETER(Inputfile[1],problem, &xlength,&ylength,&imax,&jmax,&delx,&dely, &t_end,&delt,&tau, &del_trace,&del_inj,&del_streak,&del_vec, vecfile,tracefile,streakfile, infile,outfile, &N,&pos1x,&pos1y,&pos2x,&pos2y, &itermax,&eps,&omg,&gamma,&p_bound, &Re,&Pr,&beta,&GX,&GY,&UI,&VI,&TI, &wW,&wE,&wN,&wS) != 0 ) return(1); imeas = xmeas/delx; jmeas = ymeas/dely; /* Allocate memory for the arrays */ /*--------------------------------*/ U = RMATRIX(0,imax+1,0,jmax+1); V = RMATRIX(0,imax+1,0,jmax+1); F = RMATRIX(0,imax+1,0,jmax+1); G = RMATRIX(0,imax+1,0,jmax+1); P = RMATRIX(0,imax+1,0,jmax+1); TEMP = RMATRIX(0,imax+1,0,jmax+1); PSI = RMATRIX(0,imax,0,jmax); ZETA = RMATRIX(1,imax-1,1,jmax-1); HEAT = RMATRIX(0,imax,0,jmax); RHS = RMATRIX(0,imax+1,0,jmax+1); FLAG = IMATRIX(0,imax+1,0,jmax+1); ppc = 1; /* Read initial values from file "infile" */ /*----------------------------------------*/ init_case = READ_bin(U,V,P,TEMP,FLAG,imax,jmax,infile); if( init_case > 0 ) return(1); /* Error while reading "infile" */ if( init_case < 0 ){ /* Set initial values if */ /* "infile" is not specified */ INIT_UVP(problem,U,V,P,TEMP,imax,jmax,UI,VI,TI); INIT_FLAG(problem,FLAG,imax,jmax,delx,dely,&ibound); } /* Initialize particles for streaklines or particle tracing */ /*----------------------------------------------------------*/ if (strcmp(streakfile,"none") || strcmp(tracefile,"none")) Particlelines = SET_PARTICLES(N,pos1x,pos1y,pos2x,pos2y); /* Initialize particles for free boundary problems */ /*-------------------------------------------------*/ if (!strcmp(problem,"drop") || !strcmp(problem,"dam")/* || !strcmp(problem,"icecube")*/) Particlelines = INIT_PARTICLES(&N,imax,jmax,delx,dely,ppc,problem,U,V,P); SETBCOND(U,V,P,TEMP,FLAG,imax,jmax,wW,wE,wN,wS); SETSPECBCOND(problem,U,V,P,TEMP,imax,jmax,UI,VI); /* t i m e l o o p */ /*--------------------*/ t = 0.0; cycle = 0; for(pass = 1; pass <=2; pass++) { for(t,cycle; t < t_end; t+=delt,cycle++) { COMP_delt(&delt, t, imax, jmax, delx, dely, U, V, Re, Pr, tau, &write, del_trace, del_inj, del_streak, del_vec); /* Determine fluid cells for free boundary problems */ /* and set boundary values at free surface */ /*--------------------------------------------------*/ if (!strcmp(problem,"drop") || !strcmp(problem,"dam") || !strcmp(problem,"molding") || !strcmp(problem,"wave") || (pass==2 && !strcmp(problem,"icecube"))) { MARK_CELLS(FLAG,imax,jmax,delx,dely,&ifull,&isurf, N,Particlelines); SET_UVP_SURFACE(U,V,P,FLAG,GX,GY,imax,jmax,Re,delx,dely,delt); } else ifull = imax*jmax-ibound; /* Compute new temperature */ /*-------------------------*/ COMP_TEMP(U,V,TEMP,FLAG,imax,jmax,delt,delx,dely,gamma,Re,Pr); /* Compute tentative velocity field (F,G) */ /*----------------------------------------*/ COMP_FG(U,V,TEMP,F,G,FLAG,imax,jmax,delt,delx,dely,GX,GY,gamma,Re,beta); /* Compute right hand side for pressure equation */ /*-----------------------------------------------*/ COMP_RHS(F,G,RHS,FLAG,imax,jmax,delt,delx,dely); /* Debug Code */ /* printf ("\nGeometry of the fluid domain:\n\n"); for(j=jmax+1;j>=0;j--) { for(i=0;i<=imax+1;i++) printf("%d ", (int) P[i][j]); printf("\n"); } printf("\n\n"); scanf("%d", &a); */ /* End Debug */ /* Solve the pressure equation by successive over relaxation */ /*-----------------------------------------------------------*/ if (ifull > 0) itersor = POISSON(P,RHS,FLAG,imax,jmax,delx,dely, eps,itermax,omg,&res,ifull,p_bound); printf("t_end= %1.5g, t= %1.3e, delt= %1.1e, iterations %3d, res: %e, F-cells: %d, S-cells: %d, B-cells: %d\n", t_end, t+delt, delt, itersor,res,ifull,isurf,ibound); /* Compute the new velocity field */ /*--------------------------------*/ ADAP_UV(U,V,F,G,P,FLAG,imax,jmax,delt,delx,dely); /* Set boundary conditions */ /*-------------------------*/ SETBCOND(U,V,P,TEMP,FLAG,imax,jmax,wW,wE,wN,wS); /* Set special boundary conditions */ /* Overwrite preset default values */ /*---------------------------------*/ SETSPECBCOND(problem,U,V,P,TEMP,imax,jmax,UI,VI); if (!strcmp(problem,"drop") || !strcmp(problem,"dam") || !strcmp(problem,"molding") || !strcmp(problem,"wave") || (!strcmp(problem,"icecube") && pass==2)) SET_UVP_SURFACE(U,V,P,FLAG,GX,GY,imax,jmax,Re,delx,dely,delt); /* Write data for visualization */ /*------------------------------*/ area=0; for(i=0; i<=imax+1; i++) for(j=0; j<=jmax+1; j++) { if(j==jmeas && i==imeas){ WRITEPARAMS(P[i][j], t, "presdata.txt"); WRITEPARAMS(U[i][j], t, "veldata.txt", V[i][j]); } if((FLAG[i][j] & C_E) && j<(ylength/delx*.25)) area+=delx*dely; } if(t==0){ WRITEPARAMS(area, t, "voldata.txt"); } if(area!=oldarea) { WRITEPARAMS(area, t, "voldata.txt"); oldarea=area; } if ((write & 8) && strcmp(vecfile,"none")) { COMPPSIZETA(U,V,PSI,ZETA,FLAG,imax,jmax,delx,dely); COMP_HEAT(U,V,TEMP,HEAT,FLAG,Re,Pr,imax,jmax,delx,dely); OUTPUTVEC_bin(U,V,P,TEMP,PSI,ZETA,HEAT,FLAG,xlength,ylength, imax,jmax,vecfile); } if ((write & 8) && strcmp(outfile,"none")) WRITE_bin(U,V,P,TEMP,FLAG,imax,jmax,outfile); if ((strcmp(tracefile,"none")!=0) && pass==2) PARTICLE_TRACING(tracefile,t,imax,jmax,delx,dely,delt,U,V,FLAG, N,Particlelines,write); if (strcmp(streakfile,"none")) STREAKLINES(streakfile,write,imax,jmax,delx,dely,delt,t, U,V,FLAG,N,Particlelines); } t_end = 20; if(pass==1){ for(i=1;i<=imax;i++) for(j=1;j<=jmax;j++) FLAG[i][j] = C_F; Particlelines = INIT_PARTICLES(&N,imax,jmax,delx,dely,ppc,problem,U,V,P); } /* e n d o f t i m e l o o p */ } if (strcmp(vecfile,"none")) { COMPPSIZETA(U,V,PSI,ZETA,FLAG,imax,jmax,delx,dely); COMP_HEAT(U,V,TEMP,HEAT,FLAG,Re,Pr,imax,jmax,delx,dely); OUTPUTVEC_bin(U,V,P,TEMP,PSI,ZETA,HEAT,FLAG,xlength,ylength, imax,jmax,vecfile); } if (strcmp(outfile,"none")) WRITE_bin(U,V,P,TEMP,FLAG,imax,jmax,outfile); /* printf ("\nGeometry of the fluid domain:\n\n"); for(j=jmax+1;j>=0;j--) { for(i=0;i<=imax+1;i++) printf("%d ", (int) P[i][j]); printf("\n"); } printf("\n\n"); scanf("%d", &a); */ /* free memory */ /*-------------*/ FREE_RMATRIX(U,0,imax+1,0,jmax+1); FREE_RMATRIX(V,0,imax+1,0,jmax+1); FREE_RMATRIX(F,0,imax+1,0,jmax+1); FREE_RMATRIX(G,0,imax+1,0,jmax+1); FREE_RMATRIX(P,0,imax+1,0,jmax+1); FREE_RMATRIX(TEMP,0,imax+1,0,jmax+1); FREE_RMATRIX(PSI,0,imax,0,jmax); FREE_RMATRIX(ZETA,1,imax-1,1,jmax-1); FREE_RMATRIX(HEAT,0,imax,0,jmax); FREE_RMATRIX(RHS,0,imax+1,0,jmax+1); FREE_IMATRIX(FLAG,0,imax+1,0,jmax+1); printf("Program completed in "); printf("%f", difftime(time(NULL), start)); printf(" seconds\n"); printf("End of program\n"); return(0); }
bool UnixSocketAdapter::receive(AmSipRequest &req) { string version; string fct_name; string cmd; string::size_type pos; string cseq_str; if (cacheMsg() < 0) goto failure; // handle API version SAFECTRLCALL1(getParam, version); if (version == "") { // some odd trailer from previous request -- ignore ERROR("odd trailer\n"); goto failure; } if(version != FIFO_VERSION){ ERROR("wrong FIFO Interface version: %s\n",version.c_str()); goto failure; } // handle invoked function SAFECTRLCALL1(getParam, fct_name); if((pos = fct_name.find('.')) != string::npos){ cmd = fct_name.substr(pos+1,string::npos); fct_name = fct_name.substr(0,pos); } if(fct_name != "sip_request") { ERROR("unexpected request function: '%s'\n",fct_name.c_str()); goto failure; } if(cmd.empty()) { ERROR("parameter plug-in name missing.\n"); goto failure; } req.cmd = cmd; #define READ_PARAMETER(p) \ do { \ SAFECTRLCALL1(getParam, p); \ DBG("%s = <%s>\n",#p,p.c_str()); \ } while (0) READ_PARAMETER(req.method); READ_PARAMETER(req.user); READ_PARAMETER(req.domain); READ_PARAMETER(req.dstip); // will be taken for UDP's local peer IP & Contact READ_PARAMETER(req.port); // will be taken for Contact READ_PARAMETER(req.r_uri); // ??? will be taken for the answer's Contact header field ??? READ_PARAMETER(req.from_uri); // will be taken for subsequent request uri READ_PARAMETER(req.from); READ_PARAMETER(req.to); READ_PARAMETER(req.callid); READ_PARAMETER(req.from_tag); READ_PARAMETER(req.to_tag); READ_PARAMETER(cseq_str); if(sscanf(cseq_str.c_str(),"%u", &req.cseq) != 1){ ERROR("invalid cseq number '%s'\n",cseq_str.c_str()); goto failure; } DBG("cseq = <%s>(%i)\n",cseq_str.c_str(),req.cseq); READ_PARAMETER(req.serKey); READ_PARAMETER(req.route); READ_PARAMETER(req.next_hop); SAFECTRLCALL1(getLines,req.hdrs); DBG("hdrs = <%s>\n",req.hdrs.c_str()); SAFECTRLCALL1(getLines,req.body); DBG("body = <%s>\n",req.body.c_str()); if(req.from.empty() || req.to.empty() || req.callid.empty() || req.from_tag.empty()) { ERROR("%s::%s: empty mandatory parameter (from|to|callid|from_tag)\n", __FILE__, __FUNCTION__); goto failure; } return true; failure: return false; #undef READ_PARAMETER }
int AmRequestHandler::execute(AmCtrlInterface* ctrl, const string& cmd) { AmSipRequest req; if(cmd.empty()){ ERROR("AmRequestHandler::execute: parameter plug-in name missing.\n"); return -1; } //req.cmd = cmd; #define READ_PARAMETER(p)\ {\ SAFECTRLCALL1(getParam,p);\ DBG("%s = <%s>\n",#p,p.c_str());\ } READ_PARAMETER(req.method); READ_PARAMETER(req.user); READ_PARAMETER(req.domain); READ_PARAMETER(req.dstip); // will be taken for UDP's local peer IP & Contact READ_PARAMETER(req.port); // will be taken for Contact READ_PARAMETER(req.r_uri); // ??? will be taken for the answer's Contact header field ??? READ_PARAMETER(req.from_uri); // will be taken for subsequent request uri READ_PARAMETER(req.from); READ_PARAMETER(req.to); READ_PARAMETER(req.callid); READ_PARAMETER(req.from_tag); READ_PARAMETER(req.to_tag); string cseq_str; READ_PARAMETER(cseq_str); if(sscanf(cseq_str.c_str(),"%u", &req.cseq) != 1){ ERROR("invalid cseq number '%s'\n",cseq_str.c_str()); return -1; } DBG("cseq = <%s>(%i)\n",cseq_str.c_str(),req.cseq); READ_PARAMETER(req.key); READ_PARAMETER(req.route); READ_PARAMETER(req.next_hop); #undef READ_PARAMETER SAFECTRLCALL1(getLines,req.hdrs); DBG("hdrs = <%s>\n",req.hdrs.c_str()); req.cmd = cmd; SAFECTRLCALL1(getLines,req.body); DBG("body = <%s>\n",req.body.c_str()); if(req.from.empty() || req.to.empty() || req.callid.empty() || req.from_tag.empty()) { throw string("AmRequestHandler::execute: mandatory parameter " "is empty (from|to|callid|from_tag)\n"); } DBG("Request OK: dispatch it!\n"); dispatch(req); return 0; }