void CONSTR_DC_FLOW_LIM_analyze_branch(Constr* c, Branch* br) { // Local variables Bus* bus[2]; Mat* G; Vec* l; Vec* u; int* Gcounter; REAL b; int index; double rating; // Constr data G = CONSTR_get_G(c); l = CONSTR_get_l(c); u = CONSTR_get_u(c); Gcounter = CONSTR_get_Gcounter_ptr(c); if (!Gcounter) return; bus[0] = BRANCH_get_bus_from(br); bus[1] = BRANCH_get_bus_to(br); b = BRANCH_get_b(br); index = BRANCH_get_index(br); if (BRANCH_get_ratingA(br) > 0) rating = BRANCH_get_ratingA(br); else rating = BRANCH_INF_FLOW; VEC_set(l,index,-rating); // p.u. VEC_set(u,index,rating); // p.u. if (BUS_has_flags(bus[0],FLAG_VARS,BUS_VAR_VANG)) { // wk var // G MAT_set_i(G,*Gcounter,index); MAT_set_j(G,*Gcounter,BUS_get_index_v_ang(bus[0])); // wk MAT_set_d(G,*Gcounter,-b); (*Gcounter)++; } else { // b VEC_add_to_entry(l,index,b*BUS_get_v_ang(bus[0])); VEC_add_to_entry(u,index,b*BUS_get_v_ang(bus[0])); } if (BUS_has_flags(bus[1],FLAG_VARS,BUS_VAR_VANG)) { // wm var // G MAT_set_i(G,*Gcounter,index); MAT_set_j(G,*Gcounter,BUS_get_index_v_ang(bus[1])); // wk MAT_set_d(G,*Gcounter,b); (*Gcounter)++; } else { // b VEC_add_to_entry(l,index,-b*BUS_get_v_ang(bus[1])); VEC_add_to_entry(u,index,-b*BUS_get_v_ang(bus[1])); } if (BRANCH_has_flags(br,FLAG_VARS,BRANCH_VAR_PHASE)) { // phi var // G MAT_set_i(G,*Gcounter,index); MAT_set_j(G,*Gcounter,BRANCH_get_index_phase(br)); // phi MAT_set_d(G,*Gcounter,b); (*Gcounter)++; } else { // b VEC_add_to_entry(l,index,-b*BRANCH_get_phase(br)); VEC_add_to_entry(u,index,-b*BRANCH_get_phase(br)); } }
void CONSTR_PAR_GEN_Q_analyze_branch(Constr* c, Branch* br) { // Local variables Bus* buses[2]; Bus* bus; Gen* gen1; Gen* gen2; int* Acounter; int* Aconstr_index; char* bus_counted; Vec* b; Mat* A; int i; int j; REAL Qmin1; REAL Qmin2; REAL dQ1; REAL dQ2; // Cosntr data b = CONSTR_get_b(c); A = CONSTR_get_A(c); Acounter = CONSTR_get_Acounter_ptr(c); Aconstr_index = CONSTR_get_Aconstr_index_ptr(c); bus_counted = CONSTR_get_bus_counted(c); if (!Acounter || !Aconstr_index || !bus_counted) return; // Bus data buses[0] = BRANCH_get_bus_from(br); buses[1] = BRANCH_get_bus_to(br); // Buses for (i = 0; i < 2; i++) { bus = buses[i]; if (!bus_counted[BUS_get_index(bus)]) { // Reactive power of regulating generators if (BUS_is_regulated_by_gen(bus)) { gen1 = BUS_get_reg_gen(bus); Qmin1 = GEN_get_Q_min(gen1); dQ1 = GEN_get_Q_max(gen1)-Qmin1; if (dQ1 < CONSTR_PAR_GEN_Q_PARAM) dQ1 = CONSTR_PAR_GEN_Q_PARAM; for (gen2 = GEN_get_reg_next(gen1); gen2 != NULL; gen2 = GEN_get_reg_next(gen2)) { Qmin2 = GEN_get_Q_min(gen2); dQ2 = GEN_get_Q_max(gen2)-Qmin2; if (dQ2 < CONSTR_PAR_GEN_Q_PARAM) dQ2 = CONSTR_PAR_GEN_Q_PARAM; VEC_set(b,*Aconstr_index,Qmin1/dQ1-Qmin2/dQ2); if (GEN_has_flags(gen1,FLAG_VARS,GEN_VAR_Q)) { MAT_set_i(A,*Acounter,*Aconstr_index); MAT_set_j(A,*Acounter,GEN_get_index_Q(gen1)); MAT_set_d(A,*Acounter,1./dQ1); (*Acounter)++; } else VEC_add_to_entry(b,*Aconstr_index,-GEN_get_Q(gen1)/dQ1); if (GEN_has_flags(gen2,FLAG_VARS,GEN_VAR_Q)) { MAT_set_i(A,*Acounter,*Aconstr_index); MAT_set_j(A,*Acounter,GEN_get_index_Q(gen2)); MAT_set_d(A,*Acounter,-1./dQ2); (*Acounter)++; } else VEC_add_to_entry(b,*Aconstr_index,GEN_get_Q(gen2)/dQ2); (*Aconstr_index)++; } } } // Update counted flag bus_counted[BUS_get_index(bus)] = TRUE; } }
void CONSTR_PAR_GEN_P_analyze_step(Constr* c, Branch* br, int t) { // Local variables Bus* buses[2]; Bus* bus; Gen* gen1; Gen* gen2; int* A_nnz; int* A_row; char* bus_counted; Vec* b; Mat* A; int i; int T; // Number of periods T = BRANCH_get_num_periods(br); // Cosntr data b = CONSTR_get_b(c); A = CONSTR_get_A(c); A_nnz = CONSTR_get_A_nnz_ptr(c); A_row = CONSTR_get_A_row_ptr(c); bus_counted = CONSTR_get_bus_counted(c); // Check pointers if (!A_nnz || !A_row || !bus_counted) return; // Check outage if (BRANCH_is_on_outage(br)) return; // Bus data buses[0] = BRANCH_get_bus_k(br); buses[1] = BRANCH_get_bus_m(br); // Buses for (i = 0; i < 2; i++) { bus = buses[i]; if (!bus_counted[BUS_get_index(bus)*T+t]) { // Active power of slack generators if (BUS_is_slack(bus)) { gen1 = BUS_get_gen(bus); for (gen2 = GEN_get_next(gen1); gen2 != NULL; gen2 = GEN_get_next(gen2)) { VEC_set(b,*A_row,0.); if (GEN_has_flags(gen1,FLAG_VARS,GEN_VAR_P)) { MAT_set_i(A,*A_nnz,*A_row); MAT_set_j(A,*A_nnz,GEN_get_index_P(gen1,t)); MAT_set_d(A,*A_nnz,1.); (*A_nnz)++; } else VEC_add_to_entry(b,*A_row,-GEN_get_P(gen1,t)); if (GEN_has_flags(gen2,FLAG_VARS,GEN_VAR_P)) { MAT_set_i(A,*A_nnz,*A_row); MAT_set_j(A,*A_nnz,GEN_get_index_P(gen2,t)); MAT_set_d(A,*A_nnz,-1.); (*A_nnz)++; } else VEC_add_to_entry(b,*A_row,GEN_get_P(gen2,t)); (*A_row)++; } } } // Update counted flag bus_counted[BUS_get_index(bus)*T+t] = TRUE; } }