Xyce  6.1
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-2015 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-----------------------------------------------------------------------------
26 // Filename : $RCSfile: N_DEV_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.96.2.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:20:11 $
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_UTL_fwd.h>
51 
52 #include <N_DEV_Configuration.h>
53 #include <N_DEV_DeviceInstance.h>
54 #include <N_DEV_DeviceModel.h>
55 
56 namespace Xyce {
57 namespace Device {
58 namespace TRA {
59 
60 class Model;
61 class Instance;
62 class History;
63 
64 struct Traits : public DeviceTraits<Model, Instance>
65 {
66  static const char *name() {return "Ideal Transmission Line";}
67  static const char *deviceTypeName() {return "T level 1";}
68  static int numNodes() {return 4;}
69  static bool isLinearDevice() {return true;}
70 
71  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
72  static void loadModelParameters(ParametricData<Model> &model_parameters);
73  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
74 };
75 
76 //-----------------------------------------------------------------------------
77 // Class : Instance
78 // Purpose :
79 // Special Notes :
80 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
81 // Creation Date : 3/16/00
82 //-----------------------------------------------------------------------------
83 class Instance : public DeviceInstance
84 {
85  friend class ParametricData<Instance>;
86  friend class Model;
87  friend class Traits;
88 
89 public:
90  Instance(
91  const Configuration & configuration,
92  const InstanceBlock & instance_block,
93  Model & model,
94  const FactoryBlock & factory_block);
95 
96  ~Instance();
97 
98 private:
99  Instance(const Instance &);
100  Instance &operator=(const Instance &);
101 
102 public:
103  void registerLIDs( const std::vector<int> & intLIDVecRef,
104  const std::vector<int> & extLIDVecRef );
105  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
106  void registerStoreLIDs( const std::vector<int> & st0LIDVecRef );
107 
108  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
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<Util::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;
289  double timeOld;
290 
293 };
294 
295 //-----------------------------------------------------------------------------
296 // Class : History
297 // Purpose : Provide a structure to save internal state history
298 // Special Notes :
299 // Creator : Tom Russo, SNL, Component Information and Models
300 // Creation Date : 6/14/2001
301 //-----------------------------------------------------------------------------
302 class History
303 {
304  friend class Instance;
305  friend class Traits;public:
306  History();
307  History(const History &right);
308  History(double t, double v1, double v2);
309  ~History();
310  inline bool operator<(const double &test_t) const;
311 
312 private:
313  double t;
314  double v1;
315  double v2;
316 };
317 
318 //-----------------------------------------------------------------------------
319 // Class : Model
320 // Purpose :
321 // Special Notes :
322 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
323 // Creation Date : 3/16/00
324 //-----------------------------------------------------------------------------
325 class Model : public DeviceModel
326 {
327  typedef std::vector<Instance *> InstanceVector;
328 
329  friend class ParametricData<Model>;
330  friend class Instance;
331  friend class Traits;
332 
333 public:
334  Model(
335  const Configuration & configuration,
336  const ModelBlock & MB,
337  const FactoryBlock & factory_block);
338  ~Model();
339 
340 private:
341  Model();
342  Model(const Model &);
343  Model &operator=(const Model &);
344 
345 public:
346  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
347 
348  virtual std::ostream &printOutInstances(std::ostream &os) const;
349  bool processParams ();
350  bool processInstanceParams ();
351 
352 
353 public:
354  void addInstance(Instance *instance)
355  {
356  instanceContainer.push_back(instance);
357  }
358 
359 private:
360  std::vector<Instance*> instanceContainer;
361 private:
362 
363 };
364 
365 //-----------------------------------------------------------------------------
366 // Function : History::operator<
367 // Purpose : compare used in the lower_bound operation. Returns
368 // true if the time in the history object is less than
369 // the given time (double)
370 // Special Notes :
371 // Scope : private
372 // Creator : Tom Russo, SNL, Component Information and Models
373 // Creation Date : 7/27/2005
374 //-----------------------------------------------------------------------------
375 inline bool History::operator<(const double &test_t) const
376 {
377  return (t < test_t);
378 }
379 
380 void registerDevice();
381 
382 } // namespace TRA
383 } // namespace Device
384 } // namespace Xyce
385 
386 #endif
void InterpV1V2FromHistory(double t, double *v1p, double *v2p)
Definition: N_DEV_TRA.C:904
static const char * name()
Definition: N_DEV_TRA.h:66
void registerDevice()
Definition: N_DEV_TRA.C:1551
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Definition: N_DEV_TRA.C:1471
Pure virtual class to augment a linear system.
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_TRA.C:432
static const char * deviceTypeName()
Definition: N_DEV_TRA.h:67
DeviceState * getInternalState()
Definition: N_DEV_TRA.C:1234
void pruneHistory(double t)
Definition: N_DEV_TRA.C:825
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_TRA.C:365
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_TRA.C:1429
bool getInstanceBreakPoints(std::vector< Util::BreakPoint > &breakPointTimes)
Definition: N_DEV_TRA.C:1046
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_TRA.C:307
bool processInstanceParams()
processInstanceParams
Definition: N_DEV_TRA.C:1369
static int numNodes()
Definition: N_DEV_TRA.h:68
std::vector< Instance * > InstanceVector
Definition: N_DEV_TRA.h:327
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
Instance & operator=(const Instance &)
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_TRA.C:419
bool setInternalState(const DeviceState &state)
Definition: N_DEV_TRA.C:1291
Instance(const Configuration &configuration, const InstanceBlock &instance_block, Model &model, const FactoryBlock &factory_block)
Definition: N_DEV_TRA.C:108
std::vector< Instance * > instanceContainer
Definition: N_DEV_TRA.h:360
static bool isLinearDevice()
Definition: N_DEV_TRA.h:69
static std::vector< std::vector< int > > jacStamp
Definition: N_DEV_TRA.h:145
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
void registerStoreLIDs(const std::vector< int > &st0LIDVecRef)
Definition: N_DEV_TRA.C:400
Model & operator=(const Model &)
void addInstance(Instance *instance)
Definition: N_DEV_TRA.h:354
Class Configuration contains device configuration data.
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_TRA.C:71
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_TRA.C:1545
bool operator<(const double &test_t) const
Definition: N_DEV_TRA.h:375
std::vector< History > history
Definition: N_DEV_TRA.h:288
bool processParams()
processParams
Definition: N_DEV_TRA.C:1355
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_TRA.C:93
ModelBlock represents a .MODEL line from the netlist.
The DeviceTraits template describes the configuration of a device.
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
InstanceBlock represent a device instance line from the netlist.
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_TRA.C:387