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

com.powsybl.matpower.model.MatpowerModel 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.matpower.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.*;

/**
 * @author Christian Biasuzzi {@literal }
 */
public class MatpowerModel {

    @JsonProperty("caseName")
    private String caseName;
    private double baseMva;
    private String version;

    private final List buses = new ArrayList<>();

    private final Map busByNum = new HashMap<>();

    private final List generators = new ArrayList<>();

    private final Map> generatorsByBusNum = new HashMap<>();

    private final List branches = new ArrayList<>();

    private final List dcLines = new ArrayList<>();

    @JsonCreator
    public MatpowerModel(@JsonProperty("caseName") String caseName) {
        this.caseName = Objects.requireNonNull(caseName);
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getCaseName() {
        return caseName;
    }

    public void setCaseName(String caseName) {
        this.caseName = Objects.requireNonNull(caseName);
    }

    public double getBaseMva() {
        return baseMva;
    }

    public void setBaseMva(double baseMva) {
        this.baseMva = baseMva;
    }

    public void addBus(MBus bus) {
        Objects.requireNonNull(bus);
        buses.add(bus);
        busByNum.put(bus.getNumber(), bus);
    }

    public List getBuses() {
        return buses;
    }

    public void setBuses(List buses) {
        Objects.requireNonNull(buses);
        this.buses.clear();
        for (MBus bus : buses) {
            addBus(bus);
        }
    }

    public MBus getBusByNum(int num) {
        return busByNum.get(num);
    }

    public List getGenerators() {
        return generators;
    }

    public void setGenerators(List generators) {
        Objects.requireNonNull(generators);
        this.generators.clear();
        for (MGen generator : generators) {
            addGenerator(generator);
        }
    }

    public void addGenerator(MGen generator) {
        Objects.requireNonNull(generator);
        generators.add(generator);
        generatorsByBusNum.computeIfAbsent(generator.getNumber(), k -> new ArrayList<>())
                .add(generator);
    }

    public List getGeneratorsByBusNum(int busNum) {
        return generatorsByBusNum.getOrDefault(busNum, Collections.emptyList());
    }

    public List getBranches() {
        return branches;
    }

    public void setBranches(List branches) {
        Objects.requireNonNull(branches);
        this.branches.clear();
        for (MBranch branch : branches) {
            addBranch(branch);
        }
    }

    public void addBranch(MBranch branch) {
        Objects.requireNonNull(branch);
        branches.add(branch);
    }

    public List getDcLines() {
        return dcLines;
    }

    public void addDcLine(MDcLine dcLine) {
        Objects.requireNonNull(dcLine);
        dcLines.add(dcLine);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy