Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Synapse.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_Synapse.h,v $
27 //
28 // Purpose : Synapse classes
29 //
30 // Special Notes :
31 //
32 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 02/28/00
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.26.2.1 $
40 //
41 // Revision Date : $Date: 2014/02/26 20:16:30 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Synapse_h
47 #define Xyce_N_DEV_Synapse_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 <Sacado.hpp>
57 
58 namespace Xyce {
59 namespace Device {
60 namespace Synapse {
61 
62 class Model;
63 class Instance;
64 class Master;
65 
66 struct Traits : public DeviceTraits<Model, Instance>
67 {
68  static const char *name() {return "Synapse";}
69  static const char *deviceTypeName() {return "YSYNAPSE level 1";}
70  static const int numNodes() {return 2;}
71  static const bool isLinearDevice() {return true;}
72 
73  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
74  static void loadModelParameters(ParametricData<Model> &model_parameters);
75  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
76 };
77 
78 //-----------------------------------------------------------------------------
79 // Class : Instance
80 // Purpose :
81 //
82 // This is the instance class for Synapses. It
83 // contains "unique" Synapse information - ie stuff that
84 // will be true of only one Synapse in the circuit, such
85 // as the nodes to which it is connected. A Synapse is
86 // connected to only two circuit nodes.
87 //
88 // This class does not directly contain information about
89 // its node indices. It contains indices into the 3 parts
90 // (A, dx, and b) of the matrix problem A*dx = b, and
91 // also x. A is the Jacobian matrix, dx is the update to
92 // the solution vector x, and b is the right hand side
93 // function vector. These indices are global, and
94 // determined by topology during the initialization stage
95 // of execution.
96 //
97 // Special Notes :
98 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
99 // Creation Date : 3/16/00
100 //-----------------------------------------------------------------------------
101 class Instance : public DeviceInstance
102 {
103  friend class ParametricData<Instance>;
104  friend class Model;
105  friend class Traits;friend class Master;
106 
107 public:
108  static std::vector< std::vector<int> > jacStamp;
109 
110  Instance(
111  const Configuration & configuration,
112  const InstanceBlock & IB,
113  Model & Riter,
114  const FactoryBlock & factory_block);
115 
116  ~Instance();
117 
118 private:
119  Instance(const Instance &);
120  Instance &operator=(const Instance &);
121 
122 public:
123  void registerLIDs( const std::vector<int> & intLIDVecRef,
124  const std::vector<int> & extLIDVecRef );
125  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
126  std::map<int,std::string> & getIntNameMap ();
127 
128  bool processParams ();
129 
130  bool updateTemperature(const double & temp_tmp);
131 
132  bool updateIntermediateVars ();
133  bool updatePrimaryState ();
134  bool updateSecondaryState ();
135 
136  const std::vector< std::vector<int> > & jacobianStamp() const;
137  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
138 
139  // load functions, residual:
140  bool loadDAEQVector ();
141  bool loadDAEFVector ();
142 
143  // load functions, Jacobian:
144  bool loadDAEdQdx ();
145  bool loadDAEdFdx ();
146 
147  void setupPointers();
148 
149 
151  {
152  return model_;
153  }
154 
155 private:
156 
157  Model & model_; //< Owning model
158 
159  // user-specified paramters:
160 
161  //Vector local index for Positive Node
162  int li_Prev;
163  //Vector local index for Negative Node
164  int li_Post;
165  int li_rVar;
166 
167  // Offset variables corresponding to the above declared indices.
172 
173  // Pointers for Jacobian
177  double *f_REquRNodePtr;
178 
179  // vars used for load calculations
180  double ipost; // post synapse current
181  double didVpost;
182  double didr;
183  double rFval;
184  double drFdVpre;
185  double drFdr;
186 };
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 
234  {
235  return instanceContainer;
236  }
237 
239  {
240  return instanceContainer;
241  }
242 
243 private:
244  std::vector<Instance*> instanceContainer;
245 
246 private:
247 
248 protected:
249  // Synapse parameters
250  double gMax;
251  double eRev;
252  double alpha;
253  double beta;
254  double vP;
255  double kP;
256  double tMax;
257 };
258 
259 //-----------------------------------------------------------------------------
260 // Class : Master
261 // Purpose :
262 // Special Notes :
263 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
264 // Creation Date : 11/26/08
265 //-----------------------------------------------------------------------------
266 class Master : public DeviceMaster<Traits>
267 {
268  friend class Synapse::Instance;
269  friend class Synapse::Model;
270 
271 public:
273  const Configuration & configuration,
274  const FactoryBlock & factory_block,
275  const SolverState & ss1,
276  const DeviceOptions & do1)
277  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
278  {}
279 
280  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
281  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
282 };
283 
284 // These functions represents the equations that need to be solved
285 // for this device. Since Xyce loads an F and Q contribution, the
286 // equations are broken up into their F and Q components. Thus there
287 // is a kcl1EquF() and kcl1EquQ(). Automatic differentiation will
288 // be used to generate all the derivatives of these equations for the
289 // dF/dX and dQ/dX loads
290 
291 template <typename ScalarT>
292 static ScalarT Tsyn( const ScalarT V, const ScalarT Tmax, const ScalarT Vthres, const ScalarT Kp)
293 {
294  ScalarT result = Tmax / (1.0 + std::exp( -(V - Vthres) / Kp ) );
295  return result;
296 }
297 
298 template <typename ScalarT>
299 static ScalarT PostCurrentEqu( const ScalarT Vpost, const ScalarT r, const ScalarT g, const ScalarT Erev)
300 {
301  ScalarT result = g * r * (Vpost - Erev);
302  return result;
303 }
304 
305 template <typename ScalarT>
306 static ScalarT rEquF( const ScalarT V, const ScalarT r, const ScalarT alpha, const ScalarT beta,
307  const ScalarT Tmax, const ScalarT Vthres, const ScalarT Kp)
308 {
309  ScalarT result = alpha * Tsyn< ScalarT >(V, Tmax, Vthres, Kp) * (1.0 - r) - beta * r;
310  return result;
311 }
312 
313 void registerDevice();
314 
315 } // namespace Synapse
316 } // namespace Device
317 } // namespace Xyce
318 
322 
323 #endif
324