#include <scicos/includes/scicos_block.h>Include dependency graph for bounce4.c:

Go to the source code of this file.
Functions | |
| void | bounce4 (scicos_block *blockp, int flagr) |
| void bounce4 | ( | scicos_block * | blockp, | |
| int | flagr | |||
| ) |
Definition at line 3 of file bounce4.c.
References a, b, scicos_block::g, g, i, i1, scicos_block::ipar, j, scicos_block::jroot, n, scicos_block::nevprt, scicos_block::ng, ng, scicos_block::nx, scicos_block::outptr, outptr, scicos_block::outsz, scicos_block::rpar, s1, s2, t, v, scicos_block::x, x, scicos_block::xd, and xd.
00009 { 00010 00011 int *flag,*nevprt,*nx,*ipar; 00012 int *outsz; 00013 double *x,*xd,*rpar; 00014 double **outptr,*t; 00015 double *g; 00016 int *ng; 00017 scicos_block block; 00018 int *jroot; 00019 00020 00021 int i1; 00022 double d1, d2, d3; 00023 00024 static double a, b, c; 00025 static int i, j, k, n; 00026 static double v, s1, s2, s3, s4, xsi,*y1,*y2; 00027 00028 /* Scicos block simulator */ 00029 /* bouncing ball */ 00030 /* rpar(i): mass of ball i */ 00031 /* rpar(i+n): radius of ball i */ 00032 /* rpar(2n+1:2n+4); [xmin,xmax,ymin,ymax] */ 00033 /* x: [x1,x1',y1,y1',x2,x2',y2,y2',...,yn'] */ 00034 /* n:number of ball=ny1=ny2 */ 00035 /* y1: x-coord des balles */ 00036 /* y2: y-coord des balles */ 00037 /* ipar: storage de taille [nx(n-1)/2=ng]*2 */ 00038 block=*blockp; 00039 flag=&flagr; 00040 nevprt=&block.nevprt; 00041 nx=&block.nx; 00042 ipar=block.ipar; 00043 outsz=block.outsz; 00044 x=block.x; 00045 xd=block.xd; 00046 rpar=block.rpar; 00047 outptr=block.outptr; 00048 00049 g=block.g; 00050 ng=&block.ng; 00051 jroot=block.jroot; 00052 /* Parameter adjustments to index vectors as in Scilab (fortran)*/ 00053 --g; 00054 --ipar; 00055 --rpar; 00056 --x; 00057 --xd; 00058 y1=(double *)outptr[0]; 00059 y2=(double *)outptr[1]; 00060 --y2; 00061 --y1; 00062 --jroot; 00063 00064 n = outsz[0]; 00065 if (*flag == 0) { 00066 c = rpar[(n << 1) + 6]; 00067 i1 = n; 00068 for (i = 1; i <= i1; ++i) { 00069 xd[((i - 1) << 2) + 1] = x[((i - 1) << 2) + 2]; 00070 xd[((i - 1) << 2) + 3] = x[((i - 1) << 2) + 4]; 00071 xd[((i - 1) << 2) + 2] = -c * x[((i - 1) << 2) + 2]; 00072 xd[((i - 1) << 2) + 4] = -rpar[(n << 1) + 5] ; 00073 } 00074 00075 } else if (*flag == 1) { 00076 i1 = n; 00077 for (i = 1; i <= i1; ++i) { 00078 y1[i] = x[(i - 1 << 2) + 1]; 00079 y2[i] = x[(i - 1 << 2) + 3]; 00080 } 00081 } else if (*flag == 9) { 00082 i1 = *ng - (n << 2); 00083 for (k = 1; k <= i1; ++k) { 00084 i = ipar[(k - 1 << 1) + 1]; 00085 j = ipar[(k - 1 << 1) + 2]; 00086 d1 = x[(i - 1 << 2) + 1] - x[(j - 1 << 2) + 1]; 00087 d2 = x[(i - 1 << 2) + 3] - x[(j - 1 << 2) + 3]; 00088 d3 = rpar[i + n] + rpar[j + n]; 00089 g[k] = d1 * d1 + d2 * d2 - d3 * d3; 00090 } 00091 k = *ng - (n << 2) + 1; 00092 i1 = n; 00093 for (i = 1; i <= i1; ++i) { 00094 g[k] = x[(i - 1 << 2) + 3] - rpar[i + n] - rpar[(n << 1) + 3]; 00095 ++k; 00096 g[k] = rpar[(n << 1) + 4] - x[(i - 1 << 2) + 3] - rpar[i + n]; 00097 ++k; 00098 g[k] = x[(i - 1 << 2) + 1] - rpar[(n << 1) + 1] - rpar[i + n]; 00099 ++k; 00100 g[k] = rpar[(n << 1) + 2] - rpar[i + n] - x[(i - 1 << 2) + 1]; 00101 ++k; 00102 } 00103 00104 } else if (*flag == 2 && *nevprt < 0) { 00105 i1 = *ng - (n << 2); 00106 for (k = 1; k <= i1; ++k) { 00107 if (jroot[k] < 0) { 00108 i = ipar[(k - 1 << 1) + 1]; 00109 j = ipar[(k - 1 << 1) + 2]; 00110 s1 = x[(j - 1 << 2) + 1] - x[(i - 1 << 2) + 1]; 00111 s2 = -rpar[i] * s1 / rpar[j]; 00112 s3 = x[(j - 1 << 2) + 3] - x[(i - 1 << 2) + 3]; 00113 s4 = -rpar[i] * s3 / rpar[j]; 00114 a = rpar[i] * (s1 * s1 + s3 * s3) + rpar[j] * (s2 * s2 + s4 00115 * s4); 00116 b = rpar[i] * (s1 * x[(i - 1 << 2) + 2] + s3 * x[(i - 1 00117 << 2) + 4]) + rpar[j] * (s2 * x[(j - 1 << 2) + 2] + 00118 s4 * x[(j - 1 << 2) + 4]); 00119 xsi = -(b * 2. / a); 00120 x[(i - 1 << 2) + 2] += s1 * xsi; 00121 x[(j - 1 << 2) + 2] += s2 * xsi; 00122 x[(i - 1 << 2) + 4] += s3 * xsi; 00123 x[(j - 1 << 2) + 4] += s4 * xsi; 00124 } 00125 } 00126 k = *ng - (n << 2) + 1; 00127 i1 = n; 00128 for (i = 1; i <= i1; ++i) { 00129 if (jroot[k] < 0) { 00130 x[(i - 1 << 2) + 4] = -x[(i - 1 << 2) + 4]; 00131 } 00132 ++k; 00133 if (jroot[k] < 0) { 00134 x[(i - 1 << 2) + 4] = -x[(i - 1 << 2) + 4]; 00135 } 00136 ++k; 00137 if (jroot[k] < 0) { 00138 x[(i - 1 << 2) + 2] = -x[(i - 1 << 2) + 2]; 00139 } 00140 ++k; 00141 if (jroot[k] < 0) { 00142 x[(i - 1 << 2) + 2] = -x[(i - 1 << 2) + 2]; 00143 } 00144 ++k; 00145 } 00146 } 00147 } /* bounce_ */
1.5.1