@@ -4,7 +4,9 @@ using OceanBioME.Particles: BiogeochemicalParticles
44
55import OceanBioME. Particles: required_particle_fields,
66 required_tracers,
7- coupled_tracers
7+ coupled_tracers,
8+ buffer_variables,
9+ compute_buffer_variable
810
911import OceanBioME: required_biogeochemical_tracers,
1012 required_biogeochemical_auxiliary_fields
136138 @test all (particles. fields. A .≈ 0.1 )
137139
138140 @test interior (model. tracers. B, 1 , 1 , 3 ) .≈ 0.8
139- end
141+ end
142+
143+
144+ struct SimpleParticleBiogeochemistryWithBuffer end
145+
146+ @inline (:: SimpleParticleBiogeochemistryWithBuffer )(:: Val{:A} , t, A, B, buffer_var) = one (t) + buffer_var
147+ @inline (:: SimpleParticleBiogeochemistryWithBuffer )(:: Val{:B} , t, A, B, buffer_var) = buffer_var
148+ @inline compute_buffer_variable (:: Val{:buffer_var} , :: SimpleParticleBiogeochemistryWithBuffer , B) = 1.0
149+
150+ @inline required_particle_fields (:: SimpleParticleBiogeochemistryWithBuffer ) = (:A , )
151+
152+ @inline required_tracers (:: SimpleParticleBiogeochemistryWithBuffer ) = (:B ,)
153+ @inline coupled_tracers (:: SimpleParticleBiogeochemistryWithBuffer ) = (:B ,)
154+ @inline buffer_variables (:: SimpleParticleBiogeochemistryWithBuffer ) = (:buffer_var ,)
155+
156+ @testset " Testing particles with model using buffer variables" begin
157+ # Since the buffer is used for both tracer and fields tendency
158+ # we need to have both in the model
159+ particle_biogeochemistry = SimpleParticleBiogeochemistryWithBuffer ()
160+
161+ particles = BiogeochemicalParticles (3 ; grid,
162+ biogeochemistry = particle_biogeochemistry,
163+ advection = nothing )
164+
165+ biogeochemistry = Biogeochemistry (NothingBiogeochemistry (); particles)
166+
167+
168+ model = NonhydrostaticModel (; grid, biogeochemistry, tracers = :B )
169+
170+ set! (model, B = 0.2 )
171+
172+ # since the 0, 0, 0 point is ambigously closest to both 3, 3, 3 and 1, 1, 3 (and the logic makes it go to 3, 3, 3)
173+ set! (particles, x = 0.5 , y = 0.5 )
174+ set! (particles, A = 0.5 )
175+
176+ time_step! (model, 1 )
177+
178+ @test all (particles. fields. A .≈ 2.5 )
179+
180+ @test interior (model. tracers. B, 1 , 1 , 3 ) .≈ 3.2 # 0.2 + 3 * 1 (there are 3 particles)
181+
182+ end
0 commit comments