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.25.2.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:29:36 $
42 //
43 // Current Owner : $Author: tvrusso $
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 DeviceOptions & device_options,
314  const SolverState & solver_state,
315  MatrixLoadData & matrix_load_data,
316  const ExternData & extern_data,
317  const IO::CmdParse & command_line)
318  : deviceOptions_(device_options),
319  solverState_(solver_state),
320  matrixLoadData_(matrix_load_data),
321  externData_(extern_data),
322  commandLine_(command_line)
323  {}
324 
329  const IO::CmdParse & commandLine_;
330 };
331 
332 /// Class Configuration contains device configuration data.
333 ///
334 /// The DeviceTraits template describes the device and configuration is an object that holds the data obtained via the
335 /// traits.
336 ///
337 /// The configuration also maintains several containers that allow device, instance and model data and creation functions
338 /// to be located by name and level.
339 ///
341 {
342 public:
343  typedef unordered_map<NameLevelKey, Configuration *> ConfigurationMap;
344 
345  //-----------------------------------------------------------------------------
346  // Function : getConfigurationMap
347  // Purpose : Return the configuration map
348  // Special Notes :
349  // Scope : public
350  // Creator : Dave Baur, Raytheon
351  // Creation Date : 2/5/2014
352  //-----------------------------------------------------------------------------
353  ///
354  /// Returns the configuration map of the system
355  ///
356  /// The configuration map maps the device name and level pair to its configuration.
357  ///
358  /// @return const reference to the device configuration map.
359  static const ConfigurationMap &getConfigurationMap();
360 
361  //-----------------------------------------------------------------------------
362  // Function : findConfiguration
363  // Purpose :
364  // Special Notes :
365  // Scope : public
366  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
367  // Creation Date : Wed Feb 5 10:54:24 2014
368  //-----------------------------------------------------------------------------
369  ///
370  /// Returns the configuration associated with the device name and level or 0 if not found
371  ///
372  /// @param device_name const reference to the device name
373  /// @param level device level
374  ///
375  /// @return const pointer to the specified device's configuration
376  ///
377  static const Configuration *findConfiguration(ModelTypeId model_type_id);
378 
379  //-----------------------------------------------------------------------------
380  // Function : findConfiguration
381  // Purpose :
382  // Special Notes :
383  // Scope : public
384  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
385  // Creation Date : Wed Feb 5 10:54:24 2014
386  //-----------------------------------------------------------------------------
387  ///
388  /// Returns the configuration associated with the device name and level or 0 if not found
389  ///
390  /// @param device_name const reference to the device name
391  /// @param level device level
392  ///
393  /// @return const pointer to the specified device's configuration
394  ///
395  static const Configuration *findConfiguration(const std::string &device_name, const int level);
396 
397  //-----------------------------------------------------------------------------
398  // Function : getModelType
399  // Purpose :
400  // Special Notes :
401  // Scope : public
402  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
403  // Creation Date : Wed Feb 5 10:54:24 2014
404  //-----------------------------------------------------------------------------
405  ///
406  /// Returns the model type identifier for the specified device, if
407  /// the model type and level is not found, return an invalid type.
408  ///
409  /// @param model_name const reference to the model name
410  /// @param level device level
411  ///
412  /// @return the model type identifier for the specified device model
413  ///
414  static ModelTypeId getModelType(const std::string &model_name, const int level);
415 
416  //-----------------------------------------------------------------------------
417  // Function : getModelGroup
418  // Purpose :
419  // Special Notes :
420  // Scope : public
421  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
422  // Creation Date : Wed Feb 5 10:54:24 2014
423  //-----------------------------------------------------------------------------
424  ///
425  /// Returns the model group of the device name
426  ///
427  /// A device is registered as the model group when its model type identifier equals its model group identifier.
428  ///
429  /// @param device_name const reference to the device name
430  ///
431  /// @return model group identifier for the specified device
432  ///
433  static ModelTypeId getModelGroup(const std::string &device_name);
434 
435 protected:
436  //-----------------------------------------------------------------------------
437  // Function : Configuration
438  // Purpose :
439  // Special Notes :
440  // Scope : protected
441  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
442  // Creation Date : Mon Jan 27 15:06:50 2014
443  //-----------------------------------------------------------------------------
444  ///
445  /// Populates the device configuration object.
446  ///
447  /// Note that the instanceParameters_ and modelParameters_ each reference the instanceParameters__ and
448  /// modelParameters__ object of the derived Config<Traits> class. This really just keeps that casting down and could
449  /// be implemented as ParametricData<void> objects here.
450  ///
451  /// @param instance_parameters
452  /// @param model_parameters
453  /// @param name
454  /// @param device_type_name
455  /// @param num_nodes
456  /// @param num_optional_nodes
457  /// @param num_fill_nodes
458  /// @param model_required
459  /// @param primary_parameter
460  ///
462  ParametricData<void> & instance_parameters,
463  ParametricData<void> & model_parameters,
464  const char * name,
465  const char * device_type_name,
466  const char * instance_default_parameter_name,
467  int num_nodes,
468  int num_optional_nodes,
469  int num_fill_nodes,
470  bool model_required,
471  bool linear_device,
472  bool pde_device,
473  const char * primary_parameter)
474  : instanceParameters_(instance_parameters),
475  modelParameters_(model_parameters),
476  name_(name),
477  deviceTypeName_(device_type_name),
478  instanceDefaultParameterName_(instance_default_parameter_name),
479  numNodes_(num_nodes),
480  numOptionalNodes_(num_optional_nodes),
481  numFillNodes_(num_fill_nodes),
482  modelRequired_(model_required),
483  linearDevice_(linear_device),
484  pdeDevice_(pde_device),
485  primaryParameter_(primary_parameter),
487  {}
488 
489 public:
490  virtual ~Configuration()
491  {}
492 
493 private:
494  Configuration(const Configuration &); ///< No copies allowed
495  Configuration &operator=(const Configuration &); ///< No assignment allowed
496 
497 public:
498  /// Returns the instance parameter descriptions
499  ///
500  /// @return reference to the instance parameter descriptions
501  ///
503  {
504  return instanceParameters_;
505  }
506 
507  /// Returns the model parameter descriptions
508  ///
509  /// @return reference to the model parameter descriptions
510  ///
512  {
513  return modelParameters_;
514  }
515 
516  /// Returns the device name
517  ///
518  /// @return const reference to the device name
519  ///
520  const std::string &getName() const
521  {
522  return name_;
523  }
524 
525  /// Returns the device type name
526  ///
527  /// @return const reference to the device type name
528  ///
529  const std::string &getDeviceTypeName() const
530  {
531  return deviceTypeName_;
532  }
533 
534  /// Returns the instance default parameter name
535  ///
536  /// @return const reference to the instance default parameter name
537  ///
538  const std::string &getInstanceDefaultParameterName() const
539  {
541  }
542 
543  ///
544  /// Returns the number of nodes of this device
545  ///
546  /// @return number of nodes of this device
547  ///
548  int getNumNodes() const
549  {
550  return numNodes_;
551  }
552 
553  ///
554  /// Returns the number of optional nodes of this device
555  ///
556  /// @return number of optional nodes of this device
557  ///
559  {
560  return numOptionalNodes_;
561  }
562 
563  ///
564  /// Returns the number of fill nodes of this device
565  ///
566  /// @return number of fill nodes of this device
567  ///
568  int getNumFillNodes() const
569  {
570  return numFillNodes_;
571  }
572 
573  /// Returns true of the model must be specified when defining an instance of this device
574  ///
575  /// @return true if the model must be specified
576  ///
577  bool getModelRequired() const
578  {
579  return modelRequired_;
580  }
581 
582  /// Returns true of the model is a linear device
583  ///
584  /// @return true if the model is a linear deive
585  ///
586  bool getLinearDevice() const
587  {
588  return linearDevice_;
589  }
590 
591  /// Returns true of the model is a PDE device
592  ///
593  /// @return true if the model is a PDE device
594  ///
595  bool getPDEDevice() const
596  {
597  return pdeDevice_;
598  }
599 
600  /// Returns the default primary parameter of this device or the empty string if there is no primary parameter
601  ///
602  /// @return primary parameter for this device.
603  ///
604  const std::string &getPrimaryParameter() const
605  {
606  return primaryParameter_;
607  }
608 
609  /// Returns a vector of strings that name all the model types defined of this model
610  ///
611  /// @return const reference to the vector of string names of defined model types
612  ///
613  const std::vector<std::string> &getModelTypeNames() const
614  {
615  return modelTypeNames_;
616  }
617 
618  //-----------------------------------------------------------------------------
619  // Function : findConfiguration
620  // Purpose :
621  // Special Notes :
622  // Scope : public
623  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
624  // Creation Date : Wed Feb 5 10:54:24 2014
625  //-----------------------------------------------------------------------------
626  ///
627  /// Creates the specified device
628  ///
629  /// @param model_type model type of the device to create
630  /// @param factory_block parameters provided to the factory function
631  ///
632  /// @return
633  ///
634  Device *createDevice(const FactoryBlock &factory_block) const;
635 
636  //-----------------------------------------------------------------------------
637  // Function : factory
638  // Purpose :
639  // Special Notes :
640  // Scope : protected
641  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
642  // Creation Date : Mon Jan 27 15:06:50 2014
643  //-----------------------------------------------------------------------------
644  ///
645  /// Overriding function creates an instance this device
646  ///
647  /// Ownership of this object is passed to the caller which is responsible to destory the created object.
648  ///
649  /// @param factory_block reference to the parameter block
650  ///
651  /// @return pointer to the newly created device.
652  ///
653  virtual Device *factory(const FactoryBlock &factory_block) const = 0;
654 
655  //-----------------------------------------------------------------------------
656  // Function : instancetype
657  // Purpose :
658  // Special Notes :
659  // Scope : protected
660  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
661  // Creation Date : Mon Jan 27 15:06:50 2014
662  //-----------------------------------------------------------------------------
663  ///
664  /// Returns the instance type identifier
665  ///
666  /// @return the instance type identifier
667  ///
668  virtual InstanceTypeId instanceType() const = 0;
669 
670  //-----------------------------------------------------------------------------
671  // Function : modelType
672  // Purpose :
673  // Special Notes :
674  // Scope : protected
675  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
676  // Creation Date : Mon Jan 27 15:06:50 2014
677  //-----------------------------------------------------------------------------
678  ///
679  /// Returns the model type identifier
680  ///
681  /// @return the model type identifier
682  ///
683  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
684  /// @date Wed Feb 5 10:08:52 2014
685  ///
686  virtual ModelTypeId modelType() const = 0;
687 
688  //-----------------------------------------------------------------------------
689  // Function : modelGroup
690  // Purpose :
691  // Special Notes :
692  // Scope : protected
693  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
694  // Creation Date : Mon Jan 27 15:06:50 2014
695  //-----------------------------------------------------------------------------
696  ///
697  /// Returns the model group identifier
698  ///
699  /// @return the model group identifier
700  ///
701  virtual ModelTypeId modelGroup() const = 0;
702 
703 protected:
704  //-----------------------------------------------------------------------------
705  // Function : addDevice
706  // Purpose :
707  // Special Notes :
708  // Scope : protected
709  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
710  // Creation Date : Mon Jan 27 15:06:50 2014
711  //-----------------------------------------------------------------------------
712  ///
713  /// Adds the device to the configuration
714  ///
715  /// @invariant only one device can designate itself as the group lead
716  /// @invariant device and level must be unique
717  ///
718  /// @param device_name const character pointer to the device name
719  /// @param device_level device level
720  /// @param model_type_id model type identifier of the device
721  ///
722  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);
723 
724  //-----------------------------------------------------------------------------
725  // Function : addModel
726  // Purpose :
727  // Special Notes :
728  // Scope : protected
729  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
730  // Creation Date : Mon Jan 27 15:06:50 2014
731  //-----------------------------------------------------------------------------
732  ///
733  /// Adds a model name for the device to the configuration
734  ///
735  /// @invariant only one device can designate itself as the group lead
736  /// @invariant model names must be unique within a device configuration
737  ///
738  /// @param model_name const character pointer to the model name
739  /// @param level model level of this model of the device
740  /// @param model_type_id model type identifier
741  /// @param model_group_id mode group identifier
742  ///
743  void addModel(const char *model_name, const int level, ModelTypeId model_type_id, ModelTypeId model_group_id);
744 
745 private:
746  ParametricData<void> & instanceParameters_; ///< Reference to the Instance specific parameter map
747  ParametricData<void> & modelParameters_; ///< Reference to the Model specific parameter map
748  const std::string name_; ///< Name of the devive
749  const std::string deviceTypeName_; ///< Type name of the device
750  const std::string instanceDefaultParameterName_; ///< Default parameter name for the device instance
751  int numNodes_; ///< Number of nodes of this device
752  int numOptionalNodes_; ///< Number of optional nodes of this device
753  int numFillNodes_; ///< Number of fill nodes of this device
754  bool modelRequired_; ///< True if model is required
755  bool linearDevice_; ///< True if model is a linear device
756  bool pdeDevice_; ///< True if model is a PDE device
757  std::string primaryParameter_; ///< Primary parameter name or the empty string if none
758  std::vector<std::string> modelTypeNames_; ///< Vector of defined model type of this device's model
759 };
760 
761 template<class T, class G>
763 {
764  typedef G GroupTraits_;
765 };
766 
767 template<class T>
769 {
770  typedef T GroupTraits_;
771 };
772 
773 //-----------------------------------------------------------------------------
774 // Class : Config
775 // Purpose :
776 // Special Notes :
777 // Scope : protected
778 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
779 // Creation Date : Mon Jan 27 15:06:50 2014
780 //-----------------------------------------------------------------------------
781 ///
782 /// Config template derives from the Configuration class and provides the instance and model parameter decriptions.
783 ///
784 template <class T>
785 class Config : public Configuration
786 {
787  public:
788  typedef T ModelTraits;
790 
791  /// Adds the device to the Xyce device configuration
792  ///
793  /// @return reference to newly created configuration
794  ///
795  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
796  /// @date Thu Feb 6 07:15:11 2014
797  ///
799  {
800  return *(new Config<T>());
801  }
802 
803  private:
804  /// Creates the configuration object, populating the instance and model parameter definitions from the Traits
805  ///
806  /// The registerDevice() and registerModelType() functions are used by the device registration function to name the
807  /// device and device levels.
808  ///
809  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
810  /// @date Mon Jan 27 15:28:59 2014
811  ///
813  : Configuration(instanceParameters__, modelParameters__, ModelTraits::name(), ModelTraits::deviceTypeName(), ModelTraits::instanceDefaultParameter(),
814  ModelTraits::numNodes(), ModelTraits::numOptionalNodes(), ModelTraits::numFillNodes(), ModelTraits::modelRequired(),
815  ModelTraits::isLinearDevice(), ModelTraits::isPDEDevice(), ModelTraits::primaryParameter()),
818  {
819  ModelTraits::loadInstanceParameters(instanceParameters__); /// loadInstanceParameters() is called populate the instance parameter desciptions
820  ModelTraits::loadModelParameters(modelParameters__); /// loadModelParameters() is called to populate the model parameter desciptions
821  }
822 
823  //-----------------------------------------------------------------------------
824  // Function : ~Config
825  // Purpose :
826  // Special Notes :
827  // Scope : public
828  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
829  // Creation Date : Fri Mar 14 13:19:39 2014
830  //-----------------------------------------------------------------------------
831  ///
832  /// Destroys the Config
833  ///
834  virtual ~Config()
835  {}
836 
837  Config(const Config<T> &); ///< No copying
838  Config &operator=(const Config<T> &); ///< No assignment
839 
840  public:
841  //-----------------------------------------------------------------------------
842  // Function : registerDevice
843  // Purpose :
844  // Special Notes :
845  // Scope : public
846  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
847  // Creation Date : Mon Jan 27 15:31:43 2014
848  //-----------------------------------------------------------------------------
849  ///
850  /// Adds the device into the device registry giving it the specified device name and level
851  ///
852  /// Registering a device maps the model type to the device name level key.
853  ///
854  /// @param device_name const character pointer name of the device
855  /// @param level level of the device
856  ///
857  Config<T> &registerDevice(const char *device_name, const int level)
858  {
859  addDevice(device_name, level, ModelTraits::modelType(), ModelTraits::modelGroup(), ModelTraits::numNodes(), ModelGroupTraits::numNodes());
860 
861  return *this;
862  }
863 
864  //-----------------------------------------------------------------------------
865  // Function : registerModelType
866  // Purpose :
867  // Special Notes :
868  // Scope : public
869  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
870  // Creation Date : Mon Jan 27 15:31:43 2014
871  //-----------------------------------------------------------------------------
872  ///
873  /// Adds a model type name and level to the device model type list
874  ///
875  /// @param model_name const character pointer model name
876  /// @param level model level of the model
877  ///
878  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
879  /// @date Mon Jan 27 15:32:50 2014
880  ///
881  Config<T> &registerModelType(const char *model_name, const int level)
882  {
883  addModel(model_name, level, ModelTraits::modelType(), ModelTraits::modelGroup());
884 
885  return *this;
886  }
887 
888  //-----------------------------------------------------------------------------
889  // Function : instanceType
890  // Purpose :
891  // Special Notes :
892  // Scope : public
893  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
894  // Creation Date : Mon Jan 27 15:31:43 2014
895  //-----------------------------------------------------------------------------
896  ///
897  /// Returns the instance type identifier
898  ///
899  /// @return the instance type identifier
900  ///
901  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
902  /// @date Wed Feb 5 10:08:52 2014
903  ///
904  virtual InstanceTypeId instanceType() const /* override */
905  {
906  return ModelTraits::instanceType();
907  }
908 
909  //-----------------------------------------------------------------------------
910  // Function : modelType
911  // Purpose :
912  // Special Notes :
913  // Scope : public
914  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
915  // Creation Date : Mon Jan 27 15:31:43 2014
916  //-----------------------------------------------------------------------------
917  ///
918  /// Returns the model type identifier
919  ///
920  /// @return the model type identifier
921  ///
922  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
923  /// @date Wed Feb 5 10:08:52 2014
924  ///
925  virtual ModelTypeId modelType() const /* override */
926  {
927  return ModelTraits::modelType();
928  }
929 
930  //-----------------------------------------------------------------------------
931  // Function : modelGroup
932  // Purpose :
933  // Special Notes :
934  // Scope : public
935  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
936  // Creation Date : Mon Jan 27 15:31:43 2014
937  //-----------------------------------------------------------------------------
938  ///
939  /// Returns the model group identifier
940  ///
941  /// @return the model group identifier
942  ///
943  virtual ModelTypeId modelGroup() const /* override */
944  {
945  return ModelTraits::modelGroup();
946  }
947 
948  //-----------------------------------------------------------------------------
949  // Function : factory
950  // Purpose :
951  // Special Notes :
952  // Scope : public
953  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
954  // Creation Date : Mon Jan 27 15:31:43 2014
955  //-----------------------------------------------------------------------------
956  ///
957  /// Calls the device creation function
958  ///
959  /// @param factory_block factory parameters
960  ///
961  /// @return pointer to the new device
962  ///
963  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
964  /// @date Mon Jan 27 15:35:19 2014
965  ///
966  Device *factory(const FactoryBlock &factory_block) const /* override */
967  {
968  return ModelTraits::factory(*this, factory_block);
969  }
970 
971  private:
974 };
975 
976 } // namespace Device
977 } // namespace Xyce
978 
979 #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...
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.
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:155
int getNumOptionalNodes() const
Returns the number of optional nodes of this device.
type_index EntityTypeId
Definition: N_DEV_fwd.h:153
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...
virtual Device * factory(const FactoryBlock &factory_block) const =0
Overriding function creates an instance this device.
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.
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.
virtual InstanceTypeId instanceType() const =0
Returns the instance type identifier.
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:154
const SolverState & solverState_
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.
FactoryBlock(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.
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
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.
virtual ModelTypeId modelType() const =0
Returns the model type identifier.
The DeviceTraits template describes the configuration of a device.
const std::string & getInstanceDefaultParameterName() const
Returns the instance default parameter name.
virtual ModelTypeId modelGroup() const =0
Returns the model group identifier.
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.