/[ascend]/trunk/models/johnpye/newton.a4c
ViewVC logotype

Contents of /trunk/models/johnpye/newton.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 963 - (show annotations) (download) (as text)
Tue Dec 12 13:36:52 2006 UTC (13 years, 2 months ago) by johnpye
File MIME type: text/x-ascend
File size: 1206 byte(s)
Added ATOLVECT, RTOLVECT parameters to LSODE
Fixed silly bug in testing of newton.a4c
Text changes in ida.c.
1 REQUIRE "ivpsystem.a4l";
2 REQUIRE "atoms.a4l";
3
4 (*
5 Simple dynamic model of object under gravity (for use in test suite).
6 We expect an inverted parabola. Check that after the expected elapsed time,
7 x returns to its starting value and velocity is the negative of the starting
8 value.
9 *)
10 MODEL newton;
11 x IS_A distance;
12 dx_dt IS_A speed;
13 v IS_A speed;
14 dv_dt IS_A acceleration;
15 g IS_A real_constant;
16 g :== 10{N/kg};
17
18 xderiv: dx_dt = v;
19 vderiv: dv_dt = -g;
20
21 t IS_A time;
22 METHODS
23
24 METHOD values;
25 v := +10 {m/s};
26 x := 0 {m};
27 t := 0 {s};
28 END values;
29
30 METHOD specify;
31 FIX x, v;
32 END specify;
33
34 METHOD ode_init;
35 FREE x,v;
36 t.ode_type := -1; t := 0 {s};
37 dx_dt.ode_id := 1; x.ode_id := 1; dx_dt.ode_type := 2; x.ode_type := 1;
38 dv_dt.ode_id := 2; v.ode_id := 2; dv_dt.ode_type := 2; v.ode_type := 1;
39 t.obs_id := 1;
40 x.obs_id := 2;
41 v.obs_id := 3;
42 dv_dt.obs_id := 4;
43 v.ode_atol := 1e-8;
44 x.ode_atol := 1e-8;
45 END ode_init;
46
47 METHOD on_load;
48 RUN reset; RUN values;
49 RUN ode_init;
50 END on_load;
51
52 METHOD self_test;
53 (* assumes integration up to t = (20/9.8){s}; *)
54 ASSERT abs(x - 0 {m}) < 1e-5 {m};
55 ASSERT abs(v +10 {m/s}) < 1e-5 {m/s};
56 ASSERT abs(dv_dt + g) == 0 {m/s^2};
57 END self_test;
58
59 END newton;

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22