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
36d87e81
Commit
36d87e81
authored
May 19, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ModSim ass4 taddeus: Added plot file, source cleanup.
parent
3b74dfeb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
42 deletions
+48
-42
modsim/ass4_taddeus/vibstring/plot.py
modsim/ass4_taddeus/vibstring/plot.py
+22
-0
modsim/ass4_taddeus/vibstring/seq.c
modsim/ass4_taddeus/vibstring/seq.c
+26
-42
No files found.
modsim/ass4_taddeus/vibstring/plot.py
0 → 100755
View file @
36d87e81
#!/usr/bin/env python
from
sys
import
argv
,
stdin
from
pylab
import
figure
,
plot
,
subplot
,
show
,
savefig
,
legend
from
time
import
sleep
# Collect data
data
=
{}
for
line
in
stdin
.
readlines
():
s
=
line
.
split
(
' '
)
data
[
float
(
s
[
0
])]
=
[
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
)
#legend()
i
+=
1
if
len
(
argv
)
==
2
:
savefig
(
argv
[
1
])
show
()
modsim/ass4_taddeus/vibstring/seq.c
View file @
36d87e81
...
@@ -46,16 +46,11 @@ void init_plucked(double **y, int steps, double l, double dx, double xp) {
...
@@ -46,16 +46,11 @@ void init_plucked(double **y, int steps, double l, double dx, double xp) {
y
[
steps
-
1
][
2
]
=
y
[
steps
-
1
][
1
]
=
y
[
steps
-
1
][
0
];
y
[
steps
-
1
][
2
]
=
y
[
steps
-
1
][
1
]
=
y
[
steps
-
1
][
0
];
}
}
#define DEBUG
#define VERBOSE
#define PRINT_FORMAT "%e"
#ifdef DEBUG
void
iterate
(
double
**
y
,
int
string_steps
,
double
dx
,
int
time_steps
,
double
dt
,
#define PRINT_FORMAT "%10f" // More readable print format (outlined)
double
theta
)
{
#else
#define PRINT_FORMAT "%f" // Raw data, aplittable by space character
#endif
void
iterate
(
double
**
y
,
int
string_steps
,
double
dx
,
int
time_steps
,
double
dt
,
double
theta
,
int
verbose_level
)
{
double
x
;
double
x
;
int
i
,
t
,
prev
=
0
,
current
=
1
,
next
=
2
;
int
i
,
t
,
prev
=
0
,
current
=
1
,
next
=
2
;
...
@@ -68,32 +63,37 @@ void iterate(double **y, int string_steps, double dx, int time_steps,
...
@@ -68,32 +63,37 @@ void iterate(double **y, int string_steps, double dx, int time_steps,
}
}
// Print init states
// Print init states
if
(
verbose_level
)
{
#ifdef VERBOSE
for
(
t
=
0
;
t
<
2
;
t
++
)
{
for
(
t
=
0
;
t
<
2
;
t
++
)
{
printf
(
PRINT_FORMAT
,
t
*
dt
);
printf
(
PRINT_FORMAT
,
t
*
dt
);
for
(
i
=
0
;
i
<
string_steps
;
i
++
)
for
(
i
=
0
;
i
<
string_steps
;
i
++
)
printf
(
" "
PRINT_FORMAT
,
y
[
i
][
t
]);
printf
(
" "
PRINT_FORMAT
" "
PRINT_FORMAT
,
i
*
dx
,
y
[
i
][
t
]);
puts
(
""
);
puts
(
""
);
}
}
}
#endif
// Iterate over the length of the string
// Iterate over the length of the string
for
(
t
=
0
;
t
<
time_steps
;
t
++
)
{
for
(
t
=
2
;
t
<
time_steps
;
t
++
)
{
if
(
verbose_level
)
#ifdef VERBOSE
printf
(
PRINT_FORMAT
" "
PRINT_FORMAT
,
t
*
dt
,
y
[
0
][
next
]);
printf
(
PRINT_FORMAT
" "
PRINT_FORMAT
" "
PRINT_FORMAT
,
t
*
dt
,
.
0
,
y
[
0
][
next
]);
#endif
for
(
i
=
1
;
i
<
string_steps
-
1
;
i
++
)
{
for
(
i
=
1
;
i
<
string_steps
-
1
;
i
++
)
{
y
[
i
][
next
]
=
2
*
y
[
i
][
current
]
-
y
[
i
][
prev
]
+
theta
*
theta
y
[
i
][
next
]
=
2
*
y
[
i
][
current
]
-
y
[
i
][
prev
]
+
theta
*
theta
*
(
y
[
i
-
1
][
current
]
-
2
*
y
[
i
][
current
]
+
y
[
i
+
1
][
current
]);
*
(
y
[
i
-
1
][
current
]
-
2
*
y
[
i
][
current
]
+
y
[
i
+
1
][
current
]);
if
(
verbose_level
)
#ifdef VERBOSE
printf
(
" "
PRINT_FORMAT
,
y
[
i
][
next
]);
printf
(
" "
PRINT_FORMAT
" "
PRINT_FORMAT
,
i
*
dx
,
y
[
i
][
next
]);
#endif
}
}
if
(
verbose_level
)
#ifdef VERBOSE
printf
(
" "
PRINT_FORMAT
"
\n
"
,
y
[
string_steps
-
1
][
next
]);
printf
(
" "
PRINT_FORMAT
" "
PRINT_FORMAT
"
\n
"
,
(
string_steps
-
1
)
*
dx
,
y
[
string_steps
-
1
][
next
]);
#endif
prev
=
current
;
prev
=
current
;
current
=
next
;
current
=
next
;
...
@@ -108,25 +108,12 @@ void iterate(double **y, int string_steps, double dx, int time_steps,
...
@@ -108,25 +108,12 @@ void iterate(double **y, int string_steps, double dx, int time_steps,
}
}
int
main
(
int
argc
,
const
char
**
argv
)
{
int
main
(
int
argc
,
const
char
**
argv
)
{
int
steps
,
verbose_level
=
1
;
int
steps
;
void
(
*
init_method
)(
double
**
,
int
,
double
,
double
,
double
);
void
(
*
init_method
)(
double
**
,
int
,
double
,
double
,
double
);
double
**
y
,
t
,
dt
,
l
,
dx
,
theta
,
constant
;
double
**
y
,
t
,
dt
,
l
,
dx
,
theta
,
constant
;
/*
* Argv:
* 0: ./seq
* 1: sinus/plucked
* 2: t
* 3: dt
* 4: l
* 5: dx
* 6: theta
* 7: n/xp (init constant)
* 8: verbose level
*/
if
(
argc
<
8
)
{
if
(
argc
<
8
)
{
printf
(
"Usage: %s METHOD TIME DT LENGTH DX THETA N|XP [ VERBOSE_LEVEL ]
\n
"
,
printf
(
"Usage: %s METHOD TIME DT LENGTH DX THETA N|XP
\n
"
,
argv
[
0
]);
argv
[
0
]);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
...
@@ -146,13 +133,10 @@ int main(int argc, const char **argv) {
...
@@ -146,13 +133,10 @@ int main(int argc, const char **argv) {
theta
=
atof
(
argv
[
6
]);
theta
=
atof
(
argv
[
6
]);
constant
=
atof
(
argv
[
7
]);
constant
=
atof
(
argv
[
7
]);
if
(
argc
==
9
)
verbose_level
=
atoi
(
argv
[
8
]);
y
=
create_y
(
steps
=
(
int
)
ceil
(
l
/
dx
));
y
=
create_y
(
steps
=
(
int
)
ceil
(
l
/
dx
));
(
*
init_method
)(
y
,
steps
,
l
,
dx
,
constant
);
(
*
init_method
)(
y
,
steps
,
l
,
dx
,
constant
);
iterate
(
y
,
steps
,
dx
,
(
int
)
ceil
(
t
/
dt
),
dt
,
theta
,
verbose_level
);
iterate
(
y
,
steps
,
dx
,
(
int
)
ceil
(
t
/
dt
),
dt
,
theta
);
return
EXIT_SUCCESS
;
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