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
d5bfd07b
Commit
d5bfd07b
authored
Jul 10, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://vo20.nl/home/git/repos/uva
parents
2ed3ac6e
03a8c9e4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
46 deletions
+93
-46
modsim/ass4_sander/part1/start.sh
modsim/ass4_sander/part1/start.sh
+1
-1
modsim/ass4_sander/part2/Makefile
modsim/ass4_sander/part2/Makefile
+1
-1
modsim/ass4_sander/part2/main.c
modsim/ass4_sander/part2/main.c
+79
-43
modsim/ass4_sander/part2/plot.py
modsim/ass4_sander/part2/plot.py
+12
-1
No files found.
modsim/ass4_sander/part1/start.sh
View file @
d5bfd07b
#!/bin/sh
NUM_PROCESSES
=
4
HOSTS
=
ow130,ow131
HOSTS
=
deleuze,localhost
PROGRAM_EXEC
=
main
mpirun
-np
$NUM_PROCESSES
-H
$HOSTS
$PROGRAM_EXEC
modsim/ass4_sander/part2/Makefile
View file @
d5bfd07b
CFLAGS
+=
-std
=
c99
-Wall
-Wextra
-
g
-O2
-pthread
CFLAGS
+=
-std
=
c99
-Wall
-Wextra
-
pedantic
-g
-O2
-pthread
-D_GNU_SOURCE
LDFLAGS
+=
-pthread
-lmpi
-lopen-rte
-lopen-pal
-ldl
-Wl
,--export-dynamic
\
-lnsl
-lutil
-lm
-ldl
...
...
modsim/ass4_sander/part2/main.c
View file @
d5bfd07b
...
...
@@ -2,84 +2,120 @@
#include <stdlib.h>
#include <stdio.h>
#define
GRID_LENGTH 64
#define
STRING_PARTS len
double
Y
[
GRID_LENGTH
][
3
];
int
STRING_PARTS
;
double
*
Y
;
int
t_next
,
t_prev
,
t_cur
;
void
init_sinus
(
char
**
argv
)
{
double
amp
;
int
h_phases
;
/*
* Macros used to manipulate the allocated memory for Y.
*/
#define GET_Y(i, t) \
Y[i + t * STRING_PARTS]
sscanf
(
argv
[
2
],
"%lf"
,
&
amp
);
sscanf
(
argv
[
3
],
"%i"
,
&
h_phases
);
for
(
int
i
=
0
;
i
<
GRID_LENGTH
;
i
++
)
{
Y
[
i
][
t
]
=
amp
*
sin
(
M_PI
*
(
i
(
double
)
/
(
double
)
GRID_LENGTH
)
*
h_phases
);
}
}
#define SET_Y(i, t, val) \
Y[i + t * STRING_PARTS] = val
void
init_pluck
(
char
**
argv
)
{
double
amp
,
position
;
int
ipos
,
i
;
/*
* Fill the allocated memory for Y with a sinus shape.
*/
static
void
init_sinus
(
int
phases
)
{
double
c
=
(
double
)
(
STRING_PARTS
*
phases
)
*
M_PI
;
sscanf
(
argv
[
2
],
"%lf"
,
&
amp
);
sscanf
(
argv
[
3
],
"%i"
,
&
position
);
for
(
int
i
=
0
;
i
<
STRING_PARTS
;
i
++
)
{
SET_Y
(
i
,
0
,
sin
(((
double
)
i
)
/
c
));
}
}
ipos
=
position
/
dx
*
GRID_LENGTH
;
/*
* Fill the allocated memory for Y with a pluck shape.
*/
static
void
init_pluck
(
double
pluck
,
double
length
,
double
dx
)
{
int
ipos
=
((
int
)
dx
)
+
1
,
i
;
fprintf
(
stderr
,
"ipos: %d
\n
"
,
ipos
);
for
(
i
=
0
;
i
<
ipos
;
i
++
)
{
Y
[
i
][
t
]
=
i
*
dx
/
position
*
amp
;
SET_Y
(
i
,
0
,
i
*
dx
/
pluck
)
;
}
for
(;
i
<
GRID_LENGTH
;
i
++
)
{
Y
[
i
][
t
]
=
((
GRID_LENGTH
-
i
)
*
dx
)
/
(
GRID_LENGTH
-
ipos
)
*
amp
;
for
(
;
i
<
STRING_PARTS
;
i
++
)
{
SET_Y
(
i
,
0
,
((
STRING_PARTS
-
i
)
*
dx
)
/
(
STRING_PARTS
-
ipos
));
}
}
void
iterate
(
double
C
,
int
t_prev
,
int
t_cur
,
int
t_next
)
{
for
(
int
i
=
1
;
i
<
GRID_LENGTH
;
i
++
)
{
Y
[
i
][
t_next
]
=
C
*
(
Y
[
i
-
1
][
t_cur
]
-
2
*
Y
[
i
][
t_cur
]
+
Y
[
i
+
1
][
t_cur
])
-
Y
[
i
][
t_prev
]
+
2
*
Y
[
i
][
t_cur
];
static
void
connect_string_ends
()
{
const
int
end
=
STRING_PARTS
-
1
;
Y
[
STRING_PARTS
*
2
]
=
Y
[
STRING_PARTS
*
1
]
=
Y
[
STRING_PARTS
];
Y
[
STRING_PARTS
*
2
+
end
]
=
Y
[
STRING_PARTS
*
1
+
end
]
=
Y
[
STRING_PARTS
+
end
];
}
/*
* Calculate position over the entire string at time 't_cur' (= dt).
*/
static
void
iterate
(
double
C
,
int
t_prev
,
int
t_cur
,
int
t_next
)
{
for
(
int
i
=
1
,
max
=
STRING_PARTS
-
1
;
i
<
max
;
i
++
)
{
SET_Y
(
i
,
t_next
,
\
C
*
(
GET_Y
(
i
-
1
,
t_cur
)
-
2
*
GET_Y
(
i
,
t_cur
)
+
GET_Y
(
i
+
1
,
t_cur
))
-
GET_Y
(
i
,
t_prev
)
+
2
*
GET_Y
(
i
,
t_cur
));
}
}
/*
* Integer XOR swapping macro.
*/
#define SWAP(a, b) \
a ^= b; \
b ^= a; \
a ^= b;
static
void
plot
(
int
col
)
{
printf
(
"%e"
,
GET_Y
(
0
,
col
));
for
(
int
i
=
1
;
i
<
STRING_PARTS
;
i
++
)
printf
(
",%e"
,
GET_Y
(
i
,
col
));
void
plot
(
int
col
)
{
printf
(
"%f"
,
Y
[
0
][
col
]);
for
(
int
i
=
1
;
i
<
GRID_LENGTH
;
i
++
)
printf
(
",%f"
,
Y
[
i
][
col
]);
printf
(
"
\n
"
);
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
4
)
{
fprintf
(
stderr
,
"Usage: %s <p amplitude position |s amplitude phases"
,
argv
[
0
]);
if
(
argc
<
7
)
{
fprintf
(
stderr
,
"Usage: %s <p|s> ITERATIONS LENGTH STEP_SIZE"
\
" TAU <PLUCK|PHASES>
\n
"
,
argv
[
0
]);
return
1
;
}
// Initialise time indices, iterations and string length.
int
t_prev
=
0
,
t_cur
=
1
,
t_next
=
2
,
iterations
=
atoi
(
argv
[
2
]),
length
=
atoi
(
argv
[
3
]);
double
dx
=
atof
(
argv
[
4
]),
tau
=
atof
(
argv
[
5
]);
STRING_PARTS
=
length
/
dx
;
if
(
!
(
Y
=
(
double
*
)
malloc
(
3
*
STRING_PARTS
*
sizeof
(
double
)))
)
return
2
;
// Initialise the requested shape in the allocated memory.
switch
(
*
argv
[
1
])
{
case
'p'
:
init_pluck
(
a
rgv
);
break
;
case
's'
:
init_sinus
(
a
rgv
);
break
;
case
'p'
:
init_pluck
(
a
tof
(
argv
[
6
]),
length
,
dx
);
break
;
case
's'
:
init_sinus
(
a
toi
(
argv
[
6
])
);
break
;
default:
fprintf
(
stderr
,
"Does this look like a 'p' or 's' to you?
\n
"
);
fprintf
(
stderr
,
"Argument 2 '%s' does not look like a 'p' or 's'.
\n
"
,
argv
[
1
]);
return
1
;
}
double
c
=
.
04
,
dt
=
.
1
,
dx
=
.
02
,
C
=
c
*
c
*
(
dt
/
dx
)
*
(
dt
/
dx
);
// TODO: implement iterations
int
t_prev
=
0
,
t_cur
=
1
,
t_next
=
2
,
T
=
10
;
// The string is connected at both ends.
connect_string_ends
();
for
(
int
i
=
0
;
i
<
T
;
i
++
)
{
iterate
(
C
,
t_prev
,
t_cur
,
t_next
);
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
{
iterate
(
tau
,
t_prev
,
t_cur
,
t_next
);
SWAP
(
t_cur
,
t_next
);
SWAP
(
t_prev
,
t_next
);
plot
(
t_cur
);
...
...
modsim/ass4_sander/part2/plot.py
100644 → 100755
View file @
d5bfd07b
from
pyplot
import
show
,
fig
#!/usr/bin/env python
from
pylab
import
plot
,
figure
,
clf
,
show
from
sys
import
stdin
lines
=
stdin
.
readlines
()
Y
=
map
(
float
,
lines
[
0
].
split
(
','
))
figure
(
1
)
clf
()
plot
(
Y
,
'-'
)
show
()
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