Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
defectFields.py
Go to the documentation of this file.
1# /opt/local/bin/python3.13 defectFields.py
2import sys
3import os
4import matplotlib.pyplot as plt
5import numpy as np
6sys.path.append("../build/tools/pyMoDELib")
7import pyMoDELib
8
9simulationDir=os.path.abspath("../tutorials/uniformLoadController")
10ddBase=pyMoDELib.DefectiveCrystalBase(simulationDir)
11
12# Microstructure Generation
13microstructureGenerator=pyMoDELib.MicrostructureGenerator(ddBase)
14spec=pyMoDELib.ShearLoopIndividualSpecification()
15spec.slipSystemIDs=[0,6]
16spec.loopRadii=[27.0e-8,27.0e-8]
17spec.loopCenters=np.array([[0.0,0.0,0.0],[0.0,0.0,0.0]])
18spec.loopSides=[10,10]
19microstructureGenerator.addShearLoopIndividual(spec)
20
21microstructureGenerator.writeConfigFiles(0) # write evel_0.txt (optional)
22
23# DefectiveCrystal
24defectiveCrystal=pyMoDELib.DefectiveCrystal(ddBase)
25defectiveCrystal.initializeConfiguration(microstructureGenerator.configIO)
26#defectiveCrystal.runSteps()
27
28# Exctract displacement and stress fields on the xy-plane through the center of the mesh
29xMax=ddBase.mesh.xMax(); # vector [max(x1) max(x2) max(x3)] in the mesh
30xMin=ddBase.mesh.xMin(); # vector [min(x1) min(x2) min(x3)] in the mesh
31
32n=20
33x=np.linspace(xMin[0], xMax[0], num=n) # grid x-range
34y=np.linspace(xMin[1], xMax[1], num=n) # grid x-range
35z=0.5*(xMin[2]+xMax[2])
36points = np.zeros((0, 3))
37
38for i in range(0,x.size):
39 for j in range(0,y.size):
40 pnt=np.array([x[i],y[j],z])
41 points=np.vstack((points, pnt))
42
43u=defectiveCrystal.displacement(points) # displacement field at points
44s=defectiveCrystal.stress(points) # stress field at points
45
46# Place u1 ans s11 on a grid
47u1=np.empty([n, n])
48s11=np.empty([n, n])
49k=0
50for i in range(0,x.size):
51 for j in range(0,y.size):
52 u1[i,j]=u[k,0]
53 s11[i,j]=s[k][0,0]
54 k=k+1
55
56# Plot u1
57fig=plt.figure()
58plt.imshow(u1,origin='lower',cmap='jet')
59plt.colorbar()
60plt.show()
61
62# Plot s11
63fig=plt.figure()
64plt.imshow(s11,origin='lower',cmap='jet')
65plt.colorbar()
66plt.show()
67
68#mesh=ddBase.mesh
69#grain1=ddBase.poly.grain(1)
70#for phase in grain1.secondPhases().values():
71# print(phase.name)