Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Pars.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-2011 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_Pars.C,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : David Baur
33 //
34 // Creation Date : 3/28/2013
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.12.2.4 $
40 //
41 // Revision Date : $Date: 2014/03/11 18:50:03 $
42 //
43 // Current Owner : $Author: dgbaur $
44 //-------------------------------------------------------------------------
45 
46 #include <ostream>
47 #include <string>
48 
49 #include <N_DEV_Pars.h>
50 
51 #include <N_DEV_DeviceOptions.h>
52 #include <N_ERH_Message.h>
53 #include <N_UTL_Demangle.h>
54 
55 namespace Xyce {
56 namespace Device {
57 
58 //-----------------------------------------------------------------------------
59 // Function : setDefaultParameters
60 // Purpose :
61 // Special Notes :
62 // Scope : public
63 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
64 // Creation Date : Mon Mar 10 11:14:01 2014
65 //-----------------------------------------------------------------------------
66 ///
67 /// Iterates over parameters of parameter_base object, setting parameter_base members variables to the default value
68 /// provided when the addPar() function created the parameter descrption
69 ///
70 /// @param parameter_base DeviceEntity or CompositeParam
71 /// @param begin Begin iterator of parameter descriptions
72 /// @param end End iterator of parameters descriptions
73 /// @param device_options Device options
74 ///
75 void setDefaultParameters(ParameterBase &parameter_base, ParameterMap::const_iterator begin, ParameterMap::const_iterator end, const DeviceOptions &device_options)
76 {
77 // First, allocate and zero out original and given vals
78  for (ParameterMap::const_iterator it = begin ; it != end ; ++it)
79  {
80  Descriptor &param = *(*it).second;
81  Xyce::Device::setValueGiven(parameter_base, param.getSerialNumber(), false);
82  if (param.hasGivenMember())
83  param.setGiven(parameter_base, false);
84 
85  if (param.isType<double>())
86  {
87  if (param.getExpressionAccess() & MIN_RES)
88  {
89  setDefaultValue<double>(param, device_options.minRes);
90  }
91  else if (param.getExpressionAccess() & MIN_CAP)
92  {
93  setDefaultValue<double>(param, device_options.minCap);
94  }
95  param.value<double>(parameter_base) = getDefaultValue<double>(param);
96  }
97  else if (param.isType<bool>())
98  param.value<bool>(parameter_base) = getDefaultValue<bool>(param);
99  else if (param.isType<int>())
100  param.value<int>(parameter_base) = getDefaultValue<int>(param);
101  else if (param.isType<long>())
102  param.value<long>(parameter_base) = getDefaultValue<long>(param);
103  else if (param.isType<std::string>())
104  param.value<std::string>(parameter_base) = getDefaultValue<std::string>(param);
105  else if (param.isType<std::vector<int> >())
106  (param.value<std::vector<int> >(parameter_base)).clear();
107  else if (param.isType<std::vector<double> >())
108  (param.value<std::vector<double> >(parameter_base)).clear();
109  else if (param.isType<std::vector<std::string> >())
110  (param.value<std::vector<std::string> >(parameter_base)).clear();
111  }
112 }
113 
114 //-----------------------------------------------------------------------------
115 // Function : nonexistentParameter
116 // Purpose :
117 // Special Notes :
118 // Scope : public
119 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
120 // Creation Date : Mon Mar 10 11:28:31 2014
121 //-----------------------------------------------------------------------------
122 ///
123 /// Report casting error when attempting to cast from from_type to to_type
124 ///
125 /// @param name parameter name
126 /// @param entity_type entity
127 ///
128 void nonexistentParameter(const std::string &name, const std::type_info &entity_type)
129 {
130  Report::DevelFatal0() << "Parameter " << name << " does not exist in " << demangle(entity_type.name());
131 }
132 
133 //-----------------------------------------------------------------------------
134 // Function : Xyce::Device::typeMismatch
135 // Purpose :
136 // Special Notes :
137 // Scope : public
138 // Creator : David Baur
139 // Creation Date : 8/6/2014
140 //-----------------------------------------------------------------------------
141 ///
142 /// Report casting error when attempting to cast from from_type to to_type
143 ///
144 /// @param from_type Typeinfo casting from
145 /// @param to_type Typeinfo casting to
146 ///
147 void typeMismatch(const std::type_info &from_type, const std::type_info &to_type)
148 {
149  Report::DevelFatal0() << "Attempting to cast parameter of type " << demangle(from_type.name()) << " to type " << demangle(to_type.name());
150 }
151 
152 //-----------------------------------------------------------------------------
153 // Function : checkExprAccess
154 // Purpose :
155 // Special Notes :
156 // Scope : public
157 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
158 // Creation Date : Mon Mar 10 11:28:53 2014
159 //-----------------------------------------------------------------------------
160 ///
161 /// Report error if both MIN_CAP and MIN_RES have been specified.
162 ///
163 /// @param name Parameter name
164 /// @param expr_access Parameter expr access to verify
165 /// @param parameter_data_class Typeinfo to display name of class on error
166 ///
167 void checkExprAccess(const std::string &name, ParameterType::ExprAccess &expr_access, const std::type_info &parameter_data_class)
168 {
169  if ((expr_access & ParameterType::MIN_CAP) && (expr_access & ParameterType::MIN_RES))
170  Report::DevelFatal0() << "Attempt to set MIN_CAP and MIN_RES on ParameterType::ExprAccess for parameter " << name << " in class " << parameter_data_class.name();
171 }
172 
173 
174 //-----------------------------------------------------------------------------
175 // Function : ParametricData<void>::addDescriptor
176 // Purpose :
177 // Special Notes :
178 // Scope : public
179 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
180 // Creation Date : Mon Mar 10 11:22:43 2014
181 //-----------------------------------------------------------------------------
182 ///
183 /// Adds an entry to descriptor map.
184 ///
185 /// The serial number of the parameter is set in the descriptor.
186 ///
187 /// @invariant descriptor serial number is unique for each descriptor
188 /// @invariant parameter descriptor has unique name
189 ///
190 /// @param name Name or parameter to declare
191 /// @param descriptor Type information of parameter
192 /// @param parameter_data_class Typeinfo to display name of class on error
193 ///
194 void ParametricData<void>::addDescriptor(const std::string &name, Descriptor *descriptor, const std::type_info &parameter_data_class)
195 {
196  descriptor->setSerialNumber(map_.size());
197 
198  std::pair<ParameterMap::iterator, bool> result = map_.insert(ParameterMap::value_type(name, descriptor));
199 
200  if (!result.second)
201  Report::DevelFatal0() << "Parameter " << name << " already added to class " << demangle(parameter_data_class.name());
202 }
203 
204 } // namespace Device
205 } // namespace Xyce