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

com.powsybl.openloadflow.network.util.ParticipatingElement Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2020, 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.util;

import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfGenerator;
import com.powsybl.openloadflow.network.LfLoad;

import java.util.List;

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

    private final Object element;

    private double factor;

    public ParticipatingElement(Object element, double factor) {
        this.element = element;
        this.factor = factor;
    }

    public Object getElement() {
        return element;
    }

    public double getFactor() {
        return factor;
    }

    public double getTargetP() {
        if (element instanceof LfGenerator generator) {
            return generator.getTargetP();
        } else if (element instanceof LfLoad load) {
            return load.getTargetP();
        } else {
            return Double.NaN;
        }
    }

    public static double participationFactorNorm(List participatingElements) {
        return participatingElements.stream()
                .mapToDouble(participatingElement -> participatingElement.factor)
                .sum();
    }

    public static void normalizeParticipationFactors(List participatingElements) {
        double factorSum = participationFactorNorm(participatingElements);
        for (ParticipatingElement participatingElement : participatingElements) {
            participatingElement.factor /= factorSum;
        }
    }

    public LfBus getLfBus() {
        if (element instanceof LfGenerator generator) {
            return generator.getBus();
        } else if (element instanceof LfLoad load) {
            return load.getBus();
        } else {
            return null;
        }
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy