1 |
johnpye |
132 |
#ifndef ASCXX_SIMULATION_H |
2 |
|
|
#define ASCXX_SIMULATION_H |
3 |
|
|
|
4 |
|
|
#include <string> |
5 |
|
|
#include <vector> |
6 |
johnpye |
255 |
#include <map> |
7 |
johnpye |
132 |
|
8 |
|
|
#include "symchar.h" |
9 |
|
|
#include "type.h" |
10 |
|
|
#include "instance.h" |
11 |
johnpye |
772 |
#include "variable.h" |
12 |
|
|
#include "relation.h" |
13 |
johnpye |
132 |
|
14 |
johnpye |
480 |
#include "config.h" |
15 |
johnpye |
132 |
extern "C"{ |
16 |
|
|
#include <compiler/createinst.h> |
17 |
|
|
#include <solver/slv_types.h> |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
class Solver; |
21 |
johnpye |
208 |
class SolverParameters; |
22 |
johnpye |
307 |
class SolverStatus; |
23 |
johnpye |
233 |
class IncidenceMatrix; |
24 |
johnpye |
310 |
class SolverReporter; |
25 |
johnpye |
1126 |
class Matrix; |
26 |
johnpye |
132 |
|
27 |
|
|
/** |
28 |
johnpye |
772 |
A class to contain singularity information as returned by the DOF |
29 |
|
|
function slvDOF_structsing. |
30 |
|
|
*/ |
31 |
|
|
class SingularityInfo{ |
32 |
|
|
public: |
33 |
|
|
bool isSingular() const; |
34 |
|
|
std::vector<Relation> rels; /**< relations involved in the singularity */ |
35 |
|
|
std::vector<Variable> vars; /**< variables involved in the singularity */ |
36 |
|
|
std::vector<Variable> freeablevars; /**< vars that should be freed */ |
37 |
|
|
}; |
38 |
|
|
|
39 |
johnpye |
775 |
enum StructuralStatus{ |
40 |
|
|
ASCXX_DOF_UNDERSPECIFIED=1, |
41 |
|
|
ASCXX_DOF_SQUARE=2, /* = everything's ok */ |
42 |
|
|
ASCXX_DOF_OVERSPECIFIED=4, |
43 |
|
|
ASCXX_DOF_STRUCT_SINGULAR=3 |
44 |
|
|
}; |
45 |
|
|
|
46 |
johnpye |
772 |
/** |
47 |
johnpye |
164 |
@TODO This class is for *Simulation* instances. |
48 |
johnpye |
132 |
|
49 |
|
|
Handle instantiating, running initialisation functions, solving |
50 |
|
|
and outputing results of solutions. |
51 |
|
|
|
52 |
|
|
In ASCEND C-code, a simulation is a special type of Instance. It |
53 |
|
|
has a 'simulation root' instance which often needs to be used for |
54 |
|
|
solving, inspecting, etc, rather than the simulation instance itself. |
55 |
johnpye |
972 |
|
56 |
|
|
The Simulation can be exported to an Integrator (for time-stepping) |
57 |
|
|
or a Solver (for steady-state solutions). |
58 |
|
|
|
59 |
|
|
At present the architecture is a bit muddy wrt to way that Solvers and |
60 |
|
|
Integrators 'act on' the Simulation. We need to work on improving the |
61 |
|
|
delimitation of solver and integrator, and keeping better track of the |
62 |
|
|
state of the Simulation (has it been 'built', etc). |
63 |
johnpye |
132 |
*/ |
64 |
|
|
class Simulation : public Instanc{ |
65 |
johnpye |
233 |
friend class IncidenceMatrix; |
66 |
johnpye |
307 |
friend class SolverStatus; |
67 |
johnpye |
669 |
friend class Integrator; |
68 |
johnpye |
233 |
|
69 |
johnpye |
132 |
private: |
70 |
|
|
Instanc simroot; |
71 |
johnpye |
164 |
slv_system_structure *sys; |
72 |
johnpye |
153 |
bool is_built; |
73 |
johnpye |
772 |
SingularityInfo *sing; /// will be used to store this iff singularity found |
74 |
johnpye |
285 |
int activeblock; |
75 |
|
|
|
76 |
johnpye |
233 |
protected: |
77 |
|
|
slv_system_structure *getSystem(); |
78 |
johnpye |
969 |
Simulation(); |
79 |
johnpye |
337 |
|
80 |
johnpye |
132 |
public: |
81 |
johnpye |
164 |
explicit Simulation(Instance *i, const SymChar &name); |
82 |
|
|
Simulation(const Simulation &); |
83 |
|
|
~Simulation(); |
84 |
|
|
|
85 |
johnpye |
132 |
Instanc &getModel(); |
86 |
johnpye |
900 |
|
87 |
|
|
void runDefaultMethod(); |
88 |
johnpye |
132 |
void run(const Method &method); |
89 |
johnpye |
774 |
void run(const Method &method, Instanc &model); |
90 |
johnpye |
775 |
enum StructuralStatus checkDoF() const; |
91 |
|
|
void checkInstance(); |
92 |
johnpye |
132 |
void build(); |
93 |
johnpye |
310 |
void solve(Solver s, SolverReporter &reporter); |
94 |
johnpye |
132 |
std::vector<Variable> getFixableVariables(); |
95 |
johnpye |
328 |
std::vector<Variable> getVariablesNearBounds(const double &epsilon=1e-4); |
96 |
johnpye |
1117 |
std::vector<Variable> getFixedVariables(); |
97 |
johnpye |
1126 |
Matrix getMatrix(); |
98 |
johnpye |
328 |
|
99 |
johnpye |
132 |
void write(); |
100 |
|
|
|
101 |
|
|
void setSolver(Solver &s); |
102 |
|
|
const Solver getSolver() const; |
103 |
johnpye |
196 |
|
104 |
johnpye |
1133 |
SolverParameters getParameters() const; |
105 |
|
|
void setParameters(SolverParameters &); |
106 |
johnpye |
233 |
|
107 |
|
|
IncidenceMatrix getIncidenceMatrix(); |
108 |
johnpye |
252 |
|
109 |
|
|
const std::string getInstanceName(const Instanc &) const; |
110 |
johnpye |
255 |
|
111 |
|
|
void processVarStatus(); |
112 |
johnpye |
317 |
const int getNumVars(); |
113 |
johnpye |
283 |
|
114 |
johnpye |
285 |
const int getActiveBlock() const; |
115 |
|
|
|
116 |
johnpye |
775 |
std::vector<Variable> getFreeableVariables(); |
117 |
johnpye |
772 |
bool checkStructuralSingularity(); |
118 |
|
|
const SingularityInfo &getSingularityInfo() const; |
119 |
johnpye |
132 |
}; |
120 |
|
|
|
121 |
|
|
|
122 |
|
|
#endif |