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