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.20.2.1 $
45 //
46 // Revision Date : $Date: 2015/04/02 18:20:09 $
47 //
48 // Current Owner : $Author: tvrusso $
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  deviceOptions_(device_options),
149  solverState_(solver_state),
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 protected:
355  /**
356  * Returns the solver state given during device construction
357  *
358  * @return const reference to the solver state
359  *
360  * @author David G. Baur Raytheon Sandia National Laboratories 1355
361  * @date Tue Feb 4 10:27:14 2014
362  */
363  const SolverState &getSolverState() const
364  {
365  return solverState_;
366  }
367 
368  /**
369  * Returns the device options given during device construction
370  *
371  * @return const reference to the device options
372  *
373  * @author David G. Baur Raytheon Sandia National Laboratories 1355
374  * @date Tue Feb 4 10:27:48 2014
375  */
377  {
378  return deviceOptions_;
379  }
380 
381  /**
382  * Returns an iterator to the beginning of the vector of all instances created for this device
383  *
384  * While a device instance is created, the device model owns the pointer to the device. The instanceVector_ gets a
385  * copy so that all instances of this device may be iterated over without needing to go through the model.
386  *
387  * @return iterator to the beginning of the device instance vector
388  *
389  * @author David G. Baur Raytheon Sandia National Laboratories 1355
390  * @date Tue Feb 4 10:28:29 2014
391  */
392  typename InstanceVector::const_iterator getInstanceBegin() const
393  {
394  return instanceVector_.begin();
395  }
396 
397  /**
398  * Returns an iterator to the ending of the vector of all instances created for this device
399  *
400  * While a device instance is created, the device model owns the pointer to the device. The instanceVector_ gets a
401  * copy so that all instances of this device may be iterated over without needing to go through the model.
402  *
403  * @return iterator to the ending of the device instance vector
404  *
405  * @author David G. Baur Raytheon Sandia National Laboratories 1355
406  * @date Tue Feb 4 10:28:29 2014
407  */
408  typename InstanceVector::const_iterator getInstanceEnd() const
409  {
410  return instanceVector_.end();
411  }
412 
413  /**
414  * Returns true if the model name must be specified for each instance
415  *
416  * @return the device model required value provided via the device trait.
417  *
418  * @author David G. Baur Raytheon Sandia National Laboratories 1355
419  * @date Tue Feb 4 10:32:10 2014
420  */
421  bool isModelRequired() const
422  {
423  return T::modelRequired();
424  }
425 
426 private:
427  virtual bool getBreakPoints(std::vector<Util::BreakPoint> & breakPointTimes);
428 
429 private:
430  const std::string deviceName_;
431  const std::string defaultModelName_;
435  ModelMap modelMap_;
436  InstanceVector instanceVector_;
437  InstanceMap instanceMap_;
438 };
439 
440 //-----------------------------------------------------------------------------
441 // Function : DeviceMaster::addInstance
442 // Purpose : This function adds an instance to the list of instances.
443 //
444 // Special Notes : All device instances are contained in one of many lists.
445 // Each model owns exactly one list of instances. If
446 // an instance is added which does not reference a model, or
447 // that references a model that does not exist, then a new
448 // model has to be added.
449 //
450 // For now, this function will only add a model for instances
451 // that do not specifically reference one. If an instance
452 // references a non-existant model, this function will return a
453 // fatal error. (This function should only be called from the
454 // device manager function, AddDeviceInstance, and that
455 // function will not call this one if the instance refers to a
456 // non-existant model.)
457 //
458 // Scope : public
459 // Creator : Eric Keiter, SNL
460 // Creation Date : 1/31/06
461 //-----------------------------------------------------------------------------
462 template<class T>
465  const InstanceBlock & instance_block,
466  const FactoryBlock & factory_block)
467 {
468  std::string model_name = instance_block.getModelName();
469 
470  if (model_name.empty()) // If no model name, use the default model.
471  {
472  if (isModelRequired())
473  {
474  instance_must_reference_model_error(*this, model_name, instance_block.getNetlistLocation());
475  return 0;
476  }
477  else
478  {
479  typename ModelMap::iterator it = modelMap_.find(defaultModelName_);
480  if (it == modelMap_.end())
481  {
482  addModel(ModelBlock(defaultModelName_), factory_block);
483  }
484  model_name = defaultModelName_;
485  }
486  }
487 
488  typename ModelMap::iterator it = modelMap_.find(model_name);
489  if (it == modelMap_.end())
490  {
491  could_not_find_model_error(*this, model_name, instance_block.getInstanceName().getDeviceName(), instance_block.getNetlistLocation());
492  return 0;
493  }
494 
495  ModelType &model = *(*it).second;
496 
497  std::pair<typename InstanceMap::iterator, bool> result = instanceMap_.insert(typename InstanceMap::value_type(instance_block.getInstanceName().getEncodedName(), typename InstanceMap::mapped_type(0)));
498  if (result.second)
499  {
500  InstanceType *instance = new InstanceType(configuration_, instance_block, model, factory_block);
501  instance->setDefaultParamName(T::instanceDefaultParameter());
502 
503  (*result.first).second = instance;
504 
505  model.addInstance(instance);
506 
507  instanceVector_.push_back(instance);
508 
509  if (modelMap_.find(instance_block.getInstanceName().getDeviceName()) != modelMap_.end())
510  duplicate_entity_warning(*this, *instance, instance_block.getNetlistLocation());
511  }
512  else
513  {
514  duplicate_instance_warning(*this, *(*result.first).second, instance_block.getNetlistLocation());
515  }
516 
517  return (*result.first).second;
518 }
519 
520 //-----------------------------------------------------------------------------
521 // Function : DeviceMaster::addModel
522 // Purpose : This function adds a model to the list of device models.
523 //
524 // Special Notes : This is the "public" version of the function, meaning that
525 // it returns a bool to indicate success or failure (rather
526 // than a pointer to the model). Also, it checks to see if the
527 // model being added is already part of the list. If the model
528 // already exists, it generates an error.
529 //
530 // Scope : public
531 // Creator : Eric Keiter, SNL
532 // Creation Date : 1/31/06
533 //-----------------------------------------------------------------------------
534 template<class T>
537  const ModelBlock & model_block,
538  const FactoryBlock & factory_block)
539 {
540  // Check to make sure that there doesn't already exist a model of this name.
541  std::pair<typename ModelMap::iterator, bool> result = modelMap_.insert(typename ModelMap::value_type(model_block.getName(), typename ModelMap::mapped_type(0)));
542  if (result.second)
543  {
544  ModelType *model = new ModelType(configuration_, model_block, factory_block);
545 
546  (*result.first).second = model;
547 
548  if (instanceMap_.find(model_block.getName()) != instanceMap_.end())
549  duplicate_entity_warning(*this, *model, model_block.getNetlistLocation());
550  }
551  else
552  {
553  duplicate_model_warning(*this, *(*result.first).second, model_block.getNetlistLocation());
554  }
555 
556  return (*result.first).second;
557 }
558 
559 // //-----------------------------------------------------------------------------
560 // // Function : DeviceMaster::deleteInstance
561 // // Purpose :
562 // // Special Notes :
563 // // Scope : public
564 // // Creator : Eric Keiter, SNL
565 // // Creation Date : 2/03/06
566 // //-----------------------------------------------------------------------------
567 // template<class T>
568 // bool DeviceMaster<T>::deleteInstance(const std::string & instance_name)
569 // {
570 // for (typename ModelMap::iterator it_model = modelMap_.begin(); it_model != modelMap_.end(); ++it_model)
571 // {
572 // InstanceVector &instance_list = (*it_model).second->getInstanceVector();
573 
574 // for (typename InstanceVector::iterator it_instance = instance_list.begin(); it_instance != instance_list.end(); ++it_instance)
575 // {
576 // if (equal_nocase(instance_name, (*it_instance)->getName()))
577 // {
578 // delete *it_instance;
579 // instance_list.erase(it_instance);
580 
581 // return true;
582 // }
583 // }
584 // }
585 
586 // return false;
587 // }
588 
589 //-----------------------------------------------------------------------------
590 // Function : DeviceMaster::getBreakPoints
591 // Purpose : This function adds break points to a vector of breakpoints.
592 //
593 // Special Notes : For most devices, this function won't get called. The
594 // device manager only calls getBreakPoints for certain
595 // pre-selected devices. Ultimately, this function probably
596 // isn't neccessary, as the device manager usually accesses
597 // device instances directly, rather than going through a
598 // device class middleman.
599 //
600 // Scope : public
601 // Creator : Eric Keiter, SNL
602 // Creation Date : 2/05/06
603 //-----------------------------------------------------------------------------
604 template<class T>
605 bool DeviceMaster<T>::getBreakPoints( std::vector<Util::BreakPoint> & breakPointTimes )
606 {
607  bool bsuccess = true;
608 
609  for (typename InstanceVector::iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
610  bsuccess = (*it)->getInstanceBreakPoints(breakPointTimes) && bsuccess;
611 
612  return bsuccess;
613 }
614 
615 //-----------------------------------------------------------------------------
616 // Function : DeviceMaster::updateSources
617 //
618 // Purpose :
619 //
620 // Special Notes : Just like for the getBreakPoints function, for most devices,
621 // this function won't get called. The
622 // device manager only calls updateSources for certain
623 // pre-selected devices. Ultimately, this function probably
624 // isn't neccessary, as the device manager usually accesses
625 // device instances directly, rather than going through a
626 // device class middleman.
627 //
628 // Scope : public
629 // Creator : Eric Keiter, SNL
630 // Creation Date : 02/05/06
631 //-----------------------------------------------------------------------------
632 template<class T>
634 {
635  bool bsuccess = true;
636 
637  for (typename InstanceVector::iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
638  bsuccess = (*it)->updateSource() && bsuccess;
639 
640  return bsuccess;
641 }
642 
643 //-----------------------------------------------------------------------------
644 // Function : DeviceMaster::updateState
645 // Purpose :
646 // Special Notes :
647 // Scope : public
648 // Creator : Eric Keiter, SNL
649 // Creation Date : 11/25/08
650 //-----------------------------------------------------------------------------
651 template<class T>
652 bool DeviceMaster<T>::updateState (double * solVec, double * staVec, double * stoVec)
653 {
654  bool bsuccess = true;
655  for (typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
656  {
657  bool tmpBool = (*it)->updatePrimaryState();
658  bsuccess = bsuccess && tmpBool;
659  }
660 
661  return bsuccess;
662 }
663 
664 //-----------------------------------------------------------------------------
665 // Function : DeviceMaster::updateSecondaryState
666 // Purpose :
667 // Special Notes :
668 // Scope : public
669 // Creator : Eric Keiter, SNL
670 // Creation Date : 11/25/08
671 //-----------------------------------------------------------------------------
672 template<class T>
673 bool DeviceMaster<T>::updateSecondaryState (double * staDerivVec, double * stoVec)
674 {
675  bool bsuccess = true;
676  for (typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
677  {
678  bool tmpBool = (*it)->updateSecondaryState ();
679  bsuccess = bsuccess && tmpBool;
680  }
681 
682  return bsuccess;
683 }
684 
685 //-----------------------------------------------------------------------------
686 // Function : DeviceMaster::loadDAEVectors
687 // Purpose :
688 // Special Notes :
689 // Scope : public
690 // Creator : Eric Keiter, SNL
691 // Creation Date : 11/25/08
692 //-----------------------------------------------------------------------------
693 template<class T>
694 bool DeviceMaster<T>::loadDAEVectors(double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV)
695 {
696  bool bsuccess = true;
697  for (typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
698  {
699  bool tmpBool = (*it)->loadDAEFVector();
700  bsuccess = bsuccess && tmpBool;
701 
702  tmpBool = (*it)->loadDAEQVector();
703  bsuccess = bsuccess && tmpBool;
704 
705  tmpBool = (*it)->loadDAEBVector();
706  bsuccess = bsuccess && tmpBool;
707  }
708 
709  return bsuccess;
710 }
711 
712 //-----------------------------------------------------------------------------
713 // Function : DeviceMaster::loadDAEMatrices
714 // Purpose :
715 // Special Notes :
716 // Scope : public
717 // Creator : Eric Keiter, SNL
718 // Creation Date : 11/25/08
719 //-----------------------------------------------------------------------------
720 template<class T>
721 bool DeviceMaster<T>::loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx)
722 {
723  bool bsuccess = true;
724  for (typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
725  {
726  bool tmpBool = (*it)->loadDAEdFdx();
727  bsuccess = bsuccess && tmpBool;
728  tmpBool = (*it)->loadDAEdQdx();
729  bsuccess = bsuccess && tmpBool;
730  }
731 
732  return bsuccess;
733 }
734 
735 } // namespace Device
736 } // namespace Xyce
737 
738 #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...
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:157
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.