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

Contents of /trunk/pygtk/integratorreporter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 940 - (show annotations) (download) (as text)
Fri Nov 24 08:07:33 2006 UTC (13 years, 10 months ago) by johnpye
File MIME type: text/x-c++src
File size: 2888 byte(s)
Fixed 'testLSODE' in test.py, added 'IntegratorReporterNull' that makes no output (for testing purposes)
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 <stdexcept>
10 using namespace std;
11
12 //---------------------------------------------
13 // NULL INTEGRATOR REPORTER (makes no output at all)
14
15 IntegratorReporterNull::IntegratorReporterNull(Integrator *integrator) : IntegratorReporterCxx(integrator){
16 // nothing else
17 }
18
19 IntegratorReporterNull::~IntegratorReporterNull(){
20 // nothing else
21 }
22
23 int
24 IntegratorReporterNull::initOutput(){
25 return 1;
26 }
27
28 int IntegratorReporterNull::closeOutput(){
29 return 1;
30 }
31
32 int IntegratorReporterNull::updateStatus(){
33 return 1;
34 }
35
36 int IntegratorReporterNull::recordObservedValues(){
37 return 1;
38 }
39
40
41 //----------------------------------------------------
42 // DEFAULT INTEGRATOR REPORTER (reporter start and end, outputs time at each step)
43
44 IntegratorReporterCxx::IntegratorReporterCxx(Integrator *integrator){
45 // Initialise the C-API structure with flat function pointers
46 reporter.init = &ascxx_integratorreporter_init;
47 reporter.write = &ascxx_integratorreporter_write;
48 reporter.write_obs = &ascxx_integratorreporter_write_obs;
49 reporter.close = &ascxx_integratorreporter_close;
50 this->integrator=integrator;
51 }
52
53 IntegratorReporterCxx::~IntegratorReporterCxx(){
54 // nothing, just virtual destructor
55 CONSOLE_DEBUG("DESTROYING INTEGRATOR REPORTER CXX");
56 }
57
58 IntegratorReporter *
59 IntegratorReporterCxx::getInternalType(){
60 return &reporter;
61 }
62
63 int
64 IntegratorReporterCxx::initOutput(){
65 return ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"Starting integration reporting...");
66 }
67
68 int
69 IntegratorReporterCxx::closeOutput(){
70 return ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"Closing integration reporting...");
71 }
72
73 int
74 IntegratorReporterCxx::updateStatus(){
75 double t = integrator->getCurrentTime();
76 return ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"t = %f",t);
77 }
78
79 int
80 IntegratorReporterCxx::recordObservedValues(){
81 // CONSOLE_DEBUG("...");
82 double *data = ASC_NEW_ARRAY(double,integrator->getNumObservedVars());
83 integrator_get_observations(integrator->getInternalType(),data);
84 return 0;
85 }
86
87 Integrator *
88 IntegratorReporterCxx::getIntegrator(){
89 return integrator;
90 }
91
92 int ascxx_integratorreporter_init(IntegratorSystem *blsys){
93 IntegratorReporterCxx *r = (IntegratorReporterCxx *)blsys->clientdata;
94 if(r==NULL){
95 throw runtime_error("blsys->clientdata was null");
96 }
97 return r->initOutput();
98 }
99
100 int ascxx_integratorreporter_write(IntegratorSystem *blsys){
101 IntegratorReporterCxx *r = (IntegratorReporterCxx *)blsys->clientdata;
102 return r->updateStatus();
103 }
104
105 int ascxx_integratorreporter_write_obs(IntegratorSystem *blsys){
106 IntegratorReporterCxx *r = (IntegratorReporterCxx *)blsys->clientdata;
107 return r->recordObservedValues();
108 }
109
110 int ascxx_integratorreporter_close(IntegratorSystem *blsys){
111 IntegratorReporterCxx *r = (IntegratorReporterCxx *)blsys->clientdata;
112 return r->closeOutput();
113 }

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