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