Overview
Kanapy is a python package for generating complex three-dimensional (3D) synthetic polycrystalline microstructures. The microstructures are built based on statistical information about grain geometry, given as grain size distribution and aspect ratio of grains, and crystallographic texture, in form of orientation distribution functions (ODF) and misorientation distribution functions (MDF). Kanapy offers tools to analyze EBSD maps with respect to the geometry and texture of microstructures. Based on this experimental data, it generates 3D synthetic microstructures mimicking real ones in a statistical sense. The implementation is done in Python.
The texture module of Kanapy is implemented as MATLAB functions using several algorithms implemented in MTEX for texture analysis.
Motivation
An accurate representation of a material’s microstructure is fundamental in understanding the relationship between microstructure and its corresponding mechanical behavior. In this regard, Kanapy is developed to be a robust and an efficient tool to generate synthetic microstructures as the basis for micromechanical simulations with crystal plasticity methods. The generated microstructures can be used for mechanical analysis with Finite Element (FE) of spectral solvers. Kanapy is designed to model simple and complex grain morphologies and to systematically incorporate texture data directly from experiments concurrently maintaining the numerical efficiency of the micromechanical model. Kanapy is developed to overcome the limitations of spatial tessellation methods and to provide an alternative to the existing Random Sequential Addition technique of microstructure geometry generation.
Features
Kanapy offers a Python Application Programming Interface (API).
Possibility to analyze experimental microstructures based on MTEX functions.
Generation of microstructure geometry based on statistical features as grain size distribution and grain aspect ratio distribution.
Crystallographic texture reconstruction using orientations from experimental data in form of Orientation Distribution Function (ODF).
Optimal orientation assignment based on measured Misorientation Distribution Function (MDF) that maintains correct statistical description of high-angle or low-angle grain boundary characteristics.
Independent execution of individual modules through easy data storage and handling.
In-built hexahedral mesh generator for complex polycrystalline microstructures.
Efficient generation of space filling structures by particle dynamics method.
Collision handling of particles through a two-layer collision detection method employing the Octree spatial data structure and the bounding sphere hierarchy.
Option to generate spherical particle position- and radius files that can be read by the Voronoi tessellation software Neper.
Option to generate input files for the commercial finite-element software Abaqus.
Analysis and RVE generation for dual-phase microstructures.
Import and export of voxelated structures for data transfer between different tools.
Installation
The preferred method to install kanapy is through Anaconda or Miniconda Python distributions. If you do not have any, we suggest installing miniconda.
Once done, create a virtual environment for Kanapy installation and clone the repository to a desired location and install.
$ git clone https://github.com/ICAMS/Kanapy.git <location to clone>/kanapy-master
$ cd kanapy
$ conda env create -f environment.yml
$ conda activate knpy
(knpy) $ python -m pip install .
Kanapy is now installed along with all its dependencies. If you intend to use Kanapy’s texture module, a MATLAB installation is required because the texture module is based on MTEX functions. Kanapy uses a local version of MTEX stored in libs/mtex, if you want to use another version, please set the paths accordingly. If MATLAB is available on your system, the texture module is initialized by the command
(knpy) $ kanapy setupTexture
Note
knpy
can be replaced with any name for your environment.
2. The absolute paths to {user_dependent_path}/kanapy/src/kanapy and {user_dependent_path}/kanapy/libs/mtex should to be added to the MATLABPATH environment variable, see Mathworks documentation.
3. The installation scripts have been tested for Matlab R2023a with Python 3.9 and 3.10. If you are using other Matlab versions, the script “setupTexture” might fail. In that case, you can setup the Matlab Engine API for Python manually. To do so, please follow the instructions given on the Mathworks website, to (i) Verify your configuration, (ii) Install Engine API, and (iii) Start MATLAB Engine. The Python version of the knpy-environment can be changed according to the requirements of the Matlab Engine API by editing the “environment.yml” file and re-creating the conda environment knpy.
Tip
To learn more about managing environments see Anaconda documentation.
Installation as system administrator
If system administrators with write access to the root directory of the knpy-environment want to install Kanapy for all users, they need to run
(knpy) $ python admin_setup.py
after activating the knpy-environment. This will automatically execute the Kanapy installation and texture setup in administrator mode. After that step, users can directly access Kanapy in the conda environment.
Running tests
Kanapy uses pytest to perform all its unit testing.
(knpy) $ kanapy runTests
Updates
Kanapy is constantly under development and there will be frequent updates with bugfixes and new features. To update Kanapy, follow these steps:
$ cd kanapy
$ git pull
$ conda activate knpy
(knpy) $ python -m pip install .
This will make the new version available in your knpy-environment. If your Kanapy installation has been setup for textures (MTEX module), this feature will not be affected by such updates. This update routine is also valid for global installations as system administrator.
Examples
Kanapy comes with several examples in form of Python scripts and Juypter notebooks. If you want to create a local copy of the kanapy/examples directory within the current working directory (cwd), please run the command
(knpy) $ kanapy copyExamples
Documentation build
The complete documentation for kanapy is available online on GitHub Pages: https://icams.github.io/Kanapy/
Documentation for kanapy is generated using Sphinx. You can create or update your local documentation with the command
(knpy) $ kanapy genDocs
The HTML documentation is then found at kanapy/docs/builds/html/index.html
Dependencies
Kanapy’s texture module requires MATLAB to be installed on your machine. Make sure to use MATLAB v2015a and above. The module uses a local version of MTEX contained in kanapy/libs and does not interfere with other installations of MTEX.
Core dependencies
Below are the listed dependencies for running kanapy:
Optional dependencies
Matplotlib for plotting and visualizing.
OVITO for visualizing simulation data.
Citation
The preferred way to cite Kanapy is:
@article{Biswas2020,
doi = {10.5281/zenodo.3662366},
url = {https://doi.org/10.5281/zenodo.3662366},
author = {Abhishek Biswas and Mahesh R.G. Prasad and Napat Vajragupta and Alexander Hartmaier},
title = {Kanapy: Synthetic polycrystalline microstructure generator with geometry and texture},
journal = {Zenodo},
year = {2020}
}
License
Kanapy is made available under the GNU AGPLv3 license.
The additional materials under examples and in the documentation are published under the Creative Commons Attribution-NonCommercial-ShareAlike (CC BY-NC-SA 4.0) license.
About
The name kanapy is derived from the sanskrit word káṇa meaning particle. Kanapy is primarily developed at the Interdisciplinary Center for Advanced Materials Simulation (ICAMS), Ruhr University Bochum - Germany. Our goal is to build a complete synthetic microstructure generation tool for research and industry use.
Disclaimer
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.