Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TurTLE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TurTLE
TurTLE
Commits
86526213
Commit
86526213
authored
Jun 26, 2015
by
Chichi Lalescu
Browse files
Options
Downloads
Patches
Plain Diff
fix python wrapper
parent
832f0455
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
base.py
+1
-1
1 addition, 1 deletion
base.py
code.py
+10
-7
10 additions, 7 deletions
code.py
test.py
+29
-26
29 additions, 26 deletions
test.py
with
40 additions
and
34 deletions
base.py
+
1
−
1
View file @
86526213
...
@@ -79,7 +79,7 @@ class base(object):
...
@@ -79,7 +79,7 @@ class base(object):
key
=
self
.
parameters
.
keys
()
key
=
self
.
parameters
.
keys
()
key
.
sort
()
key
.
sort
()
for
i
in
range
(
len
(
key
)):
for
i
in
range
(
len
(
key
)):
if
type
(
self
.
source
.
parameters
[
key
[
i
]])
==
float
:
if
type
(
self
.
parameters
[
key
[
i
]])
==
float
:
ofile
.
write
((
'
{0} = {1:e}
\n
'
).
format
(
key
[
i
],
self
.
parameters
[
key
[
i
]]))
ofile
.
write
((
'
{0} = {1:e}
\n
'
).
format
(
key
[
i
],
self
.
parameters
[
key
[
i
]]))
else
:
else
:
ofile
.
write
(
'
{0} = {1}
\n
'
.
format
(
key
[
i
],
self
.
parameters
[
key
[
i
]]))
ofile
.
write
(
'
{0} = {1}
\n
'
.
format
(
key
[
i
],
self
.
parameters
[
key
[
i
]]))
...
...
...
...
This diff is collapsed.
Click to expand it.
code.py
+
10
−
7
View file @
86526213
...
@@ -6,18 +6,19 @@ class code(base):
...
@@ -6,18 +6,19 @@ class code(base):
def
__init__
(
self
):
def
__init__
(
self
):
super
(
code
,
self
).
__init__
()
super
(
code
,
self
).
__init__
()
self
.
includes
=
"""
self
.
includes
=
"""
//
@
begincpp
//begincpp
#include
"
base.hpp
"
#include
"
base.hpp
"
#include
"
fluid_solver.hpp
"
#include
"
fluid_solver.hpp
"
#include <iostream>
#include <iostream>
#include <fftw3-mpi.h>
#include <fftw3-mpi.h>
//@endcpp
"""
//endcpp
"""
self
.
variables
=
'
int myrank, nprocs;
\n
'
self
.
variables
=
'
int myrank, nprocs;
\n
'
self
.
variables
=
'
int iter0;
\n
'
self
.
variables
+
=
'
int iter0;
\n
'
self
.
variables
+=
'
char simname[256];
\n
'
self
.
variables
+=
'
char simname[256];
\n
'
self
.
definitions
=
''
self
.
definitions
=
''
self
.
main_start
=
"""
self
.
main_start
=
"""
//
@
begincpp
//begincpp
int main(int argc, char *argv[])
int main(int argc, char *argv[])
{
{
MPI_Init(&argc, &argv);
MPI_Init(&argc, &argv);
...
@@ -36,16 +37,18 @@ class code(base):
...
@@ -36,16 +37,18 @@ class code(base):
std::cerr <<
"
myrank =
"
<< myrank <<
"
, simulation name is
"
<< simname << std::endl;
std::cerr <<
"
myrank =
"
<< myrank <<
"
, simulation name is
"
<< simname << std::endl;
}
}
read_parameters();
read_parameters();
//@endcpp
"""
//endcpp
"""
self
.
main_end
=
"""
self
.
main_end
=
"""
//
@
begincpp
//begincpp
// clean up
// clean up
fftwf_mpi_cleanup();
fftwf_mpi_cleanup();
fftw_mpi_cleanup();
fftw_mpi_cleanup();
MPI_Finalize();
MPI_Finalize();
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
}
//@endcpp
"""
//endcpp
"""
return
None
return
None
def
write_src
(
self
):
def
write_src
(
self
):
with
open
(
'
src/
'
+
self
.
name
+
'
.cpp
'
,
'
w
'
)
as
outfile
:
with
open
(
'
src/
'
+
self
.
name
+
'
.cpp
'
,
'
w
'
)
as
outfile
:
...
...
...
...
This diff is collapsed.
Click to expand it.
test.py
+
29
−
26
View file @
86526213
...
@@ -35,7 +35,7 @@ def basic_test(
...
@@ -35,7 +35,7 @@ def basic_test(
nsteps
=
8
):
nsteps
=
8
):
nsteps_str
=
'
{0}
'
.
format
(
nsteps
)
nsteps_str
=
'
{0}
'
.
format
(
nsteps
)
src_txt
=
"""
src_txt
=
"""
//
@
begincpp
//begincpp
fluid_solver<float> *fs;
fluid_solver<float> *fs;
fs = new fluid_solver<float>(32, 32, 32);
fs = new fluid_solver<float>(32, 32, 32);
DEBUG_MSG(
"
fluid_solver object created
\\
n
"
);
DEBUG_MSG(
"
fluid_solver object created
\\
n
"
);
...
@@ -63,7 +63,8 @@ def basic_test(
...
@@ -63,7 +63,8 @@ def basic_test(
delete fs;
delete fs;
DEBUG_MSG(
"
fluid_solver object deleted
\\
n
"
);
DEBUG_MSG(
"
fluid_solver object deleted
\\
n
"
);
//@endcpp
"""
//endcpp
"""
return
src_txt
return
src_txt
class
stat_test
(
code
):
class
stat_test
(
code
):
...
@@ -72,37 +73,39 @@ class stat_test(code):
...
@@ -72,37 +73,39 @@ class stat_test(code):
self
.
name
=
name
self
.
name
=
name
self
.
parameters
[
'
niter_todo
'
]
=
8
self
.
parameters
[
'
niter_todo
'
]
=
8
self
.
parameters
[
'
dt
'
]
=
0.01
self
.
parameters
[
'
dt
'
]
=
0.01
self
.
variables
+=
(
'
double time;
\n
'
+
self
.
includes
+=
'
#include <cstring>
\n
'
'
dobule stats[2];
\n
'
)
self
.
variables
+=
(
'
double t;
\n
'
+
'
FILE *stat_file;
\n
'
'
double stats[2];
\n
'
)
self
.
variables
+=
self
.
cdef_pars
()
self
.
variables
+=
self
.
cdef_pars
()
self
.
definitions
+=
self
.
cread_pars
()
self
.
definitions
+=
self
.
cread_pars
()
self
.
definitions
+=
"""
self
.
definitions
+=
"""
//
@
begincpp
//begincpp
void do_stats()
void do_stats(
fluid_solver<float> *fsolver
)
{
{
fs->compute_velocity(fs->cvorticity);
fs
olver
->compute_velocity(fs
olver
->cvorticity);
stats[0] = .5*fs->correl_vec(fs->cvelocity, fs->cvelocity);
stats[0] = .5*fs
olver
->correl_vec(fs
olver
->cvelocity,
fs
olver
->cvelocity);
stats[1] = .5*fs->correl_vec(fs->cvorticity, fs->cvorticity);
stats[1] = .5*fs
olver
->correl_vec(fs
olver
->cvorticity, fs
olver
->cvorticity);
if (myrank == fs->cd->io_myrank)
if (myrank == fs
olver
->cd->io_myrank)
{
{
fwrite((void*)&fs->iteration, sizeof(int), 1, stat_file);
fwrite((void*)&fs
olver
->iteration, sizeof(int), 1, stat_file);
fwrite((void*)&t
ime
, sizeof(double), 1, stat_file);
fwrite((void*)&t, sizeof(double), 1, stat_file);
fwrite((void*)stats, sizeof(double), 2, stat_file);
fwrite((void*)stats, sizeof(double), 2, stat_file);
}
}
}
}
//@endcpp
"""
//endcpp
"""
self
.
stats_dtype
=
np
.
dtype
([(
'
iteration
'
,
np
.
int32
),
self
.
stats_dtype
=
np
.
dtype
([(
'
iteration
'
,
np
.
int32
),
(
'
t
ime
'
,
np
.
float64
),
(
'
t
'
,
np
.
float64
),
(
'
energy
'
,
np
.
float64
),
(
'
energy
'
,
np
.
float64
),
(
'
enstrophy
'
,
np
.
float64
)])
(
'
enstrophy
'
,
np
.
float64
)])
pickle
.
dump
(
pickle
.
dump
(
self
.
stats_dtype
,
self
.
stats_dtype
,
open
(
self
.
name
+
'
_dtype.pickle
'
,
'
w
'
))
open
(
self
.
name
+
'
_dtype.pickle
'
,
'
w
'
))
self
.
main
=
"""
self
.
main
=
"""
//
@
begincpp
//begincpp
fluid_solver<float> *fs;
fluid_solver<float> *fs;
fs = new fluid_solver<float>(32, 32, 32);
fs = new fluid_solver<float>(32, 32, 32);
FILE *stat_file;
if (myrank == fs->cd->io_myrank)
if (myrank == fs->cd->io_myrank)
stat_file = fopen(
"
stats.bin
"
,
"
wb
"
);
stat_file = fopen(
"
stats.bin
"
,
"
wb
"
);
...
@@ -112,19 +115,20 @@ class stat_test(code):
...
@@ -112,19 +115,20 @@ class stat_test(code):
fs->low_pass_Fourier(fs->cvorticity, 3, fs->kM);
fs->low_pass_Fourier(fs->cvorticity, 3, fs->kM);
fs->force_divfree(fs->cvorticity);
fs->force_divfree(fs->cvorticity);
fs->symmetrize(fs->cvorticity, 3);
fs->symmetrize(fs->cvorticity, 3);
t
ime
= 0.0;
t = 0.0;
fs->iteration = iter0;
fs->iteration = iter0;
do_stats();
do_stats(
fs
);
for (
int t = 0; t <
niter_todo;
t++
)
for (
; fs->iteration < iter0 +
niter_todo;)
{
{
fs->step(dt);
fs->step(dt);
t
ime
+= dt;
t += dt;
do_stats();
do_stats(
fs
);
}
}
fclose(stat_file);
fclose(stat_file);
delete fs;
delete fs;
//@endcpp
"""
//endcpp
"""
return
None
return
None
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
@@ -146,15 +150,14 @@ if __name__ == '__main__':
...
@@ -146,15 +150,14 @@ if __name__ == '__main__':
Kdata0
[...,
1
]
=
Kdata01
Kdata0
[...,
1
]
=
Kdata01
Kdata0
[...,
2
]
=
Kdata02
Kdata0
[...,
2
]
=
Kdata02
Kdata0
.
tofile
(
"
Kdata0
"
)
Kdata0
.
tofile
(
"
Kdata0
"
)
c
=
code
()
c
=
stat_test
(
name
=
opt
.
test_name
)
c
.
main
=
locals
()[
opt
.
test_name
]()
c
.
write_src
()
c
.
write_src
()
c
.
write_par
()
c
.
write_par
()
c
.
run
(
ncpu
=
opt
.
ncpu
)
c
.
run
(
ncpu
=
opt
.
ncpu
)
dtype
=
pickle
.
load
(
open
(
'
stats
_dtype.pickle
'
))
dtype
=
pickle
.
load
(
open
(
opt
.
test_name
+
'
_dtype.pickle
'
))
stats
=
np
.
fromfile
(
'
stats.bin
'
,
dtype
=
dtype
)
stats
=
np
.
fromfile
(
'
stats.bin
'
,
dtype
=
dtype
)
fig
=
plt
.
figure
(
figsize
=
(
6
,
6
))
fig
=
plt
.
figure
(
figsize
=
(
6
,
6
))
a
=
fig
.
add_subplot
(
111
)
a
=
fig
.
add_subplot
(
111
)
a
.
plot
(
stats
[
'
t
ime
'
],
stats
[
'
energy
'
])
a
.
plot
(
stats
[
'
t
'
],
stats
[
'
energy
'
])
fig
.
savefig
(
'
test.pdf
'
,
format
=
'
pdf
'
)
fig
.
savefig
(
'
test.pdf
'
,
format
=
'
pdf
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment