Initial commit of "Rocket Workbench".

Taken from sources in CVS at:
    https://sourceforge.net/projects/rocketworkbench/

Sources extracted in two steps:
1. Pull entire project tree into a subdir "rwb" via "rsync":
    rsync -a a.cvs.sourceforge.net::cvsroot/rocketworkbench/ rwb/.
2. Export sources:
    export CVSROOT=$(pwd)/rwb
    SUBDIRS="analyser cpropep cpropep-web CVSROOT data libcompat libcpropep libnum libsimulation libthermo prop rocketworkbench rockflight"
    mkdir rwbx; cd rwbx
    cvs export -D now ${SUBDIRS}

After this (and some backups for safety), the directory content was
added to a Git repo:
    git init .
    git add *
This commit is contained in:
R. J. Dev. Kwan
2021-01-20 15:50:36 -08:00
commit eb05416991
411 changed files with 362300 additions and 0 deletions
@@ -0,0 +1,3 @@
ROOT = ../../../..
include $(ROOT)/config/makedef
include $(ROOT)/config/libsrc.mk
@@ -0,0 +1,242 @@
/* derivative.c - Fill the mattrix to compute thermochemical derivative
relative to logarithm of pressure and temperature */
/* $Id: derivative.c,v 1.1.1.1 2001/07/20 03:19:01 antoine Exp $ */
/* Copyright (C) 2000 */
/* Antoine Lefebvre <antoine.lefebvre@polymtl.ca> */
/* Mark Pinese <pinese@cyberwizards.com.au> */
/* */
/* Licensed under the GPLv2 */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "libnum/include/num.h"
#include "libcpropep/include/derivative.h"
#include "libcpropep/include/equilibrium.h"
#include "libcpropep/include/performance.h"
#include "libcpropep/include/print.h"
#include "libcpropep/include/return.h"
#include "libcompat/include/compat.h"
#include "libthermo/include/thermo.h"
int fill_temperature_derivative_matrix(double *matrix, equilibrium_t *e);
int fill_pressure_derivative_matrix(double *matrix, equilibrium_t *e);
/* Compute the specific_heat of the mixture using thermodynamics
derivative with respect to logarithm of temperature */
double mixture_specific_heat(equilibrium_t *e, double *sol)
{
short i, j;
double cp, tmp;
product_t *p = &(e->product);
equilib_prop_t *pr = &(e->properties);
cp = 0.0;
/* Compute Cp/R */
for (i = 0; i < p->n_element; i++)
{
tmp = 0.0;
for (j = 0; j < p->n[GAS]; j++)
tmp += p->A[i][j] * p->coef[GAS][j] *
enthalpy_0(p->species[GAS][j], pr->T);
cp += tmp * sol[i];
}
for (i = 0; i < p->n[CONDENSED]; i++)
{
cp += enthalpy_0(p->species[CONDENSED][i], pr->T)
* sol[i + p->n_element];
}
tmp = 0.0;
for (i = 0; i < p->n[GAS]; i++)
{
tmp += p->coef[GAS][i] * enthalpy_0(p->species[GAS][i], pr->T);
}
cp += tmp * sol[p->n_element + p->n[CONDENSED]];
cp += mixture_specific_heat_0(e, pr->T);
for (i = 0; i < p->n[GAS]; i++)
{
cp += p->coef[GAS][i] * pow(enthalpy_0(p->species[GAS][i], pr->T), 2);
}
return cp;
}
int derivative(equilibrium_t *e)
{
short size;
double *matrix;
double *sol;
product_t *p = &(e->product);
equilib_prop_t *prop = &(e->properties);
/* the size of the coefficient matrix */
size = p->n_element + p->n[CONDENSED] + 1;
matrix = (double *) malloc (size * (size + 1) * sizeof(double));
/* allocate the memory for the solution vector */
sol = (double *) calloc (size, sizeof(double));
fill_temperature_derivative_matrix(matrix, e);
if (NUM_lu(matrix, sol, size) == -1)
{
fprintf(outputfile, "The matrix is singular.\n");
}
else
{
if (global_verbose > 2)
{
fprintf(outputfile, "Temperature derivative results.\n");
NUM_print_vec(sol, size);
}
prop->Cp = mixture_specific_heat(e, sol)*R;
prop->dV_T = 1 + sol[e->product.n_element + e->product.n[CONDENSED]];
}
fill_pressure_derivative_matrix(matrix, e);
if (NUM_lu(matrix, sol, size) == -1)
{
fprintf(outputfile, "The matrix is singular.\n");
}
else
{
if (global_verbose > 2)
{
fprintf(outputfile, "Pressure derivative results.\n");
NUM_print_vec(sol, size);
}
prop->dV_P = sol[e->product.n_element + e->product.n[CONDENSED]] - 1;
}
prop->Cv = prop->Cp + e->itn.n * R * pow(prop->dV_T, 2)/prop->dV_P;
prop->Isex = -(prop->Cp / prop->Cv) / prop->dV_P;
prop->Vson = sqrt(1000 * e->itn.n * R * e->properties.T * prop->Isex);
free(matrix);
free(sol);
return 0;
}
/* Fill the matrix with the coefficient for evaluating derivatives with
respect to logarithm of temperature at constant pressure */
int fill_temperature_derivative_matrix(double *matrix, equilibrium_t *e)
{
short j, k, size;
double tmp;
short idx_cond, idx_n, idx_T;
product_t *p = &(e->product);
equilib_prop_t *pr = &(e->properties);
idx_cond = p->n_element;
idx_n = p->n_element + p->n[CONDENSED];
idx_T = p->n_element + p->n[CONDENSED] + 1;
/* the size of the coefficient matrix */
size = p->n_element + p->n[CONDENSED] + 1;
/* fill the common part */
fill_matrix(matrix, e, TP);
/* del ln(n)/ del ln(T) */
matrix[idx_n + size * idx_n] = 0.0;
/* right side */
for (j = 0; j < p->n_element; j++)
{
tmp = 0.0;
for (k = 0; k < p->n[GAS]; k++)
tmp -= p->A[j][k] * p->coef[GAS][k] * enthalpy_0(p->species[GAS][k],
pr->T);
matrix[j + size * idx_T] = tmp;
}
for (j = 0; j < p->n[CONDENSED]; j++) /* row */
matrix[j + idx_cond + size * idx_T] =
-enthalpy_0( p->species[CONDENSED][j], pr->T);
tmp = 0.0;
for (k = 0; k < p->n[GAS]; k++)
tmp -= p->coef[GAS][k]*enthalpy_0(p->species[GAS][k], pr->T);
matrix[idx_n + size * idx_T] = tmp;
return 0;
}
/* Fill the matrix with the coefficient for evaluating derivatives with
respect to logarithm of pressure at constant temperature */
int fill_pressure_derivative_matrix(double *matrix, equilibrium_t *e)
{
short j, k, size;
double tmp;
short idx_cond, idx_n, idx_T;
product_t *p = &(e->product);
idx_cond = p->n_element;
idx_n = p->n_element + p->n[CONDENSED];
idx_T = p->n_element + p->n[CONDENSED] + 1;
/* the size of the coefficient matrix */
size = p->n_element + p->n[CONDENSED] + 1;
/* fill the common part */
fill_matrix(matrix, e, TP);
/* del ln(n)/ del ln(T) */
matrix[idx_n + size * idx_n] = 0.0;
/* right side */
for (j = 0; j < p->n_element; j++)
{
tmp = 0.0;
for (k = 0; k < p->n[GAS]; k++)
tmp += p->A[j][k] * p->coef[GAS][k];
matrix[j + size * idx_T] = tmp;
}
for (j = 0; j < p->n[CONDENSED]; j++) /* row */
matrix[j + idx_cond + size * idx_T] = 0.0;
tmp = 0.0;
for (k = 0; k < p->n[GAS]; k++)
tmp += p->coef[GAS][k];
matrix[idx_n + size * idx_T] = tmp;
return 0;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,2 @@
LIBNAME = libcpropep.a
LIBOBJS = equilibrium.o print.o performance.o derivative.o
@@ -0,0 +1,564 @@
/* performance.c - Compute performance caracteristic of a motor
considering equilibrium */
/* $Id: performance.c,v 1.3 2001/10/08 03:22:01 antoine Exp $ */
/* Copyright (C) 2000 */
/* Antoine Lefebvre <antoine.lefebvre@polymtl.ca> */
/* Mark Pinese <pinese@cyberwizards.com.au> */
/* */
/* Licensed under the GPLv2 */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "libcpropep/include/performance.h"
#include "libcpropep/include/derivative.h"
#include "libcpropep/include/print.h"
#include "libcpropep/include/equilibrium.h"
#include "libcpropep/include/const.h"
#include "libcpropep/include/return.h"
#include "libcompat/include/compat.h"
#include "libthermo/include/thermo.h"
#define TEMP_ITERATION_MAX 8
#define PC_PT_ITERATION_MAX 5
#define PC_PE_ITERATION_MAX 6
double compute_temperature(equilibrium_t *e, double pressure,
double p_entropy);
/* Entropy of the product at the exit pressure and temperature */
double product_entropy_exit(equilibrium_t *e, double pressure, double temp)
{
double ent;
double t = e->properties.T;
double p = e->properties.P;
e->properties.T = temp;
e->properties.P = pressure;
ent = product_entropy(e); /* entropy at the new pressure */
e->properties.T = t;
e->properties.P = p;
return ent;
}
/* Enthalpy of the product at the exit temperature */
double product_enthalpy_exit(equilibrium_t *e, double temp)
{
double enth;
double t = e->properties.T;
e->properties.T = temp;
enth = product_enthalpy(e);
e->properties.T = t;
return enth;
}
/* The temperature could be found by entropy conservation with a
specified pressure */
double compute_temperature(equilibrium_t *e, double pressure, double p_entropy)
{
int i = 0;
double delta_lnt;
double temperature;
/* The first approximation is the chamber temperature */
temperature = e->properties.T;
do
{
delta_lnt = (p_entropy - product_entropy_exit(e, pressure, temperature))
/ mixture_specific_heat_0(e, temperature);
temperature = exp (log(temperature) + delta_lnt);
i++;
} while (fabs(delta_lnt) >= 0.5e-4 && i < TEMP_ITERATION_MAX);
if (i == TEMP_ITERATION_MAX)
{
fprintf(errorfile,
"Temperature do not converge in %d iterations. Don't thrust results.\n",
TEMP_ITERATION_MAX);
}
return temperature;
}
int frozen_performance(equilibrium_t *e, exit_condition_t exit_type,
double value)
{
int err_code;
short i;
double sound_velocity;
double flow_velocity;
double pc_pt; /* Chamber pressure / Throat pressure */
double pc_pe; /* Chamber pressure / Exit pressure */
double log_pc_pe; /* log(pc_pe) */
double ae_at; /* Exit aera / Throat aera */
double cp_cv;
double chamber_entropy;
double exit_pressure = 0;
equilibrium_t *t = e + 1; /* throat equilibrium */
equilibrium_t *ex = e + 2; /* exit equilibrium */
/* find the equilibrium composition in the chamber */
if (!(e->product.isequil))
{
if ((err_code = equilibrium(e, HP)) != SUCCESS)
{
fprintf(outputfile,
"No equilibrium, performance evaluation aborted.\n");
return err_code;
}
}
/* Simplification due to frozen equilibrium */
e->properties.dV_T = 1.0;
e->properties.dV_P = -1.0;
e->properties.Cp = mixture_specific_heat_0(e, e->properties.T) * R;
e->properties.Cv = e->properties.Cp - e->itn.n * R;
e->properties.Isex = e->properties.Cp/e->properties.Cv;
compute_thermo_properties(e);
chamber_entropy = product_entropy(e);
/* begin computation of throat caracteristic */
copy_equilibrium(t, e);
cp_cv = e->properties.Cp/e->properties.Cv;
/* first estimate of Pc/Pt */
pc_pt = pow (cp_cv/2 + 0.5, cp_cv/(cp_cv - 1));
i = 0;
do
{
t->properties.T = compute_temperature(t, e->properties.P/pc_pt,
chamber_entropy);
/* Cp of the combustion point assuming frozen */
t->properties.Cp = mixture_specific_heat_0(e, t->properties.T) * R;
/* Cv = Cp - nR (for frozen) */
t->properties.Cv = t->properties.Cp - t->itn.n * R;
t->properties.Isex = t->properties.Cp/t->properties.Cv;
compute_thermo_properties(t);
sound_velocity = sqrt(1000 * e->itn.n * R * t->properties.T *
t->properties.Isex);
flow_velocity = sqrt(2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy_exit(e, t->properties.T)*
R*t->properties.T));
pc_pt = pc_pt / ( 1 + ((pow(flow_velocity, 2) - pow(sound_velocity, 2))
/(1000*(t->properties.Isex + 1)*
t->itn.n * R *t->properties.T)));
i++;
} while ((fabs((pow(flow_velocity, 2) - pow(sound_velocity, 2))
/pow(flow_velocity, 2)) > 0.4e-4) &&
(i < PC_PT_ITERATION_MAX));
if (i == PC_PT_ITERATION_MAX)
{
fprintf(errorfile,
"Throat pressure do not converge in %d iterations. Don't thrust results\n",
PC_PT_ITERATION_MAX);
}
/*printf("%d iterations to evaluate throat pressure.\n", i);*/
t->properties.P = e->properties.P/pc_pt;
t->performance.Isp = t->properties.Vson = sound_velocity;
compute_thermo_properties(t);
/* Now compute exit properties */
copy_equilibrium(ex, e);
if (exit_type == PRESSURE)
{
exit_pressure = value;
}
else
{
ae_at = value;
/* Initial estimate of pressure ratio */
if (exit_type == SUPERSONIC_AREA_RATIO)
{
if ((ae_at > 1.0) && (ae_at < 2.0))
{
log_pc_pe = log(pc_pt) + sqrt (3.294*pow(ae_at,2) + 1.535*log(ae_at));
}
else if (ae_at >= 2.0)
{
log_pc_pe = t->properties.Isex + 1.4 * log(ae_at);
}
else
{
printf("Aera ratio out of range ( < 1.0 )\n");
return ERR_AERA_RATIO;
}
}
else if (exit_type == SUBSONIC_AREA_RATIO)
{
if ((ae_at > 1.0) && (ae_at < 1.09))
{
log_pc_pe = 0.9 * log(pc_pt) /
(ae_at + 10.587 * pow(log(ae_at), 3) + 9.454 * log(ae_at));
}
else if (ae_at >= 1.09)
{
log_pc_pe = log(pc_pt) /
(ae_at + 10.587 * pow(log(ae_at), 3) + 9.454 * log(ae_at));
}
else
{
printf("Aera ratio out of range ( < 1.0 )\n");
return ERR_AERA_RATIO;
}
}
else
{
return ERR_RATIO_TYPE;
}
/* Improved the estimate */
i = 0;
do
{
pc_pe = exp(log_pc_pe);
ex->properties.P = exit_pressure = e->properties.P/pc_pe;
ex->properties.T = compute_temperature(e, exit_pressure,
chamber_entropy);
/* Cp of the combustion point assuming frozen */
ex->properties.Cp = mixture_specific_heat_0(e, ex->properties.T) * R;
/* Cv = Cp - nR (for frozen) */
ex->properties.Cv = ex->properties.Cp - ex->itn.n * R;
ex->properties.Isex = ex->properties.Cp/ex->properties.Cv;
compute_thermo_properties(ex);
sound_velocity = sqrt(1000 * ex->itn.n * R * ex->properties.T *
ex->properties.Isex);
ex->performance.Isp =
flow_velocity = sqrt(2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy_exit(e, ex->properties.T)*
R*ex->properties.T));
ex->performance.ae_at =
(ex->properties.T * t->properties.P * t->performance.Isp) /
(t->properties.T * ex->properties.P * ex->performance.Isp);
log_pc_pe = log_pc_pe +
(ex->properties.Isex*pow(flow_velocity, 2)/
(pow(flow_velocity, 2) - pow(sound_velocity,2))) *
(log(ae_at) - log(ex->performance.ae_at));
i++;
} while ( (fabs((log_pc_pe - log(pc_pe))) > 0.00004) &&
(i < PC_PE_ITERATION_MAX) );
if (i == PC_PE_ITERATION_MAX)
{
fprintf(errorfile,
"Exit pressure do not converge in %d iterations. Don't thrust results\n",
PC_PE_ITERATION_MAX);
}
/*printf("%d iterations to evaluate exit pressure.\n", i); */
pc_pe = exp(log_pc_pe);
exit_pressure = e->properties.P/pc_pe;
}
ex->properties.T = compute_temperature(e, exit_pressure,
chamber_entropy);
/* We must check if the exit temperature is more than 50 K lower
than any transition temperature of condensed species.
In this case the results are not good and must be reject. */
ex->properties.P = exit_pressure;
ex->performance.Isp = sqrt(2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy_exit(e, ex->properties.T)*
R*ex->properties.T));
/* units are (m/s/atm) */
ex->performance.a_dotm = 1000 * R * ex->properties.T * ex->itn.n /
(ex->properties.P * ex->performance.Isp);
/* Cp of the combustion point assuming frozen */
ex->properties.Cp = mixture_specific_heat_0(e, ex->properties.T) * R;
/* Cv = Cp - nR (for frozen) */
ex->properties.Cv = ex->properties.Cp - ex->itn.n * R;
ex->properties.Isex = ex->properties.Cp/ex->properties.Cv;
compute_thermo_properties(ex);
ex->properties.Vson = sqrt(1000 * e->itn.n * R * ex->properties.T *
e->properties.Isex);
t->performance.a_dotm = 1000 * R * t->properties.T
* t->itn.n / (t->properties.P * t->performance.Isp);
t->performance.ae_at = 1.0;
t->performance.cstar = e->properties.P * t->performance.a_dotm;
t->performance.cf = t->performance.Isp /
(e->properties.P * t->performance.a_dotm);
t->performance.Ivac = t->performance.Isp + t->properties.P
* t->performance.a_dotm;
ex->performance.ae_at =
(ex->properties.T * t->properties.P * t->performance.Isp) /
(t->properties.T * ex->properties.P * ex->performance.Isp);
ex->performance.cstar = e->properties.P * t->performance.a_dotm;
ex->performance.cf = ex->performance.Isp /
(e->properties.P * t->performance.a_dotm);
ex->performance.Ivac = ex->performance.Isp + ex->properties.P
* ex->performance.a_dotm;
return SUCCESS;
}
int shifting_performance(equilibrium_t *e, exit_condition_t exit_type,
double value)
{
int err_code;
short i;
double sound_velocity = 0.0;
double flow_velocity;
double pc_pt;
double pc_pe;
double log_pc_pe;
double ae_at;
double chamber_entropy;
double exit_pressure = 0;
equilibrium_t *t = e + 1; /* throat equilibrium */
equilibrium_t *ex = e + 2; /* exit equilibrium */
/* find the equilibrium composition in the chamber */
if (!(e->product.isequil))
/* if the equilibrium have not already been compute */
{
if ((err_code = equilibrium(e, HP)) < 0)
{
fprintf(outputfile, "No equilibrium, performance evaluation aborted.\n");
return err_code;
}
}
/* Begin by first aproximate the new equilibrium to be
the same as the chamber equilibrium */
copy_equilibrium(t, e);
chamber_entropy = product_entropy(e);
/* Computing throat condition */
/* Approximation of the throat pressure */
pc_pt = pow(t->properties.Isex/2 + 0.5,
t->properties.Isex/(t->properties.Isex - 1) );
t->entropy = chamber_entropy;
i = 0;
do
{
t->properties.P = e->properties.P/pc_pt;
/* We must compute the new equilibrium each time */
if ((err_code = equilibrium(t, SP)) < 0)
{
fprintf(outputfile, "No equilibrium, performance evaluation aborted.\n");
return err_code;
}
sound_velocity = sqrt (1000*t->itn.n*R*t->properties.T*
t->properties.Isex);
flow_velocity = sqrt (2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy(t)*R*t->properties.T));
pc_pt = pc_pt / ( 1 + ((pow(flow_velocity, 2) - pow(sound_velocity, 2))
/(1000*(t->properties.Isex + 1)*t->itn.n*R*
t->properties.T)));
i++;
} while ((fabs((pow(flow_velocity, 2) - pow(sound_velocity, 2))
/pow(flow_velocity, 2)) > 0.4e-4) &&
(i < PC_PT_ITERATION_MAX));
if (i == PC_PT_ITERATION_MAX)
{
fprintf(errorfile, "Throat pressure do not converge in %d iterations."
" Don't thrust results.\n", PC_PT_ITERATION_MAX);
}
/*printf("%d iterations to evaluate throat pressure.\n", i);*/
t->properties.P = e->properties.P/pc_pt;
t->properties.Vson = sound_velocity;
t->performance.Isp = sound_velocity;
t->performance.a_dotm = 1000 * R *
t->properties.T * t->itn.n /
(t->properties.P * t->performance.Isp);
copy_equilibrium(ex, e);
if (exit_type == PRESSURE)
{
exit_pressure = value;
}
else
{
ae_at = value;
/* Initial estimate of pressure ratio */
if (exit_type == SUPERSONIC_AREA_RATIO)
{
if ((ae_at > 1.0) && (ae_at < 2.0))
{
log_pc_pe = log(pc_pt) + sqrt (3.294*pow(ae_at,2) + 1.535*log(ae_at));
}
else if (ae_at >= 2.0)
{
log_pc_pe = t->properties.Isex + 1.4 * log(ae_at);
}
else
{
printf("Aera ratio out of range ( < 1.0 )\n");
return ERR_AERA_RATIO;
}
}
else if (exit_type == SUBSONIC_AREA_RATIO)
{
if ((ae_at > 1.0) && (ae_at < 1.09))
{
log_pc_pe = 0.9 * log(pc_pt) /
(ae_at + 10.587 * pow(log(ae_at), 3) + 9.454 * log(ae_at));
}
else if (ae_at >= 1.09)
{
log_pc_pe = log(pc_pt) /
(ae_at + 10.587 * pow(log(ae_at), 3) + 9.454 * log(ae_at));
}
else
{
printf("Aera ratio out of range ( < 1.0 )\n");
return ERR_AERA_RATIO;
}
}
else
{
return ERR_RATIO_TYPE;
}
/* Improved the estimate */
ex->entropy = chamber_entropy;
i = 0;
do
{
pc_pe = exp(log_pc_pe);
ex->properties.P = exit_pressure = e->properties.P/pc_pe;
/* Find the exit equilibrium */
if ((err_code = equilibrium(ex, SP)) < 0)
{
fprintf(outputfile,
"No equilibrium, performance evaluation aborted.\n");
return err_code;
}
sound_velocity = ex->properties.Vson;
ex->performance.Isp =
flow_velocity = sqrt(2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy(ex)*R*ex->properties.T));
ex->performance.ae_at =
(ex->properties.T * t->properties.P * t->performance.Isp) /
(t->properties.T * ex->properties.P * ex->performance.Isp);
log_pc_pe = log_pc_pe +
(ex->properties.Isex*pow(flow_velocity, 2)/
(pow(flow_velocity, 2) - pow(sound_velocity,2))) *
(log(ae_at) - log(ex->performance.ae_at));
i++;
} while ((fabs((log_pc_pe - log(pc_pe))) > 0.00004) &&
(i < PC_PE_ITERATION_MAX));
if (i == PC_PE_ITERATION_MAX)
{
fprintf(errorfile, "Exit pressure do not converge in %d iteration."
" Don't thrust results.\n", PC_PE_ITERATION_MAX);
}
/*printf("%d iterations to evaluate exit pressure.\n", i);*/
pc_pe = exp(log_pc_pe);
exit_pressure = e->properties.P/pc_pe;
}
ex->entropy = chamber_entropy;
ex->properties.P = exit_pressure;
/* Find the exit equilibrium */
if ((err_code = equilibrium(ex, SP)) < 0)
{
fprintf(outputfile, "No equilibrium, performance evaluation aborted.\n");
return err_code;
}
flow_velocity = sqrt(2000*(product_enthalpy(e)*R*e->properties.T -
product_enthalpy(ex)*R*ex->properties.T));
ex->performance.Isp = flow_velocity;
ex->performance.a_dotm = 1000 * R *
ex->properties.T * ex->itn.n /
(ex->properties.P * ex->performance.Isp);
t->performance.ae_at = 1.0;
t->performance.cstar = e->properties.P * t->performance.a_dotm;
t->performance.cf = t->performance.Isp /
(e->properties.P * t->performance.a_dotm);
t->performance.Ivac = t->performance.Isp + t->properties.P
* t->performance.a_dotm;
ex->performance.ae_at =
(ex->properties.T * t->properties.P * t->performance.Isp) /
(t->properties.T * ex->properties.P * ex->performance.Isp);
ex->performance.cstar = e->properties.P * t->performance.a_dotm;
ex->performance.cf = ex->performance.Isp /
(e->properties.P * t->performance.a_dotm);
ex->performance.Ivac = ex->performance.Isp + ex->properties.P
* ex->performance.a_dotm;
return SUCCESS;
}
@@ -0,0 +1,428 @@
/* print.c - Output functions */
/* $Id: print.c,v 1.1.1.1 2001/07/20 03:19:05 antoine Exp $ */
/* Copyright (C) 2000 */
/* Antoine Lefebvre <antoine.lefebvre@polymtl.ca> */
/* Mark Pinese <pinese@cyberwizards.com.au> */
/* */
/* Licensed under the GPLv2 */
#include <stdio.h>
#include "libcpropep/include/print.h"
#include "libcpropep/include/performance.h"
#include "libcpropep/include/equilibrium.h"
#include "libcpropep/include/conversion.h"
#include "libcpropep/include/const.h"
#include "libthermo/include/thermo.h"
char header[][32] = {
"CHAMBER",
"THROAT",
"EXIT" };
char err_message[][64] = {
"Error allocating memory",
"Error opening file",
"Error EOF",
"Error memory not allocated",
"Error too much product",
"Error in equilibrium",
"Error bad aera ratio",
"Error bad aera ratio type"};
FILE * errorfile;
FILE * outputfile;
int print_error_message(int error_code)
{
fprintf(errorfile, "%s\n", err_message[-error_code - 1]);
return 0;
}
int print_propellant_info(int sp)
{
int j;
if (sp > num_propellant || sp < 0)
return -1;
fprintf(outputfile, "Code %-35s Enthalpy Density Composition\n", "Name");
fprintf(outputfile, "%d %-35s % .4f % .2f", sp,
(propellant_list + sp)->name,
(propellant_list + sp)->heat,
(propellant_list + sp)->density);
fprintf(outputfile, " ");
/* print the composition */
for (j = 0; j < 6; j++)
{
if (!((propellant_list + sp)->coef[j] == 0))
fprintf(outputfile, "%d%s ", (propellant_list + sp)->coef[j],
symb[ (propellant_list + sp)->elem[j] ]);
}
fprintf(outputfile, "\n");
return 0;
}
int print_thermo_info(int sp)
{
int i, j;
thermo_t *s;
if (sp > num_thermo || sp < 0)
return -1;
s = (thermo_list + sp);
fprintf(outputfile, "---------------------------------------------\n");
fprintf(outputfile, "Name: \t\t\t%s\n", s->name);
fprintf(outputfile, "Comments: \t\t%s\n", s->comments);
fprintf(outputfile, "Id: \t\t\t%s\n", s->id);
fprintf(outputfile, "Chemical formula:\t");
for (i = 0; i < 5; i++)
{
if (!(s->coef[i] == 0))
fprintf(outputfile, "%d%s", s->coef[i], symb[ s->elem[i]]);
}
fprintf(outputfile, "\n");
fprintf(outputfile, "State:\t\t\t");
switch (s->state)
{
case GAS:
fprintf(outputfile, "GAZ\n");
break;
case CONDENSED:
fprintf(outputfile, "CONDENSED\n");
break;
default:
printf("UNRECOGNIZE\n");
}
fprintf(outputfile, "\n");
fprintf(outputfile, "Molecular weight: \t\t% f g/mol\n", s->weight);
fprintf(outputfile, "Heat of formation at 298.15 K : % f J/mol\n", s->heat);
fprintf(outputfile, "Assign enthalpy : % f J/mol\n", s->enth);
fprintf(outputfile, "HO(298.15) - HO(0): \t\t% f J/mol\n", s->dho);
fprintf(outputfile, "Number of temperature range: % d\n\n", s->nint);
for (i = 0; i < s->nint; i++)
{
fprintf(outputfile, "Interval: %f - %f \n", s->range[i][0],
s->range[i][1]);
for (j = 0; j < 9; j++)
fprintf(outputfile, "% .9e ", s->param[i][j]);
fprintf(outputfile, "\n\n");
}
fprintf(outputfile, "---------------------------------------------\n");
return 0;
}
int print_thermo_list(void)
{
int i;
for (i = 0; i < num_thermo; i++)
fprintf(outputfile, "%-4d %-15s % .2f\n", i, (thermo_list + i)->name,
(thermo_list + i)->heat);
return 0;
}
int print_propellant_list(void)
{
int i;
for (i = 0; i < num_propellant; i++)
fprintf(outputfile, "%-4d %-30s %5f\n", i, (propellant_list + i)->name,
(propellant_list +i)->heat);
return 0;
}
int print_condensed(product_t p)
{
int i;
for (i = 0; i < p.n[CONDENSED]; i ++)
fprintf(outputfile, "%s ",
(thermo_list + p.species[CONDENSED][i])->name );
fprintf(outputfile, "\n");
return 0;
}
int print_gazeous(product_t p)
{
int i;
for (i = 0; i < p.n[GAS]; i++)
fprintf(outputfile, "%s ", (thermo_list + p.species[GAS][i])->name);
fprintf(outputfile, "\n");
return 0;
}
int print_product_composition(equilibrium_t *e, short npt)
{
int i, j, k;
double mol_g = e->itn.n;
/* we have to build a list of all condensed species present
in the three equilibrium */
int n = 0;
int condensed_list[MAX_PRODUCT];
/* ok become false if the species already exist in the list */
int ok = 1;
double qt;
for (i = 0; i < e->product.n[CONDENSED]; i++)
mol_g += e->product.coef[CONDENSED][i];
fprintf(outputfile, "\nMolar fractions\n\n");
for (i = 0; i < e->product.n[GAS]; i++)
{
if (e->product.coef[GAS][i]/e->itn.n > 0.0)
{
fprintf(outputfile, "%-20s",
(thermo_list + e->product.species[GAS][i])->name);
for (j = 0; j < npt; j++)
fprintf(outputfile, " %11.4e", (e+j)->product.coef[GAS][i]/mol_g);
fprintf(outputfile,"\n");
}
}
/* build the list of condensed */
for (i = 0; i < npt; i++)
{
for (j = 0; j < (e+i)->product.n[CONDENSED]; j++)
{
for (k = 0; k < n; k++)
{
/* check if the condensed are to be include in the list */
if (condensed_list[k] == (e+i)->product.species[CONDENSED][j])
{
/* we do not have to include the species */
ok = 0;
break;
}
} /* k */
if (ok)
{
condensed_list[n] = (e+i)->product.species[CONDENSED][j];
n++;
}
/* reset the flag */
ok = 1;
} /* j */
} /* i */
if (n > 0)
{
fprintf(outputfile, "Condensed species\n");
for (i = 0; i < n; i++)
{
fprintf(outputfile, "%-20s",
(thermo_list + condensed_list[i])->name);
for (j = 0; j < npt; j++)
{
/* search in the product of each equilibrium if the
condensed is present */
qt = 0.0;
for (k = 0; k < (e+j)->product.n[CONDENSED]; k++)
{
if (condensed_list[i] == (e+j)->product.species[CONDENSED][k])
{
qt = (e+j)->product.coef[CONDENSED][k];
break;
}
}
fprintf(outputfile, " %11.4e", qt/mol_g);
}
fprintf(outputfile,"\n");
}
}
fprintf(outputfile, "\n");
return 0;
}
int print_propellant_composition(equilibrium_t *e)
{
int i, j;
fprintf(outputfile, "Propellant composition\n");
fprintf(outputfile, "Code %-35s mol Mass (g) Composition\n", "Name");
for (i = 0; i < e->propellant.ncomp; i++)
{
fprintf(outputfile, "%-4d %-35s %.4f %.4f ", e->propellant.molecule[i],
PROPELLANT_NAME(e->propellant.molecule[i]), e->propellant.coef[i],
e->propellant.coef[i] *
propellant_molar_mass(e->propellant.molecule[i]));
fprintf(outputfile, " ");
/* print the composition */
for (j = 0; j < 6; j++)
{
if (!((propellant_list + e->propellant.molecule[i])->coef[j] == 0))
fprintf(outputfile, "%d%s ",
(propellant_list + e->propellant.molecule[i])->coef[j],
symb[(propellant_list + e->propellant.molecule[i])->elem[j]]);
}
fprintf(outputfile, "\n");
}
fprintf(outputfile, "Density : % .3f g/cm^3\n", e->propellant.density);
if (e->product.element_listed)
{
fprintf(outputfile, "%d different elements\n", e->product.n_element);
/* Print those elements */
for (i = 0; i < e->product.n_element; i++)
fprintf(outputfile, "%s ", symb[e->product.element[i]] );
fprintf(outputfile, "\n");
}
fprintf(outputfile, "Total mass: % f g\n", propellant_mass(e));
fprintf(outputfile, "Enthalpy : % .2f kJ/kg\n",
propellant_enthalpy(e));
fprintf(outputfile, "\n");
if (e->product.product_listed)
{
fprintf(outputfile, "%d possible gazeous species\n", e->product.n[GAS]);
if (global_verbose > 1)
print_gazeous(e->product);
fprintf(outputfile, "%d possible condensed species\n\n",
e->product.n_condensed);
if (global_verbose > 1)
print_condensed(e->product);
}
return 0;
}
int print_performance_information (equilibrium_t *e, short npt)
{
short i;
fprintf(outputfile, "Ae/At : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.ae_at);
fprintf(outputfile, "\n");
fprintf(outputfile, "A/dotm (m/s/atm) : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.a_dotm);
fprintf(outputfile, "\n");
fprintf(outputfile, "C* (m/s) : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.cstar);
fprintf(outputfile, "\n");
fprintf(outputfile, "Cf : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.cf);
fprintf(outputfile, "\n");
fprintf(outputfile, "Ivac (m/s) : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.Ivac);
fprintf(outputfile, "\n");
fprintf(outputfile, "Isp (m/s) : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.Isp);
fprintf(outputfile, "\n");
fprintf(outputfile, "Isp/g (s) : ");
for (i = 1; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->performance.Isp/Ge);
fprintf(outputfile, "\n");
return 0;
}
int print_product_properties(equilibrium_t *e, short npt)
{
short i;
fprintf(outputfile, " ");
for (i = 0; i < npt; i++)
fprintf(outputfile, " %11s", header[i]);
fprintf(outputfile, "\n");
fprintf(outputfile, "Pressure (atm) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.P);
fprintf(outputfile, "\n");
fprintf(outputfile, "Temperature (K) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.T);
fprintf(outputfile, "\n");
fprintf(outputfile, "H (kJ/kg) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.H);
fprintf(outputfile, "\n");
fprintf(outputfile, "U (kJ/kg) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.U);
fprintf(outputfile, "\n");
fprintf(outputfile, "G (kJ/kg) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.G);
fprintf(outputfile, "\n");
fprintf(outputfile, "S (kJ/(kg)(K) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.S);
fprintf(outputfile, "\n");
fprintf(outputfile, "M (g/mol) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.3f", (e+i)->properties.M);
fprintf(outputfile, "\n");
fprintf(outputfile, "(dLnV/dLnP)t :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.dV_P);
fprintf(outputfile, "\n");
fprintf(outputfile, "(dLnV/dLnT)p :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.dV_T);
fprintf(outputfile, "\n");
fprintf(outputfile, "Cp (kJ/(kg)(K)) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.Cp);
fprintf(outputfile, "\n");
fprintf(outputfile, "Cv (kJ/(kg)(K)) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.Cv);
fprintf(outputfile, "\n");
fprintf(outputfile, "Cp/Cv :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.Cp/(e+i)->properties.Cv);
fprintf(outputfile, "\n");
fprintf(outputfile, "Gamma :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.Isex);
fprintf(outputfile, "\n");
fprintf(outputfile, "Vson (m/s) :");
for (i = 0; i < npt; i++)
fprintf(outputfile, " % 11.5f", (e+i)->properties.Vson);
fprintf(outputfile, "\n");
fprintf(outputfile, "\n");
return 0;
}