46 #include <Xyce_config.h>
60 #include <N_LAS_Vector.h>
61 #include <N_UTL_BreakPoint.h>
62 #include <N_UTL_Expression.h>
80 const std::string & netlist_path,
82 : parametricData_(parametric_data),
83 solState_(solver_state),
84 globals_(solver_state.getGlobals()),
85 devOptions_(device_options),
87 netlistLocation_(netlist_path, netlist_line)
123 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Unrecognized parameter " << paramName;
130 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Original value not available for parameter " << paramName;
134 if (!param.
isType<
double>())
136 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Can scale only double parameters, parameter " << paramName <<
" is not double";
143 if (param.hasGivenMember())
144 param.setGiven(*
this,
true);
168 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Unrecognized parameter " << paramName;
175 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Original value not available for parameter " << paramName;
179 if (!param.
isType<
double>())
181 DevelFatal(*this).in(
"DeviceEntity::scaleParam") <<
"Can scale only double parameters, parameter " << paramName <<
" is not double";
209 DevelFatal(*this).in(
"DeviceEntity::scaleDefaultParam") <<
"Device does not have a default parameter";
229 DevelFatal(*this).in(
"DeviceEntity::analyticSensitivityAvailable") <<
"Unrecognized parameter " << paramName;
246 std::vector<double> & dfdpVec,
247 std::vector<double> & dqdpVec,
248 std::vector<double> & dbdpVec,
249 std::vector<int> & FindicesVec,
250 std::vector<int> & QindicesVec,
251 std::vector<int> & BindicesVec)
256 DevelFatal(*this).in(
"DeviceEntity::analyticSensitivityAvailable") <<
"Unrecognized parameter " << paramName;
263 FindicesVec, QindicesVec, BindicesVec);
296 if (param.
isType<
double>())
297 param.
value<
double>(*this) = val;
298 else if (param.
isType<
int>())
299 param.
value<
int>(*this) = static_cast <
int> (val);
300 else if (param.
isType<
long>())
301 param.
value<
long>(*
this) = static_cast <
long> (val);
302 else if (param.
isType<
bool>())
303 param.
value<
bool>(*
this) = (val != 0);
305 DevelFatal0(*
this) <<
"Illegal type for parameter " << paramName;
331 const std::string & name,
332 double & result)
const
342 if (param.
isType<
double>())
343 val = param.
value<
double>(*this);
344 else if (param.
isType<
int>())
345 val = static_cast <
double> (param.
value<
int>(*this));
346 else if (param.
isType<
long>())
347 val = static_cast <double> (param.
value<
long>(*
this));
348 else if (param.
isType<
bool>())
350 if (param.
value<
bool>(*
this))
357 DevelFatal(*this).in(
"DeviceEntity::getParam") <<
"Illegal type for parameter " << name;
383 DevelFatal(*this).in(
"DeviceEntity::setDefaultParam") <<
"Device does not have a default parameter";
433 dependentParam.
expr->evaluateFunction (rval);
450 std::vector<double> *res,
463 dependentParam.
expr->evaluateFunction (rval);
482 std::vector<std::string> instances, leads, names, variables;
484 dependentParam.
name = par.tag();
487 dependentParam.
expr =
new Util::Expression (
"(" + par.stringValue() +
")+CONSTCtoK");
488 dependentParam.
expr->make_constant (std::string(
"CONSTCTOK"),
CONSTCtoK);
492 dependentParam.
expr =
new Util::Expression (par.getValue<Util::Expression>());
500 dependentParam.
expr->get_names(XEXP_NODE, names);
501 dependentParam.
expr->get_names(XEXP_LEAD, leads);
502 dependentParam.
expr->get_names(XEXP_INSTANCE, instances);
503 dependentParam.
expr->get_names(XEXP_VARIABLE, variables);
506 std::vector<std::string>::iterator iterS;
510 if (names.size() > 0 || instances.size() > 0)
512 UserError0(*
this) <<
"Parameter " << par.tag() <<
" is not allowed to depend on voltage/current values";
517 if (dependentParam.
expr->get_num(XEXP_SPECIAL) > 0)
519 UserError0(*
this) <<
"Parameter " << par.tag() <<
" is not allowed to depend on time";
525 if (leads.size() > 0)
529 for (std::vector<std::string>::const_iterator n_i=leads.begin(); n_i != leads.end(); ++n_i)
531 index = n_i->find_last_of(
":");
532 if (index == std::string::npos )
535 type = (*n_i)[index+1];
537 if (type !=
'B' && type !=
'E' && type !=
'H')
539 UserError(*
this) <<
"Illegal use of lead current specification in expression '" << dependentParam.
expr->get_expression()
540 <<
"' in parameter " << par.tag();
543 names.insert( names.end(), leads.begin(), leads.end() );
546 names.insert( names.end(), instances.begin(), instances.end() );
549 dependentParam.
n_vars = names.size();
550 dependentParam.
vals.resize(dependentParam.
n_vars);
551 int expVarLen = dependentParam.
lo_var+dependentParam.
n_vars;
556 if (!variables.empty())
557 names.insert( names.end(), variables.begin(), variables.end() );
559 if ( !names.empty() )
563 dependentParam.
expr->order_names( names );
565 for (
int i=0 ; i<dependentParam.
n_vars ; ++i)
568 if (dependentParam.
n_vars > 0)
570 std::vector<double> zeros;
571 zeros.resize(dependentParam.
n_vars);
572 for (
int i=0 ; i<dependentParam.
n_vars ; ++i)
574 dependentParam.
expr->set_vars(zeros);
578 if (!variables.empty())
580 for (iterS=variables.begin() ; iterS!=variables.end() ; ++iterS)
585 UserError0(*
this) <<
"Global parameter " << *iterS <<
" not found";
588 dependentParam.
expr->set_var(*iterS, (*global_param_it).second);
608 bool changed =
false;
610 for ( ; dpIter != end ; ++dpIter)
615 if (dpIter->n_vars > 0)
617 int hi = dpIter->lo_var+dpIter->n_vars;
618 for (
int i = dpIter->lo_var; i < hi; ++i)
623 if (dpIter->expr->set_vars(
eVarVals))
626 dpIter->expr->evaluateFunction (rval);
627 if (dpIter->vectorIndex==-1)
628 *(dpIter->resultU.result) = rval;
630 (*(dpIter->resultU.resVec))[dpIter->vectorIndex] = rval;
650 bool changed =
false;
652 for ( ; dpIter != end ; ++dpIter)
654 if (!dpIter->global_params.empty())
656 std::vector<std::string>::iterator gp=dpIter->global_params.begin();
657 std::vector<std::string>::iterator gend=dpIter->global_params.end();
658 for ( ; gp != gend; ++gp)
660 if (global_map.find(*gp) == global_map.end())
662 DevelFatal(*this).in(
"DeviceEntity::updateGlobalParameters") <<
"Failed to find global parameter " << *gp;
664 if (dpIter->expr->set_var(*gp, global_map[*gp]))
684 bool changed =
false;
688 for ( ; dpIter != end; ++dpIter)
692 dpIter->expr->evaluateFunction (rval);
693 if (dpIter->vectorIndex == -1)
694 *(dpIter->resultU.result) = rval;
696 (*(dpIter->resultU.resVec))[dpIter->vectorIndex] = rval;
714 bool changed =
false;
718 for ( ; dpIter != end; ++dpIter)
720 if (dpIter->expr->set_sim_time(
getSolverState().currTime ) || dpIter->expr->set_temp(tempIn))
722 dpIter->expr->evaluateFunction (rval);
723 if (dpIter->vectorIndex == -1)
724 *(dpIter->resultU.result) = rval;
726 (*(dpIter->resultU.resVec))[dpIter->vectorIndex] = rval;
747 for ( ; dpIter != end; ++dpIter)
749 bTime = dpIter->expr->get_break_time();
751 breakPointTimes.push_back(bTime);
767 ParameterMap::const_iterator it =
getParameterMap().find(parameter_name);
769 DevelFatal0(*this).in(
"DeviceEntity::given") <<
"Unrecognized parameter " << parameter_name;
785 std::vector<std::string> composite_name_list;
786 std::map<std::string, std::vector<CompositeParam *>, LessNoCase> composite_parameter_map;
788 if (DEBUG_DEVICE && device_options.
debugLevel > 0)
790 Xyce::dout() << std::endl <<
"In DeviceEntity::setParams, for ";
792 Xyce::dout() <<
" parameters are:" << std::endl;
793 for (std::vector<Param>::const_iterator it = begin; it != end; ++it)
795 const Param ¶m = *it;
796 Xyce::dout() <<
"Param = " << param.tag() <<
", Type = ";
797 int tmpType = param.getType();
801 Xyce::dout() <<
"STR";
804 Xyce::dout() <<
"DBLE";
807 Xyce::dout() <<
"INT";
810 Xyce::dout() <<
"LNG";
813 Xyce::dout() <<
"EXPR";
816 Xyce::dout() <<
"BOOL";
819 Xyce::dout() <<
"STR_VEC";
822 Xyce::dout() <<
"INT_VEC";
825 Xyce::dout() <<
"DBLE_VEC";
827 case Util::DBLE_VEC_IND:
828 Xyce::dout() <<
"DBLE_VEC_IND";
830 case Util::COMPOSITE:
831 Xyce::dout() <<
"COMPOSITE";
834 Xyce::dout() <<
"Unknown";
836 Xyce::dout() <<
", Value = " << param.stringValue();
840 Xyce::dout() <<
" given=TRUE";
844 Xyce::dout() <<
" given=FALSE";
849 Xyce::dout() <<
" default=TRUE" << std::endl;
853 Xyce::dout() <<
" default=FALSE" << std::endl;
856 Xyce::dout() << std::endl;
859 for (std::vector<Param>::const_iterator param_it = begin; param_it != end; ++param_it)
861 Param ¶m =
const_cast<Param &
>(*param_it);
863 const std::string &tag = param.tag();
866 ParameterMap::const_iterator entity_parameter_it = entity.
getParameterMap().find(tag);
869 const Descriptor &descriptor = *(*entity_parameter_it).second;
876 else if (descriptor.
getGiven(entity))
885 if ( param.getType() == Util::EXPR )
887 if (descriptor.
isType<
double>())
892 else if (descriptor.
isType<std::vector<double> >())
894 int ind = (descriptor.
value<std::vector<double> >(entity)).size();
896 (descriptor.
value<std::vector<double> >(entity)).push_back(val);
900 DevelFatal(entity).in(
"DeviceEntity::setParams") <<
"Non double param " << tag <<
" cannot be set to expression";
905 if (descriptor.
isType<
double>())
907 if (!param.isNumeric())
909 UserError(entity) <<
"Cannot convert parameter " << tag <<
" to a numeric value from " << param.stringValue();
913 descriptor.
value<
double>(entity) = param.getImmutableValue<
double>();
923 else if (descriptor.
isType<std::string>())
925 descriptor.
value<std::string>(entity) = param.stringValue();
927 else if (descriptor.
isType<
int>())
929 if (!param.isInteger())
931 UserError(entity) <<
"Cannot convert parameter " << tag <<
" to an integer value from " << param.stringValue();
934 descriptor.
value<
int>(entity) = param.getImmutableValue<
int>();
940 else if (descriptor.
isType<
long>())
942 if (!param.isInteger())
944 UserError(entity) <<
"Cannot convert parameter " << tag <<
" to an integer value from " << param.stringValue();
947 descriptor.
value<
long>(entity) = param.getImmutableValue<
long>();
953 else if (descriptor.
isType<
bool>())
957 UserError(entity) <<
"Cannot convert parameter " << tag <<
" to a logical value from " << param.stringValue();
960 descriptor.
value<
bool>(entity) = param.getImmutableValue<
bool>();
963 if (descriptor.
value<
bool>(entity))
973 else if (descriptor.
isType<std::vector<int> >())
975 if (param.getType() == Util::INT_VEC)
977 (descriptor.
value<std::vector<int> >(entity)) = param.getValue<std::vector<int> >();
979 else if (param.getType() == Util::INT)
981 (descriptor.
value<std::vector<int> >(entity)).push_back(param.getImmutableValue<
int>());
984 else if (descriptor.
isType<std::vector<double> >())
986 if (param.getType() == Util::DBLE_VEC)
988 (descriptor.
value<std::vector<double> >(entity)) = param.getValue<std::vector<double> >();
990 else if (param.getType() == Util::DBLE)
992 (descriptor.
value<std::vector<double> >(entity)).push_back(param.getImmutableValue<
double>());
995 else if (descriptor.
isType<std::vector<std::string> >())
997 if (param.getType() == Util::STR_VEC)
999 (descriptor.
value<std::vector<std::string> >(entity)) = param.getValue<std::vector<std::string> >();
1001 else if (param.getType() == Util::STR)
1003 (descriptor.
value<std::vector<std::string> >(entity)).push_back(param.stringValue());
1008 composite_parameter_map[tag].clear();
1009 composite_name_list.push_back(tag);
1020 if (DEBUG_DEVICE && device_options.
debugLevel > 0)
1022 Xyce::dout() <<
"pushing back composite " << tag << std::endl;
1027 DevelFatal(entity).in(
"DeviceEntity::setParams") <<
"Unknown type";
1034 else if (param.stringValue() ==
"VECTOR")
1041 bool vc_stat =
false;
1043 std::string::size_type dot = tag.find_first_of(
'.');
1044 if (dot != std::string::npos)
1046 for (std::vector<std::string>::const_iterator it = composite_name_list.begin(); it != composite_name_list.end(); ++it)
1048 const std::string &composite_name = *it;
1050 if (tag.find(composite_name) == 0)
1052 std::string param_name(tag.begin() + dot + 1, tag.end());
1058 std::istringstream is(std::string(tag.begin() + composite_name.size(), tag.begin() + dot));
1062 if (param_name ==
"NAME")
1064 if (n != composite_parameter_map[composite_name].size())
1066 DevelFatal(entity).in(
"DeviceEntity::setParams") <<
"Error filling 'NAME' vector param " << composite_name;
1069 std::string name = param.stringValue();
1071 composite_parameter_map[composite_name].push_back(composite);
1076 if (n >= composite_parameter_map[composite_name].size())
1078 DevelFatal(entity).in(
"DeviceEntity::setParams") <<
"Internal error in vector-composite, 'NAME' must come first " << composite_name;
1087 DevelFatal(entity) <<
"Undefined parameter " << tag <<
", this parameter is in metadata, but not recognized in constructor";
1092 if (!composite_name_list.empty())
1094 for (std::vector<std::string>::const_iterator name_it = composite_name_list.begin(); name_it != composite_name_list.end(); ++name_it)
1096 const std::string &vcs = *name_it;
1098 for (std::vector<CompositeParam *>::iterator it = composite_parameter_map[vcs].begin(); it != composite_parameter_map[vcs].end(); ++it)
1100 (*it)->processParams();
1119 ParameterMap::const_iterator p_i = composite_param.
getParameterMap().find(pName);
1125 if (ndParam.
given())
1127 else if (p.
getGiven(composite_param))
1135 p.
value<
double>(composite_param) = ndParam.getImmutableValue<
double>();
1141 else if (p.
isType<std::string>())
1143 p.
value<std::string>(composite_param) = ndParam.stringValue();
1145 else if (p.
isType<
int>())
1147 p.
value<
int>(composite_param) = ndParam.getImmutableValue<
int>();
1151 else if (p.
isType<
long>())
1153 p.
value<
long>(composite_param) = ndParam.getImmutableValue<
long>();
1157 else if (p.
isType<
bool>())
1159 p.
value<
bool>(composite_param) = (ndParam.getImmutableValue<
double>() != 0.0);
1162 if (p.
value<
bool>(composite_param))
1168 else if (p.
isType<std::vector<double> >())
1170 (p.
value<std::vector<double> >(composite_param)).push_back(ndParam.getImmutableValue<
double>());
1172 else if (p.
isType<std::vector<std::string> >())
1174 p.
value<std::vector<std::string> >(composite_param).push_back(ndParam.stringValue());
1178 Report::DevelFatal().in(
"CompositeParam::setParams") <<
"Unknown parameter type for " << pName;
1184 Report::DevelFatal().in(
"CompositeParam::setParams") <<
"Undefined parameter " << pName << std::endl
1185 <<
"This parameter is in metadata, but not recognized in constructor";
1192 for (ParameterMap::const_iterator it = parameter_map.begin(); it != parameter_map.end(); ++it)
1196 if (param.
isType<
double>())
1202 val = getDefaultValue<double>(param) -
CONSTCtoK;
1204 val = getDefaultValue<double>(param);
1205 param_list.push_back(
Param((*it).first, val));
1207 else if (param.
getVec() > 0)
1212 std::string vPar((*it).first.substr(0, (*it).first.size()-1));
1213 param_list.push_back(
Param(vPar,
"VECTOR"));
1218 double val = getDefaultValue<double>(param);
1219 param_list.push_back(
Param((*it).first, val));
1222 else if (param.
isType<
bool>())
1225 param_list.push_back(
Param((*it).first, getDefaultValue<bool>(param)));
1226 else if (param.
getVec() > 0)
1230 std::string vPar((*it).first.substr(0, (*it).first.size()-1));
1231 param_list.push_back(
Param(vPar,
"VECTOR"));
1236 bool val = getDefaultValue<bool>(param);
1237 param_list.push_back(
Param((*it).first, val));
1240 else if (param.
isType<
int>())
1243 param_list.push_back(
Param((*it).first, getDefaultValue<int>(param)));
1244 else if (param.
getVec() > 0)
1248 std::string vPar((*it).first.substr(0, (*it).first.size()-1));
1249 param_list.push_back(
Param(vPar,
"VECTOR"));
1251 int val = getDefaultValue<int>(param);
1252 param_list.push_back(
Param((*it).first, val));
1255 else if (param.
isType<std::string>())
1258 param_list.push_back(
Param((*it).first, getDefaultValue<std::string>(param)));
1259 else if (param.
getVec() > 0)
1263 std::string vPar((*it).first.substr(0, (*it).first.size()-1));
1264 param_list.push_back(
Param(vPar,
"VECTOR"));
1266 std::string val = getDefaultValue<std::string>(param);
1267 param_list.push_back(
Param((*it).first, val));
1270 else if (param.
isType<std::vector<std::string> >())
1272 Param vc((*it).first, std::vector<std::string>());
1273 param_list.push_back(vc);
1275 else if (param.
isType<std::vector<double> >())
1277 Param vc((*it).first, std::vector<double>());
1278 param_list.push_back(vc);
1282 Param vc2((*it).first,
"VECTOR-COMPOSITE");
1284 param_list.push_back(vc2);
1286 std::vector<Param> compositeParams;
1291 Report::DevelFatal().in(
"populateParams") <<
"Vector-composite map for device type entity empty.";
1299 for (ParameterMap::const_iterator it4 = e.find(
"NAME"); it4 != e.end();) {
1302 compositeParams.push_back(
Param((*it4).first, getDefaultValue<double>(p)));
1303 else if (p.
isType<
bool>())
1304 compositeParams.push_back(
Param((*it4).first, getDefaultValue<bool>(p)));
1305 else if (p.
isType<
int>())
1306 compositeParams.push_back(
Param((*it4).first, getDefaultValue<int>(p)));
1307 else if (p.
isType<std::string>())
1308 compositeParams.push_back(
Param((*it4).first, getDefaultValue<std::string>(p)));
1309 if ((*it4).first ==
"NAME")
1313 if (it4 != e.end() && (*it4).first ==
"NAME")
1317 composite_param_map[(*it).first] = compositeParams;
1324 Xyce::dout() <<
"In final else clause of DeviceEntity::getParams().";
1325 if( param.
isType<std::vector<std::string> >() )
1326 Xyce::dout() <<
" type is STR_VEC ";
1327 if( param.
isType<std::vector<double> >() )
1328 Xyce::dout() <<
" type is DBLE_VEC ";
1329 Xyce::dout() << it->first <<
" this item is NOT being added to default parameter list." << std::endl;