Xyce  6.1
N_DEV_Configuration.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_Configuration.h,v $
27 //
28 // Purpose : Holds device configuration information
29 //
30 // Special Notes :
31 //
32 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
33 //
34 // Creation Date : 2013/04/18 18:01:27
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.28 $
40 //
41 // Revision Date : $Date: 2015/07/02 21:29:41 $
42 //
43 // Current Owner : $Author: hkthorn $
44 //-------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Configuration_h
47 #define Xyce_N_DEV_Configuration_h
48 
49 #if defined(HAVE_UNORDERED_MAP)
50 #include <unordered_map>
51 using std::unordered_map;
52 #elif defined(HAVE_TR1_UNORDERED_MAP)
53 #include <tr1/unordered_map>
54 using std::tr1::unordered_map;
55 #else
56 #error neither unordered_map or tr1/unordered_map found
57 #endif
58 #include <string>
59 #include <vector>
60 
61 #include <N_DEV_fwd.h>
62 #include <N_IO_fwd.h>
63 #include <N_DEV_Pars.h>
64 
65 namespace Xyce {
66 namespace Device {
67 
69 {};
70 
71 template<class M, class G>
73 {
74  typedef typename G::ModelType GroupType_;
75 };
76 
77 template<class M>
79 {
80  typedef M GroupType_;
81 };
82 
83 //-----------------------------------------------------------------------------
84 // Class : DeviceTraits
85 // Purpose : Defines the device configuration data and grouping
86 // Special Notes :
87 // Scope : public
88 // Creator : Dave Baur, Raytheon
89 // Creation Date : 1/27/2014
90 //-----------------------------------------------------------------------------
91 ///
92 /// The DeviceTraits template describes the configuration of a device.
93 ///
94 /// Generally a device uses a typedef to define its traits:
95 ///
96 /// typedef DeviceTraits<Instance, Model> Traits; ///< Device traits for a group device
97 ///
98 /// or
99 ///
100 /// typedef DeviceTraits<Instance, Model, Resistor::Traits> Traits ///< Device is part of the Resistor device group
101 ///
102 /// Every device has an Instance class, a Model class and a ModelGroup class. An Instance is created for every device in
103 /// the netlist. A Model class is created for each unique model definition in the net list. The ModelGroup serves as a
104 /// device type grouping mechanism and is generally the level 1 device of a model with the other models having higher
105 /// level values.
106 ///
107 /// The EntityTypeId, ModelTypeId and InstanceTypeId are all descriptive typedefs for Util::type_index. These model
108 /// type identifiers and instance type identifiers are uniquely defined for each instance and model. The model type
109 /// identifier also serves as the model group identifier. The model groups are identified when the model traits is
110 /// ModeGroupLeadTraits which is the case for the two parameter DeviceTraits trait.
111 ///
112 /// Every device also has or may have nodes, optional nodes, fill nodes, a model required flags, a primary parameter, a
113 /// linear device flags and PDE device flag. These values are all provided via static traits functions, most of which
114 /// have default implementations.
115 ///
116 /// Every device must specify not only the device relationships above as template parameters, but must also define the
117 /// numNodes() and isLinearDevice() functions as providing a default value was too error prone.
118 ///
119 ///
120 /// DEVICE REGISTRATION:
121 /// Each device calls registerDevice() to register the device with the configuration. Each device must also call
122 /// registerModelType() for each model type to be defined.
123 ///
124 /// registerDevice()
125 /// - adds to the configurationMap_: (device_name, device_level) -> configuration
126 /// - adds to the modelTypeConfigurationMap_: model_type_id -> configuration
127 ///
128 /// registerModel()
129 /// - if model_type_id == model_group_id, adds to the modelTypeNameModelGroupMap_: model_name -> model_group_id
130 /// - adds to the modelTypeNameLevelModelTypeMap_: (model_name, level) -> model_type_id
131 /// - adds the model_name to the modelTypeNames list of device configuration
132 ///
133 /// THE CONFIGURATION IS CURRENTLY STORED IN A SINGLETON. This may not be as issue in that the configuration is
134 /// constructed exactly once via device registration and plugin loading at Xyce startup.
135 ///
136 /// The default parameter for a device is the parameter that will be used
137 /// if a single untagged parameter value is given on an instance line. For
138 /// example, the resistor's default parameter is R, and on the
139 /// line
140 /// @code
141 /// R1 A B 5k
142 /// @endcode
143 /// the untagged value (5k) will be assigned to the resistor's
144 /// R parameter.
145 ///
146 /// A primary parameter is the parameter that will be changed by a
147 /// .STEP loop or natural parameter homotopy when only the device name
148 /// is given. In the resistor, the primary parameter is also "R", and
149 /// so
150 /// @code
151 /// .STEP R1 1 10 1
152 /// @endcode
153 /// will step R1's R parameter from 1 to 10. In
154 /// most existing devices the primary parameter is the same as the
155 /// default parameter, but it is not required that this be the
156 /// case.
157 ///
158 /// Optional nodes are nodes that may be specified on the instance line, and
159 /// if not specified are internal nodes instead of external. Fill nodes are
160 /// like optional nodes, but if not specified they are connected to ground.
161 /// Examples of optional nodes include the internal and external body contacts
162 /// in the BSIM3 SOI model. Examples of fill nodes include the substrate
163 /// node of the level 1 BJT model.
164 template <class M, class I, class G>
166 {
167 public:
168  typedef I InstanceType; ///< Make instance template parameter available
169  typedef M ModelType; ///< Make model template parameter available
170  typedef G ModelGroupTraits; ///< Make model group traits template parameter available
171  typedef typename ModelGroupType_<M, G>::GroupType_ ModelGroupType; ///< Make model group template parameter available
172 
173  //-----------------------------------------------------------------------------
174  // Function : instanceType
175  // Purpose :
176  // Special Notes :
177  // Scope : public
178  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
179  // Creation Date : Fri Mar 14 13:00:58 2014
180  //-----------------------------------------------------------------------------
181  ///
182  /// Returns the instance type identifier
183  ///
184  /// @return the typeid wrapper for the instance type identifier
185  ///
187  {
188  return EntityTypeId(typeid(InstanceType));
189  }
190 
191  //-----------------------------------------------------------------------------
192  // Function : modelType
193  // Purpose :
194  // Special Notes :
195  // Scope : public
196  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
197  // Creation Date : Wed Feb 5 10:41:46 2014
198  //-----------------------------------------------------------------------------
199  ///
200  /// Returns the model type identifier
201  ///
202  /// @return the typeid wrapper for the model type identifier
203  ///
204  static const ModelTypeId modelType()
205  {
206  return EntityTypeId(typeid(ModelType));
207  }
208 
209  //-----------------------------------------------------------------------------
210  // Function : modelGroupType
211  // Purpose :
212  // Special Notes :
213  // Scope : public
214  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
215  // Creation Date : Wed Feb 5 10:42:39 2014
216  //-----------------------------------------------------------------------------
217  ///
218  /// Returns the model group identifier
219  ///
220  /// @return the typeid wrapper for the model group identifier
221  ///
222  static const ModelTypeId modelGroup()
223  {
224  return EntityTypeId(typeid(ModelGroupType));
225  }
226 
227  //-----------------------------------------------------------------------------
228  // Function : factory
229  // Purpose :
230  // Special Notes :
231  // Scope : public
232  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
233  // Creation Date : Thu Feb 6 10:20:07 2014
234  //-----------------------------------------------------------------------------
235  ///
236  /// Creates a device via the device template
237  ///
238  /// Generally implemented as:
239  ///
240  /// @code
241  /// static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block)
242  /// {
243  /// return new DeviceMaster<Traits>(configuration, factory_block, factory_block.solverState_, factory_block.deviceOptions_);
244  /// }
245  /// @endcode
246  ///
247  /// or
248  ///
249  /// @code
250  /// static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block)
251  /// {
252  /// return new Master(configuration, factory_block, factory_block.solverState_, factory_block.deviceOptions_);
253  /// }
254  /// @endcode
255  ///
256  /// when Master extends DeviceMaster.
257  ///
258  /// @param configuration const reference to the device configuration
259  /// @param factory_block const reference to the factory parameters
260  ///
261  /// @return pointer to the newly created device
262  ///
263  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
264 
265  static int numNodes(); ///< Number of nodes must be provided in the deriving class
266  static int numOptionalNodes() {return 0;} ///< Default number of optional nodes
267  static int numFillNodes() {return 0;} ///< Default number of fill nodes
268  static bool modelRequired() {return false;} ///< By default, model is not required
269  static const char *primaryParameter() {return "";} ///< By default, there is no primary parameter
270  static const char *instanceDefaultParameter() {return "";} ///< By default, there is no instance default parameter
271  static bool isLinearDevice(); ///< Linear device flag must be provided in the deriving class
272  static bool isPDEDevice() {return false;} ///< By default, device is not a PDE device
273 };
274 
275 //-----------------------------------------------------------------------------
276 // Class : FactoryBlock
277 // Purpose :
278 // Special Notes :
279 // Scope : public
280 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
281 // Creation Date : Mon Jan 27 14:49:12 2014
282 //-----------------------------------------------------------------------------
283 ///
284 /// The FactoryBlock contains parameters needed by the device,
285 /// instance and model creation functions. This allows additional
286 /// parameter to be added without the need to change the interface.
287 ///
288 /// The DeviceMgr class generally calls the factory functions and owns
289 /// these objects, however this is by no means a requirement.
290 ///
292 {
293  //-----------------------------------------------------------------------------
294  // Function : FactoryBlock
295  // Purpose :
296  // Special Notes :
297  // Scope : public
298  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
299  // Creation Date : Fri Mar 14 13:05:27 2014
300  //-----------------------------------------------------------------------------
301  ///
302  /// The FactoryBlock constructs serves to pass data to the device factory functions
303  ///
304  /// @invariant These references must exist through the execution of Xyce
305  ///
306  /// @param device_options
307  /// @param solver_state
308  /// @param matrix_load_data
309  /// @param extern_data
310  /// @param command_line
311  ///
313  const DeviceMgr & device_manager,
314  const DeviceOptions & device_options,
315  const SolverState & solver_state,
316  MatrixLoadData & matrix_load_data,
317  const ExternData & extern_data,
318  const IO::CmdParse & command_line)
319  : deviceManager_(device_manager),
320  deviceOptions_(device_options),
321  solverState_(solver_state),
322  externData_(extern_data),
323  matrixLoadData_(matrix_load_data),
324  commandLine_(command_line)
325  {}
326 
332  const IO::CmdParse & commandLine_;
333 };
334 
335 /// Class Configuration contains device configuration data.
336 ///
337 /// The DeviceTraits template describes the device and configuration is an object that holds the data obtained via the
338 /// traits.
339 ///
340 /// The configuration also maintains several containers that allow device, instance and model data and creation functions
341 /// to be located by name and level.
342 ///
344 {
345 public:
346  typedef unordered_map<NameLevelKey, Configuration *> ConfigurationMap;
347 
348  //-----------------------------------------------------------------------------
349  // Function : getConfigurationMap
350  // Purpose : Return the configuration map
351  // Special Notes :
352  // Scope : public
353  // Creator : Dave Baur, Raytheon
354  // Creation Date : 2/5/2014
355  //-----------------------------------------------------------------------------
356  ///
357  /// Returns the configuration map of the system
358  ///
359  /// The configuration map maps the device name and level pair to its configuration.
360  ///
361  /// @return const reference to the device configuration map.
362  static const ConfigurationMap &getConfigurationMap();
363 
364  //-----------------------------------------------------------------------------
365  // Function : findConfiguration
366  // Purpose :
367  // Special Notes :
368  // Scope : public
369  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
370  // Creation Date : Wed Feb 5 10:54:24 2014
371  //-----------------------------------------------------------------------------
372  ///
373  /// Returns the configuration associated with the device name and level or 0 if not found
374  ///
375  /// @param device_name const reference to the device name
376  /// @param level device level
377  ///
378  /// @return const pointer to the specified device's configuration
379  ///
380  static const Configuration *findConfiguration(ModelTypeId model_type_id);
381 
382  //-----------------------------------------------------------------------------
383  // Function : findConfiguration
384  // Purpose :
385  // Special Notes :
386  // Scope : public
387  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
388  // Creation Date : Wed Feb 5 10:54:24 2014
389  //-----------------------------------------------------------------------------
390  ///
391  /// Returns the configuration associated with the device name and level or 0 if not found
392  ///
393  /// @param device_name const reference to the device name
394  /// @param level device level
395  ///
396  /// @return const pointer to the specified device's configuration
397  ///
398  static const Configuration *findConfiguration(const std::string &device_name, const int level);
399 
400  //-----------------------------------------------------------------------------
401  // Function : getModelType
402  // Purpose :
403  // Special Notes :
404  // Scope : public
405  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
406  // Creation Date : Wed Feb 5 10:54:24 2014
407  //-----------------------------------------------------------------------------
408  ///
409  /// Returns the model type identifier for the specified device, if
410  /// the model type and level is not found, return an invalid type.
411  ///
412  /// @param model_name const reference to the model name
413  /// @param level device level
414  ///
415  /// @return the model type identifier for the specified device model
416  ///
417  static ModelTypeId getModelType(const std::string &model_name, const int level);
418 
419  //-----------------------------------------------------------------------------
420  // Function : getModelGroup
421  // Purpose :
422  // Special Notes :
423  // Scope : public
424  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
425  // Creation Date : Wed Feb 5 10:54:24 2014
426  //-----------------------------------------------------------------------------
427  ///
428  /// Returns the model group of the device name
429  ///
430  /// A device is registered as the model group when its model type identifier equals its model group identifier.
431  ///
432  /// @param device_name const reference to the device name
433  ///
434  /// @return model group identifier for the specified device
435  ///
436  static ModelTypeId getModelGroup(const std::string &device_name);
437 
438 protected:
439  //-----------------------------------------------------------------------------
440  // Function : Configuration
441  // Purpose :
442  // Special Notes :
443  // Scope : protected
444  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
445  // Creation Date : Mon Jan 27 15:06:50 2014
446  //-----------------------------------------------------------------------------
447  ///
448  /// Populates the device configuration object.
449  ///
450  /// Note that the instanceParameters_ and modelParameters_ each reference the instanceParameters__ and
451  /// modelParameters__ object of the derived Config<Traits> class. This really just keeps that casting down and could
452  /// be implemented as ParametricData<void> objects here.
453  ///
454  /// @param instance_parameters
455  /// @param model_parameters
456  /// @param name
457  /// @param device_type_name
458  /// @param num_nodes
459  /// @param num_optional_nodes
460  /// @param num_fill_nodes
461  /// @param model_required
462  /// @param primary_parameter
463  ///
465  ParametricData<void> & instance_parameters,
466  ParametricData<void> & model_parameters,
467  const char * name,
468  const char * device_type_name,
469  const char * instance_default_parameter_name,
470  int num_nodes,
471  int num_optional_nodes,
472  int num_fill_nodes,
473  bool model_required,
474  bool linear_device,
475  bool pde_device,
476  const char * primary_parameter)
477  : instanceParameters_(instance_parameters),
478  modelParameters_(model_parameters),
479  name_(name),
480  deviceTypeName_(device_type_name),
481  instanceDefaultParameterName_(instance_default_parameter_name),
482  numNodes_(num_nodes),
483  numOptionalNodes_(num_optional_nodes),
484  numFillNodes_(num_fill_nodes),
485  modelRequired_(model_required),
486  linearDevice_(linear_device),
487  pdeDevice_(pde_device),
488  primaryParameter_(primary_parameter),
490  {}
491 
492 public:
493  virtual ~Configuration()
494  {}
495 
496 private:
497  Configuration(const Configuration &); ///< No copies allowed
498  Configuration &operator=(const Configuration &); ///< No assignment allowed
499 
500 public:
501  /// Returns the instance parameter descriptions
502  ///
503  /// @return reference to the instance parameter descriptions
504  ///
506  {
507  return instanceParameters_;
508  }
509 
510  /// Returns the model parameter descriptions
511  ///
512  /// @return reference to the model parameter descriptions
513  ///
515  {
516  return modelParameters_;
517  }
518 
519  /// Returns the device name
520  ///
521  /// @return const reference to the device name
522  ///
523  const std::string &getName() const
524  {
525  return name_;
526  }
527 
528  /// Returns the device type name
529  ///
530  /// @return const reference to the device type name
531  ///
532  const std::string &getDeviceTypeName() const
533  {
534  return deviceTypeName_;
535  }
536 
537  /// Returns the instance default parameter name
538  ///
539  /// @return const reference to the instance default parameter name
540  ///
541  const std::string &getInstanceDefaultParameterName() const
542  {
544  }
545 
546  ///
547  /// Returns the number of nodes of this device
548  ///
549  /// @return number of nodes of this device
550  ///
551  int getNumNodes() const
552  {
553  return numNodes_;
554  }
555 
556  ///
557  /// Returns the number of optional nodes of this device
558  ///
559  /// @return number of optional nodes of this device
560  ///
562  {
563  return numOptionalNodes_;
564  }
565 
566  ///
567  /// Returns the number of fill nodes of this device
568  ///
569  /// @return number of fill nodes of this device
570  ///
571  int getNumFillNodes() const
572  {
573  return numFillNodes_;
574  }
575 
576  /// Returns true of the model must be specified when defining an instance of this device
577  ///
578  /// @return true if the model must be specified
579  ///
580  bool getModelRequired() const
581  {
582  return modelRequired_;
583  }
584 
585  /// Returns true of the model is a linear device
586  ///
587  /// @return true if the model is a linear deive
588  ///
589  bool getLinearDevice() const
590  {
591  return linearDevice_;
592  }
593 
594  /// Returns true of the model is a PDE device
595  ///
596  /// @return true if the model is a PDE device
597  ///
598  bool getPDEDevice() const
599  {
600  return pdeDevice_;
601  }
602 
603  /// Returns the default primary parameter of this device or the empty string if there is no primary parameter
604  ///
605  /// @return primary parameter for this device.
606  ///
607  const std::string &getPrimaryParameter() const
608  {
609  return primaryParameter_;
610  }
611 
612  /// Returns a vector of strings that name all the model types defined of this model
613  ///
614  /// @return const reference to the vector of string names of defined model types
615  ///
616  const std::vector<std::string> &getModelTypeNames() const
617  {
618  return modelTypeNames_;
619  }
620 
621  //-----------------------------------------------------------------------------
622  // Function : findConfiguration
623  // Purpose :
624  // Special Notes :
625  // Scope : public
626  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
627  // Creation Date : Wed Feb 5 10:54:24 2014
628  //-----------------------------------------------------------------------------
629  ///
630  /// Creates the specified device
631  ///
632  /// @param model_type model type of the device to create
633  /// @param factory_block parameters provided to the factory function
634  ///
635  /// @return
636  ///
637  Device *createDevice(const FactoryBlock &factory_block) const;
638 
639  //-----------------------------------------------------------------------------
640  // Function : factory
641  // Purpose :
642  // Special Notes :
643  // Scope : protected
644  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
645  // Creation Date : Mon Jan 27 15:06:50 2014
646  //-----------------------------------------------------------------------------
647  ///
648  /// Overriding function creates an instance this device
649  ///
650  /// Ownership of this object is passed to the caller which is responsible to destory the created object.
651  ///
652  /// @param factory_block reference to the parameter block
653  ///
654  /// @return pointer to the newly created device.
655  ///
656  virtual Device *factory(const FactoryBlock &factory_block) const = 0;
657 
658  //-----------------------------------------------------------------------------
659  // Function : instancetype
660  // Purpose :
661  // Special Notes :
662  // Scope : protected
663  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
664  // Creation Date : Mon Jan 27 15:06:50 2014
665  //-----------------------------------------------------------------------------
666  ///
667  /// Returns the instance type identifier
668  ///
669  /// @return the instance type identifier
670  ///
671  virtual InstanceTypeId instanceType() const = 0;
672 
673  //-----------------------------------------------------------------------------
674  // Function : modelType
675  // Purpose :
676  // Special Notes :
677  // Scope : protected
678  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
679  // Creation Date : Mon Jan 27 15:06:50 2014
680  //-----------------------------------------------------------------------------
681  ///
682  /// Returns the model type identifier
683  ///
684  /// @return the model type identifier
685  ///
686  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
687  /// @date Wed Feb 5 10:08:52 2014
688  ///
689  virtual ModelTypeId modelType() const = 0;
690 
691  //-----------------------------------------------------------------------------
692  // Function : modelGroup
693  // Purpose :
694  // Special Notes :
695  // Scope : protected
696  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
697  // Creation Date : Mon Jan 27 15:06:50 2014
698  //-----------------------------------------------------------------------------
699  ///
700  /// Returns the model group identifier
701  ///
702  /// @return the model group identifier
703  ///
704  virtual ModelTypeId modelGroup() const = 0;
705 
706 protected:
707  //-----------------------------------------------------------------------------
708  // Function : addDevice
709  // Purpose :
710  // Special Notes :
711  // Scope : protected
712  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
713  // Creation Date : Mon Jan 27 15:06:50 2014
714  //-----------------------------------------------------------------------------
715  ///
716  /// Adds the device to the configuration
717  ///
718  /// @invariant only one device can designate itself as the group lead
719  /// @invariant device and level must be unique
720  ///
721  /// @param device_name const character pointer to the device name
722  /// @param device_level device level
723  /// @param model_type_id model type identifier of the device
724  ///
725  void addDevice(const char *model_name, const int model_level, ModelTypeId model_type_id, ModelTypeId model_group_id, int model_type_nodes, int model_group_nodes);
726 
727  //-----------------------------------------------------------------------------
728  // Function : addModel
729  // Purpose :
730  // Special Notes :
731  // Scope : protected
732  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
733  // Creation Date : Mon Jan 27 15:06:50 2014
734  //-----------------------------------------------------------------------------
735  ///
736  /// Adds a model name for the device to the configuration
737  ///
738  /// @invariant only one device can designate itself as the group lead
739  /// @invariant model names must be unique within a device configuration
740  ///
741  /// @param model_name const character pointer to the model name
742  /// @param level model level of this model of the device
743  /// @param model_type_id model type identifier
744  /// @param model_group_id mode group identifier
745  ///
746  void addModel(const char *model_name, const int level, ModelTypeId model_type_id, ModelTypeId model_group_id);
747 
748 private:
749  ParametricData<void> & instanceParameters_; ///< Reference to the Instance specific parameter map
750  ParametricData<void> & modelParameters_; ///< Reference to the Model specific parameter map
751  const std::string name_; ///< Name of the devive
752  const std::string deviceTypeName_; ///< Type name of the device
753  const std::string instanceDefaultParameterName_; ///< Default parameter name for the device instance
754  int numNodes_; ///< Number of nodes of this device
755  int numOptionalNodes_; ///< Number of optional nodes of this device
756  int numFillNodes_; ///< Number of fill nodes of this device
757  bool modelRequired_; ///< True if model is required
758  bool linearDevice_; ///< True if model is a linear device
759  bool pdeDevice_; ///< True if model is a PDE device
760  std::string primaryParameter_; ///< Primary parameter name or the empty string if none
761  std::vector<std::string> modelTypeNames_; ///< Vector of defined model type of this device's model
762 };
763 
764 template<class T, class G>
766 {
767  typedef G GroupTraits_;
768 };
769 
770 template<class T>
772 {
773  typedef T GroupTraits_;
774 };
775 
776 //-----------------------------------------------------------------------------
777 // Class : Config
778 // Purpose :
779 // Special Notes :
780 // Scope : protected
781 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
782 // Creation Date : Mon Jan 27 15:06:50 2014
783 //-----------------------------------------------------------------------------
784 ///
785 /// Config template derives from the Configuration class and provides the instance and model parameter decriptions.
786 ///
787 template <class T>
788 class Config : public Configuration
789 {
790  public:
791  typedef T ModelTraits;
793 
794  /// Adds the device to the Xyce device configuration
795  ///
796  /// @return reference to newly created configuration
797  ///
798  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
799  /// @date Thu Feb 6 07:15:11 2014
800  ///
802  {
803  return *(new Config<T>());
804  }
805 
806  private:
807  /// Creates the configuration object, populating the instance and model parameter definitions from the Traits
808  ///
809  /// The registerDevice() and registerModelType() functions are used by the device registration function to name the
810  /// device and device levels.
811  ///
812  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
813  /// @date Mon Jan 27 15:28:59 2014
814  ///
816  : Configuration(instanceParameters__, modelParameters__, ModelTraits::name(), ModelTraits::deviceTypeName(), ModelTraits::instanceDefaultParameter(),
817  ModelTraits::numNodes(), ModelTraits::numOptionalNodes(), ModelTraits::numFillNodes(), ModelTraits::modelRequired(),
818  ModelTraits::isLinearDevice(), ModelTraits::isPDEDevice(), ModelTraits::primaryParameter()),
821  {
822  ModelTraits::loadInstanceParameters(instanceParameters__); /// loadInstanceParameters() is called populate the instance parameter desciptions
823  ModelTraits::loadModelParameters(modelParameters__); /// loadModelParameters() is called to populate the model parameter desciptions
824  }
825 
826  //-----------------------------------------------------------------------------
827  // Function : ~Config
828  // Purpose :
829  // Special Notes :
830  // Scope : public
831  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
832  // Creation Date : Fri Mar 14 13:19:39 2014
833  //-----------------------------------------------------------------------------
834  ///
835  /// Destroys the Config
836  ///
837  virtual ~Config()
838  {}
839 
840  Config(const Config<T> &); ///< No copying
841  Config &operator=(const Config<T> &); ///< No assignment
842 
843  public:
844  //-----------------------------------------------------------------------------
845  // Function : registerDevice
846  // Purpose :
847  // Special Notes :
848  // Scope : public
849  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
850  // Creation Date : Mon Jan 27 15:31:43 2014
851  //-----------------------------------------------------------------------------
852  ///
853  /// Adds the device into the device registry giving it the specified device name and level
854  ///
855  /// Registering a device maps the model type to the device name level key.
856  ///
857  /// @param device_name const character pointer name of the device
858  /// @param level level of the device
859  ///
860  Config<T> &registerDevice(const char *device_name, const int level)
861  {
862  addDevice(device_name, level, ModelTraits::modelType(), ModelTraits::modelGroup(), ModelTraits::numNodes(), ModelGroupTraits::numNodes());
863 
864  return *this;
865  }
866 
867  //-----------------------------------------------------------------------------
868  // Function : registerModelType
869  // Purpose :
870  // Special Notes :
871  // Scope : public
872  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
873  // Creation Date : Mon Jan 27 15:31:43 2014
874  //-----------------------------------------------------------------------------
875  ///
876  /// Adds a model type name and level to the device model type list
877  ///
878  /// @param model_name const character pointer model name
879  /// @param level model level of the model
880  ///
881  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
882  /// @date Mon Jan 27 15:32:50 2014
883  ///
884  Config<T> &registerModelType(const char *model_name, const int level)
885  {
886  addModel(model_name, level, ModelTraits::modelType(), ModelTraits::modelGroup());
887 
888  return *this;
889  }
890 
891  //-----------------------------------------------------------------------------
892  // Function : instanceType
893  // Purpose :
894  // Special Notes :
895  // Scope : public
896  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
897  // Creation Date : Mon Jan 27 15:31:43 2014
898  //-----------------------------------------------------------------------------
899  ///
900  /// Returns the instance type identifier
901  ///
902  /// @return the instance type identifier
903  ///
904  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
905  /// @date Wed Feb 5 10:08:52 2014
906  ///
907  virtual InstanceTypeId instanceType() const /* override */
908  {
909  return ModelTraits::instanceType();
910  }
911 
912  //-----------------------------------------------------------------------------
913  // Function : modelType
914  // Purpose :
915  // Special Notes :
916  // Scope : public
917  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
918  // Creation Date : Mon Jan 27 15:31:43 2014
919  //-----------------------------------------------------------------------------
920  ///
921  /// Returns the model type identifier
922  ///
923  /// @return the model type identifier
924  ///
925  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
926  /// @date Wed Feb 5 10:08:52 2014
927  ///
928  virtual ModelTypeId modelType() const /* override */
929  {
930  return ModelTraits::modelType();
931  }
932 
933  //-----------------------------------------------------------------------------
934  // Function : modelGroup
935  // Purpose :
936  // Special Notes :
937  // Scope : public
938  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
939  // Creation Date : Mon Jan 27 15:31:43 2014
940  //-----------------------------------------------------------------------------
941  ///
942  /// Returns the model group identifier
943  ///
944  /// @return the model group identifier
945  ///
946  virtual ModelTypeId modelGroup() const /* override */
947  {
948  return ModelTraits::modelGroup();
949  }
950 
951  //-----------------------------------------------------------------------------
952  // Function : factory
953  // Purpose :
954  // Special Notes :
955  // Scope : public
956  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
957  // Creation Date : Mon Jan 27 15:31:43 2014
958  //-----------------------------------------------------------------------------
959  ///
960  /// Calls the device creation function
961  ///
962  /// @param factory_block factory parameters
963  ///
964  /// @return pointer to the new device
965  ///
966  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
967  /// @date Mon Jan 27 15:35:19 2014
968  ///
969  Device *factory(const FactoryBlock &factory_block) const /* override */
970  {
971  return ModelTraits::factory(*this, factory_block);
972  }
973 
974  private:
977 };
978 
979 } // namespace Device
980 } // namespace Xyce
981 
982 #endif // Xyce_N_DEV_Configuration_h
ModelGroupType_< M, G >::GroupType_ ModelGroupType
Make model group template parameter available.
bool getModelRequired() const
Returns true of the model must be specified when defining an instance of this device.
ParametricData< void > & getModelParameters() const
Returns the model parameter descriptions.
int getNumFillNodes() const
Returns the number of fill nodes of this device.
virtual ModelTypeId modelType() const
Returns the model type identifier.
virtual InstanceTypeId instanceType() const
Returns the instance type identifier.
int numNodes_
Number of nodes of this device.
Device * factory(const FactoryBlock &factory_block) const
Calls the device creation function.
const DeviceOptions & deviceOptions_
Config template derives from the Configuration class and provides the instance and model parameter de...
FactoryBlock(const DeviceMgr &device_manager, const DeviceOptions &device_options, const SolverState &solver_state, MatrixLoadData &matrix_load_data, const ExternData &extern_data, const IO::CmdParse &command_line)
The FactoryBlock constructs serves to pass data to the device factory functions.
bool linearDevice_
True if model is a linear device.
static bool modelRequired()
By default, model is not required.
bool getPDEDevice() const
Returns true of the model is a PDE device.
Config< T > & registerDevice(const char *device_name, const int level)
Adds the device into the device registry giving it the specified device name and level.
void addDevice(const char *model_name, const int model_level, ModelTypeId model_type_id, ModelTypeId model_group_id, int model_type_nodes, int model_group_nodes)
Adds the device to the configuration.
void G(const ScalarT &V1, const ScalarT &V2, const ScalarT &Ap, const ScalarT &An, ScalarT &Vp, ScalarT &Vn, ScalarT &fval)
Pure virtual class to augment a linear system.
static const InstanceTypeId instanceType()
Returns the instance type identifier.
const std::string & getPrimaryParameter() const
Returns the default primary parameter of this device or the empty string if there is no primary param...
ParametricData< typename ModelTraits::InstanceType > instanceParameters__
Instance parameter description.
Device * createDevice(const FactoryBlock &factory_block) const
Creates the specified device.
static const char * primaryParameter()
By default, there is no primary parameter.
static bool isLinearDevice()
Linear device flag must be provided in the deriving class.
type_index InstanceTypeId
Definition: N_DEV_fwd.h:163
int getNumOptionalNodes() const
Returns the number of optional nodes of this device.
type_index EntityTypeId
Definition: N_DEV_fwd.h:161
const std::string & getDeviceTypeName() const
Returns the device type name.
G ModelGroupTraits
Make model group traits template parameter available.
Config()
Creates the configuration object, populating the instance and model parameter definitions from the Tr...
static const Configuration * findConfiguration(ModelTypeId model_type_id)
Returns the configuration associated with the device name and level or 0 if not found.
Config & operator=(const Config< T > &)
No assignment.
virtual ~Config()
Destroys the Config.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
int numFillNodes_
Number of fill nodes of this device.
M ModelType
Make model template parameter available.
virtual Device * factory(const FactoryBlock &factory_block) const =0
Overriding function creates an instance this device.
static ModelTypeId getModelGroup(const std::string &device_name)
Returns the model group of the device name.
ParametricData< void > & modelParameters_
Reference to the Model specific parameter map.
ParametricData< void > & getInstanceParameters() const
Returns the instance parameter descriptions.
const IO::CmdParse & commandLine_
const std::string deviceTypeName_
Type name of the device.
Class ParametricData manages the configuration information and the parameter binding map...
Definition: N_DEV_Pars.h:1303
static Config< T > & addConfiguration()
Adds the device to the Xyce device configuration.
ParametricData< typename ModelTraits::ModelType > modelParameters__
Model parameter description.
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
static int numNodes()
Number of nodes must be provided in the deriving class.
std::string primaryParameter_
Primary parameter name or the empty string if none.
std::vector< std::string > modelTypeNames_
Vector of defined model type of this device's model.
static const ModelTypeId modelType()
Returns the model type identifier.
bool pdeDevice_
True if model is a PDE device.
type_index ModelTypeId
Definition: N_DEV_fwd.h:162
const SolverState & solverState_
virtual InstanceTypeId instanceType() const =0
Returns the instance type identifier.
Class Configuration contains device configuration data.
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Creates a device via the device template.
ParametricData< void > & instanceParameters_
Reference to the Instance specific parameter map.
const std::string instanceDefaultParameterName_
Default parameter name for the device instance.
Config< T > & registerModelType(const char *model_name, const int level)
Adds a model type name and level to the device model type list.
int numOptionalNodes_
Number of optional nodes of this device.
const std::string name_
Name of the devive.
static const ModelTypeId modelGroup()
Returns the model group identifier.
#define M
Configuration & operator=(const Configuration &)
No assignment allowed.
int getNumNodes() const
Returns the number of nodes of this device.
bool modelRequired_
True if model is required.
static const ConfigurationMap & getConfigurationMap()
Returns the configuration map of the system.
ModelGroupTraits_< T, typename T::ModelGroupTraits >::GroupTraits_ ModelGroupTraits
unordered_map< NameLevelKey, Configuration * > ConfigurationMap
virtual ModelTypeId modelType() const =0
Returns the model type identifier.
static ModelTypeId getModelType(const std::string &model_name, const int level)
Returns the model type identifier for the specified device, if the model type and level is not found...
static int numFillNodes()
Default number of fill nodes.
I InstanceType
Make instance template parameter available.
Configuration(ParametricData< void > &instance_parameters, ParametricData< void > &model_parameters, const char *name, const char *device_type_name, const char *instance_default_parameter_name, int num_nodes, int num_optional_nodes, int num_fill_nodes, bool model_required, bool linear_device, bool pde_device, const char *primary_parameter)
Populates the device configuration object.
static bool isPDEDevice()
By default, device is not a PDE device.
static const char * instanceDefaultParameter()
By default, there is no instance default parameter.
virtual ModelTypeId modelGroup() const
Returns the model group identifier.
const std::string & getName() const
Returns the device name.
The DeviceTraits template describes the configuration of a device.
virtual ModelTypeId modelGroup() const =0
Returns the model group identifier.
const std::string & getInstanceDefaultParameterName() const
Returns the instance default parameter name.
const std::vector< std::string > & getModelTypeNames() const
Returns a vector of strings that name all the model types defined of this model.
static int numOptionalNodes()
Default number of optional nodes.
void addModel(const char *model_name, const int level, ModelTypeId model_type_id, ModelTypeId model_group_id)
Adds a model name for the device to the configuration.
bool getLinearDevice() const
Returns true of the model is a linear device.