19 #ifndef VARIABLE_VALUE 20 #define VARIABLE_VALUE 23 #include "tensorVal.h" 34 #include <boost/locale.hpp> 42 typedef std::shared_ptr<Group>
GroupPtr;
47 using ITensorVal::operator=;
56 bool unitsCached=
false;
62 bool godleyOverridden=
false;
64 classdesc::Exclude<std::weak_ptr<Group>>
m_scope;
78 const double& valRef()
const;
80 friend class VariableManager;
92 return m_type==flow || m_type==tempFlow;}
95 return type()==tempFlow || type()==undefined;}
98 return m_type!=stock && m_type!=integral && m_type!=undefined;
101 return m_type==constant && (
init().empty() ||
init()==
"0");
111 throw std::runtime_error(
"Index out of range");
112 return operator[](i);
114 double value()
const {
return valueAt(0);}
118 throw std::runtime_error(
"Index out of range");
119 return operator[](i)=x;
122 int idx()
const {
return m_idx;}
125 double operator[](std::size_t i)
const override {
return *(&valRef()+i);}
126 double& operator[](std::size_t i)
override;
128 const Index&
index(Index&& i)
override {
129 std::size_t prevNumElems = size();
131 if (idx()==-1 || !idxInRange() || (prevNumElems<size()))
133 assert(idxInRange());
136 using ITensorVal::index;
140 assert(idx()==-1||idxInRange());
141 std::size_t prevNumElems = size();
142 ITensor::hypercube(x);
143 if (idx()==-1 || (prevNumElems<size()))
145 assert(idxInRange());
148 bool idxInRange()
const;
150 const Hypercube& hypercube()
const override;
151 const Hypercube&
hypercube(
const Hypercube& hc)
override 152 {hypercube_(hc);
return m_hypercube;}
154 {hypercube_(hc);
return m_hypercube;}
155 using ITensorVal::hypercube;
160 this->name=utf_to_utf<char>(name);
172 using ITensorVal::operator=;
182 void exportAsCSV(
const std::string& filename,
const std::string& comment=
"",
bool tabular=
false)
const;
186 const std::string&
init()
const {
return m_init;}
187 const std::string&
init(
const std::string& x);
190 void sliderSet(
double x);
192 void incrSlider(
double step);
195 void adjustSliderBounds();
202 static std::vector<double,CIVITA_ALLOCATOR<double>>
stockVars;
206 static std::vector<double,CIVITA_ALLOCATOR<double>>
flowVars;
211 #include "variableValue.cd" 212 #include "variableValue.xcd" 215 #pragma omit pack minsky::VariableValue 216 #pragma omit unpack minsky::VariableValue 224 public classdesc::NullDescriptor<classdesc::pack_t> {};
227 public classdesc::NullDescriptor<classdesc::unpack_t> {};
double value() const
set the value at the ith location
classdesc::Exclude< std::weak_ptr< Group > > m_scope
bool isFlowVar() const
returns true if variable's data is allocated on the flowVariables vector
const Hypercube & hypercube(Hypercube &&hc) override
static std::vector< double, CIVITA_ALLOCATOR< double > > stockVars
vector of variables that are integrated via Runge-Kutta. These variables label the columns of the God...
void setUnits(const std::string &x)
double valueAt(size_t i) const
VariableValue(VariableType::Type type=VariableType::undefined, const std::string &name="", const GroupPtr &group=GroupPtr())
TensorPtr rhs
when the RHS is attached to a tensor expression, this is a reference to it
size_t scope(const string &name)
extract scope from a qualified variable name
VariableType::Type type() const
value at the ith location of the vector/tensor. Default, (i=0) is right for scalar quantities ...
summary for the variable tab (aka summary tab).
const std::string & init() const
CSVDialog csvDialog
for importing CSV files
struct TCLcmd::trap::init_t init
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky's state cha...
TensorVal tensorInit
when init is a tensor of values, this overrides the init string
std::chrono::time_point< std::chrono::high_resolution_clock > Timestamp
double operator[](std::size_t i) const override
bool temp() const
variable is a temporary
represents the units (in sense of dimensional analysis) of a variable.
VariableValue(VariableType::Type type, const VariableValue &vv)
#define CLASSDESC_ACCESS(type)
Units units
dimension units of this value
const Hypercube & hypercube(const Hypercube &hc) override
const Index & index(Index &&i) override
data structure supporting sliders - shared between constant operations and variables ...
string canonicalName(const string &name)
convert a raw name into a canonical name - this is not idempotent.
double setValue(size_t i, double x)
bool lhs() const
variable has an input port
std::shared_ptr< ITensor > TensorPtr
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table
std::string m_init
the initial value of this variable
string valueIdFromScope(const GroupPtr &scope, const std::string &name)
value Id from scope and canonical name name
ITensor::Timestamp timestamp() const override
std::string valueId() const
std::shared_ptr< Group > GroupPtr
double setValue(double x)