示例#1
0
/**
 * Return the contribution to a bus from shunts
 * @param bus: pointer to the bus making the call
 * @return: contribution to Y matrix from shunts associated with branches
 */
gridpack::ComplexType
gridpack::ymatrix::YMBranch::getShunt(gridpack::ymatrix::YMBus *bus)
{
  double retr, reti;
  retr = 0.0;
  reti = 0.0;
  int i;
  for (i=0; i<p_elems; i++) {
    double tmpr, tmpi;
    if (p_shunt[i] && p_branch_status[i]) {
      tmpr = 0.0;
      tmpi = 0.0;
      if (!p_xform[i]) {
        tmpi = 0.5*p_charging[i];
        tmpr = 0.0;
      }
      // HACK: pointer comparison, maybe could handle this better
      if (bus == getBus1().get()) {
        tmpr += p_shunt_admt_g1[i];
        tmpi += p_shunt_admt_b1[i];
      } else if (bus == getBus2().get()) {
        tmpr += p_shunt_admt_g2[i];
        tmpi += p_shunt_admt_b2[i];
      } else {
        // TODO: Some kind of error
      }
    } else {
      tmpr = 0.0;
      tmpi = 0.0;
    }
    retr += tmpr;
    reti += tmpi;
  }
  return gridpack::ComplexType(retr,reti);
}
示例#2
0
bool gridpack::dsimplicit::DSBranch::matrixReverseValues(ComplexType *values)
{
  int i;
  // Get from and to buses
  gridpack::dsimplicit::DSBus *busf = dynamic_cast<gridpack::dsimplicit::DSBus*>(getBus1().get());
  gridpack::dsimplicit::DSBus *bust = dynamic_cast<gridpack::dsimplicit::DSBus*>(getBus2().get());
  // If either the from or to bus is isolated then there is no contribution to the matrix as there
  // is no flow on the branch
  if(busf->isIsolated() || bust->isIsolated()) return false;

  int nvarf,nvart;
  busf->getNvar(&nvarf);
  bust->getNvar(&nvart);


  if(p_mode == INIT_X || p_mode == RESIDUAL_EVAL || p_mode == FAULT_EVAL) {
    for(i=0; i < p_nparlines;i++) {
      if(p_status[i]) {
	values[0]       += -p_Btf[i];
	values[nvart]   += -p_Gtf[i];
	values[1]       += -p_Gtf[i];
	values[nvart+1] +=  p_Btf[i];
      }
    }
  }  
  return true;
}
示例#3
0
/**
 * Return transformer contribution from the branch to the calling
 * bus
 * @param bus: pointer to the bus making the call
 * @return: contribution to Y matrix from branch
 */
gridpack::ComplexType
gridpack::ymatrix::YMBranch::getTransformer(gridpack::ymatrix::YMBus *bus)
{
  int i;
  gridpack::ComplexType ret(0.0,0.0);
  for (i=0; i<p_elems; i++) {
    gridpack::ComplexType tmp(p_resistance[i],p_reactance[i]);
    gridpack::ComplexType tmpB(0.0,0.5*p_charging[i]);
    if (p_xform[i] && p_branch_status[i]) {
      tmp = -1.0/tmp;
      tmp = tmp - tmpB;
      gridpack::ComplexType a(cos(p_phase_shift[i]),sin(p_phase_shift[i]));
      a = p_tap_ratio[i]*a;
      if ((!p_switched[i] && bus == getBus1().get()) ||
          (p_switched[i] && bus == getBus2().get())) {
        tmp = tmp/(conj(a)*a);
      } else {
        // tmp is unchanged
      }
    } else {
      tmp = gridpack::ComplexType(0.0,0.0);
    }
    ret += tmp;
  }
  return ret;
}
示例#4
0
bool gridpack::resistor_grid::RGBranch::matrixReverseValues(ComplexType *values)
{
  gridpack::resistor_grid::RGBus *bus1
    = dynamic_cast<gridpack::resistor_grid::RGBus*>(getBus1().get());
  gridpack::resistor_grid::RGBus *bus2
    = dynamic_cast<gridpack::resistor_grid::RGBus*>(getBus2().get());
  if (!bus1->isLead() && !bus2->isLead()) {
    values[0] = -1.0/p_resistance;
    return true;
  } else {
    return false;
  }
}
示例#5
0
bool gridpack::resistor_grid::RGBranch::matrixReverseSize(int *isize, int *jsize) const
{
  gridpack::resistor_grid::RGBus *bus1
    = dynamic_cast<gridpack::resistor_grid::RGBus*>(getBus1().get());
  gridpack::resistor_grid::RGBus *bus2
    = dynamic_cast<gridpack::resistor_grid::RGBus*>(getBus2().get());
  if (!bus1->isLead() && !bus2->isLead()) {
    *isize = 1;
    *jsize = 1;
    return true;
  } else {
    return false;
  }
}
示例#6
0
/**
 * Write output from branches to standard out
 * @param string (output) string with information to be printed out
 * @param bufsize size of string buffer in bytes
 * @param signal an optional character string to signal to this
 * routine what about kind of information to write
 * @return true if branch is contributing string to output, false otherwise
 */
bool gridpack::resistor_grid::RGBranch::serialWrite(char *string, const int
    bufsize,  const char *signal)
{

  gridpack::resistor_grid::RGBus *bus1
    = dynamic_cast<gridpack::resistor_grid::RGBus*>(getBus1().get());
  gridpack::resistor_grid::RGBus *bus2
    = dynamic_cast<gridpack::resistor_grid::RGBus*>(getBus2().get());
  double v1 = bus1->voltage();
  double v2 = bus2->voltage();
  double icur = (v1 - v2)/p_resistance;
  sprintf(string,"Current on line from bus %d to %d is: %12.6f\n",
      bus1->getOriginalIndex(),bus2->getOriginalIndex(),icur);
  return true;
}
示例#7
0
bool gridpack::dsimplicit::DSBranch::matrixReverseSize(int *isize, int *jsize) const
{
  // Get from and to buses
  gridpack::dsimplicit::DSBus *busf = dynamic_cast<gridpack::dsimplicit::DSBus*>(getBus1().get());
  gridpack::dsimplicit::DSBus *bust = dynamic_cast<gridpack::dsimplicit::DSBus*>(getBus2().get());
  // If either the from or to bus is isolated then there is no contribution to the matrix as there
  // is no flow on the branch
  if(busf->isIsolated() || bust->isIsolated()) return false;

  int nvarf,nvart;
  busf->getNvar(&nvarf);
  bust->getNvar(&nvart);
  *isize = nvart;
  *jsize = nvarf;
  
  return true;
}
示例#8
0
bool gridpack::ymatrix::YMBranch::matrixReverseValues(ComplexType *values)
{
  if (p_mode == YBus) {
    gridpack::ymatrix::YMBus *bus1
      = dynamic_cast<gridpack::ymatrix::YMBus*>(getBus1().get());
    gridpack::ymatrix::YMBus *bus2
      = dynamic_cast<gridpack::ymatrix::YMBus*>(getBus2().get());
    bool ok = !bus1->isIsolated();
    ok = ok && !bus2->isIsolated();
    if (p_active && ok) {
      values[0] = gridpack::ComplexType(p_ybusr_rvrs,p_ybusi_rvrs);
      return true;
    } else {
      return false;
    }
  }
  return false;
}
示例#9
0
bool gridpack::ymatrix::YMBranch::matrixReverseSize(int *isize, int *jsize) const
{
  if (p_mode == YBus) {
    gridpack::ymatrix::YMBus *bus1
      = dynamic_cast<gridpack::ymatrix::YMBus*>(getBus1().get());
    gridpack::ymatrix::YMBus *bus2
      = dynamic_cast<gridpack::ymatrix::YMBus*>(getBus2().get());
    bool ok = !bus1->isIsolated();
    ok = ok && !bus2->isIsolated();
    if (p_active && ok) {
      *isize = 1;
      *jsize = 1;
      return true;
    } else {
      return false;
    }
  }
  return false;
}