Skip to content

Commit e1e139c

Browse files
committed
add error when using tuples as fields and writing ASAGI
1 parent 16e5814 commit e1e139c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/IO_ASAGI.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,19 @@ function fields_to_namedtuple(fields::NamedTuple, selected_fields)
8888
ndim = length(size(fields[1]))
8989

9090
s2 = NamedTuple{names}(zeros(nfield))
91-
91+
92+
# check that they are all DiskArrays
93+
for ifield in 1:nfield
94+
if !isa(getproperty(fields,names[ifield]), Array)
95+
@show typeof(getproperty(fields,names[ifield]))
96+
error("Field $(names[ifield]) is not an Array but instead a $(typeof(getproperty(fields,names[ifield]))); only Arrays are supported")
97+
end
98+
end
99+
92100
material = Array{typeof(s2),ndim}(undef, size(fields[1]))
93101
for I in eachindex(material)
94102
data_local = []
95103
for ifield in 1:nfield
96-
97104
push!(data_local,getproperty(fields,names[ifield])[I])
98105

99106
end
@@ -167,6 +174,7 @@ function read_ASAGI(fname_asagi::String)
167174
read_fields_data = ()
168175
for ifield=1:numfields
169176
data_1 = zeros(types[ifield],nx,ny,nz)
177+
170178
for I in CartesianIndices(data)
171179
loc = data[I]
172180
data_1[I] = getproperty(loc, cnames[ifield])

test/test_ASAGI_IO.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ fname_asagi = write_ASAGI("test", Data, (:Sxx,))
2727
Data_ASAGI2 = read_ASAGI(fname_asagi)
2828
@test sum(Data_ASAGI2.fields.Sxx - Data.fields.Sxx) == 0
2929

30-
fname_asagi = write_ASAGI("test", Data_tuple)
30+
# test that it errors if we use a tuple with non-scalar fields
31+
@test_throws "Field Stress is not an Array but instead a NTuple{9, Array{Float64, 3}}; only Arrays are supported" write_ASAGI("test", Data_tuple)
3132

3233
# Cleanup
3334
foreach(rm, filter(endswith(".nc"), readdir()))

0 commit comments

Comments
 (0)