Xyce  6.1
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-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_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.32 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:23 $
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 int numNodes() {return 2;}
71  static 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 
127  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
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 
150 
152  {
153  return model_;
154  }
155 
156 private:
157 
158  Model & model_; //< Owning model
159 
160  // user-specified paramters:
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 synapse current
182  double didVpost;
183  double didr;
184  double rFval;
185  double drFdVpre;
186  double drFdr;
187 };
188 
189 
190 //-----------------------------------------------------------------------------
191 // Class : Model
192 // Purpose :
193 //
194 //
195 // Special Notes :
196 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
197 // Creation Date : 3/16/00
198 //-----------------------------------------------------------------------------
199 class Model : public DeviceModel
200 {
201  typedef std::vector<Instance *> InstanceVector;
202 
203  friend class ParametricData<Model>;
204  friend class Instance;
205  friend class Traits;friend class Master;
206 
207 public:
208  Model(
209  const Configuration & configuration,
210  const ModelBlock & MB,
211  const FactoryBlock & factory_block);
212  ~Model();
213 
214 private:
215  Model();
216  Model(const Model &);
217  Model &operator=(const Model &);
218 
219 public:
220  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
221 
222  virtual std::ostream &printOutInstances(std::ostream &os) const;
223 
224  bool processParams ();
225  bool processInstanceParams ();
226 
227 
228 public:
229  void addInstance(Instance *instance)
230  {
231  instanceContainer.push_back(instance);
232  }
233 
234 private:
235  std::vector<Instance*> instanceContainer;
236 
237 private:
238 
239 protected:
240  // Synapse parameters
241  double gMax;
242  double eRev;
243  double alpha;
244  double beta;
245  double vP;
246  double kP;
247  double tMax;
248 };
249 
250 //-----------------------------------------------------------------------------
251 // Class : Master
252 // Purpose :
253 // Special Notes :
254 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
255 // Creation Date : 11/26/08
256 //-----------------------------------------------------------------------------
257 class Master : public DeviceMaster<Traits>
258 {
259  friend class Synapse::Instance;
260  friend class Synapse::Model;
261 
262 public:
264  const Configuration & configuration,
265  const FactoryBlock & factory_block,
266  const SolverState & ss1,
267  const DeviceOptions & do1)
268  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
269  {}
270 
271  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
272  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
273 };
274 
275 // These functions represents the equations that need to be solved
276 // for this device. Since Xyce loads an F and Q contribution, the
277 // equations are broken up into their F and Q components. Thus there
278 // is a kcl1EquF() and kcl1EquQ(). Automatic differentiation will
279 // be used to generate all the derivatives of these equations for the
280 // dF/dX and dQ/dX loads
281 
282 template <typename ScalarT>
283 static ScalarT Tsyn( const ScalarT V, const ScalarT Tmax, const ScalarT Vthres, const ScalarT Kp)
284 {
285  ScalarT result = Tmax / (1.0 + std::exp( -(V - Vthres) / Kp ) );
286  return result;
287 }
288 
289 template <typename ScalarT>
290 static ScalarT PostCurrentEqu( const ScalarT Vpost, const ScalarT r, const ScalarT g, const ScalarT Erev)
291 {
292  ScalarT result = g * r * (Vpost - Erev);
293  return result;
294 }
295 
296 template <typename ScalarT>
297 static ScalarT rEquF( const ScalarT V, const ScalarT r, const ScalarT alpha, const ScalarT beta,
298  const ScalarT Tmax, const ScalarT Vthres, const ScalarT Kp)
299 {
300  ScalarT result = alpha * Tsyn< ScalarT >(V, Tmax, Vthres, Kp) * (1.0 - r) - beta * r;
301  return result;
302 }
303 
304 void registerDevice();
305 
306 } // namespace Synapse
307 } // namespace Device
308 } // namespace Xyce
309 
310 #endif
311 
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
bool updateTemperature(const double &temp_tmp)
virtual bool updateSecondaryState(double *staDeriv, double *stoVec)
Updates the devices secondary state information.
Instance & operator=(const Instance &)
static const char * deviceTypeName()
Definition: N_DEV_Synapse.h:69
Pure virtual class to augment a linear system.
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
std::vector< Instance * > InstanceVector
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
DeviceMaster instantiates a device as described by the device traits T.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Riter, const FactoryBlock &factory_block)
static ScalarT Tsyn(const ScalarT V, const ScalarT Tmax, const ScalarT Vthres, const ScalarT Kp)
std::vector< Instance * > instanceContainer
void addInstance(Instance *instance)
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
static std::vector< std::vector< int > > jacStamp
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_Synapse.C:73
Model & operator=(const Model &)
static ScalarT rEquF(const ScalarT V, const ScalarT r, const ScalarT alpha, const ScalarT beta, const ScalarT Tmax, const ScalarT Vthres, const ScalarT Kp)
Class Configuration contains device configuration data.
bool processInstanceParams()
processInstanceParams
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
static ScalarT PostCurrentEqu(const ScalarT Vpost, const ScalarT r, const ScalarT g, const ScalarT Erev)
bool processParams()
processParams
static const char * name()
Definition: N_DEV_Synapse.h:68
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_Synapse.C:78
const std::vector< std::vector< int > > & jacobianStamp() const
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)
virtual std::ostream & printOutInstances(std::ostream &os) const
ModelBlock represents a .MODEL line from the netlist.
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.