{ "cells": [ { "cell_type": "markdown", "id": "9d209664-e22b-4b1e-8218-92e8c27c2620", "metadata": {}, "source": [ "# Material Phases " ] }, { "cell_type": "markdown", "id": "a42fc2d6-d322-479a-b73d-2a716b6385aa", "metadata": {}, "source": [ "The physical and mechanical properties of a polycrystalline materials depend not only on its chemical composition but also on the phases from which it is composed. This tutorial will review the objects and tools available in *Pymicro* to store, load and process the informations related to the various constitutive phases of a material." ] }, { "cell_type": "markdown", "id": "305a749d-095a-4f42-a756-c08ebe8867fa", "metadata": {}, "source": [ "In *Pymicro*, a phase is defined by a set of crystallographic and physical properties. The `CrystallinePhase` class of the `pymicro.crystal.lattice` module allows to store and manipulate phase data. In addition, the *data model* of [the Microstructure class](./Microstructure_class.ipynb) includes a specific *Group* to store phase data in datasets.\n", "\n", "To begin with, we will look at the phase data stored in one of Pymicro's example datasets. This file is zipped in the package to reduce its size. If you are reading through this tutorial as a Notebook, you will first have to unzip the file: " ] }, { "cell_type": "code", "execution_count": null, "id": "1c6e6dca-2962-4c21-be64-b131f81ebcd3", "metadata": {}, "outputs": [], "source": [ "from pymicro import get_examples_data_dir # import file directory path\n", "PYMICRO_EXAMPLES_DATA_DIR = get_examples_data_dir() # get the file directory path\n", "import os \n", "dataset_file = os.path.join(PYMICRO_EXAMPLES_DATA_DIR, 'example_microstructure') # test dataset desired file path\n", "tar_file = os.path.join(PYMICRO_EXAMPLES_DATA_DIR, 'example_microstructure.tar.gz') # dataset zipped archive path\n", "\n", "# Save current directory\n", "cwd = os.getcwd()\n", "# move to example data directory\n", "os.chdir(PYMICRO_EXAMPLES_DATA_DIR)\n", "# unarchive the dataset\n", "os.system(f'tar -xvf {tar_file}')\n", "# get back to UserGuide directory\n", "os.chdir(cwd)" ] }, { "cell_type": "markdown", "id": "a3edde71-1f51-4bcb-8132-cf9b7fc194a4", "metadata": {}, "source": [ "## Phase Groups" ] }, { "cell_type": "markdown", "id": "28c5d1d7-4b28-4037-9277-7111fff96168", "metadata": {}, "source": [ "Let us now open the dataset and display its content, using the `Microstructure` class:" ] }, { "cell_type": "code", "execution_count": null, "id": "6196e122-e027-4629-a58f-57ce45a44db4", "metadata": {}, "outputs": [], "source": [ "# import SampleData class\n", "from pymicro.crystal.microstructure import Microstructure \n", "# Open Microstructure dataset\n", "micro = Microstructure(filename=dataset_file)" ] }, { "cell_type": "code", "execution_count": null, "id": "31a2f7cf-feef-408e-9749-6676f78e172a", "metadata": {}, "outputs": [], "source": [ "# display content of dataset\n", "micro.print_dataset_content(max_depth=2, short=True)" ] }, { "cell_type": "markdown", "id": "97f984fd-324a-4215-9e8d-f4fcc703d3fc", "metadata": {}, "source": [ "The dataset contains a `PhaseData` group, that is used to store all phase data relative to the sample associated to the dataset. It has one `Group` children for each phase in the dataset, that stores all relevant information for this phase. \n", "\n", "Here there only one phase in the microstructure, whose data is stored into the `phase_01` group. The content of this group can be easily printed:" ] }, { "cell_type": "code", "execution_count": null, "id": "2e380ebd-91c4-4124-8e9b-e7902ae0b525", "metadata": {}, "outputs": [], "source": [ "micro.print_node_info('phase_01')" ] }, { "cell_type": "markdown", "id": "bb0f6ce0-c594-464a-90fc-3f768131ab9c", "metadata": {}, "source": [ "As shown by the print, this group contains only metadata (*node attributes*, see [here](./Data_Items.ipynb)) providing information on the phase crystallographic (symmetry, lattice parameters) and physical (elasticity) properties, but also some identification metadata (phase name, formula, Id number). \n", "\n", "The `CrystallinePhase` class of the `pymicro.crystal.lattice` module is the object that allows to manipulate interactively all the data stored into the `PhaseData` group. A `CrystallinePhase` can be directly retrieved from a phase description group with the `get_phase` method:" ] }, { "cell_type": "code", "execution_count": null, "id": "5f77fe02-810b-4090-8cd6-3e4d74777db0", "metadata": {}, "outputs": [], "source": [ "phase_01 = micro.get_phase(phase_id=1)\n", "print(phase_01)" ] }, { "cell_type": "markdown", "id": "c90e6368-f4f8-4436-b5ae-96c842d857eb", "metadata": {}, "source": [ "This object contains a `Lattice` object, defining the crystal lattice of the phase. It also stores the elastic constants of the phase. Currently, those are the only information that are handled by the `CrystallinePhase` object. As many attributes as desired can be stored in a `phase_XX` group, but only those will be loaded into the `CrystallinePhase` object with the `get_phase` method.\n", "\n", "The data associated to the `CrystallinePhase` class are used by other tools of the *Pymicro* package, related to X-ray diffration or mechanical behavior simulations. \n", "\n", "We will now see how to create *phase objects*, and store them into *microstructure datasets*." ] }, { "cell_type": "code", "execution_count": null, "id": "0ad48041-135b-47cd-adba-f952729d24fc", "metadata": {}, "outputs": [], "source": [ "# close the opened dataset and remove the phase object\n", "del phase_01\n", "del micro" ] }, { "cell_type": "markdown", "id": "b2e6f8c7-18ed-4544-8703-f01961c6f70f", "metadata": {}, "source": [ "## Phase objects" ] }, { "cell_type": "markdown", "id": "03239775-4d37-4e95-9414-f1e993688e89", "metadata": {}, "source": [ "As shown above, *Phase objects* are instances of the class `CrystallinePhase`. To create one, the class constructor can be used. Three arguments can be passed to the constructor:\n", "* a phase id number\n", "* a name for the phase\n", "* a crystal lattice object\n", "\n", "A *lattice object* must hence be created to be associated to the *phase object*." ] }, { "cell_type": "markdown", "id": "69f1d37d-6195-4caa-8d67-dd55380479d5", "metadata": {}, "source": [ "### Lattice objects" ] }, { "cell_type": "markdown", "id": "36db836f-1669-4392-8f10-727c66b1b7e9", "metadata": {}, "source": [ "The `Lattice` class of the `pymicro.crystal.lattice` module allows to create and manipulate *lattice objects*. A `Lattice` is defined by a by a symmetry group and three vectors. \n", "\n", "Most lattice systems encountered in real materials have a lot of symetries. In those cases, the complete description of the lattice vectors is redundant. Specific lattice constructors for each type of the 7 Bravais lattice systems are available in *Pymicro*, and allow to simplify the declaration of *lattice objects*.\n", "\n", "For instance, you can create a cubic lattice (completely defined by one lattice parameter) as follows: " ] }, { "cell_type": "code", "execution_count": null, "id": "e0447b9e-dcef-4ab2-9eb6-24148017f1a3", "metadata": {}, "outputs": [], "source": [ "from pymicro.crystal.lattice import Lattice\n", "\n", "a = 0.352 # lattice parameter for FCC Nickel (nm)\n", "l = Lattice.face_centered_cubic(a)\n", "print(l)" ] }, { "cell_type": "markdown", "id": "34fb98d3-7ed0-4cd7-9b4f-9586ddb1d0dd", "metadata": {}, "source": [ "