Skip to content

Commit

Permalink
Bugfix on FieldTimeSeries interpolation (#3558)
Browse files Browse the repository at this point in the history
* bugfix

* adding times

* better implementation

* adding an explicit Int64

* Update src/OutputReaders/field_time_series_indexing.jl

Co-authored-by: Gregory L. Wagner <[email protected]>

* Update src/OutputReaders/field_time_series_indexing.jl

Co-authored-by: Gregory L. Wagner <[email protected]>

---------

Co-authored-by: Gregory L. Wagner <[email protected]>
  • Loading branch information
simone-silvestri and glwagner committed Apr 23, 2024
1 parent b8d23f7 commit 18c67c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/OutputReaders/field_time_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@ instantiate(T::Type) = T()

new_data(FT, grid, loc, indices, ::Nothing) = nothing

function new_data(FT, grid, loc, indices, Nt::Int)
# Apparently, not explicitly specifying Int64 in here makes this function
# fail on x86 processors where `Int` is implied to be `Int32`
# see ClimaOcean commit 3c47d887659d81e0caed6c9df41b7438e1f1cd52 at https://github.com/CliMA/ClimaOcean.jl/actions/runs/8804916198/job/24166354095)
function new_data(FT, grid, loc, indices, Nt::Union{Int, Int64})
space_size = total_size(grid, loc, indices)
underlying_data = zeros(FT, architecture(grid), space_size..., Nt)
data = offset_data(underlying_data, grid, loc, indices)
Expand Down
13 changes: 7 additions & 6 deletions src/OutputReaders/field_time_series_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,27 +198,28 @@ function interpolate!(target_fts::FieldTimeSeries, source_fts::FieldTimeSeries)
source_location = map(instantiate, location(source_fts))
target_location = map(instantiate, location(target_fts))

target_times = map(Time, target_fts.times)

launch!(arch, target_grid, size(target_fts),
_interpolate_field_time_series!,
target_fts.data, target_grid, target_location,
source_fts.data, source_grid, source_location)
target_fts.data, target_grid, target_location, target_times,
source_fts, source_grid, source_location)

fill_halo_regions!(target_fts)

return nothing
end

@kernel function _interpolate_field_time_series!(target_fts, target_grid, target_location,
@kernel function _interpolate_field_time_series!(target_fts, target_grid, target_location, target_times,
source_fts, source_grid, source_location)

# 4D index, cool!
i, j, k, n = @index(Global, NTuple)

source_field = view(source_fts, :, :, :, n)
target_node = node(i, j, k, target_grid, target_location...)
target_time = @inbounds target_fts.times[n]
at_time = @inbounds target_times[n]

@inbounds target_fts[i, j, k, n] = interpolate(target_node, target_time,
@inbounds target_fts[i, j, k, n] = interpolate(target_node, at_time,
source_fts, source_location, source_grid)
end

Expand Down

0 comments on commit 18c67c8

Please sign in to comment.