Commit 2ea1c77f authored by Taddeüs Kroes's avatar Taddeüs Kroes

ModSim ass4 taddeus: Worked on sequential program.

parent 36d87e81
......@@ -4,19 +4,19 @@ from pylab import figure, plot, subplot, show, savefig, legend
from time import sleep
# Collect data
data = {}
t = []
y = []
for line in stdin.readlines():
s = line.split(' ')
data[float(s[0])] = [map(float, s[1::2]), map(float, s[2::2])]
t.append(float(s[0]))
y.append((map(float, s[1::2]), map(float, s[2::2])))
# Plot and optionally save data
figure(len(data))
i = 1
for t in data:
subplot(2, 5, i)
plot(data[t][0], data[t][1], 'x-', label='t = %.3f' % t)
figure(len(t))
for i in range(len(t)):
subplot(2, 5, i + 1)
plot(y[i][0], y[i][1], 'x-', label='t = %.3f' % t[i])
#legend()
i += 1
if len(argv) == 2:
savefig(argv[1])
show()
......@@ -8,7 +8,7 @@ double **create_y(int steps) {
int i;
if( y == NULL ) {
puts("Error: could not allocate sufficient memory.");
puts("Error: could not allocate memory.");
exit(EXIT_FAILURE);
}
......@@ -49,6 +49,9 @@ void init_plucked(double **y, int steps, double l, double dx, double xp) {
#define VERBOSE
#define PRINT_FORMAT "%e"
/*
*
*/
void iterate(double **y, int string_steps, double dx, int time_steps, double dt,
double theta) {
double x;
......@@ -74,7 +77,7 @@ void iterate(double **y, int string_steps, double dx, int time_steps, double dt,
}
#endif
// Iterate over the length of the string
// Iterate over the length of the string for each time interval step
for( t = 2; t < time_steps; t++ ) {
#ifdef VERBOSE
printf(PRINT_FORMAT " " PRINT_FORMAT " " PRINT_FORMAT, t * dt, .0,
......@@ -99,21 +102,15 @@ void iterate(double **y, int string_steps, double dx, int time_steps, double dt,
current = next;
next = (next + 1) % 3;
}
// Free allocated memory
for( i = 0; i < string_steps; i++ )
free(y[i]);
free(y);
}
int main(int argc, const char **argv) {
int steps;
int steps, i;
void (*init_method)(double **, int, double, double, double);
double **y, t, dt, l, dx, theta, constant;
if( argc < 8 ) {
printf("Usage: %s METHOD TIME DT LENGTH DX THETA N|XP\n", argv[0]);
printf("Usage: %s INIT_METHOD TIME DT LENGTH DX THETA N|XP\n", argv[0]);
return EXIT_FAILURE;
}
......@@ -134,9 +131,14 @@ int main(int argc, const char **argv) {
constant = atof(argv[7]);
y = create_y(steps = (int)ceil(l / dx));
(*init_method)(y, steps, l, dx, constant);
iterate(y, steps, dx, (int)ceil(t / dt), dt, theta);
// Free allocated memory
for( i = 0; i < steps; i++ )
free(y[i]);
free(y);
return EXIT_SUCCESS;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment