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.98 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:24 $
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  bool isLinearDevice() const { return true; }
104 
105  void registerLIDs( const std::vector<int> & intLIDVecRef,
106  const std::vector<int> & extLIDVecRef );
107  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
108  void registerStoreLIDs( const std::vector<int> & st0LIDVecRef );
109 
110  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
111 
112  const std::vector< std::vector<int> > & jacobianStamp() const;
113  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
114 
115  bool processParams ();
116  bool updateIntermediateVars ();
117  bool updatePrimaryState ();
118 
119  // load functions, residual:
120  bool loadDAEQVector () {return true;}
121  bool loadDAEFVector ();
122 
123  // load functions, Jacobian:
124  bool loadDAEdQdx () {return true;}
125  bool loadDAEdFdx ();
126 
127  bool getInstanceBreakPoints (std::vector<Util::BreakPoint> &breakPointTimes);
128  void acceptStep();
129 
130  double getMaxTimeStepSize();
131 
133  bool setInternalState( const DeviceState & state );
134 
135 private:
136  void pruneHistory(double t);
137  void InterpV1V2FromHistory(double t, double * v1p , double * v2p);
138 
139 public:
140  // Getters and setters
142  {
143  return model_;
144  }
145 
146 private:
147  static std::vector< std::vector<int> > jacStamp;
148 
149  Model & model_; //< Owning model
150 
151  double Z0; // Characteristic impedence
152  double ZO;
153  double G0; // Conductance
154  double td; // Time delay (= NL/freq if given that way)
155  double freq; // frequency
156  double NL; // Normalized length
157  // Flags
158  // not supporting initial condition just yet... this is An Issue, I think
159  // double IC_V12, IC_V34, IC_I1, IC_I2;
160 
161  bool DCMODE;
162  // Matrix equation index variables
163  // solution vector indicies
164 #if 0
165  int xPos1Var_J; // pos and negative port nodes
166  int xNeg1Var_J; // .....
167  int xInt1Var_J; // Internal variable for port 1
168  int xIbr1Var_J; // Branch current
169  int xPos2Var_J; // Duplicate above for second port
170  int xNeg2Var_J;
171  int xInt2Var_J;
172  int xIbr2Var_J;
173 #endif
174  // KCL equation indices
175 #if 0
176  int bPos1Equ_I;
177  int bNeg1Equ_I;
178  int bInt1Equ_I;
179  int bIbr1Equ_I;
180  int bPos2Equ_I;
181  int bNeg2Equ_I;
182  int bInt2Equ_I;
183  int bIbr2Equ_I;
184 #endif
185  // local indices (offsets)
186  int li_Pos1;
187  int li_Neg1;
188  int li_Int1;
189  int li_Ibr1;
190  int li_Pos2;
191  int li_Neg2;
192  int li_Int2;
193  int li_Ibr2;
194 
195  // indices into store vec for lead currents if needed
198 
199 
200  // Matrix elements
201 #if 0
202  int APos1EquPos1Node_I;
203  int APos1EquPos1Node_J;
204  int APos1EquInt1Node_I;
205  int APos1EquInt1Node_J;
206 
207  int AInt1EquPos1Node_I;
208  int AInt1EquPos1Node_J;
209  int AInt1EquInt1Node_I;
210  int AInt1EquInt1Node_J;
211  int AInt1EquIbr1Node_I;
212  int AInt1EquIbr1Node_J;
213 
214  int ANeg1EquIbr1Node_I;
215  int ANeg1EquIbr1Node_J;
216 
217  int AIbr1EquInt1Node_I;
218  int AIbr1EquInt1Node_J;
219  int AIbr1EquNeg1Node_I;
220  int AIbr1EquNeg1Node_J;
221 
222  int APos2EquPos2Node_I;
223  int APos2EquPos2Node_J;
224  int APos2EquInt2Node_I;
225  int APos2EquInt2Node_J;
226 
227  int AInt2EquPos2Node_I;
228  int AInt2EquPos2Node_J;
229  int AInt2EquInt2Node_I;
230  int AInt2EquInt2Node_J;
231  int AInt2EquIbr2Node_I;
232  int AInt2EquIbr2Node_J;
233 
234  int ANeg2EquIbr2Node_I;
235  int ANeg2EquIbr2Node_J;
236 
237  int AIbr2EquInt2Node_I;
238  int AIbr2EquInt2Node_J;
239  int AIbr2EquNeg2Node_I;
240  int AIbr2EquNeg2Node_J;
241 
242  // for DC simulations these 6 pairs get filled because v1 and v2 reduce
243  // to V1=Ibr2*Z0 and V2=Ibr1*Z0 and no time delay
244  int AIbr1EquPos2Node_I;
245  int AIbr1EquPos2Node_J;
246  int AIbr1EquNeg2Node_I;
247  int AIbr1EquNeg2Node_J;
248  int AIbr1EquIbr2Node_I;
249  int AIbr1EquIbr2Node_J;
250 
251  int AIbr2EquPos1Node_I;
252  int AIbr2EquPos1Node_J;
253  int AIbr2EquNeg1Node_I;
254  int AIbr2EquNeg1Node_J;
255  int AIbr2EquIbr1Node_I;
256  int AIbr2EquIbr1Node_J;
257 #endif
258  // Matrix equation offset variables
267  // for DC simulations these 6 pairs get filled because v1 and v2 reduce
268  // to V1=Ibr2*Z0 and V2=Ibr1*Z0 and no time delay
283 
284  double Vpos1,Vpos2,Vneg1,Vneg2,Vint1,Vint2,Ibr1,Ibr2; // solution vars
285  double last_t; // "primary" state variables
286  double v1; //
287  double v2; //
289 
290  std::vector<History> history;
291  double timeOld;
292 
295 };
296 
297 //-----------------------------------------------------------------------------
298 // Class : History
299 // Purpose : Provide a structure to save internal state history
300 // Special Notes :
301 // Creator : Tom Russo, SNL, Component Information and Models
302 // Creation Date : 6/14/2001
303 //-----------------------------------------------------------------------------
304 class History
305 {
306  friend class Instance;
307  friend class Traits;public:
308  History();
309  History(const History &right);
310  History(double t, double v1, double v2);
311  ~History();
312  inline bool operator<(const double &test_t) const;
313 
314 private:
315  double t;
316  double v1;
317  double v2;
318 };
319 
320 //-----------------------------------------------------------------------------
321 // Class : Model
322 // Purpose :
323 // Special Notes :
324 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
325 // Creation Date : 3/16/00
326 //-----------------------------------------------------------------------------
327 class Model : public DeviceModel
328 {
329  typedef std::vector<Instance *> InstanceVector;
330 
331  friend class ParametricData<Model>;
332  friend class Instance;
333  friend class Traits;
334 
335 public:
336  Model(
337  const Configuration & configuration,
338  const ModelBlock & MB,
339  const FactoryBlock & factory_block);
340  ~Model();
341 
342 private:
343  Model();
344  Model(const Model &);
345  Model &operator=(const Model &);
346 
347 public:
348  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
349 
350  virtual std::ostream &printOutInstances(std::ostream &os) const;
351  bool processParams ();
352  bool processInstanceParams ();
353 
354 
355 public:
356  void addInstance(Instance *instance)
357  {
358  instanceContainer.push_back(instance);
359  }
360 
361 private:
362  std::vector<Instance*> instanceContainer;
363 private:
364 
365 };
366 
367 //-----------------------------------------------------------------------------
368 // Function : History::operator<
369 // Purpose : compare used in the lower_bound operation. Returns
370 // true if the time in the history object is less than
371 // the given time (double)
372 // Special Notes :
373 // Scope : private
374 // Creator : Tom Russo, SNL, Component Information and Models
375 // Creation Date : 7/27/2005
376 //-----------------------------------------------------------------------------
377 inline bool History::operator<(const double &test_t) const
378 {
379  return (t < test_t);
380 }
381 
382 void registerDevice();
383 
384 } // namespace TRA
385 } // namespace Device
386 } // namespace Xyce
387 
388 #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:329
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:362
static bool isLinearDevice()
Definition: N_DEV_TRA.h:69
static std::vector< std::vector< int > > jacStamp
Definition: N_DEV_TRA.h:147
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:356
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:377
std::vector< History > history
Definition: N_DEV_TRA.h:290
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
bool isLinearDevice() const
Definition: N_DEV_TRA.h:103
InstanceBlock represent a device instance line from the netlist.
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_TRA.C:387