@@ -152,7 +152,7 @@ xml_data_array_name(::Union{String,ListOfStrings}) = "Array"
152152 data_to_xml(
153153 vtk::DatasetFile, xParent::XMLElement, data,
154154 name::AbstractString, Nc::Union{Int,AbstractFieldData} = 1;
155- component_names::Union{AbstractVector, Nothing} = nothing
155+ component_names = nothing
156156 )
157157
158158Add numerical data to VTK XML file.
@@ -164,8 +164,8 @@ In the latter case, the number of components will be deduced from the data
164164dimensions and the type of field data.
165165"""
166166function data_to_xml (vtk, xParent, data, name,
167- Nc:: Union{Int,AbstractFieldData} = 1 ;
168- component_names:: Union{AbstractVector,Nothing} = nothing )
167+ Nc:: Union{Int,AbstractFieldData} = 1 ;
168+ component_names = nothing )
169169 xDA = new_child (xParent, xml_data_array_name (data))
170170 set_attribute (xDA, " type" , datatype_str (data))
171171 set_attribute (xDA, " Name" , name)
@@ -322,14 +322,16 @@ function data_to_xml_ascii(vtk::VTKFile, xDA::XMLElement, data)
322322end
323323
324324"""
325- add_field_data(vtk::DatasetFile, data,
326- name::AbstractString, loc::AbstractFieldData)
325+ add_field_data(
326+ vtk::DatasetFile, data, name::AbstractString, loc::AbstractFieldData;
327+ component_names = nothing,
328+ )
327329
328330Add either point or cell data to VTK file.
329331"""
330332function add_field_data (vtk:: VTKFile , data, name:: AbstractString ,
331333 loc:: AbstractFieldData ;
332- component_names:: Union{AbstractVector, Nothing} = nothing )
334+ component_names = nothing )
333335 xbase = find_base_xml_node_to_add_field (vtk, loc)
334336
335337 # Find or create "nodetype" (PointData, CellData or FieldData) node.
@@ -360,19 +362,23 @@ vtk_cell_data(args...; kwargs...) = add_field_data(args..., VTKCellData(); kwarg
360362vtk_field_data (args... ; kwargs... ) = add_field_data (args... , VTKFieldData (); kwargs... )
361363
362364"""
363- setindex!(vtk::DatasetFile, data, name::AbstractString, [field_type])
365+ setindex!(vtk::DatasetFile, data, name::AbstractString, [field_type]; [component_names] )
364366
365367Add a new dataset to VTK file.
366368
367369The number of components of the dataset (e.g. for scalar or vector fields) is
368370determined automatically from the input data dimensions.
369371
370- The optional argument `field_type` should be an instance of `VTKPointData`,
372+ The optional `field_type` argument should be an instance of `VTKPointData`,
371373`VTKCellData` or `VTKFieldData`.
372374It determines whether the data should be associated to grid points, cells or
373375none.
374376If not given, this is guessed from the input data size and the grid dimensions.
375377
378+ The optional `component_names` keyword argument allows to override the default component
379+ names when writing vector or tensor fields. It should be a tuple or a vector of strings (see
380+ below for an example).
381+
376382# Example
377383
378384Add "velocity" dataset and time scalar to VTK file.
@@ -382,20 +388,27 @@ vel = rand(3, 12, 14, 42) # vector field
382388time = 42.0
383389
384390vtk = vtk_grid(...)
385- vtk["velocity", VTKPointData()] = vel
391+ vtk["velocity", VTKPointData(), component_names = ("Ux", "Uy", "Uz") ] = vel
386392vtk["time", VTKFieldData()] = time
387393
388394# This also works, and will generally give the same result:
389- vtk["velocity"] = vel
395+ vtk["velocity", component_names = ("Ux", "Uy", "Uz") ] = vel
390396vtk["time"] = time
391397```
392398"""
393- Base. setindex! (vtk:: DatasetFile , data, name:: AbstractString ,
394- loc:: AbstractFieldData ; kwargs... ) = add_field_data (vtk, data, name, loc; kwargs... )
399+ function Base. setindex! (
400+ vtk:: DatasetFile , data, name:: AbstractString , loc:: AbstractFieldData ;
401+ component_names:: Union{Nothing, ListOfStrings} = nothing ,
402+ )
403+ add_field_data (vtk, data, name, loc; component_names = component_names)
404+ end
395405
396- function Base. setindex! (vtk:: DatasetFile , data, name:: AbstractString ; kwargs... )
397- loc = guess_data_location (data, vtk) :: AbstractFieldData
398- setindex! (vtk, data, name, loc; kwargs... )
406+ function Base. setindex! (
407+ vtk:: DatasetFile , data, name:: AbstractString ;
408+ component_names:: Union{Nothing, ListOfStrings} = nothing
409+ )
410+ loc = guess_data_location (data, vtk):: AbstractFieldData
411+ setindex! (vtk, data, name, loc; component_names = component_names)
399412end
400413
401414"""
0 commit comments