@@ -169,11 +169,11 @@ namespace GridKit
169169
170170 for (const auto & bus : buses_)
171171 {
172- auto * bus_y = bus->y (). getData ( );
173- auto * bus_yp = bus->yp (). getData ( );
174- auto * bus_param = bus->param (). getData ( );
175- auto * bus_param_lo = bus->param_lo (). getData ( );
176- auto * bus_param_up = bus->param_up (). getData ( );
172+ auto * bus_y = dataOrNull ( bus->y ());
173+ auto * bus_yp = dataOrNull ( bus->yp ());
174+ auto * bus_param = dataOrNull ( bus->param ());
175+ auto * bus_param_lo = dataOrNull ( bus->param_lo ());
176+ auto * bus_param_up = dataOrNull ( bus->param_up ());
177177
178178 for (IdxT j = 0 ; j < bus->size (); ++j)
179179 {
@@ -199,11 +199,11 @@ namespace GridKit
199199
200200 for (const auto & component : components_)
201201 {
202- auto * component_y = component->y (). getData ( );
203- auto * component_yp = component->yp (). getData ( );
204- auto * component_param = component->param (). getData ( );
205- auto * component_param_lo = component->param_lo (). getData ( );
206- auto * component_param_up = component->param_up (). getData ( );
202+ auto * component_y = dataOrNull ( component->y ());
203+ auto * component_yp = dataOrNull ( component->yp ());
204+ auto * component_param = dataOrNull ( component->param ());
205+ auto * component_param_lo = dataOrNull ( component->param_lo ());
206+ auto * component_param_up = dataOrNull ( component->param_up ());
207207
208208 for (IdxT j = 0 ; j < component->size (); ++j)
209209 {
@@ -240,7 +240,7 @@ namespace GridKit
240240 for (const auto & bus : buses_)
241241 {
242242 bus->tagDifferentiable ();
243- auto * bus_tag = bus->tag (). getData ( );
243+ auto * bus_tag = dataOrNull ( bus->tag ());
244244
245245 for (IdxT j = 0 ; j < bus->size (); ++j)
246246 {
@@ -252,7 +252,7 @@ namespace GridKit
252252 for (const auto & component : components_)
253253 {
254254 component->tagDifferentiable ();
255- auto * component_tag = component->tag (). getData ( );
255+ auto * component_tag = dataOrNull ( component->tag ());
256256
257257 for (IdxT j = 0 ; j < component->size (); ++j)
258258 {
@@ -285,7 +285,7 @@ namespace GridKit
285285 for (const auto & bus : buses_)
286286 {
287287 bus->setAbsoluteTolerance (rel_tol);
288- auto * bus_abs_tol = bus->absoluteTolerance (). getData ( );
288+ auto * bus_abs_tol = dataOrNull ( bus->absoluteTolerance ());
289289
290290 for (IdxT j = 0 ; j < bus->size (); ++j)
291291 {
@@ -297,7 +297,7 @@ namespace GridKit
297297 for (const auto & component : components_)
298298 {
299299 component->setAbsoluteTolerance (rel_tol);
300- auto * component_abs_tol = component->absoluteTolerance (). getData ( );
300+ auto * component_abs_tol = dataOrNull ( component->absoluteTolerance ());
301301
302302 for (IdxT j = 0 ; j < component->size (); ++j)
303303 {
@@ -339,9 +339,9 @@ namespace GridKit
339339
340340 for (const auto & bus : buses_)
341341 {
342- auto * bus_y = bus->y (). getData ( );
343- auto * bus_yp = bus->yp (). getData ( );
344- auto * bus_param = bus->param (). getData ( );
342+ auto * bus_y = dataOrNull ( bus->y ());
343+ auto * bus_yp = dataOrNull ( bus->yp ());
344+ auto * bus_param = dataOrNull ( bus->param ());
345345
346346 for (IdxT j = 0 ; j < bus->size (); ++j)
347347 {
@@ -361,9 +361,9 @@ namespace GridKit
361361
362362 for (const auto & component : components_)
363363 {
364- auto * component_y = component->y (). getData ( );
365- auto * component_yp = component->yp (). getData ( );
366- auto * component_param = component->param (). getData ( );
364+ auto * component_y = dataOrNull ( component->y ());
365+ auto * component_yp = dataOrNull ( component->yp ());
366+ auto * component_param = dataOrNull ( component->param ());
367367
368368 for (IdxT j = 0 ; j < component->size (); ++j)
369369 {
@@ -385,7 +385,7 @@ namespace GridKit
385385 IdxT resOffset = 0 ;
386386 for (const auto & bus : buses_)
387387 {
388- auto * bus_f = bus->getResidual (). getData ( );
388+ auto * bus_f = dataOrNull ( bus->getResidual ());
389389
390390 for (IdxT j = 0 ; j < bus->size (); ++j)
391391 {
@@ -396,7 +396,7 @@ namespace GridKit
396396
397397 for (const auto & component : components_)
398398 {
399- auto * component_f = component->getResidual (). getData ( );
399+ auto * component_f = dataOrNull ( component->getResidual ());
400400
401401 for (IdxT j = 0 ; j < component->size (); ++j)
402402 {
@@ -436,9 +436,9 @@ namespace GridKit
436436
437437 for (const auto & bus : buses_)
438438 {
439- auto * bus_y = bus->y (). getData ( );
440- auto * bus_yp = bus->yp (). getData ( );
441- auto * bus_param = bus->param (). getData ( );
439+ auto * bus_y = dataOrNull ( bus->y ());
440+ auto * bus_yp = dataOrNull ( bus->yp ());
441+ auto * bus_param = dataOrNull ( bus->param ());
442442
443443 for (IdxT j = 0 ; j < bus->size (); ++j)
444444 {
@@ -458,9 +458,9 @@ namespace GridKit
458458
459459 for (const auto & component : components_)
460460 {
461- auto * component_y = component->y (). getData ( );
462- auto * component_yp = component->yp (). getData ( );
463- auto * component_param = component->param (). getData ( );
461+ auto * component_y = dataOrNull ( component->y ());
462+ auto * component_yp = dataOrNull ( component->yp ());
463+ auto * component_param = dataOrNull ( component->param ());
464464
465465 for (IdxT j = 0 ; j < component->size (); ++j)
466466 {
@@ -482,7 +482,7 @@ namespace GridKit
482482 IdxT intOffset = 0 ;
483483 for (const auto & bus : buses_)
484484 {
485- auto * bus_g = bus->getIntegrand (). getData ( );
485+ auto * bus_g = dataOrNull ( bus->getIntegrand ());
486486
487487 for (IdxT j = 0 ; j < bus->sizeQuadrature (); ++j)
488488 {
@@ -493,7 +493,7 @@ namespace GridKit
493493
494494 for (const auto & component : components_)
495495 {
496- auto * component_g = component->getIntegrand (). getData ( );
496+ auto * component_g = dataOrNull ( component->getIntegrand ());
497497
498498 for (IdxT j = 0 ; j < component->sizeQuadrature (); ++j)
499499 {
@@ -524,9 +524,9 @@ namespace GridKit
524524 // Update bus variables and optimization parameters
525525 for (const auto & bus : buses_)
526526 {
527- auto * bus_y = bus->y (). getData ( );
528- auto * bus_yp = bus->yp (). getData ( );
529- auto * bus_param = bus->param (). getData ( );
527+ auto * bus_y = dataOrNull ( bus->y ());
528+ auto * bus_yp = dataOrNull ( bus->yp ());
529+ auto * bus_param = dataOrNull ( bus->param ());
530530
531531 for (IdxT j = 0 ; j < bus->size (); ++j)
532532 {
@@ -545,9 +545,9 @@ namespace GridKit
545545 // Update component variables and optimization parameters
546546 for (const auto & component : components_)
547547 {
548- auto * component_y = component->y (). getData ( );
549- auto * component_yp = component->yp (). getData ( );
550- auto * component_param = component->param (). getData ( );
548+ auto * component_y = dataOrNull ( component->y ());
549+ auto * component_yp = dataOrNull ( component->yp ());
550+ auto * component_param = dataOrNull ( component->param ());
551551
552552 for (IdxT j = 0 ; j < component->size (); ++j)
553553 {
@@ -570,8 +570,8 @@ namespace GridKit
570570 for (const auto & bus : buses_)
571571 {
572572 bus->initializeAdjoint ();
573- auto * bus_yB = bus->yB (). getData ( );
574- auto * bus_ypB = bus->ypB (). getData ( );
573+ auto * bus_yB = dataOrNull ( bus->yB ());
574+ auto * bus_ypB = dataOrNull ( bus->ypB ());
575575
576576 for (IdxT j = 0 ; j < bus->size (); ++j)
577577 {
@@ -585,8 +585,8 @@ namespace GridKit
585585 for (const auto & component : components_)
586586 {
587587 component->initializeAdjoint ();
588- auto * component_yB = component->yB (). getData ( );
589- auto * component_ypB = component->ypB (). getData ( );
588+ auto * component_yB = dataOrNull ( component->yB ());
589+ auto * component_ypB = dataOrNull ( component->ypB ());
590590
591591 for (IdxT j = 0 ; j < component->size (); ++j)
592592 {
@@ -620,11 +620,11 @@ namespace GridKit
620620 // Update variables in component models
621621 for (const auto & bus : buses_)
622622 {
623- auto * bus_y = bus->y (). getData ( );
624- auto * bus_yp = bus->yp (). getData ( );
625- auto * bus_yB = bus->yB (). getData ( );
626- auto * bus_ypB = bus->ypB (). getData ( );
627- auto * bus_param = bus->param (). getData ( );
623+ auto * bus_y = dataOrNull ( bus->y ());
624+ auto * bus_yp = dataOrNull ( bus->yp ());
625+ auto * bus_yB = dataOrNull ( bus->yB ());
626+ auto * bus_ypB = dataOrNull ( bus->ypB ());
627+ auto * bus_param = dataOrNull ( bus->param ());
628628
629629 for (IdxT j = 0 ; j < bus->size (); ++j)
630630 {
@@ -644,11 +644,11 @@ namespace GridKit
644644
645645 for (const auto & component : components_)
646646 {
647- auto * component_y = component->y (). getData ( );
648- auto * component_yp = component->yp (). getData ( );
649- auto * component_yB = component->yB (). getData ( );
650- auto * component_ypB = component->ypB (). getData ( );
651- auto * component_param = component->param (). getData ( );
647+ auto * component_y = dataOrNull ( component->y ());
648+ auto * component_yp = dataOrNull ( component->yp ());
649+ auto * component_yB = dataOrNull ( component->yB ());
650+ auto * component_ypB = dataOrNull ( component->ypB ());
651+ auto * component_param = dataOrNull ( component->param ());
652652
653653 for (IdxT j = 0 ; j < component->size (); ++j)
654654 {
@@ -680,7 +680,7 @@ namespace GridKit
680680 IdxT resOffset = 0 ;
681681 for (const auto & bus : buses_)
682682 {
683- auto * bus_fB = bus->getAdjointResidual (). getData ( );
683+ auto * bus_fB = dataOrNull ( bus->getAdjointResidual ());
684684
685685 for (IdxT j = 0 ; j < bus->size (); ++j)
686686 {
@@ -691,7 +691,7 @@ namespace GridKit
691691
692692 for (const auto & component : components_)
693693 {
694- auto * component_fB = component->getAdjointResidual (). getData ( );
694+ auto * component_fB = dataOrNull ( component->getAdjointResidual ());
695695
696696 for (IdxT j = 0 ; j < component->size (); ++j)
697697 {
@@ -726,11 +726,11 @@ namespace GridKit
726726
727727 for (const auto & bus : buses_)
728728 {
729- auto * bus_y = bus->y (). getData ( );
730- auto * bus_yp = bus->yp (). getData ( );
731- auto * bus_yB = bus->yB (). getData ( );
732- auto * bus_ypB = bus->ypB (). getData ( );
733- auto * bus_param = bus->param (). getData ( );
729+ auto * bus_y = dataOrNull ( bus->y ());
730+ auto * bus_yp = dataOrNull ( bus->yp ());
731+ auto * bus_yB = dataOrNull ( bus->yB ());
732+ auto * bus_ypB = dataOrNull ( bus->ypB ());
733+ auto * bus_param = dataOrNull ( bus->param ());
734734
735735 for (IdxT j = 0 ; j < bus->size (); ++j)
736736 {
@@ -750,11 +750,11 @@ namespace GridKit
750750
751751 for (const auto & component : components_)
752752 {
753- auto * component_y = component->y (). getData ( );
754- auto * component_yp = component->yp (). getData ( );
755- auto * component_yB = component->yB (). getData ( );
756- auto * component_ypB = component->ypB (). getData ( );
757- auto * component_param = component->param (). getData ( );
753+ auto * component_y = dataOrNull ( component->y ());
754+ auto * component_yp = dataOrNull ( component->yp ());
755+ auto * component_yB = dataOrNull ( component->yB ());
756+ auto * component_ypB = dataOrNull ( component->ypB ());
757+ auto * component_param = dataOrNull ( component->param ());
758758
759759 for (IdxT j = 0 ; j < component->size (); ++j)
760760 {
@@ -778,7 +778,7 @@ namespace GridKit
778778 if (component->sizeQuadrature () == 1 )
779779 {
780780 component->evaluateAdjointIntegrand ();
781- auto * component_gB = component->getAdjointIntegrand (). getData ( );
781+ auto * component_gB = dataOrNull ( component->getAdjointIntegrand ());
782782
783783 for (IdxT j = 0 ; j < size_opt_; ++j)
784784 {
@@ -809,6 +809,11 @@ namespace GridKit
809809 }
810810
811811 private:
812+ static ScalarT* dataOrNull (VectorT& vector)
813+ {
814+ return vector.getSize () == 0 ? nullptr : vector.getData ();
815+ }
816+
812817 std::vector<bus_type*> buses_;
813818 std::vector<component_type*> components_;
814819
0 commit comments