Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from math import *
- Side_size = 64
- Fiber_number = 5
- VTKFileName = "Test.vtk"
- Option = "3D" #"2D"
- # RVE generation, 0 is for the matrix
- RVE = np.zeros([Side_size ,Side_size ])
- #Add a fiber at coordinate X,Y with radius R
- R = 10
- def placeFiber(X,Y,R,RVE):
- # 1 is the fiber material
- for i in range(len(RVE)):
- for j in range(len(RVE[0])):
- if sqrt((i-X)**2+(j-Y)**2) < R:
- RVE[i][j] = 1
- return RVE
- FiberCoords = np.random.random((Fiber_number,2))*Side_size
- for fiber in FiberCoords:
- RVE = placeFiber(fiber[0],fiber[1],R,RVE)
- def VTKize(RVE,FileName,Option):
- # Header
- OutputStr = ""
- OutputStr += "# vtk DataFile Version 2.0 \n"
- OutputStr += FileName + "\n"
- OutputStr += "ASCII\nDATASET STRUCTURED_POINTS\n"
- OutputStr += "DIMENSIONS "+str(Side_size)+" "+str(Side_size)+" "+str(Side_size)+"\n"
- OutputStr += "ORIGIN 0 0 0\nSPACING 1 1 1\n"
- OutputStr += "CELL_DATA "+str(Side_size*Side_size*Side_size)+"\n"
- # Proper data
- # That is stored in the RVE matrix in this program
- if Option == "3D":
- for channel in range(len(RVE)):
- for row in range(len(RVE)):
- for line in range(len(RVE[row])):
- OutputStr += str(int(RVE[row,line]))+" "
- OutputStr += "\n"
- elif Option == "2D":
- for row in range(len(RVE)):
- for line in range(len(RVE[row])):
- OutputStr += str(int(RVE[row,line]))+" "
- OutputStr += "\n"
- # Return the string
- return OutputStr
- VTKstring = VTKize(RVE,VTKFileName,Option)
- # Write the data in a File
- VTKFile = open(VTKFileName,"w")
- VTKFile.write(VTKstring)
- VTKFile.close()
- plt.imshow(RVE)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement