Xyce  6.1
N_DEV_Dump.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2015 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-------------------------------------------------------------------------
26 // Filename : $RCSfile: N_DEV_Dump.C,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : David Baur
33 //
34 // Creation Date : 04/18/2013
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.4 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:22 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 #include <algorithm>
49 #include <iomanip>
50 #include <ostream>
51 #include <stdexcept>
52 
53 #include <N_DEV_Dump.h>
54 #include <N_DEV_Configuration.h>
55 #include <N_UTL_IndentStreamBuf.h>
56 #include <N_UTL_Demangle.h>
57 
58 namespace Xyce {
59 namespace Device {
60 
61 typedef std::map<std::string, Descriptor *, LessNoCase> OrderedParameterMap;
62 
64 {
65  bool operator()(const std::type_info *t0, const std::type_info *t1) const
66  {
67  return t0->before(*t1);
68  }
69 };
70 
71 std::map<const std::type_info *, std::string, type_compare_less> s_typeInfoNameMap;
72 
73 std::ostream &printTypeName(std::ostream &os, const std::type_info &type)
74 {
75  if (s_typeInfoNameMap.empty()) {
76  s_typeInfoNameMap[&typeid(bool)] = "boolean";
77  s_typeInfoNameMap[&typeid(double)] = "double";
78  s_typeInfoNameMap[&typeid(int)] = "int";
79  s_typeInfoNameMap[&typeid(std::string)] = "string";
80  s_typeInfoNameMap[&typeid(std::vector<double>)] = "double vector";
81  s_typeInfoNameMap[&typeid(std::vector<int>)] = "int vector";
82  s_typeInfoNameMap[&typeid(std::vector<std::string>)] = "string vector";
83  }
84 
85  if (s_typeInfoNameMap[&type].empty())
86  os << "composite"; // demangle(type.name());
87  else
88  os << s_typeInfoNameMap[&type];
89 
90  return os;
91 }
92 
93 std::ostream &outputParameterMap(std::ostream &os, const OrderedParameterMap &parameter_map);
94 
95 std::ostream &outputDescriptor(std::ostream &os, const Descriptor &descriptor)
96 {
97  if (&descriptor.getEntry()) {
98  printTypeName(os, descriptor.getEntry().type());
99  }
100 
101  if (!descriptor.getCompositeParametricData<void>()) {
102  os << ", default ";
103  descriptor.getEntry().print(os);
104  if (descriptor.hasOriginalValueStored())
105  os << ", original value managed, scaling enabled";
106  }
107  else {
108  const ParametricData<void> &composite_parametric_data = *descriptor.getCompositeParametricData<void>();
109  const OrderedParameterMap composite_parametric_map(composite_parametric_data.getMap().begin(), composite_parametric_data.getMap().end());
110  os << Util::push << std::endl;
111  outputParameterMap(os, composite_parametric_map);
112  os << Util::pop;
113  }
114 
115  os << std::endl;
116 
117  return os;
118 }
119 
120 std::ostream &
122  std::ostream & os,
123  const OrderedParameterMap & parameter_map)
124 {
125  for (OrderedParameterMap::const_iterator it = parameter_map.begin(); it != parameter_map.end(); ++it) {
126  os << (*it).first << ", ";
127 
128  outputDescriptor(os, *(*it).second);
129  }
130 
131  return os;
132 }
133 
134 std::ostream &operator<<(std::ostream &os, const Configuration &configuration)
135 {
136  ParametricData<void> &instance_parameters = configuration.getInstanceParameters();
137  ParametricData<void> &model_parameters = configuration.getModelParameters();
138 
139  os << "Configuration" << Xyce::Util::push << std::endl
140  << "Name: " << configuration.getName() << std::endl
141  << "Device Type: " << configuration.getDeviceTypeName() << std::endl
142  << "Nodes: " << configuration.getNumNodes() << std::endl
143  << "Optional Nodes: " << configuration.getNumOptionalNodes() << std::endl
144  << "Fill Nodes: " << configuration.getNumFillNodes() << std::endl
145  << "Model Required: " << (configuration.getModelRequired() ? "yes" : "no") << std::endl
146  << "Linear Device: " << (configuration.getLinearDevice() ? "yes" : "no") << std::endl
147  << "PDE Device: " << (configuration.getPDEDevice() ? "yes" : "no") << std::endl
148  << "Primary Parameter: " << (configuration.getPrimaryParameter().empty() ? "<none>" : configuration.getPrimaryParameter()) << std::endl
149  << "Instance Default Parameter: " << (configuration.getInstanceDefaultParameterName().empty() ? "<none>" : configuration.getInstanceDefaultParameterName()) << std::endl;
150 
151  os << "Model Types: ";
152  for (std::vector<std::string>::const_iterator it = configuration.getModelTypeNames().begin(); it != configuration.getModelTypeNames().end(); ++it) {
153  if (it != configuration.getModelTypeNames().begin())
154  os << ", ";
155  os << *it;
156  }
157  os << Xyce::Util::pop << std::endl
158  << "Model Parameters" << Xyce::Util::push << std::endl;
159 
160  const OrderedParameterMap model_parameter_map(model_parameters.getMap().begin(), model_parameters.getMap().end());
161  outputParameterMap(os, model_parameter_map);
162  os << Xyce::Util::pop << std::endl
163  << "Instance Parameters" << Xyce::Util::push << std::endl;
164  const OrderedParameterMap instance_parameter_map(instance_parameters.getMap().begin(), instance_parameters.getMap().end());
165  outputParameterMap(os, instance_parameter_map);
166 
167  os << Xyce::Util::pop << std::endl
168  << Xyce::Util::pop << std::endl;
169 
170  return os;
171 }
172 
173 } // namespace Device
174 } // namespace Xyce
const Entry< void > & getEntry() const
Gets the entry object of the parameter.
Definition: N_DEV_Pars.h:814
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.
bool operator()(const std::type_info *t0, const std::type_info *t1) const
Definition: N_DEV_Dump.C:65
bool getPDEDevice() const
Returns true of the model is a PDE device.
std::ostream & outputParameterMap(std::ostream &os, const OrderedParameterMap &parameter_map)
Definition: N_DEV_Dump.C:121
Pure virtual class to augment a linear system.
std::ostream & outputDescriptor(std::ostream &os, const Descriptor &descriptor)
Definition: N_DEV_Dump.C:95
const std::string & getPrimaryParameter() const
Returns the default primary parameter of this device or the empty string if there is no primary param...
int getNumOptionalNodes() const
Returns the number of optional nodes of this device.
const std::string & getDeviceTypeName() const
Returns the device type name.
std::ostream & print(std::ostream &os) const
Prints the value of the entry to the output stream.
Definition: N_DEV_Pars.h:289
virtual const std::type_info & type() const =0
Returns the type_info of the data type being stored in the entry.
std::ostream & printTypeName(std::ostream &os, const std::type_info &type)
Definition: N_DEV_Dump.C:73
ParametricData< void > & getInstanceParameters() const
Returns the instance parameter descriptions.
Class ParametricData manages the configuration information and the parameter binding map...
Definition: N_DEV_Pars.h:1303
const ParametricData< U > * getCompositeParametricData() const
Return the composite parameter.
Definition: N_DEV_Pars.h:774
Class Descriptor describes the parameters stored in the ParametricData parameter map.
Definition: N_DEV_Pars.h:546
Class Configuration contains device configuration data.
std::map< std::string, Descriptor *, LessNoCase > OrderedParameterMap
Definition: N_DEV_Dump.C:61
bool hasOriginalValueStored() const
Returns whether an original value has been stored.
Definition: N_DEV_Pars.h:632
int getNumNodes() const
Returns the number of nodes of this device.
std::map< const std::type_info *, std::string, type_compare_less > s_typeInfoNameMap
Definition: N_DEV_Dump.C:71
const std::string & getName() const
Returns the device name.
const std::string & getInstanceDefaultParameterName() const
Returns the instance default parameter name.
ParameterMap & getMap()
Gets the parameter binding map map.
Definition: N_DEV_Pars.h:1341
const std::vector< std::string > & getModelTypeNames() const
Returns a vector of strings that name all the model types defined of this model.
std::ostream & operator<<(std::ostream &os, const Configuration &configuration)
Definition: N_DEV_Dump.C:134
bool getLinearDevice() const
Returns true of the model is a linear device.