50 #include <Xyce_config.h>
65 #include <N_LAS_Matrix.h>
66 #include <N_LAS_Vector.h>
68 #include <N_UTL_FeatureTest.h>
69 #include <N_UTL_IndentStreamBuf.h>
84 .setDescription(
"Number of Buses");
88 .setDescription(
"Analysis Type");
92 .setDescription(
"IC File Name");
96 .setDescription(
"BD File Name");
120 :
DeviceInstance(IB, configuration.getInstanceParameters(), factory_block),
127 if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
129 Xyce::dout() << std::endl <<
"In device constructor for " <<
getName() << std::endl;
132 std::vector<Param>::const_iterator iter = IB.
params.begin();
133 std::vector<Param>::const_iterator last = IB.
params.end();
135 for ( ; iter != last; ++iter)
137 const std::string & tmpname = iter->tag();
138 const bool & tmpgiven = iter->given();
141 if (tmpname ==
"NB" && tmpgiven ==
true)
143 numBus_ = iter->getImmutableValue<
int>();
145 if (tmpname ==
"AT" && tmpgiven ==
true)
149 if (tmpname ==
"BUF" && tmpgiven ==
true)
153 if (tmpname ==
"BRF" && tmpgiven ==
true)
166 UserError0(*
this) <<
"NB Instance Parameter must be an integer >=1";
171 UserError(*
this) <<
"Incorrect number of Initial Conditions for device "
173 <<
" and " <<
magICmap_.size() <<
" initial conditions in file "
181 if (DEBUG_DEVICE && isActive(Diag::DEVICE_DUMP_VECTORS))
209 if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
211 Xyce::dout() <<
getName() <<
" G's and B's are:"
212 << Util::push << std::endl
213 <<
"(g11,b11) = (" <<
g11 <<
" , " <<
b11 <<
")" << std::endl
214 <<
"(g12,b12) = (" <<
g12 <<
" , " <<
b12 <<
")" << std::endl
215 <<
"(g21,b21) = (" <<
g21 <<
" , " <<
b21 <<
")" << std::endl
216 <<
"(g22,b22) = (" <<
g22 <<
" , " <<
b22 <<
")" << std::endl
278 const std::vector<int> & extLIDVecRef )
297 if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
299 Xyce::dout() <<
getName() <<
" LIDs"
300 << Util::push << std::endl
301 <<
"li_VR1 = " <<
li_VR1 << std::endl
302 <<
"li_VI1 = " <<
li_VI1 << std::endl
303 <<
"li_VR2 = " <<
li_VR2 << std::endl
304 <<
"li_VI2 = " <<
li_VI2 << std::endl
315 if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
317 Xyce::dout() <<
getName() <<
" LIDs"
318 << Util::push << std::endl
319 <<
"li_Theta1 = " <<
li_Theta1 << std::endl
320 <<
"li_VM1 = " <<
li_VM1 << std::endl
321 <<
"li_Theta2 = " <<
li_Theta2 << std::endl
322 <<
"li_VM2 = " <<
li_VM2 << std::endl
328 UserError0(*
this) <<
"Analysis Type must be IV or PQ in power grid device: " <<
getName();
454 double dSin21 = sin(solVec[li_Theta2]-solVec[
li_Theta1]);
455 double dCos12 = cos(solVec[li_Theta1]-solVec[li_Theta2]);
456 double dCos21 = cos(solVec[li_Theta2]-solVec[li_Theta1]);
465 UserError0(*
this) <<
"Analysis Type must be IV or PQ in power grid device: " <<
getName();
482 if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) &&
getSolverState().debugTimeFlag)
484 Xyce::dout() <<
"Instance::updatePrimaryState" <<std::endl;
524 UserError0(*
this) <<
"Analysis Type must be IV or PQ in power grid device: " <<
getName();
599 double dSin21 = sin(solVec[li_Theta2]-solVec[
li_Theta1]);
600 double dCos12 = cos(solVec[li_Theta1]-solVec[li_Theta2]);
601 double dCos21 = cos(solVec[li_Theta2]-solVec[li_Theta1]);
629 UserError0(*
this) <<
"Analysis Type must be IV or PQ in power grid device: " <<
getName();
686 std::ifstream busDataIn;
688 if ( !busDataIn.is_open() )
690 Report::UserError() <<
"Could not find file " <<
busFileName_;
697 while ( busDataIn >> bus )
704 if (DEBUG_DEVICE && isActive(Diag::DEVICE_DUMP_VECTORS))
706 Xyce::dout() <<
"Read line in file " <<
busFileName_ <<
" for bus "
707 << bus <<
". (Mag,angle) ICs=(" <<
magICmap_[bus] <<
","
715 Report::UserError() <<
"Problem reading file " <<
busFileName_
716 << std::endl <<
"File must use space separated values,"
717 <<
"with 3 items per line.";
724 Report::UserError() <<
"Problem reading " <<
busFileName_ << std::endl
725 <<
"There is a duplicate entry for bus number " << bus;
757 std::ifstream branchDataIn;
759 if ( !branchDataIn.is_open() )
767 double resistance, reactance, susceptance,turnsRatio;
769 while ( branchDataIn >> bus1 >> bus2)
771 if ( (bus1 < 1) || (bus1 >
numBus_) || (bus2 < 1) || (bus2 >
numBus_) )
773 Report::UserError() <<
"Invalid bus number in file " <<
branchFileName_ << std::endl
774 <<
"Bus numbers should be between 1 and " <<
numBus_;
780 fromToKey = std::make_pair(bus1,bus2);
781 toFromKey = std::make_pair(bus2,bus1);
787 if ( branchDataIn >> resistance >> reactance >> susceptance >> turnsRatio )
794 turnsRatio_[fromToKey]= (turnsRatio > 0) ? turnsRatio : 1.0;
797 if (DEBUG_DEVICE && isActive(Diag::DEVICE_DUMP_VECTORS))
799 Xyce::dout() <<
"Read line in file " <<
branchFileName_ <<
" for buses "
802 <<
"). Turns Ratio=" <<
turnsRatio_[fromToKey] << std::endl;
808 << std::endl <<
"File must use space separated values,"
809 <<
"with 3 items per line.";
810 branchDataIn.close();
816 Report::UserError() <<
"Problem reading " <<
branchFileName_ << std::endl
817 <<
"There is a duplicate branch data entry for bus numbers "
818 << bus1 <<
" and " << bus2 << std::endl;
819 branchDataIn.close();
844 twodKey fromToKey, toFromKey, toToKey, fromFromKey;
846 double invTurnsRatio;
847 std::complex<double> zVal,selfVal;
853 Report::UserError() <<
"Branch Resistance, Reactance and Susceptance Matrices not same size.";
859 fromToKey=iterRes->first;
860 fromID=fromToKey.first;
861 toID=fromToKey.second;
862 if (DEBUG_DEVICE && isActive(Diag::DEVICE_DUMP_VECTORS))
864 Xyce::dout() <<
"Processing Y Matrix for branch ID: " << fromID <<
"-" << toID << std::endl;
867 toFromKey = std::make_pair(toID,fromID);
868 fromFromKey = std::make_pair(fromID,fromID);;
869 toToKey = std::make_pair(toID,toID);
878 yMatrixMap_[fromToKey] = (-1./zVal) * invTurnsRatio;
879 yMatrixMap_[toFromKey] = (-1./zVal) * invTurnsRatio;
886 selfVal=std::complex<double>(selfVal.real(),selfVal.imag() + 0.5*
branchSusceptance_[fromToKey]);
887 yMatrixMap_[fromFromKey] += selfVal*invTurnsRatio*invTurnsRatio;
888 yMatrixMap_[toToKey] += selfVal;
890 if (DEBUG_DEVICE && isActive(Diag::DEVICE_DUMP_VECTORS))
892 Xyce::dout() <<
"zVal, selfVal and inverse turns Ratio are: " << zVal <<
" " << selfVal
893 <<
" " << invTurnsRatio << std::endl <<
"Updated Y Matrix values are: " << std::endl
894 <<
" Index " << fromID <<
" and " << toID <<
" = " << yMatrixMap_[fromToKey] << std::endl
895 <<
" Index " << toID <<
" and " << fromID <<
" = " << yMatrixMap_[toFromKey] << std::endl
896 <<
" Index " << fromID <<
" and " << fromID <<
" = " << yMatrixMap_[fromFromKey] << std::endl
897 <<
" Index " << toID <<
" and " << toID <<
" = " << yMatrixMap_[toToKey] << std::endl;
902 for (fromID=1; fromID <=
numBus_; fromID++)
904 fromFromKey = std::make_pair(fromID,fromID);
928 std::complex<double> cVal;
930 std::cout <<
"Y Matrix complex values are: " << std::endl;
938 Xyce::dout() <<
" (" << toID <<
"," << fromID <<
") = " << cVal << std::endl;
970 :
DeviceModel(MB, configuration.getModelParameters(), factory_block)
984 std::vector<Instance*>::iterator iter;
988 for (iter=first; iter!=last; ++iter)
1004 std::vector<Instance*>::const_iterator iter;
1010 os <<
" name model name Parameters" << std::endl;
1011 for (i=0, iter=first; iter!=last; ++iter, ++i)
1013 os <<
" " << i <<
": " << (*iter)->getName() <<
" ";
1039 for (std::vector<Instance *>::const_iterator it = instanceContainer.begin(); it != instanceContainer.end(); ++it)
1053 .registerDevice(
"PowerGrid", 1)
1054 .registerModelType(
"PowerGrid", 1);
const InstanceName & getName() const
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
const SolverState & solverState_
Descriptor & addPar(const char *parName, T default_value, T U::*varPtr)
Adds the parameter description to the parameter map.
std::map< int, double > busShuntSusceptance_
std::pair< int, int > twodKey
twodComplexMap yMatrixMap_
Pure virtual class to augment a linear system.
std::vector< Instance * > instanceContainer
std::map< int, double > angleICmap_
virtual void registerJacLIDs(const JacobianStamp &jacLIDVec)
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Riter, const FactoryBlock &factory_block)
bool updatePrimaryState()
bool updateIntermediateVars()
void setParams(const std::vector< Param > ¶ms)
const std::string & getName() const
double * daeFVectorRawPtr
static void loadModelParameters(ParametricData< Model > &model_parameters)
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
const std::vector< std::vector< int > > & jacobianStamp() const
static std::vector< std::vector< int > > jacStamp
const DeviceOptions & deviceOptions_
std::map< int, double > magICmap_
static Config< T > & addConfiguration()
Adds the device to the Xyce device configuration.
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Linear::Matrix * dFdxMatrixPtr
twodMap branchSusceptance_
The Device class is an interface for device implementations.
std::string branchFileName_
Class Configuration contains device configuration data.
twodMap branchResistance_
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
const SolverState & getSolverState() const
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
virtual std::ostream & printOutInstances(std::ostream &os) const
const ExternData & extData
ModelBlock represents a .MODEL line from the netlist.
Manages parameter binding for class C.
InstanceBlock represent a device instance line from the netlist.
std::vector< Param > params
std::map< int, double > busShuntConductance_
std::string analysisType_
double * nextSolVectorRawPtr
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)