Page MenuHomec4science

numpy_dumper.py
No OneTemporary

File Metadata

Created
Wed, May 1, 16:31

numpy_dumper.py

# @file
# @section LICENSE
#
# Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne),
# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from ._helper import FieldDumper, step_dump, directory_dump
import os
import numpy as np
__all__ = ['NumpyDumper']
@directory_dump('numpys')
@step_dump
class NumpyDumper(FieldDumper):
"""Dumper to compressed numpy files"""
def __init__(self, basename, *fields):
default_fields = ['traction', 'displacement',
'stress', 'plastic_strain']
super().__init__(basename, default_fields, *fields)
def dump(self, model):
dump_fields = {
field: self.make_periodic[field](model.getField(field))
for field in self.fields
}
np.savez_compressed(self.file_path(), **dump_fields)
def file_path(self):
return os.path.join(self.dirname(), "{}{}.npz".format(self.basename,
self.postfix()))

Event Timeline