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 #378 from pyiron/write_functions
Browse files Browse the repository at this point in the history
Separate class methods to make functions
  • Loading branch information
samwaseda authored Sep 21, 2024
2 parents 7e70370 + 36f4ade commit 96959d4
Showing 1 changed file with 46 additions and 17 deletions.
63 changes: 46 additions & 17 deletions pyiron_continuum/damask/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Factory of the damask classes and methods to a pyironized manner"""

from pyiron_snippets.import_alarm import ImportAlarm
from typing import Sequence

with ImportAlarm(
"DAMASK functionality requires the `damask` module (and its dependencies) specified as extra"
Expand Down Expand Up @@ -34,14 +35,7 @@ def __init__(self):

@staticmethod
def config(rotation, elements, phase, homogenization):
_config = ConfigMaterial(
{"material": [], "phase": phase, "homogenization": homogenization}
)
for r, e in zip(rotation, elements):
_config = _config.material_add(
O=r, phase=e, homogenization=list(homogenization.keys())[0]
)
return _config
return generate_material(rotation, elements, phase, homogenization)

@staticmethod
def read(file_path):
Expand Down Expand Up @@ -79,18 +73,39 @@ def origin(self, value):

@staticmethod
def via_voronoi_tessellation(spatial_discretization, num_grains, box_size):
if isinstance(spatial_discretization, (int, float)):
spatial_discretization = np.array(
[spatial_discretization, spatial_discretization, spatial_discretization]
)
if isinstance(box_size, (int, float)):
box_size = np.array([box_size, box_size, box_size])
seed = seeds.from_random(box_size, num_grains)
return GeomGrid.from_Voronoi_tessellation(
spatial_discretization, box_size, seed
return generate_grid_from_voronoi_tessellation(
spatial_discretization, num_grains, box_size
)


def generate_grid_from_voronoi_tessellation(
spatial_discretization, num_grains, box_size
):
if isinstance(spatial_discretization, (int, float)):
spatial_discretization = np.array(
[spatial_discretization, spatial_discretization, spatial_discretization]
)
if isinstance(box_size, (int, float)):
box_size = np.array([box_size, box_size, box_size])
seed = seeds.from_random(box_size, num_grains)
return GeomGrid.from_Voronoi_tessellation(spatial_discretization, box_size, seed)


def generate_material(rotation, elements, phase, homogenization):
_config = ConfigMaterial(
{"material": [], "phase": phase, "homogenization": homogenization}
)
if not isinstance(rotation, (list, tuple, np.ndarray)):
rotation = [rotation]
if not isinstance(rotation, (list, tuple, np.ndarray)):
elements = [elements]
for r, e in zip(rotation, elements):
_config = _config.material_add(
O=r, phase=e, homogenization=list(homogenization.keys())[0]
)
return _config


def generate_loading_tensor(default="F"):
"""
Returns the default boundary conditions for the damask loading tensor.
Expand Down Expand Up @@ -299,6 +314,20 @@ def get_phase(composition, elasticity, plasticity=None, lattice=None, output_lis
return d


def get_random_rotation(
shape: int | np.ndarray | Sequence[int] | None = None,
rng_seed: (
int
| np.ndarray
| Sequence[int]
| np.random.bit_generator.SeedSequence
| np.random._generator.Generator
| None
) = None,
):
return Rotation.from_random(shape=shape, rng_seed=rng_seed)


def get_rotation(method="from_random", *args, **kwargs):
"""
Args:
Expand Down

0 comments on commit 96959d4

Please sign in to comment.