Skip to content

Commit

Permalink
Script demonstrating the characterization of strain localization.
Browse files Browse the repository at this point in the history
It reads the second example microstructure and an HDF5 file, the latter containing the displacement field measurements at discrete time steps.
That HDF5 file is huge, so it is not added to the git repository.
  • Loading branch information
CsatiZoltan committed Mar 4, 2021
1 parent a74f954 commit 13576f7
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions scripts/run_simulation_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from os import path
from os.path import join

import numpy as np
from scipy.stats import kurtosis
import matplotlib.pyplot as plt
from skimage.io import imread
from skimage.morphology import dilation

from grains.simulation import nature_of_deformation
from grains.dic import DIC
from grains import HAS_TABLES


# Directory where we read from and write to
script_dir = os.path.dirname(__file__) # absolute path to the directory the script is in
data_dir = join(script_dir, 'data')

################################################################################
# Determine the ratio of intergranular and intragranular strain localization #
################################################################################

# Crop data which belongs to the testing device (the indices were obtained using:
# `selected = plt.ginput(-1, timeout=-1))`
cropped_region = np.s_[800:2175, 860:3000]

# 1) Load the segmented image, representing the grains of the microstructure
microstructure = imread(join(data_dir, '2_labelimage.tiff'))
microstructure = microstructure[cropped_region]

# 2) Bands in the neighborhood of the interfaces
band_width = 3
microstructure = dilation(microstructure)

# 3) Process a series of full-field measurements (DIC)
dic_data = join(data_dir, 'FULLTEST_fields.hdf')
MEASUREMENT_COUNT = 382
PERCENTILE_COUNT = 10

# 4) User settings
show_plots = True
save_plots = False
time_instances = range(MEASUREMENT_COUNT)

# Analysis
matrix = np.zeros((PERCENTILE_COUNT+1, MEASUREMENT_COUNT))
kurt_band = []
kurt_bulk = []
visualize = show_plots or save_plots
if not path.isfile(dic_data):
raise Exception('Measurement dataset {0} not found.'.format(dic_data))
if not HAS_TABLES:
raise ImportError('The PyTables package is needed to load the dataset.')
import tables
measurement = tables.open_file(dic_data).root.res
for time_instance in time_instances:
print('Time instance:', time_instance)
# a) Load the displacement field
displacement_field = measurement[time_instance, cropped_region[0], cropped_region[1], :]
u = displacement_field[:, :, 0]
v = displacement_field[:, :, 1]
# b) Obtain the equivalent strain field
dic = DIC(u, v)
strain_tensor = dic.strain('Green-Lagrange')
vonMises_strain = DIC.equivalent_strain(strain_tensor, 'von Mises')
# c) Characterize the deformation in the current time step
boundary_strain, bulk_strain, bands = nature_of_deformation(microstructure,
vonMises_strain,
band_width, visualize=visualize)
if save_plots:
plt.savefig(join(data_dir, 't_' + str(time_instance) + '.png'), dpi=500)
if show_plots:
plt.show(block=True)
normalized_boundary_strain = boundary_strain[bands] / max(boundary_strain[bands])
normalized_bulk_strain = bulk_strain[~bands] / max(bulk_strain[~bands])
quantiles = np.percentile(normalized_boundary_strain, range(0, 101, PERCENTILE_COUNT))
matrix[:, time_instance] = quantiles
kurt_band.append(kurtosis(normalized_boundary_strain))
kurt_bulk.append(kurtosis(normalized_bulk_strain))

0 comments on commit 13576f7

Please sign in to comment.