@@ -181,11 +181,14 @@ namespace GridKit
181181
182182 for (const auto & bus : buses_)
183183 {
184- auto * bus_y = bus->y ().getData ();
185-
186- for (IdxT j = 0 ; j < bus->size (); ++j)
184+ if (bus->y ().getSize () > 0 )
187185 {
188- y[varOffset + j] = bus_y[j];
186+ auto * bus_y = bus->y ().getData ();
187+
188+ for (IdxT j = 0 ; j < bus->size (); ++j)
189+ {
190+ y[varOffset + j] = bus_y[j];
191+ }
189192 }
190193 varOffset += bus->size ();
191194 }
@@ -198,11 +201,14 @@ namespace GridKit
198201
199202 for (const auto & component : components_)
200203 {
201- auto * component_y = component->y ().getData ();
202-
203- for (IdxT j = 0 ; j < component->size (); ++j)
204+ if (component->y ().getSize () > 0 )
204205 {
205- y[varOffset + j] = component_y[j];
206+ auto * component_y = component->y ().getData ();
207+
208+ for (IdxT j = 0 ; j < component->size (); ++j)
209+ {
210+ y[varOffset + j] = component_y[j];
211+ }
206212 }
207213 varOffset += component->size ();
208214 }
@@ -266,23 +272,29 @@ namespace GridKit
266272
267273 for (const auto & bus : buses_)
268274 {
269- auto * bus_y = bus->y ().getData ();
270-
271- for (IdxT j = 0 ; j < bus->size (); ++j)
275+ if (bus->y ().getSize () > 0 )
272276 {
273- bus_y[j] = y[varOffset + j];
277+ auto * bus_y = bus->y ().getData ();
278+
279+ for (IdxT j = 0 ; j < bus->size (); ++j)
280+ {
281+ bus_y[j] = y[varOffset + j];
282+ }
274283 }
275284 varOffset += bus->size ();
276285 bus->evaluateResidual ();
277286 }
278287
279288 for (const auto & component : components_)
280289 {
281- auto * component_y = component->y ().getData ();
282-
283- for (IdxT j = 0 ; j < component->size (); ++j)
290+ if (component->y ().getSize () > 0 )
284291 {
285- component_y[j] = y[varOffset + j];
292+ auto * component_y = component->y ().getData ();
293+
294+ for (IdxT j = 0 ; j < component->size (); ++j)
295+ {
296+ component_y[j] = y[varOffset + j];
297+ }
286298 }
287299 varOffset += component->size ();
288300 component->evaluateResidual ();
@@ -292,22 +304,28 @@ namespace GridKit
292304 IdxT resOffset = 0 ;
293305 for (const auto & bus : buses_)
294306 {
295- auto * bus_f = bus->getResidual ().getData ();
296-
297- for (IdxT j = 0 ; j < bus->size (); ++j)
307+ if (bus->getResidual ().getSize () > 0 )
298308 {
299- f[resOffset + j] = bus_f[j];
309+ auto * bus_f = bus->getResidual ().getData ();
310+
311+ for (IdxT j = 0 ; j < bus->size (); ++j)
312+ {
313+ f[resOffset + j] = bus_f[j];
314+ }
300315 }
301316 resOffset += bus->size ();
302317 }
303318
304319 for (const auto & component : components_)
305320 {
306- auto * component_f = component->getResidual ().getData ();
307-
308- for (IdxT j = 0 ; j < component->size (); ++j)
321+ if (component->getResidual ().getSize () > 0 )
309322 {
310- f[resOffset + j] = component_f[j];
323+ auto * component_f = component->getResidual ().getData ();
324+
325+ for (IdxT j = 0 ; j < component->size (); ++j)
326+ {
327+ f[resOffset + j] = component_f[j];
328+ }
311329 }
312330 resOffset += component->size ();
313331 }
0 commit comments