/[ascend]/trunk/pygtk/integratorreporter.cpp
ViewVC logotype

Contents of /trunk/pygtk/integratorreporter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 944 - (show annotations) (download) (as text)
Sat Nov 25 10:46:13 2006 UTC (13 years ago) by johnpye
File MIME type: text/x-c++src
File size: 4024 byte(s)
Implemented ATOLVECT, ATOL, RTOL parameters for the IDA integrator.
1 #include "integrator.h"
2 #include "integratorreporter.h"
3
4 extern "C"{
5 #include <utilities/error.h>
6 #include <solver/integrator.h>
7 }
8
9 #include <vector>
10 #include <stdexcept>
11 #include <iostream>
12 #include <iterator>
13 #include <sstream>
14 using namespace std;
15
16 //---------------------------------------------
17 // NULL INTEGRATOR REPORTER (makes no output at all)
18
19 IntegratorReporterNull::IntegratorReporterNull(Integrator *integrator) : IntegratorReporterCxx(integrator){
20 // nothing else
21 }
22
23 IntegratorReporterNull::~IntegratorReporterNull(){
24 // nothing else
25 }
26
27 int
28 IntegratorReporterNull::initOutput(){
29 return 1;
30 }
31
32 int IntegratorReporterNull::closeOutput(){
33 return 1;
34 }
35
36 int IntegratorReporterNull::updateStatus(){
37 return 1;
38 }
39
40 int IntegratorReporterNull::recordObservedValues(){
41 return 1;
42 }
43
44 //------------------------------------------------------------------------------
45 // SIMPLE CONSOLE INTEGRATOR REPORTER
46
47 IntegratorReporterConsole::IntegratorReporterConsole(Integrator *integrator)
48 : IntegratorReporterCxx(integrator), f(cout){
49 // nothing else
50 }
51
52 IntegratorReporterConsole::~IntegratorReporterConsole(){
53 // nothing else
54 }
55
56 int
57 IntegratorReporterConsole::initOutput(){
58 long nobs = integrator->getNumObservedVars();
59 stringstream ss;
60 for(long i=0; i<nobs; ++i){
61 if(i){
62 f << "\t";
63 ss << "\t";
64 }
65 Variable v = integrator->getObservedVariable(i);
66 f << v.getName();
67 ss << "-------";
68 }
69 f << endl;
70 f << ss.str() << endl;
71 return 1;
72 }
73
74 int IntegratorReporterConsole::closeOutput(){
75 return 1;
76 }
77
78 int IntegratorReporterConsole::updateStatus(){
79 return 1;
80 }
81
82 int IntegratorReporterConsole::recordObservedValues(){
83 vector<double> data(integrator->getNumObservedVars());
84 integrator_get_observations(integrator->getInternalType(),&data[0]);
85 copy(data.begin(),data.end(),ostream_iterator<double>(f,"\t"));
86 f << endl;
87 return 1;
88 }
89
90 //----------------------------------------------------
91 // DEFAULT INTEGRATOR REPORTER (reporter start and end, outputs time at each step)
92
93 IntegratorReporterCxx::IntegratorReporterCxx(Integrator *integrator){
94 // Initialise the C-API structure with flat function pointers
95 reporter.init = &ascxx_integratorreporter_init;
96 reporter.write = &ascxx_integratorreporter_write;
97 reporter.write_obs = &ascxx_integratorreporter_write_obs;
98 reporter.close = &ascxx_integratorreporter_close;
99 this->integrator=integrator;
100 }
101
102 IntegratorReporterCxx::~IntegratorReporterCxx(){
103 // nothing, just virtual destructor
104 CONSOLE_DEBUG("DESTROYING INTEGRATOR REPORTER CXX");
105 }
106
107 IntegratorReporter *
108 IntegratorReporterCxx::getInternalType(){
109 return &reporter;
110 }
111
112 int
113 IntegratorReporterCxx::initOutput(){
114 return ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"Starting integration reporting...");
115 }
116
117 int
118 IntegratorReporterCxx::closeOutput(){
119 return ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"Closing integration reporting...");
120 }
121
122 int
123 IntegratorReporterCxx::updateStatus(){
124 double t = integrator->getCurrentTime();
125 return ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"t = %f",t);
126 }
127
128 int
129 IntegratorReporterCxx::recordObservedValues(){
130 // CONSOLE_DEBUG("...");
131 double *data = ASC_NEW_ARRAY(double,integrator->getNumObservedVars());
132 integrator_get_observations(integrator->getInternalType(),data);
133 return 0;
134 }
135
136 Integrator *
137 IntegratorReporterCxx::getIntegrator(){
138 return integrator;
139 }
140
141 int ascxx_integratorreporter_init(IntegratorSystem *blsys){
142 IntegratorReporterCxx *r = (IntegratorReporterCxx *)blsys->clientdata;
143 if(r==NULL){
144 throw runtime_error("blsys->clientdata was null");
145 }
146 return r->initOutput();
147 }
148
149 int ascxx_integratorreporter_write(IntegratorSystem *blsys){
150 IntegratorReporterCxx *r = (IntegratorReporterCxx *)blsys->clientdata;
151 return r->updateStatus();
152 }
153
154 int ascxx_integratorreporter_write_obs(IntegratorSystem *blsys){
155 IntegratorReporterCxx *r = (IntegratorReporterCxx *)blsys->clientdata;
156 return r->recordObservedValues();
157 }
158
159 int ascxx_integratorreporter_close(IntegratorSystem *blsys){
160 IntegratorReporterCxx *r = (IntegratorReporterCxx *)blsys->clientdata;
161 return r->closeOutput();
162 }

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