power-grid-model 1.10.17__py3-none-win_amd64.whl → 1.12.119__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of power-grid-model might be problematic. Click here for more details.
- power_grid_model/__init__.py +54 -29
- power_grid_model/_core/__init__.py +3 -3
- power_grid_model/_core/buffer_handling.py +507 -478
- power_grid_model/_core/data_handling.py +195 -141
- power_grid_model/_core/data_types.py +142 -0
- power_grid_model/_core/dataset_definitions.py +109 -109
- power_grid_model/_core/enum.py +226 -0
- power_grid_model/_core/error_handling.py +215 -198
- power_grid_model/_core/errors.py +134 -0
- power_grid_model/_core/index_integer.py +17 -17
- power_grid_model/_core/options.py +71 -69
- power_grid_model/_core/power_grid_core.py +577 -562
- power_grid_model/_core/power_grid_dataset.py +545 -490
- power_grid_model/_core/power_grid_meta.py +262 -244
- power_grid_model/_core/power_grid_model.py +1025 -687
- power_grid_model/_core/power_grid_model_c/__init__.py +3 -0
- power_grid_model/_core/power_grid_model_c/bin/power_grid_model_c.dll +0 -0
- power_grid_model/_core/power_grid_model_c/get_pgm_dll_path.py +63 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/basics.h +251 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/buffer.h +108 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/dataset.h +332 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/dataset_definitions.h +1060 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/handle.h +111 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/meta_data.h +189 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/model.h +130 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/options.h +142 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c/serialization.h +118 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_c.h +36 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/basics.hpp +65 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/buffer.hpp +61 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/dataset.hpp +224 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/handle.hpp +108 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/meta_data.hpp +84 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/model.hpp +63 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/options.hpp +52 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/serialization.hpp +124 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp/utils.hpp +81 -0
- power_grid_model/_core/power_grid_model_c/include/power_grid_model_cpp.hpp +19 -0
- power_grid_model/_core/power_grid_model_c/lib/cmake/power_grid_model/power_grid_modelConfig.cmake +37 -0
- power_grid_model/_core/power_grid_model_c/lib/cmake/power_grid_model/power_grid_modelConfigVersion.cmake +65 -0
- power_grid_model/_core/power_grid_model_c/lib/cmake/power_grid_model/power_grid_modelTargets-release.cmake +19 -0
- power_grid_model/_core/power_grid_model_c/lib/cmake/power_grid_model/power_grid_modelTargets.cmake +144 -0
- power_grid_model/_core/power_grid_model_c/lib/power_grid_model_c.lib +0 -0
- power_grid_model/_core/power_grid_model_c/share/LICENSE +292 -0
- power_grid_model/_core/power_grid_model_c/share/README.md +15 -0
- power_grid_model/_core/serialization.py +319 -317
- power_grid_model/_core/typing.py +20 -0
- power_grid_model/{_utils.py → _core/utils.py} +798 -783
- power_grid_model/data_types.py +321 -319
- power_grid_model/enum.py +27 -214
- power_grid_model/errors.py +37 -119
- power_grid_model/typing.py +43 -48
- power_grid_model/utils.py +529 -400
- power_grid_model/validation/__init__.py +25 -10
- power_grid_model/validation/{rules.py → _rules.py} +1167 -962
- power_grid_model/validation/{validation.py → _validation.py} +1172 -1015
- power_grid_model/validation/assertions.py +93 -92
- power_grid_model/validation/errors.py +602 -524
- power_grid_model/validation/utils.py +313 -318
- {power_grid_model-1.10.17.dist-info → power_grid_model-1.12.119.dist-info}/METADATA +162 -165
- power_grid_model-1.12.119.dist-info/RECORD +65 -0
- {power_grid_model-1.10.17.dist-info → power_grid_model-1.12.119.dist-info}/WHEEL +1 -1
- power_grid_model-1.12.119.dist-info/entry_points.txt +3 -0
- power_grid_model/_core/_power_grid_core.dll +0 -0
- power_grid_model-1.10.17.dist-info/RECORD +0 -32
- power_grid_model-1.10.17.dist-info/top_level.txt +0 -1
- {power_grid_model-1.10.17.dist-info → power_grid_model-1.12.119.dist-info/licenses}/LICENSE +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @mainpage Power Grid Model C API Documentation
|
|
7
|
+
* This gives an overview of C API.
|
|
8
|
+
* All the exported functions are included in power_grid_model_c.h, except the dataset definitions
|
|
9
|
+
*
|
|
10
|
+
* Users can also include individual headers for a subset of the functionality
|
|
11
|
+
* - power_grid_model_c/basics.h: type and enum definition
|
|
12
|
+
* - power_grid_model_c/buffer.h: functions with buffer creation, release, set and get value
|
|
13
|
+
* - power_grid_model_c/handle.h: functions with error handling
|
|
14
|
+
* - power_grid_model_c/meta_data.h: functions with meta data
|
|
15
|
+
* - power_grid_model_c/model.h: functions with create, release, run calculation of model
|
|
16
|
+
* - power_grid_model_c/options.h: functions with setting the calculation options
|
|
17
|
+
* - power_grid_model_c/serialization.h: functions with serialization functions
|
|
18
|
+
* - power_grid_model_c/dataset.h: functions with dataset handling functions
|
|
19
|
+
* - power_grid_model_c/dataset_definitions.h: external pointer variables to all datasets, components, and
|
|
20
|
+
* attributes. You have to include this header separately. It is not included by power_grid_model_c.h.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
#pragma once
|
|
24
|
+
#ifndef POWER_GRID_MODEL_C_H
|
|
25
|
+
#define POWER_GRID_MODEL_C_H
|
|
26
|
+
|
|
27
|
+
#include "power_grid_model_c/basics.h"
|
|
28
|
+
#include "power_grid_model_c/buffer.h"
|
|
29
|
+
#include "power_grid_model_c/dataset.h"
|
|
30
|
+
#include "power_grid_model_c/handle.h"
|
|
31
|
+
#include "power_grid_model_c/meta_data.h"
|
|
32
|
+
#include "power_grid_model_c/model.h"
|
|
33
|
+
#include "power_grid_model_c/options.h"
|
|
34
|
+
#include "power_grid_model_c/serialization.h"
|
|
35
|
+
|
|
36
|
+
#endif // POWER_GRID_MODEL_C_H
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
#ifndef POWER_GRID_MODEL_CPP_BASICS_HPP
|
|
7
|
+
#define POWER_GRID_MODEL_CPP_BASICS_HPP
|
|
8
|
+
|
|
9
|
+
#ifdef PGM_DLL_EXPORTS
|
|
10
|
+
#error \
|
|
11
|
+
"Cannot export out-of-line PGM C API symbols from the inline header-only PGM C++ API. Please disable PGM_DLL_EXPORT."
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#ifndef PGM_ENABLE_EXPERIMENTAL
|
|
15
|
+
#error "This is an experimental feature. Please #define PGM_ENABLE_EXPERIMENTAL to use this."
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
#include "power_grid_model_c/basics.h"
|
|
19
|
+
|
|
20
|
+
#include <cassert>
|
|
21
|
+
#include <exception>
|
|
22
|
+
#include <memory>
|
|
23
|
+
#include <string>
|
|
24
|
+
#include <vector>
|
|
25
|
+
|
|
26
|
+
namespace power_grid_model_cpp {
|
|
27
|
+
|
|
28
|
+
using Idx = PGM_Idx;
|
|
29
|
+
using ID = PGM_ID;
|
|
30
|
+
using IntS = int8_t;
|
|
31
|
+
|
|
32
|
+
using PowerGridModel = PGM_PowerGridModel;
|
|
33
|
+
using MetaDataset = PGM_MetaDataset;
|
|
34
|
+
using MetaComponent = PGM_MetaComponent;
|
|
35
|
+
using MetaAttribute = PGM_MetaAttribute;
|
|
36
|
+
using RawHandle = PGM_Handle;
|
|
37
|
+
using RawDataPtr = void*; // raw mutable data ptr
|
|
38
|
+
using RawDataConstPtr = void const*; // raw read-only data ptr
|
|
39
|
+
using RawConstDataset = PGM_ConstDataset;
|
|
40
|
+
using RawMutableDataset = PGM_MutableDataset;
|
|
41
|
+
using RawWritableDataset = PGM_WritableDataset;
|
|
42
|
+
using RawDatasetInfo = PGM_DatasetInfo;
|
|
43
|
+
using RawOptions = PGM_Options;
|
|
44
|
+
using RawDeserializer = PGM_Deserializer;
|
|
45
|
+
using RawSerializer = PGM_Serializer;
|
|
46
|
+
|
|
47
|
+
namespace detail {
|
|
48
|
+
// custom deleter
|
|
49
|
+
template <auto func> struct DeleterFunctor {
|
|
50
|
+
template <typename T> void operator()(T* arg) const { func(arg); }
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// unique pointer definition
|
|
54
|
+
template <typename T, auto func> class UniquePtr : public std::unique_ptr<T, DeleterFunctor<func>> {
|
|
55
|
+
public:
|
|
56
|
+
using std::unique_ptr<T, DeleterFunctor<func>>::unique_ptr;
|
|
57
|
+
using std::unique_ptr<T, DeleterFunctor<func>>::operator=;
|
|
58
|
+
T* get() { return static_cast<std::unique_ptr<T, DeleterFunctor<func>>&>(*this).get(); }
|
|
59
|
+
T const* get() const { return static_cast<std::unique_ptr<T, DeleterFunctor<func>> const&>(*this).get(); }
|
|
60
|
+
};
|
|
61
|
+
} // namespace detail
|
|
62
|
+
|
|
63
|
+
} // namespace power_grid_model_cpp
|
|
64
|
+
|
|
65
|
+
#endif // POWER_GRID_MODEL_CPP_BASICS_HPP
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
#ifndef POWER_GRID_MODEL_CPP_BUFFER_HPP
|
|
7
|
+
#define POWER_GRID_MODEL_CPP_BUFFER_HPP
|
|
8
|
+
|
|
9
|
+
#include "basics.hpp"
|
|
10
|
+
#include "handle.hpp"
|
|
11
|
+
|
|
12
|
+
#include "power_grid_model_c/buffer.h"
|
|
13
|
+
|
|
14
|
+
namespace power_grid_model_cpp {
|
|
15
|
+
class Buffer {
|
|
16
|
+
public:
|
|
17
|
+
Buffer(MetaComponent const* component, Idx size)
|
|
18
|
+
: component_{component}, size_{size}, buffer_{handle_.call_with(PGM_create_buffer, component, size)} {};
|
|
19
|
+
|
|
20
|
+
RawDataConstPtr get() const { return buffer_.get(); }
|
|
21
|
+
RawDataPtr get() { return buffer_.get(); }
|
|
22
|
+
|
|
23
|
+
Idx size() const { return size_; }
|
|
24
|
+
|
|
25
|
+
void set_nan() { set_nan(0, size_); }
|
|
26
|
+
void set_nan(Idx buffer_offset) { set_nan(buffer_offset, 1); }
|
|
27
|
+
void set_nan(Idx buffer_offset, Idx size) {
|
|
28
|
+
handle_.call_with(PGM_buffer_set_nan, component_, get(), buffer_offset, size);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void set_value(MetaAttribute const* attribute, RawDataConstPtr src_ptr, Idx src_stride) {
|
|
32
|
+
set_value(attribute, src_ptr, 0, size_, src_stride);
|
|
33
|
+
}
|
|
34
|
+
void set_value(MetaAttribute const* attribute, RawDataConstPtr src_ptr, Idx buffer_offset, Idx src_stride) {
|
|
35
|
+
set_value(attribute, src_ptr, buffer_offset, 1, src_stride);
|
|
36
|
+
}
|
|
37
|
+
void set_value(MetaAttribute const* attribute, RawDataConstPtr src_ptr, Idx buffer_offset, Idx size,
|
|
38
|
+
Idx src_stride) {
|
|
39
|
+
handle_.call_with(PGM_buffer_set_value, attribute, get(), src_ptr, buffer_offset, size, src_stride);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void get_value(MetaAttribute const* attribute, RawDataPtr dest_ptr, Idx dest_stride) const {
|
|
43
|
+
get_value(attribute, dest_ptr, 0, size_, dest_stride);
|
|
44
|
+
}
|
|
45
|
+
void get_value(MetaAttribute const* attribute, RawDataPtr dest_ptr, Idx buffer_offset, Idx dest_stride) const {
|
|
46
|
+
get_value(attribute, dest_ptr, buffer_offset, 1, dest_stride);
|
|
47
|
+
}
|
|
48
|
+
void get_value(MetaAttribute const* attribute, RawDataPtr dest_ptr, Idx buffer_offset, Idx size,
|
|
49
|
+
Idx dest_stride) const {
|
|
50
|
+
handle_.call_with(PGM_buffer_get_value, attribute, get(), dest_ptr, buffer_offset, size, dest_stride);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private:
|
|
54
|
+
Handle handle_{};
|
|
55
|
+
MetaComponent const* component_;
|
|
56
|
+
Idx size_;
|
|
57
|
+
detail::UniquePtr<void, &PGM_destroy_buffer> buffer_;
|
|
58
|
+
};
|
|
59
|
+
} // namespace power_grid_model_cpp
|
|
60
|
+
|
|
61
|
+
#endif // POWER_GRID_MODEL_CPP_BUFFER_HPP
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
#ifndef POWER_GRID_MODEL_CPP_DATASET_HPP
|
|
7
|
+
#define POWER_GRID_MODEL_CPP_DATASET_HPP
|
|
8
|
+
|
|
9
|
+
#include "basics.hpp"
|
|
10
|
+
#include "buffer.hpp"
|
|
11
|
+
#include "handle.hpp"
|
|
12
|
+
|
|
13
|
+
#include "power_grid_model_c/dataset.h"
|
|
14
|
+
|
|
15
|
+
namespace power_grid_model_cpp {
|
|
16
|
+
class ComponentTypeNotFound : public PowerGridError {
|
|
17
|
+
public:
|
|
18
|
+
ComponentTypeNotFound(std::string const& component)
|
|
19
|
+
: PowerGridError{[&]() {
|
|
20
|
+
using namespace std::string_literals;
|
|
21
|
+
return "ComponentType"s + component + " not found"s;
|
|
22
|
+
}()} {}
|
|
23
|
+
ComponentTypeNotFound(std::string_view component) : ComponentTypeNotFound{std::string{component}} {}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
class DatasetInfo {
|
|
27
|
+
|
|
28
|
+
public:
|
|
29
|
+
DatasetInfo(RawDatasetInfo const* info) noexcept : info_{info} {}
|
|
30
|
+
DatasetInfo(DatasetInfo&&) = default;
|
|
31
|
+
DatasetInfo& operator=(DatasetInfo&&) = default;
|
|
32
|
+
DatasetInfo(DatasetInfo const&) = delete; // No copy constructor
|
|
33
|
+
DatasetInfo& operator=(DatasetInfo const&) = delete; // No copy assignment
|
|
34
|
+
~DatasetInfo() = default;
|
|
35
|
+
|
|
36
|
+
std::string name() const { return std::string{handle_.call_with(PGM_dataset_info_name, info_)}; }
|
|
37
|
+
|
|
38
|
+
bool is_batch() const { return handle_.call_with(PGM_dataset_info_is_batch, info_) != 0; }
|
|
39
|
+
|
|
40
|
+
Idx batch_size() const { return handle_.call_with(PGM_dataset_info_batch_size, info_); }
|
|
41
|
+
|
|
42
|
+
Idx n_components() const { return handle_.call_with(PGM_dataset_info_n_components, info_); }
|
|
43
|
+
|
|
44
|
+
std::string component_name(Idx component_idx) const {
|
|
45
|
+
return std::string{handle_.call_with(PGM_dataset_info_component_name, info_, component_idx)};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Idx component_elements_per_scenario(Idx component_idx) const {
|
|
49
|
+
return handle_.call_with(PGM_dataset_info_elements_per_scenario, info_, component_idx);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Idx component_total_elements(Idx component_idx) const {
|
|
53
|
+
return handle_.call_with(PGM_dataset_info_total_elements, info_, component_idx);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Idx component_idx(std::string_view component) const {
|
|
57
|
+
Idx const n_comp = n_components();
|
|
58
|
+
for (Idx idx = 0; idx < n_comp; ++idx) {
|
|
59
|
+
if (component_name(idx) == component) {
|
|
60
|
+
return idx;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
throw ComponentTypeNotFound{component};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
bool has_attribute_indications(Idx component_idx) const {
|
|
67
|
+
return handle_.call_with(PGM_dataset_info_has_attribute_indications, info_, component_idx) != 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
std::vector<std::string> attribute_indications(Idx component_idx) const {
|
|
71
|
+
Idx const n_attributes = handle_.call_with(PGM_dataset_info_n_attribute_indications, info_, component_idx);
|
|
72
|
+
std::vector<std::string> attributes;
|
|
73
|
+
attributes.reserve(n_attributes);
|
|
74
|
+
for (Idx idx = 0; idx < n_attributes; ++idx) {
|
|
75
|
+
attributes.emplace_back(handle_.call_with(PGM_dataset_info_attribute_name, info_, component_idx, idx));
|
|
76
|
+
}
|
|
77
|
+
return attributes;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private:
|
|
81
|
+
Handle handle_{};
|
|
82
|
+
RawDatasetInfo const* info_;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
class DatasetWritable {
|
|
86
|
+
public:
|
|
87
|
+
DatasetWritable(RawWritableDataset* dataset)
|
|
88
|
+
: dataset_{dataset}, info_{handle_.call_with(PGM_dataset_writable_get_info, dataset_)} {}
|
|
89
|
+
DatasetWritable(DatasetWritable&&) = default;
|
|
90
|
+
DatasetWritable& operator=(DatasetWritable&&) = default;
|
|
91
|
+
DatasetWritable(DatasetWritable const&) = delete; // No copy constructor
|
|
92
|
+
DatasetWritable& operator=(DatasetWritable const&) = delete; // No copy assignment
|
|
93
|
+
~DatasetWritable() = default;
|
|
94
|
+
|
|
95
|
+
RawWritableDataset const* get() const { return dataset_; }
|
|
96
|
+
RawWritableDataset* get() { return dataset_; }
|
|
97
|
+
|
|
98
|
+
DatasetInfo const& get_info() const { return info_; }
|
|
99
|
+
|
|
100
|
+
void set_buffer(std::string const& component, Idx* indptr, RawDataPtr data) {
|
|
101
|
+
handle_.call_with(PGM_dataset_writable_set_buffer, get(), component.c_str(), indptr, data);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
void set_buffer(std::string const& component, Idx* indptr, Buffer& data) {
|
|
105
|
+
handle_.call_with(PGM_dataset_writable_set_buffer, get(), component.c_str(), indptr, data.get());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
void set_attribute_buffer(std::string const& component, std::string const& attribute, RawDataPtr data) {
|
|
109
|
+
handle_.call_with(PGM_dataset_writable_set_attribute_buffer, get(), component.c_str(), attribute.c_str(), data);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
void set_attribute_buffer(std::string const& component, std::string const& attribute, Buffer& data) {
|
|
113
|
+
handle_.call_with(PGM_dataset_writable_set_attribute_buffer, get(), component.c_str(), attribute.c_str(),
|
|
114
|
+
data.get());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private:
|
|
118
|
+
Handle handle_{};
|
|
119
|
+
RawWritableDataset* dataset_;
|
|
120
|
+
DatasetInfo info_;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
class DatasetMutable {
|
|
124
|
+
public:
|
|
125
|
+
explicit DatasetMutable(std::string const& dataset, bool is_batch, Idx batch_size)
|
|
126
|
+
: dataset_{handle_.call_with(PGM_create_dataset_mutable, dataset.c_str(), (is_batch ? Idx{1} : Idx{0}),
|
|
127
|
+
batch_size)},
|
|
128
|
+
info_{handle_.call_with(PGM_dataset_mutable_get_info, get())} {}
|
|
129
|
+
|
|
130
|
+
RawMutableDataset const* get() const { return dataset_.get(); }
|
|
131
|
+
RawMutableDataset* get() { return dataset_.get(); }
|
|
132
|
+
|
|
133
|
+
void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
|
|
134
|
+
RawDataPtr data) {
|
|
135
|
+
handle_.call_with(PGM_dataset_mutable_add_buffer, get(), component.c_str(), elements_per_scenario,
|
|
136
|
+
total_elements, indptr, data);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
|
|
140
|
+
Buffer& data) {
|
|
141
|
+
handle_.call_with(PGM_dataset_mutable_add_buffer, get(), component.c_str(), elements_per_scenario,
|
|
142
|
+
total_elements, indptr, data.get());
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
void add_attribute_buffer(std::string const& component, std::string const& attribute, RawDataPtr data) {
|
|
146
|
+
handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, get(), component.c_str(), attribute.c_str(), data);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
void add_attribute_buffer(std::string const& component, std::string const& attribute, Buffer& data) {
|
|
150
|
+
handle_.call_with(PGM_dataset_mutable_add_attribute_buffer, get(), component.c_str(), attribute.c_str(),
|
|
151
|
+
data.get());
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
DatasetInfo const& get_info() const { return info_; }
|
|
155
|
+
|
|
156
|
+
private:
|
|
157
|
+
Handle handle_{};
|
|
158
|
+
detail::UniquePtr<RawMutableDataset, &PGM_destroy_dataset_mutable> dataset_;
|
|
159
|
+
DatasetInfo info_;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
class DatasetConst {
|
|
163
|
+
public:
|
|
164
|
+
explicit DatasetConst(std::string const& dataset, bool is_batch, Idx batch_size)
|
|
165
|
+
: dataset_{handle_.call_with(PGM_create_dataset_const, dataset.c_str(), (is_batch ? Idx{1} : Idx{0}),
|
|
166
|
+
batch_size)},
|
|
167
|
+
info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}
|
|
168
|
+
|
|
169
|
+
DatasetConst(DatasetWritable const& writable_dataset)
|
|
170
|
+
: dataset_{handle_.call_with(PGM_create_dataset_const_from_writable, writable_dataset.get())},
|
|
171
|
+
info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}
|
|
172
|
+
|
|
173
|
+
DatasetConst(DatasetMutable const& mutable_dataset)
|
|
174
|
+
: dataset_{handle_.call_with(PGM_create_dataset_const_from_mutable, mutable_dataset.get())},
|
|
175
|
+
info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}
|
|
176
|
+
|
|
177
|
+
RawConstDataset const* get() const { return dataset_.get(); }
|
|
178
|
+
RawConstDataset* get() { return dataset_.get(); }
|
|
179
|
+
|
|
180
|
+
void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
|
|
181
|
+
RawDataConstPtr data) {
|
|
182
|
+
handle_.call_with(PGM_dataset_const_add_buffer, get(), component.c_str(), elements_per_scenario, total_elements,
|
|
183
|
+
indptr, data);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
void add_buffer(std::string const& component, Idx elements_per_scenario, Idx total_elements, Idx const* indptr,
|
|
187
|
+
Buffer const& data) {
|
|
188
|
+
handle_.call_with(PGM_dataset_const_add_buffer, get(), component.c_str(), elements_per_scenario, total_elements,
|
|
189
|
+
indptr, data.get());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
void add_attribute_buffer(std::string const& component, std::string const& attribute, RawDataConstPtr data) {
|
|
193
|
+
handle_.call_with(PGM_dataset_const_add_attribute_buffer, get(), component.c_str(), attribute.c_str(), data);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
void add_attribute_buffer(std::string const& component, std::string const& attribute, Buffer const& data) {
|
|
197
|
+
handle_.call_with(PGM_dataset_const_add_attribute_buffer, get(), component.c_str(), attribute.c_str(),
|
|
198
|
+
data.get());
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
void set_next_cartesian_product_dimension(DatasetConst const& next_dataset) {
|
|
202
|
+
handle_.call_with(PGM_dataset_const_set_next_cartesian_product_dimension, get(), next_dataset.get());
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
DatasetInfo const& get_info() const { return info_; }
|
|
206
|
+
|
|
207
|
+
private:
|
|
208
|
+
Handle handle_{};
|
|
209
|
+
detail::UniquePtr<RawConstDataset, &PGM_destroy_dataset_const> dataset_;
|
|
210
|
+
DatasetInfo info_;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
struct OwningMemory {
|
|
214
|
+
std::vector<Buffer> buffers;
|
|
215
|
+
std::vector<std::vector<Idx>> indptrs;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
struct OwningDataset {
|
|
219
|
+
DatasetMutable dataset;
|
|
220
|
+
OwningMemory storage{};
|
|
221
|
+
};
|
|
222
|
+
} // namespace power_grid_model_cpp
|
|
223
|
+
|
|
224
|
+
#endif // POWER_GRID_MODEL_CPP_DATASET_HPP
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
#ifndef POWER_GRID_MODEL_CPP_HANDLE_HPP
|
|
7
|
+
#define POWER_GRID_MODEL_CPP_HANDLE_HPP
|
|
8
|
+
|
|
9
|
+
#include "basics.hpp"
|
|
10
|
+
|
|
11
|
+
#include "power_grid_model_c/handle.h"
|
|
12
|
+
|
|
13
|
+
namespace power_grid_model_cpp {
|
|
14
|
+
class PowerGridError : public std::exception {
|
|
15
|
+
public:
|
|
16
|
+
PowerGridError(std::string message) : message_(std::move(message)) {}
|
|
17
|
+
const char* what() const noexcept override { return message_.c_str(); }
|
|
18
|
+
virtual Idx error_code() const noexcept { return PGM_regular_error; };
|
|
19
|
+
|
|
20
|
+
private:
|
|
21
|
+
std::string message_;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
class PowerGridRegularError : public PowerGridError {
|
|
25
|
+
public:
|
|
26
|
+
using PowerGridError::PowerGridError;
|
|
27
|
+
Idx error_code() const noexcept override { return PGM_regular_error; }
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
class PowerGridSerializationError : public PowerGridError {
|
|
31
|
+
public:
|
|
32
|
+
using PowerGridError::PowerGridError;
|
|
33
|
+
Idx error_code() const noexcept override { return PGM_serialization_error; }
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
class PowerGridBatchError : public PowerGridError {
|
|
37
|
+
public:
|
|
38
|
+
struct FailedScenario {
|
|
39
|
+
Idx scenario{};
|
|
40
|
+
std::string error_message;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
PowerGridBatchError(std::string message, std::vector<FailedScenario> failed_scenarios_c)
|
|
44
|
+
: PowerGridError{std::move(message)}, failed_scenarios_{std::move(failed_scenarios_c)} {}
|
|
45
|
+
Idx error_code() const noexcept override { return PGM_batch_error; }
|
|
46
|
+
std::vector<FailedScenario> const& failed_scenarios() const { return failed_scenarios_; }
|
|
47
|
+
|
|
48
|
+
private:
|
|
49
|
+
std::vector<FailedScenario> failed_scenarios_;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
class Handle {
|
|
53
|
+
public:
|
|
54
|
+
RawHandle* get() const { return handle_.get(); }
|
|
55
|
+
|
|
56
|
+
void clear_error() const { PGM_clear_error(get()); }
|
|
57
|
+
|
|
58
|
+
void check_error() const {
|
|
59
|
+
RawHandle const* handle_ptr = get();
|
|
60
|
+
Idx const error_code = PGM_error_code(handle_ptr);
|
|
61
|
+
std::string const error_message = error_code == PGM_no_error ? "" : PGM_error_message(handle_ptr);
|
|
62
|
+
switch (error_code) {
|
|
63
|
+
case PGM_no_error:
|
|
64
|
+
return;
|
|
65
|
+
case PGM_regular_error:
|
|
66
|
+
clear_error();
|
|
67
|
+
throw PowerGridRegularError{error_message};
|
|
68
|
+
case PGM_batch_error: {
|
|
69
|
+
Idx const n_failed_scenarios = PGM_n_failed_scenarios(handle_ptr);
|
|
70
|
+
std::vector<PowerGridBatchError::FailedScenario> failed_scenarios(n_failed_scenarios);
|
|
71
|
+
auto const* const failed_scenario_seqs = PGM_failed_scenarios(handle_ptr);
|
|
72
|
+
auto const* const failed_scenario_messages = PGM_batch_errors(handle_ptr);
|
|
73
|
+
for (Idx i = 0; i < n_failed_scenarios; ++i) {
|
|
74
|
+
failed_scenarios[i] =
|
|
75
|
+
PowerGridBatchError::FailedScenario{// NOLINT(modernize-use-designated-initializers)
|
|
76
|
+
failed_scenario_seqs[i], failed_scenario_messages[i]};
|
|
77
|
+
}
|
|
78
|
+
clear_error();
|
|
79
|
+
throw PowerGridBatchError{error_message, std::move(failed_scenarios)};
|
|
80
|
+
}
|
|
81
|
+
case PGM_serialization_error:
|
|
82
|
+
clear_error();
|
|
83
|
+
throw PowerGridSerializationError{error_message};
|
|
84
|
+
default:
|
|
85
|
+
clear_error();
|
|
86
|
+
throw PowerGridError{error_message};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
template <typename Func, typename... Args> auto call_with(Func&& func, Args&&... args) const {
|
|
91
|
+
if constexpr (std::is_void_v<decltype(std::forward<Func>(func)(get(), std::forward<Args>(args)...))>) {
|
|
92
|
+
std::forward<Func>(func)(get(), std::forward<Args>(args)...);
|
|
93
|
+
check_error();
|
|
94
|
+
} else {
|
|
95
|
+
auto result = std::forward<Func>(func)(get(), std::forward<Args>(args)...);
|
|
96
|
+
check_error();
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private:
|
|
102
|
+
// For handle the const semantics are not needed.
|
|
103
|
+
// It is meant to be mutated even in const situations.
|
|
104
|
+
std::unique_ptr<RawHandle, detail::DeleterFunctor<&PGM_destroy_handle>> handle_{PGM_create_handle()};
|
|
105
|
+
};
|
|
106
|
+
} // namespace power_grid_model_cpp
|
|
107
|
+
|
|
108
|
+
#endif // POWER_GRID_MODEL_CPP_HANDLE_HPP
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
#ifndef POWER_GRID_MODEL_CPP_META_DATA_HPP
|
|
7
|
+
#define POWER_GRID_MODEL_CPP_META_DATA_HPP
|
|
8
|
+
|
|
9
|
+
#include "basics.hpp"
|
|
10
|
+
#include "handle.hpp"
|
|
11
|
+
|
|
12
|
+
#include "power_grid_model_c/meta_data.h"
|
|
13
|
+
|
|
14
|
+
namespace power_grid_model_cpp {
|
|
15
|
+
class MetaData {
|
|
16
|
+
public:
|
|
17
|
+
static Idx n_datasets() { return PGM_meta_n_datasets(nullptr); }
|
|
18
|
+
|
|
19
|
+
static MetaDataset const* get_dataset_by_idx(Idx idx) {
|
|
20
|
+
Handle const handle{};
|
|
21
|
+
return handle.call_with(PGM_meta_get_dataset_by_idx, idx);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static MetaDataset const* get_dataset_by_name(std::string const& dataset) {
|
|
25
|
+
Handle const handle{};
|
|
26
|
+
return handle.call_with(PGM_meta_get_dataset_by_name, dataset.c_str());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static std::string dataset_name(MetaDataset const* dataset) {
|
|
30
|
+
return std::string{PGM_meta_dataset_name(nullptr, dataset)};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static Idx n_components(MetaDataset const* dataset) { return PGM_meta_n_components(nullptr, dataset); }
|
|
34
|
+
|
|
35
|
+
static MetaComponent const* get_component_by_idx(MetaDataset const* dataset, Idx idx) {
|
|
36
|
+
Handle const handle{};
|
|
37
|
+
return handle.call_with(PGM_meta_get_component_by_idx, dataset, idx);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static MetaComponent const* get_component_by_name(std::string const& dataset, std::string const& component) {
|
|
41
|
+
Handle const handle{};
|
|
42
|
+
return handle.call_with(PGM_meta_get_component_by_name, dataset.c_str(), component.c_str());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static std::string component_name(MetaComponent const* component) {
|
|
46
|
+
return std::string{PGM_meta_component_name(nullptr, component)};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static size_t component_size(MetaComponent const* component) { return PGM_meta_component_size(nullptr, component); }
|
|
50
|
+
|
|
51
|
+
static size_t component_alignment(MetaComponent const* component) {
|
|
52
|
+
return PGM_meta_component_alignment(nullptr, component);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static Idx n_attributes(MetaComponent const* component) { return PGM_meta_n_attributes(nullptr, component); }
|
|
56
|
+
|
|
57
|
+
static MetaAttribute const* get_attribute_by_idx(MetaComponent const* component, Idx idx) {
|
|
58
|
+
Handle const handle{};
|
|
59
|
+
return handle.call_with(PGM_meta_get_attribute_by_idx, component, idx);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static MetaAttribute const* get_attribute_by_name(std::string const& dataset, std::string const& component,
|
|
63
|
+
std::string const& attribute) {
|
|
64
|
+
Handle const handle{};
|
|
65
|
+
return handle.call_with(PGM_meta_get_attribute_by_name, dataset.c_str(), component.c_str(), attribute.c_str());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static std::string attribute_name(MetaAttribute const* attribute) {
|
|
69
|
+
return std::string{PGM_meta_attribute_name(nullptr, attribute)};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static PGM_CType attribute_ctype(MetaAttribute const* attribute) {
|
|
73
|
+
return static_cast<PGM_CType>(PGM_meta_attribute_ctype(nullptr, attribute));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static size_t attribute_offset(MetaAttribute const* attribute) {
|
|
77
|
+
return PGM_meta_attribute_offset(nullptr, attribute);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static int is_little_endian() { return PGM_is_little_endian(nullptr); }
|
|
81
|
+
};
|
|
82
|
+
} // namespace power_grid_model_cpp
|
|
83
|
+
|
|
84
|
+
#endif // POWER_GRID_MODEL_CPP_META_DATA_HPP
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
#ifndef POWER_GRID_MODEL_CPP_MODEL_HPP
|
|
7
|
+
#define POWER_GRID_MODEL_CPP_MODEL_HPP
|
|
8
|
+
|
|
9
|
+
#include "basics.hpp"
|
|
10
|
+
#include "dataset.hpp"
|
|
11
|
+
#include "handle.hpp"
|
|
12
|
+
#include "options.hpp"
|
|
13
|
+
|
|
14
|
+
#include "power_grid_model_c/model.h"
|
|
15
|
+
|
|
16
|
+
namespace power_grid_model_cpp {
|
|
17
|
+
class Model {
|
|
18
|
+
public:
|
|
19
|
+
Model(double system_frequency, DatasetConst const& input_dataset)
|
|
20
|
+
: model_{handle_.call_with(PGM_create_model, system_frequency, input_dataset.get())} {}
|
|
21
|
+
Model(Model const& other) : model_{handle_.call_with(PGM_copy_model, other.get())} {}
|
|
22
|
+
Model& operator=(Model const& other) {
|
|
23
|
+
if (this != &other) {
|
|
24
|
+
model_.reset(handle_.call_with(PGM_copy_model, other.get()));
|
|
25
|
+
}
|
|
26
|
+
return *this;
|
|
27
|
+
}
|
|
28
|
+
Model(Model&& other) noexcept : handle_{std::move(other.handle_)}, model_{std::move(other.model_)} {}
|
|
29
|
+
Model& operator=(Model&& other) noexcept {
|
|
30
|
+
if (this != &other) {
|
|
31
|
+
handle_ = std::move(other.handle_);
|
|
32
|
+
model_ = std::move(other.model_);
|
|
33
|
+
}
|
|
34
|
+
return *this;
|
|
35
|
+
}
|
|
36
|
+
~Model() = default;
|
|
37
|
+
|
|
38
|
+
PowerGridModel const* get() const { return model_.get(); }
|
|
39
|
+
PowerGridModel* get() { return model_.get(); }
|
|
40
|
+
|
|
41
|
+
void update(DatasetConst const& update_dataset) {
|
|
42
|
+
handle_.call_with(PGM_update_model, get(), update_dataset.get());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void get_indexer(std::string const& component, Idx size, ID const* ids, Idx* indexer) const {
|
|
46
|
+
handle_.call_with(PGM_get_indexer, get(), component.c_str(), size, ids, indexer);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void calculate(Options const& opt, DatasetMutable const& output_dataset, DatasetConst const& batch_dataset) {
|
|
50
|
+
handle_.call_with(PGM_calculate, get(), opt.get(), output_dataset.get(), batch_dataset.get());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void calculate(Options const& opt, DatasetMutable const& output_dataset) {
|
|
54
|
+
handle_.call_with(PGM_calculate, get(), opt.get(), output_dataset.get(), nullptr);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private:
|
|
58
|
+
Handle handle_{};
|
|
59
|
+
detail::UniquePtr<PowerGridModel, &PGM_destroy_model> model_;
|
|
60
|
+
};
|
|
61
|
+
} // namespace power_grid_model_cpp
|
|
62
|
+
|
|
63
|
+
#endif // POWER_GRID_MODEL_CPP_MODEL_HPP
|