]> git.mxchange.org Git - flightgear.git/blob - src/Systems/electrical.cxx
Include <iostream> and using declarations as needed.
[flightgear.git] / src / Systems / electrical.cxx
1 // electrical.cxx - a flexible, generic electrical system model.
2 //
3 // Written by Curtis Olson, started September 2002.
4 //
5 // Copyright (C) 2002  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24 #  include <config.h>
25 #endif
26
27 #include <simgear/structure/exception.hxx>
28 #include <simgear/misc/sg_path.hxx>
29 #include <simgear/debug/logstream.hxx>
30
31 #include <Main/fg_props.hxx>
32 #include <Main/globals.hxx>
33
34 #include "electrical.hxx"
35
36
37 FGElectricalComponent::FGElectricalComponent() :
38     kind(-1),
39     name(""),
40     volts(0.0),
41     load_amps(0.0)
42 {
43 }
44
45
46 FGElectricalSupplier::FGElectricalSupplier ( SGPropertyNode *node ) {
47     kind = FG_SUPPLIER;
48
49     // cout << "Creating a supplier" << endl;
50     name = node->getStringValue("name");
51     string _model = node->getStringValue("kind");
52     // cout << "_model = " << _model << endl;
53     if ( _model == "battery" ) {
54         model = FG_BATTERY;
55         amp_hours = node->getFloatValue("amp-hours", 40.0);
56         percent_remaining = node->getFloatValue("percent-remaining", 1.0);
57         charge_amps = node->getFloatValue("charge-amps", 7.0);
58     } else if ( _model == "alternator" ) {
59         model = FG_ALTERNATOR;
60         rpm_src = node->getStringValue("rpm-source");
61         rpm_threshold = node->getFloatValue("rpm-threshold", 600.0);
62         ideal_amps = node->getFloatValue("amps", 60.0);
63     } else if ( _model == "external" ) {
64         model = FG_EXTERNAL;
65         ideal_amps = node->getFloatValue("amps", 60.0);
66     } else {
67         model = FG_UNKNOWN;
68     }
69     ideal_volts = node->getFloatValue("volts");
70
71     int i;
72     for ( i = 0; i < node->nChildren(); ++i ) {
73         SGPropertyNode *child = node->getChild(i);
74         // cout << " scanning: " << child->getName() << endl;
75         if ( !strcmp(child->getName(), "prop") ) {
76             string prop = child->getStringValue();
77             // cout << "  Adding prop = " << prop << endl;
78             add_prop( prop );
79             fgSetFloat( prop.c_str(), ideal_amps );
80         }
81     }
82
83     _rpm_node = fgGetNode( rpm_src.c_str(), true);
84 }  
85
86
87 float FGElectricalSupplier::apply_load( float amps, float dt ) {
88     if ( model == FG_BATTERY ) {
89         // calculate amp hours used
90         float amphrs_used = amps * dt / 3600.0;
91
92         // calculate percent of total available capacity
93         float percent_used = amphrs_used / amp_hours;
94         percent_remaining -= percent_used;
95         if ( percent_remaining < 0.0 ) {
96             percent_remaining = 0.0;
97         } else if ( percent_remaining > 1.0 ) {
98             percent_remaining = 1.0;
99         }
100         // cout << "battery percent = " << percent_remaining << endl;
101         return amp_hours * percent_remaining;
102     } else if ( model == FG_ALTERNATOR ) {
103         // scale alternator output for rpms < 600.  For rpms >= 600
104         // give full output.  This is just a WAG, and probably not how
105         // it really works but I'm keeping things "simple" to start.
106         float rpm = _rpm_node->getFloatValue();
107         float factor = rpm / rpm_threshold;
108         if ( factor > 1.0 ) {
109             factor = 1.0;
110         }
111         // cout << "alternator amps = " << amps * factor << endl;
112         float available_amps = ideal_amps * factor;
113         return available_amps - amps;
114     } else if ( model == FG_EXTERNAL ) {
115         // cout << "external amps = " << 0.0 << endl;
116         float available_amps = ideal_amps;
117         return available_amps - amps;
118     } else {
119         SG_LOG( SG_ALL, SG_ALERT, "unknown supplier type" );
120     }
121
122     return 0.0;
123 }
124
125
126 float FGElectricalSupplier::get_output_volts() {
127     if ( model == FG_BATTERY ) {
128         // cout << "battery amps = " << amps << endl;
129         float x = 1.0 - percent_remaining;
130         float tmp = -(3.0 * x - 1.0);
131         float factor = (tmp*tmp*tmp*tmp*tmp + 32) / 32;
132         // cout << "battery % = " << percent_remaining <<
133         //         " factor = " << factor << endl;
134         // percent_remaining -= 0.001;
135         return ideal_volts * factor;
136     } else if ( model == FG_ALTERNATOR ) {
137         // scale alternator output for rpms < 600.  For rpms >= 600
138         // give full output.  This is just a WAG, and probably not how
139         // it really works but I'm keeping things "simple" to start.
140         float rpm = _rpm_node->getFloatValue();
141         float factor = rpm / rpm_threshold;
142         if ( factor > 1.0 ) {
143             factor = 1.0;
144         }
145         // cout << "alternator amps = " << amps * factor << endl;
146         return ideal_volts * factor;
147     } else if ( model == FG_EXTERNAL ) {
148         // cout << "external amps = " << 0.0 << endl;
149         return ideal_volts;
150     } else {
151         SG_LOG( SG_ALL, SG_ALERT, "unknown supplier type" );
152     }
153
154     return 0.0;
155 }
156
157
158 float FGElectricalSupplier::get_output_amps() {
159     if ( model == FG_BATTERY ) {
160         // cout << "battery amp_hours = " << amp_hours << endl;
161
162         // This is a WAG, but produce enough amps to burn the entire
163         // battery in one minute.
164         return amp_hours * 60.0;
165     } else if ( model == FG_ALTERNATOR ) {
166         // scale alternator output for rpms < 600.  For rpms >= 600
167         // give full output.  This is just a WAG, and probably not how
168         // it really works but I'm keeping things "simple" to start.
169         float rpm = _rpm_node->getFloatValue();
170         float factor = rpm / rpm_threshold;
171         if ( factor > 1.0 ) {
172             factor = 1.0;
173         }
174         // cout << "alternator amps = " << ideal_amps * factor << endl;
175         return ideal_amps * factor;
176     } else if ( model == FG_EXTERNAL ) {
177         // cout << "external amps = " << 0.0 << endl;
178         return ideal_amps;
179     } else {
180         SG_LOG( SG_ALL, SG_ALERT, "unknown supplier type" );
181     }
182
183     return 0.0;
184 }
185
186
187 FGElectricalBus::FGElectricalBus ( SGPropertyNode *node ) {
188     kind = FG_BUS;
189
190     name = node->getStringValue("name");
191     int i;
192     for ( i = 0; i < node->nChildren(); ++i ) {
193         SGPropertyNode *child = node->getChild(i);
194         if ( !strcmp(child->getName(), "prop") ) {
195             string prop = child->getStringValue();
196             add_prop( prop );
197         }
198     }
199 }  
200
201
202 FGElectricalOutput::FGElectricalOutput ( SGPropertyNode *node ) {
203     kind = FG_OUTPUT;
204     load_amps = 0.1;            // arbitrary default value
205
206     name = node->getStringValue("name");
207     SGPropertyNode *draw = node->getNode("rated-draw");
208     if ( draw != NULL ) {
209         load_amps = draw->getFloatValue();
210     }
211     // cout << "rated draw = " << output_amps << endl;
212
213     int i;
214     for ( i = 0; i < node->nChildren(); ++i ) {
215         SGPropertyNode *child = node->getChild(i);
216         if ( !strcmp(child->getName(), "prop") ) {
217             string prop = child->getStringValue();
218             add_prop( prop );
219         }
220     }
221 }  
222
223
224 FGElectricalSwitch::FGElectricalSwitch( SGPropertyNode *node ) :
225     switch_node( NULL ),
226     rating_amps( 0.0f ),
227     circuit_breaker( false )
228 {
229     bool initial_state = true;
230     int i;
231     for ( i = 0; i < node->nChildren(); ++i ) {
232         SGPropertyNode *child = node->getChild(i);
233         string cname = child->getName();
234         string cval = child->getStringValue();
235         if ( cname == "prop" ) {
236             switch_node = fgGetNode( cval.c_str(), true );
237             // cout << "switch node = " << cval << endl;
238         } else if ( cname == "initial-state" ) {
239             if ( cval == "off" || cval == "false" ) {
240                 initial_state = false;
241             }
242             // cout << "initial state = " << initial_state << endl;
243         } else if ( cname == "rating-amps" ) {
244             rating_amps = atof( cval.c_str() );
245             circuit_breaker = true;
246             // cout << "initial state = " << initial_state << endl;
247         }            
248     }
249
250     switch_node->setBoolValue( initial_state );
251     // cout << "  value = " << switch_node->getBoolValue() << endl;
252 }
253
254
255 FGElectricalConnector::FGElectricalConnector ( SGPropertyNode *node,
256                                                FGElectricalSystem *es ) {
257     kind = FG_CONNECTOR;
258     name = "connector";
259     int i;
260     for ( i = 0; i < node->nChildren(); ++i ) {
261         SGPropertyNode *child = node->getChild(i);
262         string cname = child->getName();
263         string cval = child->getStringValue();
264         // cout << "  " << cname << " = " << cval << endl;
265         if ( cname == "input" ) {
266             FGElectricalComponent *s = es->find( child->getStringValue() );
267             if ( s != NULL ) {
268                 add_input( s );
269                 if ( s->get_kind() == FG_SUPPLIER ) {
270                     s->add_output( this );
271                 } else if ( s->get_kind() == FG_BUS ) {
272                     s->add_output( this );
273                 } else {
274                     SG_LOG( SG_ALL, SG_ALERT,
275                             "Attempt to connect to something that can't provide an output: " 
276                             << child->getStringValue() );
277                 }
278             } else {
279                 SG_LOG( SG_ALL, SG_ALERT, "Can't find named source: " 
280                         << child->getStringValue() );
281             }
282         } else if ( cname == "output" ) {
283             FGElectricalComponent *s = es->find( child->getStringValue() );
284             if ( s != NULL ) {
285                 add_output( s );
286                 if ( s->get_kind() == FG_BUS ) {
287                     s->add_input( this );
288                 } else if ( s->get_kind() == FG_OUTPUT ) {
289                     s->add_input( this );
290                 } else if ( s->get_kind() == FG_SUPPLIER &&
291                             ((FGElectricalSupplier *)s)->get_model()
292                             == FGElectricalSupplier::FG_BATTERY ) {
293                     s->add_output( this );
294                 } else {
295                     SG_LOG( SG_ALL, SG_ALERT,
296                             "Attempt to connect to something that can't provide an input: " 
297                             << child->getStringValue() );
298                 }
299             } else {
300                 SG_LOG( SG_ALL, SG_ALERT, "Can't find named source: " 
301                         << child->getStringValue() );
302             }
303         } else if ( cname == "switch" ) {
304              // cout << "Switch = " << child->getStringValue() << endl;
305             FGElectricalSwitch s( child );
306             add_switch( s );
307         }
308     }
309 }  
310
311
312 // set all switches to the specified state
313 void FGElectricalConnector::set_switches( bool state ) {
314     // cout << "setting switch state to " << state << endl;
315     for ( unsigned int i = 0; i < switches.size(); ++i ) {
316         switches[i].set_state( state );
317     }
318 }
319
320
321 // return true if all switches are true, false otherwise.  A connector
322 // could have multiple switches, but they all need to be true(closed)
323 // for current to get through.
324 bool FGElectricalConnector::get_state() {
325     unsigned int i;
326     for ( i = 0; i < switches.size(); ++i ) {
327         if ( ! switches[i].get_state() ) {
328             return false;
329         }
330     }
331
332     return true;
333 }
334
335
336 FGElectricalSystem::FGElectricalSystem ( SGPropertyNode *node ) :
337     name(node->getStringValue("name", "electrical")),
338     num(node->getIntValue("number", 0)),
339     path(node->getStringValue("path")),
340     enabled(false)
341 {
342 }
343
344
345 FGElectricalSystem::~FGElectricalSystem () {
346 }
347
348
349 void FGElectricalSystem::init () {
350     config_props = new SGPropertyNode;
351
352     _volts_out = fgGetNode( "/systems/electrical/volts", true );
353     _amps_out = fgGetNode( "/systems/electrical/amps", true );
354
355     // allow the electrical system to be specified via the
356     // aircraft-set.xml file (for backwards compatibility) or through
357     // the aircraft-systems.xml file.  If a -set.xml entry is
358     // specified, that overrides the system entry.
359     SGPropertyNode *path_n = fgGetNode("/sim/systems/electrical/path");
360     if ( path_n ) {
361         if ( path.length() ) {
362             SG_LOG( SG_ALL, SG_INFO,
363                     "NOTICE: System manager configuration specifies an " <<
364                     "electrical system: " << path << " but it is " <<
365                     "being overridden by the one specified in the -set.xml " <<
366                     "file: " << path_n->getStringValue() );
367         }
368
369         path = path_n->getStringValue();
370     }
371
372     if ( path.length() ) {
373         SGPath config( globals->get_fg_root() );
374         config.append( path );
375
376         // load an obsolete xml configuration
377         SG_LOG( SG_ALL, SG_WARN,
378                 "Reading deprecated xml electrical system model from\n    "
379                 << config.str() );
380         try {
381             readProperties( config.str(), config_props );
382
383             if ( build() ) {
384                 enabled = true;
385             } else {
386                 SG_LOG( SG_ALL, SG_ALERT,
387                         "Detected a logic error in the electrical system ");
388                 SG_LOG( SG_ALL, SG_ALERT,
389                         "specification file.  See earlier errors for " );
390                 SG_LOG( SG_ALL, SG_ALERT,
391                         "details.");
392                 exit(-1);
393             }        
394         } catch (const sg_exception& exc) {
395             SG_LOG( SG_ALL, SG_ALERT,
396                     "Failed to load electrical system model: "
397                     << config.str() );
398         }
399     } else {
400         SG_LOG( SG_ALL, SG_INFO,
401                 "No xml-based electrical model specified for this model!");
402     }
403
404     if ( !enabled ) {
405         _amps_out->setDoubleValue(0);
406     }
407
408     delete config_props;
409 }
410
411
412 void FGElectricalSystem::bind () {
413 }
414
415
416 void FGElectricalSystem::unbind () {
417 }
418
419
420 void FGElectricalSystem::update (double dt) {
421     if ( !enabled ) {
422         return;
423     }
424
425     // cout << "Updating electrical system, dt = " << dt << endl;
426
427     unsigned int i;
428
429     // zero out the voltage before we start, but don't clear the
430     // requested load values.
431     for ( i = 0; i < suppliers.size(); ++i ) {
432         suppliers[i]->set_volts( 0.0 );
433     }
434     for ( i = 0; i < buses.size(); ++i ) {
435         buses[i]->set_volts( 0.0 );
436     }
437     for ( i = 0; i < outputs.size(); ++i ) {
438         outputs[i]->set_volts( 0.0 );
439     }
440     for ( i = 0; i < connectors.size(); ++i ) {
441         connectors[i]->set_volts( 0.0 );
442     }
443
444     // for each "external" supplier, propagate the electrical current
445     for ( i = 0; i < suppliers.size(); ++i ) {
446         FGElectricalSupplier *node = (FGElectricalSupplier *)suppliers[i];
447         if ( node->get_model() == FGElectricalSupplier::FG_EXTERNAL ) {
448             float load;
449             // cout << "Starting propagation: " << suppliers[i]->get_name()
450             //      << endl;
451             load = propagate( suppliers[i], dt,
452                               node->get_output_volts(),
453                               node->get_output_amps(),
454                               " " );
455
456             if ( node->apply_load( load, dt ) < 0.0 ) {
457                 SG_LOG(SG_ALL, SG_ALERT,
458                        "Error drawing more current than available!");
459             }
460         }     
461     }
462
463     // for each "alternator" supplier, propagate the electrical
464     // current
465     for ( i = 0; i < suppliers.size(); ++i ) {
466         FGElectricalSupplier *node = (FGElectricalSupplier *)suppliers[i];
467         if ( node->get_model() == FGElectricalSupplier::FG_ALTERNATOR) {
468             float load;
469             // cout << "Starting propagation: " << suppliers[i]->get_name()
470             //      << endl;
471             load = propagate( suppliers[i], dt,
472                               node->get_output_volts(),
473                               node->get_output_amps(),
474                               " " );
475
476             if ( node->apply_load( load, dt ) < 0.0 ) {
477                 SG_LOG(SG_ALL, SG_ALERT,
478                        "Error drawing more current than available!");
479             }
480         }     
481     }
482
483     // for each "battery" supplier, propagate the electrical
484     // current
485     for ( i = 0; i < suppliers.size(); ++i ) {
486         FGElectricalSupplier *node = (FGElectricalSupplier *)suppliers[i];
487         if ( node->get_model() == FGElectricalSupplier::FG_BATTERY ) {
488             float load;
489             // cout << "Starting propagation: " << suppliers[i]->get_name()
490             //      << endl;
491             load = propagate( suppliers[i], dt,
492                               node->get_output_volts(),
493                               node->get_output_amps(),
494                               " " );
495             // cout << "battery load = " << load << endl;
496
497             if ( node->apply_load( load, dt ) < 0.0 ) {
498                 SG_LOG(SG_ALL, SG_ALERT,
499                        "Error drawing more current than available!");
500             }
501         }     
502     }
503
504     float alt_norm
505         = fgGetFloat("/systems/electrical/suppliers/alternator") / 60.0;
506
507     // impliment an extremely simplistic voltage model (assumes
508     // certain naming conventions in electrical system config)
509     // FIXME: we probably want to be able to feed power from all
510     // engines if they are running and the master-alt is switched on
511     float volts = 0.0;
512     if ( fgGetBool("/controls/engines/engine[0]/master-bat") ) {
513         volts = 24.0;
514     }
515     if ( fgGetBool("/controls/engines/engine[0]/master-alt") ) {
516         if ( fgGetFloat("/engines/engine[0]/rpm") > 800 ) {
517             float alt_contrib = 28.0;
518             if ( alt_contrib > volts ) {
519                 volts = alt_contrib;
520             }
521         } else if ( fgGetFloat("/engines/engine[0]/rpm") > 200 ) {
522             float alt_contrib = 20.0;
523             if ( alt_contrib > volts ) {
524                 volts = alt_contrib;
525             }
526         }
527     }
528     _volts_out->setFloatValue( volts );
529
530     // impliment an extremely simplistic amps model (assumes certain
531     // naming conventions in the electrical system config) ... FIXME:
532     // make this more generic
533     float amps = 0.0;
534     if ( fgGetBool("/controls/engines/engine[0]/master-bat") ) {
535         if ( fgGetBool("/controls/engines/engine[0]/master-alt") &&
536              fgGetFloat("/engines/engine[0]/rpm") > 800 )
537         {
538             amps += 40.0 * alt_norm;
539         }
540         amps -= 15.0;            // normal load
541         if ( fgGetBool("/controls/switches/flashing-beacon") ) {
542             amps -= 7.5;
543         }
544         if ( fgGetBool("/controls/switches/nav-lights") ) {
545             amps -= 7.5;
546         }
547         if ( amps > 7.0 ) {
548             amps = 7.0;
549         }
550     }
551     _amps_out->setFloatValue( amps );
552 }
553
554
555 bool FGElectricalSystem::build () {
556     SGPropertyNode *node;
557     int i;
558
559     int count = config_props->nChildren();
560     for ( i = 0; i < count; ++i ) {
561         node = config_props->getChild(i);
562         string name = node->getName();
563         // cout << name << endl;
564         if ( name == "supplier" ) {
565             FGElectricalSupplier *s =
566                 new FGElectricalSupplier( node );
567             suppliers.push_back( s );
568         } else if ( name == "bus" ) {
569             FGElectricalBus *b =
570                 new FGElectricalBus( node );
571             buses.push_back( b );
572         } else if ( name == "output" ) {
573             FGElectricalOutput *o =
574                 new FGElectricalOutput( node );
575             outputs.push_back( o );
576         } else if ( name == "connector" ) {
577             FGElectricalConnector *c =
578                 new FGElectricalConnector( node, this );
579             connectors.push_back( c );
580         } else {
581             SG_LOG( SG_ALL, SG_ALERT, "Unknown component type specified: " 
582                     << name );
583             return false;
584         }
585     }
586
587     return true;
588 }
589
590
591 // propagate the electrical current through the network, returns the
592 // total current drawn by the children of this node.
593 float FGElectricalSystem::propagate( FGElectricalComponent *node, double dt,
594                                      float input_volts, float input_amps,
595                                      string s ) {
596     s += " ";
597     
598     float total_load = 0.0;
599
600     // determine the current to carry forward
601     float volts = 0.0;
602     if ( !fgGetBool("/systems/electrical/serviceable") ) {
603         volts = 0;
604     } else if ( node->get_kind() == FGElectricalComponent::FG_SUPPLIER ) {
605         // cout << s << "is a supplier (" << node->get_name() << ")" << endl;
606         FGElectricalSupplier *supplier = (FGElectricalSupplier *)node;
607         if ( supplier->get_model() == FGElectricalSupplier::FG_BATTERY ) {
608             // cout << s << " (and is a battery)" << endl;
609             float battery_volts = supplier->get_output_volts();
610             if ( battery_volts < (input_volts - 0.1) ) {
611                 // special handling of a battery charge condition
612                 // cout << s << "  (and is being charged) in v = "
613                 //      << input_volts << " current v = " << battery_volts
614                 //      << endl;
615                 supplier->apply_load( -supplier->get_charge_amps(), dt );
616                 return supplier->get_charge_amps();
617             }
618         }
619         volts = input_volts;
620     } else if ( node->get_kind() == FGElectricalComponent::FG_BUS ) {
621         // cout << s << "is a bus (" << node->get_name() << ")" << endl;
622         volts = input_volts;
623     } else if ( node->get_kind() == FGElectricalComponent::FG_OUTPUT ) {
624         // cout << s << "is an output (" << node->get_name() << ")" << endl;
625         volts = input_volts;
626         if ( volts > 1.0 ) {
627             // draw current if we have voltage
628             total_load = node->get_load_amps();
629         }
630     } else if ( node->get_kind() == FGElectricalComponent::FG_CONNECTOR ) {
631         // cout << s << "is a connector (" << node->get_name() << ")" << endl;
632         if ( ((FGElectricalConnector *)node)->get_state() ) {
633             volts = input_volts;
634         } else {
635             volts = 0.0;
636         }
637         // cout << s << "  input_volts = " << volts << endl;
638     } else {
639         SG_LOG( SG_ALL, SG_ALERT, "unkown node type" );
640     }
641
642     int i;
643
644     // if this node has found a stronger power source, update the
645     // value and propagate to all children
646     if ( volts > node->get_volts() ) {
647         node->set_volts( volts );
648         for ( i = 0; i < node->get_num_outputs(); ++i ) {
649             FGElectricalComponent *child = node->get_output(i);
650             // send current equal to load
651             total_load += propagate( child, dt,
652                                      volts, child->get_load_amps(),
653                                      s );
654         }
655
656         // if not an output node, register the downstream current draw
657         // (sum of all children) with this node.  If volts are zero,
658         // current draw should be zero.
659         if ( node->get_kind() != FGElectricalComponent::FG_OUTPUT ) {
660             node->set_load_amps( total_load );
661         }
662
663         node->set_available_amps( input_amps - total_load );
664
665         // publish values to specified properties
666         for ( i = 0; i < node->get_num_props(); ++i ) {
667             fgSetFloat( node->get_prop(i).c_str(), node->get_volts() );
668         }
669
670         /*
671         cout << s << node->get_name() << " -> (volts) " << node->get_volts()
672              << endl;
673         cout << s << node->get_name() << " -> (load amps) " << total_load
674              << endl;
675         cout << s << node->get_name() << " -> (input amps) " << input_amps
676              << endl;
677         cout << s << node->get_name() << " -> (extra amps) "
678              << node->get_available_amps() << endl;
679         */
680
681         return total_load;
682     } else {
683         // cout << s << "no further propagation" << endl;
684         return 0.0;
685     }
686 }
687
688
689 // search for the named component and return a pointer to it, NULL otherwise
690 FGElectricalComponent *FGElectricalSystem::find ( const string &name ) {
691     unsigned int i;
692     string s;
693
694     // search suppliers
695     for ( i = 0; i < suppliers.size(); ++i ) {
696         s = suppliers[i]->get_name();
697         // cout <<  "    " << s << endl;
698         if ( s == name ) {
699             return suppliers[i];
700         }
701     }
702
703     // then search buses
704     for ( i = 0; i < buses.size(); ++i ) {
705         s = buses[i]->get_name();
706         // cout <<  "    " << s << endl;
707         if ( s == name ) {
708             return buses[i];
709         }
710     }
711
712     // then search outputs
713     for ( i = 0; i < outputs.size(); ++i ) {
714         s = outputs[i]->get_name();
715         // cout <<  "    " << s << endl;
716         if ( s == name ) {
717             return outputs[i];
718         }
719     }
720
721     // nothing found
722     return NULL;
723 }