Xyce  6.1
N_DEV_DeviceMaster.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_DeviceMaster.h,v $
27 //
28 // Purpose : Provides templated versions of some boilerplate functions
29 // that are device-specific (so they can't easily be included
30 // in the base device, instance, or model classes).
31 //
32 // Special Notes : Much of the functionality of the device classes, like
33 // N_DEV_Capacitor, is simply to manage STL containers
34 // of model and instance pointers. That management is pretty
35 // generic, so templating that functionality makes sense.
36 //
37 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
38 //
39 // Creation Date : 01/31/06
40 //
41 // Revision Information:
42 // ---------------------
43 //
44 // Revision Number: $Revision: 1.23 $
45 //
46 // Revision Date : $Date: 2015/07/14 22:13:53 $
47 //
48 // Current Owner : $Author: hkthorn $
49 //-------------------------------------------------------------------------
50 
51 #ifndef Xyce_N_DEV_Device_Template_h
52 #define Xyce_N_DEV_Device_Template_h
53 
54 #if defined(HAVE_UNORDERED_MAP)
55 #include <unordered_map>
56 using std::unordered_map;
57 #elif defined(HAVE_TR1_UNORDERED_MAP)
58 #include <tr1/unordered_map>
59 using std::tr1::unordered_map;
60 #else
61 #error neither unordered_map or tr1/unordered_map found
62 #endif
63 #include <string>
64 #include <vector>
65 
66 #include <N_DEV_Device.h>
67 #include <N_DEV_DeviceModel.h>
68 #include <N_DEV_DeviceBlock.h>
69 #include <N_DEV_Configuration.h>
70 
71 namespace Xyce {
72 namespace Device {
73 
74 void instance_must_reference_model_error(const Device &device, const std::string &name, const NetlistLocation &netlist_location);
75 void could_not_find_model_error(const Device &device, const std::string &model_name, const std::string &instance_name, const NetlistLocation &netlist_location);
76 void duplicate_model_warning(const Device &device, const DeviceModel &model, const NetlistLocation &netlist_location);
77 void duplicate_instance_warning(const Device &device, const DeviceInstance &instance, const NetlistLocation &netlist_location);
78 void duplicate_entity_warning(const Device &device, const DeviceEntity &entity, const NetlistLocation &netlist_location);
79 
80 //-----------------------------------------------------------------------------
81 // Class : DeviceMaster
82 //
83 // Purpose : This class contains a lot of boilerplate functions, such
84 // as addInstance, which are needed by every device. However,
85 // as functions of this nature are device-specific, they
86 // didn't naturally fit as base class Device functions.
87 //
88 // This class is a template, which takes 2 typenames;
89 // model, instance and model-ptr STL vector. A specific
90 // example of these would be CapacitorModel and
91 // CapacitorInstance
92 //
93 // Each derived device class will need to set up its own
94 // version of this template.
95 //
96 // Special Notes :
97 // Creator : Eric Keiter, SNL
98 // Creation Date : 1/31/06
99 //-----------------------------------------------------------------------------
100 
101 /**
102  * DeviceMaster instantiates a device as described by the device traits T.
103  *
104  * The Device Traits are described in in the device configuration.
105  *
106  * @see Xyce::Device::Configuration
107  *
108  * @param T device traits class
109  *
110  * @author David G. Baur Raytheon Sandia National Laboratories 1355
111  * @date Tue Feb 4 10:33:44 2014
112  */
113 template<class T>
114 class DeviceMaster : public Device
115 {
116 public:
117  typedef typename T::ModelType ModelType; ///< Make the model begin defined available
118  typedef typename T::InstanceType InstanceType; ///< Make the instance being define available
119 
120 protected:
121  typedef std::vector<InstanceType *> InstanceVector;
122  typedef unordered_map<std::string, ModelType *, HashNoCase, EqualNoCase> ModelMap;
123  typedef unordered_map<std::string, InstanceType *, HashNoCase, EqualNoCase> InstanceMap;
124 
125 public:
126  /**
127  * Constructs a device
128  *
129  * When a device is constructed, a default model is created.
130  *
131  * @param configuration const reference to device configuration
132  * @param factory_block const reference to the factory provided parameters
133  * @param solver_state const reference to the solver state to use for the device
134  * @param device_options const reference to the device options to use for the device
135  *
136  * @author David G. Baur Raytheon Sandia National Laboratories 1355
137  * @date Tue Feb 4 10:20:40 2014
138  */
140  const Configuration & configuration,
141  const FactoryBlock & factory_block,
142  const SolverState & solver_state,
143  const DeviceOptions & device_options)
144  : Device(),
145  deviceName_(T::name()),
146  defaultModelName_(std::string(T::deviceTypeName()) + " (" + T::name() + ")"),
147  configuration_(configuration),
148  solverState_(solver_state),
149  deviceOptions_(device_options),
150  modelMap_(),
151  instanceVector_(),
152  instanceMap_()
153  {}
154 
155  /**
156  * Destroys the device
157  *
158  * Delete the models created by this device. The model will handle deleting the instances.
159  *
160  * @return
161  *
162  * @author David G. Baur Raytheon Sandia National Laboratories 1355
163  * @date Tue Feb 4 10:23:31 2014
164  */
165  virtual ~DeviceMaster()
166  {
167  for (typename ModelMap::iterator model_it = modelMap_.begin(); model_it != modelMap_.end(); ++model_it)
168  {
169  delete (*model_it).second;
170  }
171  }
172 
173 private:
174  DeviceMaster(const DeviceMaster &right); ///< No copying
175  DeviceMaster(const Device &); ///< Eh?
176  DeviceMaster &operator=(const DeviceMaster &right); ///< No assignments
177 
178 public:
179  /**
180  * Returns the name of this device
181  *
182  * @return const reference to the device's name
183  *
184  * @author David G. Baur Raytheon Sandia National Laboratories 1355
185  * @date Tue Feb 4 10:25:37 2014
186  */
187  virtual const std::string &getName() const /* override */
188  {
189  return deviceName_;
190  }
191 
192  /**
193  * Returns the default model name to use if the instance being created does not specify one
194  *
195  * @return const reference to the default model name
196  *
197  * @author David G. Baur Raytheon Sandia National Laboratories 1355
198  * @date Tue Feb 4 10:26:10 2014
199  */
200  virtual const std::string &getDefaultModelName() const /* override */
201  {
202  return defaultModelName_;
203  }
204 
205  /**
206  * Returns a pointer to the model or model model with the specified name
207  *
208  * @param model_name const reference to the model name
209  *
210  * @return pointer to the model or 0 is not found
211  *
212  * @author David G. Baur Raytheon Sandia National Laboratories 1355
213  * @date Tue Feb 4 10:36:44 2014
214  */
215  virtual DeviceModel *findModel(const ModelName &model_name) /* override */
216  {
217  typename ModelMap::iterator it = modelMap_.find(model_name);
218  if (it != modelMap_.end())
219  return (*it).second;
220 
221  return 0;
222  }
223 
224  /**
225  * Returns a pointer to the model or model model with the specified name
226  *
227  * @param model_name const reference to the model name
228  *
229  * @return const pointer to the model or 0 is not found
230  *
231  * @author David G. Baur Raytheon Sandia National Laboratories 1355
232  * @date Tue Feb 4 10:36:44 2014
233  */
234  virtual const DeviceModel *findModel(const ModelName &model_name) const /* override */
235  {
236  typename ModelMap::const_iterator it = modelMap_.find(model_name);
237  if (it != modelMap_.end())
238  return (*it).second;
239 
240  return 0;
241  }
242 
243  /**
244  * Returns a pointer to the model or instance entity with the specified name
245  *
246  * @param instance_name const reference to the entity name
247  *
248  * @return pointer to the entity or 0 is not found
249  *
250  * @author David G. Baur Raytheon Sandia National Laboratories 1355
251  * @date Tue Feb 4 10:36:44 2014
252  */
253  virtual DeviceEntity *findInstance(const InstanceName &instance_name) /* override */
254  {
255  typename InstanceMap::iterator it = instanceMap_.find(instance_name.getEncodedName());
256  if (it != instanceMap_.end())
257  return (*it).second;
258 
259  return 0;
260  }
261 
262  /**
263  * Returns a pointer to the model or instance entity with the specified name
264  *
265  * @param instance_name const reference to the entity name
266  *
267  * @return const pointer to the entity or 0 is not found
268  *
269  * @author David G. Baur Raytheon Sandia National Laboratories 1355
270  * @date Tue Feb 4 10:36:44 2014
271  */
272  virtual const DeviceEntity *findInstance(const InstanceName &instance_name) const /* override */
273  {
274  typename InstanceMap::const_iterator it = instanceMap_.find(instance_name.getEncodedName());
275  if (it != instanceMap_.end())
276  return (*it).second;
277 
278  return 0;
279  }
280 
281  /**
282  * Returns true if this device is a linear device
283  *
284  * @return the device is linear value provided via the device trait.
285  *
286  * @author David G. Baur Raytheon Sandia National Laboratories 1355
287  * @date Tue Feb 4 10:51:52 2014
288  */
289  virtual bool isLinearDevice() const /* override */
290  {
291  return T::isLinearDevice();
292  }
293 
294  /**
295  * Returns true if this device is a PDE device
296  *
297  * @return the device is PDE value provided via the device trait.
298  *
299  * @author David G. Baur Raytheon Sandia National Laboratories 1355
300  * @date Tue Feb 4 10:53:10 2014
301  */
302  virtual bool isPDEDevice() const /* override */
303  {
304  return T::isPDEDevice();
305  }
306 
307  /**
308  * Executes operator op, passing its DeviceModel pointer, for each device model
309  *
310  * Since the model information is managed in a map of ModelType pointers, it is not possible to return the map as an
311  * association to DeviceModel pointers. This function iterates over the models and passes it the DeviceModel
312  * pointer for each.
313  *
314  * @param op functor taking a DeviceModel pointer as an argument
315  *
316  * @author David G. Baur Raytheon Sandia National Laboratories 1355
317  * @date Tue Feb 4 10:53:45 2014
318  */
319  virtual void forEachModel(DeviceModelOp &op) const /* override */
320  {
321  for (typename ModelMap::const_iterator it = modelMap_.begin(); it != modelMap_.end(); ++it)
322  op((*it).second);
323  }
324 
325  /**
326  * Executes operator op, passing its DeviceInstance pointer, for each device instance
327  *
328  * Since the instance information is managed in a map of InstanceType pointers, it is not possible to return the map as an
329  * association to DeviceInstance pointers. This function iterates over the instances and passes it the DeviceInstance
330  * pointer for each.
331  *
332  * @param op functor taking a DeviceInstance pointer as an argument
333  *
334  * @author David G. Baur Raytheon Sandia National Laboratories 1355
335  * @date Tue Feb 4 10:53:45 2014
336  */
337  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */
338  {
339  for (typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
340  op(*it);
341  }
342 
343  // virtual bool deleteInstance(DeviceInstance *instance) /* override */;
344 
345  virtual ModelType *addModel(const ModelBlock & MB, const FactoryBlock &factory_block) /* override */;
346  virtual InstanceType *addInstance(const InstanceBlock &instance_block, const FactoryBlock &factory_block); /* override */
347 
348  virtual bool updateSources() /* override */;
349  virtual bool updateState (double * solVec, double * staVec, double * stoVec)/* override */;
350  virtual bool updateSecondaryState (double * staDerivVec, double * stoVec) /* override */;
351  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV ) /* override */;
352  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx) /* override */;
353 
354  virtual bool isConverged() const /* override */;
355 
356 protected:
357  /**
358  * Returns the solver state given during device construction
359  *
360  * @return const reference to the solver state
361  *
362  * @author David G. Baur Raytheon Sandia National Laboratories 1355
363  * @date Tue Feb 4 10:27:14 2014
364  */
365  const SolverState &getSolverState() const
366  {
367  return solverState_;
368  }
369 
370  /**
371  * Returns the device options given during device construction
372  *
373  * @return const reference to the device options
374  *
375  * @author David G. Baur Raytheon Sandia National Laboratories 1355
376  * @date Tue Feb 4 10:27:48 2014
377  */
379  {
380  return deviceOptions_;
381  }
382 
383  /**
384  * Returns an iterator to the beginning of the vector of all instances created for this device
385  *
386  * While a device instance is created, the device model owns the pointer to the device. The instanceVector_ gets a
387  * copy so that all instances of this device may be iterated over without needing to go through the model.
388  *
389  * @return iterator to the beginning of the device instance vector
390  *
391  * @author David G. Baur Raytheon Sandia National Laboratories 1355
392  * @date Tue Feb 4 10:28:29 2014
393  */
394  typename InstanceVector::const_iterator getInstanceBegin() const
395  {
396  return instanceVector_.begin();
397  }
398 
399  /**
400  * Returns an iterator to the ending of the vector of all instances created for this device
401  *
402  * While a device instance is created, the device model owns the pointer to the device. The instanceVector_ gets a
403  * copy so that all instances of this device may be iterated over without needing to go through the model.
404  *
405  * @return iterator to the ending of the device instance vector
406  *
407  * @author David G. Baur Raytheon Sandia National Laboratories 1355
408  * @date Tue Feb 4 10:28:29 2014
409  */
410  typename InstanceVector::const_iterator getInstanceEnd() const
411  {
412  return instanceVector_.end();
413  }
414 
415  /**
416  * Returns true if the model name must be specified for each instance
417  *
418  * @return the device model required value provided via the device trait.
419  *
420  * @author David G. Baur Raytheon Sandia National Laboratories 1355
421  * @date Tue Feb 4 10:32:10 2014
422  */
423  bool isModelRequired() const
424  {
425  return T::modelRequired();
426  }
427 
428 private:
429  virtual bool getBreakPoints(std::vector<Util::BreakPoint> & breakPointTimes);
430 
431 private:
432  const std::string deviceName_;
433  const std::string defaultModelName_;
437  ModelMap modelMap_;
438  InstanceVector instanceVector_;
439  InstanceMap instanceMap_;
440 };
441 
442 //-----------------------------------------------------------------------------
443 // Function : DeviceMaster::addInstance
444 // Purpose : This function adds an instance to the list of instances.
445 //
446 // Special Notes : All device instances are contained in one of many lists.
447 // Each model owns exactly one list of instances. If
448 // an instance is added which does not reference a model, or
449 // that references a model that does not exist, then a new
450 // model has to be added.
451 //
452 // For now, this function will only add a model for instances
453 // that do not specifically reference one. If an instance
454 // references a non-existant model, this function will return a
455 // fatal error. (This function should only be called from the
456 // device manager function, AddDeviceInstance, and that
457 // function will not call this one if the instance refers to a
458 // non-existant model.)
459 //
460 // Scope : public
461 // Creator : Eric Keiter, SNL
462 // Creation Date : 1/31/06
463 //-----------------------------------------------------------------------------
464 template<class T>
467  const InstanceBlock & instance_block,
468  const FactoryBlock & factory_block)
469 {
470  std::string model_name = instance_block.getModelName();
471 
472  if (model_name.empty()) // If no model name, use the default model.
473  {
474  if (isModelRequired())
475  {
476  instance_must_reference_model_error(*this, model_name, instance_block.getNetlistLocation());
477  return 0;
478  }
479  else
480  {
481  typename ModelMap::iterator it = modelMap_.find(defaultModelName_);
482  if (it == modelMap_.end())
483  {
484  addModel(ModelBlock(defaultModelName_), factory_block);
485  }
486  model_name = defaultModelName_;
487  }
488  }
489 
490  typename ModelMap::iterator it = modelMap_.find(model_name);
491  if (it == modelMap_.end())
492  {
493  could_not_find_model_error(*this, model_name, instance_block.getInstanceName().getDeviceName(), instance_block.getNetlistLocation());
494  return 0;
495  }
496 
497  ModelType &model = *(*it).second;
498 
499  std::pair<typename InstanceMap::iterator, bool> result = instanceMap_.insert(typename InstanceMap::value_type(instance_block.getInstanceName().getEncodedName(), typename InstanceMap::mapped_type(0)));
500  if (result.second)
501  {
502  InstanceType *instance = new InstanceType(configuration_, instance_block, model, factory_block);
503  instance->setDefaultParamName(T::instanceDefaultParameter());
504 
505  (*result.first).second = instance;
506 
507  model.addInstance(instance);
508 
509  instanceVector_.push_back(instance);
510 
511  if (modelMap_.find(instance_block.getInstanceName().getDeviceName()) != modelMap_.end())
512  duplicate_entity_warning(*this, *instance, instance_block.getNetlistLocation());
513  }
514  else
515  {
516  duplicate_instance_warning(*this, *(*result.first).second, instance_block.getNetlistLocation());
517  }
518 
519  return (*result.first).second;
520 }
521 
522 //-----------------------------------------------------------------------------
523 // Function : DeviceMaster::addModel
524 // Purpose : This function adds a model to the list of device models.
525 //
526 // Special Notes : This is the "public" version of the function, meaning that
527 // it returns a bool to indicate success or failure (rather
528 // than a pointer to the model). Also, it checks to see if the
529 // model being added is already part of the list. If the model
530 // already exists, it generates an error.
531 //
532 // Scope : public
533 // Creator : Eric Keiter, SNL
534 // Creation Date : 1/31/06
535 //-----------------------------------------------------------------------------
536 template<class T>
539  const ModelBlock & model_block,
540  const FactoryBlock & factory_block)
541 {
542  // Check to make sure that there doesn't already exist a model of this name.
543  std::pair<typename ModelMap::iterator, bool> result = modelMap_.insert(typename ModelMap::value_type(model_block.getName(), typename ModelMap::mapped_type(0)));
544  if (result.second)
545  {
546  ModelType *model = new ModelType(configuration_, model_block, factory_block);
547 
548  (*result.first).second = model;
549 
550  if (instanceMap_.find(model_block.getName()) != instanceMap_.end())
551  duplicate_entity_warning(*this, *model, model_block.getNetlistLocation());
552  }
553  else
554  {
555  duplicate_model_warning(*this, *(*result.first).second, model_block.getNetlistLocation());
556  }
557 
558  return (*result.first).second;
559 }
560 
561 // //-----------------------------------------------------------------------------
562 // // Function : DeviceMaster::deleteInstance
563 // // Purpose :
564 // // Special Notes :
565 // // Scope : public
566 // // Creator : Eric Keiter, SNL
567 // // Creation Date : 2/03/06
568 // //-----------------------------------------------------------------------------
569 // template<class T>
570 // bool DeviceMaster<T>::deleteInstance(const std::string & instance_name)
571 // {
572 // for (typename ModelMap::iterator it_model = modelMap_.begin(); it_model != modelMap_.end(); ++it_model)
573 // {
574 // InstanceVector &instance_list = (*it_model).second->getInstanceVector();
575 
576 // for (typename InstanceVector::iterator it_instance = instance_list.begin(); it_instance != instance_list.end(); ++it_instance)
577 // {
578 // if (equal_nocase(instance_name, (*it_instance)->getName()))
579 // {
580 // delete *it_instance;
581 // instance_list.erase(it_instance);
582 
583 // return true;
584 // }
585 // }
586 // }
587 
588 // return false;
589 // }
590 
591 //-----------------------------------------------------------------------------
592 // Function : DeviceMaster::getBreakPoints
593 // Purpose : This function adds break points to a vector of breakpoints.
594 //
595 // Special Notes : For most devices, this function won't get called. The
596 // device manager only calls getBreakPoints for certain
597 // pre-selected devices. Ultimately, this function probably
598 // isn't neccessary, as the device manager usually accesses
599 // device instances directly, rather than going through a
600 // device class middleman.
601 //
602 // Scope : public
603 // Creator : Eric Keiter, SNL
604 // Creation Date : 2/05/06
605 //-----------------------------------------------------------------------------
606 template<class T>
607 bool DeviceMaster<T>::getBreakPoints( std::vector<Util::BreakPoint> & breakPointTimes )
608 {
609  bool bsuccess = true;
610 
611  for (typename InstanceVector::iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
612  bsuccess = (*it)->getInstanceBreakPoints(breakPointTimes) && bsuccess;
613 
614  return bsuccess;
615 }
616 
617 //-----------------------------------------------------------------------------
618 // Function : DeviceMaster::updateSources
619 //
620 // Purpose :
621 //
622 // Special Notes : Just like for the getBreakPoints function, for most devices,
623 // this function won't get called. The
624 // device manager only calls updateSources for certain
625 // pre-selected devices. Ultimately, this function probably
626 // isn't neccessary, as the device manager usually accesses
627 // device instances directly, rather than going through a
628 // device class middleman.
629 //
630 // Scope : public
631 // Creator : Eric Keiter, SNL
632 // Creation Date : 02/05/06
633 //-----------------------------------------------------------------------------
634 template<class T>
636 {
637  bool bsuccess = true;
638 
639  for (typename InstanceVector::iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
640  bsuccess = (*it)->updateSource() && bsuccess;
641 
642  return bsuccess;
643 }
644 
645 //-----------------------------------------------------------------------------
646 // Function : DeviceMaster::updateState
647 // Purpose :
648 // Special Notes :
649 // Scope : public
650 // Creator : Eric Keiter, SNL
651 // Creation Date : 11/25/08
652 //-----------------------------------------------------------------------------
653 template<class T>
654 bool DeviceMaster<T>::updateState (double * solVec, double * staVec, double * stoVec)
655 {
656  bool bsuccess = true;
657  for (typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
658  {
659  bool tmpBool = (*it)->updatePrimaryState();
660  bsuccess = bsuccess && tmpBool;
661  }
662 
663  return bsuccess;
664 }
665 
666 //-----------------------------------------------------------------------------
667 // Function : DeviceMaster::updateSecondaryState
668 // Purpose :
669 // Special Notes :
670 // Scope : public
671 // Creator : Eric Keiter, SNL
672 // Creation Date : 11/25/08
673 //-----------------------------------------------------------------------------
674 template<class T>
675 bool DeviceMaster<T>::updateSecondaryState (double * staDerivVec, double * stoVec)
676 {
677  bool bsuccess = true;
678  for (typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
679  {
680  bool tmpBool = (*it)->updateSecondaryState ();
681  bsuccess = bsuccess && tmpBool;
682  }
683 
684  return bsuccess;
685 }
686 
687 //-----------------------------------------------------------------------------
688 // Function : DeviceMaster::loadDAEVectors
689 // Purpose :
690 // Special Notes :
691 // Scope : public
692 // Creator : Eric Keiter, SNL
693 // Creation Date : 11/25/08
694 //-----------------------------------------------------------------------------
695 template<class T>
696 bool DeviceMaster<T>::loadDAEVectors(double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV)
697 {
698  bool bsuccess = true;
699  for (typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
700  {
701  bool tmpBool = (*it)->loadDAEFVector();
702  bsuccess = bsuccess && tmpBool;
703 
704  tmpBool = (*it)->loadDAEQVector();
705  bsuccess = bsuccess && tmpBool;
706 
707  tmpBool = (*it)->loadDAEBVector();
708  bsuccess = bsuccess && tmpBool;
709  }
710 
711  return bsuccess;
712 }
713 
714 //-----------------------------------------------------------------------------
715 // Function : DeviceMaster::loadDAEMatrices
716 // Purpose :
717 // Special Notes :
718 // Scope : public
719 // Creator : Eric Keiter, SNL
720 // Creation Date : 11/25/08
721 //-----------------------------------------------------------------------------
722 template<class T>
723 bool DeviceMaster<T>::loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx)
724 {
725  bool bsuccess = true;
726  for (typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
727  {
728  bool tmpBool = (*it)->loadDAEdFdx();
729  bsuccess = bsuccess && tmpBool;
730  tmpBool = (*it)->loadDAEdQdx();
731  bsuccess = bsuccess && tmpBool;
732  }
733 
734  return bsuccess;
735 }
736 
737 //-----------------------------------------------------------------------------
738 // Function : DeviceMaster::isConverged
739 // Purpose :
740 // Special Notes :
741 // Scope : public
742 // Creator : Heidi Thornquist, SNL
743 // Creation Date : 7/14/15
744 //-----------------------------------------------------------------------------
745 template<class T>
747 {
748  bool bsuccess = true;
749 
750  if ( !isLinearDevice() )
751  {
752  for (typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
753  {
754  bool tmpBool = (*it)->isConverged();
755  bsuccess = bsuccess && tmpBool;
756  }
757  }
758 
759  return bsuccess;
760 }
761 
762 } // namespace Device
763 } // namespace Xyce
764 
765 #endif
const ModelName & getName() const
T::ModelType ModelType
Make the model begin defined available.
void duplicate_entity_warning(const Device &device, const DeviceEntity &entity, const NetlistLocation &netlist_location)
duplicate_entity_warning reports a duplication of entity names.
const SolverState & solverState_
unordered_map< std::string, ModelType *, HashNoCase, EqualNoCase > ModelMap
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
virtual bool getBreakPoints(std::vector< Util::BreakPoint > &breakPointTimes)
Pure virtual class to augment a linear system.
Devices and models are each named.
const std::string & getEncodedName() const
Return the instance name encoded as: [s:]*xname [s:]*Ytype!name [s:]*Utype!name!count.
void instance_must_reference_model_error(const Device &device, const std::string &name, const NetlistLocation &netlist_location)
reports that the type of instance requires that a model be specified
virtual bool updateSecondaryState(double *staDerivVec, double *stoVec)
Updates the devices secondary state information.
void duplicate_instance_warning(const Device &device, const DeviceInstance &instance, const NetlistLocation &netlist_location)
duplicate_instance_warning reports a duplication of instance names.
InstanceVector::const_iterator getInstanceEnd() const
Returns an iterator to the ending of the vector of all instances created for this device...
virtual bool isConverged() const
Checks that the device is converged.
InstanceVector::const_iterator getInstanceBegin() const
Returns an iterator to the beginning of the vector of all instances created for this device...
const std::string defaultModelName_
DeviceMaster instantiates a device as described by the device traits T.
void could_not_find_model_error(const Device &device, const std::string &model_name, const std::string &instance_name, const NetlistLocation &netlist_location)
reports that the model name is note defined
std::vector< InstanceType * > InstanceVector
virtual bool isLinearDevice() const
Returns true if this device is a linear device.
virtual bool isPDEDevice() const
Returns true if this device is a PDE device.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
DeviceMaster(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &solver_state, const DeviceOptions &device_options)
Constructs a device.
const DeviceOptions & deviceOptions_
virtual const DeviceEntity * findInstance(const InstanceName &instance_name) const
Returns a pointer to the model or instance entity with the specified name.
virtual const DeviceModel * findModel(const ModelName &model_name) const
Returns a pointer to the model or model model with the specified name.
const ModelName & getModelName() const
const DeviceOptions & getDeviceOptions() const
Returns the device options given during device construction.
const InstanceName & getInstanceName() const
void duplicate_model_warning(const Device &device, const DeviceModel &model, const NetlistLocation &netlist_location)
duplicate_model_warning reports that the model name is duplicated.
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
virtual ModelType * addModel(const ModelBlock &MB, const FactoryBlock &factory_block)
Creates a device model and adds it to the device's list of models.
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
const NetlistLocation & getNetlistLocation() const
virtual DeviceModel * findModel(const ModelName &model_name)
Returns a pointer to the model or model model with the specified name.
Class Configuration contains device configuration data.
DeviceMaster & operator=(const DeviceMaster &right)
No assignments.
virtual DeviceEntity * findInstance(const InstanceName &instance_name)
Returns a pointer to the model or instance entity with the specified name.
const NetlistLocation & getNetlistLocation() const
virtual void forEachInstance(DeviceInstanceOp &op) const
Executes operator op, passing its DeviceInstance pointer, for each device instance.
bool isModelRequired() const
Returns true if the model name must be specified for each instance.
const std::string & getDeviceName() const
Decodes the device name.
virtual InstanceType * addInstance(const InstanceBlock &instance_block, const FactoryBlock &factory_block)
Creates a device instance and adds to the device model's instance list.
T::InstanceType InstanceType
Make the instance being define available.
virtual ~DeviceMaster()
Destroys the device.
virtual const std::string & getName() const
Returns the name of this device.
ModelBlock represents a .MODEL line from the netlist.
std::string ModelName
Definition: N_DEV_fwd.h:165
InstanceBlock represent a device instance line from the netlist.
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.
virtual bool updateSources()
Updates the devices source information.
virtual void forEachModel(DeviceModelOp &op) const
Executes operator op, passing its DeviceModel pointer, for each device model.
virtual const std::string & getDefaultModelName() const
Returns the default model name to use if the instance being created does not specify one...
unordered_map< std::string, InstanceType *, HashNoCase, EqualNoCase > InstanceMap
const Configuration & configuration_
const SolverState & getSolverState() const
Returns the solver state given during device construction.