Xyce  6.1
N_DEV_ADC.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_ADC.C,v $
27 //
28 // Purpose : This file implements the ADC digital to analog conversion
29 // device used in the integration of Xyce withe SAVANT VHDL
30 // simulator.
31 //
32 // Special Notes : The ADC looks to the analog simulation like a resistor.
33 //
34 // Creator : Lon Waters
35 //
36 // Creation Date : 07/26/2002
37 //
38 // Revision Information:
39 // ---------------------
40 //
41 // Revision Number: $Revsion$
42 //
43 // Revsion Date : $Date: 2015/04/22 15:00:53 $
44 //
45 // Current Owner : $Author: dgbaur $
46 //----------------------------------------------------------------------------
47 
48 #include <Xyce_config.h>
49 
50 
51 // ---------- Standard Includes ----------
52 #include <algorithm>
53 #include <N_UTL_Math.h>
54 
55 // ---------- Xyce Includes ----------
56 #include <N_DEV_ADC.h>
57 #include <N_DEV_DeviceOptions.h>
58 #include <N_DEV_DeviceState.h>
59 #include <N_DEV_ExternData.h>
60 #include <N_DEV_MatrixLoadData.h>
61 #include <N_DEV_SolverState.h>
62 #include <N_DEV_Message.h>
63 #include <N_LAS_Vector.h>
64 #include <N_LAS_Matrix.h>
65 #include <N_UTL_FeatureTest.h>
66 
67 namespace Xyce {
68 namespace Device {
69 
70 
71 namespace ADC {
72 
73 
75 {
76  p.addPar ("R", 1.e+12, &ADC::Instance::R)
77  .setUnit(U_OHM)
78  .setDescription("internal Resistance");
79 }
80 
82 {
83  p.addPar ("LOWERVOLTAGELIMIT", 0.0, &ADC::Model::lowerVoltageLimit_)
84  .setUnit(U_VOLT)
85  .setDescription("Lower limit of ADC voltage range");
86 
87  p.addPar ("UPPERVOLTAGELIMIT", 5.0, &ADC::Model::upperVoltageLimit_)
88  .setUnit(U_VOLT)
89  .setDescription("Upper limit of ADC voltage range");
90 
91  p.addPar ("SETTLINGTIME", 1.0e-8, &ADC::Model::settlingTime_)
92  .setUnit(U_SECOND)
93  .setDescription("Settling time");
94 }
95 
96 
97 
98 std::vector< std::vector<int> > Instance::jacStamp;
99 
100 //----------------------------------------------------------------------------
101 // Function : Instance::processParams
102 // Purpose :
103 // Special Notes :
104 // Scope : public
105 // Creator : Lon Waters
106 // Creation Date : 07/29/2002
107 //----------------------------------------------------------------------------
109 {
110  return true;
111 }
112 
113 //----------------------------------------------------------------------------
114 // Function : Instance::Instance
115 // Purpose : constructor
116 // Special Notes :
117 // Scope : public
118 // Creator : Lon Waters
119 // Creation Date : 07/29/2002
120 //----------------------------------------------------------------------------
122  const Configuration & configuration,
123  const InstanceBlock & instance_block,
124  Model & model,
125  const FactoryBlock & factory_block)
126  : DeviceInstance(instance_block, configuration.getInstanceParameters(), factory_block),
127  R(1.0e12),
128  G(0.0),
129  v_pos(0.0),
130  v_neg(0.0),
131  i0(0.0),
132  outputBitVectorWidth_(1),
133  nQuantLevels_(0),
134  lastOutputLevel_(0),
135  model_(model),
136  li_Pos(-1),
137  li_Neg(-1),
138  APosEquPosNodeOffset(-1),
139  APosEquNegNodeOffset(-1),
140  ANegEquPosNodeOffset(-1),
141  ANegEquNegNodeOffset(-1)
142 {
143  numIntVars = 0;
144  numExtVars = 2;
145  numStateVars = 0;
146 
147  if( jacStamp.empty() )
148  {
149  jacStamp.resize(2);
150  jacStamp[0].resize(2);
151  jacStamp[1].resize(2);
152  jacStamp[0][0] = 0;
153  jacStamp[0][1] = 1;
154  jacStamp[1][0] = 0;
155  jacStamp[1][1] = 1;
156  }
157 
158 
159  // Set params to constant default values:
160  setDefaultParams ();
161 
162  // Set params according to instance line and constant defaults from metadata:
163  setParams (instance_block.params);
164 
165  // Set any non-constant parameter defaults:
166 
167  // Calculate any parameters specified as expressions:
168 
170 
171  // calculate dependent (ie computed) params and check for errors:
172 
173  if (R != 0.0) G = 1.0/R;
174  else G = 0.0;
175 
176  processParams ();
177 }
178 
179 //----------------------------------------------------------------------------
180 // Function : Instance::~Instance
181 // Purpose :
182 // Special Notes :
183 // Scope : public
184 // Creator : Lon Waters
185 // Creation Date : 07/29/2002
186 //----------------------------------------------------------------------------
188 {
189 }
190 
191 //----------------------------------------------------------------------------
192 // Function : Instance::registerLIDs
193 // Purpose :
194 // Special Notes :
195 // Scope : public
196 // Creator : Lon Waters
197 // Creation Date : 07/29/2002
198 //----------------------------------------------------------------------------
199 void Instance::registerLIDs( const std::vector<int> & intLIDVecRef,
200  const std::vector<int> & extLIDVecRef)
201 {
202  AssertLIDs(intLIDVecRef.size() == numIntVars);
203  AssertLIDs(extLIDVecRef.size() == numExtVars);
204 
205  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) )
206  {
207  Xyce::dout() << std::endl << section_divider << std::endl;
208  Xyce::dout() << " ADCInstance::registerLIDs" << std::endl;
209  Xyce::dout() << " name = " << getName() << std::endl;
210  }
211 
212  // copy over the global ID lists.
213  intLIDVec = intLIDVecRef;
214  extLIDVec = extLIDVecRef;
215 
216  // Now use these lists to obtain the indices into the
217  // linear algebra entities. This assumes an order.
218  // For the matrix indices, first do the rows.
219 
220  li_Pos = extLIDVec[0];
221 
222  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) )
223  Xyce::dout() << " li_Pos = " << li_Pos << std::endl;
224 
225  li_Neg = extLIDVec[1];
226 
227  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) )
228  Xyce::dout() << " li_Neg = " << li_Neg << std::endl;
229 
230  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) )
231  Xyce::dout() << section_divider << std::endl;
232 }
233 
234 //----------------------------------------------------------------------------
235 // Function : Instance::registerStateLIDs
236 // Purpose :
237 // Special Notes :
238 // Scope : public
239 // Creator : Lon Waters
240 // Creation Date : 07/29/2002
241 //----------------------------------------------------------------------------
242 void Instance::registerStateLIDs( const std::vector<int> & staLIDVecRef)
243 {
244  AssertLIDs(staLIDVecRef.size() == numStateVars);
245 }
246 
247 //----------------------------------------------------------------------------
248 // Function : jacobianStamp
249 // Purpose :
250 // Special Notes :
251 // Scope : public
252 // Creator : Lon Waters
253 // Creation Date : 11/12/2002
254 //----------------------------------------------------------------------------
255 const std::vector< std::vector<int> > & Instance::jacobianStamp() const
256 {
257  return jacStamp;
258 }
259 
260 //----------------------------------------------------------------------------
261 // Function : registerJacLIDs
262 // Purpose :
263 // Special Notes :
264 // Scope : public
265 // Creator : Lon Waters
266 // Creation Date : 11/12/2002
267 //----------------------------------------------------------------------------
268 void Instance::registerJacLIDs(const std::vector< std::vector<int> >& jacLIDVec)
269 {
270  APosEquPosNodeOffset = jacLIDVec[0][0];
271  APosEquNegNodeOffset = jacLIDVec[0][1];
272  ANegEquPosNodeOffset = jacLIDVec[1][0];
273  ANegEquNegNodeOffset = jacLIDVec[1][1];
274 }
275 
276 //-----------------------------------------------------------------------------
277 // Function : Instance::loadNodeSymbols
278 // Purpose :
279 // Special Notes :
280 // Scope : public
281 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
282 // Creation Date : 05/13/05
283 //-----------------------------------------------------------------------------
284 void Instance::loadNodeSymbols(Util::SymbolTable &symbol_table) const
285 {
286 }
287 
288 //----------------------------------------------------------------------------
289 // Function : Instance::updatePrimaryState
290 // Purpose :
291 // Special Notes :
292 // Scope : public
293 // Creator : Richard Schiek, 1437, Electrical and Microsystem Sim.
294 // Creation Date : 02/19/08
295 //----------------------------------------------------------------------------
297 {
298  bool bsuccess = true;
299  double * solVector = extData.nextSolVectorRawPtr;
300 
301  v_pos = solVector[li_Pos];
302  v_neg = solVector[li_Neg];
303  i0 = (v_pos-v_neg)*G;
304 
305  return bsuccess;
306 }
307 
308 //----------------------------------------------------------------------------
309 // Function : Instance::updatePrimaryState
310 // Purpose :
311 // Special Notes :
312 // Scope : public
313 // Creator : Lon Waters
314 // Creation Date : 07/29/2002
315 //----------------------------------------------------------------------------
317 {
318  return updateIntermediateVars ();
319 }
320 
321 //----------------------------------------------------------------------------
322 // Function : Instance::updateSecondaryState
323 // Purpose :
324 // Special Notes :
325 // Scope : public
326 // Creator : Lon Waters
327 // Creation Date : 07/29/2002
328 //----------------------------------------------------------------------------
330 {
331  // There is no secondary state
332  return true;
333 }
334 
335 //----------------------------------------------------------------------------
336 // Function : Instance::getTVVec
337 // Purpose :
338 // Special Notes :
339 // Scope :
340 // Creator : Lon Waters
341 // Creation Date : 08/28/2003
342 //----------------------------------------------------------------------------
343 void Instance::getTVVEC(std::vector< std::pair<double, double> > & TVVEC_Out)
344 {
345  TVVEC_Out.clear();
346 
347  TVVEC_Out.insert(TVVEC_Out.end(), TVVEC.begin(), TVVEC.end());
348 
349  // Now that the digital simulator knows about these, let's forget them
350  // and not worry about maintaining the list anymore
351  TVVEC.clear();
352 }
353 
354 
355 //----------------------------------------------------------------------------
356 // Function : Instance::trimTVVEC
357 // Purpose : clear out old time-voltage pairs
358 // Special Notes : ASSUMES the vector of t-v pairs is sorted by time!
359 // Scope : public
360 // Creator : Tom Russo, SNL, Component Information and Models
361 // Creation Date : 05/10/2004
362 //----------------------------------------------------------------------------
363 void Instance::trimTVVEC(double earliestTime)
364 {
365  std::vector< std::pair<double,double> >::iterator itVec;
366 
367  // get reference pointing to first element that exceeds earliestTime
368  itVec = lower_bound(TVVEC.begin(),TVVEC.end(),std::pair<double,double>(earliestTime,0.0));
369  // delete everything prior to that.
370  TVVEC.erase(TVVEC.begin(),itVec);
371 }
372 
373 //-----------------------------------------------------------------------------
374 // Function : Instance::loadDAEFVector
375 //
376 // Purpose : Loads the F-vector contributions for this device which
377 // effectively is a single instance.
378 //
379 // Special Notes :
380 //
381 // Scope : public
382 // Creator : Richard Schiek, 1437, Electrical and Microsystem Sim.
383 // Creation Date : 02/19/08
384 //-----------------------------------------------------------------------------
386 {
387  bool bsuccess = true;
388 
389  double * daeFVec = extData.daeFVectorRawPtr;
390 
391  // Load DAE F-vector
392 
393  daeFVec[li_Pos] += i0;
394 
395  daeFVec[li_Neg] += -i0;
396 
397  return bsuccess;
398 }
399 
400 //-----------------------------------------------------------------------------
401 // Function : Instance::loadDAEdFdx ()
402 //
403 // Purpose : Loads the F-vector contributions for this device which
404 // effectively is a single instance.
405 //
406 // Special Notes :
407 //
408 // Scope : public
409 // Creator : Richard Schiek, 1437, Electrical and Microsystem Sim.
410 // Creation Date : 02/19/08
411 //-----------------------------------------------------------------------------
413 {
414  bool bsuccess = true;
415 
416  Linear::Matrix * dFdxMatPtr = extData.dFdxMatrixPtr;
417 
418  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) && getSolverState().debugTimeFlag)
419  {
420  Xyce::dout() << subsection_divider <<std::endl;
421  Xyce::dout() << " name = " << getName() << std::endl;
422  Xyce::dout() << " G = " << G << std::endl;
423  }
424 
425  (*dFdxMatPtr)[li_Pos][APosEquPosNodeOffset] += G;
426 
427  (*dFdxMatPtr)[li_Pos][APosEquNegNodeOffset] -= G;
428 
429  (*dFdxMatPtr)[li_Neg][ANegEquPosNodeOffset] -= G;
430 
431  (*dFdxMatPtr)[li_Neg][ANegEquNegNodeOffset] += G;
432 
433  return bsuccess;
434 }
435 
436 //-----------------------------------------------------------------------------
437 // Function : Instance::getBreakPoints
438 // Purpose :
439 // Special Notes :
440 // Scope : public
441 // Creator : Tom Russo, SNL, Component Information and Models
442 // Creation Date : 05/06/04
443 //-----------------------------------------------------------------------------
444 
445 bool Instance::getInstanceBreakPoints ( std::vector<Util::BreakPoint> & breakPointTimes)
446 {
447  bool bsuccess = true;
448 
449  // getBreakPoints is called after a timesteps solution is converged and
450  // the step is finished. So we can count on our voltage being the real one
451  // that is valid for this time.
452 
453  // In this routine we need to check our current voltage value and see if it
454  // has changed enough since our last time step to change a bit in the digital
455  // output. If so, we need to set a time/voltage pair of the current value
456  // and (the current time + this device's conversion time), then set a
457  // breakpoint of type PAUSE_BREAKPOINT for the that time
458 
459  double vPos(0.0);
460  double vNeg(0.0);
461  double deltaV(0.0), vFrac(0.0);
462  double currentTime = getSolverState().currTime_;
463  int newState;
464 
465  // Get the pointer to the vector of accepted solution values
466  double * solVector = extData.nextSolVectorRawPtr;
467 
468  vPos = solVector[li_Pos];
469  vNeg = solVector[li_Neg];
470 
471  deltaV = vPos-vNeg;
472 
473  // This "upper voltage limit" and "lower voltage limit" crap is not right,
474  // and needs to be replaced with a "Vref+" node against which
475  // Vin is compared, with a common negative reference (e.g. ground)
476  // For now, let's always just document this failing, and tell the users
477  // to wire vNeg to ground, and use 0.0 as the
478  // lower limit. Worry about doing it right later.
479  vFrac = deltaV/(model_.upperVoltageLimit_
481 
482 #if 1
483  // I believe this is how it SHOULD be done
484  if (vFrac < (1.0)/(nQuantLevels_) )
485  {
486  newState = 0;
487  }
488  else if (vFrac >= (nQuantLevels_-1.0)/(nQuantLevels_))
489  {
490  newState = nQuantLevels_ -1;
491  }
492  else
493  {
494  newState = int(vFrac*nQuantLevels_);
495  }
496 #else
497  // but this is how simbus is doing it:
498  newState = int(vFrac*(nQuantLevels_-1));
499 #endif
500 
501  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) && getSolverState().debugTimeFlag)
502  {
503  Xyce::dout() << "In Instance::getInstanceBreakPoints. deltaV = " << deltaV
504  << " and output state is " << newState
505  << " vFrac = " << vFrac << " nQuantLevels = " << nQuantLevels_ << std::endl;
506  }
507 
508  if (newState != lastOutputLevel_)
509  {
510  // get time rounded to nearest femptosecond
511  long long int timeInFS =static_cast<long long int>(
512  (currentTime+model_.settlingTime_+6e-16)/1e-15);
513 
514  // we need to pause
515 #ifdef Xyce_OLD_PRE_ROLLBACK
516  breakPointTimes.push_back( Util::BreakPoint(timeInFS*1e-15,PAUSE_BREAKPOINT));
517 #else
518 
519  // See bug # 1720 on charleston bugzilla. This breakpoint pushback is being
520  // commented out to fix this bug.
521  //
522  // However, this should not be a long-term fix!
523 
524 #endif
525 
526  // since time is always advancing, we can simply push_back the pair,
527  // and always be sure
528  TVVEC.push_back(std::pair<double,double>(timeInFS*1e-15,deltaV));
529  lastOutputLevel_ = newState;
530 
531  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) && getSolverState().debugTimeFlag)
532  {
533  Xyce::dout() << "ADC ----------------------------------------" << std::endl;
534  Xyce::dout() << "ADC Debug output. name = " << getName() << std::endl;
535  Xyce::dout() << "ADC setting pause breakpoint for " << currentTime << std::endl;
536  double approxTime = timeInFS*1e-15;
537  Xyce::dout() << "ADC Approximated time, to nearest femptosecond: " << approxTime << std::endl;
538  Xyce::dout() << "ADC Time value pairs: " << std::endl;
539 
540  std::vector< std::pair<double, double> >::iterator beg = TVVEC.begin();
541  std::vector< std::pair<double, double> >::iterator end = TVVEC.end();
542  std::vector< std::pair<double, double> >::iterator itTV = beg;
543 
544  for (; itTV!=end; ++itTV)
545  {
546  std::pair<double, double> & tvPair = *itTV;
547  Xyce::dout() << "ADC time: " << tvPair.first << " value: " << tvPair.second << std::endl;
548  }
549 
550  Xyce::dout() << "ADC ----------------------------------------" << std::endl;
551  }
552  }
553 
554  return bsuccess;
555 }
556 
557 //-----------------------------------------------------------------------------
558 // Function : Instance::acceptStep
559 // Purpose :
560 // Special Notes :
561 // Scope : public
562 // Creator : Eric Keiter, SNL
563 // Creation Date : 12/05/08
564 //-----------------------------------------------------------------------------
566 {
567  double vPos(0.0), vNeg(0.0), deltaV(0.0), vFrac(0.0);
568  double currentTime = getSolverState().currTime_;
569 
570  if (getSolverState().dcopFlag)
571  {
572  double * solVector = extData.nextSolVectorRawPtr;
573 
574  vPos = solVector[li_Pos];
575  vNeg = solVector[li_Neg];
576  deltaV = vPos-vNeg;
577 
578  TVVEC.push_back(std::pair<double,double>(0.0,deltaV));
579  }
580 
581 }
582 
583 //----------------------------------------------------------------------------
584 // Function : Model::processParams
585 // Purpose :
586 // Special Notes :
587 // Scope : public
588 // Creator : Lon Waters
589 // Creation Date : 07/29/2002
590 //----------------------------------------------------------------------------
592 {
593  return true;
594 }
595 
596 //----------------------------------------------------------------------------
597 // Function : Model::processInstanceParams
598 // Purpose :
599 // Special Notes :
600 // Scope : public
601 // Creator : Dave Shirely, PSSI
602 // Creation Date : 03/23/06
603 //----------------------------------------------------------------------------
605 {
606  std::vector<Instance*>::iterator iter;
607  std::vector<Instance*>::iterator first = instanceContainer.begin();
608  std::vector<Instance*>::iterator last = instanceContainer.end();
609 
610  for (iter=first; iter!=last; ++iter)
611  {
612  (*iter)->processParams();
613  }
614 
615  return true;
616 }
617 
618 //----------------------------------------------------------------------------
619 // Function : Instance::getInstanceParamsMap
620 // Purpose : Return a map of name,parameter for this instance
621 // Special Notes : used by API for mixed signal
622 // in zero order version, these parameters happen to be
623 // model parameters, but that is not necessarily where they'll
624 // stay (the voltage limits, for example, should actually be
625 // taken from the nodal voltages of the reference nodes of the
626 // device instance)
627 // Scope : public
628 // Creator : Tom Russo, SNL, Component Information and Models
629 // Creation Date : 05/07/2004
630 //----------------------------------------------------------------------------
631 bool Instance::getInstanceParamsMap(std::map<std::string,double>& paramsMap)
632 {
633  paramsMap.clear();
634 
635  paramsMap["lowerVoltageLimit"] = model_.lowerVoltageLimit_;
636  paramsMap["upperVoltageLimit"] = model_.upperVoltageLimit_;
637  paramsMap["settlingTime"] = model_.settlingTime_;
638 
639  return true;
640 }
641 
642 //----------------------------------------------------------------------------
643 // Function : Instance::setBitVectorWidth
644 // Purpose : set the number of bits in the output of this ADC
645 // Special Notes :
646 // Scope : public
647 // Creator : Tom Russo
648 // Creation Date : 05/07/2004
649 //----------------------------------------------------------------------------
651 {
652  outputBitVectorWidth_ = width;
653  nQuantLevels_ = 1;
654  for (int i=0; i<width;++i)
655  nQuantLevels_ *= 2;
656 
657  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) && getSolverState().debugTimeFlag)
658  {
659  Xyce::dout() << "Instance::setBitVectorWidth name = "
660  << getName() << " width = " << width
661  << " nQuantLevels_ = " << nQuantLevels_ << std::endl;
662  }
663 
664  return true;
665 }
666 //----------------------------------------------------------------------------
667 // Function : Model::Model
668 // Purpose : constructor
669 // Special Notes :
670 // Scope : public
671 // Creator : Lon Waters
672 // Creation Date : 07/29/2002
673 //----------------------------------------------------------------------------
675  const Configuration & configuration,
676  const ModelBlock& model_block,
677  const FactoryBlock & factory_block)
678  : DeviceModel(model_block, configuration.getModelParameters(), factory_block),
679  lowerVoltageLimit_(0.0),
680  upperVoltageLimit_(5.0),
681  settlingTime_(1e-8)
682 {
683  // Set params to constant default values:
684  setDefaultParams ();
685 
686  // Set params according to .model line and constant defaults from metadata:
687  setModParams (model_block.params);
688 
689  // Set any non-constant parameter defaults:
690 
691  // Calculate any parameters specified as expressions:
693 
694  // calculate dependent (ie computed) params and check for errors:
695  processParams ();
696 }
697 
698 //----------------------------------------------------------------------------
699 // Function : Model::Model
700 // Purpose : destructor
701 // Special Notes :
702 // Scope : public
703 // Creator : Lon Waters
704 // Creation Date : 07/29/2002
705 //----------------------------------------------------------------------------
707 {
708  std::vector<Instance*>::iterator iter;
709  std::vector<Instance*>::iterator first = instanceContainer.begin();
710  std::vector<Instance*>::iterator last = instanceContainer.end();
711 
712  for (iter=first; iter!=last; ++iter)
713  {
714  delete (*iter);
715  }
716 }
717 
718 //----------------------------------------------------------------------------
719 // Function : printOutInstances
720 // Purpose : debugging tool
721 // Special Notes :
722 // Scope : public
723 // Creator : Lon Waters
724 // Creation Date : 07/29/2002
725 //----------------------------------------------------------------------------
726 std::ostream &Model::printOutInstances(std::ostream &os) const
727 {
728  std::vector<Instance*>::const_iterator iter;
729  std::vector<Instance*>::const_iterator first = instanceContainer.begin();
730  std::vector<Instance*>::const_iterator last = instanceContainer.end();
731 
732  int i;
733  os << std::endl;
734  os << " name\t\tmodelName\tParameters" << std::endl;
735 
736  for (i = 0, iter = first; iter != last; ++iter, ++i)
737  {
738  os << " " << i << ": " << (*iter)->getName() << "\t";
739  os << getName();
740  os << std::endl;
741  }
742 
743  os << std::endl;
744 
745  return os;
746 }
747 
748 void Model::forEachInstance(DeviceInstanceOp &op) const /* override */ {
749  for (std::vector<Instance *>::const_iterator it = instanceContainer.begin(); it != instanceContainer.end(); ++it)
750  op(*it);
751 }
752 
753 
754 // ADC Master functions:
755 
756 //-----------------------------------------------------------------------------
757 // Function : Master::updateState
758 // Purpose :
759 // Special Notes :
760 // Scope : public
761 // Creator : Richard Schiek, Electrical and Microsystems Modeling
762 // Creation Date : 02/25/2009
763 //-----------------------------------------------------------------------------
764 bool Master::updateState (double * solVec, double * staVec, double * stoVec)
765 {
766  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
767  {
768  Instance & di = *(*it);
769 
770  di.v_pos = solVec[di.li_Pos];
771  di.v_neg = solVec[di.li_Neg];
772  di.i0 = (di.v_pos-di.v_neg)*di.G;
773  }
774 
775  return true;
776 }
777 
778 //-----------------------------------------------------------------------------
779 // Function : Master::updateSecondaryState
780 // Purpose :
781 // Special Notes :
782 // Scope : public
783 // Creator : Richard Schiek, Electrical and Microsystems Modeling
784 // Creation Date : 02/25/2009
785 //-----------------------------------------------------------------------------
786 bool Master::updateSecondaryState ( double * staDerivVec, double * stoVec )
787 {
788  return true;
789 }
790 
791 //-----------------------------------------------------------------------------
792 // Function : Master::loadDAEVectors
793 // Purpose :
794 // Special Notes :
795 // Scope : public
796 // Creator : Richard Schiek, Electrical and Microsystems Modeling
797 // Creation Date : 02/25/2009
798 //-----------------------------------------------------------------------------
799 bool Master::loadDAEVectors (double * solVec, double * fVec, double *qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV)
800 {
801  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
802  {
803  Instance & di = *(*it);
804 
805  fVec[di.li_Pos] += di.i0;
806 
807  fVec[di.li_Neg] += -di.i0;
808  }
809 
810  return true;
811 }
812 
813 //-----------------------------------------------------------------------------
814 // Function : Master::loadDAEMatrices
815 // Purpose :
816 // Special Notes :
817 // Scope : public
818 // Creator : Richard Schiek, Electrical and Microsystems Modeling
819 // Creation Date : 02/25/2009
820 //-----------------------------------------------------------------------------
821 bool Master::loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx)
822 {
823  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
824  {
825  Instance & di = *(*it);
826 
827  dFdx[di.li_Pos][di.APosEquPosNodeOffset] += di.G;
828 
829  dFdx[di.li_Pos][di.APosEquNegNodeOffset] -= di.G;
830 
831  dFdx[di.li_Neg][di.ANegEquPosNodeOffset] -= di.G;
832 
833  dFdx[di.li_Neg][di.ANegEquNegNodeOffset] += di.G;
834  }
835  return true;
836 }
837 
838 //-----------------------------------------------------------------------------
839 // Function : ::getBreakPoints
840 // Purpose : getBreakPoints for all instances
841 // Special Notes :
842 // Scope : public
843 // Creator : Richard Schiek, Electrical and Microsystems Modeling
844 // Creation Date : 02/25/2009
845 //-----------------------------------------------------------------------------
846 bool Master::getBreakPoints ( std::vector<Util::BreakPoint> & breakPointTimes )
847 {
848  bool bsuccess = true;
849  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
850  {
851  Instance & di = *(*it);
852  bool tmpBool = di.getInstanceBreakPoints(breakPointTimes);
853  bsuccess = bsuccess && tmpBool;
854  }
855 
856  return bsuccess;
857 
858 }
859 
860 Device *Traits::factory(const Configuration &configuration, const FactoryBlock &factory_block)
861 {
862 
863  return new Master(configuration, factory_block, factory_block.solverState_, factory_block.deviceOptions_);
864 }
865 
867 {
869  .registerDevice("adc", 1)
870  .registerModelType("adc", 1);
871 }
872 
873 } // namespace ADC
874 } // namespace Device
875 } // namespace Xyce
const InstanceName & getName() const
Instance(const Configuration &configuration, const InstanceBlock &instance_block, Model &model, const FactoryBlock &factory_block)
Definition: N_DEV_ADC.C:121
static std::vector< std::vector< int > > jacStamp
Definition: N_DEV_ADC.h:158
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_ADC.C:268
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
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_ADC.C:81
virtual void forEachInstance(DeviceInstanceOp &op) const
Definition: N_DEV_ADC.C:748
void G(const ScalarT &V1, const ScalarT &V2, const ScalarT &Ap, const ScalarT &An, ScalarT &Vp, ScalarT &Vn, ScalarT &fval)
Pure virtual class to augment a linear system.
void getTVVEC(std::vector< std::pair< double, double > > &TVVVEC_Out)
Definition: N_DEV_ADC.C:343
void registerDevice()
Definition: N_DEV_ADC.C:866
bool processInstanceParams()
processInstanceParams
Definition: N_DEV_ADC.C:604
InstanceVector::const_iterator getInstanceEnd() const
Returns an iterator to the ending of the vector of all instances created for this device...
#define AssertLIDs(cmp)
bool getInstanceBreakPoints(std::vector< Util::BreakPoint > &breakPointTimes)
Definition: N_DEV_ADC.C:445
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_ADC.C:74
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_ADC.C:860
bool getInstanceParamsMap(std::map< std::string, double > &paramsMap)
Definition: N_DEV_ADC.C:631
InstanceVector::const_iterator getInstanceBegin() const
Returns an iterator to the beginning of the vector of all instances created for this device...
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_ADC.C:726
std::vector< Param > params
Parameters from the line.
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_ADC.C:821
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...
std::vector< std::pair< double, double > > TVVEC
Definition: N_DEV_ADC.h:169
std::vector< Instance * > instanceContainer
Definition: N_DEV_ADC.h:235
static Config< T > & addConfiguration()
Adds the device to the Xyce device configuration.
bool getBreakPoints(std::vector< Util::BreakPoint > &breakPointTimes)
Definition: N_DEV_ADC.C:846
Linear::Matrix * dFdxMatrixPtr
bool processParams()
processParams
Definition: N_DEV_ADC.C:591
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_ADC.C:255
const SolverState & solverState_
virtual bool updateSecondaryState(double *staDeriv, double *stoVec)
Updates the devices secondary state information.
Definition: N_DEV_ADC.C:786
Class Configuration contains device configuration data.
bool setBitVectorWidth(int width)
Definition: N_DEV_ADC.C:650
void trimTVVEC(double earliestTime)
Definition: N_DEV_ADC.C:363
const SolverState & getSolverState() const
virtual void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_ADC.C:284
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_ADC.C:764
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_ADC.C:242
ModelBlock represents a .MODEL line from the netlist.
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_ADC.C:199
InstanceBlock represent a device instance line from the netlist.
double currTime_
DeviceEntity for expression time, breakpoints DeviceMgr for dependent parameters, breakpoints...
std::vector< Param > params
void setModParams(const std::vector< Param > &params)
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_ADC.C:799