Simple Mesh
Here, we consider generating rectangular domain nodes (2D) and cuboidal domain nodes (3D) by controlling the starting range and step size in each direction.
2D
Consider a rectangular area where the range in the x-direction is from 0 to 10 and in the y-direction from 0 to 6. The step size in the x-direction is 1, and in the y-direction, it is 2. Therefore, we can do:
MaterialPointGenerator.meshbuilder
— Methodmeshbuilder(x::T, y::T; ϵ::String="FP64") where T <: AbstractRange
Description:
Generate structured mesh in 2D space.
julia> pts = meshbuilder(0.0 : 1.0 : 10.0, 0.0: 2.0 : 6.0)
44×2 Matrix{Float64}:
0.0 0.0
0.0 2.0
0.0 4.0
0.0 6.0
1.0 0.0
1.0 2.0
⋮
9.0 6.0
10.0 0.0
10.0 2.0
10.0 4.0
10.0 6.0
This way, we can obtain the results shown in the figure. The variable pts
is an array where the first column contains the x-coordinates of all the nodes, and the second column contains the corresponding y-coordinates.
3D
Similarly, we can use this function to generate a set of points in three-dimensional space.
MaterialPointGenerator.meshbuilder
— Methodmeshbuilder(x::T, y::T, z::T; ϵ::String="FP64") where T <: AbstractRange
Description:
Generate structured mesh in 3D space.
julia> pts = meshbuilder(0.0 : 1.0 : 10.0, 0.0: 2.0 : 6.0, 0.0 : 2.0 : 4.0)
132×3 Matrix{Float64}:
0.0 0.0 0.0
0.0 2.0 0.0
0.0 4.0 0.0
0.0 6.0 0.0
1.0 0.0 0.0
1.0 2.0 0.0
⋮
9.0 6.0 4.0
10.0 0.0 4.0
10.0 2.0 4.0
10.0 4.0 4.0
10.0 6.0 4.0
Export
For two-dimensional points and three-dimensional points, you can use the functions savexy
and savexyz
to save them as .xy
and .xyz
files, respectively. You can also use readxy
and readxyz
to read these files.
MaterialPointGenerator.savexy
— Methodsavexy(file_dir::P, pts::T) where {P <: String, T <: AbstractMatrix}
Description:
Save the 2D points pts
to the .xy
file (file_dir
).
MaterialPointGenerator.savexyz
— Methodsavexyz(file_dir::P, pts::T) where {P <: String, T <: AbstractMatrix}
Description:
Save the 3D points pts
to the .xyz
file (file_dir
).
MaterialPointGenerator.readxy
— Methodreadxy(file_dir::P) where P <: String
Description:
Read the 2D .xy
file from file_dir
.
MaterialPointGenerator.readxyz
— Methodreadxyz(file_dir::P) where P <: String
Description:
Read the 3D .xyz
file from file_dir
.
output_file = joinpath(@__DIR__, "test.xyz")
savexyz(output_file, pts)
data = readxyz(output_file)