Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Synapse4.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-2011 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_Synapse4.h,v $
27 //
28 // Purpose : Synapse4 classes
29 //
30 // Special Notes :
31 //
32 // Creator : Christy Warrender, SNL, Cognitive Modeling
33 //
34 // Creation Date : 10/12/11
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.38 $
40 //
41 // Revision Date : $Date: 2014/05/22 17:40:28 $
42 //
43 // Current Owner : $Author: erkeite $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Synapse4_h
47 #define Xyce_N_DEV_Synapse4_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 
56 #include <N_DEV_Synapse.h>
57 
58 #include <Sacado.hpp>
59 
60 namespace Xyce {
61 namespace Device {
62 namespace Synapse4 {
63 
64 // ---------- Forward Declarations -------
65 class Model;
66 class Instance;
67 
68 struct Traits : public DeviceTraits<Model, Instance, Synapse::Traits>
69 {
70  static const char *name() {return "Synapse";}
71  static const char *deviceTypeName() {return "YSYNAPSE level 4";}
72  static int numNodes() {return 2;}
73  static bool isLinearDevice() {return true;}
74 
75  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
76  static void loadModelParameters(ParametricData<Model> &model_parameters);
77  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
78 };
79 
80 //-----------------------------------------------------------------------------
81 // Class : 4
82 // Purpose :
83 //
84 // This is the instance class for Synapse4s. It
85 // contains "unique" Synapse4 information - ie stuff that
86 // will be true of only one Synapse4 in the circuit, such
87 // as the nodes to which it is connected. A Synapse4 is
88 // connected to only two circuit nodes.
89 //
90 // This class does not directly contain information about
91 // its node indices. It contains indices into the 3 parts
92 // (A, dx, and b) of the matrix problem A*dx = b, and
93 // also x. A is the Jacobian matrix, dx is the update to
94 // the solution vector x, and b is the right hand side
95 // function vector. These indices are global, and
96 // determined by topology during the initialization stage
97 // of execution.
98 //
99 // Special Notes :
100 // Creator : Christina Warrender, SNL,
101 // Creation Date : 10/12/11
102 //-----------------------------------------------------------------------------
103 class Instance : public DeviceInstance
104 {
105  friend class ParametricData<Instance>;
106  friend class Model;
107  friend class Traits;
108 
109  // functions
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> & stoLIDVecRef );
129  std::map<int,std::string> & getStoreNameMap ();
130  std::map<int,std::string> & getIntNameMap ();
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();
155 
156  void setupPointers();
157 
158  // is there currently a non-negligible synaptic current?
159  // (used because there's no need to do calculations otherwise)
160  bool active;
161 
162  // iterator reference to the Synapse4 model which owns this instance.
164  {
165  return model_;
166  }
167 
168 private:
169 
171 
172  // user-specified parameters:
173  double gMax;
174  bool gMaxGiven;
175 
176  //Vector local index for Positive Node
177  int li_Prev;
178  //Vector local index for Negative Node
179  int li_Post;
180 
181  // store vector quantities
186 
187 #ifdef Xyce_FullSynapseJac
188  // Offset variables corresponding to the above declared indices.
189  int APostEquPostNodeOffset;
190 
191  // Pointers for Jacobian
192  double *f_PostEquPostNodePtr;
193 #endif
194 
195  // vars used for load calculations
196  double ipost; // post Synapse4 current
197  double didVpost;
198 
199  // flag to indicate random number generator was initialized
201 
202  bool ready;
203  double respondTime;
204 };
205 
206 
207 //-----------------------------------------------------------------------------
208 // Class : Model
209 // Purpose :
210 //
211 //
212 // Special Notes :
213 // Creator : Christina Warrender, SNL
214 // Creation Date : 10/12/11
215 //-----------------------------------------------------------------------------
216 class Model : public DeviceModel
217 {
218  typedef std::vector<Instance *> InstanceVector;
219 
220  friend class ParametricData<Model>;
221  friend class Instance;
222  friend class Traits;
223 
224 public:
225  Model(
226  const Configuration & configuration,
227  const ModelBlock & MB,
228  const FactoryBlock & factory_block);
229  ~Model();
230 
231 private:
232  Model();
233  Model(const Model &);
234  Model &operator=(const Model &);
235 
236 public:
237  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
238 
239  virtual std::ostream &printOutInstances(std::ostream &os) const;
240 
241  bool processParams ();
242  bool processInstanceParams ();
243 
244 
245 public:
246  void addInstance(Instance *instance)
247  {
248  instanceContainer.push_back(instance);
249  }
250 
251 private:
252  std::vector<Instance*> instanceContainer;
253 
254 private:
255 
256  // user-specified parameters
257  double vThresh;
258  double gMax;
259  double delay;
260  double eRev;
261  double tau1;
262  double tau2;
263  double maxtau;
264 
265  // derived parameters
266  double tp; // time of EPSP peak, relative to start of postsynaptic response
267  double factor; // used to ensure peak conductance = 1S for weight (gMax) = 1
268 };
269 
270 //-----------------------------------------------------------------------------
271 // Class : Master4
272 // Purpose :
273 // Special Notes :
274 // Creator : Christina Warrender, SNL, Cognitive Modeling
275 // Creation Date : 07/16/12
276 //-----------------------------------------------------------------------------
277 class Master : public DeviceMaster<Traits>
278 {
279  friend class Instance;
280  friend class Model;
281 
282 public:
284  const Configuration & configuration,
285  const FactoryBlock & factory_block,
286  const SolverState & ss1,
287  const DeviceOptions & do1)
288  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
289  {}
290 
291  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
292  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
293 
294  // load functions:
295  virtual bool loadDAEVectors(double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ);
296  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
297 };
298 
299 void registerDevice();
300 
301 } // namespace Synapse4
302 } // namespace Device
303 } // namespace Xyce
304 
308 
309 #endif
310