19 #ifndef VARIABLE_VALUE 20 #define VARIABLE_VALUE 23 #include "tensorVal.h" 33 #include <boost/locale.hpp> 41 typedef std::shared_ptr<Group>
GroupPtr;
46 using ITensorVal::operator=;
55 bool unitsCached=
false;
61 bool godleyOverridden=
false;
63 classdesc::Exclude<std::weak_ptr<Group>>
m_scope;
77 const double& valRef()
const;
79 friend class VariableManager;
91 return m_type==flow || m_type==tempFlow;}
94 return type()==tempFlow || type()==undefined;}
97 return m_type!=stock && m_type!=integral && m_type!=undefined;
100 return m_type==constant && (init().empty() || init()==
"0");
110 throw std::runtime_error(
"Index out of range");
111 return operator[](i);
113 double value()
const {
return valueAt(0);}
117 throw std::runtime_error(
"Index out of range");
118 return operator[](i)=x;
121 int idx()
const {
return m_idx;}
124 double operator[](std::size_t i)
const override {
return *(&valRef()+i);}
125 double& operator[](std::size_t i)
override;
127 const Index&
index(Index&& i)
override {
128 std::size_t prevNumElems = size();
130 if (idx()==-1 || !idxInRange() || (prevNumElems<size()))
132 assert(idxInRange());
135 using ITensorVal::index;
139 assert(idx()==-1||idxInRange());
140 std::size_t prevNumElems = size();
141 ITensor::hypercube(x);
142 if (idx()==-1 || (prevNumElems<size()))
144 assert(idxInRange());
147 bool idxInRange()
const;
149 const Hypercube& hypercube()
const override;
150 const Hypercube&
hypercube(
const Hypercube& hc)
override 151 {hypercube_(hc);
return m_hypercube;}
153 {hypercube_(hc);
return m_hypercube;}
154 using ITensorVal::hypercube;
159 this->name=utf_to_utf<char>(name);
171 using ITensorVal::operator=;
181 void exportAsCSV(
const std::string& filename,
const std::string& comment=
"",
bool tabular=
false)
const;
185 const std::string&
init()
const {
return m_init;}
186 const std::string& init(
const std::string& x);
189 void sliderSet(
double x);
191 void incrSlider(
double step);
194 void adjustSliderBounds();
201 static std::vector<double,CIVITA_ALLOCATOR<double>>
stockVars;
205 static std::vector<double,CIVITA_ALLOCATOR<double>>
flowVars;
210 #include "variableValue.cd" 211 #include "variableValue.xcd" 214 #pragma omit pack minsky::VariableValue 215 #pragma omit unpack minsky::VariableValue 223 public classdesc::NullDescriptor<classdesc::pack_t> {};
226 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
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)