51 #ifndef Xyce_N_DEV_Device_Template_h
52 #define Xyce_N_DEV_Device_Template_h
54 #if defined(HAVE_UNORDERED_MAP)
55 #include <unordered_map>
56 using std::unordered_map;
57 #elif defined(HAVE_TR1_UNORDERED_MAP)
58 #include <tr1/unordered_map>
59 using std::tr1::unordered_map;
61 #error neither unordered_map or tr1/unordered_map found
75 void could_not_find_model_error(
const Device &device,
const std::string &model_name,
const std::string &instance_name,
const NetlistLocation &netlist_location);
76 void duplicate_model_warning(
const Device &device,
const DeviceModel &model,
const NetlistLocation &netlist_location);
77 void duplicate_instance_warning(
const Device &device,
const DeviceInstance &instance,
const NetlistLocation &netlist_location);
78 void duplicate_entity_warning(
const Device &device,
const DeviceEntity &entity,
const NetlistLocation &netlist_location);
122 typedef unordered_map<std::string, ModelType *, HashNoCase, EqualNoCase>
ModelMap;
123 typedef unordered_map<std::string, InstanceType *, HashNoCase, EqualNoCase>
InstanceMap;
167 for (
typename ModelMap::iterator model_it =
modelMap_.begin(); model_it !=
modelMap_.end(); ++model_it)
169 delete (*model_it).second;
217 typename ModelMap::iterator it =
modelMap_.find(model_name);
236 typename ModelMap::const_iterator it =
modelMap_.find(model_name);
274 typename InstanceMap::const_iterator it =
instanceMap_.find(instance_name.getEncodedName());
291 return T::isLinearDevice();
304 return T::isPDEDevice();
321 for (
typename ModelMap::const_iterator it =
modelMap_.begin(); it !=
modelMap_.end(); ++it)
349 virtual bool updateState (
double * solVec,
double * staVec,
double * stoVec);
351 virtual bool loadDAEVectors (
double * solVec,
double * fVec,
double * qVec,
double * bVec,
double * storeLeadF,
double * storeLeadQ,
double * leadF,
double * leadQ,
double * junctionV ) ;
352 virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx) ;
425 return T::modelRequired();
429 virtual bool getBreakPoints(std::vector<Util::BreakPoint> & breakPointTimes);
472 if (model_name.empty())
474 if (isModelRequired())
481 typename ModelMap::iterator it = modelMap_.find(defaultModelName_);
482 if (it == modelMap_.end())
484 addModel(
ModelBlock(defaultModelName_), factory_block);
486 model_name = defaultModelName_;
490 typename ModelMap::iterator it = modelMap_.find(model_name);
491 if (it == modelMap_.end())
499 std::pair<typename InstanceMap::iterator, bool> result = instanceMap_.insert(
typename InstanceMap::value_type(instance_block.
getInstanceName().
getEncodedName(),
typename InstanceMap::mapped_type(0)));
503 instance->setDefaultParamName(T::instanceDefaultParameter());
505 (*result.first).second = instance;
507 model.addInstance(instance);
509 instanceVector_.push_back(instance);
519 return (*result.first).second;
543 std::pair<typename ModelMap::iterator, bool> result = modelMap_.insert(
typename ModelMap::value_type(model_block.
getName(),
typename ModelMap::mapped_type(0)));
548 (*result.first).second = model;
550 if (instanceMap_.find(model_block.
getName()) != instanceMap_.end())
558 return (*result.first).second;
609 bool bsuccess =
true;
611 for (
typename InstanceVector::iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
612 bsuccess = (*it)->getInstanceBreakPoints(breakPointTimes) && bsuccess;
637 bool bsuccess =
true;
639 for (
typename InstanceVector::iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
640 bsuccess = (*it)->updateSource() && bsuccess;
656 bool bsuccess =
true;
657 for (
typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
659 bool tmpBool = (*it)->updatePrimaryState();
660 bsuccess = bsuccess && tmpBool;
677 bool bsuccess =
true;
678 for (
typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
680 bool tmpBool = (*it)->updateSecondaryState ();
681 bsuccess = bsuccess && tmpBool;
696 bool DeviceMaster<T>::loadDAEVectors(
double * solVec,
double * fVec,
double * qVec,
double * bVec,
double * storeLeadF,
double * storeLeadQ,
double * leadF,
double * leadQ,
double * junctionV)
698 bool bsuccess =
true;
699 for (
typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
701 bool tmpBool = (*it)->loadDAEFVector();
702 bsuccess = bsuccess && tmpBool;
704 tmpBool = (*it)->loadDAEQVector();
705 bsuccess = bsuccess && tmpBool;
707 tmpBool = (*it)->loadDAEBVector();
708 bsuccess = bsuccess && tmpBool;
725 bool bsuccess =
true;
726 for (
typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
728 bool tmpBool = (*it)->loadDAEdFdx();
729 bsuccess = bsuccess && tmpBool;
730 tmpBool = (*it)->loadDAEdQdx();
731 bsuccess = bsuccess && tmpBool;
748 bool bsuccess =
true;
750 if ( !isLinearDevice() )
752 for (
typename InstanceVector::const_iterator it = instanceVector_.begin(); it != instanceVector_.end(); ++it)
754 bool tmpBool = (*it)->isConverged();
755 bsuccess = bsuccess && tmpBool;
const ModelName & getName() const
T::ModelType ModelType
Make the model begin defined available.
void duplicate_entity_warning(const Device &device, const DeviceEntity &entity, const NetlistLocation &netlist_location)
duplicate_entity_warning reports a duplication of entity names.
const SolverState & solverState_
unordered_map< std::string, ModelType *, HashNoCase, EqualNoCase > ModelMap
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
virtual bool getBreakPoints(std::vector< Util::BreakPoint > &breakPointTimes)
Pure virtual class to augment a linear system.
Devices and models are each named.
const std::string & getEncodedName() const
Return the instance name encoded as: [s:]*xname [s:]*Ytype!name [s:]*Utype!name!count.
void instance_must_reference_model_error(const Device &device, const std::string &name, const NetlistLocation &netlist_location)
reports that the type of instance requires that a model be specified
virtual bool updateSecondaryState(double *staDerivVec, double *stoVec)
Updates the devices secondary state information.
void duplicate_instance_warning(const Device &device, const DeviceInstance &instance, const NetlistLocation &netlist_location)
duplicate_instance_warning reports a duplication of instance names.
InstanceVector::const_iterator getInstanceEnd() const
Returns an iterator to the ending of the vector of all instances created for this device...
virtual bool isConverged() const
Checks that the device is converged.
InstanceVector::const_iterator getInstanceBegin() const
Returns an iterator to the beginning of the vector of all instances created for this device...
const std::string defaultModelName_
DeviceMaster instantiates a device as described by the device traits T.
void could_not_find_model_error(const Device &device, const std::string &model_name, const std::string &instance_name, const NetlistLocation &netlist_location)
reports that the model name is note defined
std::vector< InstanceType * > InstanceVector
virtual bool isLinearDevice() const
Returns true if this device is a linear device.
virtual bool isPDEDevice() const
Returns true if this device is a PDE device.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
DeviceMaster(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &solver_state, const DeviceOptions &device_options)
Constructs a device.
const DeviceOptions & deviceOptions_
virtual const DeviceEntity * findInstance(const InstanceName &instance_name) const
Returns a pointer to the model or instance entity with the specified name.
const std::string deviceName_
virtual const DeviceModel * findModel(const ModelName &model_name) const
Returns a pointer to the model or model model with the specified name.
const ModelName & getModelName() const
const DeviceOptions & getDeviceOptions() const
Returns the device options given during device construction.
const InstanceName & getInstanceName() const
void duplicate_model_warning(const Device &device, const DeviceModel &model, const NetlistLocation &netlist_location)
duplicate_model_warning reports that the model name is duplicated.
The Device class is an interface for device implementations.
virtual ModelType * addModel(const ModelBlock &MB, const FactoryBlock &factory_block)
Creates a device model and adds it to the device's list of models.
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
const NetlistLocation & getNetlistLocation() const
virtual DeviceModel * findModel(const ModelName &model_name)
Returns a pointer to the model or model model with the specified name.
Class Configuration contains device configuration data.
DeviceMaster & operator=(const DeviceMaster &right)
No assignments.
virtual DeviceEntity * findInstance(const InstanceName &instance_name)
Returns a pointer to the model or instance entity with the specified name.
const NetlistLocation & getNetlistLocation() const
virtual void forEachInstance(DeviceInstanceOp &op) const
Executes operator op, passing its DeviceInstance pointer, for each device instance.
bool isModelRequired() const
Returns true if the model name must be specified for each instance.
const std::string & getDeviceName() const
Decodes the device name.
virtual InstanceType * addInstance(const InstanceBlock &instance_block, const FactoryBlock &factory_block)
Creates a device instance and adds to the device model's instance list.
T::InstanceType InstanceType
Make the instance being define available.
virtual ~DeviceMaster()
Destroys the device.
InstanceVector instanceVector_
virtual const std::string & getName() const
Returns the name of this device.
ModelBlock represents a .MODEL line from the netlist.
InstanceBlock represent a device instance line from the netlist.
virtual bool loadDAEVectors(double *solVec, double *fVec, double *qVec, double *bVec, double *storeLeadF, double *storeLeadQ, double *leadF, double *leadQ, double *junctionV)
Populates the device's ExternData object with these pointers.
virtual bool updateSources()
Updates the devices source information.
virtual void forEachModel(DeviceModelOp &op) const
Executes operator op, passing its DeviceModel pointer, for each device model.
virtual const std::string & getDefaultModelName() const
Returns the default model name to use if the instance being created does not specify one...
unordered_map< std::string, InstanceType *, HashNoCase, EqualNoCase > InstanceMap
const Configuration & configuration_
const SolverState & getSolverState() const
Returns the solver state given during device construction.