Xyce  6.1
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-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_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.124 $
40 //
41 // Revision Date : $Date: 2015/04/20 20:43:55 $
42 //
43 // Current Owner : $Author: dgbaur $
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  bool isLinearDevice() const { return true; }
130 
131  void registerLIDs( const std::vector<int> & intLIDVecRef,
132  const std::vector<int> & extLIDVecRef );
133  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
134  void registerBranchDataLIDs(const std::vector<int> & branchLIDVecRef);
135 
136  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
137 
138  const std::vector< std::vector<int> > & jacobianStamp() const;
139  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
140 
141  bool processParams ();
142 
143  bool updateIntermediateVars ();
144  bool updatePrimaryState ();
145 
146  // load functions, residual:
147  bool loadBVectorsforAC (double * bVecReal, double * bVecImag);
148  bool loadDAEQVector () { return true; }
149  bool loadDAEFVector ();
150  bool loadDAEBVector ();
151 
152  // load functions, Jacobian:
153  bool loadDAEdQdx () { return true; }
154  bool loadDAEdFdx ();
155 
156  void setupPointers();
157 
158  double getMaxTimeStepSize ();
159 
160  void varTypes( std::vector<char> & varTypeVec );
161 
162  void getLIDs(int & lpos, int & lneg,int & lbra)
163  {lpos = li_Pos; lneg = li_Neg; lbra = li_Bra;}
164 
165 public:
166  // iterator reference to the vsrc model which owns this instance.
167  // Getters and setters
169  {
170  return model_;
171  }
172 
173 private:
174 
175  Model & model_; //< Owning model
176 
177  // state variables:
178  double srcCurrent;
179  double srcVoltage;
180  double srcDrop;
181  double srcBC;
182 
183  // scale factor
184  double scale;
185  int nlstep;
186 
189 
190  // Parameters
191  double DCV0;
192  double par0;
193  double par1;
194  double par2;
195  double par3;
196  double par4;
197  double par5;
198  double par6;
199  double par7;
200  double REPEATTIME;
201  double T;
202  double V;
203  double ACMAG;
204  double ACPHASE;
205 
206  int NUM;
207  bool REPEAT;
214  bool gotParams;
215 
216  // load variables
217  double source, v_pos, v_neg, i_bra;
218 
219  // indices into state vector:
220  int istate_I; // index for i0;
221 
222  // Matrix equation index variables:
223 
224  //local indices (offsets)
225  int li_Pos;
226  int li_Neg;
227  int li_Bra;
228  int li_branch_data; ///< Index for Lead Current and junction voltage (for power calculations)
229 
230  // Jacobian matrix indices:
231  //Locally indexed offsets for jacobian
232  int ABraEquPosNodeOffset; // Offset, pos. node voltage contribution,
233  // branch current equ.
234 
235  int ABraEquNegNodeOffset; // Offset, neg. node voltage contribution,
236  // branch current equ.
237 
238  int APosEquBraVarOffset; // Offset, branch current variable
239  // contribution, KCL equation of the pos node
240 
241  int ANegEquBraVarOffset; // Offset, branch current variable
242  // contribution, KCL equation of the neg node
243 
244  // The following jacobian offsets are only neccessary
245  // for 2-level newton.
246  int APosEquPosNodeOffset; // Offset, positive node variable
247  // contribution, positive node KCL.
248 
249  int ANegEquNegNodeOffset; // Offset, negative node variable
250  // contribution, negative node KCL.
251 
252  int ABraEquBraVarOffset; // Offset, branch current variable
253  // contribution, branch current equation.
254 
255 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
256  // Jacobian matrix pointers:
261 
262  // The following jacobian pointers are only neccessary for 2-level newton.
266 #endif
267 
268  static std::vector< std::vector<int> > jacStamp;
269  static std::vector< std::vector<int> > jacStampPDE;
270 };
271 
272 //-----------------------------------------------------------------------------
273 // Class : Model
274 // Purpose :
275 // Special Notes :
276 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
277 // Creation Date : 04/06/00
278 //-----------------------------------------------------------------------------
279 class Model : public DeviceModel
280 {
281  typedef std::vector<Instance *> InstanceVector;
282 
283  friend class ParametricData<Model>;
284  friend class Instance;
285  friend class Traits;
286  friend class Master;
287  friend class dcVsrcSensitivity;
288 
289 public:
290  Model(
291  const Configuration & configuration,
292  const ModelBlock & MB,
293  const FactoryBlock & factory_block);
294  ~Model ();
295 
296 private:
297  Model();
298  Model(const Model &);
299  Model &operator=(const Model &);
300 
301 public:
302  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
303 
304  virtual std::ostream &printOutInstances(std::ostream &os) const;
305  virtual bool processParams()
306  {
307  return true;
308  }
309 
310  virtual bool processInstanceParams()
311  {
312  return true;
313  }
314 
315 
316 public:
317  void addInstance(Instance *instance)
318  {
319  instanceContainer.push_back(instance);
320  }
321 
322 private:
323  std::vector<Instance*> instanceContainer;
324 
325 private:
326 
327  // This is the dc and transient analysis value of the source.
328  double DC_TRAN;
329 };
330 
331 //-----------------------------------------------------------------------------
332 // Class : Master
333 // Purpose :
334 // Special Notes :
335 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
336 // Creation Date : 11/26/08
337 //-----------------------------------------------------------------------------
338 class Master : public DeviceMaster<Traits>
339 {
340  friend class Instance;
341  friend class Model;
342 
343 public:
344  Master(
345  const Configuration & configuration,
346  const FactoryBlock & factory_block,
347  const SolverState & solver_state,
348  const DeviceOptions & device_options);
349 
350  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
351 
352  // load functions:
353  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
354  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
355 
356 private:
358 };
359 
360 void registerDevice();
361 
362 } // namespace Vsrc
363 } // namespace Device
364 } // namespace Xyce
365 
366 #endif
bool isLinearDevice() const
Definition: N_DEV_Vsrc.h:129
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &solver_state, const DeviceOptions &device_options)
Definition: N_DEV_Vsrc.C:993
virtual bool processParams()
processParams
Definition: N_DEV_Vsrc.h:305
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_Vsrc.C:491
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_Vsrc.C:629
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_Vsrc.C:946
Pure virtual class to augment a linear system.
static const char * instanceDefaultParameter()
Definition: N_DEV_Vsrc.h:95
Base class for all parameters.
Definition: N_DEV_Pars.h:169
virtual bool processInstanceParams()
processInstanceParams
Definition: N_DEV_Vsrc.h:310
static const char * primaryParameter()
Definition: N_DEV_Vsrc.h:94
void addInstance(Instance *instance)
Definition: N_DEV_Vsrc.h:317
bool loadBVectorsforAC(double *bVecReal, double *bVecImag)
Definition: N_DEV_Vsrc.C:803
virtual void operator()(const ParameterBase &entity, const std::string &name, std::vector< double > &dfdp, std::vector< double > &dqdp, std::vector< double > &dbdp, std::vector< int > &Findices, std::vector< int > &Qindices, std::vector< int > &Bindices) const
Definition: N_DEV_Vsrc.C:1142
Model & operator=(const Model &)
static const char * name()
Definition: N_DEV_Vsrc.h:89
DeviceMaster instantiates a device as described by the device traits T.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
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_Vsrc.C:1071
static const char * deviceTypeName()
Definition: N_DEV_Vsrc.h:90
void varTypes(std::vector< char > &varTypeVec)
Definition: N_DEV_Vsrc.C:891
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_Vsrc.C:1122
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_Vsrc.C:1010
static ParametricData< Model > & modelParameters()
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_Vsrc.C:1100
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Definition: N_DEV_Vsrc.C:981
void registerBranchDataLIDs(const std::vector< int > &branchLIDVecRef)
Register the local store IDs.
Definition: N_DEV_Vsrc.C:565
static std::vector< std::vector< int > > jacStampPDE
Definition: N_DEV_Vsrc.h:269
Class Configuration contains device configuration data.
std::vector< Instance * > instanceContainer
Definition: N_DEV_Vsrc.h:323
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_Vsrc.C:70
static std::vector< std::vector< int > > jacStamp
Definition: N_DEV_Vsrc.h:268
static ParametricData< Instance > & instanceParameters()
int li_branch_data
Index for Lead Current and junction voltage (for power calculations)
Definition: N_DEV_Vsrc.h:228
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_Vsrc.C:235
Base sensitivity functor.
Definition: N_DEV_Pars.h:148
static bool isLinearDevice()
Definition: N_DEV_Vsrc.h:96
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.
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_Vsrc.C:583
static dcVsrcSensitivity dcv0Sens
Definition: N_DEV_Vsrc.h:85
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_Vsrc.C:613
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Viter, const FactoryBlock &factory_block)
Definition: N_DEV_Vsrc.C:252
std::vector< Instance * > InstanceVector
Definition: N_DEV_Vsrc.h:281
void getLIDs(int &lpos, int &lneg, int &lbra)
Definition: N_DEV_Vsrc.h:162
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_Vsrc.C:600