Skip to content

Commit

Permalink
Merge pull request #848 from PowerGridModel/feature/only-important-in…
Browse files Browse the repository at this point in the history
…tegration-tests-5

Keep only important integration tests: step 5
  • Loading branch information
TonyXiang8787 authored Dec 4, 2024
2 parents 07df291 + 5cb7a28 commit 4954709
Show file tree
Hide file tree
Showing 21 changed files with 920 additions and 1,045 deletions.
1 change: 0 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ if [[ "${COVERAGE}" ]]; then

PATH=${PATH}:${PWD} lcov -q -c \
-d ${BUILD_DIR}/tests/cpp_unit_tests/CMakeFiles/power_grid_model_unit_tests.dir \
-d ${BUILD_DIR}/tests/cpp_integration_tests/CMakeFiles/power_grid_model_integration_tests.dir \
-d ${BUILD_DIR}/tests/cpp_validation_tests/CMakeFiles/power_grid_model_validation_tests.dir \
-d ${BUILD_DIR}/tests/native_api_tests/CMakeFiles/power_grid_model_api_tests.dir \
-d ${BUILD_DIR}/power_grid_model_c/power_grid_model_c/CMakeFiles/power_grid_model_c.dir \
Expand Down
1 change: 0 additions & 1 deletion docs/advanced_documentation/build-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ In the developer build the following build targets (directories) are enabled:

* `power_grid_model_c`: a dynamic library (`.dll` or `.so`) with stable pure C API/ABI which can be used by any application
* `tests/cpp_unit_tests`: the unit test target for the C++ core using the `doctest` framework.
* `tests/cpp_integration_tests`: the integration test target for the C++ core using the `doctest` framework.
* `tests/cpp_validation_tests`: the validation test target using the `doctest` framework
* `tests/native_api_tests`: the C API test target using the `doctest` framework
* `tests/benchmark_cpp`: the C++ benchmark target for performance measure.
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced_documentation/c-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ and may vary between power grid model versions, compilers, operating systems and
<line_0><line_1><line_2> <-- 3 lines.
| | | | | | | <-- alignment: a line may start every 4 bytes.
iiiift iiiift iiiift <-- data: 6 bytes per line: 4 bytes for the ID, 1 for the from_status and 1 for the to_status.
| ..| ..| ..| <-- padding: (6 mod 4 = 2) bytes after every line.
| ..| ..| ..| <-- padding: (4 - (6 mod 4) = 2) bytes after every line.
| | | | <-- aligned size: (6 + 2 = 8) bytes every line.
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum class ControlSide : IntS { from = 0, to = 1, side_1 = 0, side_2 = 1, side_3

enum class CalculationType : IntS { power_flow = 0, state_estimation = 1, short_circuit = 2 };

enum class CalculationSymmetry : IntS { symmetric = 0, asymmetric = 1 };
enum class CalculationSymmetry : IntS { asymmetric = 0, symmetric = 1 };

enum class CalculationMethod : IntS {
default_method = -128,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ class MainModel {
}

void set_construction_complete() { impl().set_construction_complete(); }
void restore_components(ConstDataset const& update_data) {
impl().restore_components(impl().get_all_sequence_idx_map(update_data));
}

template <class CompType> void add_component(std::vector<typename CompType::InputType> const& components) {
add_component<CompType>(std::span<typename CompType::InputType const>{components});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,35 +300,6 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
update_components<CacheType>(update_data, 0, sequence_idx_map);
}

template <typename CompType> void restore_component(SequenceIdxView const& sequence_idx) {
constexpr auto component_index = main_core::utils::index_of_component<CompType, ComponentType...>;

auto& cached_inverse_update = std::get<component_index>(cached_inverse_update_);
auto const& component_sequence = std::get<component_index>(sequence_idx);

if (!cached_inverse_update.empty()) {
update_component<CompType, permanent_update_t>(cached_inverse_update, component_sequence);
cached_inverse_update.clear();
}
}

// restore the initial values of all components
void restore_components(SequenceIdxView const& sequence_idx) {
(restore_component<ComponentType>(sequence_idx), ...);

update_state(cached_state_changes_);
cached_state_changes_ = {};
}
void restore_components(std::array<std::reference_wrapper<std::vector<Idx2D> const>,
main_core::utils::n_types<ComponentType...>> const& sequence_idx) {
restore_components(std::array{std::span<Idx2D const>{
std::get<main_core::utils::index_of_component<ComponentType, ComponentType...>>(sequence_idx).get()}...});
}
void restore_components(main_core::utils::SequenceIdx<ComponentType...> const& sequence_idx) {
restore_components(std::array{std::span<Idx2D const>{
std::get<main_core::utils::index_of_component<ComponentType, ComponentType...>>(sequence_idx)}...});
}

// set complete construction
// initialize internal arrays
void set_construction_complete() {
Expand Down Expand Up @@ -399,6 +370,35 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
is_asym_parameter_up_to_date_ = is_asym_parameter_up_to_date_ && !changes.topo && !changes.param;
}

template <typename CompType> void restore_component(SequenceIdxView const& sequence_idx) {
constexpr auto component_index = main_core::utils::index_of_component<CompType, ComponentType...>;

auto& cached_inverse_update = std::get<component_index>(cached_inverse_update_);
auto const& component_sequence = std::get<component_index>(sequence_idx);

if (!cached_inverse_update.empty()) {
update_component<CompType, permanent_update_t>(cached_inverse_update, component_sequence);
cached_inverse_update.clear();
}
}

// restore the initial values of all components
void restore_components(SequenceIdxView const& sequence_idx) {
(restore_component<ComponentType>(sequence_idx), ...);

update_state(cached_state_changes_);
cached_state_changes_ = {};
}
void restore_components(std::array<std::reference_wrapper<std::vector<Idx2D> const>,
main_core::utils::n_types<ComponentType...>> const& sequence_idx) {
restore_components(std::array{std::span<Idx2D const>{
std::get<main_core::utils::index_of_component<ComponentType, ComponentType...>>(sequence_idx).get()}...});
}
void restore_components(main_core::utils::SequenceIdx<ComponentType...> const& sequence_idx) {
restore_components(std::array{std::span<Idx2D const>{
std::get<main_core::utils::index_of_component<ComponentType, ComponentType...>>(sequence_idx)}...});
}

template <solver_output_type SolverOutputType, typename MathSolverType, typename YBus, typename InputType,
typename PrepareInputFn, typename SolveFn>
requires std::invocable<std::remove_cvref_t<PrepareInputFn>, Idx /*n_math_solvers*/> &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ enum PGM_CalculationMethod {
PGM_iec60909 = 5 /**< fault analysis for short circuits using the iec60909 standard */
};

/**
* @brief Enumeration for calculation and/or component symmetry
*/
enum PGM_SymmetryType {
PGM_asymmetric = 0, /** < asymmetric calculation and/or component */
PGM_symmetric = 1 /** < symmetric calculation and/or component */
};

/**
* @brief Enumeration of error codes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ PGM_API void PGM_set_calculation_method(PGM_Handle* handle, PGM_Options* opt, PG
*
* @param handle
* @param opt The pointer to the option instance.
* @param sym 1 for symmetric calculation; 0 for asymmetric calculation.
* @param sym See #PGM_CalculationSymmetry . 1 for symmetric calculation; 0 for asymmetric calculation.
*/
PGM_API void PGM_set_symmetric(PGM_Handle* handle, PGM_Options* opt, PGM_Idx sym);

Expand Down
8 changes: 6 additions & 2 deletions power_grid_model_c/power_grid_model_c/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ constexpr auto get_calculation_type(PGM_Options const& opt) {
}

constexpr auto get_calculation_symmetry(PGM_Options const& opt) {
if (opt.symmetric == 0) {
switch (opt.symmetric) {
case PGM_asymmetric:
return CalculationSymmetry::asymmetric;
case PGM_symmetric:
return CalculationSymmetry::symmetric;
default:
throw MissingCaseForEnumError{"get_calculation_symmetry", opt.tap_changing_strategy};
}
return CalculationSymmetry::symmetric;
}

constexpr auto get_calculation_method(PGM_Options const& opt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DatasetInfo {

std::string name() const { return std::string{handle_.call_with(PGM_dataset_info_name, info_)}; }

Idx is_batch() const { return handle_.call_with(PGM_dataset_info_is_batch, info_); }
bool is_batch() const { return handle_.call_with(PGM_dataset_info_is_batch, info_) != 0; }

Idx batch_size() const { return handle_.call_with(PGM_dataset_info_batch_size, info_); }

Expand Down Expand Up @@ -88,8 +88,10 @@ class DatasetWritable {

class DatasetMutable {
public:
DatasetMutable(std::string const& dataset, Idx is_batch, Idx batch_size)
: dataset_{handle_.call_with(PGM_create_dataset_mutable, dataset.c_str(), is_batch, batch_size)},
explicit DatasetMutable(std::string const& dataset, bool is_batch, Idx batch_size)
: handle_{},
dataset_{
handle_.call_with(PGM_create_dataset_mutable, dataset.c_str(), (is_batch ? Idx{1} : Idx{0}), batch_size)},
info_{handle_.call_with(PGM_dataset_mutable_get_info, get())} {}

RawMutableDataset const* get() const { return dataset_.get(); }
Expand Down Expand Up @@ -126,12 +128,16 @@ class DatasetMutable {

class DatasetConst {
public:
DatasetConst(std::string const& dataset, Idx is_batch, Idx batch_size)
: dataset_{handle_.call_with(PGM_create_dataset_const, dataset.c_str(), is_batch, batch_size)},
explicit DatasetConst(std::string const& dataset, bool is_batch, Idx batch_size)
: handle_{},
dataset_{
handle_.call_with(PGM_create_dataset_const, dataset.c_str(), (is_batch ? Idx{1} : Idx{0}), batch_size)},
info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}

DatasetConst(DatasetWritable const& writable_dataset)
: dataset_{handle_.call_with(PGM_create_dataset_const_from_writable, writable_dataset.get())},
info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}

DatasetConst(DatasetMutable const& mutable_dataset)
: dataset_{handle_.call_with(PGM_create_dataset_const_from_mutable, mutable_dataset.get())},
info_{handle_.call_with(PGM_dataset_const_get_info, get())} {}
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sonar.projectVersion=1.0

# include C++ and Python source file
# since the C++ part is header only, also include the C++ unit test .cpp file
sonar.sources=src,tests/cpp_unit_tests,tests/cpp_integration_tests,tests/cpp_validation_tests,tests/native_api_tests,power_grid_model_c
sonar.sources=src,tests/cpp_unit_tests,tests/cpp_validation_tests,tests/native_api_tests,power_grid_model_c
sonar.tests=tests/unit
sonar.sourceEncoding=UTF-8

Expand Down
1 change: 0 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ include("${doctest_DIR}/doctest.cmake")

add_subdirectory("native_api_tests")
add_subdirectory("cpp_unit_tests")
add_subdirectory("cpp_integration_tests")
add_subdirectory("cpp_validation_tests")
add_subdirectory("benchmark_cpp")
19 changes: 0 additions & 19 deletions tests/cpp_integration_tests/CMakeLists.txt

This file was deleted.

9 changes: 0 additions & 9 deletions tests/cpp_integration_tests/test_entry_point.cpp

This file was deleted.

Loading

0 comments on commit 4954709

Please sign in to comment.