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.136 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:24 $
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  bool isLinearDevice() const { return true; }
135 
136  void registerLIDs( const std::vector<int> & intLIDVecRef, const std::vector<int> & extLIDVecRef );
137  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
138  void registerStoreLIDs( const std::vector<int> & stoLIDVecRef );
139  void registerBranchDataLIDs(const std::vector<int> & branchLIDVecRef);
140  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
141 
142  const std::vector< std::vector<int> > & jacobianStamp() const;
143  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
144 
145  bool processParams ();
146  bool updateTemperature(const double & temp_tmp);
147 
148  bool updateIntermediateVars () { return true; };
149  bool updatePrimaryState ();
150 
151  bool setIC ();
152 
153  // load functions, residual:
154  bool loadDAEQVector ();
155  bool loadDAEFVector ();
156 
157  // load functions, Jacobian:
158  bool loadDAEdQdx ();
159  bool loadDAEdFdx ();
160 
161  void setupPointers();
162 
163  void varTypes( std::vector<char> & varTypeVec );
164 
165  // Getters and setters
167  {
168  return model_;
169  }
170 
171 private:
172  Model & model_; //< Owning model
173 
174  // Stuff for handling solution-variable-dependent capacitance
175  Util::Expression * expPtr;
177 
178  std::vector<double> expVarDerivs;
179 
180  // user-specified parameters:
181  double C; // User specified capacitance. (Farads)
182  double IC; // Optional initial value capacitor voltage (V).
183 
184  // These are for the semiconductor capacitor
185  double length; // capacitor length
186  double width; // capacitor width
187  double temp; // temperature of this instance
188 
189  // Genie 121412. temperature dependence parameters
190  // these can override values specified in the model
191  double tempCoeff1; // first order temperature coeff.
192  double tempCoeff2; // second order temperature coeff.
193 
194  // flags used to tell if the user has specified one of these values
195  // on the command line.
198 
199  // These are for the age-aware capacitor
200  double age; ///< age in hours
201  double ageCoef; ///< degradation coeficient.
202  double baseCap; ///< the baseline capacitance before aging
203 
204  bool tempGiven;
205  bool ICGiven;
207 
208  // state variables:
209  double q0; ///< charge in the capacitor
210  // now held in the store vector at li_store_dev_i
211  double vcap; // voltage drop across capacitor
212 
213  //local id's (offsets)
214  int li_Pos;
215  int li_Neg;
216  int li_Bra; ///< for the "voltage source" when IC is specified
217  int li_branch_data; ///< Index for lead current and junction voltage (for power calculations)
218 
220 
221  std::vector<int> li_dQdXState;
222  std::vector<int> li_dCdXState;
225 
227 
228  // Offsets for Jacobian
233 
234  // offsets for when C is solution-variable dependent
235  std::vector<int> APosEquDepVarOffsets;
236  std::vector<int> ANegEquDepVarOffsets;
237 
243 
244 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
245  // Pointers for Jacobian
250 
256 
257  std::vector<double *> qPosEquDepVarsPtrs;
258  std::vector<double *> qNegEquDepVarsPtrs;
259 #endif
260 
261  std::vector< std::vector<int> > jacStamp;
262  std::vector< std::vector<int> > jacStamp_IC;
263 };
264 
265 //-----------------------------------------------------------------------------
266 // Class : Model
267 // Purpose :
268 // Special Notes :
269 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
270 // Creation Date : 3/16/00
271 //-----------------------------------------------------------------------------
272 /// Capacitor Model class
273 ///
274 class Model : public DeviceModel
275 {
276  typedef std::vector<Instance *> InstanceVector;
277 
278  friend class ParametricData<Model>;
279  friend class Instance;
280  friend class Traits;
281  friend class Master;
282  friend class capSensitivity;
283 
284 public:
285  Model(
286  const Configuration & configuration,
287  const ModelBlock & model_block,
288  const FactoryBlock & factory_block);
289  ~Model();
290 
291 private:
292  Model();
293  Model(const Model &);
294  Model &operator=(const Model &);
295 
296 public:
297  bool processParams ();
298  bool processInstanceParams ();
299  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
300 
301  virtual std::ostream &printOutInstances(std::ostream &os) const;
302 
303 public:
304  void addInstance(Instance *instance)
305  {
306  instanceContainer.push_back(instance);
307  }
308 
309 private:
310  std::vector<Instance*> instanceContainer;
311 
312 private:
313 
314  // for the semiconductor capacitor (cap with a model card)
315 
316  double capacitanceMultiplier; // capacitance multiplier
317  double cj; // junction bottom capacitance
318  double cjsw; // junction sidewall capacitance
319  double defWidth; // default width
320  double narrow; // narrowing due to side etching
321  double tempCoeff1; // first order temperature coeff.
322  double tempCoeff2; // second order temperature coeff.
323  double baseCap;
324  double tnom;
325 
326  bool tnomGiven;
327 };
328 
329 //-----------------------------------------------------------------------------
330 // Class : Master
331 // Purpose :
332 // Special Notes :
333 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
334 // Creation Date : 11/26/08
335 //-----------------------------------------------------------------------------
336 ///
337 /// Capacitor Master class
338 ///
339 /// The "master" class is the one that contains the updateState, loadDAEVectors
340 /// and loadDAEMatrices methods that are actually called when it is time to
341 /// compute and load device contributions.
342 ///
343 /// The default implementations of these methods in the DeviceMaster
344 /// template class simply loops over all instances and calls their
345 /// updatePrimaryState, loadDAEFVector/loadDAEQVector, and
346 /// loadDAEdFdx/loadDAEdQdx methods, respectively.
347 ///
348 /// For efficiency, the Capacitor class reimplements these methods to do the
349 /// work directly, instead of calling instance-level functions.
350 ///
351 class Master : public DeviceMaster<Traits>
352 {
353  friend class Instance;
354  friend class Model;
355 
356 public:
358  const Configuration & configuration,
359  const FactoryBlock & factory_block,
360  const SolverState & ss1,
361  const DeviceOptions & do1)
362  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
363  {}
364 
365  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
366 
367  // load functions:
368  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
369  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
370 };
371 
372 void registerDevice();
373 
374 } // namespace Capacitor
375 } // namespace Device
376 } // namespace Xyce
377 
378 #endif // Xyce_N_DEV_Capacitor_h
379 
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)