Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Neuron8.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_Neuron8.h,v $
27 //
28 // Purpose : Neuron classes.
29 //
30 // Special Notes :
31 //
32 // Creator : Richard Schiek, SNL, Electrical Systems Modeling
33 //
34 // Creation Date : 03/08/2012
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.18 $
40 //
41 // Revision Date : $Date: 2014/05/21 18:25:50 $
42 //
43 // Current Owner : $Author: dgbaur $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Neuron8_h
47 #define Xyce_N_DEV_Neuron8_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceBlock.h>
52 #include <N_DEV_DeviceInstance.h>
53 #include <N_DEV_DeviceModel.h>
54 
55 #include <N_DEV_Neuron.h>
56 
57 #ifdef HAVE_MATH_H
58 #include <math.h>
59 #endif
60 
61 namespace Xyce {
62 namespace Device {
63 namespace Neuron8 {
64 
65 class Model;
66 class Instance;
67 
68 struct Traits : public DeviceTraits<Model, Instance, Neuron::Traits>
69 {
70  static const char *name() {return "Neuron";}
71  static const char *deviceTypeName() {return "YNEURON level 8";}
72  static int numNodes() {return 1;}
73  static bool modelRequired() {return true;}
74  static bool isLinearDevice() {return true;}
75 
76  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
77  static void loadModelParameters(ParametricData<Model> &model_parameters);
78  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
79 };
80 
81 //-----------------------------------------------------------------------------
82 // Class : Instance
83 // Purpose : This is class refers to a single instance of the
84 // Neuron device. It has two nodes associated with it, a
85 // positive and a negative node. See the NeuronInstance
86 // class for a more detailed explanation.
87 // Special Notes :
88 // Creator : Richard Schiek, SNL, Electrical Systems Modeling
89 // Creation Date : 03/08/2012
90 //-----------------------------------------------------------------------------
91 class Instance : public DeviceInstance
92 {
93  friend class ParametricData<Instance>;
94  friend class Model;
95  friend class Traits;
96 
97 public:
98  static std::vector< std::vector<int> > jacStamp; // ok for this to be static as all devcies of this type have the same form of jacStamp
99 
100  Instance(
101  const Configuration & configuration,
102  const InstanceBlock & IB,
103  Model & Miter,
104  const FactoryBlock & factory_block);
105 
106  ~Instance();
107 
108 private:
109  Instance(const Instance &);
110  Instance &operator=(const Instance &);
111 
112 public:
113  void registerLIDs( const std::vector<int> & intLIDVecRef,
114  const std::vector<int> & extLIDVecRef );
115  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
116 
117  std::map<int,std::string> & getIntNameMap ();
118  bool loadDeviceMask ();
119  const std::vector< std::vector<int> > & jacobianStamp() const;
120  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
121 
122  bool processParams ();
123  bool updateTemperature(const double & temp_tmp);
124 
125  bool updateIntermediateVars ();
126  bool updatePrimaryState ();
127  bool updateSecondaryState ();
128  bool setIC ();
129 
130  void varTypes( std::vector<char> & varTypeVec );
131 
132  // load functions, residual:
133  bool loadDAEQVector ();
134  bool loadDAEFVector ();
135 
136  void auxDAECalculations ();
137 
138  // load functions, Jacobian:
139  bool loadDAEdQdx ();
140  bool loadDAEdFdx ();
141 
142 public:
143  // iterator reference to the Neuron model which owns this instance.
144  // Getters and setters
146  {
147  return model_;
148  }
149 
150 private:
151 
152  Model & model_; //< Owning model
153 
154  // model level parameters that can be overridden at the instance level
155  double memCap; // membrane capacitance [F]
156  double Vt; // instantaneous threshold potential
157  double Vr; // resting membrane potential
158  double Vpeak; // peak voltage
159  double k; // modeling param []
160  double a; // modeling param
161  double b; // modeling param
162  double c; // modeling param
163  double d; // modeling param
164  double uscale; // u is normally in pico-Amps. Scalling by 1.0e9 improves accuracy
165  double fallRate;// controlls how quickly system resets over the discontinuity
166 
168  bool VtGiven;
169  bool VrGiven;
171  bool kGiven;
172  bool aGiven;
173  bool bGiven;
174  bool cGiven;
175  bool dGiven;
176  bool uscaleGiven; // u is normally in pico-Amps. Scalling by 1.0e9 improves accuracy
177  bool fallRateGiven;// controlls how quickly system resets over the discontinuity
178 
179  // values for loading in the F, Q, dF/dx and dQ/dx
180  //
181  // equations are:
182  // v equation
183  // k * (v-Vr) * (v-Vt) - u + I - C dv/dt = 0
184  // u euqtion
185  // a * ( b * (v-Vr) - u ) - du/dt = 0
186 
187  double vEquFvalue;
188  double vEquQvalue;
189  double vEqudFdv;
190  double vEqudFdu;
191  double vEqudQdv;
192  double uEquFvalue;
193  double uEquQvalue;
194  double uEqudFdv;
195  double uEqudFdu;
196  double uEqudQdu;
197 
198  // these need to be put in the state vector as they
199  // make this device state-dependent
200  bool resetting;
201  double uPeak;
202 
203  // offests
204  int li_V;
205  int li_U;
206 
207  // jacobian offsets
212 };
213 
214 //-----------------------------------------------------------------------------
215 // Class : Model
216 // Purpose :
217 // Special Notes :
218 // Creator : Richard Schiek, SNL, Electrical Systems Modeling
219 // Creation Date : 03/08/2012
220 //-----------------------------------------------------------------------------
221 class Model : public DeviceModel
222 {
223  typedef std::vector<Instance *> InstanceVector;
224 
225  friend class ParametricData<Model>;
226  friend class Instance;
227  friend class Traits;
228 
229 public:
230  Model(
231  const Configuration & configuration,
232  const ModelBlock & MB,
233  const FactoryBlock & factory_block);
234 
235  ~Model();
236 
237 private:
238  Model();
239  Model(const Model &);
240  Model &operator=(const Model &);
241 
242 public:
243  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
244 
245  virtual std::ostream &printOutInstances(std::ostream &os) const;
246 
247  bool processParams ();
248  bool processInstanceParams ();
249 
250 private:
251 
252  // model level parameters that can be overridden at the instance level
253  double memCap; // membrane capacitance [F]
254  double Vt; // instantaneous threshold potential
255  double Vr; // resting membrane potential
256  double Vpeak; // peak voltage
257  double k; // modeling param []
258  double a; // modeling param
259  double b; // modeling param
260  double c; // modeling param
261  double d; // modeling param
262  double uscale; // u is normally in pico-Amps. Scalling by 1.0e9 improves accuracy
263  double fallRate;// controlls how quickly system resets over the discontinuity
264 
266  bool VtGiven;
267  bool VrGiven;
269  bool kGiven;
270  bool aGiven;
271  bool bGiven;
272  bool cGiven;
273  bool dGiven;
274  bool uscaleGiven; // u is normally in pico-Amps. Scalling by 1.0e9 improves accuracy
275  bool fallRateGiven;// controlls how quickly system resets over the discontinuity
276 
277 
278 public:
279  void addInstance(Instance *instance)
280  {
281  instanceContainer.push_back(instance);
282  }
283 
284 private:
285  std::vector<Instance*> instanceContainer;
286 };
287 
288 void registerDevice();
289 
290 } // namespace Neuron8
291 } // namespace Device
292 } // namespace Xyce
293 
296 
297 #endif