Xyce  6.1
N_DEV_ISRC.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_ISRC.C,v $
27 //
28 // Purpose : Independent current source
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.189 $
40 //
41 // Revision Date : $Date: 2015/04/20 20:43:55 $
42 //
43 // Current Owner : $Author: dgbaur $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 
49 // ---------- Standard Includes ----------
50 
51 // ---------- Xyce Includes ----------
52 #include <N_DEV_DeviceMgr.h>
53 #include <N_DEV_DeviceOptions.h>
54 #include <N_DEV_ExternData.h>
55 #include <N_DEV_ISRC.h>
56 #include <N_DEV_MatrixLoadData.h>
57 #include <N_DEV_SolverState.h>
58 #include <N_DEV_SourceData.h>
59 #include <N_DEV_Message.h>
60 #include <N_ERH_ErrorMgr.h>
61 
62 #include <N_LAS_Vector.h>
63 #include <N_LAS_Matrix.h>
64 #include <N_UTL_FeatureTest.h>
65 
66 namespace Xyce {
67 namespace Device {
68 namespace ISRC {
69 
71 {
72  // DC parameters
73  p.addPar ("DCV0", 0.0, &ISRC::Instance::DCV0)
74  .setOriginalValueStored(true)
75  .setUnit(U_VOLT)
76  .setDescription("DC Current");
77 
78  // Pulse parameters
79  p.addPar ("V0", 0.0, &ISRC::Instance::par0)
80  .setUnit(U_AMP)
81  .setDescription("Offset Current");
82 
83  p.addPar ("V1", 0.0, &ISRC::Instance::par0)
84  .setUnit(U_AMP)
85  .setDescription("Initial Current");
86 
87  p.addPar ("V2", 0.0, &ISRC::Instance::par1)
88  .setUnit(U_AMP)
89  .setDescription("Pulsed Current");
90 
91  p.addPar ("TD", 0.0, &ISRC::Instance::par2)
92  .setUnit(U_SECOND)
93  .setDescription("Delay");
94 
95  p.addPar ("TR", 0.0, &ISRC::Instance::par3)
96  .setUnit(U_SECOND)
97  .setDescription("Rise Time");
98 
99  p.addPar ("TF", 0.0, &ISRC::Instance::par4)
100  .setUnit(U_SECOND)
101  .setDescription("Fall Time");
102 
103  p.addPar ("PW", 0.0, &ISRC::Instance::par5)
104  .setUnit(U_SECOND)
105  .setDescription("Pulse Width");
106 
107  p.addPar ("PER", 0.0, &ISRC::Instance::par6)
108  .setUnit(U_SECOND)
109  .setDescription("Period");
110 
111  p.addPar ("SF", 0.0, &ISRC::Instance::par7)
112  .setDescription("Scale Factor -- smooth pulse only");
113 
114  // Sin parameters
115  p.addPar ("VA", 0.0, &ISRC::Instance::par1)
116  .setUnit(U_AMP)
117  .setDescription("Amplitude");
118 
119  p.addPar ("FREQ", 0.0, &ISRC::Instance::par3)
120  .setUnit(U_SECM1)
121  .setDescription("Frequency");
122 
123  p.addPar ("THETA", 0.0, &ISRC::Instance::par4)
124  .setDescription("Theta");
125 
126  p.addPar ("PHASE", 0.0, &ISRC::Instance::par5)
127  .setDescription("Phase");
128 
129  // Exp parameters
130  p.addPar ("TD1", 0.0, &ISRC::Instance::par2)
131  .setUnit(U_SECOND)
132  .setDescription("Rise Delay Time");
133 
134  p.addPar ("TAU1", 0.0, &ISRC::Instance::par3)
135  .setUnit(U_SECOND)
136  .setDescription("Rise Time Constant");
137 
138  p.addPar ("TD2", 0.0, &ISRC::Instance::par4)
139  .setUnit(U_SECOND)
140  .setDescription("Fall Delay Time");
141 
142  p.addPar ("TAU2", 0.0, &ISRC::Instance::par5)
143  .setUnit(U_SECOND)
144  .setDescription("Fall Time Constant");
145 
146  // AC parameters
147  p.addPar ("ACMAG", 0.0, &ISRC::Instance::ACMAG)
148  .setUnit(U_VOLT)
149  .setDescription("Amplitude");
150 
151  p.addPar ("ACPHASE", 0.0, &ISRC::Instance::ACPHASE)
152  .setDescription("Phase");
153 
154  // SFFM parameters
155  p.addPar ("FC", 0.0, &ISRC::Instance::par2)
156  .setUnit(U_SECM1)
157  .setDescription("Carrier Frequency");
158 
159  p.addPar ("FS", 0.0, &ISRC::Instance::par4)
160  .setUnit(U_SECM1)
161  .setDescription("Signal Frequency");
162 
163  p.addPar ("MDI", 0.0, &ISRC::Instance::par3)
164  .setDescription("Modulation Index");
165 
166  // PWL params
167  p.addPar ("R", 0.0, &ISRC::Instance::REPEATTIME)
168  .setUnit(U_SECOND)
169  .setDescription("Repeat Time");
170 
171  p.addPar ("T", 0.0, &ISRC::Instance::T)
172  .setUnit(U_SECOND)
173  .setDescription("Time"); // time-voltage pairs
174 
175  p.addPar ("V", 0.0, &ISRC::Instance::V)
176  .setUnit(U_AMP)
177  .setDescription("Current"); // time-voltage pairs
178 
179  // Set up non-double precision variables:
180  p.addPar ("TRANSIENTSOURCETYPE", (int)_DC_DATA, &ISRC::Instance::TRANSIENTSOURCETYPE)
182 
183  p.addPar ("ACSOURCETYPE", (int) _AC_DATA, &ISRC::Instance::ACSOURCETYPE)
184  .setGivenMember(&ISRC::Instance::ACSOURCETYPEgiven);
185 
186  p.addPar ("DCSOURCETYPE", (int) _DC_DATA, &ISRC::Instance::DCSOURCETYPE)
187  .setGivenMember(&ISRC::Instance::DCSOURCETYPEgiven);
188 
189  p.addPar ("NUM", 0, &ISRC::Instance::NUM);
190 }
191 
193 {
194 }
195 
196 
197 std::vector< std::vector<int> > Instance::jacStamp;
198 
199 //-----------------------------------------------------------------------------
200 // Function : Instance::Instance
201 // Purpose : instance block constructor
202 // Special Notes :
203 // Scope : public
204 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
205 // Creation Date : 04/06/00
206 //-----------------------------------------------------------------------------
208  const Configuration & configuration,
209  const InstanceBlock & instance_block,
210  Model & model,
211  const FactoryBlock & factory_block)
212  : SourceInstance(instance_block, configuration.getInstanceParameters(), factory_block),
213  model_(model),
214  li_Pos(-1),
215  li_Neg(-1),
216  li_store_dev_i(-1),
217  li_branch_data(0),
218  ACSpecified_(factory_block.deviceManager_.getACSpecified()),
219  HBSpecified_(factory_block.deviceManager_.getHBSpecified()),
220  DCV0(0.0),
221  par0(0.0),
222  par1(0.0),
223  par2(0.0),
224  par3(0.0),
225  par4(0.0),
226  par5(0.0),
227  par6(0.0),
228  par7(0.0),
229  REPEATTIME(),
230  T(0.0),
231  V(0.0),
232  ACMAG(1.0),
233  ACPHASE(0.0),
234  NUM(0),
235  REPEAT(false),
236  TRANSIENTSOURCETYPE(_DC_DATA),
237  TRANSIENTSOURCETYPEgiven(false),
238  ACSOURCETYPE(_AC_DATA),
239  ACSOURCETYPEgiven(false),
240  DCSOURCETYPE(_AC_DATA),
241  DCSOURCETYPEgiven(false),
242  gotParams(false)
243 {
244  numIntVars = 0;
245  numExtVars = 2;
246  numStateVars = 0;
247  numLeadCurrentStoreVars = 1; // lead current DEV_I
248  setNumBranchDataVars(0); // by default don't allocate space in branch vectors
249  numBranchDataVarsIfAllocated = 1; // this is the space to allocate if lead current or power is needed.
250 
251  if( jacStamp.empty() )
252  jacStamp.resize(2);
253 
254  // Set params to constant default values:
255  setDefaultParams ();
256 
257  // Set params according to instance line and constant defaults from metadata:
258  setParams (instance_block.params);
259 
260  const SolverState &solver_state = factory_block.solverState_;
261  const DeviceOptions &device_options = factory_block.deviceOptions_;
262 
263  // Set any non-constant parameter defaults:
265  {
266  acSourceData_ = new ACData(*this, instance_block.params, solver_state, device_options);
267  }
268 
269  if (DCSOURCETYPEgiven) // this will always be given, if the source spec was valid.
270  {
271  dcSourceData_ = new ConstData(*this, instance_block.params, solver_state, device_options);
272  }
273 
275  {
276  switch (TRANSIENTSOURCETYPE)
277  {
278  case _SIN_DATA:
279  tranSourceData_ = new SinData(*this, instance_block.params, solver_state, device_options);
280  break;
281 
282  case _EXP_DATA:
283  tranSourceData_ = new ExpData(*this, instance_block.params, solver_state, device_options);
284  break;
285 
286  case _PULSE_DATA:
287  tranSourceData_ = new PulseData(*this, instance_block.params, solver_state, device_options);
288  break;
289 
290  case _PWL_DATA:
291  tranSourceData_ = new PWLinData(*this, instance_block.params, solver_state, device_options);
292  break;
293 
294  case _SFFM_DATA:
295  tranSourceData_ = new SFFMData(*this, instance_block.params, solver_state, device_options);
296  break;
297 
298  case _DC_DATA:
299  tranSourceData_ = 0; // this forces us to use the DC source pointer
300  break;
301 
302  case _SMOOTH_PULSE_DATA:
303  tranSourceData_ = new SmoothPulseData(*this, instance_block.params, solver_state, device_options);
304  break;
305 
306  default:
307  UserError0(*this) << "Cannot identify source data type for " << getName();
308  break;
309  }
310  }
311 
312  processParams();
313 
314  // Calculate any parameters specified as expressions:
315 
317  processParams();
318 }
319 
320 //-----------------------------------------------------------------------------
321 // Function : Instance::processParams
322 // Purpose :
323 // Special Notes :
324 // Scope : public
325 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
326 // Creation Date : 04/06/00
327 //-----------------------------------------------------------------------------
329 {
330  if (gotParams)
331  {
332  if (dcSourceData_ != 0)
333  {
335  }
336  if (acSourceData_ != 0)
337  {
339  }
340  if (tranSourceData_ != 0)
341  {
343  }
344  }
345  else
346  {
347  if (dcSourceData_ != 0)
348  {
350  }
351  if (acSourceData_ != 0)
352  {
354  }
355  if (tranSourceData_ != 0)
356  {
358  }
359  gotParams = true;
360  }
361 
362  return true;
363 }
364 
365 //-----------------------------------------------------------------------------
366 // Function : Instance::~Instance
367 // Purpose : destructor
368 // Special Notes :
369 // Scope : public
370 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
371 // Creation Date : 04/06/00
372 //-----------------------------------------------------------------------------
374 {
375  delete tranSourceData_;
376  delete acSourceData_;
377  delete dcSourceData_;
378 }
379 
380 // additional Declarations
381 //-----------------------------------------------------------------------------
382 // Function : Instance::registerLIDs
383 // Purpose :
384 // Special Notes :
385 // Scope : public
386 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
387 // Creation Date : 6/20/02
388 //-----------------------------------------------------------------------------
389 void Instance::registerLIDs( const std::vector<int> & intLIDVecRef,
390  const std::vector<int> & extLIDVecRef)
391 {
392  AssertLIDs(intLIDVecRef.size() == numIntVars);
393  AssertLIDs(extLIDVecRef.size() == numExtVars);
394 
395  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) )
396  {
397  Xyce::dout() << std::endl << section_divider << std::endl;
398  Xyce::dout() << " ISRCInstance::registerLIDs" << std::endl;
399  Xyce::dout() << " name = " << getName() << std::endl;
400  }
401 
402  intLIDVec = intLIDVecRef;
403  extLIDVec = extLIDVecRef;
404 
405  // Now use these lists to obtain the indices into the
406  // linear algebra entities. This assumes an order. Note that
407  // for a current source, there will be no Jacobian entries.
408 
409  li_Pos = extLIDVec[0];
410  li_Neg = extLIDVec[1];
411 
412  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) )
413  {
414  Xyce::dout() << " li_Pos = " << li_Pos << std::endl;
415  Xyce::dout() << " li_Neg = " << li_Neg << std::endl;
416  Xyce::dout() << section_divider << std::endl;
417  }
418 
419 }
420 
421 //-----------------------------------------------------------------------------
422 // Function : Instance::registerStateLIDs
423 // Purpose :
424 // Special Notes :
425 // Scope : public
426 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
427 // Creation Date : 6/20/02
428 //-----------------------------------------------------------------------------
429 void Instance::registerStateLIDs(const std::vector<int> & staLIDVecRef )
430 {
431  AssertLIDs(staLIDVecRef.size() == numStateVars);
432 }
433 
434 //-----------------------------------------------------------------------------
435 // Function : Instance::registerStoreLIDs
436 // Purpose : One store var for device current.
437 // Special Notes :
438 // Scope : public
439 // Creator : Richard Schiek, Electrical Systems Modeling
440 // Creation Date : 03/27/2013
441 //-----------------------------------------------------------------------------
442 void Instance::registerStoreLIDs(const std::vector<int> & stoLIDVecRef )
443 {
444  AssertLIDs(stoLIDVecRef.size() == getNumStoreVars());
445 
446  if( loadLeadCurrent )
447  {
448  li_store_dev_i = stoLIDVecRef[0];
449  }
450 }
451 
452 //-----------------------------------------------------------------------------
453 // Function : Instance::registerBranchDataLIDs
454 // Purpose :
455 // Special Notes :
456 // Scope : public
457 // Creator : Richard Schiek, Electrical Systems Modeling
458 // Creation Date : 12/18/2012
459 //-----------------------------------------------------------------------------
460 /// Register the local store IDs
461 ///
462 /// In addition to state vector, Xyce maintains a separate datastructure
463 /// called a "branch data" vector. As with other such vectors, the device
464 /// declares at construction time how many branch vector entries it needs,
465 /// and later Topology assigns locations for devices, returning LIDs.
466 ///
467 /// These LIDs are stored in this method for later use.
468 ///
469 /// The Resistor device uses exactly one "branch data vector" element, where
470 ///
471 /// @param stoLIDVecRef Store variable local IDs
472 ///
473 /// @author Richard Schiek, Electrical Systems Modeling
474 /// @date 12/18/2012
475 
476 void Instance::registerBranchDataLIDs(const std::vector<int> & branchLIDVecRef)
477 {
478  AssertLIDs(branchLIDVecRef.size() == getNumBranchDataVars());
479 
480  if (loadLeadCurrent)
481  {
482  li_branch_data= branchLIDVecRef[0];
483  }
484 }
485 
486 //-----------------------------------------------------------------------------
487 // Function : Instance::loadNodeSymbols
488 // Purpose :
489 // Special Notes :
490 // Scope : public
491 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
492 // Creation Date : 05/13/05
493 //-----------------------------------------------------------------------------
494 void Instance::loadNodeSymbols(Util::SymbolTable &symbol_table) const
495 {
496  if (loadLeadCurrent)
497  {
498  addStoreNode(symbol_table, li_store_dev_i, getName(), "DEV_I");
499  addBranchDataNode( symbol_table, li_branch_data, getName(), "BRANCH_D");
500  }
501 }
502 
503 
504 //-----------------------------------------------------------------------------
505 // Function : Instance::jacobianStamp
506 // Purpose :
507 // Special Notes :
508 // Scope : public
509 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
510 // Creation Date : 9/5/2
511 //-----------------------------------------------------------------------------
512 const std::vector< std::vector<int> > & Instance::jacobianStamp() const
513 {
514  return jacStamp;
515 }
516 
517 //-----------------------------------------------------------------------------
518 // Function : Instance::loadBVectorsforAC
519 //
520 // Purpose : Loads the B-vector contributions for a single
521 // isrc instance.
522 //
523 // Special Notes :
524 //
525 // Scope : public
526 // Creator : Ting Mei, SNL
527 // Creation Date : 5/11
528 //-----------------------------------------------------------------------------
529 bool Instance::loadBVectorsforAC(double * bVecReal, double * bVecImag )
530 {
531  if (acSourceData_ != 0)
532  {
533  acSourceData_->setRealFlag(true);
534 
536  double source = acSourceData_->returnSource();
537 
538  bVecReal[li_Pos] -= source;
539  bVecReal[li_Neg] += source;
540 
541  acSourceData_->setRealFlag(false);
542 
544  source = acSourceData_->returnSource();
545 
546  bVecImag[li_Pos] -= source;
547  bVecImag[li_Neg] += source;
548  }
549 
550  return true;
551 }
552 
553 //-----------------------------------------------------------------------------
554 // Function : Instance::updatePrimaryState
555 // Purpose :
556 // Special Notes :
557 // Scope : public
558 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
559 // Creation Date : 01/29/01
560 //-----------------------------------------------------------------------------
562 {
563  return true;
564 }
565 
566 //-----------------------------------------------------------------------------
567 // Function : Instance::loadDAEFVector
568 // Purpose : Loads the F-vector contributions for a single
569 // ISRC instance.
570 // Special Notes :
571 // Scope : public
572 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
573 // Creation Date : 03/05/04
574 //-----------------------------------------------------------------------------
576 {
577  return true;
578 }
579 
580 
581 //-----------------------------------------------------------------------------
582 // Function : Instance::loadDAEBVector
583 // Purpose : Loads the F-vector contributions for a single
584 // ISRC instance.
585 // Special Notes :
586 // Scope : public
587 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
588 // Creation Date : 03/05/04
589 //-----------------------------------------------------------------------------
591 {
592  bool bsuccess = true;
593 
594  double * bVec = extData.daeBVectorRawPtr;
595 
596  // get the source value:
597  SourceData *dataPtr = dcSourceData_; // by default assume the DC value.
598  if ((HBSpecified_ || getSolverState().tranopFlag || getSolverState().transientFlag) && tranSourceData_ != 0 )
599  {
600  dataPtr = tranSourceData_;
601  }
602 
603  double source = 0.0;
604  if (dataPtr != 0)
605  {
606  source = dataPtr->returnSource();
607  }
608  bVec[li_Pos] -= source;
609  bVec[li_Neg] += source;
610 
611  if( loadLeadCurrent )
612  {
613  double * stoVec = extData.nextStoVectorRawPtr;
614  double * leadF = extData.nextLeadCurrFCompRawPtr;
615  double * junctionV = extData.nextJunctionVCompRawPtr;
616  double * solVec = extData.nextSolVectorRawPtr;
617  stoVec[li_store_dev_i] = source;
618  leadF[li_branch_data] = source;
619  junctionV[li_branch_data] = solVec[li_Pos] - solVec[li_Neg];
620  }
621 
622 
623 
624  return bsuccess;
625 }
626 
627 
628 
629 //-----------------------------------------------------------------------------
630 // Function : Model::Model
631 // Purpose : copy constructor
632 // Special Notes :
633 // Scope : public
634 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
635 // Creation Date : 04/06/00
636 //-----------------------------------------------------------------------------
638  const Configuration & configuration,
639  const ModelBlock & MB,
640  const FactoryBlock & factory_block)
641  : DeviceModel(MB, configuration.getModelParameters(), factory_block)
642 {
643 
644 }
645 
646 //-----------------------------------------------------------------------------
647 // Function : Model::~Model
648 // Purpose : destructor
649 // Special Notes :
650 // Scope : public
651 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
652 // Creation Date : 04/06/00
653 //-----------------------------------------------------------------------------
655 {
656  std::vector<Instance*>::iterator iter;
657  std::vector<Instance*>::iterator first = instanceContainer.begin();
658  std::vector<Instance*>::iterator last = instanceContainer.end();
659 
660  for (iter=first; iter!=last; ++iter)
661  {
662  delete (*iter);
663  }
664 }
665 
666 // additional Declarations
667 
668 //----------------------------------------------------------------------------
669 // Function : Model::processParams
670 // Purpose :
671 // Special Notes :
672 // Scope : public
673 // Creator : Lon Waters
674 // Creation Date : 07/29/2002
675 //----------------------------------------------------------------------------
677 {
678  return true;
679 }
680 
681 //----------------------------------------------------------------------------
682 // Function : Model::processInstanceParams
683 // Purpose :
684 // Special Notes :
685 // Scope : public
686 // Creator : Dave Shirely, PSSI
687 // Creation Date : 03/23/06
688 //----------------------------------------------------------------------------
690 {
691 
692  std::vector<Instance*>::iterator iter;
693  std::vector<Instance*>::iterator first = instanceContainer.begin();
694  std::vector<Instance*>::iterator last = instanceContainer.end();
695 
696  for (iter=first; iter!=last; ++iter)
697  {
698  (*iter)->processParams();
699  }
700 
701  return true;
702 }
703 
704 //-----------------------------------------------------------------------------
705 // Function : Model::printOutInstances
706 // Purpose : debugging tool.
707 // Special Notes :
708 // Scope : public
709 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
710 // Creation Date : 4/03/00
711 //-----------------------------------------------------------------------------
712 std::ostream &Model::printOutInstances(std::ostream &os) const
713 {
714  if (DEBUG_DEVICE)
715  {
716  std::vector<Instance*>::const_iterator iter;
717  std::vector<Instance*>::const_iterator first = instanceContainer.begin();
718  std::vector<Instance*>::const_iterator last = instanceContainer.end();
719 
720  int i;
721  os << std::endl;
722  os << " name modelName Parameters" << std::endl;
723  for (i=0, iter=first; iter!=last; ++iter, ++i)
724  {
725  os << " " << i << ": " << (*iter)->getName() << " ";
726  os << getName();
727  os << std::endl;
728  if ( (*iter)->tranSourceData_ != 0 )
729  {
730  (*iter)->tranSourceData_->printOutParams ();
731  }
732 
733  if ( (*iter)->dcSourceData_ != 0 )
734  {
735  (*iter)->dcSourceData_->printOutParams ();
736  }
737 
738  if ( (*iter)->acSourceData_ != 0 )
739  {
740  (*iter)->acSourceData_->printOutParams ();
741  }
742  }
743 
744  os << std::endl;
745  }
746  return os;
747 }
748 
749 //-----------------------------------------------------------------------------
750 // Function : Model::forEachInstance
751 // Purpose :
752 // Special Notes :
753 // Scope : public
754 // Creator : David Baur
755 // Creation Date : 2/4/2014
756 //-----------------------------------------------------------------------------
757 /// Apply a device instance "op" to all instances associated with this
758 /// model
759 ///
760 /// @param[in] op Operator to apply to all instances.
761 ///
762 ///
763 void Model::forEachInstance(DeviceInstanceOp &op) const /* override */
764 {
765  for (std::vector<Instance *>::const_iterator it = instanceContainer.begin(); it != instanceContainer.end(); ++it)
766  op(*it);
767 }
768 
769 //-----------------------------------------------------------------------------
770 // ISRC Master functions:
771 //-----------------------------------------------------------------------------
772 
774  const Configuration & configuration,
775  const FactoryBlock & factory_block,
776  const SolverState & solver_state,
777  const DeviceOptions & device_options)
778  : DeviceMaster<Traits>(configuration, factory_block, solver_state, device_options),
779  HBSpecified_(factory_block.deviceManager_.getHBSpecified())
780 {}
781 
782 //-----------------------------------------------------------------------------
783 // Function : Master::updateState
784 // Purpose :
785 // Special Notes :
786 // Scope : public
787 // Creator : Eric Keiter, SNL
788 // Creation Date : 11/26/08
789 //-----------------------------------------------------------------------------
790 bool Master::updateState (double * solVec, double * staVec, double * stoVec)
791 {
792  return true;
793 }
794 
795 //-----------------------------------------------------------------------------
796 // Function : Master::loadDAEVectors
797 // Purpose :
798 // Special Notes :
799 // Scope : public
800 // Creator : Eric Keiter, SNL
801 // Creation Date : 11/26/08
802 //-----------------------------------------------------------------------------
803 bool Master::loadDAEVectors (double * solVec, double * fVec, double *qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV)
804 {
805  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
806  {
807  Instance & inst = *(*it);
808 
809  SourceData *dataPtr = inst.dcSourceData_; // by default assume the DC value.
810  if ((HBSpecified_ || getSolverState().tranopFlag || getSolverState().transientFlag) && inst.tranSourceData_ != 0 )
811  {
812  dataPtr = inst.tranSourceData_;
813  }
814 
815  double source = 0.0;
816  if (dataPtr != 0)
817  {
818  source = dataPtr->returnSource();
819  }
820 
821  bVec[inst.li_Pos] -= source;
822  bVec[inst.li_Neg] += source;
823 
824  if( inst.loadLeadCurrent )
825  {
826  storeLeadF[inst.li_store_dev_i] = source;
827  leadF[inst.li_branch_data] = source;
828  junctionV[inst.li_branch_data] = solVec[inst.li_Pos] - solVec[inst.li_Neg];
829  }
830 
831 
832  }
833  return true;
834 }
835 
836 //-----------------------------------------------------------------------------
837 // Function : Master::loadDAEMatrices
838 // Purpose :
839 // Special Notes :
840 // Scope : public
841 // Creator : Eric Keiter, SNL
842 // Creation Date : 11/26/08
843 //-----------------------------------------------------------------------------
844 bool Master::loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx)
845 {
846  return true;
847 }
848 
849 
850 Device *Traits::factory(const Configuration &configuration, const FactoryBlock &factory_block)
851 {
852  return new DeviceMaster<Traits>(configuration, factory_block, factory_block.solverState_, factory_block.deviceOptions_);
853 }
854 
856 {
858  .registerDevice("i", 1);
859 }
860 
861 } // namespace Resistor
862 } // namespace Device
863 } // namespace Xyce
const InstanceName & getName() const
virtual bool processParams()
processParams
Definition: N_DEV_ISRC.C:676
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_ISRC.C:844
const SolverState & solverState_
const DeviceOptions & deviceOptions_
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
void registerBranchDataLIDs(const std::vector< int > &branchLIDVecRef)
Register the local store IDs.
Definition: N_DEV_ISRC.C:476
Pure virtual class to augment a linear system.
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_ISRC.C:192
Instance(const Configuration &configuration, const InstanceBlock &instance_block, Model &model, const FactoryBlock &factory_block)
Definition: N_DEV_ISRC.C:207
void addBranchDataNode(Util::SymbolTable &symbol_table, int index, const InstanceName &instance_name, const std::string &lead_name)
InstanceVector::const_iterator getInstanceEnd() const
Returns an iterator to the ending of the vector of all instances created for this device...
int li_branch_data
Index for lead current and junction voltage (for power calculations)
Definition: N_DEV_ISRC.h:161
#define AssertLIDs(cmp)
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &solver_state, const DeviceOptions &device_options)
Definition: N_DEV_ISRC.C:773
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_ISRC.C:389
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_ISRC.C:790
InstanceVector::const_iterator getInstanceBegin() const
Returns an iterator to the beginning of the vector of all instances created for this device...
void setParams(const std::vector< Param > &params)
DeviceMaster instantiates a device as described by the device traits T.
const std::string & getName() const
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_ISRC.C:429
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
Device::DeviceMgr & deviceManager_
Definition: N_ANP_HB.C:2199
bool loadBVectorsforAC(double *bVecReal, double *bVecImag)
Definition: N_DEV_ISRC.C:529
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_ISRC.C:850
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_ISRC.C:712
const DeviceOptions & deviceOptions_
virtual void getParams(double *)
static Config< T > & addConfiguration()
Adds the device to the Xyce device configuration.
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_ISRC.C:70
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
void addStoreNode(Util::SymbolTable &symbol_table, int index, const InstanceName &instance_name, const std::string &lead_name)
static std::vector< std::vector< int > > jacStamp
Definition: N_DEV_ISRC.h:151
const SolverState & solverState_
Class Configuration contains device configuration data.
std::vector< Instance * > instanceContainer
Definition: N_DEV_ISRC.h:234
virtual void setRealFlag(bool flag)
void registerStoreLIDs(const std::vector< int > &stoLIDVecRef)
Definition: N_DEV_ISRC.C:442
const SolverState & getSolverState() const
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Definition: N_DEV_ISRC.C:763
virtual bool processInstanceParams()
processInstanceParams
Definition: N_DEV_ISRC.C:689
void setNumBranchDataVars(int num_branch_data_vars)
virtual bool updateSource()=0
virtual bool loadDAEVectors(double *solVec, double *fVec, double *qVec, double *bVec, double *storeLeadF, double *storeLeadQ, double *leadF, double *leadQ, double *junctionV)
Populates the device's ExternData object with these pointers.
Definition: N_DEV_ISRC.C:803
virtual void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_ISRC.C:494
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_ISRC.C:512
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
virtual void setParams(double *)
const SolverState & getSolverState() const
Returns the solver state given during device construction.