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.137.2.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:20:11 $
42 //
43 // Current Owner : $Author: tvrusso $
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_store_dev_i(-1),
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  numLeadCurrentStoreVars = 1; // lead current
115 
116  if( jacStamp.empty() )
117  {
118  jacStamp.resize(4);
119  jacStamp[0].resize(2);
120  jacStamp[0][0]=2;
121  jacStamp[0][1]=3;
122  jacStamp[1].resize(2);
123  jacStamp[1][0]=2;
124  jacStamp[1][1]=3;
125  }
126 
127  // Set params to constant default values:
129 
130  // Set params according to instance line and constant defaults from metadata:
131  setParams(instance_block.params);
132 
133  // Set any non-constant parameter defaults:
134  if (!given("T"))
135  {
136  UserError0(*this) << "Could not find Transconductance parameter in instance.";
137  }
138 }
139 
140 //-----------------------------------------------------------------------------
141 // Function : Instance::~Instance
142 // Purpose : destructor
143 // Special Notes :
144 // Scope : public
145 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
146 // Creation Date : 3/16/00
147 //-----------------------------------------------------------------------------
149 {
150 
151 }
152 
153 //-----------------------------------------------------------------------------
154 // Function : Instance::registerLIDs
155 // Purpose :
156 // Special Notes :
157 // Scope : public
158 // Creator : Robert Hoekstra, SNL, Component Information and Models
159 // Creation Date : 6/21/01
160 //-----------------------------------------------------------------------------
161 void Instance::registerLIDs( const std::vector<int> & intLIDVecRef,
162  const std::vector<int> & extLIDVecRef )
163 {
164  AssertLIDs(intLIDVecRef.size() == numIntVars);
165  AssertLIDs(extLIDVecRef.size() == numExtVars);
166 
167  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
168  {
169  Xyce::dout() << std::endl << section_divider << std::endl;
170  Xyce::dout() << " VCCSInstance::registerLIDs" << std::endl;
171  Xyce::dout() << " name = " << getName() << std::endl;
172  }
173 
174  // copy over the global ID lists.
175  intLIDVec = intLIDVecRef;
176  extLIDVec = extLIDVecRef;
177 
178  // Now use these lists to obtain the indices into the
179  // linear algebra entities. This assumes an order.
180  // For the matrix indices, first do the rows.
181 
182  li_Pos = extLIDVec[0];
183  li_Neg = extLIDVec[1];
184  li_ContPos = extLIDVec[2];
185  li_ContNeg = extLIDVec[3];
186 
187  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
188  {
189  Xyce::dout() << " li_Pos = " << li_Pos << std::endl;
190  Xyce::dout() << " li_Neg = " << li_Neg << std::endl;
191  Xyce::dout() << " li_ContPos = " << li_ContPos << std::endl;
192  Xyce::dout() << " li_ContNeg = " << li_ContNeg << std::endl;
193 
194  Xyce::dout() << section_divider << std::endl;
195  }
196 }
197 
198 //-----------------------------------------------------------------------------
199 // Function : Instance::registerStateLIDs
200 // Purpose :
201 // Special Notes :
202 // Scope : public
203 // Creator : Robert Hoektra, SNL, Parallel Computational Sciences
204 // Creation Date : 6/21/02
205 //-----------------------------------------------------------------------------
206 void Instance::registerStateLIDs( const std::vector<int> & staLIDVecRef)
207 {
208  AssertLIDs(staLIDVecRef.size() == numStateVars);
209 }
210 
211 
212 //-----------------------------------------------------------------------------
213 // Function : Instance::registerStoreLIDs
214 // Purpose :
215 // Special Notes :
216 // Scope : public
217 // Creator : Richard Schiek, Electrical Systems Modeling
218 // Creation Date : 4/23/2013
219 //-----------------------------------------------------------------------------
220 void Instance::registerStoreLIDs( const std::vector<int> & stoLIDVecRef )
221 {
222  AssertLIDs(stoLIDVecRef.size() == getNumStoreVars());
223 
224  // Copy over the global ID lists:
225  stoLIDVec = stoLIDVecRef;
226  if( loadLeadCurrent )
227  {
228  li_store_dev_i = stoLIDVec[0];
229  }
230 }
231 
232 //-----------------------------------------------------------------------------
233 // Function : Instance::jacobianStamp
234 // Purpose :
235 // Special Notes :
236 // Scope : public
237 // Creator : Robert Hoektra, SNL, Parallel Computational Sciences
238 // Creation Date : 9/2/02
239 //-----------------------------------------------------------------------------
240 const std::vector< std::vector<int> > & Instance::jacobianStamp() const
241 {
242  return jacStamp;
243 }
244 
245 //-----------------------------------------------------------------------------
246 // Function : Instance::registerJacLIDs
247 // Purpose :
248 // Special Notes :
249 // Scope : public
250 // Creator : Robert Hoektra, SNL, Parallel Computational Sciences
251 // Creation Date : 9/2/02
252 //-----------------------------------------------------------------------------
253 void Instance::registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec )
254 {
255  DeviceInstance::registerJacLIDs( jacLIDVec );
256 
257  APosEquContPosVarOffset = jacLIDVec[0][0];
258  APosEquContNegVarOffset = jacLIDVec[0][1];
259  ANegEquContPosVarOffset = jacLIDVec[1][0];
260  ANegEquContNegVarOffset = jacLIDVec[1][1];
261 }
262 
263 //-----------------------------------------------------------------------------
264 // Function : Instance::setupPointers
265 // Purpose :
266 // Special Notes :
267 // Scope : public
268 // Creator : Eric Keiter, SNL
269 // Creation Date : 12/12/08
270 //-----------------------------------------------------------------------------
272 {
273 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
274  Linear::Matrix & dFdx = *(extData.dFdxMatrixPtr);
275 
280 #endif
281 }
282 
283 //-----------------------------------------------------------------------------
284 // Function : Instance::loadNodeSymbols
285 // Purpose :
286 // Special Notes :
287 // Scope : public
288 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
289 // Creation Date : 05/13/05
290 //-----------------------------------------------------------------------------
291 void Instance::loadNodeSymbols(Util::SymbolTable &symbol_table) const
292 {
293  addStoreNode(symbol_table, li_store_dev_i, getName(), "DEV_I");
294 }
295 
296 //-----------------------------------------------------------------------------
297 // Function : Instance::updatePrimaryState
298 // Purpose :
299 // Special Notes :
300 // Scope : public
301 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
302 // Creation Date : 01/29/01
303 //-----------------------------------------------------------------------------
305 {
306  return true;
307 }
308 
309 //-----------------------------------------------------------------------------
310 // Function : Instance::loadDAEFVector
311 //
312 // Purpose : Loads the F-vector contributions for a single
313 // VCCS instance.
314 //
315 // Special Notes :
316 //
317 // Scope : public
318 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
319 // Creation Date : 01/24/03
320 //-----------------------------------------------------------------------------
322 {
323  double * solVec = extData.nextSolVectorRawPtr;
324  double * fVec = extData.daeFVectorRawPtr;
325 
326  double v_cont_pos = solVec[li_ContPos];
327  double v_cont_neg = solVec[li_ContNeg];
328 
329  fVec[li_Pos] += Transconductance * ( v_cont_pos - v_cont_neg );
330  fVec[li_Neg] += -Transconductance * ( v_cont_pos - v_cont_neg );
331 
332  if( loadLeadCurrent )
333  {
334  double * storeLeadF = extData.nextStoVectorRawPtr;
335  storeLeadF[li_store_dev_i] = Transconductance * ( v_cont_pos - v_cont_neg );
336  }
337 
338  return true;
339 }
340 
341 //-----------------------------------------------------------------------------
342 // Function : Instance::loadDAEdFdx ()
343 //
344 // Purpose : Loads the F-vector contributions for a single
345 // VCCS instance.
346 //
347 // Special Notes : See the special notes for loadDAEFVector.
348 //
349 // Scope : public
350 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
351 // Creation Date : 03/05/04
352 //-----------------------------------------------------------------------------
354 {
355  Linear::Matrix & dFdx = *(extData.dFdxMatrixPtr);
356 
361 
362  return true;
363 }
364 
365 // Class Model
366 //-----------------------------------------------------------------------------
367 // Function : Model::Model
368 // Purpose : "Model block" constructor
369 // Special Notes :
370 // Scope : public
371 // Creator : Tom Russo, SNL, Component Information and Models
372 // Creation Date : 12/21/00
373 //-----------------------------------------------------------------------------
375  const Configuration & configuration,
376  const ModelBlock & MB,
377  const FactoryBlock & factory_block)
378  : DeviceModel(MB, configuration.getModelParameters(), factory_block)
379 {
380 }
381 
382 //-----------------------------------------------------------------------------
383 // Function : Model::~Model
384 // Purpose : destructor
385 // Special Notes :
386 // Scope : public
387 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
388 // Creation Date : 3/16/00
389 //-----------------------------------------------------------------------------
391 {
392  std::vector<Instance*>::iterator iter;
393  std::vector<Instance*>::iterator first = instanceContainer.begin();
394  std::vector<Instance*>::iterator last = instanceContainer.end();
395 
396  for (iter=first; iter!=last; ++iter)
397  {
398  delete (*iter);
399  }
400 }
401 
402 //-----------------------------------------------------------------------------
403 // Function : Model::printOutInstances
404 // Purpose : debugging tool.
405 // Special Notes :
406 // Scope : public
407 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
408 // Creation Date : 4/03/00
409 //-----------------------------------------------------------------------------
410 std::ostream &Model::printOutInstances(std::ostream &os) const
411 {
412  std::vector<Instance*>::const_iterator iter;
413  std::vector<Instance*>::const_iterator first = instanceContainer.begin();
414  std::vector<Instance*>::const_iterator last = instanceContainer.end();
415 
416  int i;
417  os << std::endl;
418  os << " name model name Parameters" << std::endl;
419  for (i=0, iter=first; iter!=last; ++iter, ++i)
420  {
421  os << " " << i << ": " << (*iter)->getName() << " ";
422  os << getName();
423  os << std::endl;
424  }
425 
426  os << std::endl;
427 
428  return os;
429 }
430 
431 //-----------------------------------------------------------------------------
432 // Function : Model::forEachInstance
433 // Purpose :
434 // Special Notes :
435 // Scope : public
436 // Creator : David Baur
437 // Creation Date : 2/4/2014
438 //-----------------------------------------------------------------------------
439 /// Apply a device instance "op" to all instances associated with this
440 /// model
441 ///
442 /// @param[in] op Operator to apply to all instances.
443 ///
444 ///
445 void Model::forEachInstance(DeviceInstanceOp &op) const /* override */
446 {
447  for (std::vector<Instance *>::const_iterator it = instanceContainer.begin(); it != instanceContainer.end(); ++it)
448  op(*it);
449 }
450 
451 
452 // VCCS Master functions:
453 
454 //-----------------------------------------------------------------------------
455 // Function : Master::updateState
456 // Purpose :
457 // Special Notes :
458 // Scope : public
459 // Creator : Eric Keiter, SNL
460 // Creation Date : 12/12/08
461 //-----------------------------------------------------------------------------
462 bool Master::updateState (double * solVec, double * staVec, double * stoVec)
463 {
464  return true;
465 }
466 
467 //-----------------------------------------------------------------------------
468 // Function : Master::loadDAEVectors
469 // Purpose :
470 // Special Notes :
471 // Scope : public
472 // Creator : Eric Keiter, SNL
473 // Creation Date : 12/12/08
474 //-----------------------------------------------------------------------------
475 bool Master::loadDAEVectors (double * solVec, double * fVec, double *qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV)
476 {
477  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
478  {
479  Instance & vi = *(*it);
480  double v_cont_pos = solVec[vi.li_ContPos];
481  double v_cont_neg = solVec[vi.li_ContNeg];
482 
483 
484  fVec[vi.li_Pos] += vi.Transconductance * ( v_cont_pos - v_cont_neg );
485  fVec[vi.li_Neg] += -vi.Transconductance * ( v_cont_pos - v_cont_neg );
486  if( vi.loadLeadCurrent )
487  {
488  storeLeadF[vi.li_store_dev_i] = vi.Transconductance * ( v_cont_pos - v_cont_neg );
489  }
490  }
491 
492  return true;
493 }
494 
495 //-----------------------------------------------------------------------------
496 // Function : Master::loadDAEMatrices
497 // Purpose :
498 // Special Notes :
499 // Scope : public
500 // Creator : Eric Keiter, SNL
501 // Creation Date : 12/12/08
502 //-----------------------------------------------------------------------------
503 bool Master::loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx)
504 {
505  for (InstanceVector::const_iterator it = getInstanceBegin(); it != getInstanceEnd(); ++it)
506  {
507  Instance & vi = *(*it);
508 
509 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
514 #else
515 
520 #endif
521  }
522 
523  return true;
524 }
525 
526 Device *Traits::factory(const Configuration &configuration, const FactoryBlock &factory_block)
527 {
528 
529  return new Master(configuration, factory_block, factory_block.solverState_, factory_block.deviceOptions_);
530 }
531 
533 {
535  .registerDevice("g", 1);
536 }
537 
538 } // namespace VCCS
539 } // namespace Device
540 } // 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:475
bool given(const std::string &parameter_name) const
Pure virtual class to augment a linear system.
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:445
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_VCCS.C:462
virtual void registerJacLIDs(const JacobianStamp &jacLIDVec)
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_VCCS.C:240
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:253
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
void addStoreNode(Util::SymbolTable &symbol_table, int index, const InstanceName &instance_name, const std::string &lead_name)
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_VCCS.C:503
const SolverState & solverState_
Class Configuration contains device configuration data.
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_VCCS.C:74
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_VCCS.C:161
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_VCCS.C:206
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_VCCS.C:526
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:291
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_VCCS.C:410
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:220