Xyce  6.1
N_DEV_SW.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_SW.h,v $
27 //
28 // Purpose : Switch base classes
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.104 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:24 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_SW_h
47 #define Xyce_N_DEV_SW_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceMaster.h>
52 #include <N_DEV_DeviceBlock.h>
53 #include <N_DEV_DeviceInstance.h>
54 #include <N_DEV_DeviceModel.h>
55 
56 namespace Xyce {
57 namespace Device {
58 namespace SW {
59 
60 class Model;
61 class Instance;
62 
63 struct Traits : public DeviceTraits<Model, Instance>
64 {
65  static const char *name() {return "Controlled Switch";}
66  static const char *deviceTypeName() {return "S level 1";}
67  static int numNodes() {return 2;}
68  static int numOptionalNodes() {return 2;}
69  static bool modelRequired() {return true;}
70  static bool isLinearDevice() {return true;}
71 
72  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
73  static void loadModelParameters(ParametricData<Model> &model_parameters);
74  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
75 };
76 
77 //-----------------------------------------------------------------------------
78 // Class : Instance
79 // Purpose :
80 // Special Notes :
81 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
82 // Creation Date : 3/16/00
83 //-----------------------------------------------------------------------------
84 class Instance : public DeviceInstance
85 {
86  friend class ParametricData<Instance>;
87  friend class Model;
88  friend class Traits;friend class Master;
89 
90 public:
91 
92  Instance(
93  const Configuration & configuration,
94  const InstanceBlock & IB,
95  Model & SWiter,
96  const FactoryBlock & factory_block);
97 
98 
99  ~Instance();
100 
101 private:
102  Instance(const Instance &);
103  Instance &operator=(const Instance &);
104 
105 public:
106  void registerLIDs( const std::vector<int> & intLIDVecRef,
107  const std::vector<int> & extLIDVecRef );
108  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
109  void registerStoreLIDs( const std::vector<int> & stoLIDVecRef );
110 
111  virtual void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
112 
113  bool processParams ();
114 
115  const std::vector<std::string> & getDepSolnVars();
116 
117  const std::vector< std::vector<int> > & jacobianStamp() const;
118  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
119 
120  bool updateIntermediateVars ();
121  bool updatePrimaryState ();
122  bool updateSecondaryState ();
123 
124  // load functions, residual:
125  bool loadDAEQVector () {return true;}
126  bool loadDAEFVector ();
127 
128  // load functions, Jacobian:
129  bool loadDAEdQdx () {return true;}
130  bool loadDAEdFdx ();
131 
132  void setupPointers();
133 
134 public:
135  // iterator reference to the switch model which owns this instance
136  // Getters and setters
138  {
139  return model_;
140  }
141 
142 private:
143 
144  Model & model_; //< Owning model
145 
146  Util::Expression * Exp_ptr;
150  std::list<std::string> evnList;
151 
152  std::vector<double> expVarDerivs;
153  std::vector<double> myVarVals;
154  std::vector<double> ddtVals;
155  double expVal;
156 
157 
158  // user specified parameters
159  double R; // resistance (ohms)
160  double CONTROL; // Value of control expression
161  bool ON, OFF; // whether switch is on or off initially
162 
163  // derived parameters
164  double G; // conductance (1.0/ohms)
165  double dGdI,dGdV;
166 
167  // places to store node voltages
168  double v_pos;
169  double v_neg;
170 
171  double LeadCurrent;
172 
173  // double for current state of switch
174  double SW_STATE;
175 
176  // and a state variable to save the SW_STATE
177  double switch_state;
178 
179  std::vector<int> li_ddt;
180 
182 
183  // local indices (offsets)
184  int li_Pos;
185  int li_Neg;
186 
187  // store vector location for device lead current
189 
190  // Offset variables corresponding to the above declared indices.
195 
196  // Offsets into the control nodes
197  std::vector<int> APosEquControlNodeOffset;
198  std::vector<int> ANegEquControlNodeOffset;
199 
200  // Ptr variables corresponding to the above declared indices.
205 
206  // Ptrs into the control nodes
207  std::vector<double *> fPosEquControlNodePtr;
208  std::vector<double *> fNegEquControlNodePtr;
209 
210  std::vector< std::vector<int> > jacStamp;
211 };
212 
213 //-----------------------------------------------------------------------------
214 // Class : Model
215 // Purpose :
216 // Special Notes :
217 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
218 // Creation Date : 3/16/00
219 //-----------------------------------------------------------------------------
220 class Model : public DeviceModel
221 {
222  typedef std::vector<Instance *> InstanceVector;
223 
224  friend class ParametricData<Model>;
225  friend class Instance;
226  friend class Traits;friend class Master;
227 
228 public:
229  Model(
230  const Configuration & configuration,
231  const ModelBlock & MB,
232  const FactoryBlock & factory_block);
233 
234  ~Model();
235 
236 private:
237  Model();
238  Model(const Model &);
239  Model &operator=(const Model &);
240 
241 public:
242  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
243 
244  virtual std::ostream &printOutInstances(std::ostream &os) const;
245 
246  bool processParams ();
247  bool processInstanceParams ();
248 
249 
250 public:
251  void addInstance(Instance *instance)
252  {
253  instanceContainer.push_back(instance);
254  }
255 
256 private:
257  std::vector<Instance*> instanceContainer;
258 
259 private:
260 
261  int dtype; // device type: 1=SWITCH, 2=ISWITCH, 3=VSWITCH
262  double VON;
263  double VOFF;
264  double ION;
265  double IOFF;
266  double RON;
267  double ROFF;
268  double ON;
269  double OFF;
270  double dInv; // the inverse of (ON-OFF) or 1e-12, if too small.
271  double Lm; // log mean of resistances
272  double Lr; // log ratio of resistor values
273 };
274 
275 //-----------------------------------------------------------------------------
276 // Class : Master
277 // Purpose :
278 // Special Notes :
279 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
280 // Creation Date : 11/26/08
281 //-----------------------------------------------------------------------------
282 class Master : public DeviceMaster<Traits>
283 {
284  friend class Instance;
285  friend class Model;
286 
287 public:
289  const Configuration & configuration,
290  const FactoryBlock & factory_block,
291  const SolverState & ss1,
292  const DeviceOptions & do1)
293  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
294  {}
295 
296  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
297  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
298 
299  // load functions, residual:
300  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
301 
302  // load functions, Jacobian:
303  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
304 };
305 
306 void registerDevice();
307 
308 } // namespace SW
309 } // namespace Device
310 } // namespace Xyce
311 
312 #endif
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_SW.C:90
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_SW.C:989
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_SW.C:76
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Definition: N_DEV_SW.C:795
std::vector< Instance * > InstanceVector
Definition: N_DEV_SW.h:222
virtual bool updateSecondaryState(double *staDeriv, double *stoVec)
Updates the devices secondary state information.
Definition: N_DEV_SW.C:840
Instance & operator=(const Instance &)
Pure virtual class to augment a linear system.
virtual bool loadDAEVectors(double *solVec, double *fVec, double *qVec, double *bVec, double *storeLeadF, double *storeLeadQ, double *leadF, double *leadQ, double *junctionV)
Populates the device's ExternData object with these pointers.
Definition: N_DEV_SW.C:923
void addInstance(Instance *instance)
Definition: N_DEV_SW.h:251
std::vector< double > myVarVals
Definition: N_DEV_SW.h:153
static const char * deviceTypeName()
Definition: N_DEV_SW.h:66
static const char * name()
Definition: N_DEV_SW.h:65
std::vector< int > APosEquControlNodeOffset
Definition: N_DEV_SW.h:197
static int numNodes()
Definition: N_DEV_SW.h:67
static bool modelRequired()
Definition: N_DEV_SW.h:69
std::vector< double * > fPosEquControlNodePtr
Definition: N_DEV_SW.h:207
DeviceMaster instantiates a device as described by the device traits T.
static int numOptionalNodes()
Definition: N_DEV_SW.h:68
std::list< std::string > evnList
Definition: N_DEV_SW.h:150
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_SW.C:297
std::vector< double > ddtVals
Definition: N_DEV_SW.h:154
std::vector< std::vector< int > > jacStamp
Definition: N_DEV_SW.h:210
std::vector< Instance * > instanceContainer
Definition: N_DEV_SW.h:257
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_SW.C:813
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &SWiter, const FactoryBlock &factory_block)
Definition: N_DEV_SW.C:155
std::vector< double > expVarDerivs
Definition: N_DEV_SW.h:152
std::vector< int > li_ddt
Definition: N_DEV_SW.h:179
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_SW.C:949
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_SW.C:362
Class Configuration contains device configuration data.
Util::Expression * Exp_ptr
Definition: N_DEV_SW.h:146
std::vector< int > ANegEquControlNodeOffset
Definition: N_DEV_SW.h:198
void registerStoreLIDs(const std::vector< int > &stoLIDVecRef)
Definition: N_DEV_SW.C:318
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_SW.C:757
Model & operator=(const Model &)
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_SW.C:349
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_SW.C:270
void registerDevice()
Definition: N_DEV_SW.C:995
virtual void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_SW.C:520
std::vector< double * > fNegEquControlNodePtr
Definition: N_DEV_SW.h:208
bool processParams()
processParams
Definition: N_DEV_SW.C:691
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.
static bool isLinearDevice()
Definition: N_DEV_SW.h:70
const std::vector< std::string > & getDepSolnVars()
Definition: N_DEV_SW.C:336
bool processInstanceParams()
processInstanceParams
Definition: N_DEV_SW.C:716
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)
Definition: N_DEV_SW.h:288