示例#1
0
    def test_PVPQ_switching_robustness(self):

        T = 2

        for case in test_cases.CASES:

            net = pf.Parser(case).parse(case, T)

            net.set_flags('bus', 'variable', 'any', 'voltage magnitude')

            c1 = pf.Constraint('AC power balance', net)
            c2 = pf.Constraint('PVPQ switching', net)
            c1.analyze()
            c2.analyze()

            h = pf.Heuristic('PVPQ switching', net)
            self.assertRaises(pf.HeuristicError, h.apply, [c1, c2],
                              np.zeros(0))

            h.apply([c1, c2], np.zeros(net.num_vars))

            p = pf.Problem(net)
            p.add_heuristic(h)
            p.add_constraint(c1)
            p.add_constraint(c2)
            p.analyze()
            p.apply_heuristics(p.x)
示例#2
0
文件: nr.py 项目: jbarberia/TNEP.py
    def solve_ac(self, net: pfnet.Network):
        """
        Resuelve un flujo de potencia de forma ac
        """

        net.clear_flags()

        # bus voltage angles
        net.set_flags('bus', 'variable', 'not slack', 'voltage angle')

        # bus voltage magnitudes
        net.set_flags('bus', 'variable', 'not regulated by generator',
                      'voltage magnitude')

        # slack gens active powers
        net.set_flags('generator', 'variable', 'slack', 'active power')

        # regulator gens reactive powers
        net.set_flags('generator', 'variable', 'regulator', 'reactive power')

        p = pfnet.Problem(net)
        p.add_constraint(pfnet.Constraint('AC power balance', net))
        p.add_constraint(
            pfnet.Constraint('generator active power participation', net))
        p.add_constraint(pfnet.Constraint('PVPQ switching', net))
        p.add_heuristic(pfnet.Heuristic('PVPQ switching', net))
        p.analyze()

        self.solve(p, net)
示例#3
0
def NRsolve(net):

    net.clear_flags()

    # bus voltage angles
    net.set_flags('bus', 'variable', 'not slack', 'voltage angle')

    # bus voltage magnitudes
    net.set_flags('bus', 'variable', 'not regulated by generator',
                  'voltage magnitude')

    # slack gens active powers
    net.set_flags('generator', 'variable', 'slack', 'active power')

    # regulator gens reactive powers
    net.set_flags('generator', 'variable', 'regulator', 'reactive power')

    p = pfnet.Problem(net)
    p.add_constraint(pfnet.Constraint('AC power balance', net))
    p.add_constraint(
        pfnet.Constraint('generator active power participation', net))
    p.add_constraint(pfnet.Constraint('PVPQ switching', net))
    p.analyze()

    x = p.get_init_point()
    p.eval(x)

    residual = lambda x: hstack((p.A * x - p.b, p.f))

    while norm(residual(x)) > 1e-4:
        x = x + spsolve(bmat([[p.A], [p.J]], format='csr'), -residual(x))
        p.eval(x)

    net.set_var_values(x)
    net.update_properties()
示例#4
0
    def create_problem(self, net):

        import pfnet

        # Parameters
        params = self._parameters

        # Clear flags
        net.clear_flags()

        # Voltages angles (not slack)
        net.set_flags('bus', 'variable', 'not slack', 'voltage angle')

        # Gen active powers (slack)
        net.set_flags('generator', 'variable', 'slack', 'active power')

        # Check
        try:
            assert (net.num_vars == net.num_buses - 1 +
                    net.get_num_slack_gens())
        except AssertionError:
            raise PFmethodError_BadProblem()

        # Set up problem
        problem = pfnet.Problem(net)
        problem.add_constraint(pfnet.Constraint('DC power balance', net))
        problem.add_constraint(
            pfnet.Constraint('generator active power participation', net))
        problem.analyze()

        # Return
        return problem
示例#5
0
文件: dc_opf.py 项目: mzy2240/GRIDOPT
    def create_problem(self,net):

        import pfnet
        
        # Parameters
        params = self._parameters
        thermal_limits = params['thermal_limits']
        
        # Clear flags
        net.clear_flags()
        
        # Set flags
        net.set_flags('bus',
                      'variable',
                      'not slack',
                      'voltage angle')
        net.set_flags('generator',
                      ['variable','bounded'],
                      ['adjustable active power','not on outage'],
                      'active power')
        net.set_flags('load',
                      ['variable','bounded'],
                      'adjustable active power',
                      'active power')
        if params['renewable_curtailment']:
            net.set_flags('variable generator',
                          ['variable','bounded'],
                          'any',
                          'active power')

        try:
            num_gvar =  len([g for g in net.generators if 
                             (not g.is_on_outage()) and g.is_P_adjustable()])
            num_cur = net.num_var_generators if params['renewable_curtailment'] else 0
            assert(net.num_bounded == (num_gvar+net.get_num_P_adjust_loads()+num_cur)*net.num_periods)
            assert(net.num_vars == (net.num_buses-net.get_num_slack_buses()+
                                    num_gvar+net.get_num_P_adjust_loads()+
                                    num_cur)*net.num_periods)
        except AssertionError:
            raise PFmethodError_BadProblem()
            
        # Set up problem
        problem = pfnet.Problem(net)
        problem.add_constraint(pfnet.Constraint('variable bounds',net))
        problem.add_constraint(pfnet.Constraint('DC power balance',net))
        if thermal_limits:
            problem.add_constraint(pfnet.Constraint('DC branch flow limits',net))
        problem.add_function(pfnet.Function('generation cost',1.,net))
        problem.add_function(pfnet.Function('consumption utility',-1.,net))
        problem.analyze()
        
        # Return
        return problem
示例#6
0
文件: nr.py 项目: jbarberia/TNEP.py
    def solve_dc(self, net: pfnet.Network):
        """
        Resuelve un flujo de potencia de forma dc
        """

        net.clear_flags()

        # bus voltage angles
        net.set_flags('bus', 'variable', 'not slack', 'voltage angle')

        # slack gens active powers
        net.set_flags('generator', 'variable', 'slack', 'active power')

        p = pfnet.Problem(net)
        p.add_constraint(pfnet.Constraint('DC power balance', net))
        p.add_constraint(
            pfnet.Constraint('generator active power participation', net))
        p.analyze()

        self.solve(p, net)
示例#7
0
# Solve
info = problem.solve(solver=optalg.opt_solver.OptSolverIpopt(),
                     parameters={'tol': 1e-4},
                     fast_evaluator=True)
print("OPTMOD", func.get_value())
print(info)
print('time construction', time_construction)

t = time.time()

# PFNET and OPTALG
net.set_flags('bus', 'variable', 'not slack', 'voltage angle')
net.set_flags('bus', ['variable', 'bounded'], 'any', 'voltage magnitude')
net.set_flags('generator', ['variable', 'bounded'], 'any',
              ['active power', 'reactive power'])
p = pfnet.Problem(net)
p.add_function(pfnet.Function('generation redispatch penalty', 1., net))
p.add_constraint(pfnet.Constraint('AC power balance', net))
p.add_constraint(pfnet.Constraint('variable bounds', net))

time_construction = time.time() - t

t = time.time()

p.analyze()
p.show()

time_transformation = time.time() - t

t = time.time()
示例#8
0
    def create_problem(self,net):
        
        import pfnet

        # Parameters
        params = self._parameters
        wcost  = params['weight_cost']
        wvmag  = params['weight_vmag']
        wvang = params['weight_vang']
        wpq = params['weight_pq']
        wt = params['weight_t']
        wb = params['weight_b']        
        th = params['thermal_limits']
        
        # Clear flags
        net.clear_flags()
        
        # Voltage magnitudes
        net.set_flags('bus',
                      ['variable','bounded'], 
                      'any',
                      'voltage magnitude')
        
        # Voltage angles
        net.set_flags('bus',
                      'variable',
                      'not slack',
                      'voltage angle')

        # Generator powers
        net.set_flags('generator',
                      ['variable','bounded'],
                      'any',
                      ['active power','reactive power'])

        try:
            assert(net.num_vars == (2*net.get_num_buses(True)-net.get_num_slack_buses(True) +
                                    2*net.get_num_generators(True))*net.num_periods)
            assert(net.num_bounded == (2*net.get_num_generators(True) +
                                       net.get_num_buses(True))*net.num_periods)
        except AssertionError:
            raise PFmethodError_BadProblem()
                                    
        # Problem
        problem = pfnet.Problem(net)

        # Constraints
        problem.add_constraint(pfnet.Constraint('AC power balance',net))
        problem.add_constraint(pfnet.Constraint('variable bounds',net))
        if th == 'nonlinear':
            problem.add_constraint(pfnet.Constraint("AC branch flow limits",net))
        elif th == 'linear':
            problem.add_constraint(pfnet.Constraint("linearized AC branch flow limits",net))
        elif th == 'none':
            pass
        else:
            raise PFmethodError_BadParamValue('thermal_limits')

        # Functions
        problem.add_function(pfnet.Function('generation cost',
                                            wcost/max([net.get_num_generators(True),1.]),net))
        if wvmag:
            problem.add_function(pfnet.Function('voltage magnitude regularization',
                                                wvmag/max([net.get_num_buses(True),1.]),net))
        if wvang:
            problem.add_function(pfnet.Function('voltage angle regularization',
                                                wvang/max([net.get_num_buses(True),1.]),net))
        if wpq:
            problem.add_function(pfnet.Function('generator powers regularization',
                                                wpq/max([net.get_num_generators(True),1.]),net))
        if wt:
            problem.add_function(pfnet.Function('tap ratio regularization',
                                                wt/max([net.get_num_tap_changers(True),1.]),net))
        if wb:
            problem.add_function(pfnet.Function('susceptance regularization',
                                                wb/max([net.get_num_switched_shunts(True),1.]),net))
        problem.analyze()
        
        # Return
        return problem
示例#9
0
    def create_problem(self, net):

        import pfnet

        # Parameters
        params = self._parameters
        wm = params['weight_vang']
        wa = params['weight_vmag']
        wp = params['weight_pq']
        wt = params['weight_t']
        wb = params['weight_b']
        limit_gens = params['limit_gens']
        lock_taps = params['lock_taps']
        lock_shunts = params['lock_shunts']
        solver_name = params['solver']

        # Clear flags
        net.clear_flags()

        # OPT-based
        ###########
        if solver_name != 'nr':

            # Set up variables
            net.set_flags('bus', 'variable', 'not slack',
                          ['voltage angle', 'voltage magnitude'])
            if not limit_gens:
                net.set_flags('bus', 'fixed', 'regulated by generator',
                              'voltage magnitude')
            net.set_flags('generator', 'variable', 'slack', 'active power')
            net.set_flags('generator', 'variable', 'regulator',
                          'reactive power')

            # Tap ratios
            if not lock_taps:
                net.set_flags('branch', 'variable', 'tap changer - v',
                              'tap ratio')

            # Shunt voltage control
            if not lock_shunts:
                net.set_flags('shunt', 'variable', 'switching - v',
                              'susceptance')

            try:
                num_vars = (2 * (net.num_buses - net.get_num_slack_buses()) +
                            net.get_num_slack_gens() +
                            net.get_num_reg_gens()) * net.num_periods
                if not lock_taps:
                    num_vars += net.get_num_tap_changers_v() * net.num_periods
                if not lock_shunts:
                    num_vars += net.get_num_switched_shunts() * net.num_periods
                assert (net.num_vars == num_vars)
                if limit_gens:
                    assert (net.num_fixed == 0)
                else:
                    assert (net.num_fixed == net.get_num_buses_reg_by_gen() *
                            net.num_periods)
            except AssertionError:
                raise PFmethodError_BadProblem()

            # Set up problem
            problem = pfnet.Problem(net)
            problem.add_constraint(pfnet.Constraint('AC power balance', net))
            problem.add_constraint(
                pfnet.Constraint('generator active power participation', net))
            problem.add_constraint(
                pfnet.Constraint('generator reactive power participation',
                                 net))
            problem.add_function(
                pfnet.Function('voltage magnitude regularization',
                               wm / max([net.num_buses, 1.]), net))
            problem.add_function(
                pfnet.Function('voltage angle regularization',
                               wa / max([net.num_buses, 1.]), net))
            problem.add_function(
                pfnet.Function('generator powers regularization',
                               wp / max([net.num_generators, 1.]), net))
            if limit_gens:
                problem.add_constraint(
                    pfnet.Constraint('voltage regulation by generators', net))
            else:
                problem.add_constraint(pfnet.Constraint(
                    'variable fixing', net))
            if not lock_taps:
                problem.add_constraint(
                    pfnet.Constraint('voltage regulation by transformers',
                                     net))
                problem.add_function(
                    pfnet.Function(
                        'tap ratio regularization',
                        wt / max([net.get_num_tap_changers_v(), 1.]), net))
            if not lock_shunts:
                problem.add_constraint(
                    pfnet.Constraint('voltage regulation by shunts', net))
                problem.add_function(
                    pfnet.Function(
                        'susceptance regularization',
                        wb / max([net.get_num_switched_shunts(), 1.]), net))
            problem.analyze()

            # Return
            return problem

        # NR-based
        ##########
        elif solver_name == 'nr':

            # Voltages
            net.set_flags('bus', 'variable', 'not slack',
                          ['voltage magnitude', 'voltage angle'])
            net.set_flags('bus', 'fixed', 'regulated by generator',
                          'voltage magnitude')

            # Gen active powers
            net.set_flags('generator', 'variable', 'slack', 'active power')

            # Gen reactive powers
            net.set_flags('generator', 'variable', 'regulator',
                          'reactive power')

            # Tap ratios
            net.set_flags('branch', ['variable', 'fixed'], 'tap changer - v',
                          'tap ratio')

            # Shunt susceptances
            net.set_flags('shunt', ['variable', 'fixed'], 'switching - v',
                          'susceptance')

            try:
                assert (net.num_vars ==
                        (2 * (net.num_buses - net.get_num_slack_buses()) +
                         net.get_num_slack_gens() + net.get_num_reg_gens() +
                         net.get_num_tap_changers_v() +
                         net.get_num_switched_shunts()) * net.num_periods)
                assert (net.num_fixed == (net.get_num_buses_reg_by_gen() +
                                          net.get_num_tap_changers_v() +
                                          net.get_num_switched_shunts()) *
                        net.num_periods)
            except AssertionError:
                raise PFmethodError_BadProblem()

            # Set up problem
            problem = pfnet.Problem(net)
            problem.add_constraint(pfnet.Constraint('AC power balance', net))
            problem.add_constraint(
                pfnet.Constraint('generator active power participation', net))
            problem.add_constraint(
                pfnet.Constraint('generator reactive power participation',
                                 net))
            problem.add_constraint(pfnet.Constraint('variable fixing', net))
            if limit_gens:
                problem.add_heuristic(pfnet.HEUR_TYPE_PVPQ)
            problem.analyze()

            # Return
            return problem

        # Invalid
        #########
        else:
            raise PFmethodError_BadOptSolver()
示例#10
0
    def create_problem_opt(self, net):

        import pfnet

        # Parameters
        params = self._parameters
        wm = params['weight_vmag']
        wa = params['weight_vang']
        wp = params['weight_powers']
        wc = params['weight_controls']
        wv = params['weight_var']
        wr = params['weight_redispatch']
        v_limits = params['v_limits']
        Q_mode = params['Q_mode']
        Q_limits = params['Q_limits']
        shunt_mode = params['shunt_mode']
        shunt_limits = params['shunt_limits']
        tap_mode = params['tap_mode']
        tap_limits = params['tap_limits']
        lock_vsc_P_dc = params['lock_vsc_P_dc']
        lock_csc_P_dc = params['lock_csc_P_dc']
        lock_csc_i_dc = params['lock_csc_i_dc']
        vdep_loads = params['vdep_loads']
        v_mag_warm_ref = params['v_mag_warm_ref']
        gens_redispatch = params['gens_redispatch']
        curtail_load_q = params['load_q_curtail']

        # Check shunt options
        if shunt_mode not in [self.CONTROL_MODE_LOCKED,
                               self.CONTROL_MODE_FREE,
                               self.CONTROL_MODE_REG]:
            raise ValueError('invalid shunts mode')
        if shunt_mode == self.CONTROL_MODE_REG and not shunt_limits:
            raise ValueError('unsupported shunts configuration')

        # Check tap options
        if tap_mode not in [self.CONTROL_MODE_LOCKED,
                             self.CONTROL_MODE_FREE,
                             self.CONTROL_MODE_REG]:
            raise ValueError('invalid taps mode')
        if tap_mode == self.CONTROL_MODE_REG and not tap_limits:
            raise ValueError('unsupported taps configuration')

        # Check Q options
        if Q_mode not in [self.CONTROL_MODE_REG,
                          self.CONTROL_MODE_FREE]:
            raise ValueError('invalid reactive power mode')

        # Clear flags
        net.clear_flags()

        # Buses
        net.set_flags('bus',
                      'variable',
                      'not slack',
                      'voltage angle')
        net.set_flags('bus',
                      'variable',
                      'any',
                      'voltage magnitude')
        if Q_mode == self.CONTROL_MODE_REG and not Q_limits:
            net.set_flags('bus',
                          'fixed',
                          'v set regulated',
                          'voltage magnitude')
        if v_limits:
            net.set_flags('bus',
                          'bounded',
                          'any',
                          'voltage magnitude')

        # Genertors
        if gens_redispatch:
            # Assume slack gens (excep renewables) are redispatchable
            net.set_flags('generator',
                          ['variable', 'bounded'],
                          'redispatchable',
                          'active power')
        else:
            net.set_flags('generator',
                          'variable',
                          'slack',
                          'active power')
        net.set_flags('generator',
                      'variable',
                      'regulator',
                      'reactive power')
        if Q_mode == self.CONTROL_MODE_FREE and Q_limits:
            net.set_flags('generator',
                          'bounded',
                          'regulator',
                          'reactive power')

        # Loads
        if vdep_loads:
            for load in net.loads:
                if load.is_voltage_dependent() and load.is_in_service():
                    net.set_flags_of_component(load,
                                               'variable',
                                               ['active power', 'reactive power'])

        if curtail_load_q:
            for load in net.loads:
                load.Q_min = np.minimum(load.Q, 0)
                load.Q_max = np.maximum(load.Q, 0)
                net.set_flags_of_component(load,
                                            ['variable','bounded'],
                                            'reactive power')
        # VSC HVDC
        net.set_flags('vsc converter',
                      'variable',
                      'any',
                      ['dc power', 'active power', 'reactive power'])
        if Q_mode == self.CONTROL_MODE_FREE and Q_limits:
            net.set_flags('vsc converter',
                          'bounded',
                          'any',
                          'reactive power')

        # CSC HVDC
        net.set_flags('csc converter',
                      'variable',
                      'any',
                      ['dc power', 'active power', 'reactive power'])

        # DC buses
        net.set_flags('dc bus',
                      'variable',
                      'any',
                      'voltage')

        # FACTS
        net.set_flags('facts',
                      'variable',
                      'any',
                      'all')
        if Q_mode == self.CONTROL_MODE_FREE and Q_limits:
            net.set_flags('facts',
                          'bounded',
                          'any',
                          'reactive power')

        # Tap changers
        if tap_mode != self.CONTROL_MODE_LOCKED:
            net.set_flags('branch',
                          'variable',
                          'tap changer - v',
                          'tap ratio')
        if tap_mode == self.CONTROL_MODE_FREE and tap_limits:
            net.set_flags('branch',
                          'bounded',
                          'tap changer - v',
                          'tap ratio')

        # Swtiched shunts
        if shunt_mode != self.CONTROL_MODE_LOCKED:
            net.set_flags('shunt',
                          'variable',
                          'switching - v',
                          'susceptance')
        if shunt_mode == self.CONTROL_MODE_FREE and shunt_limits:
            net.set_flags('shunt',
                          'bounded',
                          'switching - v',
                          'susceptance')

        # Set up problem
        problem = pfnet.Problem(net)

        problem.add_constraint(pfnet.Constraint('AC power balance', net))
        problem.add_constraint(pfnet.Constraint('HVDC power balance', net))
        problem.add_constraint(pfnet.Constraint('generator active power participation', net))
        problem.add_constraint(pfnet.Constraint('VSC converter equations', net))
        problem.add_constraint(pfnet.Constraint('CSC converter equations', net))
        problem.add_constraint(pfnet.Constraint('FACTS equations', net))
        problem.add_constraint(pfnet.Constraint('VSC DC voltage control', net))
        problem.add_constraint(pfnet.Constraint('CSC DC voltage control', net))
        problem.add_constraint(pfnet.Constraint('power factor regulation', net))

        if lock_vsc_P_dc:
            problem.add_constraint(pfnet.Constraint('VSC DC power control', net))
        if lock_csc_P_dc:
            problem.add_constraint(pfnet.Constraint('CSC DC power control', net))
        if lock_csc_i_dc:
            problem.add_constraint(pfnet.Constraint('CSC DC current control', net))

        func = pfnet.Function('voltage magnitude regularization', wm/(net.get_num_buses(True)+1.), net)
        func.set_parameter('v_set_reference', not v_mag_warm_ref)
        problem.add_function(func)

        problem.add_function(pfnet.Function('variable regularization', wv/(net.num_vars+1.), net))
        problem.add_function(pfnet.Function('voltage angle regularization', wa/(net.get_num_buses(True)+1.), net))
        problem.add_function(pfnet.Function('generator powers regularization', wp/(net.get_num_generators(True)+1.), net))
        problem.add_function(pfnet.Function('VSC DC power control', wc/(net.get_num_vsc_converters(True)+1.), net))
        problem.add_function(pfnet.Function('CSC DC power control', wc/(net.get_num_csc_converters(True)+1.), net))
        problem.add_function(pfnet.Function('CSC DC current control', wc/(net.get_num_csc_converters(True)+1.), net))
        problem.add_function(pfnet.Function('FACTS active power control', wc/(net.get_num_facts(True)+1.), net))
        problem.add_function(pfnet.Function('FACTS reactive power control', wc/(net.get_num_facts(True)+1.), net))

        if gens_redispatch:
            problem.add_function(pfnet.Function('generation redispatch penalty', wr/(net.get_num_generators(True)+1.), net))

        if Q_mode == self.CONTROL_MODE_REG and Q_limits:
            problem.add_constraint(pfnet.Constraint('voltage set point regulation', net))

        if net.num_fixed > 0:
            problem.add_constraint(pfnet.Constraint('variable fixing', net))

        if tap_mode != self.CONTROL_MODE_LOCKED:
            problem.add_function(pfnet.Function('tap ratio regularization', wc/(net.get_num_tap_changers_v(True)+1.), net))
            if tap_mode == self.CONTROL_MODE_REG and tap_limits:
                problem.add_constraint(pfnet.Constraint('voltage regulation by transformers', net))

        if shunt_mode != self.CONTROL_MODE_LOCKED:
            problem.add_function(pfnet.Function('susceptance regularization', wc/(net.get_num_switched_v_shunts(True)+1.), net))
            if shunt_mode == self.CONTROL_MODE_REG and shunt_limits:
                problem.add_constraint(pfnet.Constraint('voltage regulation by shunts', net))

        if vdep_loads:
            problem.add_constraint(pfnet.Constraint('load voltage dependence', net))

        if net.num_bounded > 0:
            problem.add_constraint(pfnet.Constraint('variable bounds', net))

        # Analyze
        problem.analyze()

        # Return
        return problem
示例#11
0
    def create_problem_nr(self, net):

        import pfnet

        # Parameters
        params = self._parameters
        Q_mode = params['Q_mode']
        Q_limits = params['Q_limits']
        shunt_mode = params['shunt_mode']
        shunt_limits = params['shunt_limits']
        tap_mode = params['tap_mode']
        tap_limits = params['tap_limits']
        lock_vsc_P_dc = params['lock_vsc_P_dc']
        lock_csc_P_dc = params['lock_csc_P_dc']
        lock_csc_i_dc = params['lock_csc_i_dc']
        vdep_loads = params['vdep_loads']
        gens_redispatch = params['gens_redispatch']

        # Check shunt options
        if shunt_mode not in [self.CONTROL_MODE_LOCKED,
                               self.CONTROL_MODE_REG]:
            raise ValueError('invalid shunts mode')
        if shunt_mode == self.CONTROL_MODE_REG and not shunt_limits:
            raise ValueError('unsupported shunts configuration')

        # Check tap options
        if tap_mode not in [self.CONTROL_MODE_LOCKED,
                               self.CONTROL_MODE_REG]:
            raise ValueError('invalid taps mode')
        if tap_mode == self.CONTROL_MODE_REG and not tap_limits:
            raise ValueError('unsupported taps configuration')

        # Check Q options
        if Q_mode != self.CONTROL_MODE_REG:
            raise ValueError('invalid reactive power mode')

        # Check other options
        if gens_redispatch:
            raise ValueError('generation redispatch not supported')
        if not lock_vsc_P_dc:
            raise ValueError('VSC P DC must be locked')
        if not lock_csc_P_dc:
            raise ValueError('CSC P DC must be locked')
        if not lock_csc_i_dc:
            raise ValueError('CSC i DC must be locked')

        # Clear flags
        net.clear_flags()

        # Buses
        net.set_flags('bus',
                      'variable',
                      'not slack',
                      'voltage angle')
        net.set_flags('bus',
                      'variable',
                      'any',
                      'voltage magnitude')

        # Generators
        net.set_flags('generator',
                      'variable',
                      'slack',
                      'active power')

        net.set_flags('generator',
                      'variable',
                      'regulator',
                      'reactive power')

        # VSC HVDC
        net.set_flags('vsc converter',
                      'variable',
                      'any',
                      ['dc power', 'active power', 'reactive power'])

        # CSC HVDC
        net.set_flags('csc converter',
                      'variable',
                      'any',
                      ['dc power', 'active power', 'reactive power'])

        # DC buses
        net.set_flags('dc bus',
                      'variable',
                      'any',
                      'voltage')

        # FACTS
        net.set_flags('facts',
                      'variable',
                      'any',
                      'all')

        # Loads
        if vdep_loads:
            for load in net.loads:
                if load.is_voltage_dependent() and load.is_in_service():
                    net.set_flags_of_component(load,
                                               'variable',
                                               ['active power', 'reactive power'])

        # Tap changers
        if tap_mode != self.CONTROL_MODE_LOCKED:
            net.set_flags('branch',
                          ['variable', 'fixed'],
                          'tap changer - v',
                          'tap ratio')

        # Switched shunts
        if shunt_mode != self.CONTROL_MODE_LOCKED:
            net.set_flags('shunt',
                          ['variable', 'fixed'],
                          'switching - v',
                          'susceptance')

        # Set up problem
        problem = pfnet.Problem(net)

        problem.add_constraint(pfnet.Constraint('AC power balance', net))
        problem.add_constraint(pfnet.Constraint('HVDC power balance', net))
        problem.add_constraint(pfnet.Constraint('generator active power participation', net))
        problem.add_constraint(pfnet.Constraint('variable fixing', net))
        problem.add_constraint(pfnet.Constraint('VSC converter equations', net))
        problem.add_constraint(pfnet.Constraint('CSC converter equations', net))
        problem.add_constraint(pfnet.Constraint('FACTS equations', net))
        problem.add_constraint(pfnet.Constraint('VSC DC voltage control', net))
        problem.add_constraint(pfnet.Constraint('CSC DC voltage control', net))
        problem.add_constraint(pfnet.Constraint('VSC DC power control', net))
        problem.add_constraint(pfnet.Constraint('CSC DC power control', net))
        problem.add_constraint(pfnet.Constraint('CSC DC current control', net))

        problem.add_constraint(pfnet.Constraint('PVPQ switching', net))
        problem.add_constraint(pfnet.Constraint('switching power factor regulation', net))
        problem.add_constraint(pfnet.Constraint('switching FACTS active power control', net))
        problem.add_constraint(pfnet.Constraint('switching FACTS reactive power control', net))

        if vdep_loads:
            problem.add_constraint(pfnet.Constraint('load voltage dependence', net))

        if Q_limits:
            problem.add_heuristic(pfnet.Heuristic('PVPQ switching', net))
            problem.add_heuristic(pfnet.Heuristic('switching power factor regulation', net))

        problem.analyze()

        # Check
        if (problem.J.shape[0] + problem.A.shape[0] != problem.get_num_primal_variables()):
            raise PFmethodError_BadProblem()

        # Return
        return problem
示例#12
0
            raise unittest.SkipTest('file not available')

        net = pf.ParserRAW().parse(case)

        # Voltages
        net.set_flags('bus', 'variable', 'not slack',
                      ['voltage magnitude', 'voltage angle'])

        # Gen active powers
        net.set_flags('generator', 'variable', 'slack', 'active power')

        # Gen reactive powers
        net.set_flags('generator', 'variable', 'slack', 'reactive power')

        # Set up problem
        problem = pf.Problem(net)
        problem.add_constraint(pf.Constraint('AC power balance', net))
        problem.add_constraint(
            pf.Constraint('generator active power participation', net))
        problem.add_constraint(pf.Constraint('PVPQ switching', net))
        problem.analyze()
        problem.eval(problem.get_init_point())

        # NR matrix - no HVDC
        M = bmat([[problem.A], [problem.J]])
        M = M.todense()
        self.assertEqual(np.linalg.matrix_rank(M), M.shape[0])

        # DC buses
        net.set_flags('dc bus', 'variable', 'any', 'voltage')