From 57411f0d28c32e78d666bf942f88361896cfacd3 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Wed, 6 Sep 2023 13:11:51 -0700 Subject: [PATCH] Test that set_precomputed_quantities is idempotent --- src/cache/precomputed_quantities.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cache/precomputed_quantities.jl b/src/cache/precomputed_quantities.jl index 4014011e23b..271ab9737d7 100644 --- a/src/cache/precomputed_quantities.jl +++ b/src/cache/precomputed_quantities.jl @@ -276,6 +276,21 @@ function instead of recomputing the value yourself. Otherwise, it will be difficult to ensure that the duplicated computations are consistent. """ function set_precomputed_quantities!(Y, p, t) + _Y = deepcopy(Y) + _p = deepcopy(p) + _set_precomputed_quantities!(_Y, _p, t) + Y1 = deepcopy(_Y) + _set_precomputed_quantities!(_Y, _p, t) + Y2 = deepcopy(_Y) + @test alleqeq(Y1, Y2) + + _set_precomputed_quantities!(Y, p, t) +end +using Test +alleqeq(a::Fields.FieldVector, b::Fields.FieldVector) = + all(x -> x[1] == x[2], zip(Fields._values(a), Fields._values(b))) + +function _set_precomputed_quantities!(Y, p, t) (; energy_form, moisture_model, turbconv_model) = p.atmos thermo_params = CAP.thermodynamics_params(p.params) n = n_mass_flux_subdomains(turbconv_model)