Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Synapse2.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_Synapse2.h,v $
27 //
28 // Purpose : Synapse2 classes
29 //
30 // Special Notes :
31 //
32 // Creator : Christy Warrender, SNL, Cognitive Modeling
33 //
34 // Creation Date : 11/18/10
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.28 $
40 //
41 // Revision Date : $Date: 2014/05/21 18:25:50 $
42 //
43 // Current Owner : $Author: dgbaur $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Synapse2_h
47 #define Xyce_N_DEV_Synapse2_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 Synapse2 {
63 
64 class Model;
65 class Instance;
66 
67 struct Traits : public DeviceTraits<Model, Instance, Synapse::Traits>
68 {
69  static const char *name() {return "Synapse";}
70  static const char *deviceTypeName() {return "YSYNAPSE level 2";}
71  static int numNodes() {return 2;}
72  static bool isLinearDevice() {return true;}
73 
74  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
75  static void loadModelParameters(ParametricData<Model> &model_parameters);
76  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
77 };
78 
79 //-----------------------------------------------------------------------------
80 // Class : Instance
81 // Purpose :
82 //
83 // This is the instance class for Synapse2s. It
84 // contains "unique" Synapse2 information - ie stuff that
85 // will be true of only one Synapse2 in the circuit, such
86 // as the nodes to which it is connected. A Synapse2 is
87 // connected to only two circuit nodes.
88 //
89 // This class does not directly contain information about
90 // its node indices. It contains indices into the 3 parts
91 // (A, dx, and b) of the matrix problem A*dx = b, and
92 // also x. A is the Jacobian matrix, dx is the update to
93 // the solution vector x, and b is the right hand side
94 // function vector. These indices are global, and
95 // determined by topology during the initialization stage
96 // of execution.
97 //
98 // Special Notes :
99 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
100 // Creation Date : 3/16/00
101 //-----------------------------------------------------------------------------
102 class Instance : public DeviceInstance
103 {
104  friend class ParametricData<Instance>;
105  friend class Model;
106  friend class Traits;friend class Master;
107 
108 public:
109  static std::vector< std::vector<int> > jacStamp;
110 
111  Instance(
112  const Configuration & configuration,
113  const InstanceBlock & IB,
114  Model & Riter,
115  const FactoryBlock & factory_block);
116 
117  ~Instance();
118 
119 private:
120  Instance(const Instance &);
121  Instance &operator=(const Instance &);
122 
123 public:
124  void registerLIDs( const std::vector<int> & intLIDVecRef,
125  const std::vector<int> & extLIDVecRef );
126  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
127  std::map<int,std::string> & getIntNameMap ();
128 
129  bool processParams ();
130 
131  bool updateTemperature(const double & temp_tmp);
132 
133  bool updateIntermediateVars ();
134  bool updatePrimaryState ();
135  bool updateSecondaryState ();
136 
137  const std::vector< std::vector<int> > & jacobianStamp() const;
138  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
139 
140  // load functions, residual:
141  bool loadDAEQVector ();
142  bool loadDAEFVector ();
143 
144  // load functions, Jacobian:
145  bool loadDAEdQdx ();
146  bool loadDAEdFdx ();
147 
148  void setupPointers();
149 
151  {
152  return model_;
153  }
154 
155 private:
156 
157  Model & model_; //< Owning model
158 
159  // user-specified paramters:
160 
161 
162  //Vector local index for Positive Node
163  int li_Prev;
164  //Vector local index for Negative Node
165  int li_Post;
166  int li_rVar;
167 
168  // Offset variables corresponding to the above declared indices.
173 
174  // Pointers for Jacobian
178  double *f_REquRNodePtr;
179 
180  // vars used for load calculations
181  double ipost; // post Synapse2 current
182  double didVpost;
183  double didr;
184  double rFval;
185  double drFdVpre;
186  double drFdr;
187 };
188 
189 //-----------------------------------------------------------------------------
190 // Class : Model
191 // Purpose :
192 //
193 //
194 // Special Notes :
195 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
196 // Creation Date : 3/16/00
197 //-----------------------------------------------------------------------------
198 class Model : public DeviceModel
199 {
200  typedef std::vector<Instance *> InstanceVector;
201 
202  friend class ParametricData<Model>;
203  friend class Instance;
204  friend class Traits;friend class Master;
205 
206 public:
207  Model(
208  const Configuration & configuration,
209  const ModelBlock & MB,
210  const FactoryBlock & factory_block);
211  ~Model();
212 
213 private:
214  Model();
215  Model(const Model &);
216  Model &operator=(const Model &);
217 
218 public:
219  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
220 
221  virtual std::ostream &printOutInstances(std::ostream &os) const;
222 
223  bool processParams ();
224  bool processInstanceParams ();
225 
226 
227 public:
228  void addInstance(Instance *instance)
229  {
230  instanceContainer.push_back(instance);
231  }
232 
233 private:
234  std::vector<Instance*> instanceContainer;
235 
236 private:
237 
238  // Synapse2 parameters
239  double gMax;
240  double eRev;
241  double alpha;
242  double beta;
243  double vP;
244  double kP;
245  double tMax;
246 };
247 
248 //-----------------------------------------------------------------------------
249 // Class : Master
250 // Purpose :
251 // Special Notes :
252 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
253 // Creation Date : 11/26/08
254 //-----------------------------------------------------------------------------
255 class Master : public DeviceMaster<Traits>
256 {
257  friend class Instance;
258  friend class Model;
259 
260 public:
262  const Configuration & configuration,
263  const FactoryBlock & factory_block,
264  const SolverState & ss1,
265  const DeviceOptions & do1)
266  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
267  {}
268 
269  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
270  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
271 };
272 
273 
274 // These are the base equations for the Synapse2 device.
275 // They're placed here to get compiled by the auto-diff tool Sacado
276 // These functions represent the equations that need to be solved
277 // for this device.
278 
279 template <typename ScalarT>
280 static ScalarT PostCurrentEqu( const ScalarT Vpost, const ScalarT r, const ScalarT g, const ScalarT Erev)
281 {
282  ScalarT result = g * r * (Vpost - Erev);
283  return result;
284 }
285 
286 template <typename ScalarT>
287 static ScalarT rEquF( const ScalarT V, const ScalarT r, const ScalarT alpha, const ScalarT beta,
288  const ScalarT Tmax, const ScalarT Vthres)
289 {
290  ScalarT result;
291  if (V > Vthres)
292  {
293  result = (alpha * Tmax * (1.0 - r) - beta * r);
294  }
295  else
296  {
297  result = - beta * r;
298  }
299  return result;
300 }
301 
302 void registerDevice();
303 
304 } // namespace Synapse2
305 } // namespace Device
306 } // namespace Xyce
307 
311 
312 #endif