All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.powsybl.openloadflow.network.NetworkState Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2022, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * SPDX-License-Identifier: MPL-2.0
 */
package com.powsybl.openloadflow.network;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @author Geoffroy Jamgotchian {@literal }
 */
public class NetworkState {

    private static final Logger LOGGER = LoggerFactory.getLogger(NetworkState.class);

    private final LfNetwork network;

    private final List busStates;

    private final List branchStates;

    private final List hvdcStates;

    private final Set excludedSlackBuses;

    protected NetworkState(LfNetwork network, List busStates, List branchStates, List hvdcStates,
                           Set excludedSlackBuses) {
        this.network = Objects.requireNonNull(network);
        this.busStates = Objects.requireNonNull(busStates);
        this.branchStates = Objects.requireNonNull(branchStates);
        this.hvdcStates = Objects.requireNonNull(hvdcStates);
        this.excludedSlackBuses = Objects.requireNonNull(excludedSlackBuses);
    }

    public static NetworkState save(LfNetwork network) {
        Objects.requireNonNull(network);
        LOGGER.trace("Saving network state");
        network.setGeneratorsInitialTargetPToTargetP();
        List busStates = ElementState.save(network.getBuses(), BusState::save);
        List branchStates = ElementState.save(network.getBranches(), BranchState::save);
        List hvdcStates = ElementState.save(network.getHvdcs(), HvdcState::save);
        return new NetworkState(network, busStates, branchStates, hvdcStates, network.getExcludedSlackBuses());
    }

    public void restore() {
        LOGGER.trace("Restoring network state");
        ElementState.restore(busStates);
        ElementState.restore(branchStates);
        ElementState.restore(hvdcStates);
        network.setExcludedSlackBuses(excludedSlackBuses);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy