Skip to content

Commit 02ad4d4

Browse files
committed
changed code for ffffg
1 parent 982538b commit 02ad4d4

File tree

2 files changed

+53
-32
lines changed

2 files changed

+53
-32
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.exe
2+
.vscode

ejectionChargeCalculator.cpp

+51-32
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,71 @@ E-mail: [email protected]
44
*/
55
#include <iostream>
66
#include <cmath>
7-
87
using namespace std;
98

10-
double calculatePyrotechnicCharge(double volume, double pressure, double temperature, double heightAboveSeaLevel)
9+
10+
const double pi = 3.14159;
11+
const double gm_to_lbs = 1.0 / 453.593;
12+
const double cm_to_inch_conversion = 0.393701; // 1 cm = 0.393701 inches
13+
const double B = 22.16 * 12.0; // in-lbf/lbm
14+
const double T = 3307.0; // Combustion temperature of FFFFg in degrees R
15+
16+
// Function to calculate the volume of a cylinder
17+
double calculate_cylinder_volume(double diameter_in_inches, double length_in_inches)
18+
{
19+
// Convert diameter to radius in inches
20+
double radius_in_inches = diameter_in_inches / 2.0;
21+
22+
// Calculate volume in cubic inches
23+
double volume_in_cubic_inches = pi * pow(radius_in_inches, 2) * length_in_inches;
24+
25+
return volume_in_cubic_inches;
26+
}
27+
28+
// Function to calculate the grams of FFFFg black powder
29+
double calculate_black_powder_grams(double pressure_in_PSI, double diameter_in_inches, double length_in_inches)
1130
{
12-
// Constants
13-
const double gasConstant = 8.314; // Universal gas constant [J/(mol*K)]
14-
const double standardTemperature = 288.15; // Standard temperature at sea level [K]
15-
const double molarMassAir = 0.02897; // Molar mass of dry air [kg/mol]
16-
const double specificGasConstant = gasConstant / molarMassAir; // Specific gas constant for dry air [J/(kg*K)]
17-
18-
// Adjust temperature and height above sea level
19-
double temperatureInKelvin = temperature + 273.15;
20-
double adjustedPressure = pressure * exp(-heightAboveSeaLevel / (specificGasConstant * temperatureInKelvin));
21-
22-
// Calculate the amount of pyrotechnic charge needed in moles
23-
double pyrotechnicChargeMoles = (volume * adjustedPressure) / (specificGasConstant * temperatureInKelvin);
24-
25-
// Convert moles to grams using the molar mass
26-
double pyrotechnicChargeGrams = pyrotechnicChargeMoles * molarMassAir;
27-
return pyrotechnicChargeGrams;
31+
double pressure_in_lbf_per_inch2 = pressure_in_PSI; // The input pressure is already in lbf/in^2
32+
33+
// Calculate the volume of the cylinder in cubic inches
34+
double volume_in_cubic_inches = calculate_cylinder_volume(diameter_in_inches, length_in_inches);
35+
36+
// Calculate the constant z
37+
double z = 1.0 / (gm_to_lbs * B * T);
38+
39+
// Calculate the final charge in grams
40+
double final_charge_grams = pressure_in_lbf_per_inch2 * volume_in_cubic_inches * z;
41+
42+
return final_charge_grams;
2843
}
2944

3045
int main()
3146
{
32-
// User inputs
33-
double containerVolume, requiredPressure, expectedTemperature, heightAboveSeaLevel;
47+
// User input
48+
double diameter_in_cm;
49+
double length_in_cm;
50+
double diameter_in_inches;
51+
double length_in_inches;
52+
double pressure_in_PSI;
3453

35-
// Get user inputs
36-
cout << "Enter the container volume (in cubic meters): ";
37-
cin >> containerVolume;
54+
cout << "Enter the diameter of the parachute section body tube (in cm): ";
55+
cin >> diameter_in_cm;
3856

39-
cout << "Enter the required pressure (in Pascals): ";
40-
cin >> requiredPressure;
57+
cout << "Enter the length of the parachute section body tube (in cm): ";
58+
cin >> length_in_cm;
4159

42-
cout << "Enter the expected temperature (in Celsius): ";
43-
cin >> expectedTemperature;
60+
cout << "Enter the desired pressure in PSI: ";
61+
cin >> pressure_in_PSI;
4462

45-
cout << "Enter the height above sea level (in meters): ";
46-
cin >> heightAboveSeaLevel;
63+
// cm to inches
64+
diameter_in_inches = diameter_in_cm * cm_to_inch_conversion;
65+
length_in_inches = length_in_cm * cm_to_inch_conversion;
4766

48-
// Calculate the pyrotechnic charge in grams
49-
double chargeAmountInGrams = calculatePyrotechnicCharge(containerVolume, requiredPressure, expectedTemperature, heightAboveSeaLevel);
67+
// Calculate the grams of FFFFg black powder
68+
double black_powder_grams = calculate_black_powder_grams(pressure_in_PSI, diameter_in_inches, length_in_inches);
5069

5170
// Display the result
52-
cout << "The amount of pyrotechnic charge needed is: " << chargeAmountInGrams << " grams" << endl;
71+
cout << "Grams of FFFFg Black Powder: " << black_powder_grams << " grams" << endl;
5372

5473
return 0;
5574
}

0 commit comments

Comments
 (0)