Xyce  6.1
N_DEV_Capacitor.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_Capacitor.h,v $
27 //
28 // Purpose :
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.134.2.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:20:10 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Capacitor_h
47 #define Xyce_N_DEV_Capacitor_h
48 
49 #include <N_DEV_fwd.h>
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceMaster.h>
52 #include <N_DEV_DeviceInstance.h>
53 #include <N_DEV_DeviceModel.h>
54 
55 namespace Xyce {
56 namespace Device {
57 namespace Capacitor {
58 
59 class Model;
60 class Instance;
61 
62 /// sensitivity functor
64 {
65  public:
67  baseSensitivity() {};
68 
69  virtual ~capSensitivity() {};
70 
71  virtual void operator()(
72  const ParameterBase &entity,
73  const std::string &name,
74  std::vector<double> & dfdp,
75  std::vector<double> & dqdp,
76  std::vector<double> & dbdp,
77  std::vector<int> & Findices,
78  std::vector<int> & Qindices,
79  std::vector<int> & Bindices
80  ) const ;
81 };
82 
84 
85 struct Traits : public DeviceTraits<Model, Instance>
86 {
87  static const char *name() {return "Capacitor";}
88  static const char *deviceTypeName() {return "C level 1";}
89 
90  static int numNodes() {return 2;}
91  static const char *primaryParameter() {return "C";}
92  static const char *instanceDefaultParameter() {return "C";}
93  static bool isLinearDevice() {return true;}
94 
95  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
96  static void loadModelParameters(ParametricData<Model> &model_parameters);
97  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
98 };
99 
100 //-----------------------------------------------------------------------------
101 // Class : Capacitor::Instance
102 // Special Notes : A capacitor will have two circuit nodes.
103 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
104 // Creation Date : 3/16/00
105 //-----------------------------------------------------------------------------
106 /// Capacitor instance
107 ///
108 /// This class refers to a single instance of the capacitor device. It
109 /// contains indicies into the matrix equation. See the comments for the
110 /// Resistor::Instance class for more details.
111 ///
112 class Instance : public DeviceInstance
113 {
114  friend class ParametricData<Instance>;
115  friend class Model;
116  friend class Traits;
117  friend class Master;
118  friend class capSensitivity;
119 
120 public:
121  Instance(
122  const Configuration & configuration,
123  const InstanceBlock & instance_block,
124  Model & model,
125  const FactoryBlock & factory_block);
126 
127  ~Instance();
128 
129 private:
130  Instance(const Instance &);
131  Instance &operator=(const Instance &);
132 
133 public:
134  void registerLIDs( const std::vector<int> & intLIDVecRef, const std::vector<int> & extLIDVecRef );
135  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
136  void registerStoreLIDs( const std::vector<int> & stoLIDVecRef );
137  void registerBranchDataLIDs(const std::vector<int> & branchLIDVecRef);
138  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
139 
140  const std::vector< std::vector<int> > & jacobianStamp() const;
141  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
142 
143  bool processParams ();
144  bool updateTemperature(const double & temp_tmp);
145 
146  bool updateIntermediateVars () { return true; };
147  bool updatePrimaryState ();
148 
149  bool setIC ();
150 
151  // load functions, residual:
152  bool loadDAEQVector ();
153  bool loadDAEFVector ();
154 
155  // load functions, Jacobian:
156  bool loadDAEdQdx ();
157  bool loadDAEdFdx ();
158 
159  void setupPointers();
160 
161  void varTypes( std::vector<char> & varTypeVec );
162 
163  // Getters and setters
165  {
166  return model_;
167  }
168 
169 private:
170  Model & model_; //< Owning model
171 
172  // Stuff for handling solution-variable-dependent capacitance
173  Util::Expression * expPtr;
175 
176  std::vector<double> expVarDerivs;
177 
178  // user-specified parameters:
179  double C; // User specified capacitance. (Farads)
180  double IC; // Optional initial value capacitor voltage (V).
181 
182  // These are for the semiconductor capacitor
183  double length; // capacitor length
184  double width; // capacitor width
185  double temp; // temperature of this instance
186 
187  // Genie 121412. temperature dependence parameters
188  // these can override values specified in the model
189  double tempCoeff1; // first order temperature coeff.
190  double tempCoeff2; // second order temperature coeff.
191 
192  // flags used to tell if the user has specified one of these values
193  // on the command line.
196 
197  // These are for the age-aware capacitor
198  double age; ///< age in hours
199  double ageCoef; ///< degradation coeficient.
200  double baseCap; ///< the baseline capacitance before aging
201 
202  bool tempGiven;
203  bool ICGiven;
205 
206  // state variables:
207  double q0; ///< charge in the capacitor
208  // now held in the store vector at li_store_dev_i
209  double vcap; // voltage drop across capacitor
210 
211  //local id's (offsets)
212  int li_Pos;
213  int li_Neg;
214  int li_Bra; ///< for the "voltage source" when IC is specified
215  int li_branch_data; ///< Index for lead current and junction voltage (for power calculations)
216 
218 
219  std::vector<int> li_dQdXState;
220  std::vector<int> li_dCdXState;
223 
225 
226  // Offsets for Jacobian
231 
232  // offsets for when C is solution-variable dependent
233  std::vector<int> APosEquDepVarOffsets;
234  std::vector<int> ANegEquDepVarOffsets;
235 
241 
242 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
243  // Pointers for Jacobian
248 
254 
255  std::vector<double *> qPosEquDepVarsPtrs;
256  std::vector<double *> qNegEquDepVarsPtrs;
257 #endif
258 
259  std::vector< std::vector<int> > jacStamp;
260  std::vector< std::vector<int> > jacStamp_IC;
261 };
262 
263 //-----------------------------------------------------------------------------
264 // Class : Model
265 // Purpose :
266 // Special Notes :
267 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
268 // Creation Date : 3/16/00
269 //-----------------------------------------------------------------------------
270 /// Capacitor Model class
271 ///
272 class Model : public DeviceModel
273 {
274  typedef std::vector<Instance *> InstanceVector;
275 
276  friend class ParametricData<Model>;
277  friend class Instance;
278  friend class Traits;
279  friend class Master;
280  friend class capSensitivity;
281 
282 public:
283  Model(
284  const Configuration & configuration,
285  const ModelBlock & model_block,
286  const FactoryBlock & factory_block);
287  ~Model();
288 
289 private:
290  Model();
291  Model(const Model &);
292  Model &operator=(const Model &);
293 
294 public:
295  bool processParams ();
296  bool processInstanceParams ();
297  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
298 
299  virtual std::ostream &printOutInstances(std::ostream &os) const;
300 
301 public:
302  void addInstance(Instance *instance)
303  {
304  instanceContainer.push_back(instance);
305  }
306 
307 private:
308  std::vector<Instance*> instanceContainer;
309 
310 private:
311 
312  // for the semiconductor capacitor (cap with a model card)
313 
314  double capacitanceMultiplier; // capacitance multiplier
315  double cj; // junction bottom capacitance
316  double cjsw; // junction sidewall capacitance
317  double defWidth; // default width
318  double narrow; // narrowing due to side etching
319  double tempCoeff1; // first order temperature coeff.
320  double tempCoeff2; // second order temperature coeff.
321  double baseCap;
322  double tnom;
323 
324  bool tnomGiven;
325 };
326 
327 //-----------------------------------------------------------------------------
328 // Class : Master
329 // Purpose :
330 // Special Notes :
331 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
332 // Creation Date : 11/26/08
333 //-----------------------------------------------------------------------------
334 ///
335 /// Capacitor Master class
336 ///
337 /// The "master" class is the one that contains the updateState, loadDAEVectors
338 /// and loadDAEMatrices methods that are actually called when it is time to
339 /// compute and load device contributions.
340 ///
341 /// The default implementations of these methods in the DeviceMaster
342 /// template class simply loops over all instances and calls their
343 /// updatePrimaryState, loadDAEFVector/loadDAEQVector, and
344 /// loadDAEdFdx/loadDAEdQdx methods, respectively.
345 ///
346 /// For efficiency, the Capacitor class reimplements these methods to do the
347 /// work directly, instead of calling instance-level functions.
348 ///
349 class Master : public DeviceMaster<Traits>
350 {
351  friend class Instance;
352  friend class Model;
353 
354 public:
356  const Configuration & configuration,
357  const FactoryBlock & factory_block,
358  const SolverState & ss1,
359  const DeviceOptions & do1)
360  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
361  {}
362 
363  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
364 
365  // load functions:
366  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
367  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
368 };
369 
370 void registerDevice();
371 
372 } // namespace Capacitor
373 } // namespace Device
374 } // namespace Xyce
375 
376 #endif // Xyce_N_DEV_Capacitor_h
377 
void addInstance(Instance *instance)
bool loadDAEdQdx()
Load the DAE the derivative of the Q vector with respect to the solution vector x, dFdx.
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Update state for all capacitor instances, regardless of model.
bool processParams()
Process model parameters.
static const char * name()
Pure virtual class to augment a linear system.
bool loadDAEQVector()
Load the DAE Q vector.
std::vector< Instance * > instanceContainer
bool processInstanceParams()
Process the instance parameters of instance owned by this model.
double baseCap
the baseline capacitance before aging
void registerDevice()
Define how to use the device in a netlist.
Capacitor Master class.
Model & operator=(const Model &)
Base class for all parameters.
Definition: N_DEV_Pars.h:169
virtual bool loadDAEVectors(double *solVec, double *fVec, double *qVec, double *bVec, double *storeLeadF, double *storeLeadQ, double *leadF, double *leadQ, double *junctionV)
Load DAE vectors of all capacitor instances, regardless of model.
Instance(const Configuration &configuration, const InstanceBlock &instance_block, Model &model, const FactoryBlock &factory_block)
Construct a Capacitor model from a "model block" that was created by the netlist parser.
void registerStoreLIDs(const std::vector< int > &stoLIDVecRef)
Register the local store IDs.
Instance & operator=(const Instance &)
bool updatePrimaryState()
Update the state variables.
std::vector< int > ANegEquDepVarOffsets
Capacitor Model class.
DeviceMaster instantiates a device as described by the device traits T.
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Create a new instance of the Capacitor device.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Register the local state IDs.
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
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Loads the parameter definition into the instance parameter map.
bool loadDAEdFdx()
Load the DAE the derivative of the F vector with respect to the solution vector x, dFdx.
static void loadModelParameters(ParametricData< Model > &model_parameters)
Loads the parameter definition into the model parameter map.
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
static capSensitivity capSens
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
double q0
charge in the capacitor
int li_Bra
for the "voltage source" when IC is specified
Class Configuration contains device configuration data.
std::vector< int > APosEquDepVarOffsets
bool processParams()
Process parameters.
std::vector< double > expVarDerivs
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Register the Jacobian local IDs.
std::vector< double * > qPosEquDepVarsPtrs
const std::vector< std::vector< int > > & jacobianStamp() const
Return Jacobian stamp that informs topology of the layout of the resistor jacobian.
static const char * instanceDefaultParameter()
static const char * deviceTypeName()
bool updateTemperature(const double &temp_tmp)
Update the parameters that depend on the temperature of the device.
virtual std::ostream & printOutInstances(std::ostream &os) const
std::vector< std::vector< int > > jacStamp_IC
std::vector< std::vector< int > > jacStamp
std::vector< double * > qNegEquDepVarsPtrs
std::vector< Instance * > InstanceVector
Base sensitivity functor.
Definition: N_DEV_Pars.h:148
void setupPointers()
Setup direct access pointer to solution matrix and vectors.
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.
bool loadDAEFVector()
Load the DAE F vector.
double ageCoef
degradation coeficient.
static const char * primaryParameter()
void registerBranchDataLIDs(const std::vector< int > &branchLIDVecRef)
Register the local store IDs.
int li_branch_data
Index for lead current and junction voltage (for power calculations)
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Register local IDs.
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Load DAE matrices for all capacitor instances, regardless of model.
void varTypes(std::vector< char > &varTypeVec)