/[ascend]/trunk/ascxx/simulation.h
ViewVC logotype

Contents of /trunk/ascxx/simulation.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2327 - (show annotations) (download) (as text)
Wed Dec 22 07:17:24 2010 UTC (13 years, 8 months ago) by jpye
File MIME type: text/x-chdr
File size: 3442 byte(s)
Merging in refactor of the C++ code, which is moved out of 'pygtk' and into 'ascxx'.
Adding support for IPOPT 3.9.1, the current latest version.
Support in dtar for parallel builds (possibly needs some testing still).
1 #ifndef ASCXX_SIMULATION_H
2 #define ASCXX_SIMULATION_H
3
4 #include <string>
5 #include <vector>
6 #include <map>
7
8 #include "symchar.h"
9 #include "type.h"
10 #include "instance.h"
11 #include "variable.h"
12 #include "relation.h"
13
14 #include <cstdio>
15
16 #include "config.h"
17 extern "C"{
18 #include <ascend/compiler/createinst.h>
19 #include <ascend/system/slv_types.h>
20 }
21
22 class Solver;
23 class SolverParameters;
24 class SolverStatus;
25 class IncidenceMatrix;
26 class SolverReporter;
27 class Matrix;
28 class SolverHooks;
29
30 /**
31 A class to contain singularity information as returned by the DOF
32 function slvDOF_structsing.
33 */
34 class SingularityInfo{
35 public:
36 bool isSingular() const;
37 std::vector<Relation> rels; /**< relations involved in the singularity */
38 std::vector<Variable> vars; /**< variables involved in the singularity */
39 std::vector<Variable> freeablevars; /**< vars that should be freed */
40 };
41
42 enum StructuralStatus{
43 ASCXX_DOF_UNDERSPECIFIED=1,
44 ASCXX_DOF_SQUARE=2, /* = everything's ok */
45 ASCXX_DOF_OVERSPECIFIED=4,
46 ASCXX_DOF_STRUCT_SINGULAR=3
47 };
48
49 /**
50 @TODO This class is for *Simulation* instances.
51
52 Handle instantiating, running initialisation functions, solving
53 and outputing results of solutions.
54
55 In ASCEND C-code, a simulation is a special type of Instance. It
56 has a 'simulation root' instance which often needs to be used for
57 solving, inspecting, etc, rather than the simulation instance itself.
58
59 The Simulation can be exported to an Integrator (for time-stepping)
60 or a Solver (for steady-state solutions).
61
62 At present the architecture is a bit muddy wrt to way that Solvers and
63 Integrators 'act on' the Simulation. We need to work on improving the
64 delimitation of solver and integrator, and keeping better track of the
65 state of the Simulation (has it been 'built', etc).
66 */
67 class Simulation : public Instanc{
68 friend class IncidenceMatrix;
69 friend class SolverStatus;
70 friend class Integrator;
71 friend class System;
72 private:
73 Instanc simroot;
74 slv_system_t sys;
75 bool is_built;
76 SingularityInfo *sing; /// will be used to store this iff singularity found
77 int activeblock;
78 SolverHooks *solverhooks;
79 protected:
80 slv_system_t getSystem();
81 Instanc getRoot();
82 public:
83 explicit Simulation(Instance *i, const SymChar &name);
84 Simulation(const Simulation &);
85 ~Simulation();
86
87 Instanc &getModel();
88
89 void runDefaultMethod();
90 void run(const Method &method);
91 void run(const Method &method, Instanc &model);
92 enum StructuralStatus checkDoF() const;
93 void checkInstance();
94
95 void build();
96
97 void solve(Solver s, SolverReporter &reporter);
98
99 std::vector<Variable> getFixableVariables();
100 std::vector<Variable> getVariablesNearBounds(const double &epsilon=1e-4);
101 std::vector<Variable> getVariablesFarFromNominals(const double &bignum);
102 std::vector<Variable> getFixedVariables();
103 std::vector<Variable> getallVariables();
104 Matrix getMatrix();
105
106 void write(FILE *fp,const char *type=NULL) const;
107
108 void setSolver(Solver &s);
109 const Solver getSolver() const;
110
111 SolverParameters getParameters() const;
112 void setParameters(SolverParameters &);
113
114 IncidenceMatrix getIncidenceMatrix();
115
116 const std::string getInstanceName(const Instanc &) const;
117
118 void processVarStatus();
119 const int getNumVars();
120
121 const int getActiveBlock() const;
122
123 std::vector<Variable> getFreeableVariables();
124 bool checkStructuralSingularity();
125 const SingularityInfo &getSingularityInfo() const;
126
127 void setSolverHooks(SolverHooks *H);
128 SolverHooks *getSolverHooks() const;
129 };
130
131 #endif

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