/* 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 rkfr 1.0e-6 /* RKF max resolution h=4) h=4*h; else h=sigma*h; /* Alternative method if (err>=emax) h=h/2; if (err<=emin) h=h*2; if (h>hmax) h=hmax; */ /* } while (err>rkfr); */ /* y3 weighted average of operators 5^ order */ y3[0]=(double)(y+(ips5[0]*r1+ips5[2]*r3+ips5[3]*r4+ips5[4]*r5)*h); } ovmain() { char buf[20],rev; 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 in simulation */ x2=(double)0.0; /* time in discharge */ keep=(double)0.0; swi=(double)1.0; /* switch set to 1 = charge */ y=yinit; /* set initial condition parameter vc(o) */ /*h=hmax; /* need for adaptative step */ /* 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; /* increment time in discharge */ } /* 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; /* increment time in simulation */ 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; }