Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_SourceData.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_SourceData.C,v $
27 //
28 // Purpose : This file contains the member functions of the
29 // N_DEV_SourceData class, which is used by the Vsrc
30 // and ISRC devices.
31 //
32 // Special Notes :
33 //
34 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
35 //
36 // Creation Date : 02/28/00
37 //
38 // Revision Information:
39 // ---------------------
40 //
41 // Revision Number: $Revision: 1.124 $
42 //
43 // Revision Date : $Date: 2014/02/24 23:49:15 $
44 //
45 // Current Owner : $Author: tvrusso $
46 //-------------------------------------------------------------------------
47 
48 #include <Xyce_config.h>
49 
50 
51 // ---------- Standard Includes ----------
52 
53 #ifdef HAVE_CMATH
54 #include <cmath>
55 #else
56 #include <math.h>
57 #endif
58 
59 // ---------- Xyce Includes ----------
60 #include <N_DEV_SourceData.h>
61 #include <N_DEV_DeviceInstance.h>
62 #include <N_DEV_SolverState.h>
63 #include <N_DEV_DeviceOptions.h>
64 
65 #include <N_ERH_ErrorMgr.h>
66 
67 #include <N_UTL_BreakPoint.h>
68 
69 namespace Xyce {
70 namespace Device {
71 
72 //-----------------------------------------------------------------------------
73 // Function : SourceData::SourceData
74 // Purpose : constructor
75 // Special Notes :
76 // Scope : public
77 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
78 // Creation Date : 4/24/00
79 //-----------------------------------------------------------------------------
81  const DeviceOptions & do1)
82  : SourceValue(0.0),
83  initializeFlag_(false),
84  resetFlag_(true),
85  solState_(ss1),
86  time(0.0),
87  devOptions_(do1),
88  typeName_(""),
89  sourceName_(""),
90  defaultParamName_("") ,
91  fastTimeScaleFlag_(false),
92  realFlag_(true)
93 {
94 
95 }
96 
97 //-----------------------------------------------------------------------------
98 // Function : SourceData::SourceData
99 // Purpose : copy constructor
100 // Special Notes :
101 // Scope : public
102 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
103 // Creation Date : 4/24/00
104 //-----------------------------------------------------------------------------
106  : SourceValue (right.SourceValue),
107  initializeFlag_(right.initializeFlag_),
108  resetFlag_(right.resetFlag_),
109  solState_(right.solState_),
110  time(right.time),
111  devOptions_(right.devOptions_),
112  typeName_(right.typeName_),
113  sourceName_(right.sourceName_),
114  defaultParamName_(right.defaultParamName_)
115 {
116 
117 }
118 
119 //-----------------------------------------------------------------------------
120 // Function : SourceData::~SourceData
121 // Purpose : destructor
122 // Special Notes :
123 // Scope : public
124 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
125 // Creation Date : 4/24/00
126 //-----------------------------------------------------------------------------
128 {
129 
130 }
131 
132 //-----------------------------------------------------------------------------
133 // Function : SourceData::initializeSource
134 // Purpose : Base class initialization function.
135 // Special Notes :
136 // Scope : public
137 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
138 // Creation Date : 9/04/01
139 //-----------------------------------------------------------------------------
141 {
142  initializeFlag_ = true;
143  return true;
144 }
145 
146 //-----------------------------------------------------------------------------
147 // Function : SourceData::updateSource
148 // Purpose : Base class update function - flags an error.
149 // Special Notes :
150 // Scope : public
151 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
152 // Creation Date : 4/24/00
153 //-----------------------------------------------------------------------------
155 {
156  std::string msg;
157 
158  msg = "SourceData::updateSource:\n";
159  msg += "\tAttempted to update the source for a source type that is not";
160  msg += " yet implemented";
161  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL, msg);
162 
163  return false;
164 }
165 
166 //-----------------------------------------------------------------------------
167 // Function : SourceData::returnSource
168 // Purpose :
169 // Special Notes :
170 // Scope : public
171 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
172 // Creation Date : 4/24/00
173 //-----------------------------------------------------------------------------
175 {
176  return SourceValue;
177 }
178 
179 //-----------------------------------------------------------------------------
180 // Function : SourceData::returnSource
181 // Purpose :
182 // Special Notes :
183 // Scope : public
184 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
185 // Creation Date : 4/24/00
186 //-----------------------------------------------------------------------------
188 {
189  return typeName_;
190 }
191 
192 
193 
194 #ifdef Xyce_DEBUG_DEVICE
195 //-----------------------------------------------------------------------------
196 // Function : SourceData::printOutParams
197 // Purpose :
198 // Special Notes :
199 // Scope : public
200 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
201 // Creation Date : 6/21/00
202 //-----------------------------------------------------------------------------
203 void SourceData::printOutParams()
204 {
205 
206 }
207 #endif
208 
209 //-----------------------------------------------------------------------------
210 // Function : SourceData::getMaxTimeStepSize
211 // Purpose :
212 // Special Notes :
213 // Scope : public
214 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
215 // Creation Date : 4/01/02
216 //-----------------------------------------------------------------------------
218 {
220 }
221 
222 //-----------------------------------------------------------------------------
223 // Function : SourceData::getTime_
224 // Purpose :
225 // Special Notes :
226 // Scope : protected
227 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
228 // Creation Date : 3/25/04
229 //-----------------------------------------------------------------------------
231 {
232  double tmpTime = 0.0;
233 
234 //#ifdef Xyce_MPDE
235  if (fastTimeScaleFlag_)
236  tmpTime = solState_.currFastTime;
237  else
238 //#endif // Xyce_MPDE
239  tmpTime = solState_.currTime;
240 
241 #ifdef Xyce_DEBUG_DEVICE
242 //#ifdef Xyce_MPDE
244  {
245  Xyce::dout() << "SourceData::getTime. time = ";
246  Xyce::dout() << tmpTime << std::endl;
247  Xyce::dout() << "SourceData::getTime. currFastTime = ";
248  Xyce::dout() << solState_.currFastTime<< std::endl;
249  Xyce::dout() << "SourceData::getTime. currTime = ";
250  Xyce::dout() << solState_.currTime << std::endl;
251  }
252 //#endif // Xyce_MPDE
253 #endif
254  return tmpTime;
255 }
256 
257 // Class SinData
258 
259 //-----------------------------------------------------------------------------
260 // Function : SinData::SinData
261 // Purpose : copy constructor
262 // Special Notes :
263 // Scope : public
264 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
265 // Creation Date : 3/16/00
266 //-----------------------------------------------------------------------------
267 SinData::SinData(const SinData & right)
268  : SourceData(right),
269  V0(right.V0),
270  VA(right.VA),
271  FREQ(right.FREQ),
272  TD(right.TD),
273  THETA(right.THETA),
274  PHASE(right.PHASE),
275  V0given(right.V0given),
276  VAgiven(right.VAgiven),
277  FREQgiven(right.FREQgiven),
278  TDgiven(right.TDgiven),
279  THETAgiven(right.THETAgiven),
280  PHASEgiven(right.PHASEgiven)
281 {
282 
283 }
284 
285 //-----------------------------------------------------------------------------
286 // Function : SinData::SinData
287 // Purpose : constructor
288 // Special Notes :
289 // Scope : public
290 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
291 // Creation Date : 3/16/00
292 //
293 // From 3f5: remember to incorporate this later:
294 //
295 //-----------------------------------------------------------------------------
296 #if 0
297  // this is from 3f5:
298  #define FREQ (((here->VSRCfunctionOrder >=3) && (*(here->VSRCcoeffs+2)))? \
299  (*(here->VSRCcoeffs+2)):(1/ckt->CKTfinalTime))
300 #endif
301 
302 SinData::SinData( const std::vector<Param> & paramRef,
303  const SolverState & ss1,
304  const DeviceOptions & do1)
305  : SourceData(ss1,do1),
306  V0(0.0),
307  VA(0.0),
308  FREQ(0.0),
309  TD(0.0),
310  THETA(0.0),
311  PHASE(0.0),
312  V0given(false),
313  VAgiven(false),
314  FREQgiven(false),
315  TDgiven(false),
316  THETAgiven(false),
317  PHASEgiven(false)
318 {
319  std::vector<Param>::const_iterator iter = paramRef.begin();
320  std::vector<Param>::const_iterator last = paramRef.end();
321 
322  for ( ; iter != last; ++iter)
323  {
324  const std::string & tmpname = iter->tag();
325 
326  if (tmpname == "V0") { V0 = iter->getImmutableValue<double>(); V0given = iter->given();}
327  if (tmpname == "VA") { VA = iter->getImmutableValue<double>(); VAgiven = iter->given();}
328  if (tmpname == "FREQ") { FREQ = iter->getImmutableValue<double>(); FREQgiven = iter->given();}
329  if (tmpname == "TD") { TD = iter->getImmutableValue<double>(); TDgiven = iter->given();}
330  if (tmpname == "THETA") { THETA = iter->getImmutableValue<double>(); THETAgiven =
331  iter->given();}
332  if (tmpname == "PHASE") { PHASE = iter->getImmutableValue<double>();
333  PHASEgiven = iter->given();}
334  }
335 
336  typeName_ = "SIN";
337  defaultParamName_ = "V0";
338 }
339 
340 //-----------------------------------------------------------------------------
341 // Function : SinData::initializeSource
342 // Purpose :
343 // Special Notes :
344 // Scope : public
345 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
346 // Creation Date : 9/04/01
347 //-----------------------------------------------------------------------------
349 {
350 
351  // If neccessary, set defaults:
352  double tstop = solState_.finalTime;
353 
354  if (!FREQgiven) FREQ = 1.0/tstop;
355  if (!TDgiven) TD = 0.0;
356  if (!THETAgiven) THETA = 0.0;
357 
358  initializeFlag_ = true;
359 
360  return true;
361 }
362 
363 //-----------------------------------------------------------------------------
364 // Function : SinData::~SinData
365 // Purpose : destructor
366 // Special Notes :
367 // Scope : public
368 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
369 // Creation Date : 3/16/00
370 //-----------------------------------------------------------------------------
372 {
373 
374 }
375 
376 #ifdef Xyce_DEBUG_DEVICE
377 //-----------------------------------------------------------------------------
378 // Function : SinData::printOutParams
379 // Purpose :
380 // Special Notes :
381 // Scope : public
382 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
383 // Creation Date : 6/21/00
384 //-----------------------------------------------------------------------------
385 
386 void SinData::printOutParams()
387 
388 {
389  Xyce::dout() << "SinData:\n";
390  Xyce::dout() << "V0 = " << V0 << std::endl;
391  Xyce::dout() << "VA = " << VA << std::endl;
392  Xyce::dout() << "FREQ = " << FREQ << std::endl;
393  Xyce::dout() << "TD = " << TD << std::endl;
394  Xyce::dout() << "THETA = " << THETA << std::endl;
395  Xyce::dout() << "PHASE = " << PHASE << std::endl;
396 }
397 #endif
398 
399 // Additional Declarations
400 
401 //-----------------------------------------------------------------------------
402 // Function : SinData::updateSource
403 // Purpose : Update the sinwave source.
404 // Special Notes :
405 //
406 // V0 - offset (V or A)
407 // VA - Amplitude (V or A)
408 // FREQ - frequency in Hz
409 // TD - delay in seconds
410 // THETA - damping factor (Hz).
411 // PHASE - phase (degrees)
412 //
413 // Scope : public
414 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
415 // Creation Date : 4/24/00
416 //-----------------------------------------------------------------------------
418 {
419  bool bsuccess = true;
420 
421  if (!initializeFlag_) bsuccess = initializeSource ();
422 
423 //#ifdef Xyce_MPDE
424  time = getTime_();
425 //#else
426 // time = solState_.currTime;
427 //#endif // Xyce_MPDE
428 
429  time -= TD;
430  double mpi = M_PI;
431  if (time <= 0)
432  {
433  //SourceValue = V0;
434  SourceValue = V0 + VA * sin (2.0*mpi*(PHASE/360)) ;
435  }
436  else
437  {
438  // 2PI to convert from hz to radians/sec
439  SourceValue = V0 + VA * sin (2.0*mpi*(FREQ*time + PHASE/360)) *
440  exp( -(time*THETA));
441  }
442 
443  resetFlag_ = false;
444  return bsuccess;
445 }
446 
447 //-----------------------------------------------------------------------------
448 // Function : SinData::getParams
449 // Purpose : Pass back the sine source params.
450 // Special Notes : TD and FREQ are interchanged from their normal order
451 // to accomodate the storage layout in the device classes
452 //
453 // Scope : public
454 // Creator : Dave Shirley, PSSI
455 // Creation Date : 4/14/05
456 //-----------------------------------------------------------------------------
457 void SinData::getParams(double *params)
458 {
459  params[0] = V0;
460  params[1] = VA;
461  params[2] = TD;
462  params[3] = FREQ;
463  params[4] = THETA;
464  params[5] = PHASE;
465  return;
466 }
467 
468 //-----------------------------------------------------------------------------
469 // Function : SinData::setParams
470 // Purpose : Update the sine source params.
471 // Special Notes : TD and FREQ are interchanged from their normal order
472 // to accomodate the storage layout in the device classes
473 //
474 // Scope : public
475 // Creator : Dave Shirley, PSSI
476 // Creation Date : 4/14/05
477 //-----------------------------------------------------------------------------
478 void SinData::setParams(double *params)
479 {
480  bool reset=false;
481  if (V0 != params[0])
482  {
483  V0 = params[0];
484  reset = true;
485  }
486  if (VA != params[1])
487  {
488  VA = params[1];
489  reset = true;
490  }
491  if (TD != params[2])
492  {
493  TD = params[2];
494  reset = true;
495  }
496  if (FREQ != params[3])
497  {
498  FREQ = params[3];
499  reset = true;
500  }
501  if (THETA != params[4])
502  {
503  THETA = params[4];
504  reset = true;
505  }
506  if (PHASE != params[5])
507  {
508  PHASE = params[5];
509  reset = true;
510  }
511  if (reset)
512  {
513  updateSource();
514  }
515 
516  return;
517 }
518 
519 // Class ExpData
520 
521 //-----------------------------------------------------------------------------
522 // Function : ExpData::ExpData
523 // Purpose : copy constructor
524 // Special Notes :
525 // Scope : public
526 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
527 // Creation Date : 3/16/00
528 //-----------------------------------------------------------------------------
530  : SourceData(right),
531  V1 (right.V1),
532  V2 (right.V2),
533  TD1 (right.TD1),
534  TAU1 (right.TAU1),
535  TD2 (right.TD2),
536  TAU2 (right.TAU2),
537  V1given (right.V1given),
538  V2given (right.V2given),
539  TD1given (right.TD1given),
540  TAU1given (right.TAU1given),
541  TD2given (right.TD2given),
542  TAU2given (right.TAU2given)
543 {
544 
545 }
546 
547 //-----------------------------------------------------------------------------
548 // Function : ExpData::ExpData
549 // Purpose : constructor
550 // Special Notes :
551 // Scope : public
552 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
553 // Creation Date : 3/16/00
554 //-----------------------------------------------------------------------------
555 ExpData::ExpData(const std::vector<Param> & paramRef,
556  const SolverState & ss1,
557  const DeviceOptions & do1)
558  : SourceData(ss1,do1),
559  V1 (0.0),
560  V2 (0.0),
561  TD1 (0.0),
562  TAU1 (0.0),
563  TD2 (0.0),
564  TAU2 (0.0),
565  V1given (false),
566  V2given (false),
567  TD1given (false),
568  TAU1given (false),
569  TD2given (false),
570  TAU2given (false)
571 {
572  // Set the user-defined params:
573  std::vector<Param>::const_iterator iter = paramRef.begin();
574  std::vector<Param>::const_iterator last = paramRef.end();
575 
576  for ( ; iter != last; ++iter)
577  {
578  const std::string & tmpname = iter->tag();
579 
580  if (tmpname == "V1") { V1 = iter->getImmutableValue<double>(); V1given = iter->given();}
581  if (tmpname == "V2") { V2 = iter->getImmutableValue<double>(); V2given = iter->given();}
582  if (tmpname == "TD1") { TD1 = iter->getImmutableValue<double>(); TD1given = iter->given();}
583  if (tmpname == "TAU1") { TAU1 = iter->getImmutableValue<double>(); TAU1given = iter->given();}
584  if (tmpname == "TD2") { TD2 = iter->getImmutableValue<double>(); TD2given = iter->given();}
585  if (tmpname == "TAU2") { TAU2 = iter->getImmutableValue<double>(); TAU2given = iter->given();}
586  }
587 
588  typeName_ = "EXP";
589  defaultParamName_ = "V1";
590 }
591 
592 //-----------------------------------------------------------------------------
593 // Function : ExpData::~ExpData
594 // Purpose : destructor
595 // Special Notes :
596 // Scope : public
597 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
598 // Creation Date : 3/16/00
599 //-----------------------------------------------------------------------------
601 {
602 
603 }
604 
605 // Additional Declarations
606 
607 #ifdef Xyce_DEBUG_DEVICE
608 //-----------------------------------------------------------------------------
609 // Function : ExpData::printOutParams
610 // Purpose :
611 // Special Notes :
612 // Scope : public
613 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
614 // Creation Date : 6/21/00
615 //-----------------------------------------------------------------------------
616 void ExpData::printOutParams()
617 {
618  Xyce::dout() << "ExpData:\n";
619 
620  Xyce::dout() << "V1 = " << V1 << std::endl;
621  Xyce::dout() << "V2 = " << V2 << std::endl;
622 
623  Xyce::dout() << "TD1 = " << TD1 << std::endl;
624  Xyce::dout() << "TAU1 = " << TAU1 << std::endl;
625 
626  Xyce::dout() << "TD2 = " << TD2 << std::endl;
627  Xyce::dout() << "TAU2 = " << TAU2 << std::endl;
628 
629 }
630 #endif
631 
632 //-----------------------------------------------------------------------------
633 // Function : ExpData::initializeSource
634 // Purpose :
635 // Special Notes :
636 // Scope : public
637 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
638 // Creation Date : 9/04/01
639 //-----------------------------------------------------------------------------
641 {
642  // If neccessary, set defaults:
643  double tstep = solState_.startingTimeStep;
644 
645  if (!TD1given) TD1 = 0.0;
646  if (!TAU1given) TAU1 = tstep;
647  if (!TD2given) TD2 = TD1 + tstep;
648  if (!TAU2given) TAU2 = tstep;
649 
650  initializeFlag_ = true;
651 
652  return true;
653 }
654 
655 //-----------------------------------------------------------------------------
656 // Function : ExpData::updateSource
657 // Purpose : Updates an exponential source:
658 // Special Notes :
659 //
660 // V1 - Initial value (V or A)
661 // V2 - Pulsed value (V or A).
662 // TD1 - Rise delay time (seconds).
663 // TAU1 - Rise time constant (seconds)
664 // TD2 - Fall delay time (seconds).
665 // TAU2 - Fall time constant (seconds)
666 //
667 // Scope : public
668 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
669 // Creation Date : 4/24/00
670 //-----------------------------------------------------------------------------
671 
673 
674 {
675  bool bsuccess = true;
676 
677  if (!initializeFlag_) bsuccess = initializeSource ();
678 
679 //#ifdef Xyce_MPDE
680  time = getTime_();
681 //#else
682 // time = solState_.currTime;
683 //#endif // Xyce_MPDE
684 
685  if (time <= TD1)
686  {
687  SourceValue = V1;
688  }
689  else if (time <= TD2)
690  {
691  SourceValue = V1 + (V2-V1)*(1-exp(-(time-TD1)/TAU1));
692  }
693  else
694  {
695  SourceValue = V1 + (V2-V1)*(1-exp(-(time-TD1)/TAU1)) +
696  (V1-V2)*(1-exp(-(time-TD2)/TAU2)) ;
697  }
698 
699  resetFlag_ = false;
700 
701  return bsuccess;
702 
703 }
704 
705 //-----------------------------------------------------------------------------
706 // Function : ExpData::getParams
707 // Purpose : Pass back the exponential source params.
708 // Special Notes :
709 //
710 // Scope : public
711 // Creator : Dave Shirley, PSSI
712 // Creation Date : 4/14/05
713 //-----------------------------------------------------------------------------
714 void ExpData::getParams(double *params)
715 {
716  params[0] = V1;
717  params[1] = V2;
718  params[2] = TD1;
719  params[3] = TAU1;
720  params[4] = TD2;
721  params[5] = TAU2;
722  return;
723 }
724 
725 //-----------------------------------------------------------------------------
726 // Function : ExpData::setParams
727 // Purpose : Update the exponential source params.
728 // Special Notes :
729 //
730 // Scope : public
731 // Creator : Dave Shirley, PSSI
732 // Creation Date : 4/14/05
733 //-----------------------------------------------------------------------------
734 void ExpData::setParams(double *params)
735 {
736  bool reset=false;
737  if (V1 != params[0])
738  {
739  V1 = params[0];
740  reset = true;
741  }
742  if (V2 != params[1])
743  {
744  V2 = params[1];
745  reset = true;
746  }
747  if (TD1 != params[2])
748  {
749  TD1 = params[2];
750  reset = true;
751  }
752  if (TAU1 != params[3])
753  {
754  TAU1 = params[3];
755  reset = true;
756  }
757  if (TD2 != params[4])
758  {
759  TD2 = params[4];
760  reset = true;
761  }
762  if (TAU2 != params[5])
763  {
764  TAU2 = params[5];
765  reset = true;
766  }
767  if (reset)
768  {
769  updateSource();
770  }
771 
772  return;
773 }
774 
775 // Class PulseData
776 //-----------------------------------------------------------------------------
777 // Function : PulseData::PulseData
778 // Purpose : copy constructor
779 // Special Notes :
780 // Scope : public
781 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
782 // Creation Date : 3/16/00
783 //-----------------------------------------------------------------------------
785  : SourceData(right),
786  V1 (right.V1),
787  V2 (right.V2),
788  TD (right.TD),
789  TR (right.TR),
790  TF (right.TF),
791  PW (right.PW),
792  PER (right.PER),
793  V1given (right.V1given),
794  V2given (right.V2given),
795  TDgiven (right.TDgiven),
796  TRgiven (right.TRgiven),
797  TFgiven (right.TFgiven),
798  PWgiven (right.PWgiven),
799  PERgiven (right.PERgiven)
800 {
801 
802 }
803 
804 //-----------------------------------------------------------------------------
805 // Function : PulseData::PulseData
806 // Purpose : constructor
807 // Special Notes :
808 // Scope : public
809 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
810 // Creation Date : 3/16/00
811 //-----------------------------------------------------------------------------
812 PulseData::PulseData( const std::vector<Param> & paramRef,
813  const SolverState & ss1,
814  const DeviceOptions & do1)
815  : SourceData (ss1,do1),
816  V1 (0.0),
817  V2 (0.0),
818  TD (0.0),
819  TR (0.0),
820  TF (0.0),
821  PW (0.0),
822  PER (0.0),
823  V1given (false),
824  V2given (false),
825  TDgiven (false),
826  TRgiven (false),
827  TFgiven (false),
828  PWgiven (false),
829  PERgiven (false)
830 {
831 
832  // Get the user-defined values:
833  std::vector<Param>::const_iterator iter = paramRef.begin();
834  std::vector<Param>::const_iterator last = paramRef.end();
835 
836  for ( ; iter != last; ++iter)
837  {
838  const std::string & tmpname = iter->tag();
839 
840  if (tmpname == "V1") { V1 = iter->getImmutableValue<double>(); V1given = iter->given();}
841  if (tmpname == "V2") { V2 = iter->getImmutableValue<double>(); V2given = iter->given();}
842  if (tmpname == "TD") { TD = iter->getImmutableValue<double>(); TDgiven = iter->given();}
843  if (tmpname == "TR") { TR = iter->getImmutableValue<double>(); TRgiven = iter->given();}
844  if (tmpname == "TF") { TF = iter->getImmutableValue<double>(); TFgiven = iter->given();}
845  if (tmpname == "PW") { PW = iter->getImmutableValue<double>(); PWgiven = iter->given();}
846  if (tmpname == "PER") { PER = iter->getImmutableValue<double>(); PERgiven = iter->given();}
847  }
848 
849  typeName_ = "PULSE";
850  defaultParamName_ = "V2";
851 }
852 
853 //-----------------------------------------------------------------------------
854 // Function : PulseData::~PulseData
855 // Purpose : destructor
856 // Special Notes :
857 // Scope : public
858 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
859 // Creation Date : 3/16/00
860 //-----------------------------------------------------------------------------
862 {
863 
864 }
865 
866 // Additional Declarations
867 
868 #ifdef Xyce_DEBUG_DEVICE
869 //-----------------------------------------------------------------------------
870 // Function : PulseData::printOutParams
871 // Purpose :
872 // Special Notes :
873 // Scope : public
874 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
875 // Creation Date : 6/21/00
876 //-----------------------------------------------------------------------------
877 void PulseData::printOutParams()
878 {
879  Xyce::dout() << std::endl;
880  Xyce::dout() << " PulseData::printOutParams\n";
881  Xyce::dout() << " V1 = " << V1 << std::endl;
882  Xyce::dout() << " V2 = " << V2 << std::endl;
883 
884  Xyce::dout() << " TD = " << TD << std::endl;
885  Xyce::dout() << " TR = " << TR << std::endl;
886  Xyce::dout() << " TF = " << TF << std::endl;
887  Xyce::dout() << " PW = " << PW << std::endl;
888  Xyce::dout() << " PER = " << PER << std::endl;
889  Xyce::dout() << std::endl;
890 
891 }
892 #endif
893 
894 //-----------------------------------------------------------------------------
895 // Function : PulseData::initializeSource
896 // Purpose :
897 // Special Notes :
898 // Scope : public
899 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
900 // Creation Date : 9/04/01
901 //-----------------------------------------------------------------------------
903 {
904  // If neccessary, set the defaults:
905 
906  double tstep = solState_.startingTimeStep;
907  double tstop = solState_.finalTime;
908 
909  if (!TDgiven) TD = 0.0;
910  if (!TRgiven) TR = tstep;
911  if (!TFgiven) TF = tstep;
912  if (!PWgiven) PW = tstop;
913  if (!PERgiven) PER = tstop;
914 
915  initializeFlag_ = true;
916 
917  return true;
918 }
919 
920 //-----------------------------------------------------------------------------
921 // Function : PulseData::updateSource
922 // Purpose :
923 // Special Notes :
924 // Scope : public
925 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
926 // Creation Date : 4/24/00
927 //-----------------------------------------------------------------------------
929 
930 {
931 //notused: double tstep = solState_.startingTimeStep;
932 //notused: double tstop = solState_.finalTime;
933  bool bsuccess = true;
934 
935  if (!initializeFlag_) bsuccess = initializeSource ();
936 
937  double basetime = 0;
938 
939 #ifdef Xyce_DEBUG_DEVICE
941  {
942  Xyce::dout() << " PulseData::updateSources\n";
943  printOutParams();
944  }
945 #endif
946 
947 //#ifdef Xyce_MPDE
948  time = getTime_();
949 //#else
950 // time = solState_.currTime;
951 //#endif // Xyce_MPDE
952 
953 #ifdef Xyce_DEBUG_DEVICE
955  {
956  Xyce::dout() << " Time = " << time << std::endl;
957  }
958 #endif
959 
960  time -= TD;
961 
962  if (time > PER && PER != 0.0)
963  {
964  // repeating signal - figure out where we are in period
965  basetime = PER * floor(time/PER);
966  time -= basetime;
967  }
968 
969  // This section got ugly because of a nasty roundoff bug.
970  // Instead of doing "time > X" you need also check that time
971  // is not within bptol of X.
972  // So the following translation is used:
973  // Instead of: we do:
974  // time > X time>X && fabs(time-x)>bptol
975  // time <= X time<X || fabs(time-x)<bptol
976 
977  if (time <= 0 || (time > (TR + PW + TF) &&
978  (fabs (time - (TR+PW+TF)) > solState_.bpTol) ) )
979  {
980  SourceValue = V1;
981  }
982  else if ((time > TR && fabs(time-TR) > solState_.bpTol)
983  && (time < (TR + PW) || fabs (time-(TR+PW))<solState_.bpTol) )
984  {
985  SourceValue = V2;
986  }
987  else if (time > 0 &&
988  (time < TR || fabs(time-TR) < solState_.bpTol))
989  {
990  if (TR != 0.0)
991  {
992  SourceValue = V1 + (V2 - V1) * (time) / TR;
993  }
994  else
995  {
996  SourceValue = V1;
997  }
998  }
999  else
1000  { // time > (TR + PW) && <= (TR + PW + TF)
1001  if (TF != 0.0)
1002  {
1003  SourceValue = V2 + (V1 - V2) * (time - (TR + PW)) / TF;
1004  }
1005  else
1006  {
1007  SourceValue = V2; // SourceValue = 0.5 * (V1 + V2);
1008  }
1009  }
1010 
1011 #ifdef Xyce_DEBUG_DEVICE
1013  {
1014  Xyce::dout() << " SourceValue = " << SourceValue << std::endl;
1015  }
1016 #endif
1017 
1018  resetFlag_ = false;
1019 
1020  return bsuccess;
1021 }
1022 
1023 //-----------------------------------------------------------------------------
1024 // Function : PulseData::getParams
1025 // Purpose : Pass back the pulse source params.
1026 // Special Notes :
1027 //
1028 // Scope : public
1029 // Creator : Dave Shirley, PSSI
1030 // Creation Date : 4/14/05
1031 //-----------------------------------------------------------------------------
1032 void PulseData::getParams(double *params)
1033 {
1034  params[0] = V1;
1035  params[1] = V2;
1036  params[2] = TD;
1037  params[3] = TR;
1038  params[4] = TF;
1039  params[5] = PW;
1040  params[6] = PER;
1041  return;
1042 }
1043 
1044 //-----------------------------------------------------------------------------
1045 // Function : PulseData::setParams
1046 // Purpose : Update the pulse source params.
1047 // Special Notes :
1048 //
1049 // Scope : public
1050 // Creator : Dave Shirley, PSSI
1051 // Creation Date : 4/14/05
1052 //-----------------------------------------------------------------------------
1053 void PulseData::setParams(double *params)
1054 {
1055  bool reset=false;
1056  if (V1 != params[0])
1057  {
1058  V1 = params[0];
1059  reset = true;
1060  }
1061  if (V2 != params[1])
1062  {
1063  V2 = params[1];
1064  reset = true;
1065  }
1066  if (TD != params[2])
1067  {
1068  TD = params[2];
1069  reset = true;
1070  }
1071  if (TR != params[3])
1072  {
1073  TR = params[3];
1074  reset = true;
1075  }
1076  if (TF != params[4])
1077  {
1078  TF = params[4];
1079  reset = true;
1080  }
1081  if (PW != params[5])
1082  {
1083  PW = params[5];
1084  reset = true;
1085  }
1086  if (PER != params[6])
1087  {
1088  PER = params[6];
1089  reset = true;
1090  }
1091  if (reset)
1092  {
1093  updateSource();
1094  }
1095 
1096  return;
1097 }
1098 
1099 //-----------------------------------------------------------------------------
1100 // Function : PulseData::getBreakPoints
1101 // Purpose : This function adds break points to a vector of breakpoints.
1102 //
1103 // It does not bother to check them in any way, or put them
1104 // in order. It only adds them in.
1105 //
1106 // Special Notes : Like much of this file, this is adapted from spice 3f5.
1107 // Some of the stuff in it is a little hokey, and may get
1108 // removed or modified later.
1109 //
1110 // Scope : public
1111 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1112 // Creation Date : 06/08/01
1113 //-----------------------------------------------------------------------------
1115  (std::vector<N_UTL_BreakPoint> & breakPointTimes )
1116 {
1117  bool bsuccess = true;
1118 
1119  if (!initializeFlag_) bsuccess = initializeSource ();
1120 
1121  // currPeriodIndex is the integer index representing the period of
1122  // the current circuit time.
1123  int currPeriodIndex = 0;
1124 
1125  // subtract out the delay.
1126  double basetime = 0.0;
1127 
1128 //#ifdef Xyce_MPDE
1129  time = getTime_() - TD;
1130 //#else
1131 // time = solState_.currTime - TD;
1132 //#endif // Xyce_MPDE
1133 
1134 #ifdef Xyce_DEBUG_DEVICE
1135  if (devOptions_.debugLevel > 0 && solState_.debugTimeFlag)
1136  {
1137  Xyce::dout() << std::endl;
1138  Xyce::dout() << " In PulseData::getBreakPoints\n";
1139  Xyce::dout() << " time = " << time << std::endl;
1140  Xyce::dout() << " TD = " << TD << std::endl;
1141  Xyce::dout() << " PER = " << PER << std::endl;
1142  }
1143 #endif
1144 
1145  // repeating signal - figure out where we are in period
1146  if(time >= PER)
1147  {
1148  if (PER != 0.0)
1149  {
1150  currPeriodIndex = (static_cast<int> (floor(time/PER)));
1151  basetime = PER * (static_cast<double> (currPeriodIndex));
1152  time -= basetime;
1153  }
1154  }
1155 
1156 #ifdef Xyce_DEBUG_DEVICE
1157  if (devOptions_.debugLevel > 0 && solState_.debugTimeFlag)
1158  {
1159  Xyce::dout() << " time = " << time << std::endl;
1160  Xyce::dout() << " basetime = " << basetime << std::endl;
1161  Xyce::dout() << " currPeriodIndex = " << currPeriodIndex << std::endl;
1162  Xyce::dout() << std::endl;
1163  }
1164 #endif
1165 
1166  // now that we know which period this is, push_back all breakpoints
1167  // in this period and the next. If we are still in the delay, then
1168  // just use first two periods.
1169 
1170  // current period:
1171  breakPointTimes.push_back(basetime+TD);
1172  breakPointTimes.push_back(basetime+TD+TR);
1173  breakPointTimes.push_back(basetime+TD+TR+PW);
1174  breakPointTimes.push_back(basetime+TD+TR+PW+TF);
1175 
1176  if (PER != 0.0)
1177  {
1178  breakPointTimes.push_back(basetime+TD+PER);
1179 
1180  // next period:
1181  breakPointTimes.push_back(basetime+TD+PER+TR);
1182  breakPointTimes.push_back(basetime+TD+PER+TR+PW);
1183  breakPointTimes.push_back(basetime+TD+PER+TR+PW+TF);
1184  breakPointTimes.push_back(basetime+TD+PER+PER);
1185  }
1186 
1187  return bsuccess;
1188 }
1189 
1190 //-----------------------------------------------------------------------------
1191 // Function : PulseData::getMaxTimeStepSize
1192 // Purpose :
1193 // Special Notes :
1194 // Scope : public
1195 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1196 // Creation Date : 9/25/01
1197 //-----------------------------------------------------------------------------
1199 {
1200  double maxTimeStep = devOptions_.defaultMaxTimeStep;
1201 
1202  // check if we are still in the delay or not.
1203 //#ifdef Xyce_MPDE
1204  time = getTime_();
1205 //#else
1206 // time = solState_.currTime;
1207 //#endif // Xyce_MPDE
1208 
1209  if (time < TD) maxTimeStep = (0.1*TD );
1210  else maxTimeStep = (0.1*PER);
1211 
1212 #ifdef Xyce_DEBUG_DEVICE
1214  {
1215  Xyce::dout() << "\nIn PulseData::getMaxTimeStepSize. ";
1216  Xyce::dout() << " maxTimeStep = "<< maxTimeStep;
1217  Xyce::dout() << " TD = " << TD << " PER = " <<PER;
1218  Xyce::dout() << " time = "<< time << std::endl;
1219  }
1220 #endif
1221 
1222  return maxTimeStep;
1223 }
1224 
1225 // Class PWLinData
1226 
1227 //-----------------------------------------------------------------------------
1228 // Function : PWLinData::PWLinData
1229 // Purpose : copy constructor
1230 // Special Notes :
1231 // Scope : public
1232 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1233 // Creation Date : 3/16/00
1234 //-----------------------------------------------------------------------------
1236  : SourceData(right),
1237  NUM(right.NUM),
1238  REPEAT(right.REPEAT),
1239  REPEATTIME(right.REPEATTIME),
1240  TD(right.TD),
1241  TVVEC(right.TVVEC),
1242  loc_(right.loc_),
1243  starttime_(right.starttime_)
1244 {
1245 }
1246 
1247 //-----------------------------------------------------------------------------
1248 // Function : PWLinData::PWLinData
1249 // Purpose : constructor
1250 // Special Notes :
1251 // Scope : public
1252 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1253 // Creation Date : 3/16/00
1254 //-----------------------------------------------------------------------------
1255 PWLinData::PWLinData( const std::vector<Param> & paramRef,
1256  const SolverState & ss1,
1257  const DeviceOptions & do1)
1258  : SourceData(ss1,do1),
1259  NUM(0),
1260  REPEAT(false),
1261  REPEATTIME(0.0),
1262  TD(0.0),
1263  loc_(0),
1264  starttime_(0.0)
1265 {
1266  std::vector<Param>::const_iterator iter = paramRef.begin();
1267  std::vector<Param>::const_iterator last = paramRef.end();
1268 
1269  for ( ; iter != last; ++iter)
1270  {
1271  const std::string & tmpname = iter->tag();
1272 
1273  if (tmpname == "NUM") NUM = iter->getImmutableValue<int>();
1274  if (tmpname == "REPEAT") REPEAT = iter->getImmutableValue<bool>();
1275  if (tmpname == "REPEATTIME") REPEATTIME = iter->getImmutableValue<double>();
1276  if (tmpname == "TD") TD = iter->getImmutableValue<double>();
1277 
1278  if ( tmpname == "T" && iter->given() )
1279  {
1280  time = iter->getImmutableValue<double>();
1281  ++iter;
1282 
1283  TVVEC.push_back(std::pair<double,double>(time, iter->getImmutableValue<double>()));
1284  }
1285  }
1286 
1287  typeName_ = "PWL";
1288 }
1289 
1290 //-----------------------------------------------------------------------------
1291 // Function : PWLinData::PWLinData
1292 // Purpose : destructor
1293 // Special Notes :
1294 // Scope : public
1295 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1296 // Creation Date : 3/16/00
1297 //-----------------------------------------------------------------------------
1299 {
1300 }
1301 
1302 #ifdef Xyce_DEBUG_DEVICE
1303 //-----------------------------------------------------------------------------
1304 // Function : PWLinData::printOutParams
1305 // Purpose :
1306 // Special Notes :
1307 // Scope : public
1308 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1309 // Creation Date : 6/21/00
1310 //-----------------------------------------------------------------------------
1311 void PWLinData::printOutParams()
1312 {
1313  Xyce::dout() << std::endl;
1314  Xyce::dout() << " NUM = " << NUM << std::endl;
1315  Xyce::dout() << " REPEAT = " << REPEAT << std::endl;
1316  Xyce::dout() << " REPEATTIME = " << REPEATTIME << std::endl;
1317  Xyce::dout() << " TD = " << TD << std::endl;
1318  Xyce::dout() << " loc_ = " << loc_ << std::endl;
1319  Xyce::dout() << " starttime_ = " << starttime_ << std::endl;
1320 
1321  Xyce::dout() << " Time Voltage" << std::endl;
1322  for( int i = 0; i < NUM; ++i )
1323  Xyce::dout() << " " << TVVEC[i].first << " " << TVVEC[i].second << std::endl;
1324 
1325  Xyce::dout() << std::endl;
1326 }
1327 #endif
1328 
1329 // Additional Declarations
1330 
1331 //-----------------------------------------------------------------------------
1332 // Function : PWLinData::updateSource
1333 // Purpose :
1334 // Special Notes :
1335 // Scope : public
1336 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1337 // Creation Date : 4/24/00
1338 //-----------------------------------------------------------------------------
1340 {
1341 
1342  bool bsuccess = true;
1343 
1344  if (!initializeFlag_) bsuccess = initializeSource ();
1345 
1346 #ifdef Xyce_DEBUG_DEVICE
1348  {
1349  Xyce::dout() << std::endl;
1350  Xyce::dout() << " PWLinData::updateSource\n";
1351  printOutParams();
1352  }
1353 #endif
1354 
1355 //#ifdef Xyce_MPDE
1356  time = getTime_();
1357 //#else
1358 // time = solState_.currTime;
1359 //#endif // Xyce_MPDE
1360 
1361 #ifdef Xyce_DEBUG_DEVICE
1363  {
1364  Xyce::dout() << Xyce::section_divider << std::endl;
1365  Xyce::dout() << " Time = " << time << std::endl;
1366  }
1367 #endif
1368 
1369  double time1, time2, voltage1, voltage2;
1370 
1371  if( time >= TD )
1372  {
1373  time -= TD;
1374 
1375  if( time <= TVVEC[NUM-1].first )
1376  {
1377  for( int i = 0; i < NUM; ++i )
1378  if( time < TVVEC[i].first ) {loc_ = i;break;}
1379 
1380  if( loc_ == 0 )
1381  {
1382  time1 = 0.0;
1383  voltage1 = 0.0;
1384  }
1385  else
1386  {
1387  time1 = TVVEC[loc_-1].first;
1388  voltage1 = TVVEC[loc_-1].second;
1389  }
1390  time2 = TVVEC[loc_].first;
1391  voltage2 = TVVEC[loc_].second;
1392 
1393  }
1394  else if( !REPEAT )
1395  {
1396  time1 = 0.0;
1397  time2 = 1.0;
1398  voltage1 = voltage2 = TVVEC[NUM-1].second;
1399  }
1400  else
1401  {
1402  double looptime = TVVEC[NUM-1].first - REPEATTIME;
1403 
1404  time -= TVVEC[NUM-1].first;
1405  time -= looptime * floor(time / looptime);
1406  time += REPEATTIME;
1407 
1408 
1409  for( int i = 0; i < NUM; ++i )
1410  {
1411  if( time < TVVEC[i].first ) {loc_ = i;break;}
1412  }
1413 
1414  if (time == REPEATTIME)
1415  {
1416  time1 = 0.0;
1417  time2 = 1.0;
1418  voltage1 = voltage2 = TVVEC[NUM-1].second;
1419  }
1420  else
1421  {
1422  if( loc_ == 0 )
1423  {
1424  time1 = REPEATTIME;
1425  voltage1 = TVVEC[NUM-1].second;
1426  }
1427  else
1428  {
1429  time1 = TVVEC[loc_-1].first;
1430  voltage1 = TVVEC[loc_-1].second;
1431  }
1432  time2 = TVVEC[loc_].first;
1433  voltage2 = TVVEC[loc_].second;
1434  }
1435 
1436  }
1437 
1438  if( time1 == time2 )
1439  SourceValue = voltage2;
1440  else
1441  {
1442  double length = time2 - time1;
1443  SourceValue = ( time2 - time ) * voltage1 / length;
1444  SourceValue += ( -time1 + time ) * voltage2 / length;
1445  }
1446 
1447 #ifdef Xyce_DEBUG_DEVICE
1449  {
1450  Xyce::dout() << "time: " << time << std::endl;
1451  Xyce::dout() << "time1: " << time1 << std::endl;
1452  Xyce::dout() << "time2: " << time2 << std::endl;
1453  Xyce::dout() << "voltage1: " << voltage1 << std::endl;
1454  Xyce::dout() << "voltage2: " << voltage2 << std::endl;
1455  Xyce::dout() << "Src: " << SourceValue << std::endl;
1456  Xyce::dout() << Xyce::section_divider << std::endl;
1457  }
1458 #endif
1459 
1460  }
1461  else
1462  {
1463  SourceValue = 0.0;
1464  }
1465 
1466 
1467  resetFlag_ = false;
1468 
1469  return bsuccess;
1470 }
1471 
1472 //-----------------------------------------------------------------------------
1473 // Function : PWLinData::getBreakPoints
1474 // Purpose :
1475 // Special Notes :
1476 // Scope : public
1477 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1478 // Creation Date : 06/08/01
1479 //-----------------------------------------------------------------------------
1481  (std::vector<N_UTL_BreakPoint> & breakPointTimes )
1482 {
1483  bool bsuccess = true;
1484 
1485 #ifdef Xyce_DEBUG_DEVICE
1486  if (devOptions_.debugLevel > 0 && solState_.debugTimeFlag)
1487  {
1488  Xyce::dout() << " In PWLinData::getBreakPoints\n";
1489  }
1490 #endif
1491 
1492  if (!initializeFlag_) bsuccess = initializeSource ();
1493 
1494  time = solState_.currTime;
1495 
1496  time -= TD;
1497 
1498  // if it's a repeating signal, figure out what period we are in
1499  if (REPEAT && time >= TVVEC[NUM - 1].first)
1500  {
1501  double loopBaseTime = 0.0;
1502  double bp_time;
1503 
1504  double looptime = TVVEC[NUM-1].first - REPEATTIME;
1505  loopBaseTime = looptime * (1.0 + floor((time - TVVEC[NUM - 1].first) / looptime));
1506 #ifdef Xyce_DEBUG_DEVICE
1507  if (devOptions_.debugLevel > 0 && solState_.debugTimeFlag)
1508  {
1509  Xyce::dout() << "loopBaseTime: " << loopBaseTime << std::endl;
1510  Xyce::dout() << "floor function: " << floor((time - TVVEC[NUM - 1].first) / (TVVEC[NUM - 1].first - REPEATTIME)) << std::endl;
1511  }
1512 #endif
1513 
1514  for (int i = 0; i < NUM; ++i)
1515  {
1516  bp_time = TVVEC[i].first;
1517  if (bp_time >= REPEATTIME)
1518  {
1519  breakPointTimes.push_back(bp_time + loopBaseTime);
1520 #ifdef Xyce_DEBUG_DEVICE
1521  if (devOptions_.debugLevel > 0 && solState_.debugTimeFlag)
1522  {
1523  Xyce::dout() << "bp_time + loopBaseTime: " << bp_time + loopBaseTime << std::endl;
1524  }
1525 #endif
1526  }
1527  }
1528  }
1529  else
1530  {
1531  for (int i = 0; i < NUM; ++i)
1532  {
1533  double bp_time = TVVEC[i].first;
1534  breakPointTimes.push_back(bp_time);
1535 #ifdef Xyce_DEBUG_DEVICE
1536  if (devOptions_.debugLevel > 0 && solState_.debugTimeFlag)
1537  {
1538  Xyce::dout() << "bp_time: " << bp_time << std::endl;
1539  }
1540 #endif
1541  }
1542  }
1543  // now that we know which period this is, push_back all breakpoints
1544  // in this period and the next.
1545 
1546  return bsuccess;
1547 }
1548 
1549 // Class SFFMData
1550 
1551 //-----------------------------------------------------------------------------
1552 // Function : SFFMData::SFFMData
1553 // Purpose : copy constructor
1554 // Special Notes : SFFM = spice frequency modulation
1555 // Scope : public
1556 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1557 // Creation Date : 3/16/00
1558 //-----------------------------------------------------------------------------
1559 
1561  : SourceData(right),
1562  V0(right.V0),
1563  VA(right.VA),
1564  FC(right.FC),
1565  MDI(right.MDI),
1566  FS(right.FS),
1567  V0given (right.V0given),
1568  VAgiven (right.VAgiven),
1569  FCgiven (right.FCgiven),
1570  MDIgiven (right.MDIgiven),
1571  FSgiven (right.FSgiven)
1572 {
1573 
1574 }
1575 
1576 //-----------------------------------------------------------------------------
1577 // Function : SFFMData::SFFMData
1578 // Purpose : constructor
1579 // Special Notes :
1580 // Scope : public
1581 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1582 // Creation Date : 3/16/00
1583 //-----------------------------------------------------------------------------
1584 
1585 SFFMData::SFFMData( const std::vector<Param> & paramRef,
1586  const SolverState & ss1,
1587  const DeviceOptions & do1)
1588  : SourceData(ss1,do1),
1589  V0 (0.0),
1590  VA (0.0),
1591  FC (0.0),
1592  MDI (0.0),
1593  FS (0.0),
1594  V0given (false),
1595  VAgiven (false),
1596  FCgiven (false),
1597  MDIgiven (false),
1598  FSgiven (false)
1599 
1600 {
1601  std::vector<Param>::const_iterator iter = paramRef.begin();
1602  std::vector<Param>::const_iterator last = paramRef.end();
1603 
1604  for ( ; iter != last; ++iter)
1605  {
1606  const std::string & tmpname = iter->tag();
1607 
1608  if (tmpname == "V0") { V0 = iter->getImmutableValue<double>(); V0given = iter->given(); }
1609  if (tmpname == "VA") { VA = iter->getImmutableValue<double>(); VAgiven = iter->given(); }
1610  if (tmpname == "FC") { FC = iter->getImmutableValue<double>(); FCgiven = iter->given(); }
1611  if (tmpname == "MDI") { MDI = iter->getImmutableValue<double>(); MDIgiven = iter->given(); }
1612  if (tmpname == "FS") { FS = iter->getImmutableValue<double>(); FSgiven = iter->given(); }
1613  }
1614 
1615  typeName_ = "SFFM";
1616 }
1617 
1618 //-----------------------------------------------------------------------------
1619 // Function : SFFMData::~SFFMData
1620 // Purpose : destructor
1621 // Special Notes :
1622 // Scope : public
1623 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1624 // Creation Date : 3/16/00
1625 //-----------------------------------------------------------------------------
1626 
1628 {
1629 
1630 }
1631 
1632 // Additional Declarations
1633 
1634 #ifdef Xyce_DEBUG_DEVICE
1635 //-----------------------------------------------------------------------------
1636 // Function : SFFMData::printOutParams
1637 // Purpose :
1638 // Special Notes :
1639 // Scope : public
1640 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1641 // Creation Date : 5/01/00
1642 //-----------------------------------------------------------------------------
1643 
1644 void SFFMData::printOutParams()
1645 {
1646  Xyce::dout() << "SFFMData:\n";
1647  Xyce::dout() << "V0 = " << V0 << std::endl;
1648  Xyce::dout() << "VA = " << VA << std::endl;
1649  Xyce::dout() << "FC = " << FC << std::endl;
1650  Xyce::dout() << "MDI = " << MDI << std::endl;
1651  Xyce::dout() << "FS = " << FS << std::endl;
1652 }
1653 #endif
1654 
1655 //-----------------------------------------------------------------------------
1656 // Function : SFFMData::initializeSource
1657 // Purpose :
1658 // Special Notes :
1659 // Scope : public
1660 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1661 // Creation Date : 9/04/01
1662 //-----------------------------------------------------------------------------
1663 
1665 {
1666  // If neccessary, set the defaults:
1667  double tstop = solState_.finalTime;
1668 
1669  if (!FCgiven) FC = 1.0/tstop;
1670  if (!FSgiven) FS = 1.0/tstop;
1671 
1672  initializeFlag_ = true;
1673 
1674  return true;
1675 }
1676 
1677 //-----------------------------------------------------------------------------
1678 // Function : SFFMData::updateSource
1679 // Purpose :
1680 // Special Notes :
1681 //
1682 // V0 - offset (V or A)
1683 // VA - Amplitude (V or A)
1684 // FC - carrier frequency
1685 // MDI - modulation index
1686 // FS - signal frequency
1687 //
1688 // Scope : public
1689 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1690 // Creation Date : 4/24/00
1691 //-----------------------------------------------------------------------------
1692 
1694 {
1695  bool bsuccess = true;
1696 
1697  if (!initializeFlag_) bsuccess = initializeSource ();
1698 
1699 //#ifdef Xyce_MPDE
1700  time = getTime_();
1701 //#else
1702 // time = solState_.currTime;
1703 //#endif // Xyce_MPDE
1704 
1705  double mpi = M_PI;
1706  SourceValue = V0 + VA * sin((2 * mpi * FC * time) +
1707  MDI * sin (2 * mpi * FS * time));
1708 
1709  resetFlag_ = false;
1710 
1711  return bsuccess;
1712 }
1713 
1714 //-----------------------------------------------------------------------------
1715 // Function : SFFMData::getParams
1716 // Purpose : Pass back the SFFM source params.
1717 // Special Notes :
1718 //
1719 // Scope : public
1720 // Creator : Dave Shirley, PSSI
1721 // Creation Date : 4/14/05
1722 //-----------------------------------------------------------------------------
1723 void SFFMData::getParams(double *params)
1724 {
1725  params[0] = V0;
1726  params[1] = VA;
1727  params[2] = FC;
1728  params[3] = MDI;
1729  params[4] = FS;
1730  return;
1731 }
1732 
1733 //-----------------------------------------------------------------------------
1734 // Function : SFFMData::setParams
1735 // Purpose : Update the SFFM source params.
1736 // Special Notes :
1737 //
1738 // Scope : public
1739 // Creator : Dave Shirley, PSSI
1740 // Creation Date : 4/14/05
1741 //-----------------------------------------------------------------------------
1742 void SFFMData::setParams(double *params)
1743 {
1744  bool reset=false;
1745  if (V0 != params[0])
1746  {
1747  V0 = params[0];
1748  reset = true;
1749  }
1750  if (VA != params[1])
1751  {
1752  VA = params[1];
1753  reset = true;
1754  }
1755  if (FC != params[2])
1756  {
1757  FC = params[2];
1758  reset = true;
1759  }
1760  if (MDI != params[3])
1761  {
1762  MDI = params[3];
1763  reset = true;
1764  }
1765  if (FS != params[4])
1766  {
1767  FS = params[4];
1768  reset = true;
1769  }
1770  if (reset)
1771  updateSource();
1772 
1773  return;
1774 }
1775 
1776 // Class ACData
1777 
1778 //-----------------------------------------------------------------------------
1779 // Function : ACData::ACData
1780 // Purpose : copy constructor
1781 // Special Notes :
1782 // Scope : public
1783 // Creator : Ting Mei, SNL
1784 // Creation Date :
1785 //-----------------------------------------------------------------------------
1786 
1787 ACData::ACData(const ACData & right)
1788  : SourceData(right),
1789  ACMAG(right.ACMAG),
1790  ACPHASE(right.ACPHASE),
1791  ACMAGgiven(right.ACMAGgiven),
1792  ACPHASEgiven(right.ACPHASEgiven)
1793 {
1794 
1795 }
1796 
1797 
1798 //-----------------------------------------------------------------------------
1799 // Function : ACData::ACData
1800 // Purpose : constructor
1801 // Special Notes :
1802 // Scope : public
1803 // Creator : Ting Mei, SNL
1804 // Creation Date :
1805 //-----------------------------------------------------------------------------
1806 
1807 ACData::ACData( const std::vector<Param> & paramRef,
1808  const SolverState & ss1,
1809  const DeviceOptions & do1)
1810  : SourceData(ss1,do1),
1811  ACMAG(1.0),
1812  ACPHASE(0.0),
1813  ACMAGgiven(false),
1814  ACPHASEgiven(false)
1815 {
1816  std::vector<Param>::const_iterator iter = paramRef.begin();
1817  std::vector<Param>::const_iterator last = paramRef.end();
1818 
1819  for ( ; iter != last; ++iter)
1820  {
1821  const std::string & tmpname = iter->tag();
1822 
1823  if (tmpname == "ACMAG") { ACMAG = iter->getImmutableValue<double>(); ACMAGgiven = iter->given();}
1824  if (tmpname == "ACPHASE") { ACPHASE = iter->getImmutableValue<double>(); ACPHASEgiven = iter->given();}
1825  }
1826 
1827  typeName_ = "AC";
1828  defaultParamName_ = "ACMAG";
1829 }
1830 
1831 //-----------------------------------------------------------------------------
1832 // Function : ACData::~ACData
1833 // Purpose : destructor
1834 // Special Notes :
1835 // Scope : public
1836 // Creator : Ting Mei, SNL
1837 // Creation Date : 3/16/00
1838 //-----------------------------------------------------------------------------
1839 
1841 {
1842 
1843 }
1844 
1845 #ifdef Xyce_DEBUG_DEVICE
1846 //-----------------------------------------------------------------------------
1847 // Function : ACData::printOutParams
1848 // Purpose :
1849 // Special Notes :
1850 // Scope : public
1851 // Creator : Ting Mei, SNL
1852 // Creation Date : 6/21/00
1853 //-----------------------------------------------------------------------------
1854 
1855 void ACData::printOutParams()
1856 
1857 {
1858  Xyce::dout() << "ACData:\n";
1859  Xyce::dout() << "ACMAG = " << ACMAG << std::endl;
1860  Xyce::dout() << "ACPHASE = " << ACPHASE << std::endl;
1861 }
1862 #endif
1863 
1864 //-----------------------------------------------------------------------------
1865 // Function : ACData::updateSource
1866 // Purpose : Update the sinwave source.
1867 // Special Notes :
1868 //
1869 // Scope : public
1870 // Creator : Ting Mei, SNL
1871 // Creation Date :
1872 //-----------------------------------------------------------------------------
1873 
1875 {
1876  bool bsuccess = true;
1877 
1878  double mpi = M_PI;
1879 
1880  if (!initializeFlag_) bsuccess = initializeSource ();
1881 
1882  if (realFlag_)
1883  {
1884  SourceValue = ACMAG * cos(2.0*mpi*ACPHASE/360);
1885  }
1886  else
1887  {
1888  SourceValue = ACMAG * sin(2.0*mpi*ACPHASE/360);
1889  }
1890 
1891 #ifdef Xyce_DEBUG_DEVICE
1892  if (devOptions_.debugLevel > 0)
1893  {
1894  Xyce::dout() << " SourceValue = " << SourceValue << std::endl;
1895  }
1896 #endif
1897 
1898  resetFlag_ = false;
1899 
1900  return bsuccess;
1901 }
1902 
1903 //-----------------------------------------------------------------------------
1904 // Function : ACData::getParams
1905 // Purpose : Pass back the AC source params.
1906 // Special Notes :
1907 // Scope : public
1908 // Creator : Ting Mei
1909 // Creation Date :
1910 //-----------------------------------------------------------------------------
1911 void ACData::getParams(double *params)
1912 {
1913  params[0] = ACMAG;
1914  params[1] = ACPHASE;
1915  return;
1916 }
1917 
1918 //-----------------------------------------------------------------------------
1919 // Function : ACData::setParams
1920 // Purpose : Update the AC source params.
1921 // Special Notes :
1922 //
1923 // Scope : public
1924 // Creator : Ting Mei
1925 // Creation Date :
1926 //-----------------------------------------------------------------------------
1927 void ACData::setParams(double *params)
1928 {
1929  bool reset=false;
1930  if (ACMAG!= params[0])
1931  {
1932  ACMAG = params[0];
1933  reset = true;
1934  }
1935  if ( ACPHASE != params[1])
1936  {
1937  ACPHASE = params[1];
1938  reset = true;
1939  }
1940  if (reset)
1941  updateSource();
1942 
1943  return;
1944 }
1945 
1946 
1947 // Class ConstData
1948 
1949 //-----------------------------------------------------------------------------
1950 // Function : ConstData::ConstData
1951 // Purpose : copy constructor
1952 // Special Notes :
1953 // Scope : public
1954 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
1955 // Creation Date : 10/5/00
1956 //-----------------------------------------------------------------------------
1958  : SourceData(right),
1959  V0(right.V0)
1960 {
1961 
1962 }
1963 
1964 //-----------------------------------------------------------------------------
1965 // Function : ConstData::ConstData
1966 // Purpose : constructor
1967 // Special Notes :
1968 // Scope : public
1969 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
1970 // Creation Date : 10/5/00
1971 //-----------------------------------------------------------------------------
1972 
1973 ConstData::ConstData( const std::vector<Param> & paramRef,
1974  const SolverState & ss1,
1975  const DeviceOptions & do1)
1976  : SourceData(ss1,do1),
1977  V0(0.0)
1978 {
1979  std::vector<Param>::const_iterator iter = paramRef.begin();
1980  std::vector<Param>::const_iterator last = paramRef.end();
1981 
1982  for ( ; iter != last; ++iter)
1983  {
1984  const std::string & tmpname = iter->tag();
1985  if (tmpname == "DCV0")
1986  {
1987  V0 = iter->getImmutableValue<double>();
1988  }
1989  }
1990 
1991  typeName_ = "CONST";
1992  defaultParamName_ = "DCV0";
1993 // SourceValue = V0; // updateSource function is a no-op, essentially.
1994 }
1995 
1996 //-----------------------------------------------------------------------------
1997 // Function : ConstData::~ConstData
1998 // Purpose : destructor
1999 // Special Notes :
2000 // Scope : public
2001 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
2002 // Creation Date : 10/5/00
2003 //-----------------------------------------------------------------------------
2005 {
2006 
2007 }
2008 
2009 #ifdef Xyce_DEBUG_DEVICE
2010 //-----------------------------------------------------------------------------
2011 // Function : ConstData::printOutParams
2012 // Purpose :
2013 // Special Notes :
2014 // Scope : public
2015 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
2016 // Creation Date : 10/5/00
2017 //-----------------------------------------------------------------------------
2018 
2019 void ConstData::printOutParams()
2020 
2021 {
2022  Xyce::dout() << "ConstData:\n";
2023  Xyce::dout() << "V0: " << V0 << std::endl;
2024 }
2025 #endif
2026 
2027 // Additional Declarations
2028 
2029 //-----------------------------------------------------------------------------
2030 // Function : ConstData::updateSource
2031 // Purpose : Update the const source.
2032 // Special Notes : ERK: this is now a no-op, as the source value is set in
2033 // the constructor. The value for this source never changes,
2034 // so there isn't any point is re-setting the same value
2035 // over and over.
2036 //
2037 // Scope : public
2038 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
2039 // Creation Date : 10/5/00
2040 //-----------------------------------------------------------------------------
2042 {
2043 
2044  bool bsuccess = true;
2045 
2046  if (!initializeFlag_) bsuccess = initializeSource ();
2047 
2048  SourceValue = V0;
2049 
2050  resetFlag_ = false;
2051 
2052  return bsuccess;
2053 
2054 }
2055 
2056 //-----------------------------------------------------------------------------
2057 // Function : ConstData::getParams
2058 // Purpose : Pass back the const source params.
2059 // Special Notes :
2060 //
2061 // Scope : public
2062 // Creator : Dave Shirley, PSSI
2063 // Creation Date : 4/13/05
2064 //-----------------------------------------------------------------------------
2065 void ConstData::getParams(double *params)
2066 {
2067  params[0] = V0;
2068  return;
2069 }
2070 
2071 //-----------------------------------------------------------------------------
2072 // Function : ConstData::setParams
2073 // Purpose : Update the const source params.
2074 // Special Notes :
2075 //
2076 // Scope : public
2077 // Creator : Dave Shirley, PSSI
2078 // Creation Date : 4/13/05
2079 //-----------------------------------------------------------------------------
2080 void ConstData::setParams(double *params)
2081 {
2082  if (V0 != params[0])
2083  {
2084  V0 = params[0];
2085 // SourceValue = V0;
2086  updateSource();
2087  }
2088  return;
2089 }
2090 
2091 
2092 // Class SmoothPulseData
2093 //-----------------------------------------------------------------------------
2094 // Function : SmoothPulseData::SmoothPulseData
2095 // Purpose : copy constructor
2096 // Special Notes :
2097 // Scope : public
2098 // Creator : Richard Schiek, Electrical Systems Modeling
2099 // Creation Date : 04/13/11
2100 //-----------------------------------------------------------------------------
2101 
2103  : SourceData(right),
2104  V1 (right.V1),
2105  V2 (right.V2),
2106  TD (right.TD),
2107  TR (right.TR),
2108  TF (right.TF),
2109  PW (right.PW),
2110  PER (right.PER),
2111  riseScaleFactor_(right.riseScaleFactor_),
2112  fallScaleFactor_(right.fallScaleFactor_),
2113  functionScaleFactor_(right.functionScaleFactor_),
2114  V1given (right.V1given),
2115  V2given (right.V2given),
2116  TDgiven (right.TDgiven),
2117  TRgiven (right.TRgiven),
2118  TFgiven (right.TFgiven),
2119  PWgiven (right.PWgiven),
2120  PERgiven (right.PERgiven),
2121  functionScaleFactorGiven_(right.functionScaleFactorGiven_)
2122 {
2123 
2124 }
2125 
2126 //-----------------------------------------------------------------------------
2127 // Function : SmoothPulseData::SmoothPulseData
2128 // Purpose : constructor
2129 // Special Notes :
2130 // Scope : public
2131 // Creator : Richard Schiek, Electrical Systems Modeling
2132 // Creation Date : 04/13/11
2133 //-----------------------------------------------------------------------------
2134 
2135 SmoothPulseData::SmoothPulseData( const std::vector<Param> & paramRef,
2136  const SolverState & ss1,
2137  const DeviceOptions & do1)
2138  : SourceData (ss1,do1),
2139  V1 (0.0),
2140  V2 (0.0),
2141  TD (0.0),
2142  TR (0.0),
2143  TF (0.0),
2144  PW (0.0),
2145  PER (0.0),
2146  riseScaleFactor_(0.0),
2147  fallScaleFactor_(0.0),
2148  functionScaleFactor_(20.0),
2149  V1given (false),
2150  V2given (false),
2151  TDgiven (false),
2152  TRgiven (false),
2153  TFgiven (false),
2154  PWgiven (false),
2155  PERgiven (false),
2156  functionScaleFactorGiven_(false)
2157 {
2158 
2159  // Get the user-defined values:
2160  std::vector<Param>::const_iterator iter = paramRef.begin();
2161  std::vector<Param>::const_iterator last = paramRef.end();
2162 
2163  for ( ; iter != last; ++iter)
2164  {
2165  const std::string & tmpname = iter->tag();
2166 
2167  if (tmpname == "V1") { V1 = iter->getImmutableValue<double>(); V1given = iter->given();}
2168  if (tmpname == "V2") { V2 = iter->getImmutableValue<double>(); V2given = iter->given();}
2169  if (tmpname == "TD") { TD = iter->getImmutableValue<double>(); TDgiven = iter->given();}
2170  if (tmpname == "TR") { TR = iter->getImmutableValue<double>(); TRgiven = iter->given();}
2171  if (tmpname == "TF") { TF = iter->getImmutableValue<double>(); TFgiven = iter->given();}
2172  if (tmpname == "PW") { PW = iter->getImmutableValue<double>(); PWgiven = iter->given();}
2173  if (tmpname == "PER") { PER = iter->getImmutableValue<double>(); PERgiven = iter->given();}
2174  if (tmpname == "SF") { functionScaleFactor_ = iter->getImmutableValue<double>(); functionScaleFactorGiven_ = iter->given();}
2175  }
2176 
2177  typeName_ = "SMOOTHPULSE";
2178  defaultParamName_ = "V2";
2179 }
2180 
2181 //-----------------------------------------------------------------------------
2182 // Function : SmoothPulseData::~SmoothPulseData
2183 // Purpose : destructor
2184 // Special Notes :
2185 // Scope : public
2186 // Creator : Richard Schiek, Electrical Systems Modeling
2187 // Creation Date : 04/13/11
2188 //-----------------------------------------------------------------------------
2189 
2191 {
2192 
2193 }
2194 
2195 // Additional Declarations
2196 
2197 #ifdef Xyce_DEBUG_DEVICE
2198 //-----------------------------------------------------------------------------
2199 // Function : SmoothPulseData::printOutParams
2200 // Purpose :
2201 // Special Notes :
2202 // Scope : public
2203 // Creator : Richard Schiek, Electrical Systems Modeling
2204 // Creation Date : 04/13/11
2205 //-----------------------------------------------------------------------------
2206 
2207 void SmoothPulseData::printOutParams()
2208 {
2209 
2210  Xyce::dout() << std::endl;
2211  Xyce::dout() << " SmoothPulseData::printOutParams\n";
2212  Xyce::dout() << " V1 = " << V1 << std::endl;
2213  Xyce::dout() << " V2 = " << V2 << std::endl;
2214 
2215  Xyce::dout() << " TD = " << TD << std::endl;
2216  Xyce::dout() << " TR = " << TR << std::endl;
2217  Xyce::dout() << " TF = " << TF << std::endl;
2218  Xyce::dout() << " PW = " << PW << std::endl;
2219  Xyce::dout() << " PER = " << PER << std::endl;
2220  Xyce::dout() << " SF = " << functionScaleFactor_ << std::endl;
2221  Xyce::dout() << std::endl;
2222 
2223 }
2224 #endif
2225 
2226 //-----------------------------------------------------------------------------
2227 // Function : SmoothPulseData::initializeSource
2228 // Purpose :
2229 // Special Notes :
2230 // Scope : public
2231 // Creator : Richard Schiek, Electrical Systems Modeling
2232 // Creation Date : 04/13/11
2233 //-----------------------------------------------------------------------------
2234 
2236 {
2237 
2238  // If neccessary, set the defaults:
2239 
2240  double tstep = solState_.startingTimeStep;
2241  double tstop = solState_.finalTime;
2242 
2243  if (!TDgiven) TD = 0.0;
2244  if (!TRgiven) TR = tstep;
2245  if (!TFgiven) TF = tstep;
2246  if (!PWgiven) PW = tstop;
2247  if (!PERgiven) PER = tstop;
2248  // scale the amplitude of the response so it better joins the low and hi value
2249  // riseFallScaleFactor_ = M_PI;
2250  riseScaleFactor_ = 2.0*fabs( atan(M_PI * functionScaleFactor_ * (0.5*TR) / TR) );
2251  fallScaleFactor_ = 2.0*fabs( atan(M_PI * functionScaleFactor_ * (0.5*TF) / TF) );
2252  initializeFlag_ = true;
2253 
2254  return true;
2255 }
2256 
2257 //-----------------------------------------------------------------------------
2258 // Function : SmoothPulseData::updateSource
2259 // Purpose :
2260 // Special Notes :
2261 // Scope : public
2262 // Creator : Richard Schiek, Electrical Systems Modeling
2263 // Creation Date : 04/13/11
2264 //-----------------------------------------------------------------------------
2265 
2267 
2268 {
2269  bool bsuccess = true;
2270 
2271  if (!initializeFlag_) bsuccess = initializeSource ();
2272 
2273  double basetime = 0;
2274 
2275 #ifdef Xyce_DEBUG_DEVICE
2277  {
2278  Xyce::dout() << " SmoothPulseData::updateSources\n";
2279  printOutParams();
2280  }
2281 #endif
2282 
2283  time = getTime_();
2284 
2285 #ifdef Xyce_DEBUG_DEVICE
2287  {
2288  Xyce::dout() << " Time = " << time << std::endl;
2289  }
2290 #endif
2291 
2292  time -= TD;
2293 
2294  if (time > PER && PER != 0.0)
2295  {
2296  // repeating signal - figure out where we are in period
2297  basetime = PER * floor(time/PER);
2298  time -= basetime;
2299  }
2300 
2301  // This section got ugly because of a nasty roundoff bug.
2302  // Instead of doing "time > X" you need also check that time
2303  // is not within bptol of X.
2304  // So the following translation is used:
2305  // Instead of: we do:
2306  // time > X time>X && fabs(time-x)>bptol
2307  // time <= X time<X || fabs(time-x)<bptol
2308 
2309  if (time <= 0 || (time > (TR + PW + TF) &&
2310  (fabs (time - (TR+PW+TF)) > solState_.bpTol) ) )
2311  {
2312  SourceValue = V1;
2313  }
2314  else if ((time > TR && fabs(time-TR) > solState_.bpTol)
2315  && (time < (TR + PW) || fabs (time-(TR+PW))<solState_.bpTol) )
2316  {
2317  SourceValue = V2;
2318  }
2319  else if (time > 0 &&
2320  (time < TR || fabs(time-TR) < solState_.bpTol))
2321  {
2322  if (TR != 0.0)
2323  SourceValue = V1 + (V2 - V1) *
2324  (((atan(M_PI * functionScaleFactor_ * (time-0.5*TR) / TR))/riseScaleFactor_) + 0.5);
2325  else
2326  SourceValue = V1;
2327  }
2328  else
2329  { // time > (TR + PW) && <= (TR + PW + TF)
2330  if (TF != 0.0)
2331  SourceValue = V2 + (V1 - V2) *
2332  (((atan(M_PI * functionScaleFactor_ * (time - (TR + PW + 0.5*TF)) / TF))/fallScaleFactor_) + 0.5);
2333  else
2334  SourceValue = V2;
2335  }
2336 
2337 #ifdef Xyce_DEBUG_DEVICE
2339  {
2340  Xyce::dout() << " SourceValue = " << SourceValue << std::endl;
2341  }
2342 #endif
2343 
2344  resetFlag_ = false;
2345 
2346  return bsuccess;
2347 }
2348 
2349 //-----------------------------------------------------------------------------
2350 // Function : SmoothPulseData::getParams
2351 // Purpose : Pass back the pulse source params.
2352 // Special Notes :
2353 //
2354 // Scope : public
2355 // Creator : Richard Schiek, Electrical Systems Modeling
2356 // Creation Date : 04/13/11
2357 //-----------------------------------------------------------------------------
2358 void SmoothPulseData::getParams(double *params)
2359 {
2360  params[0] = V1;
2361  params[1] = V2;
2362  params[2] = TD;
2363  params[3] = TR;
2364  params[4] = TF;
2365  params[5] = PW;
2366  params[6] = PER;
2367  return;
2368 }
2369 
2370 //-----------------------------------------------------------------------------
2371 // Function : SmoothPulseData::setParams
2372 // Purpose : Update the pulse source params.
2373 // Special Notes :
2374 //
2375 // Scope : public
2376 // Creator : Richard Schiek, Electrical Systems Modeling
2377 // Creation Date : 04/13/11
2378 //-----------------------------------------------------------------------------
2379 void SmoothPulseData::setParams(double *params)
2380 {
2381  bool reset=false;
2382  if (V1 != params[0])
2383  {
2384  V1 = params[0];
2385  reset = true;
2386  }
2387  if (V2 != params[1])
2388  {
2389  V2 = params[1];
2390  reset = true;
2391  }
2392  if (TD != params[2])
2393  {
2394  TD = params[2];
2395  reset = true;
2396  }
2397  if (TR != params[3])
2398  {
2399  TR = params[3];
2400  reset = true;
2401  }
2402  if (TF != params[4])
2403  {
2404  TF = params[4];
2405  reset = true;
2406  }
2407  if (PW != params[5])
2408  {
2409  PW = params[5];
2410  reset = true;
2411  }
2412  if (PER != params[6])
2413  {
2414  PER = params[6];
2415  reset = true;
2416  }
2417  if (reset)
2418  updateSource();
2419 
2420  return;
2421 }
2422 
2423 //-----------------------------------------------------------------------------
2424 // Function : SmoothPulseData::getBreakPoints
2425 // Purpose : This function adds break points to a vector of breakpoints.
2426 //
2427 // It does not bother to check them in any way, or put them
2428 // in order. It only adds them in.
2429 //
2430 // Special Notes : Like much of this file, this is adapted from spice 3f5.
2431 // Some of the stuff in it is a little hokey, and may get
2432 // removed or modified later.
2433 //
2434 // Scope : public
2435 // Creator : Richard Schiek, Electrical Systems Modeling
2436 // Creation Date : 04/13/11
2437 //-----------------------------------------------------------------------------
2439  (std::vector<N_UTL_BreakPoint> & breakPointTimes )
2440 {
2441  bool bsuccess = true;
2442 
2443  if (!initializeFlag_) bsuccess = initializeSource ();
2444 
2445  return bsuccess;
2446 }
2447 
2448 //-----------------------------------------------------------------------------
2449 // Function : SmoothPulseData::getMaxTimeStepSize
2450 // Purpose :
2451 // Special Notes :
2452 // Scope : public
2453 // Creator : Richard Schiek, Electrical Systems Modeling
2454 // Creation Date : 04/13/11
2455 //-----------------------------------------------------------------------------
2457 {
2458  double maxTimeStep = devOptions_.defaultMaxTimeStep;
2459 
2460  // check if we are still in the delay or not.
2461  time = getTime_();
2462 
2463  if (time < TD) maxTimeStep = (0.1*TD );
2464  else maxTimeStep = (0.1*PER);
2465 
2466 #ifdef Xyce_DEBUG_DEVICE
2468  {
2469  Xyce::dout() << "\nIn SmoothPulseData::getMaxTimeStepSize. ";
2470  Xyce::dout() << " maxTimeStep = "<< maxTimeStep;
2471  Xyce::dout() << " TD = " << TD << " PER = " <<PER;
2472  Xyce::dout() << " time = "<< time << std::endl;
2473  }
2474 #endif
2475 
2476  return maxTimeStep;
2477 }
2478 
2479 } // namespace Device
2480 } // namespace Xyce