Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_LTRA.h
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_LTRA.h,v $
27 //
28 // Purpose : Transmission line.
29 //
30 // Special Notes :
31 //
32 // Creator : Eric R. Keiter, SNL
33 //
34 // Creation Date : 06/16/10
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.38.2.2 $
40 //
41 // Revision Date : $Date: 2014/03/04 23:50:54 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_LTRA_h
47 #define Xyce_N_DEV_LTRA_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceMaster.h>
52 #include <N_DEV_DeviceInstance.h>
53 #include <N_DEV_DeviceModel.h>
54 #include <N_UTL_BreakPoint.h>
55 
56 // device parameters
57 #define LTRA_MOD_LTRA 0
58 #define LTRA_MOD_R 1
59 #define LTRA_MOD_L 2
60 #define LTRA_MOD_G 3
61 #define LTRA_MOD_C 4
62 #define LTRA_MOD_LEN 5
63 #define LTRA_V1 6
64 #define LTRA_I1 7
65 #define LTRA_V2 8
66 #define LTRA_I2 9
67 #define LTRA_IC 10
68 #define LTRA_MOD_RELTOL 11
69 #define LTRA_MOD_ABSTOL 12
70 #define LTRA_POS_NODE1 13
71 #define LTRA_NEG_NODE1 14
72 #define LTRA_POS_NODE2 15
73 #define LTRA_NEG_NODE2 16
74 #define LTRA_INPUT1 17
75 #define LTRA_INPUT2 18
76 #define LTRA_DELAY 19
77 #define LTRA_BR_EQ1 20
78 #define LTRA_BR_EQ2 21
79 #define LTRA_MOD_NL 22
80 #define LTRA_MOD_FREQ 23
81 
82 #define LTRA_MOD_FULLCONTROL 26
83 #define LTRA_MOD_HALFCONTROL 27
84 #define LTRA_MOD_NOCONTROL 28
85 #define LTRA_MOD_PRINT 29
86 #define LTRA_MOD_NOPRINT 30
87 
88 #define LTRA_MOD_STEPLIMIT 32
89 #define LTRA_MOD_NOSTEPLIMIT 33
90 #define LTRA_MOD_LININTERP 34
91 #define LTRA_MOD_QUADINTERP 35
92 #define LTRA_MOD_MIXEDINTERP 36
93 #define LTRA_MOD_RLC 37
94 #define LTRA_MOD_RC 38
95 #define LTRA_MOD_RG 39
96 #define LTRA_MOD_LC 40
97 #define LTRA_MOD_RL 41
98 #define LTRA_MOD_STLINEREL 42
99 #define LTRA_MOD_STLINEABS 43
100 #define LTRA_MOD_CHOPREL 44
101 #define LTRA_MOD_CHOPABS 45
102 #define LTRA_MOD_TRUNCNR 46
103 #define LTRA_MOD_TRUNCDONTCUT 47
104 
105 namespace Xyce {
106 namespace Device {
107 namespace LTRA {
108 
109 class Model;
110 class Instance;
111 
112 struct Traits : public DeviceTraits<Model, Instance>
113 {
114  static const char *name() {return "Lossy Transmission Line";}
115  static const char *deviceTypeName() {return "O level 1";}
116  static const int numNodes() {return 4;}
117  static const bool modelRequired() {return true;}
118  static const bool isLinearDevice() {return true;}
119 
120  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
121  static void loadModelParameters(ParametricData<Model> &model_parameters);
122  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
123 };
124 
125 //-----------------------------------------------------------------------------
126 // Class : Instance
127 // Purpose :
128 // Special Notes :
129 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
130 // Creation Date : 3/16/00
131 //-----------------------------------------------------------------------------
132 class Instance : public DeviceInstance
133 {
134  friend class ParametricData<Instance>;
135  friend class Model;
136  friend class Traits;friend class Master;
137 
138 public:
139  Instance(
140  const Configuration & configuration,
141  const InstanceBlock & instance_block,
142  Model & model,
143  const FactoryBlock & factory_block);
144 
145  ~Instance();
146 
147 private:
148  Instance(const Instance &);
149  Instance &operator=(const Instance &);
150 
151 public:
152  void registerLIDs( const std::vector<int> & intLIDVecRef,
153  const std::vector<int> & extLIDVecRef );
154  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
155 
156  std::map<int,std::string> & getIntNameMap ();
157 
158  const std::vector< std::vector<int> > & jacobianStamp() const;
159  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
160 
161  bool processParams ();
162  bool updateIntermediateVars ();
163  bool updatePrimaryState ();
164  bool updateSecondaryState ();
165 
166  bool loadDAEQVector () {return true;}
167  bool loadDAEFVector ();
168 
169  bool loadDAEdQdx () {return true;}
170  bool loadDAEdFdx ();
171 
172  void setupPointers();
173 
174  bool getInstanceBreakPoints (std::vector<N_UTL_BreakPoint> &breakPointTimes);
175  void acceptStep();
176 
177  double getMaxTimeStepSize();
178 
180  bool setInternalState( const DeviceState & state );
181  bool setIC();
182 
183 public:
185  {
186  return model_;
187  }
188 
189 private:
190  static std::vector< std::vector<int> > jacStamp;
191 
192  Model & model_; //< Owning model
193 
194  void calculateMaxTimeStep_(void); // Calculate a maximum time step size to minimize errors
195 
196  double input1; // accumulated excitation for port 1
197  double input2; // accumulated excitation for port 2
198 
199  double currp1; // Current at port 1
200  double currp2; // Current at port 2
201 
202  double vpos1; // Voltage at port 1 positive node
203  double vneg1; // Voltage at port 1 negative node
204 
205  double vpos2; // Voltage at port 2 positive node
206  double vneg2; // Voltage at port 2 negative node
207 
208  double initVolt1; // initial condition: voltage on port 1
209  double initVolt2; // initial condition: voltage on port 2
210 
211  double initCur1; // initial condition: current at port 1
212  double initCur2; // initial condition: current at port 2
213 
214  std::vector<double> v1; // past values of voltage at port 1
215  std::vector<double> v2; // past values of voltage at port 2
216 
217  std::vector<double> i1; // past values of current at port 1
218  std::vector<double> i2; // past values of current at port 2
219 
220  size_t listSize; // Size of variables vectors above
221 
224 
227 
228  // local indices (offsets)
229  int li_Pos1;
230  int li_Neg1;
231 
232  int li_Pos2;
233  int li_Neg2;
234 
235  int li_Ibr1;
236  int li_Ibr2;
237 
238  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
239  // Matrix elements
240  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
241 
242  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
243  // Matrix equation offset variables
244  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
245  // Positive Node1
248  // Negative Node1
251  // Positive Node2
254  // Negative Node1
257  // Branch1 equation due to Jajeet LTRA
264  // Branch2 equation due to Jajeet LTRA
271 
272  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
273  // Entries in matrix corresponding to offsets above
274  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
275  double *pos1Pos1Ptr;
276  double *pos1Ibr1Ptr;
277 
278  double *neg1Neg1Ptr;
279  double *neg1Ibr1Ptr;
280 
281  double *pos2Pos2Ptr;
282  double *pos2Ibr2Ptr;
283 
284  double *neg2Neg2Ptr;
285  double *neg2Ibr2Ptr;
286 
287  double *ibr1Pos1Ptr;
288  double *ibr1Neg1Ptr;
289  double *ibr1Pos2Ptr;
290  double *ibr1Neg2Ptr;
291  double *ibr1Ibr1Ptr;
292  double *ibr1Ibr2Ptr;
293 
294  double *ibr2Pos1Ptr;
295  double *ibr2Neg1Ptr;
296  double *ibr2Pos2Ptr;
297  double *ibr2Neg2Ptr;
298  double *ibr2Ibr1Ptr;
299  double *ibr2Ibr2Ptr;
300 
302 
305 };
306 
307 //-----------------------------------------------------------------------------
308 // Class : Model
309 // Purpose :
310 // Special Notes :
311 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
312 // Creation Date : 3/16/00
313 //-----------------------------------------------------------------------------
314 class Model : public DeviceModel
315 {
316  typedef std::vector<Instance *> InstanceVector;
317 
318  friend class ParametricData<Model>;
319  friend class Instance;
320  friend class Traits;friend class Master;
321 
322 public:
323  Model(
324  const Configuration & configuration,
325  const ModelBlock & MB,
326  const FactoryBlock & factory_block);
327  ~Model();
328 
329 private:
330  Model();
331  Model(const Model &);
332  Model &operator=(const Model &);
333 
334 public:
335  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
336 
337  virtual std::ostream &printOutInstances(std::ostream &os) const;
338  bool processParams ();
339  bool processInstanceParams ();
340 
341 private:
342 
343  int quadInterp_ (double t, double t1, double t2, double t3, double& c1, double& c2, double& c3);
344  int linInterp_ (double t, double t1, double t2, double& c1, double& c2);
345  double intlinfunc_ (double lolimit, double hilimit,
346  double lovalue, double hivalue,
347  double t1, double t2);
348  double twiceintlinfunc_(double lolimit, double hilimit,
349  double otherlolimit, double lovalue,
350  double hivalue, double t1, double t2);
351  double thriceintlinfunc_(double lolimit, double hilimit,
352  double secondlolimit, double thirdlolimit,
353  double lovalue, double hivalue,
354  double t1, double t2);
355 
356  bool modelCalculations_(int& isaved, double& qf1, double& qf2, double& qf3,
357  double& lf2, double& lf3);
358 
359  // from numerical recipies in C:
360  double bessI0_(double x);
361  double bessI1_(double x);
362  double bessI1xOverX_(double x);
363 
364  double rlcH1dashFunc_(double time, double T, double alpha, double beta);
365  double rlcH2Func_(double time, double T, double alpha, double beta);
366  double rlcH3dashFunc_(double time, double T, double alpha, double beta);
367  double rlcH1dashTwiceIntFunc_(double time, double beta);
368  double rlcH3dashIntFunc_(double time, double T, double beta);
369  double rcH1dashTwiceIntFunc_(double time, double cbyr);
370  double rcH2TwiceIntFunc_(double time, double rclsqr);
371 
372  double rcH3dashTwiceIntFunc_(double time, double cbyr, double rclsqr);
373 
374  // coefficient setups:
375  void rcCoeffsSetup_(
376  double & h1dashfirstcoeff,
377  double & h2firstcoeff,
378  double & h3dashfirstcoeff,
379  std::vector<double> & h1dashcoeffs,
380  std::vector<double> & h2coeffs,
381  std::vector<double> & h3dashcoeffs,
382  size_t listsize, double cbyr, double rclsqr, double curtime,
383  const std::vector<double> & timelist, int timeindex, double reltol);
384 
385  void rlcCoeffsSetup_(
386  double & h1dashfirstcoeff, double & h2firstcoeff, double & h3dashfirstcoeff,
387  std::vector<double> & h1dashcoeffs, std::vector<double> & h2coeffs, std::vector<double> & h3dashcoeffs,
388  size_t listsize, double T, double alpha, double beta, double curtime,
389  const std::vector<double> & timelist, int timeindex, double reltol, int *auxindexptr);
390 
391  bool straightLineCheck_(double x1, double y1,
392  double x2, double y2,
393  double x3, double y3,
394  double reltol, double abstol);
395 
396 
397 
398  double lteCalculate_ ( Instance & instance,
399  double curtime );
400 
401  double SECONDDERIV_(int i, double a, double b, double c);
402 
403 
404 public:
405  void addInstance(Instance *instance)
406  {
407  instanceContainer.push_back(instance);
408  }
409 
411  {
412  return instanceContainer;
413  }
414 
416  {
417  return instanceContainer;
418  }
419 
420 private:
421  std::vector<Instance*> instanceContainer;
422 
423 private:
424 
425 
426  double h1dashFirstVal; // first needed value of h1dasg at current timepoint
427  double h2FirstVal; // first needed value of h2 at current timepoint
428  double h3dashFirstVal; // first needed value of h3dash at current timepoint
429 
430  double h1dashFirstCoeff; // first needed coeff of h1dash for the current timepoint
431  double h2FirstCoeff; // first needed coeff of h2 for the current timepoint
432  double h3dashFirstCoeff; // first needed coeff of h3dash for the current timepoint
433 
434  std::vector<double> h1dashCoeffs; // list of other coefficients for h1dash
435  std::vector<double> h2Coeffs; // list of other coefficients for h2
436  std::vector<double> h3dashCoeffs; // list of other coefficients for h3dash
437 
438  size_t listSize; // size of above lists
439 
440  // input parameters:
441  double resist;
442  double induct;
443  double conduct;
444  double capac;
445  double length;
446  double reltol;
447  double abstol;
448 
449  bool noStepLimit; // Don't limit step size to less than line delay
450  bool stepLimit; // Do limit step size to less than line delay
452  // (These could be combined into a single
453  // bool, but preserving spice3 compatibility)
454 
455  bool linInterp;
458 
459  double stLineReltol;
460  double stLineAbstol;
461 
462  bool lteTimeStepControl; // indicates whether full time step
463  // control using local-truncation
464  // error estimation is performed
465 
466  bool truncNR;
468 
486 
487  // calculated parameters
488  double td; // propagation delay T - calculated
489  double imped; // impedance Z - calculated
490  double admit; // admittance Y - calculated
491  double alpha; // alpha - calculated
492  double beta; // beta - calculated
493  double attenuation; // e^(-beta T) - calculated
494  double cByR; // C/R - for the RC line - calculated
495  double rclsqr; // RCl^2 - for the RC line - calculated
496  double intH1dash; // \int_0^\inf h'_1(\tau) d \tau - calculated
497  double intH2; // \int_0^\inf h_2(\tau) d \tau - calculated
498  double intH3dash; // \int_0^\inf h'_3(\tau) d \tau - calculated
499 
500  double coshlrootGR; // cosh(l*sqrt(G*R)), used for DC analysis
501  double rRsLrGRorG; // sqrt(R)*sinh(l*sqrt(G*R))/sqrt(G)
502  double rGsLrGRorR; // sqrt(G)*sinh(l*sqrt(G*R))/sqrt(R)
503 
504  int auxIndex; // auxiliary index for h2 and h3dash
505  double chopReltol; // separate reltol for truncation of impulse responses
506  double chopAbstol; // separate abstol for truncation of impulse responses
507 
508  double maxSafeStep; // maximum safe step for impulse response calculations
509  double maxTimeStep; // maximum time step to be used
510  int howToInterp; // indicates how to interpolate for delayed timepoint
511  bool printFlag; // flag to indicate whether debugging output should be printed
512 
513  int specialCase; // what kind of model (RC, RLC, RL, ...)
514 
515  bool tdover;
516 
517  bool restartStoredFlag; // flag to indicate if this particular model has
518  // been saved to the restart file already (restart
519  // functions are instance functions, so the potential
520  // exists for storing same model multiple times.)
521 };
522 
523 //-----------------------------------------------------------------------------
524 // Class : Master
525 // Purpose :
526 // Special Notes :
527 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
528 // Creation Date : 11/26/08
529 //-----------------------------------------------------------------------------
530 class Master : public DeviceMaster<Traits>
531 {
532  friend class Instance;
533  friend class Model;
534 
535 public:
537  const Configuration & configuration,
538  const FactoryBlock & factory_block,
539  const SolverState & ss1,
540  const DeviceOptions & do1)
541  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1),
542  vars_initialized(false)
543  {}
544 
545  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
546  virtual bool updateSecondaryState (double * staDeriv, double * stoVec) {return true;}
547 
548  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * storeLeadF, double * storeLeadQ);
549  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
550 
551 private:
553 
554  void initialize_vars_();
555 };
556 
557 void registerDevice();
558 
559 } // namespace LTRA
560 } // namespace Device
561 } // namespace Xyce
562 
566 
567 #endif