/[ascend]/trunk/models/force1d.a4c
ViewVC logotype

Contents of /trunk/models/force1d.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Fri Oct 29 20:54:12 2004 UTC (19 years, 10 months ago) by aw0a
File MIME type: text/x-ascend
File size: 11958 byte(s)
Setting up web subdirectory in repository
1 REQUIRE "atoms.a4l";
2 (* => atoms.a4l, measures.a4l, system.a4l, basemodel.a4l *)
3 REQUIRE "plot.a4l";
4 (* => plot.a4l, atoms.a4l, measures.a4l, system.a4l, basemodel.a4l *)
5 PROVIDE "force1d.a4c";
6 (*
7 * This file is part of the ASCEND Modeling Library and is released
8 * under the GNU Public License as described at the end of this file.
9 *)
10
11 CONSTANT spring_constant REFINES real_constant DIMENSION M/T^2;
12 CONSTANT position_constant REFINES real_constant DIMENSION L;
13 ATOM position REFINES distance DEFAULT 0{m};
14 END position;
15
16 MODEL force_base() REFINES cmumodel();
17 NOTES
18 'purpose' SELF {
19 This set of models illustrates building complex mechanical
20 systems from simple components at perhaps the level of
21 junior high school physics.
22 It does this primarily as an excuse to demonstrate
23 the plt_plot models and the ALIASES/ISA statement of ASCEND.
24 }
25 'revision' SELF {
26 $Revision: 1.2 $
27 }
28 END NOTES;
29 END force_base;
30
31 MODEL test_force_base() REFINES testcmumodel;
32 END test_force_base;
33
34 MODEL hook REFINES force_base;
35 NOTES
36 'purpose' SELF {
37 Hooks are used to connect masses, springs, and other
38 objects. Each hook defines a point in a 1-dimensional coordinate
39 system and computes a force balance at that point.
40 Some other model must set one of the forces and the position.
41 The hook is stationary in this MODEL since no net force term is written.
42 }
43 END NOTES;
44
45 F_left, F_right IS_A force;
46 F_left = F_right;
47 X IS_A position;
48 NOTES 'ascii-picture' SELF {
49 F_left <--O--> F_right
50 }
51 END NOTES;
52
53 METHODS
54 (* generated code for hook to be customized or corrected. *)
55 METHOD default_all;
56 RUN default_self;
57 END default_all;
58 METHOD default_self;
59 (* ATOM defaults are fine *)
60 END default_self;
61 METHOD check_all;
62 RUN check_self;
63 END check_all;
64 METHOD check_self;
65 END check_self;
66 METHOD bound_all;
67 RUN bound_self;
68 END bound_all;
69 METHOD bound_self;
70 END bound_self;
71 METHOD scale_all;
72 RUN scale_self;
73 END scale_all;
74 METHOD scale_self;
75 F_left.nominal := abs(F_left) * 1.001 + 1.0e-4{N};
76 F_right.nominal := abs(F_right) * 1.001 + 1.0e-4{N};
77 X.nominal := abs(X) * 1.001 + 1.0e-4{?};
78 END scale_self;
79
80 METHOD specify;
81 F_right.fixed := TRUE;
82 END specify;
83 METHOD specify_float;
84 END specify_float;
85
86 END hook;
87
88 MODEL massless_spring(
89 k IS_A spring_constant;
90 h_left WILL_BE hook;
91 h_right WILL_BE hook;
92 ) WHERE (
93 h_left, h_right WILL_NOT_BE_THE_SAME;
94 ) REFINES force_base;
95
96 L0, dx IS_A distance;
97
98 (* spring takes up space *)
99 (* compute right end of spring position. *)
100 h_right.X = h_left.X + L0 + dx;
101
102 (* spring may exert force if loaded. *)
103 F = k * dx;
104 h_left.F_right = F;
105 h_right.F_left = F;
106 F IS_A force;
107
108 NOTES 'ascii-picture' SELF {
109 O--/\/\/\/\/\/--O
110 |-L0-|-dx-|
111 }
112 END NOTES;
113 METHODS
114
115 METHOD default_self;
116 dx := 1{cm};
117 L0 := 10{cm};
118 END default_self;
119
120 METHOD default_all;
121 RUN h_left.default_all;
122 RUN h_right.default_all;
123 RUN default_self;
124 END default_all;
125
126 METHOD check_all;
127 RUN h_left.check_all;
128 RUN h_right.check_all;
129 RUN check_self;
130 END check_all;
131
132 METHOD check_self;
133 END check_self;
134
135 METHOD bound_all;
136 RUN h_left.bound_all;
137 RUN h_right.bound_all;
138 RUN bound_self;
139 END bound_all;
140
141 METHOD bound_self;
142 END bound_self;
143
144 METHOD scale_all;
145 RUN h_left.scale_all;
146 RUN h_right.scale_all;
147 RUN scale_self;
148 END scale_all;
149
150 METHOD scale_self;
151 F.nominal := abs(F) * 1.001 + 1.0e-4{N};
152 L0.nominal := abs(L0) * 1.001 + 1.0e-4{m};
153 dx.nominal := abs(dx) * 1.001 + 1.0e-4{m};
154 END scale_self;
155
156 METHOD specify;
157 L0.fixed := TRUE;
158 RUN h_left.reset;
159 RUN h_right.reset;
160 h_left.F_right.fixed := FALSE;
161 h_left.X.fixed := TRUE;
162 END specify;
163
164 METHOD specify_float;
165 L0.fixed := TRUE;
166 RUN h_left.specify_float;
167 RUN h_right.specify_float;
168 END specify_float;
169
170 END massless_spring;
171
172 MODEL massless_block(
173 h_left WILL_BE hook;
174 h_right WILL_BE hook;
175 ) WHERE (
176 h_left, h_right WILL_NOT_BE_THE_SAME;
177 ) REFINES force_base;
178
179 (* this block has no momentum or acceleration so it is massless *)
180 width IS_A distance;
181
182 (* condition of the block not moving *)
183 h_left.F_right = h_right.F_left;
184 (* block takes up space *)
185 h_right.X = h_left.X + width;
186
187 X "center of the block" IS_A position;
188 X = width/2 + h_left.X;
189
190 NOTES 'ascii-picture' SELF {
191 ___
192 O--| |--O
193 |___|
194 }
195 END NOTES;
196 METHODS
197
198 METHOD default_self;
199 width := 3{cm};
200 END default_self;
201
202
203 METHOD default_all;
204 RUN h_left.default_all;
205 RUN h_right.default_all;
206 RUN default_self;
207 END default_all;
208
209 METHOD check_all;
210 RUN h_left.check_all;
211 RUN h_right.check_all;
212 RUN check_self;
213 END check_all;
214
215 METHOD check_self;
216 END check_self;
217
218 METHOD bound_all;
219 RUN h_left.bound_all;
220 RUN h_right.bound_all;
221 RUN bound_self;
222 END bound_all;
223
224 METHOD bound_self;
225 END bound_self;
226
227 METHOD scale_all;
228 RUN h_left.scale_all;
229 RUN h_right.scale_all;
230 RUN scale_self;
231 END scale_all;
232
233 METHOD scale_self;
234 width.nominal := abs(width) * 1.001 + 1.0e-4{m};
235 END scale_self;
236
237 METHOD specify;
238 width.fixed := TRUE;
239 RUN h_left.reset;
240 h_left.F_right.fixed := FALSE;
241 h_left.X.fixed := TRUE;
242 RUN h_right.reset;
243 END specify;
244
245 METHOD specify_float;
246 width.fixed := TRUE;
247 RUN h_left.specify_float;
248 RUN h_right.specify_float;
249 END specify_float;
250
251 END massless_block;
252
253 MODEL anchor(
254 x IS_A position_constant;
255 h_right WILL_BE hook;
256 ) REFINES force_base;
257
258 h_right.X = x;
259 F = h_right.F_left;
260 F IS_A force;
261
262 NOTES 'ascii-picture' SELF {
263 \\--O
264 }
265 END NOTES;
266 METHODS
267
268 METHOD default_self;
269 END default_self;
270
271 METHOD default_all;
272 RUN h_right.default_all;
273 RUN default_self;
274 END default_all;
275
276 METHOD check_all;
277 RUN h_right.check_all;
278 RUN check_self;
279 END check_all;
280
281 METHOD check_self;
282 END check_self;
283
284 METHOD bound_all;
285 RUN h_right.bound_all;
286 RUN bound_self;
287 END bound_all;
288
289 METHOD bound_self;
290 END bound_self;
291
292 METHOD scale_all;
293 RUN h_right.scale_all;
294 RUN scale_self;
295 END scale_all;
296
297 METHOD scale_self;
298 F.nominal := abs(F) * 1.001 + 1.0e-4{N};
299 END scale_self;
300
301 METHOD specify;
302 RUN h_right.reset;
303 END specify;
304
305 METHOD specify_float;
306 END specify_float;
307
308 END anchor;
309
310 MODEL finger(
311 h1 WILL_BE hook;
312 ) REFINES force_base;
313 pull IS_A force;
314 h1.F_right = pull;
315
316 NOTES 'ascii-picture' SELF {
317 __
318 O(_ \
319 \ \
320 }
321 END NOTES;
322 METHODS
323 METHOD default_self;
324 pull := 3{N};
325 END default_self;
326
327 METHOD default_all;
328 RUN h1.default_all;
329 RUN default_self;
330 END default_all;
331
332 METHOD check_all;
333 RUN h1.check_all;
334 RUN check_self;
335 END check_all;
336
337 METHOD check_self;
338 END check_self;
339
340 METHOD bound_all;
341 RUN h1.bound_all;
342 RUN bound_self;
343 END bound_all;
344
345 METHOD bound_self;
346 END bound_self;
347
348 METHOD scale_all;
349 RUN h1.scale_all;
350 RUN scale_self;
351 END scale_all;
352
353 METHOD scale_self;
354 pull.nominal := abs(pull) * 1.001 + 1.0e-4{N};
355 END scale_self;
356
357 METHOD specify;
358 RUN h1.reset;
359 h1.F_right.fixed := FALSE;
360 pull.fixed := TRUE;
361 END specify;
362
363 END finger;
364
365
366 MODEL finger_test() REFINES test_force_base();
367
368 NOTES 'ascii-picture' SELF {
369 ___ __
370 \\--O--/\/\/\/\/\/--O--| |--O(_ \
371 |___| \ \
372 (reference)-h1-(s1)-h2-(m1)-h3-(pinky)
373 }
374 END NOTES;
375
376 reference IS_A anchor(0.0{m},h1);
377 h1 IS_A hook;
378 s1 IS_A massless_spring(100{kg/s^2},h1,h2);
379 h2 IS_A hook;
380 m1 IS_A massless_block(h2,h3);
381 h3 IS_A hook;
382 pinky IS_A finger(h3);
383
384 METHODS
385 (* generated code for finger_test to be customized or corrected. *)
386 METHOD default_all;
387 RUN default_self;
388 END default_all;
389
390 METHOD default_self;
391 RUN h1.default_self;
392 RUN h2.default_self;
393 RUN h3.default_self;
394 RUN m1.default_self;
395 RUN pinky.default_self;
396 RUN reference.default_self;
397 RUN s1.default_self;
398 END default_self;
399
400 METHOD check_all;
401 RUN check_self;
402 END check_all;
403
404 METHOD check_self;
405 RUN h1.check_self;
406 RUN h2.check_self;
407 RUN h3.check_self;
408 RUN m1.check_self;
409 RUN pinky.check_self;
410 RUN reference.check_self;
411 RUN s1.check_self;
412 END check_self;
413
414 METHOD bound_all;
415 RUN bound_self;
416 END bound_all;
417
418 METHOD bound_self;
419 RUN h1.bound_self;
420 RUN h2.bound_self;
421 RUN h3.bound_self;
422 RUN m1.bound_self;
423 RUN pinky.bound_self;
424 RUN reference.bound_self;
425 RUN s1.bound_self;
426 END bound_self;
427
428 METHOD scale_all;
429 RUN scale_self;
430 END scale_all;
431
432 METHOD scale_self;
433 RUN h1.scale_self;
434 RUN h2.scale_self;
435 RUN h3.scale_self;
436 RUN m1.scale_self;
437 RUN pinky.scale_self;
438 RUN reference.scale_self;
439 RUN s1.scale_self;
440 END scale_self;
441
442 METHOD specify;
443 RUN m1.specify_float;
444 RUN pinky.reset;
445 RUN reference.specify_float;
446 RUN s1.specify_float;
447 END specify;
448 END finger_test;
449
450 MODEL spring_test() REFINES test_force_base();
451
452 NOTES 'ascii-picture' SELF {
453 ___ __
454 \\--O--/\/\/\/\/\/--O--| |--O(_ \
455 |___| \ \
456 (reference)-h1-(s1)-h2-(s2)-h3-(pinky)
457 }
458 END NOTES;
459
460 reference IS_A anchor(0.0{m},h1);
461 h1 IS_A hook;
462 s1 IS_A massless_spring(100{kg/s^2},h1,h2);
463 h2 IS_A hook;
464 s2 IS_A massless_spring(75{kg/s^2},h2,h3);
465 h3 IS_A hook;
466 pinky IS_A finger(h3);
467
468 METHODS
469 (* generated code for finger_test to be customized or corrected. *)
470 METHOD default_all;
471 RUN default_self;
472 END default_all;
473
474 METHOD default_self;
475 RUN h1.default_self;
476 RUN h2.default_self;
477 RUN h3.default_self;
478 RUN s2.default_self;
479 RUN pinky.default_self;
480 RUN reference.default_self;
481 RUN s1.default_self;
482 END default_self;
483
484 METHOD check_all;
485 RUN check_self;
486 END check_all;
487
488 METHOD check_self;
489 RUN h1.check_self;
490 RUN h2.check_self;
491 RUN h3.check_self;
492 RUN s2.check_self;
493 RUN pinky.check_self;
494 RUN reference.check_self;
495 RUN s1.check_self;
496 END check_self;
497
498 METHOD bound_all;
499 RUN bound_self;
500 END bound_all;
501
502 METHOD bound_self;
503 RUN h1.bound_self;
504 RUN h2.bound_self;
505 RUN h3.bound_self;
506 RUN s2.bound_self;
507 RUN pinky.bound_self;
508 RUN reference.bound_self;
509 RUN s1.bound_self;
510 END bound_self;
511
512 METHOD scale_all;
513 RUN scale_self;
514 END scale_all;
515
516 METHOD scale_self;
517 RUN h1.scale_self;
518 RUN h2.scale_self;
519 RUN h3.scale_self;
520 RUN s2.scale_self;
521 RUN pinky.scale_self;
522 RUN reference.scale_self;
523 RUN s1.scale_self;
524 END scale_self;
525
526 METHOD specify;
527 RUN pinky.reset;
528 RUN reference.specify_float;
529 RUN s1.specify_float;
530 RUN s2.specify_float;
531 END specify;
532
533 END spring_test;
534
535 MODEL plot_spring_test;
536
537 (* create our model *)
538 st IS_A spring_test;
539
540 (* Now gather the sampled data into an array for plotting *)
541 x_data[Xset] ALIASES (st.h1.X,st.h2.X,st.h3.X)
542 WHERE Xset IS_A set OF integer_constant;
543
544 (* Now create the Y coordinates of the plot since there is no
545 * natural Y coordinate in our MODEL.
546 *)
547 y_data[Xset] IS_A real; (* all will be assigned to 1.0 *)
548
549 X_curve IS_A plt_curve(Xset,y_data,x_data);
550
551 (* Make X_curve into the expected array for plt_plot *)
552 curves[curve_set] ALIASES (X_curve) WHERE
553 curve_set IS_A set OF integer_constant;
554
555 Plot_X IS_A plt_plot_integer(curve_set,curves);
556
557 METHODS
558
559 METHOD default_self;
560 RUN st.default_self;
561 st.s1.L0 := 0.2{m};
562 RUN X_curve.default_self;
563 RUN Plot_X.default_self;
564 FOR i IN Xset DO
565 y_data[i] := i;
566 END FOR;
567 X_curve.legend := 'meter';
568 Plot_X.title := 'Hook locations';
569 Plot_X.XLabel := 'location';
570 Plot_X.YLabel := 'hook #';
571 END default_self;
572
573 END plot_spring_test;
574
575
576 (*
577 * force1d.a4c
578 * by Ben Allan
579 * Part of the ASCEND Library
580 * $Date: 1998/06/17 19:06:54 $
581 * $Revision: 1.2 $
582 * $Author: mthomas $
583 * $Source: /afs/cs.cmu.edu/project/ascend/Repository/models/force1d.a4c,v $
584 *
585 * This file is part of the ASCEND Modeling Library.
586 *
587 * Copyright (C) 1998 Carnegie Mellon University
588 *
589 * The ASCEND Modeling Library is free software; you can redistribute
590 * it and/or modify it under the terms of the GNU General Public
591 * License as published by the Free Software Foundation; either
592 * version 2 of the License, or (at your option) any later version.
593 *
594 * The ASCEND Modeling Library is distributed in hope that it will be
595 * useful, but WITHOUT ANY WARRANTY; without even the implied
596 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
597 * See the GNU General Public License for more details.
598 *
599 * You should have received a copy of the GNU General Public License
600 * along with the program; if not, write to the Free Software
601 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check
602 * the file named COPYING.
603 *)

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