/* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. * * This project is based on 1999-2000 Thesis work of Greco Riccardo. * It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set * by use of double precision floating point operation in Aztec C65 language. * It allow to simulate different mathematical models such as: * Resistance Capacitor electrical circuit, Direct Current electric motor, * Alternative Current three phase induction motor. * * Thanks to Bill Buckels for his invaluable support: * Aztec C compilers http://www.aztecmuseum.ca/compilers.htm */ /* PROCESS MODULE */ #include #include #include #include #define chk 1 /* set chk to 1 charge */ #define rk4r 5.0e-3 /* RK4 max resolution hrk4r); /* RK4 max resolution */ /* y3 plus weighted average of operators 4^ order */ y3[0] = (double)(y+(r1+y3err*r2+y3err*r3+r4)/y3div); } ovmain() { char buf[20],rev;/*conv[4]*/ double atof(); /* DON'T FORGET THIS */ double x,x2,nc,y3,y,errtx,cur,exa; struct data rk; /* inizialization */ cnt=(int)0.0; /* Reset counter */ y3 = (double)0.0; x=(double)0.0; /* time simulation */ x2=(double)0.0; /* time discharge */ keep=(double)0.0; swi=(double)1.0; /* switch set to 1 = charge */ y=yinit; /* set initial condition parameter vc(o) */ /* Start simulation */ scr_clear(); scr_curs(0,0); puts("Pocessing..."); /* open and write header data to file */ open(FILE_NAME,O_WRONLY|O_APPEND,0xC3); write(fd,fbuf,80); buf[0]='\0'; /* buffers reset */ fbuf[0]='\0'; /* RK main Cycle */ while (x time2) { if (chk) { swi=(double)0.0; /* switch set to 0 = discharge */ keep=(double)y3; /* keep the value of vc(td) in the istant of discharge */ !chk; /* NOT chk */ } exa=(double)exact2(x2); errtx=(double)fabs(y3-exa); /* exact solution in discharge */ x2=x2+h; } /* store output in buffer */ ftoa(x,buf,6,2); strcat(fbuf,outr[0]); strcat(fbuf,buf); /* store time (x) */ ftoa(y3,buf,6,2); strcat(fbuf,outr[1]); strcat(fbuf,buf); /* store voltage vc(t) (y3) */ ftoa(errtx,buf,6,2); strcat(fbuf,outr[2]); strcat(fbuf,buf); /* store voltage error vcerr(t) (errtx) */ ftoa(cur,buf,6,2); strcat(fbuf,outr[3]); strcat(fbuf,buf); /* store current i(t) (cur) */ /* converting using max floating resolution */ ftoa(y3,rk.v,14,1); /* vc(t) */ ftoa(cur,rk.i,14,1); /* i(t) */ ftoa(exa,rk.ideal,14,1); /* vc(t) exact solution */ puts(fbuf); /* output to screen */ /* write data result to file */ write(fd,rk.v,20); /* write vc(t) */ write(fd,rk.i,20); /* write i(t) */ write(fd,rk.ideal,20); /* write vc(t) exact solution */ fbuf[0]='\0'; /* reset buffer */ y=y3; x=x+h; cnt++; /* renew counter */ } close(fd); /* close the data file */ /*printf("Cycles number= %d",(cnt-1)); /* NOT YET itoa ? */ puts("Press any key to start plotting..."); getch(); return 0; }