xref: /honee/src/differential_filter.c (revision fff85bd3a0c82b434cd3f01285a22a362dfa8070)
1 // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2 // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
3 /// @file
4 /// Functions for setting up and performing differential filtering
5 
6 #include "../qfunctions/differential_filter.h"
7 #include <ceed.h>
8 
9 #include <petscdmplex.h>
10 
11 #include <navierstokes.h>
12 
13 // @brief Create RHS and LHS operators for differential filtering
14 PetscErrorCode DifferentialFilterCreateOperators(Ceed ceed, Honee honee, CeedQFunctionContext diff_filter_qfctx) {
15   DiffFilterData      diff_filter = honee->diff_filter;
16   DM                  dm_filter   = diff_filter->dm_filter;
17   CeedInt             num_comp_q, q_data_size, num_comp_x;
18   PetscInt            dim;
19   CeedVector          q_data;
20   CeedElemRestriction elem_restr_qd;
21   DMLabel             domain_label = NULL;
22   PetscInt            label_value = 0, height = 0;
23 
24   PetscFunctionBeginUser;
25   PetscCall(DMGetDimension(honee->dm, &dim));
26   PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(honee->elem_restr_x, &num_comp_x));
27   PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(honee->elem_restr_q, &num_comp_q));
28 
29   PetscCall(QDataGet(ceed, dm_filter, domain_label, label_value, honee->elem_restr_x, honee->basis_x, honee->x_coord, &elem_restr_qd, &q_data,
30                      &q_data_size));
31 
32   {  // -- Create RHS MatopApplyContext
33     CeedQFunction qf_rhs;
34     CeedOperator  op_rhs;
35     switch (honee->phys->state_var) {
36       case STATEVAR_PRIMITIVE:
37         PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_RHS_Prim, DifferentialFilter_RHS_Prim_loc, &qf_rhs));
38         break;
39       case STATEVAR_CONSERVATIVE:
40         PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_RHS_Conserv, DifferentialFilter_RHS_Conserv_loc, &qf_rhs));
41         break;
42       case STATEVAR_ENTROPY:
43         PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_RHS_Entropy, DifferentialFilter_RHS_Entropy_loc, &qf_rhs));
44         break;
45     }
46     if (diff_filter->do_mms_test) {
47       PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_rhs));
48       PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_MMS_RHS, DifferentialFilter_MMS_RHS_loc, &qf_rhs));
49     }
50 
51     PetscCallCeed(ceed, CeedQFunctionSetContext(qf_rhs, diff_filter_qfctx));
52     PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs, "q", num_comp_q, CEED_EVAL_INTERP));
53     PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs, "qdata", q_data_size, CEED_EVAL_NONE));
54     PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs, "x", num_comp_x, CEED_EVAL_INTERP));
55     for (PetscInt i = 0; i < diff_filter->num_filtered_fields; i++) {
56       char field_name[PETSC_MAX_PATH_LEN];
57 
58       PetscCall(PetscSNPrintf(field_name, PETSC_MAX_PATH_LEN, "v%" PetscInt_FMT, i));
59       PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_rhs, field_name, diff_filter->num_field_components[i], CEED_EVAL_INTERP));
60     }
61 
62     PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_rhs, NULL, NULL, &op_rhs));
63     PetscCallCeed(ceed, CeedOperatorSetField(op_rhs, "q", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE));
64     PetscCallCeed(ceed, CeedOperatorSetField(op_rhs, "qdata", elem_restr_qd, CEED_BASIS_NONE, q_data));
65     PetscCallCeed(ceed, CeedOperatorSetField(op_rhs, "x", honee->elem_restr_x, honee->basis_x, honee->x_coord));
66     for (PetscInt dm_field = 0; dm_field < diff_filter->num_filtered_fields; dm_field++) {
67       char                field_name[PETSC_MAX_PATH_LEN];
68       CeedElemRestriction elem_restr_filter;
69       CeedBasis           basis_filter;
70 
71       PetscCall(DMPlexCeedElemRestrictionCreate(ceed, dm_filter, domain_label, label_value, height, dm_field, &elem_restr_filter));
72       PetscCall(CreateBasisFromPlex(ceed, dm_filter, domain_label, label_value, height, dm_field, &basis_filter));
73 
74       PetscCall(PetscSNPrintf(field_name, PETSC_MAX_PATH_LEN, "v%" PetscInt_FMT, dm_field));
75       PetscCallCeed(ceed, CeedOperatorSetField(op_rhs, field_name, elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE));
76 
77       PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_filter));
78       PetscCallCeed(ceed, CeedBasisDestroy(&basis_filter));
79     }
80 
81     PetscCall(OperatorApplyContextCreate(honee->dm, dm_filter, ceed, op_rhs, NULL, NULL, honee->Q_loc, NULL, &diff_filter->op_rhs_ctx));
82 
83     PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_rhs));
84     PetscCallCeed(ceed, CeedOperatorDestroy(&op_rhs));
85   }
86 
87   {  // Setup LHS Operator and KSP for the differential filtering solve
88     CeedOperator        op_lhs;
89     Mat                 mat_lhs;
90     PetscInt            dim, num_comp_grid_aniso;
91     CeedElemRestriction elem_restr_grid_aniso;
92     CeedVector          grid_aniso_ceed;
93 
94     PetscCall(DMGetDimension(honee->dm, &dim));
95     PetscCall(GridAnisotropyTensorCalculateCollocatedVector(ceed, honee, &elem_restr_grid_aniso, &grid_aniso_ceed, &num_comp_grid_aniso));
96 
97     PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, &op_lhs));
98     for (PetscInt i = 0; i < diff_filter->num_filtered_fields; i++) {
99       CeedQFunction       qf_lhs;
100       PetscInt            num_comp_filter = diff_filter->num_field_components[i];
101       CeedOperator        op_lhs_sub;
102       CeedElemRestriction elem_restr_filter;
103       CeedBasis           basis_filter;
104 
105       switch (num_comp_filter) {
106         case 1:
107           PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_1, DifferentialFilter_LHS_1_loc, &qf_lhs));
108           break;
109         case 5:
110           PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_5, DifferentialFilter_LHS_5_loc, &qf_lhs));
111           break;
112         case 6:
113           PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_6, DifferentialFilter_LHS_6_loc, &qf_lhs));
114           break;
115         case 11:
116           PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_11, DifferentialFilter_LHS_11_loc, &qf_lhs));
117           break;
118         default:
119           SETERRQ(PetscObjectComm((PetscObject)honee->dm), PETSC_ERR_SUP, "Differential filtering not available for (%" PetscInt_FMT ") components",
120                   num_comp_filter);
121       }
122 
123       PetscCallCeed(ceed, CeedQFunctionSetContext(qf_lhs, diff_filter_qfctx));
124       PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(qf_lhs, 0));
125       PetscCallCeed(ceed, CeedQFunctionAddInput(qf_lhs, "q", num_comp_filter, CEED_EVAL_INTERP));
126       PetscCallCeed(ceed, CeedQFunctionAddInput(qf_lhs, "Grad_q", num_comp_filter * dim, CEED_EVAL_GRAD));
127       PetscCallCeed(ceed, CeedQFunctionAddInput(qf_lhs, "anisotropy tensor", num_comp_grid_aniso, CEED_EVAL_NONE));
128       PetscCallCeed(ceed, CeedQFunctionAddInput(qf_lhs, "x", num_comp_x, CEED_EVAL_INTERP));
129       PetscCallCeed(ceed, CeedQFunctionAddInput(qf_lhs, "qdata", q_data_size, CEED_EVAL_NONE));
130       PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_lhs, "v", num_comp_filter, CEED_EVAL_INTERP));
131       PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_lhs, "Grad_v", num_comp_filter * dim, CEED_EVAL_GRAD));
132 
133       {
134         CeedOperatorField op_field;
135         char              field_name[PETSC_MAX_PATH_LEN];
136 
137         PetscCall(PetscSNPrintf(field_name, PETSC_MAX_PATH_LEN, "v%" PetscInt_FMT, i));
138         PetscCallCeed(ceed, CeedOperatorGetFieldByName(diff_filter->op_rhs_ctx->op, field_name, &op_field));
139         PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(op_field, &elem_restr_filter));
140         PetscCallCeed(ceed, CeedOperatorFieldGetBasis(op_field, &basis_filter));
141       }
142 
143       PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_lhs, NULL, NULL, &op_lhs_sub));
144       PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "q", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE));
145       PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "Grad_q", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE));
146       PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "anisotropy tensor", elem_restr_grid_aniso, CEED_BASIS_NONE, grid_aniso_ceed));
147       PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "x", honee->elem_restr_x, honee->basis_x, honee->x_coord));
148       PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "qdata", elem_restr_qd, CEED_BASIS_NONE, q_data));
149       PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "v", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE));
150       PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "Grad_v", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE));
151 
152       PetscCallCeed(ceed, CeedCompositeOperatorAddSub(op_lhs, op_lhs_sub));
153       PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_filter));
154       PetscCallCeed(ceed, CeedBasisDestroy(&basis_filter));
155       PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_lhs));
156       PetscCallCeed(ceed, CeedOperatorDestroy(&op_lhs_sub));
157     }
158     PetscCallCeed(ceed, CeedVectorDestroy(&grid_aniso_ceed));
159     PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_grid_aniso));
160 
161     PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(op_lhs, "filter width scaling", &diff_filter->filter_width_scaling_label));
162     PetscCall(MatCreateCeed(dm_filter, dm_filter, op_lhs, NULL, &mat_lhs));
163 
164     PetscCall(KSPCreate(PetscObjectComm((PetscObject)dm_filter), &diff_filter->ksp));
165     PetscCall(KSPSetOptionsPrefix(diff_filter->ksp, "diff_filter_"));
166     {
167       PC pc;
168       PetscCall(KSPGetPC(diff_filter->ksp, &pc));
169       PetscCall(PCSetType(pc, PCJACOBI));
170       PetscCall(PCJacobiSetType(pc, PC_JACOBI_DIAGONAL));
171       PetscCall(KSPSetType(diff_filter->ksp, KSPCG));
172       PetscCall(KSPSetNormType(diff_filter->ksp, KSP_NORM_NATURAL));
173       PetscCall(KSPSetTolerances(diff_filter->ksp, 1e-10, PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT));
174     }
175     PetscCall(KSPSetFromOptions_WithMatCeed(diff_filter->ksp, mat_lhs));
176 
177     PetscCall(MatDestroy(&mat_lhs));
178     PetscCallCeed(ceed, CeedOperatorDestroy(&op_lhs));
179   }
180 
181   PetscCallCeed(ceed, CeedVectorDestroy(&q_data));
182   PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd));
183   PetscFunctionReturn(PETSC_SUCCESS);
184 }
185 
186 // @brief Setup DM, operators, contexts, etc. for performing differential filtering
187 PetscErrorCode DifferentialFilterSetup(Ceed ceed, Honee honee, ProblemData problem) {
188   MPI_Comm                  comm = honee->comm;
189   NewtonianIdealGasContext  gas;
190   DifferentialFilterContext diff_filter_ctx;
191   CeedQFunctionContext      diff_filter_qfctx;
192 
193   PetscFunctionBeginUser;
194   PetscCall(PetscNew(&honee->diff_filter));
195   DiffFilterData diff_filter = honee->diff_filter;
196   PetscCall(PetscOptionsGetBool(NULL, NULL, "-diff_filter_mms", &diff_filter->do_mms_test, NULL));
197 
198   {  // Create DM for filtered quantities
199     PetscSection section;
200 
201     PetscCall(DMClone(honee->dm, &diff_filter->dm_filter));
202     PetscCall(DMSetMatrixPreallocateSkip(diff_filter->dm_filter, PETSC_TRUE));
203     PetscCall(PetscObjectSetName((PetscObject)diff_filter->dm_filter, "Differential Filtering"));
204 
205     diff_filter->num_filtered_fields = diff_filter->do_mms_test ? 1 : 2;
206     PetscCall(PetscMalloc1(diff_filter->num_filtered_fields, &diff_filter->num_field_components));
207 
208     if (diff_filter->do_mms_test) {
209       PetscInt field_components;
210       diff_filter->num_field_components[0] = field_components = 1;
211       PetscCall(DMSetupByOrder_FEM(PETSC_TRUE, PETSC_TRUE, honee->app_ctx->degree, 1, honee->app_ctx->q_extra, diff_filter->num_filtered_fields,
212                                    &field_components, diff_filter->dm_filter));
213 
214       PetscCall(DMGetLocalSection(diff_filter->dm_filter, &section));
215       PetscCall(PetscSectionSetFieldName(section, 0, ""));
216       PetscCall(PetscSectionSetComponentName(section, 0, 0, "FilteredPhi"));
217     } else {
218       PetscInt field_components[2];
219       diff_filter->num_field_components[0] = field_components[0] = DIFF_FILTER_STATE_NUM;
220       diff_filter->num_field_components[1] = field_components[1] = DIFF_FILTER_VELOCITY_SQUARED_NUM;
221       PetscCall(DMSetupByOrder_FEM(PETSC_TRUE, PETSC_TRUE, honee->app_ctx->degree, 1, honee->app_ctx->q_extra, diff_filter->num_filtered_fields,
222                                    field_components, diff_filter->dm_filter));
223 
224       diff_filter->field_prim_state = 0;
225       diff_filter->field_velo_prod  = 1;
226       PetscCall(DMGetLocalSection(diff_filter->dm_filter, &section));
227       PetscCall(PetscSectionSetFieldName(section, diff_filter->field_prim_state, "Filtered Primitive State Variables"));
228       PetscCall(PetscSectionSetComponentName(section, 0, DIFF_FILTER_PRESSURE, "FilteredPressure"));
229       PetscCall(PetscSectionSetComponentName(section, 0, DIFF_FILTER_VELOCITY_X, "FilteredVelocityX"));
230       PetscCall(PetscSectionSetComponentName(section, 0, DIFF_FILTER_VELOCITY_Y, "FilteredVelocityY"));
231       PetscCall(PetscSectionSetComponentName(section, 0, DIFF_FILTER_VELOCITY_Z, "FilteredVelocityZ"));
232       PetscCall(PetscSectionSetComponentName(section, 0, DIFF_FILTER_TEMPERATURE, "FilteredTemperature"));
233       PetscCall(PetscSectionSetFieldName(section, diff_filter->field_velo_prod, "Filtered Velocity Products"));
234       PetscCall(PetscSectionSetComponentName(section, 1, DIFF_FILTER_VELOCITY_SQUARED_XX, "FilteredVelocitySquaredXX"));
235       PetscCall(PetscSectionSetComponentName(section, 1, DIFF_FILTER_VELOCITY_SQUARED_YY, "FilteredVelocitySquaredYY"));
236       PetscCall(PetscSectionSetComponentName(section, 1, DIFF_FILTER_VELOCITY_SQUARED_ZZ, "FilteredVelocitySquaredZZ"));
237       PetscCall(PetscSectionSetComponentName(section, 1, DIFF_FILTER_VELOCITY_SQUARED_YZ, "FilteredVelocitySquaredYZ"));
238       PetscCall(PetscSectionSetComponentName(section, 1, DIFF_FILTER_VELOCITY_SQUARED_XZ, "FilteredVelocitySquaredXZ"));
239       PetscCall(PetscSectionSetComponentName(section, 1, DIFF_FILTER_VELOCITY_SQUARED_XY, "FilteredVelocitySquaredXY"));
240     }
241   }
242 
243   PetscCall(PetscNew(&diff_filter_ctx));
244   diff_filter_ctx->grid_based_width = false;
245   for (int i = 0; i < 3; i++) diff_filter_ctx->width_scaling[i] = 1;
246   diff_filter_ctx->kernel_scaling   = 0.1;
247   diff_filter_ctx->damping_function = DIFF_FILTER_DAMP_NONE;
248   diff_filter_ctx->friction_length  = 0;
249   diff_filter_ctx->damping_constant = 25;
250 
251   PetscOptionsBegin(comm, NULL, "Differential Filtering Options", NULL);
252   PetscInt narray = 3;
253   PetscCall(PetscOptionsBool("-diff_filter_grid_based_width", "Use filter width based on the grid size", NULL, diff_filter_ctx->grid_based_width,
254                              (PetscBool *)&diff_filter_ctx->grid_based_width, NULL));
255   PetscCall(PetscOptionsRealArray("-diff_filter_width_scaling", "Anisotropic scaling of filter width tensor", NULL, diff_filter_ctx->width_scaling,
256                                   &narray, NULL));
257   PetscCall(PetscOptionsReal("-diff_filter_kernel_scaling", "Scaling to make differential kernel size \"equivalent\" to other filter kernels", NULL,
258                              diff_filter_ctx->kernel_scaling, &diff_filter_ctx->kernel_scaling, NULL));
259   PetscCall(PetscOptionsEnum("-diff_filter_wall_damping_function", "Damping function to use at the wall", NULL, DifferentialFilterDampingFunctions,
260                              (PetscEnum)(diff_filter_ctx->damping_function), (PetscEnum *)&diff_filter_ctx->damping_function, NULL));
261   PetscCall(PetscOptionsReal("-diff_filter_wall_damping_constant", "Contant for the wall-damping function", NULL, diff_filter_ctx->damping_constant,
262                              &diff_filter_ctx->damping_constant, NULL));
263   PetscCall(PetscOptionsReal("-diff_filter_friction_length", "Friction length associated with the flow, \\delta_\\nu. For wall-damping functions",
264                              NULL, diff_filter_ctx->friction_length, &diff_filter_ctx->friction_length, NULL));
265   PetscOptionsEnd();
266 
267   Units units = honee->units;
268   for (int i = 0; i < 3; i++) diff_filter_ctx->width_scaling[i] *= units->meter;
269   diff_filter_ctx->kernel_scaling *= units->meter;
270   diff_filter_ctx->friction_length *= units->meter;
271 
272   // -- Create QFContext
273   PetscCallCeed(ceed, CeedQFunctionContextGetDataRead(problem->apply_vol_ifunction.qfctx, CEED_MEM_HOST, &gas));
274   diff_filter_ctx->gas = *gas;
275   PetscCallCeed(ceed, CeedQFunctionContextRestoreDataRead(problem->apply_vol_ifunction.qfctx, &gas));
276 
277   PetscCallCeed(ceed, CeedQFunctionContextCreate(ceed, &diff_filter_qfctx));
278   PetscCallCeed(ceed, CeedQFunctionContextSetData(diff_filter_qfctx, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*diff_filter_ctx), diff_filter_ctx));
279   PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(diff_filter_qfctx, CEED_MEM_HOST, FreeContextPetsc));
280   PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(
281                           diff_filter_qfctx, "filter width scaling", offsetof(struct DifferentialFilterContext_, width_scaling),
282                           sizeof(diff_filter_ctx->width_scaling) / sizeof(diff_filter_ctx->width_scaling[0]), "Filter width scaling"));
283 
284   // -- Setup Operators
285   PetscCall(DifferentialFilterCreateOperators(ceed, honee, diff_filter_qfctx));
286 
287   PetscCallCeed(ceed, CeedQFunctionContextDestroy(&diff_filter_qfctx));
288   PetscFunctionReturn(PETSC_SUCCESS);
289 }
290 
291 // @brief Apply differential filter to the solution given by Q
292 PetscErrorCode DifferentialFilterApply(Honee honee, const PetscReal solution_time, const Vec Q, Vec Filtered_Solution) {
293   DiffFilterData   diff_filter = honee->diff_filter;
294   PetscObjectState X_loc_state;
295   Vec              RHS;
296 
297   PetscFunctionBeginUser;
298   PetscCall(PetscLogEventBegin(FLUIDS_DifferentialFilter, Q, Filtered_Solution, 0, 0));
299   PetscCall(DMGetNamedGlobalVector(diff_filter->dm_filter, "RHS", &RHS));
300   PetscCall(UpdateBoundaryValues(honee, diff_filter->op_rhs_ctx->X_loc, solution_time));
301   PetscCall(VecGetState(diff_filter->op_rhs_ctx->X_loc, &X_loc_state));
302   if (X_loc_state != diff_filter->X_loc_state) {
303     PetscCall(ApplyCeedOperatorGlobalToGlobal(Q, RHS, diff_filter->op_rhs_ctx));
304     PetscCall(VecGetState(diff_filter->op_rhs_ctx->X_loc, &X_loc_state));
305     diff_filter->X_loc_state = X_loc_state;
306   }
307   PetscCall(VecViewFromOptions(RHS, NULL, "-diff_filter_rhs_view"));
308 
309   PetscCall(KSPSolve(diff_filter->ksp, RHS, Filtered_Solution));
310   PetscCall(DMRestoreNamedGlobalVector(diff_filter->dm_filter, "RHS", &RHS));
311   PetscCall(PetscLogEventEnd(FLUIDS_DifferentialFilter, Q, Filtered_Solution, 0, 0));
312   PetscFunctionReturn(PETSC_SUCCESS);
313 }
314 
315 // @brief TSMonitor for just applying differential filtering to the simulation
316 // This runs every time step and is primarily for testing purposes
317 PetscErrorCode TSMonitor_DifferentialFilter(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, void *ctx) {
318   Honee          honee       = (Honee)ctx;
319   DiffFilterData diff_filter = honee->diff_filter;
320   Vec            Filtered_Field;
321 
322   PetscFunctionBeginUser;
323   PetscCall(DMGetGlobalVector(diff_filter->dm_filter, &Filtered_Field));
324 
325   PetscCall(DifferentialFilterApply(honee, solution_time, Q, Filtered_Field));
326   PetscCall(VecViewFromOptions(Filtered_Field, NULL, "-diff_filter_view"));
327   if (honee->app_ctx->test_type == TESTTYPE_DIFF_FILTER) PetscCall(RegressionTest(honee->app_ctx, Filtered_Field));
328 
329   PetscCall(DMRestoreGlobalVector(diff_filter->dm_filter, &Filtered_Field));
330   PetscFunctionReturn(PETSC_SUCCESS);
331 }
332 
333 PetscErrorCode DifferentialFilterDataDestroy(DiffFilterData diff_filter) {
334   PetscFunctionBeginUser;
335   if (!diff_filter) PetscFunctionReturn(PETSC_SUCCESS);
336 
337   PetscCall(OperatorApplyContextDestroy(diff_filter->op_rhs_ctx));
338   PetscCall(DMDestroy(&diff_filter->dm_filter));
339   PetscCall(KSPDestroy(&diff_filter->ksp));
340 
341   PetscCall(PetscFree(diff_filter->num_field_components));
342   PetscCall(PetscFree(diff_filter));
343   PetscFunctionReturn(PETSC_SUCCESS);
344 }
345 
346 PetscErrorCode DifferentialFilterMmsICSetup(ProblemData problem) {
347   PetscFunctionBeginUser;
348   problem->ics.qf_func_ptr = DifferentialFilter_MMS_IC;
349   problem->ics.qf_loc      = DifferentialFilter_MMS_IC_loc;
350   PetscFunctionReturn(PETSC_SUCCESS);
351 }
352