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:
R. J. Dev. Kwan
2021-01-20 15:50:36 -08:00
commit eb05416991
411 changed files with 362300 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
#
# Makefile to build Debian package for Rocketworkbench utility suite
# Written by Geoff O'Callaghan <geoff@starbiz.com.au>
# Based on existing Makefile from Rocketworkbench project
#
.PHONY: clean
all:
@echo " --------------------"
@echo " Compiling gpcp ..."
@echo " --------------------"
@$(MAKE) --no-print-directory -C gpcp all
@echo " --------------------"
@echo " Compiling libnum ..."
@echo " --------------------"
@$(MAKE) --no-print-directory -C libnum all
@echo " -----------------------"
@echo " Compiling libcpropep..."
@echo " -----------------------"
@$(MAKE) --no-print-directory -C libcpropep all
@echo " ----------------------"
@echo " Compiling libthermo..."
@echo " ----------------------"
@$(MAKE) --no-print-directory -C libthermo all
@echo " -----------------------"
@echo " Compiling libconvert..."
@echo " -----------------------"
@$(MAKE) --no-print-directory -C libconvert all
@echo " ----------------------"
@echo " Compiling libcompat..."
@echo " ----------------------"
@$(MAKE) --no-print-directory -C libcompat all
@echo " -------------------"
@echo " Compiling liblrd..."
@echo " -------------------"
@$(MAKE) --no-print-directory -C liblrd all
@echo " --------------------------"
@echo " Compiling librockflight..."
@echo " --------------------------"
@$(MAKE) --no-print-directory -C librockflight all
@echo " -------------------"
@echo " Compiling libmcp..."
@echo " -------------------"
@$(MAKE) --no-print-directory -C libmcp all
clean:
@echo " Cleaning libnum..."
@$(MAKE) --no-print-directory -C libnum clean
@echo " Cleaning libcpropep..."
@$(MAKE) --no-print-directory -C libcpropep clean
@echo " Cleaning libthermo..."
@$(MAKE) --no-print-directory -C libthermo clean
@echo " Cleaning libconvert..."
@$(MAKE) --no-print-directory -C libconvert clean
@echo " Cleaning libcompat..."
@$(MAKE) --no-print-directory -C libcompat clean
@echo " Cleaning liblrd..."
@$(MAKE) --no-print-directory -C liblrd clean
@echo " Cleaning librockflight..."
@$(MAKE) --no-print-directory -C librockflight clean
@echo " Cleaning libmcp..."
@$(MAKE) --no-print-directory -C libmcp clean
@@ -0,0 +1,2 @@
ROOT = ../../..
include $(ROOT)/config/presrc.mk
@@ -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,68 @@
#ifndef COMPAT_H
#define COMPAT_H
/*
Checking for _MSC_VER will detect whether MSVC++ is being used.
I don't know of the other compiler flags, so others will want to
add to this for their own compilers.
Mark Pinese 24/4/2000
*/
#ifdef _MSC_VER
/* MSVC++ 6.0 Std */
#define STRNCASECMP _strnicmp
/* add for MSVC++ 5.0 */
#define STRCASECMP _stricmp
#ifdef _DEBUG
#include <crtdbg.h>
#endif /* defined (_DEBUG) */
#ifndef __cplusplus
typedef enum
{
false = 0,
true = 1
} bool;
#endif /* !defined (__cplusplus) */
#endif /* define _MSC_VER */
#ifdef GCC
#define STRCASECMP strcasecmp
#define STRNCASECMP strncasecmp
#define __min(a, b) ( (a) <= (b) ? (a) : (b))
#define __max(a, b) ( (a) >= (b) ? (a) : (b))
typedef enum
{
false = 0,
true = 1
} bool;
#endif /* define GCC */
#ifdef BORLAND
int StrNCaseCmp(const char *s1, const char *s2, size_t sz);
#define STRNCASECMP StrNCaseCmp
#define __min(a, b) ( (a) <= (b) ? (a) : (b))
#define __max(a, b) ( (a) >= (b) ? (a) : (b))
typedef enum
{
false = 0,
true = 1
} bool;
#endif /* define BORLAND */
#endif /* !defined(COMPAT_H) */
@@ -0,0 +1,10 @@
/* getopt.h from Don Libes "Obfuscated C" (extended by PRW) */
#ifndef GETOPT_H
#define GETOPT_H
extern int getopt(int argc, char **argv, char *opts);
extern char *optarg; /* current argv string */
extern int optind; /* current argv index */
extern int optopt; /* option character */
extern int opterr; /* getopt prints errors if 1 */
#endif /* GETOPT_H */
@@ -0,0 +1,3 @@
ROOT = ../../../..
include $(ROOT)/config/makedef
include $(ROOT)/config/libsrc.mk
@@ -0,0 +1,46 @@
#ifdef BORLAND
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
/* Compare two strings, ignoring case */
static int strcasecmp(const char *s1, const char *s2)
{
unsigned int i, len = strlen(s1)+1;
char c1, c2;
for (i = 0; i < len; ++i)
{
c1 = tolower(s1[i]);
c2 = tolower(s2[i]);
if (c1 != c2)
{
return ((c1 > c2) ? (1) : (-1));
}
}
return 0;
}
/* Compare two strings up to n characters, ignoring case */
static int strncasecmp(const char *s1, const char *s2, size_t sz)
{
unsigned int i, len = strlen(s1)+1;
char c1, c2;
if (sz < len) len = sz;
for (i = 0; i < len; ++i)
{
c1 = tolower(s1[i]);
c2 = tolower(s2[i]);
if (c1 != c2)
{
return ((c1 > c2) ? (1) : (-1));
}
}
return 0;
}
#endif
@@ -0,0 +1,83 @@
/* file getopt.c */
/* Author: Peter Wilson */
/* Catholic University and NIST */
/* pwilson@cme.nist.gov */
/* */
/* getopt() from Don Libes "Obfuscated C" */
#include <stdio.h>
#include <string.h>
/* getopt() -- parse command line arguments */
/* Original Author: AT&T */
/* This version from Don Libes "Obfuscated C and Other Mysteries" */
/* John Wiley & Sons, 1993. Chapter 6 */
#define ERR(s, c) if (opterr) {\
char errbuf[3];\
errbuf[0] = c; errbuf[1] = '\n'; errbuf[2] = '\0'; \
fprintf(stderr, "%s", argv[0]);\
fprintf(stderr, "%s", s);\
fprintf(stderr, "%s", errbuf); }
int opterr = 1; /* getopt prints errors if this is one */
int optind = 1; /* token pointer */
int optopt; /* option character passed back to user */
char *optarg; /* flag argument (or value) */
/* return option option character, EOF if no more or ? if problem */
int getopt(int argc, char **argv, char *opts) /* opts: option string */
{
static int sp = 1; /* character index in current token */
register char *cp; /* pointer into current token */
if (sp == 1) {
/* check for more flag-like tokens */
if(optind >= argc ||
argv[optind][0] != '-' || argv[optind][1] == '\0')
return(EOF);
else if(strcmp(argv[optind], "--") == 0) {
optind++;
return(EOF);
}
}
optopt = argv[optind][sp];
if(optopt == ':' || ( cp = strchr(opts, optopt)) == 0) {
ERR(": illegal option -- ", optopt);
/* if no chars left in this token, move to next token */
if(argv[optind][++sp] == '\0') {
optind++;
sp = 1;
}
return('?');
}
if(*++cp == ':') {/* if a value is expected, get it */
if(argv[optind][sp+1] != '\0')
/* flag value is rest of current token */
optarg = &argv[optind++][sp+1];
else if (++optind >= argc) {
ERR(": option requires an argument -- ", optopt);
sp = 1;
return('?');
} else
/* flag value is next token */
optarg = argv[optind++];
sp = 1;
} else {
/* set up to look at next char in token, next time */
if(argv[optind][++sp] == '\0') {
/* no m ore in current token, set up next token */
sp = 1;
optind++;
}
optarg = 0;
}
return(optopt); /* return current flag character found */
}
@@ -0,0 +1,2 @@
LIBNAME = libcompat.a
LIBOBJS = getopt.o compat.o
@@ -0,0 +1,2 @@
ROOT = ../../..
include $(ROOT)/config/presrc.mk
@@ -0,0 +1,6 @@
#ifndef convert_h
#define convert_h
int convert(double *val, char *from_units, char *to_units, double *newval);
#endif
@@ -0,0 +1,3 @@
ROOT = ../../../..
include $(ROOT)/config/makedef
include $(ROOT)/config/libsrc.mk
@@ -0,0 +1,83 @@
#include <stdlib.h>
#include <stdio.h>
typedef enum type
{
MASS = 1,
FORCE = 2,
PRESSURE = 3
} type_t;
typedef struct conversion
{
char *units;
double factor;
type_t type;
} conversion_t;
conversion_t conversion_factors[] = {
{"kg", 1.0, MASS},
{"g", 0.001, MASS},
{"lb", 0.45359237, MASS},
{"oz", 0.028349523, MASS},
{"N", 1.0, FORCE},
{"lbf", 4.4482216, FORCE},
{"Pa", 1.0, PRESSURE},
{"atm", 101325, PRESSURE},
{"bar", 1e5, PRESSURE},
{"psi", 6894.7573, PRESSURE},
{NULL, 0.0, 0}
};
/* This function will convert the value 'val' represent in units
* to is SI representation
*/
int convert(double *val, char *from_units, char *to_units, double *newval)
{
conversion_t *conv = conversion_factors;
int i = 0;
double factor = 1;
short from_ok = 0, to_ok = 0;
type_t from_type = 0, to_type = 0;
while (conv[i].units != NULL)
{
if (strcmp(from_units, conv[i].units) == 0)
{
factor *= conv[i].factor;
from_ok = 1;
from_type = conv[i].type;
}
else if (strcmp(to_units, conv[i].units) == 0)
{
factor /= conv[i].factor;
to_ok = 1;
to_type = conv[i].type;
}
i++;
}
if ((from_type != to_type) || from_type == 0 || to_type == 0)
printf("Incompatible units.\n");
if (from_ok == 0)
printf("Unrecognized from units.\n");
if (to_ok == 0)
printf("Unrecognized to units.\n");
if (from_ok && to_ok)
*newval = *val * factor;
else
return -1;
return 0;
}
@@ -0,0 +1,2 @@
LIBNAME = libconvert.a
LIBOBJS = convert.o
@@ -0,0 +1,2 @@
ROOT = ../../..
include $(ROOT)/config/presrc.mk
@@ -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,11 @@
#ifndef const_h
#define const_h
/* molar gaz constant in J/(mol K)*/
#define R 8.31451
/* earth gravitational acceleration */
#define Ge 9.80665
#endif
@@ -0,0 +1,60 @@
#ifndef conversion_h
#define conversion_h
/* pressure units */
enum
{
ATM,
PSI,
BAR,
KPA
};
/* Transform calories to joules */
#define CAL_TO_JOULE 4.1868
/* Transform pound/(cubic inch) to gram/(cubic centimeter) */
#define LBS_IN3_TO_G_CM3 27.679905
/* Transform different pressure units */
#define ATM_TO_PA 101325.0
#define ATM_TO_PSI 14.695949
#define ATM_TO_BAR 1.01325
#define BAR_TO_PSI 14.503774
#define BAR_TO_ATM 0.98692327
#define PSI_TO_ATM 0.068045964
#define KPA_TO_ATM 0.0098692327
/* Length */
#define M_TO_CM 100.0
#define M_TO_IN 39.370079
#define IN_TO_M 0.0254
/* Surface */
#define M2_TO_CM2 10000.0
#define M2_TO_IN2 1550.0031
/* Volume */
#define M3_TO_CM3 1000000.0
#define M3_TO_IN3 61023.744
/* Mass flow */
#define KG_S_TO_LB_S 2.2046226
/* force */
/* newton to pound-force */
#define N_TO_LBF 0.22480894
#define LBF_TO_N 4.4482216
#endif
@@ -0,0 +1,8 @@
#ifndef derivative_h
#define derivative_h
#include "equilibrium.h"
int derivative(equilibrium_t *e);
#endif
@@ -0,0 +1,156 @@
#ifndef equilibrium_h
#define equilibrium_h
/* equilibrium.h - Calculation of Complex Chemical Equilibrium */
/* $Id: equilibrium.h,v 1.1.1.1 2001/07/20 03:19:06 antoine Exp $ */
/* Copyright (C) 2000 */
/* Antoine Lefebvre <antoine.lefebvre@polymtl.ca> */
/* Mark Pinese <pinese@cyberwizards.com.au> */
/* */
/* Licensed under the GPLv2 */
#include "libcompat/include/compat.h"
#include "type.h"
#define GRAM_TO_MOL(g, sp) g/propellant_molar_mass(sp)
#define _min(a, b, c) __min( __min(a, b), c)
#define _max(a, b, c) __max( __max(a, b), c)
extern int global_verbose;
/***************************************************************
FUNCTION PROTOTYPE SECTION
****************************************************************/
int set_verbose(equilibrium_t *e, int v);
/************************************************************
FUNCTION: This function search for all elements present in
the composition and fill the list with the
corresponding number.
PARAMETER: e is of type equilibrium_t and hold the information
about the propellant composition.
COMMENTS: It fill the member element in equilibrium_t
DATE: February 6, 2000
AUTHOR: Antoine Lefebvre
**************************************************************/
int list_element(equilibrium_t *e);
int reset_element_list(equilibrium_t *e);
int list_product(equilibrium_t *e);
/***************************************************************
FUNCTION: This function initialize the equilibrium structure.
The function allocate memory for all the structure
it need. It is important to call dealloc_equilibrium
after.
AUTHOR: Antoine Lefebvre
DATE: February 27, 2000
****************************************************************/
int initialize_equilibrium(equilibrium_t *e);
/***************************************************************
FUNCTION: Dealloc what have been allocated by
initialize_equilibrium
***************************************************************/
int dealloc_equilibrium(equilibrium_t *e);
int reset_equilibrium(equilibrium_t *e);
int copy_equilibrium(equilibrium_t *dest, equilibrium_t *src);
int compute_thermo_properties(equilibrium_t *e);
/***************************************************************
FUNCTION: Set the state at which we want to compute the
equilibrium.
PARAMETER: e is a pointer to an equilibrium_t structure
T is the temperature in deg K
P is the pressure in atm
AUTHOR: Antoine Lefebvre
****************************************************************/
int set_state(equilibrium_t *e, double T, double P);
/***************************************************************
FUNCTION: Add a new molecule in the propellant
PARAMETER: e is a pointer to the equilibrium_t structure
sp is the number of the molecule in the list
mol is the quantity in mol
AUTHOR: Antoine Lefebvre
****************************************************************/
int add_in_propellant(equilibrium_t *e, int sp, double mol);
/***************************************************************
FUNCTION: Return the stochiometric coefficient of an element
in a molecule. If the element isn't present, it return 0.
COMMENTS: There is a different function for the product and for the
propellant.
AUTHOR: Antoine Lefebvre
****************************************************************/
int product_element_coef(int element, int molecule);
/*int propellant_element_coef(int element, int molecule);*/
/***************************************************************
FUNCTION: This function fill the matrix in function of the data
store in the structure equilibrium_t. The solution
of this matrix give corresction to initial estimate.
COMMENTS: It use the theory explain in
"Computer Program for Calculation of Complex Chemical
Equilibrium Compositions, Rocket Performance, Incident
and Reflected Shocks, and Chapman-Jouguet Detonations"
by Gordon and McBride
AUTHOR: Antoine Lefebvre
****************************************************************/
/*#ifdef TRUE_ARRAY*/
/*int fill_equilibrium_matrix(double *matrix, equilibrium_t *e, problem_t P);*/
int fill_matrix(double *matrix, equilibrium_t *e, problem_t P);
/*#else*/
/*int fill_equilibrium_matrix(double **matrix, equilibrium_t *e, problem_t P);*/
/*int fill_matrix(double **matrix, equilibrium_t *e, problem_t P);*/
/*#endif*/
/****************************************************************
FUNCTION: This function compute the equilibrium composition at
at specific pressure/temperature point. It use fill_matrix
to obtain correction to initial estimate. It correct the
value until equilibrium is obtain.
AUTHOR: Antoine Lefebvre
******************************************************************/
int equilibrium(equilibrium_t *equil, problem_t P);
double product_molar_mass(equilibrium_t *e);
#endif
@@ -0,0 +1,18 @@
#ifndef performance_h
#define performance_h
#include "libcompat/include/compat.h"
#include "return.h"
#include "equilibrium.h"
#include "derivative.h"
int frozen_performance(equilibrium_t *e, exit_condition_t exit_type,
double value);
int shifting_performance(equilibrium_t *e, exit_condition_t exit_type,
double value);
#endif
@@ -0,0 +1,69 @@
#ifndef print_h
#define print_h
#include "type.h"
#include "equilibrium.h"
#include "derivative.h"
#include "performance.h"
#define PROPELLANT_NAME(sp) (propellant_list + sp)->name
extern FILE * errorfile;
extern FILE * outputfile;
int print_error_message(int error_code);
/***************************************************************
FUNCTION: Print the information of a specie in the thermo_list
PARAMETER: an integer corresponding to the molecule
AUTHOR: Antoine Lefebvre
***************************************************************/
int print_propellant_info(int sp);
int print_thermo_info(int sp);
/*************************************************************
FUNCTION: Print the content of the respective list with the
number which refer to the molecule
AUTHOR: Antoine Lefebvre
modification by Mark Pinese
**************************************************************/
int print_thermo_list(void);
int print_propellant_list(void);
/*************************************************************
FUNCTION: Print the list of condensed species in the product
PARAMETER: a structure of tupe product_t
AUTHOR: Antoine Lefebvre
**************************************************************/
int print_condensed(product_t p);
/*************************************************************
FUNCTION: Print the list of gazeous species in the product
PARAMETER: a structure of tupe product_t
AUTHOR: Antoine Lefebvre
**************************************************************/
int print_gazeous(product_t p);
int print_product_composition(equilibrium_t *e, short npt);
int print_product_properties(equilibrium_t *e, short npt);
int print_propellant_composition(equilibrium_t *e);
/*int print_derivative_results(deriv_t *d);*/
/*int print_performance_information(performance_t *p);*/
int print_performance_information(equilibrium_t *e, short npt);
#endif
@@ -0,0 +1,22 @@
#ifndef RETURN_H
#define RETURN_H
/* Codes used in some functions by Antoine Lefebvre */
#define SUCCESS 0
#define ERROR -1
/*
Return codes
Mark Pinese 24/4/2000
*/
#define ERR_MALLOC -1
#define ERR_FOPEN -2
#define ERR_EOF -3
#define ERR_NOT_ALLOC -4
#define ERR_TOO_MUCH_PRODUCT -5
#define ERR_EQUILIBRIUM -6
#define ERR_AERA_RATIO -7
#define ERR_RATIO_TYPE -8
#endif /* !defined(RETURN_H) */
@@ -0,0 +1,161 @@
#ifndef type_h
#define type_h
#define MAX_PRODUCT 400 /* Maximum species in product */
#define MAX_ELEMENT 15 /* Maximum different element */
#define MAX_COMP 20 /* Maximum different ingredient in
composition */
#include "libcompat/include/compat.h"
/****************************************************************
TYPE: Enumeration of the possible state of a substance
*****************************************************************/
typedef enum
{
GAS,
CONDENSED,
STATE_LAST
} state_t;
typedef enum
{
TP, /* assign temperature and pressure */
HP, /* assign enthalpy and pressure */
SP /* assign entropy and pressure */
} problem_t;
typedef enum
{
SUBSONIC_AREA_RATIO,
SUPERSONIC_AREA_RATIO,
PRESSURE
} exit_condition_t;
/********************************************
Note: Specific impulse have unit of m/s
Ns/kg = (kg m / s^2) * (s / kg)
= (m / s)
It is habitual to found in literature
specific impulse in units of second.
It is in reality Isp/g where g is
the earth acceleration.
**********************************************/
typedef struct _performance_prop
{
double ae_at; /* Exit aera / Throat aera */
double a_dotm; /* Exit aera / mass flow rate (m/s/atm) */
double cstar; /* Characteristic velocity */
double cf; /* Coefficient of thrust */
double Ivac; /* Specific impulse (vacuum) */
double Isp; /* Specific impulse */
} performance_prop_t;
/***************************************************************
TYPE: Hold the composition of a specific propellant
ncomp is the number of component
molecule[ ] hold the number in propellant_list corresponding
to the molecule
coef[ ] hold the stochiometric coefficient
NOTE: It should be great to allocate the memory of the array in
function of the number of element
DATE: February 6, 2000
****************************************************************/
typedef struct _composition
{
short ncomp; /* Number of different component */
short molecule[MAX_COMP]; /* Molecule code */
double coef[MAX_COMP]; /* Moles of molecule */
double density; /* Density of propellant */
} composition_t;
/*****************************************************************
TYPE: Hold the composition of the combustion product. The molecule
are separate between their different possible state.
NOTE: This structure should be initialize with the function
initialize_product.
DATE: February 13, 2000
******************************************************************/
typedef struct _product
{
bool element_listed; /* true if element have been listed */
bool product_listed; /* true if product have been listed */
bool isequil; /* true if equilibrium is ok */
/* coefficient matrix for the gases */
unsigned short A[MAX_ELEMENT][MAX_PRODUCT];
short n_element; /* n. of different element */
short element[MAX_ELEMENT]; /* element list */
short n[STATE_LAST]; /* n. of species for each state */
short n_condensed; /* n. of total possible condensed */
short species[STATE_LAST][MAX_PRODUCT]; /* possible species in each state */
double coef[STATE_LAST][MAX_PRODUCT]; /* coef. of each molecule */
} product_t;
/* Structure to hold information during the iteration procedure */
typedef struct _iteration_var
{
double n; /* mol/g of the mixture */
double ln_n; /* ln(n) */
double sumn; /* sum of all the nj */
double delta_ln_n; /* delta ln(n) in the iteration process */
double delta_ln_T; /* delta ln(T) in the iteration process */
double delta_ln_nj[MAX_PRODUCT]; /* delta ln(nj) in the iteration process */
double ln_nj[MAX_PRODUCT]; /* ln(nj) nj are the individual mol/g */
} iteration_var_t;
/**********************************************
Hold information on equilibrium properties once
it have been compute
June 14, 2000
***********************************************/
typedef struct _equilib_prop
{
double P; /* Pressure (atm) */
double T; /* Temperature (K) */
double H; /* Enthalpy (kJ/kg) */
double U; /* Internal energy (kJ/kg) */
double G; /* Gibbs free energy (kJ/kg) */
double S; /* Entropy (kJ/(kg)(K)) */
double M; /* Molar mass (g/mol) */
double dV_P; /* (d ln(V) / d ln(P))t */
double dV_T; /* (d ln(V) / d ln(T))p */
double Cp; /* Specific heat (kJ/(kg)(K)) */
double Cv; /* Specific heat (kJ/(kg)(K)) */
double Isex; /* Isentropic exponent (gamma) */
double Vson; /* Sound speed (m/s) */
} equilib_prop_t;
typedef struct _new_equilibrium
{
bool equilibrium_ok; /* true if the equilibrium have been compute */
bool properties_ok; /* true if the properties have been compute */
bool performance_ok; /* true if the performance have been compute */
/*temporarily*/
double entropy;
iteration_var_t itn;
composition_t propellant;
product_t product;
equilib_prop_t properties;
performance_prop_t performance;
} equilibrium_t;
#endif
@@ -0,0 +1,3 @@
ROOT = ../../../..
include $(ROOT)/config/makedef
include $(ROOT)/config/libsrc.mk
@@ -0,0 +1,242 @@
/* derivative.c - Fill the mattrix to compute thermochemical derivative
relative to logarithm of pressure and temperature */
/* $Id: derivative.c,v 1.1.1.1 2001/07/20 03:19:01 antoine Exp $ */
/* Copyright (C) 2000 */
/* Antoine Lefebvre <antoine.lefebvre@polymtl.ca> */
/* Mark Pinese <pinese@cyberwizards.com.au> */
/* */
/* Licensed under the GPLv2 */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "libnum/include/num.h"
#include "libcpropep/include/derivative.h"
#include "libcpropep/include/equilibrium.h"
#include "libcpropep/include/performance.h"
#include "libcpropep/include/print.h"
#include "libcpropep/include/return.h"
#include "libcompat/include/compat.h"
#include "libthermo/include/thermo.h"
int fill_temperature_derivative_matrix(double *matrix, equilibrium_t *e);
int fill_pressure_derivative_matrix(double *matrix, equilibrium_t *e);
/* Compute the specific_heat of the mixture using thermodynamics
derivative with respect to logarithm of temperature */
double mixture_specific_heat(equilibrium_t *e, double *sol)
{
short i, j;
double cp, tmp;
product_t *p = &(e->product);
equilib_prop_t *pr = &(e->properties);
cp = 0.0;
/* Compute Cp/R */
for (i = 0; i < p->n_element; i++)
{
tmp = 0.0;
for (j = 0; j < p->n[GAS]; j++)
tmp += p->A[i][j] * p->coef[GAS][j] *
enthalpy_0(p->species[GAS][j], pr->T);
cp += tmp * sol[i];
}
for (i = 0; i < p->n[CONDENSED]; i++)
{
cp += enthalpy_0(p->species[CONDENSED][i], pr->T)
* sol[i + p->n_element];
}
tmp = 0.0;
for (i = 0; i < p->n[GAS]; i++)
{
tmp += p->coef[GAS][i] * enthalpy_0(p->species[GAS][i], pr->T);
}
cp += tmp * sol[p->n_element + p->n[CONDENSED]];
cp += mixture_specific_heat_0(e, pr->T);
for (i = 0; i < p->n[GAS]; i++)
{
cp += p->coef[GAS][i] * pow(enthalpy_0(p->species[GAS][i], pr->T), 2);
}
return cp;
}
int derivative(equilibrium_t *e)
{
short size;
double *matrix;
double *sol;
product_t *p = &(e->product);
equilib_prop_t *prop = &(e->properties);
/* the size of the coefficient matrix */
size = p->n_element + p->n[CONDENSED] + 1;
matrix = (double *) malloc (size * (size + 1) * sizeof(double));
/* allocate the memory for the solution vector */
sol = (double *) calloc (size, sizeof(double));
fill_temperature_derivative_matrix(matrix, e);
if (NUM_lu(matrix, sol, size) == -1)
{
fprintf(outputfile, "The matrix is singular.\n");
}
else
{
if (global_verbose > 2)
{
fprintf(outputfile, "Temperature derivative results.\n");
NUM_print_vec(sol, size);
}
prop->Cp = mixture_specific_heat(e, sol)*R;
prop->dV_T = 1 + sol[e->product.n_element + e->product.n[CONDENSED]];
}
fill_pressure_derivative_matrix(matrix, e);
if (NUM_lu(matrix, sol, size) == -1)
{
fprintf(outputfile, "The matrix is singular.\n");
}
else
{
if (global_verbose > 2)
{
fprintf(outputfile, "Pressure derivative results.\n");
NUM_print_vec(sol, size);
}
prop->dV_P = sol[e->product.n_element + e->product.n[CONDENSED]] - 1;
}
prop->Cv = prop->Cp + e->itn.n * R * pow(prop->dV_T, 2)/prop->dV_P;
prop->Isex = -(prop->Cp / prop->Cv) / prop->dV_P;
prop->Vson = sqrt(1000 * e->itn.n * R * e->properties.T * prop->Isex);
free(matrix);
free(sol);
return 0;
}
/* Fill the matrix with the coefficient for evaluating derivatives with
respect to logarithm of temperature at constant pressure */
int fill_temperature_derivative_matrix(double *matrix, equilibrium_t *e)
{
short j, k, size;
double tmp;
short idx_cond, idx_n, idx_T;
product_t *p = &(e->product);
equilib_prop_t *pr = &(e->properties);
idx_cond = p->n_element;
idx_n = p->n_element + p->n[CONDENSED];
idx_T = p->n_element + p->n[CONDENSED] + 1;
/* the size of the coefficient matrix */
size = p->n_element + p->n[CONDENSED] + 1;
/* fill the common part */
fill_matrix(matrix, e, TP);
/* del ln(n)/ del ln(T) */
matrix[idx_n + size * idx_n] = 0.0;
/* right side */
for (j = 0; j < p->n_element; j++)
{
tmp = 0.0;
for (k = 0; k < p->n[GAS]; k++)
tmp -= p->A[j][k] * p->coef[GAS][k] * enthalpy_0(p->species[GAS][k],
pr->T);
matrix[j + size * idx_T] = tmp;
}
for (j = 0; j < p->n[CONDENSED]; j++) /* row */
matrix[j + idx_cond + size * idx_T] =
-enthalpy_0( p->species[CONDENSED][j], pr->T);
tmp = 0.0;
for (k = 0; k < p->n[GAS]; k++)
tmp -= p->coef[GAS][k]*enthalpy_0(p->species[GAS][k], pr->T);
matrix[idx_n + size * idx_T] = tmp;
return 0;
}
/* Fill the matrix with the coefficient for evaluating derivatives with
respect to logarithm of pressure at constant temperature */
int fill_pressure_derivative_matrix(double *matrix, equilibrium_t *e)
{
short j, k, size;
double tmp;
short idx_cond, idx_n, idx_T;
product_t *p = &(e->product);
idx_cond = p->n_element;
idx_n = p->n_element + p->n[CONDENSED];
idx_T = p->n_element + p->n[CONDENSED] + 1;
/* the size of the coefficient matrix */
size = p->n_element + p->n[CONDENSED] + 1;
/* fill the common part */
fill_matrix(matrix, e, TP);
/* del ln(n)/ del ln(T) */
matrix[idx_n + size * idx_n] = 0.0;
/* right side */
for (j = 0; j < p->n_element; j++)
{
tmp = 0.0;
for (k = 0; k < p->n[GAS]; k++)
tmp += p->A[j][k] * p->coef[GAS][k];
matrix[j + size * idx_T] = tmp;
}
for (j = 0; j < p->n[CONDENSED]; j++) /* row */
matrix[j + idx_cond + size * idx_T] = 0.0;
tmp = 0.0;
for (k = 0; k < p->n[GAS]; k++)
tmp += p->coef[GAS][k];
matrix[idx_n + size * idx_T] = tmp;
return 0;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,2 @@
LIBNAME = libcpropep.a
LIBOBJS = equilibrium.o print.o performance.o derivative.o
@@ -0,0 +1,564 @@
/* performance.c - Compute performance caracteristic of a motor
considering equilibrium */
/* $Id: performance.c,v 1.3 2001/10/08 03:22:01 antoine Exp $ */
/* Copyright (C) 2000 */
/* Antoine Lefebvre <antoine.lefebvre@polymtl.ca> */
/* Mark Pinese <pinese@cyberwizards.com.au> */
/* */
/* Licensed under the GPLv2 */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "libcpropep/include/performance.h"
#include "libcpropep/include/derivative.h"
#include "libcpropep/include/print.h"
#include "libcpropep/include/equilibrium.h"
#include "libcpropep/include/const.h"
#include "libcpropep/include/return.h"
#include "libcompat/include/compat.h"
#include "libthermo/include/thermo.h"
#define TEMP_ITERATION_MAX 8
#define PC_PT_ITERATION_MAX 5
#define PC_PE_ITERATION_MAX 6
double compute_temperature(equilibrium_t *e, double pressure,
double p_entropy);
/* Entropy of the product at the exit pressure and temperature */
double product_entropy_exit(equilibrium_t *e, double pressure, double temp)
{
double ent;
double t = e->properties.T;
double p = e->properties.P;
e->properties.T = temp;
e->properties.P = pressure;
ent = product_entropy(e); /* entropy at the new pressure */
e->properties.T = t;
e->properties.P = p;
return ent;
}
/* Enthalpy of the product at the exit temperature */
double product_enthalpy_exit(equilibrium_t *e, double temp)
{
double enth;
double t = e->properties.T;
e->properties.T = temp;
enth = product_enthalpy(e);
e->properties.T = t;
return enth;
}
/* The temperature could be found by entropy conservation with a
specified pressure */
double compute_temperature(equilibrium_t *e, double pressure, double p_entropy)
{
int i = 0;
double delta_lnt;
double temperature;
/* The first approximation is the chamber temperature */
temperature = e->properties.T;
do
{
delta_lnt = (p_entropy - product_entropy_exit(e, pressure, temperature))
/ mixture_specific_heat_0(e, temperature);
temperature = exp (log(temperature) + delta_lnt);
i++;
} while (fabs(delta_lnt) >= 0.5e-4 && i < TEMP_ITERATION_MAX);
if (i == TEMP_ITERATION_MAX)
{
fprintf(errorfile,
"Temperature do not converge in %d iterations. Don't thrust results.\n",
TEMP_ITERATION_MAX);
}
return temperature;
}
int frozen_performance(equilibrium_t *e, exit_condition_t exit_type,
double value)
{
int err_code;
short i;
double sound_velocity;
double flow_velocity;
double pc_pt; /* Chamber pressure / Throat pressure */
double pc_pe; /* Chamber pressure / Exit pressure */
double log_pc_pe; /* log(pc_pe) */
double ae_at; /* Exit aera / Throat aera */
double cp_cv;
double chamber_entropy;
double exit_pressure = 0;
equilibrium_t *t = e + 1; /* throat equilibrium */
equilibrium_t *ex = e + 2; /* exit equilibrium */
/* find the equilibrium composition in the chamber */
if (!(e->product.isequil))
{
if ((err_code = equilibrium(e, HP)) != SUCCESS)
{
fprintf(outputfile,
"No equilibrium, performance evaluation aborted.\n");
return err_code;
}
}
/* Simplification due to frozen equilibrium */
e->properties.dV_T = 1.0;
e->properties.dV_P = -1.0;
e->properties.Cp = mixture_specific_heat_0(e, e->properties.T) * R;
e->properties.Cv = e->properties.Cp - e->itn.n * R;
e->properties.Isex = e->properties.Cp/e->properties.Cv;
compute_thermo_properties(e);
chamber_entropy = product_entropy(e);
/* begin computation of throat caracteristic */
copy_equilibrium(t, e);
cp_cv = e->properties.Cp/e->properties.Cv;
/* first estimate of Pc/Pt */
pc_pt = pow (cp_cv/2 + 0.5, cp_cv/(cp_cv - 1));
i = 0;
do
{
t->properties.T = compute_temperature(t, e->properties.P/pc_pt,
chamber_entropy);
/* Cp of the combustion point assuming frozen */
t->properties.Cp = mixture_specific_heat_0(e, t->properties.T) * R;
/* Cv = Cp - nR (for frozen) */
t->properties.Cv = t->properties.Cp - t->itn.n * R;
t->properties.Isex = t->properties.Cp/t->properties.Cv;
compute_thermo_properties(t);
sound_velocity = sqrt(1000 * e->itn.n * R * t->properties.T *
t->properties.Isex);
flow_velocity = sqrt(2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy_exit(e, t->properties.T)*
R*t->properties.T));
pc_pt = pc_pt / ( 1 + ((pow(flow_velocity, 2) - pow(sound_velocity, 2))
/(1000*(t->properties.Isex + 1)*
t->itn.n * R *t->properties.T)));
i++;
} while ((fabs((pow(flow_velocity, 2) - pow(sound_velocity, 2))
/pow(flow_velocity, 2)) > 0.4e-4) &&
(i < PC_PT_ITERATION_MAX));
if (i == PC_PT_ITERATION_MAX)
{
fprintf(errorfile,
"Throat pressure do not converge in %d iterations. Don't thrust results\n",
PC_PT_ITERATION_MAX);
}
/*printf("%d iterations to evaluate throat pressure.\n", i);*/
t->properties.P = e->properties.P/pc_pt;
t->performance.Isp = t->properties.Vson = sound_velocity;
compute_thermo_properties(t);
/* Now compute exit properties */
copy_equilibrium(ex, e);
if (exit_type == PRESSURE)
{
exit_pressure = value;
}
else
{
ae_at = value;
/* Initial estimate of pressure ratio */
if (exit_type == SUPERSONIC_AREA_RATIO)
{
if ((ae_at > 1.0) && (ae_at < 2.0))
{
log_pc_pe = log(pc_pt) + sqrt (3.294*pow(ae_at,2) + 1.535*log(ae_at));
}
else if (ae_at >= 2.0)
{
log_pc_pe = t->properties.Isex + 1.4 * log(ae_at);
}
else
{
printf("Aera ratio out of range ( < 1.0 )\n");
return ERR_AERA_RATIO;
}
}
else if (exit_type == SUBSONIC_AREA_RATIO)
{
if ((ae_at > 1.0) && (ae_at < 1.09))
{
log_pc_pe = 0.9 * log(pc_pt) /
(ae_at + 10.587 * pow(log(ae_at), 3) + 9.454 * log(ae_at));
}
else if (ae_at >= 1.09)
{
log_pc_pe = log(pc_pt) /
(ae_at + 10.587 * pow(log(ae_at), 3) + 9.454 * log(ae_at));
}
else
{
printf("Aera ratio out of range ( < 1.0 )\n");
return ERR_AERA_RATIO;
}
}
else
{
return ERR_RATIO_TYPE;
}
/* Improved the estimate */
i = 0;
do
{
pc_pe = exp(log_pc_pe);
ex->properties.P = exit_pressure = e->properties.P/pc_pe;
ex->properties.T = compute_temperature(e, exit_pressure,
chamber_entropy);
/* Cp of the combustion point assuming frozen */
ex->properties.Cp = mixture_specific_heat_0(e, ex->properties.T) * R;
/* Cv = Cp - nR (for frozen) */
ex->properties.Cv = ex->properties.Cp - ex->itn.n * R;
ex->properties.Isex = ex->properties.Cp/ex->properties.Cv;
compute_thermo_properties(ex);
sound_velocity = sqrt(1000 * ex->itn.n * R * ex->properties.T *
ex->properties.Isex);
ex->performance.Isp =
flow_velocity = sqrt(2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy_exit(e, ex->properties.T)*
R*ex->properties.T));
ex->performance.ae_at =
(ex->properties.T * t->properties.P * t->performance.Isp) /
(t->properties.T * ex->properties.P * ex->performance.Isp);
log_pc_pe = log_pc_pe +
(ex->properties.Isex*pow(flow_velocity, 2)/
(pow(flow_velocity, 2) - pow(sound_velocity,2))) *
(log(ae_at) - log(ex->performance.ae_at));
i++;
} while ( (fabs((log_pc_pe - log(pc_pe))) > 0.00004) &&
(i < PC_PE_ITERATION_MAX) );
if (i == PC_PE_ITERATION_MAX)
{
fprintf(errorfile,
"Exit pressure do not converge in %d iterations. Don't thrust results\n",
PC_PE_ITERATION_MAX);
}
/*printf("%d iterations to evaluate exit pressure.\n", i); */
pc_pe = exp(log_pc_pe);
exit_pressure = e->properties.P/pc_pe;
}
ex->properties.T = compute_temperature(e, exit_pressure,
chamber_entropy);
/* We must check if the exit temperature is more than 50 K lower
than any transition temperature of condensed species.
In this case the results are not good and must be reject. */
ex->properties.P = exit_pressure;
ex->performance.Isp = sqrt(2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy_exit(e, ex->properties.T)*
R*ex->properties.T));
/* units are (m/s/atm) */
ex->performance.a_dotm = 1000 * R * ex->properties.T * ex->itn.n /
(ex->properties.P * ex->performance.Isp);
/* Cp of the combustion point assuming frozen */
ex->properties.Cp = mixture_specific_heat_0(e, ex->properties.T) * R;
/* Cv = Cp - nR (for frozen) */
ex->properties.Cv = ex->properties.Cp - ex->itn.n * R;
ex->properties.Isex = ex->properties.Cp/ex->properties.Cv;
compute_thermo_properties(ex);
ex->properties.Vson = sqrt(1000 * e->itn.n * R * ex->properties.T *
e->properties.Isex);
t->performance.a_dotm = 1000 * R * t->properties.T
* t->itn.n / (t->properties.P * t->performance.Isp);
t->performance.ae_at = 1.0;
t->performance.cstar = e->properties.P * t->performance.a_dotm;
t->performance.cf = t->performance.Isp /
(e->properties.P * t->performance.a_dotm);
t->performance.Ivac = t->performance.Isp + t->properties.P
* t->performance.a_dotm;
ex->performance.ae_at =
(ex->properties.T * t->properties.P * t->performance.Isp) /
(t->properties.T * ex->properties.P * ex->performance.Isp);
ex->performance.cstar = e->properties.P * t->performance.a_dotm;
ex->performance.cf = ex->performance.Isp /
(e->properties.P * t->performance.a_dotm);
ex->performance.Ivac = ex->performance.Isp + ex->properties.P
* ex->performance.a_dotm;
return SUCCESS;
}
int shifting_performance(equilibrium_t *e, exit_condition_t exit_type,
double value)
{
int err_code;
short i;
double sound_velocity = 0.0;
double flow_velocity;
double pc_pt;
double pc_pe;
double log_pc_pe;
double ae_at;
double chamber_entropy;
double exit_pressure = 0;
equilibrium_t *t = e + 1; /* throat equilibrium */
equilibrium_t *ex = e + 2; /* exit equilibrium */
/* find the equilibrium composition in the chamber */
if (!(e->product.isequil))
/* if the equilibrium have not already been compute */
{
if ((err_code = equilibrium(e, HP)) < 0)
{
fprintf(outputfile, "No equilibrium, performance evaluation aborted.\n");
return err_code;
}
}
/* Begin by first aproximate the new equilibrium to be
the same as the chamber equilibrium */
copy_equilibrium(t, e);
chamber_entropy = product_entropy(e);
/* Computing throat condition */
/* Approximation of the throat pressure */
pc_pt = pow(t->properties.Isex/2 + 0.5,
t->properties.Isex/(t->properties.Isex - 1) );
t->entropy = chamber_entropy;
i = 0;
do
{
t->properties.P = e->properties.P/pc_pt;
/* We must compute the new equilibrium each time */
if ((err_code = equilibrium(t, SP)) < 0)
{
fprintf(outputfile, "No equilibrium, performance evaluation aborted.\n");
return err_code;
}
sound_velocity = sqrt (1000*t->itn.n*R*t->properties.T*
t->properties.Isex);
flow_velocity = sqrt (2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy(t)*R*t->properties.T));
pc_pt = pc_pt / ( 1 + ((pow(flow_velocity, 2) - pow(sound_velocity, 2))
/(1000*(t->properties.Isex + 1)*t->itn.n*R*
t->properties.T)));
i++;
} while ((fabs((pow(flow_velocity, 2) - pow(sound_velocity, 2))
/pow(flow_velocity, 2)) > 0.4e-4) &&
(i < PC_PT_ITERATION_MAX));
if (i == PC_PT_ITERATION_MAX)
{
fprintf(errorfile, "Throat pressure do not converge in %d iterations."
" Don't thrust results.\n", PC_PT_ITERATION_MAX);
}
/*printf("%d iterations to evaluate throat pressure.\n", i);*/
t->properties.P = e->properties.P/pc_pt;
t->properties.Vson = sound_velocity;
t->performance.Isp = sound_velocity;
t->performance.a_dotm = 1000 * R *
t->properties.T * t->itn.n /
(t->properties.P * t->performance.Isp);
copy_equilibrium(ex, e);
if (exit_type == PRESSURE)
{
exit_pressure = value;
}
else
{
ae_at = value;
/* Initial estimate of pressure ratio */
if (exit_type == SUPERSONIC_AREA_RATIO)
{
if ((ae_at > 1.0) && (ae_at < 2.0))
{
log_pc_pe = log(pc_pt) + sqrt (3.294*pow(ae_at,2) + 1.535*log(ae_at));
}
else if (ae_at >= 2.0)
{
log_pc_pe = t->properties.Isex + 1.4 * log(ae_at);
}
else
{
printf("Aera ratio out of range ( < 1.0 )\n");
return ERR_AERA_RATIO;
}
}
else if (exit_type == SUBSONIC_AREA_RATIO)
{
if ((ae_at > 1.0) && (ae_at < 1.09))
{
log_pc_pe = 0.9 * log(pc_pt) /
(ae_at + 10.587 * pow(log(ae_at), 3) + 9.454 * log(ae_at));
}
else if (ae_at >= 1.09)
{
log_pc_pe = log(pc_pt) /
(ae_at + 10.587 * pow(log(ae_at), 3) + 9.454 * log(ae_at));
}
else
{
printf("Aera ratio out of range ( < 1.0 )\n");
return ERR_AERA_RATIO;
}
}
else
{
return ERR_RATIO_TYPE;
}
/* Improved the estimate */
ex->entropy = chamber_entropy;
i = 0;
do
{
pc_pe = exp(log_pc_pe);
ex->properties.P = exit_pressure = e->properties.P/pc_pe;
/* Find the exit equilibrium */
if ((err_code = equilibrium(ex, SP)) < 0)
{
fprintf(outputfile,
"No equilibrium, performance evaluation aborted.\n");
return err_code;
}
sound_velocity = ex->properties.Vson;
ex->performance.Isp =
flow_velocity = sqrt(2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy(ex)*R*ex->properties.T));
ex->performance.ae_at =
(ex->properties.T * t->properties.P * t->performance.Isp) /
(t->properties.T * ex->properties.P * ex->performance.Isp);
log_pc_pe = log_pc_pe +
(ex->properties.Isex*pow(flow_velocity, 2)/
(pow(flow_velocity, 2) - pow(sound_velocity,2))) *
(log(ae_at) - log(ex->performance.ae_at));
i++;
} while ((fabs((log_pc_pe - log(pc_pe))) > 0.00004) &&
(i < PC_PE_ITERATION_MAX));
if (i == PC_PE_ITERATION_MAX)
{
fprintf(errorfile, "Exit pressure do not converge in %d iteration."
" Don't thrust results.\n", PC_PE_ITERATION_MAX);
}
/*printf("%d iterations to evaluate exit pressure.\n", i);*/
pc_pe = exp(log_pc_pe);
exit_pressure = e->properties.P/pc_pe;
}
ex->entropy = chamber_entropy;
ex->properties.P = exit_pressure;
/* Find the exit equilibrium */
if ((err_code = equilibrium(ex, SP)) < 0)
{
fprintf(outputfile, "No equilibrium, performance evaluation aborted.\n");
return err_code;
}
flow_velocity = sqrt(2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy(ex)*R*ex->properties.T));
ex->performance.Isp = flow_velocity;
ex->performance.a_dotm = 1000 * R *
ex->properties.T * ex->itn.n /
(ex->properties.P * ex->performance.Isp);
t->performance.ae_at = 1.0;
t->performance.cstar = e->properties.P * t->performance.a_dotm;
t->performance.cf = t->performance.Isp /
(e->properties.P * t->performance.a_dotm);
t->performance.Ivac = t->performance.Isp + t->properties.P
* t->performance.a_dotm;
ex->performance.ae_at =
(ex->properties.T * t->properties.P * t->performance.Isp) /
(t->properties.T * ex->properties.P * ex->performance.Isp);
ex->performance.cstar = e->properties.P * t->performance.a_dotm;
ex->performance.cf = ex->performance.Isp /
(e->properties.P * t->performance.a_dotm);
ex->performance.Ivac = ex->performance.Isp + ex->properties.P
* ex->performance.a_dotm;
return SUCCESS;
}
@@ -0,0 +1,428 @@
/* print.c - Output functions */
/* $Id: print.c,v 1.1.1.1 2001/07/20 03:19:05 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 "libcpropep/include/print.h"
#include "libcpropep/include/performance.h"
#include "libcpropep/include/equilibrium.h"
#include "libcpropep/include/conversion.h"
#include "libcpropep/include/const.h"
#include "libthermo/include/thermo.h"
char header[][32] = {
"CHAMBER",
"THROAT",
"EXIT" };
char err_message[][64] = {
"Error allocating memory",
"Error opening file",
"Error EOF",
"Error memory not allocated",
"Error too much product",
"Error in equilibrium",
"Error bad aera ratio",
"Error bad aera ratio type"};
FILE * errorfile;
FILE * outputfile;
int print_error_message(int error_code)
{
fprintf(errorfile, "%s\n", err_message[-error_code - 1]);
return 0;
}
int print_propellant_info(int sp)
{
int j;
if (sp > num_propellant || sp < 0)
return -1;
fprintf(outputfile, "Code %-35s Enthalpy Density Composition\n", "Name");
fprintf(outputfile, "%d %-35s % .4f % .2f", sp,
(propellant_list + sp)->name,
(propellant_list + sp)->heat,
(propellant_list + sp)->density);
fprintf(outputfile, " ");
/* print the composition */
for (j = 0; j < 6; j++)
{
if (!((propellant_list + sp)->coef[j] == 0))
fprintf(outputfile, "%d%s ", (propellant_list + sp)->coef[j],
symb[ (propellant_list + sp)->elem[j] ]);
}
fprintf(outputfile, "\n");
return 0;
}
int print_thermo_info(int sp)
{
int i, j;
thermo_t *s;
if (sp > num_thermo || sp < 0)
return -1;
s = (thermo_list + sp);
fprintf(outputfile, "---------------------------------------------\n");
fprintf(outputfile, "Name: \t\t\t%s\n", s->name);
fprintf(outputfile, "Comments: \t\t%s\n", s->comments);
fprintf(outputfile, "Id: \t\t\t%s\n", s->id);
fprintf(outputfile, "Chemical formula:\t");
for (i = 0; i < 5; i++)
{
if (!(s->coef[i] == 0))
fprintf(outputfile, "%d%s", s->coef[i], symb[ s->elem[i]]);
}
fprintf(outputfile, "\n");
fprintf(outputfile, "State:\t\t\t");
switch (s->state)
{
case GAS:
fprintf(outputfile, "GAZ\n");
break;
case CONDENSED:
fprintf(outputfile, "CONDENSED\n");
break;
default:
printf("UNRECOGNIZE\n");
}
fprintf(outputfile, "\n");
fprintf(outputfile, "Molecular weight: \t\t% f g/mol\n", s->weight);
fprintf(outputfile, "Heat of formation at 298.15 K : % f J/mol\n", s->heat);
fprintf(outputfile, "Assign enthalpy : % f J/mol\n", s->enth);
fprintf(outputfile, "HO(298.15) - HO(0): \t\t% f J/mol\n", s->dho);
fprintf(outputfile, "Number of temperature range: % d\n\n", s->nint);
for (i = 0; i < s->nint; i++)
{
fprintf(outputfile, "Interval: %f - %f \n", s->range[i][0],
s->range[i][1]);
for (j = 0; j < 9; j++)
fprintf(outputfile, "% .9e ", s->param[i][j]);
fprintf(outputfile, "\n\n");
}
fprintf(outputfile, "---------------------------------------------\n");
return 0;
}
int print_thermo_list(void)
{
int i;
for (i = 0; i < num_thermo; i++)
fprintf(outputfile, "%-4d %-15s % .2f\n", i, (thermo_list + i)->name,
(thermo_list + i)->heat);
return 0;
}
int print_propellant_list(void)
{
int i;
for (i = 0; i < num_propellant; i++)
fprintf(outputfile, "%-4d %-30s %5f\n", i, (propellant_list + i)->name,
(propellant_list +i)->heat);
return 0;
}
int print_condensed(product_t p)
{
int i;
for (i = 0; i < p.n[CONDENSED]; i ++)
fprintf(outputfile, "%s ",
(thermo_list + p.species[CONDENSED][i])->name );
fprintf(outputfile, "\n");
return 0;
}
int print_gazeous(product_t p)
{
int i;
for (i = 0; i < p.n[GAS]; i++)
fprintf(outputfile, "%s ", (thermo_list + p.species[GAS][i])->name);
fprintf(outputfile, "\n");
return 0;
}
int print_product_composition(equilibrium_t *e, short npt)
{
int i, j, k;
double mol_g = e->itn.n;
/* we have to build a list of all condensed species present
in the three equilibrium */
int n = 0;
int condensed_list[MAX_PRODUCT];
/* ok become false if the species already exist in the list */
int ok = 1;
double qt;
for (i = 0; i < e->product.n[CONDENSED]; i++)
mol_g += e->product.coef[CONDENSED][i];
fprintf(outputfile, "\nMolar fractions\n\n");
for (i = 0; i < e->product.n[GAS]; i++)
{
if (e->product.coef[GAS][i]/e->itn.n > 0.0)
{
fprintf(outputfile, "%-20s",
(thermo_list + e->product.species[GAS][i])->name);
for (j = 0; j < npt; j++)
fprintf(outputfile, " %11.4e", (e+j)->product.coef[GAS][i]/mol_g);
fprintf(outputfile,"\n");
}
}
/* build the list of condensed */
for (i = 0; i < npt; i++)
{
for (j = 0; j < (e+i)->product.n[CONDENSED]; j++)
{
for (k = 0; k < n; k++)
{
/* check if the condensed are to be include in the list */
if (condensed_list[k] == (e+i)->product.species[CONDENSED][j])
{
/* we do not have to include the species */
ok = 0;
break;
}
} /* k */
if (ok)
{
condensed_list[n] = (e+i)->product.species[CONDENSED][j];
n++;
}
/* reset the flag */
ok = 1;
} /* j */
} /* i */
if (n > 0)
{
fprintf(outputfile, "Condensed species\n");
for (i = 0; i < n; i++)
{
fprintf(outputfile, "%-20s",
(thermo_list + condensed_list[i])->name);
for (j = 0; j < npt; j++)
{
/* search in the product of each equilibrium if the
condensed is present */
qt = 0.0;
for (k = 0; k < (e+j)->product.n[CONDENSED]; k++)
{
if (condensed_list[i] == (e+j)->product.species[CONDENSED][k])
{
qt = (e+j)->product.coef[CONDENSED][k];
break;
}
}
fprintf(outputfile, " %11.4e", qt/mol_g);
}
fprintf(outputfile,"\n");
}
}
fprintf(outputfile, "\n");
return 0;
}
int print_propellant_composition(equilibrium_t *e)
{
int i, j;
fprintf(outputfile, "Propellant composition\n");
fprintf(outputfile, "Code %-35s mol Mass (g) Composition\n", "Name");
for (i = 0; i < e->propellant.ncomp; i++)
{
fprintf(outputfile, "%-4d %-35s %.4f %.4f ", e->propellant.molecule[i],
PROPELLANT_NAME(e->propellant.molecule[i]), e->propellant.coef[i],
e->propellant.coef[i] *
propellant_molar_mass(e->propellant.molecule[i]));
fprintf(outputfile, " ");
/* print the composition */
for (j = 0; j < 6; j++)
{
if (!((propellant_list + e->propellant.molecule[i])->coef[j] == 0))
fprintf(outputfile, "%d%s ",
(propellant_list + e->propellant.molecule[i])->coef[j],
symb[(propellant_list + e->propellant.molecule[i])->elem[j]]);
}
fprintf(outputfile, "\n");
}
fprintf(outputfile, "Density : % .3f g/cm^3\n", e->propellant.density);
if (e->product.element_listed)
{
fprintf(outputfile, "%d different elements\n", e->product.n_element);
/* Print those elements */
for (i = 0; i < e->product.n_element; i++)
fprintf(outputfile, "%s ", symb[e->product.element[i]] );
fprintf(outputfile, "\n");
}
fprintf(outputfile, "Total mass: % f g\n", propellant_mass(e));
fprintf(outputfile, "Enthalpy : % .2f kJ/kg\n",
propellant_enthalpy(e));
fprintf(outputfile, "\n");
if (e->product.product_listed)
{
fprintf(outputfile, "%d possible gazeous species\n", e->product.n[GAS]);
if (global_verbose > 1)
print_gazeous(e->product);
fprintf(outputfile, "%d possible condensed species\n\n",
e->product.n_condensed);
if (global_verbose > 1)
print_condensed(e->product);
}
return 0;
}
int print_performance_information (equilibrium_t *e, short npt)
{
short i;
fprintf(outputfile, "Ae/At : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.ae_at);
fprintf(outputfile, "\n");
fprintf(outputfile, "A/dotm (m/s/atm) : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.a_dotm);
fprintf(outputfile, "\n");
fprintf(outputfile, "C* (m/s) : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.cstar);
fprintf(outputfile, "\n");
fprintf(outputfile, "Cf : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.cf);
fprintf(outputfile, "\n");
fprintf(outputfile, "Ivac (m/s) : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.Ivac);
fprintf(outputfile, "\n");
fprintf(outputfile, "Isp (m/s) : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.Isp);
fprintf(outputfile, "\n");
fprintf(outputfile, "Isp/g (s) : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.Isp/Ge);
fprintf(outputfile, "\n");
return 0;
}
int print_product_properties(equilibrium_t *e, short npt)
{
short i;
fprintf(outputfile, " ");
for (i = 0; i < npt; i++)
fprintf(outputfile, " %11s", header[i]);
fprintf(outputfile, "\n");
fprintf(outputfile, "Pressure (atm) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.P);
fprintf(outputfile, "\n");
fprintf(outputfile, "Temperature (K) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.T);
fprintf(outputfile, "\n");
fprintf(outputfile, "H (kJ/kg) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.H);
fprintf(outputfile, "\n");
fprintf(outputfile, "U (kJ/kg) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.U);
fprintf(outputfile, "\n");
fprintf(outputfile, "G (kJ/kg) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.G);
fprintf(outputfile, "\n");
fprintf(outputfile, "S (kJ/(kg)(K) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.S);
fprintf(outputfile, "\n");
fprintf(outputfile, "M (g/mol) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.M);
fprintf(outputfile, "\n");
fprintf(outputfile, "(dLnV/dLnP)t :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.dV_P);
fprintf(outputfile, "\n");
fprintf(outputfile, "(dLnV/dLnT)p :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.dV_T);
fprintf(outputfile, "\n");
fprintf(outputfile, "Cp (kJ/(kg)(K)) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.Cp);
fprintf(outputfile, "\n");
fprintf(outputfile, "Cv (kJ/(kg)(K)) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.Cv);
fprintf(outputfile, "\n");
fprintf(outputfile, "Cp/Cv :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.Cp/(e+i)->properties.Cv);
fprintf(outputfile, "\n");
fprintf(outputfile, "Gamma :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.Isex);
fprintf(outputfile, "\n");
fprintf(outputfile, "Vson (m/s) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.Vson);
fprintf(outputfile, "\n");
fprintf(outputfile, "\n");
return 0;
}
@@ -0,0 +1,2 @@
ROOT = ../../..
include $(ROOT)/config/presrc.mk
@@ -0,0 +1,72 @@
#ifndef lrd_h
#define lrd_h
#include "libcpropep/include/type.h"
typedef struct _design_param_t
{
/* Design criteria */
double chamber_pressure; /* Operating pressure of the motor (atm) */
double thrust; /* Thrust of the motor (N) */
double Lstar; /* Cracteristic chamber lengtgh */
double Dc_Dt; /* Chamber diameter / Throat diameter */
double R_Rt; /* Ratio of nozzle contour arc radius
to throat radius */
double theta; /* Convergent half angle (deg) */
} design_param_t;
typedef struct _motor_t
{
/* Unknown that will be compute */
double mass_flow_rate; /* Total mass flow (kg/s) */
double ox_flow_rate; /* Oxidant mass flow rate */
double fu_flow_rate; /* Fuel mass flow rate */
double throat_area; /* (m^2) */
double throat_diameter; /* (m) */
double throat_radius; /* (m) */
double exit_area; /* (m^2) */
double exit_diameter; /* (m) */
double exit_radius; /* (m) */
double Ac_At; /* Chamber area / throat area */
/* total */
double chamber_volume; /* (m^3) */
double chamber_area; /* (m^2) */
double chamber_diameter; /* (m) */
double chamber_radius; /* (m) */
double chamber_length; /* (m) */
/* conical section */
double convergent_volume; /* (m^3) */
double convergent_length; /* (m) */
/* cylindrical section */
double cylinder_volume; /* (m^3) */
double cylinder_length; /* (m) */
double walls_area; /* total surface area of the
combustion chamber walls
excluding injector face */
} motor_t;
typedef struct _liquid_propellant_t
{
int oxidant;
int fuel;
double o_f_ratio;
} liquid_propellant_t;
int LRD_compute_caracteristics(equilibrium_t *e, design_param_t *d,
motor_t *m, liquid_propellant_t *p);
int LRD_print_propellant_info(liquid_propellant_t *p);
int LRD_print_design_criteria(design_param_t *c);
int LRD_print_design_information(motor_t *mf, motor_t *ms);
#endif
@@ -0,0 +1,3 @@
ROOT = ../../../..
include $(ROOT)/config/makedef
include $(ROOT)/config/libsrc.mk
@@ -0,0 +1,156 @@
/* Liquid rocket design */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "libcpropep/include/print.h"
#include "libcpropep/include/type.h"
#include "libthermo/include/thermo.h"
#include "libcpropep/include/conversion.h"
#include "liblrd/include/lrd.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
int LRD_compute_caracteristics(equilibrium_t *e, design_param_t *d, motor_t *m,
liquid_propellant_t *p)
{
equilibrium_t *throat, *exit;
throat = e + 1;
exit = e + 2;
m->mass_flow_rate = d->thrust / exit->performance.Isp;
m->fu_flow_rate = m->mass_flow_rate / (p->o_f_ratio + 1);
m->ox_flow_rate = m->mass_flow_rate - m->fu_flow_rate;
m->throat_area = m->mass_flow_rate * throat->performance.a_dotm
/ ATM_TO_PA;
m->throat_diameter = 2 * sqrt(m->throat_area / M_PI);
m->throat_radius = m->throat_diameter/2;
m->exit_area = m->throat_area * exit->performance.ae_at;
m->exit_diameter = 2 * sqrt(m->exit_area / M_PI);
m->exit_radius = m->exit_diameter/2;
m->Ac_At = pow(d->Dc_Dt, 2);
m->chamber_volume = d->Lstar * m->throat_area;
m->chamber_diameter = d->Dc_Dt * m->throat_diameter;
m->chamber_radius = m->chamber_diameter/2;
m->chamber_area = M_PI * pow(m->chamber_radius, 2);
m->convergent_length = (m->throat_radius*(sqrt(m->Ac_At) - 1) +
d->R_Rt*m->throat_radius*
(pow(cos(d->theta*M_PI/180),-1) -1))
/tan(d->theta*M_PI/180);
/* m->convergent_volume = (M_PI/3)*m->convergent_length*
(pow(m->chamber_radius, 2)+pow(m->throat_radius, 2)+
m->chamber_radius*m->throat_radius); */
m->convergent_volume = (1/3) * m->throat_area *sqrt(m->throat_area/M_PI) *
pow(tan(d->theta*M_PI/180), -1)*(pow(m->Ac_At, 1/3) - 1);
/*
m->convergent_length = d->R_Rt*m->throat_radius*sin(d->theta*M_PI/180) +
(m->chamber_radius - d->R_Rt*m->throat_radius*(cos(d->theta*M_PI/180)-1)
- m->throat_radius)/tan(d->theta*M_PI/180);
*/
m->cylinder_volume = m->chamber_volume - m->convergent_volume;
m->cylinder_length = m->cylinder_volume / m->chamber_area;
m->chamber_length = m->cylinder_length + m->convergent_length;
m->walls_area = 2*m->chamber_length*sqrt(M_PI*m->Ac_At*m->throat_area)
+ pow(sin(d->theta), -1)*(m->Ac_At - 1)*m->throat_area;
return 0;
}
int LRD_print_propellant_info(liquid_propellant_t *p)
{
printf("Propellant\n");
printf("----------\n");
printf("Fuel : %s\n", PROPELLANT_NAME(p->fuel));
printf("Oxidant : %s\n", PROPELLANT_NAME(p->oxidant));
printf("O/F ratio : %.2f\n\n", p->o_f_ratio);
return 0;
}
int LRD_print_design_criteria(design_param_t *c)
{
printf("Design criteria\n");
printf("---------------\n");
printf("Chamber pressure (atm) (psi) : % 11.4f % 11.4f\n",
c->chamber_pressure, c->chamber_pressure * ATM_TO_PSI);
printf("Thrust (N) (lbf) : % 11.4e % 11.4e\n",
c->thrust, c->thrust * N_TO_LBF);
printf("L* (m) (in) : % 11.4f % 11.4f\n",
c->Lstar, c->Lstar * M_TO_IN);
printf("Chamber to throat diameter : % 11.4f\n",
c->Dc_Dt);
printf("R/Rt : % 11.4f\n",
c->R_Rt);
printf("Convergent half angle (deg) : % 11.4f\n", c->theta);
printf("\n");
return 0;
}
int LRD_print_design_information(motor_t *mf, motor_t *ms)
{
printf("\n");
printf(" "
"frozen | shifting\n");
printf("Mass flow rate (kg/s) (lb/s) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->mass_flow_rate, mf->mass_flow_rate * KG_S_TO_LB_S,
ms->mass_flow_rate, ms->mass_flow_rate * KG_S_TO_LB_S);
printf("Fuel flow rate (kg/s) (lb/s) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->fu_flow_rate, mf->fu_flow_rate * KG_S_TO_LB_S,
ms->fu_flow_rate, ms->fu_flow_rate * KG_S_TO_LB_S);
printf("Oxidant flow rate (kg/s) (lb/s) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->ox_flow_rate, mf->ox_flow_rate * KG_S_TO_LB_S,
ms->ox_flow_rate, ms->ox_flow_rate * KG_S_TO_LB_S);
printf("Throat area (m^2) (in^2) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->throat_area, mf->throat_area * M2_TO_IN2,
ms->throat_area, ms->throat_area * M2_TO_IN2);
printf("Throat diameter (m) (in) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->throat_diameter, mf->throat_diameter * M_TO_IN,
ms->throat_diameter, ms->throat_diameter * M_TO_IN);
printf("Exit area (m^2) (in^2) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->exit_area, mf->exit_area * M2_TO_IN2,
ms->exit_area, ms->exit_area * M2_TO_IN2);
printf("Exit diameter (m) (in) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->exit_diameter, mf->exit_diameter * M_TO_IN,
ms->exit_diameter, ms->exit_diameter * M_TO_IN);
printf("Chamber volume (m^3) (in^3) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->chamber_volume, mf->chamber_volume * M3_TO_IN3,
ms->chamber_volume, ms->chamber_volume * M3_TO_IN3);
printf("Chamber diameter (m) (in) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->chamber_diameter, mf->chamber_diameter * M_TO_IN,
ms->chamber_diameter, ms->chamber_diameter * M_TO_IN);
printf("Chamber length (m) (in) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->chamber_length, mf->chamber_length * M_TO_IN,
ms->chamber_length, ms->chamber_length * M_TO_IN);
printf("Convergent length (m) (in) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->convergent_length, mf->convergent_length * M_TO_IN,
ms->convergent_length, ms->convergent_length * M_TO_IN);
printf("Cylinder length (m) (in) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->cylinder_length, mf->cylinder_length * M_TO_IN,
ms->cylinder_length, ms->cylinder_length * M_TO_IN);
printf("Chamber walls area (m^2) (in^2) : %8.4e %8.4e | %8.4e %8.4e\n",
mf->walls_area, mf->walls_area * M2_TO_IN2,
ms->walls_area, ms->walls_area * M2_TO_IN2);
return 0;
}
@@ -0,0 +1,2 @@
LIBNAME = liblrd.a
LIBOBJS = lrd.o
@@ -0,0 +1,2 @@
ROOT = ../../..
include $(ROOT)/config/presrc.mk
@@ -0,0 +1,41 @@
#ifndef mcp_h
#define mcp_h
#include "libcpropep/include/type.h"
/* We assume a cylindrical motor */
typedef struct _motor_t
{
/* propellant burning information */
/* coefficient for burning rate equation
r = aP^n (r is in m/s and P in atm */
double a;
double n;
/* nozzle */
double throat_diameter;
double exit_diameter;
//double divergent_angle; /* deg */
//double grain_surface;
} motor_t;
typedef struct _data_
{
/* fixed parameters */
double a; /* burning coefficient */
double n; /* burning exponent */
double ta; /* throat area */
double ea; /* exit area */
equilibrium_t *e; /* pointer to the equilibrium structure */
/* changing parameters */
double (*Ab)(double s); /* Burning area */
double (*Vc)(double s); /* Chamber volume */
} data_t;
#endif
@@ -0,0 +1,3 @@
ROOT = ../../../..
include $(ROOT)/config/makedef
include $(ROOT)/config/libsrc.mk
@@ -0,0 +1,2 @@
LIBNAME = libmcp.a
LIBOBJS = mcp.o
@@ -0,0 +1,287 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "libthermo/include/load.h"
#include "libcpropep/include/print.h"
#include "libcpropep/include/type.h"
#include "libthermo/include/thermo.h"
#include "libcpropep/include/conversion.h"
#define THERMO_FILE "../cpropep/data/thermo.dat"
#define PROPELLANT_FILE "../cpropep/data/propellant.dat"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
/* We assume a cylindrical motor */
typedef struct _motor_t
{
/* propellant burning information */
/* coefficient for burning rate equation
r = aP^n (r is in m/s and P in atm */
double a;
double n;
/* nozzle */
double throat_diameter;
double exit_diameter;
double divergent_angle; /* deg */
double grain_surface;
} motor_t;
int load_input(FILE *fd, motor_t *motor, equilibrium_t *e)
{
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 (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, "Motor", 5) == 0)
{
section = 2;
}
else
{
printf ("Unknown option.\n");
}
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 (sp != 0)
{
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;
}
}
else
{
if (strcmp(bufptr, "a") == 0)
{
motor->a = m;
}
else if (strcmp(bufptr, "n") == 0)
{
motor->n = m;
}
else
{
printf("Unknown option.\n");
}
}
}
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, "throat_diameter") == 0)
{
m = atof(qt);
motor->throat_diameter = m;
}
else if (strcmp(bufptr, "exit_diameter") == 0)
{
m = atof(qt);
motor->exit_diameter = m;
}
else if (strcmp(bufptr, "propellant_surface") == 0)
{
m = atof(qt);
motor->grain_surface = m;
}
}
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;
FILE *fd;
double chamber_pressure;
motor_t motor;
equilibrium_t *frozen;
double throat_mass_flow_rate;
double burning_mass_flow_rate;
double throat_area;
double exit_area;
double Cd;
double burning_area;
errorfile = stderr;
outputfile = stdout;
if (load_thermo (THERMO_FILE) < 0 )
{
printf("Problem loading thermo file.\n");
return -1;
}
if (load_propellant (PROPELLANT_FILE) < 0)
{
printf("Problem loading propellant file.\n");
return -1;
}
frozen = (equilibrium_t *) malloc (sizeof(equilibrium_t)*3);
for (i = 0; i < 3; i++)
{
initialize_equilibrium(frozen + i);
}
fd = fopen("input.mot", "r");
load_input(fd, &motor, frozen);
fclose(fd);
compute_density(&(frozen->propellant));
if (frozen->propellant.density == 0.0)
{
printf("Density is 0.0, Aborted.\n");
return 0;
}
throat_area = M_PI * pow(motor.throat_diameter/2, 2);
exit_area = M_PI * pow(motor.exit_diameter/2, 2);
burning_area = motor.grain_surface;
/* initial estimate of the chamber pressure */
chamber_pressure = 60;
i = 0;
do
{
if (chamber_pressure > 500)
{
printf("Pressure increase over 500 atm. Aborted.\n");
return -1;
}
frozen->properties.P = chamber_pressure;
equilibrium(frozen, HP);
frozen_performance(frozen, SUPERSONIC_AREA_RATIO,
exit_area / throat_area);
throat_mass_flow_rate = throat_area * ATM_TO_PA /
(frozen + 1)->performance.a_dotm;
burning_mass_flow_rate = burning_area * (frozen->propellant.density * 1000)
* motor.a * pow(chamber_pressure, motor.n);
/* Evaluate Cd */
Cd = ATM_TO_PA / ((frozen + 1)->performance.a_dotm * chamber_pressure);
chamber_pressure = pow(
(throat_area * Cd /(burning_area * motor.a
* (frozen + 1)->propellant.density * 1000)),
1/(motor.n - 1));
i++;
} while (fabs(burning_mass_flow_rate - throat_mass_flow_rate) > 0.0004);
printf("Pressure evaluation assuming frozen equilibrium.\n\n");
print_propellant_composition(frozen);
printf("Properties of the propellant.\n");
printf("b = aP^n\n\n");
printf("a = %.4f\n", motor.a);
printf("n = %.4f\n\n", motor.n);
print_product_properties(frozen, 3);
print_product_composition(frozen, 3);
print_performance_information(frozen, 3);
printf("\n");
printf("Chamber pressure converge in %d iterations.\n", i);
printf("Pressure (atm) : % .4f\n", chamber_pressure);
printf("Throat dot m (kg/s) : % .4f\n", throat_mass_flow_rate);
printf("Thrust (N) : % .4f\n", throat_mass_flow_rate *
(frozen + 2)->performance.Isp);
printf("\nKn : % .4f\n", burning_area/throat_area);
return 0;
}
@@ -0,0 +1,2 @@
ROOT = ../../..
include $(ROOT)/config/presrc.mk
@@ -0,0 +1,43 @@
CC = bcc32
CPP32 = cpp32
LIBRARIAN = tlib
LINKER = ilink32
RC = brc32
COPT = -3 -O2 -w-8012 -w-8004 -w-8057 -IC:\borland\bcc55\include
OBJS = lu.obj rk4.obj general.obj print.obj sec.obj
TLIBNUM = +lu.obj +rk4.obj +general.obj +print.obj +sec.obj
LDOPT = -LC:\borland\bcc55\lib
PROG = test.exe
PROGOBJS = test.obj
LIBNUM = libnum.lib
.SUFFIXES: .c
all: $(LIBNUM) $(PROG)
.c.obj:
$(CC) $(DEF) $(COPT) -c $*.c -o $*.obj
$(LIBNUM): $(OBJS)
tlib $@ $(TLIBNUM)
$(PROG): $(PROGOBJS)
$(CC) $(LDOPT) $(LIBNUM) $(PROGOBJS)
clean:
del *.obj
del *.bak
del *.tds
deep-clean: clean
del $(LIBNUM)
del $(PROG)
@@ -0,0 +1,149 @@
/* num.h - Library of numerical method
* $Id: num.h,v 1.1.1.1 2001/07/20 03:19:08 antoine Exp $
* Copyright (C) 2000
* Antoine Lefebvre <antoine.lefebvre@polymtl.ca>
*
* Licensed under the GPL
*/
#ifndef num_h
#define num_h
/* NOTE on matrix representation
* -----------------------------
* All matrix should be allocate the following way
*
* matrix = (double *) malloc (sizeof(double) * line * column)
*
* to access the value at line 2, column 4, you do it like that
*
* matrix[2 + 4*line]
*/
/* This type is used as function pointer for the
* sysnewton algorithm.
*/
typedef double (*func_t)(double *x);
typedef struct status
{
int itn;
} status_t;
#define NO_CONVERGENCE 1
#define NO_SOLUTION 2
/* Find the solution of linear system of equation using the
* LU factorisation method as explain in
* 'Advanced engineering mathematics' bye Erwin Kreyszig.
*
* This algorithm will also do column permutation to find
* the larger pivot.
*
* ARGUMENTS
* ---------
* matrix: the augmented matrix of coefficient in the system
* with right hand side value.
*
* solution: the solution vector
*
* neq: number of equation in the system
*
* Antoine Lefebvre
* february 6, 2000 Initial version
* october 20, 2000 revision of the permutation method
*/
int NUM_lu(double *matrix, double *solution, int neq);
/*int old_lu(double *matrix, double *solution, int neq);*/
/* This function print the coefficient of the matrix to
* the screen.
*
* matrix: should be an augmented matrix
* neq : number of equation
*/
int NUM_print_matrix(double *matrix, int neq);
/* Print the coefficient of the square matrix to the screen
*/
int NUM_print_square_matrix(double *matrix, int neq);
/* This function print the contents of the vector to
* the screen.
*
* vec: vector containing neq element
*/
int NUM_print_vec(double *vec, int neq);
/**************************************************************
FUNCTION: This function solve systems of ODE of the first order
with the Runge-Kutta method of the fourth order.
PARAMETER: The first parameter is a pointer to the function we
we want to solve. This function take five parameter
neq is the number of equations in the system
time is the time at which we want to evaluate
y is an array containing an initial value
dy will store the result of the function
ierr any error field
step is the time variation
duration is the total time of the simulation
ic are the initial conditions
**y is an array containing all the data
void * is nay user data
COMMENTS: **y must be properly allocated, [number of points]X[neq]
It could be interesting to add a tolerance and use
variable step to reach our tolerance instead of using a
fixed step.
AUTHOR: Antoine Lefebvre
DATE: February 11
*****************************************************************/
int NUM_rk4(int (*f)(int neq, double time, double *y, double *dy, void *data),
int neq, double step, double duration, float *ic,
double **y, void *data );
int NUM_rkf(int (*f)(int neq, double time, double *y, double *dy, void *data),
int neq, double step, double duration, float *ic,
double **y, double epsil, void *data);
/* this function return the nearest integer to a */
/* it is a replacement of rint which is not ANSI complient */
int Round(double a);
double epsilon(void);
int NUM_sec(double (*f)(double x), double x0, double x1, int nmax,
double epsilon, double *ans);
int NUM_newton(double (*f)(double x), double (*df)(double x), double x0,
int nmax, double epsilon, double *ans);
int NUM_ptfix(double (*f)(double x), double x0,
double nmax, double epsilon, double *ans);
int NUM_sysnewton(func_t *Jac, func_t *R, double *x, int nvar,
int nmax, double eps);
int trapeze(double *data, int n_point, int col, int off, double *integral);
int simpson(double *data, int n_point, int col, int off, double *integral);
int create_spline(double *data, int n_point, double *spline);
#endif
@@ -0,0 +1,3 @@
ROOT = ../../../..
include $(ROOT)/config/makedef
include $(ROOT)/config/libsrc.mk
@@ -0,0 +1,42 @@
ROOT = ../../../..
include $(ROOT)/config/makedef
LIB = -lnum -lm
LIBDIR = -L$(ROOT)/lib/
INCDIR = -I$(ROOT)/source/libraries/libnum/include/
DEF = -DLINUX
PROG = test
OBJS = test.o
LIBOBJS = lu.o rk4.o rkf.o general.o print.o sec.o newton.o ptfix.o\
sysnewton.o trapeze.o simpson.o spline.o
LIBNUM = libnum.a
all: $(LIBNUM) $(PROG)
.c.o:
@echo $<
$(CC) $(DEF) $(INCDIR) $(COPT) -c $< -o $@
$(LIBNUM): $(LIBOBJS)
ar -r $@ $(LIBOBJS)
ranlib $@
mv $(LIBNUM) $(ROOT)/lib/
$(PROG): $(LIBNUM) $(OBJS)
$(CC) $(COPT) $(OBJS) $(LIBDIR) $(LIB) -o $@
clean:
@rm -f $(PROG) *.o *~
deep-clean: clean
rm -f $(ROOT)/lib/$(LIBNUM)
@@ -0,0 +1,32 @@
#include "libnum/include/num.h"
int Round(double a)
{
int t = a;
if (a - (double)t < 0.5)
return t;
else if (a - (double)t > 0.5)
return t + 1;
else
return (t + (t % 2));
}
double epsilon(void)
{
double epsilon;
double temp;
epsilon = 1.0;
temp = epsilon + 1.0;
while (temp > 1.0)
{
epsilon = epsilon / 2.0;
temp = epsilon + 1.0;
}
return (epsilon * 2.0);
}
@@ -0,0 +1,172 @@
/* lu.c - PA = LU factorisation with pivoting
* $Id: lu.c,v 1.1.1.1 2001/07/20 03:19:08 antoine Exp $
* Copyright (C) 2000
* Antoine Lefebvre <antoine.lefebvre@polymtl.ca>
*
*
* Licensed under the GPLv2
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "libnum/include/num.h"
/*
This algorithm will compute an LU factorisation on the augmented
matrix (A) passed in arguments.
This algorithm assumed the element on the diagonal of the lower
triangular matrix set to 1.
In order to save memory space, every coefficient of both matrix
L and U are written in the original matrix overwriting initial
values of A.
*/
int NUM_lu(double *matrix, double *solution, int neq)
{
int i, j, k;
int idx; /* index of the larger pivot */
double big; /* the larger pivot found */
double tmp = 0.0;
int *P; /* keep memory of permutation (column permutation) */
double *y;
P = (int *) calloc (neq, sizeof(int));
y = (double *) calloc (neq, sizeof(double));
for (i = 0; i < neq; i++)
{
solution[i] = 0; /* reset the solution vector */
P[i] = i; /* initialize permutation vector */
}
/* LU Factorisation */
for (i = 0; i < neq - 1; i++) /* line */
{
for (j = i; j < neq; j++) /* column */
{
tmp = 0.0;
for (k = 0; k < i; k++)
tmp += matrix[i + neq*P[k]] * matrix[k + neq*P[j]];
matrix[i + neq*P[j]] = matrix[i + neq*P[j]] - tmp;
}
/* find the larger pivot and interchange the columns */
big = 0.0;
idx = i;
for (j = i; j < neq; j++)
{
if (big < fabs(matrix[i + neq*P[j]])) /* we found a larger pivot */
{
idx = j;
big = fabs(matrix[i + neq*P[j]]);
}
}
/* check if we have to interchange the lines */
if (idx != i)
{
tmp = P[i];
P[i] = P[idx];
P[idx] = tmp;
}
if (matrix[i + neq*P[i]] == 0.0)
{
printf("LU: matrix is singular, no unique solution.\n");
return NO_SOLUTION;
}
for (j = i+1; j < neq; j++)
{
tmp = 0.0;
for (k = 0; k < i; k++)
tmp += matrix[j + neq*P[k]] * matrix[k + neq*P[i]];
matrix[j + neq*P[i]] = (matrix[j + neq*P[i]] - tmp)/matrix[i + neq*P[i]];
}
}
i = neq - 1;
tmp = 0.0;
for (k = 0; k < neq-1; k++)
tmp += matrix[i + neq*P[k]] * matrix[k + neq*P[i]];
matrix[i + neq*P[i]] = matrix[i + neq*P[i]] - tmp;
/* End LU-Factorisation */
/* substitution for y Ly = b*/
for (i = 0; i < neq; i++)
{
tmp = 0.0;
for (j = 0; j < i; j++)
tmp += matrix[i + neq*P[j]] * y[j];
y[i] = matrix[i + neq*neq] - tmp;
}
/* substitution for x Ux = y*/
for (i = neq - 1; i >=0; i--)
{
if (matrix[i + neq*P[i]] == 0.0)
{
printf("LU: No unique solution exist.\n");
return NO_SOLUTION;
}
tmp = 0.0;
for (j = i; j < neq; j++)
tmp += matrix[i + neq*P[j]] * solution[P[j]];
solution[P[i]] = (y[i] - tmp)/matrix[i + neq*P[i]];
}
free (y);
return 0;
}
/* This function will divide each row of the matrix
* by the highest element of this row.
* This kind of scaling could improve precision while
* solving some difficult matrix.
*/
int NUM_matscale(double *matrix, int neq)
{
int i; /* line */
int j; /* column */
double val;
double tmp;
for (i = 0; i < neq; i++)
{
val = 0;
/* find the highest value */
for (j = 0; j < neq; j++)
{
tmp = abs(matrix[i + neq*j]);
val = (tmp > val) ? tmp : val;
}
/* divide element of the line by this value
* including the right side
* if the max value is defferent than zero
*/
if (val != 0.0)
{
for (j = 0; j < neq+1; j++)
matrix[i + neq*j] = matrix[i + neq*j]/val;
}
}
return 0;
}
@@ -0,0 +1,3 @@
LIBNAME = libnum.a
LIBOBJS = lu.o rk4.o rkf.o general.o print.o sec.o newton.o ptfix.o\
sysnewton.o trapeze.o simpson.o spline.o
@@ -0,0 +1,31 @@
#include <math.h>
#include <stdio.h>
#include "libnum/include/num.h"
int NUM_newton(double (*f)(double x), double (*df)(double x), double x0,
int nmax, double eps, double *ans)
{
int i = 0;
double x1;
double delta;
do
{
if (i >= nmax)
{
return NO_CONVERGENCE;
}
x1 = x0 - f(x0)/df(x0);
delta = fabs(x1 - x0)/fabs(x1);
x0 = x1;
i++;
} while (delta > eps);
*ans = x1;
return 0;
}
@@ -0,0 +1,54 @@
/* print.c
* $Id: print.c,v 1.1.1.1 2001/07/20 03:19:08 antoine Exp $
* Copyright (C) 2000
* Antoine Lefebvre <antoine.lefebvre@polymtl.ca>
*
* Licensed under the GPL
*/
#include <stdio.h>
#include "libnum/include/num.h"
int NUM_print_square_matrix(double *matrix, int neq)
{
int i = 0;
int j = 0;
for (i = 0; i < neq; i++)
{
for (j = 0; j < neq; j++)
printf("% .5f ", matrix[i + neq*j]);
printf("\n");
}
printf("\n");
return 0;
}
int NUM_print_matrix(double *matrix, int neq)
{
int i = 0;
int j = 0;
for (i = 0; i < neq; i++)
{
for (j = 0; j <= neq; j++)
printf("% .5e ", matrix[i + neq*j]);
printf("\n");
}
printf("\n");
return 0;
}
int NUM_print_vec(double *vec, int neq)
{
int i;
for (i = 0; i < neq; i++)
printf("% .5e ", vec[i]);
printf("\n");
return 0;
}
@@ -0,0 +1,31 @@
#include <math.h>
#include <stdio.h>
#include "libnum/include/num.h"
int NUM_ptfix(double (*f)(double x), double x0, double nmax,
double epsilon, double *ans)
{
int i = 0;
double x1;
double delta;
do
{
if (i >= nmax)
{
return NO_CONVERGENCE;
}
x1 = f(x0);
delta = fabs(x1 - x0)/fabs(x1);
x0 = x1;
i++;
} while (delta > epsilon);
*ans = x1;
return 0;
}
@@ -0,0 +1,107 @@
#include <stdlib.h>
#include <math.h>
#include "libnum/include/num.h"
int NUM_rk4(int (*f)(int neq, double time, double *y, double *dy, void *data),
int neq, double step, double duration, float *ic,
double **y, void *data)
{
int i;
int n;
int status;
int length;
double t = 0.0;
double *tmp;
double *dy;
double *K1, *K2, *K3, *K4;
double *a;
tmp = (double *) malloc(sizeof(double) * neq);
dy = (double *) malloc(sizeof(double) * neq);
K1 = (double *) malloc(sizeof(double) * neq);
K2 = (double *) malloc(sizeof(double) * neq);
K3 = (double *) malloc(sizeof(double) * neq);
K4 = (double *) malloc(sizeof(double) * neq);
/* allocation of the answer vector */
length = (int)ceil(duration/step) + 1;
a = *y = (double *) malloc(sizeof(double) * neq * length);
for (i = 0; i < neq; i++)
{
tmp[i] = a[i + neq*0] = (double) ic[i]; /* initials conditions */
}
for (n = 0; n < Round(duration/step); n++)
{
for (i = 0; i < neq; i++)
{
status = f(neq, t, tmp, dy, data);
if (status)
return status;
K1[i] = step * dy[i];
tmp[i] = a[i + neq*n] + K1[i]/2; /* for the next step */
}
/* FIXME: verify the coefficient t + step/2 */
for (i = 0; i < neq; i++)
{
status = f(neq, t + step/2, tmp, dy, data);
if (status)
return -1;
K2[i] = step * dy[i];
tmp[i] = a[i + neq*n] + K2[i]/2;
}
for (i = 0; i < neq; i++)
{
status = f(neq, t + step/2, tmp, dy, data);
if (status)
return status;
K3[i] = step * dy[i];
tmp[i] = a[i + neq*n] + K3[i];
}
for (i = 0; i < neq; i++)
{
status = f(neq, t + step, tmp, dy, data);
if (status)
return -1;
K4[i] = step * dy[i];
}
for (i = 0; i < neq; i++)
a[i + neq*(n+1)] = a[i + neq*n] +
(1.0/6.0)*(K1[i] + 2.0*K2[i] + 2.0*K3[i] + K4[i]);
t = t + step;
}
free(tmp);
free(dy);
free(K1);
free(K2);
free(K3);
free(K4);
return length;
}
@@ -0,0 +1,179 @@
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include "libnum/include/num.h"
/* neq: number of equations
* step: initial time step
* duration: total duration of the simulation
* ic: initial conditions vector
* y: solution vector
* epsil: precision on the data
* data: pointer to data structure
*/
/* Runge-Kutta-Fehlberg 4-5 order */
int NUM_rkf(int (*f)(int neq, double time, double *y, double *dy, void *data),
int neq, double step, double duration, float *ic,
double **y, double epsil, void *data)
{
int i, n;
int col;
int status;
double h;
double t = 0.0;
double *a;
double *tmp;
double *dy;
double *K1, *K2, *K3, *K4, *K5, *K6;
double *E; /* Error vector of the error */
double err; /* maximum error */
double beta;
tmp = (double *) malloc(sizeof(double) * neq);
dy = (double *) malloc(sizeof(double) * neq);
E = (double *) malloc(sizeof(double) * neq);
K1 = (double *) malloc(sizeof(double) * neq);
K2 = (double *) malloc(sizeof(double) * neq);
K3 = (double *) malloc(sizeof(double) * neq);
K4 = (double *) malloc(sizeof(double) * neq);
K5 = (double *) malloc(sizeof(double) * neq);
K6 = (double *) malloc(sizeof(double) * neq);
h = step;
n = 0;
col = neq + 1;
a = *y = (double *) malloc(sizeof(double) * col * (n + 1));
for (i = 0; i < neq; i++)
{
tmp[i] = a[i + col*0] = (double) ic[i]; /* initial conditions */
}
a[neq] = t;
while (t < duration)
{
a = *y = (double *) realloc(*y, sizeof(double) * col * (n + 2));
for (i = 0; i < neq; i++)
{
status = f(neq, t, tmp, dy, data);
K1[i] = h * dy[i];
tmp[i] = a[i + col*n] + K1[i]/4.0; /* for the next step */
}
for (i = 0; i < neq; i++)
{
status = f(neq, t + h/4.0, tmp, dy, data);
K2[i] = h * dy[i];
tmp[i] = a[i + col*n] + 3.0*K1[i]/32.0 + 9.0*K2[i]/32.0;
}
for (i = 0; i < neq; i++)
{
status = f(neq, t + 3.0*h/8.0, tmp, dy, data);
K3[i] = h * dy[i];
tmp[i] = a[i + col*n] + 1932.0*K1[i]/2197.0 - 7200.0*K2[i]/2197.0 +
7296.0*K3[i]/2197.0;
}
for (i = 0; i < neq; i++)
{
status = f(neq, t + 12.0*h/13.0, tmp, dy, data);
K4[i] = h * dy[i];
tmp[i] = a[i + col*n] + 439.0*K1[i]/216.0 - 8.0*K2[i] +
3680.0*K3[i]/513.0 - 845.0*K4[i]/4104.0;
}
for (i = 0; i < neq; i++)
{
status = f(neq, t + h, tmp, dy, data);
K5[i] = h * dy[i];
tmp[i] = a[i + col*n] - 8.0*K1[i]/27.0 + 2.0*K2[i] -
3544.0*K3[i]/2565.0 + 1859.0*K4[i]/4104.0 - 11.0*K5[i]/40.0;
}
for (i = 0; i < neq; i++)
{
status = f(neq, t + h/2.0, tmp, dy, data);
K6[i] = h * dy[i];
}
err = 0.0;
for (i = 0; i < neq; i++)
{
E[i] = fabs(K1[i]/360.0 - 128.0*K3[i]/4275.0 - 2197.0*K4[i]/75240.0 +
K5[i]/50.0 + 2.0*K6[i]/55.0); /* /h ?? */
/*printf("E[%d] = %f\n", i, E[i]);*/
err = ((E[i] > err) ? E[i] : err);
}
/*printf("err = %e\n", err);*/
if ((err < epsil) || (h <= step/1000) )
{
t += h;
for (i = 0; i < neq; i++)
{
a[i + col*(n+1)] = a[i + col*n] + 25.0*K1[i]/216.0 +
1408.0*K3[i]/2565.0 + 2197.0*K4[i]/4104.0 - 0.2*K5[i];
}
/* store the time */
a[neq + col*(n+1)] = t;
n++;
}
beta = pow(epsil/(2*err), 0.25);
if (beta < 0.1)
{
h = 0.1* h;
}
else if (beta > 4)
{
h = 4.0*h;
}
else
{
h = beta * h;
}
/* we have to prevent too little h*/
if (h < step/1000)
h = step/1000;
/* prevent too big */
if (h > duration/16)
h = duration/16;
if (t + h > duration)
{
h = duration - t;
}
}
return n+1;
}
@@ -0,0 +1,33 @@
#include <math.h>
#include <stdio.h>
#include "libnum/include/num.h"
/* Resolution of non-linear equation of the for
f(x) = 0 with the secante method which is a modified
newton method using secante instead of derivative */
int NUM_sec(double (*f)(double x), double x0, double x1, int nmax,
double epsilon, double *ans)
{
int i = 0;
double x2;
double delta;
do
{
if (i >= nmax)
{
return NO_CONVERGENCE;
}
x2 = x1 - f(x1)*(x1 - x0)/(f(x1) - f(x0));
delta = fabs(x2 - x1)/fabs(x2);
x0 = x1;
x1 = x2;
i++;
} while (delta > epsilon);
*ans = x2;
return 0;
}
@@ -0,0 +1,49 @@
#include <math.h>
int simpson(double *data, int n_point, int col, int off, double *integral)
{
int i;
double val = 0;
double x0, x1, x2, fx0, fx1, fx2;
double dd_x0x1;
double dd_x1x2;
double dd_x0x1x2;
int beg = 0;
if ((n_point%2) != 1)
{
beg = 1;
x0 = data[0 + 0*col];
x1 = data[0 + 1*col];
fx0 = data[off + 0*col];
fx1 = data[off + 1*col];
val += (fx0+fx1)*(x1-x0)/2;
}
for (i = beg; i < n_point - 2; i += 2)
{
x0 = data[0 + (i+0)*col];
x1 = data[0 + (i+1)*col];
x2 = data[0 + (i+2)*col];
fx0 = data[off + (i+0)*col];
fx1 = data[off + (i+1)*col];
fx2 = data[off + (i+2)*col];
dd_x0x1 = (fx1 - fx0)/(x1 - x0);
dd_x1x2 = (fx2 - fx1)/(x2 - x1);
dd_x0x1x2 = (dd_x1x2 - dd_x0x1)/(x2 - x0);
val += (fx0 - dd_x0x1*x0 + dd_x0x1x2*x0*x1)*(x2 - x0) +
(dd_x0x1 - dd_x0x1x2*(x0+x1))*(pow(x2, 2)-pow(x0, 2))/2 +
dd_x0x1x2*(pow(x2, 3) - pow(x0,3))/3;
}
*integral = val;
return 0;
}
@@ -0,0 +1,108 @@
/* spline.c - Cubic spline interpolation
* $Id: spline.c,v 1.1.1.1 2001/07/20 03:19:09 antoine Exp $
* Copyright (C) 2000
* Antoine Lefebvre <antoine.lefebvre@polymtl.ca>
*
*
* Licensed under the GPLv2
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "libnum/include/num.h"
#define OUT_OF_RANGE -1
/* Computation of natural spline.
*/
int create_spline(double *data, int n_point, double *spline)
{
int i;
int col;
double hi0, hi1, hi2;
double fi0, fi1, fi2;
double *matrix;
col = 2;
matrix = (double *) calloc (n_point*(n_point+1), sizeof(double));
/* create the linear system */
matrix[0 + 0] = 1;
for (i = 1; i < n_point - 1; i++)
{
hi0 = data[0 + (i+0)*col] - data[0 + (i-1)*col];
hi1 = data[0 + (i+1)*col] - data[0 + (i-0)*col];
hi2 = data[0 + (i+1)*col] - data[0 + (i-1)*col];
fi0 = data[1 + (i-1)*col]; /* f(x_(i-1)) */
fi1 = data[1 + (i-0)*col]; /* f(x_i) */
fi2 = data[1 + (i+1)*col]; /* f(x_(i+1)) */
matrix[i + (i-1)*n_point] = hi0/(hi0+hi1);
matrix[i + (i-0)*n_point] = 2;
matrix[i + (i+1)*n_point] = hi1/(hi0+hi1);
matrix[i + n_point*n_point] = 6*( (fi2-fi1)/hi1 - (fi1-fi0)/hi0)/hi2;
}
matrix[n_point - 1 + (n_point - 1)*n_point] = 1;
NUM_print_matrix(matrix, n_point);
NUM_lu(matrix, spline, n_point);
NUM_print_vec(spline, n_point);
free(matrix);
return 0;
}
int eval_spline(double *data, double *spline, int n_point, double x, double *y)
{
int i;
int col = 2;
double hi0;
double xi0;
double xi1;
double fi0;
double fi1;
double d2f0;
double d2f1;
/* we must find the interval in which x is located */
i = 0;
if ((x < data[0]) || (x > data[0 + (n_point - 1)*col]))
{
printf("Out of range: %f\n", x);
return OUT_OF_RANGE;
}
for (i = 0; x > data[0 + i*col]; i++);
xi0 = data[0 + (i-1)*col];
xi1 = data[0 + i*col];
hi0 = xi1 - xi0;
fi0 = data[1 + (i-1)*col];
fi1 = data[1 + i*col];
d2f0 = spline[i-1];
d2f1 = spline[i];
/* evaluation of the spline at the specified point */
*y = -d2f0*pow(x-xi1, 3)/(6*hi0) + d2f1*pow(x-xi0, 3)/(6*hi0)
-(fi0/hi0 - hi0*d2f0/6)*(x-xi1) + (fi1/hi0 - hi0*d2f1/6)*(x-xi0);
return 0;
}
@@ -0,0 +1,86 @@
/* sysnewton.c - Solve system of non-linear equations with newton's method
* $Id: sysnewton.c,v 1.1.1.1 2001/07/20 03:19:09 antoine Exp $
* Copyright (C) 2000
* Antoine Lefebvre <antoine.lefebvre@polymtl.ca>
*
* Licensed under the GPL
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "libnum/include/num.h"
double norme(double *x, int n);
/* Jac : Pointer to a matrix of pointer to function (Jacobian matrix)
* R : Pointer to a vector of pointer to function (Residue vector)
* x : Initial estimate of the solution (will be overwrite by the answer)
* nvar: Number of variable in the system
* nmax: Maximal number of iterations
* eps : Precision on the answer
*/
int NUM_sysnewton(func_t *Jac, func_t *R, double *x, int nvar,
int nmax, double eps)
{
int i, j, l;
double *r;
double *dx; /* solution of the system */
double *matrix; /* the matrix to be solve */
/* Allow space for the left hand side */
matrix = (double *) malloc (sizeof(double) * nvar * (nvar + 1));
r = (double *) malloc (sizeof(double) * nvar);
dx = (double *) malloc(sizeof(double) * nvar);
l = 0;
do
{
/* set up the matrix */
for (i = 0; i < nvar; i++) /* line */
{
for (j = 0; j < nvar; j++) /* column */
{
matrix[i + nvar*j] = Jac[i + nvar*j](x);
}
r[i] = matrix[i + nvar*nvar] = -R[i](x);
}
/* if the matrix is singular */
if (NUM_lu(matrix, dx, nvar))
return NO_CONVERGENCE;
for (i = 0; i < nvar; i++)
{
x[i] = x[i] + dx[i];
}
if ((norme(dx, nvar)/norme(x, nvar) < eps) &&
(norme(r, nvar) <= eps))
{
/* the solution converged */
return 0;
}
l++;
} while (l < nmax);
return NO_CONVERGENCE;
}
double norme(double *x, int n)
{
int i;
double a = 0.0;
for (i = 0; i < n; i++)
{
a += pow(x[i], 2);
}
return sqrt(a);
}
@@ -0,0 +1,344 @@
/* test.c - Testing the functionnality of the various method
* $Id: test.c,v 1.1.1.1 2001/07/20 03:19:09 antoine Exp $
* Copyright (C) 2000
* Antoine Lefebvre <antoine.lefebvre@polymtl.ca>
*
* Licensed under the GPL
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//#include <time.h>
#include "num.h"
FILE * errorfile;
FILE * outputfile;
int test_rk4(void);
int test_lu(void);
int test_sysnewton(void);
int test_sec(void);
int test_newton(void);
int test_ptfix(void);
int test_spline(void);
/* g1(x) = x + 1 - ln(x) */
double g1(double x) {
return x + 1 - log(x);
}
/* f1(x) = ln(x) - 1 */
double f1(double x) {
return log(x) - 1;
}
/* f1'(x) = 1/x */
double df1(double x) {
return 1/x;
}
double dg1(double x) {
return 1 - 1/x;
}
/* f(x) = (x-1)^3 */
double f(double x) {
return pow(x-1, 3);
}
int function(int neq, double time, double *y, double *dy,
void *data)
{
dy[0] = y[1];
dy[1] = -9.8;
dy[2] = y[3];
dy[3] = 0;
return 0;
}
/* functions to test the sysnewton algorythm
*
* The system to be solve is the following
* r1(x1, x2) = e^x1 - x2 = 0
* r2(x1, x2) = x1^2 + x2^2 - 16 = 0
*
*/
double r1(double *x)
{
return exp(x[0]) - x[1];
}
double r2(double *x)
{
return pow(x[0], 2) + pow(x[1], 2) - 16;
}
/* We need partial derivative of these function with each variable
* dr1_dx1(x1, x2) = e^x1
* dr1_dx2(x1, x2) = -1
* dr2_dx1(x1, x2) = 2*x1
* dr2_dx2(x1, x2) = 2*x2
*/
double dr1_dx1(double *x)
{
return exp(x[0]);
}
double dr1_dx2(double *x)
{
return -1;
}
double dr2_dx1(double *x)
{
return 2*x[0];
}
double dr2_dx2(double *x)
{
return 2*x[1];
}
int main(void)
{
test_lu();
test_spline();
test_rk4();
test_sysnewton();
test_sec();
test_newton();
test_ptfix();
return 0;
}
int test_sec(void)
{
double ans;
printf("Testing Secante method\n");
if (NUM_sec(f1, 1, 2, 100, 0.0001, &ans))
printf("No solution: error in the method.\n\n");
else
printf("Solution: %f\n\n", ans);
return 0;
}
int test_newton(void)
{
double ans;
printf("Testing Newton method\n");
if (NUM_newton(f1, df1, 1, 100, 0.0001, &ans))
printf("No solution: error in the method.\n\n");
else
printf("Solution: %f\n\n", ans);
return 0;
}
int test_ptfix(void)
{
double ans;
printf("Testing fixed point method\n");
if (NUM_ptfix(g1, 1, 100, 0.0001, &ans))
printf("No solution: error in the method.\n");
else
printf("Solution: %f\n\n", ans);
return 0;
}
int test_sysnewton(void)
{
func_t *jac;
func_t *r;
int nvar = 2;
double x[2]; /* solution vector, contain initially the initial conditions */
printf("Testing newton method for solving"
" non-linear system of equations.\n");
jac = (func_t *) malloc (sizeof(func_t) * nvar * nvar);
r = (func_t *) malloc (sizeof(func_t) * nvar);
/* Initialize the functions pointers array */
r[0] = r1;
r[1] = r2;
jac[0] = dr1_dx1;
jac[1] = dr2_dx1;
jac[2] = dr1_dx2;
jac[3] = dr2_dx2;
/* set the initial estimate */
x[0] = 2.8;
x[1] = 2.8;
/* call the sysnewton function */
NUM_sysnewton(jac, r, x, 2, 100, 1e-8);
/* print the solution */
printf("Solution: x1 = %f, x2 = %f\n", x[0], x[1]);
printf("\n");
return 0;
}
int test_lu(void)
{
int i;
double *matrix;
double *solution;
int size = 8;
printf("Testing the LU factorisation algotythm.\n");
matrix = (double *) malloc (sizeof(double)*size*(size+1));
solution = (double *) malloc (sizeof(double)*size);
matrix[0] = 4.77088e-02; matrix[8] = 1.17204e-01; matrix[16] = 1.88670e-02;
matrix[1] = 1.17204e-01; matrix[9] = 4.07815e-01; matrix[17] = 1.25752e-02;
matrix[2] = 1.88670e-02; matrix[10] = 1.25752e-02; matrix[18] = 4.40215e-02;
matrix[3] = 0.00000e+00; matrix[11] = 0.00000e+00; matrix[19] = 0.00000e+00;
matrix[4] = 0.00000e+00; matrix[12] = 0.00000e+00; matrix[20] = 0.00000e+00;
matrix[5] = 1.00000e+00; matrix[13] = 0.00000e+00; matrix[21] = 3.00000e+00;
matrix[6] = 2.97603e-02; matrix[14] = 8.67031e-02; matrix[22] = 2.51546e-02;
matrix[7] = 5.15962e+01; matrix[15] = 1.67940e+02; matrix[23] = -7.46975e+01;
matrix[24] = 0.00000e+00;
matrix[25] = 0.00000e+00;
matrix[26] = 0.00000e+00;
matrix[27] = 1.28681e-02;
matrix[28] = 0.00000e+00;
matrix[29] = 0.00000e+00;
matrix[30] = 6.43406e-03;
matrix[31] = -7.23674e-01;
matrix[32] = 0.0000e+00; matrix[40] = 1.00000e+00; matrix[48] = 2.97603e-02;
matrix[33] = 0.0000e+00; matrix[41] = 0.00000e+00; matrix[49] = 8.67031e-02;
matrix[34] = 0.0000e+00; matrix[42] = 3.00000e+00; matrix[50] = 2.51546e-02;
matrix[35] = 0.0000e+00; matrix[43] = 0.00000e+00; matrix[51] = 6.43406e-03;
matrix[36] = 0.0000e+00; matrix[44] = 2.00000e+00; matrix[52] = 0.00000e+00;
matrix[37] = 2.0000e+00; matrix[45] = 0.00000e+00; matrix[53] = 0.00000e+00;
matrix[38] = 0.0000e+00; matrix[46] = 0.00000e+00; matrix[54] = 1.45616e-02;
matrix[39] = 0.0000e+00; matrix[47] =-9.68727e+03; matrix[55] =-3.06747e+01;
matrix[56] = 5.15962e+01; matrix[64] =-1.12677e+01;
matrix[57] = 1.67940e+02; matrix[65] = 8.29437e+00;
matrix[58] =-7.46975e+01; matrix[66] =-7.39145e+01;
matrix[59] =-7.23674e-01; matrix[67] =-5.99249e-01;
matrix[60] = 0.00000e+00; matrix[68] = 1.58804e-02;
matrix[61] =-9.68727e+03; matrix[69] =-9.62706e+03;
matrix[62] =-3.06747e+01; matrix[70] =-4.63904e+01;
matrix[63] = 4.68590e+05; matrix[71] = 2.37298e+05;
//NUM_matscale(matrix, size);
NUM_print_matrix(matrix, size);
if (NUM_lu(matrix, solution, size))
printf("No solution: Error in the numerical method,\n");
else
NUM_print_vec(solution, size);
/*
for (i = 0; i < size; i++)
{
if (solution[i] != 1.0)
{
printf("Error found in the solution.\n");
}
}
*/
printf("\n");
return 0;
}
int test_rk4(void)
{
int i, n;
double *ans;
double *ic;
printf("\nTesting the RK4 and RKF algorythm.\n");
ic = (double *) malloc(sizeof(double) * 4);
ic[0] = 0;
ic[1] = 100;
ic[2] = 0;
ic[3] = 10;
/* it return the length of the answer vector */
//n = NUM_rk4 (function, 4, 0.1, 10, ic, &ans, NULL);
//for (i = 0; i < n; i++)
//{
// printf("%f %f %f %f \n", ans[4*i], ans[1 + 4*i], ans[2+4*i], ans[3+4*i]);
//}
n = NUM_rkf (function, 4, 0.1, 20, ic, &ans, 1e-4, NULL);
printf("n = %i\n", n);
for( i = 0; i < n; i++)
{
printf("%f %f %f %f %f\n", ans[4 + 5*i], ans[5*i],
ans[1+5*i], ans[2 + 5*i], ans[3 + 5*i]);
}
free(ic);
free(ans);
return 0;
}
int test_spline(void)
{
int i;
double *data;
double *spline;
int size = 10;
double ans;
printf("Testing the spline function.\n\n");
data = malloc (2 * size * sizeof(double));
spline = malloc (size * sizeof(double));
data[0] = 0; /* x0 */
data[1] = 55; /* y0 */
data[2] = 5; /* x1 */
data[3] = 60; /* y1 */
data[4] = 10; /* ... */
data[5] = 58;
data[6] = 15;
data[7] = 54;
data[8] = 20;
data[9] = 55;
data[10] = 25;
data[11] = 60;
data[12] = 30;
data[13] = 54;
data[14] = 35;
data[15] = 57;
data[16] = 40;
data[17] = 52;
data[18] = 45;
data[19] = 49;
create_spline(data, size, spline);
for (i = 0; i < 45; i++)
{
eval_spline(data, spline, size, (double)i, &ans);
printf("%d %f\n", i, ans);
}
printf("Spline test finish\n");
return 0;
}
@@ -0,0 +1,16 @@
int trapeze(double *data, int n_point, int col, int off, double *integral)
{
int i;
double val = 0.0;
for (i = 0; i < n_point - 1; i++)
{
val += (data[off + i*col] + data[off + (i + 1)*col])*
(data[0 + (i + 1)*col] - data[0 + i*col])/2;
}
*integral = val;
return 0;
}
@@ -0,0 +1,2 @@
ROOT = ../../..
include $(ROOT)/config/presrc.mk
@@ -0,0 +1,17 @@
#ifndef __rockflight_h__
#define __rockflight_h__
/* universal gravitational constant */
#define UGC 6.672e-11
/* earth angular velocity */
#define WE 7.27e-5
/* square of earth angular velocity */
#define WE2 5.28529e-9
/* earth mass */
#define ME 5.98e24
/* earth radius */
#define EARTH_RAD 6.3567668e6
#endif __rockflight_h__
@@ -0,0 +1,169 @@
#ifndef __state_h__
#define __state_h__
typedef double real;
typedef real scalar_t;
typedef real vector_t[3];
typedef real matrix_t[3][3];
typedef enum
{
_CONSTANT,
_FUNCTION,
_TABLE
} val_t;
typedef enum
{
ALT,
MACH,
AOA,
TIME
} parameter_t;
typedef struct _function
{
char *name;
val_t type;
/* if type is _CONSTANT */
float constant_value;
/* if type is _TABLE */
int n_point;
parameter_t independant_var;
float *x, *y;
/* if type is _FUNCTION */
char *function;
} function_t;
typedef struct state
{
int s; /* active stage */
scalar_t m; /* mass of the rocket */
scalar_t g; /* gravitational acceleration */
scalar_t Ix;
scalar_t Iy;
scalar_t Iz;
/* */
scalar_t alt;
scalar_t aoa;
scalar_t mach;
/* aerodynamic coefficients */
scalar_t Cd;
scalar_t CL;
scalar_t CB;
scalar_t Cspin;
scalar_t Cmoment;
scalar_t Cdamping;
scalar_t D; /* Diameter of the rocket */
scalar_t A; /* reference area (m^2) */
scalar_t C; /* reference distance */
/* aerodynamic forces */
vector_t Faero; /* (X, Y, Z) */
/* moments */
vector_t Maero; /* (L, M, N) */
/* engine forces and moments */
vector_t Feng;
vector_t Meng;
/* component of centripetal acceleration in F_B */
scalar_t Cx;
scalar_t Cy;
scalar_t Cz;
/* earth angular velocity in F_B */
scalar_t pE;
scalar_t qE;
scalar_t rE;
/* relative angular velocity of F_B to F_V */
scalar_t P;
scalar_t Q;
scalar_t R;
matrix_t L_BV;
matrix_t L_VB;
} state_t;
typedef struct engine
{
float propellant_mass;
float dry_mass;
function_t thrust;
float c;
float mass_flow;
float start_time;
float burn_time;
float drop_time;
float position[3];
float direction[3];
} engine_t;
typedef struct rocket_properties
{
float dry_mass;
function_t Ix;
function_t Iy;
function_t Iz;
function_t Cd;
function_t CL;
function_t CB;
float Cspin;
float Cmoment;
float Cdamping;
float Diameter;
float active_time;
int n_engine;
engine_t *engines;
} rocket_properties_t;
typedef struct rocket
{
int n_stage;
rocket_properties_t *stage_properties;
state_t state;
} rocket_t;
typedef struct solution
{
float duration;
float dt;
float precision;
} solution_t;
#endif /* __state_h__ */
@@ -0,0 +1,3 @@
ROOT = ../../../..
include $(ROOT)/config/makedef
include $(ROOT)/config/libsrc.mk
@@ -0,0 +1,122 @@
#include <stdio.h>
#include <math.h>
#include "aero.h"
#include "atmos.h"
#include "librockflight/include/state.h"
#define EARTH_RAD 6.3567668e6
#define AIR_GAS_CONSTANT 287.0
/* Compute aerodynamic forces and moments */
int aero(rocket_t *r, double *y, double *t)
{
state_t *s;
double q; /* dynamic pressure */
double u = y[0]; /* velocity component in x */
double v = y[1]; /* velocity component in y */
double w = y[2]; /* velocity component in z */
/* double p = y[3];*/ /* angular velocity */
/* double q = y[4];*/ /* */
/* double r = y[5];*/ /* */
/* double lambda = y[6];*/ /* latitude */
/* double mu = y[7];*/ /* longitude */
double Re = y[8]; /* distance from earth center */
/* double phi = y[9];*/ /* euler angles */
/* double theta = y[10];*/ /* */
/* double psi = y[11];*/ /* */
double X = 0;
double Y = 0;
double Z = 0;
double FD = 0; /* Drag */
double FL = 0; /* Lift */
double FB = 0; /* sideslip force */
/* double SL = 0;*/ /* Cross spin */
/* double SB = 0;*/ /* Cross spin */
/* restoring moments */
double ML = 0;
double MM = 0;
double MN = 0;
/* damping moments */
double MG = 0;
double MH = 0;
double MI = 0;
AIR air;
/* double A; reference aera */
/* double C; reference length */
double V; /* airspeed */
double alpha; /* angle of attack */
double beta; /* angle of sideslip */
s = &(r->state);
/* compute atmospheric properties */
atmosphere(&air, Re - EARTH_RAD);
/*printf("T = %f, P = %f, rho = %f, c = %f\n", air.T, air.P, air.rho, air.c);*/
V = sqrt(u*u + v*v + w*w);
s->mach = V / sqrt ( 1.4 * AIR_GAS_CONSTANT * air.T);
if (V == 0.0)
return 0;
alpha = atan(w/u);
beta = asin(v/V);
/* A = M_PI * s->D * S->D / 4; */
/* S = S->D; */
q = 0.5 * air.rho * V * V;
FD = - s->Cd * q * s->A;
FL = - s->CL * q * s->A * alpha;
FB = - s->CB * q * s->A * beta;
/*printf("FD = %f, FL = %f\n", FD, FL);*/
ML = 0;
MG = 0; /*s->C_l_p * q * s->A * pow(s->C, 2) * s->P / (2 * u); */
MM = s->Cmoment * q * s->A * s->C * alpha;
MH = s->Cdamping * q * s->A * pow(s->C, 2) * s->Q / (2 * u);
/*printf("MM = %f, MH = %f\n", MM, MH);*/
MN = s->Cmoment * q * s->A * s->C * beta;
MI = s->Cdamping * q * s->A * pow(s->C, 2) * s->R / (2 * u);
/* transform wind axis forces to body axis forces */
X = FD*cos(alpha)*cos(beta) - FB*cos(alpha)*sin(beta) - FL*sin(alpha);
Y = FD*sin(beta) + FB*cos(beta);
Z = FD*sin(alpha)*cos(beta) - FB*sin(alpha)*sin(beta) + FL*cos(alpha);
s->Faero[0] = X;
s->Faero[1] = Y;
s->Faero[2] = Z;
s->Maero[0] = ML + MG;
s->Maero[1] = MM + MH;
s->Maero[2] = MN + MI;
return 0;
}
@@ -0,0 +1,9 @@
#ifndef __aero_h__
#define __aero_h__
#include "librockflight/include/state.h"
/*int aero(double *y, state_t *s);*/
int aero(rocket_t *r, double *y, double *t);
#endif __aero_h__
@@ -0,0 +1,103 @@
/************************************************************************
File: atmos.c
Author: David E. Hall
Date: 24 April 1996
Description: A quick and dirty atmosphere calculator based upon the
module found in the ExtREME (Extendible Round Earth Missile Emulation)
simulation (authored by your's truly as well).
*************************************************************************/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "atmos.h"
/*--- physical constants */
#define EARTH_RAD 6.3567668e6 /* earth radius (m) */
#define GRAVITY -9.806655352 /* gravitation accel (m/s2) */
#define R 287.05376255 /* gas constant for air */
int atmosphere (AIR *a, double altitude)
{
/*
This function determines the atmospheric conditions at any given
altitude. Note: the routine is a translation of an old FORTRAN
routine of unknown origin and thus I have no idea as to what is
being referenced in the original notes listed below....
This atmosphere model is after the ISO Standard atmosphere as
documented in ref. no. ISO 2533-1975(E) which has a first edition
date of 1975-05-15 and corrected and reprinted date of 1978-12-15.
This atmosphere is identical with the ICAO and WMO Standard
atmospheres from -2000 to 32000 meters.
*/
static double Abreak[9] = {-2.0, 11.0, 20.0, 32.0, 47.0,
52.0, 61.0, 79.0, 88.74 };
static double Tnot[9] = {301.15, 216.65, 216.65, 228.65, 270.65,
270.65, 252.65, 180.65, 180.65 };
static double Tslope[9] = {-6.5, 0.0, 1.0, 2.8, 0.0,
-2.0, -4.0, 0.0, 0.0 };
static double Pnot[9] = {127774.0, 22632.0, 5475.87, 868.014,
110.906, 59.002, 18.208, 1.03757, 0.00 };
int zone = -1;
double alt;
double delta_alt;
double x, y;
/*fprintf(stderr, "%f\n", altitude);*/
/* Convert to geopotential altitude */
alt = EARTH_RAD*altitude/(EARTH_RAD+altitude)/1000.0;
while ((zone < 8) && (alt >= Abreak[zone + 1]))
zone++;
if (zone < 0)
{ /* Below atmosphere data! */
/* fprintf(stderr, "*** ERROR: Below atmospheric model (%f)\n", alt); */
return -1;
}
/* The meat of the function */
delta_alt = alt - Abreak[zone];
a->T = Tnot[zone] + Tslope[zone] * delta_alt;
switch (zone)
{
case 1:
case 4:
case 7:
case 8:
a->P = Pnot[zone] * exp(GRAVITY*delta_alt*1000.0/R
/a->T);
break;
default:
x = 1.0 + Tslope[zone] * delta_alt / Tnot[zone];
y = GRAVITY * 1000.0 / Tslope[zone] / R;
a->P = Pnot[zone] * pow(x,y);
break;
}
a->rho = a->P / R / a->T;
a->c = 20.046796 * sqrt(a->T); /* c = sqrt(kRT) k=1.4 */
return 0;
}
/*
int main(int argc, char *argw[])
{
AIR air;
double alt;
for (alt = 0; alt < 100000; alt += 1000)
{
atmosphere(&air, alt);
printf("%f %f %f %f\n", air.temperature, air.pressure,
air.density, air.mach1);
}
return 0;
}
*/
@@ -0,0 +1,14 @@
#ifndef __atmos_h__
#define __atmos_h__
typedef struct
{
double T;
double P;
double rho;
double c;
} AIR;
int atmosphere (AIR *a, double altitude);
#endif __atmos_h__
@@ -0,0 +1,58 @@
#include <stdio.h>
#include <math.h>
#include "librockflight/include/state.h"
#include "engine.h"
int evaluate_function(function_t *f, state_t *s, double time, double *ans);
/* Add engine component of force and moment */
int engine(rocket_t *r, double *t)
{
int i;
float tref = 0.0;
float trel;
float thrust = 0.0;
float norm = 1.0;
double tmp_val;
state_t *s;
engine_t *e = NULL;
s = &(r->state);
for (i = 0; i < s->s; i++)
tref += r->stage_properties[i].active_time;
for (i = 0; i < r->stage_properties[s->s].n_engine; i++)
{
e = r->stage_properties[s->s].engines + i;
norm = sqrt( pow(e->direction[0], 2) +
pow(e->direction[1], 2) +
pow(e->direction[2], 2) );
trel = *t - tref - e->start_time;
if ((trel >= 0.0) && (*t < tref + e->drop_time))
{
evaluate_function(&(e->thrust), s, trel, &tmp_val);
thrust += (float)tmp_val;
}
}
s->Feng[0] = thrust * e->direction[0] / norm;
s->Feng[1] = thrust * e->direction[1] / norm;
s->Feng[2] = thrust * e->direction[2] / norm;
s->Meng[0] = 0.0;
s->Meng[1] = 0.0;
s->Meng[2] = 0.0;
return 0;
}
@@ -0,0 +1,9 @@
#ifndef __engine_h__
#define __engine_h__
/*int engine(double *y, state_t *s);*/
int engine(rocket_t *r, double *t);
#endif __engine_h__
@@ -0,0 +1,230 @@
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include "aero.h"
#include "librockflight/include/rockflight.h"
#include "librockflight/include/state.h"
#include "atmos.h"
#include "engine.h"
#include "mass.h"
#include "stage.h"
#define SEC(THETA) (1./cos(THETA))
#define EARTH_RAD 6.3567668e6
int set_state(rocket_t *rocket, double *y, double *time);
int evaluate_function(function_t *f, state_t *s, double time, double *ans);
int eom(int neq, double time, double *y, double *dy, void *data)
{
state_t *s;
rocket_t *rocket = (rocket_t *) data;
double u = y[0]; /* velocity component in x */
double v = y[1]; /* velocity component in y */
double w = y[2]; /* velocity component in z */
double p = y[3]; /* angular velocity */
double q = y[4]; /* */
double r = y[5]; /* */
double lambda = y[6]; /* latitude */
/*double mu = y[7];*//* longitude */
double Re = y[8]; /* distance from earth center */
double phi = y[9]; /* euler angles */
double theta = y[10]; /* */
/*double psi = y[11];*//* */
/* aerodynamic forces */
double X = 0.0;
double Y = 0.0;
double Z = 0.0;
/* moments */
double L = 0.0;
double M = 0.0;
double N = 0.0;
/* set the pointer to the rocket state structure */
s = &(rocket->state);
set_state(rocket, y, &time);
X += s->Faero[0]; /*printf("X = %f\n", s->Faero[0]);*/
Y += s->Faero[1]; /*printf("Y = %f\n", s->Faero[1]);*/
Z += s->Faero[2]; /*printf("Z = %f\n", s->Faero[2]);*/
L += s->Maero[0]; /*printf("L = %f\n", s->Maero[0]);*/
M += s->Maero[1]; /*printf("M = %f\n", s->Maero[1]);*/
N += s->Maero[2]; /*printf("N = %f\n", s->Maero[2]);*/
/* add the thrust of the engine */
X += s->Feng[0];
Y += s->Feng[1];
Z += s->Feng[2];
L += s->Meng[0];
M += s->Meng[1];
N += s->Meng[2];
/* acceleration of the rocket in the body axis */
dy[0] = X/s->m - s->g*sin(theta) - s->Cx - (s->qE + q)*w +
(s->rE + r)*v;
dy[1] = Y/s->m + s->g*cos(theta)*sin(phi) - s->Cy - (s->rE + r)*u +
(s->pE + p)*w;
dy[2] = Z/s->m + s->g*cos(theta)*cos(phi) - s->Cz - (s->pE + p)*v +
(s->qE + q)*u;
/* angular acceleration equation */
dy[3] = (L + (s->Iy - s->Iz)*q*r)/s->Ix;
dy[4] = (M + (s->Iz - s->Ix)*r*p)/s->Iy;
dy[5] = (N + (s->Ix - s->Iy)*p*q)/s->Iz;
/* position relative to earth */
dy[6] = (s->L_VB[0][0]*u + s->L_VB[0][1]*v+s->L_VB[0][2]*w)/Re;
dy[7] = (s->L_VB[1][0]*u + s->L_VB[1][1]*v+s->L_VB[1][2]*w)/(Re*cos(lambda));
dy[8] =-(s->L_VB[2][0]*u + s->L_VB[2][1]*v+s->L_VB[2][2]*w);
/* relative angular velocity of vehicle relative to atmosphere */
s->P = p - (s->L_BV[0][0]*(WE + dy[7])*cos(lambda) -
s->L_BV[0][1]*dy[6] - s->L_BV[0][2]*(WE + dy[7])*sin(lambda));
s->Q = q - (s->L_BV[1][0]*(WE + dy[7])*cos(lambda) -
s->L_BV[1][1]*dy[6] - s->L_BV[1][2]*(WE + dy[7])*sin(lambda));
s->R = r - (s->L_BV[2][0]*(WE + dy[7])*cos(lambda) -
s->L_BV[2][1]*dy[6] - s->L_BV[2][2]*(WE + dy[7])*sin(lambda));
/* euler angle equation */
/* we have to check for division by zero */
if (abs(cos(theta)) > 0.001)
{
dy[9] = s->P + sin(phi)*tan(theta)*s->Q + cos(phi)*tan(theta)*s->R;
dy[10] = cos(phi) *s->Q - sin(phi) *s->R;
dy[11] = sin(phi)*SEC(theta)*s->Q + cos(phi)*SEC(theta)*s->R;
}
else
{
dy[9] = s->P;
dy[10] = cos(phi)*s->Q - sin(phi)*s->R;
dy[11] = 0;
}
return 0;
}
int set_state(rocket_t *rocket, double *y, double *time)
{
state_t *s;
function_t *f;
/*double u = y[0];*/ /* velocity component in x */
/*double v = y[1];*/ /* velocity component in y */
/*double w = y[2];*/ /* velocity component in z */
/*double p = y[3];*/ /* angular velocity */
/*double q = y[4];*/ /* */
/*double r = y[5];*/ /* */
double lambda = y[6]; /* latitude */
/* double mu = y[7];*/ /* longitude */
double Re = y[8]; /* distance from earth center */
double phi = y[9]; /* euler angles */
double theta = y[10]; /* */
double psi = y[11]; /* */
s = &(rocket->state);
/* transformation matrix (vector in vehicle carried reference to
body reference */
s->L_BV[0][0] = cos(theta)*cos(psi);
s->L_BV[0][1] = cos(theta)*sin(psi);
s->L_BV[0][2] = -sin(theta);
s->L_BV[1][0] = sin(phi)*sin(theta)*cos(psi) - cos(phi)*sin(psi);
s->L_BV[1][1] = sin(phi)*sin(theta)*sin(psi) + cos(phi)*cos(psi);
s->L_BV[1][2] = sin(phi)*cos(theta);
s->L_BV[2][0] = cos(phi)*sin(theta)*cos(psi) + sin(phi)*sin(psi);
s->L_BV[2][1] = cos(phi)*sin(theta)*sin(psi) - sin(phi)*cos(psi);
s->L_BV[2][2] = cos(phi)*cos(theta);
/* Inverse of the previous matrix */
s->L_VB[0][0] = s->L_BV[0][0];
s->L_VB[0][1] = s->L_BV[1][0];
s->L_VB[0][2] = s->L_BV[2][0];
s->L_VB[1][0] = s->L_BV[0][1];
s->L_VB[1][1] = s->L_BV[1][1];
s->L_VB[1][2] = s->L_BV[2][1];
s->L_VB[2][0] = s->L_BV[0][2];
s->L_VB[2][1] = s->L_BV[1][2];
s->L_VB[2][2] = s->L_BV[2][2];
/* Earth angular velocity vector expressed in body reference */
s->pE = (s->L_BV[0][0]*cos(lambda) - s->L_BV[0][2]*sin(lambda)) * WE;
s->qE = (s->L_BV[1][0]*cos(lambda) - s->L_BV[1][2]*sin(lambda)) * WE;
s->rE = (s->L_BV[2][0]*cos(lambda) - s->L_BV[2][2]*sin(lambda)) * WE;
/* Centripetal acceleration */
s->Cx = (s->L_BV[0][0]*Re*cos(lambda)*sin(lambda) +
s->L_BV[0][2]*Re*cos(lambda)*cos(lambda)) * WE2;
s->Cy = (s->L_BV[1][0]*Re*cos(lambda)*sin(lambda) +
s->L_BV[1][2]*Re*cos(lambda)*cos(lambda)) * WE2;
s->Cz = (s->L_BV[2][0]*Re*cos(lambda)*sin(lambda) +
s->L_BV[2][2]*Re*cos(lambda)*cos(lambda)) * WE2;
s->alt = Re - EARTH_RAD;
/* gravitational model */
s->g = UGC*ME/(Re*Re);
/* find the actual active stage */
if (stage(rocket, time))
return -1;
/* set the inertia of the rocket */
f = &(rocket->stage_properties[s->s].Ix);
evaluate_function(f, s, *time, &(s->Ix));
f = &(rocket->stage_properties[s->s].Iy);
evaluate_function(f, s, *time, &(s->Iy));
f = &(rocket->stage_properties[s->s].Iz);
evaluate_function(f, s, *time, &(s->Iz));
f = &(rocket->stage_properties[s->s].Cd);
evaluate_function(f, s, *time, &(s->Cd));
f = &(rocket->stage_properties[s->s].CL);
evaluate_function(f, s, *time, &(s->CL));
f = &(rocket->stage_properties[s->s].CB);
evaluate_function(f, s, *time, &(s->CB));
/* compute rocket mass */
if (mass(rocket, time))
return -1;
/* compute aerodynamic forces and moments */
if (aero(rocket, y, time))
return -1;
/* compute enginethrust */
if (engine(rocket, time))
return -1;
return 0;
}
@@ -0,0 +1,76 @@
#include <stdlib.h>
#include <stdio.h>
#include "librockflight/include/state.h"
int interpolate(int n_point, float *x, float *y, double *ans, double xval);
int evaluate_function(function_t *f, state_t *s, double time, double *ans)
{
double independant_var_value = 0.0;
switch (f->type)
{
case _CONSTANT:
*ans = f->constant_value;
break;
case _TABLE:
switch (f->independant_var)
{
case TIME:
independant_var_value = time;
break;
case ALT:
independant_var_value = s->alt;
break;
case MACH:
independant_var_value = s->mach;
break;
default:
}
interpolate(f->n_point, f->x, f->y, ans, independant_var_value);
break;
case _FUNCTION:
printf("Analytical functions are not supported yet.\n");
break;
}
return 0;
}
int interpolate(int n_point, float *x, float *y, double *ans, double xval)
{
int i;
if (xval < x[0])
{
*ans = (y[0]/x[0])*xval;
}
else
{
for (i = 0; i < n_point; i++)
{
if (xval < x[i])
{
*ans = y[i-1] + ( (y[i]-y[i-1])/(x[i]-x[i-1]) ) * (xval - x[i-1]);
return 0;
}
}
/* use the last segment of curve to extrapolate out of range value */
*ans = y[n_point-1];
}
return 0;
}
@@ -0,0 +1,31 @@
SRC = hwm93dist.f hwm93dist_test.f
OBJS = hwm93dist.o hwm93dist_test.o
COBJ = test.o
PROG = hwm93dist_test
CTEST = ctest
OPT = -g -Wall
all: $(PROG) $(CTEST) libtest.a
.c.o :
$(CC) $(OPT) -c $< -o $@
.f.o :
f77 $(OPT) -c $< -o $@
$(PROG): $(OBJS)
f77 $(OBJS) -o $@
$(CTEST): $(OBJS) $(COBJ)
$(CC) $(COBJ) $(OBJS) -lm -lg2c -o $@
libtest.a : $(OBJS)
ar -r $@ $(LIBOBJS)
clean:
rm -f *.o *~ *.a hwm93dist_test
@@ -0,0 +1,528 @@
SUBROUTINE GWS3(IYD,SEC,ALT,GLAT,GLONG,STL,F107A,F107,AP,W)
C Horizontal wind model HWM87
C A. E. HEDIN (11/3/87)
C 10/8/88 CHANGE HANDLING OF SW(9)
C Currently intended only for winds above about 220 km.
C Calling argument list made similar to GTS5 subroutine for
C MSIS-86 density model. Some arguments not currently used but
C left in for compatability and expected use in later versions.
C INPUT:
C IYD - YEAR AND DAY AS YYDDD
C SEC - UT(SEC)
C ALT - ALTITUDE(KM) $not used$
C GLAT - GEODETIC LATITUDE(DEG)
C GLONG - GEODETIC LONGITUDE(DEG)
C STL - LOCAL APPARENT SOLAR TIME(HRS)
C F107A - 3 MONTH AVERAGE OF F10.7 FLUX $not used$
C F107 - DAILY F10.7 FLUX FOR PREVIOUS DAY $not used$
C AP - MAGNETIC INDEX(DAILY) OR WHEN SW(9)=-1. :
C AP(2)=CURRENT 3HR AP INDEX
C OUTPUT
C W(1) = MERIDIANAL (m/sec + North)
C W(2) = ZONAL (m/sec + East)
C ADDITIONAL COMMENTS
C TO TURN ON AND OFF PARTICULAR VARIATIONS CALL TSELEC(SW)
C WHERE SW IS A 25 ELEMENT ARRAY CONTAINING 0. FOR OFF, 1.
C FOR ON, OR 2. FOR MAIN EFFECTS OFF BUT CROSS TERMS ON
C FOR THE FOLLOWING VARIATIONS
C 1 - F10.7 EFFECT ON MEAN 2 - TIME INDEPENDENT
C 3 - SYMMETRICAL ANNUAL 4 - SYMMETRICAL SEMIANNUAL
C 5 - ASYMMETRICAL ANNUAL 6 - ASYMMETRICAL SEMIANNUAL
C 7 - DIURNAL 8 - SEMIDIURNAL
C 9 - DAILY AP 10 - ALL UT/LONG EFFECTS
C 11 - LONGITUDINAL 12 - UT AND MIXED UT/LONG
C 13 - MIXED AP/UT/LONG 14 - TERDIURNAL
C 24 - ALL B FIELDS (DIV) 25 - ALL C FIELDS (CURL)
C
C To get current values of SW: CALL TRETRV(SW)
C
DIMENSION AP(1),W(1),WINDF(2)
COMMON/PARMW3/PWB(150),PWC(200)
COMMON/CSW/SW(25),ISW,SWC(25)
COMMON/DATIME/ISDATE(3),ISTIME(2),NAME(2)
DATA IFL/0/
IF(IFL.EQ.1.AND.NAME(1).EQ.'HWM8'.AND.NAME(2).EQ.'7 ') GO TO 5
CALL PRMW3
IFL=1
5 CONTINUE
YRD=IYD
CALL GLOBW3(YRD,SEC,GLAT,GLONG,STL,F107A,F107,AP,PWB,PWC,WINDF)
W(1)= WINDF(1)
W(2)= WINDF(2)
RETURN
END
SUBROUTINE GLOBW3(YRD,SEC,LAT,LONG,STL,F107A,F107,AP,PB,PC,WW)
REAL LAT,LONG
DIMENSION WB(2,15),WC(2,15),PB(1),PC(1),WW(2),BT(20,20),BP(20,20)
DIMENSION AP(1),SV(25)
COMMON/CSW/SW(25),ISW,SWC(25)
COMMON/HWMC/WBT(2),WCT(2)
COMMON/WTEST/WB,WC
DATA DGTR/.017453/,SR/7.2722E-5/,HR/.2618/,DR/1.72142E-2/
DATA NSW/14/,WB/30*0/,WC/30*0/,TLL/-99./,XL/-999./,XLONG/-999./
DATA SV/25*1./,SW9/1./
G0(A)=(A-4.+(PB(26)-1.)*(A-4.+(EXP(-ABS(PB(25))*(A-4.))-1.)/
* ABS(PB(25))))
IF(ISW.NE.64999) CALL TSELEC(SV)
WB(1,11)=0
WB(2,11)=0
WB(1,12)=0
WB(2,12)=0
WB(1,13)=0
WB(2,13)=0
WC(1,11)=0
WC(2,11)=0
WC(1,12)=0
WC(2,12)=0
WC(1,13)=0
WC(2,13)=0
IF(SW(9).GT.0) SW9=1.
IF(SW(9).LT.0) SW9=-1.
IYR = YRD/1000.
DAY = YRD - IYR*1000.
IF(XL.NE.LAT) THEN
CALL VSPHER(LAT,12,3,BT,BP,20)
XL=LAT
ENDIF
IF(TLL.NE.STL) THEN
SSTL = SIN(HR*STL)
CSTL = COS(HR*STL)
S2STL = SIN(2.*HR*STL)
C2STL = COS(2.*HR*STL)
S3STL = SIN(3.*HR*STL)
C3STL = COS(3.*HR*STL)
TLL = STL
ENDIF
IF(DAY.NE.DAYL.OR.PB(14).NE.PB14) CD14=COS(DR*(DAY-PB(14)))
DAYL=DAY
PB14=PB(14)
IF(XLONG.NE.LONG) THEN
SLONG=SIN(DGTR*LONG)
CLONG=COS(DGTR*LONG)
XLONG=LONG
ENDIF
C F10.7 EFFECT
F1=1.
F2=1.
C TIME INDEPENDENT
WB(1,2)=PB(2)*BT(3,1)+PB(3)*BT(5,1)+PB(23)*BT(7,1)
WC(2,2)=-(PC(2)*BT(2,1)+PC(3)*BT(4,1)+PC(23)*BT(6,1))
$ -(PC(27)*BT(3,1)+PC(15)*BT(5,1)+PC(60)*BT(7,1)
$ +PC(161)*BT(9,1)+PC(162)*BT(11,1)+PC(163)*BT(13,1))
C ANNUAL
WB(1,5)=(PB(10)*BT(2,1)+PB(11)*BT(4,1))*CD14*F1
WC(2,5)=-(PC(10)*BT(3,1)+PC(11)*BT(5,1))*CD14*F1
C DIURNAL
WB(1,7)=(PB(7)*BT(2,2)+PB(8)*BT(4,2)+PB(29)*BT(6,2)
$ )*SSTL*F2
$ + (PB(4)*BT(2,2)+PB(5)*BT(4,2)+PB(28)*BT(6,2)
$ )*CSTL*F2
WB(2,7)=-(PB(4)*BP(2,2)+PB(5)*BP(4,2)+PB(28)*BP(6,2)
$ )*SSTL*F2
$ + (PB(7)*BP(2,2)+PB(8)*BP(4,2)+PB(29)*BP(6,2)
$ )*CSTL*F2
DCASY=1.
WC(1,7)=-(PC(4)*BP(3,2)+PC(5)*BP(5,2)+PC(28)*BP(7,2)
$ +PC(141)*BP(9,2)+PC(143)*BP(11,2)
$ +PC(181)*BP(2,2)+PC(183)*BP(4,2)+PC(185)*BP(6,2)
$ +PC(187)*BP(8,2)+PC(189)*BP(10,2)
$ +PC(12)*BP(2,2)*CD14*SWC(5)
$ )*SSTL*DCASY
$ +(PC(7)*BP(3,2)+PC(8)*BP(5,2)+PC(29)*BP(7,2)
$ +PC(142)*BP(9,2)+PC(144)*BP(11,2)
$ +PC(182)*BP(2,2)+PC(184)*BP(4,2)+PC(186)*BP(6,2)
$ +PC(188)*BP(8,2)+PC(190)*BP(10,2)
$ +PC(13)*BP(2,2)*CD14*SWC(5)
$ )*CSTL*DCASY
WC(2,7)=-(PC(7)*BT(3,2)+PC(8)*BT(5,2)+PC(29)*BT(7,2)
$ +PC(142)*BT(9,2)+PC(144)*BT(11,2)
$ +PC(182)*BT(2,2)+PC(184)*BT(4,2)+PC(186)*BT(6,2)
$ +PC(188)*BT(8,2)+PC(190)*BT(10,2)
$ +PC(13)*BT(2,2)*CD14*SWC(5)
$ )*SSTL*DCASY
$ -(PC(4)*BT(3,2)+PC(5)*BT(5,2)+PC(28)*BT(7,2)
$ +PC(141)*BT(9,2)+PC(143)*BT(11,2)
$ +PC(181)*BT(2,2)+PC(183)*BT(4,2)+PC(185)*BT(6,2)
$ +PC(187)*BT(8,2)+PC(189)*BT(10,2)
$ +PC(12)*BT(2,2)*CD14*SWC(5)
$ )*CSTL*DCASY
C SEMIDIURNAL
WB(1,8)=(PB(9)*BT(3,3)+PB(43)*BT(5,3)
$ )*S2STL*F2
$ + (PB(6)*BT(3,3)+PB(42)*BT(5,3)
$ )*C2STL*F2
WB(2,8)=-(PB(6)*BP(3,3)+PB(42)*BP(5,3)
$ )*S2STL*F2
$ + (PB(9)*BP(3,3)+PB(43)*BP(5,3)
$ )*C2STL*F2
WC(1,8)=-(PC(6)*BP(4,3)+PC(42)*BP(6,3)
$ +PC(24)*BP(3,3)*CD14*SWC(5)
$ )*S2STL*DCASY
$ + (PC(9)*BP(4,3)+PC(43)*BP(6,3)
$ +PC(34)*BP(3,3)*CD14*SWC(5)
$ )*C2STL*DCASY
$ -(PC(151)*BP(3,3)+PC(153)*BP(5,3)+PC(155)*BP(7,3)
$ +PC(157)*BP(9,3)
$ )*S2STL
$ + (PC(152)*BP(3,3)+PC(154)*BP(5,3)+PC(156)*BP(7,3)
$ +PC(158)*BP(9,3)
$ )*C2STL
WC(2,8)=-(PC(9)*BT(4,3)+PC(43)*BT(6,3)
$ +PC(34)*BT(3,3)*CD14*SWC(5)
$ )*S2STL*DCASY
$ - (PC(6)*BT(4,3)+PC(42)*BT(6,3)
$ +PC(24)*BT(3,3)*CD14*SWC(5)
$ )*C2STL*DCASY
$ -(PC(151)*BT(3,3)+PC(153)*BT(5,3)+PC(155)*BT(7,3)
$ +PC(157)*BT(9,3)
$ )*C2STL
$ -(PC(152)*BT(3,3)+PC(154)*BT(5,3)+PC(156)*BT(7,3)
$ +PC(158)*BT(9,3)
$ )*S2STL
C TERDIURNAL
WB(1,14)=(PB(40)*BT(4,4)
$ )*S3STL*F2
$ + (PB(41)*BT(4,4)
$ )*C3STL*F2
WB(2,14)=-(PB(41)*BP(4,4)
$ )*S3STL*F2
$ + (PB(40)*BP(4,4)
$ )*C3STL*F2
C MAGNETIC ACTIVITY
IF(SW9.EQ.-1.) GOTO 30
C daily AP
APD=AP(1)-4.
APDF=(APD+(PB(45)-1.)*(APD+(EXP(-PB(44)*APD)-1.)/PB(44)))
APDFC=APDF
WB(1,9)=(PB(46)*BT(3,1)+PB(35)*BT(5,1))*APDF
WC(1,9)=SWC(7)*WC(1,7)*PC(122)*APDFC
WC(2,9)=-(PC(46)*BT(2,1)+PC(35)*BT(4,1))*APDFC
$ +SWC(7)*WC(2,7)*PC(122)*APDFC
GO TO 40
30 CONTINUE
IF(PB(25).LT.1.E-4) PB(25)=1.E-4
APT=G0(AP(2))
WB(1,9)=(PB(97)*BT(3,1)+PB(55)*BT(5,1))*APT
WC(1,9)=SWC(7)*WC(1,7)*PC(129)*APT
WC(2,9)=-(PC(97)*BT(2,1)+PC(55)*BT(4,1))*APT
$ +SWC(7)*WC(2,7)*PC(129)*APT
40 CONTINUE
IF(SW(10).EQ.0) GOTO 49
C LONGITUDINAL
DLBASY=1.
WB(1,11)=(PB(91)*BT(3,2)+PB(92)*BT(5,2)+PB(93)*BT(7,2))
$ *SLONG*DLBASY
$ + (PB(65)*BT(3,2)+PB(66)*BT(5,2)+PB(67)*BT(7,2))
$ *CLONG*DLBASY
WB(2,11)=-(PB(65)*BP(3,2)+PB(66)*BP(5,2)+PB(67)*BP(7,2))
$ *SLONG*DLBASY
$ + (PB(91)*BP(3,2)+PB(92)*BP(5,2)+PB(93)*BP(7,2))
$ *CLONG*DLBASY
DLCASY=1.
WC(1,11)=-(PC(65)*BP(2,2)+PC(66)*BP(4,2)+PC(67)*BP(6,2)
$ +PC(73)*BP(8,2)+PC(74)*BP(10,2)
$ )*SLONG*DLCASY
$ + (PC(91)*BP(2,2)+PC(92)*BP(4,2)+PC(93)*BP(6,2)
$ +PC(87)*BP(8,2)+PC(88)*BP(10,2)
$ )*CLONG*DLCASY
WC(2,11)=-(PC(91)*BT(2,2)+PC(92)*BT(4,2)+PC(93)*BT(6,2)
$ +PC(87)*BT(8,2)+PC(88)*BT(10,2)
$ )*SLONG*DLCASY
$ - (PC(65)*BT(2,2)+PC(66)*BT(4,2)+PC(67)*BT(6,2)
$ +PC(73)*BT(8,2)+PC(74)*BT(10,2)
$ )*CLONG*DLCASY
C UT & MIXED UT/LONG
UTCASY=1.
WC(1,12)=(PC(77)*BP(3,3)+PC(78)*BP(5,3)+PC(79)*BP(7,3)
$ +PC(165)*BP(9,3)+PC(166)*BP(11,3)+PC(167)*BP(13,3)
$ )*COS(SR*(SEC-PC(80))+2.*DGTR*LONG)
WC(2,12)=-(PC(69)*BT(3,1)+PC(70)*BT(5,1)+PC(71)*BT(7,1)
$ +PC(116)*BT(9,1)+PC(117)*BT(11,1)+PC(118)*BT(13,1)
$ )*COS(SR*(SEC-PC(72)))*UTCASY
$ + (PC(77)*BT(3,3)+PC(78)*BT(5,3)+PC(79)*BT(7,3)
$ +PC(165)*BT(9,3)+PC(166)*BT(11,3)+PC(167)*BT(13,3)
$ )*COS(SR*(SEC-PC(80)+21600.)+2.*DGTR*LONG)
C MIXED LONG,UT,AP
IF(SW9.EQ.-1.) GO TO 45
WB(1,13)=
$ (PB(84)*BT(2,1)+PB(85)*BT(4,1)+PB(86)*BT(6,1))
$ *COS(SR*(SEC-PB(76)))*APDF*SWC(12)
WC(1,13)=SWC(11)*WC(1,11)*PC(61)*APDFC
$ +SWC(12)*WC(1,12)*PC(84)*APDFC
WC(2,13)=SWC(11)*WC(2,11)*PC(61)*APDFC
$ +SWC(12)*WC(2,12)*PC(84)*APDFC
GOTO 48
45 CONTINUE
WB(1,13)=
$ (PB(56)*BT(2,1)+PB(57)*BT(4,1)+PB(58)*BT(6,1))
$ *COS(SR*(SEC-PB(59)))*APT*SWC(12)
WC(1,13)=SWC(11)*WC(1,11)*PC(53)*APT
$ +SWC(12)*WC(1,12)*PC(56)*APT
WC(2,13)=SWC(11)*WC(2,11)*PC(53)*APT
$ +SWC(12)*WC(2,12)*PC(56)*APT
48 CONTINUE
49 CONTINUE
WBT(1)=0
WBT(2)=0
WCT(1)=0
WCT(2)=0
C SUM WINDS AND CHANGE MERIDIONAL SIGN TO + NORTH
DO 50 I=1,NSW
WBT(1)=WBT(1)-ABS(SW(I))*WB(1,I)
WCT(1)=WCT(1)-ABS(SW(I))*WC(1,I)
WBT(2)=WBT(2)+ABS(SW(I))*WB(2,I)
WCT(2)=WCT(2)+ABS(SW(I))*WC(2,I)
50 CONTINUE
WW(1)=WBT(1)*SW(24)+WCT(1)*SW(25)
WW(2)=WBT(2)*SW(24)+WCT(2)*SW(25)
RETURN
END
SUBROUTINE TSELEC(SV)
C SET SWITCHES
DIMENSION SV(1),SAV(25),SVV(1)
COMMON/CSW/SW(25),ISW,SWC(25)
DO 100 I = 1,25
SAV(I)=SV(I)
SW(I)=AMOD(SV(I),2.)
IF(ABS(SV(I)).GT.0.) THEN
SWC(I)=1.
ELSE
SWC(I)=0.
ENDIF
100 CONTINUE
ISW=64999
RETURN
ENTRY TRETRV(SVV)
DO 200 I=1,25
SVV(I)=SAV(I)
200 CONTINUE
END
SUBROUTINE VSPHER(THETA,L,M,BT,BP,LMAX)
C CALCULATE VECTOR SPHERICAL HARMONIC B FIELD THETA AND PHI
C FUNCTIONS BT,BP FOR GEOGRAPHICAL LATITUDE THETA THROUGH ORDER L,M
C BT(L+1,M+1)= [(L-M+1) P(L+1,M) - (L+1) P(L,M) SIN(THETA)] /
C [SQRT(L(L+1)) COS(THETA)]
C BP(L+1,M+1)= M P(L,M) /[SQRT(L(L+1)) COS(THETA)]
C RESULT FOR GIVEN L,M SAVED IN BT AND BP AT ONE HIGHER INDEX NUM
DIMENSION BT(LMAX,1),BP(LMAX,1),PLG(20,20)
DATA DGTR/1.74533E-2/
IF(M.GT.L.OR.L.GT.LMAX-1) THEN
WRITE(6,99) L,M,LMAX
99 FORMAT(1X,'ILLEGAL INDICIES TO VSPHER',3I5)
RETURN
ENDIF
BT(1,1)=0
BP(1,1)=0
IF(L.EQ.0.AND.M.EQ.0) RETURN
CALL LEGPOL(THETA,L+1,M,PLG,20)
C=SIN(THETA*DGTR)
S=COS(THETA*DGTR)
IF(ABS(S).LT.1.E-5) THEN
S=0
IC=SIGN(1,IFIX(THETA))
ENDIF
DO 20 LL=1,L
SQT=SQRT(FLOAT(LL)*(FLOAT(LL)+1))
LMX=MIN(LL,M)
DO 10 MM=0,LMX
IF(S.EQ.0) THEN
IF(MM.NE.1) THEN
BT(LL+1,MM+1)=0
BP(LL+1,MM+1)=0
ELSE
BT(LL+1,MM+1)=(LL*(LL+1)*(LL+2)*.5*(IC)**(LL+2)
$ -(LL+1)*C*LL*(LL+1)*.5*(IC)**(LL+1))/SQT
BP(LL+1,MM+1)=MM*LL*(LL+1)*.5*(IC)**(LL+1)/SQT
ENDIF
ELSE
BT(LL+1,MM+1)=((LL-MM+1)*PLG(LL+2,MM+1)
$ -(LL+1)*C*PLG(LL+1,MM+1))/(S*SQT)
BP(LL+1,MM+1)=MM*PLG(LL+1,MM+1)/(S*SQT)
ENDIF
10 CONTINUE
20 CONTINUE
END
SUBROUTINE LEGPOL(GLAT,L,M,PLG,LMAX)
C CALCULATE LEGENDRE POLYNOMIALS PLG(L+1,M+1) FOR GEOGRAPHICAL
C LATITUDE GLAT THROUGH ORDER L,M
DIMENSION PLG(LMAX,1)
DATA DGTR/1.74533E-2/
IF(M.GT.L.OR.L.GT.LMAX-1) THEN
WRITE(6,99) L,M,LMAX
99 FORMAT(1X,'ILLEGAL INDICIES TO LEGPOL',3I5)
RETURN
ENDIF
PLG(1,1)=1.
IF(L.EQ.0.AND.M.EQ.0) RETURN
C=SIN(GLAT*DGTR)
S=COS(GLAT*DGTR)
C CALCULATE L=M CASE AND L=M+1
DO 10 MM=0,M
IF(MM.GT.0) PLG(MM+1,MM+1)=PLG(MM,MM)*(2.*MM-1.)*S
IF(L.GT.MM) PLG(MM+2,MM+1)=PLG(MM+1,MM+1)*(2.*MM+1)*C
10 CONTINUE
IF(L.EQ.1) RETURN
MMX=MIN(M,L-2)
DO 30 MM=0,MMX
DO 20 LL=MM+2,L
PLG(LL+1,MM+1)=((2.*LL-1.)*C*PLG(LL,MM+1)-
$ (LL+MM-1.)*PLG(LL-1,MM+1))/(LL-MM)
20 CONTINUE
30 CONTINUE
RETURN
END
SUBROUTINE PRMW3
C HWM87 4-NOV-87
DIMENSION ISD(3),IST(2)
COMMON/PARMB/GSURF,RE
COMMON/PARMW3/PWB1(50),PWB2(50),PWB3(50),PWC1(50),
* PWC2(50),PWC3(50),PWC4(50)
COMMON/DATIME/ISDATE(3),ISTIME(2),NAME(2)
DATA GSURF,RE/980.665,6356.77/
DATA ISD/' 4-N','OV-8','7 '/,IST/'17:3','9:09'/
DATA NAME/'HWM8','7 '/
C IRROTATIONAL WIND FIELD (DIVERGENCE FIELD)
DATA PWB1/
* 0.00000E+00,-1.11368E+01,-1.24858E+01, 1.10036E+02, 5.72915E+00,
* 6.27672E+00, 7.79161E+01, 2.26817E+00, 1.48345E+00, 5.82466E+01,
* 0.00000E+00, 0.00000E+00, 0.00000E+00,-1.41351E+01, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 1.59211E+01, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 4.01565E-02,
* 8.29674E-02, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 3.36523E+01, 0.00000E+00, 0.00000E+00,-1.38693E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 3.76631E+00,-2.15251E+00,
* -8.60431E-01, 0.00000E+00, 0.00000E+00, 4.15805E-02, 1.05645E-01,
* -1.42416E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
DATA PWB2/
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,-1.55057E+00,
* 2.24596E+00, 3.33952E+00, 0.00000E+00, 1.81985E+04, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00,-1.50640E+02,-4.30700E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 1.61029E+04, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* -2.42610E+04, 0.00000E+00, 0.00000E+00, 0.00000E+00,-1.46241E+04,
* 0.00000E+00, 0.00000E+00, 0.00000E+00,-2.29211E+00,-3.23009E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 5.12558E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00,-2.07665E+00,-1.67008E+02, 0.00000E+00, 0.00000E+00/
DATA PWB3/
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00,-8.48854E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 4.75654E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 6.85704E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 1.47178E+01, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
C SOLENOIDAL WIND FIELD (CURL FIELD)
DATA PWC1/
* 0.00000E+00,-5.26044E-01,-4.29072E+01, 2.44965E+01,-1.29728E+01,
* 0.00000E+00, 3.82628E+01, 5.69565E+00, 0.00000E+00, 5.21497E+01,
* 0.00000E+00,-1.13601E+01,-6.45490E+00,-8.45400E+00,-4.07973E+00,
* 0.00000E+00, 0.00000E+00, 1.05267E+02, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00,-3.77522E+01,-4.06479E+00, 1.32400E-01,
* 2.13300E-01,-7.54067E+00,-5.54014E-01, 1.05543E+01, 0.00000E+00,
* 0.00000E+00,-1.57793E+02, 0.00000E+00,-4.48707E+00,-3.70910E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 1.13100E-01, 1.69100E-01,
* -2.29760E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
DATA PWC2/
* 0.00000E+00, 0.00000E+00, 5.37245E-02, 0.00000E+00,-3.78497E+00,
* 6.88459E-02, 0.00000E+00, 0.00000E+00, 0.00000E+00,-1.44635E+01,
* 5.43764E-02, 0.00000E+00, 0.00000E+00, 0.00000E+00,-6.94340E+00,
* -7.24977E+00,-4.85673E+00, 0.00000E+00,-3.60101E+00,-2.23183E+01,
* -5.12095E+01, 3.85590E+04,-1.33714E+00,-7.45792E-01, 0.00000E+00,
* -5.90503E+03, 5.89137E-01,-1.06978E+00,-9.62826E-01, 2.76396E+04,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 4.72006E-02, 0.00000E+00,
* 0.00000E+00, 5.34227E+00, 2.11187E+00, 0.00000E+00, 0.00000E+00,
* -4.35022E-01, 7.38162E+00, 6.74852E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00,-2.56217E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
DATA PWC3/
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* -4.92677E+01,-4.23828E+01, 0.00000E+00,-1.50460E+02, 0.00000E+00,
* 0.00000E+00, 1.25104E-02, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 2.47276E-02, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 5.29549E-01,
* 6.93886E-01, 7.47271E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
DATA PWC4/
* 3.28297E-01, 3.05222E+00,-2.57528E-01,-4.91601E-01, 2.13823E-01,
* 5.00134E-01, 2.17499E-01, 4.36531E-01, 0.00000E+00, 0.00000E+00,
* -5.33759E+00,-1.39053E+01,-1.91954E+01, 0.00000E+00,-8.00168E-01,
* -2.65953E-01, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 4.24063E+00, 7.14516E+00, 3.89825E-01, 3.84909E+00,-9.55319E-01,
* 2.20323E+00, 1.46817E-01, 5.46172E+00,-6.35371E-01, 6.19758E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
DO 10 I=1,3
ISDATE(I)=ISD(I)
10 CONTINUE
DO 20 I=1,2
ISTIME(I)=IST(I)
20 CONTINUE
NAME(1)='HWM8'
NAME(2)='7 '
END
*******************************************************************
C TEST DRIVER FOR GWS3 (HWM87 HORIZONTAL WIND MODEL)
DIMENSION W(2,10)
DIMENSION IDAY(10),UT(10),ALT(10),XLAT(10),XLONG(10),XLST(10),
$ F107A(10),F107(10),AP(16)
COMMON/HWMC/WBT(2),WCT(2)
DATA IDAY/172,81,8*172/
DATA UT/29000.,29000.,75000.,7*29000./
DATA ALT/400.,400.,400.,100.,6*400./
DATA XLAT/4*60.,0.,5*60./
DATA XLONG/5*-70.,0.,4*-70./
DATA XLST/6*16.,4.,3*16./
DATA F107A/7*150.,70.,150.,150./
DATA F107/8*150.,180.,150./
DATA AP/9*4.,40.,6*0/
DO 10 I=1,10
CALL GWS3(IDAY(I),UT(I),ALT(I),XLAT(I),XLONG(I),XLST(I),
$ F107A(I),F107(I),AP(I),W(1,I))
WRITE(6,100) W(1,I),WBT(1),WCT(1),W(2,I),WBT(2),WCT(2)
10 CONTINUE
WRITE(6,200) (IDAY(I),I=1,5)
WRITE(6,201) (UT(I),I=1,5)
WRITE(6,202) (ALT(I),I=1,5)
WRITE(6,203) (XLAT(I),I=1,5)
WRITE(6,204) (XLONG(I),I=1,5)
WRITE(6,205) (XLST(I),I=1,5)
WRITE(6,206) (F107A(I),I=1,5)
WRITE(6,207) (F107(I),I=1,5)
WRITE(6,210) (AP(I),I=1,5)
WRITE(6,208) (W(1,I),I=1,5)
WRITE(6,209) (W(2,I),I=1,5)
WRITE(6,200) (IDAY(I),I=6,10)
WRITE(6,201) (UT(I),I=6,10)
WRITE(6,202) (ALT(I),I=6,10)
WRITE(6,203) (XLAT(I),I=6,10)
WRITE(6,204) (XLONG(I),I=6,10)
WRITE(6,205) (XLST(I),I=6,10)
WRITE(6,206) (F107A(I),I=6,10)
WRITE(6,207) (F107(I),I=6,10)
WRITE(6,210) (AP(I),I=6,10)
WRITE(6,208) (W(1,I),I=6,10)
WRITE(6,209) (W(2,I),I=6,10)
100 FORMAT(1X,6F10.2)
200 FORMAT(//' DAY ',5I12)
201 FORMAT(' UT ',5F12.0)
202 FORMAT(' ALT ',5F12.0)
203 FORMAT(' LAT ',5F12.0)
204 FORMAT(' LONG ',5F12.0)
205 FORMAT(' LST ',5F12.0)
206 FORMAT(' F107A',5F12.0)
207 FORMAT(' F107 ',5F12.0)
210 FORMAT(' AP ',5F12.0)
208 FORMAT(/' U ',5F12.2)
209 FORMAT(' V ',5F12.2)
STOP
END
@@ -0,0 +1,576 @@
Contents: FORTRAN SUBROUTINE GWS3
FORTRAN TEST DRIVER
OUTPUT OF TEST
*******************************************************************
SUBROUTINE GWS3(IYD,SEC,ALT,GLAT,GLONG,STL,F107A,F107,AP,W)
C Horizontal wind model HWM87
C A. E. HEDIN (11/3/87)
C 10/8/88 CHANGE HANDLING OF SW(9)
C Currently intended only for winds above about 220 km.
C Calling argument list made similar to GTS5 subroutine for
C MSIS-86 density model. Some arguments not currently used but
C left in for compatability and expected use in later versions.
C INPUT:
C IYD - YEAR AND DAY AS YYDDD
C SEC - UT(SEC)
C ALT - ALTITUDE(KM) $not used$
C GLAT - GEODETIC LATITUDE(DEG)
C GLONG - GEODETIC LONGITUDE(DEG)
C STL - LOCAL APPARENT SOLAR TIME(HRS)
C F107A - 3 MONTH AVERAGE OF F10.7 FLUX $not used$
C F107 - DAILY F10.7 FLUX FOR PREVIOUS DAY $not used$
C AP - MAGNETIC INDEX(DAILY) OR WHEN SW(9)=-1. :
C AP(2)=CURRENT 3HR AP INDEX
C OUTPUT
C W(1) = MERIDIANAL (m/sec + North)
C W(2) = ZONAL (m/sec + East)
C ADDITIONAL COMMENTS
C TO TURN ON AND OFF PARTICULAR VARIATIONS CALL TSELEC(SW)
C WHERE SW IS A 25 ELEMENT ARRAY CONTAINING 0. FOR OFF, 1.
C FOR ON, OR 2. FOR MAIN EFFECTS OFF BUT CROSS TERMS ON
C FOR THE FOLLOWING VARIATIONS
C 1 - F10.7 EFFECT ON MEAN 2 - TIME INDEPENDENT
C 3 - SYMMETRICAL ANNUAL 4 - SYMMETRICAL SEMIANNUAL
C 5 - ASYMMETRICAL ANNUAL 6 - ASYMMETRICAL SEMIANNUAL
C 7 - DIURNAL 8 - SEMIDIURNAL
C 9 - DAILY AP 10 - ALL UT/LONG EFFECTS
C 11 - LONGITUDINAL 12 - UT AND MIXED UT/LONG
C 13 - MIXED AP/UT/LONG 14 - TERDIURNAL
C 24 - ALL B FIELDS (DIV) 25 - ALL C FIELDS (CURL)
C
C To get current values of SW: CALL TRETRV(SW)
C
DIMENSION AP(1),W(1),WINDF(2)
COMMON/PARMW3/PWB(150),PWC(200)
COMMON/CSW/SW(25),ISW,SWC(25)
COMMON/DATIME/ISDATE(3),ISTIME(2),NAME(2)
DATA IFL/0/
IF(IFL.EQ.1.AND.NAME(1).EQ.'HWM8'.AND.NAME(2).EQ.'7 ') GO TO 5
CALL PRMW3
IFL=1
5 CONTINUE
YRD=IYD
CALL GLOBW3(YRD,SEC,GLAT,GLONG,STL,F107A,F107,AP,PWB,PWC,WINDF)
W(1)= WINDF(1)
W(2)= WINDF(2)
RETURN
END
SUBROUTINE GLOBW3(YRD,SEC,LAT,LONG,STL,F107A,F107,AP,PB,PC,WW)
REAL LAT,LONG
DIMENSION WB(2,15),WC(2,15),PB(1),PC(1),WW(2),BT(20,20),BP(20,20)
DIMENSION AP(1),SV(25)
COMMON/CSW/SW(25),ISW,SWC(25)
COMMON/HWMC/WBT(2),WCT(2)
COMMON/WTEST/WB,WC
DATA DGTR/.017453/,SR/7.2722E-5/,HR/.2618/,DR/1.72142E-2/
DATA NSW/14/,WB/30*0/,WC/30*0/,TLL/-99./,XL/-999./,XLONG/-999./
DATA SV/25*1./,SW9/1./
G0(A)=(A-4.+(PB(26)-1.)*(A-4.+(EXP(-ABS(PB(25))*(A-4.))-1.)/
* ABS(PB(25))))
IF(ISW.NE.64999) CALL TSELEC(SV)
WB(1,11)=0
WB(2,11)=0
WB(1,12)=0
WB(2,12)=0
WB(1,13)=0
WB(2,13)=0
WC(1,11)=0
WC(2,11)=0
WC(1,12)=0
WC(2,12)=0
WC(1,13)=0
WC(2,13)=0
IF(SW(9).GT.0) SW9=1.
IF(SW(9).LT.0) SW9=-1.
IYR = YRD/1000.
DAY = YRD - IYR*1000.
IF(XL.NE.LAT) THEN
CALL VSPHER(LAT,12,3,BT,BP,20)
XL=LAT
ENDIF
IF(TLL.NE.STL) THEN
SSTL = SIN(HR*STL)
CSTL = COS(HR*STL)
S2STL = SIN(2.*HR*STL)
C2STL = COS(2.*HR*STL)
S3STL = SIN(3.*HR*STL)
C3STL = COS(3.*HR*STL)
TLL = STL
ENDIF
IF(DAY.NE.DAYL.OR.PB(14).NE.PB14) CD14=COS(DR*(DAY-PB(14)))
DAYL=DAY
PB14=PB(14)
IF(XLONG.NE.LONG) THEN
SLONG=SIN(DGTR*LONG)
CLONG=COS(DGTR*LONG)
XLONG=LONG
ENDIF
C F10.7 EFFECT
F1=1.
F2=1.
C TIME INDEPENDENT
WB(1,2)=PB(2)*BT(3,1)+PB(3)*BT(5,1)+PB(23)*BT(7,1)
WC(2,2)=-(PC(2)*BT(2,1)+PC(3)*BT(4,1)+PC(23)*BT(6,1))
$ -(PC(27)*BT(3,1)+PC(15)*BT(5,1)+PC(60)*BT(7,1)
$ +PC(161)*BT(9,1)+PC(162)*BT(11,1)+PC(163)*BT(13,1))
C ANNUAL
WB(1,5)=(PB(10)*BT(2,1)+PB(11)*BT(4,1))*CD14*F1
WC(2,5)=-(PC(10)*BT(3,1)+PC(11)*BT(5,1))*CD14*F1
C DIURNAL
WB(1,7)=(PB(7)*BT(2,2)+PB(8)*BT(4,2)+PB(29)*BT(6,2)
$ )*SSTL*F2
$ + (PB(4)*BT(2,2)+PB(5)*BT(4,2)+PB(28)*BT(6,2)
$ )*CSTL*F2
WB(2,7)=-(PB(4)*BP(2,2)+PB(5)*BP(4,2)+PB(28)*BP(6,2)
$ )*SSTL*F2
$ + (PB(7)*BP(2,2)+PB(8)*BP(4,2)+PB(29)*BP(6,2)
$ )*CSTL*F2
DCASY=1.
WC(1,7)=-(PC(4)*BP(3,2)+PC(5)*BP(5,2)+PC(28)*BP(7,2)
$ +PC(141)*BP(9,2)+PC(143)*BP(11,2)
$ +PC(181)*BP(2,2)+PC(183)*BP(4,2)+PC(185)*BP(6,2)
$ +PC(187)*BP(8,2)+PC(189)*BP(10,2)
$ +PC(12)*BP(2,2)*CD14*SWC(5)
$ )*SSTL*DCASY
$ +(PC(7)*BP(3,2)+PC(8)*BP(5,2)+PC(29)*BP(7,2)
$ +PC(142)*BP(9,2)+PC(144)*BP(11,2)
$ +PC(182)*BP(2,2)+PC(184)*BP(4,2)+PC(186)*BP(6,2)
$ +PC(188)*BP(8,2)+PC(190)*BP(10,2)
$ +PC(13)*BP(2,2)*CD14*SWC(5)
$ )*CSTL*DCASY
WC(2,7)=-(PC(7)*BT(3,2)+PC(8)*BT(5,2)+PC(29)*BT(7,2)
$ +PC(142)*BT(9,2)+PC(144)*BT(11,2)
$ +PC(182)*BT(2,2)+PC(184)*BT(4,2)+PC(186)*BT(6,2)
$ +PC(188)*BT(8,2)+PC(190)*BT(10,2)
$ +PC(13)*BT(2,2)*CD14*SWC(5)
$ )*SSTL*DCASY
$ -(PC(4)*BT(3,2)+PC(5)*BT(5,2)+PC(28)*BT(7,2)
$ +PC(141)*BT(9,2)+PC(143)*BT(11,2)
$ +PC(181)*BT(2,2)+PC(183)*BT(4,2)+PC(185)*BT(6,2)
$ +PC(187)*BT(8,2)+PC(189)*BT(10,2)
$ +PC(12)*BT(2,2)*CD14*SWC(5)
$ )*CSTL*DCASY
C SEMIDIURNAL
WB(1,8)=(PB(9)*BT(3,3)+PB(43)*BT(5,3)
$ )*S2STL*F2
$ + (PB(6)*BT(3,3)+PB(42)*BT(5,3)
$ )*C2STL*F2
WB(2,8)=-(PB(6)*BP(3,3)+PB(42)*BP(5,3)
$ )*S2STL*F2
$ + (PB(9)*BP(3,3)+PB(43)*BP(5,3)
$ )*C2STL*F2
WC(1,8)=-(PC(6)*BP(4,3)+PC(42)*BP(6,3)
$ +PC(24)*BP(3,3)*CD14*SWC(5)
$ )*S2STL*DCASY
$ + (PC(9)*BP(4,3)+PC(43)*BP(6,3)
$ +PC(34)*BP(3,3)*CD14*SWC(5)
$ )*C2STL*DCASY
$ -(PC(151)*BP(3,3)+PC(153)*BP(5,3)+PC(155)*BP(7,3)
$ +PC(157)*BP(9,3)
$ )*S2STL
$ + (PC(152)*BP(3,3)+PC(154)*BP(5,3)+PC(156)*BP(7,3)
$ +PC(158)*BP(9,3)
$ )*C2STL
WC(2,8)=-(PC(9)*BT(4,3)+PC(43)*BT(6,3)
$ +PC(34)*BT(3,3)*CD14*SWC(5)
$ )*S2STL*DCASY
$ - (PC(6)*BT(4,3)+PC(42)*BT(6,3)
$ +PC(24)*BT(3,3)*CD14*SWC(5)
$ )*C2STL*DCASY
$ -(PC(151)*BT(3,3)+PC(153)*BT(5,3)+PC(155)*BT(7,3)
$ +PC(157)*BT(9,3)
$ )*C2STL
$ -(PC(152)*BT(3,3)+PC(154)*BT(5,3)+PC(156)*BT(7,3)
$ +PC(158)*BT(9,3)
$ )*S2STL
C TERDIURNAL
WB(1,14)=(PB(40)*BT(4,4)
$ )*S3STL*F2
$ + (PB(41)*BT(4,4)
$ )*C3STL*F2
WB(2,14)=-(PB(41)*BP(4,4)
$ )*S3STL*F2
$ + (PB(40)*BP(4,4)
$ )*C3STL*F2
C MAGNETIC ACTIVITY
IF(SW9.EQ.-1.) GOTO 30
C daily AP
APD=AP(1)-4.
APDF=(APD+(PB(45)-1.)*(APD+(EXP(-PB(44)*APD)-1.)/PB(44)))
APDFC=APDF
WB(1,9)=(PB(46)*BT(3,1)+PB(35)*BT(5,1))*APDF
WC(1,9)=SWC(7)*WC(1,7)*PC(122)*APDFC
WC(2,9)=-(PC(46)*BT(2,1)+PC(35)*BT(4,1))*APDFC
$ +SWC(7)*WC(2,7)*PC(122)*APDFC
GO TO 40
30 CONTINUE
IF(PB(25).LT.1.E-4) PB(25)=1.E-4
APT=G0(AP(2))
WB(1,9)=(PB(97)*BT(3,1)+PB(55)*BT(5,1))*APT
WC(1,9)=SWC(7)*WC(1,7)*PC(129)*APT
WC(2,9)=-(PC(97)*BT(2,1)+PC(55)*BT(4,1))*APT
$ +SWC(7)*WC(2,7)*PC(129)*APT
40 CONTINUE
IF(SW(10).EQ.0) GOTO 49
C LONGITUDINAL
DLBASY=1.
WB(1,11)=(PB(91)*BT(3,2)+PB(92)*BT(5,2)+PB(93)*BT(7,2))
$ *SLONG*DLBASY
$ + (PB(65)*BT(3,2)+PB(66)*BT(5,2)+PB(67)*BT(7,2))
$ *CLONG*DLBASY
WB(2,11)=-(PB(65)*BP(3,2)+PB(66)*BP(5,2)+PB(67)*BP(7,2))
$ *SLONG*DLBASY
$ + (PB(91)*BP(3,2)+PB(92)*BP(5,2)+PB(93)*BP(7,2))
$ *CLONG*DLBASY
DLCASY=1.
WC(1,11)=-(PC(65)*BP(2,2)+PC(66)*BP(4,2)+PC(67)*BP(6,2)
$ +PC(73)*BP(8,2)+PC(74)*BP(10,2)
$ )*SLONG*DLCASY
$ + (PC(91)*BP(2,2)+PC(92)*BP(4,2)+PC(93)*BP(6,2)
$ +PC(87)*BP(8,2)+PC(88)*BP(10,2)
$ )*CLONG*DLCASY
WC(2,11)=-(PC(91)*BT(2,2)+PC(92)*BT(4,2)+PC(93)*BT(6,2)
$ +PC(87)*BT(8,2)+PC(88)*BT(10,2)
$ )*SLONG*DLCASY
$ - (PC(65)*BT(2,2)+PC(66)*BT(4,2)+PC(67)*BT(6,2)
$ +PC(73)*BT(8,2)+PC(74)*BT(10,2)
$ )*CLONG*DLCASY
C UT & MIXED UT/LONG
UTCASY=1.
WC(1,12)=(PC(77)*BP(3,3)+PC(78)*BP(5,3)+PC(79)*BP(7,3)
$ +PC(165)*BP(9,3)+PC(166)*BP(11,3)+PC(167)*BP(13,3)
$ )*COS(SR*(SEC-PC(80))+2.*DGTR*LONG)
WC(2,12)=-(PC(69)*BT(3,1)+PC(70)*BT(5,1)+PC(71)*BT(7,1)
$ +PC(116)*BT(9,1)+PC(117)*BT(11,1)+PC(118)*BT(13,1)
$ )*COS(SR*(SEC-PC(72)))*UTCASY
$ + (PC(77)*BT(3,3)+PC(78)*BT(5,3)+PC(79)*BT(7,3)
$ +PC(165)*BT(9,3)+PC(166)*BT(11,3)+PC(167)*BT(13,3)
$ )*COS(SR*(SEC-PC(80)+21600.)+2.*DGTR*LONG)
C MIXED LONG,UT,AP
IF(SW9.EQ.-1.) GO TO 45
WB(1,13)=
$ (PB(84)*BT(2,1)+PB(85)*BT(4,1)+PB(86)*BT(6,1))
$ *COS(SR*(SEC-PB(76)))*APDF*SWC(12)
WC(1,13)=SWC(11)*WC(1,11)*PC(61)*APDFC
$ +SWC(12)*WC(1,12)*PC(84)*APDFC
WC(2,13)=SWC(11)*WC(2,11)*PC(61)*APDFC
$ +SWC(12)*WC(2,12)*PC(84)*APDFC
GOTO 48
45 CONTINUE
WB(1,13)=
$ (PB(56)*BT(2,1)+PB(57)*BT(4,1)+PB(58)*BT(6,1))
$ *COS(SR*(SEC-PB(59)))*APT*SWC(12)
WC(1,13)=SWC(11)*WC(1,11)*PC(53)*APT
$ +SWC(12)*WC(1,12)*PC(56)*APT
WC(2,13)=SWC(11)*WC(2,11)*PC(53)*APT
$ +SWC(12)*WC(2,12)*PC(56)*APT
48 CONTINUE
49 CONTINUE
WBT(1)=0
WBT(2)=0
WCT(1)=0
WCT(2)=0
C SUM WINDS AND CHANGE MERIDIONAL SIGN TO + NORTH
DO 50 I=1,NSW
WBT(1)=WBT(1)-ABS(SW(I))*WB(1,I)
WCT(1)=WCT(1)-ABS(SW(I))*WC(1,I)
WBT(2)=WBT(2)+ABS(SW(I))*WB(2,I)
WCT(2)=WCT(2)+ABS(SW(I))*WC(2,I)
50 CONTINUE
WW(1)=WBT(1)*SW(24)+WCT(1)*SW(25)
WW(2)=WBT(2)*SW(24)+WCT(2)*SW(25)
RETURN
END
SUBROUTINE TSELEC(SV)
C SET SWITCHES
DIMENSION SV(1),SAV(25),SVV(1)
COMMON/CSW/SW(25),ISW,SWC(25)
DO 100 I = 1,25
SAV(I)=SV(I)
SW(I)=AMOD(SV(I),2.)
IF(ABS(SV(I)).GT.0.) THEN
SWC(I)=1.
ELSE
SWC(I)=0.
ENDIF
100 CONTINUE
ISW=64999
RETURN
ENTRY TRETRV(SVV)
DO 200 I=1,25
SVV(I)=SAV(I)
200 CONTINUE
END
SUBROUTINE VSPHER(THETA,L,M,BT,BP,LMAX)
C CALCULATE VECTOR SPHERICAL HARMONIC B FIELD THETA AND PHI
C FUNCTIONS BT,BP FOR GEOGRAPHICAL LATITUDE THETA THROUGH ORDER L,M
C BT(L+1,M+1)= [(L-M+1) P(L+1,M) - (L+1) P(L,M) SIN(THETA)] /
C [SQRT(L(L+1)) COS(THETA)]
C BP(L+1,M+1)= M P(L,M) /[SQRT(L(L+1)) COS(THETA)]
C RESULT FOR GIVEN L,M SAVED IN BT AND BP AT ONE HIGHER INDEX NUM
DIMENSION BT(LMAX,1),BP(LMAX,1),PLG(20,20)
DATA DGTR/1.74533E-2/
IF(M.GT.L.OR.L.GT.LMAX-1) THEN
WRITE(6,99) L,M,LMAX
99 FORMAT(1X,'ILLEGAL INDICIES TO VSPHER',3I5)
RETURN
ENDIF
BT(1,1)=0
BP(1,1)=0
IF(L.EQ.0.AND.M.EQ.0) RETURN
CALL LEGPOL(THETA,L+1,M,PLG,20)
C=SIN(THETA*DGTR)
S=COS(THETA*DGTR)
IF(ABS(S).LT.1.E-5) THEN
S=0
IC=SIGN(1,IFIX(THETA))
ENDIF
DO 20 LL=1,L
SQT=SQRT(FLOAT(LL)*(FLOAT(LL)+1))
LMX=MIN(LL,M)
DO 10 MM=0,LMX
IF(S.EQ.0) THEN
IF(MM.NE.1) THEN
BT(LL+1,MM+1)=0
BP(LL+1,MM+1)=0
ELSE
BT(LL+1,MM+1)=(LL*(LL+1)*(LL+2)*.5*(IC)**(LL+2)
$ -(LL+1)*C*LL*(LL+1)*.5*(IC)**(LL+1))/SQT
BP(LL+1,MM+1)=MM*LL*(LL+1)*.5*(IC)**(LL+1)/SQT
ENDIF
ELSE
BT(LL+1,MM+1)=((LL-MM+1)*PLG(LL+2,MM+1)
$ -(LL+1)*C*PLG(LL+1,MM+1))/(S*SQT)
BP(LL+1,MM+1)=MM*PLG(LL+1,MM+1)/(S*SQT)
ENDIF
10 CONTINUE
20 CONTINUE
END
SUBROUTINE LEGPOL(GLAT,L,M,PLG,LMAX)
C CALCULATE LEGENDRE POLYNOMIALS PLG(L+1,M+1) FOR GEOGRAPHICAL
C LATITUDE GLAT THROUGH ORDER L,M
DIMENSION PLG(LMAX,1)
DATA DGTR/1.74533E-2/
IF(M.GT.L.OR.L.GT.LMAX-1) THEN
WRITE(6,99) L,M,LMAX
99 FORMAT(1X,'ILLEGAL INDICIES TO LEGPOL',3I5)
RETURN
ENDIF
PLG(1,1)=1.
IF(L.EQ.0.AND.M.EQ.0) RETURN
C=SIN(GLAT*DGTR)
S=COS(GLAT*DGTR)
C CALCULATE L=M CASE AND L=M+1
DO 10 MM=0,M
IF(MM.GT.0) PLG(MM+1,MM+1)=PLG(MM,MM)*(2.*MM-1.)*S
IF(L.GT.MM) PLG(MM+2,MM+1)=PLG(MM+1,MM+1)*(2.*MM+1)*C
10 CONTINUE
IF(L.EQ.1) RETURN
MMX=MIN(M,L-2)
DO 30 MM=0,MMX
DO 20 LL=MM+2,L
PLG(LL+1,MM+1)=((2.*LL-1.)*C*PLG(LL,MM+1)-
$ (LL+MM-1.)*PLG(LL-1,MM+1))/(LL-MM)
20 CONTINUE
30 CONTINUE
RETURN
END
SUBROUTINE PRMW3
C HWM87 4-NOV-87
DIMENSION ISD(3),IST(2)
COMMON/PARMB/GSURF,RE
COMMON/PARMW3/PWB1(50),PWB2(50),PWB3(50),PWC1(50),
* PWC2(50),PWC3(50),PWC4(50)
COMMON/DATIME/ISDATE(3),ISTIME(2),NAME(2)
DATA GSURF,RE/980.665,6356.77/
DATA ISD/' 4-N','OV-8','7 '/,IST/'17:3','9:09'/
DATA NAME/'HWM8','7 '/
C IRROTATIONAL WIND FIELD (DIVERGENCE FIELD)
DATA PWB1/
* 0.00000E+00,-1.11368E+01,-1.24858E+01, 1.10036E+02, 5.72915E+00,
* 6.27672E+00, 7.79161E+01, 2.26817E+00, 1.48345E+00, 5.82466E+01,
* 0.00000E+00, 0.00000E+00, 0.00000E+00,-1.41351E+01, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 1.59211E+01, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 4.01565E-02,
* 8.29674E-02, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 3.36523E+01, 0.00000E+00, 0.00000E+00,-1.38693E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 3.76631E+00,-2.15251E+00,
* -8.60431E-01, 0.00000E+00, 0.00000E+00, 4.15805E-02, 1.05645E-01,
* -1.42416E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
DATA PWB2/
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,-1.55057E+00,
* 2.24596E+00, 3.33952E+00, 0.00000E+00, 1.81985E+04, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00,-1.50640E+02,-4.30700E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 1.61029E+04, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* -2.42610E+04, 0.00000E+00, 0.00000E+00, 0.00000E+00,-1.46241E+04,
* 0.00000E+00, 0.00000E+00, 0.00000E+00,-2.29211E+00,-3.23009E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 5.12558E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00,-2.07665E+00,-1.67008E+02, 0.00000E+00, 0.00000E+00/
DATA PWB3/
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00,-8.48854E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 4.75654E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 6.85704E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 1.47178E+01, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
C SOLENOIDAL WIND FIELD (CURL FIELD)
DATA PWC1/
* 0.00000E+00,-5.26044E-01,-4.29072E+01, 2.44965E+01,-1.29728E+01,
* 0.00000E+00, 3.82628E+01, 5.69565E+00, 0.00000E+00, 5.21497E+01,
* 0.00000E+00,-1.13601E+01,-6.45490E+00,-8.45400E+00,-4.07973E+00,
* 0.00000E+00, 0.00000E+00, 1.05267E+02, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00,-3.77522E+01,-4.06479E+00, 1.32400E-01,
* 2.13300E-01,-7.54067E+00,-5.54014E-01, 1.05543E+01, 0.00000E+00,
* 0.00000E+00,-1.57793E+02, 0.00000E+00,-4.48707E+00,-3.70910E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 1.13100E-01, 1.69100E-01,
* -2.29760E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
DATA PWC2/
* 0.00000E+00, 0.00000E+00, 5.37245E-02, 0.00000E+00,-3.78497E+00,
* 6.88459E-02, 0.00000E+00, 0.00000E+00, 0.00000E+00,-1.44635E+01,
* 5.43764E-02, 0.00000E+00, 0.00000E+00, 0.00000E+00,-6.94340E+00,
* -7.24977E+00,-4.85673E+00, 0.00000E+00,-3.60101E+00,-2.23183E+01,
* -5.12095E+01, 3.85590E+04,-1.33714E+00,-7.45792E-01, 0.00000E+00,
* -5.90503E+03, 5.89137E-01,-1.06978E+00,-9.62826E-01, 2.76396E+04,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 4.72006E-02, 0.00000E+00,
* 0.00000E+00, 5.34227E+00, 2.11187E+00, 0.00000E+00, 0.00000E+00,
* -4.35022E-01, 7.38162E+00, 6.74852E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00,-2.56217E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
DATA PWC3/
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* -4.92677E+01,-4.23828E+01, 0.00000E+00,-1.50460E+02, 0.00000E+00,
* 0.00000E+00, 1.25104E-02, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 2.47276E-02, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 5.29549E-01,
* 6.93886E-01, 7.47271E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
DATA PWC4/
* 3.28297E-01, 3.05222E+00,-2.57528E-01,-4.91601E-01, 2.13823E-01,
* 5.00134E-01, 2.17499E-01, 4.36531E-01, 0.00000E+00, 0.00000E+00,
* -5.33759E+00,-1.39053E+01,-1.91954E+01, 0.00000E+00,-8.00168E-01,
* -2.65953E-01, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 4.24063E+00, 7.14516E+00, 3.89825E-01, 3.84909E+00,-9.55319E-01,
* 2.20323E+00, 1.46817E-01, 5.46172E+00,-6.35371E-01, 6.19758E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00,
* 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00, 0.00000E+00/
DO 10 I=1,3
ISDATE(I)=ISD(I)
10 CONTINUE
DO 20 I=1,2
ISTIME(I)=IST(I)
20 CONTINUE
NAME(1)='HWM8'
NAME(2)='7 '
END
*******************************************************************
C TEST DRIVER FOR GWS3 (HWM87 HORIZONTAL WIND MODEL)
DIMENSION W(2,10)
DIMENSION IDAY(10),UT(10),ALT(10),XLAT(10),XLONG(10),XLST(10),
$ F107A(10),F107(10),AP(16)
COMMON/HWMC/WBT(2),WCT(2)
DATA IDAY/172,81,8*172/
DATA UT/29000.,29000.,75000.,7*29000./
DATA ALT/400.,400.,400.,100.,6*400./
DATA XLAT/4*60.,0.,5*60./
DATA XLONG/5*-70.,0.,4*-70./
DATA XLST/6*16.,4.,3*16./
DATA F107A/7*150.,70.,150.,150./
DATA F107/8*150.,180.,150./
DATA AP/9*4.,40.,6*0/
DO 10 I=1,10
CALL GWS3(IDAY(I),UT(I),ALT(I),XLAT(I),XLONG(I),XLST(I),
$ F107A(I),F107(I),AP(I),W(1,I))
WRITE(6,100) W(1,I),WBT(1),WCT(1),W(2,I),WBT(2),WCT(2)
10 CONTINUE
WRITE(6,200) (IDAY(I),I=1,5)
WRITE(6,201) (UT(I),I=1,5)
WRITE(6,202) (ALT(I),I=1,5)
WRITE(6,203) (XLAT(I),I=1,5)
WRITE(6,204) (XLONG(I),I=1,5)
WRITE(6,205) (XLST(I),I=1,5)
WRITE(6,206) (F107A(I),I=1,5)
WRITE(6,207) (F107(I),I=1,5)
WRITE(6,210) (AP(I),I=1,5)
WRITE(6,208) (W(1,I),I=1,5)
WRITE(6,209) (W(2,I),I=1,5)
WRITE(6,200) (IDAY(I),I=6,10)
WRITE(6,201) (UT(I),I=6,10)
WRITE(6,202) (ALT(I),I=6,10)
WRITE(6,203) (XLAT(I),I=6,10)
WRITE(6,204) (XLONG(I),I=6,10)
WRITE(6,205) (XLST(I),I=6,10)
WRITE(6,206) (F107A(I),I=6,10)
WRITE(6,207) (F107(I),I=6,10)
WRITE(6,210) (AP(I),I=6,10)
WRITE(6,208) (W(1,I),I=6,10)
WRITE(6,209) (W(2,I),I=6,10)
100 FORMAT(1X,6F10.2)
200 FORMAT(//' DAY ',5I12)
201 FORMAT(' UT ',5F12.0)
202 FORMAT(' ALT ',5F12.0)
203 FORMAT(' LAT ',5F12.0)
204 FORMAT(' LONG ',5F12.0)
205 FORMAT(' LST ',5F12.0)
206 FORMAT(' F107A',5F12.0)
207 FORMAT(' F107 ',5F12.0)
210 FORMAT(' AP ',5F12.0)
208 FORMAT(/' U ',5F12.2)
209 FORMAT(' V ',5F12.2)
STOP
END
*******************************************************************
Output of test program
69.82 50.44 19.38 -72.12 27.40 -99.53
86.78 69.62 17.16 -50.97 27.40 -78.37
99.88 50.44 49.44 -117.57 27.40 -144.97
69.82 50.44 19.38 -72.12 27.40 -99.53
-27.19 -48.81 21.62 -59.95 -4.91 -55.04
86.01 49.23 36.78 -63.09 35.27 -98.37
-105.90 -105.33 -0.57 -100.31 -47.40 -52.91
69.82 50.44 19.38 -72.12 27.40 -99.53
69.82 50.44 19.38 -72.12 27.40 -99.53
79.70 61.17 18.53 -155.92 27.40 -183.33
DAY 172 81 172 172 172
UT 29000. 29000. 75000. 29000. 29000.
ALT 400. 400. 400. 100. 400.
LAT 60. 60. 60. 60. 0.
LONG -70. -70. -70. -70. -70.
LST 16. 16. 16. 16. 16.
F107A 150. 150. 150. 150. 150.
F107 150. 150. 150. 150. 150.
AP 4. 4. 4. 4. 4.
U 69.82 86.78 99.88 69.82 -27.19
V -72.12 -50.97 -117.57 -72.12 -59.95
DAY 172 172 172 172 172
UT 29000. 29000. 29000. 29000. 29000.
ALT 400. 400. 400. 400. 400.
LAT 60. 60. 60. 60. 60.
LONG 0. -70. -70. -70. -70.
LST 16. 4. 16. 16. 16.
F107A 150. 150. 70. 150. 150.
F107 150. 150. 150. 180. 150.
AP 4. 4. 4. 4. 40.
U 86.01 -105.90 69.82 69.82 79.70
V -63.09 -100.31 -72.12 -72.12 -155.92
*******************************************************************
@@ -0,0 +1,55 @@
C TEST DRIVER FOR GWS3 (HWM87 HORIZONTAL WIND MODEL)
DIMENSION W(2,10)
DIMENSION IDAY(10),UT(10),ALT(10),XLAT(10),XLONG(10),XLST(10),
$ F107A(10),F107(10),AP(16)
COMMON/HWMC/WBT(2),WCT(2)
DATA IDAY/172,81,8*172/
DATA UT/29000.,29000.,75000.,7*29000./
DATA ALT/400.,400.,400.,100.,6*400./
DATA XLAT/4*60.,0.,5*60./
DATA XLONG/5*-70.,0.,4*-70./
DATA XLST/6*16.,4.,3*16./
DATA F107A/7*150.,70.,150.,150./
DATA F107/8*150.,180.,150./
DATA AP/9*4.,40.,6*0/
DO 10 I=1,10
CALL GWS3(IDAY(I),UT(I),ALT(I),XLAT(I),XLONG(I),XLST(I),
$ F107A(I),F107(I),AP(I),W(1,I))
WRITE(6,100) W(1,I),WBT(1),WCT(1),W(2,I),WBT(2),WCT(2)
10 CONTINUE
WRITE(6,200) (IDAY(I),I=1,5)
WRITE(6,201) (UT(I),I=1,5)
WRITE(6,202) (ALT(I),I=1,5)
WRITE(6,203) (XLAT(I),I=1,5)
WRITE(6,204) (XLONG(I),I=1,5)
WRITE(6,205) (XLST(I),I=1,5)
WRITE(6,206) (F107A(I),I=1,5)
WRITE(6,207) (F107(I),I=1,5)
WRITE(6,210) (AP(I),I=1,5)
WRITE(6,208) (W(1,I),I=1,5)
WRITE(6,209) (W(2,I),I=1,5)
WRITE(6,200) (IDAY(I),I=6,10)
WRITE(6,201) (UT(I),I=6,10)
WRITE(6,202) (ALT(I),I=6,10)
WRITE(6,203) (XLAT(I),I=6,10)
WRITE(6,204) (XLONG(I),I=6,10)
WRITE(6,205) (XLST(I),I=6,10)
WRITE(6,206) (F107A(I),I=6,10)
WRITE(6,207) (F107(I),I=6,10)
WRITE(6,210) (AP(I),I=6,10)
WRITE(6,208) (W(1,I),I=6,10)
WRITE(6,209) (W(2,I),I=6,10)
100 FORMAT(1X,6F10.2)
200 FORMAT(//' DAY ',5I12)
201 FORMAT(' UT ',5F12.0)
202 FORMAT(' ALT ',5F12.0)
203 FORMAT(' LAT ',5F12.0)
204 FORMAT(' LONG ',5F12.0)
205 FORMAT(' LST ',5F12.0)
206 FORMAT(' F107A',5F12.0)
207 FORMAT(' F107 ',5F12.0)
210 FORMAT(' AP ',5F12.0)
208 FORMAT(/' U ',5F12.2)
209 FORMAT(' V ',5F12.2)
STOP
END
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,3 @@
LIBNAME = librockflight.a
LIBOBJS = eom.o atmos.o aero.o engine.o mass.o stage.o rocket.o\
evaluate_function.o
@@ -0,0 +1,69 @@
#include <stdio.h>
#include <math.h>
#include "librockflight/include/state.h"
#include "mass.h"
/* compute rocket mass */
int mass(rocket_t *r, double *t)
{
int i, j;
double tref = 0.0; /* this is the absolute time where the current stage
were activate */
state_t *s;
engine_t *e;
s = &(r->state);
s->m = 0;
/* the active stage is s->s */
if (s->s > r->n_stage - 1)
{
printf("active stage do not exist...\n");
return -1;
}
tref = 0;
for (i = 0; i < s->s; i++)
tref += r->stage_properties[i].active_time;
/* we start from the last stage down to the active stage to add masses */
for (i = r->n_stage - 1; i > s->s; i--)
{
s->m += r->stage_properties[i].dry_mass;
for (j = 0; j < r->stage_properties[i].n_engine; j++)
{
e = r->stage_properties[i].engines + j;
s->m += e->dry_mass;
s->m += e->propellant_mass;
}
}
/* printf("i = %d, tref = %5.2f\n", i, tref);*/
s->m += r->stage_properties[i].dry_mass;
for (j = 0; j < r->stage_properties[i].n_engine; j++)
{
e = r->stage_properties[i].engines + j;
if (*t < tref + e->drop_time)
{
s->m += e->dry_mass;
if (*t < tref + e->start_time)
s->m += e->propellant_mass;
else /* linear interpolation of the propellant_mass */
s->m += e->propellant_mass *
(1 - (*t - tref - e->start_time)/e->burn_time);
}
}
return 0;
}
@@ -0,0 +1,7 @@
#ifndef __mass_h__
#define __mass_h__
int mass(rocket_t *r, double *t);
#endif __mass_h__
@@ -0,0 +1,25 @@
eom : equations of motion
aero : compute aerodynamic forces and moments on rocket
compute engine thrust at a given time
int engine(double time, double *y, state_t *s)
How to represent a rocket engine or booster
- propellant_mass
- thrust vs time data
- constant thrust
- mass of propellant expelled linear with burn time ?
- constant mass flow rate
- mass flow rate in linear relation with thrust
- thrust is in the direction of rocket
- thrust is not in the direction of rocket
- position of the exit plane of the nozzle (with reference to CG)
- direction vector of the thrust
atmos : atmosphere model
mass : compute mass the mass of the rocket at a given time
@@ -0,0 +1,40 @@
#include <stdlib.h>
#include "rocket.h"
int initialize_flight (flight_t *flight, int n_stages)
{
int i;
flight = (flight_t *) malloc (sizeof(flight_t));
if (flight == NULL)
return -1;
flight->n_stages = n_stages;
flight->stages = malloc (sizeof(stage_t));
if (flight->stages == NULL)
return -1;
for (i = 0; i < n_stages; i++)
{
flight->stages[i].is_set = 0;
}
return 0;
}
int set_stages (flight_t *flight, int stage, float dry_mass,
float start_time, float burn_time, float drop_time,
float propellant_mass, float thrust, float Isp)
{
flight->stages[stage].is_set = 1;
flight->stages[stage].dry_mass = dry_mass;
flight->stages[stage].start_time = start_time;
flight->stages[stage].burn_time = burn_time;
flight->stages[stage].drop_time = drop_time;
flight->stages[stage].propellant_mass = propellant_mass;
flight->stages[stage].thrust = thrust;
flight->stages[stage].Isp = Isp;
return 0;
}
@@ -0,0 +1,44 @@
#ifndef __stage_h__
#define __stage_h__
typedef struct stage
{
int is_set;
/* engine properties */
float propellant_mass;
float thrust;
float Isp;
/* flight profile */
float start_time;
float burn_time;
float drop_time;
/* inertial properties */
float dry_mass;
float Ix;
float Iy;
float Iz;
/* aerodynamic properties */
float Cdrag;
float Clift;
float Cbeta;
float Cspin;
float Cmoment;
float Cdamping;
float Diameter;
} stage_t;
typedef struct flight
{
int n_stages;
stage_t *stages;
} flight_t;
#endif __stage_h__
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <math.h>
#include "librockflight/include/state.h"
#include "stage.h"
/* find the actual stage */
/* this routine should be optimized ! */
int stage(rocket_t *r, double *t)
{
int i, j;
state_t *s;
double time = 0.0;
s = &(r->state);
for (i = 0; i < r->n_stage; i++)
{
if ( i == r->n_stage - 1)
{
/* the last stage could not be drop, so it is necesseraly active
if all the other one are not*/
s->s = i;
return 0;
}
time += r->stage_properties[i].active_time;
if (*t < time)
{
s->s = i;
return 0;
}
}
return 0;
}
@@ -0,0 +1,8 @@
#ifndef __stage_h__
#define __stage_h__
int stage(rocket_t *r, double *t);
#endif __stage_h__
@@ -0,0 +1,2 @@
ROOT = ../../..
include $(ROOT)/config/presrc.mk
@@ -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 "libcpropep/include/equilibrium.h"
#include "libcpropep/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,3 @@
ROOT = ../../../..
include $(ROOT)/config/makedef
include $(ROOT)/config/libsrc.mk
@@ -0,0 +1,521 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libcpropep/include/equilibrium.h"
#include "libthermo/include/load.h"
#include "libthermo/include/thermo.h"
#include "libcpropep/include/conversion.h"
#include "libcpropep/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,2 @@
LIBNAME = libthermo.a
LIBOBJS = load.o thermo.o
@@ -0,0 +1,563 @@
/* thermo.c - Compute thermodynamic properties of individual
species and composition of species */
/* $Id: thermo.c,v 1.1.1.1 2001/07/20 03:19:13 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 "libthermo/include/thermo.h"
#include "libcompat/include/compat.h"
#include "libcpropep/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;
}