@@ -48,15 +48,27 @@ trixi2vtk(sol.u[end], semi, 0.0, iter=1, my_custom_quantity=kinetic_energy)
4848
4949```
5050"""
51- function trixi2vtk (vu_ode, semi, t; iter= nothing , output_directory= " out" , prefix= " " ,
52- write_meta_data= true , git_hash= compute_git_hash (),
51+ function trixi2vtk (vu_ode, semi, t; iter= nothing , output_directory= " out" ,
52+ prefix= " " , write_meta_data= true , git_hash= compute_git_hash (),
53+ max_coordinates= Inf , custom_quantities... )
54+
55+ # The first argument is not necessary in most cases. Since it is usually not available to the user,
56+ # this API wrapper makes it optional.
57+ # Note that custom quantities using the fluid acceleration will not work and return NaN acceleration.
58+ return trixi2vtk (fill! (similar (vu_ode), NaN ), vu_ode, semi, t; iter, output_directory,
59+ prefix, write_meta_data, git_hash, max_coordinates,
60+ custom_quantities... )
61+ end
62+
63+ function trixi2vtk (dvdu_ode, vu_ode, semi, t; iter= nothing , output_directory= " out" ,
64+ prefix= " " , write_meta_data= true , git_hash= compute_git_hash (),
5365 max_coordinates= Inf , custom_quantities... )
5466 (; systems) = semi
55- v_ode, u_ode = vu_ode. x
5667
5768 # Update quantities that are stored in the systems. These quantities (e.g. pressure)
5869 # still have the values from the last stage of the previous step if not updated here.
5970 @trixi_timeit timer () " update systems" begin
71+ v_ode, u_ode = vu_ode. x
6072 # Don't create sub-timers here to avoid cluttering the timer output
6173 @notimeit timer () update_systems_and_nhs (v_ode, u_ode, semi, t)
6274 end
@@ -67,24 +79,26 @@ function trixi2vtk(vu_ode, semi, t; iter=nothing, output_directory="out", prefix
6779 system_index = system_indices (system, semi)
6880 periodic_box = get_neighborhood_search (system, semi). periodic_box
6981
70- trixi2vtk (system, v_ode, u_ode , semi, t, periodic_box;
82+ trixi2vtk (system, dvdu_ode, vu_ode , semi, t, periodic_box;
7183 system_name= filenames[system_index], output_directory, iter, prefix,
7284 write_meta_data, git_hash, max_coordinates, custom_quantities... )
7385 end
7486end
7587
7688# Convert data for a single TrixiParticle system to VTK format
77- function trixi2vtk (system_, v_ode_, u_ode_ , semi_, t, periodic_box; output_directory = " out " ,
78- prefix = " " , iter = nothing , system_name = vtkname (system_) ,
79- write_meta_data= true , max_coordinates= Inf , git_hash = compute_git_hash () ,
80- custom_quantities... )
89+ function trixi2vtk (system_, dvdu_ode_, vu_ode_ , semi_, t, periodic_box;
90+ output_directory = " out " , prefix = " " , iter = nothing ,
91+ system_name = vtkname (system_), write_meta_data= true , max_coordinates= Inf ,
92+ git_hash = compute_git_hash (), custom_quantities... )
8193 mkpath (output_directory)
8294
8395 # Skip empty systems
8496 if nparticles (system_) == 0
8597 return
8698 end
8799
100+ v_ode_, u_ode_ = vu_ode_. x
101+
88102 # Transfer to CPU if data is on the GPU. Do nothing if already on CPU.
89103 v_ode, u_ode, system, semi = transfer2cpu (v_ode_, u_ode_, system_, semi_)
90104
@@ -136,10 +150,16 @@ function trixi2vtk(system_, v_ode_, u_ode_, semi_, t, periodic_box; output_direc
136150 end
137151
138152 # Extract custom quantities for this system
139- for (key, quantity) in custom_quantities
140- value = custom_quantity (quantity, system, v_ode, u_ode, semi, t)
141- if value != = nothing
142- vtk[string (key)] = value
153+ if ! isempty (custom_quantities)
154+ dv_ode, du_ode = dvdu_ode_. x
155+ dv_ode, du_ode = transfer2cpu (dv_ode, du_ode)
156+
157+ for (key, quantity) in custom_quantities
158+ value = custom_quantity (quantity, system, dv_ode, du_ode, v_ode, u_ode,
159+ semi, t)
160+ if value != = nothing
161+ vtk[string (key)] = value
162+ end
143163 end
144164 end
145165
@@ -150,33 +170,45 @@ function trixi2vtk(system_, v_ode_, u_ode_, semi_, t, periodic_box; output_direc
150170end
151171
152172function transfer2cpu (v_:: AbstractGPUArray , u_, system_, semi_)
153- v = Adapt. adapt (Array, v_)
154- u = Adapt. adapt (Array, u_)
155173 semi = Adapt. adapt (Array, semi_)
156174 system_index = system_indices (system_, semi_)
157175 system = semi. systems[system_index]
158176
177+ v, u = transfer2cpu (v_, u_)
178+
159179 return v, u, system, semi
160180end
161181
162182function transfer2cpu (v_, u_, system_, semi_)
163183 return v_, u_, system_, semi_
164184end
165185
166- function custom_quantity (quantity:: AbstractArray , system, v_ode, u_ode, semi, t)
186+ function transfer2cpu (v_:: AbstractGPUArray , u_)
187+ v = Adapt. adapt (Array, v_)
188+ u = Adapt. adapt (Array, u_)
189+
190+ return v, u
191+ end
192+
193+ function transfer2cpu (v_, u_)
194+ return v_, u_
195+ end
196+
197+ function custom_quantity (quantity:: AbstractArray , system, dv_ode, du_ode, v_ode, u_ode,
198+ semi, t)
167199 return quantity
168200end
169201
170- function custom_quantity (quantity, system, v_ode, u_ode, semi, t)
202+ function custom_quantity (quantity, system, dv_ode, du_ode, v_ode, u_ode, semi, t)
171203 # Check if `quantity` is a function of `system`, `v_ode`, `u_ode`, `semi` and `t`
172204 if ! isempty (methods (quantity,
173- (typeof (system), typeof (v_ode ), typeof (u_ode ),
174- typeof (semi), typeof (t))))
175- return quantity (system, v_ode, u_ode, semi, t)
205+ (typeof (system), typeof (dv_ode ), typeof (du_ode), typeof (v_ode ),
206+ typeof (u_ode), typeof ( semi), typeof (t))))
207+ return quantity (system, dv_ode, du_ode, v_ode, u_ode, semi, t)
176208 end
177209
178210 # Assume `quantity` is a function of `data`
179- data = system_data (system, v_ode, u_ode, semi)
211+ data = system_data (system, dv_ode, du_ode, v_ode, u_ode, semi)
180212 return quantity (system, data, t)
181213end
182214
0 commit comments