From b0b4caf44b51906797a66dd43b25c33bf215caa9 Mon Sep 17 00:00:00 2001 From: Gerard Capes Date: Thu, 30 Nov 2023 10:50:02 +0000 Subject: [PATCH 1/3] Implement modify VE spread orientations Work in progress - demo workflow errors with suspected bug in hpcflow. Would otherwise fix #206. --- .../damask/modify_VE_spread_orientations.py | 8 ++++++++ .../template_components/task_schemas.yaml | 18 +++++++++++++++++ .../data/workflows/spread_orientations.yaml | 20 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 matflow/data/scripts/damask/modify_VE_spread_orientations.py create mode 100644 matflow/data/workflows/spread_orientations.yaml diff --git a/matflow/data/scripts/damask/modify_VE_spread_orientations.py b/matflow/data/scripts/damask/modify_VE_spread_orientations.py new file mode 100644 index 00000000..0067b9e8 --- /dev/null +++ b/matflow/data/scripts/damask/modify_VE_spread_orientations.py @@ -0,0 +1,8 @@ +from damask_parse.utils import spread_orientations + + +def modify_VE_spread_orientations(volume_element, phases, stddev_degrees): + VE = spread_orientations(volume_element, phases, sigmas=stddev_degrees) + VE["grid_size"] = tuple(int(i) for i in VE["grid_size"]) + VE["size"] = tuple(float(i) for i in VE["size"]) + return {"volume_element": VE} diff --git a/matflow/data/template_components/task_schemas.yaml b/matflow/data/template_components/task_schemas.yaml index e1e51c34..06b087ea 100644 --- a/matflow/data/template_components/task_schemas.yaml +++ b/matflow/data/template_components/task_schemas.yaml @@ -991,3 +991,21 @@ script_data_in: direct script_data_out: direct script_exe: python_script + +- objective: modify_VE + method: spread_orientations + inputs: + - parameter: volume_element + - parameter: phases + - parameter: stddev_degrees + outputs: + - parameter: volume_element + actions: + - environments: + - scope: + type: any + environment: damask_parse_env + script: <> + script_data_in: direct + script_data_out: direct + script_exe: python_script diff --git a/matflow/data/workflows/spread_orientations.yaml b/matflow/data/workflows/spread_orientations.yaml new file mode 100644 index 00000000..6f3e9a34 --- /dev/null +++ b/matflow/data/workflows/spread_orientations.yaml @@ -0,0 +1,20 @@ +doc: + - > + Demonstration of modifying a volume element by applying a perturbation to its orientations. + +tasks: + - schema: generate_microstructure_seeds_from_random + inputs: + VE_size: [1, 1, 1] + num_grains: 4 + phase_label: Al + + - schema: generate_volume_element_from_voronoi + inputs: + homog_label: SX + VE_grid_size: [8, 8, 8] + + - schema: modify_VE_spread_orientations # underscore to separate the levels of the task schema objective/method + inputs: + phases: [Al] + stddev_degrees: [0.01] From 0f69465dbf5aa733725835cd877c60412fa6362f Mon Sep 17 00:00:00 2001 From: aplowman Date: Wed, 13 Dec 2023 13:20:23 +0000 Subject: [PATCH 2/3] docs: update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c226ff86..33a2370b 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ This is a list tracking which workflows/tasks we have reimplemented/tested in th | ⇒ method: [add_buffer_zones/damask](https://github.com/LightForm-group/UoM-CSF-matflow/blob/569fa7bdc7006d04bd6ed2d4e4b6a114df23492e/task_schemas.yml#L760) | ✅ | [modify_VE/add_buffer_zones](https://docs.matflow.io/stable/reference/template_components/task_schemas.html#modify-ve-add-buffer-zones) | | ⇒ method: [new_orientations/damask](https://github.com/LightForm-group/UoM-CSF-matflow/blob/569fa7bdc7006d04bd6ed2d4e4b6a114df23492e/task_schemas.yml#L770) | ❌ | Unimplemented | | ⇒ method: [geometry](https://github.com/LightForm-group/UoM-CSF-matflow/blob/569fa7bdc7006d04bd6ed2d4e4b6a114df23492e/task_schemas.yml#L775) | ❌ | Unimplemented | -| ⇒ method: [spread_orientations/damask](https://github.com/LightForm-group/UoM-CSF-matflow/blob/569fa7bdc7006d04bd6ed2d4e4b6a114df23492e/task_schemas.yml#L780) | ❌ | Unimplemented | +| ⇒ method: [spread_orientations/damask](https://github.com/LightForm-group/UoM-CSF-matflow/blob/569fa7bdc7006d04bd6ed2d4e4b6a114df23492e/task_schemas.yml#L780) | ✅ | [modify_VE/spread_orientations](https://docs.matflow.io/stable/reference/template_components/task_schemas.html#modify-ve-spread-orientations) | | ⇒ method: [grid_size/damask](https://github.com/LightForm-group/UoM-CSF-matflow/blob/569fa7bdc7006d04bd6ed2d4e4b6a114df23492e/task_schemas.yml#L786) | ✅ | [modify_VE/grid_size](https://docs.matflow.io/stable/reference/template_components/task_schemas.html#modify-ve-grid-size) | | **generate_load_case** | | | | ⇒ method: [mixed/formable](https://github.com/LightForm-group/UoM-CSF-matflow/blob/569fa7bdc7006d04bd6ed2d4e4b6a114df23492e/task_schemas.yml#L912) | ✅ | [define_load_case](https://docs.matflow.io/stable/reference/template_components/task_schemas.html#define-load-case) / [LoadCase](https://docs.matflow.io/stable/reference/template_components/parameters.html#load-case) | From 81e2436708a9bcc521cfda6d78eb5451576ec80b Mon Sep 17 00:00:00 2001 From: aplowman Date: Wed, 13 Dec 2023 19:35:07 +0000 Subject: [PATCH 3/3] fix: script `modify_VE_spread_orientations` so Zarr arrays are cast to numpy --- .../damask/modify_VE_spread_orientations.py | 19 ++++++++++++- .../data/workflows/spread_orientations.yaml | 27 +++++++++++++------ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/matflow/data/scripts/damask/modify_VE_spread_orientations.py b/matflow/data/scripts/damask/modify_VE_spread_orientations.py index 0067b9e8..aeec7d0c 100644 --- a/matflow/data/scripts/damask/modify_VE_spread_orientations.py +++ b/matflow/data/scripts/damask/modify_VE_spread_orientations.py @@ -2,7 +2,24 @@ def modify_VE_spread_orientations(volume_element, phases, stddev_degrees): - VE = spread_orientations(volume_element, phases, sigmas=stddev_degrees) + # need to convert Zarr arrays to numpy arrays first: + VE = volume_element + ori_copy = VE["orientations"] + ori_copy["quaternions"] = ori_copy["quaternions"][:] + VE_copy = { + "size": VE["size"], + "grid_size": VE["grid_size"][:], + "orientations": ori_copy, + "element_material_idx": VE["element_material_idx"][:], + "constituent_material_idx": VE["constituent_material_idx"][:], + "constituent_material_fraction": VE["constituent_material_fraction"][:], + "constituent_phase_label": VE["constituent_phase_label"][:], + "constituent_orientation_idx": VE["constituent_orientation_idx"][:], + "material_homog": VE["material_homog"][:], + } + VE = spread_orientations( + volume_element=VE_copy, phase_names=phases, sigmas=stddev_degrees + ) VE["grid_size"] = tuple(int(i) for i in VE["grid_size"]) VE["size"] = tuple(float(i) for i in VE["size"]) return {"volume_element": VE} diff --git a/matflow/data/workflows/spread_orientations.yaml b/matflow/data/workflows/spread_orientations.yaml index 6f3e9a34..9a74dbc2 100644 --- a/matflow/data/workflows/spread_orientations.yaml +++ b/matflow/data/workflows/spread_orientations.yaml @@ -1,19 +1,30 @@ -doc: +doc: - > Demonstration of modifying a volume element by applying a perturbation to its orientations. tasks: - - schema: generate_microstructure_seeds_from_random - inputs: - VE_size: [1, 1, 1] - num_grains: 4 - phase_label: Al - - schema: generate_volume_element_from_voronoi inputs: homog_label: SX VE_grid_size: [8, 8, 8] - + microstructure_seeds::from_random: + num_seeds: 4 + box_size: [1, 1, 1] + phase_label: Al + orientations: + data: + - [1, 0, 0, 0] + - [1, 0, 0, 0] + - [1, 0, 0, 0] + - [1, 0, 0, 0] + unit_cell_alignment: + x: a + y: b + z: c + representation: + type: quaternion + quat_order: scalar_vector + - schema: modify_VE_spread_orientations # underscore to separate the levels of the task schema objective/method inputs: phases: [Al]