/[ascend]/trunk/models/westerberg/ivpDimensional/ivpStep.AWW.tcl
ViewVC logotype

Annotation of /trunk/models/westerberg/ivpDimensional/ivpStep.AWW.tcl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 669 - (hide annotations) (download) (as text)
Wed Jun 21 07:00:45 2006 UTC (13 years, 4 months ago) by johnpye
File MIME type: text/x-tcl
File size: 3989 byte(s)
Merged changes from DAE branch (revisions 702 to 819) back into trunk.
This adds the Integration API to the ASCEND solver (in base/generic).
Also provides pre-alpha support for 'IDA' from the SUNDIALS suite, a DAE solver.
Many other minor code clean-ups, including adoption of new 'ASC_NEW' and friends (to replace 'ascmalloc')
Added some very sketchy stuff providing 'DIFF(...)' syntax, although it is anticipated that this will be removed.
1 aw0a 87 proc IVP.AWW.Integrator {qlfdid method relativeError maxNumberSolves xUnits initDeltaX maxDeltaX stopX} {
2    
3     # qkfdid stands for qualified id (this name occurs often in ASCEND
4     # tcl code)
5     # method must have value Am or Bdf and is used to set integration
6     # method
7     # relativeError is the desired relative integration error, e.g., 1.0e-3.
8     # maxNumberSolves is max number of model solves the integrator is allowed
9     # to perform before forcibly stopping, e.g., 1000.
10     # xUnits are the units in which all following parameters are given for
11     # the independent variable X, e.g., second.
12     # initDeltaX is the initial value to use for the stepsize for X.
13     # maxDeltaX is the maximum value for X the integrator should use when
14     # stepping.
15     # stopX is the stopping value for X.
16    
17     global ascSolvStatVect;
18    
19     # Solve initial point
20    
21     RUN $qlfdid.valuesForInitializing;
22     RUN $qlfdid.specifyForInitializing;
23     SOLVE $qlfdid.currentPt WITH QRSlv;
24     if { !$ascSolvStatVect(converged) } {
25     error "Initial point solve: Equations for model did not converge";
26     }
27    
28     # Prepare to take first integration step
29    
30     DELETE SYSTEM;
31     RUN $qlfdid.valuesForStepping;
32     RUN $qlfdid.specifyForStepping;
33    
34     # Run one of the following to set the method
35    
36     switch $method {
37     {Am} -
38     {Bdf} {}
39     default {
40     error "Expected Am or Bdf as method";
41     }
42     }
43     RUN $qlfdid.setUseMethodTo$method;
44    
45     # Set initial step size, integration error, stopping
46     # point
47    
48     ASSIGN $qlfdid.deltaX $initDeltaX $xUnits;
49     ASSIGN $qlfdid.maxDeltaX $maxDeltaX $xUnits;
50     ASSIGN $qlfdid.maxNominalSteppingError $relativeError;
51     ASSIGN $qlfdid.stopX $stopX $xUnits;
52    
53     set numberSolves 1;
54     set ascStopCondHit 0;
55     set ascThisIsTheFinalStep 0;
56    
57     # Integrate
58    
59     while {$numberSolves < $maxNumberSolves} {
60    
61     incr numberSolves;
62     set ascPolyOrder [u_getval $qlfdid.usePolyOrder];
63     set ascPolyOrderValue [lindex $ascPolyOrder 0];
64     set ivp_steps $ascPolyOrderValue;
65    
66     for {set ivp_i 1} {$ivp_i <= $ivp_steps} {incr ivp_i} {
67     if {[expr ($ascThisIsTheFinalStep == 0)]} {
68     if {[expr ($ascStopCondHit == 0)]} {
69     RUN $qlfdid.stepX;
70     }
71 johnpye 669 SOLVE $qlfdid WITH QRSlv;
72 aw0a 87 if {!$ascSolvStatVect(converged)} {
73     error "Model solution $numberSolves: Equations for model did not converge.";
74     }
75 johnpye 669 }
76 aw0a 87 if {[expr ($ascThisIsTheFinalStep == 1)]} {
77     error "Model solution $numberSolves: STOP condition reached";
78 johnpye 669 }
79 aw0a 87
80     RUN $qlfdid.setStopConditions;
81     set ascStopCondHit [lindex [u_getval $qlfdid.stopCondHit] 0];
82     set ascThisIsTheFinalStep [lindex [u_getval $qlfdid.thisIsTheFinalStep] 0];
83    
84     }
85    
86     RUN $qlfdid.computeMaxNominalStepsForEachVariable;
87    
88     }
89    
90     error "Model solution $numberSolves: Maximum solutions reached. Stopping.";
91    
92     }
93    
94    
95     proc getBoolean {varName} {
96     # proc for getting value of boolean atoms
97     qlfdid $varName
98     set bval [inst atomvalue search]
99     return $bval
100     }
101    
102    
103     proc getAttribute {varName attrName} {
104     # proc for getting value of atom attributes
105     # in the case of attributes with units, does not return units.
106     qlfdid $varName
107     set cnames "[inst child search]"
108     set cindex [lsearch $cnames $attrName]
109     if {$cindex < 0} {
110     error "No child named $attrName"
111     }
112     # children index from 1,not 0, so the list position is cindex++
113     incr cindex
114     set cdata [brow_child_list search $cindex VALUE]
115     # modify the next lines if you want to return units also
116     set cval [lindex [lindex $cdata 0] 2]
117     return $cval
118     }
119    

Properties

Name Value
svn:executable *

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