/[ascend]/trunk/pygtk/instance.h
ViewVC logotype

Contents of /trunk/pygtk/instance.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1039 - (show annotations) (download) (as text)
Thu Jan 4 23:21:20 2007 UTC (12 years, 11 months ago) by johnpye
File MIME type: text/x-chdr
File size: 4818 byte(s)
Fixed up some #includes in compiler .[ch] files.
Switched instantiate.c to using 'asc_assert' instead of 'assert'.
Added some missing GPL headers in C++ code.
Silenced some slv3.c debug output.
Switch void-return to int-return in slv9_presolve etc (slv9.c)
Attemping to fix solvernotes.py for the commandline environment (browser==None)
Removed redundant solve(SELF) in thermalequilibrium2.a4c.
Some error reporting from addone_calc (extfntest.c).
Expanded test size in extrelfor.a4c.
Big rearrangement of bboxtest.c for top-down style.
Fixed TestFreesteam.testintegrator, added end-value checks.

1 /* ASCEND modelling environment
2 Copyright (C) 2006 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 */
19
20 #ifndef ASCXX_INSTANCE_H
21 #define ASCXX_INSTANCE_H
22
23 #include "symchar.h"
24 #include "type.h"
25 #include "set.h"
26 #include "dimensions.h"
27
28 class Plot;
29
30 #include "config.h"
31 extern "C"{
32 #include <utilities/ascConfig.h>
33 #include <utilities/error.h>
34 #include <compiler/expr_types.h>
35 #include <compiler/instance_enum.h>
36 #include <compiler/atomvalue.h>
37 #include <compiler/plot.h>
38 }
39
40 #include <string>
41 #include <vector>
42
43 typedef enum{
44 ASCXX_VAR_STATUS_UNKNOWN=0, ASCXX_VAR_FIXED, ASCXX_VAR_UNSOLVED, ASCXX_VAR_ACTIVE, ASCXX_VAR_SOLVED
45 } VarStatus;
46
47 /**
48 This class has to be called 'Instanc' in C++ to avoid a name clash
49 with C. Maybe coulda done it with namespaces but didn't know how.
50
51 This class is renamed back to 'Instance' by SWIG, so use 'Instance'
52 when you're in Python.
53
54 The Right Way to implement this class would be as a base class
55 with lots of diffent subclasses for the different atom types.
56 Maybe even multiple inheritance.
57
58 But until the underlying C code is ported to C++ or modularised in
59 some other way, it's not going to be worth the effort. We discussed
60 this in the mailing list.
61 */
62 class Instanc{
63 private:
64 struct Instance *i;
65 SymChar name;
66 std::vector<Instanc> children;
67 void setName(SymChar);
68 static SymChar fixedsym;
69 static SymChar solvervarsym;
70 public:
71 Instanc();
72 Instanc(Instance *i);
73 Instanc(Instance *i, const SymChar &name);
74 Instanc(const Instanc &parent, const unsigned long &childnum);
75 Instanc(const Instanc&);
76 ~Instanc();
77 std::vector<Instanc> &getChildren();
78 Instanc getChild(const SymChar &) const;
79 Instanc getChild(const long &) const;
80 const enum inst_t getKind() const;
81 const std::string getKindStr() const;
82 const Type getType() const;
83 const bool isAtom() const;
84 const bool isFixed() const;
85 const bool isActive() const;
86
87 const bool isFund() const;
88 const bool isConst() const;
89 const bool isCompound() const;
90 const bool isRelation() const;
91 const bool isLogicalRelation() const;
92 const bool isWhen() const;
93 const bool isSet() const;
94 const bool isSetInt() const;
95 const bool isSetString() const;
96 const bool isSetEmpty() const; // set of of type 'empty', NB not same as SetInt::length()==0
97 const bool isArray() const;
98 const bool isDefined() const;
99 const bool isChildless() const;
100 const bool isBool() const;
101 const bool isInt() const;
102 const bool isSymbol() const;
103 const bool isReal() const;
104 const bool isAssigned() const;
105 const bool isModel() const;
106 const SymChar &getName() const;
107 const double getRealValue() const;
108 const bool isDimensionless() const;
109 const Dimensions getDimensions() const;
110 const bool getBoolValue() const;
111 const long getIntValue() const;
112 const SymChar getSymbolValue() const;
113
114 const std::string getValueAsString() const;
115 const std::string getRelationAsString(const Instanc &relative_to) const;
116 Plot getPlot() const;
117
118 const bool isPlottable() const;
119
120 void setFixed(const bool &val=true);
121 void setBoolValue(const bool&, const unsigned &depth=0);
122 void setRealValue(const double&, const unsigned &depth=0);
123 void setRealValueWithUnits(double, const char *, const unsigned &depth=0);
124 void setSymbolValue(const SymChar &);
125
126 template<class T>
127 const ASCXX_Set<T> getSetValue() const{
128 if(!isSet()){
129 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not set-valued",getName().toString());
130 return ASCXX_Set<T>();
131 }
132 if(!isConst() && !isDefined()){
133 ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Variable '%s' is not defined",getName().toString());
134 return ASCXX_Set<T>();
135 }
136 return ASCXX_Set<T>(SetAtomList(i));
137 }
138
139 const enum set_kind getSetType() const;
140 void write();
141 Instance *getInternalType() const;
142
143 void setVarStatus(const VarStatus &); ///< make this one private, just for friend Simulation?
144 const VarStatus getVarStatus() const;
145
146 void setLowerBound(const double &);
147 void setUpperBound(const double &);
148 void setNominal(const double &);
149 const double getLowerBound() const;
150 const double getUpperBound() const;
151 const double getNominal() const;
152
153 const std::vector<Instanc> getClique() const;
154
155 const double getResidual() const;
156 };
157
158 #endif
159

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