Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Neuron5.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_Neuron5.h,v $
27 //
28 // Purpose : Neuron classes.
29 //
30 // Special Notes :
31 //
32 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
33 //
34 // Creation Date : 01/02/08
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.20.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_Neuron5_h
47 #define Xyce_N_DEV_Neuron5_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 Neuron5 {
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 5";}
72  static const int numNodes() {return 2;}
73  static const bool modelRequired() {return true;}
74  static const 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 and Microsystem Modeling
89 // Creation Date : 01/02/08
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;
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  // derrived quantities computed in updateIntermediateVars
155  // and used in the load functions
167 
181 
182  // state variables
185 
186  // local state indices (offsets)
189 
190  // local solution indices (offsets)
191  int li_Pos; // local index to positive node on this device
192  int li_Neg; // local index to negative node on this device
193  int li_nPro; // local index to n promoter value (Na current)
194  int li_mPro; // local index to m promoter value (K current)
195  int li_hPro; // local index to h promoter value (K current)
196  int li_aPro; // local index to
197  int li_bPro; // local index
198  int li_M_Pro; // local index
199  int li_H_Pro; // local index
200  int li_cPro; // local index
201  int li_CaPro; // local index
202 
203  // Matrix equation index variables:
204 
205  // Offset variables corresponding to the above declared indices.
216 
227 
230 
233 
236 
239 
242 
245 
248 
252 
258 };
259 
260 //-----------------------------------------------------------------------------
261 // Class : Model
262 // Purpose :
263 // Special Notes :
264 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
265 // Creation Date : 01/02/08
266 //-----------------------------------------------------------------------------
267 class Model : public DeviceModel
268 {
269  typedef std::vector<Instance *> InstanceVector;
270 
271  friend class ParametricData<Model>;
272  friend class Instance;
273  friend class Traits;
274 
275 public:
276  Model(
277  const Configuration & configuration,
278  const ModelBlock & MB,
279  const FactoryBlock & factory_block);
280  ~Model();
281 
282 private:
283  Model();
284  Model(const Model &);
285  Model &operator=(const Model &);
286 
287 public:
288  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
289 
290  virtual std::ostream &printOutInstances(std::ostream &os) const;
291 
292  bool processParams ();
293  bool processInstanceParams ();
294 
295 private:
296 
297  // parameter variables
298  double cMem; // membrane capacitance
299  double gMem; // membrane conductance
300  double vRest; // resting potential
301  double eNa; // sodium rest potential
302  double gNa; // sodium base conductance
303  double eK; // potassium rest potential
304  double gK; // potassium base conductance
305  double eA; // a-current rest potential
306  double gA; // a-current base conductance
307  double eCa; // Calcium rest potential
308  double gCa; // Calcium base conductance
309  double eKCa; // potassium-calcium rest potential
310  double gKCa; // potassium-calcium base conductance
311  double CaInit; // initial intra-cellular calcium concentration
312  double CaGamma; // calcium current to concentration multiplier
313  double CaTau; // calcium removal time constant
314 
315  // flags that parameters were given
316  bool cMemGiven;
317  bool gMemGiven;
319  bool eNaGiven;
320  bool gNaGiven;
321  bool eKGiven;
322  bool gKGiven;
323  bool eAGiven;
324  bool gAGiven;
325  bool eCaGiven;
326  bool gCaGiven;
327  bool eKCaGiven;
328  bool gKCaGiven;
332 
333 
334 public:
335  void addInstance(Instance *instance)
336  {
337  instanceContainer.push_back(instance);
338  }
339 
341  {
342  return instanceContainer;
343  }
344 
346  {
347  return instanceContainer;
348  }
349 
350 private:
351  std::vector<Instance*> instanceContainer;
352 };
353 
354 void registerDevice();
355 
356 } // namespace Neuron5
357 } // namespace Device
358 } // namespace Xyce
359 
362 
363 #endif