Xyce  6.1
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-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_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.30.2.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:29:37 $
42 //
43 // Current Owner : $Author: tvrusso $
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 
128  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
129 
130  bool processParams ();
131 
132  bool updateTemperature(const double & temp_tmp);
133 
134  bool updateIntermediateVars ();
135  bool updatePrimaryState ();
136  bool updateSecondaryState ();
137 
138  const std::vector< std::vector<int> > & jacobianStamp() const;
139  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
140 
141  // load functions, residual:
142  bool loadDAEQVector ();
143  bool loadDAEFVector ();
144 
145  // load functions, Jacobian:
146  bool loadDAEdQdx ();
147  bool loadDAEdFdx ();
148 
149  void setupPointers();
150 
152  {
153  return model_;
154  }
155 
156 private:
157 
158  Model & model_; //< Owning model
159 
160  // user-specified paramters:
161 
162 
163  //Vector local index for Positive Node
164  int li_Prev;
165  //Vector local index for Negative Node
166  int li_Post;
167  int li_rVar;
168 
169  // Offset variables corresponding to the above declared indices.
174 
175  // Pointers for Jacobian
179  double *f_REquRNodePtr;
180 
181  // vars used for load calculations
182  double ipost; // post Synapse2 current
183  double didVpost;
184  double didr;
185  double rFval;
186  double drFdVpre;
187  double drFdr;
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  // Synapse2 parameters
240  double gMax;
241  double eRev;
242  double alpha;
243  double beta;
244  double vP;
245  double kP;
246  double tMax;
247 };
248 
249 //-----------------------------------------------------------------------------
250 // Class : Master
251 // Purpose :
252 // Special Notes :
253 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
254 // Creation Date : 11/26/08
255 //-----------------------------------------------------------------------------
256 class Master : public DeviceMaster<Traits>
257 {
258  friend class Instance;
259  friend class Model;
260 
261 public:
263  const Configuration & configuration,
264  const FactoryBlock & factory_block,
265  const SolverState & ss1,
266  const DeviceOptions & do1)
267  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
268  {}
269 
270  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
271  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
272 };
273 
274 
275 // These are the base equations for the Synapse2 device.
276 // They're placed here to get compiled by the auto-diff tool Sacado
277 // These functions represent the equations that need to be solved
278 // for this device.
279 
280 template <typename ScalarT>
281 static ScalarT PostCurrentEqu( const ScalarT Vpost, const ScalarT r, const ScalarT g, const ScalarT Erev)
282 {
283  ScalarT result = g * r * (Vpost - Erev);
284  return result;
285 }
286 
287 template <typename ScalarT>
288 static ScalarT rEquF( const ScalarT V, const ScalarT r, const ScalarT alpha, const ScalarT beta,
289  const ScalarT Tmax, const ScalarT Vthres)
290 {
291  ScalarT result;
292  if (V > Vthres)
293  {
294  result = (alpha * Tmax * (1.0 - r) - beta * r);
295  }
296  else
297  {
298  result = - beta * r;
299  }
300  return result;
301 }
302 
303 void registerDevice();
304 
305 } // namespace Synapse2
306 } // namespace Device
307 } // namespace Xyce
308 
309 #endif
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
bool processParams()
processParams
Pure virtual class to augment a linear system.
std::vector< Instance * > instanceContainer
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
void addInstance(Instance *instance)
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
static ScalarT PostCurrentEqu(const ScalarT Vpost, const ScalarT r, const ScalarT g, const ScalarT Erev)
static const char * name()
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Instance & operator=(const Instance &)
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Riter, const FactoryBlock &factory_block)
DeviceMaster instantiates a device as described by the device traits T.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
bool processInstanceParams()
processInstanceParams
std::vector< Instance * > InstanceVector
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)
static ScalarT rEquF(const ScalarT V, const ScalarT r, const ScalarT alpha, const ScalarT beta, const ScalarT Tmax, const ScalarT Vthres)
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
virtual bool updateSecondaryState(double *staDeriv, double *stoVec)
Updates the devices secondary state information.
virtual std::ostream & printOutInstances(std::ostream &os) const
Class Configuration contains device configuration data.
static std::vector< std::vector< int > > jacStamp
static void loadModelParameters(ParametricData< Model > &model_parameters)
ModelBlock represents a .MODEL line from the netlist.
The DeviceTraits template describes the configuration of a device.
const std::vector< std::vector< int > > & jacobianStamp() const
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
InstanceBlock represent a device instance line from the netlist.
static const char * deviceTypeName()
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
bool updateTemperature(const double &temp_tmp)
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Model & operator=(const Model &)