7import matplotlib.pyplot
as plt
10import matplotlib
as mpl
11import matplotlib.transforms
as mtransforms
13sys.path.append(
"../../build/tools/pyMoDELib/")
15from scipy.signal
import correlate2d
16from scipy.stats
import norm
17from matplotlib
import cm
18from matplotlib.colors
import Normalize
20sys.path.append(
"../../python")
21from modlibUtils
import *
22from pathlib
import Path
26 "dd_file": Path(
"../../Library/DislocationDynamics/DD.txt"),
27 "noise_file": Path(
"../../Library/GlidePlaneNoise/MDSolidSolution.txt"),
28 "material_file": Path(
"../../Library/Materials/FeCrAl_Fe.txt"),
29 "elastic_deformation_file": Path(
30 "../../Library/ElasticDeformation/ElasticDeformation.txt"
32 "mesh": Path(
"../../Library/Meshes/unitCube24.msh"),
33 "microstructure": Path(
34 "../../Library/Microstructures/periodicDipoleIndividual.txt"
38MDSolidSolution_parameters = {
41 "type":
"MDSolidSolutionNoise",
47 "correlationFile_xz": Path(
48 "../../Library/GlidePlaneNoise/MoDELCompatible_FeCr8_xz.vtk"
50 "correlationFile_yz": Path(
51 "../../Library/GlidePlaneNoise/MoDELCompatible_FeCr8_yz.vtk"
57 "value": np.array([100, 100, 1]),
58 "comment":
"number of grid points in each direction",
61 "value": np.array([1.0e-10, 1.0e-10, 1e-10]),
62 "comment":
"grid spacing in each direction",
65 "copy_to":
"inputFiles/MDSolidSolution.txt",
68Material_parameters = {
70 "enabledSlipSystems":
"Shockley",
72 "glidePlaneNoise":
"MDSolidSolution.txt",
73 "atomsPerUnitCell":
"1",
74 "dislocationMobilityType":
"default",
76 "copy_to":
"inputFiles/FeCrAl_Fe.txt",
79Polycrystal_parameters = {
81 "absoluteTemperature": 1,
82 "grain1globalX1": np.array([0, 1, 1]),
83 "grain1globalX3": np.array([-1, 1, -1]),
84 "boxEdges": np.array([[0, 1, 1], [-2, -1, 1], [-1, 1, -1]]),
85 "boxScaling": np.array([200, 200, 200]),
87 "X0": np.array([0.0, 0.0, 0.0]),
88 "periodicFaceIDs": np.array([0, 1, 2, 3, 4, 5]),
89 "gridSpacing_SI": np.array([1.0e-10, 1.0e-10]),
95 reader = vtk.vtkGenericDataObjectReader()
96 reader.SetFileName(fname)
97 reader.ReadAllVectorsOn()
98 reader.ReadAllScalarsOn()
102 reader.GetOutput().GetDimensions(dims)
106 pointData = reader.GetOutput().GetPointData()
111 for i
in range(pointData.GetNumberOfArrays()):
112 array = pointData.GetArray(i)
114 if array.GetNumberOfComponents() == 1:
115 scalarArrays.append(np.array(array))
116 noiseScalars = scalarArrays[0]
117 noiseScalars = np.reshape(noiseScalars, shape=(NX, NY))
118 return noiseScalars, dims
123 print(
"\033[1;32mCopying template files...\033[0m")
124 for key, src_path
in file_templates.items():
125 dest = f
"inputFiles/{src_path.name}"
126 shutil.copy2(src_path.resolve(), dest)
128 print(f
"Created {dest}")
130 print(
"\033[1;32mCreating noiseFile\033[0m")
133 MDSolidSolution_parameters[
"variables"][
"correlationFile_xz"],
"inputFiles/"
136 MDSolidSolution_parameters[
"variables"][
"correlationFile_yz"],
"inputFiles/"
139 for param, value
in MDSolidSolution_parameters[
"variables"].items():
140 if "correlationFile" in param:
141 relativePath = f
"{str(value).split('/')[-1]}"
142 setInputVariable(MDSolidSolution_parameters[
"copy_to"], param, relativePath)
145 for param, data
in MDSolidSolution_parameters[
"vectors"].items():
147 MDSolidSolution_parameters[
"copy_to"], param, data[
"value"], data[
"comment"]
151 print(
"\033[1;32mCreating materialFile...\033[0m")
153 matParams = Material_parameters[
"variables"]
155 Material_parameters[
"copy_to"],
156 "enabledSlipSystems",
157 matParams[
"enabledSlipSystems"],
161 Material_parameters[
"copy_to"],
"glidePlaneNoise", matParams[
"glidePlaneNoise"]
165 Material_parameters[
"copy_to"],
167 matParams[
"atomsPerUnitCell"],
170 Material_parameters[
"copy_to"],
171 "dislocationMobilityType",
172 matParams[
"dislocationMobilityType"],
179 pf.meshFile = f
'{str(file_templates["mesh"]).split("/")[-1]}'
180 for param, value
in Polycrystal_parameters[
"parameters"].items():
181 setattr(pf, param, value)
182 pf.write(
"inputFiles")
185def circularShift(corrArray: np.ndarray, gridSize: np.ndarray) -> np.ndarray:
186 NX, NY = np.squeeze(gridSize[0]), np.squeeze(gridSize[1])
189 tempArr = np.zeros(NX * NY)
190 for y
in np.arange(NY):
191 newY = int((y + shiftY) % NY)
192 for x
in np.arange(NX):
193 newX = int((x + shiftX) % NX)
194 tempArr[newY * NX + newX] += corrArray[y * NX + x]
200 folders = [
"inputFiles"]
203 if os.path.exists(x):
211 simulationDir = os.path.abspath(
".")
212 ddBase = pyMoDELib.DefectiveCrystalBase(simulationDir)
214 matFile =
"inputFiles/FeCrAl_Fe.txt"
216 mat = pyMoDELib.PolycrystallineMaterialBase(matFile, absoluteTemp)
222 originalCorrFile_xz =
"./inputFiles/MoDELCompatible_FeCr8_xz.vtk"
223 originalCorrFile_yz =
"./inputFiles/MoDELCompatible_FeCr8_yz.vtk"
225 gridSize = np.array([100, 100, 1])
226 gridSpacing = np.array([1e-10, 1e-10, 1e-10]) / b_SI
227 latticeBasis = np.array([[1, 0], [0, 1]]).reshape(2, 2)
228 a_cai_SI = 1e-10 / b_SI
230 ssNoise = pyMoDELib.MDSolidSolutionNoise(
236 gridSize.reshape(3, 1),
237 gridSpacing.reshape(3, 1),
242 corr_xz, corr_yz = np.array(ssNoise.averageNoiseCorrelation(realizationNum)) * mu0_SI**2
246 corr_xz = corr_xz.reshape(100, 100)
247 corr_yz = corr_yz.reshape(100, 100)
249 fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12, 6), dpi=200)
251 axes[0].set_title(
"corr_xz")
252 im0 = axes[0].imshow(corr_xz, cmap=
"coolwarm", origin=
"lower")
253 fig.colorbar(im0, ax=axes[0], label=
"Pa2")
254 axes[0].set_xlabel(
"X")
255 axes[0].set_ylabel(
"Y")
258 axes[1].set_title(
"corr_yz")
259 im1 = axes[1].imshow(corr_yz, cmap=
"coolwarm", origin=
"lower")
260 fig.colorbar(im1, ax=axes[1], label=
"Pa2")
261 axes[1].set_xlabel(
"X")
262 axes[1].set_ylabel(
"Y")
264 fig.savefig(f
"ensemCorrSS_R{realizationNum}.png", transparent=
True)
269if __name__ ==
"__main__":
np.ndarray circularShift(np.ndarray corrArray, np.ndarray gridSize)
None processInitialConfigurations()
setInputVector(fileName, variable, newVal, newCom)
setInputVariable(fileName, variable, newVal)
getValueInFile(fileName, variable)