Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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.95.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_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 const int numNodes() {return 2;}
68  static const int numOptionalNodes() {return 2;}
69  static const bool modelRequired() {return true;}
70  static const 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  std::map<int,std::string> & getStoreNameMap();
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 
257  {
258  return instanceContainer;
259  }
260 
262  {
263  return instanceContainer;
264  }
265 
266 private:
267  std::vector<Instance*> instanceContainer;
268 
269 private:
270 
271  int dtype; // device type: 1=SWITCH, 2=ISWITCH, 3=VSWITCH
272  double VON;
273  double VOFF;
274  double ION;
275  double IOFF;
276  double RON;
277  double ROFF;
278  double ON;
279  double OFF;
280  double dInv; // the inverse of (ON-OFF) or 1e-12, if too small.
281  double Lm; // log mean of resistances
282  double Lr; // log ratio of resistor values
283 };
284 
285 //-----------------------------------------------------------------------------
286 // Class : Master
287 // Purpose :
288 // Special Notes :
289 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
290 // Creation Date : 11/26/08
291 //-----------------------------------------------------------------------------
292 class Master : public DeviceMaster<Traits>
293 {
294  friend class Instance;
295  friend class Model;
296 
297 public:
299  const Configuration & configuration,
300  const FactoryBlock & factory_block,
301  const SolverState & ss1,
302  const DeviceOptions & do1)
303  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
304  {}
305 
306  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
307  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
308 
309  // load functions, residual:
310  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * storeLeadF, double * storeLeadQ);
311 
312  // load functions, Jacobian:
313  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
314 };
315 
316 void registerDevice();
317 
318 } // namespace SW
319 } // namespace Device
320 } // namespace Xyce
321 
325 
326 #endif