Files Classes Functions Hierarchy
#include <desystest.h>
Classes | |
| class | f1 |
| Equation y''+y=0 Assumes xval[0], yi is 2D array and have memory allocated. More... | |
Static Public Member Functions | |
| static void | test01 (int argc, char **argv) |
| Euler on y''+y=0 where y(0)=1 and y'(0)=0. | |
| static void | test02 () |
| TrapezoidEuler on y''+y=0 where y(0)=1 and y'(0)=0. | |
| static int | test03 (int argc, char **argv) |
| Point in time - RungKutta on y''+y=0 where y(0)=1 and y'(0)=0. | |
| static int | test04 (int argc, char **argv) |
| Point in time - Euler on y''+y=0 as 2 equations using desys. | |
| static void | test05 (int argc, char **argv) |
| Spring mass system with 2 masses. | |
Static Public Attributes | |
| static string | doc [] |
| Brief description of each test. | |
Definition at line 5 of file desystest.h.
| void desystest::test01 | ( | int | argc, | |
| char ** | argv | |||
| ) | [static] |
Euler on y''+y=0 where y(0)=1 and y'(0)=0.
Definition at line 88 of file desystest.cpp.
References delta, desys< NINT, T >::eval(), desys< NINT, T >::hstep, commandline::mapvar(), SHOW, and desys< NINT, T >::xval.
Referenced by main().
00089 { 00090 commandline cmd(argc,argv); 00091 00092 //typedef nintegrationRK< desystestf1<double>, double > integrator; 00093 typedef nintegrationRK< f1<double>, double > integrator; 00094 //typedef nintegrationRK< desystestf3<double>, double > integrator; 00095 00096 //desys< eul ,double > de(1,2); 00097 desys< integrator ,double > de(1,2); 00098 00099 //de.yiGet(0,0)=1.0; 00100 //de.yiGet(0,1)=0.0; 00101 00102 // de.yiGet(0,0)=1.0; 00103 // de.yiGet(0,1)=0.0; 00104 de.hstep=0.1; 00105 cmd.mapvar(de.hstep,"h"); 00106 double xmax(0.3); 00107 cmd.mapvar(xmax,"xmax"); 00108 00109 cout << SHOW(de.xval) << endl; 00110 cout << SHOW(de.hstep) << endl; 00111 cout << SHOW(xmax) << endl; 00112 00113 //cout << de << endl; 00114 00115 double delta=1e-10; 00116 for (; de.xval+delta < xmax; de.eval() ) 00117 { 00118 cout << "***---------***" << endl; 00119 cout << de << endl; 00120 } 00121 cout << de << endl; 00122 }
| void desystest::test02 | ( | ) | [static] |
TrapezoidEuler on y''+y=0 where y(0)=1 and y'(0)=0.
Definition at line 124 of file desystest.cpp.
References desys< NINT, T >::eval(), desys< NINT, T >::hstep, desys< NINT, T >::xval, and desys< NINT, T >::yiGet().
Referenced by main().
00125 { 00126 typedef nintegrationTrapezoidEuler< f1<double>, double > eul; 00127 00128 desys< eul ,double > de(1,2); 00129 00130 de.yiGet(0,0)=1.0; 00131 de.yiGet(0,1)=0.0; 00132 de.hstep = 0.001; 00133 00134 cout << de << endl; 00135 00136 for (; de.xval < 0.3; de.eval() ); 00137 cout << de << endl; 00138 cout << de << endl; 00139 }
| int desystest::test03 | ( | int | argc, | |
| char ** | argv | |||
| ) | [static] |
Point in time - RungKutta on y''+y=0 where y(0)=1 and y'(0)=0.
Definition at line 141 of file desystest.cpp.
References assertreturnOS, error, desys< NINT, T >::eval(), desys< NINT, T >::hstep, commandline::mapvar(), SHOW, desys< NINT, T >::xval, and desys< NINT, T >::yiGet().
Referenced by main().
00142 { 00143 typedef nintegrationRK< f1<double>, double > integrator; 00144 00145 desys< integrator ,double > de(1,2); 00146 00147 //de.yiGet(0,0)=1.0; 00148 //de.yiGet(0,1)=0.0; 00149 de.hstep=0.001; 00150 00151 commandline cmd(argc,argv); 00152 cmd.mapvar(de.hstep,"hstep"); 00153 00154 00155 cout << de << endl; 00156 00157 double time_end=0.3; 00158 cmd.mapvar(time_end,"time_end"); 00159 cout << SHOW(time_end) << endl; 00160 00161 // Iterate in time to time_end; 00162 for (; de.xval < time_end; de.eval() ); 00163 00164 cout << de << endl; 00165 00166 double error[2]; 00167 error[0] = abs(cos(de.xval) - de.yiGet(0,0)); 00168 error[1] = abs(-sin(de.xval) - de.yiGet(0,1)); 00169 00170 cout << SHOW(error[0]) << endl; 00171 cout << SHOW(error[1]) << endl; 00172 00173 double myerror=de.hstep*10; 00174 assertreturnOS( error[0] < myerror ); 00175 assertreturnOS( error[1] < myerror ); 00176 00177 return 0; 00178 }
| int desystest::test04 | ( | int | argc, | |
| char ** | argv | |||
| ) | [static] |
Point in time - Euler on y''+y=0 as 2 equations using desys.
Definition at line 220 of file desystest.cpp.
References assertreturnOS, error, desys< NINT, T >::eval(), desys< NINT, T >::hstep, commandline::mapvar(), SHOW, desys< NINT, T >::xval, and desys< NINT, T >::yiGet().
Referenced by main().
00221 { 00222 00223 typedef nintegrationEuler< desystestf2, double > eul; 00224 00225 desys< eul ,double > de(2,1); 00226 00227 de.yiGet(0,0)=0.0; 00228 de.yiGet(1,0)=1.0; 00229 de.hstep=0.00001; 00230 00231 commandline cmd(argc,argv); 00232 00233 cmd.mapvar(de.hstep,"hstep"); 00234 00235 double time_end=0.3; 00236 cmd.mapvar(time_end,"time_end"); 00237 cout << SHOW(time_end) << endl; 00238 00239 cout << de << endl; 00240 00241 for (; de.xval < time_end; de.eval() ); 00242 00243 cout << de << endl; 00244 00245 00246 double error[2]; 00247 error[0] = abs(cos(de.xval) - de.yiGet(1,0)); 00248 error[1] = abs(-sin(de.xval) - de.yiGet(0,0)); 00249 00250 cout << SHOW(error[0]) << endl; 00251 cout << SHOW(error[1]) << endl; 00252 00253 double myerror=de.hstep*100; 00254 assertreturnOS( error[0] < myerror ); 00255 assertreturnOS( error[1] < myerror ); 00256 00257 return 0; 00258 }
| void desystest::test05 | ( | int | argc, | |
| char ** | argv | |||
| ) | [static] |
Spring mass system with 2 masses.
Definition at line 261 of file desystest.cpp.
References desys< NINT, T >::eval(), desys< NINT, T >::hstep, desys< NINT, T >::integrator, commandline::mapvar(), desys< NINT, T >::xval, and desys< NINT, T >::yiGet().
Referenced by main().
00262 { 00263 typedef nintegrationRK< desystestspring2, double > integrator; 00264 desys< integrator, double > de(2,2); 00265 00266 commandline cmd(argc,argv); 00267 00268 double w0=1.0; 00269 double w1=0.0; 00270 double Dw0=0.3; 00271 double Dw1=0.2; 00272 double h=0.001; 00273 00274 cmd.mapvar(w0,"w0"); 00275 cmd.mapvar(Dw0,"Dw0"); 00276 cmd.mapvar(w1,"w1"); 00277 cmd.mapvar(Dw1,"Dw1"); 00278 cmd.mapvar(h,"h"); 00279 00280 de.yiGet(0,0)=w0; 00281 de.yiGet(0,1)=Dw0; 00282 de.yiGet(1,0)=w1; 00283 de.yiGet(1,1)=Dw1; 00284 de.hstep=h; 00285 00286 double k0=0.1; 00287 double k1=0.03; 00288 double k2=0.2; 00289 00290 cmd.mapvar(k0,"k0"); 00291 cmd.mapvar(k1,"k1"); 00292 cmd.mapvar(k2,"k2"); 00293 de.integrator.yDorder.ki[0] = k0; 00294 de.integrator.yDorder.ki[1] = k1; 00295 de.integrator.yDorder.ki[2] = k2; 00296 00297 string filename("myfile.txt"); 00298 cmd.mapvar(filename,"filename"); 00299 00300 ofstream fil(filename.c_str(),ios::trunc); 00301 00302 de.xval = 0.0; 00303 00304 cout << de << endl; 00305 00306 double xmax(0.3); 00307 cmd.mapvar(xmax,"xmax"); 00308 00309 uint width(14); 00310 /* 00311 00312 fil << setw(width) << de.xval; 00313 fil << setw(width) << de.yiGet(0,0); 00314 fil << setw(width) << de.yiGet(1,0); 00315 fil << endl; 00316 */ 00317 00318 long unsigned int sample=1; 00319 long unsigned int counter=0; 00320 00321 cmd.mapvar(sample,"sample"); 00322 00323 for (; de.xval < xmax; de.eval(), ++counter ) 00324 { 00325 if ((counter % sample)!=0) 00326 continue; 00327 00328 00329 fil << setw(width) << de.xval; 00330 fil << setw(width) << de.yiGet(0,0); 00331 fil << setw(width) << de.yiGet(1,0); 00332 fil << endl; 00333 } 00334 // cout << de << endl; 00335 00336 00337 }
string desystest::doc [static] |
Initial value:
{
"",
"Euler on y''+y=0 where y(0)=1 and y'(0)=0.",
"TrapezoidEuler on y''+y=0 where y(0)=1 and y'(0)=0.",
"Point in time - RungKutta on y''+y=0 where y(0)=1 and y'(0)=0.",
"Point in time - Euler on y''+y=0 as 2 equations using desys. ",
"Spring mass system with 2 masses. "
}
Definition at line 10 of file desystest.h.
Referenced by main().
1.5.8