Xyce  6.1
N_DEV_Synapse3.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2015 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-----------------------------------------------------------------------------
26 // Filename : $RCSfile: N_DEV_Synapse3.h,v $
27 //
28 // Purpose : Simple delay synapse
29 //
30 // Special Notes :
31 //
32 // Creator : Rich Schiek, SNL, Electrical Systems Modeling
33 //
34 // Creation Date : 01/25/2011
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.38 $
40 //
41 // Revision Date : $Date: 2015/10/26 20:07:26 $
42 //
43 // Current Owner : $Author: rlschie $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Synapse3_h
47 #define Xyce_N_DEV_Synapse3_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceMaster.h>
52 #include <N_DEV_DeviceBlock.h>
53 #include <N_DEV_DeviceInstance.h>
54 #include <N_DEV_DeviceModel.h>
55 #include <N_UTL_RandomNumbers.h>
56 
57 #include <N_DEV_Synapse.h>
58 
59 
60 #include <Sacado.hpp>
61 
62 namespace Xyce {
63 namespace Device {
64 namespace Synapse3 {
65 
66 class Model;
67 class Instance;
68 
69 struct Traits : public DeviceTraits<Model, Instance, Synapse::Traits>
70 {
71  static const char *name() {return "Synapse, Clopath";}
72  static const char *deviceTypeName() {return "YSYNAPSE level 3";}
73  static int numNodes() {return 2;}
74  static bool isLinearDevice() {return true;}
75 
76  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
77  static void loadModelParameters(ParametricData<Model> &model_parameters);
78  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
79 };
80 
81 //-----------------------------------------------------------------------------
82 // Class : 3
83 // Purpose :
84 //
85 // This is the instance class for Synapse4s. It
86 // contains "unique" Synapse4 information - ie stuff that
87 // will be true of only one Synapse4 in the circuit, such
88 // as the nodes to which it is connected. A Synapse4 is
89 // connected to only two circuit nodes.
90 //
91 // This class does not directly contain information about
92 // its node indices. It contains indices into the 3 parts
93 // (A, dx, and b) of the matrix problem A*dx = b, and
94 // also x. A is the Jacobian matrix, dx is the update to
95 // the solution vector x, and b is the right hand side
96 // function vector. These indices are global, and
97 // determined by topology during the initialization stage
98 // of execution.
99 //
100 // Special Notes :
101 // Creator : Christina Warrender, SNL,
102 // Creation Date : 10/12/11
103 //-----------------------------------------------------------------------------
104 class Instance : public DeviceInstance
105 {
106  friend class ParametricData<Instance>;
107  friend class Model;
108  friend class Traits;
109 
110 public:
111  static std::vector< std::vector<int> > jacStamp;
112 
113  Instance(
114  const Configuration & configuration,
115  const InstanceBlock & IB,
116  Model & Riter,
117  const FactoryBlock & factory_block);
118 
119  ~Instance();
120 
121 private:
122  Instance(const Instance &);
123  Instance &operator=(const Instance &);
124 
125 public:
126  void registerLIDs( const std::vector<int> & intLIDVecRef,
127  const std::vector<int> & extLIDVecRef );
128  void registerStoreLIDs( const std::vector<int> & storeLIDVecRef );
129 
130  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
131 
132  bool processParams ();
133 
134  bool updateTemperature(const double & temp_tmp);
135 
136  bool updateIntermediateVars ();
137  bool updatePrimaryState ();
138  bool updateSecondaryState ();
139 
140  const std::vector< std::vector<int> > & jacobianStamp() const;
141  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
142 
143  // load functions, residual:
144  bool loadDAEQVector ();
145  bool loadDAEFVector ();
146 
147  // load functions, Jacobian:
148  bool loadDAEdQdx ();
149  bool loadDAEdFdx ();
150 
151  // enable the interface to produce plot files. - although we're not
152  // actually using this for output
153  bool plotfileFlag () {return true;}
154  bool outputPlotFiles(bool force_final_output);
155 
156  void setupPointers();
157 
159  {
160  return model_;
161  }
162 
163  // make this static so that synapses share a random number generator and
164  // thus don't all seed the same generator with the same seed and then follow
165  // the same sequence.
166  static Xyce::Util::RandomNumbers randomNumberGenerator_;
167 
168 private:
169 
170  Model & model_; //< Owning model
171  // make this public so that the master-class can potentially
172  // access and output these values en-mass rather than
173  // on a object by object basis.
175  // user-specified parameters:
176  double gMax;
177  bool gMaxGiven;
180 
181  //Vector local index for Positive Node
182  int li_Prev;
183  //Vector local index for Negative Node
184  int li_Post;
185 
186  // store variable quantities
195 
196 
197 
198 #ifdef Xyce_FullSynapseJac
199  // Offset variables corresponding to the above declared indices.
200  int APostEquPostNodeOffset;
201 
202  // Pointers for Jacobian
203  double *f_PostEquPostNodePtr;
204 #endif
205 
206  // vars used for load calculations
207  double ipost; // post Synapse4 current
208  double didVpost;
209 
210  bool ready;
211  double respondTime;
212  int transmissionFactor; // 0 or 1 depending on random number < transmissionProbability
213 
214  // flag to indicate random number generator was initialized
216 
217  // initial weight can be specified on the instance line to override the model value
218  double wInitialValue; // initial value for weighting
219  bool wInitialValueGiven; // flag set by parser if this value is given.
220 
221  double synapticWeightUpdate; // value calculated to update synaptic weight.
222  double vl1Update;
223  double vl2Update;
224  double vl3Update;
225 };
226 
227 
228 //-----------------------------------------------------------------------------
229 // Class : Model
230 // Purpose :
231 //
232 //
233 // Special Notes :
234 // Creator : Christina Warrender, SNL
235 // Creation Date : 10/12/11
236 //-----------------------------------------------------------------------------
237 class Model : public DeviceModel
238 {
239  typedef std::vector<Instance *> InstanceVector;
240 
241  friend class ParametricData<Model>;
242  friend class Instance;
243  friend class Traits;
244 
245 public:
246  Model(
247  const Configuration & configuration,
248  const ModelBlock & MB,
249  const FactoryBlock & factory_block);
250  ~Model();
251 
252 private:
253  Model();
254  Model(const Model &);
255  Model &operator=(const Model &);
256 
257 public:
258  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
259 
260  virtual std::ostream &printOutInstances(std::ostream &os) const;
261 
262  bool processParams ();
263  bool processInstanceParams ();
264 
265 
266 public:
267  void addInstance(Instance *instance)
268  {
269  instanceContainer.push_back(instance);
270  }
271 
272 private:
273  std::vector<Instance*> instanceContainer;
274 
275 private:
276 
277  // user-specified parameters
278  double vThresh;
279  double gMax;
280  double delay;
281  double eRev;
282  double tau1;
283  double tau2;
284  // parameters for weighting function
285  double sParam; // voltage threshold for a spike event
286  double rParam; // Resting voltage for resting event
287  double wMin; // minimum value for weighting
288  double wMax; // maximum value for weighting
289  double wInitialValue; // initial value for weighting
290  double vL1tau1; // rate for Longterm potentiation factor (LPF) based on post-synaptic voltage (rate 1)
291  double vL2tau2; // rate for Longterm potentiation factor (LPF) based on post-synaptic voltage (rate 2)
292  double vL3tau3; // rate for Longterm potentiation factor (LPF) based on pre-synaptic voltage (rate 3)
293  double aLTD; // long term depression coefficient
294  double aLTP; // long term potentiation coefficient
296 
297  // derived parameters
298  double tp; // time of EPSP peak, relative to start of postsynaptic response
299  double factor; // used to ensure peak conductance = 1S for weight (gMax) = 1
300 };
301 
302 void registerDevice();
303 
304 } // namespace Synapse3
305 } // namespace Device
306 } // namespace Xyce
307 
308 #endif
void addInstance(Instance *instance)
std::vector< Instance * > InstanceVector
const std::vector< std::vector< int > > & jacobianStamp() const
static void loadModelParameters(ParametricData< Model > &model_parameters)
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Riter, const FactoryBlock &factory_block)
Pure virtual class to augment a linear system.
void registerStoreLIDs(const std::vector< int > &storeLIDVecRef)
static const char * deviceTypeName()
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
static const char * name()
std::vector< Instance * > instanceContainer
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
bool processInstanceParams()
processInstanceParams
static Xyce::Util::RandomNumbers randomNumberGenerator_
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Class Configuration contains device configuration data.
bool updateTemperature(const double &temp_tmp)
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
bool processParams()
processParams
static std::vector< std::vector< int > > jacStamp
virtual std::ostream & printOutInstances(std::ostream &os) const
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
ModelBlock represents a .MODEL line from the netlist.
Instance & operator=(const Instance &)
The DeviceTraits template describes the configuration of a device.
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
InstanceBlock represent a device instance line from the netlist.
bool outputPlotFiles(bool force_final_output)
Model & operator=(const Model &)