Xyce  6.1
N_DEV_VCCS.C
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_VCCS.C,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.140 $
40 //
41 // Revision Date : $Date: 2015/04/27 20:33:21 $
42 //
43 // Current Owner : $Author: peshola $
44 //-------------------------------------------------------------------------
45 #include <Xyce_config.h>
46 
47 // ---------- Standard Includes ----------
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_DeviceOptions.h>
51 #include <N_DEV_ExternData.h>
52 #include <N_DEV_MatrixLoadData.h>
53 #include <N_DEV_SolverState.h>
54 #include <N_DEV_VCCS.h>
55 #include <N_DEV_Message.h>
56 #include <N_ERH_ErrorMgr.h>
57 
58 #include <N_LAS_Vector.h>
59 #include <N_LAS_Matrix.h>
60 #include <N_UTL_FeatureTest.h>
61 
62 namespace Xyce {
63 namespace Device {
64 
65 namespace VCCS {
66 
67 
69 {
71  .setDescription("Transconductance");
72 }
73 
75 {
76 }
77 
78 // static member components
79 std::vector< std::vector<int> > Instance::jacStamp;
80 
81 //-----------------------------------------------------------------------------
82 // Function : ::
83 // Purpose : "instance block" constructor
84 // Special Notes :
85 // Scope : public
86 // Creator : Tom Russo, SNL, Component Information and Models
87 // Creation Date : 12/20/00
88 //-----------------------------------------------------------------------------
90  const Configuration & configuration,
91  const InstanceBlock & instance_block,
92  Model & model,
93  const FactoryBlock & factory_block)
94  : DeviceInstance(instance_block, configuration.getInstanceParameters(), factory_block),
95  model_(model),
96  Transconductance(1.0),
97  li_Pos(-1),
98  li_Neg(-1),
99  li_ContPos(-1),
100  li_ContNeg(-1),
101  li_branch_data(0),
102  APosEquContPosVarOffset(-1),
103  APosEquContNegVarOffset(-1),
104  ANegEquContPosVarOffset(-1),
105  ANegEquContNegVarOffset(-1),
106  f_PosEquContPosVarPtr(0),
107  f_PosEquContNegVarPtr(0),
108  f_NegEquContPosVarPtr(0),
109  f_NegEquContNegVarPtr(0)
110 {
111  numIntVars = 0;
112  numExtVars = 4;
113  numStateVars = 0;
114  setNumBranchDataVars(0); // by default don't allocate space in branch vectors
115  numBranchDataVarsIfAllocated = 1; // this is the space to allocate if lead current or power is needed.
116 
117  if( jacStamp.empty() )
118  {
119  jacStamp.resize(4);
120  jacStamp[0].resize(2);
121  jacStamp[0][0]=2;
122  jacStamp[0][1]=3;
123  jacStamp[1].resize(2);
124  jacStamp[1][0]=2;
125  jacStamp[1][1]=3;
126  }
127 
128  // Set params to constant default values:
130 
131  // Set params according to instance line and constant defaults from metadata:
132  setParams(instance_block.params);
133 
134  // Set any non-constant parameter defaults:
135  if (!given("T"))
136  {
137  UserError0(*this) << "Could not find Transconductance parameter in instance.";
138  }
139 }
140 
141 //-----------------------------------------------------------------------------
142 // Function : Instance::~Instance
143 // Purpose : destructor
144 // Special Notes :
145 // Scope : public
146 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
147 // Creation Date : 3/16/00
148 //-----------------------------------------------------------------------------
150 {
151 
152 }
153 
154 //-----------------------------------------------------------------------------
155 // Function : Instance::registerLIDs
156 // Purpose :
157 // Special Notes :
158 // Scope : public
159 // Creator : Robert Hoekstra, SNL, Component Information and Models
160 // Creation Date : 6/21/01
161 //-----------------------------------------------------------------------------
162 void Instance::registerLIDs( const std::vector<int> & intLIDVecRef,
163  const std::vector<int> & extLIDVecRef )
164 {
165  AssertLIDs(intLIDVecRef.size() == numIntVars);
166  AssertLIDs(extLIDVecRef.size() == numExtVars);
167 
168  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
169  {
170  Xyce::dout() << std::endl << section_divider << std::endl;
171  Xyce::dout() << " VCCSInstance::registerLIDs" << std::endl;
172  Xyce::dout() << " name = " << getName() << std::endl;
173  }
174 
175  // copy over the global ID lists.
176  intLIDVec = intLIDVecRef;
177  extLIDVec = extLIDVecRef;
178 
179  // Now use these lists to obtain the indices into the
180  // linear algebra entities. This assumes an order.
181  // For the matrix indices, first do the rows.
182 
183  li_Pos = extLIDVec[0];
184  li_Neg = extLIDVec[1];
185  li_ContPos = extLIDVec[2];
186  li_ContNeg = extLIDVec[3];
187 
188  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
189  {
190  Xyce::dout() << " li_Pos = " << li_Pos << std::endl;
191  Xyce::dout() << " li_Neg = " << li_Neg << std::endl;
192  Xyce::dout() << " li_ContPos = " << li_ContPos << std::endl;
193  Xyce::dout() << " li_ContNeg = " << li_ContNeg << std::endl;
194 
195  Xyce::dout() << section_divider << std::endl;
196  }
197 }
198 
199 //-----------------------------------------------------------------------------
200 // Function : Instance::registerBranchDataLIDs
201 // Purpose :
202 // Special Notes :
203 // Scope : public
204 // Creator : Richard Schiek, Electrical Systems Modeling
205 // Creation Date : 12/18/2012
206 //-----------------------------------------------------------------------------
207 /// Register the local store IDs
208 ///
209 /// In addition to state vector, Xyce maintains a separate datastructure
210 /// called a "branch data" vector. As with other such vectors, the device
211 /// declares at construction time how many branch vector entries it needs,
212 /// and later Topology assigns locations for devices, returning LIDs.
213 ///
214 /// These LIDs are stored in this method for later use.
215 ///
216 /// The Resistor device uses exactly one "branch data vector" element, where
217 ///
218 /// @param stoLIDVecRef Store variable local IDs
219 ///
220 /// @author Richard Schiek, Electrical Systems Modeling
221 /// @date 12/18/2012
222 
223 void Instance::registerBranchDataLIDs(const std::vector<int> & branchLIDVecRef)
224 {
225  AssertLIDs(branchLIDVecRef.size() == getNumBranchDataVars());
226 
227  if (loadLeadCurrent)
228  {
229  li_branch_data= branchLIDVecRef[0];
230  }
231 }
232 
233 //-----------------------------------------------------------------------------
234 // Function : Instance::registerStateLIDs
235 // Purpose :
236 // Special Notes :
237 // Scope : public
238 // Creator : Robert Hoektra, SNL, Parallel Computational Sciences
239 // Creation Date : 6/21/02
240 //-----------------------------------------------------------------------------
241 void Instance::registerStateLIDs( const std::vector<int> & staLIDVecRef)
242 {
243  AssertLIDs(staLIDVecRef.size() == numStateVars);
244 }
245 
246 
247 //-----------------------------------------------------------------------------
248 // Function : Instance::registerStoreLIDs
249 // Purpose :
250 // Special Notes :
251 // Scope : public
252 // Creator : Richard Schiek, Electrical Systems Modeling
253 // Creation Date : 4/23/2013
254 //-----------------------------------------------------------------------------
255 void Instance::registerStoreLIDs( const std::vector<int> & stoLIDVecRef )
256 {
257  AssertLIDs(stoLIDVecRef.size() == getNumStoreVars());
258 
259  // Copy over the global ID lists:
260  stoLIDVec = stoLIDVecRef;
261 }
262 
263 //-----------------------------------------------------------------------------
264 // Function : Instance::jacobianStamp
265 // Purpose :
266 // Special Notes :
267 // Scope : public
268 // Creator : Robert Hoektra, SNL, Parallel Computational Sciences
269 // Creation Date : 9/2/02
270 //-----------------------------------------------------------------------------
271 const std::vector< std::vector<int> > & Instance::jacobianStamp() const
272 {
273  return jacStamp;
274 }
275 
276 //-----------------------------------------------------------------------------
277 // Function : Instance::registerJacLIDs
278 // Purpose :
279 // Special Notes :
280 // Scope : public
281 // Creator : Robert Hoektra, SNL, Parallel Computational Sciences
282 // Creation Date : 9/2/02
283 //-----------------------------------------------------------------------------
284 void Instance::registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec )
285 {
286  DeviceInstance::registerJacLIDs( jacLIDVec );
287 
288  APosEquContPosVarOffset = jacLIDVec[0][0];
289  APosEquContNegVarOffset = jacLIDVec[0][1];
290  ANegEquContPosVarOffset = jacLIDVec[1][0];
291  ANegEquContNegVarOffset = jacLIDVec[1][1];
292 }
293 
294 //-----------------------------------------------------------------------------
295 // Function : Instance::setupPointers
296 // Purpose :
297 // Special Notes :
298 // Scope : public
299 // Creator : Eric Keiter, SNL
300 // Creation Date : 12/12/08
301 //-----------------------------------------------------------------------------
303 {
304 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
305  Linear::Matrix & dFdx = *(extData.dFdxMatrixPtr);
306 
311 #endif
312 }
313 
314 //-----------------------------------------------------------------------------
315 // Function : Instance::loadNodeSymbols
316 // Purpose :
317 // Special Notes :
318 // Scope : public
319 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
320 // Creation Date : 05/13/05
321 //-----------------------------------------------------------------------------
322 void Instance::loadNodeSymbols(Util::SymbolTable &symbol_table) const
323 {
324  if (loadLeadCurrent)
325  {
326  addBranchDataNode( symbol_table, li_branch_data, getName(), "BRANCH_D");
327  }
328 }
329 
330 //-----------------------------------------------------------------------------
331 // Function : Instance::updatePrimaryState
332 // Purpose :
333 // Special Notes :
334 // Scope : public
335 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
336 // Creation Date : 01/29/01
337 //-----------------------------------------------------------------------------
339 {
340  return true;
341 }
342 
343 //-----------------------------------------------------------------------------
344 // Function : Instance::loadDAEFVector
345 //
346 // Purpose : Loads the F-vector contributions for a single
347 // VCCS instance.
348 //
349 // Special Notes :
350 //
351 // Scope : public
352 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
353 // Creation Date : 01/24/03
354 //-----------------------------------------------------------------------------
356 {
357  double * solVec = extData.nextSolVectorRawPtr;
358  double * fVec = extData.daeFVectorRawPtr;
359 
360  double v_cont_pos = solVec[li_ContPos];
361  double v_cont_neg = solVec[li_ContNeg];
362 
363  fVec[li_Pos] += Transconductance * ( v_cont_pos - v_cont_neg );
364  fVec[li_Neg] += -Transconductance * ( v_cont_pos - v_cont_neg );
365 
366  if( loadLeadCurrent )
367  {
368  double * storeLeadF = extData.nextStoVectorRawPtr;
369  double * leadF = extData.nextLeadCurrFCompRawPtr;
370  double * junctionV = extData.nextJunctionVCompRawPtr;
371  leadF[li_branch_data] = Transconductance * ( v_cont_pos - v_cont_neg );
372  junctionV[li_branch_data] = solVec[li_Pos] - solVec[li_Neg];
373  }
374 
375  return true;
376 }
377 
378 //-----------------------------------------------------------------------------
379 // Function : Instance::loadDAEdFdx ()
380 //
381 // Purpose : Loads the F-vector contributions for a single
382 // VCCS instance.
383 //
384 // Special Notes : See the special notes for loadDAEFVector.
385 //
386 // Scope : public
387 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
388 // Creation Date : 03/05/04
389 //-----------------------------------------------------------------------------
391 {
392  Linear::Matrix & dFdx = *(extData.dFdxMatrixPtr);
393 
398 
399  return true;
400 }
401 
402 // Class Model
403 //-----------------------------------------------------------------------------
404 // Function : Model::Model
405 // Purpose : "Model block" constructor
406 // Special Notes :
407 // Scope : public
408 // Creator : Tom Russo, SNL, Component Information and Models
409 // Creation Date : 12/21/00
410 //-----------------------------------------------------------------------------
412  const Configuration & configuration,
413  const ModelBlock & MB,
414  const FactoryBlock & factory_block)
415  : DeviceModel(MB, configuration.getModelParameters(), factory_block)
416 {
417 }
418 
419 //-----------------------------------------------------------------------------
420 // Function : Model::~Model
421 // Purpose : destructor
422 // Special Notes :
423 // Scope : public
424 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
425 // Creation Date : 3/16/00
426 //-----------------------------------------------------------------------------
428 {
429  std::vector<Instance*>::iterator iter;
430  std::vector<Instance*>::iterator first = instanceContainer.begin();
431  std::vector<Instance*>::iterator last = instanceContainer.end();
432 
433  for (iter=first; iter!=last; ++iter)
434  {
435  delete (*iter);
436  }
437 }
438 
439 //-----------------------------------------------------------------------------
440 // Function : Model::printOutInstances
441 // Purpose : debugging tool.
442 // Special Notes :
443 // Scope : public
444 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
445 // Creation Date : 4/03/00
446 //-----------------------------------------------------------------------------
447 std::ostream &Model::printOutInstances(std::ostream &os) const
448 {
449  std::vector<Instance*>::const_iterator iter;
450  std::vector<Instance*>::const_iterator first = instanceContainer.begin();
451  std::vector<Instance*>::const_iterator last = instanceContainer.end();
452 
453  int i;
454  os << std::endl;
455  os << " name model name Parameters" << std::endl;
456  for (i=0, iter=first; iter!=last; ++iter, ++i)
457  {
458  os << " " << i << ": " << (*iter)->getName() << " ";
459  os << getName();
460  os << std::endl;
461  }
462 
463  os << std::endl;
464 
465  return os;
466 }
467 
468 //-----------------------------------------------------------------------------
469 // Function : Model::forEachInstance
470 // Purpose :
471 // Special Notes :
472 // Scope : public
473 // Creator : David Baur
474 // Creation Date : 2/4/2014
475 //-----------------------------------------------------------------------------
476 /// Apply a device instance "op" to all instances associated with this
477 /// model
478 ///
479 /// @param[in] op Operator to apply to all instances.
480 ///
481 ///
482 void Model::forEachInstance(DeviceInstanceOp &op) const /* override */
483 {
484  for (std::vector<Instance *>::const_iterator it = instanceContainer.begin(); it != instanceContainer.end(); ++it)
485  op(*it);
486 }
487 
488 
489 // VCCS Master functions:
490 
491 //-----------------------------------------------------------------------------
492 // Function : Master::updateState
493 // Purpose :
494 // Special Notes :
495 // Scope : public
496 // Creator : Eric Keiter, SNL
497 // Creation Date : 12/12/08
498 //-----------------------------------------------------------------------------
499 bool Master::updateState (double * solVec, double * staVec, double * stoVec)
500 {
501  return true;
502 }
503 
504 //-----------------------------------------------------------------------------
505 // Function : Master::loadDAEVectors
506 // Purpose :
507 // Special Notes :
508 // Scope : public
509 // Creator : Eric Keiter, SNL
510 // Creation Date : 12/12/08
511 //-----------------------------------------------------------------------------
512 bool Master::loadDAEVectors (double * solVec, double * fVec, double *qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV)
513 {
514  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
515  {
516  Instance & vi = *(*it);
517  double v_cont_pos = solVec[vi.li_ContPos];
518  double v_cont_neg = solVec[vi.li_ContNeg];
519 
520 
521  fVec[vi.li_Pos] += vi.Transconductance * ( v_cont_pos - v_cont_neg );
522  fVec[vi.li_Neg] += -vi.Transconductance * ( v_cont_pos - v_cont_neg );
523  if( vi.loadLeadCurrent )
524  {
525  leadF[vi.li_branch_data] = vi.Transconductance * ( v_cont_pos - v_cont_neg );
526  junctionV[vi.li_branch_data] = solVec[vi.li_Pos] - solVec[vi.li_Neg];
527  }
528  }
529 
530  return true;
531 }
532 
533 //-----------------------------------------------------------------------------
534 // Function : Master::loadDAEMatrices
535 // Purpose :
536 // Special Notes :
537 // Scope : public
538 // Creator : Eric Keiter, SNL
539 // Creation Date : 12/12/08
540 //-----------------------------------------------------------------------------
541 bool Master::loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx)
542 {
543  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
544  {
545  Instance & vi = *(*it);
546 
547 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
552 #else
553 
558 #endif
559  }
560 
561  return true;
562 }
563 
564 Device *Traits::factory(const Configuration &configuration, const FactoryBlock &factory_block)
565 {
566 
567  return new Master(configuration, factory_block, factory_block.solverState_, factory_block.deviceOptions_);
568 }
569 
571 {
573  .registerDevice("g", 1);
574 }
575 
576 } // namespace VCCS
577 } // namespace Device
578 } // namespace Xyce
const InstanceName & getName() const
const DeviceOptions & deviceOptions_
std::vector< Instance * > instanceContainer
Definition: N_DEV_VCCS.h:213
Descriptor & addPar(const char *parName, T default_value, T U::*varPtr)
Adds the parameter description to the parameter map.
Definition: N_DEV_Pars.h:1429
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_VCCS.C:512
bool given(const std::string &parameter_name) const
Pure virtual class to augment a linear system.
void addBranchDataNode(Util::SymbolTable &symbol_table, int index, const InstanceName &instance_name, const std::string &lead_name)
InstanceVector::const_iterator getInstanceEnd() const
Returns an iterator to the ending of the vector of all instances created for this device...
#define AssertLIDs(cmp)
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Definition: N_DEV_VCCS.C:482
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_VCCS.C:499
virtual void registerJacLIDs(const JacobianStamp &jacLIDVec)
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_VCCS.C:271
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_VCCS.C:68
InstanceVector::const_iterator getInstanceBegin() const
Returns an iterator to the beginning of the vector of all instances created for this device...
void setParams(const std::vector< Param > &params)
const std::string & getName() const
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_VCCS.C:284
Instance(const Configuration &configuration, const InstanceBlock &instance_block, Model &model, const FactoryBlock &factory_block)
Definition: N_DEV_VCCS.C:89
static Config< T > & addConfiguration()
Adds the device to the Xyce device configuration.
Linear::Matrix * dFdxMatrixPtr
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_VCCS.C:541
const SolverState & solverState_
Class Configuration contains device configuration data.
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_VCCS.C:74
void setNumBranchDataVars(int num_branch_data_vars)
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_VCCS.C:162
void registerBranchDataLIDs(const std::vector< int > &branchLIDVecRef)
Register the local store IDs.
Definition: N_DEV_VCCS.C:223
int li_branch_data
Index for lead current and junction voltage (for power calculations)
Definition: N_DEV_VCCS.h:151
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_VCCS.C:241
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_VCCS.C:564
static std::vector< std::vector< int > > jacStamp
Definition: N_DEV_VCCS.h:137
virtual void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_VCCS.C:322
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_VCCS.C:447
ModelBlock represents a .MODEL line from the netlist.
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
InstanceBlock represent a device instance line from the netlist.
std::vector< Param > params
void registerStoreLIDs(const std::vector< int > &stoLIDVecRef)
Definition: N_DEV_VCCS.C:255