46 #include <Xyce_config.h>
60 #include <N_UTL_BreakPoint.h>
61 #include <N_UTL_Expression.h>
76 const char *
const entity_type,
77 const std::string & device_name,
81 const std::string & netlist_path,
83 : entityType_(entity_type),
85 parametricData_(parametric_data),
86 solState_(solver_state),
87 devOptions_(device_options),
89 netlistLocation_(netlist_path, netlist_line)
104 for ( ; d != end; ++d)
127 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Unrecognized parameter " << paramName;
134 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Original value not available for parameter " << paramName;
138 if (!param.
isType<
double>())
140 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Can scale only double parameters, parameter " << paramName <<
" is not double";
147 if (param.hasGivenMember())
148 param.setGiven(*
this,
true);
172 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Unrecognized parameter " << paramName;
179 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Original value not available for parameter " << paramName;
183 if (!param.
isType<
double>())
185 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Can scale only double parameters, parameter " << paramName <<
" is not double";
213 DevelFatal(*this).in(
"DeviceEntity::scaleDefaultParam") <<
"Device " <<
getName() <<
" does not have a default parameter";
250 if (param.
isType<
double>())
251 param.
value<
double>(*this) = val;
252 else if (param.
isType<
int>())
253 param.
value<
int>(*this) = static_cast <
int> (val);
254 else if (param.
isType<
long>())
255 param.
value<
long>(*
this) = static_cast <
long> (val);
256 else if (param.
isType<
bool>())
257 param.
value<
bool>(*
this) = (val != 0);
259 DevelFatal0(*
this) <<
"Illegal type for parameter " << paramName;
293 if (param.
isType<
double>())
294 val = param.
value<
double>(*this);
295 else if (param.
isType<
int>())
296 val = static_cast <
double> (param.
value<
int>(*this));
297 else if (param.
isType<
long>())
298 val = static_cast <double> (param.
value<
long>(*
this));
299 else if (param.
isType<
bool>())
301 if (param.
value<
bool>(*
this))
308 DevelFatal(*this).in(
"DeviceEntity::getParam") <<
"Illegal type for parameter " << paramName;
334 DevelFatal(*this).in(
"DeviceEntity::setDefaultParam") <<
getName() <<
" does not have a default parameter";
384 dependentParam.
expr->evaluateFunction (rval);
401 std::vector<double> *res,
414 dependentParam.
expr->evaluateFunction (rval);
433 std::vector<std::string> instances, leads, names, variables;
435 dependentParam.
name = par.tag();
438 dependentParam.
expr =
new Util::Expression (
"(" + par.stringValue() +
")+CONSTCtoK");
439 dependentParam.
expr->make_constant (std::string(
"CONSTCTOK"),
CONSTCtoK);
443 dependentParam.
expr =
new Util::Expression (par.getValue<Util::Expression>());
451 dependentParam.
expr->get_names(XEXP_NODE, names);
452 dependentParam.
expr->get_names(XEXP_LEAD, leads);
453 dependentParam.
expr->get_names(XEXP_INSTANCE, instances);
454 dependentParam.
expr->get_names(XEXP_VARIABLE, variables);
457 std::vector<std::string>::iterator iterS;
461 if (names.size() > 0 || instances.size() > 0)
463 UserError0(*
this) <<
"Parameter " << par.tag() <<
" is not allowed to depend on voltage/current values";
468 if (dependentParam.
expr->get_num(XEXP_SPECIAL) > 0)
470 UserError0(*
this) <<
"Parameter " << par.tag() <<
" is not allowed to depend on time";
476 if (leads.size() > 0)
480 for (std::vector<std::string>::const_iterator n_i=leads.begin(); n_i != leads.end(); ++n_i)
482 index = n_i->find_last_of(
":");
483 if (index == std::string::npos )
486 type = (*n_i)[index+1];
488 if (type !=
'B' && type !=
'E' && type !=
'H')
490 UserError(*
this) <<
"Illegal use of lead current specification in expression '" << dependentParam.
expr->get_expression()
491 <<
"' in parameter " << par.tag();
494 names.insert( names.end(), leads.begin(), leads.end() );
497 names.insert( names.end(), instances.begin(), instances.end() );
500 dependentParam.
n_vars = names.size();
501 dependentParam.
vals.resize(dependentParam.
n_vars);
502 int expVarLen = dependentParam.
lo_var+dependentParam.
n_vars;
507 if (!variables.empty())
508 names.insert( names.end(), variables.begin(), variables.end() );
510 if ( !names.empty() )
514 dependentParam.
expr->order_names( names );
516 for (
int i=0 ; i<dependentParam.
n_vars ; ++i)
519 if (dependentParam.
n_vars > 0)
521 std::vector<double> zeros;
522 zeros.resize(dependentParam.
n_vars);
523 for (
int i=0 ; i<dependentParam.
n_vars ; ++i)
525 dependentParam.
expr->set_vars(zeros);
529 if (!variables.empty())
531 for (iterS=variables.begin() ; iterS!=variables.end() ; ++iterS)
535 UserError0(*
this) <<
"Global parameter " << *iterS <<
" not found";
559 bool changed =
false;
561 for ( ; dpIter != end ; ++dpIter)
566 if (dpIter->n_vars > 0)
568 hi = dpIter->lo_var+dpIter->n_vars;
569 for (i=dpIter->lo_var ; i<hi ; ++i)
574 if (dpIter->expr->set_vars(
eVarVals))
577 dpIter->expr->evaluateFunction (rval);
578 if (dpIter->vectorIndex==-1)
579 *(dpIter->resultU.result) = rval;
581 (*(dpIter->resultU.resVec))[dpIter->vectorIndex] = rval;
601 bool changed =
false;
603 for ( ; dpIter != end ; ++dpIter)
605 if (!dpIter->global_params.empty())
607 std::vector<std::string>::iterator gp=dpIter->global_params.begin();
608 std::vector<std::string>::iterator gend=dpIter->global_params.end();
609 for ( ; gp != gend; ++gp)
611 if (global_map.find(*gp) == global_map.end())
613 DevelFatal(*this).in(
"DeviceEntity::updateGlobalParameters") <<
"Failed to find global parameter " << *gp;
615 if (dpIter->expr->set_var(*gp, global_map[*gp]))
635 bool changed =
false;
639 for ( ; dpIter != end; ++dpIter)
643 dpIter->expr->evaluateFunction (rval);
644 if (dpIter->vectorIndex == -1)
645 *(dpIter->resultU.result) = rval;
647 (*(dpIter->resultU.resVec))[dpIter->vectorIndex] = rval;
665 bool changed =
false;
669 for ( ; dpIter != end; ++dpIter)
671 if (dpIter->expr->set_sim_time(
getSolverState().currTime ) || dpIter->expr->set_temp(tempIn))
673 dpIter->expr->evaluateFunction (rval);
674 if (dpIter->vectorIndex == -1)
675 *(dpIter->resultU.result) = rval;
677 (*(dpIter->resultU.resVec))[dpIter->vectorIndex] = rval;
698 for ( ; dpIter != end; ++dpIter)
700 bTime = dpIter->expr->get_break_time();
702 breakPointTimes.push_back(bTime);
718 ParameterMap::const_iterator it =
getParameterMap().find(parameter_name);
720 DevelFatal0(*this).in(
"DeviceEntity::given") <<
"Unrecognized parameter " << parameter_name;
736 std::vector<std::string> composite_name_list;
737 std::map<std::string, std::vector<CompositeParam *>, LessNoCase> composite_parameter_map;
739 if (DEBUG_DEVICE && device_options.
debugLevel > 0)
741 Xyce::dout() << std::endl <<
"In DeviceEntity::setParams, for " << entity.
getEntityType()
742 <<
": " << entity.
getName() <<
" parameters are:" << std::endl;
743 for (std::vector<Param>::const_iterator it = begin; it != end; ++it)
745 const Param ¶m = *it;
746 Xyce::dout() <<
"Param = " << param.tag() <<
", Type = ";
747 int tmpType = param.getType();
751 Xyce::dout() <<
"STR";
754 Xyce::dout() <<
"DBLE";
757 Xyce::dout() <<
"INT";
760 Xyce::dout() <<
"LNG";
763 Xyce::dout() <<
"EXPR";
766 Xyce::dout() <<
"BOOL";
769 Xyce::dout() <<
"STR_VEC";
772 Xyce::dout() <<
"INT_VEC";
775 Xyce::dout() <<
"DBLE_VEC";
777 case Util::DBLE_VEC_IND:
778 Xyce::dout() <<
"DBLE_VEC_IND";
780 case Util::COMPOSITE:
781 Xyce::dout() <<
"COMPOSITE";
784 Xyce::dout() <<
"Unknown";
786 Xyce::dout() <<
", Value = " << param.stringValue();
790 Xyce::dout() <<
" given=TRUE";
794 Xyce::dout() <<
" given=FALSE";
799 Xyce::dout() <<
" default=TRUE" << std::endl;
803 Xyce::dout() <<
" default=FALSE" << std::endl;
806 Xyce::dout() << std::endl;
809 for (std::vector<Param>::const_iterator param_it = begin; param_it != end; ++param_it)
811 Param ¶m =
const_cast<Param &
>(*param_it);
813 const std::string &tag = param.tag();
816 ParameterMap::const_iterator entity_parameter_it = entity.
getParameterMap().find(tag);
819 const Descriptor &descriptor = *(*entity_parameter_it).second;
826 else if (descriptor.
getGiven(entity))
835 if ( param.getType() == Util::EXPR )
837 if (descriptor.
isType<
double>())
842 else if (descriptor.
isType<std::vector<double> >())
844 int ind = (descriptor.
value<std::vector<double> >(entity)).size();
846 (descriptor.
value<std::vector<double> >(entity)).push_back(val);
850 DevelFatal(entity).in(
"DeviceEntity::setParams") <<
"Non double param " << tag <<
" cannot be set to expression";
855 if (descriptor.
isType<
double>())
857 if (!param.isNumeric())
859 UserFatal(entity) <<
"Cannot convert parameter " << tag <<
" to a numeric value from " << param.stringValue();
862 descriptor.
value<
double>(entity) = param.getImmutableValue<
double>();
872 else if (descriptor.
isType<std::string>())
874 descriptor.
value<std::string>(entity) = param.stringValue();
876 else if (descriptor.
isType<
int>())
878 if (!param.isInteger())
880 UserFatal(entity) <<
"Cannot convert parameter " << tag <<
" to an integer value from " << param.stringValue();
882 descriptor.
value<
int>(entity) = param.getImmutableValue<
int>();
888 else if (descriptor.
isType<
long>())
890 if (!param.isInteger())
892 UserFatal(entity) <<
"Cannot convert parameter " << tag <<
" to an integer value from " << param.stringValue();
894 descriptor.
value<
long>(entity) = param.getImmutableValue<
long>();
900 else if (descriptor.
isType<
bool>())
904 UserFatal(entity) <<
"Cannot convert parameter " << tag <<
" to a logical value from " << param.stringValue();
906 descriptor.
value<
bool>(entity) = param.getImmutableValue<
bool>();
909 if (descriptor.
value<
bool>(entity))
919 else if (descriptor.
isType<std::vector<int> >())
921 if (param.getType() == Util::INT_VEC)
923 (descriptor.
value<std::vector<int> >(entity)) = param.getValue<std::vector<int> >();
925 else if (param.getType() == Util::INT)
927 (descriptor.
value<std::vector<int> >(entity)).push_back(param.getImmutableValue<
int>());
930 else if (descriptor.
isType<std::vector<double> >())
932 if (param.getType() == Util::DBLE_VEC)
934 (descriptor.
value<std::vector<double> >(entity)) = param.getValue<std::vector<double> >();
936 else if (param.getType() == Util::DBLE)
938 (descriptor.
value<std::vector<double> >(entity)).push_back(param.getImmutableValue<
double>());
941 else if (descriptor.
isType<std::vector<std::string> >())
943 if (param.getType() == Util::STR_VEC)
945 (descriptor.
value<std::vector<std::string> >(entity)) = param.getValue<std::vector<std::string> >();
947 else if (param.getType() == Util::STR)
949 (descriptor.
value<std::vector<std::string> >(entity)).push_back(param.stringValue());
954 composite_parameter_map[tag].clear();
955 composite_name_list.push_back(tag);
966 if (DEBUG_DEVICE && device_options.
debugLevel > 0)
968 Xyce::dout() <<
"pushing back composite " << tag << std::endl;
973 DevelFatal(entity).in(
"DeviceEntity::setParams") <<
"Unknown type";
980 else if (param.stringValue() ==
"VECTOR")
987 bool vc_stat =
false;
989 std::string::size_type dot = tag.find_first_of(
'.');
990 if (dot != std::string::npos)
992 for (std::vector<std::string>::const_iterator it = composite_name_list.begin(); it != composite_name_list.end(); ++it)
994 const std::string &composite_name = *it;
996 if (tag.find(composite_name) == 0)
998 std::string param_name(tag.begin() + dot + 1, tag.end());
1004 std::istringstream is(std::string(tag.begin() + composite_name.size(), tag.begin() + dot));
1008 if (param_name ==
"NAME")
1010 if (n != composite_parameter_map[composite_name].size())
1012 DevelFatal(entity).in(
"DeviceEntity::setParams") <<
"Error filling 'NAME' vector param " << composite_name;
1015 std::string name = param.stringValue();
1017 composite_parameter_map[composite_name].push_back(composite);
1022 if (n >= composite_parameter_map[composite_name].size())
1024 DevelFatal(entity).in(
"DeviceEntity::setParams") <<
"Internal error in vector-composite, 'NAME' must come first " << composite_name;
1033 UserError(entity) <<
"Undefined parameter " << tag <<
", this parameter is in metadata, but not recognized in constructor";
1038 if (!composite_name_list.empty())
1040 for (std::vector<std::string>::const_iterator name_it = composite_name_list.begin(); name_it != composite_name_list.end(); ++name_it)
1042 const std::string &vcs = *name_it;
1044 for (std::vector<CompositeParam *>::iterator it = composite_parameter_map[vcs].begin(); it != composite_parameter_map[vcs].end(); ++it)
1046 (*it)->processParams();
1065 ParameterMap::const_iterator p_i = composite_param.
getParameterMap().find(pName);
1071 if (ndParam.
given())
1073 else if (p.
getGiven(composite_param))
1081 p.
value<
double>(composite_param) = ndParam.getImmutableValue<
double>();
1087 else if (p.
isType<std::string>())
1089 p.
value<std::string>(composite_param) = ndParam.stringValue();
1091 else if (p.
isType<
int>())
1093 p.
value<
int>(composite_param) = ndParam.getImmutableValue<
int>();
1097 else if (p.
isType<
long>())
1099 p.
value<
long>(composite_param) = ndParam.getImmutableValue<
long>();
1103 else if (p.
isType<
bool>())
1105 p.
value<
bool>(composite_param) = (ndParam.getImmutableValue<
double>() != 0.0);
1108 if (p.
value<
bool>(composite_param))
1114 else if (p.
isType<std::vector<double> >())
1116 (p.
value<std::vector<double> >(composite_param)).push_back(ndParam.getImmutableValue<
double>());
1118 else if (p.
isType<std::vector<std::string> >())
1120 p.
value<std::vector<std::string> >(composite_param).push_back(ndParam.stringValue());
1124 Report::DevelFatal().in(
"CompositeParam::setParams") <<
"Unknown parameter type for " << pName;
1130 Report::DevelFatal().in(
"CompositeParam::setParams") <<
"Undefined parameter " << pName << std::endl
1131 <<
"This parameter is in metadata, but not recognized in constructor";
1138 for (ParameterMap::const_iterator it = parameter_map.begin(); it != parameter_map.end(); ++it)
1142 if (param.
isType<
double>())
1148 val = getDefaultValue<double>(param) -
CONSTCtoK;
1150 val = getDefaultValue<double>(param);
1151 param_list.push_back(
Param((*it).first, val));
1153 else if (param.
getVec() > 0)
1158 std::string vPar((*it).first.substr(0, (*it).first.size()-1));
1159 param_list.push_back(
Param(vPar,
"VECTOR"));
1164 double val = getDefaultValue<double>(param);
1165 param_list.push_back(
Param((*it).first, val));
1168 else if (param.
isType<
bool>())
1171 param_list.push_back(
Param((*it).first, getDefaultValue<bool>(param)));
1172 else if (param.
getVec() > 0)
1176 std::string vPar((*it).first.substr(0, (*it).first.size()-1));
1177 param_list.push_back(
Param(vPar,
"VECTOR"));
1182 bool val = getDefaultValue<bool>(param);
1183 param_list.push_back(
Param((*it).first, val));
1186 else if (param.
isType<
int>())
1189 param_list.push_back(
Param((*it).first, getDefaultValue<int>(param)));
1190 else if (param.
getVec() > 0)
1194 std::string vPar((*it).first.substr(0, (*it).first.size()-1));
1195 param_list.push_back(
Param(vPar,
"VECTOR"));
1197 int val = getDefaultValue<int>(param);
1198 param_list.push_back(
Param((*it).first, val));
1201 else if (param.
isType<std::string>())
1204 param_list.push_back(
Param((*it).first, getDefaultValue<std::string>(param)));
1205 else if (param.
getVec() > 0)
1209 std::string vPar((*it).first.substr(0, (*it).first.size()-1));
1210 param_list.push_back(
Param(vPar,
"VECTOR"));
1212 std::string val = getDefaultValue<std::string>(param);
1213 param_list.push_back(
Param((*it).first, val));
1216 else if (param.
isType<std::vector<std::string> >())
1218 Param vc((*it).first, std::vector<std::string>());
1219 param_list.push_back(vc);
1221 else if (param.
isType<std::vector<double> >())
1223 Param vc((*it).first, std::vector<double>());
1224 param_list.push_back(vc);
1228 Param vc2((*it).first,
"VECTOR-COMPOSITE");
1230 param_list.push_back(vc2);
1232 std::vector<Param> compositeParams;
1237 Report::DevelFatal().in(
"populateParams") <<
"Vector-composite map for device type entity empty.";
1245 for (ParameterMap::const_iterator it4 = e.find(
"NAME"); it4 != e.end();) {
1248 compositeParams.push_back(
Param((*it4).first, getDefaultValue<double>(p)));
1249 else if (p.
isType<
bool>())
1250 compositeParams.push_back(
Param((*it4).first, getDefaultValue<bool>(p)));
1251 else if (p.
isType<
int>())
1252 compositeParams.push_back(
Param((*it4).first, getDefaultValue<int>(p)));
1253 else if (p.
isType<std::string>())
1254 compositeParams.push_back(
Param((*it4).first, getDefaultValue<std::string>(p)));
1255 if ((*it4).first ==
"NAME")
1259 if (it4 != e.end() && (*it4).first ==
"NAME")
1263 composite_param_map[(*it).first] = compositeParams;
1270 Xyce::dout() <<
"In final else clause of DeviceEntity::getParams().";
1271 if( param.
isType<std::vector<std::string> >() )
1272 Xyce::dout() <<
" type is STR_VEC ";
1273 if( param.
isType<std::vector<double> >() )
1274 Xyce::dout() <<
" type is DBLE_VEC ";
1275 Xyce::dout() << it->first <<
" this item is NOT being added to default parameter list." << std::endl;
1294 if (param.
isType<
double>())
1302 os << param.
value<
double>(entity);
1305 else if (param.
isType<
bool>())
1307 os << param.
value<
bool>(entity);
1309 else if (param.
isType<
int>())
1311 os << param.
value<
int>(entity);
1313 else if (param.
isType<
long>())
1315 os << param.
value<
long>(entity);
1317 else if (param.
isType<std::string>())
1319 os << param.
value<std::string>(entity);
1321 else if (param.
isType<std::vector<std::string> >())
1323 os <<
" (string vector) : ";
1324 os <<
"length = " << (param.
value<std::vector<std::string> >(entity)).size();
1325 if ((param.
value<std::vector<std::string> >(entity)).size() > 0)
1328 std::vector<std::string>::const_iterator iterStringVec = (param.
value<std::vector<std::string> >(entity)).begin();
1329 for ( ; iterStringVec != (param.
value<std::vector<std::string> >(entity)).end() ; ++iterStringVec)
1331 os <<
" " << *iterStringVec;
1335 else if (param.
isType<std::vector<int> >())
1337 os <<
" (int vector) : ";
1338 os <<
"length = " << (param.
value<std::vector<int> >(entity)).size();
1339 if ((param.
value<std::vector<int> >(entity)).size() > 0)
1342 std::vector<int>::const_iterator v_i = (param.
value<std::vector<int> >(entity)).begin();
1343 for ( ; v_i != (param.
value<std::vector<int> >(entity)).end() ; ++v_i)
1349 else if (param.
isType<std::vector<double> >())
1351 os <<
" (double vector) : ";
1352 os <<
"length = " << (param.
value<std::vector<double> >(entity)).size();
1353 if ((param.
value<std::vector<double> >(entity)).size() > 0)
1356 std::vector<double>::const_iterator iterDoubleVec = (param.
value<std::vector<double> >(entity)).begin();
1357 for ( ; iterDoubleVec != (param.
value<std::vector<double> >(entity)).end() ; ++iterDoubleVec)
1359 os <<
" " << *iterDoubleVec;
1368 std::map<std::string, CompositeParam *>::const_iterator c_i = (param.
value<
CompositeMap>(entity)).begin();
1381 os << std::endl <<
" " <<(*it_parameter).first <<
" ";
1382 const Descriptor &p = *(*it_parameter).second;
1384 os <<
"(double) : " << p.
value<
double>(composite);
1385 else if (p.
isType<
bool>())
1386 os <<
"(bool) : " << p.
value<
bool>(composite);
1387 else if (p.
isType<
int>())
1388 os <<
"(int) : " << p.
value<
int>(composite);
1389 else if (p.
isType<
long>())
1390 os <<
"(long) : " << p.
value<
long>(composite);
1391 else if (p.
isType<std::string>())
1392 os <<
"(string) : " << p.
value<std::string>(composite);
1393 else if (p.
isType<std::vector<std::string> >())
1395 const std::vector<std::string> &string_vector = p.
value<std::vector<std::string> >(composite);
1397 for (std::vector<std::string>::const_iterator it = string_vector.begin(); it != string_vector.end(); ++it)
1400 else if (p.
isType<std::vector<double> >())
1402 const std::vector<double> &string_vector = p.
value<std::vector<double> >(composite);
1404 for (std::vector<double>::const_iterator it = string_vector.begin(); it != string_vector.end(); ++it)
1408 if ((*it_parameter).first ==
"NAME")
1413 if (it_parameter != composite.
getParameterMap().end() && (*it_parameter).first ==
"NAME")