Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_TRA.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_TRA.h,v $
27 //
28 // Purpose : Transmission line.
29 //
30 // Special Notes :
31 //
32 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 02/28/00
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.89.2.1 $
40 //
41 // Revision Date : $Date: 2014/02/26 20:16:30 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_TRA_h
47 #define Xyce_N_DEV_TRA_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceInstance.h>
52 #include <N_DEV_DeviceModel.h>
53 #include <N_UTL_BreakPoint.h>
54 
55 namespace Xyce {
56 namespace Device {
57 namespace TRA {
58 
59 class Model;
60 class Instance;
61 class History;
62 
63 struct Traits : public DeviceTraits<Model, Instance>
64 {
65  static const char *name() {return "Ideal Transmission Line";}
66  static const char *deviceTypeName() {return "T level 1";}
67  static const int numNodes() {return 4;}
68  static const bool isLinearDevice() {return true;}
69 
70  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
71  static void loadModelParameters(ParametricData<Model> &model_parameters);
72  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
73 };
74 
75 //-----------------------------------------------------------------------------
76 // Class : Instance
77 // Purpose :
78 // Special Notes :
79 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
80 // Creation Date : 3/16/00
81 //-----------------------------------------------------------------------------
82 class Instance : public DeviceInstance
83 {
84  friend class ParametricData<Instance>;
85  friend class Model;
86  friend class Traits;
87 
88 public:
89  Instance(
90  const Configuration & configuration,
91  const InstanceBlock & instance_block,
92  Model & model,
93  const FactoryBlock & factory_block);
94 
95  ~Instance();
96 
97 private:
98  Instance(const Instance &);
99  Instance &operator=(const Instance &);
100 
101 public:
102  void registerLIDs( const std::vector<int> & intLIDVecRef,
103  const std::vector<int> & extLIDVecRef );
104  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
105  void registerStoreLIDs( const std::vector<int> & st0LIDVecRef );
106 
107  std::map<int,std::string> & getIntNameMap ();
108  std::map<int,std::string> & getStoreNameMap ();
109 
110  const std::vector< std::vector<int> > & jacobianStamp() const;
111  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
112 
113  bool processParams ();
114  bool updateIntermediateVars ();
115  bool updatePrimaryState ();
116 
117  // load functions, residual:
118  bool loadDAEQVector () {return true;}
119  bool loadDAEFVector ();
120 
121  // load functions, Jacobian:
122  bool loadDAEdQdx () {return true;}
123  bool loadDAEdFdx ();
124 
125  bool getInstanceBreakPoints (std::vector<N_UTL_BreakPoint> &breakPointTimes);
126  void acceptStep();
127 
128  double getMaxTimeStepSize();
129 
131  bool setInternalState( const DeviceState & state );
132 
133 private:
134  void pruneHistory(double t);
135  void InterpV1V2FromHistory(double t, double * v1p , double * v2p);
136 
137 public:
138  // Getters and setters
140  {
141  return model_;
142  }
143 
144 private:
145  static std::vector< std::vector<int> > jacStamp;
146 
147  Model & model_; //< Owning model
148 
149  double Z0; // Characteristic impedence
150  double ZO;
151  double G0; // Conductance
152  double td; // Time delay (= NL/freq if given that way)
153  double freq; // frequency
154  double NL; // Normalized length
155  // Flags
156  // not supporting initial condition just yet... this is An Issue, I think
157  // double IC_V12, IC_V34, IC_I1, IC_I2;
158 
159  bool DCMODE;
160  // Matrix equation index variables
161  // solution vector indicies
162 #if 0
163  int xPos1Var_J; // pos and negative port nodes
164  int xNeg1Var_J; // .....
165  int xInt1Var_J; // Internal variable for port 1
166  int xIbr1Var_J; // Branch current
167  int xPos2Var_J; // Duplicate above for second port
168  int xNeg2Var_J;
169  int xInt2Var_J;
170  int xIbr2Var_J;
171 #endif
172  // KCL equation indices
173 #if 0
174  int bPos1Equ_I;
175  int bNeg1Equ_I;
176  int bInt1Equ_I;
177  int bIbr1Equ_I;
178  int bPos2Equ_I;
179  int bNeg2Equ_I;
180  int bInt2Equ_I;
181  int bIbr2Equ_I;
182 #endif
183  // local indices (offsets)
184  int li_Pos1;
185  int li_Neg1;
186  int li_Int1;
187  int li_Ibr1;
188  int li_Pos2;
189  int li_Neg2;
190  int li_Int2;
191  int li_Ibr2;
192 
193  // indices into store vec for lead currents if needed
196 
197 
198  // Matrix elements
199 #if 0
200  int APos1EquPos1Node_I;
201  int APos1EquPos1Node_J;
202  int APos1EquInt1Node_I;
203  int APos1EquInt1Node_J;
204 
205  int AInt1EquPos1Node_I;
206  int AInt1EquPos1Node_J;
207  int AInt1EquInt1Node_I;
208  int AInt1EquInt1Node_J;
209  int AInt1EquIbr1Node_I;
210  int AInt1EquIbr1Node_J;
211 
212  int ANeg1EquIbr1Node_I;
213  int ANeg1EquIbr1Node_J;
214 
215  int AIbr1EquInt1Node_I;
216  int AIbr1EquInt1Node_J;
217  int AIbr1EquNeg1Node_I;
218  int AIbr1EquNeg1Node_J;
219 
220  int APos2EquPos2Node_I;
221  int APos2EquPos2Node_J;
222  int APos2EquInt2Node_I;
223  int APos2EquInt2Node_J;
224 
225  int AInt2EquPos2Node_I;
226  int AInt2EquPos2Node_J;
227  int AInt2EquInt2Node_I;
228  int AInt2EquInt2Node_J;
229  int AInt2EquIbr2Node_I;
230  int AInt2EquIbr2Node_J;
231 
232  int ANeg2EquIbr2Node_I;
233  int ANeg2EquIbr2Node_J;
234 
235  int AIbr2EquInt2Node_I;
236  int AIbr2EquInt2Node_J;
237  int AIbr2EquNeg2Node_I;
238  int AIbr2EquNeg2Node_J;
239 
240  // for DC simulations these 6 pairs get filled because v1 and v2 reduce
241  // to V1=Ibr2*Z0 and V2=Ibr1*Z0 and no time delay
242  int AIbr1EquPos2Node_I;
243  int AIbr1EquPos2Node_J;
244  int AIbr1EquNeg2Node_I;
245  int AIbr1EquNeg2Node_J;
246  int AIbr1EquIbr2Node_I;
247  int AIbr1EquIbr2Node_J;
248 
249  int AIbr2EquPos1Node_I;
250  int AIbr2EquPos1Node_J;
251  int AIbr2EquNeg1Node_I;
252  int AIbr2EquNeg1Node_J;
253  int AIbr2EquIbr1Node_I;
254  int AIbr2EquIbr1Node_J;
255 #endif
256  // Matrix equation offset variables
265  // for DC simulations these 6 pairs get filled because v1 and v2 reduce
266  // to V1=Ibr2*Z0 and V2=Ibr1*Z0 and no time delay
281 
282  double Vpos1,Vpos2,Vneg1,Vneg2,Vint1,Vint2,Ibr1,Ibr2; // solution vars
283  double last_t; // "primary" state variables
284  double v1; //
285  double v2; //
287 
288  std::vector<History> history;
290  double timeOld;
291 
294 };
295 
296 //-----------------------------------------------------------------------------
297 // Class : History
298 // Purpose : Provide a structure to save internal state history
299 // Special Notes :
300 // Creator : Tom Russo, SNL, Component Information and Models
301 // Creation Date : 6/14/2001
302 //-----------------------------------------------------------------------------
303 class History
304 {
305  friend class Instance;
306  friend class Traits;public:
307  History();
308  History(const History &right);
309  History(double t, double v1, double v2);
310  ~History();
311  inline bool operator<(const double &test_t) const;
312 
313 private:
314  double t;
315  double v1;
316  double v2;
317 };
318 
319 //-----------------------------------------------------------------------------
320 // Class : Model
321 // Purpose :
322 // Special Notes :
323 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
324 // Creation Date : 3/16/00
325 //-----------------------------------------------------------------------------
326 class Model : public DeviceModel
327 {
328  typedef std::vector<Instance *> InstanceVector;
329 
330  friend class ParametricData<Model>;
331  friend class Instance;
332  friend class Traits;
333 
334 public:
335  Model(
336  const Configuration & configuration,
337  const ModelBlock & MB,
338  const FactoryBlock & factory_block);
339  ~Model();
340 
341 private:
342  Model();
343  Model(const Model &);
344  Model &operator=(const Model &);
345 
346 public:
347  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
348 
349  virtual std::ostream &printOutInstances(std::ostream &os) const;
350  bool processParams ();
351  bool processInstanceParams ();
352 
353 
354 public:
355  void addInstance(Instance *instance)
356  {
357  instanceContainer.push_back(instance);
358  }
359 
361  {
362  return instanceContainer;
363  }
364 
366  {
367  return instanceContainer;
368  }
369 
370 private:
371  std::vector<Instance*> instanceContainer;
372 private:
373 
374 };
375 
376 //-----------------------------------------------------------------------------
377 // Function : History::operator<
378 // Purpose : compare used in the lower_bound operation. Returns
379 // true if the time in the history object is less than
380 // the given time (double)
381 // Special Notes :
382 // Scope : private
383 // Creator : Tom Russo, SNL, Component Information and Models
384 // Creation Date : 7/27/2005
385 //-----------------------------------------------------------------------------
386 inline bool History::operator<(const double &test_t) const
387 {
388  return (t < test_t);
389 }
390 
391 void registerDevice();
392 
393 } // namespace TRA
394 } // namespace Device
395 } // namespace Xyce
396 
400 
401 #endif