powsybl / powsybl-core

A framework to build power system oriented software
https://www.powsybl.org
Mozilla Public License 2.0
123 stars 39 forks source link

Generate a custom comment in UCTE files header #1115

Open murgeyseb opened 4 years ago

murgeyseb commented 4 years ago

The comment block (##C) at the top of data should describe at least the provider of the file.

Though it is important that a PowSyBl user can add a comment in the header part of UCTE file exported to define the provider of the file.

jlabous commented 4 years ago

Do we need to add a Property "provider" to the exporter to let the prossibility to change it ?

mathbagu commented 4 years ago

@murgeyseb How should we implement this?

Do we add a property to the UCTEExporter to give the name of the implementation (that overrides the config.yml file), like it's possible with the naming strategy?

Do we introduce export post-processor mechanism: a groovy script could be executed just after the conversion IIDM -> UCTE based on two binded variables (network and ucteNetwork)? This one is very flexible.

murgeyseb commented 4 years ago

The second possibility could be really nice for other purpose too. If it is possible it would be the prefered solution on my side.

mathbagu commented 4 years ago

@jlabous I will try to explain you what we expect as a UCTE export post-processor:

Post-processors is a concept that already exists in powsybl. It's mainly used to complete the conversion of a grid from a format to IIDM. The idea there, is to provide the same kind of mechanism for the UCTE export. I propose to add a UcteExportPostProcessor interface and an implementation based on a groovy script so that @murgeyseb could update the header of the UCTE network just before its export.

The interface looks like this:

public interface UcteExportPostProcessor {
    public String getName();
    public void process(Network network, UcteNetwork ucteNetwork);
}

The groovy implementation should look like the GroovyScriptPostProcessor. You have to bind both the network and the ucteNetwork, and execute the script:

    @Override
    public void process(Network network, UcteNetwork ucteNetwork) throws Exception {
        if (Files.exists(script)) {
            LOGGER.debug("Execute groovy post processor {}", script);
            try (Reader reader = Files.newBufferedReader(script, StandardCharsets.UTF_8)) {
                CompilerConfiguration conf = new CompilerConfiguration();

                Binding binding = new Binding();
                binding.setVariable("network", network);
                binding.setVariable("ucteNetwork", ucteNetwork);

                GroovyShell shell = new GroovyShell(binding, conf);
                shell.evaluate(reader);
            }
        }
    }