]> git.mxchange.org Git - flightgear.git/blob - src/Systems/vacuum.cxx
Sync. w. JSBSim CVS
[flightgear.git] / src / Systems / vacuum.cxx
1 // vacuum.cxx - a vacuum pump connected to the aircraft engine.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #ifdef HAVE_CONFIG_H
7 #  include <config.h>
8 #endif
9
10 #include "vacuum.hxx"
11 #include <Main/fg_props.hxx>
12
13
14 VacuumSystem::VacuumSystem ( SGPropertyNode *node )
15     :
16     _name(node->getStringValue("name", "vacuum")),
17     _num(node->getIntValue("number", 0)),
18     _scale(node->getDoubleValue("scale", 1.0))
19 {
20     for ( int i = 0; i < node->nChildren(); ++i ) {
21         SGPropertyNode *child = node->getChild(i);
22         if (!strcmp(child->getName(), "rpm"))
23             _rpms.push_back(child->getStringValue());
24     }
25 }
26
27 VacuumSystem::~VacuumSystem ()
28 {
29 }
30
31 void
32 VacuumSystem::init()
33 {
34     unsigned int i;
35     string branch;
36     branch = "/systems/" + _name;
37
38     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
39     _serviceable_node = node->getChild("serviceable", 0, true);
40     for ( i = 0; i < _rpms.size(); i++ ) {
41       SGPropertyNode_ptr _rpm_node = fgGetNode(_rpms[i].c_str(), true);
42       _rpm_nodes.push_back( _rpm_node );
43     }
44     _pressure_node = fgGetNode("/environment/pressure-inhg", true);
45     _suction_node = node->getChild("suction-inhg", 0, true);
46 }
47
48 void
49 VacuumSystem::bind ()
50 {
51 }
52
53 void
54 VacuumSystem::unbind ()
55 {
56 }
57
58 void
59 VacuumSystem::update (double dt)
60 {
61     // Model taken from steam.cxx
62
63     double suction;
64     unsigned int i;
65
66     if (!_serviceable_node->getBoolValue()) {
67         suction = 0.0;
68     } else {
69         // select the source with the max rpm
70         double rpm = 0.0;
71         for ( i = 0; i < _rpm_nodes.size(); i++ ) {
72           double tmp = _rpm_nodes[i]->getDoubleValue() * _scale;
73           if ( tmp > rpm ) {
74             rpm = tmp;
75           }
76         }
77         double pressure = _pressure_node->getDoubleValue();
78         // This magic formula yields about 4 inhg at 700 rpm
79         suction = pressure * rpm / (rpm + 4875.0);
80
81         // simple regulator model that clamps smoothly to about 5 inhg
82         // over a normal rpm range
83         double max = (rpm > 0 ? 5.39 - 1.0 / ( rpm * 0.00111 ) : 0);
84         if ( suction < 0.0 ) suction = 0.0;
85         if ( suction > max ) suction = max;
86     }
87     _suction_node->setDoubleValue(suction);
88 }
89
90 // end of vacuum.cxx