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
c9fce26c
Commit
c9fce26c
authored
May 24, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ModSim ass4 taddeus: Source code cleanup.
parent
2ea1c77f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
43 deletions
+42
-43
modsim/ass4_taddeus/vibstring/seq.c
modsim/ass4_taddeus/vibstring/seq.c
+42
-43
No files found.
modsim/ass4_taddeus/vibstring/seq.c
View file @
c9fce26c
...
...
@@ -4,7 +4,7 @@
#include <math.h>
double
**
create_y
(
int
steps
)
{
double
**
y
=
(
double
**
)
malloc
(
steps
*
sizeof
(
double
*
));
double
**
y
=
(
double
**
)
malloc
(
3
*
sizeof
(
double
*
));
int
i
;
if
(
y
==
NULL
)
{
...
...
@@ -12,8 +12,8 @@ double **create_y(int steps) {
exit
(
EXIT_FAILURE
);
}
for
(
i
=
0
;
i
<
steps
;
i
++
)
y
[
i
]
=
(
double
*
)
malloc
(
3
*
sizeof
(
double
));
for
(
i
=
0
;
i
<
3
;
i
++
)
y
[
i
]
=
(
double
*
)
malloc
(
steps
*
sizeof
(
double
));
return
y
;
}
...
...
@@ -23,11 +23,11 @@ double **create_y(int steps) {
*/
void
init_sinus
(
double
**
y
,
int
steps
,
double
l
,
double
dx
,
double
n
)
{
for
(
int
i
=
0
;
i
<
steps
;
i
++
)
y
[
i
][
0
]
=
sin
(
n
*
M_PI
*
i
*
dx
/
l
);
y
[
0
][
i
]
=
sin
(
n
*
M_PI
*
i
*
dx
/
l
);
// The string is attached at both ends
y
[
0
][
2
]
=
y
[
0
][
1
]
=
y
[
0
][
0
];
y
[
steps
-
1
][
2
]
=
y
[
steps
-
1
][
1
]
=
y
[
steps
-
1
][
0
];
y
[
2
][
0
]
=
y
[
1
][
0
]
=
y
[
0
][
0
];
y
[
2
][
steps
-
1
]
=
y
[
1
][
steps
-
1
]
=
y
[
0
][
steps
-
1
];
}
/*
...
...
@@ -38,64 +38,63 @@ void init_plucked(double **y, int steps, double l, double dx, double xp) {
for
(
int
i
=
0
;
i
<
steps
;
i
++
)
{
x
=
i
*
dx
;
y
[
i
][
0
]
=
x
<
xp
?
x
/
xp
:
(
l
-
x
)
/
(
l
-
xp
);
y
[
0
][
i
]
=
x
<
xp
?
x
/
xp
:
(
l
-
x
)
/
(
l
-
xp
);
}
// The string is attached at both ends
y
[
0
][
2
]
=
y
[
0
][
1
]
=
y
[
0
][
0
];
y
[
steps
-
1
][
2
]
=
y
[
steps
-
1
][
1
]
=
y
[
steps
-
1
][
0
];
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
time_step
,
int
t
,
int
string_steps
,
double
dx
)
{
printf
(
"%d"
,
time_step
);
for
(
int
i
=
0
;
i
<
string_steps
;
i
++
)
printf
(
" "
PRINT_FORMAT
" "
PRINT_FORMAT
,
i
*
dx
,
y
[
t
][
i
]);
puts
(
""
);
}
#endif
/*
*
*/
void
iterate
(
double
**
y
,
int
string_steps
,
double
dx
,
int
time_steps
,
double
dt
,
double
t
heta
)
{
void
iterate
(
double
**
y
,
int
string_steps
,
double
dx
,
int
count
,
int
stride
,
double
t
au
)
{
double
x
;
int
i
,
t
,
prev
=
0
,
current
=
1
,
next
=
2
;
int
i
,
t
,
prev
=
0
,
current
=
1
,
next
=
2
,
time_steps
=
count
*
stride
;
// 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
[
i
][
1
]
=
y
[
i
][
0
]
+
.
5
*
theta
*
theta
*
(
y
[
i
-
1
][
0
]
-
2
*
y
[
i
][
0
]
+
y
[
i
+
1
][
0
]);
y
[
1
][
i
]
=
y
[
0
][
i
]
+
.
5
*
tau
*
tau
*
(
y
[
0
][
i
-
1
]
-
2
*
y
[
0
][
i
]
+
y
[
0
][
i
+
1
]);
}
// Print init states
#ifdef VERBOSE
for
(
t
=
0
;
t
<
2
;
t
++
)
{
printf
(
PRINT_FORMAT
,
t
*
dt
);
for
(
i
=
0
;
i
<
string_steps
;
i
++
)
printf
(
" "
PRINT_FORMAT
" "
PRINT_FORMAT
,
i
*
dx
,
y
[
i
][
t
]);
// Print init states
print
(
y
,
0
,
0
,
string_steps
,
dx
);
puts
(
""
);
}
if
(
stride
==
1
)
print
(
y
,
1
,
1
,
string_steps
,
dx
);
#endif
// 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
,
y
[
0
][
next
]);
#endif
for
(
i
=
1
;
i
<
string_steps
-
1
;
i
++
)
{
y
[
i
][
next
]
=
2
*
y
[
i
][
current
]
-
y
[
i
][
prev
]
+
theta
*
theta
*
(
y
[
i
-
1
][
current
]
-
2
*
y
[
i
][
current
]
+
y
[
i
+
1
][
current
]);
#ifdef VERBOSE
printf
(
" "
PRINT_FORMAT
" "
PRINT_FORMAT
,
i
*
dx
,
y
[
i
][
next
]);
#endif
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
printf
(
" "
PRINT_FORMAT
" "
PRINT_FORMAT
"
\n
"
,
(
string_steps
-
1
)
*
dx
,
y
[
string_steps
-
1
][
next
]
);
if
(
!
(
t
%
stride
)
)
print
(
y
,
t
,
next
,
string_steps
,
dx
);
#endif
prev
=
current
;
...
...
@@ -105,12 +104,12 @@ void iterate(double **y, int string_steps, double dx, int time_steps, double dt,
}
int
main
(
int
argc
,
const
char
**
argv
)
{
int
steps
,
i
;
int
steps
,
i
,
count
,
stride
;
void
(
*
init_method
)(
double
**
,
int
,
double
,
double
,
double
);
double
**
y
,
t
,
dt
,
l
,
dx
,
theta
,
constant
;
double
**
y
,
l
,
dx
,
tau
,
constant
;
if
(
argc
<
8
)
{
printf
(
"Usage: %s INIT_METHOD
TIME DT LENGTH DX THETA
N|XP
\n
"
,
argv
[
0
]);
printf
(
"Usage: %s INIT_METHOD
COUNT STRIDE LENGTH DX TAU
N|XP
\n
"
,
argv
[
0
]);
return
EXIT_FAILURE
;
}
...
...
@@ -123,19 +122,19 @@ int main(int argc, const char **argv) {
return
EXIT_FAILURE
;
}
t
=
atof
(
argv
[
2
]);
dt
=
atof
(
argv
[
3
]);
count
=
atoi
(
argv
[
2
]);
stride
=
atoi
(
argv
[
3
]);
l
=
atof
(
argv
[
4
]);
dx
=
atof
(
argv
[
5
]);
t
heta
=
atof
(
argv
[
6
]);
t
au
=
atof
(
argv
[
6
]);
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
);
iterate
(
y
,
steps
,
dx
,
count
,
stride
,
tau
);
// Free allocated memory
for
(
i
=
0
;
i
<
steps
;
i
++
)
for
(
i
=
0
;
i
<
3
;
i
++
)
free
(
y
[
i
]);
free
(
y
);
...
...
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