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
b4fa04e7
Commit
b4fa04e7
authored
May 10, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added sources files for part 2 of modsim assignment 4.
parent
c19b79d2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
0 deletions
+105
-0
modsim/ass4_sander/part2/Makefile
modsim/ass4_sander/part2/Makefile
+14
-0
modsim/ass4_sander/part2/main.c
modsim/ass4_sander/part2/main.c
+89
-0
modsim/ass4_sander/part2/plot.py
modsim/ass4_sander/part2/plot.py
+2
-0
No files found.
modsim/ass4_sander/part2/Makefile
0 → 100644
View file @
b4fa04e7
CFLAGS
+=
-std
=
c99
-Wall
-Wextra
-g
-O2
-pthread
LDFLAGS
+=
-pthread
-lmpi
-lopen-rte
-lopen-pal
-ldl
-Wl
,--export-dynamic
\
-lnsl
-lutil
-lm
-ldl
MAIN
=
main
OFILES
=
$
(
$(
wildcard
*
.c
)
:.c
=
.o
)
$(MAIN)
:
$(OFILES)
clean
:
rm
-vf
$(MAIN)
$(OFILES)
check-syntax
:
$(CXX)
$(CXXFLAGS)
-fsyntax-only
${CHK_SOURCES}
modsim/ass4_sander/part2/main.c
0 → 100644
View file @
b4fa04e7
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#define GRID_LENGTH 64
double
Y
[
GRID_LENGTH
][
3
];
int
t_next
,
t_prev
,
t_cur
;
void
init_sinus
(
char
**
argv
)
{
double
amp
;
int
h_phases
;
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
);
}
}
void
init_pluck
(
char
**
argv
)
{
double
amp
,
position
;
int
ipos
,
i
;
sscanf
(
argv
[
2
],
"%lf"
,
&
amp
);
sscanf
(
argv
[
3
],
"%i"
,
&
position
);
ipos
=
position
/
dx
*
GRID_LENGTH
;
for
(
i
=
0
;
i
<
ipos
;
i
++
)
{
Y
[
i
][
t
]
=
i
*
dx
/
position
*
amp
;
}
for
(;
i
<
GRID_LENGTH
;
i
++
)
{
Y
[
i
][
t
]
=
((
GRID_LENGTH
-
i
)
*
dx
)
/
(
GRID_LENGTH
-
ipos
)
*
amp
;
}
}
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
];
}
}
#define SWAP(a, b) \
a ^= b; \
b ^= a; \
a ^= b;
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
)
{
if
(
argc
<
4
)
{
fprintf
(
stderr
,
"Usage: %s <p amplitude position |s amplitude phases"
,
argv
[
0
]);
return
1
;
}
switch
(
*
argv
[
1
])
{
case
'p'
:
init_pluck
(
argv
);
break
;
case
's'
:
init_sinus
(
argv
);
break
;
default:
fprintf
(
stderr
,
"Does this look like a 'p' or 's' to you?
\n
"
);
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
;
for
(
int
i
=
0
;
i
<
T
;
i
++
)
{
iterate
(
C
,
t_prev
,
t_cur
,
t_next
);
SWAP
(
t_cur
,
t_next
);
SWAP
(
t_prev
,
t_next
);
plot
(
t_cur
);
}
return
0
;
}
modsim/ass4_sander/part2/plot.py
0 → 100644
View file @
b4fa04e7
from
pyplot
import
show
,
fig
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