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.116 $
40 //
41 // Revision Date : $Date: 2014/08/07 21:23:14 $
42 //
43 // Current Owner : $Author: erkeite $
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 /// sensitivity functor
66 {
67  public:
69  baseSensitivity() {};
70 
71  virtual ~dcVsrcSensitivity() {};
72 
73  virtual void operator()(
74  const ParameterBase &entity,
75  const std::string &name,
76  std::vector<double> & dfdp,
77  std::vector<double> & dqdp,
78  std::vector<double> & dbdp,
79  std::vector<int> & Findices,
80  std::vector<int> & Qindices,
81  std::vector<int> & Bindices
82  ) const ;
83 };
84 
86 
87 struct Traits : public DeviceTraits<Model, Instance>
88 {
89  static const char *name() {return "Independent Voltage Source";}
90  static const char *deviceTypeName() {return "V level 1";}
92 
93  static int numNodes() {return 2;}
94  static const char *primaryParameter() {return "DCV0";}
95  static const char *instanceDefaultParameter() {return "DCV0";}
96  static bool isLinearDevice() {return true;}
97 
98  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
99  static void loadModelParameters(ParametricData<Model> &model_parameters);
100  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
102 };
103 
104 //-----------------------------------------------------------------------------
105 // Class : Instance
106 // Purpose :
107 // Special Notes :
108 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
109 // Creation Date : 04/06/00
110 //-----------------------------------------------------------------------------
111 class Instance : public SourceInstance
112 {
113  friend class ParametricData<Instance>;
114  friend class Model;
115  friend class Traits;
116  friend class Master;
117  friend class dcVsrcSensitivity;
118 
119 public:
120  Instance(
121  const Configuration & configuration,
122  const InstanceBlock & IB,
123  Model & Viter,
124  const FactoryBlock & factory_block);
125 
126  Instance(const Instance & right);
127  ~Instance();
128 
129  void registerLIDs( const std::vector<int> & intLIDVecRef,
130  const std::vector<int> & extLIDVecRef );
131  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
132  std::map<int,std::string> & getIntNameMap ();
133 
134  const std::vector< std::vector<int> > & jacobianStamp() const;
135  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
136 
137  bool processParams ();
138 
139  bool updateIntermediateVars ();
140  bool updatePrimaryState ();
141 
142  // load functions, residual:
143  bool loadBVectorsforAC (double * bVecReal, double * bVecImag);
144  bool loadDAEQVector () { return true; }
145  bool loadDAEFVector ();
146  bool loadDAEBVector ();
147 
148  // load functions, Jacobian:
149  bool loadDAEdQdx () { return true; }
150  bool loadDAEdFdx ();
151 
152  void setupPointers();
153 
154  double getMaxTimeStepSize ();
155 
156  void varTypes( std::vector<char> & varTypeVec );
157 
158  void getLIDs(int & lpos, int & lneg,int & lbra)
159  {lpos = li_Pos; lneg = li_Neg; lbra = li_Bra;}
160 
161 public:
162  // iterator reference to the vsrc model which owns this instance.
163  // Getters and setters
165  {
166  return model_;
167  }
168 
169 private:
170 
171  Model & model_; //< Owning model
172 
173  // state variables:
174  double srcCurrent;
175  double srcVoltage;
176  double srcDrop;
177  double srcBC;
178 
179  // scale factor
180  double scale;
181  int nlstep;
182 
183  // Parameters
184  double DCV0;
185  double par0;
186  double par1;
187  double par2;
188  double par3;
189  double par4;
190  double par5;
191  double par6;
192  double par7;
193  double REPEATTIME;
194  double T;
195  double V;
196  double ACMAG;
197  double ACPHASE;
198 
199  int NUM;
200  bool REPEAT;
207  bool gotParams;
208 
209  // load variables
210  double source, v_pos, v_neg, i_bra;
211 
212  // indices into state vector:
213  int istate_I; // index for i0;
214 
215  // Matrix equation index variables:
216 
217  //local indices (offsets)
218  int li_Pos;
219  int li_Neg;
220  int li_Bra;
221 
222  // Jacobian matrix indices:
223  //Locally indexed offsets for jacobian
224  int ABraEquPosNodeOffset; // Offset, pos. node voltage contribution,
225  // branch current equ.
226 
227  int ABraEquNegNodeOffset; // Offset, neg. node voltage contribution,
228  // branch current equ.
229 
230  int APosEquBraVarOffset; // Offset, branch current variable
231  // contribution, KCL equation of the pos node
232 
233  int ANegEquBraVarOffset; // Offset, branch current variable
234  // contribution, KCL equation of the neg node
235 
236  // The following jacobian offsets are only neccessary
237  // for 2-level newton.
238  int APosEquPosNodeOffset; // Offset, positive node variable
239  // contribution, positive node KCL.
240 
241  int ANegEquNegNodeOffset; // Offset, negative node variable
242  // contribution, negative node KCL.
243 
244  int ABraEquBraVarOffset; // Offset, branch current variable
245  // contribution, branch current equation.
246 
247 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
248  // Jacobian matrix pointers:
253 
254  // The following jacobian pointers are only neccessary for 2-level newton.
258 #endif
259 
260  static std::vector< std::vector<int> > jacStamp;
261  static std::vector< std::vector<int> > jacStampPDE;
262 };
263 
264 //-----------------------------------------------------------------------------
265 // Class : Model
266 // Purpose :
267 // Special Notes :
268 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
269 // Creation Date : 04/06/00
270 //-----------------------------------------------------------------------------
271 class Model : public DeviceModel
272 {
273  typedef std::vector<Instance *> InstanceVector;
274 
275  friend class ParametricData<Model>;
276  friend class Instance;
277  friend class Traits;
278  friend class Master;
279  friend class dcVsrcSensitivity;
280 
281 public:
282  Model(
283  const Configuration & configuration,
284  const ModelBlock & MB,
285  const FactoryBlock & factory_block);
286  ~Model ();
287 
288 private:
289  Model();
290  Model(const Model &);
291  Model &operator=(const Model &);
292 
293 public:
294  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
295 
296  virtual std::ostream &printOutInstances(std::ostream &os) const;
297  virtual bool processParams()
298  {
299  return true;
300  }
301 
302  virtual bool processInstanceParams()
303  {
304  return true;
305  }
306 
307 
308 public:
309  void addInstance(Instance *instance)
310  {
311  instanceContainer.push_back(instance);
312  }
313 
314 private:
315  std::vector<Instance*> instanceContainer;
316 
317 private:
318 
319  // This is the dc and transient analysis value of the source.
320  double DC_TRAN;
321 };
322 
323 //-----------------------------------------------------------------------------
324 // Class : Master
325 // Purpose :
326 // Special Notes :
327 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
328 // Creation Date : 11/26/08
329 //-----------------------------------------------------------------------------
330 class Master : public DeviceMaster<Traits>
331 {
332  friend class Instance;
333  friend class Model;
334 
335 public:
337  const Configuration & configuration,
338  const FactoryBlock & factory_block,
339  const SolverState & ss1,
340  const DeviceOptions & do1)
341  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
342  {}
343 
344  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
345 
346  // load functions:
347  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ);
348  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
349 };
350 
351 void registerDevice();
352 
353 } // namespace Vsrc
354 } // namespace Device
355 } // namespace Xyce
356 
360 
361 #endif