Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #256 from pyiron/damask_imports
Browse files Browse the repository at this point in the history
[Damask] update import names
  • Loading branch information
samwaseda authored Apr 10, 2024
2 parents 93aa06e + 9a7a497 commit 8d92388
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
13 changes: 6 additions & 7 deletions .ci_support/environment-notebooks-damask.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ dependencies:
- coveralls
- coverage
- codacy-coverage
- damask-mesh =3.0.0a8
- damask-grid =3.0.0a8
- damask =3.0.0a8
- mshr =2019.1.0=*_9
- k3d =2.16.0
- damask-mesh =3.0.0b
- damask-grid =3.0.0b
- damask =3.0.0b
- k3d
- matplotlib =3.8.0
- numpy =1.26.3
- pyiron =0.5.0
- pyiron-data =0.0.26
- python-damask =3.0.0a8
- pyiron-data
- python-damask =3.0.0b
- pyvista =0.42.3
- scipy =1.11.4
- seaborn =0.13.1
Expand Down
4 changes: 2 additions & 2 deletions .ci_support/environment-notebooks-fenics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ dependencies:
- codacy-coverage
- fenics =2019.1.0
- fenics =2019.1.0=*_42
- mshr =2019.1.0=*_9
- k3d =2.16.0
- mshr
- k3d
- matplotlib =3.8.0
- numpy =1.26.3
- pyiron =0.5.0
Expand Down
8 changes: 4 additions & 4 deletions .ci_support/environment-notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ dependencies:
- coveralls
- coverage
- codacy-coverage
- damask-mesh =3.0.0a8
- damask-grid =3.0.0a8
- damask =3.0.0a8
- damask-mesh =3.0.0b
- damask-grid =3.0.0b
- damask =3.0.0b
- fenics =2019.1.0
- fenics =2019.1.0=*_42
- mshr =2019.1.0=*_9
Expand All @@ -16,7 +16,7 @@ dependencies:
- numpy =1.26.3
- pyiron =0.5.0
- pyiron-data =0.0.26
- python-damask =3.0.0a8
- python-damask =3.0.0b
- pyvista =0.42.3
- scipy =1.11.4
- seaborn =0.13.1
Expand Down
16 changes: 8 additions & 8 deletions pyiron_continuum/damask/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'DAMASK functionality requires the `damask` module (and its dependencies) specified as extra'
'requirements. Please install it and try again.'
) as damask_alarm:
from damask import Grid, Config, ConfigMaterial, seeds
from damask import GeomGrid, YAML, ConfigMaterial, seeds
import numpy as np

__author__ = "Muhammad Hassani"
Expand Down Expand Up @@ -49,22 +49,22 @@ def write(file_path):

class GridFactory:
def __init__(self):
"""A factory for damask._grid.Grid class."""
"""A factory for damask._grid.GeomGrid class."""
self._origin = None

@staticmethod
def read(file_path):
return Grid.load(fname=file_path)
return GeomGrid.load(fname=file_path)

@property
def origin(self):
"""
Returns damask._grid.Grid, it can be used to call damask original methods.
Returns damask._grid.GeomGrid, it can be used to call damask original methods.
For example:
origin.from_Voronoi_tessellation(...)
"""
if self._origin is None:
return Grid(material=np.ones((1, 1, 1)), size=[1., 1., 1.])
return GeomGrid(material=np.ones((1, 1, 1)), size=[1., 1., 1.])
else:
return self._origin

Expand All @@ -79,12 +79,12 @@ def via_voronoi_tessellation(spatial_discretization, num_grains, box_size):
if isinstance(box_size, int) or isinstance(box_size, float):
box_size = np.array([box_size, box_size, box_size])
seed = seeds.from_random(box_size, num_grains)
return Grid.from_Voronoi_tessellation(spatial_discretization, box_size, seed)
return GeomGrid.from_Voronoi_tessellation(spatial_discretization, box_size, seed)


class DamaskLoading(dict):
def __init__(self, solver, load_steps):
"""A factory for damask Loading class, which is a damask._config.Config object."""
"""A factory for damask Loading class, which is a damask._config.YAML object."""
super(DamaskLoading, self).__init__(self)

def __new__(cls, solver, load_steps):
Expand All @@ -102,7 +102,7 @@ def __new__(cls, solver, load_steps):
discretization=load_steps['discretization'],
additional_parameters_dict=load_steps["additional"])
]
return Config(solver=loading_dict["solver"], loadstep=loading_dict["loadstep"])
return YAML(solver=loading_dict["solver"], loadstep=loading_dict["loadstep"])


class LoadStep(dict):
Expand Down
10 changes: 5 additions & 5 deletions pyiron_continuum/damask/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def regrid_Geom(work_dir, geom_name, load_name, seed_scale=1.0, increment='last'
Regrid the geometry
It requires the previous geom.vti and result.hdf5
'''
geom_0 = damask.Grid.load(f'{geom_name}.vti')
geom_0 = damask.GeomGrid.load(f'{geom_name}.vti')
cells_0 = geom_0.cells
size_0 = geom_0.size

Expand All @@ -26,11 +26,11 @@ def regrid_Geom(work_dir, geom_name, load_name, seed_scale=1.0, increment='last'
d5Out = damask.Result(f'{work_dir}/{geom_name}_{load_name}_material.hdf5')

if increment == 'last':
inc = int(d5Out.increments[-1][10::]) # take the increment number
inc = int(d5Out.increments[-1]) # take the increment number
d5Out = d5Out.view(increments=inc)
increment_title = d5Out.increments[-1]
elif increment in d5Out.increments:
inc = int(increment[10::]) # take the increment number
inc = int(increment) # take the increment number
d5Out = d5Out.view(increments=inc)
increment_title = increment
else:
Expand Down Expand Up @@ -75,9 +75,9 @@ def write_RegriddedGeom(work_dir, geom_name, increment_title, map_0to_rg, cells_
Save the regridded geometry to a new vti file
'''
os.chdir(f'{work_dir}')
grid_0 = damask.Grid.load(geom_name + '.vti')
grid_0 = damask.GeomGrid.load(geom_name + '.vti')
material_rg = grid_0.material.flatten('F')[map_0to_rg].reshape(cells_rg, order='F')
grid = damask.Grid(material_rg, size_rg, grid_0.origin, comments=grid_0.comments \
grid = damask.GeomGrid(material_rg, size_rg, grid_0.origin, comments=grid_0.comments \
).save(f'{geom_name}_regridded_{increment_title}.vti')
print(f'save regrid geometry to {geom_name}_regridded_{increment_title}.vti')
regrid_geom_name = f'{geom_name}_regridded_{increment_title}'
Expand Down
8 changes: 3 additions & 5 deletions pyiron_continuum/damask/rolling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ast import arg
import imp
import os
from random import vonmisesvariate
import numpy as np
Expand All @@ -14,8 +13,7 @@

from damaskjob import DAMASK
import regrid as rgg
from damask import Result
from damask import Config
from damask import Result, YAML
from factory import DamaskLoading


Expand All @@ -33,7 +31,7 @@ def __init__(self, project, job_name):
def loading_discretization(self, rolltimes, filename):
time = rolltimes * self._height_reduction / (self._rolling_speed * self._number_passes)

self.load_case = Config(solver={'mechanical': 'spectral_basic'}, loadstep=[])
self.load_case = YAML(solver={'mechanical': 'spectral_basic'}, loadstep=[])
dotF = [['x', 0, 0],
[0, 0, 0],
[0, 0, -1.0 * self._rolling_speed]]
Expand Down Expand Up @@ -72,7 +70,7 @@ def executeRolling(self, reduction_height, reduction_speed, reduction_outputs, r
self._write_material()
self._write_geometry()

self.load_case = Config(solver={'mechanical': 'spectral_basic'}, loadstep=[])
self.load_case = YAML(solver={'mechanical': 'spectral_basic'}, loadstep=[])
reduction_time = reduction_height / reduction_speed
dotF = [['x', 0, 0],
[0, 0, 0],
Expand Down

0 comments on commit 8d92388

Please sign in to comment.