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 |
132 |
|
26 |
|
|
/** |
27 |
johnpye |
772 |
A class to contain singularity information as returned by the DOF |
28 |
|
|
function slvDOF_structsing. |
29 |
|
|
*/ |
30 |
|
|
class SingularityInfo{ |
31 |
|
|
public: |
32 |
|
|
bool isSingular() const; |
33 |
|
|
std::vector<Relation> rels; /**< relations involved in the singularity */ |
34 |
|
|
std::vector<Variable> vars; /**< variables involved in the singularity */ |
35 |
|
|
std::vector<Variable> freeablevars; /**< vars that should be freed */ |
36 |
|
|
}; |
37 |
|
|
|
38 |
johnpye |
775 |
enum StructuralStatus{ |
39 |
|
|
ASCXX_DOF_UNDERSPECIFIED=1, |
40 |
|
|
ASCXX_DOF_SQUARE=2, /* = everything's ok */ |
41 |
|
|
ASCXX_DOF_OVERSPECIFIED=4, |
42 |
|
|
ASCXX_DOF_STRUCT_SINGULAR=3 |
43 |
|
|
}; |
44 |
|
|
|
45 |
johnpye |
772 |
/** |
46 |
johnpye |
164 |
@TODO This class is for *Simulation* instances. |
47 |
johnpye |
132 |
|
48 |
|
|
Handle instantiating, running initialisation functions, solving |
49 |
|
|
and outputing results of solutions. |
50 |
|
|
|
51 |
|
|
In ASCEND C-code, a simulation is a special type of Instance. It |
52 |
|
|
has a 'simulation root' instance which often needs to be used for |
53 |
|
|
solving, inspecting, etc, rather than the simulation instance itself. |
54 |
|
|
*/ |
55 |
|
|
class Simulation : public Instanc{ |
56 |
johnpye |
233 |
friend class IncidenceMatrix; |
57 |
johnpye |
307 |
friend class SolverStatus; |
58 |
johnpye |
669 |
friend class Integrator; |
59 |
johnpye |
233 |
|
60 |
johnpye |
132 |
private: |
61 |
|
|
Instanc simroot; |
62 |
johnpye |
164 |
slv_system_structure *sys; |
63 |
johnpye |
153 |
bool is_built; |
64 |
johnpye |
772 |
SingularityInfo *sing; /// will be used to store this iff singularity found |
65 |
johnpye |
132 |
|
66 |
|
|
// options to pass to BinTokenSetOptions |
67 |
johnpye |
775 |
/// @TODO these should probably be put somewhere else |
68 |
johnpye |
132 |
std::string *bin_srcname; |
69 |
|
|
std::string *bin_objname; |
70 |
|
|
std::string *bin_libname; |
71 |
|
|
std::string *bin_cmd; |
72 |
|
|
std::string *bin_rm; |
73 |
|
|
|
74 |
johnpye |
285 |
int activeblock; |
75 |
|
|
|
76 |
johnpye |
233 |
protected: |
77 |
|
|
slv_system_structure *getSystem(); |
78 |
johnpye |
337 |
|
79 |
johnpye |
132 |
public: |
80 |
johnpye |
164 |
explicit Simulation(Instance *i, const SymChar &name); |
81 |
|
|
Simulation(const Simulation &); |
82 |
|
|
~Simulation(); |
83 |
|
|
|
84 |
johnpye |
132 |
Instanc &getModel(); |
85 |
|
|
void run(const Method &method); |
86 |
johnpye |
774 |
void run(const Method &method, Instanc &model); |
87 |
johnpye |
775 |
enum StructuralStatus checkDoF() const; |
88 |
|
|
void checkInstance(); |
89 |
johnpye |
132 |
void build(); |
90 |
johnpye |
310 |
void solve(Solver s, SolverReporter &reporter); |
91 |
johnpye |
132 |
std::vector<Variable> getFixableVariables(); |
92 |
johnpye |
328 |
std::vector<Variable> getVariablesNearBounds(const double &epsilon=1e-4); |
93 |
|
|
|
94 |
johnpye |
132 |
void write(); |
95 |
|
|
|
96 |
|
|
void setSolver(Solver &s); |
97 |
|
|
const Solver getSolver() const; |
98 |
johnpye |
196 |
|
99 |
johnpye |
208 |
SolverParameters getSolverParameters() const; |
100 |
johnpye |
225 |
void setSolverParameters(SolverParameters &); |
101 |
johnpye |
233 |
|
102 |
|
|
IncidenceMatrix getIncidenceMatrix(); |
103 |
johnpye |
252 |
|
104 |
|
|
const std::string getInstanceName(const Instanc &) const; |
105 |
johnpye |
255 |
|
106 |
|
|
void processVarStatus(); |
107 |
johnpye |
317 |
const int getNumVars(); |
108 |
johnpye |
283 |
|
109 |
johnpye |
285 |
const int getActiveBlock() const; |
110 |
|
|
|
111 |
johnpye |
775 |
std::vector<Variable> getFreeableVariables(); |
112 |
johnpye |
772 |
bool checkStructuralSingularity(); |
113 |
|
|
const SingularityInfo &getSingularityInfo() const; |
114 |
johnpye |
132 |
}; |
115 |
|
|
|
116 |
|
|
|
117 |
|
|
#endif |