xref: /honee/problems/advection.c (revision 236a8ba61b9630532acdcf285f3dbed6efe2e73e)
1ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
3a515125bSLeila Ghaffari 
4a515125bSLeila Ghaffari /// @file
5a515125bSLeila Ghaffari /// Utility functions for setting up ADVECTION
6a515125bSLeila Ghaffari 
72b916ea7SJeremy L Thompson #include "../qfunctions/advection.h"
82b916ea7SJeremy L Thompson 
9e419654dSJeremy L Thompson #include <ceed.h>
10e419654dSJeremy L Thompson #include <petscdm.h>
11e419654dSJeremy L Thompson 
12149fb536SJames Wright #include <navierstokes.h>
13a515125bSLeila Ghaffari 
14a78efa86SJames Wright // @brief Create CeedOperator for stabilized mass KSP for explicit timestepping
15a78efa86SJames Wright //
16a78efa86SJames Wright // Only used for SUPG stabilization
17a78efa86SJames Wright PetscErrorCode CreateKSPMassOperator_AdvectionStabilized(User user, CeedOperator *op_mass) {
18a78efa86SJames Wright   Ceed                 ceed = user->ceed;
19a78efa86SJames Wright   CeedInt              num_comp_q, q_data_size;
2087d3884fSJeremy L Thompson   CeedQFunction        qf_mass = NULL;
21a78efa86SJames Wright   CeedElemRestriction  elem_restr_q, elem_restr_qd_i;
22a78efa86SJames Wright   CeedBasis            basis_q;
23a78efa86SJames Wright   CeedVector           q_data;
24*236a8ba6SJames Wright   CeedQFunctionContext qfctx = NULL;
25a78efa86SJames Wright   PetscInt             dim;
26a78efa86SJames Wright 
27a78efa86SJames Wright   PetscFunctionBeginUser;
28a78efa86SJames Wright   PetscCall(DMGetDimension(user->dm, &dim));
29a78efa86SJames Wright   {  // Get restriction and basis from the RHS function
30a78efa86SJames Wright     CeedOperator     *sub_ops;
31a78efa86SJames Wright     CeedOperatorField field;
32a78efa86SJames Wright     PetscInt          sub_op_index = 0;  // will be 0 for the volume op
33a78efa86SJames Wright 
34a78efa86SJames Wright     PetscCallCeed(ceed, CeedCompositeOperatorGetSubList(user->op_rhs_ctx->op, &sub_ops));
35a78efa86SJames Wright     PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "q", &field));
36a78efa86SJames Wright     PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_q));
37a78efa86SJames Wright     PetscCallCeed(ceed, CeedOperatorFieldGetBasis(field, &basis_q));
38a78efa86SJames Wright 
39a78efa86SJames Wright     PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "qdata", &field));
40a78efa86SJames Wright     PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_qd_i));
41a78efa86SJames Wright     PetscCallCeed(ceed, CeedOperatorFieldGetVector(field, &q_data));
42a78efa86SJames Wright 
43*236a8ba6SJames Wright     PetscCallCeed(ceed, CeedOperatorGetContext(sub_ops[sub_op_index], &qfctx));
44a78efa86SJames Wright   }
45a78efa86SJames Wright 
46a78efa86SJames Wright   PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_q, &num_comp_q));
47a78efa86SJames Wright   PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_qd_i, &q_data_size));
48a78efa86SJames Wright 
49a78efa86SJames Wright   switch (dim) {
50a78efa86SJames Wright     case 2:
51a78efa86SJames Wright       PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, MassFunction_Advection2D, MassFunction_Advection2D_loc, &qf_mass));
52a78efa86SJames Wright       break;
53a78efa86SJames Wright     case 3:
54a78efa86SJames Wright       PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, MassFunction_Advection, MassFunction_Advection_loc, &qf_mass));
55a78efa86SJames Wright       break;
56a78efa86SJames Wright   }
57a78efa86SJames Wright 
58*236a8ba6SJames Wright   PetscCallCeed(ceed, CeedQFunctionSetContext(qf_mass, qfctx));
59a78efa86SJames Wright   PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(qf_mass, 0));
60a78efa86SJames Wright   PetscCallCeed(ceed, CeedQFunctionAddInput(qf_mass, "q_dot", 5, CEED_EVAL_INTERP));
61a78efa86SJames Wright   PetscCallCeed(ceed, CeedQFunctionAddInput(qf_mass, "q", 5, CEED_EVAL_INTERP));
62a78efa86SJames Wright   PetscCallCeed(ceed, CeedQFunctionAddInput(qf_mass, "qdata", q_data_size, CEED_EVAL_NONE));
63a78efa86SJames Wright   PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_mass, "v", 5, CEED_EVAL_INTERP));
64a78efa86SJames Wright   PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_mass, "Grad_v", 5 * dim, CEED_EVAL_GRAD));
65a78efa86SJames Wright 
66a78efa86SJames Wright   PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_mass, NULL, NULL, op_mass));
67a78efa86SJames Wright   PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "q_dot", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE));
68a78efa86SJames Wright   PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "q", elem_restr_q, basis_q, user->q_ceed));
69a78efa86SJames Wright   PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "qdata", elem_restr_qd_i, CEED_BASIS_NONE, q_data));
70a78efa86SJames Wright   PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE));
71a78efa86SJames Wright   PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "Grad_v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE));
72a78efa86SJames Wright 
73*236a8ba6SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextDestroy(&qfctx));
74a78efa86SJames Wright   PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass));
75a78efa86SJames Wright   PetscFunctionReturn(PETSC_SUCCESS);
76a78efa86SJames Wright }
77a78efa86SJames Wright 
78991aef52SJames Wright PetscErrorCode NS_ADVECTION(ProblemData problem, DM dm, void *ctx, SimpleBC bc) {
795f636aeaSJames Wright   AdvDifWindType             wind_type;
805f636aeaSJames Wright   AdvDifICType               advectionic_type;
81108c6689SJames Wright   AdvDifBubbleContinuityType bubble_continuity_type = -1;
82a515125bSLeila Ghaffari   StabilizationType          stab;
8357272ee0SJames Wright   StabilizationTauType       stab_tau;
843636f6a4SJames Wright   SetupContextAdv            setup_context;
85a515125bSLeila Ghaffari   User                       user = *(User *)ctx;
86b4c37c5cSJames Wright   MPI_Comm                   comm = user->comm;
87b4c37c5cSJames Wright   Ceed                       ceed = user->ceed;
88a515125bSLeila Ghaffari   PetscBool                  implicit;
8915a3537eSJed Brown   AdvectionContext           advection_ctx;
90e07531f7SJames Wright   CeedQFunctionContext       advection_qfctx;
919529d636SJames Wright   PetscInt                   dim;
92a515125bSLeila Ghaffari 
9315a3537eSJed Brown   PetscFunctionBeginUser;
942b916ea7SJeremy L Thompson   PetscCall(PetscCalloc1(1, &setup_context));
952b916ea7SJeremy L Thompson   PetscCall(PetscCalloc1(1, &advection_ctx));
969529d636SJames Wright   PetscCall(DMGetDimension(dm, &dim));
97a515125bSLeila Ghaffari 
98a515125bSLeila Ghaffari   // ------------------------------------------------------
99a515125bSLeila Ghaffari   //               SET UP ADVECTION
100a515125bSLeila Ghaffari   // ------------------------------------------------------
10128160fc2SJames Wright   problem->print_info        = PRINT_ADVECTION;
10228160fc2SJames Wright   problem->jac_data_size_vol = 0;
10328160fc2SJames Wright   problem->jac_data_size_sur = 0;
1049529d636SJames Wright   switch (dim) {
1059529d636SJames Wright     case 2:
106e07531f7SJames Wright       problem->ics.qf_func_ptr                 = ICsAdvection2d;
107e07531f7SJames Wright       problem->ics.qf_loc                      = ICsAdvection2d_loc;
108e07531f7SJames Wright       problem->apply_vol_rhs.qf_func_ptr       = RHS_Advection2d;
109e07531f7SJames Wright       problem->apply_vol_rhs.qf_loc            = RHS_Advection2d_loc;
110e07531f7SJames Wright       problem->apply_vol_ifunction.qf_func_ptr = IFunction_Advection2d;
111e07531f7SJames Wright       problem->apply_vol_ifunction.qf_loc      = IFunction_Advection2d_loc;
112e07531f7SJames Wright       problem->apply_inflow.qf_func_ptr        = Advection2d_InOutFlow;
113e07531f7SJames Wright       problem->apply_inflow.qf_loc             = Advection2d_InOutFlow_loc;
11458ce1233SJames Wright       problem->compute_exact_solution_error    = PETSC_TRUE;
1159529d636SJames Wright       break;
1169529d636SJames Wright     case 3:
117e07531f7SJames Wright       problem->ics.qf_func_ptr                 = ICsAdvection;
118e07531f7SJames Wright       problem->ics.qf_loc                      = ICsAdvection_loc;
119e07531f7SJames Wright       problem->apply_vol_rhs.qf_func_ptr       = RHS_Advection;
120e07531f7SJames Wright       problem->apply_vol_rhs.qf_loc            = RHS_Advection_loc;
121e07531f7SJames Wright       problem->apply_vol_ifunction.qf_func_ptr = IFunction_Advection;
122e07531f7SJames Wright       problem->apply_vol_ifunction.qf_loc      = IFunction_Advection_loc;
123e07531f7SJames Wright       problem->apply_inflow.qf_func_ptr        = Advection_InOutFlow;
124e07531f7SJames Wright       problem->apply_inflow.qf_loc             = Advection_InOutFlow_loc;
12558ce1233SJames Wright       problem->compute_exact_solution_error    = PETSC_FALSE;
1269529d636SJames Wright       break;
1279529d636SJames Wright   }
128a515125bSLeila Ghaffari 
129a515125bSLeila Ghaffari   // ------------------------------------------------------
130a515125bSLeila Ghaffari   //             Create the libCEED context
131a515125bSLeila Ghaffari   // ------------------------------------------------------
132a515125bSLeila Ghaffari   CeedScalar     rc              = 1000.;  // m (Radius of bubble)
133a515125bSLeila Ghaffari   CeedScalar     CtauS           = 0.;     // dimensionless
134059d1c40SJames Wright   PetscBool      strong_form     = PETSC_FALSE;
135a515125bSLeila Ghaffari   CeedScalar     E_wind          = 1.e6;  // J
13657272ee0SJames Wright   CeedScalar     Ctau_a          = PetscPowScalarInt(user->app_ctx->degree, 2);
13757272ee0SJames Wright   CeedScalar     Ctau_t          = 0.;
138a515125bSLeila Ghaffari   PetscReal      wind[3]         = {1., 0, 0};  // m/s
139c8d249deSJames Wright   CeedScalar     diffusion_coeff = 0.;
140a62be6baSJames Wright   CeedScalar     wave_frequency  = 2 * M_PI;
141a62be6baSJames Wright   CeedScalar     wave_phase      = 0;
142108c6689SJames Wright   AdvDifWaveType wave_type       = -1;
14387d3884fSJeremy L Thompson   PetscReal      domain_min[3], domain_max[3], domain_size[3] = {0.};
1442b916ea7SJeremy L Thompson   PetscCall(DMGetBoundingBox(dm, domain_min, domain_max));
14566d54740SJames Wright   for (PetscInt i = 0; i < dim; i++) domain_size[i] = domain_max[i] - domain_min[i];
14605a512bdSLeila Ghaffari 
147a515125bSLeila Ghaffari   // ------------------------------------------------------
148a515125bSLeila Ghaffari   //             Create the PETSc context
149a515125bSLeila Ghaffari   // ------------------------------------------------------
150a515125bSLeila Ghaffari   PetscScalar meter    = 1e-2;  // 1 meter in scaled length units
151a515125bSLeila Ghaffari   PetscScalar kilogram = 1e-6;  // 1 kilogram in scaled mass units
152a515125bSLeila Ghaffari   PetscScalar second   = 1e-2;  // 1 second in scaled time units
153a515125bSLeila Ghaffari   PetscScalar Joule;
154a515125bSLeila Ghaffari 
155a515125bSLeila Ghaffari   // ------------------------------------------------------
156a515125bSLeila Ghaffari   //              Command line Options
157a515125bSLeila Ghaffari   // ------------------------------------------------------
1581485969bSJeremy L Thompson   PetscOptionsBegin(comm, NULL, "Options for ADVECTION problem", NULL);
159a515125bSLeila Ghaffari   // -- Physics
1602b916ea7SJeremy L Thompson   PetscCall(PetscOptionsScalar("-rc", "Characteristic radius of thermal bubble", NULL, rc, &rc, NULL));
161a515125bSLeila Ghaffari   PetscBool translation;
1625f636aeaSJames Wright   PetscCall(PetscOptionsEnum("-wind_type", "Wind type in Advection", NULL, AdvDifWindTypes, (PetscEnum)(wind_type = ADVDIF_WIND_ROTATION),
1635f636aeaSJames Wright                              (PetscEnum *)&wind_type, &translation));
16466d54740SJames Wright   PetscInt  n = dim;
165a515125bSLeila Ghaffari   PetscBool user_wind;
1662b916ea7SJeremy L Thompson   PetscCall(PetscOptionsRealArray("-wind_translation", "Constant wind vector", NULL, wind, &n, &user_wind));
167c8d249deSJames Wright   PetscCall(PetscOptionsScalar("-diffusion_coeff", "Diffusion coefficient", NULL, diffusion_coeff, &diffusion_coeff, NULL));
1682b916ea7SJeremy L Thompson   PetscCall(PetscOptionsScalar("-CtauS", "Scale coefficient for tau (nondimensional)", NULL, CtauS, &CtauS, NULL));
169059d1c40SJames Wright   PetscCall(PetscOptionsBool("-strong_form", "Strong (true) or weak/integrated by parts (false) advection residual", NULL, strong_form, &strong_form,
170059d1c40SJames Wright                              NULL));
1712b916ea7SJeremy L Thompson   PetscCall(PetscOptionsScalar("-E_wind", "Total energy of inflow wind", NULL, E_wind, &E_wind, NULL));
1725f636aeaSJames Wright   PetscCall(PetscOptionsEnum("-advection_ic_type", "Initial condition for Advection problem", NULL, AdvDifICTypes,
1735f636aeaSJames Wright                              (PetscEnum)(advectionic_type = ADVDIF_IC_BUBBLE_SPHERE), (PetscEnum *)&advectionic_type, NULL));
1742b916ea7SJeremy L Thompson   PetscCall(PetscOptionsEnum("-stab", "Stabilization method", NULL, StabilizationTypes, (PetscEnum)(stab = STAB_NONE), (PetscEnum *)&stab, NULL));
17557272ee0SJames Wright   PetscCall(PetscOptionsEnum("-stab_tau", "Stabilization constant, tau", NULL, StabilizationTauTypes, (PetscEnum)(stab_tau = STAB_TAU_CTAU),
17657272ee0SJames Wright                              (PetscEnum *)&stab_tau, NULL));
17757272ee0SJames Wright   PetscCall(PetscOptionsScalar("-Ctau_t", "Stabilization time constant", NULL, Ctau_t, &Ctau_t, NULL));
17857272ee0SJames Wright   PetscCall(PetscOptionsScalar("-Ctau_a", "Coefficient for the stabilization ", NULL, Ctau_a, &Ctau_a, NULL));
1792b916ea7SJeremy L Thompson   PetscCall(PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", NULL, implicit = PETSC_FALSE, &implicit, NULL));
180a515125bSLeila Ghaffari 
181108c6689SJames Wright   if (advectionic_type == ADVDIF_IC_WAVE) {
182108c6689SJames Wright     PetscCall(PetscOptionsEnum("-wave_type", "Type of wave", NULL, AdvDifWaveTypes, (PetscEnum)(wave_type = ADVDIF_WAVE_SINE),
183108c6689SJames Wright                                (PetscEnum *)&wave_type, NULL));
184a62be6baSJames Wright     PetscCall(PetscOptionsScalar("-wave_frequency", "Frequency of sine wave", NULL, wave_frequency, &wave_frequency, NULL));
185a62be6baSJames Wright     PetscCall(PetscOptionsScalar("-wave_phase", "Length correction", NULL, wave_phase, &wave_phase, NULL));
186108c6689SJames Wright   }
187108c6689SJames Wright 
188108c6689SJames Wright   if (advectionic_type == ADVDIF_IC_BUBBLE_CYLINDER || advectionic_type == ADVDIF_IC_BUBBLE_SPHERE) {
189108c6689SJames Wright     bubble_continuity_type = dim == 3 ? ADVDIF_BUBBLE_CONTINUITY_SMOOTH : ADVDIF_BUBBLE_CONTINUITY_COSINE;
190108c6689SJames Wright     PetscCall(PetscOptionsEnum("-bubble_continuity", "Smooth, back_sharp, or thick", NULL, AdvDifBubbleContinuityTypes,
191108c6689SJames Wright                                (PetscEnum)bubble_continuity_type, (PetscEnum *)&bubble_continuity_type, NULL));
192108c6689SJames Wright   }
193a62be6baSJames Wright 
194a515125bSLeila Ghaffari   // -- Units
1952b916ea7SJeremy L Thompson   PetscCall(PetscOptionsScalar("-units_meter", "1 meter in scaled length units", NULL, meter, &meter, NULL));
196a515125bSLeila Ghaffari   meter = fabs(meter);
1972b916ea7SJeremy L Thompson   PetscCall(PetscOptionsScalar("-units_kilogram", "1 kilogram in scaled mass units", NULL, kilogram, &kilogram, NULL));
198a515125bSLeila Ghaffari   kilogram = fabs(kilogram);
1992b916ea7SJeremy L Thompson   PetscCall(PetscOptionsScalar("-units_second", "1 second in scaled time units", NULL, second, &second, NULL));
200a515125bSLeila Ghaffari   second = fabs(second);
201a515125bSLeila Ghaffari 
202a515125bSLeila Ghaffari   // -- Warnings
2035f636aeaSJames Wright   if (wind_type == ADVDIF_WIND_ROTATION && user_wind) {
2042b916ea7SJeremy L Thompson     PetscCall(PetscPrintf(comm, "Warning! Use -wind_translation only with -wind_type translation\n"));
205a515125bSLeila Ghaffari   }
2065f636aeaSJames Wright   if (wind_type == ADVDIF_WIND_TRANSLATION && advectionic_type == ADVDIF_IC_BUBBLE_CYLINDER && wind[2] != 0.) {
207a515125bSLeila Ghaffari     wind[2] = 0;
208c51f031aSJames Wright     PetscCall(
209c51f031aSJames Wright         PetscPrintf(comm, "Warning! Background wind in the z direction should be zero (-wind_translation x,x,0) with -advection_ic_type cylinder\n"));
210a515125bSLeila Ghaffari   }
211a515125bSLeila Ghaffari   if (stab == STAB_NONE && CtauS != 0) {
2122b916ea7SJeremy L Thompson     PetscCall(PetscPrintf(comm, "Warning! Use -CtauS only with -stab su or -stab supg\n"));
213a515125bSLeila Ghaffari   }
2141485969bSJeremy L Thompson   PetscOptionsEnd();
215a515125bSLeila Ghaffari 
216a78efa86SJames Wright   if (stab == STAB_SUPG) problem->create_mass_operator = CreateKSPMassOperator_AdvectionStabilized;
217a78efa86SJames Wright 
218a515125bSLeila Ghaffari   // ------------------------------------------------------
219a515125bSLeila Ghaffari   //           Set up the PETSc context
220a515125bSLeila Ghaffari   // ------------------------------------------------------
221a515125bSLeila Ghaffari   // -- Define derived units
222a515125bSLeila Ghaffari   Joule = kilogram * PetscSqr(meter) / PetscSqr(second);
223a515125bSLeila Ghaffari 
224a515125bSLeila Ghaffari   user->units->meter    = meter;
225a515125bSLeila Ghaffari   user->units->kilogram = kilogram;
226a515125bSLeila Ghaffari   user->units->second   = second;
227a515125bSLeila Ghaffari   user->units->Joule    = Joule;
228a515125bSLeila Ghaffari 
229a515125bSLeila Ghaffari   // ------------------------------------------------------
230a515125bSLeila Ghaffari   //           Set up the libCEED context
231a515125bSLeila Ghaffari   // ------------------------------------------------------
232a515125bSLeila Ghaffari   // -- Scale variables to desired units
233a515125bSLeila Ghaffari   E_wind *= Joule;
234a515125bSLeila Ghaffari   rc = fabs(rc) * meter;
23566d54740SJames Wright   for (PetscInt i = 0; i < dim; i++) {
23605a512bdSLeila Ghaffari     wind[i] *= (meter / second);
23705a512bdSLeila Ghaffari     domain_size[i] *= meter;
23805a512bdSLeila Ghaffari   }
239a515125bSLeila Ghaffari 
240a515125bSLeila Ghaffari   // -- Setup Context
241a515125bSLeila Ghaffari   setup_context->rc                     = rc;
24205a512bdSLeila Ghaffari   setup_context->lx                     = domain_size[0];
24305a512bdSLeila Ghaffari   setup_context->ly                     = domain_size[1];
24466d54740SJames Wright   setup_context->lz                     = dim == 3 ? domain_size[2] : 0.;
245a515125bSLeila Ghaffari   setup_context->wind[0]                = wind[0];
246a515125bSLeila Ghaffari   setup_context->wind[1]                = wind[1];
24766d54740SJames Wright   setup_context->wind[2]                = dim == 3 ? wind[2] : 0.;
248a515125bSLeila Ghaffari   setup_context->wind_type              = wind_type;
249c51f031aSJames Wright   setup_context->initial_condition_type = advectionic_type;
250a515125bSLeila Ghaffari   setup_context->bubble_continuity_type = bubble_continuity_type;
251a515125bSLeila Ghaffari   setup_context->time                   = 0;
252a62be6baSJames Wright   setup_context->wave_frequency         = wave_frequency;
253a62be6baSJames Wright   setup_context->wave_phase             = wave_phase;
254a62be6baSJames Wright   setup_context->wave_type              = wave_type;
255a515125bSLeila Ghaffari 
256a515125bSLeila Ghaffari   // -- QFunction Context
257a515125bSLeila Ghaffari   user->phys->implicit             = implicit;
25815a3537eSJed Brown   advection_ctx->CtauS             = CtauS;
25915a3537eSJed Brown   advection_ctx->E_wind            = E_wind;
26015a3537eSJed Brown   advection_ctx->implicit          = implicit;
26115a3537eSJed Brown   advection_ctx->strong_form       = strong_form;
26215a3537eSJed Brown   advection_ctx->stabilization     = stab;
26357272ee0SJames Wright   advection_ctx->stabilization_tau = stab_tau;
26457272ee0SJames Wright   advection_ctx->Ctau_a            = Ctau_a;
26557272ee0SJames Wright   advection_ctx->Ctau_t            = Ctau_t;
266c8d249deSJames Wright   advection_ctx->diffusion_coeff   = diffusion_coeff;
267a515125bSLeila Ghaffari 
268e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &problem->ics.qfctx));
269e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextSetData(problem->ics.qfctx, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context));
270e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(problem->ics.qfctx, CEED_MEM_HOST, FreeContextPetsc));
271a515125bSLeila Ghaffari 
272e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &advection_qfctx));
273e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextSetData(advection_qfctx, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*advection_ctx), advection_ctx));
274e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(advection_qfctx, CEED_MEM_HOST, FreeContextPetsc));
275e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(advection_qfctx, "timestep size", offsetof(struct AdvectionContext_, dt), 1,
27657272ee0SJames Wright                                                          "Size of timestep, delta t"));
277e07531f7SJames Wright   problem->apply_vol_rhs.qfctx = advection_qfctx;
278e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(advection_qfctx, &problem->apply_vol_ifunction.qfctx));
279e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(advection_qfctx, &problem->apply_inflow.qfctx));
280d949ddfcSJames Wright   PetscFunctionReturn(PETSC_SUCCESS);
281a515125bSLeila Ghaffari }
282a515125bSLeila Ghaffari 
283991aef52SJames Wright PetscErrorCode PRINT_ADVECTION(User user, ProblemData problem, AppCtx app_ctx) {
2842d49c0afSJames Wright   MPI_Comm         comm = user->comm;
285b4c37c5cSJames Wright   Ceed             ceed = user->ceed;
2863636f6a4SJames Wright   SetupContextAdv  setup_ctx;
28715a3537eSJed Brown   AdvectionContext advection_ctx;
28866d54740SJames Wright   PetscInt         dim;
289a515125bSLeila Ghaffari 
29015a3537eSJed Brown   PetscFunctionBeginUser;
29166d54740SJames Wright   PetscCall(DMGetDimension(user->dm, &dim));
292e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->ics.qfctx, CEED_MEM_HOST, &setup_ctx));
293e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfctx, CEED_MEM_HOST, &advection_ctx));
2942b916ea7SJeremy L Thompson   PetscCall(PetscPrintf(comm,
295a515125bSLeila Ghaffari                         "  Problem:\n"
296a515125bSLeila Ghaffari                         "    Problem Name                       : %s\n"
297a515125bSLeila Ghaffari                         "    Stabilization                      : %s\n"
2985bcc2007SJames Wright                         "    Stabilization Tau                  : %s\n"
299a515125bSLeila Ghaffari                         "    Wind Type                          : %s\n",
3005bcc2007SJames Wright                         app_ctx->problem_name, StabilizationTypes[advection_ctx->stabilization],
3015f636aeaSJames Wright                         StabilizationTauTypes[advection_ctx->stabilization_tau], AdvDifWindTypes[setup_ctx->wind_type]));
302a515125bSLeila Ghaffari 
3035f636aeaSJames Wright   if (setup_ctx->wind_type == ADVDIF_WIND_TRANSLATION) {
304c781aee8SJames Wright     CeedScalar *wind = setup_ctx->wind;
30566d54740SJames Wright     switch (dim) {
3069529d636SJames Wright       case 2:
307c781aee8SJames Wright         PetscCall(PetscPrintf(comm, "    Background Wind                    : %f,%f\n", wind[0], wind[1]));
3089529d636SJames Wright         break;
3099529d636SJames Wright       case 3:
310c781aee8SJames Wright         PetscCall(PetscPrintf(comm, "    Background Wind                    : %f,%f,%f\n", wind[0], wind[1], wind[2]));
3119529d636SJames Wright         break;
3129529d636SJames Wright     }
313a515125bSLeila Ghaffari   }
314c781aee8SJames Wright 
3155f636aeaSJames Wright   PetscCall(PetscPrintf(comm, "    Initial Condition Type             : %s\n", AdvDifICTypes[setup_ctx->initial_condition_type]));
316c781aee8SJames Wright   switch (setup_ctx->initial_condition_type) {
3175f636aeaSJames Wright     case ADVDIF_IC_SKEW:
3185f636aeaSJames Wright     case ADVDIF_IC_COSINE_HILL:
319c781aee8SJames Wright       break;
3205f636aeaSJames Wright     case ADVDIF_IC_BUBBLE_SPHERE:
3215f636aeaSJames Wright     case ADVDIF_IC_BUBBLE_CYLINDER:
3225f636aeaSJames Wright       PetscCall(PetscPrintf(comm, "    Bubble Continuity                  : %s\n", AdvDifBubbleContinuityTypes[setup_ctx->bubble_continuity_type]));
323c781aee8SJames Wright       break;
3245f636aeaSJames Wright     case ADVDIF_IC_WAVE:
325c781aee8SJames Wright       PetscCall(PetscPrintf(comm, "    Wave Type                          : %s\n", AdvDifWaveTypes[setup_ctx->wave_type]));
326c781aee8SJames Wright       break;
327c781aee8SJames Wright   }
328c781aee8SJames Wright 
329e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->ics.qfctx, &setup_ctx));
330e07531f7SJames Wright   PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfctx, &advection_ctx));
331d949ddfcSJames Wright   PetscFunctionReturn(PETSC_SUCCESS);
332a515125bSLeila Ghaffari }
333