Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65149929
test_dumper.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Jun 1, 05:53
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Jun 3, 05:53 (2 d)
Engine
blob
Format
Raw Data
Handle
17983931
Attached To
rTAMAAS tamaas
test_dumper.py
View Options
#!/usr/bin/env python
# coding: utf-8
# -----------------------------------------------------------------------------
# @author Lucas Frérot <lucas.frerot@epfl.ch>
#
# @section LICENSE
#
# Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
# Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
# Solides)
#
# Tamaas is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
from
__future__
import
print_function
,
division
import
tamaas
as
tm
import
numpy
as
np
import
os
import
shutil
from
tamaas.dumpers
import
NumpyDumper
class
Dumper
(
tm
.
ModelDumper
):
"""Simple numpy dumper"""
def
__init__
(
self
):
tm
.
ModelDumper
.
__init__
(
self
)
def
dump
(
self
,
model
):
np
.
savetxt
(
'tractions.txt'
,
np
.
ravel
(
model
.
getField
(
'traction'
)))
np
.
savetxt
(
'displacement.txt'
,
np
.
ravel
(
model
.
getField
(
'displacement'
)))
def
test_dumpers
(
tamaas_fixture
):
model
=
tm
.
ModelFactory
.
createModel
(
tm
.
model_type
.
volume_2d
,
[
1.
,
1.
,
1.
],
[
16
,
4
,
8
])
dumper
=
Dumper
()
np_dumper
=
NumpyDumper
(
'test_dump'
,
[
'traction'
,
'displacement'
])
model
.
addDumper
(
dumper
)
model
.
addDumper
(
np_dumper
)
model
.
dump
()
tractions
=
np
.
loadtxt
(
'tractions.txt'
)
displacements
=
np
.
loadtxt
(
'displacement.txt'
)
assert
tractions
.
size
==
model
.
getTraction
()
.
size
assert
displacements
.
size
==
model
.
getDisplacement
()
.
size
with
np
.
load
(
'numpys/test_dump_0000.npz'
)
as
npfile
:
tractions
=
npfile
[
'traction'
]
displacements
=
npfile
[
'displacement'
]
t_shape
=
list
(
model
.
getTraction
()
.
shape
)
t_shape
[
0
]
+=
1
t_shape
[
1
]
+=
1
d_shape
=
list
(
model
.
getDisplacement
()
.
shape
)
d_shape
[
1
]
+=
1
d_shape
[
2
]
+=
1
assert
tractions
.
shape
==
tuple
(
t_shape
)
assert
displacements
.
shape
==
tuple
(
d_shape
)
for
name
in
[
'tractions.txt'
,
'displacement.txt'
,
'numpys'
]:
if
os
.
path
.
exists
(
name
)
and
os
.
path
.
isdir
(
name
):
shutil
.
rmtree
(
name
)
elif
os
.
path
.
exists
(
name
):
os
.
remove
(
name
)
Event Timeline
Log In to Comment