Initial commit of "Rocket Workbench".
Taken from sources in CVS at:
https://sourceforge.net/projects/rocketworkbench/
Sources extracted in two steps:
1. Pull entire project tree into a subdir "rwb" via "rsync":
rsync -a a.cvs.sourceforge.net::cvsroot/rocketworkbench/ rwb/.
2. Export sources:
export CVSROOT=$(pwd)/rwb
SUBDIRS="analyser cpropep cpropep-web CVSROOT data libcompat libcpropep libnum libsimulation libthermo prop rocketworkbench rockflight"
mkdir rwbx; cd rwbx
cvs export -D now ${SUBDIRS}
After this (and some backups for safety), the directory content was
added to a Git repo:
git init .
git add *
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
|
||||
CC = gcc
|
||||
COPT = -g -Wall -O3 #-pg -O6\
|
||||
# -mpentium -ffast-math -funroll-loops -fnonnull-objects\
|
||||
# -fno-exceptions -fforce-mem -fforce-addr -fcse-follow-jumps\
|
||||
# -fexpensive-optimizations -march=pentium -fno-rtti #-fomit-frame-pointer
|
||||
|
||||
DEF = -DGCC #-DTRUE_ARRAY
|
||||
|
||||
all:
|
||||
make -C src all
|
||||
|
||||
clean:
|
||||
make -C src clean
|
||||
|
||||
deep-clean: clean
|
||||
make -C src deep-clean
|
||||
@@ -0,0 +1,135 @@
|
||||
<plaintext>
|
||||
The NASA thermo data file format was documented in:
|
||||
|
||||
Sanford Gordon and Bonnie J. McBride, "Computer Program for Calculation of
|
||||
Complex Chemical Equilibrium Compositions and Applications: I. Analysis",
|
||||
NASA Reference Publication 1311, October 1994.
|
||||
|
||||
Bonnie J. McBride and Sanford Gordon, "Computer Program for Calculation of
|
||||
Complex Chemical Equilibrium Compositions and Applications: II. Users Manual
|
||||
and Program Description", NASA Reference Publication 1311, June 1996.
|
||||
|
||||
The equations below for nondimensional specific heat, enthalpy, and
|
||||
entropy, are given in Sanford and Bonnie (1994). Eqs. 4.6-4.8 are the
|
||||
"old" NASA format, and Eqs. 4.9-4.11 are the "new" NASA format as discussed
|
||||
in this file.
|
||||
|
||||
Eq. 4.6: Cp0/R = a1 + a2*T + a3*T^2 + a4*T^3 + a5*T^4
|
||||
Eq. 4.7: H0/RT = a1 + a2/2*T + a3/3*T^2 + a4/4*T^3 + a5/5*T^4 + a6/T
|
||||
Eq. 4.8: S0/R = a1*ln(T) + a2*T + a3/2*T^2 + a4/3*T^3 + a5/4*T^4 + a7
|
||||
|
||||
Eq. 4.9: Cp0/R = a1*T^-2 + a2*T^-1 + a3 + a4*T + a5*T^2 + a6*T^3 + a7*T^4
|
||||
Eq. 4.10: H0/RT = -a1*T^-2 + a2*T^-1*ln(T) + a3 + a4*T/2 + a5*T^2/3 +
|
||||
a6*T^3/4 + a7*T^4/5 + b1/T
|
||||
Eq. 4.11: S0/R = -a1*T^-2/2 - a2*T^-1 + a3*ln(T) + a4*T + a5*T^2/2 +
|
||||
a6*T^3/6 + a7*T^4/4 + b2
|
||||
|
||||
The following information is quoted directly from McBride and Gordon (1996):
|
||||
|
||||
"Appendix A: Format for Thermodynamic Data
|
||||
|
||||
The library of thermodynamic data contains data for both reaction products
|
||||
and reactants. All reaction products and some reactants are in the
|
||||
nine-constant functional form discussed in section 4.2 of Gordon and
|
||||
McBride (1994). The format for these data is given here. Thermodynamic
|
||||
data are provided with the program on a separate file, thermo.inp.
|
||||
Sections 2.8 and 5.24 discuss the processing of the thermo.inp data and
|
||||
the storing of the processed data in thermo.lib for subsequent use in the
|
||||
CEA program. Names of species contained in thermo.inp are listed in
|
||||
Appendix B.
|
||||
|
||||
The general format is given in table A1. This format is applicable for
|
||||
all gaseous species and for those condensed species whose data extend over
|
||||
a temperature range. For those condensed species with data given at only
|
||||
one temperature, the format is somewhat different. On record 2, instead
|
||||
of the last number being a heat of formation, it is an assigned enthalpy.
|
||||
(Note that if the temperature is 298.15 K, the heat of formation and the
|
||||
assigned enthalpy are equivalent.) The first number in record 2 (number
|
||||
of temperature intervals) is always zero. On record 3, only one number is
|
||||
given, the temperature of the assigned enthalpy on record 2. Two examples are
|
||||
given. Example A1, for chlorine gas, illustrates the general format.
|
||||
Example A2, for liquid acetylene, illustrates the format for a condensed
|
||||
species with data given at only one temperature. The general equations
|
||||
for dimensionless heat capacity, enthalpy, and entropy (eqs. (4.6) to (4.8)
|
||||
<sic> from Gordon and McBride, 1994) are repeated for convenience.
|
||||
|
||||
Record Constants Format Column
|
||||
1 Species name or formula A24 1 to 24
|
||||
Comments (data source) A56 25-80
|
||||
2 Number of T intervals I2 2
|
||||
Optional identification code A6 4-9
|
||||
Chemical formulas, symbols, and numbers 5(A2,F6.2) 11-50
|
||||
Zero for gas and nonzero for condensed phases I1 52
|
||||
Molecular weight F13.5 53-65
|
||||
Heat of formation at 298.15 K, J/mol F13.5 66-80
|
||||
3 Temperature range 2F10.3 2-21
|
||||
Number of coefficients for Cp0/R I1 23
|
||||
T exponents in empirical equation for Cp0/R 8F5.1 24-63
|
||||
{H0(298.15)-H0(0)}, J/mol F15.3 66-80
|
||||
4 First five coefficients for Cp0/R 5D16.8 1-80
|
||||
5 Last three coefficients for Cp0/R 3D16.8 1-48
|
||||
Integration constants b1 and b2 2D16.8 49-80
|
||||
... Repeat 3, 4, and 5 for each interval
|
||||
|
||||
Example A.1:
|
||||
|
||||
CL2 Chlorine gas. TPIS 1989, v1, pt2, p88.
|
||||
2 tpis89 CL 2.00 0.00 0.00 0.00 0.00 0 70.90540 0.000
|
||||
200.000 1000.000 7 -2.0 -1.0 0.0 1.0 2.0 3.0 4.0 0.0 9181.110
|
||||
3.46281724D+04 -5.54712949D+02 6.20759103D+00 -2.98963673D-03 3.17303416D-06
|
||||
-1.79363467D-09 4.26005863D-13 0.00000000D+00 1.53407075D+03 -9.43835303D+00
|
||||
1000.000 6000.000 7 -2.0 -1.0 0.0 1.0 2.0 3.0 4.0 0.0 9181.110
|
||||
6.09256675D+06 -1.94962688D+04 2.85453491D+01 -1.44996828D-02 4.46388943D-06
|
||||
-6.35852403D-10 3.32735931D-14 0.00000000D+00 1.21211722D+05 -1.69077832D+02
|
||||
|
||||
Empirical equations for example A.1:
|
||||
|
||||
Heat capacity: Cp0/R = a1*T^-2 + a2*T^-1 + a3 + a4*T + a5*T^2 + a6*T^3 + a7*T^4
|
||||
Enthalpy: H0(T)/(RT) = -a1*T^-2 + a2*T^-1*ln(T) + a3 + a4*T/2 + a5*T^2/3 +
|
||||
a6*T^3/4 + a7*T^4/5 + b1/T
|
||||
Entropy: S0(T)/R = -a1*T^-2/2 - a2*T^-1 + a3*ln(T) + a4*T + a5*T^2/2 +
|
||||
at*T^3/3 + a7*T^4/4 + b2
|
||||
|
||||
Example A.2:
|
||||
|
||||
C2H2(L),acetyle Acetylene. JANAF Prop.Ser.E,1/67. TRC a-3000,10/86.
|
||||
0 1 3/95 C 2.00H 2.00 0.00 0.00 0.00 1 26.03788 207599.000
|
||||
192.35"
|
||||
|
||||
Notes:
|
||||
1. Besides a very different file layout, the most significant change between
|
||||
the older (1971) NASA thermo data and the 1996 data is the generalization
|
||||
to any number of temperature intervals.
|
||||
2. The preceding discussion only mentions the format of individual species
|
||||
data blocks. In addition, the thermo input file included with the NASA
|
||||
CEA program contains:
|
||||
a. Comments at the top of the file marked by exclamation (!) points in the
|
||||
first column
|
||||
b. Two lines at the beginning of the species data:
|
||||
i. One line containing only "thermo"
|
||||
ii. One line with 4 temperatures and a date
|
||||
c. A line containing only "END PRODUCTS" separating product species from
|
||||
reactants, and a line at the end of the file containing only
|
||||
"END REACTANTS".
|
||||
3. There are some differences between the format actually used by CEA and
|
||||
the format described in McBride and Gordon (1996), and some undocumented
|
||||
features:
|
||||
a. In the CEA code, the actual read and format statements differ from the
|
||||
documentation by:
|
||||
i. The species name on the first line of a block is 15 characters long,
|
||||
not 24. The rest of the line is comments.
|
||||
ii. The heat of formation at the end of line 2 is read with f15.3, not f13.5
|
||||
iii. The temperature range at the beginning of line 3 is read as 2F11.3,
|
||||
not 2F10.3.
|
||||
iv. Line 5 is formatted as 2D16.8,16x,2D16.8 rather than
|
||||
3D16.8,2D16.8. The 16x acknowledges that the third field is
|
||||
not actually used. The first two fields are the 6th and 7th
|
||||
polynomial coefficients, and the last two fields are the 8th and
|
||||
9th (integration constants).
|
||||
b. Although the number of polynomial coefficients is included in the data,
|
||||
this number is almost always 7 (plus 2 integration constants). In the
|
||||
current NASA database, there are only 3 species that use less than
|
||||
7 coefficients (P4O10(cr), P4O10(cr), and P4O10(L)). Apparently if
|
||||
less than 7 are used, they are the lowest numbered (a1, a2, a3, ...).
|
||||
4. In the preceding excerpt from McBride and Gordon (1996), reference is
|
||||
made to eqs. (4.6) to (4.8). These should be eqs. (4.9) to (4.11).
|
||||
@@ -0,0 +1,31 @@
|
||||
CC = gcc
|
||||
COPT = -g -Wall -O3 #-pg
|
||||
|
||||
LIB = -lcpropep -lthermo -lnum -lm
|
||||
ROOT = ../..
|
||||
LIBDIR = -L$(ROOT)/libnum/lib \
|
||||
-L$(ROOT)/libthermo/lib \
|
||||
-L$(ROOT)/libcpropep/lib
|
||||
|
||||
INCDIR = -I$(ROOT)/libnum/include/ \
|
||||
-I$(ROOT)/libthermo/include/ \
|
||||
-I$(ROOT)/libcpropep/include/ \
|
||||
-I$(ROOT)/libcompat/include/
|
||||
|
||||
DEF = -DGCC -DCONF_FILE=\"/etc/rocketworkbench/cpropep.conf\"
|
||||
PROG = cpropep
|
||||
OBJS = cpropep.o
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
.c.o:
|
||||
$(CC) $(DEF) $(INCDIR) $(COPT) -c $*.c -o $*.o
|
||||
|
||||
$(PROG): $(OBJS)
|
||||
$(CC) $(COPT) $(OBJS) $(LIBDIR) $(LIB) -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o *~
|
||||
|
||||
deep-clean: clean
|
||||
rm -f $(PROG)
|
||||
@@ -0,0 +1,36 @@
|
||||
CC = bcc32
|
||||
CPP32 = cpp32
|
||||
LIBRARIAN = tlib
|
||||
LINKER = ilink32
|
||||
RC = brc32
|
||||
|
||||
COPT = -3 -O2 -w-8012 -w-8004 -w-8057 -IC:\borland\bcc55\include
|
||||
LDOPT = -LC:\borland\bcc55\lib
|
||||
IDIR = -I..\..\libnum\ -I..\lib\ -I.
|
||||
|
||||
LIB = compat.lib libnum.lib thermo.lib cpropep.lib
|
||||
|
||||
LIBDIR = -L..\..\libnum\ -L..\lib\
|
||||
|
||||
DEF = -DBORLAND
|
||||
|
||||
PROG = cpropep.exe
|
||||
OBJS = cpropep.obj getopt.obj
|
||||
|
||||
.SUFFIXES: .c
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(COPT) $(IDIR) $(DEF) -c $*.c -o $*.obj
|
||||
|
||||
$(PROG): $(OBJS)
|
||||
$(CC) $(LDOPT) $(LIBDIR) $(LIB) $(OBJS)
|
||||
|
||||
clean:
|
||||
del *.obj
|
||||
del *.bak
|
||||
del *.tds
|
||||
|
||||
deep-clean: clean
|
||||
del $(PROG)
|
||||
@@ -0,0 +1,31 @@
|
||||
This is cpropep version 1.0, a program for determining the
|
||||
theoretical performance of rocket propellant compositions.
|
||||
Cpropep is released under the GPL and is written in ANSI C.
|
||||
It has compiled successfully under the following platforms:
|
||||
|
||||
. i686 Windows 98 (4.10.1998) running Microsoft Visual
|
||||
C++ 6.0 Standard Edition with Microsoft Visual Studio
|
||||
Service Pack 2
|
||||
. i686 Red Hat Linux 6.2 (Kernel 2.2.14-12) with gcc
|
||||
. i586 Debian GNU/Linux 2.2 (Kernel 2.2.16) with gcc
|
||||
|
||||
To compile under linux, type make in the top-level directory.
|
||||
Under MSVC++, create a new Win32 console project file, add
|
||||
all source and header files to the project, set the header
|
||||
file directory to ..\lib\ (or copy all files from \lib to
|
||||
\cpropep or change the #include statements in cpropep.c) and
|
||||
build.
|
||||
|
||||
|
||||
Run using
|
||||
cpropep -h
|
||||
for command-line help and usage.
|
||||
|
||||
|
||||
Cpropep is Copyright (C) 2000 Antoine Lefebvre
|
||||
<antoinelefebvre@softhome.net>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,764 @@
|
||||
/* cpropep.c - Calculation of Complex Chemical Equilibrium */
|
||||
/* $Id: cpropep.c,v 1.3 2001/07/09 13:51:39 antoine Exp $ */
|
||||
/* Copyright (C) 2000 */
|
||||
/* Antoine Lefebvre <antoine.lefebvre@polymtl.ca> */
|
||||
/* Mark Pinese <pinese@cyberwizards.com.au> */
|
||||
/* */
|
||||
/* Licensed under the GPLv2 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <malloc.h>
|
||||
//#include <time.h>
|
||||
|
||||
#ifdef GCC
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "getopt.h"
|
||||
#endif
|
||||
|
||||
#include "load.h"
|
||||
#include "equilibrium.h"
|
||||
#include "performance.h"
|
||||
#include "derivative.h"
|
||||
#include "thermo.h"
|
||||
|
||||
#include "print.h"
|
||||
|
||||
#include "conversion.h"
|
||||
#include "compat.h"
|
||||
#include "return.h"
|
||||
|
||||
#define version "1.0"
|
||||
#define date "10/07/2000"
|
||||
|
||||
//#define CHAMBER_MSG "Time spent for computing chamber equilibrium"
|
||||
//#define FROZEN_MSG "Time spent for computing frozen performance"
|
||||
//#define EQUILIBRIUM_MSG "Time spent for computing equilibrium performance"
|
||||
|
||||
#ifndef CONF_FILE
|
||||
#define CONF_FILE "cpropep.conf"
|
||||
#endif
|
||||
|
||||
|
||||
//#undef TIME
|
||||
//#define TIME(function, msg) function;
|
||||
|
||||
#define MAX_CASE 10
|
||||
|
||||
typedef enum _p
|
||||
{
|
||||
SIMPLE_EQUILIBRIUM,
|
||||
FIND_FLAME_TEMPERATURE,
|
||||
FROZEN_PERFORMANCE,
|
||||
EQUILIBRIUM_PERFORMANCE
|
||||
} p_type;
|
||||
|
||||
char case_name[][80] = {
|
||||
"Fixed pressure-temperature equilibrium",
|
||||
"Fixed enthalpy-pressure equilibrium - adiabatic flame temperature",
|
||||
"Frozen equilibrium performance evaluation",
|
||||
"Shifting equilibrium performance evaluation"
|
||||
};
|
||||
|
||||
char thermo_file[FILENAME_MAX] = "thermo.dat";
|
||||
char propellant_file[FILENAME_MAX] = "propellant.dat";
|
||||
|
||||
|
||||
typedef struct _case_t
|
||||
{
|
||||
p_type p;
|
||||
|
||||
bool temperature_set;
|
||||
bool pressure_set;
|
||||
bool exit_condition_set;
|
||||
|
||||
double temperature;
|
||||
double pressure;
|
||||
exit_condition_t exit_cond_type;
|
||||
double exit_condition;
|
||||
|
||||
} case_t;
|
||||
|
||||
|
||||
void welcome_message(void)
|
||||
{
|
||||
printf("----------------------------------------------------------\n");
|
||||
printf("Cpropep is an implementation in standard C of the chemical\n");
|
||||
printf("equilibrium algorythm presented by GORDON and McBRIDE in the\n");
|
||||
printf("NASA report RP-1311.\n");
|
||||
printf("This is the version %s %s\n", version, date);
|
||||
printf("This software is release under the GPL and is free of charge\n");
|
||||
printf("Copyright (C) 2000 Antoine Lefebvre <antoine.lefebvre@polymtl.ca>\n");
|
||||
printf("----------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
void info(char **argv)
|
||||
{
|
||||
printf("Try `%s -h' for more information\n", argv[0]);
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
/*
|
||||
Usage:
|
||||
cpropep -f infile [-voe]
|
||||
cpropep -pqtuh
|
||||
|
||||
Arguments:
|
||||
*/
|
||||
|
||||
printf("Usage:");
|
||||
printf("\n\tcpropep -f infile [-voe]");
|
||||
printf("\n\tcpropep -pqtuh");
|
||||
|
||||
printf("\n\nArguments:\n");
|
||||
printf("-f file \t Perform an analysis of the propellant data in file\n");
|
||||
printf("-v num \t Verbosity setting, 0 - 10\n");
|
||||
printf("-o file \t Results file, stdout if omitted\n");
|
||||
printf("-e file \t Error file, stdout if omitted\n");
|
||||
printf("-p \t Print the propellant list\n");
|
||||
printf("-q num \t Print information about propellant component number num\n");
|
||||
printf("-t \t Print the combustion product list\n");
|
||||
printf("-u num \t Print information about product number num\n");
|
||||
printf("-h \t Print help\n");
|
||||
printf("-i \t Print program information\n");
|
||||
}
|
||||
|
||||
|
||||
int load_input(FILE *fd, equilibrium_t *e, case_t *t, double *pe)
|
||||
{
|
||||
double m;
|
||||
|
||||
int sp;
|
||||
int section = 0;
|
||||
|
||||
int n_case = 0;
|
||||
|
||||
char buffer[128], num[10], qt[10], unit[10];
|
||||
char variable[64];
|
||||
|
||||
char *bufptr;
|
||||
|
||||
while ( fgets(buffer, 128, fd) != NULL )
|
||||
{
|
||||
switch (section)
|
||||
{
|
||||
case 0:
|
||||
|
||||
if (n_case >= MAX_CASE)
|
||||
{
|
||||
fprintf(outputfile, "Warning: Too many different case, "
|
||||
"maximum is %d: deleting case.\n", MAX_CASE+1);
|
||||
section = 100;
|
||||
break;
|
||||
}
|
||||
|
||||
if (buffer[0] == ' ' || buffer[0] == '\n' || buffer[0] == '\0' ||
|
||||
buffer[0] == '#')
|
||||
{
|
||||
section = 0;
|
||||
break;
|
||||
}
|
||||
else if (strncmp(buffer, "Propellant", 10) == 0)
|
||||
{
|
||||
section = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strncmp(buffer, "TP", 2) == 0)
|
||||
t[n_case].p = SIMPLE_EQUILIBRIUM;
|
||||
else if (strncmp(buffer, "HP", 2) == 0)
|
||||
t[n_case].p = FIND_FLAME_TEMPERATURE;
|
||||
else if (strncmp(buffer, "FR", 2) == 0)
|
||||
t[n_case].p = FROZEN_PERFORMANCE;
|
||||
else if (strncmp(buffer, "EQ", 2) == 0)
|
||||
t[n_case].p = EQUILIBRIUM_PERFORMANCE;
|
||||
else
|
||||
{
|
||||
printf ("Unknown option.\n");
|
||||
break;
|
||||
}
|
||||
section = 2;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 1: /* propellant section */
|
||||
if (buffer[0] == '+')
|
||||
{
|
||||
sscanf(buffer, "%s %s %s", num, qt, unit);
|
||||
bufptr = num + 1;
|
||||
sp = atoi(bufptr);
|
||||
|
||||
m = atof(qt);
|
||||
|
||||
if (strcmp(unit, "g") == 0)
|
||||
{
|
||||
add_in_propellant(e, sp, GRAM_TO_MOL(m, sp) );
|
||||
}
|
||||
else if (strcmp(unit, "m") == 0)
|
||||
{
|
||||
add_in_propellant(e, sp, m);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unit must be g (gram) or m (mol)\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (buffer[0] == '#')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (buffer[0] == ' ' || buffer[0] == '\n' || buffer[0] == '\0')
|
||||
{
|
||||
section = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (buffer[0] == '+')
|
||||
{
|
||||
sscanf(buffer, "%s %s %s", variable, qt, unit);
|
||||
|
||||
bufptr = variable + 1;
|
||||
|
||||
if (strcmp(bufptr, "chamber_temperature") == 0)
|
||||
{
|
||||
|
||||
m = atof(qt);
|
||||
|
||||
if (strcmp(unit, "k") == 0)
|
||||
{
|
||||
t[n_case].temperature = m;
|
||||
}
|
||||
else if (strcmp(unit, "c") == 0)
|
||||
{
|
||||
t[n_case].temperature = m + 273.15;
|
||||
}
|
||||
else if (strcmp(unit, "f") == 0)
|
||||
{
|
||||
t[n_case].temperature = (5.0/9.0) * (m - 32.0) + 273.15;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unit must be k (kelvin) or c (celcius)\n");
|
||||
break;
|
||||
}
|
||||
|
||||
t[n_case].temperature_set = true;
|
||||
|
||||
}
|
||||
else if (strcmp(bufptr, "chamber_pressure") == 0)
|
||||
{
|
||||
m = atof(qt);
|
||||
|
||||
if (strcmp(unit, "atm") == 0)
|
||||
{
|
||||
t[n_case].pressure = m;
|
||||
}
|
||||
else if (strcmp(unit, "kPa") == 0)
|
||||
{
|
||||
t[n_case].pressure = KPA_TO_ATM * m;
|
||||
}
|
||||
else if (strcmp(unit, "psi") == 0)
|
||||
{
|
||||
t[n_case].pressure = PSI_TO_ATM * m;
|
||||
}
|
||||
else if (strcmp(unit, "bar") == 0)
|
||||
{
|
||||
t[n_case].pressure = BAR_TO_ATM * m;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(errorfile, "Units must be psi, kPa, atm or bar.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
t[n_case].pressure_set = true;
|
||||
}
|
||||
else if (strcmp(bufptr, "exit_pressure") == 0)
|
||||
{
|
||||
m = atof(qt);
|
||||
|
||||
if (strcmp(unit, "atm") == 0)
|
||||
{
|
||||
t[n_case].exit_condition = m;
|
||||
}
|
||||
else if (strcmp(unit, "kPa") == 0)
|
||||
{
|
||||
t[n_case].exit_condition = KPA_TO_ATM * m;
|
||||
}
|
||||
else if (strcmp(unit, "psi") == 0)
|
||||
{
|
||||
t[n_case].exit_condition = PSI_TO_ATM * m;
|
||||
}
|
||||
else if (strcmp(unit, "bar") == 0)
|
||||
{
|
||||
t[n_case].exit_condition = BAR_TO_ATM * m;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(errorfile, "Units must be psi, kPa, atm or bar.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
t[n_case].exit_cond_type = PRESSURE;
|
||||
t[n_case].exit_condition_set = true;
|
||||
|
||||
}
|
||||
else if (strcmp(bufptr, "supersonic_area_ratio") == 0)
|
||||
{
|
||||
t[n_case].exit_cond_type = SUPERSONIC_AREA_RATIO;
|
||||
t[n_case].exit_condition = atof(qt);
|
||||
t[n_case].exit_condition_set = true;
|
||||
}
|
||||
else if (strcmp(bufptr, "subsonic_area_ratio") == 0)
|
||||
{
|
||||
t[n_case].exit_cond_type = SUBSONIC_AREA_RATIO;
|
||||
t[n_case].exit_condition = atof(qt);
|
||||
t[n_case].exit_condition_set = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown keyword.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
else if (buffer[0] == '#')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (buffer[0] == ' ' || buffer[0] == '\n' || buffer[0] == '\0')
|
||||
{
|
||||
section = 0;
|
||||
n_case++;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
section = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, c, v = 0;
|
||||
int err_code;
|
||||
char filename[FILENAME_MAX];
|
||||
FILE *fd = NULL;
|
||||
|
||||
FILE *conf = NULL;
|
||||
|
||||
equilibrium_t *equil, *frozen, *shifting;
|
||||
|
||||
int thermo_loaded = 0;
|
||||
int propellant_loaded = 0;
|
||||
|
||||
double exit_pressure;
|
||||
|
||||
// clock_t timer;
|
||||
|
||||
char variable[64];
|
||||
char path[FILENAME_MAX];
|
||||
char buffer[512];
|
||||
|
||||
case_t case_list[MAX_CASE];
|
||||
for (i = 0; i < MAX_CASE; i++)
|
||||
{
|
||||
case_list[i].p = -1;
|
||||
case_list[i].temperature_set = false;
|
||||
case_list[i].pressure_set = false;
|
||||
case_list[i].exit_condition_set = false;
|
||||
}
|
||||
|
||||
errorfile = stderr;
|
||||
outputfile = stdout;
|
||||
|
||||
/* global_verbose = 1; */
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
usage ();
|
||||
exit (ERROR);
|
||||
}
|
||||
|
||||
/* read the configuration file if there is one*/
|
||||
if ((conf = fopen(CONF_FILE, "r")) != NULL)
|
||||
{
|
||||
while (fgets(buffer, 512, conf))
|
||||
{
|
||||
sscanf(buffer, "%s %s", variable, path);
|
||||
if (strcmp(variable, "thermo") == 0)
|
||||
{
|
||||
strncpy(thermo_file, path, FILENAME_MAX);
|
||||
}
|
||||
else if (strcmp(variable, "propellant") == 0)
|
||||
{
|
||||
strncpy(propellant_file, path, FILENAME_MAX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = getopt(argc, argv, "ipht?f:v:o:e:q:u:");
|
||||
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
/* the output file */
|
||||
case 'o':
|
||||
if (strlen(optarg) > FILENAME_MAX)
|
||||
{
|
||||
printf("Filename too long!\n");
|
||||
break;
|
||||
}
|
||||
strncpy (filename, optarg, FILENAME_MAX);
|
||||
|
||||
if ( (outputfile = fopen (filename, "w")) == NULL )
|
||||
return 1;
|
||||
|
||||
break;
|
||||
|
||||
/* the output error file */
|
||||
case 'e':
|
||||
if (strlen(optarg) > FILENAME_MAX)
|
||||
{
|
||||
printf("Filename too long!\n");
|
||||
break;
|
||||
}
|
||||
strncpy (filename, optarg, FILENAME_MAX);
|
||||
|
||||
if ( (errorfile = fopen (filename, "w")) == NULL )
|
||||
return (ERROR);
|
||||
|
||||
break;
|
||||
|
||||
/* print the propellant list */
|
||||
case 'p':
|
||||
if (!propellant_loaded)
|
||||
{
|
||||
if (load_propellant (propellant_file) < 0)
|
||||
{
|
||||
printf("Error loading propellant file: %s\n", propellant_file);
|
||||
return -1;
|
||||
}
|
||||
propellant_loaded = 1;
|
||||
}
|
||||
print_propellant_list();
|
||||
free(propellant_list);
|
||||
return (SUCCESS);
|
||||
|
||||
/* print propellant info */
|
||||
case 'q':
|
||||
if (!propellant_loaded)
|
||||
{
|
||||
if (load_propellant (propellant_file) < 0)
|
||||
{
|
||||
printf("Error loading propellant file: %s\n", propellant_file);
|
||||
return -1;
|
||||
}
|
||||
propellant_loaded = 1;
|
||||
}
|
||||
print_propellant_info( atoi(optarg) );
|
||||
free(propellant_list);
|
||||
return (SUCCESS);
|
||||
|
||||
/* print the usage */
|
||||
case 'h':
|
||||
usage();
|
||||
return (SUCCESS);
|
||||
|
||||
/* the input file */
|
||||
case 'f':
|
||||
if (strlen(optarg) > FILENAME_MAX)
|
||||
{
|
||||
printf("Filename too long!\n");
|
||||
break;
|
||||
}
|
||||
strncpy (filename, optarg, FILENAME_MAX);
|
||||
|
||||
if ( (fd = fopen (filename, "r")) == NULL )
|
||||
return (ERROR);
|
||||
|
||||
break;
|
||||
|
||||
/* print the thermo list */
|
||||
case 't':
|
||||
if (!thermo_loaded)
|
||||
{
|
||||
if (load_thermo (thermo_file) < 0)
|
||||
{
|
||||
printf("Error loading thermo data file: %s\n", thermo_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
thermo_loaded = 1;
|
||||
}
|
||||
print_thermo_list();
|
||||
free(thermo_list);
|
||||
return (SUCCESS);
|
||||
|
||||
case 'u':
|
||||
if (!thermo_loaded)
|
||||
{
|
||||
if (load_thermo (thermo_file) < 0)
|
||||
{
|
||||
printf("Error loading thermo data file: %s\n", thermo_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
thermo_loaded = 1;
|
||||
}
|
||||
print_thermo_info( atoi(optarg) );
|
||||
free(thermo_list);
|
||||
return (SUCCESS);
|
||||
|
||||
/* set the verbosity level */
|
||||
case 'v':
|
||||
v = atoi(optarg);
|
||||
if (v < 0 || v > 10)
|
||||
{
|
||||
printf("Verbose is an integer betwenn 0 and 10.\n");
|
||||
v = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
/* print information */
|
||||
case 'i':
|
||||
welcome_message();
|
||||
return (SUCCESS);
|
||||
|
||||
case '?':
|
||||
info(argv);
|
||||
return (SUCCESS);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!thermo_loaded)
|
||||
{
|
||||
if (load_thermo (thermo_file) < 0)
|
||||
{
|
||||
printf("Error loading thermo data file: %s\n", thermo_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
thermo_loaded = 1;
|
||||
}
|
||||
if (!propellant_loaded)
|
||||
{
|
||||
if (load_propellant (propellant_file) < 0)
|
||||
{
|
||||
printf("Error loading propellant file: %s\n", propellant_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
propellant_loaded = 1;
|
||||
}
|
||||
|
||||
|
||||
if (fd != NULL)
|
||||
{
|
||||
equil = (equilibrium_t *) malloc (sizeof (equilibrium_t));
|
||||
initialize_equilibrium(equil);
|
||||
|
||||
frozen = (equilibrium_t *) malloc (sizeof(equilibrium_t)*3);
|
||||
shifting = (equilibrium_t *) malloc (sizeof(equilibrium_t)*3);
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
initialize_equilibrium(frozen + i);
|
||||
initialize_equilibrium(shifting + i);
|
||||
}
|
||||
|
||||
load_input(fd, equil, case_list, &exit_pressure);
|
||||
|
||||
compute_density(&(equil->propellant));
|
||||
|
||||
fclose(fd);
|
||||
global_verbose = v;
|
||||
|
||||
list_element(equil);
|
||||
if ((err_code = list_product(equil)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while ((case_list[i].p != -1) && (i <= MAX_CASE))
|
||||
{
|
||||
fprintf(outputfile, "Computing case %d\n%s\n\n", i+1,
|
||||
case_name[case_list[i].p]);
|
||||
|
||||
/* be sure to begin iteration without considering
|
||||
condensed species. Once n_condensed have been set */
|
||||
equil->product.n[CONDENSED] = 0;
|
||||
|
||||
switch (case_list[i].p)
|
||||
{
|
||||
case SIMPLE_EQUILIBRIUM:
|
||||
|
||||
if (!(case_list[i].temperature_set))
|
||||
{
|
||||
printf("Chamber temperature not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
else if (!(case_list[i].pressure_set))
|
||||
{
|
||||
printf("Chamber pressure not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
equil->properties.T = case_list[i].temperature;
|
||||
equil->properties.P = case_list[i].pressure;
|
||||
|
||||
print_propellant_composition(equil);
|
||||
if ((err_code = equilibrium(equil, TP)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
print_product_properties(equil, 1);
|
||||
print_product_composition(equil, 1);
|
||||
break;
|
||||
|
||||
case FIND_FLAME_TEMPERATURE:
|
||||
|
||||
if (!(case_list[i].pressure_set))
|
||||
{
|
||||
printf("Chamber pressure not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
equil->properties.P = case_list[i].pressure;
|
||||
|
||||
print_propellant_composition(equil);
|
||||
if ((err_code = equilibrium(equil, HP)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
print_product_properties(equil, 1);
|
||||
print_product_composition(equil, 1);
|
||||
break;
|
||||
|
||||
case FROZEN_PERFORMANCE:
|
||||
|
||||
if (!(case_list[i].pressure_set))
|
||||
{
|
||||
printf("Chamber pressure not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
else if (!(case_list[i].exit_condition_set))
|
||||
{
|
||||
printf("Exit condition not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
equil->properties.T = case_list[i].temperature;
|
||||
equil->properties.P = case_list[i].pressure;
|
||||
|
||||
copy_equilibrium(frozen, equil);
|
||||
|
||||
print_propellant_composition(frozen);
|
||||
|
||||
if ((err_code = equilibrium(equil, HP)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
if ((err_code =
|
||||
frozen_performance(frozen, case_list[i].exit_cond_type,
|
||||
case_list[i].exit_condition)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
print_product_properties(frozen, 3);
|
||||
print_performance_information(frozen, 3);
|
||||
print_product_composition(frozen, 3);
|
||||
|
||||
break;
|
||||
case EQUILIBRIUM_PERFORMANCE:
|
||||
|
||||
|
||||
if (!(case_list[i].pressure_set))
|
||||
{
|
||||
printf("Chamber pressure not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
else if (!(case_list[i].exit_condition_set))
|
||||
{
|
||||
printf("Exit condition not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
equil->properties.T = case_list[i].temperature;
|
||||
equil->properties.P = case_list[i].pressure;
|
||||
|
||||
copy_equilibrium(shifting, equil);
|
||||
|
||||
print_propellant_composition(shifting);
|
||||
|
||||
if ((err_code = equilibrium(shifting, HP)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
if ((err_code = shifting_performance(shifting,
|
||||
case_list[i].exit_cond_type,
|
||||
case_list[i].exit_condition))
|
||||
< 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
print_product_properties(shifting, 3);
|
||||
print_performance_information(shifting, 3);
|
||||
print_product_composition(shifting, 3);
|
||||
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
free (equil);
|
||||
free (frozen);
|
||||
free (shifting);
|
||||
|
||||
}
|
||||
|
||||
free (propellant_list);
|
||||
free (thermo_list);
|
||||
|
||||
if (errorfile != stderr)
|
||||
fclose (errorfile);
|
||||
|
||||
if (outputfile != stdout)
|
||||
fclose (outputfile);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
thermo /usr/share/rocketworkbench/cpropep/thermo.dat
|
||||
propellant /usr/share/rocketworkbench/cpropep/propellant.dat
|
||||
@@ -0,0 +1,102 @@
|
||||
# Cpropep is based on the theory presented by Gordon and McBride
|
||||
# in the NASA report RP-1311. You can download a pdf version of
|
||||
# this document at http://www.arocket.net/library/
|
||||
|
||||
# The thermodynamics data file thermo.dat coma also from McBride
|
||||
# at the NASA Gleen Research center.
|
||||
|
||||
# Here is an example of an input file to be use by cpropep.
|
||||
# Any line beginning by a '#' a space or a new_line is considered
|
||||
# as a comment.
|
||||
|
||||
# This file should first contain a section named 'Propellant' which
|
||||
# contain a list of all substance contain in the propellant. The
|
||||
# number refer to an element in the data file containing propellant
|
||||
# information. In order to have a list of the substance, you could
|
||||
# invoque the program like that: 'cpropep -p'
|
||||
|
||||
# There is two units that are support for ingredient quantity g (gram) or m (mole)
|
||||
|
||||
#Propellant HTPB/KClO4/Al
|
||||
#+108 78 g
|
||||
#+788 11 g
|
||||
#+34 7 g
|
||||
#+788 8.4 g
|
||||
#+108 62 g
|
||||
#+493 18 g
|
||||
|
||||
#Propellant DEXTROSE/KNO3
|
||||
#+1024 35 g
|
||||
#+765 65 g
|
||||
|
||||
#Propellant DEXTROSE/KNO3/AL
|
||||
#+1024 10 g
|
||||
#+765 37 g
|
||||
#+34 20 g
|
||||
|
||||
#Propellant PVC/AIR
|
||||
#+1030 60 g
|
||||
#+15 300 g
|
||||
|
||||
#Propellant H2O2/OCTANE
|
||||
#+673 12 g
|
||||
#+469 80 g
|
||||
|
||||
#Propellant O2/OCTANE
|
||||
#+686 51 g
|
||||
#+673 20 g
|
||||
|
||||
Propellant O2/PROPANE
|
||||
+686 51 g
|
||||
+771 20 g
|
||||
|
||||
#Propellant O2/NH3
|
||||
#+686 28 g
|
||||
#+54 20 g
|
||||
|
||||
#Propellant NITRIC ACID/OCTANE
|
||||
#+630 80 g
|
||||
#+673 19 g
|
||||
|
||||
# You could then specify a list of problem to be solve. There is 4
|
||||
# possible cases:
|
||||
|
||||
# TP for temperature-pressure fixed problem
|
||||
# You have to specify the temperature and the pressure (of course)
|
||||
# There is 4 pressure units (psi, kPa, atm and bar) and 3 temperature units (k, c and f)
|
||||
|
||||
#TP
|
||||
#+chamber_pressure 500 psi
|
||||
#+chamber_temperature 673 k
|
||||
|
||||
# HP for enthalpy-pressure fixed problem. It use the enthalpy of
|
||||
# the propellant describe at the beginning.
|
||||
|
||||
# Only the chamber pressure shoud be specified. The temperature of
|
||||
# the product will be the adiabatic flame temperature.
|
||||
|
||||
#HP
|
||||
#+chamber_pressure 20.4 atm # 136 atm
|
||||
|
||||
# FR is used to compute frozen performance.
|
||||
# You have to specify the chamber pressure and an exit condition.
|
||||
# This condition could be one of the following three:
|
||||
|
||||
# exit_pressure: pressure at the exit.
|
||||
# supersonic_area_ratio: exit to throat area for an area after the nozzle
|
||||
# subsonic_area_ratio: exit to throat area for an area before any nozzle
|
||||
|
||||
FR
|
||||
+chamber_pressure 40 atm
|
||||
+exit_pressure 1 atm
|
||||
#+supersonic_area_ratio 8.566
|
||||
#+subsonic_area_ratio 5
|
||||
|
||||
# EQ is used to compute shifting equilibrium performance.
|
||||
# The options are the same as for frozen.
|
||||
|
||||
EQ
|
||||
+chamber_pressure 40 atm
|
||||
+exit_pressure 1 atm
|
||||
#+supersonic_area_ratio 10
|
||||
#+subsonic_area_ratio 5
|
||||
Reference in New Issue
Block a user