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

com.powsybl.flow_decomposition.FlowComputerUtils Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2024, Coreso SA (https://www.coreso.eu/) and TSCNET Services GmbH (https://www.tscnet.eu/)
 * 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.flow_decomposition;

import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.TwoSides;

import java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Sebastien Murgey {@literal }
 * @author Hugo Schindler {@literal }
 * @author Guillaume Verger {@literal }
 * @author Caio Luke {@literal }
 */
public final class FlowComputerUtils {

    private FlowComputerUtils() {
        // empty constructor
    }

    public static Map calculateAcTerminalReferenceFlows(Collection xnecList, boolean fallbackHasBeenActivated, TwoSides side) {
        return fallbackHasBeenActivated ? getFallbackActivatedTerminalResults(xnecList) : getTerminalReferenceFlow(xnecList, side);
    }

    public static Map getTerminalReferenceFlow(Collection xnecList, TwoSides side) {
        return xnecList.stream()
                .collect(Collectors.toMap(
                        Identifiable::getId,
                        branch -> branch.getTerminal(side).getP()
                ));
    }

    public static Map calculateAcTerminalCurrents(Collection xnecList, boolean fallbackHasBeenActivated, TwoSides side) {
        return fallbackHasBeenActivated ? getFallbackActivatedTerminalResults(xnecList) : getTerminalCurrent(xnecList, side);
    }

    public static Map getTerminalCurrent(Collection xnecList, TwoSides side) {
        return xnecList.stream()
                .collect(Collectors.toMap(
                        Identifiable::getId,
                        branch -> branch.getTerminal(side).getI()
                ));
    }

    private static Map getFallbackActivatedTerminalResults(Collection xnecList) {
        return xnecList.stream().collect(Collectors.toMap(Identifiable::getId, branch -> Double.NaN));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy