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