66#pragma once
77
88#include < format>
9- #include < map>
109#include < set>
1110#include < stdexcept>
1211#include < string>
@@ -43,7 +42,7 @@ namespace GridKit
4342
4443 for (const auto & branch : data.branch )
4544 {
46- branches_. push_back (& addDevice<BranchT> (branch) );
45+ addDevice<Branch<ScalarT, IdxT>> (branch);
4746 }
4847
4948 for (const auto & generator : data.generator )
@@ -71,8 +70,7 @@ namespace GridKit
7170 }
7271
7372 /* *
74- * @brief Every problem with the data, including an island without a
75- * reference bus
73+ * @brief Every problem with the data
7674 */
7775 template <typename scalar_type, typename index_type>
7876 Model::ConfigurationChecks SystemModel<scalar_type, index_type>::verify() const
@@ -91,11 +89,6 @@ namespace GridKit
9189 std::format (" {}: invalid bus number" , bus->id ()));
9290 }
9391
94- for (const IdxT number : unreferencedIslands ())
95- {
96- checks.fail (std::format (" OptimalPowerFlow::SystemModel: the island of bus {} has no reference bus" , number));
97- }
98-
9992 std::set<std::string> ids;
10093 for (const auto & component : components_)
10194 {
@@ -274,7 +267,7 @@ namespace GridKit
274267 */
275268 template <typename scalar_type, typename index_type>
276269 template <typename ModelT, typename DataT>
277- ModelT& SystemModel<scalar_type, index_type>::addDevice(const DataT& data)
270+ void SystemModel<scalar_type, index_type>::addDevice(const DataT& data)
278271 {
279272 using Ports = typename DataT::Ports;
280273 static_assert (ModelT::NUM_PORT_VARIABLES .size () == Utilities::enum_size<Ports>());
@@ -302,9 +295,7 @@ namespace GridKit
302295 }
303296 }
304297
305- ModelT& added = *device;
306298 components_.push_back (std::move (device));
307- return added;
308299 }
309300
310301 /* *
@@ -371,61 +362,5 @@ namespace GridKit
371362 component.bound_ = true ;
372363 return 0 ;
373364 }
374-
375- /* *
376- * @brief Lowest bus number of each island without a reference bus
377- *
378- * In-service branches connect the buses of their ports.
379- */
380- template <typename scalar_type, typename index_type>
381- std::vector<index_type> SystemModel<scalar_type, index_type>::unreferencedIslands() const
382- {
383- // Each bus points toward the root bus of its island
384- std::map<const ComponentT*, const ComponentT*> parent;
385- for (const auto & [number, bus] : buses_)
386- {
387- parent[bus] = bus;
388- }
389-
390- const auto root = [&parent](const ComponentT* bus)
391- {
392- while (parent.at (bus) != bus)
393- {
394- bus = parent.at (bus);
395- }
396- return bus;
397- };
398-
399- for (const auto * branch : branches_)
400- {
401- const auto & ports = branch->ports ();
402- if (!branch->inService () || ports[0 ].component == nullptr || ports[1 ].component == nullptr )
403- {
404- continue ;
405- }
406- parent[root (ports[1 ].component )] = root (ports[0 ].component );
407- }
408-
409- std::set<const ComponentT*> referenced;
410- for (const auto & [number, bus] : buses_)
411- {
412- if (bus->reference ())
413- {
414- referenced.insert (root (bus));
415- }
416- }
417-
418- std::vector<IdxT> unreferenced;
419- std::set<const ComponentT*> reported;
420- for (const auto & [number, bus] : buses_)
421- {
422- const auto * island = root (bus);
423- if (!referenced.contains (island) && reported.insert (island).second )
424- {
425- unreferenced.push_back (number);
426- }
427- }
428- return unreferenced;
429- }
430365 } // namespace OptimalPowerFlow
431366} // namespace GridKit
0 commit comments