Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2014 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.226.2.2 $
40 //
41 // Revision Date : $Date: 2014/03/06 23:33:43 $
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 
63 namespace Xyce {
64 namespace Device {
65 
66 
67 namespace Vsrc {
68 
69 
71 {
72  // Set up double precision variables:
73  // DC parameters
74  p.addPar ("DCV0", 0.0, true, ParameterType::NO_DEP,
76  NULL, U_VOLT, CAT_NONE, "DC Voltage");
77 
78  // Pulse parameters
79  p.addPar ("V0", 0.0, false, ParameterType::NO_DEP,
81  NULL, U_VOLT, CAT_NONE, "Offset Voltage");
82 
83  p.addPar ("V1", 0.0, false, ParameterType::NO_DEP,
85  NULL, U_VOLT, CAT_NONE, "Initial Voltage");
86 
87  p.addPar ("V2", 0.0, false, ParameterType::NO_DEP,
89  NULL, U_VOLT, CAT_NONE, "Pulsed Voltage");
90 
91  p.addPar ("TD", 0.0, false, ParameterType::NO_DEP,
93  NULL, U_SECOND, CAT_NONE, "Delay");
94 
95  p.addPar ("TR", 0.0, false, ParameterType::NO_DEP,
97  NULL, U_SECOND, CAT_NONE, "Rise Time");
98 
99  p.addPar ("TF", 0.0, false, ParameterType::NO_DEP,
101  NULL, U_SECOND, CAT_NONE, "Fall Time");
102 
103  p.addPar ("PW", 0.0, false, ParameterType::NO_DEP,
105  NULL, U_SECOND, CAT_NONE, "Pulse Width");
106 
107  p.addPar ("PER", 0.0, false, ParameterType::NO_DEP,
109  NULL, U_SECOND, CAT_NONE, "Period");
110 
111  p.addPar ("SF", 0.0, false, ParameterType::NO_DEP,
113  NULL, U_NONE, CAT_NONE, "Scale Factor -- smooth pulse only");
114 
115  // Sin parameters
116  p.addPar ("VA", 0.0, false, ParameterType::NO_DEP,
118  NULL, U_VOLT, CAT_NONE, "Amplitude");
119 
120  p.addPar ("FREQ", 0.0, false, ParameterType::NO_DEP,
122  NULL, U_SECM1, CAT_NONE, "Frequency");
123 
124  p.addPar ("THETA", 0.0, false, ParameterType::NO_DEP,
126  NULL, U_NONE, CAT_NONE, "Theta");
127 
128  p.addPar ("PHASE", 0.0, false, ParameterType::NO_DEP,
130  NULL, U_NONE, CAT_NONE, "Phase");
131 
132  // Exp parameters
133  p.addPar ("TD1", 0.0, false, ParameterType::NO_DEP,
135  NULL, U_SECOND, CAT_NONE, "Rise Delay Time");
136 
137  p.addPar ("TAU1", 0.0, false, ParameterType::NO_DEP,
139  NULL, U_SECOND, CAT_NONE, "Rise Time Constant");
140 
141  p.addPar ("TD2", 0.0, false, ParameterType::NO_DEP,
143  NULL, U_SECOND, CAT_NONE, "Fall Delay Time");
144 
145  p.addPar ("TAU2", 0.0, false, ParameterType::NO_DEP,
147  NULL, U_SECOND, CAT_NONE, "Fall Time Constant");
148 
149 // AC parameters
150  p.addPar ("ACMAG", 0.0, false, ParameterType::NO_DEP,
152  NULL, U_VOLT, CAT_NONE, "Amplitude");
153 
154  p.addPar ("ACPHASE", 0.0, false, ParameterType::NO_DEP,
156  NULL, U_NONE, CAT_NONE, "Phase");
157 
158  // SFFM parameters
159  p.addPar ("FC", 0.0, false, ParameterType::NO_DEP,
161  NULL, U_SECM1, CAT_NONE, "Carrier Frequency");
162 
163  p.addPar ("FS", 0.0, false, ParameterType::NO_DEP,
165  NULL, U_SECM1, CAT_NONE, "Signal Frequency");
166 
167  p.addPar ("MDI", 0.0, false, ParameterType::NO_DEP,
169  NULL, U_NONE, CAT_NONE, "Modulation Index");
170 
171  // PWL params
172  p.addPar ("R", 0.0, false, ParameterType::NO_DEP,
174  NULL, U_SECOND, CAT_NONE, "Repeat Time");
175 
176  p.addPar ("REPEATTIME", 0.0, false, ParameterType::NO_DEP,
178  NULL, U_SECOND, CAT_NONE, "Repeat Time");
179 
180  p.addPar ("T", 0.0, false, ParameterType::NO_DEP,
182  NULL, U_SECOND, CAT_NONE, "Time"); // time-voltage pairs
183 
184  p.addPar ("V", 0.0, false, ParameterType::NO_DEP,
186  NULL, U_VOLT, CAT_NONE, "Voltage"); // time-voltage pairs
187 
188  // Set up exceptions (ie variables that are not doubles):
189  p.addPar ("TRANSIENTSOURCETYPE", (int) _DC_DATA, false, ParameterType::NO_DEP,
192  U_NONE, CAT_NONE, "" );
193 
194  p.addPar ("ACSOURCETYPE", (int) _AC_DATA, false, ParameterType::NO_DEP,
197  U_NONE, CAT_NONE, "" );
198 
199  p.addPar ("DCSOURCETYPE", (int) _DC_DATA, false, ParameterType::NO_DEP,
202  U_NONE, CAT_NONE, "" );
203 
204  p.addPar ("NUM", 0, false, ParameterType::NO_DEP,
206  NULL, U_NONE, CAT_NONE, "" );
207 
208  p.addPar ("REPEAT", false, false, ParameterType::NO_DEP,
210  NULL, U_NONE, CAT_NONE, "" );
211 }
212 
214 {
215 }
216 
217 
218 std::vector< std::vector<int> > Instance::jacStamp;
219 std::vector< std::vector<int> > Instance::jacStampPDE;
220 
221 // Class Instance
222 //-----------------------------------------------------------------------------
223 // Function : Instance::Instance
224 // Purpose : "instance block" constructor
225 // Special Notes :
226 // Scope : public
227 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
228 // Creation Date : 04/06/00
229 //-----------------------------------------------------------------------------
231  const Configuration & configuration,
232  const InstanceBlock & IB,
233  Model & Viter,
234  const FactoryBlock & factory_block)
235  : SourceInstance(IB, configuration.getInstanceParameters(), factory_block),
236  model_(Viter),
237  srcCurrent(0.0),
238  srcVoltage(0.0),
239  srcDrop(0.0),
240  srcBC(0.0),
241 
242  scale(1.0),
243  nlstep(-1),
244  DCV0(0.0),
245  par0(0.0),
246  par1(0.0),
247  par2(0.0),
248  par3(0.0),
249  par4(0.0),
250  par5(0.0),
251  par6(0.0),
252  par7(0.0),
253  REPEATTIME(),
254  T(0.0),
255  V(0.0),
256  ACMAG(1.0),
257  ACPHASE(0.0),
258  NUM(0),
259  REPEAT(false),
260  TRANSIENTSOURCETYPE(_DC_DATA),
261  TRANSIENTSOURCETYPEgiven(false),
262  ACSOURCETYPE(_AC_DATA),
263  ACSOURCETYPEgiven(false),
264  DCSOURCETYPE(_AC_DATA),
265  DCSOURCETYPEgiven(false),
266 
267  li_Pos(-1),
268  li_Neg(-1),
269  li_Bra(-1),
270 
271  gotParams(false),
272 
273  ABraEquPosNodeOffset(-1),
274  ABraEquNegNodeOffset(-1),
275  APosEquBraVarOffset(-1),
276  ANegEquBraVarOffset(-1),
277  ABraEquBraVarOffset(-1),
278  APosEquPosNodeOffset(-1),
279  ANegEquNegNodeOffset(-1),
280 
282  fBraEquPosNodePtr(0),
283  fBraEquNegNodePtr(0),
284  fPosEquBraVarPtr(0),
285  fNegEquBraVarPtr(0),
286  fPosEquPosNodePtr(0),
287  fNegEquNegNodePtr(0),
288  fBraEquBraVarPtr(0),
289 #endif
290 
291  source(0.0),
292  v_pos(0.0),
293  v_neg(0.0),
294  i_bra(0.0)
295 {
296  numIntVars = 1;
297  numExtVars = 2;
298  numStateVars = 0;
299 
300  if( jacStamp.empty() )
301  {
302  jacStamp.resize(3);
303  jacStamp[0].resize(1);
304  jacStamp[0][0] = 2;
305  jacStamp[1].resize(1);
306  jacStamp[1][0] = 2;
307  jacStamp[2].resize(2);
308  jacStamp[2][0] = 0;
309  jacStamp[2][1] = 1;
310 
311  // PDE supporting stamp. This includes diagonal elements, needed by the
312  // 2-level Newton.
313  jacStampPDE.resize(3);
314  jacStampPDE[0].resize(2);
315  jacStampPDE[0][0] = 0;
316  jacStampPDE[0][1] = 2;
317  jacStampPDE[1].resize(2);
318  jacStampPDE[1][0] = 1;
319  jacStampPDE[1][1] = 2;
320  jacStampPDE[2].resize(3);
321  jacStampPDE[2][0] = 0;
322  jacStampPDE[2][1] = 1;
323  jacStampPDE[2][2] = 2;
324  }
325 
326  // Set params to constant default values:
327  setDefaultParams ();
328 
329  // Set params according to instance line and constant defaults from metadata:
330  setParams (IB.params);
331 
332  // Set any non-constant parameter defaults:
333  if (getSolverState().ACspecified && ACSOURCETYPEgiven)
334  {
336  }
337 
338  if (DCSOURCETYPEgiven) // this will always be given, if the source spec was valid.
339  {
341  }
342 
343  if (getSolverState().HBspecified || TRANSIENTSOURCETYPEgiven)
344  {
345  switch (TRANSIENTSOURCETYPE)
346  {
347  case _SIN_DATA:
349  break;
350 
351  case _EXP_DATA:
353  break;
354 
355  case _PULSE_DATA:
357  break;
358 
359  case _PWL_DATA:
361  break;
362 
363  case _SFFM_DATA:
365  break;
366 
367  case _DC_DATA:
369  break;
370 
371  case _SMOOTH_PULSE_DATA:
373  break;
374 
375 // case _AC_DATA:
376 // Data_ptr = new ACData (IB.params,getSolverState(),getDeviceOptions());
377  // break;
378 
379  default:
380  UserFatal0(*this) << "Cannot identify source data type for " << getName();
381  break;
382  }
383  }
384 
385  processParams();
386 
387  // Calculate any parameters specified as expressions:
389  processParams();
390 
391  // calculate dependent (ie computed) params and check for errors:
392 
393 }
394 
395 //-----------------------------------------------------------------------------
396 // Function : Instance::processParams
397 // Purpose :
398 // Special Notes :
399 // Scope : public
400 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
401 // Creation Date : 07/26/03
402 //-----------------------------------------------------------------------------
404 {
405  if (gotParams)
406  {
407  if (dcData_ptr != 0)
408  {
410  }
411  if (acData_ptr != 0)
412  {
414  }
415  if (Data_ptr != 0)
416  {
418  }
419  }
420  else
421  {
422  if (dcData_ptr != 0)
423  {
425  }
426  if (acData_ptr != 0)
427  {
429  }
430  if (Data_ptr != 0)
431  {
433  }
434  gotParams = true;
435  }
436 
437  return true;
438 }
439 
440 //-----------------------------------------------------------------------------
441 // Function : Instance::~Instance
442 // Purpose : destructor
443 // Special Notes :
444 // Scope : public
445 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
446 // Creation Date : 04/06/00
447 //-----------------------------------------------------------------------------
449 {
450  if (Data_ptr != 0)
451  {
452  delete Data_ptr;
453  }
454  if (acData_ptr != 0)
455  {
456  delete acData_ptr;
457  }
458  if (dcData_ptr != 0)
459  {
460  delete dcData_ptr;
461  }
462 }
463 
464 // Additional Declarations
465 
466 //-----------------------------------------------------------------------------
467 // Function : Instance::registerLIDs
468 // Purpose :
469 // Special Notes :
470 // Scope : public
471 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
472 // Creation Date : 6/20/02
473 //-----------------------------------------------------------------------------
474 void Instance::registerLIDs ( const std::vector<int> & intLIDVecRef,
475  const std::vector<int> & extLIDVecRef)
476 {
477  std::string msg;
478 
479 #ifdef Xyce_DEBUG_DEVICE
480  if (getDeviceOptions().debugLevel > 0 )
481  {
482  Xyce::dout() << std::endl << section_divider << std::endl;
483  Xyce::dout() << " VsrcInstance::registerLIDs" << std::endl;
484  Xyce::dout() << " name = " << getName() << std::endl;
485  }
486 #endif
487 
488  // Check if the size of the ID lists corresponds to the
489  // proper number of internal and external variables.
490  int numInt = intLIDVecRef.size();
491  int numExt = extLIDVecRef.size();
492 
493  if (numInt != numIntVars)
494  {
495  msg = "Instance::registerLIDs:";
496  msg += "numInt != numIntVars";
497  N_ERH_ErrorMgr::report ( N_ERH_ErrorMgr::DEV_FATAL_0,msg);
498  }
499 
500  if (numExt != numExtVars)
501  {
502  msg = "Instance::registerLIDs:";
503  msg += "numExt != numExtVars";
504  N_ERH_ErrorMgr::report ( N_ERH_ErrorMgr::DEV_FATAL_0,msg);
505  }
506 
507  // copy over the global ID lists.
508  intLIDVec = intLIDVecRef;
509  extLIDVec = extLIDVecRef;
510 
511  // Now use these lists to obtain the indices into the
512  // linear algebra entities. This assumes an order.
513  // For the matrix indices, first do the rows.
514 
515  li_Pos = extLIDVec[0];
516  li_Neg = extLIDVec[1];
517  li_Bra = intLIDVec[0];
518 
519 #ifdef Xyce_DEBUG_DEVICE
520  if (getDeviceOptions().debugLevel > 0 )
521  {
522  Xyce::dout() << " li_Pos = " << li_Pos << std::endl;
523  Xyce::dout() << " li_Neg = " << li_Neg << std::endl;
524  Xyce::dout() << " li_Bra = " << li_Bra << std::endl;
525  Xyce::dout() << section_divider << std::endl;
526  }
527 #endif
528 }
529 
530 //-----------------------------------------------------------------------------
531 // Function : Instance::getIntNameMap
532 // Purpose :
533 // Special Notes :
534 // Scope : public
535 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
536 // Creation Date : 05/13/05
537 //-----------------------------------------------------------------------------
538 std::map<int,std::string> & Instance::getIntNameMap ()
539 {
540  // set up the internal name map, if it hasn't been already.
541  if (intNameMap.empty ())
542  {
543  // set up the internal name map
544  std::string tmpstr(getName()+"_branch");
545  spiceInternalName (tmpstr);
546  intNameMap[ li_Bra ] = tmpstr;
547  }
548 
549  return intNameMap;
550 }
551 
552 
553 
554 //-----------------------------------------------------------------------------
555 // Function : Instance::registerStateLIDs
556 // Purpose :
557 // Special Notes :
558 // Scope : public
559 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
560 // Creation Date : 6/20/02
561 //-----------------------------------------------------------------------------
562 void Instance::registerStateLIDs( const std::vector<int> & staLIDVecRef )
563 {
564  AssertLIDs(staLIDVecRef.size() == numStateVars);
565 }
566 
567 //-----------------------------------------------------------------------------
568 // Function : Instance::jacobianStamp
569 // Purpose :
570 // Special Notes :
571 // Scope : public
572 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
573 // Creation Date : 8/21/02
574 //-----------------------------------------------------------------------------
575 const std::vector< std::vector<int> > & Instance::jacobianStamp() const
576 {
577  if (getSolverState().PDESystemFlag)
578  return jacStampPDE;
579 
580  return jacStamp;
581 }
582 
583 //-----------------------------------------------------------------------------
584 // Function : Instance::registerJacLIDs
585 // Purpose :
586 // Special Notes :
587 // Scope : public
588 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
589 // Creation Date : 8/27/02
590 //-----------------------------------------------------------------------------
591 void Instance::registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec )
592 {
593  DeviceInstance::registerJacLIDs( jacLIDVec );
594  if (getSolverState().PDESystemFlag)
595  {
596  APosEquBraVarOffset = jacLIDVec[0][1];
597  ANegEquBraVarOffset = jacLIDVec[1][1];
598  ABraEquPosNodeOffset = jacLIDVec[2][0];
599  ABraEquNegNodeOffset = jacLIDVec[2][1];
600  }
601  else
602  {
603  APosEquBraVarOffset = jacLIDVec[0][0];
604  ANegEquBraVarOffset = jacLIDVec[1][0];
605  ABraEquPosNodeOffset = jacLIDVec[2][0];
606  ABraEquNegNodeOffset = jacLIDVec[2][1];
607  }
608 
609 }
610 
611 //-----------------------------------------------------------------------------
612 // Function : Instance::setupPointers
613 // Purpose :
614 // Special Notes :
615 // Scope : public
616 // Creator : Eric Keiter, SNL
617 // Creation Date : 11/30/08
618 //-----------------------------------------------------------------------------
620 {
621 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
622  N_LAS_Matrix & dFdx = *(extData.dFdxMatrixPtr);
623 
628 #endif
629 }
630 
631 //-----------------------------------------------------------------------------
632 // Function : Instance::updateIntermediateVars
633 // Purpose :
634 // Special Notes :
635 // Scope : public
636 // Creator : Eric Keiter, 9233, Computational Sciences
637 // Creation Date : 03/05/04
638 //-----------------------------------------------------------------------------
640 {
641  double * solVec = extData.nextSolVectorRawPtr;
642 
643  // Get the value for the source.
644  SourceData *dataPtr = dcData_ptr; // by default assume the DC value.
645  if ( (getSolverState().HBspecified || getSolverState().tranopFlag || getSolverState().transientFlag) && Data_ptr != 0 )
646  {
647  dataPtr = Data_ptr;
648  }
649 
650  if (dataPtr != 0)
651  {
652  source = dataPtr->returnSource();
653  }
654  else
655  {
656  source = 0.0;
657  }
658 
659  // get the value for v_pos, v_neg, i_bra
660  v_pos = solVec[li_Pos];
661  v_neg = solVec[li_Neg];
662  i_bra = solVec[li_Bra];
663 
664  srcCurrent = i_bra;
665  srcDrop = (v_pos-v_neg);
666  srcBC = source;
668 
669  if( getDeviceOptions().scale_src != 0.0 )
670  {
671  srcCurrent *= scale;
672 
673  // first newton step, generate new scaling
674  //if( nlsMgrPtr->getNonLinearIter() != nlstep )
675  if( getSolverState().newtonIter != nlstep )
676  {
677  //nlstep = nlsMgrPtr->getNonLinearIter();
679  double new_scale = fabs(i_bra) * scale;
680 
681  scale = Xycemax( new_scale, getDeviceOptions().scale_src );
682  }
683 
684  srcVoltage *= scale;
685  srcDrop *= scale;
686  srcBC *= scale;
687  }
688 
689  return true;
690 }
691 
692 //-----------------------------------------------------------------------------
693 // Function : Instance::updatePrimaryState
694 // Purpose :
695 // Special Notes :
696 // Scope : public
697 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
698 // Creation Date : 01/29/01
699 //-----------------------------------------------------------------------------
701 {
702  bool bsuccess = updateIntermediateVars ();
703  return bsuccess;
704 }
705 
706 //-----------------------------------------------------------------------------
707 // Function : Instance::loadDAEFVector
708 //
709 // Purpose : Loads the F-vector contributions for a single
710 // vsrc instance.
711 //
712 // Special Notes :
713 //
714 // Scope : public
715 // Creator : Eric Keiter, SNL
716 // Creation Date :
717 //-----------------------------------------------------------------------------
719 {
720  double * fVec = extData.daeFVectorRawPtr;
721 
722  fVec[li_Pos] += srcCurrent;
723  fVec[li_Neg] += -srcCurrent;
724  fVec[li_Bra] += srcDrop;
725  fVec[li_Bra] -= srcBC;
726 
727  return true;
728 }
729 
730 //-----------------------------------------------------------------------------
731 // Function : Instance::loadBVectorsforAC
732 //
733 // Purpose : Loads the B-vector contributions for a single
734 // vsrc instance.
735 //
736 // Special Notes :
737 //
738 // Scope : public
739 // Creator : Ting Mei, SNL
740 // Creation Date : 5/11
741 //-----------------------------------------------------------------------------
742 bool Instance::loadBVectorsforAC(double * bVecReal, double * bVecImag )
743 {
744  if (acData_ptr != 0)
745  {
746  bool flag = true;
747  acData_ptr->setRealFlag(flag);
748 
751  srcBC = source;
752 
753  if( getDeviceOptions().scale_src != 0.0 )
754  {
755  srcBC *= scale;
756  }
757 
758  bVecReal[li_Bra] += srcBC;
759 
760  flag = false;
761  acData_ptr->setRealFlag(flag);
762 
765  srcBC = source;
766 
767  if( getDeviceOptions().scale_src != 0.0 )
768  {
769  srcBC *= scale;
770  }
771 
772  bVecImag[li_Bra] += srcBC;
773  }
774 
775  return true;
776 }
777 
778 //-----------------------------------------------------------------------------
779 // Function : Instance::loadDAEdFdx ()
780 //
781 // Purpose : Loads the F-vector contributions for a single
782 // resistor instance.
783 //
784 // Special Notes :
785 //
786 // Scope : public
787 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
788 // Creation Date : 03/05/04
789 //-----------------------------------------------------------------------------
791 {
792  N_LAS_Matrix & dFdx = *(extData.dFdxMatrixPtr);
793 
794  dFdx[li_Pos][APosEquBraVarOffset] += 1.0;
795  dFdx[li_Neg][ANegEquBraVarOffset] -= 1.0;
796  dFdx[li_Bra][ABraEquPosNodeOffset] += 1.0;
797  dFdx[li_Bra][ABraEquNegNodeOffset] -= 1.0;
798 
799  return true;
800 }
801 
802 // end of new-DAE functions
803 
804 //-----------------------------------------------------------------------------
805 // Function : Instance::getMaxTimeStepSize
806 // Purpose :
807 // Special Notes :
808 // Scope : public
809 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
810 // Creation Date : 07/23/03
811 //-----------------------------------------------------------------------------
813 {
814  double maxStep = 1.0e+100;
815  if (Data_ptr != 0)
816  {
817  maxStep = Data_ptr->getMaxTimeStepSize ();
818  }
819  return maxStep;
820 }
821 
822 //-----------------------------------------------------------------------------
823 // Function : Instance::varTypes
824 // Purpose :
825 // Special Notes :
826 // Scope : public
827 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
828 // Creation Date : 02/17/04
829 //-----------------------------------------------------------------------------
830 void Instance::varTypes( std::vector<char> & varTypeVec )
831 {
832  varTypeVec.resize(1);
833  varTypeVec[0] = 'I';
834 }
835 
836 // Class Model
837 
838 //-----------------------------------------------------------------------------
839 // Function : Model::Model
840 // Purpose : copy constructor
841 // Special Notes :
842 // Scope : public
843 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
844 // Creation Date : 04/06/00
845 //-----------------------------------------------------------------------------
847  const Configuration & configuration,
848  const ModelBlock & MB,
849  const FactoryBlock & factory_block)
850  : DeviceModel(MB, configuration.getModelParameters(), factory_block),
851  DC_TRAN (0)
852 {
853 }
854 
855 //-----------------------------------------------------------------------------
856 // Function : Model::~Model
857 // Purpose : destructor
858 // Special Notes :
859 // Scope : public
860 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
861 // Creation Date : 04/06/00
862 //-----------------------------------------------------------------------------
864 {
865  std::vector<Instance*>::iterator iter;
866  std::vector<Instance*>::iterator first = instanceContainer.begin();
867  std::vector<Instance*>::iterator last = instanceContainer.end();
868 
869  for (iter=first; iter!=last; ++iter)
870  {
871  delete (*iter);
872  }
873 }
874 
875 // Additional Declarations
876 
877 //-----------------------------------------------------------------------------
878 // Function : Model::printOutInstances
879 // Purpose : debugging tool.
880 // Special Notes :
881 // Scope : public
882 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
883 // Creation Date : 4/03/00
884 //-----------------------------------------------------------------------------
885 std::ostream &Model::printOutInstances(std::ostream &os) const
886 {
887  std::vector<Instance*>::const_iterator iter;
888  std::vector<Instance*>::const_iterator first = instanceContainer.begin();
889  std::vector<Instance*>::const_iterator last = instanceContainer.end();
890 
891  int i;
892  os << std::endl;
893  os << " name model name Parameters" << std::endl;
894  for (i=0, iter=first; iter!=last; ++iter, ++i)
895  {
896  os << " " << i << ": " << (*iter)->getName() << " ";
897  os << getName();
898  os << std::endl;
899  }
900 
901  os << std::endl;
902 
903  return os;
904 }
905 
906 //-----------------------------------------------------------------------------
907 // Function : Model::forEachInstance
908 // Purpose :
909 // Special Notes :
910 // Scope : public
911 // Creator : David Baur
912 // Creation Date : 2/4/2014
913 //-----------------------------------------------------------------------------
914 /// Apply a device instance "op" to all instances associated with this
915 /// model
916 ///
917 /// @param[in] op Operator to apply to all instances.
918 ///
919 ///
920 void Model::forEachInstance(DeviceInstanceOp &op) const /* override */
921 {
922  for (std::vector<Instance *>::const_iterator it = instanceContainer.begin(); it != instanceContainer.end(); ++it)
923  op(*it);
924 }
925 
926 
927 
928 //-----------------------------------------------------------------------------
929 // Vsrc Master functions:
930 //-----------------------------------------------------------------------------
931 
932 
933 //-----------------------------------------------------------------------------
934 // Function : Master::updateState
935 // Purpose :
936 // Special Notes :
937 // Scope : public
938 // Creator : Eric Keiter, SNL
939 // Creation Date : 11/26/08
940 //-----------------------------------------------------------------------------
941 bool Master::updateState (double * solVec, double * staVec, double * stoVec)
942 {
943  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
944  {
945  Instance & vi = *(*it);
946  // Get the value for the source.
947  SourceData *dataPtr = vi.dcData_ptr; // by default assume the DC value.
948  if ( (getSolverState().HBspecified || getSolverState().tranopFlag || getSolverState().transientFlag) && vi.Data_ptr != 0 )
949  {
950  dataPtr = vi.Data_ptr;
951  }
952 
953  if (dataPtr != 0)
954  {
955  vi.source = dataPtr->returnSource();
956  }
957  else
958  {
959  vi.source = 0.0;
960  }
961 
962  // get the value for v_pos, v_neg, i_bra
963  vi.v_pos = solVec[vi.li_Pos];
964  vi.v_neg = solVec[vi.li_Neg];
965  vi.i_bra = solVec[vi.li_Bra];
966 
967  vi.srcCurrent = vi.i_bra;
968  vi.srcDrop = (vi.v_pos-vi.v_neg);
969  vi.srcBC = vi.source;
970  vi.srcVoltage = vi.srcDrop-vi.srcBC;
971 
972  if( getDeviceOptions().scale_src != 0.0 )
973  {
974  vi.srcCurrent *= vi.scale;
975 
976  // first newton step, generate new scaling
977  if( getSolverState().newtonIter != vi.nlstep )
978  {
980  double new_scale = fabs(vi.i_bra) * vi.scale;
981 
982  vi.scale = Xycemax( new_scale, getDeviceOptions().scale_src );
983  }
984 
985  vi.srcVoltage *= vi.scale;
986  vi.srcDrop *= vi.scale;
987  vi.srcBC *= vi.scale;
988  }
989  }
990 
991  return true;
992 }
993 
994 //-----------------------------------------------------------------------------
995 // Function : Master::loadDAEVectors
996 // Purpose :
997 // Special Notes :
998 // Scope : public
999 // Creator : Eric Keiter, SNL
1000 // Creation Date : 11/26/08
1001 //-----------------------------------------------------------------------------
1002 bool Master::loadDAEVectors (double * solVec, double * fVec, double *qVec, double * storeLeadF, double * storeLeadQ)
1003 {
1004  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
1005  {
1006  Instance & vi = *(*it);
1007  fVec[vi.li_Pos] += vi.srcCurrent;
1008  fVec[vi.li_Neg] += -vi.srcCurrent;
1009  fVec[vi.li_Bra] += vi.srcDrop;
1010  fVec[vi.li_Bra] -= vi.srcBC;
1011  }
1012  return true;
1013 }
1014 
1015 //-----------------------------------------------------------------------------
1016 // Function : Master::loadDAEMatrices
1017 // Purpose :
1018 // Special Notes :
1019 // Scope : public
1020 // Creator : Eric Keiter, SNL
1021 // Creation Date : 11/26/08
1022 //-----------------------------------------------------------------------------
1023 bool Master::loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx)
1024 {
1025  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
1026  {
1027  Instance & vi = *(*it);
1028 
1029 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
1030  *(vi.fPosEquBraVarPtr) += 1.0;
1031  *(vi.fNegEquBraVarPtr) -= 1.0;
1032  *(vi.fBraEquPosNodePtr) += 1.0;
1033  *(vi.fBraEquNegNodePtr) -= 1.0;
1034 #else
1035  dFdx[vi.li_Pos][vi.APosEquBraVarOffset] += 1.0;
1036  dFdx[vi.li_Neg][vi.ANegEquBraVarOffset] -= 1.0;
1037  dFdx[vi.li_Bra][vi.ABraEquPosNodeOffset] += 1.0;
1038  dFdx[vi.li_Bra][vi.ABraEquNegNodeOffset] -= 1.0;
1039 #endif
1040  }
1041  return true;
1042 }
1043 
1044 Device *
1045 Traits::factory(const Configuration &configuration, const FactoryBlock &factory_block)
1046 {
1047 
1048  return new Master(configuration, factory_block, factory_block.solverState_, factory_block.deviceOptions_);
1049 }
1050 
1052 {
1054  .registerDevice("v", 1);
1055 }
1056 
1057 } // namespace Vsrc
1058 } // namespace Device
1059 } // namespace Xyce