Xyce  6.1
N_DEV_Vsrc.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_Vsrc.C,v $
27 //
28 // Purpose :
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.247.2.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:20:11 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-------------------------------------------------------------------------
45 #include <Xyce_config.h>
46 
47 // ---------- Standard Includes ----------
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_DeviceOptions.h>
51 #include <N_DEV_ExternData.h>
52 #include <N_DEV_MatrixLoadData.h>
53 #include <N_DEV_SolverState.h>
54 #include <N_DEV_SourceData.h>
55 #include <N_DEV_Vsrc.h>
56 #include <N_DEV_Message.h>
57 #include <N_ERH_ErrorMgr.h>
58 
59 #include <N_LAS_Vector.h>
60 #include <N_LAS_Matrix.h>
61 #include <N_UTL_BreakPoint.h>
62 #include <N_UTL_FeatureTest.h>
63 
64 namespace Xyce {
65 namespace Device {
66 
67 namespace Vsrc {
68 
70 {
71  p.addPar ("DCV0", 0.0, &Vsrc::Instance::DCV0)
72  .setOriginalValueStored(true)
73  .setUnit(U_VOLT)
74  .setDescription("DC Voltage")
75  .setAnalyticSensitivityAvailable(true)
76  .setSensitivityFunctor(&dcv0Sens);
77 
78  // Pulse parameters
79  p.addPar ("V0",0.0,&Vsrc::Instance::par0)
80  .setUnit(U_VOLT)
81  .setCategory(CAT_NONE)
82  .setDescription("Offset Voltage");
83 
84  p.addPar ("V1",0.0,&Vsrc::Instance::par0)
85  .setUnit(U_VOLT)
86  .setCategory(CAT_NONE)
87  .setDescription("Initial Voltage");
88 
89  p.addPar ("V2",0.0,&Vsrc::Instance::par1)
90  .setUnit(U_VOLT)
91  .setCategory(CAT_NONE)
92  .setDescription("Pulsed Voltage");
93 
94  p.addPar ("TD",0.0,&Vsrc::Instance::par2)
95  .setUnit(U_SECOND)
96  .setCategory(CAT_NONE)
97  .setDescription("Delay");
98 
99  p.addPar ("TR",0.0,&Vsrc::Instance::par3)
100  .setUnit(U_SECOND)
101  .setCategory(CAT_NONE)
102  .setDescription("Rise Time");
103 
104  p.addPar ("TF",0.0,&Vsrc::Instance::par4)
105  .setUnit(U_SECOND)
106  .setCategory(CAT_NONE)
107  .setDescription("Fall Time");
108 
109  p.addPar ("PW",0.0,&Vsrc::Instance::par5)
110  .setUnit(U_SECOND)
111  .setCategory(CAT_NONE)
112  .setDescription("Pulse Width");
113 
114  p.addPar ("PER",0.0,&Vsrc::Instance::par6)
115  .setUnit(U_SECOND)
116  .setCategory(CAT_NONE)
117  .setDescription("Period");
118 
119  p.addPar ("SF",0.0,&Vsrc::Instance::par7)
120  .setUnit(U_NONE)
121  .setCategory(CAT_NONE)
122  .setDescription("Scale Factor -- smooth pulse only");
123 
124  // Sin parameters
125  p.addPar ("VA",0.0,&Vsrc::Instance::par1)
126  .setUnit(U_VOLT)
127  .setCategory(CAT_NONE)
128  .setDescription("Amplitude");
129 
130  p.addPar ("FREQ",0.0,&Vsrc::Instance::par3)
131  .setUnit(U_SECM1)
132  .setCategory(CAT_NONE)
133  .setDescription("Frequency");
134 
135  p.addPar ("THETA",0.0,&Vsrc::Instance::par4)
136  .setUnit(U_NONE)
137  .setCategory(CAT_NONE)
138  .setDescription("Theta");
139 
140  p.addPar ("PHASE",0.0,&Vsrc::Instance::par5)
141  .setUnit(U_NONE)
142  .setCategory(CAT_NONE)
143  .setDescription("Phase");
144 
145  // Exp parameters
146  p.addPar ("TD1",0.0,&Vsrc::Instance::par2)
147  .setUnit(U_SECOND)
148  .setCategory(CAT_NONE)
149  .setDescription("Rise Delay Time");
150 
151  p.addPar ("TAU1",0.0,&Vsrc::Instance::par3)
152  .setUnit(U_SECOND)
153  .setCategory(CAT_NONE)
154  .setDescription("Rise Time Constant");
155 
156  p.addPar ("TD2",0.0,&Vsrc::Instance::par4)
157  .setUnit(U_SECOND)
158  .setCategory(CAT_NONE)
159  .setDescription("Fall Delay Time");
160 
161  p.addPar ("TAU2",0.0,&Vsrc::Instance::par5)
162  .setUnit(U_SECOND)
163  .setCategory(CAT_NONE)
164  .setDescription("Fall Time Constant");
165 
166  // AC parameters
167  p.addPar ("ACMAG",0.0,&Vsrc::Instance::ACMAG)
168  .setUnit(U_VOLT)
169  .setCategory(CAT_NONE)
170  .setDescription("Amplitude");
171 
172  p.addPar ("ACPHASE",0.0,&Vsrc::Instance::ACPHASE)
173  .setUnit(U_NONE)
174  .setCategory(CAT_NONE)
175  .setDescription("Phase");
176 
177  // SFFM parameters
178  p.addPar ("FC",0.0,&Vsrc::Instance::par2)
179  .setUnit(U_SECM1)
180  .setCategory(CAT_NONE)
181  .setDescription("Carrier Frequency");
182 
183  p.addPar ("FS",0.0,&Vsrc::Instance::par4)
184  .setUnit(U_SECM1)
185  .setCategory(CAT_NONE)
186  .setDescription("Signal Frequency");
187 
188  p.addPar ("MDI",0.0,&Vsrc::Instance::par3)
189  .setUnit(U_NONE)
190  .setCategory(CAT_NONE)
191  .setDescription("Modulation Index");
192 
193  // PWL params
195  .setUnit(U_SECOND)
196  .setCategory(CAT_NONE)
197  .setDescription("Repeat Time");
198 
199  p.addPar ("T",0.0,&Vsrc::Instance::T)
200  .setUnit(U_SECOND)
201  .setCategory(CAT_NONE)
202  .setDescription("Time"); // time-voltage pairs
203 
204  p.addPar ("V",0.0,&Vsrc::Instance::V)
205  .setUnit(U_VOLT)
206  .setCategory(CAT_NONE)
207  .setDescription("Voltage"); // time-voltage pairs
208 
209  // Set up exceptions (ie variables that are not doubles):
210  p.addPar ("TRANSIENTSOURCETYPE",(int) _DC_DATA, &Vsrc::Instance::TRANSIENTSOURCETYPE)
212  .setUnit(U_NONE)
213  .setCategory(CAT_NONE)
214  .setDescription("" );
215 
216  p.addPar ("ACSOURCETYPE",(int) _AC_DATA, &Vsrc::Instance::ACSOURCETYPE)
217  .setGivenMember(&Vsrc::Instance::ACSOURCETYPEgiven)
218  .setUnit(U_NONE)
219  .setCategory(CAT_NONE)
220  .setDescription("" );
221 
222  p.addPar ("DCSOURCETYPE",(int) _DC_DATA, &Vsrc::Instance::DCSOURCETYPE)
223  .setGivenMember(&Vsrc::Instance::DCSOURCETYPEgiven)
224  .setUnit(U_NONE)
225  .setCategory(CAT_NONE)
226  .setDescription("" );
227 
228  p.addPar ("NUM",0,&Vsrc::Instance::NUM)
229  .setUnit(U_NONE)
230  .setCategory(CAT_NONE)
231  .setDescription("" );
232 }
233 
235 {
236 }
237 
238 
239 std::vector< std::vector<int> > Instance::jacStamp;
240 std::vector< std::vector<int> > Instance::jacStampPDE;
241 
242 // Class Instance
243 //-----------------------------------------------------------------------------
244 // Function : Instance::Instance
245 // Purpose : "instance block" constructor
246 // Special Notes :
247 // Scope : public
248 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
249 // Creation Date : 04/06/00
250 //-----------------------------------------------------------------------------
252  const Configuration & configuration,
253  const InstanceBlock & IB,
254  Model & Viter,
255  const FactoryBlock & factory_block)
256  : SourceInstance(IB, configuration.getInstanceParameters(), factory_block),
257  model_(Viter),
258  srcCurrent(0.0),
259  srcVoltage(0.0),
260  srcDrop(0.0),
261  srcBC(0.0),
262 
263  scale(1.0),
264  nlstep(-1),
265  DCV0(0.0),
266  par0(0.0),
267  par1(0.0),
268  par2(0.0),
269  par3(0.0),
270  par4(0.0),
271  par5(0.0),
272  par6(0.0),
273  par7(0.0),
274  REPEATTIME(),
275  T(0.0),
276  V(0.0),
277  ACMAG(1.0),
278  ACPHASE(0.0),
279  NUM(0),
280  REPEAT(false),
281  TRANSIENTSOURCETYPE(_DC_DATA),
282  TRANSIENTSOURCETYPEgiven(false),
283  ACSOURCETYPE(_AC_DATA),
284  ACSOURCETYPEgiven(false),
285  DCSOURCETYPE(_AC_DATA),
286  DCSOURCETYPEgiven(false),
287 
288  li_Pos(-1),
289  li_Neg(-1),
290  li_Bra(-1),
291 
292  gotParams(false),
293 
294  ABraEquPosNodeOffset(-1),
295  ABraEquNegNodeOffset(-1),
296  APosEquBraVarOffset(-1),
297  ANegEquBraVarOffset(-1),
298  ABraEquBraVarOffset(-1),
299  APosEquPosNodeOffset(-1),
300  ANegEquNegNodeOffset(-1),
301 
303  fBraEquPosNodePtr(0),
304  fBraEquNegNodePtr(0),
305  fPosEquBraVarPtr(0),
306  fNegEquBraVarPtr(0),
307  fPosEquPosNodePtr(0),
308  fNegEquNegNodePtr(0),
309  fBraEquBraVarPtr(0),
310 #endif
311 
312  source(0.0),
313  v_pos(0.0),
314  v_neg(0.0),
315  i_bra(0.0),
316  li_branch_data(0)
317 {
318  numIntVars = 1;
319  numExtVars = 2;
320  numStateVars = 0;
321  setNumBranchDataVars(0); // by default don't allocate space in branch vectors
322  numBranchDataVarsIfAllocated = 1; // this is the space to allocate if lead current or power is needed.
323 
324  if( jacStamp.empty() )
325  {
326  jacStamp.resize(3);
327  jacStamp[0].resize(1);
328  jacStamp[0][0] = 2;
329  jacStamp[1].resize(1);
330  jacStamp[1][0] = 2;
331  jacStamp[2].resize(2);
332  jacStamp[2][0] = 0;
333  jacStamp[2][1] = 1;
334 
335  // PDE supporting stamp. This includes diagonal elements, needed by the
336  // 2-level Newton.
337  jacStampPDE.resize(3);
338  jacStampPDE[0].resize(2);
339  jacStampPDE[0][0] = 0;
340  jacStampPDE[0][1] = 2;
341  jacStampPDE[1].resize(2);
342  jacStampPDE[1][0] = 1;
343  jacStampPDE[1][1] = 2;
344  jacStampPDE[2].resize(3);
345  jacStampPDE[2][0] = 0;
346  jacStampPDE[2][1] = 1;
347  jacStampPDE[2][2] = 2;
348  }
349 
350  // Set params to constant default values:
351  setDefaultParams ();
352 
353  // Set params according to instance line and constant defaults from metadata:
354  setParams (IB.params);
355 
356  // Set any non-constant parameter defaults:
357  if (getSolverState().ACspecified && ACSOURCETYPEgiven)
358  {
360  }
361 
362  if (DCSOURCETYPEgiven) // this will always be given, if the source spec was valid.
363  {
365  }
366 
367  if (getSolverState().HBspecified || TRANSIENTSOURCETYPEgiven)
368  {
369  switch (TRANSIENTSOURCETYPE)
370  {
371  case _SIN_DATA:
373  break;
374 
375  case _EXP_DATA:
377  break;
378 
379  case _PULSE_DATA:
381  break;
382 
383  case _PWL_DATA:
385  break;
386 
387  case _SFFM_DATA:
389  break;
390 
391  case _DC_DATA:
392  tranSourceData_ = 0; // this forces us to use the dcSourceData_ object instead
393  break;
394 
395  case _SMOOTH_PULSE_DATA:
397  break;
398 
399  default:
400  UserFatal0(*this) << "Cannot identify source data type for " << getName();
401  break;
402  }
403  }
404 
405  processParams();
406 
407  // Calculate any parameters specified as expressions:
409  processParams();
410 
411  // calculate dependent (ie computed) params and check for errors:
412 
413 }
414 
415 //-----------------------------------------------------------------------------
416 // Function : Instance::processParams
417 // Purpose :
418 // Special Notes :
419 // Scope : public
420 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
421 // Creation Date : 07/26/03
422 //-----------------------------------------------------------------------------
424 {
425  if (gotParams)
426  {
427  if (dcSourceData_ != 0)
428  {
430  }
431  if (acSourceData_ != 0)
432  {
434  }
435  if (tranSourceData_ != 0)
436  {
438  }
439  }
440  else
441  {
442  if (dcSourceData_ != 0)
443  {
445  }
446  if (acSourceData_ != 0)
447  {
449  }
450  if (tranSourceData_ != 0)
451  {
453  }
454  gotParams = true;
455  }
456 
457  return true;
458 }
459 
460 //-----------------------------------------------------------------------------
461 // Function : Instance::~Instance
462 // Purpose : destructor
463 // Special Notes :
464 // Scope : public
465 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
466 // Creation Date : 04/06/00
467 //-----------------------------------------------------------------------------
469 {
470  delete tranSourceData_;
471  delete acSourceData_;
472  delete dcSourceData_;
473 }
474 
475 // Additional Declarations
476 
477 //-----------------------------------------------------------------------------
478 // Function : Instance::registerLIDs
479 // Purpose :
480 // Special Notes :
481 // Scope : public
482 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
483 // Creation Date : 6/20/02
484 //-----------------------------------------------------------------------------
485 void Instance::registerLIDs ( const std::vector<int> & intLIDVecRef,
486  const std::vector<int> & extLIDVecRef)
487 {
488  std::string msg;
489 
490  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) )
491  {
492  Xyce::dout() << std::endl << section_divider << std::endl;
493  Xyce::dout() << " VsrcInstance::registerLIDs" << std::endl;
494  Xyce::dout() << " name = " << getName() << std::endl;
495  }
496 
497  // Check if the size of the ID lists corresponds to the
498  // proper number of internal and external variables.
499  int numInt = intLIDVecRef.size();
500  int numExt = extLIDVecRef.size();
501 
502  if (numInt != numIntVars)
503  {
504  DevelFatal0(*this).in("Instance::registerLIDs") << "numInt != numIntVars";
505  }
506 
507  if (numExt != numExtVars)
508  {
509  DevelFatal0(*this).in("Instance::registerLIDs") << "numExt != numExtVars";
510  }
511 
512  // copy over the global ID lists.
513  intLIDVec = intLIDVecRef;
514  extLIDVec = extLIDVecRef;
515 
516  // Now use these lists to obtain the indices into the
517  // linear algebra entities. This assumes an order.
518  // For the matrix indices, first do the rows.
519 
520  li_Pos = extLIDVec[0];
521  li_Neg = extLIDVec[1];
522  li_Bra = intLIDVec[0];
523 
524  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) )
525  {
526  Xyce::dout() << " li_Pos = " << li_Pos << std::endl;
527  Xyce::dout() << " li_Neg = " << li_Neg << std::endl;
528  Xyce::dout() << " li_Bra = " << li_Bra << std::endl;
529  Xyce::dout() << section_divider << std::endl;
530  }
531 }
532 
533 //-----------------------------------------------------------------------------
534 // Function : Xyce::Device::Resistor::Instance::registerBranchDataLIDs
535 // Purpose :
536 // Special Notes :
537 // Scope : public
538 // Creator : Richard Schiek, Electrical Systems Modeling
539 // Creation Date : 12/18/2012
540 //-----------------------------------------------------------------------------
541 /// Register the local store IDs
542 ///
543 /// In addition to state vector, Xyce maintains a separate datastructure
544 /// called a "branch data" vector. As with other such vectors, the device
545 /// declares at construction time how many branch vector entries it needs,
546 /// and later Topology assigns locations for devices, returning LIDs.
547 ///
548 /// These LIDs are stored in this method for later use.
549 ///
550 /// The Voltage Source device uses exactly one "branch data vector" element, where
551 /// it keeps the "lead current" that may be used on .PRINT lines as
552 /// "I(V1)" for the current through resistor V1. and a junction voltage.
553 ///
554 ///
555 /// @param stoLIDVecRef Store variable local IDs
556 ///
557 /// @author Richard Schiek, Electrical Systems Modeling
558 /// @date 12/18/2012
559 void Instance::registerBranchDataLIDs(const std::vector<int> & branchLIDVecRef)
560 {
561  AssertLIDs(branchLIDVecRef.size() == getNumBranchDataVars());
562 
563  if (loadLeadCurrent)
564  {
565  li_branch_data= branchLIDVecRef[0];
566  }
567 }
568 
569 //-----------------------------------------------------------------------------
570 // Function : Instance::loadNodeSymbols
571 // Purpose :
572 // Special Notes :
573 // Scope : public
574 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
575 // Creation Date : 05/13/05
576 //-----------------------------------------------------------------------------
577 void Instance::loadNodeSymbols(Util::SymbolTable &symbol_table) const
578 {
579  addInternalNode(symbol_table, li_Bra, getName(), "branch");
580  if (loadLeadCurrent)
581  {
582  addBranchDataNode( symbol_table, li_branch_data, getName(), "BRANCH_D");
583  }
584 }
585 
586 //-----------------------------------------------------------------------------
587 // Function : Instance::registerStateLIDs
588 // Purpose :
589 // Special Notes :
590 // Scope : public
591 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
592 // Creation Date : 6/20/02
593 //-----------------------------------------------------------------------------
594 void Instance::registerStateLIDs( const std::vector<int> & staLIDVecRef )
595 {
596  AssertLIDs(staLIDVecRef.size() == numStateVars);
597 }
598 
599 //-----------------------------------------------------------------------------
600 // Function : Instance::jacobianStamp
601 // Purpose :
602 // Special Notes :
603 // Scope : public
604 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
605 // Creation Date : 8/21/02
606 //-----------------------------------------------------------------------------
607 const std::vector< std::vector<int> > & Instance::jacobianStamp() const
608 {
609  if (getSolverState().PDESystemFlag)
610  return jacStampPDE;
611 
612  return jacStamp;
613 }
614 
615 //-----------------------------------------------------------------------------
616 // Function : Instance::registerJacLIDs
617 // Purpose :
618 // Special Notes :
619 // Scope : public
620 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
621 // Creation Date : 8/27/02
622 //-----------------------------------------------------------------------------
623 void Instance::registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec )
624 {
625  DeviceInstance::registerJacLIDs( jacLIDVec );
626  if (getSolverState().PDESystemFlag)
627  {
628  APosEquBraVarOffset = jacLIDVec[0][1];
629  ANegEquBraVarOffset = jacLIDVec[1][1];
630  ABraEquPosNodeOffset = jacLIDVec[2][0];
631  ABraEquNegNodeOffset = jacLIDVec[2][1];
632  }
633  else
634  {
635  APosEquBraVarOffset = jacLIDVec[0][0];
636  ANegEquBraVarOffset = jacLIDVec[1][0];
637  ABraEquPosNodeOffset = jacLIDVec[2][0];
638  ABraEquNegNodeOffset = jacLIDVec[2][1];
639  }
640 
641 }
642 
643 //-----------------------------------------------------------------------------
644 // Function : Instance::setupPointers
645 // Purpose :
646 // Special Notes :
647 // Scope : public
648 // Creator : Eric Keiter, SNL
649 // Creation Date : 11/30/08
650 //-----------------------------------------------------------------------------
652 {
653 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
654  Linear::Matrix & dFdx = *(extData.dFdxMatrixPtr);
655 
660 #endif
661 }
662 
663 //-----------------------------------------------------------------------------
664 // Function : Instance::updateIntermediateVars
665 // Purpose :
666 // Special Notes :
667 // Scope : public
668 // Creator : Eric Keiter, 9233, Computational Sciences
669 // Creation Date : 03/05/04
670 //-----------------------------------------------------------------------------
672 {
673  double * solVec = extData.nextSolVectorRawPtr;
674 
675  // Get the value for the source.
676  SourceData *dataPtr = dcSourceData_; // by default assume the DC value.
677  if ( (getSolverState().HBspecified || getSolverState().tranopFlag || getSolverState().transientFlag) && tranSourceData_ != 0 )
678  {
679  dataPtr = tranSourceData_;
680  }
681 
682  if (dataPtr != 0)
683  {
684  source = dataPtr->returnSource();
685  }
686  else
687  {
688  source = 0.0;
689  }
690 
691  // get the value for v_pos, v_neg, i_bra
692  v_pos = solVec[li_Pos];
693  v_neg = solVec[li_Neg];
694  i_bra = solVec[li_Bra];
695 
696  srcCurrent = i_bra;
697  srcDrop = (v_pos-v_neg);
698  srcBC = source;
700 
701  if( getDeviceOptions().scale_src != 0.0 )
702  {
703  srcCurrent *= scale;
704 
705  // first newton step, generate new scaling
706  //if( nlsMgrPtr->getNonLinearIter() != nlstep )
707  if( getSolverState().newtonIter != nlstep )
708  {
709  //nlstep = nlsMgrPtr->getNonLinearIter();
711  double new_scale = fabs(i_bra) * scale;
712 
713  scale = std::max( new_scale, getDeviceOptions().scale_src );
714  }
715 
716  srcVoltage *= scale;
717  srcDrop *= scale;
718  srcBC *= scale;
719  }
720 
721  return true;
722 }
723 
724 //-----------------------------------------------------------------------------
725 // Function : Instance::updatePrimaryState
726 // Purpose :
727 // Special Notes :
728 // Scope : public
729 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
730 // Creation Date : 01/29/01
731 //-----------------------------------------------------------------------------
733 {
734  bool bsuccess = updateIntermediateVars ();
735  return bsuccess;
736 }
737 
738 //-----------------------------------------------------------------------------
739 // Function : Instance::loadDAEFVector
740 // Purpose : Loads the F-vector contributions for a single vsrc instance.
741 // Special Notes :
742 // Scope : public
743 // Creator : Eric Keiter, SNL
744 // Creation Date :
745 //-----------------------------------------------------------------------------
747 {
748  double * fVec = extData.daeFVectorRawPtr;
749 
750  fVec[li_Pos] += srcCurrent;
751  fVec[li_Neg] += -srcCurrent;
752  fVec[li_Bra] += srcDrop;
753 
754  if( loadLeadCurrent )
755  {
756  double * leadF = extData.nextLeadCurrFCompRawPtr;
757  double * junctionV = extData.nextJunctionVCompRawPtr;
758  leadF[li_branch_data] = srcCurrent;
759  junctionV[li_branch_data] = srcDrop;
760  }
761 
762  return true;
763 }
764 
765 //-----------------------------------------------------------------------------
766 // Function : Instance::loadDAEBVector
767 //
768 // Purpose : Loads the B-vector contributions for a single
769 // vsrc instance.
770 //
771 // Special Notes :
772 //
773 // Scope : public
774 // Creator : Eric Keiter, SNL
775 // Creation Date :
776 //-----------------------------------------------------------------------------
778 {
779  double * bVec = extData.daeBVectorRawPtr;
780  bVec[li_Bra] += srcBC;
781 
782  return true;
783 }
784 
785 //-----------------------------------------------------------------------------
786 // Function : Instance::loadBVectorsforAC
787 //
788 // Purpose : Loads the B-vector contributions for a single
789 // vsrc instance.
790 //
791 // Special Notes :
792 //
793 // Scope : public
794 // Creator : Ting Mei, SNL
795 // Creation Date : 5/11
796 //-----------------------------------------------------------------------------
797 bool Instance::loadBVectorsforAC(double * bVecReal, double * bVecImag )
798 {
799  if (acSourceData_ != 0)
800  {
801  bool flag = true;
802  acSourceData_->setRealFlag(flag);
803 
806  srcBC = source;
807 
808  if( getDeviceOptions().scale_src != 0.0 )
809  {
810  srcBC *= scale;
811  }
812 
813  bVecReal[li_Bra] += srcBC;
814 
815  flag = false;
816  acSourceData_->setRealFlag(flag);
817 
820  srcBC = source;
821 
822  if( getDeviceOptions().scale_src != 0.0 )
823  {
824  srcBC *= scale;
825  }
826 
827  bVecImag[li_Bra] += srcBC;
828  }
829 
830  return true;
831 }
832 
833 //-----------------------------------------------------------------------------
834 // Function : Instance::loadDAEdFdx ()
835 //
836 // Purpose : Loads the F-vector contributions for a single
837 // vsrc instance.
838 //
839 // Special Notes :
840 //
841 // Scope : public
842 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
843 // Creation Date : 03/05/04
844 //-----------------------------------------------------------------------------
846 {
847  Linear::Matrix & dFdx = *(extData.dFdxMatrixPtr);
848 
849  dFdx[li_Pos][APosEquBraVarOffset] += 1.0;
850  dFdx[li_Neg][ANegEquBraVarOffset] -= 1.0;
851  dFdx[li_Bra][ABraEquPosNodeOffset] += 1.0;
852  dFdx[li_Bra][ABraEquNegNodeOffset] -= 1.0;
853 
854  return true;
855 }
856 
857 // end of new-DAE functions
858 
859 //-----------------------------------------------------------------------------
860 // Function : Instance::getMaxTimeStepSize
861 // Purpose :
862 // Special Notes :
863 // Scope : public
864 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
865 // Creation Date : 07/23/03
866 //-----------------------------------------------------------------------------
868 {
869  double maxStep = 1.0e+100;
870  if (tranSourceData_ != 0)
871  {
872  maxStep = tranSourceData_->getMaxTimeStepSize ();
873  }
874  return maxStep;
875 }
876 
877 //-----------------------------------------------------------------------------
878 // Function : Instance::varTypes
879 // Purpose :
880 // Special Notes :
881 // Scope : public
882 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
883 // Creation Date : 02/17/04
884 //-----------------------------------------------------------------------------
885 void Instance::varTypes( std::vector<char> & varTypeVec )
886 {
887  varTypeVec.resize(1);
888  varTypeVec[0] = 'I';
889 }
890 
891 // Class Model
892 
893 //-----------------------------------------------------------------------------
894 // Function : Model::Model
895 // Purpose : copy constructor
896 // Special Notes :
897 // Scope : public
898 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
899 // Creation Date : 04/06/00
900 //-----------------------------------------------------------------------------
902  const Configuration & configuration,
903  const ModelBlock & MB,
904  const FactoryBlock & factory_block)
905  : DeviceModel(MB, configuration.getModelParameters(), factory_block),
906  DC_TRAN (0)
907 {
908 }
909 
910 //-----------------------------------------------------------------------------
911 // Function : Model::~Model
912 // Purpose : destructor
913 // Special Notes :
914 // Scope : public
915 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
916 // Creation Date : 04/06/00
917 //-----------------------------------------------------------------------------
919 {
920  std::vector<Instance*>::iterator iter;
921  std::vector<Instance*>::iterator first = instanceContainer.begin();
922  std::vector<Instance*>::iterator last = instanceContainer.end();
923 
924  for (iter=first; iter!=last; ++iter)
925  {
926  delete (*iter);
927  }
928 }
929 
930 // Additional Declarations
931 
932 //-----------------------------------------------------------------------------
933 // Function : Model::printOutInstances
934 // Purpose : debugging tool.
935 // Special Notes :
936 // Scope : public
937 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
938 // Creation Date : 4/03/00
939 //-----------------------------------------------------------------------------
940 std::ostream &Model::printOutInstances(std::ostream &os) const
941 {
942  std::vector<Instance*>::const_iterator iter;
943  std::vector<Instance*>::const_iterator first = instanceContainer.begin();
944  std::vector<Instance*>::const_iterator last = instanceContainer.end();
945 
946  int i;
947  os << std::endl;
948  os << " name model name Parameters" << std::endl;
949  for (i=0, iter=first; iter!=last; ++iter, ++i)
950  {
951  os << " " << i << ": " << (*iter)->getName() << " ";
952  os << getName();
953  os << std::endl;
954  }
955 
956  os << std::endl;
957 
958  return os;
959 }
960 
961 //-----------------------------------------------------------------------------
962 // Function : Model::forEachInstance
963 // Purpose :
964 // Special Notes :
965 // Scope : public
966 // Creator : David Baur
967 // Creation Date : 2/4/2014
968 //-----------------------------------------------------------------------------
969 /// Apply a device instance "op" to all instances associated with this
970 /// model
971 ///
972 /// @param[in] op Operator to apply to all instances.
973 ///
974 ///
975 void Model::forEachInstance(DeviceInstanceOp &op) const /* override */
976 {
977  for (std::vector<Instance *>::const_iterator it = instanceContainer.begin(); it != instanceContainer.end(); ++it)
978  op(*it);
979 }
980 
981 
982 
983 //-----------------------------------------------------------------------------
984 // Vsrc Master functions:
985 //-----------------------------------------------------------------------------
986 
987 
988 //-----------------------------------------------------------------------------
989 // Function : Master::updateState
990 // Purpose :
991 // Special Notes :
992 // Scope : public
993 // Creator : Eric Keiter, SNL
994 // Creation Date : 11/26/08
995 //-----------------------------------------------------------------------------
996 bool Master::updateState (double * solVec, double * staVec, double * stoVec)
997 {
998  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
999  {
1000  Instance & vi = *(*it);
1001  // Get the value for the source.
1002  SourceData *dataPtr = vi.dcSourceData_; // by default assume the DC value.
1003  if ( (getSolverState().HBspecified || getSolverState().tranopFlag || getSolverState().transientFlag) && vi.tranSourceData_ != 0 )
1004  {
1005  dataPtr = vi.tranSourceData_;
1006  }
1007 
1008  if (dataPtr != 0)
1009  {
1010  vi.source = dataPtr->returnSource();
1011  }
1012  else
1013  {
1014  vi.source = 0.0;
1015  }
1016 
1017  // get the value for v_pos, v_neg, i_bra
1018  vi.v_pos = solVec[vi.li_Pos];
1019  vi.v_neg = solVec[vi.li_Neg];
1020  vi.i_bra = solVec[vi.li_Bra];
1021 
1022  vi.srcCurrent = vi.i_bra;
1023  vi.srcDrop = (vi.v_pos-vi.v_neg);
1024  vi.srcBC = vi.source;
1025  vi.srcVoltage = vi.srcDrop-vi.srcBC;
1026 
1027  if( getDeviceOptions().scale_src != 0.0 )
1028  {
1029  vi.srcCurrent *= vi.scale;
1030 
1031  // first newton step, generate new scaling
1032  if( getSolverState().newtonIter != vi.nlstep )
1033  {
1035  double new_scale = fabs(vi.i_bra) * vi.scale;
1036 
1037  vi.scale = std::max( new_scale, getDeviceOptions().scale_src );
1038  }
1039 
1040  vi.srcVoltage *= vi.scale;
1041  vi.srcDrop *= vi.scale;
1042  vi.srcBC *= vi.scale;
1043  }
1044  }
1045 
1046  return true;
1047 }
1048 
1049 //-----------------------------------------------------------------------------
1050 // Function : Master::loadDAEVectors
1051 // Purpose :
1052 // Special Notes :
1053 // Scope : public
1054 // Creator : Eric Keiter, SNL
1055 // Creation Date : 11/26/08
1056 //-----------------------------------------------------------------------------
1057 bool Master::loadDAEVectors (double * solVec, double * fVec, double *qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV)
1058 {
1059  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
1060  {
1061  Instance & vi = *(*it);
1062  fVec[vi.li_Pos] += vi.srcCurrent;
1063  fVec[vi.li_Neg] += -vi.srcCurrent;
1064  fVec[vi.li_Bra] += vi.srcDrop;
1065 
1066  bVec[vi.li_Bra] += vi.srcBC;
1067 
1068  if( vi.loadLeadCurrent )
1069  {
1070  leadF[vi.li_branch_data] = vi.srcCurrent;
1071  junctionV[vi.li_branch_data] = vi.srcDrop;
1072  }
1073 
1074  }
1075  return true;
1076 }
1077 
1078 //-----------------------------------------------------------------------------
1079 // Function : Master::loadDAEMatrices
1080 // Purpose :
1081 // Special Notes :
1082 // Scope : public
1083 // Creator : Eric Keiter, SNL
1084 // Creation Date : 11/26/08
1085 //-----------------------------------------------------------------------------
1086 bool Master::loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx)
1087 {
1088  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
1089  {
1090  Instance & vi = *(*it);
1091 
1092 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
1093  *(vi.fPosEquBraVarPtr) += 1.0;
1094  *(vi.fNegEquBraVarPtr) -= 1.0;
1095  *(vi.fBraEquPosNodePtr) += 1.0;
1096  *(vi.fBraEquNegNodePtr) -= 1.0;
1097 #else
1098  dFdx[vi.li_Pos][vi.APosEquBraVarOffset] += 1.0;
1099  dFdx[vi.li_Neg][vi.ANegEquBraVarOffset] -= 1.0;
1100  dFdx[vi.li_Bra][vi.ABraEquPosNodeOffset] += 1.0;
1101  dFdx[vi.li_Bra][vi.ABraEquNegNodeOffset] -= 1.0;
1102 #endif
1103  }
1104  return true;
1105 }
1106 
1107 Device *
1108 Traits::factory(const Configuration &configuration, const FactoryBlock &factory_block)
1109 {
1110  return new Master(configuration, factory_block, factory_block.solverState_, factory_block.deviceOptions_);
1111 }
1112 
1114 {
1116  .registerDevice("v", 1);
1117 }
1118 
1119 
1120 //-----------------------------------------------------------------------------
1121 // Function : dcVsrcSensitivity::operator
1122 // Purpose : produces df/dp and dq/dp, where p=DCV0.
1123 // Special Notes :
1124 // Scope : public
1125 // Creator : Eric Keiter, SNL
1126 // Creation Date : 7/18/2014
1127 //-----------------------------------------------------------------------------
1129  const ParameterBase &entity,
1130  const std::string & name,
1131  std::vector<double> & dfdp,
1132  std::vector<double> & dqdp,
1133  std::vector<double> & dbdp,
1134  std::vector<int> & Findices,
1135  std::vector<int> & Qindices,
1136  std::vector<int> & Bindices
1137  ) const
1138 {
1139  const ParameterBase * e1 = &entity;
1140  const Instance * in = dynamic_cast<const Instance *> (e1);
1141 
1142  dbdp.resize(1);
1143  dbdp[0] += 1.0;
1144  Bindices.resize(1);
1145  Bindices[0] = in->li_Bra;
1146 }
1147 
1148 } // namespace Vsrc
1149 } // namespace Device
1150 } // namespace Xyce
const InstanceName & getName() const
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 registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_Vsrc.C:485
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_Vsrc.C:623
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_Vsrc.C:940
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 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...
Base class for all parameters.
Definition: N_DEV_Pars.h:169
#define AssertLIDs(cmp)
virtual void registerJacLIDs(const JacobianStamp &jacLIDVec)
bool loadBVectorsforAC(double *bVecReal, double *bVecImag)
Definition: N_DEV_Vsrc.C:797
InstanceVector::const_iterator getInstanceBegin() const
Returns an iterator to the beginning of the vector of all instances created for this device...
virtual void operator()(const ParameterBase &entity, const std::string &name, std::vector< double > &dfdp, std::vector< double > &dqdp, std::vector< double > &dbdp, std::vector< int > &Findices, std::vector< int > &Qindices, std::vector< int > &Bindices) const
Definition: N_DEV_Vsrc.C:1128
void setParams(const std::vector< Param > &params)
const std::string & getName() const
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
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_Vsrc.C:1057
const DeviceOptions & getDeviceOptions() const
virtual double getMaxTimeStepSize()
virtual void getParams(double *)
static Config< T > & addConfiguration()
Adds the device to the Xyce device configuration.
void varTypes(std::vector< char > &varTypeVec)
Definition: N_DEV_Vsrc.C:885
Linear::Matrix * dFdxMatrixPtr
const DeviceOptions & getDeviceOptions() const
Returns the device options given during device construction.
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_Vsrc.C:1108
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_Vsrc.C:996
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_Vsrc.C:1086
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Definition: N_DEV_Vsrc.C:975
void registerBranchDataLIDs(const std::vector< int > &branchLIDVecRef)
Register the local store IDs.
Definition: N_DEV_Vsrc.C:559
static std::vector< std::vector< int > > jacStampPDE
Definition: N_DEV_Vsrc.h:264
const SolverState & solverState_
Class Configuration contains device configuration data.
virtual void setRealFlag(bool flag)
std::vector< Instance * > instanceContainer
Definition: N_DEV_Vsrc.h:318
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_Vsrc.C:69
const SolverState & getSolverState() const
static std::vector< std::vector< int > > jacStamp
Definition: N_DEV_Vsrc.h:263
void setNumBranchDataVars(int num_branch_data_vars)
#define Xyce_NONPOINTER_MATRIX_LOAD
Definition: N_DEV_Bsrc.C:92
virtual bool updateSource()=0
int li_branch_data
Index for Lead Current and junction voltage (for power calculations)
Definition: N_DEV_Vsrc.h:223
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_Vsrc.C:234
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
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_Vsrc.C:577
virtual void setParams(double *)
static dcVsrcSensitivity dcv0Sens
Definition: N_DEV_Vsrc.h:85
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_Vsrc.C:607
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Viter, const FactoryBlock &factory_block)
Definition: N_DEV_Vsrc.C:251
const SolverState & getSolverState() const
Returns the solver state given during device construction.
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_Vsrc.C:594