Xyce  6.1
N_DEV_Neuron7.C
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_Neuron7.C,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Richard Schiek, Electrical and Microsytem Modeling
33 //
34 // Creation Date : 06/10/09
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.42 $
40 //
41 // Revision Date : $Date: 2015/10/20 22:32:48 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 
49 #include <N_DEV_DeviceOptions.h>
50 #include <N_DEV_DeviceMaster.h>
51 #include <N_DEV_ExternData.h>
52 #include <N_DEV_MatrixLoadData.h>
53 #include <N_DEV_Neuron7.h>
55 #include <N_DEV_SolverState.h>
56 #include <N_DEV_Message.h>
57 #include <N_ERH_ErrorMgr.h>
58 
59 #include <N_DEV_Neuron.h>
60 
61 #include <N_LAS_Vector.h>
62 #include <N_LAS_Matrix.h>
63 #include <N_UTL_FeatureTest.h>
64 
65 namespace Xyce {
66 namespace Device {
67 
68 namespace Neuron7 {
69 
71 {
72  p.addPar ("MEMC",0.0,&Neuron7::Instance::memCap)
73  .setGivenMember(&Neuron7::Instance::memCapGiven)
74  .setUnit(U_FARAD)
75  .setCategory(CAT_NONE)
76  .setDescription("Membrane capacitance");
77 
78  p.addPar ("VT",0.0,&Neuron7::Instance::Vt)
79  .setGivenMember(&Neuron7::Instance::VtGiven)
80  .setUnit(U_VOLT)
81  .setCategory(CAT_NONE)
82  .setDescription("Instantaneous threshold voltage");
83 
84  p.addPar ("VR",0.0,&Neuron7::Instance::Vr)
85  .setGivenMember(&Neuron7::Instance::VrGiven)
86  .setUnit(U_VOLT)
87  .setCategory(CAT_NONE)
88  .setDescription("Resting membrane potential");
89 
90  p.addPar ("VP",0.0,&Neuron7::Instance::Vpeak)
91  .setGivenMember(&Neuron7::Instance::VpeakGiven)
92  .setUnit(U_VOLT)
93  .setCategory(CAT_NONE)
94  .setDescription("Peak voltage");
95 
96  p.addPar ("K",0.0,&Neuron7::Instance::k)
97  .setGivenMember(&Neuron7::Instance::kGiven)
98  .setUnit(U_NONE)
99  .setCategory(CAT_NONE)
100  .setDescription("instanceing parameter");
101 
102  p.addPar ("A",0.0,&Neuron7::Instance::a)
103  .setGivenMember(&Neuron7::Instance::aGiven)
104  .setUnit(U_NONE)
105  .setCategory(CAT_NONE)
106  .setDescription("instanceing parameter");
107 
108  p.addPar ("B",0.0,&Neuron7::Instance::b)
109  .setGivenMember(&Neuron7::Instance::bGiven)
110  .setUnit(U_NONE)
111  .setCategory(CAT_NONE)
112  .setDescription("instanceing parameter");
113 
114  p.addPar ("C",0.0,&Neuron7::Instance::c)
115  .setGivenMember(&Neuron7::Instance::cGiven)
116  .setUnit(U_NONE)
117  .setCategory(CAT_NONE)
118  .setDescription("instanceing parameter");
119 
120  p.addPar ("D",0.0,&Neuron7::Instance::d)
121  .setGivenMember(&Neuron7::Instance::dGiven)
122  .setUnit(U_NONE)
123  .setCategory(CAT_NONE)
124  .setDescription("instanceing parameter");
125 
126  p.addPar ("USCALE",1.0e-9,&Neuron7::Instance::uscale)
127  .setGivenMember(&Neuron7::Instance::uscaleGiven)
128  .setUnit(U_NONE)
129  .setCategory(CAT_NONE)
130  .setDescription("scaling for u variable");
131 
132  p.addPar ("FALLRATE",1.0e3,&Neuron7::Instance::fallRate)
133  .setGivenMember(&Neuron7::Instance::fallRateGiven)
134  .setUnit(U_NONE)
135  .setCategory(CAT_NONE)
136  .setDescription("recovery rate");
137 }
138 
140 {
141  p.addPar ("MEMC",0.0,&Neuron7::Model::memCap)
142  .setGivenMember(&Neuron7::Model::memCapGiven)
143  .setUnit(U_FARAD)
144  .setCategory(CAT_NONE)
145  .setDescription("Membrane capacitance");
146 
147  p.addPar ("VT",0.0,&Neuron7::Model::Vt)
148  .setGivenMember(&Neuron7::Model::VtGiven)
149  .setUnit(U_VOLT)
150  .setCategory(CAT_NONE)
151  .setDescription("Instantaneous threshold voltage");
152 
153  p.addPar ("VR",0.0,&Neuron7::Model::Vr)
154  .setGivenMember(&Neuron7::Model::VrGiven)
155  .setUnit(U_VOLT)
156  .setCategory(CAT_NONE)
157  .setDescription("Resting membrane potential");
158 
159  p.addPar ("VP",0.0,&Neuron7::Model::Vpeak)
160  .setGivenMember(&Neuron7::Model::VpeakGiven)
161  .setUnit(U_VOLT)
162  .setCategory(CAT_NONE)
163  .setDescription("Peak voltage");
164 
165  p.addPar ("K",0.0,&Neuron7::Model::k)
166  .setGivenMember(&Neuron7::Model::kGiven)
167  .setUnit(U_NONE)
168  .setCategory(CAT_NONE)
169  .setDescription("Neuron7::Modeling parameter");
170 
171  p.addPar ("A",0.0,&Neuron7::Model::a)
172  .setGivenMember(&Neuron7::Model::aGiven)
173  .setUnit(U_NONE)
174  .setCategory(CAT_NONE)
175  .setDescription("Neuron7::Modeling parameter");
176 
177  p.addPar ("B",0.0,&Neuron7::Model::b)
178  .setGivenMember(&Neuron7::Model::bGiven)
179  .setUnit(U_NONE)
180  .setCategory(CAT_NONE)
181  .setDescription("Neuron7::Modeling parameter");
182 
183  p.addPar ("C",0.0,&Neuron7::Model::c)
184  .setGivenMember(&Neuron7::Model::cGiven)
185  .setUnit(U_NONE)
186  .setCategory(CAT_NONE)
187  .setDescription("Neuron7::Modeling parameter");
188 
189  p.addPar ("D",0.0,&Neuron7::Model::d)
190  .setGivenMember(&Neuron7::Model::dGiven)
191  .setUnit(U_NONE)
192  .setCategory(CAT_NONE)
193  .setDescription("Neuron7::Modeling parameter");
194 
195  p.addPar ("USCALE",1.0e-9,&Neuron7::Model::uscale)
196  .setGivenMember(&Neuron7::Model::uscaleGiven)
197  .setUnit(U_NONE)
198  .setCategory(CAT_NONE)
199  .setDescription("scaling for u variable");
200 
201  p.addPar ("FALLRATE",1.0e3,&Neuron7::Model::fallRate)
202  .setGivenMember(&Neuron7::Model::fallRateGiven)
203  .setUnit(U_NONE)
204  .setCategory(CAT_NONE)
205  .setDescription("recovery rate");
206 }
207 
208 //
209 // static class member inits
210 //
211 std::vector< std::vector<int> > Instance::jacStamp;
212 
213 // Class Instance
214 
215 //-----------------------------------------------------------------------------
216 // Function : Instance::Instance
217 // Purpose : constructor
218 // Special Notes :
219 // Scope : public
220 // Creator : Richard Schiek, Electrical and Microsytem Modeling
221 // Creation Date : 06/10/09
222 //-----------------------------------------------------------------------------
224  const Configuration & configuration,
225  const InstanceBlock & IB,
226  Model & Miter,
227  const FactoryBlock & factory_block)
228  : DeviceInstance(IB, configuration.getInstanceParameters(), factory_block),
229  model_(Miter),
230  memCap(0.0),
231  Vt(0.0),
232  Vr(0.0),
233  Vpeak(0.0),
234  k(0.0),
235  a(0.0),
236  b(0.0),
237  c(0.0),
238  d(0.0),
239  uscale(1.0e-9),
240  fallRate(1.0e3),
241  memCapGiven(false),
242  VtGiven(false),
243  VrGiven(false),
244  VpeakGiven(false),
245  kGiven(false),
246  aGiven(false),
247  bGiven(false),
248  cGiven(false),
249  dGiven(false),
250  uscaleGiven(false),
251  fallRateGiven(false),
252  vEquFvalue(0.0),
253  vEquQvalue(0.0),
254  vEqudFdv(0.0),
255  vEqudFdu(0.0),
256  vEqudQdv(0.0),
257  uEquFvalue(0.0),
258  uEquQvalue(0.0),
259  uEqudFdv(0.0),
260  uEqudFdu(0.0),
261  uEqudQdu(0.0),
262  resetting(false),
263  uPeak(0.0),
264  li_V(-1),
265  li_U(-1),
266  vEquVOffset(-1),
267  vEquUOffset(-1),
268  uEquVOffset(-1),
269  uEquUOffset(-1)
270 {
271  numExtVars = 1; // membrane voltage
272 
273  // Set params to constant default values:
274  setDefaultParams ();
275 
276  // Set params according to instance line
277  setParams (IB.params);
278 
279  // Set any non-constant parameter defaults:
280 
281  //if (!given("TEMP"))
282  // temp = getDeviceOptions().temp.dVal();
283 
284  // Calculate any parameters specified as expressions:
286 
287  // calculate dependent (ie computed) params and check for errors:
288  processParams ();
289 
290 
291  /*
292  Xyce::dout() << "Instance::Instance" << std::endl
293  << "memC = " << memCap << std::endl
294  << "Vt = " << Vt << std::endl
295  << "Vr = " << Vr << std::endl
296  << "Vp = " << Vpeak << std::endl
297  << "k = " << k << std::endl
298  << "a = " << a << std::endl
299  << "b = " << b << std::endl
300  << "c = " << c << std::endl
301  << "d = " << d << std::endl
302  << "uscale = " << uscale << std::endl
303  << "fallRate = " << fallRate << std::endl;
304  */
305 
306  numIntVars = 1; // u
307  numStateVars = 0;
308 
309  // total up number of vars.
310  int numVars = numExtVars + numIntVars;
311 
312 
313  //
314  // equations are:
315  // v equation
316  // k * (v-Vr) * (v-Vt) - u + I - C dv/dt = 0
317  // u euqtion
318  // a * ( b * (v-Vr) - u ) - du/dt = 0
319 
320  // df/dx
321  // V u
322  // Vequ 2k V - Vt - Vr -1
323  // Uequ a b -a
324  //
325  // dq/dx
326  // V u
327  // Vequ -memCap 0
328  // Uequ 0 -1
329  //
330  // so jacStamp is dense.
331 
332 
333  // set up jacStamp
334  if( jacStamp.empty() )
335  {
336  jacStamp.resize(2);
337  jacStamp[0].resize(2);
338  jacStamp[0][0] = 0;
339  jacStamp[0][1] = 1;
340  jacStamp[1].resize(2);
341  jacStamp[1][0] = 0;
342  jacStamp[1][1] = 1;
343  }
344 
345  /*
346  // print out jacStamp
347  Xyce::dout() << "jacStamp for Neuron6" << std::endl;
348  int numRows = jacStamp.size();
349  for( int i=0; i< numRows; i++ )
350  {
351  int numCol = jacStamp[i].size();
352  Xyce::dout() << "jacStamp[ " << i << " ] = { ";
353  for(int j=0; j<numCol; j++)
354  {
355  Xyce::dout() << jacStamp[i][j] << " ";
356  }
357  Xyce::dout() << " } " << std::endl;
358  }
359  Xyce::dout() << std::endl;
360  */
361 
362 }
363 
364 //-----------------------------------------------------------------------------
365 // Function : Instance::~Instance
366 // Purpose : destructor
367 // Special Notes :
368 // Scope : public
369 // Creator : Richard Schiek, Electrical and Microsytem Modeling
370 // Creation Date : 06/10/09
371 //-----------------------------------------------------------------------------
373 {
374 }
375 
376 //-----------------------------------------------------------------------------
377 // Function : Instance::processParams
378 // Purpose :
379 // Special Notes :
380 // Scope : public
381 // Creator : Richard Schiek, Electrical and Microsytem Modeling
382 // Creation Date : 06/10/09
383 //-----------------------------------------------------------------------------
385 {
386  // If there are any time dependent parameters, set their values at for
387  // the current time.
388 
389  // now set the temperature related stuff.
390  //updateTemperature(temp);
391 
392  // pull unspecified params out of the model if they weren't specified here
393  if( !memCapGiven && model_.memCapGiven )
394  {
395  memCap = model_.memCap;
396  }
397  if( !VtGiven && model_.VtGiven )
398  {
399  Vt = model_.Vt;
400  }
401  if( !VrGiven && model_.VrGiven )
402  {
403  Vr = model_.Vr;
404  }
405  if( !VpeakGiven && model_.VpeakGiven )
406  {
407  Vpeak = model_.Vpeak;
408  }
409  if( !kGiven && model_.kGiven )
410  {
411  k = model_.k;
412  }
413  if( !aGiven && model_.aGiven )
414  {
415  a = model_.a;
416  }
417  if( !bGiven && model_.bGiven )
418  {
419  b = model_.b;
420  }
421  if( !cGiven && model_.cGiven )
422  {
423  c = model_.c;
424  }
425  if( !dGiven && model_.dGiven )
426  {
427  d = model_.d;
428  }
429  if( !uscaleGiven && model_.uscaleGiven )
430  {
431  uscale = model_.uscale;
432  }
434  {
436  }
437 
438  return true;
439 }
440 
441 //-----------------------------------------------------------------------------
442 // Function : Instance::updateTemperature
443 // Purpose :
444 // Special Notes :
445 // Scope : public
446 // Creator : Richard Schiek, Electrical and Microsytem Modeling
447 // Creation Date : 06/10/09
448 //-----------------------------------------------------------------------------
449 bool Instance::updateTemperature ( const double & temp)
450 {
451  bool bsuccess = true;
452  return bsuccess;
453 }
454 
455 //-----------------------------------------------------------------------------
456 // Function : Instance::registerLIDs
457 // Purpose :
458 // Special Notes :
459 // Scope : public
460 // Creator : Richard Schiek, Electrical and Microsytem Modeling
461 // Creation Date : 06/10/09
462 //-----------------------------------------------------------------------------
463 void Instance::registerLIDs(const std::vector<int> & intLIDVecRef,
464  const std::vector<int> & extLIDVecRef)
465 {
466  AssertLIDs(intLIDVecRef.size() == numIntVars);
467  AssertLIDs(extLIDVecRef.size() == numExtVars);
468 
469  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
470  {
471  Xyce::dout() << std::endl << section_divider << std::endl;
472  Xyce::dout() << " Instance::registerLIDs" << std::endl;
473  Xyce::dout() << " name = " << getName() << std::endl;
474  }
475 
476  // copy over the global ID lists.
477  intLIDVec = intLIDVecRef;
478  extLIDVec = extLIDVecRef;
479 
480  li_V = extLIDVec[0];
481  li_U = intLIDVec[0];
482 
483  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) )
484  {
485  Xyce::dout() << " li_V = " << li_V << std::endl
486  << " li_U = " << li_U << std::endl;
487 
488  }
489 
490  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) )
491  {
492  Xyce::dout() << section_divider << std::endl;
493  }
494 
495 }
496 
497 //-----------------------------------------------------------------------------
498 // Function : Instance::loadNodeSymbols
499 // Purpose :
500 // Special Notes :
501 // Scope : public
502 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
503 // Creation Date : 05/13/05
504 //-----------------------------------------------------------------------------
505 void Instance::loadNodeSymbols(Util::SymbolTable &symbol_table) const
506 {
507  addInternalNode(symbol_table, li_U, getName(), "U");
508 }
509 
510 //-----------------------------------------------------------------------------
511 // Function : Instance::registerStateLIDs
512 // Purpose :
513 // Special Notes :
514 // Scope : public
515 // Creator : Richard Schiek, Electrical and Microsytem Modeling
516 // Creation Date : 06/10/09
517 //-----------------------------------------------------------------------------
518 void Instance::registerStateLIDs( const std::vector<int> & staLIDVecRef )
519 {
520  AssertLIDs(staLIDVecRef.size() == numStateVars);
521 }
522 
523 //-----------------------------------------------------------------------------
524 // Function : Instance::jacobianStamp
525 // Purpose :
526 // Special Notes :
527 // Scope : public
528 // Creator : Richard Schiek, Electrical and Microsytem Modeling
529 // Creation Date : 06/10/09
530 //-----------------------------------------------------------------------------
531 const std::vector< std::vector<int> > & Instance::jacobianStamp() const
532 {
533  return jacStamp;
534 }
535 
536 //-----------------------------------------------------------------------------
537 // Function : Instance::registerJacLIDs
538 // Purpose :
539 // Special Notes :
540 // Scope : public
541 // Creator : Richard Schiek, Electrical and Microsytem Modeling
542 // Creation Date : 06/10/09
543 //-----------------------------------------------------------------------------
544 void Instance::registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec )
545 {
546  DeviceInstance::registerJacLIDs( jacLIDVec );
547 
548  vEquVOffset = jacLIDVec[0][0];
549  vEquUOffset = jacLIDVec[0][1];
550  uEquVOffset = jacLIDVec[1][0];
551  uEquUOffset = jacLIDVec[1][1];
552 }
553 
554 
555 //-----------------------------------------------------------------------------
556 // Function : Instance::updateIntermediateVars
557 // Purpose :
558 // Special Notes :
559 // Scope : public
560 // Creator : Richard Schiek, Electrical and Microsytem Modeling
561 // Creation Date : 06/10/09
562 //-----------------------------------------------------------------------------
564 {
565  bool bsuccess = true;
566 
567  // here we take the current solutions for V1, V2, n, m and h
568  // and use those to calculate all the terms needed for the next
569  // load cycle (F, Q, dFdX, dQdX)
570  Linear::Vector * solVectorPtr = extData.nextSolVectorPtr;
571 
572  double vVal = (*solVectorPtr)[li_V];
573  double uVal = (*solVectorPtr)[li_U];
574 
575  // not sure if I need to do this as it should just
576  // fall out of the solution when d/dt = 0. Possibly
577  // it doesn't because there are two solutions when d/dt = 0,
578  // either vVal = Vr or vVal = Vt we want vVal=Vr.
579  if( getSolverState().dcopFlag )
580  {
581  // vVal - Vr = 0 and uVal=0
582  vEquFvalue = vVal - Vr;
583  vEquQvalue = - memCap * vVal;
584  vEqudFdv = 1.0;
585  vEqudFdu = 0.0;
586  vEqudQdv = - memCap;
587  uEquFvalue = uVal*uscale;
588  uEquQvalue = -uVal*uscale;
589  uEqudFdv = 0.0;
590  uEqudFdu = 1.0*uscale;
591  uEqudQdu = uscale;
592  }
593  else
594  {
595  // need to cacth case where v> Vpeak
596  if( !resetting && (vVal >= Vpeak) )
597  {
598  resetting = true;
599  uPeak = uVal;
600  }
601  else
602  {
603  // only break out of the resetting phase at the start of a newton solve
604  if( (getSolverState().newtonIter == 0 ) && (vVal <= (c+0.0001) ) && (uVal >= (uPeak + (d-1.0e-13)/uscale) ))
605  {
606  // reset is done, go back to old form
607  resetting = false;
608  }
609  }
610 
611  if ( resetting )
612  {
613  //Xyce::dout() << "In resetting section. (uPeak*uscale + d) = " << (uPeak + d/uscale) << std::endl;
614  vEquFvalue = -fallRate*(vVal - c) - uVal*uscale;
615  vEquQvalue = -memCap* vVal;
616  vEqudFdv = -fallRate;
617  vEqudFdu = -uscale;
618  vEqudQdv = -memCap;
619 
620  uEquFvalue = -fallRate*(uVal - (uPeak + d/uscale) );
621  uEquQvalue = -uVal;
622  uEqudFdv = 0.0;
623  uEqudFdu = -fallRate;
624  uEqudQdu = -1.0;
625  }
626  else
627  {
628  //Xyce::dout() << "In normal section." << std::endl;
629  vEquFvalue = k * (vVal - Vr) * (vVal - Vt) - uVal*uscale;
630  vEquQvalue = - memCap * vVal;
631  vEqudFdv = k * ( 2*vVal - Vt - Vr);
632  vEqudFdu = -uscale;
633  vEqudQdv = -memCap;
634 
635  uEquFvalue = a * ( b * (vVal - Vr)/uscale - uVal );
636  uEquQvalue = -uVal;
637  uEqudFdv = a * b / uscale;
638  uEqudFdu = -a;
639  uEqudQdu = -1.0;
640  }
641 
642 
643  }
644 
645  /*
646  Xyce::dout() << "Instance::updateIntermediateVars()" << std::endl
647  << "vEquFvalue = " << vEquFvalue << std::endl
648  << "vEquQvalue = " << vEquQvalue << std::endl
649  << "vEqudFdv = " << vEqudFdv << std::endl
650  << "vEqudFdu = " << vEqudFdu << std::endl
651  << "vEqudQdv = " << vEqudQdv << std::endl
652  << "uEquFvalue = " << uEquFvalue << std::endl
653  << "uEquQvalue = " << uEquQvalue << std::endl
654  << "uEqudFdv = " << uEqudFdv << std::endl
655  << "uEqudFdu = " << uEqudFdu << std::endl
656  << "uEqudQdu = " << uEqudQdu << std::endl
657  << "vVal = " << vVal << std::endl
658  << "uVal = " << uVal << std::endl;
659  */
660  return bsuccess;
661 }
662 
663 /*
664  this approach can be problematic if many of these devices are out of
665  phase and issueing breakpoints all the time. Thus, not very workable -- RLS
666 //-----------------------------------------------------------------------------
667 // Function : Instance::getInstanceBreakPoints
668 // Purpose :
669 // Special Notes :
670 // Scope : public
671 // Creator : Richard Schiek, Electrical and Microsytem Modeling
672 // Creation Date : 06/10/09
673 //-----------------------------------------------------------------------------
674 bool Instance::getInstanceBreakPoints(
675 std::vector<Util::BreakPoint> &breakPointTimes)
676 {
677 breakPointTimes.push_back(breakPoint);
678 return true;
679 }
680 */
681 
682 //-----------------------------------------------------------------------------
683 // Function : Instance::updatePrimaryState
684 // Purpose :
685 // Special Notes :
686 // Scope : public
687 // Creator : Richard Schiek, Electrical and Microsytem Modeling
688 // Creation Date : 06/10/09
689 //-----------------------------------------------------------------------------
691 {
692  bool bsuccess = true;
693 
695 
696  return bsuccess;
697 }
698 
699 //-----------------------------------------------------------------------------
700 // Function : Instance::updateSecondaryState
701 // Purpose :
702 // Special Notes :
703 // Scope : public
704 // Creator : Richard Schiek, Electrical and Microsytem Modeling
705 // Creation Date : 06/10/09
706 //-----------------------------------------------------------------------------
708 {
709  bool bsuccess = true;
710 
711  return bsuccess;
712 }
713 
714 //-----------------------------------------------------------------------------
715 // Function : Instance::loadDAEQVector
716 //
717 // Purpose : Loads the Q-vector contributions for a single
718 // Neuron 7 instance.
719 //
720 // Special Notes : The "Q" vector is part of a standard DAE formalism in
721 // which the system of equations is represented as:
722 //
723 // f(x) = dQ(x)/dt + F(x) - B(t) = 0
724 //
725 // Scope : public
726 // Creator : Richard Schiek, Electrical and Microsytem Modeling
727 // Creation Date : 06/10/09
728 //-----------------------------------------------------------------------------
730 {
731  bool bsuccess = true;
732 
733  Linear::Vector * daeQVecPtr = extData.daeQVectorPtr;
734  (*daeQVecPtr)[li_V] += vEquQvalue;
735  (*daeQVecPtr)[li_U] += uEquQvalue;
736 
737  return bsuccess;
738 }
739 
740 //-----------------------------------------------------------------------------
741 // Function : Instance::loadDAEFVector
742 //
743 // Purpose : Loads the F-vector contributions for a single
744 // Neuron 7 instance.
745 //
746 // Special Notes :
747 //
748 // Scope : public
749 // Creator : Richard Schiek, Electrical and Microsytem Modeling
750 // Creation Date : 06/10/09
751 //-----------------------------------------------------------------------------
753 {
754  bool bsuccess=true;
755 
756  Linear::Vector * daeFVecPtr = extData.daeFVectorPtr;
757 
758  (*daeFVecPtr)[li_V] += vEquFvalue;
759  (*daeFVecPtr)[li_U] += uEquFvalue;
760 
761  return bsuccess;
762 }
763 
764 //-----------------------------------------------------------------------------
765 // Function : Instance::loadDAEdQdx
766 //
767 // Purpose : Loads the Q-vector contributions for a single
768 // Neuron 7 instance.
769 // Scope : public
770 // Creator : Richard Schiek, Electrical and Microsytem Modeling
771 // Creation Date : 06/10/09
772 //-----------------------------------------------------------------------------
774 {
775  bool bsuccess = true;
776 
777  Linear::Matrix * dQdxMatPtr = extData.dQdxMatrixPtr;
778 
779  (*dQdxMatPtr)[li_V][vEquVOffset] += vEqudQdv;
780  (*dQdxMatPtr)[li_U][uEquUOffset] += uEqudQdu;
781 
782  return bsuccess;
783 }
784 
785 
786 
787 //-----------------------------------------------------------------------------
788 // Function : Instance::loadDAEdFdx ()
789 //
790 // Purpose : Loads the F-vector contributions for a single
791 // Neuron 7 instance.
792 //
793 // Special Notes : This is an algebraic constaint.
794 //
795 // Scope : public
796 // Creator : Richard Schiek, Electrical and Microsytem Modeling
797 // Creation Date : 06/10/09
798 //-----------------------------------------------------------------------------
800 {
801  bool bsuccess = true;
802 
803  Linear::Matrix * dFdxMatPtr = extData.dFdxMatrixPtr;
804 
805  (*dFdxMatPtr)[li_V][vEquVOffset] += vEqudFdv;
806  (*dFdxMatPtr)[li_V][vEquUOffset] += vEqudFdu;
807 
808  (*dFdxMatPtr)[li_U][uEquVOffset] += uEqudFdv;
809  (*dFdxMatPtr)[li_U][uEquUOffset] += uEqudFdu;
810 
811  return bsuccess;
812 }
813 
814 //-----------------------------------------------------------------------------
815 // Function : Instance::setIC
816 // Purpose :
817 // Special Notes :
818 // Scope : public
819 // Creator : Richard Schiek, Electrical and Microsytem Modeling
820 // Creation Date : 06/10/09
821 //-----------------------------------------------------------------------------
823 {
824  bool bsuccess = true;
825 
826  return bsuccess;
827 }
828 
829 //-----------------------------------------------------------------------------
830 // Function : Instance::varTypes
831 // Purpose :
832 // Special Notes :
833 // Scope : public
834 // Creator : Richard Schiek, Electrical and Microsytem Modeling
835 // Creation Date : 06/10/09
836 //-----------------------------------------------------------------------------
837 void Instance::varTypes( std::vector<char> & varTypeVec )
838 {
839  //varTypeVec.resize(1);
840  //varTypeVec[0] = 'I';
841 }
842 
843 
844 //-----------------------------------------------------------------------------
845 // Function : Model::Model
846 // Purpose : block constructor
847 // Special Notes :
848 // Scope : public
849 // Creator : Richard Schiek, Electrical and Microsytem Modeling
850 // Creation Date : 06/10/09
851 //-----------------------------------------------------------------------------
853  const Configuration & configuration,
854  const ModelBlock & MB,
855  const FactoryBlock & factory_block)
856  : DeviceModel(MB, configuration.getModelParameters(), factory_block),
857  memCap(0.0),
858  Vt(0.0),
859  Vr(0.0),
860  Vpeak(0.0),
861  k(0.0),
862  a(0.0),
863  b(0.0),
864  c(0.0),
865  d(0.0),
866  uscale(1.0e-9),
867  fallRate(1.0e3),
868  memCapGiven(false),
869  VtGiven(false),
870  VrGiven(false),
871  VpeakGiven(false),
872  kGiven(false),
873  aGiven(false),
874  bGiven(false),
875  cGiven(false),
876  dGiven(false),
877  uscaleGiven(false),
878  fallRateGiven(false)
879 {
880 
881  /*
882  Xyce::dout() << "Model::Model" << std::endl
883  << "memC = " << memCap << std::endl
884  << "Vt = " << Vt << std::endl
885  << "Vr = " << Vr << std::endl
886  << "Vp = " << Vpeak << std::endl
887  << "k = " << k << std::endl
888  << "a = " << a << std::endl
889  << "b = " << b << std::endl
890  << "c = " << c << std::endl
891  << "d = " << d << std::endl
892  << "uscale = " << uscale << std::endl
893  << "fallRate = " << fallRate << std::endl;
894  */
895 
896  // Set params to constant default values:
897  setDefaultParams ();
898 
899  // Set params according to .model line and constant defaults from metadata:
900  setModParams (MB.params);
901 
902  // Set any non-constant parameter defaults:
903  //if (!given("TNOM"))
904  // tnom = getDeviceOptions().tnom;
905 
906  // Calculate any parameters specified as expressions:
908 
909  // calculate dependent (ie computed) params and check for errors:
910 
911  processParams ();
912 }
913 
914 
915 //-----------------------------------------------------------------------------
916 // Function : Model::~Model
917 // Purpose : destructor
918 // Special Notes :
919 // Scope : public
920 // Creator : Richard Schiek, Electrical and Microsytem Modeling
921 // Creation Date : 06/10/09
922 //-----------------------------------------------------------------------------
924 {
925  std::vector<Instance*>::iterator iter;
926  std::vector<Instance*>::iterator first = instanceContainer.begin();
927  std::vector<Instance*>::iterator last = instanceContainer.end();
928 
929  for (iter=first; iter!=last; ++iter)
930  {
931  delete (*iter);
932  }
933 
934 }
935 
936 // additional Declarations
937 //-----------------------------------------------------------------------------
938 // Function : Model::processParams
939 // Purpose :
940 // Special Notes :
941 // Scope : public
942 // Creator : Richard Schiek, Electrical and Microsytem Modeling
943 // Creation Date : 06/10/09
944 //-----------------------------------------------------------------------------
946 {
947  return true;
948 }
949 
950 //----------------------------------------------------------------------------
951 // Function : Model::processInstanceParams
952 // Purpose :
953 // Special Notes :
954 // Scope : public
955 // Creator : Richard Schiek, Electrical and Microsytem Modeling
956 // Creation Date : 06/10/09
957 //----------------------------------------------------------------------------
959 {
960 
961  std::vector<Instance*>::iterator iter;
962  std::vector<Instance*>::iterator first = instanceContainer.begin();
963  std::vector<Instance*>::iterator last = instanceContainer.end();
964 
965  for (iter=first; iter!=last; ++iter)
966  {
967  (*iter)->processParams();
968  }
969 
970  return true;
971 }
972 //-----------------------------------------------------------------------------
973 // Function : Model::printOutInstances
974 // Purpose : debugging tool.
975 // Special Notes :
976 // Scope : public
977 // Creator : Richard Schiek, Electrical and Microsytem Modeling
978 // Creation Date : 06/10/09
979 //-----------------------------------------------------------------------------
980 std::ostream &Model::printOutInstances(std::ostream &os) const
981 {
982  std::vector<Instance*>::const_iterator iter;
983  std::vector<Instance*>::const_iterator first = instanceContainer.begin();
984  std::vector<Instance*>::const_iterator last = instanceContainer.end();
985 
986  int i, isize;
987  isize = instanceContainer.size();
988 
989  os << std::endl;
990  os << "Number of Neuron instances: " << isize << std::endl;
991  os << " name=\t\tmodelName\tParameters" << std::endl;
992  for (i=0, iter=first; iter!=last; ++iter, ++i)
993  {
994  os << " " << i << ": " << (*iter)->getName() << "\t";
995  os << getName();
996  os << std::endl;
997  }
998 
999  os << std::endl;
1000  return os;
1001 }
1002 
1003 //-----------------------------------------------------------------------------
1004 // Function : Model::forEachInstance
1005 // Purpose :
1006 // Special Notes :
1007 // Scope : public
1008 // Creator : David Baur
1009 // Creation Date : 2/4/2014
1010 //-----------------------------------------------------------------------------
1011 /// Apply a device instance "op" to all instances associated with this
1012 /// model
1013 ///
1014 /// @param[in] op Operator to apply to all instances.
1015 ///
1016 ///
1017 void Model::forEachInstance(DeviceInstanceOp &op) const /* override */
1018 {
1019  for (std::vector<Instance *>::const_iterator it = instanceContainer.begin(); it != instanceContainer.end(); ++it)
1020  op(*it);
1021 }
1022 
1023 
1024 Device *Traits::factory(const Configuration &configuration, const FactoryBlock &factory_block)
1025 {
1026 
1027  return new DeviceMaster<Traits>(configuration, factory_block, factory_block.solverState_, factory_block.deviceOptions_);
1028 }
1029 
1031 {
1033  .registerDevice("neuron", 7)
1034  .registerModelType("neuron", 7);
1035 }
1036 
1037 } // namespace Neuron2
1038 } // namespace Device
1039 } // namespace Xyce
const InstanceName & getName() const
const SolverState & solverState_
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Descriptor & addPar(const char *parName, T default_value, T U::*varPtr)
Adds the parameter description to the parameter map.
Definition: N_DEV_Pars.h:1429
Linear::Vector * nextSolVectorPtr
Linear::Vector * daeQVectorPtr
Pure virtual class to augment a linear system.
void addInternalNode(Util::SymbolTable &symbol_table, int index, const InstanceName &instance_name, const std::string &lead_name)
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
static void loadModelParameters(ParametricData< Model > &model_parameters)
#define AssertLIDs(cmp)
bool processInstanceParams()
processInstanceParams
RetScalarT Vt(Arg1ScalarT U, Arg2ScalarT Ud)
virtual void registerJacLIDs(const JacobianStamp &jacLIDVec)
static std::vector< std::vector< int > > jacStamp
Definition: N_DEV_Neuron7.h:94
bool updateTemperature(const double &temp_tmp)
virtual std::ostream & printOutInstances(std::ostream &os) const
std::vector< Param > params
Parameters from the line.
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
void setParams(const std::vector< Param > &params)
const std::string & getName() const
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
const DeviceOptions & deviceOptions_
const std::vector< std::vector< int > > & jacobianStamp() const
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_Neuron7.C:70
std::vector< Instance * > instanceContainer
static Config< T > & addConfiguration()
Adds the device to the Xyce device configuration.
bool processParams()
processParams
Linear::Matrix * dFdxMatrixPtr
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
Class Configuration contains device configuration data.
void varTypes(std::vector< char > &varTypeVec)
const SolverState & getSolverState() const
Linear::Vector * daeFVectorPtr
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Miter, const FactoryBlock &factory_block)
ModelBlock represents a .MODEL line from the netlist.
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
InstanceBlock represent a device instance line from the netlist.
std::vector< Param > params
Linear::Matrix * dQdxMatrixPtr
void setModParams(const std::vector< Param > &params)