Minsky
minsky::VariableValue Class Reference

#include <variableValue.h>

Inheritance diagram for minsky::VariableValue:
Inheritance graph
Collaboration diagram for minsky::VariableValue:
Collaboration graph

Public Member Functions

bool lhs () const
 variable has an input port More...
 
bool temp () const
 variable is a temporary More...
 
bool isFlowVar () const
 returns true if variable's data is allocated on the flowVariables vector More...
 
bool isZero () const
 
VariableType::Type type () const
 value at the ith location of the vector/tensor. Default, (i=0) is right for scalar quantities More...
 
double valueAt (size_t i) const
 
double value () const
 set the value at the ith location More...
 
double setValue (size_t i, double x)
 
double setValue (double x)
 
int idx () const
 
void reset_idx ()
 
double operator[] (std::size_t i) const override
 
double & operator[] (std::size_t i) override
 
const Index & index (Index &&i) override
 
template<class T >
void hypercube_ (T x)
 
bool idxInRange () const
 
const Hypercube & hypercube () const override
 
const Hypercube & hypercube (const Hypercube &hc) override
 
const Hypercube & hypercube (Hypercube &&hc) override
 
 VariableValue (VariableType::Type type=VariableType::undefined, const std::string &name="", const GroupPtr &group=GroupPtr())
 
 VariableValue (VariableType::Type type, const VariableValue &vv)
 
 VariableValue (const VariableValue &)=delete
 
void operator= (const VariableValue &)=delete
 
VariableValueoperator= (TensorVal const &)
 
VariableValueoperator= (const ITensor &x) override
 
VariableValueallocValue ()
 allocate space in the variable vector. More...
 
std::string valueId () const
 
void exportAsCSV (const std::string &filename, const std::string &comment="", bool tabular=false) const
 export this to a CSV file. If comment is non-empty, it is written as the first line of the file. If tabular is false, there is one data point per line, if true, the the longest dimension is written as a series on the line. More...
 
Summary summary () const
 
const std::string & init () const
 
const std::string & init (const std::string &x)
 
void sliderSet (double x)
 sets variable value (or init value) More...
 
void incrSlider (double step)
 increment slider by step More...
 
void adjustSliderBounds ()
 adjust slider bounds to encompass the current value More...
 
- Public Member Functions inherited from minsky::VariableValueData
void setUnits (const std::string &x)
 
- Public Member Functions inherited from minsky::Slider
double maxSliderSteps () const
 ensure there are at most 10000 steps between sliderMin and Max. see ticket 1255. More...
 

Protected Attributes

std::string m_init
 the initial value of this variable More...
 

Private Member Functions

 CLASSDESC_ACCESS (VariableValue)
 
double & valRef ()
 index into value vector More...
 
const double & valRef () const
 
ITensor::Timestamp timestamp () const override
 

Private Attributes

Type m_type
 
int m_idx =-1
 

Friends

class VariableManager
 
struct SchemaHelper
 

Additional Inherited Members

- Public Types inherited from minsky::VariableType
enum  Type {
  undefined, constant, parameter, flow,
  integral, stock, tempFlow, numVarTypes
}
 
- Static Public Member Functions inherited from minsky::VariableType
static std::string typeName (int t)
 
- Public Attributes inherited from minsky::VariableValueData
TensorVal tensorInit
 when init is a tensor of values, this overrides the init string More...
 
TensorPtr rhs
 when the RHS is attached to a tensor expression, this is a reference to it More...
 
Units units
 dimension units of this value More...
 
bool unitsCached =false
 
std::string detailedText
 long and short descriptions - common to all variables of a given name More...
 
std::string tooltip
 
bool godleyOverridden =false
 
std::string name
 
classdesc::Exclude< std::weak_ptr< Group > > m_scope
 
CSVDialog csvDialog
 for importing CSV files More...
 
- Public Attributes inherited from minsky::Slider
bool sliderStepRel =false
 
double sliderMin =std::numeric_limits<double>::max()
 
double sliderMax =-sliderMin
 
double sliderStep =0
 
bool enableSlider =true
 

Detailed Description

Definition at line 71 of file variableValue.h.

Constructor & Destructor Documentation

◆ VariableValue() [1/3]

minsky::VariableValue::VariableValue ( VariableType::Type  type = VariableType::undefined,
const std::string &  name = "",
const GroupPtr group = GroupPtr() 
)
inline

Definition at line 157 of file variableValue.h.

References minsky::scope().

157  :
158  m_type(type)
159  {
160  this->name=utf_to_utf<char>(name);
162  }
classdesc::Exclude< std::weak_ptr< Group > > m_scope
Definition: variableValue.h:64
size_t scope(const string &name)
extract scope from a qualified variable name
Definition: valueId.cc:83
VariableType::Type type() const
value at the ith location of the vector/tensor. Default, (i=0) is right for scalar quantities ...
Definition: group.tcl:84
Here is the call graph for this function:

◆ VariableValue() [2/3]

minsky::VariableValue::VariableValue ( VariableType::Type  type,
const VariableValue vv 
)
inline

Definition at line 164 of file variableValue.h.

References init(), and TCLcmd::trap::init.

164  : VariableValueData(vv) {
165  m_type=type;
166  init(vv.init());
167  }
VariableType::Type type() const
value at the ith location of the vector/tensor. Default, (i=0) is right for scalar quantities ...
const std::string & init() const
Here is the call graph for this function:

◆ VariableValue() [3/3]

minsky::VariableValue::VariableValue ( const VariableValue )
delete

Member Function Documentation

◆ adjustSliderBounds()

void minsky::VariableValue::adjustSliderBounds ( )

adjust slider bounds to encompass the current value

Definition at line 237 of file variableValue.cc.

References minsky::anonymous_namespace{userFunction.cc}::isfinite(), and minsky::anonymous_namespace{userFunction.cc}::isnan().

238  {
239  if (size()==1 && !isnan(value()))
240  {
241  if (!isfinite(sliderMax) ||sliderMax<value())
242  sliderMax=value()? abs(10*value()):1;
243  if (!isfinite(sliderMin) || sliderMin>=value())
244  sliderMin=value()? -abs(10*value()):-1;
245  assert(sliderMin<sliderMax);
247  }
248  }
double value() const
set the value at the ith location
double sliderStep
Definition: slider.h:34
double sliderMax
Definition: slider.h:34
double maxSliderSteps() const
ensure there are at most 10000 steps between sliderMin and Max. see ticket 1255.
Definition: slider.h:38
double sliderMin
Definition: slider.h:33
Here is the call graph for this function:

◆ allocValue()

VariableValue & minsky::VariableValue::allocValue ( )

allocate space in the variable vector.

Returns
reference to this

Definition at line 121 of file variableValue.cc.

Referenced by minsky::VariableValues::reset(), and minsky::VariableValues::resetValue().

122  {
123  switch (m_type)
124  {
125  case undefined:
126  m_idx=-1;
127  break;
128  case flow:
129  case tempFlow:
130  case constant:
131  case parameter:
133  assert(size());
134  // return a more meaningful error message to the user than what STL does
135  if (ValueVector::flowVars.max_size()-ValueVector::flowVars.size()<size())
136  throw runtime_error("Maximum processing data exceeded.");
137  ValueVector::flowVars.resize(ValueVector::flowVars.size()+size());
138  break;
139  case stock:
140  case integral:
142  assert(size());
143  // return a more meaningful error message to the user than what STL does
144  if (ValueVector::stockVars.max_size()-ValueVector::stockVars.size()<size())
145  throw runtime_error("Maximum processing data exceeded.");
146  ValueVector::stockVars.resize(ValueVector::stockVars.size()+size());
147  break;
148  default: break;
149  }
150  return *this;
151  }
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...
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
Here is the caller graph for this function:

◆ CLASSDESC_ACCESS()

minsky::VariableValue::CLASSDESC_ACCESS ( VariableValue  )
private

◆ exportAsCSV()

void minsky::VariableValue::exportAsCSV ( const std::string &  filename,
const std::string &  comment = "",
bool  tabular = false 
) const

export this to a CSV file. If comment is non-empty, it is written as the first line of the file. If tabular is false, there is one data point per line, if true, the the longest dimension is written as a series on the line.

Definition at line 417 of file variableValue.cc.

References minsky::CSVQuote(), minsky::anonymous_namespace{userFunction.cc}::isfinite(), and minsky::str().

Referenced by minsky::Sheet::exportAsCSV(), and minsky::Ravel::exportAsCSV().

418  {
419  ofstream of(filename);
420  if (!comment.empty())
421  of<<R"(""")"<<comment<<R"(""")"<<endl;
422 
423  // calculate longest dimension
424  auto dims=hypercube().dims();
425  auto longestDim=max_element(dims.begin(),dims.end())-dims.begin();
426 
427  const auto& xv=hypercube().xvectors;
428 
429  ostringstream os;
430  for (const auto& i: xv)
431  {
432  if (&i>xv.data()) os<<",";
433  os<<json(static_cast<const NamedDimension&>(i));
434  }
435  of<<quoted("RavelHypercube=["+os.str()+"]")<<endl;
436  if (tabular)
437  of<<"HorizontalDimension="<<quoted(xv[longestDim].name)<<endl;
438 
439  for (size_t i=0; i<xv.size(); ++i)
440  if (!tabular || i!=longestDim)
441  of<<CSVQuote(xv[i].name,',')<<",";
442 
443  if (tabular)
444  for (size_t k=0; k<dims[longestDim]; ++k)
445  {
446  if (k>0) of<<",";
447  of<<CSVQuote(str(xv[longestDim][k],xv[longestDim].dimension.units),',');
448  }
449  else
450  of<<"value$";
451  of<<"\n";
452 
453  auto idxv=index();
454 
455  if (tabular)
456  {
457  size_t stride=1;
458  for (size_t i=0; i<longestDim; ++i)
459  stride*=dims[i];
460  for (size_t i=0; i<hypercube().numElements(); i+=stride*dims[longestDim])
461  for (size_t j=0; j<stride; ++j)
462  {
463  // collect elements in a buffer, which can be discarded if no data on line
464  bool isData=false;
465  vector<double> data;
466  data.reserve(dims[longestDim]);
467  for (size_t k=0; k<stride*dims[longestDim]; k+=stride)
468  {
469  data.push_back(this->atHCIndex(i+j+k));
470  if (isfinite(data.back())) isData=true;
471  }
472  if (isData)
473  {
474  auto idx=i+j;
475  for (size_t k=0; k<rank(); ++k)
476  {
477  auto div=std::div(idx, ssize_t(dims[k]));
478  if (k!=longestDim)
479  {
480  if (k>1 || (k>0 && longestDim>0)) of<<",";
481  of << "\""<<str(xv[k][div.rem], xv[k].dimension.units) << "\"";
482  }
483  idx=div.quot;
484  }
485  for (auto d: data)
486  {
487  of<<",";
488  if (isfinite(d)) of<<d;
489  }
490  of<<"\n";
491  }
492  }
493  }
494  else
495  {
496  size_t i=0;
497  for (auto d=begin(); d!=end(); ++i, ++d)
498  if (isfinite(*d))
499  {
500  ssize_t idx=idxv.empty()? i: idxv[i];
501  for (size_t j=0; j<rank(); ++j)
502  {
503  auto div=std::div(idx, ssize_t(dims[j]));
504  of << "\""<<str(xv[j][div.rem], xv[j].dimension.units) << "\",";
505  idx=div.quot;
506  }
507  of << *d << "\n";
508  }
509  }
510  }
const Hypercube & hypercube() const override
const Index & index(Index &&i) override
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
std::string CSVQuote(const std::string &x, char sep)
quotes a string if it contains a separator character, and double quotes quotes
Definition: str.h:162
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hypercube() [1/3]

const Hypercube & minsky::VariableValue::hypercube ( ) const
override

Definition at line 213 of file variableValue.cc.

References minsky::cminsky(), minsky::Minsky::definingVar(), and minsky::valueId().

Referenced by minsky::loadValueFromCSVFileT(), and minsky::Minsky::populateMissingDimensionsFromVariable().

214  {
215  if (rhs) return rhs->hypercube();
216  // return the initialisation hypercube if not a defined flowVar
217  if (tensorInit.rank()>0 && (!isFlowVar() || m_type==parameter || !cminsky().definingVar(valueId())))
218  return tensorInit.hypercube();
219  return m_hypercube;
220  }
bool isFlowVar() const
returns true if variable&#39;s data is allocated on the flowVariables vector
Definition: variableValue.h:97
TensorPtr rhs
when the RHS is attached to a tensor expression, this is a reference to it
Definition: variableValue.h:52
TensorVal tensorInit
when init is a tensor of values, this overrides the init string
Definition: variableValue.h:50
VariablePtr definingVar(const std::string &valueId) const
returns reference to variable defining (ie input wired) for valueId
Definition: minsky.cc:205
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
std::string valueId() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hypercube() [2/3]

const Hypercube& minsky::VariableValue::hypercube ( const Hypercube &  hc)
inlineoverride

Definition at line 151 of file variableValue.h.

152  {hypercube_(hc); return m_hypercube;}

◆ hypercube() [3/3]

const Hypercube& minsky::VariableValue::hypercube ( Hypercube &&  hc)
inlineoverride

Definition at line 153 of file variableValue.h.

154  {hypercube_(hc); return m_hypercube;}

◆ hypercube_()

template<class T >
void minsky::VariableValue::hypercube_ ( x)
inline

Definition at line 139 of file variableValue.h.

139  {
140  assert(idx()==-1||idxInRange());
141  std::size_t prevNumElems = size();
142  ITensor::hypercube(x);
143  if (idx()==-1 || (prevNumElems<size()))
144  allocValue();
145  assert(idxInRange());
146  }
virtual const Hypercube & hypercube() const
information describing the axes, types and labels of this tensor
bool idxInRange() const
VariableValue & allocValue()
allocate space in the variable vector.

◆ idx()

int minsky::VariableValue::idx ( ) const
inline

Definition at line 122 of file variableValue.h.

Referenced by minsky::EvalOpPtr::EvalOpPtr(), and minsky::VariableValues::resetValue().

122 {return m_idx;}
Here is the caller graph for this function:

◆ idxInRange()

bool minsky::VariableValue::idxInRange ( ) const

Definition at line 89 of file variableValue.cc.

Referenced by minsky::VariableValues::reset(), and minsky::VariableValues::resetValue().

90  {return m_type==undefined || idx()+size()<=
bool isFlowVar() const
returns true if variable&#39;s data is allocated on the flowVariables vector
Definition: variableValue.h:97
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...
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
Here is the caller graph for this function:

◆ incrSlider()

void minsky::VariableValue::incrSlider ( double  step)

increment slider by step

Definition at line 232 of file variableValue.cc.

References step().

233  {
235  }
double value() const
set the value at the ith location
double sliderStep
Definition: slider.h:34
void sliderSet(double x)
sets variable value (or init value)
step
Definition: minsky.tcl:1289
bool sliderStepRel
Definition: slider.h:30
Here is the call graph for this function:

◆ index()

const Index& minsky::VariableValue::index ( Index &&  i)
inlineoverride

Definition at line 128 of file variableValue.h.

Referenced by minsky::loadValueFromCSVFileT().

128  {
129  std::size_t prevNumElems = size();
130  m_index=i;
131  if (idx()==-1 || !idxInRange() || (prevNumElems<size()))
132  allocValue();
133  assert(idxInRange());
134  return m_index;
135  }
bool idxInRange() const
VariableValue & allocValue()
allocate space in the variable vector.
Here is the caller graph for this function:

◆ init() [1/2]

const std::string& minsky::VariableValue::init ( ) const
inline

Definition at line 186 of file variableValue.h.

Referenced by minsky::VariableBase::init(), minsky::VariableValues::initValue(), MathDAG::latexInit(), MathDAG::matlabInit(), minsky::GodleyIcon::update(), and VariableValue().

186 {return m_init;}
std::string m_init
the initial value of this variable
Definition: variableValue.h:88
Here is the caller graph for this function:

◆ init() [2/2]

const std::string & minsky::VariableValue::init ( const std::string &  x)

Definition at line 201 of file variableValue.cc.

References minsky::cminsky(), minsky::Minsky::definingVar(), minsky::VariableValues::initValue(), minsky::valueId(), and minsky::Minsky::variableValues.

201  {
202  m_init=x;
203  // don't reallocate if initialisation will be ignored (eg wired flow)
204  if (x.empty() || (m_type!=parameter && isFlowVar() && cminsky().definingVar(valueId())))
205  return m_init;
207  if (tensorInit.size()>size()) m_idx=-1; // force reallocation
208  index(tensorInit.index());
209  hypercube(tensorInit.hypercube());
210  return m_init;
211  }
TensorVal initValue(const VariableValue &, std::set< std::string > &visited) const
evaluates the initial value of a given variableValue in the context given by this. visited is used to check for circular definitions
const Hypercube & hypercube() const override
bool isFlowVar() const
returns true if variable&#39;s data is allocated on the flowVariables vector
Definition: variableValue.h:97
VariableValues variableValues
Definition: minsky.h:200
TensorVal tensorInit
when init is a tensor of values, this overrides the init string
Definition: variableValue.h:50
const Index & index(Index &&i) override
VariablePtr definingVar(const std::string &valueId) const
returns reference to variable defining (ie input wired) for valueId
Definition: minsky.cc:205
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
std::string m_init
the initial value of this variable
Definition: variableValue.h:88
std::string valueId() const
Here is the call graph for this function:

◆ isFlowVar()

bool minsky::VariableValue::isFlowVar ( ) const
inline

returns true if variable's data is allocated on the flowVariables vector

Definition at line 97 of file variableValue.h.

Referenced by minsky::EvalOpPtr::EvalOpPtr(), and minsky::VariableValues::resetValue().

Here is the caller graph for this function:

◆ isZero()

bool minsky::VariableValue::isZero ( ) const
inline

Definition at line 100 of file variableValue.h.

References TCLcmd::trap::init.

100  {
101  return m_type==constant && (init().empty() || init()=="0");
102  }
const std::string & init() const

◆ lhs()

bool minsky::VariableValue::lhs ( ) const
inline

variable has an input port

Definition at line 91 of file variableValue.h.

◆ operator=() [1/3]

void minsky::VariableValue::operator= ( const VariableValue )
delete

◆ operator=() [2/3]

VariableValue& minsky::VariableValue::operator= ( TensorVal const &  )

◆ operator=() [3/3]

VariableValue & minsky::VariableValue::operator= ( const ITensor x)
override

Definition at line 111 of file variableValue.cc.

References civita::ITensor::hypercube(), civita::ITensor::index(), and civita::ITensor::size().

112  {
113  index(x.index());
114  hypercube(x.hypercube());
115  assert(idxInRange());
116  for (size_t i=0; i<x.size(); ++i)
117  (*this)[i]=x[i];
118  return *this;
119  }
const Hypercube & hypercube() const override
bool idxInRange() const
const Index & index(Index &&i) override
Here is the call graph for this function:

◆ operator[]() [1/2]

double minsky::VariableValue::operator[] ( std::size_t  i) const
inlineoverride

Definition at line 125 of file variableValue.h.

125 {return *(&valRef()+i);}
double & valRef()
index into value vector

◆ operator[]() [2/2]

double& minsky::VariableValue::operator[] ( std::size_t  i)
override

◆ reset_idx()

void minsky::VariableValue::reset_idx ( )
inline

Definition at line 123 of file variableValue.h.

Referenced by minsky::VariableValues::reset().

123 {m_idx=-1;}
Here is the caller graph for this function:

◆ setValue() [1/2]

double minsky::VariableValue::setValue ( size_t  i,
double  x 
)
inline

Definition at line 116 of file variableValue.h.

116  {
117  if (i>=size())
118  throw std::runtime_error("Index out of range");
119  return operator[](i)=x;
120  }
double operator[](std::size_t i) const override

◆ setValue() [2/2]

double minsky::VariableValue::setValue ( double  x)
inline

Definition at line 121 of file variableValue.h.

References setValue().

Referenced by setValue().

121 {return setValue(0,x);}
double setValue(size_t i, double x)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sliderSet()

void minsky::VariableValue::sliderSet ( double  x)

sets variable value (or init value)

Definition at line 222 of file variableValue.cc.

References TCLcmd::trap::init, minsky::anonymous_namespace{userFunction.cc}::isfinite(), and minsky::to_string().

223  {
224  if (!isfinite(x)) return;
225  if (x<sliderMin) x=sliderMin;
226  if (x>sliderMax) x=sliderMax;
228  init(to_string(x));
229  setValue(x);
230  }
double sliderStep
Definition: slider.h:34
const std::string & init() const
double sliderMax
Definition: slider.h:34
double setValue(size_t i, double x)
double maxSliderSteps() const
ensure there are at most 10000 steps between sliderMin and Max. see ticket 1255.
Definition: slider.h:38
string to_string(CONST84 char *x)
Definition: minskyTCLObj.h:33
double sliderMin
Definition: slider.h:33
Here is the call graph for this function:

◆ summary()

Summary minsky::VariableValue::summary ( ) const

Definition at line 512 of file variableValue.cc.

References minsky::cminsky(), MathDAG::SystemOfEquations::getNodeFromIntVar(), MathDAG::SystemOfEquations::getNodeFromValueId(), TCLcmd::trap::init, minsky::Minsky::model, minsky::scope(), minsky::valueId(), and minsky::var.

513  {
515  MathDAG::VariableDAGPtr varNode;
516  switch (type())
517  {
518  case integral:
519  case stock:
520  varNode=system.getNodeFromIntVar(valueId());
521  break;
522  default:
523  varNode=system.getNodeFromValueId(valueId());
524  break;
525  }
526 
527  string scopeName=":";
528  if (auto scope=m_scope.lock())
529  if (scope!=cminsky().model)
530  scopeName=scope->title.empty()? scope->id(): scope->title;
531 
532  string godleyName;
533  string definition=varNode && varNode->rhs? varNode->rhs->latexStr(): "";
534  string udfDefinition;
535  try
536  {
537  udfDefinition=varNode && varNode->rhs? varNode->rhs->matlabStr():"";
538  }
539  catch (const std::exception& ex)
540  {
541  udfDefinition=ex.what(); // if matlabStr fails, insert error message
542  }
543  if (auto var=cminsky().definingVar(valueId()))
544  {
545  if (auto controller=dynamic_pointer_cast<GodleyIcon>(var->controller.lock()))
546  godleyName=controller->table.title.empty()? controller->id(): controller->table.title;
547  if (auto p=var->ports(1).lock())
548  if (!p->wires().empty())
549  if (auto udf=dynamic_cast<UserFunction*>(&p->wires().front()->from()->item()))
550  {
551  definition="\\text{"+udf->expression+"}";
552  udfDefinition=udf->expression;
553  }
554  }
555 
556 
557  return Summary{
558  valueId(),
559  name,
560  type(),
561  definition,
562  udfDefinition,
563  init(),
565  value(),
566  scopeName,
567  godleyName,
568  hypercube().dims(),
569  units.latexStr()
570  };
571 
572  }
double value() const
set the value at the ith location
classdesc::Exclude< std::weak_ptr< Group > > m_scope
Definition: variableValue.h:64
const Hypercube & hypercube() const override
double sliderStep
Definition: slider.h:34
size_t scope(const string &name)
extract scope from a qualified variable name
Definition: valueId.cc:83
VariableType::Type type() const
value at the ith location of the vector/tensor. Default, (i=0) is right for scalar quantities ...
const std::string & init() const
double sliderMax
Definition: slider.h:34
Units units
dimension units of this value
Definition: variableValue.h:55
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
std::string valueId() const
GroupPtr model
Definition: minsky.h:255
std::string latexStr() const
insert braces around exponents for LaTeX processing
Definition: variableType.cc:40
shared_ptr< VariableDAG > VariableDAGPtr
Definition: equations.h:208
double sliderMin
Definition: slider.h:33
Here is the call graph for this function:

◆ temp()

bool minsky::VariableValue::temp ( ) const
inline

variable is a temporary

Definition at line 94 of file variableValue.h.

94  {
95  return type()==tempFlow || type()==undefined;}
VariableType::Type type() const
value at the ith location of the vector/tensor. Default, (i=0) is right for scalar quantities ...

◆ timestamp()

ITensor::Timestamp minsky::VariableValue::timestamp ( ) const
inlineoverrideprivate

Definition at line 84 of file variableValue.h.

84 {return Timestamp::clock::now();}

◆ type()

VariableType::Type minsky::VariableValue::type ( ) const
inline

value at the ith location of the vector/tensor. Default, (i=0) is right for scalar quantities

Definition at line 104 of file variableValue.h.

◆ valRef() [1/2]

double & minsky::VariableValue::valRef ( )
private

index into value vector

Definition at line 177 of file variableValue.cc.

178  {
179  if (m_idx==-1)
180  allocValue();
181  switch (m_type)
182  {
183  case flow:
184  case tempFlow:
185  case constant:
186  case parameter:
187  assert(idxInRange());
188  if (size_t(m_idx+size())<=ValueVector::flowVars.size())
189  return ValueVector::flowVars[m_idx];
190  case stock:
191  case integral:
192  assert(idxInRange());
193  if (size_t(m_idx+size())<=ValueVector::stockVars.size())
194  return ValueVector::stockVars[m_idx];
195  break;
196  default: break;
197  }
198  throw error("invalid access of variable value reference: %s",name.c_str());
199  }
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...
bool idxInRange() const
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
VariableValue & allocValue()
allocate space in the variable vector.

◆ valRef() [2/2]

const double & minsky::VariableValue::valRef ( ) const
private

Definition at line 153 of file variableValue.cc.

154  {
155  switch (m_type)
156  {
157  case flow:
158  case tempFlow:
159  case constant:
160  case parameter:
161  //assert(idxInRange()); // assertions fail after cancelled reset()
162  if (size_t(m_idx)<ValueVector::flowVars.size())
164  break;
165  case stock:
166  case integral:
167  //assert(idxInRange()); // assertions fail after cancelled reset()
168  if (size_t(m_idx)<ValueVector::stockVars.size())
170  break;
171  default: break;
172  }
173  static const double zero=0;
174  return zero;
175  }
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...
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

◆ value()

double minsky::VariableValue::value ( ) const
inline

set the value at the ith location

Definition at line 114 of file variableValue.h.

◆ valueAt()

double minsky::VariableValue::valueAt ( size_t  i) const
inline

Definition at line 109 of file variableValue.h.

109  {
110  if (i>=size())
111  throw std::runtime_error("Index out of range");
112  return operator[](i);
113  }
double operator[](std::size_t i) const override

◆ valueId()

std::string minsky::VariableValue::valueId ( ) const
inline

Definition at line 179 of file variableValue.h.

References minsky::canonicalName(), and minsky::valueIdFromScope().

Referenced by minsky::VariableValues::resetValue().

179 {return valueIdFromScope(m_scope.lock(),canonicalName(name));}
classdesc::Exclude< std::weak_ptr< Group > > m_scope
Definition: variableValue.h:64
string canonicalName(const string &name)
convert a raw name into a canonical name - this is not idempotent.
Definition: valueId.cc:63
string valueIdFromScope(const GroupPtr &scope, const std::string &name)
value Id from scope and canonical name name
Definition: valueId.cc:128
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ SchemaHelper

friend struct SchemaHelper
friend

Definition at line 81 of file variableValue.h.

◆ VariableManager

friend class VariableManager
friend

Definition at line 80 of file variableValue.h.

Member Data Documentation

◆ m_idx

int minsky::VariableValue::m_idx =-1
private

Definition at line 76 of file variableValue.h.

◆ m_init

std::string minsky::VariableValue::m_init
protected

the initial value of this variable

Definition at line 88 of file variableValue.h.

◆ m_type

Type minsky::VariableValue::m_type
private

Definition at line 75 of file variableValue.h.


The documentation for this class was generated from the following files: