47 #include <Xyce_config.h>
62 #include <N_LAS_Matrix.h>
63 #include <N_LAS_Vector.h>
65 #include <N_UTL_ExtendedString.h>
66 #include <N_UTL_FeatureTest.h>
67 #include <N_UTL_IndentStreamBuf.h>
71 namespace PowerGridBranch {
80 .setDescription(
"Analysis Type");
85 .setDescription(
"Branch Resistance");
90 .setDescription(
"Branch Reactance");
95 .setDescription(
"Branch Shunt Susceptance");
148 :
DeviceInstance(IB, configuration.getInstanceParameters(), factory_block),
150 analysisTypeStr_(
"PQP"),
152 branchResistance_(1.0),
153 branchReactance_(1.0),
154 branchSusceptance_(1.0)
162 if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
164 Xyce::dout() << std::endl <<
"In device constructor for " <<
getName() << std::endl;
167 std::vector<Param>::const_iterator iter = IB.
params.begin();
168 std::vector<Param>::const_iterator last = IB.
params.end();
170 for ( ; iter != last; ++iter)
172 const std::string & tmpname = iter->tag();
173 const bool & tmpgiven = iter->given();
176 if (tmpname ==
"AT" && tmpgiven ==
true)
178 ExtendedString atStr(iter->stringValue());
185 else if ( atStr ==
"PQR" )
190 else if ( atStr ==
"PQP" )
197 UserError0(*
this) <<
"Analysis Type must be IV, PQR or PQP in power grid device: " <<
getName();
200 if (tmpname ==
"R" && tmpgiven ==
true)
204 if (tmpname ==
"X" && tmpgiven ==
true)
208 if (tmpname ==
"B" && tmpgiven ==
true)
242 std::complex<double> zVal, selfVal;
257 selfVal = std::complex<double>(selfVal.real(),selfVal.imag() + 0.5*
branchSusceptance_);
277 if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
279 Xyce::dout() <<
getName() <<
" G's and B's are:"
280 << Util::push << std::endl
281 <<
"(g11,b11) = (" <<
g11 <<
" , " <<
b11 <<
")" << std::endl
282 <<
"(g12,b12) = (" <<
g12 <<
" , " <<
b12 <<
")" << std::endl
283 <<
"(g21,b21) = (" <<
g21 <<
" , " <<
b21 <<
")" << std::endl
284 <<
"(g22,b22) = (" <<
g22 <<
" , " <<
b22 <<
")" << std::endl
345 const std::vector<int> & extLIDVecRef )
364 if (DEBUG_DEVICE && isActive(Diag::DEVICE_LIDS))
366 Xyce::dout() <<
getName() <<
" LIDs"
367 << Util::push << std::endl
368 <<
"li_VR1 = " <<
li_VR1 << std::endl
369 <<
"li_VI1 = " <<
li_VI1 << std::endl
370 <<
"li_VR2 = " <<
li_VR2 << std::endl
371 <<
"li_VI2 = " <<
li_VI2 << std::endl
382 if (DEBUG_DEVICE && isActive(Diag::DEVICE_LIDS))
384 Xyce::dout() <<
getName() <<
" LIDs"
385 << Util::push << std::endl
386 <<
"li_Theta1 = " <<
li_Theta1 << std::endl
387 <<
"li_VM1 = " <<
li_VM1 << std::endl
388 <<
"li_Theta2 = " <<
li_Theta2 << std::endl
389 <<
"li_VM2 = " <<
li_VM2 << std::endl
395 UserError0(*
this) <<
"Analysis Type must be IV, PQR or PQP in power grid device: " <<
getName();
473 if (DEBUG_DEVICE && (isActive(Diag::DEVICE_JACSTAMP) || isActive(Diag::DEVICE_LIDS)))
475 Xyce::dout() <<
getName() <<
": In registerJacLIDs, the offsets are:" << std::endl
508 if (DEBUG_DEVICE && (isActive(Diag::DEVICE_JACSTAMP) || isActive(Diag::DEVICE_LIDS)))
510 Xyce::dout() <<
getName() <<
": In registerJacLIDs, the offsets are:" << std::endl
554 solVec[li_VI1]*(
g12*solVec[
li_VR2] -
b12*solVec[li_VI2]) -
558 solVec[li_VI2]*(
g21*solVec[
li_VR1] -
b21*solVec[li_VI1]) -
564 double dSin21 = sin(solVec[li_Theta2]-solVec[
li_Theta1]);
565 double dCos12 = cos(solVec[li_Theta1]-solVec[li_Theta2]);
566 double dCos21 = cos(solVec[li_Theta2]-solVec[li_Theta1]);
575 UserError0(*
this) <<
"Analysis Type must be IV, PQR or PQP in power grid device: " <<
getName();
634 if (DEBUG_DEVICE && isActive(Diag::DEVICE_LOAD_VECTOR))
636 Xyce::dout() <<
getName() <<
": F Vector Load info is: (P1,P2,Q1,Q2) load is: (" <<
P1 <<
" , "
637 <<
P2 <<
" , " <<
Q1 <<
" , " <<
Q2 <<
")" << std::endl << std::endl;
642 UserError0(*
this) <<
"Analysis Type must be IV, PQR or PQP in power grid device: " <<
getName();
741 double dSin21 = sin(solVec[li_Theta2]-solVec[
li_Theta1]);
742 double dCos12 = cos(solVec[li_Theta1]-solVec[li_Theta2]);
743 double dCos21 = cos(solVec[li_Theta2]-solVec[li_Theta1]);
745 if (DEBUG_DEVICE && isActive(Diag::DEVICE_LOAD_VECTOR))
747 Xyce::dout() <<
getName() <<
": dFdx info is: " << std::endl
748 <<
"(dSin12,dSin21,dCos12,dCos21 = (" << dSin12 <<
" , " << dSin21
749 <<
" , " << dCos12 <<
" , " << dCos21 <<
")" << std::endl
750 <<
"(solVec[li_Theta1],solVec[li_Theta2]) = (" << solVec[
li_Theta1]
751 <<
" , " << solVec[
li_Theta2] <<
")" << std::endl
752 <<
"(solVec[li_VM1],solVec[li_VM2]) = (" << solVec[
li_VM1]
753 <<
" , " << solVec[
li_VM2] <<
")" << std::endl;
782 UserError0(*
this) <<
"Analysis Type must be IV, PQR or PQP in power grid device: " <<
getName();
841 :
DeviceModel(MB, configuration.getModelParameters(), factory_block)
855 std::vector<Instance*>::iterator iter;
859 for (iter=first; iter!=last; ++iter)
875 std::vector<Instance*>::const_iterator iter;
881 os <<
" name model name Parameters" << std::endl;
882 for (i=0, iter=first; iter!=last; ++iter, ++i)
884 os <<
" " << i <<
": " << (*iter)->getName() <<
" ";
910 for (std::vector<Instance *>::const_iterator it = instanceContainer.begin(); it != instanceContainer.end(); ++it)
924 .registerDevice(
"PowerGridBranch", 1)
925 .registerDevice(
"PGBR", 1)
926 .registerModelType(
"PowerGridBranch", 1);
const InstanceName & getName() const
static std::vector< std::vector< int > > jacStamp
const SolverState & solverState_
Descriptor & addPar(const char *parName, T default_value, T U::*varPtr)
Adds the parameter description to the parameter map.
Pure virtual class to augment a linear system.
Parameter may be specified as time dependent expression from netlist.
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
static void loadModelParameters(ParametricData< Model > &model_parameters)
std::string analysisTypeStr_
double branchSusceptance_
std::vector< Instance * > instanceContainer
virtual void registerJacLIDs(const JacobianStamp &jacLIDVec)
std::complex< double > y12
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
const std::vector< std::vector< int > > & jacobianStamp() const
bool updateIntermediateVars()
std::complex< double > y11
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
void setParams(const std::vector< Param > ¶ms)
const std::string & getName() const
double * daeFVectorRawPtr
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
const DeviceOptions & deviceOptions_
static Config< T > & addConfiguration()
Adds the device to the Xyce device configuration.
Linear::Matrix * dFdxMatrixPtr
The Device class is an interface for device implementations.
Class Configuration contains device configuration data.
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Riter, const FactoryBlock &factory_block)
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
const SolverState & getSolverState() const
std::complex< double > y22
bool updatePrimaryState()
const ExternData & extData
ModelBlock represents a .MODEL line from the netlist.
Manages parameter binding for class C.
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
InstanceBlock represent a device instance line from the netlist.
virtual std::ostream & printOutInstances(std::ostream &os) const
std::vector< Param > params
std::complex< double > y21
double * nextSolVectorRawPtr
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)