Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
b4842ecf
Commit
b4842ecf
authored
Jul 06, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed temporary file.
parent
d6f87998
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
179 deletions
+36
-179
modsim/ass4_taddeus/vibstring/Makefile
modsim/ass4_taddeus/vibstring/Makefile
+2
-2
modsim/ass4_taddeus/vibstring/seq.c
modsim/ass4_taddeus/vibstring/seq.c
+34
-20
modsim/ass4_taddeus/vibstring/seq2.c
modsim/ass4_taddeus/vibstring/seq2.c
+0
-157
No files found.
modsim/ass4_taddeus/vibstring/Makefile
View file @
b4842ecf
...
@@ -2,8 +2,8 @@ CC=gcc
...
@@ -2,8 +2,8 @@ CC=gcc
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-O0
-D_GNU_SOURCE
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-O0
-D_GNU_SOURCE
LDFLAGS
=
-lm
LDFLAGS
=
-lm
all
:
seq
2
all
:
seq
seq
2
:
seq2
.o
seq
:
seq
.o
clean
:
clean
:
rm
-vf
*
.o vibstring
rm
-vf
*
.o vibstring
modsim/ass4_taddeus/vibstring/seq.c
View file @
b4842ecf
...
@@ -51,11 +51,13 @@ void init_plucked(double **y, int steps, double l, double dx, double xp) {
...
@@ -51,11 +51,13 @@ void init_plucked(double **y, int steps, double l, double dx, double xp) {
#ifdef VERBOSE
#ifdef VERBOSE
#define PRINT_FORMAT "%e"
#define PRINT_FORMAT "%e"
void
print
(
double
**
y
,
int
time_step
,
int
t
,
int
string_steps
,
double
dx
)
{
void
print
(
double
*
y
,
int
string_steps
)
{
printf
(
"%d"
,
time_step
);
for
(
int
i
=
0
;
i
<
string_steps
;
i
++
)
{
if
(
i
)
printf
(
" "
);
for
(
int
i
=
0
;
i
<
string_steps
;
i
++
)
printf
(
PRINT_FORMAT
,
y
[
i
]);
printf
(
" "
PRINT_FORMAT
" "
PRINT_FORMAT
,
i
*
dx
,
y
[
t
][
i
]);
}
puts
(
""
);
puts
(
""
);
}
}
...
@@ -64,10 +66,10 @@ void print(double **y, int time_step, int t, int string_steps, double dx) {
...
@@ -64,10 +66,10 @@ void print(double **y, int time_step, int t, int string_steps, double dx) {
/*
/*
*
*
*/
*/
void
iterate
(
double
**
y
,
int
string_steps
,
double
dx
,
int
c
ount
,
int
stride
,
void
iterate
(
double
**
y
,
int
string_steps
,
double
dx
,
int
c
alc_steps
,
double
tau
)
{
int
print_resolution
,
double
tau
)
{
double
x
;
double
x
;
int
i
,
t
,
prev
=
0
,
current
=
1
,
next
=
2
,
time_steps
=
count
*
stride
;
int
i
,
t
,
prev
=
0
,
current
=
1
,
next
=
2
;
// Calculate the position over the entire string at time dt using the
// Calculate the position over the entire string at time dt using the
// position at t = 0 and the information that y(x, -dt) == y(x, dt)
// position at t = 0 and the information that y(x, -dt) == y(x, dt)
...
@@ -78,23 +80,33 @@ void iterate(double **y, int string_steps, double dx, int count, int stride,
...
@@ -78,23 +80,33 @@ void iterate(double **y, int string_steps, double dx, int count, int stride,
}
}
#ifdef VERBOSE
#ifdef VERBOSE
// Print x values (which are the same for every y-series)
for
(
i
=
0
;
i
<
string_steps
;
i
++
)
{
if
(
i
)
printf
(
" "
);
printf
(
PRINT_FORMAT
,
i
*
dx
);
}
puts
(
""
);
// Print init states
// Print init states
print
(
y
,
0
,
0
,
string_steps
,
dx
);
print
(
y
[
prev
],
string_steps
);
if
(
stride
==
1
)
if
(
print_resolution
==
1
)
print
(
y
,
1
,
1
,
string_steps
,
dx
);
print
(
y
[
current
],
string_steps
);
#endif
#endif
// Iterate over the length of the string for each time interval step
// Iterate over the length of the string for each time interval step
for
(
t
=
2
;
t
<
time
_steps
;
t
++
)
{
for
(
t
=
2
;
t
<
calc
_steps
;
t
++
)
{
for
(
i
=
1
;
i
<
string_steps
-
1
;
i
++
)
{
for
(
i
=
1
;
i
<
string_steps
-
1
;
i
++
)
{
y
[
next
][
i
]
=
2
*
y
[
current
][
i
]
-
y
[
prev
][
i
]
+
tau
*
tau
y
[
next
][
i
]
=
2
*
y
[
current
][
i
]
-
y
[
prev
][
i
]
+
tau
*
tau
*
(
y
[
current
][
i
-
1
]
-
2
*
y
[
current
][
i
]
+
y
[
current
][
i
+
1
]);
*
(
y
[
current
][
i
-
1
]
-
2
*
y
[
current
][
i
]
+
y
[
current
][
i
+
1
]);
}
}
#ifdef VERBOSE
#ifdef VERBOSE
if
(
!
(
t
%
stride
)
)
if
(
!
(
t
%
print_resolution
)
)
print
(
y
,
t
,
next
,
string_steps
,
dx
);
print
(
y
[
next
],
string_steps
);
#endif
#endif
prev
=
current
;
prev
=
current
;
...
@@ -104,12 +116,13 @@ void iterate(double **y, int string_steps, double dx, int count, int stride,
...
@@ -104,12 +116,13 @@ void iterate(double **y, int string_steps, double dx, int count, int stride,
}
}
int
main
(
int
argc
,
const
char
**
argv
)
{
int
main
(
int
argc
,
const
char
**
argv
)
{
int
steps
,
i
,
count
,
stride
;
int
x_steps
,
calc_steps
,
i
,
print_resolution
;
void
(
*
init_method
)(
double
**
,
int
,
double
,
double
,
double
);
void
(
*
init_method
)(
double
**
,
int
,
double
,
double
,
double
);
double
**
y
,
l
,
dx
,
tau
,
constant
;
double
**
y
,
l
,
dx
,
tau
,
constant
;
if
(
argc
<
8
)
{
if
(
argc
<
8
)
{
printf
(
"Usage: %s INIT_METHOD COUNT STRIDE LENGTH DX TAU N|XP
\n
"
,
argv
[
0
]);
printf
(
"Usage: %s INIT_METHOD CALCULATION_STEPS PRINT_RESOLUTION LENGTH"
" DX TAU N|XP
\n
"
,
argv
[
0
]);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
...
@@ -122,16 +135,17 @@ int main(int argc, const char **argv) {
...
@@ -122,16 +135,17 @@ int main(int argc, const char **argv) {
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
c
ount
=
atoi
(
argv
[
2
]);
c
alc_steps
=
atoi
(
argv
[
2
]);
stride
=
atoi
(
argv
[
3
]);
print_resolution
=
atoi
(
argv
[
3
]);
l
=
atof
(
argv
[
4
]);
l
=
atof
(
argv
[
4
]);
dx
=
atof
(
argv
[
5
]);
dx
=
atof
(
argv
[
5
]);
tau
=
atof
(
argv
[
6
]);
tau
=
atof
(
argv
[
6
]);
constant
=
atof
(
argv
[
7
]);
constant
=
atof
(
argv
[
7
]);
y
=
create_y
(
steps
=
(
int
)
ceil
(
l
/
dx
));
x_steps
=
(
int
)
ceil
(
l
/
dx
);
(
*
init_method
)(
y
,
steps
,
l
,
dx
,
constant
);
y
=
create_y
(
x_steps
);
iterate
(
y
,
steps
,
dx
,
count
,
stride
,
tau
);
(
*
init_method
)(
y
,
x_steps
,
l
,
dx
,
constant
);
iterate
(
y
,
x_steps
,
dx
,
calc_steps
,
print_resolution
,
tau
);
// Free allocated memory
// Free allocated memory
for
(
i
=
0
;
i
<
3
;
i
++
)
for
(
i
=
0
;
i
<
3
;
i
++
)
...
...
modsim/ass4_taddeus/vibstring/seq2.c
deleted
100644 → 0
View file @
d6f87998
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
double
**
create_y
(
int
steps
)
{
double
**
y
=
(
double
**
)
malloc
(
3
*
sizeof
(
double
*
));
int
i
;
if
(
y
==
NULL
)
{
puts
(
"Error: could not allocate memory."
);
exit
(
EXIT_FAILURE
);
}
for
(
i
=
0
;
i
<
3
;
i
++
)
y
[
i
]
=
(
double
*
)
malloc
(
steps
*
sizeof
(
double
));
return
y
;
}
/*
*
*/
void
init_sinus
(
double
**
y
,
int
steps
,
double
l
,
double
dx
,
double
n
)
{
for
(
int
i
=
0
;
i
<
steps
;
i
++
)
y
[
0
][
i
]
=
sin
(
n
*
M_PI
*
i
*
dx
/
l
);
// The string is attached at both ends
y
[
2
][
0
]
=
y
[
1
][
0
]
=
y
[
0
][
0
];
y
[
2
][
steps
-
1
]
=
y
[
1
][
steps
-
1
]
=
y
[
0
][
steps
-
1
];
}
/*
*
*/
void
init_plucked
(
double
**
y
,
int
steps
,
double
l
,
double
dx
,
double
xp
)
{
double
x
;
for
(
int
i
=
0
;
i
<
steps
;
i
++
)
{
x
=
i
*
dx
;
y
[
0
][
i
]
=
x
<
xp
?
x
/
xp
:
(
l
-
x
)
/
(
l
-
xp
);
}
// The string is attached at both ends
y
[
2
][
0
]
=
y
[
1
][
0
]
=
y
[
0
][
0
];
y
[
2
][
steps
-
1
]
=
y
[
1
][
steps
-
1
]
=
y
[
0
][
steps
-
1
];
}
#define VERBOSE
#ifdef VERBOSE
#define PRINT_FORMAT "%e"
void
print
(
double
*
y
,
int
string_steps
)
{
for
(
int
i
=
0
;
i
<
string_steps
;
i
++
)
{
if
(
i
)
printf
(
" "
);
printf
(
PRINT_FORMAT
,
y
[
i
]);
}
puts
(
""
);
}
#endif
/*
*
*/
void
iterate
(
double
**
y
,
int
string_steps
,
double
dx
,
int
calc_steps
,
int
print_resolution
,
double
tau
)
{
double
x
;
int
i
,
t
,
prev
=
0
,
current
=
1
,
next
=
2
;
// Calculate the position over the entire string at time dt using the
// position at t = 0 and the information that y(x, -dt) == y(x, dt)
for
(
i
=
1
;
i
<
string_steps
-
1
;
i
++
)
{
x
=
i
*
dx
;
y
[
1
][
i
]
=
y
[
0
][
i
]
+
.
5
*
tau
*
tau
*
(
y
[
0
][
i
-
1
]
-
2
*
y
[
0
][
i
]
+
y
[
0
][
i
+
1
]);
}
#ifdef VERBOSE
// Print x values (which are the same for every y-series)
for
(
i
=
0
;
i
<
string_steps
;
i
++
)
{
if
(
i
)
printf
(
" "
);
printf
(
PRINT_FORMAT
,
i
*
dx
);
}
puts
(
""
);
// Print init states
print
(
y
[
prev
],
string_steps
);
if
(
print_resolution
==
1
)
print
(
y
[
current
],
string_steps
);
#endif
// Iterate over the length of the string for each time interval step
for
(
t
=
2
;
t
<
calc_steps
;
t
++
)
{
for
(
i
=
1
;
i
<
string_steps
-
1
;
i
++
)
{
y
[
next
][
i
]
=
2
*
y
[
current
][
i
]
-
y
[
prev
][
i
]
+
tau
*
tau
*
(
y
[
current
][
i
-
1
]
-
2
*
y
[
current
][
i
]
+
y
[
current
][
i
+
1
]);
}
#ifdef VERBOSE
if
(
!
(
t
%
print_resolution
)
)
print
(
y
[
next
],
string_steps
);
#endif
prev
=
current
;
current
=
next
;
next
=
(
next
+
1
)
%
3
;
}
}
int
main
(
int
argc
,
const
char
**
argv
)
{
int
x_steps
,
calc_steps
,
i
,
print_resolution
;
void
(
*
init_method
)(
double
**
,
int
,
double
,
double
,
double
);
double
**
y
,
l
,
dx
,
tau
,
constant
;
if
(
argc
<
8
)
{
printf
(
"Usage: %s INIT_METHOD CALCULATION_STEPS PRINT_RESOLUTION LENGTH"
" DX TAU N|XP
\n
"
,
argv
[
0
]);
return
EXIT_FAILURE
;
}
if
(
!
strcmp
(
argv
[
1
],
"sinus"
)
)
{
init_method
=
init_sinus
;
}
else
if
(
!
strcmp
(
argv
[
1
],
"plucked"
)
)
{
init_method
=
init_plucked
;
}
else
{
printf
(
"Unknown initialization method '%s'.
\n
"
,
argv
[
1
]);
return
EXIT_FAILURE
;
}
calc_steps
=
atoi
(
argv
[
2
]);
print_resolution
=
atoi
(
argv
[
3
]);
l
=
atof
(
argv
[
4
]);
dx
=
atof
(
argv
[
5
]);
tau
=
atof
(
argv
[
6
]);
constant
=
atof
(
argv
[
7
]);
x_steps
=
(
int
)
ceil
(
l
/
dx
);
y
=
create_y
(
x_steps
);
(
*
init_method
)(
y
,
x_steps
,
l
,
dx
,
constant
);
iterate
(
y
,
x_steps
,
dx
,
calc_steps
,
print_resolution
,
tau
);
// Free allocated memory
for
(
i
=
0
;
i
<
3
;
i
++
)
free
(
y
[
i
]);
free
(
y
);
return
EXIT_SUCCESS
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment