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,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