Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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.128.2.1 $
40 //
41 // Revision Date : $Date: 2014/08/28 18:08:27 $
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 
138  std::map<int,std::string> & getIntNameMap ();
139  std::map<int,std::string> & getStoreNameMap();
140 
141  const std::vector< std::vector<int> > & jacobianStamp() const;
142  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
143 
144  bool processParams ();
145  bool updateTemperature(const double & temp_tmp);
146 
147  bool updateIntermediateVars () { return true; };
148  bool updatePrimaryState ();
149 
150  bool setIC ();
151 
152  // load functions, residual:
153  bool loadDAEQVector ();
154  bool loadDAEFVector ();
155 
156  // load functions, Jacobian:
157  bool loadDAEdQdx ();
158  bool loadDAEdFdx ();
159 
160  void setupPointers();
161 
162  void varTypes( std::vector<char> & varTypeVec );
163 
164  // Getters and setters
166  {
167  return model_;
168  }
169 
170 private:
171  Model & model_; //< Owning model
172 
173  // Stuff for handling solution-variable-dependent capacitance
174  Util::Expression * expPtr;
176 
177  std::vector<double> expVarDerivs;
178 
179  // user-specified parameters:
180  double C; // User specified capacitance. (Farads)
181  double IC; // Optional initial value capacitor voltage (V).
182 
183  // These are for the semiconductor capacitor
184  double length; // capacitor length
185  double width; // capacitor width
186  double temp; // temperature of this instance
187 
188  // Genie 121412. temperature dependence parameters
189  // these can override values specified in the model
190  double tempCoeff1; // first order temperature coeff.
191  double tempCoeff2; // second order temperature coeff.
192 
193  // flags used to tell if the user has specified one of these values
194  // on the command line.
197 
198  // These are for the age-aware capacitor
199  double age; ///< age in hours
200  double ageCoef; ///< degradation coeficient.
201  double baseCap; ///< the baseline capacitance before aging
202 
203  bool tempGiven;
204  bool ICGiven;
206 
207  // state variables:
208  double q0; ///< charge in the capacitor
209  // now held in the store vector at li_store_dev_i
210  double vcap; // voltage drop across capacitor
211 
212  //local id's (offsets)
213  int li_Pos;
214  int li_Neg;
215  int li_Bra; ///< for the "voltage source" when IC is specified
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);
367  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
368 };
369 
370 void registerDevice();
371 
372 } // namespace Capacitor
373 } // namespace Device
374 } // namespace Xyce
375 
379 
380 #endif // Xyce_N_DEV_Capacitor_h
381