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