Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update model interface for optimal filter #145

Merged
merged 5 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ be used by [`run_particle_filter`](@ref):
ParticleDA.get_particles
ParticleDA.get_truth
ParticleDA.update_truth!
ParticleDA.update_particles!
ParticleDA.update_particle_dynamics!
ParticleDA.update_particle_noise!
ParticleDA.get_particle_observations!
ParticleDA.write_snapshot
```

Expand Down
30 changes: 25 additions & 5 deletions src/ParticleDA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,32 @@ above signature, specifying the type of `model_data`.
function update_truth! end

"""
ParticleDA.update_particles!(model_data, nprt_per_rank::Int) -> particles_observations
ParticleDA.update_particle_dynamics!(model_data, nprt_per_rank::Int)

Update the particles using the dynamic of the model and return the vector of the
Update the particles using the dynamic of the model. `nprt_per_rank` is the
number of particles per each MPI rank. This method is intended to be extended
by the user with the above signature, specifying the type of `model_data`.
"""
function update_particle_dynamics! end

"""
ParticleDA.update_particle_noise!(model_data, nprt_per_rank::Int)

Update the particles using the noise of the model and return the vector of the
particles. `nprt_per_rank` is the number of particles per each MPI rank. This
method is intended to be extended by the user with the above signature,
specifying the type of `model_data`.
"""
function update_particles! end
function update_particle_noise! end

"""
ParticleDA.get_particle_observations!(model_data, nprt_per_rank::Int) -> particles_observations

Return the vector of the particles observations. `nprt_per_rank` is the number
of particles per each MPI rank. This method is intended to be extended by the
user with the above signature, specifying the type of `model_data`.
"""
function get_particle_observations! end

"""
ParticleDA.write_snapshot(output_filename, model_data, avg_arr, var_arr, weights, it)
Expand Down Expand Up @@ -325,9 +343,11 @@ function run_particle_filter(init, filter_params::FilterParameters, model_params
# Forecast: Update tsunami forecast and get observations from it
# Parallelised with threads.

@timeit_debug timer "Particle State Update and Process Noise" model_observations = update_particles!(model_data, nprt_per_rank)
@timeit_debug timer "Particle Dynamics" update_particle_dynamics!(model_data, nprt_per_rank);
@timeit_debug timer "Particle Noise" update_particle_noise!(model_data, nprt_per_rank)
@timeit_debug timer "Particle Observations" model_observations = get_particle_observations!(model_data, nprt_per_rank)

@timeit_debug timer "Weights" get_log_weights!(@view(filter_data.weights[1:nprt_per_rank]),
@timeit_debug timer "Particle Weights" get_log_weights!(@view(filter_data.weights[1:nprt_per_rank]),
truth_observations,
model_observations,
filter_params.weight_std)
Expand Down
9 changes: 7 additions & 2 deletions test/model/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,20 +455,25 @@ function ParticleDA.update_truth!(d::ModelData, _)
return d.observations.truth
end

function ParticleDA.update_particles!(d::ModelData, nprt_per_rank)
function ParticleDA.update_particle_dynamics!(d::ModelData, nprt_per_rank)
# Update dynamics
Threads.@threads for ip in 1:nprt_per_rank
tsunami_update!(@view(d.field_buffer[:, :, 1, threadid()]), @view(d.field_buffer[:, :, 2, threadid()]),
@view(d.states.particles[:, :, :, ip]), d.model_matrices, d.model_params)

end
end

function ParticleDA.update_particle_noise!(d::ModelData, nprt_per_rank)
# Add process noise
add_random_field!(d.states.particles,
d.field_buffer,
d.background_grf,
d.rng,
d.model_params.n_state_var,
nprt_per_rank)
end

function ParticleDA.get_particle_observations!(d::ModelData, nprt_per_rank)
# get observations
for ip in 1:nprt_per_rank
get_obs!(@view(d.observations.model[:,ip]),
Expand Down