Minsky: 3.17.0
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 70 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 156 of file variableValue.h.

References minsky::group, and minsky::scope().

156  :
157  m_type(type)
158  {
159  this->name=utf_to_utf<char>(name);
161  }
classdesc::Exclude< std::weak_ptr< Group > > m_scope
Definition: variableValue.h:63
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 ...
Here is the call graph for this function:

◆ VariableValue() [2/3]

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

Definition at line 163 of file variableValue.h.

References init().

163  : VariableValueData(vv) {
164  m_type=type;
165  init(vv.init());
166  }
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 (!of)
421  throw runtime_error("Unable to open "+filename+" for writing.");
422  if (!comment.empty())
423  of<<R"(""")"<<comment<<R"(""")"<<endl;
424 
425  // calculate longest dimension
426  auto dims=hypercube().dims();
427  auto longestDim=max_element(dims.begin(),dims.end())-dims.begin();
428 
429  const auto& xv=hypercube().xvectors;
430 
431  ostringstream os;
432  for (const auto& i: xv)
433  {
434  if (&i>xv.data()) os<<",";
435  os<<json(static_cast<const NamedDimension&>(i));
436  }
437  of<<quoted("RavelHypercube=["+os.str()+"]")<<endl;
438  if (tabular && rank()>0)
439  of<<"HorizontalDimension="<<quoted(xv[longestDim].name)<<endl;
440 
441  for (size_t i=0; i<xv.size(); ++i)
442  if (!tabular || i!=longestDim)
443  of<<CSVQuote(xv[i].name,',')<<",";
444 
445  if (tabular && rank()>0)
446  for (size_t k=0; k<dims[longestDim]; ++k)
447  {
448  if (k>0) of<<",";
449  of<<CSVQuote(str(xv[longestDim][k],xv[longestDim].dimension.units),',');
450  }
451  else
452  of<<"value$";
453  of<<"\n";
454 
455  auto idxv=index();
456 
457  if (tabular && rank()>0)
458  {
459  size_t stride=1;
460  for (size_t i=0; i<longestDim; ++i)
461  stride*=dims[i];
462  for (size_t i=0; i<hypercube().numElements(); i+=stride*dims[longestDim])
463  for (size_t j=0; j<stride; ++j)
464  {
465  // collect elements in a buffer, which can be discarded if no data on line
466  bool isData=false;
467  vector<double> data;
468  data.reserve(dims[longestDim]);
469  for (size_t k=0; k<stride*dims[longestDim]; k+=stride)
470  {
471  data.push_back(this->atHCIndex(i+j+k));
472  if (isfinite(data.back())) isData=true;
473  }
474  if (isData)
475  {
476  auto idx=i+j;
477  for (size_t k=0; k<rank(); ++k)
478  {
479  auto div=std::div(idx, ssize_t(dims[k]));
480  if (k!=longestDim)
481  {
482  if (k>1 || (k>0 && longestDim>0)) of<<",";
483  of << "\""<<str(xv[k][div.rem], xv[k].dimension.units) << "\"";
484  }
485  idx=div.quot;
486  }
487  for (auto d: data)
488  {
489  of<<",";
490  if (isfinite(d)) of<<d;
491  }
492  of<<"\n";
493  }
494  }
495  }
496  else
497  {
498  size_t i=0;
499  for (auto d=begin(); d!=end(); ++i, ++d)
500  if (isfinite(*d))
501  {
502  ssize_t idx=idxv.empty()? i: idxv[i];
503  for (size_t j=0; j<rank(); ++j)
504  {
505  auto div=std::div(idx, ssize_t(dims[j]));
506  of << "\""<<str(xv[j][div.rem], xv[j].dimension.units) << "\",";
507  idx=div.quot;
508  }
509  of << *d << "\n";
510  }
511  }
512  }
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::Ravel::exportAsCSV(), 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:96
TensorPtr rhs
when the RHS is attached to a tensor expression, this is a reference to it
Definition: variableValue.h:51
TensorVal tensorInit
when init is a tensor of values, this overrides the init string
Definition: variableValue.h:49
VariablePtr definingVar(const std::string &valueId) const
returns reference to variable defining (ie input wired) for valueId
Definition: minsky.cc:204
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
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 150 of file variableValue.h.

151  {hypercube_(hc); return m_hypercube;}

◆ hypercube() [3/3]

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

Definition at line 152 of file variableValue.h.

153  {hypercube_(hc); return m_hypercube;}

◆ hypercube_()

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

Definition at line 138 of file variableValue.h.

138  {
139  assert(idx()==-1||idxInRange());
140  std::size_t prevNumElems = size();
141  ITensor::hypercube(x);
142  if (idx()==-1 || (prevNumElems<size()))
143  allocValue();
144  assert(idxInRange());
145  }
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 121 of file variableValue.h.

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

121 {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:96
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.

233  {
234  sliderSet(value()+step*(sliderStepRel? value(): 1)*sliderStep);
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)
bool sliderStepRel
Definition: slider.h:30

◆ index()

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

Definition at line 127 of file variableValue.h.

Referenced by minsky::loadValueFromCSVFileT().

127  {
128  std::size_t prevNumElems = size();
129  m_index=i;
130  if (idx()==-1 || !idxInRange() || (prevNumElems<size()))
131  allocValue();
132  assert(idxInRange());
133  return m_index;
134  }
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 185 of file variableValue.h.

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

185 {return m_init;}
std::string m_init
the initial value of this variable
Definition: variableValue.h:87
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:96
VariableValues variableValues
Definition: minsky.h:188
TensorVal tensorInit
when init is a tensor of values, this overrides the init string
Definition: variableValue.h:49
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:204
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
std::string m_init
the initial value of this variable
Definition: variableValue.h:87
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 96 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 99 of file variableValue.h.

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

◆ lhs()

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

variable has an input port

Definition at line 90 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 124 of file variableValue.h.

124 {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 122 of file variableValue.h.

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

122 {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 115 of file variableValue.h.

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

◆ setValue() [2/2]

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

Definition at line 120 of file variableValue.h.

References setValue().

Referenced by setValue().

120 {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 minsky::anonymous_namespace{userFunction.cc}::isfinite().

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
double sliderMin
Definition: slider.h:33
Here is the call graph for this function:

◆ summary()

Summary minsky::VariableValue::summary ( ) const

Definition at line 514 of file variableValue.cc.

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

515  {
517  MathDAG::VariableDAGPtr varNode;
518  switch (type())
519  {
520  case integral:
521  case stock:
522  varNode=system.getNodeFromIntVar(valueId());
523  break;
524  default:
525  varNode=system.getNodeFromValueId(valueId());
526  break;
527  }
528 
529  string scopeName=":";
530  if (auto scope=m_scope.lock())
531  if (scope!=cminsky().model)
532  scopeName=scope->title.empty()? scope->id(): scope->title;
533 
534  string godleyName;
535  string definition=varNode && varNode->rhs? varNode->rhs->latexStr(): "";
536  string udfDefinition;
537  try
538  {
539  udfDefinition=varNode && varNode->rhs? varNode->rhs->matlabStr():"";
540  }
541  catch (const std::exception& ex)
542  {
543  udfDefinition=ex.what(); // if matlabStr fails, insert error message
544  }
545  if (auto var=cminsky().definingVar(valueId()))
546  {
547  if (auto controller=dynamic_pointer_cast<GodleyIcon>(var->controller.lock()))
548  godleyName=controller->table.title.empty()? controller->id(): controller->table.title;
549  if (auto p=var->ports(1).lock())
550  if (!p->wires().empty())
551  if (auto udf=dynamic_cast<UserFunction*>(&p->wires().front()->from()->item()))
552  {
553  definition="\\text{"+udf->expression+"}";
554  udfDefinition=udf->expression;
555  }
556  }
557 
558 
559  return Summary{
560  valueId(),
561  name,
562  type(),
563  definition,
564  udfDefinition,
565  init(),
567  value(),
568  scopeName,
569  godleyName,
570  hypercube().dims(),
571  units.latexStr()
572  };
573 
574  }
double value() const
set the value at the ith location
classdesc::Exclude< std::weak_ptr< Group > > m_scope
Definition: variableValue.h:63
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:54
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
std::string valueId() const
GroupPtr model
Definition: minsky.h:242
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 93 of file variableValue.h.

93  {
94  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 83 of file variableValue.h.

83 {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 103 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 113 of file variableValue.h.

◆ valueAt()

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

Definition at line 108 of file variableValue.h.

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

◆ valueId()

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

Definition at line 178 of file variableValue.h.

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

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

178 {return valueIdFromScope(m_scope.lock(),canonicalName(name));}
classdesc::Exclude< std::weak_ptr< Group > > m_scope
Definition: variableValue.h:63
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 80 of file variableValue.h.

◆ VariableManager

friend class VariableManager
friend

Definition at line 79 of file variableValue.h.

Member Data Documentation

◆ m_idx

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

Definition at line 75 of file variableValue.h.

◆ m_init

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

the initial value of this variable

Definition at line 87 of file variableValue.h.

◆ m_type

Type minsky::VariableValue::m_type
private

Definition at line 74 of file variableValue.h.


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