Minsky
minsky::EvalGodley Class Reference

#include <evalGodley.h>

Collaboration diagram for minsky::EvalGodley:
Collaboration graph

Public Member Functions

template<class GodleyIterator >
void initialiseGodleys (const GodleyIterator &begin, const GodleyIterator &end, const VariableValues &values)
 initialise this to a sequence of Godley tables - adaptors provided below More...
 
void eval (double *sv, const double *fv) const
 evaluate Godley tables on sv (of type double[]) and current value of fv (of type double[]), storing result in output variable (of fv). sv is assume to be of size stockVars and fv is assumed to be of size flowVars. More...
 
 EvalGodley ()
 

Public Attributes

bool compatibility
 if compatibility is true, then consttrainst between Godley tables is not applied, and shared columns are merely summed More...
 

Private Member Functions

 CLASSDESC_ACCESS (EvalGodley)
 

Private Attributes

ecolab::array< int > sidx
 representation of matrix connecting flow variables to stock variables More...
 
ecolab::array< int > fidx
 
ecolab::array< double > m
 
ecolab::array< int > initIdx
 index of stock variables that need to be zeroed at start of eval More...
 

Detailed Description

Definition at line 36 of file evalGodley.h.

Constructor & Destructor Documentation

◆ EvalGodley()

minsky::EvalGodley::EvalGodley ( )
inline

Definition at line 60 of file evalGodley.h.

60 : compatibility(false) {}
bool compatibility
if compatibility is true, then consttrainst between Godley tables is not applied, and shared columns ...
Definition: evalGodley.h:63

Member Function Documentation

◆ CLASSDESC_ACCESS()

minsky::EvalGodley::CLASSDESC_ACCESS ( EvalGodley  )
private

◆ eval()

void minsky::EvalGodley::eval ( double *  sv,
const double *  fv 
) const

evaluate Godley tables on sv (of type double[]) and current value of fv (of type double[]), storing result in output variable (of fv). sv is assume to be of size stockVars and fv is assumed to be of size flowVars.

Definition at line 92 of file evalGodley.cc.

93  {
94  for (size_t i=0; i<initIdx.size(); ++i)
95  sv[initIdx[i]]=0;
96 
97  for (size_t i=0; i<sidx.size(); ++i)
98  sv[sidx[i]] += fv[fidx[i]] * m[i];
99  }
ecolab::array< int > fidx
Definition: evalGodley.h:39
ecolab::array< int > sidx
representation of matrix connecting flow variables to stock variables
Definition: evalGodley.h:39
ecolab::array< int > initIdx
index of stock variables that need to be zeroed at start of eval
Definition: evalGodley.h:43
ecolab::array< double > m
Definition: evalGodley.h:40

◆ initialiseGodleys()

template<class GodleyIterator >
void minsky::EvalGodley::initialiseGodleys ( const GodleyIterator &  begin,
const GodleyIterator &  end,
const VariableValues values 
)

initialise this to a sequence of Godley tables - adaptors provided below

Definition at line 121 of file evalGodley.h.

References minsky::SharedColumnCheck::checkShared(), minsky::SharedColumnCheck::checkSharedColDefs(), minsky::trimWS(), and minsky::SharedColumnCheck::updateColDefs().

123  {
124  SharedColumnCheck scCheck;
125  sidx.resize(0);
126  fidx.resize(0);
127  m.resize(0);
128 
129  std::set<int> iidx;
130 
131  for (GodleyIterator g=begin; g!=end; ++g)
132  {
133  if (g.data().empty()) continue;
134  // check for shared columns
135  if (!compatibility)
136  for (std::size_t col=1; col<g.data()[0].size(); ++col)
137  if (!trimWS(g.data()[0][col]).empty())
138  scCheck.checkShared(g.valueId(trimWS(g.data()[0][col])), g.assetClass(col));
139 
140  for (std::size_t row=1; row<g.data().size(); ++row)
141  if (!g.initialConditionRow(row))
142  for (std::size_t col=1; col<g.data()[row].size(); ++col)
143  {
144  FlowCoef fvc(g.data()[row][col]);
145  auto svName=col<g.data()[0].size()? trimWS(g.data()[0][col]): "";
146  if (fvc.name.empty() || svName.empty()) continue;
147  fvc.name=g.valueId(fvc.name);
148  svName=g.valueId(svName);
149 
150  auto fv=values.find(fvc.name);
151  auto sv=values.find(svName);
152  if (fv!=values.end() && sv!=values.end() &&
153  fv->second->idx()>=0 && sv->second->idx()>=0)
154  {
155  // check for compatible column definitions
156  if (!compatibility &&
157  scCheck.updateColDefs(svName, fvc))
158  continue;
159 
160  iidx.insert(sv->second->idx());
161  sidx<<=sv->second->idx();
162  fidx<<=fv->second->idx();
163  m<<=fvc.coef;
164  }
165  }
166  }
167 
168  initIdx.clear();
169  for (auto i: iidx)
170  initIdx<<=i;
171 
172  if (!compatibility)
173  scCheck.checkSharedColDefs();
174  }
ecolab::array< int > fidx
Definition: evalGodley.h:39
ecolab::array< int > sidx
representation of matrix connecting flow variables to stock variables
Definition: evalGodley.h:39
bool compatibility
if compatibility is true, then consttrainst between Godley tables is not applied, and shared columns ...
Definition: evalGodley.h:63
std::string trimWS(const std::string &s)
Definition: str.h:49
ecolab::array< int > initIdx
index of stock variables that need to be zeroed at start of eval
Definition: evalGodley.h:43
ecolab::array< double > m
Definition: evalGodley.h:40
Here is the call graph for this function:

Member Data Documentation

◆ compatibility

bool minsky::EvalGodley::compatibility

if compatibility is true, then consttrainst between Godley tables is not applied, and shared columns are merely summed

Definition at line 63 of file evalGodley.h.

◆ fidx

ecolab::array<int> minsky::EvalGodley::fidx
private

Definition at line 39 of file evalGodley.h.

◆ initIdx

ecolab::array<int> minsky::EvalGodley::initIdx
private

index of stock variables that need to be zeroed at start of eval

Definition at line 43 of file evalGodley.h.

◆ m

ecolab::array<double> minsky::EvalGodley::m
private

Definition at line 40 of file evalGodley.h.

◆ sidx

ecolab::array<int> minsky::EvalGodley::sidx
private

representation of matrix connecting flow variables to stock variables

Definition at line 39 of file evalGodley.h.


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