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]),
93def processInitialConfigurations() -> None:
95 print(
"\033[1;32mCopying template files...\033[0m")
96 for key, src_path
in file_templates.items():
97 dest = f
"inputFiles/{src_path.name}"
98 shutil.copy2(src_path.resolve(), dest)
100 print(f
"Created {dest}")
102 print(
"\033[1;32mCreating noiseFile\033[0m")
105 MDSolidSolution_parameters[
"variables"][
"correlationFile_xz"],
"inputFiles/"
108 MDSolidSolution_parameters[
"variables"][
"correlationFile_yz"],
"inputFiles/"
111 for param, value
in MDSolidSolution_parameters[
"variables"].items():
112 if "correlationFile" in param:
113 relativePath = f
"{str(value).split('/')[-1]}"
114 setInputVariable(MDSolidSolution_parameters[
"copy_to"], param, relativePath)
116 setInputVariable(MDSolidSolution_parameters[
"copy_to"], param, str(value))
117 for param, data
in MDSolidSolution_parameters[
"vectors"].items():
119 MDSolidSolution_parameters[
"copy_to"], param, data[
"value"], data[
"comment"]
123 print(
"\033[1;32mCreating materialFile...\033[0m")
125 matParams = Material_parameters[
"variables"]
127 Material_parameters[
"copy_to"],
128 "enabledSlipSystems",
129 matParams[
"enabledSlipSystems"],
133 Material_parameters[
"copy_to"],
"glidePlaneNoise", matParams[
"glidePlaneNoise"]
137 Material_parameters[
"copy_to"],
139 matParams[
"atomsPerUnitCell"],
142 Material_parameters[
"copy_to"],
143 "dislocationMobilityType",
144 matParams[
"dislocationMobilityType"],
149 pf = PolyCrystalFile(Material_parameters[
"copy_to"].
split(
"/")[-1])
151 pf.meshFile = f
'{str(file_templates["mesh"]).split("/")[-1]}'
152 for param, value
in Polycrystal_parameters[
"parameters"].items():
153 setattr(pf, param, value)
154 pf.write(
"inputFiles")
157def circularShift(corrArray: np.ndarray, gridSize: np.ndarray) -> np.ndarray:
158 NX, NY = np.squeeze(gridSize[0]), np.squeeze(gridSize[1])
161 tempArr = np.zeros(NX * NY)
162 for y
in np.arange(NY):
163 newY = int((y + shiftY) % NY)
164 for x
in np.arange(NX):
165 newX = int((x + shiftX) % NX)
166 tempArr[newY * NX + newX] += corrArray[y * NX + x]
172 folders = [
"inputFiles"]
175 if os.path.exists(x):
181 processInitialConfigurations()
183 simulationDir = os.path.abspath(
".")
184 ddBase = pyMoDELib.DefectiveCrystalBase(simulationDir)
186 matFile =
"inputFiles/FeCrAl_Fe.txt"
188 mat = pyMoDELib.PolycrystallineMaterialBase(matFile, absoluteTemp)
189 b_SI = getValueInFile(f
"{matFile}",
"b_SI")
190 mu0_SI = getValueInFile(f
"{matFile}",
"mu0_SI")
191 rho_SI = getValueInFile(f
"{matFile}",
"rho_SI")
194 originalCorrFile_xz =
"./inputFiles/MoDELCompatible_FeCr8_xz.vtk"
195 originalCorrFile_yz =
"./inputFiles/MoDELCompatible_FeCr8_yz.vtk"
197 gridSize = np.array([100, 100, 1])
198 gridSpacing = np.array([1e-10, 1e-10, 1e-10]) / b_SI
199 latticeBasis = np.array([[1, 0], [0, 1]]).reshape(2, 2)
201 a_cai_SI = 1e-10 / b_SI
202 ssNoise = pyMoDELib.MDSolidSolutionNoise(
208 gridSize.reshape(3, 1),
209 gridSpacing.reshape(3, 1),
214 sampledNoises = np.array(ssNoise.sampleAverageNoise(realizationNum)) * mu0_SI**2
216 xzNoises = sampledNoises[::2]
218 yzNoises = sampledNoises[1::2]
220 fig, axs = plt.subplots(1, 2, figsize=(16,6), dpi=200)
222 xzNoises = xzNoises.ravel()
223 yzNoises = yzNoises.ravel()
224 axs[0].hist(xzNoises, density=
True, alpha=0.3, bins=
'auto', label=f
"R{realizationNum}")
225 axs[1].hist(yzNoises, density=
True, alpha=0.3, bins=
'auto', label=f
"R{realizationNum}")
227 std_xz = np.std(xzNoises)
228 std_yz = np.std(yzNoises)
229 print(f
"std_xz = {std_xz} Pa2")
230 print(f
"std_yz = {std_yz} Pa2")
249 axs[0].set_title(f
"noise xz")
250 axs[0].set_xlabel(f
"")
251 axs[0].set_ylabel(f
"")
254 axs[1].set_title(f
"noise yz")
255 axs[1].set_xlabel(f
"")
256 axs[1].set_ylabel(f
"")
258 fig.savefig(f
'sampledNoiseDistribution_R{realizationNum}.png')
264if __name__ ==
"__main__":