~jdpipe/ascend/trunk-old

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*	ASCEND modelling environment
	Copyright (C) 2006 Carnegie Mellon University

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2, or (at your option)
	any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*//** @file
	C++ wrapper for the Integrator interface. Intention is that this will allow
	us to use the PyGTK 'observer' tab to receive the results of an integration
	job, which can then be easily exported to a spreadsheet for plotting (or
	we can implement ASCPLOT style plotting, perhaps).
*/
#ifndef ASCXX_INTEGRATOR_H
#define ASCXX_INTEGRATOR_H

#include <string>
#include <map>
#include <vector>

#include "config.h"
extern "C"{
#include <ascend/integrator/integrator.h>
#include <ascend/integrator/samplelist.h>
}

const int LSODE = INTEG_LSODE;
#ifdef ASC_WITH_IDA
const int IDA = INTEG_IDA;
#endif

#include "simulation.h"
#include "units.h"
#include "integratorreporter.h"
#include "variable.h"

class Integrator{
	friend class IntegratorReporterCxx;
	friend class IntegratorReporterConsole;

public:
	Integrator(Simulation &);
	~Integrator();

	static std::vector<std::string> getEngines();
	void setEngine(const std::string &name);
	std::string getName() const;

	SolverParameters getParameters() const;
	void setParameters(const SolverParameters &);

	void setReporter(IntegratorReporterCxx *reporter);

	void setMinSubStep(double);
	void setMaxSubStep(double);
	void setInitialSubStep(double);
	void setMaxSubSteps(int);

	void setLinearTimesteps(UnitsM units, double start, double end, unsigned long num);
	void setLogTimesteps(UnitsM units, double start, double end, unsigned long num);
	std::vector<double> getCurrentObservations();
	Variable getObservedVariable(const long &i);
	Variable getIndependentVariable();

	void findIndependentVar(); /**< find the independent variable (must not presume a certain choice of integration engine) */
	void analyse();
	void solve();

	/** write out a named matrix associated with the integrator, if possible. type can be NULL for the default matrix. */
	void writeMatrix(FILE *fp,const char *type) const;
	void writeDebug(FILE *fp) const;

	double getCurrentTime();
	long getCurrentStep();
	long getNumSteps();
	int getNumVars();
	int getNumObservedVars();

protected:
	IntegratorSystem *getInternalType();
private:
	Simulation &simulation;
	SampleList *samplelist;
	IntegratorSystem *blsys;
};

#endif