-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathrectilinear.jl
64 lines (51 loc) · 1.63 KB
/
rectilinear.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function vtk_grid(
dtype::VTKRectilinearGrid, filename::AbstractString,
xs::Tuple{Vararg{AbstractVector, 3}};
extent = map(length, xs), whole_extent = extent, kwargs...,
)
Ns = map(length, xs)
Npts = prod(Ns)
Ncls = num_cells_structured(Ns)
xvtk = XMLDocument()
vtk = DatasetFile(dtype, xvtk, filename, Npts, Ncls; kwargs...)
# VTKFile node
xroot = vtk_xml_write_header(vtk)
# RectilinearGrid node
xGrid = new_child(xroot, vtk.grid_type)
let ext = extent_attribute(whole_extent)
set_attribute(xGrid, "WholeExtent", ext)
end
# Piece node
xPiece = new_child(xGrid, "Piece")
let ext = extent_attribute(extent)
set_attribute(xPiece, "Extent", ext)
end
# Coordinates node
xPoints = new_child(xPiece, "Coordinates")
# DataArray node
x, y, z = xs
data_to_xml(vtk, xPoints, x, "x")
data_to_xml(vtk, xPoints, y, "y")
data_to_xml(vtk, xPoints, z, "z")
vtk
end
"""
vtk_grid(filename::AbstractString,
x::AbstractVector{T}, y::AbstractVector{T}, [z::AbstractVector{T}];
kwargs...)
Create 2D or 3D rectilinear grid (`.vtr`) file.
Coordinates are specified by separate vectors `x`, `y`, `z`.
# Examples
```jldoctest
julia> vtk = vtk_grid("abc", [0., 0.2, 0.5], collect(-2.:0.2:3), [1., 2.1, 2.3])
VTK file 'abc.vtr' (RectilinearGrid file, open)
```
"""
function vtk_grid(
filename::AbstractString,
x::AbstractVector{T}, y::AbstractVector{T},
z::AbstractVector{T} = Zeros{T}(1);
kwargs...,
) where {T}
vtk_grid(VTKRectilinearGrid(), filename, (x, y, z); kwargs...)
end