Skip to content

Commit

Permalink
Merge pull request #5 from PowerGridModel/feature/vnf-skeleton
Browse files Browse the repository at this point in the history
Feature/vnf skeleton
  • Loading branch information
Laurynas-Jagutis authored Sep 23, 2024
2 parents e5c2d27 + 102693e commit 169272d
Show file tree
Hide file tree
Showing 23 changed files with 305 additions and 10 deletions.
10 changes: 10 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,34 @@ Checks: '
-*,
boost-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
cert-*,
clang-analyzer-*,
concurrency-*,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-reinterpret-cast,
darwin-*,
hiccp-*,
llvm-*,
-llvm-header-guard,
google-*,
-google-build-using-namespace,
-google-explicit-constructor
misc-*,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-avoid-c-arrays,
-modernize-use-trailing-return-type,
-modernize-use-nodiscard,
performance-*,
portability-*,
readability-*,
-readability-identifier-length,
-readability-magic-numbers,
'

WarningsAsErrors: '*'
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: 'true'

- name: Initialize and update submodules
run: |
git submodule update --init --recursive
- name: Install packages
run: |
sudo apt-get update
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: 'true'

- name: Initialize and update submodules
run: |
git submodule update --init --recursive
- name: Install packages
run: |
sudo apt-get update
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
submodules: 'true'
- name: Initialize and update submodules
run: |
git submodule update --init --recursive
- name: Install packages
run: |
sudo apt-get update
Expand Down
5 changes: 3 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MPL-2.0

[submodule "power-grid-model"]
path = power-grid-model
[submodule "deps/power-grid-model"]
path = deps/power-grid-model
url = [email protected]:PowerGridModel/power-grid-model.git
branch = main
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

include(GNUInstallDirs)

add_subdirectory("power-grid-model")
find_package(Eigen3 CONFIG REQUIRED)
find_package(Boost REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)

add_subdirectory("deps")

# add C library
add_subdirectory("power_grid_model_io_native_c")
Expand Down
6 changes: 6 additions & 0 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
#
# SPDX-License-Identifier: MPL-2.0

add_subdirectory("power-grid-model")

1 change: 1 addition & 0 deletions deps/power-grid-model
Submodule power-grid-model added at a05b88
1 change: 0 additions & 1 deletion power-grid-model
Submodule power-grid-model deleted from 560323
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

add_library(power_grid_model_io_native INTERFACE)

target_link_libraries(power_grid_model_io_native INTERFACE power_grid_model)

target_include_directories(power_grid_model_io_native INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")

target_link_libraries(power_grid_model_io_native INTERFACE power_grid_model)
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
//
// SPDX-License-Identifier: MPL-2.0

#pragma once
#ifndef POWER_GRID_MODEL_IO_NATIVE_C_VNF_PGM_CONVERTER_HPP
#define POWER_GRID_MODEL_IO_NATIVE_C_VNF_PGM_CONVERTER_HPP

#include <power_grid_model/auxiliary/dataset.hpp>
#include <power_grid_model/common/exception.hpp>

#include <iostream>

class PgmVnfConverter {
public:
PgmVnfConverter(char* buffer = nullptr, power_grid_model::WritableDataset* data = nullptr);

// Public member functions
void parse_vnf_file();
power_grid_model::ConstDataset const* convert_input(power_grid_model::ConstDataset const* dataset);

private:
// Private attributes
char* f_file_buffer;
power_grid_model::WritableDataset*
deserialized_data; // this type because it is generated by a deserializer type structure

// Private setters/getters
void set_file_buffer(char* file_buffer);

void set_deserialized_data(power_grid_model::WritableDataset* deserialized_data);

char* get_file_buffer();

power_grid_model::WritableDataset* get_deserialized_data();

// Private member functions
void convert_node_input();
void convert_line_input();
void convert_sources_input();
void convert_sym_loads_input();
void convert_shunts_input();
void convert_transformer_input();
void convert_sym_gens_input();
void convert_links_input();
};

inline PgmVnfConverter::PgmVnfConverter(char* buffer, power_grid_model::WritableDataset* data)
: f_file_buffer(buffer), deserialized_data(data) {
using namespace std::string_literals;
using power_grid_model::ExperimentalFeature;
throw ExperimentalFeature{"PGM_VNF_converter", ExperimentalFeature::TypeValuePair{.name = "PGM_VNF_conversion",
.value = std::to_string(1)}};
}

inline void PgmVnfConverter::parse_vnf_file() {
// the function should use a deserializer type structure
// will be implemented later
}

inline power_grid_model::ConstDataset const*
PgmVnfConverter::convert_input(power_grid_model::ConstDataset const* /*dataset*/) {
convert_node_input();
convert_line_input();
convert_sources_input();
convert_sym_loads_input();
convert_shunts_input();
convert_transformer_input();
convert_sym_gens_input();
convert_links_input();

// then return the buffer
// return pgm_input_data;
// for now.
power_grid_model::ConstDataset* fake_data = nullptr;
return fake_data;
}

inline void PgmVnfConverter::set_file_buffer(char* file_buffer) { this->f_file_buffer = file_buffer; }

inline void PgmVnfConverter::set_deserialized_data(power_grid_model::WritableDataset* data) {
this->deserialized_data = data;
}

inline char* PgmVnfConverter::get_file_buffer() { return this->f_file_buffer; }

inline power_grid_model::WritableDataset* PgmVnfConverter::get_deserialized_data() { return this->deserialized_data; }

inline void PgmVnfConverter::convert_node_input() {
// Implementation
}

inline void PgmVnfConverter::convert_line_input() {
// Implementation
}

inline void PgmVnfConverter::convert_sources_input() {
// Implementation
}

inline void PgmVnfConverter::convert_sym_loads_input() {
// Implementation
}

inline void PgmVnfConverter::convert_shunts_input() {
// Implementation
}

inline void PgmVnfConverter::convert_transformer_input() {
// Implementation
}

inline void PgmVnfConverter::convert_sym_gens_input() {
// Implementation
}

inline void PgmVnfConverter::convert_links_input() {
// Implementation
}

inline void parse_vnf_file_wrapper(PgmVnfConverter* obj) { obj->parse_vnf_file(); }

inline power_grid_model::ConstDataset const* convert_input_wrapper(PgmVnfConverter* obj,
power_grid_model::ConstDataset const* dataset) {
return obj->convert_input(dataset);
}

#endif // POWER_GRID_MODEL_IO_NATIVE_C_VNF_PGM_CONVERTER_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# C API library
add_library(power_grid_model_io_native_c SHARED
"src/handle.cpp"
"src/vnf_pgm_converter.cpp"
)

target_include_directories(power_grid_model_io_native_c PUBLIC
Expand All @@ -15,6 +16,7 @@ target_include_directories(power_grid_model_io_native_c PUBLIC
set(PGM_IO_NATIVE_PUBLIC_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_io_native_c/basics.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_io_native_c/handle.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_io_native_c/vnf_pgm_converter.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/power_grid_model_io_native_c.h"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@

#include "power_grid_model_io_native_c/basics.h"
#include "power_grid_model_io_native_c/handle.h"
#include "power_grid_model_io_native_c/vnf_pgm_converter.h"

#endif // POWER_GRID_MODEL_IO_NATIVE_C_H
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ typedef int32_t PGM_IO_ID;
// */
// typedef struct PGM_IO_VnfConverter PGM_IO_VnfConverter;

/**
* @brief Opaque struct for the VnfConverter class.
*
*/
typedef struct PGM_IO_VnfConverter PGM_IO_VnfConverter;

/**
* @brief Opaque struct for the ConstDataset.
*
*/
typedef struct PGM_IO_ConstDataset PGM_IO_ConstDataset;

/**
* @brief Opaque struct for the handle class.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
//
// SPDX-License-Identifier: MPL-2.0

#pragma once
#ifndef POWER_GRID_MODEL_IO_NATIVE_C_VNF_PGM_CONVERTER_H
#define POWER_GRID_MODEL_IO_NATIVE_C_VNF_PGM_CONVERTER_H

#include "basics.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Create the PGM_VNF_converter
* @param handle
* @param file_buffer A pointer to the null-terminated C string.
* @return The pointer to a PGM_VNF_converter instance. The instance must be freed by
* PGM_VNF_delete_Converter
*/
PGM_IO_API PGM_IO_VnfConverter* PGM_VNF_create_converter(PGM_IO_Handle* handle, char* file_buffer);

/**
* @brief Retrieve the transformed input data from .vnf format to PGM format
* @param handle
* @param converter_ptr A pointer to a PGM_VNF_converter instace.
* @param dataset A pointer to the const dataset supplied by the user.
* @return The pointer to the const dataset instance supplied by the user which has been filled in.
*/
PGM_IO_API PGM_IO_ConstDataset const* PGM_VNF_get_input_data(PGM_IO_Handle* handle, PGM_IO_VnfConverter* converter_ptr,
PGM_IO_ConstDataset const* dataset);

/**
* @brief Destroy the converter and free up the memory that was dedicated to it.
* @param converter_ptr A pointer to a PGM_VNF_converter instance.
*/
PGM_IO_API void PGM_VNF_delete_Converter(PGM_IO_VnfConverter* converter_ptr);

#ifdef __cplusplus
}
#endif

#endif // POWER_GRID_MODEL_IO_NATIVE_C_VNF_PGM_CONVERTER_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
//
// SPDX-License-Identifier: MPL-2.0

#define PGM_IO_DLL_EXPORTS

#include <power_grid_model_io_native/vnf_converter/vnf_pgm_converter.hpp>

#include "handle.hpp"
#include <power_grid_model_io_native_c/basics.h>
#include <power_grid_model_io_native_c/vnf_pgm_converter.h>

#include <power_grid_model/auxiliary/dataset.hpp>

using power_grid_model::ConstDataset;

// TODO(Laurynas-Jagutis) add call_with_catch for these functions
PGM_IO_VnfConverter* PGM_VNF_create_converter(const PGM_IO_Handle* /*handle*/, char* file_buffer) {
auto* converter = new PgmVnfConverter(file_buffer);
parse_vnf_file_wrapper(converter);
return reinterpret_cast<PGM_IO_VnfConverter*>(converter);
}

PGM_IO_ConstDataset const* PGM_VNF_get_input_data(const PGM_IO_Handle* /*handle*/, PGM_IO_VnfConverter* converter_ptr,
PGM_IO_ConstDataset const* dataset) {
auto* converter = reinterpret_cast<PgmVnfConverter*>(converter_ptr);
auto const* data = reinterpret_cast<ConstDataset const*>(dataset);
convert_input_wrapper(converter, data);
return reinterpret_cast<PGM_IO_ConstDataset const*>(data);
}

void PGM_VNF_delete_Converter(PGM_IO_VnfConverter* converter_ptr) {
auto* converter = reinterpret_cast<PgmVnfConverter*>(converter_ptr);
delete converter;
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ignore_missing_imports = true
show_column_numbers = true
non_interactive = true
install_types = true
exclude = "power-grid-model/"
exclude = "deps/power-grid-model/"

# CI build options
[tool.cibuildwheel]
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def generate_build_ext(pkg_dir: Path, pkg_name: str):
pgm_io_c = Path("power_grid_model_io_native_c")
pgm = Path("power_grid_model")
pgm_c = Path("power_grid_model_c")
pgm_pkg_dir = pkg_dir / str(pgm).replace("_", "-")
deps = Path("deps")
pgm_pkg_dir = pkg_dir / deps / str(pgm).replace("_", "-")

# include-folders
include_dirs = [
Expand Down
1 change: 1 addition & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sonar.sourceEncoding=UTF-8
sonar.issue.ignore.allfile=a1
sonar.issue.ignore.allfile.a1.fileRegexp='.*#include.*doctest\.h[>"].*'
sonar.coverage.exclusions="tests/**/*"
sonar.coverage.exclusions=power_grid_model_io_native_c/power_grid_model_io_native/include/power_grid_model_io_native/vnf_converter/vnf_pgm_converter.hpp,power_grid_model_io_native_c/power_grid_model_io_native_c/src/vnf_pgm_converter.cpp
sonar.cpd.exclusions="tests/**/*"
sonar.cfamily.threads=1
sonar.coverageReportPaths=cpp_coverage.xml
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ find_package(doctest REQUIRED)
include("${doctest_DIR}/doctest.cmake")

add_subdirectory("c_api_tests")
add_subdirectory("cpp_unit_tests")
Loading

0 comments on commit 169272d

Please sign in to comment.