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,11 @@
|
||||
|
||||
all:
|
||||
@mkdir -p lib
|
||||
make -C src all
|
||||
|
||||
clean:
|
||||
@rm -rf lib
|
||||
make -C src clean
|
||||
|
||||
deep-clean: clean
|
||||
make -C src deep-clean
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
CC = bcc32
|
||||
CPP32 = cpp32
|
||||
LIBRARIAN = tlib
|
||||
LINKER = ilink32
|
||||
RC = brc32
|
||||
|
||||
COPT = -3 -O2 -w-8004 -w-8012 -w-8057 -IC:\borland\bcc55\include
|
||||
LDOPT = -LC:\borland\bcc55\lib
|
||||
|
||||
INCLUDEDIR = -I..\..\libnum\ -I.
|
||||
|
||||
DEF = -DBORLAND
|
||||
|
||||
COMPAT_LIBNAME = compat.lib
|
||||
CPROPEP_LIBNAME = cpropep.lib
|
||||
THERMO_LIBNAME = thermo.lib
|
||||
|
||||
COMPAT_LIBOBJS = compat.obj getopt.obj
|
||||
THERMO_LIBOBJS = load.obj thermo.obj
|
||||
CPROPEP_LIBOBJS = equilibrium.obj print.obj performance.obj derivative.obj
|
||||
|
||||
TLIBCOMPAT = +compat.obj +getopt.obj
|
||||
TLIBTHERMO = +load.obj +thermo.obj
|
||||
TLIBCPROPEP = +equilibrium.obj +print.obj +performance.obj +derivative.obj
|
||||
.SUFFIXES: .c
|
||||
|
||||
all: $(CPROPEP_LIBNAME) $(THERMO_LIBNAME) $(COMPAT_LIBNAME)
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(DEF) $(INCLUDEDIR) $(COPT) -c $*.c -o $*.obj
|
||||
|
||||
$(COMPAT_LIBNAME): $(COMPAT_LIBOBJS)
|
||||
tlib $@ $(TLIBCOMPAT)
|
||||
|
||||
$(CPROPEP_LIBNAME): $(CPROPEP_LIBOBJS)
|
||||
tlib $@ $(TLIBCPROPEP)
|
||||
|
||||
$(THERMO_LIBNAME): $(THERMO_LIBOBJS)
|
||||
tlib $@ $(TLIBTHERMO)
|
||||
|
||||
clean:
|
||||
del *.obj
|
||||
del *.bak
|
||||
del *.tds
|
||||
|
||||
deep-clean: clean
|
||||
del $(COMPAT_LIBNAME)
|
||||
del $(CPROPEP_LIBNAME)
|
||||
del $(THERMO_LIBNAME)
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef load_h
|
||||
#define load_h
|
||||
|
||||
/***************************************************************
|
||||
FUNCTION: Load the propellant data contain in filename
|
||||
|
||||
PARAMETER: filename should be the path of the file containing
|
||||
the information on propellant. It should be exactly
|
||||
in the format of the file propellant.dat include
|
||||
in the distribution.
|
||||
|
||||
COMMENTS: It load the information in the global variable
|
||||
propellant_list[MAX_PROPELLANT] that is of type
|
||||
propellant_t
|
||||
|
||||
AUTHOR: Antoine Lefebvre
|
||||
modification bye Mark Pinese
|
||||
****************************************************************/
|
||||
int load_propellant(char *filename);
|
||||
|
||||
/***************************************************************
|
||||
FUNCTION: Load the thermo data contain in filename
|
||||
|
||||
PARAMETER: filename should be the path of the file containing
|
||||
the thermo information . It should be exactly
|
||||
in the format of the file thermo.dat include
|
||||
in the distribution.
|
||||
|
||||
COMMENTS: It load the information in the global variable
|
||||
thermo_list[MAX_THERMO] that is of type
|
||||
thermo_t
|
||||
|
||||
AUTHOR: Antoine Lefebvre
|
||||
modification bye Mark Pinese
|
||||
****************************************************************/
|
||||
int load_thermo(char *filename);
|
||||
|
||||
/***************************************************************
|
||||
Removes trailing ' ' in str. If str is all ' ', removes all
|
||||
but the first.
|
||||
str - pointer to a character array (not necessarily a string)
|
||||
len - length of str.
|
||||
|
||||
AUTHOR: Mark Pinese
|
||||
****************************************************************/
|
||||
void trim_spaces(char *str, unsigned int len);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
#ifndef thermo_h
|
||||
#define thermo_h
|
||||
|
||||
#include "equilibrium.h"
|
||||
#include "const.h"
|
||||
|
||||
/* MACRO: Number of symbol in the symbol table */
|
||||
#define N_SYMB 102
|
||||
|
||||
/***************************************************************
|
||||
TYPE: Structure to hold information of species contain in the
|
||||
thermo data file
|
||||
****************************************************************/
|
||||
typedef struct _thermo
|
||||
{
|
||||
char name[19];
|
||||
char comments[57];
|
||||
int nint; /* number of different temperature interval */
|
||||
char id[7]; /* identification code */
|
||||
int elem[5];
|
||||
int coef[5];
|
||||
state_t state;
|
||||
double weight; /* molecular weight */
|
||||
float heat; /* heat of formation at 298.15 K (J/mol) */
|
||||
double dho; /* HO(298.15) - HO(0) */
|
||||
float range[4][2]; /* temperature range */
|
||||
int ncoef[4]; /* number of coefficient for Cp0/R */
|
||||
int ex[4][8]; /* exponent in empirical equation */
|
||||
|
||||
double param[4][9];
|
||||
|
||||
/* for species with data at only one temperature */
|
||||
/* especially condensed */
|
||||
float temp;
|
||||
float enth;
|
||||
|
||||
} thermo_t;
|
||||
|
||||
/***************************************************************
|
||||
TYPE: Structure to hold information of species contain in the
|
||||
propellant data file
|
||||
****************************************************************/
|
||||
typedef struct _propellant
|
||||
{
|
||||
char name[120]; /* name of the propellant */
|
||||
int elem[6]; /* element in the molecule (atomic number) max 6 */
|
||||
int coef[6]; /* stochiometric coefficient of this element
|
||||
(0 for none) */
|
||||
float heat; /* heat of formation in Joule/gram */
|
||||
float density; /* density in g/cubic cm */
|
||||
|
||||
} propellant_t;
|
||||
|
||||
|
||||
extern propellant_t *propellant_list;
|
||||
extern thermo_t *thermo_list;
|
||||
|
||||
extern const float molar_mass[];
|
||||
extern const char symb[][3];
|
||||
|
||||
extern unsigned long num_thermo;
|
||||
extern unsigned long num_propellant;
|
||||
|
||||
/*************************************************************
|
||||
FUNCTION: Search in the field name of thermo_list and return
|
||||
the value of the found item.
|
||||
|
||||
PARAMETER: A string corresponding to what we search,
|
||||
example: "CO2"
|
||||
|
||||
COMMENTS: If nothing is found, it return -1
|
||||
|
||||
AUTHOR: Antoine Lefebvre
|
||||
modification bye Mark Pinese
|
||||
**************************************************************/
|
||||
int thermo_search(char *str);
|
||||
|
||||
int propellant_search(char *str);
|
||||
|
||||
int atomic_number(char *symbole);
|
||||
|
||||
int propellant_search_by_formula(char *str);
|
||||
|
||||
/*************************************************************
|
||||
FUNCTION: Return the enthalpy of the molecule in thermo_list[sp]
|
||||
at the temperature T in K. (Ho/RT)
|
||||
|
||||
PARAMETER: sp is the position in the array of the molecule
|
||||
T is the temperature in K
|
||||
|
||||
COMMENTS: It use the parametric form explain in the documentation
|
||||
to compute the value from the data read in the file
|
||||
thermo.dat
|
||||
|
||||
AUTHOR: Antoine Lefebvre
|
||||
**************************************************************/
|
||||
double enthalpy_0(int sp, float T);
|
||||
|
||||
/*************************************************************
|
||||
FUNCTION: Return the entropy of the molecule in thermo_list[sp]
|
||||
at the temperature T in K. (So/RT)
|
||||
|
||||
PARAMETER: sp is the position in the array of the molecule
|
||||
T is the temperature in K
|
||||
|
||||
COMMENTS: It use the parametric form explain in the documentation
|
||||
to compute the value from the data read in the file
|
||||
thermo.dat
|
||||
|
||||
AUTHOR: Antoine Lefebvre
|
||||
**************************************************************/
|
||||
double entropy_0(int sp, float T);
|
||||
|
||||
double entropy(int sp, state_t st, double ln_nj_n, float T, float P);
|
||||
|
||||
/*************************************************************
|
||||
FUNCTION: Return the specific heat (Cp) of the molecule in
|
||||
thermo_list[sp] at the temperature T in K. (Cp/RT)
|
||||
|
||||
PARAMETER: sp is the position in the array of the molecule
|
||||
T is the temperature in K
|
||||
|
||||
COMMENTS: It use the parametric form explain in the documentation
|
||||
to compute the value from the data read in the file
|
||||
thermo.dat
|
||||
|
||||
AUTHOR: Antoine Lefebvre
|
||||
**************************************************************/
|
||||
double specific_heat_0(int sp, float T);
|
||||
|
||||
double mixture_specific_heat_0(equilibrium_t *e, double temp);
|
||||
|
||||
/*************************************************************
|
||||
FUNCTION: Return true if the thermochemical data are define for
|
||||
this temperature.
|
||||
|
||||
PARAMETER: The same as for entropy
|
||||
|
||||
COMMENTS: It is useful to determine if a specie is present at
|
||||
a given temperature.
|
||||
|
||||
AUTHOR: Antoine Lefebvre
|
||||
**************************************************************/
|
||||
int temperature_check(int sp, float T);
|
||||
|
||||
double transition_temperature(int sp, float T);
|
||||
|
||||
/*************************************************************
|
||||
FUNCTION: Return the variation of enthalpy of the molecule in
|
||||
thermo_list[sp] between the temperature T in K and
|
||||
298.15 K.
|
||||
|
||||
PARAMETER: sp is the position in the array of the molecule
|
||||
T is the temperature in K
|
||||
|
||||
COMMENTS: It call enthalpy(...) for the enthalpy at temperature
|
||||
T and use the field heat of thermo_t for the enthalpy
|
||||
at 298.15
|
||||
|
||||
AUTHOR: Antoine Lefebvre
|
||||
**************************************************************/
|
||||
double delta_enthalpy(int sp, float T);
|
||||
|
||||
double propellant_enthalpy(equilibrium_t *e);
|
||||
double product_enthalpy(equilibrium_t *e);
|
||||
double product_entropy(equilibrium_t *e);
|
||||
double propellant_mass(equilibrium_t *e);
|
||||
|
||||
int compute_density(composition_t *c);
|
||||
|
||||
|
||||
/*************************************************************
|
||||
FUNCTION: Return the gibbs free energy of the molecule in
|
||||
thermo_list[sp] at temperature T. (uo/RT)
|
||||
|
||||
PARAMETER: sp is the position in the array of the molecule
|
||||
T is the temperature in K
|
||||
|
||||
COMMENTS: g = H - ST where H is the enthalpy, T the temperature
|
||||
and S the entropy.
|
||||
**************************************************************/
|
||||
double gibbs_0(int sp, float T);
|
||||
|
||||
|
||||
/*************************************************************
|
||||
FUNCTION: Return the gibbs free energy of the molecule in
|
||||
thermo_list[sp] at temperature T, pressure P. (u/RT)
|
||||
|
||||
PARAMETER: sp is the position in the array of the molecule
|
||||
T is the temperature in K
|
||||
|
||||
COMMENTS: g = uo + ln(nj/n) + ln(P) for gazes
|
||||
g = uo for condensed
|
||||
|
||||
AUTHOR: Antoine Lefebvre
|
||||
**************************************************************/
|
||||
//double gibbs(int sp, state_t st, double nj, double n, float T, float P);
|
||||
double gibbs(int sp, state_t st, double nj_n_n, float T, float P);
|
||||
|
||||
|
||||
/***************************************************************
|
||||
FUNCTION: Return the heat of formation of a propellant in kJ/mol
|
||||
****************************************************************/
|
||||
double heat_of_formation(int molecule);
|
||||
|
||||
/*************************************************************
|
||||
FUNCTION: Return the molar mass of a propellant (g/mol)
|
||||
|
||||
PARAMETER: molecule is the number in propellant_list
|
||||
**************************************************************/
|
||||
double propellant_molar_mass(int molecule);
|
||||
|
||||
|
||||
|
||||
double propellant_mass(equilibrium_t *e);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
CC = gcc
|
||||
COPT = -g -Wall -O3 # -pg
|
||||
|
||||
ROOT = ../..
|
||||
INCLUDEDIR = -I$(ROOT)/libcpropep/include \
|
||||
-I$(ROOT)/libcompat/include \
|
||||
-I$(ROOT)/libnum/include \
|
||||
-I../include/
|
||||
|
||||
DEF = -DGCC
|
||||
|
||||
LIBNAME = libthermo.a
|
||||
|
||||
LIBOBJS = load.o thermo.o
|
||||
|
||||
all: $(LIBNAME)
|
||||
|
||||
.c.o:
|
||||
$(CC) $(DEF) $(INCLUDEDIR) $(COPT) -c $*.c -o $*.o
|
||||
|
||||
$(LIBNAME): $(LIBOBJS)
|
||||
ar -r $@ $(LIBOBJS)
|
||||
ranlib $@
|
||||
mv $(LIBNAME) ../lib/
|
||||
|
||||
clean:
|
||||
rm -f *.o *~
|
||||
|
||||
deep-clean: clean
|
||||
rm -f ../lib/$(LIBNAME)
|
||||
@@ -0,0 +1,520 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "equilibrium.h"
|
||||
#include "load.h"
|
||||
#include "thermo.h"
|
||||
|
||||
#include "conversion.h"
|
||||
#include "return.h"
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
Initial format of thermo.dat:
|
||||
interval variable type size description
|
||||
-----------------------------------------------------------------------------
|
||||
(0, 18) name string 18 compound name
|
||||
(18, 73) comments string 55 comment
|
||||
(73, 75) nint int 2 the number of temperature intervals
|
||||
(75, 81) id string 6 the material id
|
||||
81 state int 1 0 - GAS, else CONDENSED
|
||||
(82, 95) weight float 13 molecular weight
|
||||
(95, 108) enth/heat float 13 enthaply if nint == 0
|
||||
else heat of formation
|
||||
...
|
||||
rest of file
|
||||
...
|
||||
***************************************************************************/
|
||||
|
||||
int load_thermo(char *filename)
|
||||
{
|
||||
FILE *fd;
|
||||
|
||||
int i = 0;
|
||||
int j, k, l;
|
||||
|
||||
bool ok;
|
||||
|
||||
char buf[88], *buf_ptr, tmp[32], *tmp_ptr;
|
||||
buf_ptr = &buf[0];
|
||||
tmp_ptr = &tmp[0];
|
||||
|
||||
/* open the file for reading */
|
||||
if ((fd = fopen(filename, "r")) == NULL )
|
||||
return ERR_FOPEN;
|
||||
|
||||
if (global_verbose)
|
||||
{
|
||||
printf("Scanning thermo data file...");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
num_thermo = 0;
|
||||
|
||||
|
||||
/* Scan thermo.dat to find the number of positions in thermo_list
|
||||
to allocate */
|
||||
while (fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
/*
|
||||
All that is required is to count the number of lines not
|
||||
starting with ' ', '!' or '-'
|
||||
*/
|
||||
if (*buf_ptr != ' ' && *buf_ptr != '!' && *buf_ptr != '-')
|
||||
num_thermo++;
|
||||
}
|
||||
|
||||
/* Reset the file pointer */
|
||||
fseek(fd, 0, SEEK_SET);
|
||||
|
||||
if (global_verbose)
|
||||
{
|
||||
printf("\nScan complete. %ld records found. Allocating memory...",
|
||||
num_thermo);
|
||||
}
|
||||
|
||||
if ((thermo_list = (thermo_t *)malloc (sizeof(thermo_t) * num_thermo)) ==
|
||||
NULL)
|
||||
{
|
||||
printf("\n\nMemory allocation error with thermo_t thermo_list[%ld], %ld bytes required", num_thermo, sizeof(thermo_t) * num_thermo);
|
||||
return ERR_MALLOC;
|
||||
}
|
||||
|
||||
if (global_verbose)
|
||||
{
|
||||
printf("\nSuccessful. Loading thermo data file...");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
for (i = 0; i < num_thermo; i++)
|
||||
{
|
||||
/* Read in the next line and check for EOF */
|
||||
if (!fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
fclose(fd);
|
||||
free(thermo_list);
|
||||
return ERR_EOF;
|
||||
}
|
||||
|
||||
/* Skip commented lines */
|
||||
while (*buf_ptr == '!')
|
||||
{
|
||||
if (!fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
fclose(fd);
|
||||
free(thermo_list);
|
||||
return ERR_EOF;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read in the name and the comments */
|
||||
strncpy((thermo_list + i)->name, buf_ptr, 18);
|
||||
trim_spaces((thermo_list + i)->name, 18);
|
||||
|
||||
strncpy((thermo_list + i)->comments, buf_ptr + 18, 55);
|
||||
trim_spaces((thermo_list + i)->comments, 55);
|
||||
|
||||
// Read in the next line and check for EOF
|
||||
if (!fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
fclose(fd);
|
||||
free(thermo_list);
|
||||
return ERR_EOF;
|
||||
}
|
||||
|
||||
strncpy(tmp_ptr, buf_ptr, 3);
|
||||
(thermo_list + i)->nint = atoi(tmp_ptr);
|
||||
|
||||
strncpy((thermo_list + i)->id, buf_ptr + 3, 6);
|
||||
trim_spaces((thermo_list + i)->id, 6);
|
||||
|
||||
/* get the chemical formula and coefficient */
|
||||
/* grep the elements (5 max) */
|
||||
for (k = 0; k < 5; k++)
|
||||
{
|
||||
tmp[0] = buf[k * 8 + 10];
|
||||
tmp[1] = buf[k * 8 + 11];
|
||||
tmp[2] = '\0';
|
||||
|
||||
/* Check for an empty place (no more atoms) */
|
||||
if (strcmp(tmp, " "))
|
||||
{
|
||||
/* Atoms still to be processed */
|
||||
|
||||
/* find the atomic number of the element */
|
||||
(thermo_list + i)->elem[k] = atomic_number(tmp);
|
||||
|
||||
/* And the number of atoms */
|
||||
strncpy(tmp_ptr, buf_ptr + k * 8 + 13, 6);
|
||||
tmp[6] = '\0';
|
||||
|
||||
/* Should this be an int? If so, why is it stored in x.2 format? */
|
||||
(thermo_list + i)->coef[k] = (int) atof(tmp_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No atom here */
|
||||
(thermo_list + i)->coef[k] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* grep the state */
|
||||
if (buf[51] == '0')
|
||||
(thermo_list + i)->state = GAS;
|
||||
else
|
||||
(thermo_list + i)->state = CONDENSED;
|
||||
|
||||
/* grep the molecular weight */
|
||||
strncpy(tmp_ptr, buf_ptr + 52, 13);
|
||||
tmp[13] = '\0';
|
||||
(thermo_list + i)->weight = atof(tmp_ptr);
|
||||
|
||||
/* grep the heat of formation (J/mol) or enthalpy if condensed */
|
||||
/* The values are assigned in the if block following */
|
||||
strncpy(tmp_ptr, buf_ptr + 65, 15);
|
||||
tmp[15] = '\0';
|
||||
|
||||
/* now get the data */
|
||||
/* there is '(thermo_list + i)->nint' set of data */
|
||||
if ((thermo_list + i)->nint == 0)
|
||||
{
|
||||
/* Set the enthalpy */
|
||||
(thermo_list + i)->enth = atof(tmp_ptr);
|
||||
|
||||
/* condensed phase, different info */
|
||||
/* Read in the next line and check for EOF */
|
||||
if (!fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
fclose(fd);
|
||||
free(thermo_list);
|
||||
return ERR_EOF;
|
||||
}
|
||||
|
||||
/* treat the line */
|
||||
/* get the temperature of the assigned enthalpy */
|
||||
strncpy(tmp_ptr, buf_ptr + 1, 10);
|
||||
tmp[10] = '\0';
|
||||
|
||||
(thermo_list + i)->temp = atof(tmp_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the heat of formation */
|
||||
(thermo_list + i)->heat = atof(tmp_ptr);
|
||||
|
||||
|
||||
/* I'm not quite sure this is necessary */
|
||||
/* if the value is 0 and this is the same substance as
|
||||
the previous one but in a different state ... */
|
||||
if ((thermo_list + i)->heat == 0 && i != 0)
|
||||
{
|
||||
ok = true;
|
||||
for (j = 0; j < 5; j++)
|
||||
{
|
||||
/* set to the same value as the previous one if the same */
|
||||
if (!((thermo_list+i)->coef[j] == (thermo_list+i-1)->coef[j] &&
|
||||
(thermo_list+i)->elem[j] == (thermo_list+i-1)->elem[j]))
|
||||
ok = false;
|
||||
|
||||
}
|
||||
if (ok)
|
||||
(thermo_list+i)->heat = (thermo_list+i-1)->heat;
|
||||
}
|
||||
|
||||
for (j = 0; j < (thermo_list + i)->nint; j++)
|
||||
{
|
||||
/* Get the first line of three */
|
||||
/* Read in the line and check for EOF */
|
||||
if (!fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
fclose(fd);
|
||||
free(thermo_list);
|
||||
return ERR_EOF;
|
||||
}
|
||||
|
||||
/* low */
|
||||
strncpy(tmp_ptr, buf_ptr + 1, 10);
|
||||
tmp[10] = '\0';
|
||||
(thermo_list + i)->range[j][0] = atof(tmp_ptr);
|
||||
|
||||
/* high */
|
||||
strncpy(tmp_ptr, buf_ptr + 11, 10);
|
||||
tmp[10] = '\0';
|
||||
(thermo_list + i)->range[j][1] = atof(tmp_ptr);
|
||||
|
||||
tmp[0] = buf[22];
|
||||
tmp[1] = '\0';
|
||||
(thermo_list + i)->ncoef[j] = atoi(tmp_ptr);
|
||||
|
||||
/* grep the exponent */
|
||||
for (l = 0; l < 8; l++)
|
||||
{
|
||||
strncpy(tmp_ptr, buf_ptr + l * 5 + 23, 5);
|
||||
tmp[5] = '\0';
|
||||
(thermo_list + i)->ex[j][l] = atoi(tmp_ptr);
|
||||
}
|
||||
|
||||
/* HO(298.15) -HO(0) */
|
||||
strncpy(tmp_ptr, buf_ptr + 65, 15);
|
||||
tmp[15] = '\0';
|
||||
(thermo_list + i)->dho = atof(tmp);
|
||||
|
||||
/* Get the second line of three */
|
||||
/* Read in the line and check for EOF */
|
||||
if (!fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
fclose(fd);
|
||||
free(thermo_list);
|
||||
return ERR_EOF;
|
||||
}
|
||||
|
||||
/* grep the first data line */
|
||||
/* there are 5 coefficients */
|
||||
for (l = 0; l < 5; l++)
|
||||
{
|
||||
strncpy(tmp_ptr, buf_ptr + l * 16, 16);
|
||||
tmp[16] = '\0';
|
||||
|
||||
(thermo_list + i)->param[j][l] = atof(tmp_ptr);
|
||||
//(thermo_list + i)->param[j][l] = strtod(tmp_ptr, NULL);
|
||||
}
|
||||
|
||||
/* Get the third line of three */
|
||||
/* Read in the line and check for EOF */
|
||||
if (!fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
fclose(fd);
|
||||
free(thermo_list);
|
||||
return ERR_EOF;
|
||||
}
|
||||
|
||||
/* grep the second data line */
|
||||
for (l = 0; l < 2; l++)
|
||||
{
|
||||
strncpy(tmp_ptr, buf_ptr + l * 16, 16);
|
||||
tmp[16] = '\0';
|
||||
|
||||
(thermo_list + i)->param[j][l + 5] = atof(tmp_ptr);
|
||||
}
|
||||
|
||||
for (l = 0; l < 2; l++)
|
||||
{
|
||||
strncpy(tmp_ptr, buf_ptr + l * 16 + 48, 16);
|
||||
tmp[16] = '\0';
|
||||
|
||||
(thermo_list + i)->param[j][l + 7] = atof(tmp_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
|
||||
if (global_verbose)
|
||||
printf("%d species loaded.\n", i);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
int load_propellant(char *filename)
|
||||
{
|
||||
|
||||
FILE *fd;
|
||||
|
||||
int i = 0, j, len, name_start, name_end, name_len;
|
||||
|
||||
/* temporary string to store string in order to treat the informations */
|
||||
char buf[88], *buf_ptr, tmp[70], *tmp_ptr;
|
||||
buf_ptr = &buf[0];
|
||||
tmp_ptr = &tmp[0];
|
||||
|
||||
/* open the file for reading */
|
||||
if ((fd = fopen(filename, "r")) == NULL )
|
||||
return ERR_FOPEN;
|
||||
|
||||
if (global_verbose)
|
||||
{
|
||||
printf("Scanning propellant data file...");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
num_propellant = 0;
|
||||
|
||||
/* Scan propellant.dat to find the number of positions in propellant_list
|
||||
to allocate */
|
||||
while (fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
/* All that is required is to count the number of lines not starting
|
||||
with '*' or '+' */
|
||||
if (*buf_ptr != '*' && *buf_ptr != '+')
|
||||
num_propellant++;
|
||||
}
|
||||
|
||||
/* Reset the file pointer */
|
||||
fseek(fd, 0, SEEK_SET);
|
||||
|
||||
if (global_verbose)
|
||||
{
|
||||
printf("\nScan complete. %ld records found. Allocating memory...",
|
||||
num_propellant);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if ((propellant_list = (propellant_t *) malloc(sizeof(propellant_t) *
|
||||
num_propellant)) == NULL)
|
||||
{
|
||||
printf ("\n\nMemory allocation error with propellant_t propellant_list[%ld], %ld bytes required", num_propellant, sizeof(propellant_t) * num_propellant);
|
||||
return ERR_MALLOC;
|
||||
}
|
||||
|
||||
if (global_verbose)
|
||||
{
|
||||
printf("\nSuccessful. Loading propellant data file...");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if (!fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
fclose(fd);
|
||||
free(propellant_list);
|
||||
return ERR_EOF;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < num_propellant; i++)
|
||||
{
|
||||
/* Skip commented code */
|
||||
do
|
||||
{
|
||||
if (!fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
fclose(fd);
|
||||
free(propellant_list);
|
||||
return ERR_EOF;
|
||||
}
|
||||
}
|
||||
while (*buf_ptr == '*');
|
||||
|
||||
/* Check for a continued name */
|
||||
while (*buf_ptr == '+')
|
||||
{
|
||||
/* A continued name found */
|
||||
strncpy(tmp_ptr, buf_ptr + 9, 70);
|
||||
|
||||
|
||||
/* Find the end of the whitespaces. name_start + 1 is used to leave
|
||||
one space. */
|
||||
for (name_start = 0; name_start < 70; name_start++)
|
||||
{
|
||||
if (*(tmp_ptr + name_start + 1) != ' ')
|
||||
break;
|
||||
}
|
||||
|
||||
/* Find the end of the name. > 0 is used to be consistent with the
|
||||
one space left */
|
||||
/* when finding name_start */
|
||||
for (name_end = 69; name_end > 0; name_end--)
|
||||
{
|
||||
if (*(tmp_ptr + name_end) != ' ')
|
||||
break;
|
||||
}
|
||||
|
||||
name_len = name_end - name_start + 1;
|
||||
len = strlen((propellant_list + i - 1)->name);
|
||||
|
||||
/* Check for room in the destination string. Take into account
|
||||
the possibility of a
|
||||
multiple line continuation
|
||||
TODO - > 120 or >= 120 */
|
||||
if (len + name_len >= 120)
|
||||
{
|
||||
/* Not enough room - copy as much as possible and leave the
|
||||
name alone */
|
||||
strncpy((propellant_list + i - 1)->name + len,
|
||||
tmp_ptr + name_start, 119 - len);
|
||||
*((propellant_list + i - 1)->name + 119) = '\x0';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Concatenate the entire string */
|
||||
strncpy((propellant_list + i - 1)->name + len,
|
||||
tmp_ptr + name_start, name_len);
|
||||
*((propellant_list + i - 1)->name + len + name_len) = '\x0';
|
||||
}
|
||||
|
||||
|
||||
/* Processing of this line is done, so get the next one */
|
||||
if (!fgets(buf_ptr, 88, fd))
|
||||
{
|
||||
fclose(fd);
|
||||
free(propellant_list);
|
||||
return ERR_EOF;
|
||||
}
|
||||
}
|
||||
|
||||
/* grep the name */
|
||||
strncpy((propellant_list + i)->name, buf_ptr + 9, 30);
|
||||
trim_spaces((propellant_list + i)->name, 30);
|
||||
|
||||
for (j = 0; j < 6; j++)
|
||||
{
|
||||
tmp[0] = buf[j * 5 + 39];
|
||||
tmp[1] = buf[j * 5 + 40];
|
||||
tmp[2] = buf[j * 5 + 41];
|
||||
tmp[3] = '\0';
|
||||
|
||||
(propellant_list + i)->coef[j] = atoi(tmp);
|
||||
|
||||
tmp[0] = buf[j * 5 + 42];
|
||||
tmp[1] = buf[j * 5 + 43];
|
||||
tmp[2] = '\0';
|
||||
|
||||
/* find the atomic number of the element */
|
||||
/*
|
||||
for (k = 0; k < N_SYMB; k++)
|
||||
{
|
||||
if (!(strcmp(tmp, symb[k])))
|
||||
{
|
||||
(propellant_list + i)->elem[j] = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
(propellant_list + i)->elem[j] = atomic_number(tmp);
|
||||
}
|
||||
|
||||
strncpy(tmp_ptr, buf_ptr + 69, 5);
|
||||
tmp[5] = '\0';
|
||||
propellant_list[i].heat = atof(tmp) * CAL_TO_JOULE;
|
||||
|
||||
strncpy(tmp_ptr, buf_ptr + 75, 5);
|
||||
tmp[5] = '\0';
|
||||
propellant_list[i].density = atof(tmp) * LBS_IN3_TO_G_CM3;
|
||||
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
|
||||
if (global_verbose)
|
||||
printf("%d species loaded.\n", i);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
void trim_spaces(char *str, unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = len - 1; i > 0; i--)
|
||||
{
|
||||
if (*(str + i) != ' ' && *(str + i) != '\t')
|
||||
{
|
||||
*(str + i + 1) = '\0';
|
||||
return;
|
||||
}
|
||||
}
|
||||
*(str + 1) = '\0';
|
||||
}
|
||||
@@ -0,0 +1,563 @@
|
||||
/* thermo.c - Compute thermodynamic properties of individual
|
||||
species and composition of species */
|
||||
/* $Id: thermo.c,v 1.2 2001/02/22 19:48:44 antoine Exp $ */
|
||||
/* Copyright (C) 2000 */
|
||||
/* Antoine Lefebvre <antoine.lefebvre@polymtl.ca> */
|
||||
/* Mark Pinese <pinese@cyberwizards.com.au> */
|
||||
/* */
|
||||
/* Licensed under the GPLv2 */
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "thermo.h"
|
||||
#include "compat.h"
|
||||
#include "conversion.h"
|
||||
|
||||
/**************************************************************
|
||||
These variables hold the number of records for propellant and thermo data
|
||||
***************************************************************/
|
||||
unsigned long num_propellant, num_thermo;
|
||||
|
||||
/* global variable containing the information about chemical species */
|
||||
propellant_t *propellant_list;
|
||||
thermo_t *thermo_list;
|
||||
|
||||
|
||||
/****************************************************************
|
||||
VARIABLE: Contain the molar mass of element by atomic number
|
||||
molar_mass[0] contain hydrogen and so on.
|
||||
Data come from Sargent-Welch 1996
|
||||
*****************************************************************/
|
||||
const float molar_mass[N_SYMB] = {
|
||||
1.00794, 4.002602, 6.941, 9.012182, 10.811, 12.0107,
|
||||
14.00674, 15.9994, 18.9984032, 20.11797, 22.989770, 24.305,
|
||||
26.981538, 28.0855, 30.973761, 32.066, 35.4527, 39.948,
|
||||
39.0983, 40.078, 44.95591, 47.88, 50.9415, 51.996,
|
||||
54.938, 55.847, 58.9332, 58.6934, 63.546, 65.39,
|
||||
69.723, 72.61, 74.9216, 78.96, 79.904, 83.80,
|
||||
85.4678, 87.62, 88.9059, 91.224, 92.9064, 95.94,
|
||||
98.0, 101.07, 102.9055, 106.42, 107.868, 112.41,
|
||||
114.82, 118.71, 121.757, 127.60, 126.9045, 131.29,
|
||||
132.9054, 137.33, 138.9055, 140.12, 140.9077, 144.24,
|
||||
145., 150.36, 151.965, 157.25, 158.9253, 162.50,
|
||||
164.9303, 167.26, 168.9342, 173.04, 174.967, 178.49,
|
||||
180.9479, 183.85, 186.207, 190.2, 192.22, 195.08,
|
||||
196.9665, 200.59, 204.383, 207.2, 208.9804, 209.,
|
||||
210., 222., 223., 226.0254, 227., 232.0381,
|
||||
231.0359, 238.029, 237.0482, 244., 12.011, 9.01218,
|
||||
10.811, 24.305, 26.98154, 257.0, 0, 2};
|
||||
|
||||
|
||||
/****************************************************************
|
||||
VARIABLE: Contain the symbol of the element in the same way as
|
||||
for the molar mass.
|
||||
|
||||
COMMENTS: It is use in the loading of the data file to recognize
|
||||
the chemical formula.
|
||||
*****************************************************************/
|
||||
const char symb[N_SYMB][3] = {
|
||||
"H ","HE","LI","BE","B ","C ","N ","O ",
|
||||
"F ","NE","NA","MG","AL","SI","P ","S ","CL","AR","K ","CA",
|
||||
"SC","TI","V ","CR","MN","FE","CO","NI","CU","ZN","GA","GE",
|
||||
"AS","SE","BR","KR","RB","SR","Y ","ZR","NB","MO","TC","RU",
|
||||
"RH","PD","AG","CD","IN","SN","SB","TE","I ","XE","CS","BA",
|
||||
"LA","CE","PR","ND","PM","SM","EU","GD","TB","DY","HO","ER",
|
||||
"TM","YB","LU","HF","TA","W ","RE","OS","IR","PT","AU","HG","TL",
|
||||
"PB","BI","PO","AT","RN","FR","RA","AC","TH","PA","U ","NP",
|
||||
"U6","U5","U1","U2","U3","U4","FM",
|
||||
"E ", "D " }; /* the E stand for electron and D for deuterium*/
|
||||
|
||||
|
||||
/* Enthalpy in the standard state (Dimensionless) */
|
||||
double enthalpy_0(int sp, float T)
|
||||
{
|
||||
thermo_t *s = (thermo_list + sp);
|
||||
|
||||
double val;
|
||||
int pos = 0, i;
|
||||
|
||||
if (T < s->range[0][0]) /* Temperature below the lower range */
|
||||
{
|
||||
pos = 0;
|
||||
} /*Temperature above the higher range */
|
||||
else if (T >= s->range[s->nint-1][1])
|
||||
{
|
||||
pos = s->nint - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < s->nint; i++) /* Find the range */
|
||||
{
|
||||
if ((T >= s->range[i][0]) && (T < s->range[i][1]))
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* parametric equation for dimentionless enthalpy */
|
||||
val = -s->param[pos][0]*pow(T, -2) + s->param[pos][1]*pow(T, -1)*log(T)
|
||||
+ s->param[pos][2] + s->param[pos][3]*T/2 + s->param[pos][4]*pow(T, 2)/3
|
||||
+ s->param[pos][5]*pow(T, 3)/4 + s->param[pos][6]*pow(T, 4)/5
|
||||
+ s->param[pos][7]/T;
|
||||
|
||||
return val; /* dimensionless enthalpy */
|
||||
}
|
||||
|
||||
/* Entropy in the standard state (Dimensionless)*/
|
||||
double entropy_0(int sp, float T)
|
||||
{
|
||||
thermo_t *s = (thermo_list + sp);
|
||||
double val;
|
||||
int pos = 0, i;
|
||||
|
||||
if (T < s->range[0][0])
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
else if (T >= s->range[s->nint-1][1])
|
||||
{
|
||||
pos = s->nint - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < s->nint; i++)
|
||||
{
|
||||
if ((T >= s->range[i][0]) && (T < s->range[i][1]))
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* parametric equation for dimentionless entropy */
|
||||
val = -s->param[pos][0]*pow(T, -2)/2 - s->param[pos][1]*pow(T, -1)
|
||||
+ s->param[pos][2]*log(T) + s->param[pos][3]*T
|
||||
+ s->param[pos][4]*pow(T, 2)/2
|
||||
+ s->param[pos][5]*pow(T, 3)/3 + s->param[pos][6]*pow(T, 4)/4
|
||||
+ s->param[pos][8];
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/* Specific heat in the standard state (Dimensionless) */
|
||||
double specific_heat_0(int sp, float T)
|
||||
{
|
||||
thermo_t *s = (thermo_list + sp);
|
||||
double val;
|
||||
int pos = 0, i;
|
||||
|
||||
if (T < s->range[0][0])
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
else if (T >= s->range[s->nint-1][1])
|
||||
{
|
||||
pos = s->nint - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < s->nint; i++)
|
||||
{
|
||||
if ((T >= s->range[i][0]) && (T < s->range[i][1]))
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* parametric equation for dimentionless specific_heat */
|
||||
val = s->param[pos][0]*pow(T, -2) + s->param[pos][1]*pow(T, -1)
|
||||
+ s->param[pos][2] + s->param[pos][3]*T + s->param[pos][4]*pow(T, 2)
|
||||
+ s->param[pos][5]*pow(T, 3) + s->param[pos][6]*pow(T, 4);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/* Dimensionless Gibbs free energy in the standard state */
|
||||
double gibbs_0(int sp, float T)
|
||||
{
|
||||
return enthalpy_0(sp, T) - entropy_0(sp, T); /* dimensionless */
|
||||
}
|
||||
|
||||
/* Check if the species is in its range of definition
|
||||
0 if out of range, 1 if ok */
|
||||
int temperature_check(int sp, float T)
|
||||
{
|
||||
thermo_t *s = (thermo_list + sp);
|
||||
|
||||
if ((T > s->range[s->nint-1][1]) || (T < s->range[0][0]))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* This function return the transition temperature of the species
|
||||
considered which is nearest of the temperature T */
|
||||
double transition_temperature(int sp, float T)
|
||||
{
|
||||
thermo_t *s = (thermo_list + sp);
|
||||
|
||||
/* first assume that the lowest temperature is the good one */
|
||||
double transition_T = s->range[0][0];
|
||||
|
||||
/* verify if we did the good bet */
|
||||
if (fabs(transition_T - T) > fabs(s->range[s->nint-1][1] - T))
|
||||
{
|
||||
transition_T = s->range[s->nint-1][1];
|
||||
}
|
||||
|
||||
return transition_T;
|
||||
}
|
||||
|
||||
double entropy(int sp, state_t st, double ln_nj_n, float T, float P)
|
||||
{
|
||||
double s;
|
||||
|
||||
switch (st)
|
||||
{
|
||||
case GAS:
|
||||
/* The thermodynamic data are based on a standard state pressure
|
||||
of 1 bar (10^5 Pa) */
|
||||
s = entropy_0(sp, T) - ln_nj_n - log(P * ATM_TO_BAR);
|
||||
break;
|
||||
case CONDENSED:
|
||||
s = entropy_0(sp, T);
|
||||
break;
|
||||
default:
|
||||
s = 0;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/* J/mol T is in K, P is in atm */
|
||||
double gibbs(int sp, state_t st, double ln_nj_n, float T, float P)
|
||||
{
|
||||
double g;
|
||||
|
||||
switch (st)
|
||||
{
|
||||
case GAS:
|
||||
g = gibbs_0(sp, T) + ln_nj_n + log(P * ATM_TO_BAR);
|
||||
break;
|
||||
case CONDENSED:
|
||||
g = gibbs_0(sp, T);
|
||||
break;
|
||||
default:
|
||||
g = 0;
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
double propellant_molar_mass(int molecule)
|
||||
{
|
||||
int i = 0, coef;
|
||||
double ans = 0;
|
||||
|
||||
while ((coef = (propellant_list + molecule)->coef[i]))
|
||||
{
|
||||
ans += coef * molar_mass[(propellant_list + molecule)->elem[i]];
|
||||
i++;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
/* J/mol */
|
||||
double heat_of_formation(int molecule)
|
||||
{
|
||||
double hf = (propellant_list + molecule)->heat *
|
||||
propellant_molar_mass(molecule);
|
||||
return hf;
|
||||
}
|
||||
|
||||
|
||||
/* should not be in thermo.c */
|
||||
double propellant_enthalpy(equilibrium_t *e)
|
||||
{
|
||||
int i;
|
||||
double h = 0.0;
|
||||
for (i = 0; i < e->propellant.ncomp; i++)
|
||||
{
|
||||
h += e->propellant.coef[i] * heat_of_formation (e->propellant.molecule[i])
|
||||
/ propellant_mass (e);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
/* should not be in thermo.c */
|
||||
double product_enthalpy(equilibrium_t *e)
|
||||
{
|
||||
int i;
|
||||
double h = 0.0;
|
||||
|
||||
for (i = 0; i < e->product.n[GAS]; i++)
|
||||
{
|
||||
h += e->product.coef[GAS][i] * enthalpy_0(e->product.species[GAS][i], e->properties.T);
|
||||
}
|
||||
|
||||
for (i = 0; i < e->product.n[CONDENSED]; i++)
|
||||
{
|
||||
h += e->product.coef[CONDENSED][i] * enthalpy_0(e->product.species[CONDENSED][i], e->properties.T);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
/* should not be in thermo.c */
|
||||
double product_entropy(equilibrium_t *e)
|
||||
{
|
||||
int i;
|
||||
double ent = 0.0;
|
||||
for (i = 0; i < e->product.n[GAS]; i++)
|
||||
{
|
||||
ent += e->product.coef[GAS][i]*entropy(e->product.species[GAS][i], GAS,
|
||||
e->itn.ln_nj[i] - e->itn.ln_n,
|
||||
e->properties.T, e->properties.P);
|
||||
}
|
||||
for (i = 0; i < e->product.n[CONDENSED]; i++)
|
||||
{
|
||||
ent += e->product.coef[CONDENSED][i]*entropy(e->product.species[CONDENSED][i],
|
||||
CONDENSED, 0, e->properties.T, e->properties.P);
|
||||
}
|
||||
return ent;
|
||||
}
|
||||
|
||||
/* should not be in thermo.c */
|
||||
/* The specific heat of the mixture for frozen performance */
|
||||
double mixture_specific_heat_0(equilibrium_t *e, double temp)
|
||||
{
|
||||
int i;
|
||||
double cp = 0.0;
|
||||
/* for gases */
|
||||
for (i = 0; i < e->product.n[GAS]; i++)
|
||||
{
|
||||
cp += e->product.coef[GAS][i]*specific_heat_0(e->product.species[GAS][i], temp);
|
||||
}
|
||||
/* for condensed */
|
||||
for (i = 0; i < e->product.n[CONDENSED]; i++)
|
||||
{
|
||||
cp += e->product.coef[CONDENSED][i]*
|
||||
specific_heat_0(e->product.species[CONDENSED][i], temp);
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
||||
|
||||
int thermo_search(char *str)
|
||||
{
|
||||
int i;
|
||||
int last = -1;
|
||||
|
||||
for (i = 0; i < num_thermo; i++)
|
||||
{
|
||||
if (!(STRNCASECMP(str, (thermo_list + i)->name, strlen(str))))
|
||||
{
|
||||
last = i;
|
||||
printf("%-5d %s\n", i, (thermo_list + i)->name);
|
||||
}
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
int propellant_search(char *str)
|
||||
{
|
||||
int i;
|
||||
int last = -1;
|
||||
|
||||
for (i = 0; i < num_propellant; i++)
|
||||
{
|
||||
if (!(STRNCASECMP(str, (propellant_list + i)->name, strlen(str))))
|
||||
{
|
||||
last = i;
|
||||
printf("%-5d %s\n", i, (propellant_list + i)->name);
|
||||
}
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
|
||||
int atomic_number(char *symbole)
|
||||
{
|
||||
int i;
|
||||
int element = -1;
|
||||
|
||||
/* find the atomic number of the element */
|
||||
for (i = 0; i < N_SYMB; i++)
|
||||
{
|
||||
if (!STRCASECMP(symbole, symb[i]))
|
||||
{
|
||||
element = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
int compute_density(composition_t *c)
|
||||
{
|
||||
short i;
|
||||
double mass = 0;
|
||||
|
||||
c->density = 0.0;
|
||||
|
||||
for (i = 0; i < c->ncomp; i++)
|
||||
{
|
||||
mass += c->coef[i] * propellant_molar_mass(c->molecule[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < c->ncomp; i++)
|
||||
{
|
||||
if ((propellant_list + c->molecule[i])->density != 0.0)
|
||||
{
|
||||
c->density += c->coef[i] * propellant_molar_mass(c->molecule[i])
|
||||
/ (mass * (propellant_list + c->molecule[i])->density);
|
||||
}
|
||||
}
|
||||
|
||||
if (c->density != 0.0)
|
||||
{
|
||||
c->density = 1/c->density;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This fonction return the offset of the molecule in the propellant_list
|
||||
the argument is the chemical formula of the molecule */
|
||||
int propellant_search_by_formula(char *str)
|
||||
{
|
||||
int i = 0, j ;
|
||||
|
||||
char tmp[5];
|
||||
char *ptr;
|
||||
|
||||
int elem[6] = {0, 0, 0, 0, 0, 1};
|
||||
int coef[6] = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
int molecule = -1;
|
||||
|
||||
ptr = str; /* beginning of the string */
|
||||
|
||||
while ( (i < 6) && ((ptr - str) < strlen(str)) )
|
||||
{
|
||||
if (isupper(*ptr) && islower(*(ptr+1)) && (isupper(*(ptr+2)) ||
|
||||
iscntrl(*(ptr+2))) )
|
||||
{
|
||||
tmp[0] = *ptr;
|
||||
tmp[1] = toupper(*(ptr+1));
|
||||
tmp[2] = '\0';
|
||||
/* find the atomic number of the element */
|
||||
elem[i] = atomic_number(tmp);
|
||||
coef[i] = 1;
|
||||
i++;
|
||||
ptr += 2;
|
||||
}
|
||||
else if (isupper(*ptr) && (isupper(*(ptr+1)) ||
|
||||
iscntrl(*(ptr+1))) )
|
||||
{
|
||||
tmp[0] = *ptr;
|
||||
tmp[1] = ' ';
|
||||
tmp[2] = '\0';
|
||||
elem[i] = atomic_number(tmp);
|
||||
coef[i] = 1;
|
||||
i++;
|
||||
ptr++;
|
||||
}
|
||||
else if (isupper(*ptr) && isdigit(*(ptr+1)))
|
||||
{
|
||||
tmp[0] = *ptr;
|
||||
tmp[1] = ' ';
|
||||
tmp[2] = '\0';
|
||||
elem[i] = atomic_number(tmp);
|
||||
|
||||
j = 0;
|
||||
do
|
||||
{
|
||||
tmp[j] = *(ptr + 1 + j);
|
||||
j++;
|
||||
} while (isdigit(*(ptr + 1 + j)));
|
||||
|
||||
tmp[j] = '\0';
|
||||
|
||||
coef[i] = atoi(tmp);
|
||||
i++;
|
||||
|
||||
ptr = ptr + j + 1;
|
||||
}
|
||||
else if (isupper(*ptr) && islower(*(ptr+1)) && isdigit(*(ptr+2)))
|
||||
{
|
||||
tmp[0] = *ptr;
|
||||
tmp[1] = toupper(*(ptr+1));
|
||||
tmp[2] = '\0';
|
||||
elem[i] = atomic_number(tmp);
|
||||
|
||||
j = 0;
|
||||
while (isdigit(*(ptr + 2 + j)))
|
||||
{
|
||||
tmp[j] = *(ptr + 1 + j);
|
||||
j++;
|
||||
}
|
||||
tmp[j] = '\0';
|
||||
|
||||
coef[i] = atoi(tmp);
|
||||
i++;
|
||||
|
||||
ptr = ptr + j + 2;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
if (elem[i] != -1)
|
||||
printf("%s %d\n", symb[elem[i]], coef[i]);
|
||||
}
|
||||
*/
|
||||
|
||||
for (i = 0; i < num_propellant; i++)
|
||||
{
|
||||
for (j = 0; j < 6; j++)
|
||||
{
|
||||
/* set to the same value as the previous one if the same */
|
||||
if (!( ((propellant_list+i)->coef[j] == coef[j]) &&
|
||||
((propellant_list+i)->elem[j] == elem[j]) ))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Now search in propellant list for this molecule */
|
||||
/*
|
||||
for (j = 0; j < num_propellant; j++)
|
||||
{
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
if ( (coef[i] != propellant_element_coef(elem[i], j)) &&
|
||||
(propellant_list + i)
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
if (j == 5) /* we found the molecule ! */
|
||||
{
|
||||
|
||||
/* check if the inverse is true */
|
||||
molecule = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return molecule;
|
||||
}
|
||||
|
||||
|
||||
/* Mass of propellant in gram */
|
||||
double propellant_mass(equilibrium_t *e)
|
||||
{
|
||||
int i;
|
||||
double mass = 0.0;
|
||||
for (i = 0; i < e->propellant.ncomp; i++)
|
||||
{
|
||||
mass += e->propellant.coef[i] *
|
||||
propellant_molar_mass(e->propellant.molecule[i]);
|
||||
}
|
||||
return mass;
|
||||
}
|
||||
Reference in New Issue
Block a user