Initial commit of "Rocket Workbench".
Taken from sources in CVS at:
https://sourceforge.net/projects/rocketworkbench/
Sources extracted in two steps:
1. Pull entire project tree into a subdir "rwb" via "rsync":
rsync -a a.cvs.sourceforge.net::cvsroot/rocketworkbench/ rwb/.
2. Export sources:
export CVSROOT=$(pwd)/rwb
SUBDIRS="analyser cpropep cpropep-web CVSROOT data libcompat libcpropep libnum libsimulation libthermo prop rocketworkbench rockflight"
mkdir rwbx; cd rwbx
cvs export -D now ${SUBDIRS}
After this (and some backups for safety), the directory content was
added to a Git repo:
git init .
git add *
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
all:
|
||||
@echo " --------------------"
|
||||
@echo " Building analyser..."
|
||||
@echo " --------------------"
|
||||
@$(MAKE) --no-print-directory -C analyser all
|
||||
|
||||
@echo " -------------------"
|
||||
@echo " Building cpropep..."
|
||||
@echo " -------------------"
|
||||
@$(MAKE) --no-print-directory -C cpropep all
|
||||
|
||||
# @echo " Building cpropep-2..."
|
||||
# @$(MAKE) --no-print-directory -C cpropep-2 all
|
||||
|
||||
@echo " -----------------------"
|
||||
@echo " Building cpropep-web..."
|
||||
@echo " -----------------------"
|
||||
@$(MAKE) --no-print-directory -C cpropep-web all
|
||||
|
||||
@echo " ---------------"
|
||||
@echo " Building gba..."
|
||||
@echo " ---------------"
|
||||
@$(MAKE) --no-print-directory -C gba all
|
||||
|
||||
# @echo " Building grainanalysis..."
|
||||
# @$(MAKE) --no-print-directory -C grainanalysis all
|
||||
|
||||
@echo " ---------------"
|
||||
@echo " Building lrd..."
|
||||
@echo " ---------------"
|
||||
@$(MAKE) --no-print-directory -C lrd all
|
||||
|
||||
@echo " -------------------"
|
||||
@echo " Building lrd-web..."
|
||||
@echo " -------------------"
|
||||
@$(MAKE) --no-print-directory -C lrd-web all
|
||||
|
||||
@echo " ---------------"
|
||||
@echo " Building mcp..."
|
||||
@echo " ---------------"
|
||||
@$(MAKE) --no-print-directory -C mcp all
|
||||
|
||||
@echo " --------------------"
|
||||
@echo " Building profiler..."
|
||||
@echo " --------------------"
|
||||
@$(MAKE) --no-print-directory -C profiler all
|
||||
|
||||
@echo " ----------------"
|
||||
@echo " Building prop..."
|
||||
@echo " ----------------"
|
||||
@$(MAKE) --no-print-directory -C prop all
|
||||
|
||||
@echo " ----------------------"
|
||||
@echo " Building rockflight..."
|
||||
@echo " ----------------------"
|
||||
@$(MAKE) --no-print-directory -C rockflight all
|
||||
|
||||
clean:
|
||||
@echo " Cleaning analyser..."
|
||||
@$(MAKE) --no-print-directory -C analyser clean
|
||||
@echo " Cleaning cpropep..."
|
||||
@$(MAKE) --no-print-directory -C cpropep clean
|
||||
# @echo " Cleaning cpropep-2..."
|
||||
# @$(MAKE) --no-print-directory -C cpropep-2 clean
|
||||
@echo " Cleaning cpropep-web..."
|
||||
@$(MAKE) --no-print-directory -C cpropep-web clean
|
||||
@echo " Cleaning gba..."
|
||||
@$(MAKE) --no-print-directory -C gba clean
|
||||
# @echo " Cleaning grainanalysis..."
|
||||
# @$(MAKE) --no-print-directory -C grainanalysis clean
|
||||
@echo " Cleaning lrd..."
|
||||
@$(MAKE) --no-print-directory -C lrd clean
|
||||
@echo " Cleaning lrd-web..."
|
||||
@$(MAKE) --no-print-directory -C lrd-web clean
|
||||
@echo " Cleaning mcp..."
|
||||
@$(MAKE) --no-print-directory -C mcp clean
|
||||
@echo " Cleaning profiler..."
|
||||
@$(MAKE) --no-print-directory -C profiler clean
|
||||
@echo " Cleaning prop..."
|
||||
@$(MAKE) --no-print-directory -C prop clean
|
||||
@echo " Cleaning rockflight..."
|
||||
@$(MAKE) --no-print-directory -C rockflight clean
|
||||
|
||||
install:
|
||||
@$(MAKE) --no-print-directory -C analyser install
|
||||
@$(MAKE) --no-print-directory -C cpropep install
|
||||
@$(MAKE) --no-print-directory -C cpropep-2 install
|
||||
@$(MAKE) --no-print-directory -C cpropep-web install
|
||||
@$(MAKE) --no-print-directory -C gba install
|
||||
@$(MAKE) --no-print-directory -C grainanalysis install
|
||||
@$(MAKE) --no-print-directory -C lrd install
|
||||
@$(MAKE) --no-print-directory -C lrd-web install
|
||||
@$(MAKE) --no-print-directory -C mcp install
|
||||
@$(MAKE) --no-print-directory -C profiler install
|
||||
@$(MAKE) --no-print-directory -C prop install
|
||||
@$(MAKE) --no-print-directory -C rockflight install
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
@@ -0,0 +1,371 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
/*#include <unistd.h>*/
|
||||
#include <math.h>
|
||||
|
||||
/* Numerical method library */
|
||||
#include "libnum/include/num.h"
|
||||
/* Config file parser library */
|
||||
#include "gpcp/src/gpcp.h"
|
||||
/* Conversion library */
|
||||
#include "libconvert/include/convert.h"
|
||||
|
||||
#include "libcompat/include/getopt.h"
|
||||
|
||||
#include "analyser.h"
|
||||
|
||||
#define MAX_LINE 100
|
||||
|
||||
Options analyser_options[] = {
|
||||
{"datafile", STRING, NULL},
|
||||
{"format", PARENT, NULL},
|
||||
{"column", INTEGER, "format"},
|
||||
{"time", PARENT, "format"},
|
||||
{"col", INTEGER, "time"},
|
||||
{"units", STRING, "time"},
|
||||
{"thrust", PARENT, "format"},
|
||||
{"col", INTEGER, "thrust"},
|
||||
{"units", STRING, "thrust"},
|
||||
{"comments", STRING, "format"},
|
||||
{"motor", PARENT, NULL},
|
||||
{"propellant_mass", PARENT, "motor"},
|
||||
{"val", FLOAT, "propellant_mass"},
|
||||
{"units", STRING, "propellant_mass"},
|
||||
{"total_mass", PARENT, "motor"},
|
||||
{"val", FLOAT, "total_mass"},
|
||||
{"units", STRING, "total_mass"},
|
||||
{NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n, c;
|
||||
|
||||
char *datafile; /* Name of the datafile */
|
||||
double *data = NULL; /* Array containing the data read in the data file */
|
||||
|
||||
format_t format;
|
||||
motor_t motor;
|
||||
results_t results;
|
||||
|
||||
/* Name of the config file */
|
||||
char filename[FILENAME_MAX] = "\0";
|
||||
|
||||
GPCP_RegisterOptions(analyser_options);
|
||||
|
||||
/* Read the command line arguments */
|
||||
while (1)
|
||||
{
|
||||
c = getopt(argc, argv, "f:");
|
||||
if (c == EOF)
|
||||
break;
|
||||
switch (c)
|
||||
{
|
||||
case 'f':
|
||||
strncpy(filename, optarg, FILENAME_MAX);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (filename[0] =='\0')
|
||||
{
|
||||
printf("A config file must be specified.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (parse_config(filename, &datafile, &format, &motor))
|
||||
return 1;
|
||||
|
||||
if (parse_datafile(datafile, &data, &n, &format))
|
||||
return 1;
|
||||
|
||||
analyse_data(data, n, &results, &format, &motor);
|
||||
print_results(&results);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_results(results_t *res)
|
||||
{
|
||||
printf("Results of thrust data analysis.\n");
|
||||
printf("--------------------------------\n");
|
||||
printf("Maximum thrust : %.2f N\n", res->max_thrust);
|
||||
printf("Total impulse : %.2f Ns\n", res->impulse);
|
||||
printf("Average thrust : %.2f N\n", res->avg_thrust);
|
||||
printf("Burn time : %.2f s\n", res->burn_time);
|
||||
printf("Exhaust velocity : %.2f m/s\n", res->vg);
|
||||
printf("Specific impulse : %.2f s\n", res->isp);
|
||||
printf("Propellant mass fraction : %.2f \n", res->prop_mass_fraction);
|
||||
printf("Impulse to weight ratio : %.2f \n", res->impulse_to_weight);
|
||||
/* I will have to invert thrust and impulse in the definition*/
|
||||
printf("Motor classification : %c-%d\n",
|
||||
'A' + (char) (log(res->max_thrust/2.5)/log(2)) + 1,
|
||||
(int) res->impulse);
|
||||
}
|
||||
|
||||
int analyse_data(double *data, int n, results_t *res, format_t *f, motor_t *m)
|
||||
{
|
||||
int i;
|
||||
double max;
|
||||
double integral;
|
||||
|
||||
/* Calculation based on those data */
|
||||
/*double max_thrust;*/ /* Maximum thrust */
|
||||
/*double avg_thrust;*/ /* Mean thrust */
|
||||
/*double burn_time;*/ /* Burning time */
|
||||
/*double impulse;*/ /* Total impulse */
|
||||
/*double vg;*/ /* Exhaust velocity */
|
||||
/*double isp;*/ /* Specific impulse */
|
||||
/*double prop_mass_fraction;*/ /* Propellant mass fraction */
|
||||
/*double impulse_to_weight;*/ /* Impulse to weight ratio */
|
||||
|
||||
memset(res, 0x00, sizeof(results_t));
|
||||
|
||||
max = 0;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
max = ((data[1 + i*f->col] > max) ? data[1 + i*f->col] : max);
|
||||
}
|
||||
|
||||
res->max_thrust = max;
|
||||
res->burn_time = data[0 + (n - 1)*f->col];
|
||||
|
||||
simpson(data, n, 2, 1, &integral);
|
||||
|
||||
res->impulse = integral;
|
||||
res->avg_thrust = res->impulse / res->burn_time;
|
||||
|
||||
if (m->isprop)
|
||||
{
|
||||
res->vg = res->impulse / m->prop_mass;
|
||||
res->isp = res->vg / 9.80665;
|
||||
}
|
||||
if (m->isprop && m->istot)
|
||||
{
|
||||
res->prop_mass_fraction = m->prop_mass / m->total_mass;
|
||||
res->impulse_to_weight = res->impulse / (m->total_mass * 9.80665);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_datafile(char *datafile, double **data, int *ndata, format_t *f)
|
||||
{
|
||||
FILE *inputfile;
|
||||
|
||||
int i, n;
|
||||
|
||||
char *token;
|
||||
char line[MAX_LINE];
|
||||
|
||||
double *tmp;
|
||||
|
||||
if ((inputfile = fopen(datafile, "r")) == NULL)
|
||||
{
|
||||
printf("Unable to open datafile.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmp = (double *) malloc (sizeof(double) * f->col);
|
||||
|
||||
/* Reading file */
|
||||
n = 0;
|
||||
while (fgets(line, MAX_LINE, inputfile) != NULL)
|
||||
{
|
||||
if (line[0] != f->comments[0]) /* comments */
|
||||
{
|
||||
token = strtok(line, " \t");
|
||||
|
||||
if (!isdigit(token[0])) /* no number on this line, skip... */
|
||||
continue;
|
||||
|
||||
tmp[0] = atof(token);
|
||||
|
||||
for (i = 1; i < f->col; i++)
|
||||
{
|
||||
token = strtok(NULL, " \t");
|
||||
if (!isdigit(token[0])) /* error, there is missing number
|
||||
on this line */
|
||||
return -1;
|
||||
|
||||
tmp[i] = atof(token);
|
||||
}
|
||||
|
||||
/* reallocating the memory */
|
||||
*data = (double *) realloc(*data, sizeof(double) * 2 * (n + 1));
|
||||
|
||||
(*data)[0 + n*f->col] = tmp[f->time - 1] * f->sctime;
|
||||
(*data)[1 + n*f->col] = tmp[f->thrust - 1] * f->scthrust;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
*ndata = n;
|
||||
|
||||
fclose(inputfile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_config(char *configfile, char **datafile, format_t *f, motor_t *m)
|
||||
{
|
||||
char *tmp;
|
||||
float number;
|
||||
double dtmp;
|
||||
|
||||
Data *config;
|
||||
|
||||
/* read the file */
|
||||
if (GPCP_ReadFile(configfile, &config) != 0)
|
||||
{
|
||||
printf("Error reading config file.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Use config data (we must provide string length*/
|
||||
if (GPCP_GetValue ("datafile", datafile) != 0)
|
||||
{
|
||||
printf("A 'datafile' must be specified.\n");
|
||||
return 1;
|
||||
}
|
||||
if (GPCP_EnterLevel("format", 0) != 0)
|
||||
{
|
||||
printf("The file format must be specified.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue ("column", &f->col) != 0)
|
||||
{
|
||||
printf("Unable to get number of column.\n");
|
||||
return 1;
|
||||
}
|
||||
if (GPCP_GetValue ("comments", &f->comments) != 0)
|
||||
{
|
||||
printf("No 'comments' sign specified: assuming '#'.\n");
|
||||
strcpy(f->comments, "#");
|
||||
}
|
||||
if (GPCP_EnterLevel("time", 0) == -1)
|
||||
{
|
||||
printf("Unable to get time information.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue ("col", &f->time) != 0)
|
||||
{
|
||||
printf("Unable to get time column index.\n");
|
||||
return 1;
|
||||
}
|
||||
if (GPCP_GetValue ("units", &tmp) != 0)
|
||||
{
|
||||
printf("Unable to get units.\n");
|
||||
return 1;
|
||||
}
|
||||
f->sctime = 1;
|
||||
free(tmp);
|
||||
GPCP_ExitLevel();
|
||||
}
|
||||
if (GPCP_EnterLevel("thrust", 0) == -1)
|
||||
{
|
||||
printf("Unable to get thrust information.\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue ("col", &f->thrust) != 0)
|
||||
{
|
||||
printf("Unable to get time column index.\n");
|
||||
return 1;
|
||||
}
|
||||
if (GPCP_GetValue ("units", &tmp) != 0)
|
||||
{
|
||||
printf("Unable to get units.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dtmp = 1.0;
|
||||
/*convert("force", &(f->scthrust), tmp, "N");*/
|
||||
convert(&dtmp, tmp, "N", &(f->scthrust));
|
||||
|
||||
free(tmp);
|
||||
|
||||
GPCP_ExitLevel();
|
||||
}
|
||||
GPCP_ExitLevel();
|
||||
}
|
||||
|
||||
m->isprop = 0;
|
||||
m->istot = 0;
|
||||
|
||||
if (GPCP_EnterLevel("motor", 0) != 0)
|
||||
{
|
||||
printf("No motor information specified.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_EnterLevel("propellant_mass", 0) == -1)
|
||||
{
|
||||
printf("No propellant mass specified.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue ("val", &number) != 0)
|
||||
{
|
||||
printf("Unable propellant mass.\n");
|
||||
return 1;
|
||||
}
|
||||
if (GPCP_GetValue ("units", &tmp) != 0)
|
||||
{
|
||||
printf("Unable to get units.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dtmp = (double) number;
|
||||
if (convert(&dtmp, tmp, "kg", &(m->prop_mass)))
|
||||
{
|
||||
printf("Incorrect units: %s\n", tmp);
|
||||
return -1;
|
||||
}
|
||||
free(tmp);
|
||||
|
||||
m->isprop = 1;
|
||||
|
||||
GPCP_ExitLevel();
|
||||
}
|
||||
if (GPCP_EnterLevel("total_mass", 0) == -1)
|
||||
{
|
||||
printf("No total mass specified.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue ("val", &number) != 0)
|
||||
{
|
||||
printf("Unable total mass.\n");
|
||||
return 1;
|
||||
}
|
||||
if (GPCP_GetValue ("units", &tmp) != 0)
|
||||
{
|
||||
printf("Unable to get units.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
m->total_mass = (double) number;
|
||||
dtmp = (double) number;
|
||||
if (convert(&dtmp, tmp, "kg", &(m->total_mass)))
|
||||
{
|
||||
printf("Incorrect units: %s\n", tmp);
|
||||
return -1;
|
||||
}
|
||||
free(tmp);
|
||||
m->istot = 1;
|
||||
|
||||
GPCP_ExitLevel();
|
||||
}
|
||||
GPCP_ExitLevel();
|
||||
}
|
||||
|
||||
GPCP_FreeData(&config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef analyser_h
|
||||
#define analyser_h
|
||||
|
||||
struct flags
|
||||
{
|
||||
unsigned char a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1;
|
||||
};
|
||||
|
||||
typedef unsigned char uchar;
|
||||
|
||||
typedef struct _motor
|
||||
{
|
||||
uchar isprop; /* prop mass have bben read */
|
||||
uchar istot; /* total mass have been read */
|
||||
|
||||
double prop_mass; /* Propellant mass (kg)*/
|
||||
double total_mass; /* Total engine mass (kg)*/
|
||||
} motor_t;
|
||||
|
||||
typedef struct _results
|
||||
{
|
||||
|
||||
double max_thrust; /* Maximum thrust */
|
||||
double avg_thrust; /* Mean thrust */
|
||||
double burn_time; /* Burning time */
|
||||
double impulse; /* Total impulse */
|
||||
double vg; /* Exhaust velocity */
|
||||
double isp; /* Specific impulse */
|
||||
double prop_mass_fraction; /* Propellant mass fraction */
|
||||
double impulse_to_weight; /* Impulse to weight ratio */
|
||||
|
||||
} results_t;
|
||||
|
||||
typedef struct _format
|
||||
{
|
||||
int col; /* Number of columns */
|
||||
int time; /* Index of time column */
|
||||
double sctime; /* convesion factor to put time in seconds */
|
||||
int thrust; /* Index of thrust column */
|
||||
double scthrust; /* Conversion factor to put thrust in N */
|
||||
char *comments; /* Character beginning commented lines */
|
||||
|
||||
} format_t;
|
||||
|
||||
void print_results(results_t *res);
|
||||
int analyse_data(double *data, int n, results_t *res, format_t *f, motor_t *m);
|
||||
int parse_config(char *configfile, char **datafile, format_t *f, motor_t *m);
|
||||
int parse_datafile(char *datafile, double **data, int *ndata, format_t *f);
|
||||
|
||||
|
||||
#endif /* analyser_h */
|
||||
@@ -0,0 +1,3 @@
|
||||
LIB = -lnum -lconvert -lgpcp -lm
|
||||
PROG = analyser
|
||||
OBJS = analyser.o
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,385 @@
|
||||
/* -*- Mode: C; c-file-style: "k&r"; -*-*/
|
||||
|
||||
/* rocket.c
|
||||
* sample program for parsing a rocket propellant simulator config.
|
||||
*
|
||||
* $Id: rocket.c,v 1.1.1.1 2001/07/20 03:18:51 antoine Exp $
|
||||
*
|
||||
* Copyright (C) 2000,
|
||||
* Antoine Lefebvre <antoine.lefebvre@polymtl.ca>
|
||||
* Remi Lefebvre <remi@debian.org>
|
||||
*
|
||||
* gpcp is free software; you can redistribute them and/or modify them
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "gpcp.h"
|
||||
|
||||
#include "thermo.h"
|
||||
|
||||
#define DEFAULT_THERMO_FILE "thermo.dat"
|
||||
#define DEFAULT_PROP_FILE "propellant.dat"
|
||||
|
||||
char *thermo_file;
|
||||
char *propellant_file;
|
||||
|
||||
typedef struct _ing
|
||||
{
|
||||
char *name; /* name of the propellant */
|
||||
char *formula;
|
||||
int n_elem;
|
||||
int *elem;
|
||||
int *coef;
|
||||
float heat; /* heat of formation in Joule/gram */
|
||||
float density; /* density in g/cubic cm */
|
||||
float qty; /* number of mol of this ingrediant */
|
||||
|
||||
} ing_t;
|
||||
|
||||
typedef struct _prop_t
|
||||
{
|
||||
char *name;
|
||||
short ncomp;
|
||||
ing_t *ing;
|
||||
float density;
|
||||
|
||||
} prop_t;
|
||||
|
||||
|
||||
int get_value(char *keyword, float *val);
|
||||
int get_composition(ing_t *ing);
|
||||
int get_ingrediant(prop_t *p);
|
||||
int get_qty(char *str, float *qty);
|
||||
int print_info(prop_t *p, int n);
|
||||
|
||||
Options rocket_options[] = {
|
||||
{"global", PARENT, NULL},
|
||||
{"propellant_database", STRING, "global"},
|
||||
{"product_database", STRING, "global"},
|
||||
{"propellant", PARENT, NULL},
|
||||
{"name", STRING, "propellant"},
|
||||
{"ingrediant", PARENT, "propellant"},
|
||||
{"name", STRING, "ingrediant"},
|
||||
{"formula", STRING, "ingrediant"},
|
||||
{"comp", PARENT, "ingrediant"},
|
||||
{"ing", STRING, "comp"},
|
||||
{"enthalpy", STRING, "ingrediant"},
|
||||
{"qty", STRING, "ingrediant"},
|
||||
{"density", STRING, "propellant"},
|
||||
{"database", INTEGER, "ingrediant"},
|
||||
{"problem", PARENT, NULL},
|
||||
{"type", STRING, "problem"},
|
||||
{"propellant", STRING, "problem"},
|
||||
{"chamber_pressure", STRING, "problem"},
|
||||
{"exit_pressure", STRING, "problem"},
|
||||
{NULL, 0, NULL}
|
||||
};
|
||||
|
||||
Functions rocket_functions[] = {
|
||||
{"compute_density", FLOAT},
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int n;
|
||||
|
||||
int n_prop;
|
||||
prop_t *prop_list = NULL;
|
||||
|
||||
Data *data;
|
||||
|
||||
GPCP_RegisterOptions(rocket_options);
|
||||
|
||||
if (GPCP_ReadFile("input.pro", &data) != 0)
|
||||
{
|
||||
printf("Error reading config file.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//GPCP_PrintData(data);
|
||||
|
||||
if (GPCP_EnterLevel("global", 0) == -1)
|
||||
{
|
||||
printf("No global definitions, using default values.\n");
|
||||
propellant_file = (char *) malloc(strlen(DEFAULT_PROP_FILE) + 1);
|
||||
strcpy(propellant_file, DEFAULT_PROP_FILE);
|
||||
|
||||
thermo_file = (char *) malloc(strlen(DEFAULT_THERMO_FILE) + 1);
|
||||
strcpy(thermo_file, DEFAULT_THERMO_FILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue ("propellant_database", &propellant_file) != 0)
|
||||
{
|
||||
printf("No propellant database file specified,"
|
||||
" using default.\n");
|
||||
propellant_file = (char *) malloc(strlen(DEFAULT_PROP_FILE)+1);
|
||||
strcpy(propellant_file, DEFAULT_PROP_FILE);
|
||||
}
|
||||
if (GPCP_GetValue ("product_database", &thermo_file) != 0)
|
||||
{
|
||||
printf("No product database file specified, using default.\n");
|
||||
thermo_file = (char *) malloc(strlen(DEFAULT_THERMO_FILE) + 1);
|
||||
strcpy(thermo_file, DEFAULT_THERMO_FILE);
|
||||
}
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave directory.\n");
|
||||
}
|
||||
}
|
||||
|
||||
if ((n = GPCP_NumParent("propellant")) == 0)
|
||||
{
|
||||
printf ("No propellant definition available.\n");
|
||||
}
|
||||
|
||||
//printf("There is %d propellant.\n", n);
|
||||
|
||||
n_prop = 0;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
//printf("Propellant............\n");
|
||||
|
||||
if (GPCP_EnterLevel("propellant", i) != 0)
|
||||
{
|
||||
printf("Unable to get propellant definition for %d.\n", i);
|
||||
}
|
||||
else
|
||||
{
|
||||
n_prop++;
|
||||
prop_list = (prop_t *) realloc (prop_list,
|
||||
sizeof(prop_t) * n_prop);
|
||||
|
||||
if (GPCP_GetValue ("name", &(prop_list[i].name)) != 0)
|
||||
printf("Name of propellant not specified.\n");
|
||||
|
||||
//printf("%s\n", prop_list[i].name);
|
||||
|
||||
get_ingrediant(prop_list + i);
|
||||
|
||||
//get_value("density", &(prop_list[i].density));
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
printf("Unable to leave level.\n");
|
||||
}
|
||||
}
|
||||
|
||||
print_info(prop_list, n_prop);
|
||||
|
||||
GPCP_FreeData(&data);
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int get_ingrediant(prop_t *p)
|
||||
{
|
||||
int i, n;
|
||||
|
||||
char *string;
|
||||
|
||||
if ((n = GPCP_NumParent("ingrediant")) == 0)
|
||||
{
|
||||
printf("No ingrediant available.\n");
|
||||
}
|
||||
|
||||
p->ncomp = n;
|
||||
p->ing = NULL;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (GPCP_EnterLevel("ingrediant", i) != 0)
|
||||
printf("Unable to get ingrediant number %d.\n", i);
|
||||
else
|
||||
{
|
||||
p->ing = (ing_t *) realloc(p->ing,
|
||||
sizeof(ing_t)*(i+1));
|
||||
|
||||
if (GPCP_GetValue("name", &(p->ing[i].name)) != 0)
|
||||
{
|
||||
printf("Name of ingrediant not specified.\n");
|
||||
p->ing[i].name = (char *) malloc (sizeof(char)
|
||||
*(strlen("NONE")+1));
|
||||
strcpy(p->ing[i].name, "NONE");
|
||||
}
|
||||
if (GPCP_GetValue("formula", &(p->ing[i].formula)) != 0)
|
||||
{
|
||||
printf("Formula of ingrediant not specified.\n");
|
||||
p->ing[i].formula = (char *) malloc (sizeof(char)
|
||||
*(strlen("NONE")+1));
|
||||
strcpy(p->ing[i].formula, "NONE");
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("enthalpy", &string) != 0)
|
||||
printf("Enthalpy not specified.\n");
|
||||
else
|
||||
{
|
||||
get_qty(string, &(p->ing[i].heat));
|
||||
free(string);
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("qty", &string) != 0)
|
||||
printf("No quantity specified.\n");
|
||||
else
|
||||
{
|
||||
get_qty(string, &(p->ing[i].qty));
|
||||
free(string);
|
||||
}
|
||||
|
||||
get_composition(p->ing + i);
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
printf("Unable to leave level.\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_qty(char *str, float *qty)
|
||||
{
|
||||
char *token;
|
||||
|
||||
*qty = atof(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_composition(ing_t *ing)
|
||||
{
|
||||
int i, n;
|
||||
|
||||
float tmp;
|
||||
|
||||
char *tmpstr;
|
||||
|
||||
char *string;
|
||||
|
||||
char elem[3];
|
||||
|
||||
if (GPCP_EnterLevel("comp", 0) != 0)
|
||||
{
|
||||
printf("Unable to get composition of ingredient.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((n = GPCP_NumEntry("ing")) == 0)
|
||||
{
|
||||
printf("No ing field found\n");
|
||||
}
|
||||
|
||||
ing->n_elem = 0;
|
||||
ing->elem = NULL;
|
||||
ing->coef = NULL;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (GPCP_GetValue_n("ing", &string, i) != 0)
|
||||
printf("Can't read ingrediant.\n");
|
||||
else
|
||||
{
|
||||
ing->n_elem++;
|
||||
ing->elem = (int *) realloc(ing->elem,
|
||||
sizeof(int) * ing->n_elem);
|
||||
ing->coef = (int *) realloc(ing->coef,
|
||||
sizeof(int) * ing->n_elem);
|
||||
|
||||
ing->coef[i] = atoi(string);
|
||||
|
||||
tmpstr = string;
|
||||
while (*tmpstr != ' ')
|
||||
tmpstr++;
|
||||
|
||||
elem[0] = *(tmpstr+1);
|
||||
elem[1] = *(tmpstr+2);
|
||||
elem[2] = '\0';
|
||||
if (!(isalpha(elem[1])))
|
||||
elem[1] = ' ';
|
||||
|
||||
//printf("%s, %d, %s...\n", string, ing->coef[i], elem);
|
||||
|
||||
ing->elem[i] = atomic_number(elem);
|
||||
|
||||
|
||||
free(string);
|
||||
}
|
||||
}
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
printf("Unable to leave level.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_value(char *keyword, float *val)
|
||||
{
|
||||
float v = 0;
|
||||
char *units;
|
||||
|
||||
if (GPCP_EnterLevel(keyword, 0) != 0)
|
||||
{
|
||||
printf("Unable to enter level.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue("val", &v) != 0)
|
||||
printf("Unable to get value.\n");
|
||||
|
||||
if (GPCP_GetValue("units", &units) != 0)
|
||||
printf("Unable to get value.\n");
|
||||
|
||||
*val = v;
|
||||
//convert_to_si(*val, v, units);
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
printf("Unable to leave level.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int print_info(prop_t *p, int n)
|
||||
{
|
||||
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
printf("Propellant Definition.\n");
|
||||
printf("Name : %s\n", p[i].name);
|
||||
printf("Density : %f\n", p[i].density);
|
||||
printf("Composition\n");
|
||||
|
||||
for (j = 0; j < p[i].ncomp; j++)
|
||||
{
|
||||
printf("%f mol of %s (%s)\n", p[i].ing[j].qty,
|
||||
p[i].ing[j].formula, p[i].ing[j].name);
|
||||
|
||||
printf("heat of formation: %f\n", p[i].ing[j].heat);
|
||||
|
||||
for (k = 0; k < p[i].ing[j].n_elem; k++)
|
||||
{
|
||||
printf(" %d %s\n", p[i].ing[j].coef[k],
|
||||
symb[p[i].ing[j].elem[k]]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,6 @@
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
|
||||
upload:
|
||||
scp $(PROG) antoine@rocketworkbench.sourceforge.net:/home/groups/rocketworkbench/cgi-bin/
|
||||
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
cgitest.c - Testprogram for cgi.o
|
||||
Copyright (c) 1998,9 by Martin Schulze <joey@infodrom.north.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Compile with: cc -o cgitest cgitest.c -lcgi
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cgi.h>
|
||||
|
||||
|
||||
#include "libcpropep/include/equilibrium.h"
|
||||
#include "libcpropep/include/performance.h"
|
||||
#include "libthermo/include/thermo.h"
|
||||
|
||||
#include "libthermo/include/load.h"
|
||||
#include "libcpropep/include/print.h"
|
||||
|
||||
|
||||
s_cgi *cgi;
|
||||
|
||||
#ifdef SOURCEFORGE
|
||||
#define THERMO_PATH "thermo.dat"
|
||||
#define PROPELLANT_PATH "propellant.dat"
|
||||
#else
|
||||
#define THERMO_PATH "/home/antoine/projets/rocket/rocketworkbench/cpropep/thermo.dat"
|
||||
#define PROPELLANT_PATH "/home/antoine/projets/rocket/rocketworkbench/cpropep/propellant.dat"
|
||||
#endif
|
||||
|
||||
void init_equil(void)
|
||||
{
|
||||
load_thermo (THERMO_PATH);
|
||||
load_propellant (PROPELLANT_PATH);
|
||||
}
|
||||
|
||||
void destroy(void)
|
||||
{
|
||||
free (propellant_list);
|
||||
free (thermo_list);
|
||||
}
|
||||
|
||||
int eval_cgi(equilibrium_t *e, double *exit_condition,
|
||||
exit_condition_t *exit_type)
|
||||
{
|
||||
int mol = 0;
|
||||
char buffer[64];
|
||||
double tmp;
|
||||
double tmp1;
|
||||
|
||||
printf ("<h1>Results</h1>\n\n");
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "temp"), 64);
|
||||
|
||||
if ( ((tmp = atof(buffer)) != 0) && tmp > 298.15 && tmp < 6000 )
|
||||
e->properties.T = tmp;
|
||||
else
|
||||
return -1;
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "pressure"), 64);
|
||||
|
||||
if ((tmp = atof(buffer)) != 0)
|
||||
e->properties.P = tmp;
|
||||
else
|
||||
return -1;
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "exit_cond_type"), 64);
|
||||
|
||||
if (!(strcmp(buffer, "Pressure")))
|
||||
*exit_type = PRESSURE;
|
||||
else if (!(strcmp(buffer, "Supersonic aera ratio")))
|
||||
*exit_type = SUPERSONIC_AREA_RATIO;
|
||||
else if (!(strcmp(buffer, "Subsonic aera ratio")))
|
||||
*exit_type = SUBSONIC_AREA_RATIO;
|
||||
else
|
||||
return -1;
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "exit_cond"), 64);
|
||||
|
||||
if ((tmp = atof(buffer)) != 0)
|
||||
*exit_condition = tmp;
|
||||
else
|
||||
return -1;
|
||||
|
||||
|
||||
if (strncmp("mol", cgiGetValue(cgi, "select"), 3) == 0)
|
||||
mol = 1;
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "qt1"), 32);
|
||||
tmp = atof(buffer);
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "ml1"), 32);
|
||||
tmp1 = atof(buffer);
|
||||
|
||||
if ((tmp != 0) && (tmp1 != 0))
|
||||
{
|
||||
if (mol)
|
||||
add_in_propellant(e, tmp1, tmp);
|
||||
else
|
||||
add_in_propellant(e, tmp1, GRAM_TO_MOL(tmp, tmp1));
|
||||
}
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "qt2"), 32);
|
||||
tmp = atof(buffer);
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "ml2"), 32);
|
||||
tmp1 = atof(buffer);
|
||||
|
||||
if ((tmp != 0) && (tmp1 != 0))
|
||||
{
|
||||
if (mol)
|
||||
add_in_propellant(e, tmp1, tmp);
|
||||
else
|
||||
add_in_propellant(e, tmp1, GRAM_TO_MOL(tmp, tmp1));
|
||||
}
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "qt3"), 32);
|
||||
tmp = atof(buffer);
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "ml3"), 32);
|
||||
tmp1 = atof(buffer);
|
||||
|
||||
if ((tmp != 0) && (tmp1 != 0))
|
||||
{
|
||||
if (mol)
|
||||
add_in_propellant(e, tmp1, tmp);
|
||||
else
|
||||
add_in_propellant(e, tmp1, GRAM_TO_MOL(tmp, tmp1));
|
||||
}
|
||||
|
||||
compute_density(&(e->propellant));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv, char **env)
|
||||
{
|
||||
short i;
|
||||
|
||||
char *path_info = NULL;
|
||||
|
||||
equilibrium_t *equil, *frozen, *shifting;
|
||||
|
||||
char buffer[32];
|
||||
|
||||
double value;
|
||||
double exit_cond;
|
||||
exit_condition_t exit_cond_type;
|
||||
|
||||
int val;
|
||||
problem_t P = TP;
|
||||
|
||||
errorfile = stderr;
|
||||
outputfile = stdout;
|
||||
|
||||
cgiDebug(0, 0);
|
||||
cgi = cgiInit();
|
||||
|
||||
init_equil();
|
||||
|
||||
global_verbose = 0;
|
||||
|
||||
path_info = getenv("PATH_INFO");
|
||||
|
||||
if (path_info)
|
||||
{
|
||||
if (!strcmp(path_info, "/list"))
|
||||
{
|
||||
cgiHeader();
|
||||
printf("<pre>");
|
||||
print_propellant_list();
|
||||
printf("</pre>");
|
||||
|
||||
}
|
||||
else if (!strcmp(path_info, "/list_thermo"))
|
||||
{
|
||||
cgiHeader();
|
||||
printf("<pre>");
|
||||
print_thermo_list();
|
||||
printf("</pre>");
|
||||
|
||||
}
|
||||
else if (!strcmp(path_info, "/search_thermo"))
|
||||
{
|
||||
cgiHeader();
|
||||
printf("<pre>");
|
||||
thermo_search( cgiGetValue(cgi, "formula"));
|
||||
printf("</pre>");
|
||||
|
||||
|
||||
}
|
||||
else if (!strcmp(path_info, "/search_prop"))
|
||||
{
|
||||
cgiHeader();
|
||||
printf("<pre>");
|
||||
propellant_search( cgiGetValue(cgi, "name"));
|
||||
/*thermo_search( cgiGetValue(cgi, "formula"));*/
|
||||
printf("</pre>");
|
||||
|
||||
}
|
||||
else if (!strcmp(path_info, "/equil"))
|
||||
{
|
||||
cgiHeader();
|
||||
|
||||
equil = (equilibrium_t *) malloc (sizeof (equilibrium_t));
|
||||
initialize_equilibrium(equil);
|
||||
|
||||
frozen = (equilibrium_t *) malloc (sizeof(equilibrium_t)*3);
|
||||
shifting = (equilibrium_t *) malloc (sizeof(equilibrium_t)*3);
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
initialize_equilibrium(frozen + i);
|
||||
initialize_equilibrium(shifting + i);
|
||||
}
|
||||
|
||||
if (eval_cgi(equil, &exit_cond, &exit_cond_type))
|
||||
printf("<b>Error</b>");
|
||||
else
|
||||
{
|
||||
list_element(equil);
|
||||
list_product(equil);
|
||||
|
||||
printf("<pre>");
|
||||
|
||||
|
||||
if (strncmp("Find", cgiGetValue(cgi, "type"), 4) == 0)
|
||||
{
|
||||
print_propellant_composition(equil);
|
||||
P = HP;
|
||||
equilibrium(equil, P);
|
||||
print_product_properties(equil, 1);
|
||||
print_product_composition(equil, 1);
|
||||
|
||||
}
|
||||
else if (strncmp("Froz", cgiGetValue(cgi, "type"), 4) == 0)
|
||||
{
|
||||
copy_equilibrium(frozen, equil);
|
||||
|
||||
print_propellant_composition(frozen);
|
||||
equilibrium(frozen, HP);
|
||||
|
||||
frozen_performance(frozen, exit_cond_type, exit_cond);
|
||||
|
||||
print_product_properties(frozen, 3);
|
||||
print_performance_information(frozen, 3);
|
||||
print_product_composition(frozen, 3);
|
||||
|
||||
}
|
||||
else if (strncmp("Shifting", cgiGetValue(cgi, "type"), 8) == 0)
|
||||
{
|
||||
copy_equilibrium(shifting, equil);
|
||||
|
||||
print_propellant_composition(shifting);
|
||||
|
||||
equilibrium(shifting, HP);
|
||||
shifting_performance(shifting, exit_cond_type, exit_cond);
|
||||
|
||||
print_product_properties(shifting, 3);
|
||||
print_performance_information(shifting, 3);
|
||||
print_product_composition(shifting, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
print_propellant_composition(equil);
|
||||
equilibrium(equil, P);
|
||||
print_product_properties(equil, 1);
|
||||
print_product_composition(equil, 1);
|
||||
|
||||
}
|
||||
|
||||
printf("</pre>");
|
||||
}
|
||||
|
||||
free (equil);
|
||||
free (frozen);
|
||||
free (shifting);
|
||||
|
||||
}
|
||||
else if (!strcmp(path_info, "/prop"))
|
||||
{
|
||||
cgiHeader();
|
||||
printf("<pre>");
|
||||
strncpy(buffer, cgiGetValue(cgi, "propellant"), 32);
|
||||
|
||||
if ( print_propellant_info (atoi (buffer)))
|
||||
printf("Request out of range\n");
|
||||
|
||||
printf("</pre>");
|
||||
|
||||
}
|
||||
else if (!strcmp(path_info, "/prod"))
|
||||
{
|
||||
|
||||
cgiHeader();
|
||||
printf("<pre>");
|
||||
strncpy(buffer, cgiGetValue(cgi, "product"), 32);
|
||||
val = atoi (buffer);
|
||||
|
||||
if ( print_thermo_info (val))
|
||||
printf("Request out of range\n");
|
||||
else
|
||||
{
|
||||
strncpy(buffer, cgiGetValue(cgi, "temp"), 32);
|
||||
value = atof(buffer);
|
||||
|
||||
printf("Thermodynamics properties at temperature %.2f K\n", value);
|
||||
printf("Enthalpy: % f J/mol\n", enthalpy_0(val, value)*R*value);
|
||||
printf("Entropy: % f J/(mol K)\n", entropy_0(val, value)*R);
|
||||
printf("Specific heat: % f J/(mol K)\n",
|
||||
specific_heat_0(val, value)*R);
|
||||
|
||||
}
|
||||
printf("</pre>");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
cgiHeader();
|
||||
printf("<br>Bad queries<br>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cgiHeader();
|
||||
printf("<br>Bad PATH_INFO<br>");
|
||||
}
|
||||
|
||||
printf ("\n<hr>\n</body>\n</html>\n");
|
||||
|
||||
|
||||
destroy();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
LIB = -lcpropep -lthermo -lm -lnum -lcgi
|
||||
DEF = -DGCC -DSOURCEFORGE
|
||||
PROG = cpropep-web.cgi
|
||||
OBJS = cpropep-web.o
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
@@ -0,0 +1,36 @@
|
||||
CC = bcc32
|
||||
CPP32 = cpp32
|
||||
LIBRARIAN = tlib
|
||||
LINKER = ilink32
|
||||
RC = brc32
|
||||
|
||||
COPT = -3 -O2 -w-8012 -w-8004 -w-8057 -IC:\borland\bcc55\include
|
||||
LDOPT = -LC:\borland\bcc55\lib
|
||||
IDIR = -I..\..\libnum\ -I..\lib\ -I.
|
||||
|
||||
LIB = compat.lib libnum.lib thermo.lib cpropep.lib
|
||||
|
||||
LIBDIR = -L..\..\libnum\ -L..\lib\
|
||||
|
||||
DEF = -DBORLAND
|
||||
|
||||
PROG = cpropep.exe
|
||||
OBJS = cpropep.obj getopt.obj
|
||||
|
||||
.SUFFIXES: .c
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(COPT) $(IDIR) $(DEF) -c $*.c -o $*.obj
|
||||
|
||||
$(PROG): $(OBJS)
|
||||
$(CC) $(LDOPT) $(LIBDIR) $(LIB) $(OBJS)
|
||||
|
||||
clean:
|
||||
del *.obj
|
||||
del *.bak
|
||||
del *.tds
|
||||
|
||||
deep-clean: clean
|
||||
del $(PROG)
|
||||
@@ -0,0 +1,777 @@
|
||||
/* cpropep.c - Calculation of Complex Chemical Equilibrium */
|
||||
/* $Id: cpropep.c,v 1.3 2002/01/12 23:09:09 antoine Exp $ */
|
||||
/* Copyright (C) 2000 */
|
||||
/* Antoine Lefebvre <antoine.lefebvre@polymtl.ca> */
|
||||
/* Mark Pinese <pinese@cyberwizards.com.au> */
|
||||
/* */
|
||||
/* Licensed under the GPLv2 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <malloc.h>
|
||||
/*#include <time.h>*/
|
||||
|
||||
/*
|
||||
#ifdef GCC
|
||||
#include <unistd.h>
|
||||
#else
|
||||
*/
|
||||
#include "libcompat/include/getopt.h"
|
||||
/*#endif
|
||||
*/
|
||||
|
||||
#include "libthermo/include/load.h"
|
||||
#include "libthermo/include/thermo.h"
|
||||
|
||||
#include "libcpropep/include/equilibrium.h"
|
||||
#include "libcpropep/include/performance.h"
|
||||
#include "libcpropep/include/derivative.h"
|
||||
#include "libcpropep/include/print.h"
|
||||
#include "libcpropep/include/conversion.h"
|
||||
#include "libcpropep/include/return.h"
|
||||
|
||||
#include "libcompat/include/compat.h"
|
||||
|
||||
#define version "1.1"
|
||||
#define date "25/10/2001"
|
||||
|
||||
#ifndef CONF_FILE
|
||||
#define CONF_FILE "cpropep.conf"
|
||||
#endif
|
||||
|
||||
#define MAX_CASE 10
|
||||
|
||||
typedef enum _p
|
||||
{
|
||||
SIMPLE_EQUILIBRIUM,
|
||||
FIND_FLAME_TEMPERATURE,
|
||||
FROZEN_PERFORMANCE,
|
||||
EQUILIBRIUM_PERFORMANCE
|
||||
} p_type;
|
||||
|
||||
char case_name[][80] = {
|
||||
"Fixed pressure-temperature equilibrium",
|
||||
"Fixed enthalpy-pressure equilibrium - adiabatic flame temperature",
|
||||
"Frozen equilibrium performance evaluation",
|
||||
"Shifting equilibrium performance evaluation"
|
||||
};
|
||||
|
||||
char thermo_file[FILENAME_MAX] = "thermo.dat";
|
||||
char propellant_file[FILENAME_MAX] = "propellant.dat";
|
||||
|
||||
|
||||
typedef struct _case_t
|
||||
{
|
||||
p_type p;
|
||||
|
||||
bool temperature_set;
|
||||
bool pressure_set;
|
||||
bool exit_condition_set;
|
||||
|
||||
double temperature;
|
||||
double pressure;
|
||||
exit_condition_t exit_cond_type;
|
||||
double exit_condition;
|
||||
|
||||
} case_t;
|
||||
|
||||
|
||||
void welcome_message(void)
|
||||
{
|
||||
printf("----------------------------------------------------------\n");
|
||||
printf("Cpropep is an implementation in standard C of the chemical\n");
|
||||
printf("equilibrium algorythm presented by GORDON and McBRIDE in the\n");
|
||||
printf("NASA report RP-1311.\n");
|
||||
printf("This is the version %s %s\n", version, date);
|
||||
printf("This software is release under the GPL and is free of charge\n");
|
||||
printf("Copyright (C) 2000 Antoine Lefebvre <antoine.lefebvre@polymtl.ca>\n");
|
||||
printf("----------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
void info(char **argv)
|
||||
{
|
||||
printf("Try `%s -h' for more information\n", argv[0]);
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
/*
|
||||
Usage:
|
||||
cpropep -f infile [-voe]
|
||||
cpropep -pqtuh
|
||||
|
||||
Arguments:
|
||||
*/
|
||||
|
||||
printf("Usage:");
|
||||
printf("\n\tcpropep -f infile [-voe]");
|
||||
printf("\n\tcpropep -pqtuh");
|
||||
|
||||
printf("\n\nArguments:\n");
|
||||
printf("-f file \t Perform an analysis of the propellant data in file\n");
|
||||
printf("-v num \t Verbosity setting, 0 - 10\n");
|
||||
printf("-o file \t Results file, stdout if omitted\n");
|
||||
printf("-e file \t Error file, stdout if omitted\n");
|
||||
printf("-p \t Print the propellant list\n");
|
||||
printf("-q num \t Print information about propellant component number num\n");
|
||||
printf("-t \t Print the combustion product list\n");
|
||||
printf("-u num \t Print information about product number num\n");
|
||||
printf("-h \t Print help\n");
|
||||
printf("-i \t Print program information\n");
|
||||
}
|
||||
|
||||
|
||||
int load_input(FILE *fd, equilibrium_t *e, case_t *t, double *pe)
|
||||
{
|
||||
double m;
|
||||
|
||||
int sp;
|
||||
int section = 0;
|
||||
|
||||
int n_case = 0;
|
||||
|
||||
char buffer[128], num[10], qt[10], unit[10];
|
||||
char variable[64];
|
||||
|
||||
char *bufptr;
|
||||
|
||||
while ( fgets(buffer, 128, fd) != NULL )
|
||||
{
|
||||
switch (section)
|
||||
{
|
||||
case 0:
|
||||
|
||||
if (n_case >= MAX_CASE)
|
||||
{
|
||||
fprintf(outputfile, "Warning: Too many different case, "
|
||||
"maximum is %d: deleting case.\n", MAX_CASE+1);
|
||||
section = 100;
|
||||
break;
|
||||
}
|
||||
|
||||
if (buffer[0] == ' ' || buffer[0] == '\n' || buffer[0] == '\0' ||
|
||||
buffer[0] == '#')
|
||||
{
|
||||
section = 0;
|
||||
break;
|
||||
}
|
||||
else if (strncmp(buffer, "Propellant", 10) == 0)
|
||||
{
|
||||
section = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strncmp(buffer, "TP", 2) == 0)
|
||||
t[n_case].p = SIMPLE_EQUILIBRIUM;
|
||||
else if (strncmp(buffer, "HP", 2) == 0)
|
||||
t[n_case].p = FIND_FLAME_TEMPERATURE;
|
||||
else if (strncmp(buffer, "FR", 2) == 0)
|
||||
t[n_case].p = FROZEN_PERFORMANCE;
|
||||
else if (strncmp(buffer, "EQ", 2) == 0)
|
||||
t[n_case].p = EQUILIBRIUM_PERFORMANCE;
|
||||
else
|
||||
{
|
||||
printf ("Unknown option.\n");
|
||||
break;
|
||||
}
|
||||
section = 2;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 1: /* propellant section */
|
||||
if (buffer[0] == '+')
|
||||
{
|
||||
sscanf(buffer, "%s %s %s", num, qt, unit);
|
||||
bufptr = num + 1;
|
||||
sp = atoi(bufptr);
|
||||
|
||||
m = atof(qt);
|
||||
|
||||
if (strcmp(unit, "g") == 0)
|
||||
{
|
||||
add_in_propellant(e, sp, GRAM_TO_MOL(m, sp) );
|
||||
}
|
||||
else if (strcmp(unit, "m") == 0)
|
||||
{
|
||||
add_in_propellant(e, sp, m);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unit must be g (gram) or m (mol)\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (buffer[0] == '#')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (buffer[0] == ' ' || buffer[0] == '\n' || buffer[0] == '\0')
|
||||
{
|
||||
section = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (buffer[0] == '+')
|
||||
{
|
||||
sscanf(buffer, "%s %s %s", variable, qt, unit);
|
||||
|
||||
bufptr = variable + 1;
|
||||
|
||||
if (strcmp(bufptr, "chamber_temperature") == 0)
|
||||
{
|
||||
|
||||
m = atof(qt);
|
||||
|
||||
if (strcmp(unit, "k") == 0)
|
||||
{
|
||||
t[n_case].temperature = m;
|
||||
}
|
||||
else if (strcmp(unit, "c") == 0)
|
||||
{
|
||||
t[n_case].temperature = m + 273.15;
|
||||
}
|
||||
else if (strcmp(unit, "f") == 0)
|
||||
{
|
||||
t[n_case].temperature = (5.0/9.0) * (m - 32.0) + 273.15;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unit must be k (kelvin) or c (celcius)\n");
|
||||
break;
|
||||
}
|
||||
|
||||
t[n_case].temperature_set = true;
|
||||
|
||||
}
|
||||
else if (strcmp(bufptr, "chamber_pressure") == 0)
|
||||
{
|
||||
m = atof(qt);
|
||||
|
||||
if (strcmp(unit, "atm") == 0)
|
||||
{
|
||||
t[n_case].pressure = m;
|
||||
}
|
||||
else if (strcmp(unit, "kPa") == 0)
|
||||
{
|
||||
t[n_case].pressure = KPA_TO_ATM * m;
|
||||
}
|
||||
else if (strcmp(unit, "psi") == 0)
|
||||
{
|
||||
t[n_case].pressure = PSI_TO_ATM * m;
|
||||
}
|
||||
else if (strcmp(unit, "bar") == 0)
|
||||
{
|
||||
t[n_case].pressure = BAR_TO_ATM * m;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(errorfile, "Units must be psi, kPa, atm or bar.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
t[n_case].pressure_set = true;
|
||||
}
|
||||
else if (strcmp(bufptr, "exit_pressure") == 0)
|
||||
{
|
||||
m = atof(qt);
|
||||
|
||||
if (strcmp(unit, "atm") == 0)
|
||||
{
|
||||
t[n_case].exit_condition = m;
|
||||
}
|
||||
else if (strcmp(unit, "kPa") == 0)
|
||||
{
|
||||
t[n_case].exit_condition = KPA_TO_ATM * m;
|
||||
}
|
||||
else if (strcmp(unit, "psi") == 0)
|
||||
{
|
||||
t[n_case].exit_condition = PSI_TO_ATM * m;
|
||||
}
|
||||
else if (strcmp(unit, "bar") == 0)
|
||||
{
|
||||
t[n_case].exit_condition = BAR_TO_ATM * m;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(errorfile, "Units must be psi, kPa, atm or bar.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
t[n_case].exit_cond_type = PRESSURE;
|
||||
t[n_case].exit_condition_set = true;
|
||||
|
||||
}
|
||||
else if (strcmp(bufptr, "supersonic_area_ratio") == 0)
|
||||
{
|
||||
t[n_case].exit_cond_type = SUPERSONIC_AREA_RATIO;
|
||||
t[n_case].exit_condition = atof(qt);
|
||||
t[n_case].exit_condition_set = true;
|
||||
}
|
||||
else if (strcmp(bufptr, "subsonic_area_ratio") == 0)
|
||||
{
|
||||
t[n_case].exit_cond_type = SUBSONIC_AREA_RATIO;
|
||||
t[n_case].exit_condition = atof(qt);
|
||||
t[n_case].exit_condition_set = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown keyword.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
else if (buffer[0] == '#')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (buffer[0] == ' ' || buffer[0] == '\n' || buffer[0] == '\0')
|
||||
{
|
||||
section = 0;
|
||||
n_case++;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
section = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, c, v = 0;
|
||||
int err_code;
|
||||
char filename[FILENAME_MAX];
|
||||
FILE *fd = NULL;
|
||||
|
||||
FILE *conf = NULL;
|
||||
|
||||
equilibrium_t *equil, *frozen, *shifting;
|
||||
|
||||
int thermo_loaded = 0;
|
||||
int propellant_loaded = 0;
|
||||
|
||||
double exit_pressure;
|
||||
|
||||
/* clock_t timer;*/
|
||||
|
||||
char variable[64];
|
||||
char path[FILENAME_MAX];
|
||||
char buffer[512];
|
||||
|
||||
case_t case_list[MAX_CASE];
|
||||
for (i = 0; i < MAX_CASE; i++)
|
||||
{
|
||||
case_list[i].p = -1;
|
||||
case_list[i].temperature_set = false;
|
||||
case_list[i].pressure_set = false;
|
||||
case_list[i].exit_condition_set = false;
|
||||
}
|
||||
|
||||
errorfile = stderr;
|
||||
outputfile = stdout;
|
||||
|
||||
/* global_verbose = 1; */
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
usage ();
|
||||
exit (ERROR);
|
||||
}
|
||||
|
||||
/* read the configuration file if there is one*/
|
||||
if ((conf = fopen(CONF_FILE, "r")) != NULL)
|
||||
{
|
||||
while (fgets(buffer, 512, conf))
|
||||
{
|
||||
sscanf(buffer, "%s %s", variable, path);
|
||||
if (strcmp(variable, "thermo") == 0)
|
||||
{
|
||||
printf("Thermo data file: %s\n", path);
|
||||
strncpy(thermo_file, path, FILENAME_MAX);
|
||||
}
|
||||
else if (strcmp(variable, "propellant") == 0)
|
||||
{
|
||||
printf("Propellant data file: %s\n", path);
|
||||
strncpy(propellant_file, path, FILENAME_MAX);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s file not present, using default values.\n", CONF_FILE);
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = getopt(argc, argv, "ipht?f:v:o:e:q:u:");
|
||||
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
/* the output file */
|
||||
case 'o':
|
||||
if (strlen(optarg) > FILENAME_MAX)
|
||||
{
|
||||
printf("Filename too long!\n");
|
||||
break;
|
||||
}
|
||||
strncpy (filename, optarg, FILENAME_MAX);
|
||||
|
||||
if ( (outputfile = fopen (filename, "w")) == NULL )
|
||||
return 1;
|
||||
|
||||
break;
|
||||
|
||||
/* the output error file */
|
||||
case 'e':
|
||||
if (strlen(optarg) > FILENAME_MAX)
|
||||
{
|
||||
printf("Filename too long!\n");
|
||||
break;
|
||||
}
|
||||
strncpy (filename, optarg, FILENAME_MAX - 1);
|
||||
|
||||
if ( (errorfile = fopen (filename, "w")) == NULL )
|
||||
return (ERROR);
|
||||
|
||||
break;
|
||||
|
||||
/* print the propellant list */
|
||||
case 'p':
|
||||
if (!propellant_loaded)
|
||||
{
|
||||
if (load_propellant (propellant_file) < 0)
|
||||
{
|
||||
printf("Error loading propellant file: %s\n", propellant_file);
|
||||
return -1;
|
||||
}
|
||||
propellant_loaded = 1;
|
||||
}
|
||||
print_propellant_list();
|
||||
free(propellant_list);
|
||||
return (SUCCESS);
|
||||
|
||||
/* print propellant info */
|
||||
case 'q':
|
||||
if (!propellant_loaded)
|
||||
{
|
||||
if (load_propellant (propellant_file) < 0)
|
||||
{
|
||||
printf("Error loading propellant file: %s\n", propellant_file);
|
||||
return -1;
|
||||
}
|
||||
propellant_loaded = 1;
|
||||
}
|
||||
print_propellant_info( atoi(optarg) );
|
||||
free(propellant_list);
|
||||
return (SUCCESS);
|
||||
|
||||
/* print the usage */
|
||||
case 'h':
|
||||
usage();
|
||||
return (SUCCESS);
|
||||
|
||||
/* the input file */
|
||||
case 'f':
|
||||
if (strlen(optarg) > FILENAME_MAX)
|
||||
{
|
||||
printf("Filename too long!\n");
|
||||
break;
|
||||
}
|
||||
strncpy (filename, optarg, FILENAME_MAX);
|
||||
|
||||
if ( (fd = fopen (filename, "r")) == NULL )
|
||||
return (ERROR);
|
||||
|
||||
break;
|
||||
|
||||
/* print the thermo list */
|
||||
case 't':
|
||||
if (!thermo_loaded)
|
||||
{
|
||||
if (load_thermo (thermo_file) < 0)
|
||||
{
|
||||
printf("Error loading thermo data file: %s\n", thermo_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
thermo_loaded = 1;
|
||||
}
|
||||
print_thermo_list();
|
||||
free(thermo_list);
|
||||
return (SUCCESS);
|
||||
|
||||
case 'u':
|
||||
if (!thermo_loaded)
|
||||
{
|
||||
if (load_thermo (thermo_file) < 0)
|
||||
{
|
||||
printf("Error loading thermo data file: %s\n", thermo_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
thermo_loaded = 1;
|
||||
}
|
||||
print_thermo_info( atoi(optarg) );
|
||||
free(thermo_list);
|
||||
return (SUCCESS);
|
||||
|
||||
/* set the verbosity level */
|
||||
case 'v':
|
||||
v = atoi(optarg);
|
||||
if (v < 0 || v > 10)
|
||||
{
|
||||
printf("Verbose is an integer betwenn 0 and 10.\n");
|
||||
v = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
/* print information */
|
||||
case 'i':
|
||||
welcome_message();
|
||||
return (SUCCESS);
|
||||
|
||||
case '?':
|
||||
info(argv);
|
||||
return (SUCCESS);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!thermo_loaded)
|
||||
{
|
||||
if (load_thermo (thermo_file) < 0)
|
||||
{
|
||||
printf("Error loading thermo data file: %s\n", thermo_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
thermo_loaded = 1;
|
||||
}
|
||||
if (!propellant_loaded)
|
||||
{
|
||||
if (load_propellant (propellant_file) < 0)
|
||||
{
|
||||
printf("Error loading propellant file: %s\n", propellant_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
propellant_loaded = 1;
|
||||
}
|
||||
|
||||
|
||||
if (fd != NULL)
|
||||
{
|
||||
equil = (equilibrium_t *) malloc (sizeof (equilibrium_t));
|
||||
initialize_equilibrium(equil);
|
||||
|
||||
frozen = (equilibrium_t *) malloc (sizeof(equilibrium_t)*3);
|
||||
shifting = (equilibrium_t *) malloc (sizeof(equilibrium_t)*3);
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
initialize_equilibrium(frozen + i);
|
||||
initialize_equilibrium(shifting + i);
|
||||
}
|
||||
|
||||
load_input(fd, equil, case_list, &exit_pressure);
|
||||
|
||||
compute_density(&(equil->propellant));
|
||||
|
||||
fclose(fd);
|
||||
global_verbose = v;
|
||||
|
||||
list_element(equil);
|
||||
if ((err_code = list_product(equil)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while ((case_list[i].p != -1) && (i <= MAX_CASE))
|
||||
{
|
||||
/*
|
||||
printf("Type : %d\n", case_list[i].p);
|
||||
printf("Tset : %d\n", case_list[i].temperature_set);
|
||||
printf("Pset : %d\n", case_list[i].pressure_set);
|
||||
printf("Eset : %d\n", case_list[i].exit_condition_set);
|
||||
printf("T : %f\n", case_list[i].temperature);
|
||||
printf("P : %f\n", case_list[i].pressure);
|
||||
printf("E : %f\n", case_list[i].exit_condition);
|
||||
*/
|
||||
|
||||
fprintf(outputfile, "Computing case %d\n%s\n\n", i+1,
|
||||
case_name[case_list[i].p]);
|
||||
|
||||
/* be sure to begin iteration without considering
|
||||
condensed species. Once n_condensed have been set */
|
||||
equil->product.n[CONDENSED] = 0;
|
||||
|
||||
switch (case_list[i].p)
|
||||
{
|
||||
case SIMPLE_EQUILIBRIUM:
|
||||
|
||||
if (!(case_list[i].temperature_set))
|
||||
{
|
||||
printf("Chamber temperature not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
else if (!(case_list[i].pressure_set))
|
||||
{
|
||||
printf("Chamber pressure not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
equil->properties.T = case_list[i].temperature;
|
||||
equil->properties.P = case_list[i].pressure;
|
||||
|
||||
print_propellant_composition(equil);
|
||||
if ((err_code = equilibrium(equil, TP)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
print_product_properties(equil, 1);
|
||||
print_product_composition(equil, 1);
|
||||
break;
|
||||
|
||||
case FIND_FLAME_TEMPERATURE:
|
||||
|
||||
if (!(case_list[i].pressure_set))
|
||||
{
|
||||
printf("Chamber pressure not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
equil->properties.P = case_list[i].pressure;
|
||||
|
||||
print_propellant_composition(equil);
|
||||
if ((err_code = equilibrium(equil, HP)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
print_product_properties(equil, 1);
|
||||
print_product_composition(equil, 1);
|
||||
break;
|
||||
|
||||
case FROZEN_PERFORMANCE:
|
||||
|
||||
if (!(case_list[i].pressure_set))
|
||||
{
|
||||
printf("Chamber pressure not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
else if (!(case_list[i].exit_condition_set))
|
||||
{
|
||||
printf("Exit condition not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
initialize_equilibrium(equil);
|
||||
|
||||
equil->properties.T = case_list[i].temperature;
|
||||
equil->properties.P = case_list[i].pressure;
|
||||
|
||||
copy_equilibrium(frozen, equil);
|
||||
|
||||
print_propellant_composition(frozen);
|
||||
|
||||
if ((err_code = equilibrium(equil, HP)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
if ((err_code =
|
||||
frozen_performance(frozen, case_list[i].exit_cond_type,
|
||||
case_list[i].exit_condition)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
print_product_properties(frozen, 3);
|
||||
print_performance_information(frozen, 3);
|
||||
print_product_composition(frozen, 3);
|
||||
|
||||
break;
|
||||
case EQUILIBRIUM_PERFORMANCE:
|
||||
|
||||
|
||||
if (!(case_list[i].pressure_set))
|
||||
{
|
||||
printf("Chamber pressure not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
else if (!(case_list[i].exit_condition_set))
|
||||
{
|
||||
printf("Exit condition not set. Aborted.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
equil->properties.T = case_list[i].temperature;
|
||||
equil->properties.P = case_list[i].pressure;
|
||||
|
||||
copy_equilibrium(shifting, equil);
|
||||
|
||||
print_propellant_composition(shifting);
|
||||
|
||||
if ((err_code = equilibrium(shifting, HP)) < 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
if ((err_code = shifting_performance(shifting,
|
||||
case_list[i].exit_cond_type,
|
||||
case_list[i].exit_condition))
|
||||
< 0)
|
||||
{
|
||||
print_error_message(err_code);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
print_product_properties(shifting, 3);
|
||||
print_performance_information(shifting, 3);
|
||||
print_product_composition(shifting, 3);
|
||||
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
free (equil);
|
||||
free (frozen);
|
||||
free (shifting);
|
||||
|
||||
}
|
||||
|
||||
free (propellant_list);
|
||||
free (thermo_list);
|
||||
|
||||
if (errorfile != stderr)
|
||||
fclose (errorfile);
|
||||
|
||||
if (outputfile != stdout)
|
||||
fclose (outputfile);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
thermo /usr/share/rocketworkbench/cpropep/thermo.dat
|
||||
propellant /usr/share/rocketworkbench/cpropep/propellant.dat
|
||||
@@ -0,0 +1,5 @@
|
||||
LIB = -lcpropep -lthermo -lnum -lm
|
||||
DEF = -DGCC -DCONF_FILE=\"/etc/rocketworkbench/cpropep.conf\"
|
||||
PROG = cpropep
|
||||
OBJS = cpropep.o
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%% generic configureation file for %%%%
|
||||
%%%% the ccmalloc memory profiler %%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%-----------------------------------------------------------------%
|
||||
% COPY THIS FILE TO `.ccmalloc' in your project or home directory %
|
||||
%-----------------------------------------------------------------%
|
||||
|
||||
##############################################################################
|
||||
## (C) 1997-1998 Armin Biere, 1998 Johannes Keukelaar
|
||||
## $Id: .ccmalloc,v 1.1.1.1 2001/07/20 03:18:59 antoine Exp $
|
||||
##############################################################################
|
||||
|
||||
%%% `%' and `#' are comments !!!!!!!
|
||||
|
||||
% This file must be called `.ccmalloc' and is searched for in the
|
||||
% current directory and in the home directory of the user. If it
|
||||
% does not exist then the default values mentioned below are used.
|
||||
|
||||
% It is also the currently only available user manual ;-) So here
|
||||
% is a reading hint. First have a look at the short one line
|
||||
% descriptions of each option ...
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% with `file' the executable is specified [a.out]
|
||||
% ----------------------------------------------------------------------
|
||||
% This should not be necessary for Linux and Solaris because the proc
|
||||
% file system can be used to find argv[0].
|
||||
%
|
||||
% (the rest of this comment only applies to other OS)
|
||||
%
|
||||
% For other OS you should use this option unless the executable is
|
||||
% in the current directory or its name is `a.out'.
|
||||
%
|
||||
% If you do not specify this then ccmalloc tries to find an executable
|
||||
% in the current directory that matches the running program starting
|
||||
% with `a.out'. For this process it must call `nm' on each executable
|
||||
% file in the directory which may be time consuming. With this option
|
||||
% you can speed up this process.
|
||||
%
|
||||
% You can also specify absolute or relative path names. This is
|
||||
% necessary if you do not start your program from the current directory.
|
||||
% But you can also simply link or name your program to `a.out'.
|
||||
|
||||
%file FILE
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `log' specify the logfile [stderr]
|
||||
% ----------------------------------------------------------------------
|
||||
% The default is to use stderr. The argument to `log' is the name of
|
||||
% the file you want to write to. It can also be `stdout' or `-' which
|
||||
% sets stdout as logfile. If the logfile is stdout or stderr and is
|
||||
% connected to a terminal then the output is slightly different.
|
||||
%
|
||||
% For big programs the logfile can be really big. To reduce the size
|
||||
% you can use a small chain length (see `chain-length' below). The other
|
||||
% possibility is to use compressed logfiles. This can be done by
|
||||
% specifying a logfile name with a `.gz' (or a `.Z') suffix. This means
|
||||
% that gnuzip (resp. compress) is used to compress the output.
|
||||
|
||||
log report
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `logpid' specify the logfile
|
||||
% ----------------------------------------------------------------------
|
||||
% Can be used alternatively to the `log' command if you want to use
|
||||
% ccmalloc for debugging parallel applications where several copies of
|
||||
% the program you are debugging must be run simoultaneously. In this
|
||||
% case you can not use `log' because you do not want to write to the same
|
||||
% log file. Using `logpid' uses a file name ending with the <pid> of
|
||||
% the process which means the name is unique even if several copies of
|
||||
% your program are run simoultaneously.
|
||||
%
|
||||
% If you use the compressing suffixes then the <pid> is inserted before
|
||||
% the suffix (e.g. `logpid ccmalloc.log.gz' uses `ccmalloc.log.<pid>.gz'
|
||||
% as the name for the log file).
|
||||
|
||||
%logpid FILE
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `dont-log-chain' skip info about certain chains []
|
||||
% ----------------------------------------------------------------------
|
||||
% This command may be repeated any number of times. The argument to this
|
||||
% command is a comma-separated list of function-or-file-and-line
|
||||
% specifications. Garbage allocated from a callchain that contains this
|
||||
% subchain anywhere will _not_ be logged.
|
||||
%
|
||||
% The comma-separated list should not contain any spaces. E.g. not:
|
||||
% main, foo, bar
|
||||
% but:
|
||||
% main,foo,bar
|
||||
% A function-or-file-and-line specification is a string followed by an
|
||||
% optional colon and number, for example: main or main:14 or main.c or
|
||||
% main.c:15. Note that the string is compared with both the function and
|
||||
% the file name, if available. If main.c happens to be a function name,
|
||||
% that will cause a match (for that string at least).
|
||||
% Not specifying a line number will match any line number. If line number
|
||||
% information is not available, anything will match!
|
||||
% Not specifying a name (e.g. ,,,) will match an unknown function name.
|
||||
% Not giving any parameters at all, will match a chain containing at least
|
||||
% one unknown function.
|
||||
%
|
||||
% Note that if you say
|
||||
% dont-log-chain wrapper.c
|
||||
% _nothing_ will be logged...
|
||||
|
||||
%dont-log-chain
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `only-log-chain' skip info about other chains []
|
||||
% ----------------------------------------------------------------------
|
||||
% The obvious counterpart to dont-log-chain. In this case, only matching
|
||||
% chains will be reported. Non-matching chains will not be reported.
|
||||
% Can be repeated any number of times; if the chain matches any of the
|
||||
% instances, it will be reported.
|
||||
|
||||
%only-log-chain
|
||||
|
||||
########################################################################
|
||||
# #
|
||||
# This is the `flag' section #
|
||||
# #
|
||||
# `set FLAG' is the same as `set FLAG 1' #
|
||||
# #
|
||||
# The default values are those set below. If `silent' is disabled #
|
||||
# then you will find the banner in the log file (or it is listed on #
|
||||
# stdout or stderr). The banner describes the current settings of all #
|
||||
# these flags. #
|
||||
# #
|
||||
########################################################################
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% with `only-count' ccmalloc only counts garbage - no call chains [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% If only-count is set to one then only one additional pointer for
|
||||
% each allocated data is used and no call chain is generated. This is
|
||||
% the fasted and most space efficient mode ccmalloc can operate
|
||||
% in. In this mode you get at least the size of garbage produced.
|
||||
%
|
||||
% Note that `check-free-space' does not work at all with `only-count'
|
||||
% set and over writes (`check-overwrites') are only checked when
|
||||
% calling free.
|
||||
|
||||
%set only-count 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `load-dynlibs' load dynamic linked libraries into gdb [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% If your program is linked with dynamic libraries, function and file
|
||||
% name information is not available for addresses in those libraries,
|
||||
% unless you set `load-dynlibs' to 1.
|
||||
|
||||
%set load-dynlibs 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `keep-deallocated-data' does not recycle deallocated data [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% If you enable keep-deallocated-data then all data deallocated with
|
||||
% `free' (or `delete' in C++) is not given back to the free store
|
||||
% but stays associated with the call chain of its allocation. This is
|
||||
% very useful if your program does multiple deallocation of the
|
||||
% same data.
|
||||
|
||||
%set keep-deallocated-data 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `check-overwrites' detect overwrites [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% If you want to detect `off by n bytes' errors you should set
|
||||
% `checking-overwrites' to n/4 (on 32-Bit machines).
|
||||
%
|
||||
% ccmalloc inserts a boundary above allocated data. This boundary
|
||||
% consists of `check-overwrites' words. If your program writes to
|
||||
% this area then ccmalloc can detect this (see also check-start
|
||||
% and check-interval). `ccmalloc' also does checking for overwrites
|
||||
% at non word boundaries (e.g. strcpy(malloc(strlen("hello")),"hello");)
|
||||
|
||||
%set check-overwrites 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `check-underwrites' detect overwrites [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% same with writes below allocated data. You do not have to set this
|
||||
% option if you only want detect `off (below) by one' errors because
|
||||
% ccmalloc keeps a magic value just before the user data.
|
||||
|
||||
%set check-overwrites 0
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `check-free-space' can be used to find dangling pointers. [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% A very serious type of bug is to write on data that has already been
|
||||
% freed. If this happens the free space management of malloc is in
|
||||
% trouble and you will perhaps encounter non deterministic behaviour of
|
||||
% your program. To test this first enable `keep-deallocated-data' and
|
||||
% restart your program. If the problem goes away and ccmalloc does not
|
||||
% report anything then you should *also* enable `check-free-space'. Now
|
||||
% ccmalloc checks already deallocated data for corruption.
|
||||
%
|
||||
% Note that to perform this check `keep-deallocated-data' also must
|
||||
% be enabled and `only-count' disabled.
|
||||
|
||||
%set check-free-space 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `check-interval' can be used to speed up checks [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% If check-overwrite, check-underwrites or check-free-space is set then
|
||||
% the default is to do `write checks' when data is deallocated and
|
||||
% to do `free space checks' when reporting together with
|
||||
% `write checks' for garbage. When you want these checks to be
|
||||
% performed more often then you should set `check-interval' to a
|
||||
% positive number. This number is the interval between the number of
|
||||
% calls to free or malloc without performing the checks.
|
||||
|
||||
%set check-interval 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `check-start' can be used to speed up checks [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% The flag `check-start' delays the start of checks until the given
|
||||
% number of calls to free and malloc have occured. Together with
|
||||
% `check-interval' you can use a binary search to find an aproximation
|
||||
% when a corruption occured! If you simply set check-interval to 1 and
|
||||
% check-start to 0 then this will slow done your program too much.
|
||||
|
||||
%set check-start 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `silent' disables banner [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% If you don't want to see the banner of ccmalloc then set
|
||||
% `silent' to 1 (f.e. when logging to stderr)
|
||||
|
||||
%set silent
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `file-info' en/disables file and line number information [1]
|
||||
% ----------------------------------------------------------------------
|
||||
% If your program was compiled with debugging information (-g) then
|
||||
% ccmalloc can generate line number and file info for call chains opening
|
||||
% a pipe to gdb. For very big programs this method is slow. In this case
|
||||
% you can set `file-info' to zero and you will only get the function
|
||||
% names. For SunOS 4.3.1 `nm' does not `demangle' C++ identifiers
|
||||
% very well. So gdb is called instead but only if `file-info' is
|
||||
% not set to 0.
|
||||
|
||||
%set file-info 1
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `continue' if ccmalloc aborts when something weired happened [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% If the free function of ccmalloc is called with an argument that does
|
||||
% not make sense to ccmalloc or that has already been freed then you
|
||||
% probably want the program to stop at this point. This is also
|
||||
% the default behaviour. But you can force ccmalloc also to ignore
|
||||
% this if you set `continue' to 1. This flag also controls the behaviour
|
||||
% of ccmalloc when free space is found to be corrupted or a write
|
||||
% boundary has been overwritten.
|
||||
|
||||
%set continue 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `chain-length' is the length of the maximal call chain [0 = infinite]
|
||||
% ----------------------------------------------------------------------
|
||||
% You can restrict the length of call chains by setting `chain-length'
|
||||
% to a number greater than zero. If `chain-length' is zero (the default)
|
||||
% then chains are as long as possible (on a non x86 system only call
|
||||
% chains with a finite maximal length can be generated). For big
|
||||
% programs especially if keep-deallocated-data is enabled this can
|
||||
% reduce the size of the log file from over 100MB to several MB!
|
||||
|
||||
%set chain-length 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `print-addresses' of data [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% If you want to see the addresses of the allocated data (and
|
||||
% deallocated data if keep-deallocated-data is set to 1) set
|
||||
% `print-addresses' to 1.
|
||||
|
||||
%set print-addresses 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `print-on-one-line' shortens log file [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% The default is to print function names and file/line number info
|
||||
% on separate lines. With `print-on-one-line' set 1 all are printed
|
||||
% on one line.
|
||||
|
||||
%set print-on-one-line 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `additional-line' enlarges readability [1]
|
||||
% ----------------------------------------------------------------------
|
||||
% When printing call chains an empty line is printed between to
|
||||
% call points. Set `additional-line' to 0 to disable this feature.
|
||||
|
||||
%set additional-line 1
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% `statistics' enables more accurate profiling [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% Calculate number of allocations and deallocations and bytes also on
|
||||
% a per call chain basis. This uses 4 additional pointers for each
|
||||
% call chain.
|
||||
|
||||
%set statistics 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% set order for sorting of call chains [1] [1]
|
||||
% ----------------------------------------------------------------------
|
||||
% When printing the report to the log file the call chains are sorted by
|
||||
% default with respect to the largest accumulated garbage produced by
|
||||
% that call chain. This can be changed with setting `sort-by-wasted'
|
||||
% to 0. In this case they are sorted by the number of allocated bytes.
|
||||
% If you want the number of allocations (only possible if `statistics'
|
||||
% is enabled) as sorting criteria instead then set `sort-by-size' to 0.
|
||||
|
||||
%set sort-by-wasted 1
|
||||
%set sort-by-size 1
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% report library chains [0]
|
||||
% ----------------------------------------------------------------------
|
||||
% Some external libraries (like libg++) have memory leaks. On some
|
||||
% systems even a call to printf produces a leak. ccmalloc tries to
|
||||
% detect this (only heuristically!) and with this flag you can control
|
||||
% if leaks produced by such library calls are reported.
|
||||
%
|
||||
% Since version 0.2.1 some similar effect can be achieved by using
|
||||
% `dont-log-chain' with no argument.
|
||||
|
||||
%set library-chains 0
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% print debugging information [X] (compile time dependend)
|
||||
% ----------------------------------------------------------------------
|
||||
|
||||
%set debug X
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% align memory on 8 byte boundary [0] (no effect on SunOS or Solaris)
|
||||
% ----------------------------------------------------------------------
|
||||
|
||||
%set align-8-byte 0
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
@@ -0,0 +1,150 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "shape.h"
|
||||
#include "output.h"
|
||||
#include "grain.h"
|
||||
|
||||
#define STRING_LEN 64
|
||||
|
||||
#define STRIDE 0.3
|
||||
|
||||
#define NBURN 12
|
||||
|
||||
typedef struct _grain_info
|
||||
{
|
||||
double perimeter; /* perimeter of the grain shape */
|
||||
double surface; /* inside surface */
|
||||
double depth; /* thickness of propellant burned */
|
||||
} grain_info_t;
|
||||
|
||||
int output_info(grain_info_t *info, int n, char *filename);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *octscript;
|
||||
|
||||
int i;
|
||||
int nb_point;
|
||||
|
||||
point_t *beginning; /* pointer to the first point in the structure */
|
||||
|
||||
char string[STRING_LEN];
|
||||
char filename[STRING_LEN];
|
||||
|
||||
char c[2];
|
||||
int d;
|
||||
|
||||
grain_info_t info[NBURN+1];
|
||||
|
||||
/* for nuclear */
|
||||
/*int n = 8;
|
||||
nb_point = 200 * n;*/
|
||||
|
||||
/* for rectangular */
|
||||
/*nb_point = 4;*/
|
||||
|
||||
/* for cross */
|
||||
nb_point = 12;
|
||||
|
||||
/* for round */
|
||||
/*nb_point = 20;*/
|
||||
|
||||
/* generate a random file name */
|
||||
snprintf(string, STRING_LEN, "%s", "patate");
|
||||
|
||||
d = 0;
|
||||
|
||||
snprintf(filename, STRING_LEN, "%s%s%s", "Z", string, ".m");
|
||||
octscript = fopen(filename, "w");
|
||||
perror(filename);
|
||||
|
||||
create_list(&beginning, nb_point);
|
||||
|
||||
/* fill the shape with a triangular form */
|
||||
/*build_triangular(beginning, nb_point, 4);*/
|
||||
/*build_nuclear(beginning, nb_point, 0.5, 1, n);*/
|
||||
/*build_rectangular(beginning, nb_point, 0.5, 8.0);*/
|
||||
build_cross(beginning, nb_point, 1.0, 7.0);
|
||||
/* build_round(beginning, nb_point, 1.0);*/
|
||||
|
||||
|
||||
properties(beginning, &(info[0].perimeter), &(info[0].surface));
|
||||
info[0].depth = 0.0;
|
||||
|
||||
|
||||
snprintf(filename, STRING_LEN, "%s%d%s", string, d, ".m");
|
||||
|
||||
output_matlab(beginning, filename, d);
|
||||
|
||||
snprintf(filename, STRING_LEN, "%s%d", string, d);
|
||||
|
||||
fprintf(octscript, "gset nokey\n");
|
||||
fprintf(octscript, "%s;\n", filename);
|
||||
fprintf(octscript, "plot(S%d(:,1),S%d(:,2))\n", d, d);
|
||||
fprintf(octscript, "hold on\n");
|
||||
|
||||
/*c[0]++;*/
|
||||
d++;
|
||||
|
||||
for (i = 0; i < NBURN; i++)
|
||||
{
|
||||
burn_surface(&beginning, STRIDE, 5);
|
||||
|
||||
snprintf(filename, STRING_LEN, "%s%d%s", string, d, ".m");
|
||||
|
||||
output_matlab(beginning, filename, d);
|
||||
|
||||
snprintf(filename, STRING_LEN, "%s%d", string, d);
|
||||
fprintf(octscript, "%s;\n", filename);
|
||||
fprintf(octscript, "plot(S%d(:,1),S%d(:,2))\n", d, d);
|
||||
|
||||
properties(beginning, &(info[i+1].perimeter), &(info[i+1].surface));
|
||||
|
||||
info[i+1].depth = info[i].depth + STRIDE;
|
||||
|
||||
/*c[0]++;*/
|
||||
d++;
|
||||
|
||||
}
|
||||
|
||||
output_info(info, NBURN+1, "info.m");
|
||||
|
||||
fclose (octscript);
|
||||
|
||||
dealloc_list(&beginning);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int output_info(grain_info_t *info, int n, char *filename)
|
||||
{
|
||||
|
||||
FILE *fd;
|
||||
|
||||
int i;
|
||||
|
||||
fd = fopen(filename, "w");
|
||||
|
||||
fprintf(fd, "I = [\n");
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
fprintf(fd, "%f %f %f\n", info[i].depth, info[i].perimeter,
|
||||
info[i].surface);
|
||||
}
|
||||
|
||||
fprintf(fd, "];\n");
|
||||
fclose(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,420 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "shape.h"
|
||||
#include "grain.h"
|
||||
|
||||
#include "output.h"
|
||||
|
||||
int burn_surface(point_t **h, double qt, double radius)
|
||||
{
|
||||
int i;
|
||||
double x1_0, y1_0, x1_1, y1_1;
|
||||
double x1, y1, x2, y2, x3, y3;
|
||||
|
||||
double A, B, C, det, n1, n2, n;
|
||||
|
||||
|
||||
double c_angle; /* cosinus of the angle */
|
||||
/*double s_angle;*/ /* sinus of the angle */
|
||||
|
||||
double distance;
|
||||
double next_distance;
|
||||
|
||||
int itn;
|
||||
double nqt;
|
||||
|
||||
point_t *ptr1;
|
||||
point_t *ptr2;
|
||||
|
||||
/* do itn iteration to have small enough step */
|
||||
itn = (int) ceil(3 * qt / MIN_DIST);
|
||||
|
||||
nqt = qt/itn;
|
||||
|
||||
printf("Number of iteration need: %d\n", itn);
|
||||
|
||||
for (i = 0; i < itn; i++)
|
||||
{
|
||||
|
||||
/* first fill the space */
|
||||
adjust_space(h);
|
||||
|
||||
|
||||
ptr1 = *h;
|
||||
ptr2 = ptr1->next;
|
||||
|
||||
x1_0 = ptr1->x;
|
||||
y1_0 = ptr1->y;
|
||||
x1_1 = ptr2->x;
|
||||
y1_1 = ptr2->y;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
x1 = ptr1->x;
|
||||
y1 = ptr1->y;
|
||||
|
||||
x2 = ptr2->x;
|
||||
y2 = ptr2->y;
|
||||
|
||||
x3 = ptr2->next->x;
|
||||
y3 = ptr2->next->y;
|
||||
|
||||
distance = sqrt( pow(x2-x1, 2) + pow(y2-y1, 2) );
|
||||
next_distance = sqrt( pow(x3-x2, 2) + pow(y3-y2, 2) );
|
||||
|
||||
/* compute the cosinus of the angle between the two next line segment
|
||||
using the scalar product */
|
||||
c_angle = ((x2-x1)*(x3-x2) + (y2-y1)*(y3-y2))/(distance * next_distance);
|
||||
/* compute the sinus of the angle between the two next line segment
|
||||
using the vectorial product */
|
||||
/*s_angle = (x1*y2-x2*y1) / (distance * next_distance);*/
|
||||
|
||||
if ((c_angle < 0))/* && (s_angle > 0))*/
|
||||
{
|
||||
delete_next_point(ptr1);
|
||||
|
||||
if (ptr2 == *h)
|
||||
*h = ptr1->next;
|
||||
|
||||
ptr2 = ptr1->next;
|
||||
x2 = ptr2->x;
|
||||
y2 = ptr2->y;
|
||||
x3 = ptr2->next->x;
|
||||
y3 = ptr2->next->y;
|
||||
distance = sqrt( pow(x2-x1, 2) + pow(y2-y1, 2) );
|
||||
next_distance = sqrt( pow(x3-x2, 2) + pow(y3-y2, 2) );
|
||||
|
||||
if (distance < MIN_DIST/2.0)
|
||||
merge_point(ptr1);
|
||||
|
||||
ptr2 = ptr1->next;
|
||||
x1 = ptr1->x;
|
||||
y1 = ptr1->y;
|
||||
x2 = ptr2->x;
|
||||
y2 = ptr2->y;
|
||||
x3 = ptr2->next->x;
|
||||
y3 = ptr2->next->y;
|
||||
distance = sqrt( pow(x2-x1, 2) + pow(y2-y1, 2) );
|
||||
next_distance = sqrt( pow(x3-x2, 2) + pow(y3-y2, 2) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* new point position */
|
||||
ptr1->x = (x1+x2)/2.0 + nqt * (y1-y2)/distance;
|
||||
ptr1->y = (y1+y2)/2.0 + nqt * (x2-x1)/distance;
|
||||
|
||||
/* check if the point has attain the rocket wall */
|
||||
if ((pow(ptr1->x, 2) + pow(ptr1->y, 2)) >= pow(radius, 2))
|
||||
{
|
||||
/* fit the point on the wall */
|
||||
|
||||
A = pow(y1-y2, 2) + pow(x2-x1, 2);
|
||||
B = (x1+x2)*(y1-y2) + (y1+y2)*(x2-x1);
|
||||
C = pow((x1+x2)/2.0, 2) + pow((y1+y2)/2.0, 2) - pow(radius, 2);
|
||||
|
||||
det = sqrt(pow(B, 2) - 4*A*C);
|
||||
n1 = (-B + det)/(2*A);
|
||||
n2 = (-B - det)/(2*A);
|
||||
|
||||
n = ((n1 > n2) ? n1 : n2);
|
||||
if (isnan(n))
|
||||
{
|
||||
printf("Error, isnan...\n");
|
||||
exit(-1);
|
||||
}
|
||||
/* new point position */
|
||||
ptr1->x = (x1+x2)/2.0 + n * (y1-y2);
|
||||
ptr1->y = (y1+y2)/2.0 + n * (x2-x1);
|
||||
|
||||
/* the point has finish burning */
|
||||
ptr1->s = BURNED;
|
||||
}
|
||||
|
||||
ptr1 = ptr2;
|
||||
ptr2 = ptr2->next;
|
||||
|
||||
} while (ptr2 != *h);
|
||||
|
||||
/* the last point is connect with the first one */
|
||||
|
||||
if (ptr1->s == BURNING)
|
||||
{
|
||||
x1 = ptr1->x;
|
||||
y1 = ptr1->y;
|
||||
x2 = x1_0;
|
||||
y2 = y1_0;
|
||||
x3 = x1_1;
|
||||
y3 = y1_1;
|
||||
|
||||
distance = sqrt( pow(x2-x1, 2) + pow(y2-y1, 2) );
|
||||
next_distance = sqrt( pow(x3-x2, 2) + pow(y3-y2, 2) );
|
||||
|
||||
/* compute the angle between the two next line segment
|
||||
using the scalar product */
|
||||
|
||||
c_angle = ((x2-x1)*(x3-x2) + (y2-y1)*(y3-y2))/(distance * next_distance);
|
||||
/*s_angle = (x1*y2-x2*y1) / (distance * next_distance); */
|
||||
|
||||
if ((c_angle < 0))/* && (s_angle > 0))*/
|
||||
{
|
||||
delete_next_point(ptr1->prev);
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr1->x = (x1+x2)/2 + nqt * (y1-y2)/distance;
|
||||
ptr1->y = (y1+y2)/2 + nqt * (x2-x1)/distance;
|
||||
|
||||
|
||||
if ((pow(ptr1->x, 2) + pow(ptr1->y, 2)) >= pow(radius, 2))
|
||||
{
|
||||
/* fit the point on the wall */
|
||||
A = pow(y1-y2, 2) + pow(x2-x1, 2);
|
||||
B = (x1+x2)*(y1-y2) + (y1+y2)*(x2-x1);
|
||||
C = pow((x1+x2)/2.0, 2) + pow((y1+y2)/2.0, 2) - pow(radius, 2);
|
||||
|
||||
det = sqrt(pow(B, 2) - 4*A*C);
|
||||
n1 = (-B + det)/(2*A);
|
||||
n2 = (-B - det)/(2*A);
|
||||
|
||||
n = ((n1 > n2) ? n1 : n2);
|
||||
if (isnan(n))
|
||||
{
|
||||
printf("Error, isnan...\n");
|
||||
exit(-1);
|
||||
}
|
||||
/* new point position */
|
||||
ptr1->x = (x1+x2)/2.0 + n * (y1-y2);
|
||||
ptr1->y = (y1+y2)/2.0 + n * (x2-x1);
|
||||
|
||||
/* the point has finish burning */
|
||||
ptr1->s = BURNED;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* verify if there is line crossing for the new surface */
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int create_list(point_t **h, int nb)
|
||||
{
|
||||
int i;
|
||||
point_t *ptr;
|
||||
|
||||
*h = (point_t *) malloc(sizeof(point_t));
|
||||
ptr = *h;
|
||||
|
||||
for (i = 0; i < nb-1; i++)
|
||||
{
|
||||
ptr->next = (point_t *) malloc(sizeof(point_t));
|
||||
ptr->next->prev = ptr;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
ptr->next = *h; /* the las element point to the first */
|
||||
|
||||
(*h)->prev = ptr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dealloc_list(point_t **h)
|
||||
{
|
||||
point_t *ptr;
|
||||
point_t *next;
|
||||
|
||||
ptr = *h;
|
||||
next = ptr->next;
|
||||
|
||||
do
|
||||
{
|
||||
free(ptr);
|
||||
ptr = next;
|
||||
next = ptr->next;
|
||||
} while (ptr != *h);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int properties(point_t *h, double *perimeter, double *surface)
|
||||
{
|
||||
point_t *ptr1;
|
||||
point_t *ptr2;
|
||||
|
||||
double x1, y1, x2, y2;
|
||||
|
||||
*perimeter = 0.0;
|
||||
*surface = 0.0;
|
||||
|
||||
ptr1 = h;
|
||||
ptr2 = ptr1->next;
|
||||
|
||||
do
|
||||
{
|
||||
x1 = ptr1->x;
|
||||
y1 = ptr1->y;
|
||||
|
||||
x2 = ptr2->x;
|
||||
y2 = ptr2->y;
|
||||
|
||||
/* We can compute the inside surface by the green-riemann theorem
|
||||
A = integral (x dy - y dx)/2 on the closed curve */
|
||||
*surface += fabs((x1*(y2-y1) - y1*(x2-x1)))/2;
|
||||
|
||||
if (ptr1->s == BURNING)
|
||||
*perimeter += sqrt( pow(x2-x1, 2) + pow(y2-y1, 2) );
|
||||
|
||||
ptr1 = ptr2;
|
||||
ptr2 = ptr2->next;
|
||||
|
||||
} while (ptr1 != h);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int adjust_space (point_t **h)
|
||||
{
|
||||
point_t *ptr1, *ptr2;
|
||||
double x1, x2, x3, y1, y2, y3;
|
||||
double distance;
|
||||
|
||||
double next_distance;
|
||||
|
||||
/* when the first distance is too litle, we go out of the
|
||||
while statement because ptr1 point gain to the header,
|
||||
so we have to check if the first point was done */
|
||||
short first_done = 0;
|
||||
|
||||
ptr1 = *h;
|
||||
|
||||
ptr2 = ptr1->next;
|
||||
do
|
||||
{
|
||||
x1 = ptr1->x;
|
||||
y1 = ptr1->y;
|
||||
|
||||
x2 = ptr2->x;
|
||||
y2 = ptr2->y;
|
||||
|
||||
x3 = ptr2->next->x;
|
||||
y3 = ptr2->next->y;
|
||||
|
||||
distance = sqrt( pow(x2-x1, 2) + pow(y2-y1, 2) );
|
||||
|
||||
/* insert new points if the distance is too large */
|
||||
if (distance > (3.0*MIN_DIST))
|
||||
{
|
||||
do
|
||||
{
|
||||
insert_point(ptr1);
|
||||
ptr2 = ptr1->next;
|
||||
x2 = ptr2->x;
|
||||
y2 = ptr2->y;
|
||||
distance = sqrt( pow(x2-x1, 2) + pow(y2-y1, 2) );
|
||||
} while (distance > (3.0*MIN_DIST));
|
||||
|
||||
ptr1 = ptr2;
|
||||
ptr2 = ptr2->next;
|
||||
|
||||
}
|
||||
else if (distance < MIN_DIST/2.0)
|
||||
{
|
||||
next_distance = sqrt( pow(x3-x2, 2) + pow(y3-y2, 2) );
|
||||
|
||||
if (next_distance < MIN_DIST/2.0)
|
||||
{
|
||||
delete_next_point(ptr1);
|
||||
|
||||
if (ptr2 == *h) /* do not delete the beginning point !! */
|
||||
{
|
||||
*h = ptr1->next;
|
||||
}
|
||||
|
||||
ptr2 = ptr1->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr1 = ptr2;
|
||||
ptr2 = ptr2->next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr1 = ptr2;
|
||||
ptr2 = ptr2->next;
|
||||
}
|
||||
|
||||
if (!(first_done) && (ptr1 != *h))
|
||||
first_done = 1;
|
||||
|
||||
} while ((ptr1 != *h) || !(first_done));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int insert_point(point_t *p)
|
||||
{
|
||||
point_t *ptr;
|
||||
|
||||
ptr = (point_t *) malloc(sizeof(point_t));
|
||||
|
||||
/* insert the point in the list */
|
||||
ptr->next = p->next;
|
||||
ptr->next->prev = ptr;
|
||||
|
||||
p->next = ptr;
|
||||
ptr->prev = p;
|
||||
|
||||
/* set the point value in the middle of the other */
|
||||
ptr->x = (p->x + ptr->next->x)/2;
|
||||
ptr->y = (p->y + ptr->next->y)/2;
|
||||
|
||||
ptr->s = p->s;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int merge_point(point_t *p)
|
||||
{
|
||||
|
||||
point_t *ptr;
|
||||
|
||||
ptr = p->next;
|
||||
/* The point will be move in the middle of the two points */
|
||||
p->x = (p->x + ptr->x)/2;
|
||||
p->y = (p->y + ptr->y)/2;
|
||||
|
||||
p->next = ptr->next;
|
||||
ptr->next->prev = p;
|
||||
|
||||
free(ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int delete_next_point(point_t *p)
|
||||
{
|
||||
point_t *ptr;
|
||||
ptr = p->next;
|
||||
p->next = ptr->next;
|
||||
ptr->next->prev = p;
|
||||
free(ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef grain_h
|
||||
#define grain_h
|
||||
|
||||
|
||||
#define MIN_DIST 0.05
|
||||
|
||||
#define SQRT_3 1.732050807568877
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BURNING,
|
||||
BURNED
|
||||
} point_state_t;
|
||||
|
||||
typedef struct _point
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
point_state_t s;
|
||||
struct _point *prev;
|
||||
struct _point *next;
|
||||
} point_t;
|
||||
|
||||
int adjust_space (point_t **h);
|
||||
int fill_space (point_t *h);
|
||||
int insert_point (point_t *p);
|
||||
int merge_point (point_t *p);
|
||||
int delete_next_point (point_t *p);
|
||||
|
||||
int create_list(point_t **h, int nb);
|
||||
int burn_surface(point_t **h, double qt, double radius);
|
||||
int properties(point_t *h, double *perimeter, double *surface);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
LIB = -lm
|
||||
PROG = grain
|
||||
OBJS = gba.o grain.o shape.o output.o
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "grain.h"
|
||||
|
||||
int output_matlab(point_t *h, char *filename, int id)
|
||||
{
|
||||
FILE *fd;
|
||||
char header[10];
|
||||
point_t *ptr;
|
||||
|
||||
ptr = h;
|
||||
|
||||
sprintf(header, "S%d = [\n", id);
|
||||
fd = fopen(filename, "w");
|
||||
fprintf(fd, header);
|
||||
|
||||
do
|
||||
{
|
||||
fprintf(fd, "% .15f, % .15f\n", ptr->x, ptr->y);
|
||||
ptr = ptr->next;
|
||||
} while (ptr != h);
|
||||
|
||||
fprintf(fd, "% .15f, % .15f\n", ptr->x, ptr->y);
|
||||
|
||||
fprintf(fd, "];\n");
|
||||
|
||||
fclose(fd);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef output_h
|
||||
#define output_h
|
||||
|
||||
int output_matlab(point_t *h, char *filename, char id);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "grain.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
int build_triangular(point_t *h, int nb_point, double c)
|
||||
{
|
||||
int i;
|
||||
point_t *ptr;
|
||||
|
||||
ptr = h;
|
||||
|
||||
for (i = 0; i < nb_point/3; i++)
|
||||
{
|
||||
ptr->x = (c/2.0) * (3.0*i/nb_point - 1.0);
|
||||
ptr->y = (SQRT_3*c/2.0) * (3.0*i/nb_point - 1.0/3.0);
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
for (i = 0; i < nb_point/3; i++)
|
||||
{
|
||||
ptr->x = (c/2.0) * (3.0*i/nb_point);
|
||||
ptr->y = (SQRT_3*c/2.0) * (2.0/3.0 - 3.0*i/nb_point);
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
for (i = 0; i < nb_point/3; i++)
|
||||
{
|
||||
ptr->x = c * (1.0/2.0 - 3.0*i/nb_point);
|
||||
ptr->y = (SQRT_3*c/2.0) * (-1.0/3.0);
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int build_nuclear(point_t *h, int nb_point, double r1, double r2, int n)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
point_t *ptr;
|
||||
|
||||
ptr = h;
|
||||
|
||||
for (i = 0; i < 2*n; i++)
|
||||
{
|
||||
if (i%2 == 0)
|
||||
{
|
||||
for (j = 0; j < nb_point/(2*n); j++)
|
||||
{
|
||||
ptr->x = r1*sin((i*M_PI/n)+(j*2*M_PI/nb_point));
|
||||
ptr->y = r1*cos((i*M_PI/n)+(j*2*M_PI/nb_point));
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < nb_point/(2*n); j++)
|
||||
{
|
||||
ptr->x = r2*sin((i*M_PI/n)+(j*2*M_PI/nb_point));
|
||||
ptr->y = r2*cos((i*M_PI/n)+(j*2*M_PI/nb_point));
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int build_rectangular(point_t *h, int nb_point, double width, double height)
|
||||
{
|
||||
point_t *ptr;
|
||||
|
||||
ptr = h;
|
||||
|
||||
ptr->x = width/2;
|
||||
ptr->y = height/2;
|
||||
ptr->s = BURNING;
|
||||
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = width/2;
|
||||
ptr->y = -height/2;
|
||||
ptr->s = BURNING;
|
||||
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = -width/2;
|
||||
ptr->y = -height/2;
|
||||
ptr->s = BURNING;
|
||||
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = -width/2;
|
||||
ptr->y = height/2;
|
||||
ptr->s = BURNING;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int build_cross(point_t *h, int nb_point, double width, double height)
|
||||
{
|
||||
point_t *ptr;
|
||||
|
||||
ptr = h;
|
||||
|
||||
ptr->x = width/2;
|
||||
ptr->y = height/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = width/2;
|
||||
ptr->y = width/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = height/2;
|
||||
ptr->y = width/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = height/2;
|
||||
ptr->y = -width/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = width/2;
|
||||
ptr->y = -width/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = width/2;
|
||||
ptr->y = -height/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = -width/2;
|
||||
ptr->y = -height/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = -width/2;
|
||||
ptr->y = -width/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = -height/2;
|
||||
ptr->y = -width/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = -height/2;
|
||||
ptr->y = width/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = -width/2;
|
||||
ptr->y = width/2;
|
||||
ptr->s = BURNING;
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->x = -width/2;
|
||||
ptr->y = height/2;
|
||||
ptr->s = BURNING;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int build_round(point_t *h, int nb_point, double r)
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
double inc;
|
||||
double angle;
|
||||
|
||||
point_t *ptr;
|
||||
|
||||
ptr = h;
|
||||
|
||||
inc = 2*M_PI/nb_point;
|
||||
|
||||
angle = 0;
|
||||
|
||||
for (i = 0; i < nb_point; i++)
|
||||
{
|
||||
ptr->x = r*cos(angle);
|
||||
ptr->y = r*sin(angle);
|
||||
ptr->s = BURNING;
|
||||
|
||||
angle -= inc;
|
||||
|
||||
ptr = ptr->next;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef shape_h
|
||||
#define shape_h
|
||||
|
||||
#include "grain.h"
|
||||
|
||||
int build_triangular(point_t *h, int nb_point, double c);
|
||||
int build_nuclear(point_t *h, int nb_point, double r1, double r2, int n);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,132 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct _star
|
||||
{
|
||||
int N;
|
||||
double n;
|
||||
double e;
|
||||
double R;
|
||||
double w;
|
||||
double r1;
|
||||
double r2;
|
||||
} star_t;
|
||||
|
||||
double torad(double deg);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
star_t star;
|
||||
|
||||
double x, y;
|
||||
double dx, dy;
|
||||
|
||||
star.N = 6;
|
||||
star.n = 33.53;
|
||||
star.e = 30;
|
||||
star.R = 1.5;
|
||||
star.w = 0.5;
|
||||
star.r1 = 0.0625;
|
||||
star.r2 = 0.0625;
|
||||
|
||||
/* header */
|
||||
printf("%%!PS-Adobe-1.0\n");
|
||||
printf("%%%%BoundingBox: 0 0 595 842\n");
|
||||
printf("/cm {72 mul} def\n");
|
||||
printf("/n {newpath} def\n");
|
||||
printf("/s {stroke} def\n");
|
||||
printf("/t {translate} def\n");
|
||||
printf("0 setgray\n");
|
||||
printf("1.5 setlinewidth\n");
|
||||
printf("2 cm 2 cm t\n");
|
||||
|
||||
/* external circle */
|
||||
|
||||
printf("n %.10f cm %.10f cm %.10f cm %.10f %.10f arc s\n", 0., 0.,
|
||||
star.R, 0., 360.);
|
||||
|
||||
printf("0 %d 360 {\n", (int) 360.0/star.N);
|
||||
printf(" gsave\n rotate\n");
|
||||
|
||||
/* star shape first part*/
|
||||
printf("n %.10f cm %.10f cm %.10f cm %.10f %.10f arc s\n",
|
||||
0., 0., (star.R - star.w),
|
||||
90.0 - 180.0/star.N,
|
||||
90.0 - star.e);
|
||||
|
||||
printf("n %.10f cm %.10f cm %.10f cm %.10f %.10f arc s\n",
|
||||
(star.R - star.w - star.r1)*cos(torad(90 - star.e)),
|
||||
(star.R - star.w - star.r1)*sin(torad(90 - star.e)),
|
||||
star.r1,
|
||||
90.0 - star.e,
|
||||
180.0 - star.n);
|
||||
|
||||
x = (star.R - star.w - star.r1)*cos(torad(90 - star.e)) -
|
||||
star.r1*cos(torad(star.n));
|
||||
// star.r1*cos(torad(180.0 + star.e - star.n - 180.0/star.N));
|
||||
y = (star.R - star.w - star.r1)*sin(torad(90 - star.e)) +
|
||||
star.r1*sin(torad(star.n));
|
||||
// star.r1*sin(torad(180.0 + star.e - star.n - 180.0/star.N));
|
||||
|
||||
dx = -((star.R-star.w-star.r1)*sin(torad(star.e))/sin(torad(star.n)) -
|
||||
star.r1*tan(torad(90.0 - star.n)) -
|
||||
star.r2*tan(torad(90.0 - star.n))
|
||||
)*sin(torad(star.n));
|
||||
|
||||
dy = -((star.R-star.w-star.r1)*sin(torad(star.e))/sin(torad(star.n)) -
|
||||
star.r1*tan(torad(90.0 - star.n)) -
|
||||
star.r2*tan(torad(90.0 - star.n))
|
||||
)*cos(torad(star.n));
|
||||
|
||||
printf("n %.10f cm %.10f cm moveto \n", x, y);
|
||||
printf("%.10f cm %.10f cm lineto s\n", x+dx, y+dy);
|
||||
|
||||
/* circle */
|
||||
|
||||
x = (star.R - star.w - star.r1)*cos(torad(90 - star.e)) +
|
||||
star.r1*cos(torad(180.0 + star.e - star.n - 180.0/star.N)) +
|
||||
dx - star.r2*cos(torad(star.n));
|
||||
|
||||
y = (star.R - star.w - star.r1)*sin(torad(90 - star.e)) +
|
||||
star.r1*sin(torad(star.n)) +
|
||||
dy + star.r2*sin(torad(star.n));
|
||||
|
||||
printf("n %.10f cm %.10f cm %.10f cm %.10f %.10f arc s\n", 0., y, star.r2,
|
||||
-180+star.n, -star.n);
|
||||
|
||||
//printf("n -1 cm %.10f cm moveto 1 cm 0 cm rlineto s\n", y);
|
||||
|
||||
/* second part */
|
||||
printf("n %.10f cm %.10f cm %.10f cm %.10f %.10f arc s\n",
|
||||
0., 0., (star.R - star.w),
|
||||
90.0 + star.e,
|
||||
90.0 + 180.0/star.N);
|
||||
|
||||
printf("n %.10f cm %.10f cm %.10f cm %.10f %.10f arc s\n",
|
||||
-(star.R - star.w - star.r1)*cos(torad(90 - star.e)),
|
||||
(star.R - star.w - star.r1)*sin(torad(90 - star.e)),
|
||||
star.r1,
|
||||
star.n,
|
||||
90.0 + star.e);
|
||||
|
||||
x = -(star.R - star.w - star.r1)*cos(torad(90 - star.e)) +
|
||||
star.r1*cos(torad(star.n));
|
||||
//star.r1*cos(torad(star.n + 180.0/star.N - star.e));
|
||||
y = (star.R - star.w - star.r1)*sin(torad(90 - star.e)) +
|
||||
star.r1*sin(torad(star.n));
|
||||
//star.r1*sin(torad(star.n + 180.0/star.N - star.e));
|
||||
|
||||
printf("%.10f cm %.10f cm moveto\n", x, y);
|
||||
printf("%.10f cm %.10f cm rlineto s\n",-dx, dy);
|
||||
|
||||
printf(" grestore\n} for\n");
|
||||
|
||||
printf("showpage\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
double torad(double deg)
|
||||
{
|
||||
return deg*2*M_PI/360;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
@@ -0,0 +1,265 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cgi.h>
|
||||
|
||||
|
||||
#include "libcpropep/include/equilibrium.h"
|
||||
#include "libcpropep/include/performance.h"
|
||||
#include "libthermo/include/thermo.h"
|
||||
#include "libcpropep/include/conversion.h"
|
||||
|
||||
#include "libthermo/include/load.h"
|
||||
#include "libcpropep/include/print.h"
|
||||
|
||||
#include "liblrd/include/lrd.h"
|
||||
|
||||
s_cgi *cgi;
|
||||
|
||||
#ifdef SOURCEFORGE
|
||||
#define THERMO_PATH "thermo.dat"
|
||||
#define PROPELLANT_PATH "propellant.dat"
|
||||
#else
|
||||
#define THERMO_PATH "/home/antoine/projets/rocket/rocketworkbench/data/thermo.dat"
|
||||
#define PROPELLANT_PATH "/home/antoine/projets/rocket/rocketworkbench/data/propellant.dat"
|
||||
#endif
|
||||
|
||||
|
||||
int init_equil(void)
|
||||
{
|
||||
if (load_thermo (THERMO_PATH) < 0)
|
||||
return -1;
|
||||
if (load_propellant (PROPELLANT_PATH) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void destroy(void)
|
||||
{
|
||||
free (propellant_list);
|
||||
free (thermo_list);
|
||||
}
|
||||
|
||||
int eval_cgi(liquid_propellant_t *p, design_param_t *d)
|
||||
{
|
||||
int sp;
|
||||
|
||||
char buffer[64];
|
||||
double tmp;
|
||||
double tmp1;
|
||||
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "oxidant"), 64);
|
||||
sp = atoi(buffer);
|
||||
|
||||
if ((sp >= 0) && (sp < num_propellant))
|
||||
{
|
||||
p->oxidant = sp;
|
||||
}
|
||||
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "fuel"), 64);
|
||||
sp = atoi(buffer);
|
||||
|
||||
|
||||
if ((sp >= 0) && (sp < num_propellant))
|
||||
{
|
||||
p->fuel = sp;
|
||||
}
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "ratio"), 64);
|
||||
tmp = atof(buffer);
|
||||
|
||||
if (tmp >= 0.0)
|
||||
{
|
||||
p->o_f_ratio = tmp;
|
||||
}
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "pressure"), 64);
|
||||
tmp = atof(buffer);
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "pressure_unit"), 64);
|
||||
|
||||
if (tmp > 0.0)
|
||||
{
|
||||
if (strcmp(buffer, "atm") == 0)
|
||||
{
|
||||
d->chamber_pressure = tmp;
|
||||
}
|
||||
else if (strcmp(buffer, "psi") == 0)
|
||||
{
|
||||
d->chamber_pressure = tmp * PSI_TO_ATM;
|
||||
}
|
||||
}
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "thrust"), 64);
|
||||
tmp = atof(buffer);
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "thrust_unit"), 64);
|
||||
|
||||
if (tmp > 0.0)
|
||||
{
|
||||
if (strcmp(buffer, "newton") == 0)
|
||||
{
|
||||
d->thrust = tmp;
|
||||
}
|
||||
else if (strcmp(buffer, "pound-force") == 0)
|
||||
{
|
||||
d->thrust = tmp * LBF_TO_N;
|
||||
}
|
||||
}
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "lstar"), 64);
|
||||
tmp = atof(buffer);
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "length_unit"), 64);
|
||||
|
||||
if (tmp > 0.0)
|
||||
{
|
||||
if (strcmp(buffer, "m") == 0)
|
||||
{
|
||||
d->Lstar = tmp;
|
||||
}
|
||||
else if (strcmp(buffer, "in") == 0)
|
||||
{
|
||||
d->Lstar = tmp * IN_TO_M;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "dc_dt"), 64);
|
||||
tmp = atof(buffer);
|
||||
|
||||
d->Dc_Dt = tmp;
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "r_rt"), 64);
|
||||
tmp = atof(buffer);
|
||||
|
||||
d->R_Rt = tmp;
|
||||
|
||||
strncpy(buffer, cgiGetValue(cgi, "theta"), 64);
|
||||
tmp = atof(buffer);
|
||||
|
||||
d->theta = tmp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char **argv, char **env)
|
||||
{
|
||||
short i;
|
||||
|
||||
char *path_info = NULL;
|
||||
|
||||
char buffer[32];
|
||||
|
||||
double value;
|
||||
int val;
|
||||
|
||||
liquid_propellant_t p;
|
||||
design_param_t param;
|
||||
motor_t motor_frozen,
|
||||
motor_shifting;
|
||||
|
||||
equilibrium_t *frozen,
|
||||
*shifting;
|
||||
|
||||
|
||||
errorfile = stdout;
|
||||
outputfile = stdout;
|
||||
|
||||
cgiDebug(0, 0);
|
||||
cgi = cgiInit();
|
||||
|
||||
global_verbose = 0;
|
||||
|
||||
path_info = getenv("PATH_INFO");
|
||||
|
||||
if (path_info)
|
||||
{
|
||||
if (!strcmp(path_info, "/design"))
|
||||
{
|
||||
cgiHeader();
|
||||
printf("<pre>");
|
||||
|
||||
frozen = (equilibrium_t *) malloc (sizeof(equilibrium_t) * 3);
|
||||
shifting = (equilibrium_t *) malloc (sizeof(equilibrium_t) * 3);
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
initialize_equilibrium(frozen + i);
|
||||
initialize_equilibrium(shifting + i);
|
||||
}
|
||||
|
||||
if (init_equil())
|
||||
{
|
||||
printf("Problem loading data file.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
eval_cgi(&p, ¶m);
|
||||
|
||||
add_in_propellant(frozen, p.fuel, GRAM_TO_MOL(10.0, p.fuel));
|
||||
add_in_propellant(frozen, p.oxidant, GRAM_TO_MOL(10.0 * p.o_f_ratio,
|
||||
p.oxidant));
|
||||
|
||||
copy_equilibrium(shifting, frozen);
|
||||
|
||||
printf("Liquid-fuel rocket engine design (lrd).\n\n");
|
||||
|
||||
LRD_print_propellant_info(&p);
|
||||
LRD_print_design_criteria(¶m);
|
||||
|
||||
frozen->properties.P = param.chamber_pressure;
|
||||
equilibrium(frozen, HP);
|
||||
frozen_performance(frozen, PRESSURE, 1);
|
||||
|
||||
LRD_compute_caracteristics(frozen, ¶m, &motor_frozen, &p);
|
||||
|
||||
shifting->properties.P = param.chamber_pressure;
|
||||
equilibrium(shifting, HP);
|
||||
shifting_performance(shifting, PRESSURE, 1);
|
||||
|
||||
LRD_compute_caracteristics(shifting, ¶m, &motor_shifting, &p);
|
||||
|
||||
LRD_print_design_information(&motor_frozen, &motor_shifting);
|
||||
|
||||
printf("\nFrozen equilibrium caracteristics.\n\n");
|
||||
print_product_properties(frozen, 3);
|
||||
print_performance_information(frozen, 3);
|
||||
print_product_composition(frozen, 3);
|
||||
|
||||
printf("\nShifting equilibrium caracteristics.\n\n");
|
||||
print_product_properties(shifting, 3);
|
||||
print_performance_information(shifting, 3);
|
||||
print_product_composition(shifting, 3);
|
||||
|
||||
|
||||
free(frozen);
|
||||
free(shifting);
|
||||
|
||||
printf("</pre>");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
cgiHeader();
|
||||
printf("<br>Bad queries<br>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cgiHeader();
|
||||
printf("<br>Bad PATH_INFO<br>");
|
||||
}
|
||||
|
||||
printf ("\n<hr>\n</body>\n</html>\n");
|
||||
|
||||
destroy();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
LIB = -lcpropep -lthermo -llrd -lm -lnum -lcgi
|
||||
PROG = lrd.cgi
|
||||
OBJS = lrdcgi.o
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
@@ -0,0 +1,181 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libcpropep/include/conversion.h"
|
||||
|
||||
#include "liblrd/include/lrd.h"
|
||||
|
||||
int load_input(char *filename, design_param_t *d, liquid_propellant_t *p)
|
||||
{
|
||||
int section = 0;
|
||||
|
||||
FILE *fd;
|
||||
|
||||
double sp;
|
||||
|
||||
char buffer[128], keyword[64], num[10], qt[10], unit[10];
|
||||
|
||||
char *bufptr;
|
||||
|
||||
fd = fopen(filename, "r");
|
||||
|
||||
if (fd == NULL)
|
||||
return -1;
|
||||
|
||||
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, "Parameter", 9) == 0)
|
||||
{
|
||||
section = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown keyword 1.\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
if (buffer[0] == '+')
|
||||
{
|
||||
sscanf(buffer, "%s %s", keyword, num);
|
||||
bufptr = keyword + 1;
|
||||
|
||||
sp = atof(num);
|
||||
|
||||
if (strcmp(bufptr, "oxidant") == 0)
|
||||
{
|
||||
p->oxidant = (int) sp;
|
||||
}
|
||||
else if (strcmp(bufptr, "fuel") == 0)
|
||||
{
|
||||
p->fuel = (int) sp;
|
||||
}
|
||||
else if (strcmp(bufptr, "o/f") == 0)
|
||||
{
|
||||
p->o_f_ratio = sp;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown keyword 2.\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (buffer[0] == '#')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (buffer[0] == ' ' || buffer[0] == '\n' || buffer[0] == '\0')
|
||||
{
|
||||
section = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
if (buffer[0] == '+')
|
||||
{
|
||||
sscanf(buffer, "%s %s %s", keyword, num, unit);
|
||||
bufptr = keyword + 1;
|
||||
|
||||
sp = atof(num);
|
||||
|
||||
if (strcmp(bufptr, "chamber_pressure") == 0)
|
||||
{
|
||||
if (strcmp(unit, "atm") == 0)
|
||||
{
|
||||
d->chamber_pressure = sp;
|
||||
}
|
||||
else if (strcmp(unit, "psi") == 0)
|
||||
{
|
||||
d->chamber_pressure = sp * PSI_TO_ATM;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown unit.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
else if (strcmp(bufptr, "thrust") == 0)
|
||||
{
|
||||
if (strcmp(unit, "N") == 0)
|
||||
{
|
||||
d->thrust = sp;
|
||||
}
|
||||
else if (strcmp(unit, "lbf") == 0)
|
||||
{
|
||||
d->thrust = sp * LBF_TO_N;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown unit.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (strcmp(bufptr, "L*") == 0)
|
||||
{
|
||||
if (strcmp(unit, "m") == 0)
|
||||
{
|
||||
d->Lstar = sp;
|
||||
}
|
||||
else if (strcmp(unit, "in") == 0)
|
||||
{
|
||||
d->Lstar = sp * IN_TO_M;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown unit.\n");
|
||||
}
|
||||
}
|
||||
else if (strcmp(bufptr, "Dc/Dt") == 0)
|
||||
{
|
||||
d->Dc_Dt = sp;
|
||||
}
|
||||
else if (strcmp(bufptr, "theta") == 0)
|
||||
{
|
||||
d->theta = sp;
|
||||
}
|
||||
else if (strcmp(bufptr, "r_rt") == 0)
|
||||
{
|
||||
d->R_Rt = sp;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown keyword 3.\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (buffer[0] == '#')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (buffer[0] == ' ' || buffer[0] == '\n' || buffer[0] == '\0')
|
||||
{
|
||||
section = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef lrd_load_h
|
||||
#define lrd_load_h
|
||||
|
||||
#include "liblrd/include/lrd.h"
|
||||
|
||||
int load_input(char *filename, design_param_t *d, liquid_propellant_t *p);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,92 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "libthermo/include/load.h"
|
||||
#include "libcpropep/include/print.h"
|
||||
#include "libthermo/include/thermo.h"
|
||||
|
||||
#include "lrd_load.h"
|
||||
#include "liblrd/include/lrd.h"
|
||||
|
||||
#define THERMO_FILE "../../data/thermo.dat"
|
||||
#define PROPELLANT_FILE "../../data/propellant.dat"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
liquid_propellant_t p;
|
||||
design_param_t param;
|
||||
motor_t motor_frozen,
|
||||
motor_shifting;
|
||||
|
||||
equilibrium_t *frozen,
|
||||
*shifting;
|
||||
|
||||
|
||||
load_input("input.lr", ¶m, &p);
|
||||
|
||||
/* Initialisation of cpropep lib */
|
||||
errorfile = stdout;
|
||||
outputfile = stdout;
|
||||
|
||||
if (load_thermo (THERMO_FILE) < 0)
|
||||
{
|
||||
printf("Error loading thermodynamic data file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (load_propellant (PROPELLANT_FILE) < 0)
|
||||
{
|
||||
printf("Error loading propellant data file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
frozen = (equilibrium_t *) malloc (sizeof(equilibrium_t) * 3);
|
||||
shifting = (equilibrium_t *) malloc (sizeof(equilibrium_t) * 3);
|
||||
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
initialize_equilibrium(frozen + i);
|
||||
initialize_equilibrium(shifting + i);
|
||||
}
|
||||
|
||||
add_in_propellant(frozen, p.fuel, GRAM_TO_MOL(10.0, p.fuel));
|
||||
add_in_propellant(frozen, p.oxidant, GRAM_TO_MOL(10.0 * p.o_f_ratio, p.oxidant));
|
||||
|
||||
copy_equilibrium(shifting, frozen);
|
||||
|
||||
printf("Liquid-fuel rocket engine design (lrd).\n\n");
|
||||
|
||||
LRD_print_propellant_info(&p);
|
||||
LRD_print_design_criteria(¶m);
|
||||
|
||||
frozen->properties.P = param.chamber_pressure;
|
||||
equilibrium(frozen, HP);
|
||||
frozen_performance(frozen, PRESSURE, 1);
|
||||
|
||||
LRD_compute_caracteristics(frozen, ¶m, &motor_frozen, &p);
|
||||
|
||||
shifting->properties.P = param.chamber_pressure;
|
||||
equilibrium(shifting, HP);
|
||||
shifting_performance(shifting, PRESSURE, 1);
|
||||
|
||||
LRD_compute_caracteristics(shifting, ¶m, &motor_shifting, &p);
|
||||
|
||||
LRD_print_design_information(&motor_frozen, &motor_shifting);
|
||||
|
||||
printf("\nFrozen equilibrium caracteristics.\n\n");
|
||||
print_product_properties(frozen, 3);
|
||||
print_performance_information(frozen, 3);
|
||||
print_product_composition(frozen, 3);
|
||||
|
||||
printf("\nShifting equilibrium caracteristics.\n\n");
|
||||
print_product_properties(shifting, 3);
|
||||
print_performance_information(shifting, 3);
|
||||
print_product_composition(shifting, 3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
LIB = -lcpropep -lthermo -lnum -llrd -lm
|
||||
PROG = lrd
|
||||
OBJS = main.o lrd_load.o
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
LIB = -lmcp -lcpropep -lthermo -lnum -lm
|
||||
PROG = mcp
|
||||
OBJS1 = modele.o test.o
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libmcp/include/mcp.h"
|
||||
|
||||
#include "libcpropep/include/equilibrium.h"
|
||||
#include "libcpropep/include/performance.h"
|
||||
|
||||
#include "libcpropep/include/conversion.h"
|
||||
#include "libcpropep/include/const.h"
|
||||
|
||||
int modele(int neq, double time, double *y, double *dy, void *data)
|
||||
{
|
||||
|
||||
data_t *d; /* structure containing the data */
|
||||
|
||||
double ld; /* linear density of propellant kg/m */
|
||||
double tmdot; /* throat mass flow rate */
|
||||
|
||||
|
||||
double s; /* linear distance already burned (m) */
|
||||
double p; /* pressure (atm) */
|
||||
|
||||
double t; /* thrust in Newton */
|
||||
|
||||
d = (data_t *) data;
|
||||
|
||||
s = y[0];
|
||||
p = y[1];
|
||||
|
||||
|
||||
d->e->properties.P = p;
|
||||
|
||||
equilibrium(d->e, HP);
|
||||
frozen_performance(d->e, SUPERSONIC_AREA_RATIO, d->ea/d->ta);
|
||||
|
||||
ld = (d->Ab)(s) * (d->e->propellant.density * 1000); /* kg/m */
|
||||
tmdot = d->ta * ATM_TO_PA / (d->e + 1)->performance.a_dotm; /* kg/s */
|
||||
|
||||
dy[0] = d->a * pow(p, d->n);
|
||||
|
||||
dy[1] = (R*1000*d->e->properties.T/(d->Vc)(s)) *
|
||||
(ld*dy[0] - tmdot) / (d->e->properties.M * ATM_TO_PA);
|
||||
|
||||
/*
|
||||
printf("%.2e %.2e %.2e %.2e %.2e\n",
|
||||
time,
|
||||
d->e->properties.T,
|
||||
d->e->properties.M,
|
||||
(d->e + 2)->performance.Isp,
|
||||
tmdot*(d->e + 2)->performance.Isp);
|
||||
*/
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#include "libnum/include/num.h"
|
||||
#include "libcpropep/include/equilibrium.h"
|
||||
#include "libthermo/include/thermo.h"
|
||||
|
||||
#include "libmcp/include/mcp.h"
|
||||
#include "libthermo/include/load.h"
|
||||
#include "libcpropep/include/print.h"
|
||||
|
||||
#define NEQ 2
|
||||
|
||||
#define NPOINT 300
|
||||
#define STEP 0.002
|
||||
|
||||
double Ab(double s);
|
||||
double Vc(double s);
|
||||
|
||||
extern int modele(int neq, double time, double *y, double *dy, void *data);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
data_t data;
|
||||
|
||||
double temp;
|
||||
double tmp2[2];
|
||||
|
||||
double **ans;
|
||||
double *ic; /* initial conditions */
|
||||
|
||||
equilibrium_t *e;
|
||||
|
||||
char thermo_file[FILENAME_MAX] = "../cpropep/data/thermo.dat";
|
||||
char propellant_file[FILENAME_MAX] = "../cpropep/data/propellant.dat";
|
||||
|
||||
// global_verbose = 1;
|
||||
errorfile = stderr;
|
||||
outputfile = stdout;
|
||||
|
||||
if (load_thermo (thermo_file) < 0)
|
||||
{
|
||||
printf("Unable to open %s\n", thermo_file);
|
||||
return -1;
|
||||
}
|
||||
if (load_propellant (propellant_file) < 0)
|
||||
{
|
||||
printf("Unable to open: %s\n", propellant_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
e = (equilibrium_t *) malloc (sizeof (equilibrium_t) * 3);
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
initialize_equilibrium(e + i);
|
||||
}
|
||||
add_in_propellant(e, 108, GRAM_TO_MOL(78, 766)); /* NH4ClO4 */
|
||||
add_in_propellant(e, 788, GRAM_TO_MOL(11, 788)); /* HTPB */
|
||||
add_in_propellant(e, 34, GRAM_TO_MOL(7, 34)); /* ALU */
|
||||
|
||||
compute_density(&(e->propellant));
|
||||
|
||||
|
||||
ic = (double *) malloc (sizeof(double) * NEQ);
|
||||
|
||||
if ( (ans = (double **) malloc (sizeof(double *) * (NPOINT+1))) == NULL)
|
||||
{
|
||||
printf("Problem allocating memory\n");
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < (NPOINT+1); i++)
|
||||
{
|
||||
ans[i] = (double *) malloc (sizeof(double) * NEQ);
|
||||
}
|
||||
|
||||
ic[0] = 0;
|
||||
ic[1] = 5; /* atm */
|
||||
|
||||
// data.a = 0.001804;
|
||||
data.a = 0.0016917;
|
||||
data.n = 0.35;
|
||||
data.ta = M_PI * pow(0.00595/2, 2);
|
||||
data.ea = M_PI * pow(0.00795/2, 2);
|
||||
data.Ab = Ab;
|
||||
data.Vc = Vc;
|
||||
data.e = e;
|
||||
|
||||
// modele(2, 0, ic, tmp2, (void*)&data);
|
||||
|
||||
// printf("%f %f\n", tmp2[0], tmp2[1]);
|
||||
|
||||
/* find the solution */
|
||||
printf("%d\n", Round(1.0/0.001));
|
||||
|
||||
|
||||
NUM_rk4 (modele, NEQ, STEP, NPOINT*STEP, ic, ans, (void*)&data);
|
||||
|
||||
|
||||
for (i = 0; i < NPOINT; i++)
|
||||
{
|
||||
printf("%.2e %.2e %.2e\n", i*STEP, ans[i][0], ans[i][1]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
||||
free(ic);
|
||||
for (i = 0; i < (NPOINT+1); i++)
|
||||
free(ans[i]);
|
||||
free(ans);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
double Ab(double s)
|
||||
{
|
||||
double A;
|
||||
|
||||
if ((s >= 0) && (s < 0.01265))
|
||||
A = 2 * M_PI * 0.09525 * (s + 0.00635);
|
||||
else
|
||||
A = 0;
|
||||
|
||||
return A;
|
||||
}
|
||||
|
||||
double Vc(double s)
|
||||
{
|
||||
double V;
|
||||
|
||||
if (s < 0)
|
||||
s = 0;
|
||||
else if (s > 0.01265)
|
||||
s = 0.01265;
|
||||
|
||||
V = M_PI * 0.09525 * pow(s + 0.00635, 2);
|
||||
|
||||
return V;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
LIB = -lgpcp -lm
|
||||
PROG = profiler
|
||||
OBJS = profiler.o parser.o
|
||||
@@ -0,0 +1,368 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "gpcp.h"
|
||||
#include "profiler.h"
|
||||
|
||||
double mass_convert; /* factor to convert user units to SI (kg) */
|
||||
double length_convert; /* factor to convert user units to SI (m) */
|
||||
|
||||
int read_value(Data *d, rocket_t *r)
|
||||
{
|
||||
int i, j, k, l, m, n;
|
||||
|
||||
body_part_t *part;
|
||||
fin_t *fin;
|
||||
|
||||
char *str;
|
||||
int int_val;
|
||||
float float_val;
|
||||
char *type = NULL;
|
||||
|
||||
if (GPCP_EnterLevel("global", 0))
|
||||
{
|
||||
printf("No global value defined.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue("length_units", &str) != 0)
|
||||
{
|
||||
printf("No length units have been specified.\n"
|
||||
"Values are assumed to be in meter.\n");
|
||||
length_convert = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*printf("Length units used are: %s\n", str);*/
|
||||
if ((strcmp(str, "m") == 0) || (strcmp(str, "meter") == 0))
|
||||
{
|
||||
length_convert = 1.0;
|
||||
}
|
||||
else if (strcmp(str, "in") == 0)
|
||||
{
|
||||
length_convert = 0.0254;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown length unit.\n"
|
||||
"Values are assumed to be in meter.\n");
|
||||
length_convert = 1.0;
|
||||
}
|
||||
free(str);
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("mass_units", &str) != 0)
|
||||
{
|
||||
printf("No mass units have been specified.\n"
|
||||
"Values are assumes to be in kilograms.\n");
|
||||
mass_convert = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*printf("Mass units used are : %s\n", str);*/
|
||||
if (strcmp(str, "kg") == 0)
|
||||
{
|
||||
mass_convert = 1.0;
|
||||
}
|
||||
else if (strcmp(str, "lb") == 0)
|
||||
{
|
||||
mass_convert = 0.45359237;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown mass unit.\n"
|
||||
"Values are assumed to be in kilograms.\n");
|
||||
mass_convert = 1.0;
|
||||
}
|
||||
free (str);
|
||||
}
|
||||
}
|
||||
|
||||
GPCP_ExitLevel();
|
||||
|
||||
l = GPCP_NumParent("rocket");
|
||||
|
||||
for (i = 0; i < l; i++)
|
||||
{
|
||||
if (GPCP_EnterLevel("rocket", i))
|
||||
{
|
||||
printf("Strange, should not be here....\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue("name", &(r->name)) != 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
/*printf("Rocket name : %s\n", r->name);*/
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("cg", &float_val) != 0)
|
||||
{
|
||||
printf("Rocket cg position not specified.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
r->Xcg = float_val;
|
||||
/*printf("cg position : % f\n", r->Xcg);*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
m = GPCP_NumParent("body");
|
||||
for (j = 0; j < m; j++)
|
||||
{
|
||||
if (GPCP_EnterLevel("body", j))
|
||||
{
|
||||
printf("Strange, should not be here....\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
r->body.n_body_parts++;
|
||||
r->body.body_parts = (body_part_t *)
|
||||
realloc(r->body.body_parts,
|
||||
r->body.n_body_parts*sizeof(body_part_t));
|
||||
|
||||
part = r->body.body_parts + j;
|
||||
|
||||
if (GPCP_GetValue("type", &type) != 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
/*printf("Type : %s\n", type);*/
|
||||
|
||||
if (strcmp(type, "ogive_nose") == 0)
|
||||
{
|
||||
if (r->body.n_body_parts != 1)
|
||||
{
|
||||
printf("Only the first part could be a nose.\n");
|
||||
return -1;
|
||||
}
|
||||
part->type = OGIVE_NOSE;
|
||||
}
|
||||
else if (strcmp(type, "elliptic_nose") == 0)
|
||||
{
|
||||
if (r->body.n_body_parts != 1)
|
||||
{
|
||||
printf("Only the first part could be a nose.\n");
|
||||
return -1;
|
||||
}
|
||||
part->type = ELLIPTIC_NOSE;
|
||||
}
|
||||
else if (strcmp(type, "conic_nose") == 0)
|
||||
{
|
||||
if (r->body.n_body_parts != 1)
|
||||
{
|
||||
printf("Only the first part could be a nose.\n");
|
||||
return -1;
|
||||
}
|
||||
part->type = CONIC_NOSE;
|
||||
}
|
||||
else if (strcmp(type, "parabolic_nose") == 0)
|
||||
{
|
||||
if (r->body.n_body_parts != 1)
|
||||
{
|
||||
printf("Only the first part could be a nose.\n");
|
||||
return -1;
|
||||
}
|
||||
part->type = PARABOLIC_NOSE;
|
||||
}
|
||||
else if (strcmp(type, "tube") == 0)
|
||||
{
|
||||
|
||||
/*printf("Here is the tube...\n");*/
|
||||
|
||||
if (r->body.n_body_parts == 1)
|
||||
{
|
||||
printf("The first part should be a nose.\n");
|
||||
return -1;
|
||||
}
|
||||
part->type = TUBE;
|
||||
part->d = r->body.body_parts[j - 1].d;
|
||||
|
||||
}
|
||||
else if (strcmp(type, "transition") == 0)
|
||||
{
|
||||
if (r->body.n_body_parts == 1)
|
||||
{
|
||||
printf("The first part should be a nose.\n");
|
||||
return -1;
|
||||
}
|
||||
part->type = TRANSITION;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown type of body part.\n");
|
||||
}
|
||||
|
||||
free(type);
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("length", &float_val) != 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
part->l = float_val * length_convert;
|
||||
/*printf("Length is : %f (m)\n", float_val * length_convert);*/
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("diameter", &float_val) != 0)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
part->d = float_val * length_convert;
|
||||
/*printf("Diameter is : %f (m)\n", float_val * length_convert);*/
|
||||
if (part->d > r->Lr)
|
||||
r->Lr = part->d;
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("density", &float_val) != 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
/*printf("Density is : %f\n", float_val);*/
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("mass", &float_val) != 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
part->m = float_val;
|
||||
/*printf("Density is : %f\n", float_val);*/
|
||||
}
|
||||
|
||||
}
|
||||
GPCP_ExitLevel();
|
||||
}
|
||||
|
||||
m = GPCP_NumParent("fin");
|
||||
for (j = 0; j < m; j++)
|
||||
{
|
||||
if (GPCP_EnterLevel("fin", j))
|
||||
{
|
||||
printf("Strange, should not be here....\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
r->n_fin_set += 1;
|
||||
r->fin_set = (fin_t *) realloc(r->fin_set,
|
||||
r->n_fin_set*sizeof(fin_t));
|
||||
|
||||
fin = r->fin_set + j;
|
||||
|
||||
if (GPCP_GetValue("num", &int_val) != 0)
|
||||
{
|
||||
printf("Number of fins not specified.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fin->N = int_val;
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("pos", &float_val) != 0)
|
||||
{
|
||||
printf("Position of fins not specified.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fin->lt = float_val * length_convert;
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("root_chord", &float_val) != 0)
|
||||
{
|
||||
printf("Root chord not specified.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fin->cr = float_val * length_convert;
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("tip_chord", &float_val) != 0)
|
||||
{
|
||||
printf("Tip chord not specified.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fin->ct = float_val * length_convert;
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("root_tip_d", &float_val) != 0)
|
||||
{
|
||||
printf("Position of tip chord relative to root chord"
|
||||
" not specified.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fin->xt = float_val * length_convert;
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("semispan", &float_val) != 0)
|
||||
{
|
||||
printf("Semispan not specified.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fin->s = float_val * length_convert;
|
||||
}
|
||||
|
||||
if (GPCP_GetValue("body_radius", &float_val) != 0)
|
||||
{
|
||||
printf("Body radius not specified.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fin->rt = float_val * length_convert;
|
||||
}
|
||||
|
||||
}
|
||||
GPCP_ExitLevel();
|
||||
}
|
||||
|
||||
if (GPCP_EnterLevel("motor", 0))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
GPCP_ExitLevel();
|
||||
|
||||
if (GPCP_EnterLevel("tank", 0))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
GPCP_ExitLevel();
|
||||
|
||||
if (GPCP_EnterLevel("other", 0))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
GPCP_ExitLevel();
|
||||
|
||||
}
|
||||
GPCP_ExitLevel();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,532 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "gpcp.h"
|
||||
#include "libcompat/include/getopt.h"
|
||||
|
||||
#include "profiler.h"
|
||||
|
||||
#define M_PI2 9.869604401
|
||||
|
||||
Options rocket_options[] = {
|
||||
{"global", PARENT, NULL},
|
||||
{"length_units", STRING, "global"},
|
||||
{"mass_units", STRING, "global"},
|
||||
|
||||
{"rocket", PARENT, NULL},
|
||||
{"name", STRING, "rocket"},
|
||||
{"cg", FLOAT, "rocket"},
|
||||
|
||||
{"body", PARENT, "rocket"},
|
||||
{"type", STRING, "body"},
|
||||
{"length", FLOAT, "body"},
|
||||
{"diameter", FLOAT, "body"},
|
||||
{"density", FLOAT, "body"},
|
||||
{"mass", FLOAT, "body"},
|
||||
|
||||
{"fin", PARENT, "rocket"},
|
||||
{"num", INTEGER, "fin"},
|
||||
{"pos", FLOAT, "fin"},
|
||||
{"root_chord", FLOAT, "fin"},
|
||||
{"tip_chord", FLOAT, "fin"},
|
||||
{"root_tip_d", FLOAT, "fin"},
|
||||
{"semispan", FLOAT, "fin"},
|
||||
{"body_radius", FLOAT, "fin"},
|
||||
{"mass", FLOAT, "fin"},
|
||||
|
||||
{"motor", PARENT, "rocket"},
|
||||
{"zpos", FLOAT, "motor"},
|
||||
{"rpos", FLOAT, "motor"},
|
||||
{"diameter", FLOAT, "motor"},
|
||||
{"length", FLOAT, "motor"},
|
||||
{"empty_mass", FLOAT, "motor"},
|
||||
{"full_mass", FLOAT, "motor"},
|
||||
|
||||
{"tank", PARENT, "rocket"},
|
||||
{"zpos", FLOAT, "tank"},
|
||||
{"rpos", FLOAT, "tank"},
|
||||
{"diameter", FLOAT, "tank"},
|
||||
{"length", FLOAT, "tank"},
|
||||
{"empty_mass", FLOAT, "tank"},
|
||||
{"full_mass", FLOAT, "tank"},
|
||||
|
||||
{"other", PARENT, "rocket"},
|
||||
{"shape", STRING, "other"},
|
||||
{"zpos", FLOAT, "other"},
|
||||
{"rpos", FLOAT, "other"},
|
||||
{"Ix", FLOAT, "other"},
|
||||
{"Iy", FLOAT, "other"},
|
||||
{"mass", FLOAT, "other"},
|
||||
{NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int read_value(Data *d, rocket_t *r);
|
||||
|
||||
int profile_rocket(rocket_t *r);
|
||||
int profile_fins(rocket_t *r);
|
||||
int profile_body(rocket_t *r);
|
||||
|
||||
void usage(void);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
Data *data;
|
||||
rocket_t rocket;
|
||||
char filename[FILENAME_MAX] = "";
|
||||
|
||||
rocket.body.n_body_parts = 0;
|
||||
rocket.body.body_parts = NULL;
|
||||
|
||||
rocket.n_fin_set = 0;
|
||||
rocket.fin_set = NULL;
|
||||
|
||||
rocket.Lr = 0;
|
||||
rocket.Ar = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = getopt(argc, argv, "f:");
|
||||
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 'f':
|
||||
if (strlen(optarg) > FILENAME_MAX)
|
||||
{
|
||||
printf("Filename too long!\n");
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
strncpy (filename, optarg, FILENAME_MAX);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(filename, "") == 0)
|
||||
{
|
||||
printf("A rocket description file must be provide.\n");
|
||||
usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
GPCP_RegisterOptions(rocket_options);
|
||||
|
||||
if (GPCP_ReadFile(filename, &data))
|
||||
{
|
||||
printf("Error parsing configuration file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
read_value(data, &rocket);
|
||||
|
||||
/* GPCP_PrintData(data); */
|
||||
|
||||
GPCP_FreeData(&data);
|
||||
|
||||
profile_rocket(&rocket);
|
||||
|
||||
free (rocket.fin_set);
|
||||
free (rocket.body.body_parts);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
printf("Usage:");
|
||||
printf("\n\tprofiler -f infile");
|
||||
|
||||
printf("\n\nArguments:\n");
|
||||
printf("-f file \t Perform an analysis of the specified rocket.\n");
|
||||
printf("-h \t Print usage.\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int profile_rocket(rocket_t *r)
|
||||
{
|
||||
int i, n;
|
||||
fin_t *f;
|
||||
|
||||
r->m = 0;
|
||||
/* reference area of the rocket */
|
||||
r->Ar = M_PI * pow(r->Lr, 2)/4;
|
||||
|
||||
r->n_mach = 20;
|
||||
r->mach = (double *) malloc(sizeof(double) * r->n_mach);
|
||||
|
||||
/* fill the table of the mach number */
|
||||
for (i = 0; i < r->n_mach; i++)
|
||||
{
|
||||
r->mach[i] = (1.0/r->n_mach) * i;
|
||||
}
|
||||
|
||||
profile_fins(r);
|
||||
profile_body(r);
|
||||
|
||||
/* tables in function of the mach number */
|
||||
r->X = (double *) malloc(sizeof(double) * r->n_mach);
|
||||
r->C_N_alpha = (double *) malloc(sizeof(double) * r->n_mach);
|
||||
r->C_mq = (double *) malloc(sizeof(double) * r->n_mach);
|
||||
r->C_m_alpha = (double *) malloc(sizeof(double) * r->n_mach);
|
||||
|
||||
for (i = 0; i < r->n_mach; i++)
|
||||
{
|
||||
|
||||
r->C_N_alpha[i] = r->body.C_N_alpha_b;
|
||||
|
||||
/* formula 3-106 */
|
||||
for (n = 0; n < r->n_fin_set; n++)
|
||||
{
|
||||
f = r->fin_set + n;
|
||||
|
||||
r->C_N_alpha[i] += f->C_N_alpha_tb_m * f->C_N_alpha_1[i];
|
||||
r->C_N_alpha[i] += f->C_N_alpha_bt_m * f->C_N_alpha_1[i];
|
||||
}
|
||||
|
||||
/* rocket center of pressure location */
|
||||
r->X[i] = r->body.Xb * r->body.C_N_alpha_b;
|
||||
/* formula 3-107 */
|
||||
for (n = 0; n < r->n_fin_set; n++)
|
||||
{
|
||||
f = r->fin_set + n;
|
||||
r->X[i] += f->Xt * f->C_N_alpha_tb_m * f->C_N_alpha_1[i];
|
||||
r->X[i] += f->Xbt * f->C_N_alpha_bt_m * f->C_N_alpha_1[i];
|
||||
}
|
||||
r->X[i] = r->X[i] / r->C_N_alpha[i];
|
||||
|
||||
/* formula 3-115 CHECKME, formula was badly print,
|
||||
i redevelop it myself */
|
||||
r->C_mq[i] = 0;
|
||||
for (n = 0; n < r->n_fin_set; n++)
|
||||
{
|
||||
f = r->fin_set + n;
|
||||
|
||||
r->C_mq[i] += 2 * f->C_N_alpha_tb_m * f->C_N_alpha_1[i] *
|
||||
pow((f->Xt - r->Xcg)/r->Lr, 2);
|
||||
}
|
||||
|
||||
r->C_m_alpha[i] = 0;
|
||||
for (n = 0; n < r->n_fin_set; n++)
|
||||
{
|
||||
f = r->fin_set + n;
|
||||
r->C_m_alpha[i] += f->C_N_alpha_tb_m * f->C_N_alpha_1[i] *
|
||||
(r->X[i] - r->Xcg) / r->Lr;
|
||||
}
|
||||
|
||||
/*
|
||||
printf("Aerodynamic properties of the entire rocket.\n"
|
||||
"--------------------------------------------\n");
|
||||
printf("Reference area (Ar) = % f m2\n", r->Ar);
|
||||
|
||||
printf("C_N_alpha = % f\n", r->C_N_alpha);
|
||||
printf("X = % f\n", r->X);
|
||||
printf("Cmq = % f\n", r->C_mq);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
for (i = 0; i < r->n_mach; i++)
|
||||
{
|
||||
printf("M = %.2f -> C_N_alpha = %.3f, Cmq = %.3f, Cm_alpha = %.3f,"
|
||||
" X = %.2f\n",
|
||||
r->mach[i], r->C_N_alpha[i], r->C_mq[i], r->C_m_alpha[i], r->X[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int profile_fins(rocket_t *r)
|
||||
{
|
||||
int i, n;
|
||||
float cr, ct, rt, lt, xt, s;
|
||||
|
||||
float beta;
|
||||
float lambda;
|
||||
float sac; /* midchord sweep angle cosine */
|
||||
float tau; /* (s + rt)/rt */
|
||||
float tau2; /* tau^2 */
|
||||
float tau3;
|
||||
|
||||
fin_t *f;
|
||||
|
||||
/* fin treatment */
|
||||
for (n = 0; n < r->n_fin_set; n++)
|
||||
{
|
||||
f = r->fin_set + n;
|
||||
|
||||
f->C_N_alpha_1 = (double *) malloc(sizeof(double) * r->n_mach);
|
||||
|
||||
cr = f->cr;
|
||||
ct = f->ct;
|
||||
rt = f->rt;
|
||||
lt = f->lt;
|
||||
xt = f->xt;
|
||||
s = f->s;
|
||||
|
||||
/* add fin mass to the rocket mass */
|
||||
r->m += f->N * f->m;
|
||||
|
||||
/* inertial properties */
|
||||
f->Xcg = 0;
|
||||
f->Ixx = 0;
|
||||
f->Iyy = 0;
|
||||
|
||||
/* center of pressure of the fins */
|
||||
/* formula 3-27 */
|
||||
f->Yt = rt + (s/3)*(cr + 2*ct)/(cr + ct);
|
||||
/* formula 3-30 */
|
||||
f->Xt = lt + (xt/3)*(cr + 2*ct)/(cr + ct) +
|
||||
(cr + ct - cr*ct/(cr+ct))/6;
|
||||
|
||||
/* formula 3-101 */
|
||||
f->Xbt = lt + cr/4 +
|
||||
((sqrt(s*s - rt*rt)*acosh(s/rt) - s + M_PI*rt/2)/
|
||||
(rt*acosh(s/rt)/sqrt(s*s - rt*rt) + s/rt - M_PI/2) - rt) *
|
||||
(xt + 0.25*(ct-cr))/s; /* check this part (tan(sweepback)) */
|
||||
|
||||
/* fin area */
|
||||
f->Af = cr*s - xt*s/2 + (xt + ct - cr)*s/2;
|
||||
|
||||
/* fin aspect ratio */
|
||||
f->AR = pow(s,2)/f->Af;
|
||||
|
||||
/* cosine of the midchord sweep angle */
|
||||
sac = s/sqrt(pow(xt + ct - cr/2 - ct/2, 2) + pow(s, 2));
|
||||
|
||||
for (i = 0; i < r->n_mach; i++)
|
||||
{
|
||||
/* M is the mach number */
|
||||
beta = sqrt(1 - pow(r->mach[i], 2));
|
||||
|
||||
/* formula 3-6 */
|
||||
f->C_N_alpha_1[i] = 2 * M_PI * f->AR *
|
||||
(f->Af/r->Ar) / (2 + sqrt(4 + pow(beta*f->AR/sac, 2) ));
|
||||
}
|
||||
|
||||
/* formula 3-35 */
|
||||
f->C_l_delta_m = f->N * f->Yt / r->Lr; /* *f->C_N_alpha_1 */
|
||||
|
||||
lambda = ct / cr;
|
||||
|
||||
/* formula 3-51 */
|
||||
f->C_l_p_m = -(f->N * cr * s / (6*pow(r->Lr, 2)))*
|
||||
((1+3*lambda)*pow(s, 2) + 4*(1+2*lambda)*s*rt + 6*(1+lambda)*pow(rt, 2));
|
||||
/* * f->C_N_alpha_1;*/
|
||||
|
||||
tau = (s + rt)/rt;
|
||||
tau2 = pow(tau, 2);
|
||||
tau3 = pow(tau, 3);
|
||||
|
||||
/* formula 3-96 */
|
||||
f->Ktb_alpha = 2*((1 + pow(tau, -4))*(0.5*atan(0.5*(tau-1/tau))) -
|
||||
pow(tau, -2)*((tau-1/tau) + 2*atan(1/tau)))/
|
||||
(M_PI * pow(1-1/tau, 2));
|
||||
|
||||
/*formula 3-98 */
|
||||
f->Kbt = pow((1 - 1/tau2)/(1 - 1/tau), 2) - f->Ktb_alpha;
|
||||
|
||||
/* formula 3-105 */
|
||||
/* CHECK THIS : when optimize with -O2 or -O3 in gcc, the value is nan
|
||||
but is good with -O ???? */
|
||||
f->Ktb_delta =
|
||||
(M_PI2 * pow(1+1/tau, 2)/4 +
|
||||
M_PI * pow( (tau2 + 1)/(tau2-tau), 2)*asin((tau2-1)/(tau2+1)) -
|
||||
2*M_PI*(tau+1)/(tau2 - tau) +
|
||||
pow((tau2+1)/(tau2-tau), 2)*pow(asin((tau2-1)/(tau2+1)), 2) -
|
||||
4*(tau+1)*asin((tau2-1)/(tau2+1))/(tau2-tau) +
|
||||
8*log((tau2+1)/(2*tau))/pow(tau-1,2))/M_PI2;
|
||||
|
||||
/* formula 3-122 */
|
||||
f->Krb = 1 + ((tau-lambda)/tau - (1-lambda)*log(tau)/(tau-1))/
|
||||
((tau+1)*(tau-lambda)/2 - (1-lambda)*(tau3-1)/(3*(tau-1)));
|
||||
|
||||
|
||||
f->C_N_alpha_tb_m = f->N * f->Ktb_alpha / 2; /* * f->C_N_alpha_1 */
|
||||
f->C_N_alpha_bt_m = f->N * f->Kbt / 2; /* * f->C_N_alpha_1 */
|
||||
f->C_l_delta_tb_m = f->C_l_delta_m * f->Ktb_delta;
|
||||
f->C_l_p_tb_m = f->C_l_p_m * f->Krb;
|
||||
|
||||
printf("Aerodynamic properties of the fin set number %d\n"
|
||||
"-----------------------------------------------\n", n+1);
|
||||
printf("Fin area (Af) = % f m2\n", f->Af);
|
||||
printf("Aspect ratio (AR) = % f\n", f->AR);
|
||||
printf("\n");
|
||||
|
||||
printf("Interference factors.\n");
|
||||
printf("Ktb_alpha = % f\n", f->Ktb_alpha);
|
||||
printf("Kbt = % f\n", f->Kbt);
|
||||
printf("Ktb_delta = % f\n", f->Ktb_delta);
|
||||
printf("Krb = % f\n", f->Krb);
|
||||
printf("\n");
|
||||
|
||||
printf("Fin center of pressure location.\n");
|
||||
printf("Yt = % .3f m\n", f->Yt);
|
||||
printf("Xt = % .3f m\n", f->Xt);
|
||||
printf("Xbt = % .3f m\n", f->Xbt);
|
||||
printf("\n");
|
||||
|
||||
printf("Fin stability coefficients.\n");
|
||||
for (i = 0; i < r->n_mach; i++)
|
||||
{
|
||||
printf("M = % .2f -> C_N_alpha_1 = % .4f\n",
|
||||
r->mach[i], f->C_N_alpha_1[i]);
|
||||
}
|
||||
|
||||
printf("C_l_delta_m = % f\n", f->C_l_delta_m);
|
||||
printf("C_l_p_m = % f\n", f->C_l_p_m);
|
||||
printf("\n");
|
||||
|
||||
printf("Fin stability coefficients with interference factors.\n");
|
||||
printf("C_N_alpha_tb_m = % f\n", f->C_N_alpha_tb_m);
|
||||
printf("C_N_alpha_bt_m = % f\n", f->C_N_alpha_bt_m);
|
||||
printf("C_N_delta_tb_m = % f\n", f->C_l_delta_tb_m);
|
||||
printf("C_l_p_tb_m = % f\n", f->C_l_p_tb_m);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int profile_body(rocket_t *r)
|
||||
{
|
||||
int i, n;
|
||||
|
||||
float fn;
|
||||
float dp; /* diameter of the previous part */
|
||||
|
||||
body_part_t *previous_part = NULL;
|
||||
body_part_t *part = NULL;
|
||||
|
||||
/* body parts treatment */
|
||||
for (n = 0; n < r->body.n_body_parts; n++)
|
||||
{
|
||||
part = r->body.body_parts + n;
|
||||
if (n != 0)
|
||||
previous_part = r->body.body_parts + n - 1;
|
||||
|
||||
r->m += part->m;
|
||||
|
||||
switch (part->type)
|
||||
{
|
||||
|
||||
case OGIVE_NOSE:
|
||||
fn = part->l / part->d;
|
||||
|
||||
part->A = 0;
|
||||
part->V = 0;
|
||||
part->Xof = 0;
|
||||
part->Xcg = 0.466 * part->l;
|
||||
part->Ix = 0;
|
||||
part->Iy = 0;
|
||||
|
||||
break;
|
||||
|
||||
case ELLIPTIC_NOSE:
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case CONIC_NOSE:
|
||||
part->A = M_PI * part->d *
|
||||
sqrt(pow(part->d/2, 2) + pow(part->l, 2)) / 2;
|
||||
|
||||
part->V = M_PI * pow(part->d/2, 2) * part->l / 3;
|
||||
|
||||
part->Xof = 0;
|
||||
part->Xcg = 2 * part->l / 3;
|
||||
|
||||
part->Ix = part->m * pow(part->d, 2) / 8;
|
||||
/* moment of inertia about the axis passing at the tip of the cone */
|
||||
part->Iy = part->m * (pow(part->d, 2)/16 + pow(part->l, 2)/2);
|
||||
break;
|
||||
|
||||
case PARABOLIC_NOSE:
|
||||
|
||||
break;
|
||||
|
||||
case TUBE:
|
||||
part->A = M_PI * part->d * part->l;
|
||||
part->V = M_PI * pow(part->d, 2) * part->l / 4;
|
||||
|
||||
if (previous_part == NULL)
|
||||
return -1;
|
||||
part->Xof = previous_part->Xof + previous_part->l;
|
||||
part->Xcg = part->Xof + part->l / 2;
|
||||
|
||||
part->Ix = part->m * pow(part->d, 2) / 4;
|
||||
part->Iy = part->m * (pow(part->d, 2)/8 + pow(part->l, 2)/12);
|
||||
break;
|
||||
|
||||
case TRANSITION:
|
||||
dp = r->body.body_parts[n - 1].d;
|
||||
|
||||
part->A = M_PI*(part->d*sqrt(pow(part->d/2, 2) +
|
||||
pow(part->l/(1 - part->d/dp), 2))/2 -
|
||||
dp*sqrt(pow(dp/2, 2) +
|
||||
pow(part->l*part->d/(dp*(1-part->d/dp)), 2))/2);
|
||||
|
||||
part->V = M_PI * part->l *
|
||||
(pow(part->d/2, 2) - pow(dp/2, 2)*dp/part->d)/(3*(1 - dp/part->d));
|
||||
|
||||
/*part->Ix = ;*/
|
||||
|
||||
break;
|
||||
default:
|
||||
printf("Unknown type : %d\n", part->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
r->body.V = 0;
|
||||
r->body.lo = 0;
|
||||
r->body.Ab = 0;
|
||||
for (i = 0; i < r->body.n_body_parts; i++)
|
||||
{
|
||||
part = r->body.body_parts + i;
|
||||
r->body.V += part->V;
|
||||
r->body.lo += part->l;
|
||||
|
||||
/* compute it only for the last part */
|
||||
r->body.Ab = M_PI * pow(part->d, 2) / 4;
|
||||
|
||||
printf("Part geometric characteristics.\n");
|
||||
printf("Volume = %e m3\n", part->V);
|
||||
printf("Area = %e m2\n", part->A);
|
||||
printf("Mass = %e kg\n", part->m);
|
||||
printf("Ixx = %e kg-m2\n", part->Ix);
|
||||
printf("Iyy = %e kg-m2\n", part->Iy);
|
||||
printf("Xof = %e m\n", part->Xof);
|
||||
printf("Xcg = %e m\n", part->Xcg);
|
||||
}
|
||||
|
||||
/* formula 3-66 */
|
||||
r->body.C_N_alpha_b = 2 * r->body.Ab / r->Ar;
|
||||
r->body.Xb = r->body.lo - r->body.V/r->body.Ab;
|
||||
|
||||
printf("\n");
|
||||
printf("Aerodynamic properties of the body.\n"
|
||||
"-----------------------------------\n");
|
||||
printf("Ab = % f\n", r->body.Ab);
|
||||
printf("lo = % f\n", r->body.lo);
|
||||
printf("C_N_alpha_b = % f\n", r->body.C_N_alpha_b);
|
||||
printf("Xb = % f\n", r->body.Xb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
#ifndef __profiler_h__
|
||||
#define __profiler_h__
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
typedef struct _fin_t
|
||||
{
|
||||
int N; /* number of fins in this set (usually 3 or 4) */
|
||||
|
||||
/* fin description */
|
||||
double s; /* semispan */
|
||||
double cr; /* root chord */
|
||||
double ct; /* tip chord */
|
||||
double rt; /* rocket radius where the fin is located */
|
||||
double lt; /* position of the leading edge from nose tip */
|
||||
double xt; /* position of the leading edge at tip chord relative to
|
||||
leading edge at root chord, in the x direction */
|
||||
|
||||
/* calculation results */
|
||||
double Yt; /* Center of pressure Y position (radially) */
|
||||
double Xt; /* Center of pressure X position (from the nose tip) */
|
||||
double Xbt; /* Center of pressure X position with body interferance */
|
||||
|
||||
double AR; /* aspect ratio */
|
||||
double Af; /* aera of one fin */
|
||||
|
||||
/* the C_N_alpha_1 value is a function of the mach number.
|
||||
the values will evaluate for some discrete value of the mach
|
||||
number and stored in an array for table lookup.
|
||||
*/
|
||||
|
||||
double *C_N_alpha_1; /* fin normal force coefficient derivative for each
|
||||
mach number */
|
||||
|
||||
|
||||
/* these value should be multiply by C_N_alpha_1 to get the coefficient */
|
||||
double C_l_delta_m; /* fin roll forcing moment coefficient derivative
|
||||
multiplier*/
|
||||
double C_l_p_m; /* tail roll damping moment derivative multiplier */
|
||||
|
||||
double Ktb_alpha; /* interference factor of tail in presence of the body
|
||||
for C_N_alpha */
|
||||
double Ktb_delta; /* interference factor of tail in presence of the body
|
||||
for C_l_delta */
|
||||
double Kbt;
|
||||
double Krb; /* roll damping interference factor */
|
||||
|
||||
/* these should also be multiply by C_N_alpha_1 to get the coefficients */
|
||||
double C_N_alpha_tb_m;
|
||||
double C_N_alpha_bt_m;
|
||||
double C_l_delta_tb_m;
|
||||
double C_l_p_tb_m;
|
||||
|
||||
/* mass and inertial properties */
|
||||
double m;
|
||||
double Xcg;
|
||||
double Ixx;
|
||||
double Iyy;
|
||||
|
||||
} fin_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OGIVE_NOSE,
|
||||
ELLIPTIC_NOSE,
|
||||
CONIC_NOSE,
|
||||
PARABOLIC_NOSE,
|
||||
TUBE,
|
||||
TRANSITION
|
||||
} body_enum_t;
|
||||
|
||||
typedef struct _body_part_t
|
||||
{
|
||||
/* part description */
|
||||
body_enum_t type; /* type of body part */
|
||||
double d; /* diameter */
|
||||
double l; /* length */
|
||||
double m; /* mass of the part */
|
||||
|
||||
/* calculation results */
|
||||
double A; /* area of the part */
|
||||
double V; /* volume of the part */
|
||||
|
||||
double Xof; /* distance of the beginning of the part from nose tip */
|
||||
double Xcg;
|
||||
/* moments of inertia about axis passing trough the cg of the part */
|
||||
double Ix;
|
||||
double Iy; /* Iy = Iz for body parts (symmetry of rotation) */
|
||||
|
||||
|
||||
} body_part_t;
|
||||
|
||||
typedef struct _body_t
|
||||
{
|
||||
int n_body_parts;
|
||||
body_part_t *body_parts;
|
||||
|
||||
float lo; /* total length of the rocket */
|
||||
float V; /* total volume of the body */
|
||||
float Ab; /* base area */
|
||||
float C_N_alpha_b; /* normal force coefficient for body */
|
||||
float Xb;
|
||||
|
||||
} body_t;
|
||||
|
||||
|
||||
typedef struct _rocket_t
|
||||
{
|
||||
char *name;
|
||||
|
||||
int n_mach; /* number of points in the values table */
|
||||
double *mach;
|
||||
|
||||
float Lr; /* maximum diameter of the rocket */
|
||||
float Ar; /* reference area */
|
||||
float m; /* total mass of the rocket */
|
||||
float Xcg; /* position of the center of gravity */
|
||||
|
||||
body_t body;
|
||||
int n_fin_set;
|
||||
fin_t *fin_set;
|
||||
|
||||
|
||||
/* calculated values (table as a function of the mach number) */
|
||||
|
||||
double *X; /* center of pressure location for the whole rocket */
|
||||
double *C_N_alpha; /* total normal force coefficient derivative */
|
||||
double *C_mq; /* pitch damping moment coefficient derivative */
|
||||
double *C_m_alpha; /* pitch forcing moment coefficient derivative */
|
||||
|
||||
/* ???? should they be here */
|
||||
double C_l_p;
|
||||
double C_l_delta;
|
||||
|
||||
} rocket_t;
|
||||
|
||||
#endif __profiler_h__
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,38 @@
|
||||
CC = bcc32
|
||||
CPP32 = cpp32
|
||||
LIBRARIAN = tlib
|
||||
LINKER = ilink32
|
||||
RC = brc32
|
||||
|
||||
COPT = -3 -O2 -w-8012 -w-8004 -w-8057 -IC:\borland\bcc55\include
|
||||
LDOPT = -LC:\borland\bcc55\lib
|
||||
|
||||
LIB = compat.lib thermo.lib
|
||||
|
||||
LIBDIR = -L..\lib\
|
||||
|
||||
IDIR = -I..\lib\
|
||||
|
||||
DEF = -DBORLAND
|
||||
|
||||
PROG = prop.exe
|
||||
|
||||
OBJS = prop.obj getopt.obj
|
||||
|
||||
.SUFFIXES: .c
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(DEF) $(COPT) $(IDIR) -c $*.c -o $*.obj
|
||||
|
||||
$(PROG): $(OBJS)
|
||||
$(CC) $(LDOPT) $(LIBDIR) $(LIB) $(OBJS)
|
||||
|
||||
clean:
|
||||
del *.obj
|
||||
del *.bak
|
||||
del *.tds
|
||||
|
||||
deep-clean: clean
|
||||
del $(PROG)
|
||||
@@ -0,0 +1,3 @@
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
LIB = -lthermo -lm
|
||||
PROG = prop
|
||||
OBJS = prop.o
|
||||
@@ -0,0 +1,334 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libthermo/include/thermo.h"
|
||||
#include "libthermo/include/load.h"
|
||||
|
||||
|
||||
int global_verbose = 0;
|
||||
|
||||
#define MAX_MOL 100
|
||||
|
||||
typedef enum _unit_
|
||||
{
|
||||
DIMENSIONLESS,
|
||||
SPECIFIC,
|
||||
MOLAR
|
||||
} units_t;
|
||||
|
||||
|
||||
typedef struct _prop_
|
||||
{
|
||||
char symb[3];
|
||||
char unit_1[12];
|
||||
char unit_2[12];
|
||||
char title[24];
|
||||
double (*f)(int n, double T);
|
||||
} prop_t;
|
||||
|
||||
typedef enum _value_
|
||||
{
|
||||
CP = 0,
|
||||
H = 1,
|
||||
U = 2,
|
||||
S = 3
|
||||
} value_t;
|
||||
|
||||
double SpecificHeat(int n, double T);
|
||||
double Enthalpy(int n, double T);
|
||||
double InternalEnergy(int n, double T);
|
||||
double Entropy(int n, double T);
|
||||
|
||||
prop_t properties[] = {
|
||||
{"cp", "Cp/R", "kJ/%s-K", "Specific Heat (Cp)", SpecificHeat},
|
||||
{"h", "H/RT", "kJ/%s", "Enthalpy", Enthalpy},
|
||||
{"u", "U/RT", "kJ/%s", "Internal Energy", InternalEnergy},
|
||||
{"s", "S/R", "kJ/%s-K", "Entropy", Entropy},
|
||||
{"\0", "\0", "\0", "\0", NULL}
|
||||
};
|
||||
|
||||
double SpecificHeat(int n, double T)
|
||||
{
|
||||
return specific_heat_0(n, T);
|
||||
}
|
||||
|
||||
double Enthalpy(int n, double T)
|
||||
{
|
||||
return enthalpy_0(n, T) -
|
||||
((thermo_list + n)->heat - (thermo_list + n)->dho)/(R*T);
|
||||
}
|
||||
double InternalEnergy(int n, double T)
|
||||
{
|
||||
return (enthalpy_0(n, T) - ((thermo_list + n)->heat -
|
||||
(thermo_list + n)->dho)/(R*T) - 1);
|
||||
}
|
||||
double Entropy(int n, double T)
|
||||
{
|
||||
return entropy_0(n, T);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
FILE *fdres;
|
||||
FILE *fdplot;
|
||||
|
||||
double T;
|
||||
int i, c, n;
|
||||
|
||||
int num_mol;
|
||||
int mol[MAX_MOL];
|
||||
|
||||
char thermo_file[FILENAME_MAX] = "../data/thermo.dat";
|
||||
char propellant_file[FILENAME_MAX] = "../data/propellant.dat";
|
||||
|
||||
value_t val;
|
||||
units_t units;
|
||||
|
||||
double Ti, Tf, step;
|
||||
|
||||
char temp[128];
|
||||
|
||||
char *ptr;
|
||||
char *token;
|
||||
char *running;
|
||||
|
||||
bool _molec = false;
|
||||
bool _value = false;
|
||||
bool _units = false;
|
||||
bool _range = false;
|
||||
|
||||
|
||||
if (load_thermo (thermo_file) < 0)
|
||||
{
|
||||
printf("Error loading thermo data file: %s\n", thermo_file);
|
||||
return -1;
|
||||
}
|
||||
if (load_propellant (propellant_file) < 0)
|
||||
{
|
||||
printf("Error loading propellant file: %s\n", propellant_file);
|
||||
return -1;
|
||||
}
|
||||
if ((fdres = fopen("result.m", "w")) == NULL)
|
||||
{
|
||||
printf("Error opening file.\n");
|
||||
return -1;
|
||||
}
|
||||
if ((fdplot = fopen("plotres.m", "w")) == NULL)
|
||||
{
|
||||
printf("Error opening file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
num_mol = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
c = getopt(argc, argv, "m:p:u:T:");
|
||||
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
/* the output file */
|
||||
case 'm':
|
||||
/* duplicate the string */
|
||||
if ((running = strdup(optarg)) == NULL)
|
||||
{
|
||||
printf("Not enough memory.\n");
|
||||
return -1;
|
||||
}
|
||||
ptr = running;
|
||||
token = strsep(&running, "-");
|
||||
|
||||
/* get each molecule */
|
||||
while (token != NULL)
|
||||
{
|
||||
mol[num_mol] = atoi(token);
|
||||
num_mol++;
|
||||
token = strsep(&running, "-");
|
||||
}
|
||||
free(ptr);
|
||||
|
||||
_molec = true;
|
||||
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
if (strcmp(optarg, "cp") == 0)
|
||||
val = CP;
|
||||
else if (strcmp(optarg, "h") == 0)
|
||||
val = H;
|
||||
else if (strcmp(optarg, "u") == 0)
|
||||
val = U;
|
||||
else if (strcmp(optarg, "s") == 0)
|
||||
val = S;
|
||||
else
|
||||
{
|
||||
printf("Unknown properties: %s\n", optarg);
|
||||
break;
|
||||
}
|
||||
|
||||
_value = true;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
if (strcmp(optarg, "dimensionless") == 0)
|
||||
units = DIMENSIONLESS;
|
||||
else if (strcmp(optarg, "specific") == 0)
|
||||
units = SPECIFIC;
|
||||
else if (strcmp(optarg, "molar") == 0)
|
||||
units = MOLAR;
|
||||
else
|
||||
{
|
||||
printf("Unknown units: %s\n", optarg);
|
||||
break;
|
||||
}
|
||||
_units = true;
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
/* duplicate the string */
|
||||
if ((running = strdup(optarg)) == NULL)
|
||||
{
|
||||
printf("Not enough memory.\n");
|
||||
return -1;
|
||||
}
|
||||
ptr = running;
|
||||
if ((token = strsep(&running, ":")) == NULL)
|
||||
{
|
||||
printf("Not enought arguments to temperature.\n");
|
||||
break;
|
||||
}
|
||||
Ti = atof(token);
|
||||
if ((token = strsep(&running, ":")) == NULL)
|
||||
{
|
||||
printf("Not enought arguments to temperature.\n");
|
||||
break;
|
||||
}
|
||||
step = atof(token);
|
||||
if ((token = strsep(&running, ":")) == NULL)
|
||||
{
|
||||
printf("Not enought arguments to temperature.\n");
|
||||
break;
|
||||
}
|
||||
Tf = atof(token);
|
||||
|
||||
free(ptr);
|
||||
|
||||
_range = true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for (i = 0; i < num_mol; i++)
|
||||
{
|
||||
printf("%d\n", mol[i]);
|
||||
}
|
||||
printf("%d\n", val);
|
||||
printf("%d\n", units);
|
||||
printf("%f - %f - %f\n", Ti, step, Tf);
|
||||
return 0;
|
||||
*/
|
||||
|
||||
if (!(_molec == _value == _units == _range == true))
|
||||
{
|
||||
printf("Missing arguments. Aborted.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(fdplot, "result;\n");
|
||||
fprintf(fdplot, "hold on;\n");
|
||||
fprintf(fdplot, "gset grid\n");
|
||||
fprintf(fdplot, "gset title \"%s as a function of Temperature in the standard state\"\n",
|
||||
properties[val].title);
|
||||
fprintf(fdplot, "gset xlabel \"Temperature (K)\"\n");
|
||||
|
||||
if (units == DIMENSIONLESS)
|
||||
{
|
||||
fprintf(fdplot, "gset ylabel \"%s\"\n", properties[val].unit_1);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(temp, "gset ylabel \"%s\"\n", properties[val].unit_2);
|
||||
if (units == SPECIFIC)
|
||||
{
|
||||
fprintf(fdplot, temp, "kg");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(fdplot, temp, "mol");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < num_mol; i++)
|
||||
{
|
||||
n = mol[i];
|
||||
|
||||
fprintf(fdres, "M%d = [\n", n);
|
||||
|
||||
fprintf(fdplot, "plot(M%d(:,1),M%d(:,2), ';%s;')\n", n, n,
|
||||
(thermo_list + n)->name);
|
||||
|
||||
switch (units)
|
||||
{
|
||||
case DIMENSIONLESS:
|
||||
for (T = Ti; T < Tf; T += step)
|
||||
{
|
||||
fprintf(fdres, "%.1f, %.3f,\n", T, properties[val].f(n, T));
|
||||
}
|
||||
break;
|
||||
|
||||
case SPECIFIC:
|
||||
if ((val == CP) || (val == S))
|
||||
{
|
||||
for (T = Ti; T < Tf; T += step)
|
||||
{
|
||||
fprintf(fdres, "%.1f, %.3f,\n", T,
|
||||
properties[val].f(n, T)*R/(thermo_list + n)->weight);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (T = Ti; T < Tf; T += step)
|
||||
{
|
||||
fprintf(fdres, "%.1f, %.3f,\n", T,
|
||||
properties[val].f(n, T)*R*T/(thermo_list + n)->weight);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MOLAR:
|
||||
if ((val == CP) || (val == S))
|
||||
{
|
||||
for (T = Ti; T < Tf; T += step)
|
||||
{
|
||||
fprintf(fdres, "%.1f, %.3f,\n", T, properties[val].f(n, T)*R);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (T = Ti; T < Tf; T += step)
|
||||
{
|
||||
fprintf(fdres, "%.1f, %.3f,\n", T, properties[val].f(n, T)*R*T);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
fprintf(fdres, "];\n");
|
||||
}
|
||||
|
||||
|
||||
fclose(fdres);
|
||||
fclose(fdplot);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,613 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
/*
|
||||
#ifdef GCC
|
||||
#include <unistd.h>
|
||||
#else
|
||||
*/
|
||||
#include "libcompat/include/getopt.h"
|
||||
/*
|
||||
#endif
|
||||
*/
|
||||
#include "libthermo/include/thermo.h"
|
||||
#include "libthermo/include/load.h"
|
||||
|
||||
#define MAX_LINE 500
|
||||
#define ARG_LENGTH 32
|
||||
|
||||
#define PROMPT "PROP>"
|
||||
#define VERSION "1.0"
|
||||
|
||||
/* Dimensionless Enthalpy */
|
||||
#define ENTHALPY(n, T) (enthalpy_0(n, T) - ((thermo_list + n)->heat -\
|
||||
(thermo_list + n)->dho)/(R*T))
|
||||
|
||||
/* Dimensionless Entropy */
|
||||
#define ENTROPY(n, T) entropy_0(n, T)
|
||||
|
||||
/* Dimensionless Internal Energy */
|
||||
#define INTERNAL_ENERGY(n, T) (enthalpy_0(n, T) - ((thermo_list + n)->heat -\
|
||||
(thermo_list + n)->dho)/(R*T) - 1)
|
||||
|
||||
/* Dimensionless Specific Heat */
|
||||
#define SPECIFIC_HEAT(n, T) specific_heat_0(n, T)
|
||||
|
||||
/* Dimensionless gibbs function */
|
||||
#define GIBBS(n, T) gibbs_0(n, T)
|
||||
|
||||
#define MOLAR_MASS(n) (thermo_list + n)->weight
|
||||
|
||||
#define NAME(n) (thermo_list + n)->name
|
||||
|
||||
int global_verbose = 0;
|
||||
|
||||
|
||||
typedef struct _command_
|
||||
{
|
||||
char name[64];
|
||||
int num_arg;
|
||||
void (*function)(char **arg);
|
||||
char description[512];
|
||||
char syntax[256];
|
||||
} command_t;
|
||||
|
||||
|
||||
void help(char **arg);
|
||||
void molarMass(char **arg);
|
||||
void Entropy(char **arg);
|
||||
void Gibbs(char **arg);
|
||||
void Enthalpy(char **arg);
|
||||
void Specific_heat(char **arg);
|
||||
void Internal_energy(char **arg);
|
||||
void Properties(char **arg);
|
||||
void List(char **arg);
|
||||
void Info(char **arg);
|
||||
|
||||
int converti(char *string, unsigned int *number);
|
||||
int convertd(char *string, double *number);
|
||||
|
||||
command_t command_list[] = {
|
||||
{"properties", 2, (void*)Properties,
|
||||
"All properties.\n", "<molecule> <temp>"},
|
||||
{"enthalpy", 2, (void*)Enthalpy,
|
||||
"Enthalpy.\n", "<molecule> <temp>"},
|
||||
{"internal_energy", 2, (void*)Internal_energy,
|
||||
"Internal energy.\n", "<molecule> <temp>"},
|
||||
{"entropy", 2, (void*)Entropy,
|
||||
"Entropy.\n", "<molucule> <temp>"},
|
||||
{"specific_heat", 2, (void*)Specific_heat,
|
||||
"Specific heat (Cp).\n", "<molecule> <temp>"},
|
||||
{"gibbs", 2, (void*)Gibbs,
|
||||
"Gibbs free energy.\n", "<molecule> <temp>"},
|
||||
{"molar_mass", 1, (void*)molarMass,
|
||||
"Molar mass.\n", "<molucule>"},
|
||||
{"info", 1, (void*)Info,
|
||||
"Reference information.\n", "<molecule>"},
|
||||
{"list", 1, (void*)List,
|
||||
"List molecule code beginning by formula.\n", "<formula>"},
|
||||
{"quit", 0, (void*)exit, "Exit the program.\n", ""},
|
||||
{"bye", 0, (void*)exit, "Exit the program.\n", ""},
|
||||
{"exit", 0, (void*)exit, "Exit the program.\n", ""},
|
||||
{"help", 0, (void*)help, "Display help message.\n", ""},
|
||||
{"\0", 0, NULL, "\0"}
|
||||
};
|
||||
|
||||
void help(char **arg)
|
||||
{
|
||||
int i = 0;
|
||||
printf("\n");
|
||||
printf("%-36s %s\n", "Command", "Description");
|
||||
printf("%-36s %s\n", "-------", "-----------");
|
||||
|
||||
while (command_list[i].name[0] != '\0')
|
||||
{
|
||||
printf("%-15s %-20s %s", command_list[i].name, command_list[i].syntax,
|
||||
command_list[i].description);
|
||||
i++;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("Arguments\n");
|
||||
printf("---------\n");
|
||||
printf("<molecule> Number representing a specific molecule in\n");
|
||||
printf(" the database.\n");
|
||||
printf("<temp> Temperature in deg K.\n");
|
||||
printf("<formula> Chemical notation (ex: Fe2Cl)\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
printf("Usage:\n");
|
||||
printf(" -d data_file\n");
|
||||
printf(" -fh\n\n");
|
||||
printf("Arguments:\n");
|
||||
printf("-d data_file Path of the thermodynamics data file\n");
|
||||
printf("-f Supress introduction message\n");
|
||||
printf("-h Help message\n");
|
||||
}
|
||||
|
||||
void List(char **arg)
|
||||
{
|
||||
int i;
|
||||
|
||||
#ifdef BORLAND
|
||||
int j = 0;
|
||||
#endif
|
||||
|
||||
char formula[128];
|
||||
strncpy(formula, arg[0], 128);
|
||||
for (i = 0; i < num_thermo; i++)
|
||||
{
|
||||
if ((STRNCASECMP(NAME(i), formula, strlen(formula)-1)) == 0)
|
||||
{
|
||||
#ifdef BORLAND
|
||||
j++;
|
||||
if (j%22 == 0)
|
||||
{
|
||||
printf("(Press any key to continue)");
|
||||
getchar();
|
||||
}
|
||||
#endif
|
||||
printf("%4d: %s\n", i, NAME(i));
|
||||
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void Info(char **arg)
|
||||
{
|
||||
unsigned int n;
|
||||
/* molecule temperature pressure */
|
||||
if (converti(arg[0], &n) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
if (n > num_thermo)
|
||||
{
|
||||
printf("Value out of range.\n");
|
||||
return;
|
||||
}
|
||||
printf("\nInformation about %s data.\n", NAME(n));
|
||||
printf("---------------------------\n");
|
||||
printf("Reference: %s\n", (thermo_list + n)->comments);
|
||||
printf("Id : %s\n\n", (thermo_list + n)->id);
|
||||
return;
|
||||
}
|
||||
|
||||
void Properties(char **arg)
|
||||
{
|
||||
unsigned int n;
|
||||
double T;
|
||||
|
||||
/* molecule temperature pressure */
|
||||
if (converti(arg[0], &n) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
if (n > num_thermo)
|
||||
{
|
||||
printf("Value out of range.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (convertd(arg[1], &T) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nProperties of %s at %.2f deg K\n", NAME(n), T);
|
||||
printf("---------------------------------\n");
|
||||
printf(" Enthalpy - Internal energy - Entropy\n");
|
||||
printf("%9.3f %-11s %9.3f %-9s %9.3f %-10s\n",
|
||||
ENTHALPY(n, T), "(-)",
|
||||
INTERNAL_ENERGY(n, T), "(-)",
|
||||
ENTROPY(n, T), "(-)");
|
||||
printf("%9.3f %-11s %9.3f %-9s %9.3f %-10s\n",
|
||||
ENTHALPY(n, T)*R*T/1000, "(kJ/mol)",
|
||||
INTERNAL_ENERGY(n, T)*R*T/1000, "(kJ/mol)",
|
||||
ENTROPY(n, T)*R, "(kJ/kmol-K)");
|
||||
printf("%9.3f %-11s %9.3f %-9s %9.3f %-10s\n\n",
|
||||
ENTHALPY(n, T)*R*T/MOLAR_MASS(n), "(kJ/kg)",
|
||||
INTERNAL_ENERGY(n, T)*R*T/MOLAR_MASS(n), "(kJ/kg)",
|
||||
ENTROPY(n, T)*R/MOLAR_MASS(n), "(kJ/kg-K)");
|
||||
|
||||
printf(" Specific Heat - Gibbs free energy\n");
|
||||
printf("%9.3f %-11s %9.3f %-9s\n",
|
||||
SPECIFIC_HEAT(n, T), "(-)",
|
||||
GIBBS(n, T), "(-)");
|
||||
printf("%9.3f %-11s %9.3f %-9s\n",
|
||||
SPECIFIC_HEAT(n, T)*R, "(kJ/kmol-K)",
|
||||
GIBBS(n, T)*R*T/1000, "(kJ/mol)");
|
||||
printf("%9.3f %-11s %9.3f %-9s\n\n",
|
||||
SPECIFIC_HEAT(n, T)*R/MOLAR_MASS(n), "(kJ/kg-K)",
|
||||
GIBBS(n, T)*R*T/MOLAR_MASS(n), "(kJ/kg)");
|
||||
|
||||
}
|
||||
|
||||
void Internal_energy(char **arg)
|
||||
{
|
||||
unsigned int n;
|
||||
double T;
|
||||
|
||||
/* molecule temperature pressure */
|
||||
if (converti(arg[0], &n) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
if (n > num_thermo)
|
||||
{
|
||||
printf("Value out of range.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (convertd(arg[1], &T) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nInternal Energy of %s at %.2f\n", NAME(n), T);
|
||||
printf("%9.3f (-)\n%9.3f (kJ/mol)\n %9.3f (kJ/kg)\n\n",
|
||||
INTERNAL_ENERGY(n, T),
|
||||
INTERNAL_ENERGY(n, T)*R*T/1000,
|
||||
INTERNAL_ENERGY(n, T)*R*T/MOLAR_MASS(n));
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void Entropy(char **arg)
|
||||
{
|
||||
unsigned int n;
|
||||
double T;
|
||||
|
||||
/* molecule temperature pressure */
|
||||
if (converti(arg[0], &n) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
if (n > num_thermo)
|
||||
{
|
||||
printf("Value out of range.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (convertd(arg[1], &T) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nEntropy of %s at %.2f deg K\n", NAME(n), T);
|
||||
printf("%9.3f (-)\n%9.3f kJ/kmol-K\n%9.3f kJ/kg-K\n\n",
|
||||
ENTROPY(n, T),
|
||||
ENTROPY(n, T)*R,
|
||||
ENTROPY(n, T)*R/MOLAR_MASS(n));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Gibbs(char **arg)
|
||||
{
|
||||
unsigned int n;
|
||||
double T;
|
||||
|
||||
/* molecule temperature pressure */
|
||||
if (converti(arg[0], &n) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
if (n > num_thermo)
|
||||
{
|
||||
printf("Value out of range.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (convertd(arg[1], &T) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nGibbs function of %s at %.2f deg K\n", NAME(n), T);
|
||||
printf("%9.3f (-)\n%9.3f (kJ/mol)\n%9.3f (kJ/kg)\n\n",
|
||||
GIBBS(n, T),
|
||||
GIBBS(n, T)*R*T/1000,
|
||||
GIBBS(n, T)*R*T/MOLAR_MASS(n));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Enthalpy(char **arg)
|
||||
{
|
||||
unsigned int n;
|
||||
double T;
|
||||
|
||||
/* molecule temperature pressure */
|
||||
if (converti(arg[0], &n) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
if (n > num_thermo)
|
||||
{
|
||||
printf("Value out of range.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (convertd(arg[1], &T) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nEnthalpy of %s at %.2f deg K\n", NAME(n), T);
|
||||
printf("%9.3f (-)\n%9.3f (kJ/mol)\n%9.3f (kJ/kg)\n\n",
|
||||
ENTHALPY(n, T),
|
||||
ENTHALPY(n, T)*R*T/1000,
|
||||
ENTHALPY(n, T)*R*T/MOLAR_MASS(n));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Specific_heat(char **arg)
|
||||
{
|
||||
unsigned int n;
|
||||
double T;
|
||||
|
||||
/* molecule temperature pressure */
|
||||
if (converti(arg[0], &n) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
if (n > num_thermo)
|
||||
{
|
||||
printf("Value out of range.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (convertd(arg[1], &T) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nSpecific heat (Cp) of %s at %.2f\n", NAME(n), T);
|
||||
printf("%9.3f (-)\n%9.3f (kJ/kmol-K)\n%9.3f (kJ/kg-K)\n\n",
|
||||
SPECIFIC_HEAT(n, T),
|
||||
SPECIFIC_HEAT(n, T)*R,
|
||||
SPECIFIC_HEAT(n, T)*R/MOLAR_MASS(n));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void molarMass(char **arg)
|
||||
{
|
||||
unsigned int n;
|
||||
|
||||
if (converti(arg[0], &n) != 0)
|
||||
{
|
||||
printf("Error converting number.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (n > num_thermo)
|
||||
{
|
||||
printf("Value out of range.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\nMolar mass of %s\n", NAME(n));
|
||||
printf("%9.4f g/mol\n\n", MOLAR_MASS(n));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void welcome(void)
|
||||
{
|
||||
printf("PROP, version %s (GPL License).\n", VERSION);
|
||||
printf("Ideal Gas Thermochemical Properties.\n");
|
||||
printf("Interface to the NASA Gleen Research Center Database\n");
|
||||
printf("provide by Bonnie J. McBride.\n");
|
||||
printf("Copyright (C) 2000 Antoine Lefebvre.\n");
|
||||
printf("For command list, type `help'.\n\n");
|
||||
}
|
||||
|
||||
int converti(char *string, unsigned int *number)
|
||||
{
|
||||
|
||||
char *ptr;
|
||||
|
||||
if (string[0] == '\0')
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
*number = strtoul(string, &ptr, 10);
|
||||
|
||||
if (errno == ERANGE)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ptr[0] == string[0])
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int convertd(char *string, double *number)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
if (string[0] == '\0')
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
*number = strtod(string, &ptr);
|
||||
|
||||
if (errno == ERANGE)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ptr[0] == string[0])
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int i, j, n, c;
|
||||
bool found;
|
||||
bool ok;
|
||||
bool msg = true;
|
||||
|
||||
char line[MAX_LINE];
|
||||
char *ptr;
|
||||
char *running;
|
||||
char *token;
|
||||
|
||||
char **arg;
|
||||
|
||||
char thermo_file[FILENAME_MAX] = "../../data/thermo.dat";
|
||||
|
||||
/* parse the command line */
|
||||
while (1)
|
||||
{
|
||||
c = getopt(argc, argv, "fhd:");
|
||||
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 'd':
|
||||
strncpy(thermo_file, optarg, FILENAME_MAX);
|
||||
break;
|
||||
case 'f':
|
||||
msg = false;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (msg)
|
||||
welcome();
|
||||
|
||||
if (load_thermo (thermo_file) < 0)
|
||||
{
|
||||
printf("Error loading thermo data file: %s\n", thermo_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("%s", PROMPT);
|
||||
|
||||
if (fgets(line, MAX_LINE, stdin) == NULL)
|
||||
{
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (line[0] != '\n')
|
||||
{
|
||||
i = 0;
|
||||
found = false;
|
||||
|
||||
/* duplicate the string */
|
||||
if ((running = strdup(line)) == NULL)
|
||||
{
|
||||
printf("Not enough memory.\n");
|
||||
return -1;
|
||||
}
|
||||
/* keep the adress in memory to free it later */
|
||||
ptr = running;
|
||||
/* first get the command name */
|
||||
token = strtok(running, " \n");
|
||||
|
||||
while ((command_list[i].name[0] != '\0') && (found == false))
|
||||
{
|
||||
|
||||
if (STRNCASECMP(command_list[i].name, token,
|
||||
strlen(token)) == 0)
|
||||
{
|
||||
found = true;
|
||||
ok = true;
|
||||
|
||||
/* number of arguments for this command */
|
||||
n = command_list[i].num_arg;
|
||||
|
||||
/* allocate the memory for the arguments */
|
||||
arg = (char **) malloc(n * sizeof(char*));
|
||||
for (j = 0; j < n; j++)
|
||||
arg[j] = (char *) malloc(ARG_LENGTH * sizeof(char));
|
||||
|
||||
/* get each arguments */
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
if ((token = strtok(NULL, " ")) == NULL)
|
||||
{
|
||||
printf("Not enough arguments.\n");
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
/* copy it */
|
||||
if (ok)
|
||||
strncpy(arg[j], token, ARG_LENGTH);
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
/* verify if there is more arguments than needed */
|
||||
if ((token = strtok(NULL, " ")) != NULL)
|
||||
printf("Too much arguments. Need only %d.\n", n);
|
||||
|
||||
/* execute the command */
|
||||
command_list[i].function(arg);
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
for (j = 0; j < n; j++)
|
||||
free(arg[j]);
|
||||
free(arg);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
free(ptr);
|
||||
|
||||
if (found == false)
|
||||
{
|
||||
printf("?Invalid command\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
ROOT = ../../..
|
||||
include $(ROOT)/config/presrc.mk
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
CC = gcc
|
||||
COPT = -g -Wall -O3 #-pg
|
||||
|
||||
ROOT = ../..
|
||||
|
||||
LIB = -lMagick -lrockflight -lnum -lm
|
||||
|
||||
LIBDIR = -L$(ROOT)/libnum/lib -L/usr/X11R6/lib/ -L../lib/
|
||||
|
||||
INCDIR = -I$(ROOT)/libnum/include -I../src/ \
|
||||
-I/usr/X11R6/include/magick -I/usr/X11R6/include/
|
||||
|
||||
DEF =
|
||||
|
||||
PROG = viewer
|
||||
|
||||
OBJS = viewer.o
|
||||
|
||||
all: $(PROG) $(PROG2)
|
||||
|
||||
.c.o:
|
||||
$(CC) $(DEF) $(INCDIR) $(COPT) -c $*.c -o $*.o
|
||||
|
||||
$(PROG): $(OBJS) $(LIBNAME)
|
||||
$(CC) $(COPT) $(OBJS) $(LIBDIR) $(LIB) -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o *~
|
||||
|
||||
deep-clean: clean
|
||||
rm -f $(PROG)
|
||||
@@ -0,0 +1,454 @@
|
||||
|
||||
#include <X11/Xlib.h> // Every Xlib program must include this
|
||||
#include <linux/mc146818rtc.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h> // So we got the profile for 10 seconds
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "rocflight.h"
|
||||
#include "num.h"
|
||||
#include "state.h"
|
||||
|
||||
|
||||
#define PIXEL_M 15
|
||||
#define PIXEL_M_S 15
|
||||
|
||||
#define H 40
|
||||
#define L 40
|
||||
#define SCALEY 1
|
||||
|
||||
#define WIDTH L * PIXEL_M
|
||||
#define HEIGHT (int)(H * PIXEL_M * SCALEY)
|
||||
|
||||
#define MAX_HISTORY 200
|
||||
#define FREQ 32
|
||||
#define STEP (1.0/FREQ)
|
||||
|
||||
#define POSX_TO_PIXEL(x) (WIDTH/2 + (int)((x) * PIXEL_M))
|
||||
#define POSY_TO_PIXEL(y) (HEIGHT - (int)((y) * PIXEL_M * SCALEY))
|
||||
|
||||
|
||||
struct rocketAnim_t
|
||||
{
|
||||
int width, height;
|
||||
|
||||
GC gc;
|
||||
GC tmpgc;
|
||||
Display *display;
|
||||
Window window;
|
||||
Pixmap pixmap;
|
||||
unsigned long red, blue, white, green;
|
||||
|
||||
XFontStruct *font_info;
|
||||
int font_height;
|
||||
|
||||
} rocket;
|
||||
|
||||
|
||||
|
||||
int eom(int neq, double time, double *y, double *dy, void *data);
|
||||
|
||||
|
||||
|
||||
unsigned long AllocColor(char *colName)
|
||||
{
|
||||
Colormap cmap;
|
||||
XColor c0, c1;
|
||||
cmap = DefaultColormap(rocket.display, 0);
|
||||
XAllocNamedColor(rocket.display, cmap, colName, &c1, &c0);
|
||||
return(c1.pixel);
|
||||
}
|
||||
|
||||
void ExposeScreen(void)
|
||||
{
|
||||
XCopyArea(rocket.display, rocket.pixmap,
|
||||
rocket.window, rocket.tmpgc,
|
||||
0, 0, rocket.width, rocket.height, 0, 0);
|
||||
}
|
||||
|
||||
void rocketInit(void)
|
||||
{
|
||||
Display *d;
|
||||
Window w;
|
||||
Pixmap p;
|
||||
XEvent e;
|
||||
|
||||
d = rocket.display = XOpenDisplay(NULL);
|
||||
|
||||
w = rocket.window = XCreateSimpleWindow(d, DefaultRootWindow(d),
|
||||
0, 0,
|
||||
rocket.width, rocket.height,
|
||||
2, BlackPixel(d, 0),
|
||||
WhitePixel(d, 0));
|
||||
|
||||
p = rocket.pixmap = XCreatePixmap(d, DefaultRootWindow(d),
|
||||
rocket.width, rocket.height,
|
||||
DefaultDepth(d, 0));
|
||||
|
||||
rocket.gc = XCreateGC(d, w, 0, 0);
|
||||
rocket.tmpgc = XCreateGC(d, w, 0, 0);
|
||||
rocket.red = AllocColor("red");
|
||||
rocket.blue = AllocColor("blue");
|
||||
rocket.white = AllocColor("white");
|
||||
rocket.green = AllocColor("green");
|
||||
|
||||
rocket.font_info = XQueryFont(d, XGContextFromGC(rocket.gc));
|
||||
rocket.font_height = rocket.font_info->ascent + rocket.font_info->descent;
|
||||
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.white);
|
||||
XFillRectangle(d, p, rocket.gc, 0, 0, rocket.width, rocket.height);
|
||||
XMapWindow(d, w);
|
||||
XSelectInput(d, w, StructureNotifyMask);
|
||||
|
||||
for(;;) {
|
||||
XNextEvent(d, &e);
|
||||
if (e.type == MapNotify)
|
||||
break;
|
||||
}
|
||||
XFlush(d);
|
||||
}
|
||||
|
||||
void DrawLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
/* Draw the new line */
|
||||
XDrawLine(rocket.display, rocket.pixmap, rocket.gc, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
void DrawPoint(int x, int y)
|
||||
{
|
||||
/* draw the point */
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.red);
|
||||
XDrawPoint(rocket.display, rocket.pixmap, rocket.gc, x, y);
|
||||
}
|
||||
|
||||
void DrawFillCircle(int x, int y, int r)
|
||||
{
|
||||
/* Draw the circle */
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.red);
|
||||
XFillArc(rocket.display, rocket.pixmap, rocket.gc,
|
||||
x - r, y - r, 2*r, 2*r, 0, 360*64);
|
||||
}
|
||||
|
||||
void DrawSystem(double *y)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
double x1, y1;
|
||||
|
||||
double theta;
|
||||
double vitesse_tot;
|
||||
|
||||
char vitessex[32];
|
||||
char vitessey[32];
|
||||
char vitesset[32];
|
||||
|
||||
char alpha_str[32];
|
||||
|
||||
char theta_str[32];
|
||||
char velocity_str[32];
|
||||
|
||||
double velocity;
|
||||
|
||||
theta = y[10];
|
||||
|
||||
velocity = sqrt(y[0]*y[0] + y[1]*y[1] + y[2]*y[2]);
|
||||
|
||||
vitesse_tot =
|
||||
sqrt(pow(y[0], 2) + pow(y[2], 2));
|
||||
|
||||
sprintf(velocity_str, "Velocity : % .2f m/s", velocity);
|
||||
sprintf(alpha_str, "Angle of attack : % 6.2f deg", atan(y[2]/y[0])*180/M_PI);
|
||||
sprintf(theta_str, "Theta : % .2f deg", theta*180/M_PI);
|
||||
|
||||
sprintf(vitessex, "Vitesse axe x : % .2f", y[0]);
|
||||
sprintf(vitessey, "Vitesse axe y : % .2f", y[2]);
|
||||
sprintf(vitesset, "Vitesse absolue: % .2f", vitesse_tot);
|
||||
|
||||
/* Clear the screen */
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.white);
|
||||
XFillRectangle(rocket.display, rocket.pixmap,
|
||||
rocket.gc, 0, 0, rocket.width, rocket.height);
|
||||
|
||||
//DrawFillCircle(POSX_TO_PIXEL(x), POSY_TO_PIXEL(y), 10);
|
||||
//printf("%f\n", y[10]);
|
||||
|
||||
|
||||
/* Draw the rocket */
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.red);
|
||||
|
||||
x1 = 0 + 8*cos(theta);
|
||||
y1 = 20 + 8*sin(theta);
|
||||
|
||||
DrawLine(POSX_TO_PIXEL(0 - sin(theta)), POSY_TO_PIXEL(20 + cos(theta)),
|
||||
POSX_TO_PIXEL(x1 - sin(theta)), POSY_TO_PIXEL(y1 + cos(theta)));
|
||||
DrawLine(POSX_TO_PIXEL(0 + sin(theta)), POSY_TO_PIXEL(20 - cos(theta)),
|
||||
POSX_TO_PIXEL(x1 + sin(theta)), POSY_TO_PIXEL(y1 - cos(theta)));
|
||||
DrawLine(POSX_TO_PIXEL(x1 - sin(theta)), POSY_TO_PIXEL(y1 + cos(theta)),
|
||||
POSX_TO_PIXEL(x1 + 4*cos(theta)), POSY_TO_PIXEL(y1 + 4*sin(theta)));
|
||||
DrawLine(POSX_TO_PIXEL(x1 + sin(theta)), POSY_TO_PIXEL(y1 - cos(theta)),
|
||||
POSX_TO_PIXEL(x1 + 4*cos(theta)), POSY_TO_PIXEL(y1 + 4*sin(theta)));
|
||||
|
||||
|
||||
XSetForeground(rocket.display, rocket.gc, rocket.blue);
|
||||
|
||||
|
||||
x1 = (y[0]*cos(theta) - y[2]*sin(theta))/50;
|
||||
y1 = 20 + (y[0]*sin(theta) + y[2]*cos(theta))/50;
|
||||
|
||||
DrawLine(POSX_TO_PIXEL(0), POSY_TO_PIXEL(20),
|
||||
POSX_TO_PIXEL(x1), POSY_TO_PIXEL(y1));
|
||||
|
||||
//DrawLine(x, y,
|
||||
|
||||
/*
|
||||
if (modeleInfo.full)
|
||||
j = MAX_HISTORY;
|
||||
else
|
||||
j = modeleInfo.lasthistory;
|
||||
|
||||
for (i = 0; i < j; i++)
|
||||
DrawPoint(POSX_TO_PIXEL(modeleInfo.pointhistory[i][0]),
|
||||
POSY_TO_PIXEL(modeleInfo.pointhistory[i][1]));
|
||||
*/
|
||||
|
||||
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 10,
|
||||
HEIGHT - 3*rocket.font_height, velocity_str,
|
||||
strlen(velocity_str));
|
||||
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 10,
|
||||
HEIGHT - 2*rocket.font_height, alpha_str, strlen(alpha_str));
|
||||
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 10,
|
||||
HEIGHT - rocket.font_height, theta_str, strlen(theta_str));
|
||||
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 100,
|
||||
HEIGHT - 3*rocket.font_height, vitessex,
|
||||
strlen(vitessex));
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 100,
|
||||
HEIGHT - 2*rocket.font_height, vitessey,
|
||||
strlen(vitessey));
|
||||
XDrawString(rocket.display, rocket.pixmap, rocket.gc, 100,
|
||||
HEIGHT - 1*rocket.font_height, vitesset,
|
||||
strlen(vitesset));
|
||||
|
||||
|
||||
|
||||
/* XFillRectangle(rocket.display, rocket.pixmap, rocket.gc, 140,
|
||||
HEIGHT - 4*rocket.font_height + rocket.font_info->ascent/2,
|
||||
(int)(PIXEL_M_S * fabs(modeleInfo.state[2])),
|
||||
rocket.font_height/2);
|
||||
|
||||
XFillRectangle(rocket.display, rocket.pixmap, rocket.gc, 140,
|
||||
HEIGHT - 3*rocket.font_height + rocket.font_info->ascent/2,
|
||||
(int)(PIXEL_M_S * fabs(modeleInfo.state[3])),
|
||||
rocket.font_height/2);
|
||||
|
||||
XFillRectangle(rocket.display, rocket.pixmap, rocket.gc, 140,
|
||||
HEIGHT - 2*rocket.font_height + rocket.font_info->ascent/2,
|
||||
(int)(PIXEL_M_S * vitesse_tot),
|
||||
rocket.font_height/2);
|
||||
|
||||
*/
|
||||
|
||||
ExposeScreen();
|
||||
XFlush(rocket.display);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int i, n;
|
||||
int neq = 12;
|
||||
|
||||
double time;
|
||||
double res[12];
|
||||
|
||||
double *ans;
|
||||
double *init_cond;
|
||||
|
||||
double u = 100; /* velocity component in x */
|
||||
double v = 0; /* velocity component in y */
|
||||
double w = 0; /* velocity component in z */
|
||||
|
||||
double P = 0; /* angular velocity */
|
||||
double Q = 0; /* */
|
||||
double R = 0; /* */
|
||||
|
||||
double lambda = 0*(M_PI/180); /* latitude (positive north) */
|
||||
double mu = 0*(M_PI/180); /* longitude (positive east) */
|
||||
double Re = EARTH_RAD + 5000; /* distance from earth center */
|
||||
double phi = 0*(M_PI/180); /* */
|
||||
double theta = 45*(M_PI/180); /* positive up */
|
||||
double psi = 0*(M_PI/180); /* positive cw*/
|
||||
|
||||
|
||||
// double dt = 0.05;
|
||||
double duration = 10;
|
||||
|
||||
state_t s;
|
||||
|
||||
|
||||
int fd, retval;
|
||||
unsigned long tmp, data;
|
||||
struct rtc_time rtc_tm;
|
||||
|
||||
/* Initialize the window */
|
||||
rocket.width = WIDTH;
|
||||
rocket.height = HEIGHT;
|
||||
rocketInit();
|
||||
|
||||
|
||||
/* open and configure the realtime clock */
|
||||
fd = open ("/dev/rtc", O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("/dev/rtc");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
/* Set the periodic IRQ rate to FREQ Hz */
|
||||
retval = ioctl(fd, RTC_IRQP_SET, FREQ);
|
||||
if (retval == -1)
|
||||
{
|
||||
perror("ioctl");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
/* Enable periodic interrupts */
|
||||
retval = ioctl(fd, RTC_PIE_ON, 0);
|
||||
if (retval == -1)
|
||||
{
|
||||
perror("ioctl");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
//initModele();
|
||||
|
||||
|
||||
s.m = 10.0;
|
||||
|
||||
s.Ix = 25e-3;
|
||||
s.Iy = 3;
|
||||
s.Iz = 3;
|
||||
|
||||
s.Faero[0] = 0;
|
||||
s.Faero[1] = 0;
|
||||
s.Faero[2] = 0;
|
||||
|
||||
s.Maero[0] = 0;
|
||||
s.Maero[1] = 0;
|
||||
s.Maero[2] = 0;
|
||||
|
||||
init_cond = (double *) malloc(sizeof(double) * neq);
|
||||
|
||||
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);
|
||||
|
||||
init_cond[0] = u; /* velocity component in x */
|
||||
init_cond[1] = v; /* velocity component in y */
|
||||
init_cond[2] = w; /* velocity component in z */
|
||||
init_cond[3] = P+ (s.L_BV[0][0]*WE*cos(lambda)-s.L_BV[0][2]*WE*sin(lambda));
|
||||
init_cond[4] = Q+ (s.L_BV[1][0]*WE*cos(lambda)-s.L_BV[1][2]*WE*sin(lambda));
|
||||
init_cond[5] = R+ (s.L_BV[2][0]*WE*cos(lambda)-s.L_BV[2][2]*WE*sin(lambda));
|
||||
init_cond[6] = lambda; /* latitude */
|
||||
init_cond[7] = mu; /* longitude */
|
||||
init_cond[8] = Re; /* radius */
|
||||
init_cond[9] = phi; /* phi */
|
||||
init_cond[10] = theta; /* theta */
|
||||
init_cond[11] = psi; /* psi */
|
||||
|
||||
time = 0;
|
||||
|
||||
// eom(neq, time, init_cond, res, &s);
|
||||
/*
|
||||
fprintf(stderr, "% e (u dot)\n", res[0]);
|
||||
fprintf(stderr, "% e (v dot)\n", res[1]);
|
||||
fprintf(stderr, "% e (w dot)\n", res[2]);
|
||||
fprintf(stderr, "% e (p dot)\n", res[3]);
|
||||
fprintf(stderr, "% e (q dot)\n", res[4]);
|
||||
fprintf(stderr, "% e (r dot)\n", res[5]);
|
||||
fprintf(stderr, "% e (lambda dot)\n", res[6]);
|
||||
fprintf(stderr, "% e (mu dot)\n", res[7]);
|
||||
fprintf(stderr, "% e (R dot)\n", res[8]);
|
||||
fprintf(stderr, "% e (phi dot)\n", res[9]);
|
||||
fprintf(stderr, "% e (theta dot)\n", res[10]);
|
||||
fprintf(stderr, "% e (psi dot)\n", res[11]);
|
||||
*/
|
||||
|
||||
n = NUM_rk4 (eom, neq, STEP, duration, init_cond, &ans, &s);
|
||||
|
||||
|
||||
|
||||
/* set the initial conditions */
|
||||
//modeleInfo.state[0] = 7.0;
|
||||
//modeleInfo.state[1] = 25.0;//.3944;
|
||||
//modeleInfo.state[2] = 0.0;
|
||||
//modeleInfo.state[3] = 0.0;
|
||||
|
||||
|
||||
// for( i = 0; i < n; i++)
|
||||
// {
|
||||
// printf("% .12e ", ans[0 + neq*i]); /* u */
|
||||
// printf("% .12e ", ans[1 + neq*i]); /* v */
|
||||
// printf("% .12e ", ans[2 + neq*i]); /* w */
|
||||
// printf("% .12e ", ans[3 + neq*i]); /* p */
|
||||
// printf("% .12e ", ans[4 + neq*i]); /* q */
|
||||
// printf("% .12e ", ans[5 + neq*i]); /* r */
|
||||
// printf("% .12e ", ans[6 + neq*i]); /* lambda */
|
||||
// printf("% .12e ", ans[7 + neq*i]); /* mu */
|
||||
// printf("% .12e ", ans[8 + neq*i]); /* R */
|
||||
// printf("% .12e ", ans[9 + neq*i]); /* phi */
|
||||
// printf("% .12e ", ans[10 + neq*i]); /* theta */
|
||||
// printf("% .12e \n", ans[11 + neq*i]); /* psi */
|
||||
// }
|
||||
|
||||
|
||||
// DrawSystem(y);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
/* This blocks */
|
||||
retval = read(fd, &data, sizeof(unsigned long));
|
||||
if (retval == -1)
|
||||
{
|
||||
perror("read");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
DrawSystem(ans + neq*i);
|
||||
}
|
||||
|
||||
/* Disable periodic interrupts */
|
||||
retval = ioctl(fd, RTC_PIE_OFF, 0);
|
||||
if (retval == -1)
|
||||
{
|
||||
perror("ioctl");
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
|
||||
free(init_cond);
|
||||
//free(ans);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
TYPE = "debug"
|
||||
ROOT = ../../../..
|
||||
include $(ROOT)/config/makedef
|
||||
include $(ROOT)/config/exesrc.mk
|
||||
@@ -0,0 +1,40 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "librockflight/include/state.h"
|
||||
|
||||
extern int stage(rocket_t *r, double *t);
|
||||
extern int mass(rocket_t *r, double *t);
|
||||
extern int engine(rocket_t *r, double *t);
|
||||
|
||||
/* This function will output rocket state from 0 to t every dt interval.
|
||||
It is useful to check if the thrust, masses, engines and stages follow
|
||||
the configuration we want. */
|
||||
int check(rocket_t *r, double tf, double dt)
|
||||
{
|
||||
double t;
|
||||
|
||||
for (t = 0.0; t < tf; t += dt)
|
||||
{
|
||||
if (stage(r, &t))
|
||||
{
|
||||
printf("Error in function stage.\n");
|
||||
return -1;
|
||||
}
|
||||
if (mass(r, &t))
|
||||
{
|
||||
printf("Error in function mass.\n");
|
||||
return -1;
|
||||
}
|
||||
if (engine(r, &t))
|
||||
{
|
||||
printf("Error in function engine.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Time: %5.2f s -> Stage: %d -> Mass: %7.2f -> Thrust: %7.2f\n",
|
||||
t, r->state.s, r->state.m, r->state.Feng[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
LIB = -lrockflight -lgpcp -lnum -lm
|
||||
PROG = rockflight
|
||||
OBJS = parser.o print.o simulate.o check.o rockflight.o
|
||||
@@ -0,0 +1,638 @@
|
||||
/* rocket.c
|
||||
* sample program for parsing a rocket propellant simulator config.
|
||||
*
|
||||
* $Id: parser.c,v 1.6 2002/03/09 18:05:28 antoine Exp $
|
||||
*
|
||||
* Copyright (C) 2000,
|
||||
* Antoine Lefebvre <antoine.lefebvre@polymtl.ca>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "gpcp.h"
|
||||
#include "librockflight/include/state.h"
|
||||
|
||||
int get_point_value(char *name, float *point);
|
||||
int load_data(char *file, float **x, float **y, int *n, parameter_t *p);
|
||||
int load_function_data(function_t *f, char *constant_name, char *table_name);
|
||||
|
||||
Options rockflight_options[] = {
|
||||
{"simulation", PARENT, NULL},
|
||||
|
||||
{"initial_conditions", PARENT, "simulation"},
|
||||
{"u", FLOAT, "initial_conditions"},
|
||||
{"v", FLOAT, "initial_conditions"},
|
||||
{"w", FLOAT, "initial_conditions"},
|
||||
{"P", FLOAT, "initial_conditions"},
|
||||
{"Q", FLOAT, "initial_conditions"},
|
||||
{"R", FLOAT, "initial_conditions"},
|
||||
{"latitude", FLOAT, "initial_conditions"},
|
||||
{"longitude", FLOAT, "initial_conditions"},
|
||||
{"altitude", FLOAT, "initial_conditions"},
|
||||
{"phi", FLOAT, "initial_conditions"},
|
||||
{"theta", FLOAT, "initial_conditions"},
|
||||
{"psi", FLOAT, "initial_conditions"},
|
||||
|
||||
{"rocket", PARENT, "simulation"},
|
||||
{"stage", PARENT, "rocket"},
|
||||
|
||||
{"dry_mass", FLOAT, "stage"},
|
||||
{"Ix", FLOAT, "stage"},
|
||||
{"Ix_data_file", STRING, "stage"},
|
||||
{"Iy", FLOAT, "stage"},
|
||||
{"Iy_data_file", STRING, "stage"},
|
||||
{"Iz", FLOAT, "stage"},
|
||||
{"Iz_data_file", STRING, "stage"},
|
||||
{"Cd", FLOAT, "stage"},
|
||||
{"Cd_data_file", STRING, "stage"},
|
||||
{"CL", FLOAT, "stage"},
|
||||
{"CL_data_file", STRING, "stage"},
|
||||
{"CB", FLOAT, "stage"},
|
||||
{"CB_data_file", STRING, "stage"},
|
||||
{"Cspin", FLOAT, "stage"},
|
||||
{"Cmoment", FLOAT, "stage"},
|
||||
{"Cdamping", FLOAT, "stage"},
|
||||
{"Diameter", FLOAT, "stage"},
|
||||
{"active_time", FLOAT, "stage"},
|
||||
|
||||
{"engine", PARENT, "stage"},
|
||||
{"type", STRING, "engine"},
|
||||
{"propellant_mass", FLOAT, "engine"},
|
||||
{"dry_mass", FLOAT, "engine"},
|
||||
{"thrust", FLOAT, "engine"},
|
||||
{"thrust_data_file", STRING, "engine"},
|
||||
{"mass_flow", FLOAT, "engine"},
|
||||
{"c", FLOAT, "engine"},
|
||||
{"start_time", FLOAT, "engine"},
|
||||
{"burn_time", FLOAT, "engine"},
|
||||
{"drop_time", FLOAT, "engine"},
|
||||
{"position", PARENT, "engine"},
|
||||
{"x", FLOAT, "position"},
|
||||
{"y", FLOAT, "position"},
|
||||
{"z", FLOAT, "position"},
|
||||
{"direction", PARENT, "engine"},
|
||||
{"x", FLOAT, "direction"},
|
||||
{"y", FLOAT, "direction"},
|
||||
{"z", FLOAT, "direction"},
|
||||
|
||||
{"solution", PARENT, "simulation"},
|
||||
{"duration", FLOAT, "solution"},
|
||||
{"dt", FLOAT, "solution"},
|
||||
{"precision", FLOAT, "solution"},
|
||||
{NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int load_config(Data *data, rocket_t *rocket, float *init_cond,
|
||||
solution_t *solution)
|
||||
{
|
||||
int i, j;
|
||||
int n, m;
|
||||
|
||||
/* int status; */
|
||||
|
||||
/*char *type;*/
|
||||
/*char *filename;*/
|
||||
float *val;
|
||||
|
||||
engine_t *engine;
|
||||
|
||||
function_t *f;
|
||||
|
||||
if (GPCP_EnterLevel("simulation", 0) == -1)
|
||||
{
|
||||
printf("Error: no simulation to execute in config file.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/***************** initial conditions ********************/
|
||||
n = GPCP_NumParent("initial_conditions");
|
||||
if (n > 1)
|
||||
{
|
||||
printf("There should be only one \"initial_conditions\""
|
||||
" keyword in \"simulation\".\n"
|
||||
"The first one will be used.\n");
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
printf("No \"initial_conditions\" in config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (GPCP_EnterLevel("initial_conditions", 0) == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (GPCP_GetValue ("u", init_cond) != 0)
|
||||
*(init_cond+0) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("v", init_cond+1) != 0)
|
||||
*(init_cond+1) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("w", init_cond+2) != 0)
|
||||
*(init_cond+2) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("P", init_cond+3) != 0)
|
||||
*(init_cond+3) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("Q", init_cond+4) != 0)
|
||||
*(init_cond+4) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("R", init_cond+5) != 0)
|
||||
*(init_cond+5) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("latitude", init_cond+6) != 0)
|
||||
*(init_cond+6) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("longitude", init_cond+7) != 0)
|
||||
*(init_cond+7) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("altitude", init_cond+8) != 0)
|
||||
*(init_cond+8) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("phi", init_cond+9) != 0)
|
||||
*(init_cond+9) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("theta", init_cond+10) != 0)
|
||||
*(init_cond+10) = 0.0;
|
||||
|
||||
if (GPCP_GetValue ("psi", init_cond+11) != 0)
|
||||
*(init_cond+11) = 0.0;
|
||||
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave 'initial_conditions' level.\n");
|
||||
}
|
||||
}
|
||||
/********************* end initial_conditions *****************/
|
||||
|
||||
/********************* rocket *********************************/
|
||||
n = GPCP_NumParent("rocket");
|
||||
if (n > 1)
|
||||
{
|
||||
printf("There should be only one \"rocket\""
|
||||
" keyword in \"simulation\".\n"
|
||||
"The first one will be used.\n");
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
printf("No \"rocket\" in config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (GPCP_EnterLevel("rocket", 0) == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
n = GPCP_NumParent("stage");
|
||||
if (n == 0)
|
||||
{
|
||||
printf("No \"stage\" in config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* allocate memory for stage properties */
|
||||
(*rocket).n_stage = n;
|
||||
(*rocket).stage_properties = (rocket_properties_t *)
|
||||
malloc (sizeof(rocket_properties_t) * n);
|
||||
|
||||
/* for each stage */
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (GPCP_EnterLevel("stage", i) == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
val = &(*rocket).stage_properties[i].dry_mass;
|
||||
if (GPCP_GetValue ("dry_mass", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
f = &(*rocket).stage_properties[i].Ix;
|
||||
if (load_function_data(f, "Ix", "Ix_data_file"))
|
||||
return -1;
|
||||
|
||||
f = &(*rocket).stage_properties[i].Iy;
|
||||
if (load_function_data(f, "Iy", "Iy_data_file"))
|
||||
return -1;
|
||||
|
||||
f = &(*rocket).stage_properties[i].Iz;
|
||||
if (load_function_data(f, "Iz", "Iz_data_file"))
|
||||
return -1;
|
||||
|
||||
f = &(*rocket).stage_properties[i].Cd;
|
||||
if (load_function_data(f, "Cd", "Cd_data_file"))
|
||||
return -1;
|
||||
|
||||
f = &(*rocket).stage_properties[i].CL;
|
||||
if (load_function_data(f, "CL", "CL_data_file"))
|
||||
return -1;
|
||||
|
||||
f = &(*rocket).stage_properties[i].CB;
|
||||
if (load_function_data(f, "CB", "CB_data_file"))
|
||||
return -1;
|
||||
|
||||
val = &(*rocket).stage_properties[i].Cspin;
|
||||
if (GPCP_GetValue ("Cspin", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(*rocket).stage_properties[i].Cmoment;
|
||||
if (GPCP_GetValue ("Cmoment", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(*rocket).stage_properties[i].Cdamping;
|
||||
if (GPCP_GetValue ("Cdamping", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(*rocket).stage_properties[i].Diameter;
|
||||
if (GPCP_GetValue ("Diameter", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(*rocket).stage_properties[i].active_time;
|
||||
if (GPCP_GetValue ("active_time", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
m = GPCP_NumParent("engine");
|
||||
(*rocket).stage_properties[i].n_engine = m;
|
||||
if (m < 1)
|
||||
{
|
||||
printf("There is no engine for stage %d\n", i);
|
||||
(*rocket).stage_properties[i].engines = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* allocate memory for engines */
|
||||
(*rocket).stage_properties[i].engines =
|
||||
(engine_t *) malloc (sizeof(engine_t)*m);
|
||||
}
|
||||
|
||||
for (j = 0; j < m; j++)
|
||||
{
|
||||
if (GPCP_EnterLevel("engine", j) == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set a temporary pointer */
|
||||
engine =
|
||||
&((*rocket).stage_properties[i].engines[j]);
|
||||
|
||||
f = &(engine->thrust);
|
||||
if (load_function_data(f, "thrust", "thrust_data_file"))
|
||||
return -1;
|
||||
|
||||
/*
|
||||
if (GPCP_GetValue("type", &type) != 0)
|
||||
{
|
||||
printf("Type of thrust must be specified.\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp("constant_thrust", type) == 0)
|
||||
{
|
||||
engine->thrust.type = _CONSTANT;
|
||||
}
|
||||
else if (strcmp("thrust_table_data", type) == 0)
|
||||
{
|
||||
engine->thrust.type = _TABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Undefined type of thrust : %s.\n", type);
|
||||
return -1;
|
||||
}
|
||||
free(type);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
switch (engine->thrust.type)
|
||||
{
|
||||
|
||||
case _CONSTANT:
|
||||
engine->thrust.x = NULL;
|
||||
engine->thrust.y = NULL;
|
||||
|
||||
val = &(engine->thrust.constant_value);
|
||||
if (GPCP_GetValue("thrust", val) != 0)
|
||||
*val = 0.0;
|
||||
break;
|
||||
|
||||
case _TABLE:
|
||||
|
||||
if (GPCP_GetValue("thrust_data_file",
|
||||
&filename)
|
||||
== 0)
|
||||
{
|
||||
status = load_data(filename,
|
||||
&(engine->thrust.x),
|
||||
&(engine->thrust.y),
|
||||
&(engine->thrust.n_point),
|
||||
&(engine->thrust.independant_var)
|
||||
);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
printf("Error reading data file.\n");
|
||||
return -1;
|
||||
}
|
||||
free(filename);
|
||||
}
|
||||
break;
|
||||
|
||||
case _FUNCTION:
|
||||
printf("Functions are not supported yet.\n");
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
val = &(engine->propellant_mass);
|
||||
if (GPCP_GetValue("propellant_mass", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->dry_mass);
|
||||
if (GPCP_GetValue("dry_mass", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->mass_flow);
|
||||
if (GPCP_GetValue("mass_flow", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->c);
|
||||
if (GPCP_GetValue("c", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->start_time);
|
||||
if (GPCP_GetValue("start_time", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->burn_time);
|
||||
if (GPCP_GetValue("burn_time", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = &(engine->drop_time);
|
||||
if (GPCP_GetValue("drop_time", val) != 0)
|
||||
*val = 0.0;
|
||||
|
||||
val = engine->position;
|
||||
if (get_point_value("position", val) != 0)
|
||||
{
|
||||
printf("Unable to get position.\n");
|
||||
}
|
||||
|
||||
val = engine->direction;
|
||||
if (get_point_value("direction", val) != 0)
|
||||
{
|
||||
printf("Unble to get direction.\n");
|
||||
}
|
||||
|
||||
}
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave engine level.\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave 'initial_conditions'"
|
||||
" level.\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave 'rocket' level.\n");
|
||||
}
|
||||
}
|
||||
/********************* end rocket *****************************/
|
||||
|
||||
|
||||
/********************* solution *******************************/
|
||||
n = GPCP_NumParent("solution");
|
||||
if (n > 1)
|
||||
{
|
||||
printf("There should be only one \"solution\""
|
||||
" keyword in \"simulation\".\n"
|
||||
"The first one will be used.\n");
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
printf("No \"solution\" in config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (GPCP_EnterLevel("solution", 0) == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue ("duration", &((*solution).duration)) != 0)
|
||||
{
|
||||
printf("A duration mus be specified.\n");
|
||||
}
|
||||
if (GPCP_GetValue ("dt", &((*solution).dt)) != 0)
|
||||
{
|
||||
(*solution).dt = 0.1;
|
||||
}
|
||||
if (GPCP_GetValue ("precision", &((*solution).precision)) != 0)
|
||||
{
|
||||
(*solution).precision = 0.01;
|
||||
}
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave 'solution' level.\n");
|
||||
}
|
||||
}
|
||||
/***************** end solution *****************************/
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave 'simulation' level.\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int get_point_value(char *name, float *point)
|
||||
{
|
||||
if (GPCP_EnterLevel(name, 0) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GPCP_GetValue("x", point+0) != 0)
|
||||
*(point+0) = 0.0;
|
||||
if (GPCP_GetValue("y", point+1) != 0)
|
||||
*(point+1) = 0.0;
|
||||
if (GPCP_GetValue("z", point+2) != 0)
|
||||
*(point+2) = 0.0;
|
||||
}
|
||||
|
||||
if (GPCP_ExitLevel() != 0)
|
||||
{
|
||||
printf("Unable to leave '%s' level.\n", name);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read_file(char *config_file, rocket_t *rocket, float *init_cond,
|
||||
solution_t *solution)
|
||||
{
|
||||
Data *data;
|
||||
GPCP_RegisterOptions(rockflight_options);
|
||||
|
||||
if (GPCP_ReadFile(config_file, &data) != 0)
|
||||
{
|
||||
printf("Error reading config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (load_config(data, rocket, init_cond, solution) != 0)
|
||||
{
|
||||
printf("Error: unable to correctly load data.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* GPCP_PrintData(data); */
|
||||
|
||||
GPCP_FreeData(&data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int load_data(char *file, float **x, float **y, int *n, parameter_t *p)
|
||||
{
|
||||
int i;
|
||||
FILE *fd;
|
||||
char line[128];
|
||||
char *retval;
|
||||
int scan_status;
|
||||
|
||||
fd = fopen(file, "r");
|
||||
|
||||
if (fd == NULL)
|
||||
{
|
||||
printf("Unable to open file: %s.\n", file);
|
||||
return -1;
|
||||
}
|
||||
printf("Reading data file (%s)...\n", file);
|
||||
|
||||
/* read the first line containing the independant variable name */
|
||||
retval = fgets(line, 128, fd);
|
||||
/* find the \n and replace it by \0 */
|
||||
retval = strchr(line, '\n');
|
||||
if (retval != NULL)
|
||||
*retval = '\0';
|
||||
|
||||
if (strcmp("ALT", line) == 0)
|
||||
*p = ALT;
|
||||
else if (strcmp("MACH", line) == 0)
|
||||
*p = MACH;
|
||||
else if (strcmp("AOA", line) == 0)
|
||||
*p = AOA;
|
||||
else if (strcmp("TIME", line) == 0)
|
||||
*p = TIME;
|
||||
else
|
||||
{
|
||||
printf("Unknown independant variable : %s.\n", line);
|
||||
return -1;
|
||||
}
|
||||
|
||||
retval = fgets(line, 128, fd);
|
||||
*x = NULL;
|
||||
*y = NULL;
|
||||
i = 0;
|
||||
while (retval != NULL)
|
||||
{
|
||||
if (line[0] != '#')
|
||||
{
|
||||
i++;
|
||||
|
||||
*x = (float *) realloc(*x, sizeof(float)*i);
|
||||
if (*x == NULL)
|
||||
{
|
||||
printf("memory error.\n");
|
||||
return -1;
|
||||
}
|
||||
*y = (float *) realloc(*y, sizeof(float)*i);
|
||||
if (*y == NULL)
|
||||
{
|
||||
printf("memory error.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
scan_status = sscanf(line, "%f %f", *x+i-1, *y+i-1);
|
||||
|
||||
if (scan_status != 2)
|
||||
{
|
||||
printf("Error reading file.\n");
|
||||
}
|
||||
}
|
||||
retval = fgets(line, 128, fd);
|
||||
}
|
||||
|
||||
*n = i;
|
||||
|
||||
printf("... %d points read.\n", i);
|
||||
|
||||
fclose(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int load_function_data(function_t *f, char *constant_name, char *table_name)
|
||||
{
|
||||
|
||||
int status;
|
||||
char *filename;
|
||||
float *val;
|
||||
|
||||
f->name = (char *) malloc(sizeof(char) * (strlen(constant_name) + 1));
|
||||
strcpy(f->name, constant_name);
|
||||
|
||||
if (GPCP_GetValue(table_name, &filename) == 0)
|
||||
{
|
||||
status = load_data(filename, &(f->x), &(f->y),
|
||||
&(f->n_point), &(f->independant_var));
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
printf("Error reading data file.\n");
|
||||
return -1;
|
||||
}
|
||||
f->type = _TABLE;
|
||||
free(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
f->type = _CONSTANT;
|
||||
f->x = NULL;
|
||||
f->y = NULL;
|
||||
val = &(f->constant_value);
|
||||
if (GPCP_GetValue (constant_name, val) != 0)
|
||||
*val = 0.0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
#include <stdio.h>
|
||||
#include "librockflight/include/state.h"
|
||||
|
||||
void print_function(function_t *f);
|
||||
|
||||
void print_summary(rocket_t *rocket, float *init_cond, solution_t *solution)
|
||||
{
|
||||
int i, j;
|
||||
double propellant_mass = 0.0;
|
||||
double rocket_mass = 0.0;
|
||||
|
||||
engine_t *e;
|
||||
|
||||
printf("---------------------------------------------\n");
|
||||
printf(" SOLUTION SUMMARY\n");
|
||||
printf("---------------------------------------------\n");
|
||||
printf("Solution duration : %.2f s\n", (*solution).duration);
|
||||
printf("Solution dt : %g \n", (*solution).dt);
|
||||
printf("Solution precision : %.2e \n", (*solution).precision);
|
||||
printf("\n");
|
||||
printf("Initial conditions.\n");
|
||||
printf("-------------------\n");
|
||||
printf(" u = %.2e m/s\n", init_cond[0]);
|
||||
printf(" v = %.2e m/s\n", init_cond[1]);
|
||||
printf(" w = %.2e m/s\n", init_cond[2]);
|
||||
printf(" P = %.2e rad/s\n", init_cond[3]);
|
||||
printf(" Q = %.2e rad/s\n", init_cond[4]);
|
||||
printf(" R = %.2e rad/s\n", init_cond[5]);
|
||||
printf(" longitude = %.2e deg\n", init_cond[6]);
|
||||
printf(" latitude = %.2e deg\n", init_cond[7]);
|
||||
printf(" altitude = %.2e m\n", init_cond[8]);
|
||||
printf(" phi = %.2e deg\n", init_cond[9]);
|
||||
printf(" theta = %.2e deg\n", init_cond[10]);
|
||||
printf(" psi = %.2e deg\n", init_cond[11]);
|
||||
printf("\n");
|
||||
printf("Rocket properties.\n");
|
||||
printf("------------------\n");
|
||||
printf(" Number of stages : %d\n", (*rocket).n_stage);
|
||||
|
||||
for (i = 0; i < (*rocket).n_stage; i++)
|
||||
{
|
||||
/* engines contribution */
|
||||
for (j = 0; j < (*rocket).stage_properties[i].n_engine; j++)
|
||||
{
|
||||
propellant_mass +=
|
||||
(*rocket).stage_properties[i].engines[j].propellant_mass;
|
||||
rocket_mass +=
|
||||
(*rocket).stage_properties[i].engines[j].dry_mass;
|
||||
}
|
||||
/* stage structure and payload */
|
||||
rocket_mass += (*rocket).stage_properties[i].dry_mass;
|
||||
}
|
||||
|
||||
printf(" Propellant mass : %.2e kg\n", propellant_mass);
|
||||
printf(" Rocket dry mass : %.2e kg\n", rocket_mass);
|
||||
printf(" Total mass : %.2e kg\n", propellant_mass + rocket_mass);
|
||||
printf("\n");
|
||||
printf(" Propellant mass fraction : %.2f %%\n",
|
||||
100*propellant_mass/(propellant_mass + rocket_mass));
|
||||
printf("\n");
|
||||
|
||||
printf("Stages properties.\n");
|
||||
printf("------------------\n");
|
||||
|
||||
for (i = 0; i < (*rocket).n_stage; i++)
|
||||
{
|
||||
printf(" Stage %d\n", i+1);
|
||||
printf(" |->Diameter : %.2e m\n",
|
||||
(*rocket).stage_properties[i].Diameter);
|
||||
printf(" |->Dry mass : %.2e kg\n",
|
||||
(*rocket).stage_properties[i].dry_mass);
|
||||
|
||||
print_function(&(*rocket).stage_properties[i].Ix);
|
||||
print_function(&(*rocket).stage_properties[i].Iy);
|
||||
print_function(&(*rocket).stage_properties[i].Iz);
|
||||
|
||||
printf(" |->Active time : %.2e s\n",
|
||||
(*rocket).stage_properties[i].active_time);
|
||||
|
||||
print_function(&(*rocket).stage_properties[i].Cd);
|
||||
print_function(&(*rocket).stage_properties[i].CL);
|
||||
print_function(&(*rocket).stage_properties[i].CB);
|
||||
|
||||
printf(" |->Cross spin coefficient : %.2e\n",
|
||||
(*rocket).stage_properties[i].Cspin);
|
||||
printf(" |->Moment coefficient : %.2e\n",
|
||||
(*rocket).stage_properties[i].Cmoment);
|
||||
printf(" |->Damping coefficient : %.2e\n",
|
||||
(*rocket).stage_properties[i].Cdamping);
|
||||
|
||||
printf(" |->Number of engines : %d\n",
|
||||
(*rocket).stage_properties[i].n_engine);
|
||||
for (j = 0; j < (*rocket).stage_properties[i].n_engine; j++)
|
||||
{
|
||||
e = (*rocket).stage_properties[i].engines + j;
|
||||
|
||||
printf(" |->Engine %d\n", j);
|
||||
printf(" |->Propellant mass : %.2e\n", e->propellant_mass);
|
||||
printf(" |->Dry mass : %.2e\n", e->dry_mass);
|
||||
printf(" |->Start time : %.2e\n", e->start_time);
|
||||
printf(" |->Burn time : %.2e\n", e->burn_time);
|
||||
printf(" |->Drop time : %.2e\n", e->drop_time);
|
||||
printf(" |->Position : (%.2e, %.2e, %.2e)\n",
|
||||
e->position[0], e->position[1], e->position[2]);
|
||||
printf(" |->Direction : (%.2e, %.2e, %.2e)\n",
|
||||
e->direction[0], e->direction[1], e->direction[2]);
|
||||
|
||||
print_function(&(e->thrust));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
printf("---------------------------------------------\n");
|
||||
printf(" END SUMMARY\n");
|
||||
printf("---------------------------------------------\n");
|
||||
}
|
||||
|
||||
|
||||
void print_function(function_t *f)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*printf(" |->%s type : ", f->name);*/
|
||||
|
||||
switch (f->type)
|
||||
{
|
||||
case _CONSTANT:
|
||||
/*printf("Constant\n");*/
|
||||
printf(" |->%s : %.2e\n",
|
||||
f->name, f->constant_value);
|
||||
break;
|
||||
break;
|
||||
|
||||
case _TABLE:
|
||||
printf(" |->%s : ", f->name);
|
||||
printf("Table (%d points) function of ", f->n_point);
|
||||
|
||||
switch (f->independant_var)
|
||||
{
|
||||
case TIME:
|
||||
printf("time.\n");
|
||||
break;
|
||||
case ALT:
|
||||
printf("altitude.\n");
|
||||
break;
|
||||
case MACH:
|
||||
printf("mach number.\n");
|
||||
break;
|
||||
case AOA:
|
||||
printf("angle of attack.\n");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < f->n_point; i++)
|
||||
{
|
||||
printf(" (%.2e, %.2e)\n",
|
||||
f->x[i], f->y[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
case _FUNCTION:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void print_octave_results(double *ans, const int neq, const int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("# Created by rocflight\n");
|
||||
printf("# name: M\n");
|
||||
printf("# type: matrix\n");
|
||||
printf("# rows: %d\n", n);/*(int)(duration/dt) + 1);*/
|
||||
printf("# columns: %d\n", neq + 1);
|
||||
|
||||
|
||||
for( i = 0; i < n; i++)
|
||||
{
|
||||
printf("% .12e ", ans[12 + (neq+1)*i]); /* t */
|
||||
printf("% .12e ", ans[0 + (neq+1)*i]); /* u */
|
||||
printf("% .12e ", ans[1 + (neq+1)*i]); /* v */
|
||||
printf("% .12e ", ans[2 + (neq+1)*i]); /* w */
|
||||
printf("% .12e ", ans[3 + (neq+1)*i]); /* p */
|
||||
printf("% .12e ", ans[4 + (neq+1)*i]); /* q */
|
||||
printf("% .12e ", ans[5 + (neq+1)*i]); /* r */
|
||||
printf("% .12e ", ans[6 + (neq+1)*i]); /* lambda */
|
||||
printf("% .12e ", ans[7 + (neq+1)*i]); /* mu */
|
||||
printf("% .12e ", ans[8 + (neq+1)*i]); /* R */
|
||||
printf("% .12e ", ans[9 + (neq+1)*i]); /* phi */
|
||||
printf("% .12e ", ans[10 + (neq+1)*i]); /* theta */
|
||||
printf("% .12e ", ans[11 + (neq+1)*i]); /* psi */
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libcompat/include/getopt.h"
|
||||
|
||||
#include "librockflight/include/state.h"
|
||||
#include "librockflight/include/rockflight.h"
|
||||
#include "libnum/include/num.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
void usage(void);
|
||||
extern void print_summary(rocket_t *rocket, float *init_cond,
|
||||
solution_t *solution);
|
||||
extern void print_octave_results(double *ans, int neq, int n);
|
||||
|
||||
int eom(int neq, double time, double *y, double *dy, void *data);
|
||||
int read_file(char *config_file, rocket_t *rocket, float *init_cond,
|
||||
solution_t *solution);
|
||||
extern int simulate(rocket_t *r, solution_t *s, float *ic, double **ans);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int n = 0, c;
|
||||
int neq = 12;
|
||||
|
||||
/* hold the rocket properties */
|
||||
rocket_t rocket;
|
||||
solution_t solution;
|
||||
double *ans;
|
||||
float *init_cond;
|
||||
|
||||
|
||||
int debug = 0;
|
||||
int check_only = 0;
|
||||
|
||||
int Lfileread = 0;
|
||||
char config_file[FILENAME_MAX];
|
||||
|
||||
/* allocate memory to hold initial conditions */
|
||||
init_cond = (float *) malloc(sizeof(float) * neq);
|
||||
|
||||
/* Read command line options */
|
||||
while (1)
|
||||
{
|
||||
c = getopt(argc, argv, "cdhf:");
|
||||
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
/* the input file */
|
||||
case 'f':
|
||||
if (strlen(optarg) > FILENAME_MAX)
|
||||
{
|
||||
printf("Filename too long!\n");
|
||||
break;
|
||||
}
|
||||
strncpy (config_file, optarg, FILENAME_MAX - 1);
|
||||
Lfileread = 1;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
check_only = 1;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
debug = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! (Lfileread))
|
||||
{
|
||||
printf("Error: A config file must be specified.\n");
|
||||
printf(" try rockflight -h for options.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
/* parse the configuration file */
|
||||
if ((read_file (config_file, &rocket, init_cond, &solution)) != 0)
|
||||
abort();
|
||||
|
||||
print_summary(&rocket, init_cond, &solution);
|
||||
|
||||
if (check_only)
|
||||
check(&rocket, 300.0, 1.0);
|
||||
else
|
||||
/* solve the model */
|
||||
n = simulate(&rocket, &solution, init_cond, &ans);
|
||||
|
||||
fprintf(stderr, "Memory used: %d kB\n", n*(neq+1)*sizeof(double)/1024);
|
||||
|
||||
print_octave_results(ans, neq, n);
|
||||
|
||||
free(init_cond);
|
||||
free(ans);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
printf("Usage:");
|
||||
printf("\n\trockflight -f infile [-o outfile] [-d]");
|
||||
printf("\n\trockflight -h");
|
||||
|
||||
printf("\n\nArguments:\n");
|
||||
printf("-f file \t Perform a simulation using file.\n");
|
||||
printf("-o file \t Results file, stdout if omitted\n");
|
||||
printf("-d \t Debug mode\n");
|
||||
printf("-h \t Print help\n\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "libnum/include/num.h"
|
||||
|
||||
#include "librockflight/include/state.h"
|
||||
#include "librockflight/include/rockflight.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
int eom(int neq, double time, double *y, double *dy, void *data);
|
||||
|
||||
int simulate(rocket_t *r, solution_t *sol, float *ic, double **ans)
|
||||
{
|
||||
|
||||
int n;
|
||||
|
||||
//double time;
|
||||
float init_cond[12];
|
||||
|
||||
int neq = 12;
|
||||
|
||||
/* s.A = M_PI*s.D*s.D/4;*/ /* reference area (m^2) */
|
||||
/* s.C = 1;*/ /* reference distance */
|
||||
|
||||
double u = ic[0];
|
||||
double v = ic[1];
|
||||
double w = ic[2];
|
||||
double P = ic[3];
|
||||
double Q = ic[4];
|
||||
double R = ic[5];
|
||||
double lambda = ic[6];
|
||||
double mu = ic[7];
|
||||
double Re = ic[8] + EARTH_RAD; /* convert altitude to distance
|
||||
from eartj center */
|
||||
double phi = ic[9];
|
||||
double theta = ic[10]*(M_PI/180); /* convert deg to rad
|
||||
(use convert instead) */
|
||||
double psi = ic[11];
|
||||
|
||||
|
||||
/* in kg */
|
||||
//r->state.m = 16.0;
|
||||
|
||||
//r->state.Ix = 0.0025;
|
||||
//r->state.Iy = 0.84;
|
||||
//r->state.Iz = 0.84;
|
||||
|
||||
/* aerodynamic coefficients */
|
||||
|
||||
//r->state.Cdrag = 0.2;
|
||||
//r->state.Clift = 2.3;
|
||||
//r->state.Cbeta = 2.3;
|
||||
//r->state.Cspin = 20.0;
|
||||
//r->state.Cmoment = 6.32;
|
||||
//r->state.Cdamping = 31.6;
|
||||
|
||||
//r->state.D = 0.1143;
|
||||
|
||||
r->state.Faero[0] = 0;
|
||||
r->state.Faero[1] = 0;
|
||||
r->state.Faero[2] = 0;
|
||||
r->state.Maero[0] = 0;
|
||||
r->state.Maero[1] = 0;
|
||||
r->state.Maero[2] = 0;
|
||||
|
||||
r->state.L_BV[0][0] = cos(theta)*cos(psi);
|
||||
r->state.L_BV[0][1] = cos(theta)*sin(psi);
|
||||
r->state.L_BV[0][2] =-sin(theta);
|
||||
r->state.L_BV[1][0] = sin(phi)*sin(theta)*cos(psi) - cos(phi)*sin(psi);
|
||||
r->state.L_BV[1][1] = sin(phi)*sin(theta)*sin(psi) + cos(phi)*cos(psi);
|
||||
r->state.L_BV[1][2] = sin(phi)*cos(theta);
|
||||
r->state.L_BV[2][0] = cos(phi)*sin(theta)*cos(psi) + sin(phi)*sin(psi);
|
||||
r->state.L_BV[2][1] = cos(phi)*sin(theta)*sin(psi) - sin(phi)*cos(psi);
|
||||
r->state.L_BV[2][2] = cos(phi)*cos(theta);
|
||||
|
||||
init_cond[0] = u; /* velocity component in x */
|
||||
init_cond[1] = v; /* velocity component in y */
|
||||
init_cond[2] = w; /* velocity component in z */
|
||||
init_cond[3] = P+ (r->state.L_BV[0][0]*WE*cos(lambda) -
|
||||
r->state.L_BV[0][2]*WE*sin(lambda));
|
||||
init_cond[4] = Q+ (r->state.L_BV[1][0]*WE*cos(lambda) -
|
||||
r->state.L_BV[1][2]*WE*sin(lambda));
|
||||
init_cond[5] = R+ (r->state.L_BV[2][0]*WE*cos(lambda) -
|
||||
r->state.L_BV[2][2]*WE*sin(lambda));
|
||||
init_cond[6] = lambda; /* latitude */
|
||||
init_cond[7] = mu; /* longitude */
|
||||
init_cond[8] = Re; /* radius */
|
||||
init_cond[9] = phi; /* phi */
|
||||
init_cond[10] = theta; /* theta */
|
||||
init_cond[11] = psi; /* psi */
|
||||
|
||||
//time = 0;
|
||||
|
||||
n = NUM_rkf (eom, neq, sol->dt, sol->duration, init_cond, ans,
|
||||
sol->precision, r);
|
||||
return n;
|
||||
}
|
||||
Reference in New Issue
Block a user