Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63535223
uvw_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
Mon, May 20, 20:04
Size
3 KB
Mime Type
text/x-python
Expires
Wed, May 22, 20:04 (2 d)
Engine
blob
Format
Raw Data
Handle
17785126
Attached To
rTAMAAS tamaas
uvw_dumper.py
View Options
# @author Lucas Frérot <lucas.frerot@epfl.ch>
#
# @section LICENSE
#
# Copyright (©) 2018 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
..
import
ModelDumper
from
._helper
import
makePeriodic
,
makeTractionPeriodic
import
os
import
uvw
import
numpy
as
np
__all__
=
[
"UVWDumper"
]
class
UVWDumper
(
ModelDumper
):
"""Dumper for elasto-plastic calculations"""
def
__init__
(
self
,
residual
,
filename
,
dump_numpys
=
False
):
ModelDumper
.
__init__
(
self
)
self
.
residual
=
residual
self
.
count
=
0
self
.
filename
=
filename
self
.
dump_numpys
=
dump_numpys
if
not
os
.
path
.
exists
(
'paraview'
):
os
.
mkdir
(
'paraview'
)
if
self
.
dump_numpys
and
not
os
.
path
.
exists
(
'numpys'
):
os
.
mkdir
(
'numpys'
)
def
dump
(
self
,
model
):
self
.
uvw_dump
(
model
)
if
self
.
dump_numpys
:
self
.
numpy_dump
(
model
)
self
.
count
+=
1
def
uvw_dump
(
self
,
model
):
"""Dump displacements, plastic deformations and stresses"""
discretization
=
model
.
getDiscretization
()
.
copy
()
discretization
[
1
]
+=
1
discretization
[
2
]
+=
1
coordinates
=
[
np
.
linspace
(
0
,
L
,
N
)
for
L
,
N
in
zip
(
model
.
getSystemSize
(),
discretization
)]
# Correct order of coordinate dimensions
dimension_indices
=
[
1
,
2
,
0
]
# Creating rectilinear grid with correct order for components
grid
=
uvw
.
RectilinearGrid
(
"paraview/{}_{:04d}.vtr"
.
format
(
self
.
filename
,
self
.
count
),
(
coordinates
[
i
]
for
i
in
dimension_indices
))
# Point data arrays
stress
=
uvw
.
DataArray
(
makePeriodic
(
self
.
residual
.
getStress
()),
dimension_indices
,
'stress'
)
plastic_strain
=
uvw
.
DataArray
(
makePeriodic
(
self
.
residual
.
getPlasticStrain
()),
dimension_indices
,
'plastic_strain'
)
displacement
=
uvw
.
DataArray
(
makePeriodic
(
model
.
getDisplacement
()),
dimension_indices
,
'displacement'
)
residual
=
uvw
.
DataArray
(
makePeriodic
(
self
.
residual
.
getVector
()),
dimension_indices
,
'residual'
)
grid
.
addPointData
(
stress
)
grid
.
addPointData
(
plastic_strain
)
grid
.
addPointData
(
displacement
)
grid
.
addPointData
(
residual
)
grid
.
write
()
def
numpy_dump
(
self
,
model
):
normal_traction
=
\
makeTractionPeriodic
(
model
.
getTraction
()[:,
:,
2
])
normal_displacement
=
makeTractionPeriodic
(
model
.
getDisplacement
()[
0
,
:,
:,
2
])
np
.
savez
(
'numpys/{}_{:04d}.npz'
.
format
(
self
.
filename
,
self
.
count
),
traction
=
normal_traction
,
displacement
=
normal_displacement
)
Event Timeline
Log In to Comment