Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Vsrc.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_Vsrc.h,v $
27 //
28 // Purpose : Independent voltage source 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.109.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_Vsrc_h
47 #define Xyce_N_DEV_Vsrc_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceMaster.h>
52 #include <N_DEV_Source.h>
53 #include <N_DEV_DeviceBlock.h>
54 #include <N_DEV_DeviceInstance.h>
55 #include <N_DEV_DeviceModel.h>
56 
57 namespace Xyce {
58 namespace Device {
59 namespace Vsrc {
60 
61 class Model;
62 class Instance;
63 
64 struct Traits : public DeviceTraits<Model, Instance>
65 {
66  static const char *name() {return "Independent Voltage Source";}
67  static const char *deviceTypeName() {return "V level 1";}
69 
70  static const int numNodes() {return 2;}
71  static const char *primaryParameter() {return "DCV0";}
72  static const char *instanceDefaultParameter() {return "DCV0";}
73  static const bool isLinearDevice() {return true;}
74 
75  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
76  static void loadModelParameters(ParametricData<Model> &model_parameters);
77  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
79 };
80 
81 //-----------------------------------------------------------------------------
82 // Class : Instance
83 // Purpose :
84 // Special Notes :
85 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
86 // Creation Date : 04/06/00
87 //-----------------------------------------------------------------------------
88 class Instance : public SourceInstance
89 {
90  friend class ParametricData<Instance>;
91  friend class Model;
92  friend class Traits;friend class Master;
93 
94 public:
95  Instance(
96  const Configuration & configuration,
97  const InstanceBlock & IB,
98  Model & Viter,
99  const FactoryBlock & factory_block);
100 
101  Instance(const Instance & right);
102  ~Instance();
103 
104  void registerLIDs( const std::vector<int> & intLIDVecRef,
105  const std::vector<int> & extLIDVecRef );
106  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
107  std::map<int,std::string> & getIntNameMap ();
108 
109  const std::vector< std::vector<int> > & jacobianStamp() const;
110  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
111 
112  bool processParams ();
113 
114  bool updateIntermediateVars ();
115  bool updatePrimaryState ();
116 
117  // load functions, residual:
118  bool loadBVectorsforAC (double * bVecReal, double * bVecImag);
119  bool loadDAEQVector () { return true; }
120  bool loadDAEFVector ();
121 
122  // load functions, Jacobian:
123  bool loadDAEdQdx () { return true; }
124  bool loadDAEdFdx ();
125 
126  void setupPointers();
127 
128  double getMaxTimeStepSize ();
129 
130  void varTypes( std::vector<char> & varTypeVec );
131 
132  void getLIDs(int & lpos, int & lneg,int & lbra)
133  {lpos = li_Pos; lneg = li_Neg; lbra = li_Bra;}
134 
135 public:
136  // iterator reference to the vsrc model which owns this instance.
137  // Getters and setters
139  {
140  return model_;
141  }
142 
143 private:
144 
145  Model & model_; //< Owning model
146 
147  // state variables:
148  double srcCurrent;
149  double srcVoltage;
150  double srcDrop;
151  double srcBC;
152 
153  // scale factor
154  double scale;
155  int nlstep;
156 
157  // Parameters
158  double DCV0;
159  double par0;
160  double par1;
161  double par2;
162  double par3;
163  double par4;
164  double par5;
165  double par6;
166  double par7;
167  double REPEATTIME;
168  double T;
169  double V;
170  double ACMAG;
171  double ACPHASE;
172 
173  int NUM;
174  bool REPEAT;
181  bool gotParams;
182 
183  // load variables
184  double source, v_pos, v_neg, i_bra;
185 
186  // indices into state vector:
187  int istate_I; // index for i0;
188 
189  // Matrix equation index variables:
190 
191  //local indices (offsets)
192  int li_Pos;
193  int li_Neg;
194  int li_Bra;
195 
196  // Jacobian matrix indices:
197  //Locally indexed offsets for jacobian
198  int ABraEquPosNodeOffset; // Offset, pos. node voltage contribution,
199  // branch current equ.
200 
201  int ABraEquNegNodeOffset; // Offset, neg. node voltage contribution,
202  // branch current equ.
203 
204  int APosEquBraVarOffset; // Offset, branch current variable
205  // contribution, KCL equation of the pos node
206 
207  int ANegEquBraVarOffset; // Offset, branch current variable
208  // contribution, KCL equation of the neg node
209 
210  // The following jacobian offsets are only neccessary
211  // for 2-level newton.
212  int APosEquPosNodeOffset; // Offset, positive node variable
213  // contribution, positive node KCL.
214 
215  int ANegEquNegNodeOffset; // Offset, negative node variable
216  // contribution, negative node KCL.
217 
218  int ABraEquBraVarOffset; // Offset, branch current variable
219  // contribution, branch current equation.
220 
221 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
222  // Jacobian matrix pointers:
227 
228  // The following jacobian pointers are only neccessary for 2-level newton.
232 #endif
233 
234  static std::vector< std::vector<int> > jacStamp;
235  static std::vector< std::vector<int> > jacStampPDE;
236 };
237 
238 //-----------------------------------------------------------------------------
239 // Class : Model
240 // Purpose :
241 // Special Notes :
242 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
243 // Creation Date : 04/06/00
244 //-----------------------------------------------------------------------------
245 class Model : public DeviceModel
246 {
247  typedef std::vector<Instance *> InstanceVector;
248 
249  friend class ParametricData<Model>;
250  friend class Instance;
251  friend class Traits;friend class Master;
252 
253 public:
254  Model(
255  const Configuration & configuration,
256  const ModelBlock & MB,
257  const FactoryBlock & factory_block);
258  ~Model ();
259 
260 private:
261  Model();
262  Model(const Model &);
263  Model &operator=(const Model &);
264 
265 public:
266  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
267 
268  virtual std::ostream &printOutInstances(std::ostream &os) const;
269  virtual bool processParams()
270  {
271  return true;
272  }
273 
274  virtual bool processInstanceParams()
275  {
276  return true;
277  }
278 
279 
280 public:
281  void addInstance(Instance *instance)
282  {
283  instanceContainer.push_back(instance);
284  }
285 
287  {
288  return instanceContainer;
289  }
290 
292  {
293  return instanceContainer;
294  }
295 
296 private:
297  std::vector<Instance*> instanceContainer;
298 
299 private:
300 
301  // This is the dc and transient analysis value of the source.
302  double DC_TRAN;
303 };
304 
305 //-----------------------------------------------------------------------------
306 // Class : Master
307 // Purpose :
308 // Special Notes :
309 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
310 // Creation Date : 11/26/08
311 //-----------------------------------------------------------------------------
312 class Master : public DeviceMaster<Traits>
313 {
314  friend class Instance;
315  friend class Model;
316 
317 public:
319  const Configuration & configuration,
320  const FactoryBlock & factory_block,
321  const SolverState & ss1,
322  const DeviceOptions & do1)
323  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
324  {}
325 
326  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
327 
328  // load functions:
329  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * storeLeadF, double * storeLeadQ);
330  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
331 };
332 
333 void registerDevice();
334 
335 } // namespace Vsrc
336 } // namespace Device
337 } // namespace Xyce
338 
342 
343 #endif