示例#1
0
def env():
    net = Network.load('net/net_test.yaml')
    env = gym.make('openmodelica_microgrid_gym:ModelicaEnv_test-v1',
                   viz_mode=None,
                   model_path='omg_grid/test.fmu',
                   max_episode_steps=100,
                   net=net)

    return env, net.in_vars(), flatten(net.out_vars())
def test_load():
    Network.load('net/net_valid.yaml')
    assert True
def test_load_dup_inputs():
    with pytest.raises(ValueError):
        Network.load('net/net_dupinputs.yaml')
from matplotlib import pyplot as plt

from openmodelica_microgrid_gym import Runner
from openmodelica_microgrid_gym.agents import StaticControlAgent
from openmodelica_microgrid_gym.aux_ctl import PI_params, DroopParams, MultiPhaseDQ0PIPIController, \
    MultiPhaseDQCurrentController, InverseDroopParams, PLLParams
from openmodelica_microgrid_gym.env import PlotTmpl
from openmodelica_microgrid_gym.net import Network

# Simulation definitions
max_episode_steps = 3000  # number of simulation steps per episode
num_episodes = 1  # number of simulation episodes
# (here, only 1 episode makes sense since simulation conditions don't change in this example)
DroopGain = 40000.0  # virtual droop gain for active power / W/Hz
QDroopGain = 1000.0  # virtual droop gain for reactive power / VAR/V
net = Network.load('../net/net.yaml')
delta_t = net.ts  # simulation time step size / s
freq_nom = net.freq_nom  # nominal grid frequency / Hz
v_nom = net.v_nom  # nominal grid voltage / V
v_DC = net[
    'inverter1'].v_DC  # DC-link voltage / V; will be set as model parameter in the FMU
i_lim = net['inverter1'].i_lim  # inverter current limit / A
i_nom = net['inverter1'].i_nom  # nominal inverter current / A

logging.basicConfig()


def load_step(t, gain):
    """
    Doubles the load parameters
    :param t:
示例#5
0
from openmodelica_microgrid_gym.util import FullHistory

include_simulate = True
show_plots = False
balanced_load = False
do_measurement = False
save_results = True

current_directory = os.getcwd()
save_folder = os.path.join(current_directory, r'4Dtest1')
os.makedirs(save_folder, exist_ok=True)

np.random.seed(1)

# Simulation definitions
net = Network.load('../../net/net_single-inv-Paper_Loadstep.yaml')
delta_t = 1e-4  # simulation time step size / s
undersample = 1
max_episode_steps = 2000  # number of simulation steps per episode
num_episodes = 1  # number of simulation episodes (i.e. SafeOpt iterations)
n_MC = 1  # number of Monte-Carlo samples for simulation - samples device parameters (e.g. L,R, noise) from
v_DC = 600  # DC-link voltage / V; will be set as model parameter in the FMU
nomFreq = 60  # nominal grid frequency / Hz
nomVoltPeak = 169.7  # 230 * 1.414  # nominal grid voltage / V
iLimit = 16  # inverter current limit / A
iNominal = 12  # nominal inverter current / A
vNominal = 190  # nominal inverter current / A
vLimit = vNominal * 1.5  # inverter current limit / A
funnelFactor = 0.02
vFunnel = np.array([
    vNominal * funnelFactor, vNominal * funnelFactor, vNominal * funnelFactor
示例#6
0
from openmodelica_microgrid_gym import Runner
from openmodelica_microgrid_gym.agents import SafeOptAgent
from openmodelica_microgrid_gym.agents.util import MutableFloat
from openmodelica_microgrid_gym.aux_ctl import PI_params, DroopParams, MultiPhaseDQ0PIPIController
from openmodelica_microgrid_gym.env import PlotTmpl
from openmodelica_microgrid_gym.net import Network
from openmodelica_microgrid_gym.util import dq0_to_abc, nested_map, FullHistory

# Simulation definitions
max_episode_steps = 300  # number of simulation steps per episode
num_episodes = 2  # number of simulation episodes (i.e. SafeOpt iterations)
mu = 2  # factor for barrier function (see below)
DroopGain = 40000.0  # virtual droop gain for active power / W/Hz
QDroopGain = 1000.0  # virtual droop gain for reactive power / VAR/V
net = Network.load('../net/net_single-inv-volt.yaml')
i_lim = net['inverter1'].i_lim  # inverter current limit / A
i_nom = net['inverter1'].i_nom  # nominal inverter current / A

# Files saves results and  resulting plots to the folder saves_VI_control_safeopt in the current directory
current_directory = os.getcwd()
save_folder = os.path.join(current_directory, r'saves_VI_control_safeopt')
os.makedirs(save_folder, exist_ok=True)


class Reward:
    def __init__(self):
        self._idx = None

    def set_idx(self, obs):
        if self._idx is None:
示例#7
0
# - Ki: 1D example: Only the integral gain Ki of the PI controller is adjusted
# - Kpi: 2D example: Kp and Ki are adjusted simultaneously

adjust = 'Kpi'

# Check if really only one simulation scenario was selected
if adjust not in {'Kp', 'Ki', 'Kpi'}:
    raise ValueError(
        "Please set 'adjust' to one of the following values: 'Kp', 'Ki', 'Kpi'"
    )

# Simulation definitions
max_episode_steps = 600  # number of simulation steps per episode
num_episodes = 10  # number of simulation episodes (i.e. SafeOpt iterations)
mu = 2  # factor for barrier function (see below)
net = Network.load('../net/net_single-inv-curr.yaml')
i_lim = net['inverter1'].i_lim  # inverter current limit / A
i_nom = net['inverter1'].i_nom  # nominal inverter current / A
i_ref = np.array(net['inverter1'].i_ref
                 )  # exemplary set point i.e. id = 15, iq = 0, i0 = 0 / A


class Reward:
    def __init__(self):
        self._idx = None

    def set_idx(self, obs):
        if self._idx is None:
            self._idx = nested_map(lambda n: obs.index(n),
                                   [[f'lc1.inductor{k}.i'
                                     for k in '123'], 'master.phase',
include_simulate = True
show_plots = True
balanced_load = True
do_measurement = False
save_results = False

# Files saves results and  resulting plots to the folder saves_VI_control_safeopt in the current directory
current_directory = os.getcwd()
save_folder = os.path.join(current_directory, r'../1Test')
os.makedirs(save_folder, exist_ok=True)

np.random.seed(1)

# Simulation definitions
net = Network.load('../../net/net_single-inv-curr_Paper_SC.yaml')
delta_t = 1e-4  # simulation time step size / s
undersample = 1  # undersampling of controller
max_episode_steps = 1000  # number of simulation steps per episode
num_episodes = 1  # number of simulation episodes (i.e. SafeOpt iterations)
n_MC = 1  # number of Monte-Carlo samples for simulation - samples device parameters (e.g. L,R, noise) from
iLimit = 16  # inverter current limit / A
iNominal = 12  # nominal inverter current / A
mu = 80  # factor for barrier function (see below)
i_ref1 = np.array([10, 0, 0])  # exemplary set point i.e. id = 10, iq = 0, i0 = 0 / A
i_ref2 = np.array([5, 0, 0])  # exemplary set point i.e. id = 15, iq = 0, i0 = 0 / A

# plant
L = 2.3e-3  # / H
R = 400e-3  # / Ohm