xref: /libCEED/examples/fluids/navierstokes.h (revision d4cc18453651bd0f94c1a2e078b2646a92dafdcc)
1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
377841947SLeila Ghaffari //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
577841947SLeila Ghaffari //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
724a65d3dSJeremy L Thompson #pragma once
877841947SLeila Ghaffari 
977841947SLeila Ghaffari #include <ceed.h>
10a8748852SJames Wright #include <bc_definition.h>
119d992146SJames Wright #include <log_events.h>
1291c97f41SJames Wright #include <mat-ceed.h>
135037d55dSJames Wright #include <petsc-ceed-utils.h>
1477841947SLeila Ghaffari #include <petscts.h>
1577841947SLeila Ghaffari #include <stdbool.h>
162b730f8bSJeremy L Thompson 
174021610dSJames Wright #include "./include/petsc_ops.h"
1897baf651SJames Wright #include "qfunctions/newtonian_types.h"
1977841947SLeila Ghaffari 
20bfbde1a2SJeremy L Thompson #if PETSC_VERSION_LT(3, 23, 0)
21bfbde1a2SJeremy L Thompson #error "PETSc v3.23 or later is required"
2249a40c8aSKenneth E. Jansen #endif
2349a40c8aSKenneth E. Jansen 
2477841947SLeila Ghaffari // -----------------------------------------------------------------------------
2577841947SLeila Ghaffari // Enums
2677841947SLeila Ghaffari // -----------------------------------------------------------------------------
2777841947SLeila Ghaffari 
2877841947SLeila Ghaffari // Euler - test cases
2977841947SLeila Ghaffari typedef enum {
30bc7bbd5dSLeila Ghaffari   EULER_TEST_ISENTROPIC_VORTEX = 0,
3177841947SLeila Ghaffari   EULER_TEST_1                 = 1,
3277841947SLeila Ghaffari   EULER_TEST_2                 = 2,
3377841947SLeila Ghaffari   EULER_TEST_3                 = 3,
3477841947SLeila Ghaffari   EULER_TEST_4                 = 4,
3532f166c6SLeila Ghaffari   EULER_TEST_5                 = 5,
3677841947SLeila Ghaffari } EulerTestType;
37fc39c77eSJames Wright static const char *const EulerTestTypes[] = {"ISENTROPIC_VORTEX", "1", "2", "3", "4", "5", "EulerTestType", "EULER_TEST_", NULL};
3877841947SLeila Ghaffari 
39700ae941SJames Wright // Advection - Wind types
40fc39c77eSJames Wright static const char *const WindTypes[] = {"ROTATION", "TRANSLATION", "WindType", "WIND_", NULL};
41700ae941SJames Wright 
427b77ddfdSJames Wright // Advection - Initial Condition Types
43fc39c77eSJames Wright static const char *const AdvectionICTypes[] = {"SPHERE", "CYLINDER", "COSINE_HILL", "SKEW", "AdvectionICType", "ADVECTIONIC_", NULL};
44700ae941SJames Wright 
45700ae941SJames Wright // Advection - Bubble Continuity Types
46fc39c77eSJames Wright static const char *const BubbleContinuityTypes[] = {"SMOOTH", "BACK_SHARP", "THICK", "COSINE", "BubbleContinuityType", "BUBBLE_CONTINUITY_", NULL};
47700ae941SJames Wright 
4877841947SLeila Ghaffari // Stabilization methods
49fc39c77eSJames Wright static const char *const StabilizationTypes[] = {"NONE", "SU", "SUPG", "StabilizationType", "STAB_", NULL};
5077841947SLeila Ghaffari 
51b18328c4SJames Wright // Stabilization tau constants
52fc39c77eSJames Wright static const char *const StabilizationTauTypes[] = {"CTAU", "ADVDIFF_SHAKIB", "ADVDIFF_SHAKIB_P", "StabilizationTauType", "STAB_TAU_", NULL};
53b18328c4SJames Wright 
5451b00d91SJames Wright // Test mode type
558fb33541SJames Wright typedef enum {
568fb33541SJames Wright   TESTTYPE_NONE           = 0,
578fb33541SJames Wright   TESTTYPE_SOLVER         = 1,
588fb33541SJames Wright   TESTTYPE_TURB_SPANSTATS = 2,
59970fa48bSJames Wright   TESTTYPE_DIFF_FILTER    = 3,
608fb33541SJames Wright } TestType;
61fc39c77eSJames Wright static const char *const TestTypes[] = {"NONE", "SOLVER", "TURB_SPANSTATS", "DIFF_FILTER", "TestType", "TESTTYPE_", NULL};
628fb33541SJames Wright 
632526956eSJames Wright // Mesh transformation type
642526956eSJames Wright typedef enum {
652526956eSJames Wright   MESH_TRANSFORM_NONE      = 0,
662526956eSJames Wright   MESH_TRANSFORM_PLATEMESH = 1,
672526956eSJames Wright } MeshTransformType;
68fc39c77eSJames Wright static const char *const MeshTransformTypes[] = {"NONE", "PLATEMESH", "MeshTransformType", "MESH_TRANSFORM_", NULL};
692526956eSJames Wright 
70bd882c8aSJames Wright static const char *const DifferentialFilterDampingFunctions[] = {
71fc39c77eSJames Wright     "NONE", "VAN_DRIEST", "MMS", "DifferentialFilterDampingFunction", "DIFF_FILTER_DAMP_", NULL};
72bd882c8aSJames Wright 
7377841947SLeila Ghaffari // -----------------------------------------------------------------------------
7477841947SLeila Ghaffari // Structs
7577841947SLeila Ghaffari // -----------------------------------------------------------------------------
7677841947SLeila Ghaffari // Structs declarations
7777841947SLeila Ghaffari typedef struct AppCtx_private      *AppCtx;
7877841947SLeila Ghaffari typedef struct CeedData_private    *CeedData;
7977841947SLeila Ghaffari typedef struct User_private        *User;
8077841947SLeila Ghaffari typedef struct Units_private       *Units;
8177841947SLeila Ghaffari typedef struct SimpleBC_private    *SimpleBC;
8277841947SLeila Ghaffari typedef struct Physics_private     *Physics;
83a8748852SJames Wright typedef struct ProblemData_private *ProblemData;
8477841947SLeila Ghaffari 
8577841947SLeila Ghaffari // Application context from user command line options
8677841947SLeila Ghaffari struct AppCtx_private {
8777841947SLeila Ghaffari   // libCEED arguments
8877841947SLeila Ghaffari   char     ceed_resource[PETSC_MAX_PATH_LEN];  // libCEED backend
8977841947SLeila Ghaffari   PetscInt degree;
9077841947SLeila Ghaffari   PetscInt q_extra;
91544be873SJed Brown   // Solver arguments
92544be873SJed Brown   MatType amat_type;
9377841947SLeila Ghaffari   // Post-processing arguments
9437cbb16aSJed Brown   PetscInt  checkpoint_interval;
9577841947SLeila Ghaffari   PetscInt  viz_refine;
9677841947SLeila Ghaffari   PetscInt  cont_steps;
974de8550aSJed Brown   PetscReal cont_time;
9869293791SJames Wright   char      cont_file[PETSC_MAX_PATH_LEN];
9969293791SJames Wright   char      cont_time_file[PETSC_MAX_PATH_LEN];
10077841947SLeila Ghaffari   char      output_dir[PETSC_MAX_PATH_LEN];
10169293791SJames Wright   PetscBool add_stepnum2bin;
10237cbb16aSJed Brown   PetscBool checkpoint_vtk;
10377841947SLeila Ghaffari   // Problem type arguments
10477841947SLeila Ghaffari   PetscFunctionList problems;
10577841947SLeila Ghaffari   char              problem_name[PETSC_MAX_PATH_LEN];
10677841947SLeila Ghaffari   // Test mode arguments
1078fb33541SJames Wright   TestType    test_type;
10877841947SLeila Ghaffari   PetscScalar test_tol;
109b7d66439SJames Wright   char        test_file_path[PETSC_MAX_PATH_LEN];
110b7d66439SJames Wright   // Turbulent spanwise statistics
111b7d66439SJames Wright   PetscBool         turb_spanstats_enable;
112b7d66439SJames Wright   PetscInt          turb_spanstats_collect_interval;
113b7d66439SJames Wright   PetscInt          turb_spanstats_viewer_interval;
114b7d66439SJames Wright   PetscViewer       turb_spanstats_viewer;
115b7d66439SJames Wright   PetscViewerFormat turb_spanstats_viewer_format;
116ca69d878SAdeleke O. Bankole   // Wall forces
117ca69d878SAdeleke O. Bankole   struct {
118ca69d878SAdeleke O. Bankole     PetscInt          num_wall;
119ca69d878SAdeleke O. Bankole     PetscInt         *walls;
120ca69d878SAdeleke O. Bankole     PetscViewer       viewer;
121ca69d878SAdeleke O. Bankole     PetscViewerFormat viewer_format;
122ca69d878SAdeleke O. Bankole     PetscBool         header_written;
123ca69d878SAdeleke O. Bankole   } wall_forces;
1244e9802d1SJames Wright   // Differential Filtering
1254e9802d1SJames Wright   PetscBool         diff_filter_monitor;
1262526956eSJames Wright   MeshTransformType mesh_transform_type;
12777841947SLeila Ghaffari };
12877841947SLeila Ghaffari 
12977841947SLeila Ghaffari // libCEED data struct
13077841947SLeila Ghaffari struct CeedData_private {
13177841947SLeila Ghaffari   CeedVector           x_coord, q_data;
132e9c36be0SJames Wright   CeedBasis            basis_x, basis_q;
13377841947SLeila Ghaffari   CeedElemRestriction  elem_restr_x, elem_restr_q, elem_restr_qd_i;
1345263e9c6SJames Wright   OperatorApplyContext op_ics_ctx;
13577841947SLeila Ghaffari };
13677841947SLeila Ghaffari 
13751ee423eSJames Wright typedef struct {
13851ee423eSJames Wright   DM                    dm;
1391737222fSJames Wright   PetscSF               sf;  // For communicating child data to parents
140ed331efdSJames Wright   OperatorApplyContext  op_stats_collect_ctx, op_proj_rhs_ctx;
14151ee423eSJames Wright   PetscInt              num_comp_stats;
142ed331efdSJames Wright   Vec                   Child_Stats_loc, Parent_Stats_loc;
143a175e481SJames Wright   KSP                   ksp;         // For the L^2 projection solve
144a175e481SJames Wright   CeedScalar            span_width;  // spanwise width of the child domain
145b7d66439SJames Wright   PetscBool             do_mms_test;
1464021610dSJames Wright   OperatorApplyContext  mms_error_ctx;
147495b9769SJames Wright   CeedContextFieldLabel solution_time_label, previous_time_label;
148cbef7084SJames Wright } SpanStatsData;
14951ee423eSJames Wright 
150999ff5c7SJames Wright typedef struct {
151999ff5c7SJames Wright   DM                   dm;
152999ff5c7SJames Wright   PetscInt             num_comp;
153999ff5c7SJames Wright   OperatorApplyContext l2_rhs_ctx;
154999ff5c7SJames Wright   KSP                  ksp;
155999ff5c7SJames Wright } *NodalProjectionData;
156999ff5c7SJames Wright 
157ee3b213aSJames Wright typedef struct {
1584e9802d1SJames Wright   DM                    dm_filter;
15981530087SJames Wright   PetscInt              num_filtered_fields;
16081530087SJames Wright   CeedInt              *num_field_components;
161051427eeSJames Wright   PetscInt              field_prim_state, field_velo_prod;
1624e9802d1SJames Wright   OperatorApplyContext  op_rhs_ctx;
1634e9802d1SJames Wright   KSP                   ksp;
16456f5e811SJames Wright   PetscObjectState      X_loc_state;
1652029a677SJames Wright   PetscBool             do_mms_test;
166c79b0730SJames Wright   CeedContextFieldLabel filter_width_scaling_label;
1674e9802d1SJames Wright } *DiffFilterData;
1684e9802d1SJames Wright 
16977841947SLeila Ghaffari // PETSc user data
17077841947SLeila Ghaffari struct User_private {
17177841947SLeila Ghaffari   MPI_Comm             comm;
17277841947SLeila Ghaffari   DM                   dm;
17377841947SLeila Ghaffari   DM                   dm_viz;
17477841947SLeila Ghaffari   Mat                  interp_viz;
17577841947SLeila Ghaffari   Ceed                 ceed;
17677841947SLeila Ghaffari   Units                units;
17704292f7dSJames Wright   Vec                  Q_loc, Q_dot_loc;
17877841947SLeila Ghaffari   Physics              phys;
17977841947SLeila Ghaffari   AppCtx               app_ctx;
18091c97f41SJames Wright   CeedVector           q_ceed, q_dot_ceed, g_ceed, x_ceed;
181a5b0ec6fSJames Wright   CeedOperator         op_ifunction;
18291c97f41SJames Wright   Mat                  mat_ijacobian;
18304292f7dSJames Wright   KSP                  mass_ksp;
1849ad5e8e4SJames Wright   OperatorApplyContext op_rhs_ctx, op_strong_bc_ctx;
18515637395SJames Wright   CeedScalar           time_bc_set;
186cbef7084SJames Wright   SpanStatsData        spanstats;
187999ff5c7SJames Wright   NodalProjectionData  grad_velo_proj;
1884e9802d1SJames Wright   DiffFilterData       diff_filter;
18977841947SLeila Ghaffari };
19077841947SLeila Ghaffari 
19177841947SLeila Ghaffari // Units
19277841947SLeila Ghaffari struct Units_private {
19377841947SLeila Ghaffari   // fundamental units
19477841947SLeila Ghaffari   PetscScalar meter;
19577841947SLeila Ghaffari   PetscScalar kilogram;
19677841947SLeila Ghaffari   PetscScalar second;
19777841947SLeila Ghaffari   PetscScalar Kelvin;
19877841947SLeila Ghaffari   // derived units
19977841947SLeila Ghaffari   PetscScalar Pascal;
20077841947SLeila Ghaffari   PetscScalar J_per_kg_K;
20177841947SLeila Ghaffari   PetscScalar m_per_squared_s;
20277841947SLeila Ghaffari   PetscScalar W_per_m_K;
20377841947SLeila Ghaffari   PetscScalar Joule;
20477841947SLeila Ghaffari };
20577841947SLeila Ghaffari 
20677841947SLeila Ghaffari // Boundary conditions
20777841947SLeila Ghaffari struct SimpleBC_private {
208a8748852SJames Wright   PetscInt num_inflow, num_outflow, num_freestream, num_slip;
209a8748852SJames Wright   PetscInt inflows[16], outflows[16], freestreams[16], slips[16];
21077841947SLeila Ghaffari };
21177841947SLeila Ghaffari 
21277841947SLeila Ghaffari // Struct that contains all enums and structs used for the physics of all problems
21377841947SLeila Ghaffari struct Physics_private {
21477841947SLeila Ghaffari   PetscBool             implicit;
21597baf651SJames Wright   StateVariable         state_var;
21611436a05SJames Wright   CeedContextFieldLabel solution_time_label;
217cd4035ffSJames Wright   CeedContextFieldLabel stg_solution_time_label;
21888626eedSJames Wright   CeedContextFieldLabel timestep_size_label;
219841e4c73SJed Brown   CeedContextFieldLabel ics_time_label;
22077841947SLeila Ghaffari };
22177841947SLeila Ghaffari 
222a8748852SJames Wright PetscErrorCode BoundaryConditionSetUp(User user, ProblemData problem, AppCtx app_ctx, SimpleBC bc);
223a8748852SJames Wright 
22491e5af17SJed Brown typedef struct {
22591e5af17SJed Brown   CeedQFunctionUser    qfunction;
22691e5af17SJed Brown   const char          *qfunction_loc;
227841e4c73SJed Brown   CeedQFunctionContext qfunction_context;
22891e5af17SJed Brown } ProblemQFunctionSpec;
22991e5af17SJed Brown 
23077841947SLeila Ghaffari // Problem specific data
231841e4c73SJed Brown struct ProblemData_private {
232e334ad8fSJed Brown   CeedInt              dim, q_data_size_vol, q_data_size_sur, jac_data_size_sur;
2331864f1c2SLeila Ghaffari   CeedScalar           dm_scale;
234cfb075a4SJames Wright   ProblemQFunctionSpec ics, apply_vol_rhs, apply_vol_ifunction, apply_vol_ijacobian, apply_inflow, apply_outflow, apply_freestream, apply_slip,
235cfb075a4SJames Wright       apply_inflow_jacobian, apply_outflow_jacobian, apply_freestream_jacobian, apply_slip_jacobian;
236de327db4SJames Wright   bool          compute_exact_solution_error;
237de327db4SJames Wright   PetscBool     set_bc_from_ics, use_strong_bc_ceed, uses_newtonian;
238a82e6db6SJeremy L Thompson   PetscCount    num_bc_defs;
239a8748852SJames Wright   BCDefinition *bc_defs;
240731c13d7SJames Wright   PetscErrorCode (*print_info)(User, ProblemData, AppCtx);
241b4e9a8f8SJames Wright   PetscErrorCode (*create_mass_operator)(User, CeedOperator *);
242841e4c73SJed Brown };
24377841947SLeila Ghaffari 
244841e4c73SJed Brown extern int FreeContextPetsc(void *);
245841e4c73SJed Brown 
24677841947SLeila Ghaffari // -----------------------------------------------------------------------------
24777841947SLeila Ghaffari // Set up problems
24877841947SLeila Ghaffari // -----------------------------------------------------------------------------
24977841947SLeila Ghaffari // Set up function for each problem
250731c13d7SJames Wright extern PetscErrorCode NS_TAYLOR_GREEN(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
251731c13d7SJames Wright extern PetscErrorCode NS_GAUSSIAN_WAVE(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
252731c13d7SJames Wright extern PetscErrorCode NS_CHANNEL(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
253731c13d7SJames Wright extern PetscErrorCode NS_BLASIUS(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
254731c13d7SJames Wright extern PetscErrorCode NS_NEWTONIAN_IG(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
255731c13d7SJames Wright extern PetscErrorCode NS_DENSITY_CURRENT(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
256731c13d7SJames Wright extern PetscErrorCode NS_EULER_VORTEX(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
257731c13d7SJames Wright extern PetscErrorCode NS_SHOCKTUBE(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
258731c13d7SJames Wright extern PetscErrorCode NS_ADVECTION(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
259731c13d7SJames Wright extern PetscErrorCode NS_ADVECTION2D(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
26077841947SLeila Ghaffari 
26177841947SLeila Ghaffari // Print function for each problem
262731c13d7SJames Wright extern PetscErrorCode PRINT_NEWTONIAN(User user, ProblemData problem, AppCtx app_ctx);
26377841947SLeila Ghaffari 
264731c13d7SJames Wright extern PetscErrorCode PRINT_EULER_VORTEX(User user, ProblemData problem, AppCtx app_ctx);
26577841947SLeila Ghaffari 
266731c13d7SJames Wright extern PetscErrorCode PRINT_SHOCKTUBE(User user, ProblemData problem, AppCtx app_ctx);
267019b7682STimothy Aiken 
268731c13d7SJames Wright extern PetscErrorCode PRINT_ADVECTION(User user, ProblemData problem, AppCtx app_ctx);
26977841947SLeila Ghaffari 
270731c13d7SJames Wright extern PetscErrorCode PRINT_ADVECTION2D(User user, ProblemData problem, AppCtx app_ctx);
27177841947SLeila Ghaffari 
2727bc7b61fSJames Wright PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData problem, TS ts);
2732e31f396SJames Wright 
27477841947SLeila Ghaffari // -----------------------------------------------------------------------------
27577841947SLeila Ghaffari // libCEED functions
27677841947SLeila Ghaffari // -----------------------------------------------------------------------------
27777841947SLeila Ghaffari // Utility function to create local CEED restriction
278431cd09aSJames Wright PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt label_value, PetscInt dm_field,
279431cd09aSJames Wright                                          CeedElemRestriction *elem_restr);
28077841947SLeila Ghaffari 
281bb85d312SJames Wright PetscErrorCode DMPlexCeedElemRestrictionCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field,
282bb85d312SJames Wright                                                CeedElemRestriction *restriction);
283bb85d312SJames Wright PetscErrorCode DMPlexCeedElemRestrictionCoordinateCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height,
284bb85d312SJames Wright                                                          CeedElemRestriction *restriction);
285bb85d312SJames Wright PetscErrorCode DMPlexCeedElemRestrictionQDataCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height,
286bb85d312SJames Wright                                                     PetscInt q_data_size, CeedElemRestriction *restriction);
287bb85d312SJames Wright PetscErrorCode DMPlexCeedElemRestrictionCollocatedCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height,
288bb85d312SJames Wright                                                          PetscInt q_data_size, CeedElemRestriction *restriction);
28977841947SLeila Ghaffari 
2900814d5a7SKenneth E. Jansen PetscErrorCode CreateBasisFromPlex(Ceed ceed, DM dm, DMLabel domain_label, CeedInt label_value, CeedInt height, CeedInt dm_field, CeedBasis *basis);
2910814d5a7SKenneth E. Jansen 
292731c13d7SJames Wright PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, AppCtx app_ctx, ProblemData problem, SimpleBC bc);
29377841947SLeila Ghaffari 
294cfb075a4SJames Wright PetscErrorCode QDataGet(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, CeedElemRestriction elem_restr_x, CeedBasis basis_x,
295cfb075a4SJames Wright                         CeedVector x_coord, CeedElemRestriction *elem_restr_qd, CeedVector *q_data, CeedInt *q_data_size);
296cfb075a4SJames Wright PetscErrorCode QDataGetNumComponents(DM dm, CeedInt *q_data_size);
297cfb075a4SJames Wright PetscErrorCode QDataBoundaryGet(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, CeedElemRestriction elem_restr_x, CeedBasis basis_x,
298cfb075a4SJames Wright                                 CeedVector x_coord, CeedElemRestriction *elem_restr_qd, CeedVector *q_data, CeedInt *q_data_size);
299cfb075a4SJames Wright PetscErrorCode QDataBoundaryGetNumComponents(DM dm, CeedInt *q_data_size);
30077841947SLeila Ghaffari // -----------------------------------------------------------------------------
30177841947SLeila Ghaffari // Time-stepping functions
30277841947SLeila Ghaffari // -----------------------------------------------------------------------------
30377841947SLeila Ghaffari // RHS (Explicit time-stepper) function setup
30477841947SLeila Ghaffari PetscErrorCode RHS_NS(TS ts, PetscReal t, Vec Q, Vec G, void *user_data);
30577841947SLeila Ghaffari 
30677841947SLeila Ghaffari // Implicit time-stepper function setup
3072b730f8bSJeremy L Thompson PetscErrorCode IFunction_NS(TS ts, PetscReal t, Vec Q, Vec Q_dot, Vec G, void *user_data);
30877841947SLeila Ghaffari 
30977841947SLeila Ghaffari // User provided TS Monitor
3102b730f8bSJeremy L Thompson PetscErrorCode TSMonitor_NS(TS ts, PetscInt step_no, PetscReal time, Vec Q, void *ctx);
31177841947SLeila Ghaffari 
31277841947SLeila Ghaffari // TS: Create, setup, and solve
31324078fc4SJames Wright PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, ProblemData problem, Vec *Q, PetscScalar *f_time, TS *ts);
31477841947SLeila Ghaffari 
315a0b9a424SJames Wright // Update Boundary Values when time has changed
316a0b9a424SJames Wright PetscErrorCode UpdateBoundaryValues(User user, Vec Q_loc, PetscReal t);
317a0b9a424SJames Wright 
31877841947SLeila Ghaffari // -----------------------------------------------------------------------------
31977841947SLeila Ghaffari // Setup DM
32077841947SLeila Ghaffari // -----------------------------------------------------------------------------
3211864f1c2SLeila Ghaffari // Create mesh
322731c13d7SJames Wright PetscErrorCode CreateDM(MPI_Comm comm, ProblemData problem, MatType, VecType, DM *dm);
32377841947SLeila Ghaffari 
32477841947SLeila Ghaffari // Set up DM
325731c13d7SJames Wright PetscErrorCode SetUpDM(DM dm, ProblemData problem, PetscInt degree, PetscInt q_extra, SimpleBC bc, Physics phys);
326d68a66c4SJames Wright PetscErrorCode DMSetupByOrderBegin_FEM(PetscBool setup_faces, PetscBool setup_coords, PetscInt degree, PetscInt coord_order, PetscInt q_extra,
32785df0564SJames Wright                                        PetscInt num_fields, const PetscInt *field_sizes, DM dm);
328d68a66c4SJames Wright PetscErrorCode DMSetupByOrderEnd_FEM(PetscBool setup_coords, DM dm);
329d68a66c4SJames Wright PetscErrorCode DMSetupByOrder_FEM(PetscBool setup_faces, PetscBool setup_coords, PetscInt degree, PetscInt coord_order, PetscInt q_extra,
33085df0564SJames Wright                                   PetscInt num_fields, const PetscInt *field_sizes, DM dm);
33177841947SLeila Ghaffari 
33277841947SLeila Ghaffari // Refine DM for high-order viz
333731c13d7SJames Wright PetscErrorCode VizRefineDM(DM dm, User user, ProblemData problem, SimpleBC bc, Physics phys);
33477841947SLeila Ghaffari 
33577841947SLeila Ghaffari // -----------------------------------------------------------------------------
33677841947SLeila Ghaffari // Process command line options
33777841947SLeila Ghaffari // -----------------------------------------------------------------------------
33877841947SLeila Ghaffari // Register problems to be available on the command line
33977841947SLeila Ghaffari PetscErrorCode RegisterProblems_NS(AppCtx app_ctx);
34077841947SLeila Ghaffari 
34177841947SLeila Ghaffari // Process general command line options
3422b730f8bSJeremy L Thompson PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx, SimpleBC bc);
34377841947SLeila Ghaffari 
34477841947SLeila Ghaffari // -----------------------------------------------------------------------------
34577841947SLeila Ghaffari // Miscellaneous utility functions
34677841947SLeila Ghaffari // -----------------------------------------------------------------------------
3473a10b0eeSJames Wright PetscErrorCode GetInverseMultiplicity(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field,
3483a10b0eeSJames Wright                                       PetscBool get_global_multiplicity, CeedElemRestriction *elem_restr_inv_multiplicity,
3493a10b0eeSJames Wright                                       CeedVector *inv_multiplicity);
3502b730f8bSJeremy L Thompson PetscErrorCode ICs_FixMultiplicity(DM dm, CeedData ceed_data, User user, Vec Q_loc, Vec Q, CeedScalar time);
35177841947SLeila Ghaffari 
3523c9e7ad1SJames Wright PetscErrorCode DMPlexInsertBoundaryValues_FromICs(DM dm, PetscBool insert_essential, Vec Q_loc, PetscReal time, Vec face_geom_FVM, Vec cell_geom_FVM,
3532b730f8bSJeremy L Thompson                                                   Vec grad_FVM);
35477841947SLeila Ghaffari 
35577841947SLeila Ghaffari // Compare reference solution values with current test run for CI
3563c9e7ad1SJames Wright PetscErrorCode RegressionTest(AppCtx app_ctx, Vec Q);
35777841947SLeila Ghaffari 
35877841947SLeila Ghaffari // Get error for problems with exact solutions
3593c9e7ad1SJames Wright PetscErrorCode PrintError(CeedData ceed_data, DM dm, User user, Vec Q, PetscScalar final_time);
36077841947SLeila Ghaffari 
36177841947SLeila Ghaffari // Post-processing
362731c13d7SJames Wright PetscErrorCode PostProcess(TS ts, CeedData ceed_data, DM dm, ProblemData problem, User user, Vec Q, PetscScalar final_time);
36377841947SLeila Ghaffari 
36477841947SLeila Ghaffari // -- Gather initial Q values in case of continuation of simulation
36577841947SLeila Ghaffari PetscErrorCode SetupICsFromBinary(MPI_Comm comm, AppCtx app_ctx, Vec Q);
36677841947SLeila Ghaffari 
36777841947SLeila Ghaffari // Record boundary values from initial condition
3683c9e7ad1SJames Wright PetscErrorCode SetBCsFromICs(DM dm, Vec Q, Vec Q_loc);
36977841947SLeila Ghaffari 
3704de8550aSJed Brown // Versioning token for binary checkpoints
3710de6a49fSJames Wright extern const PetscInt32 FLUIDS_FILE_TOKEN;  // for backwards compatibility
3720de6a49fSJames Wright extern const PetscInt32 FLUIDS_FILE_TOKEN_32;
3730de6a49fSJames Wright extern const PetscInt32 FLUIDS_FILE_TOKEN_64;
3744de8550aSJed Brown 
375ef080ff9SJames Wright // Create appropriate mass qfunction based on number of components N
376ef080ff9SJames Wright PetscErrorCode CreateMassQFunction(Ceed ceed, CeedInt N, CeedInt q_data_size, CeedQFunction *qf);
377ef080ff9SJames Wright 
378999ff5c7SJames Wright PetscErrorCode NodalProjectionDataDestroy(NodalProjectionData context);
379999ff5c7SJames Wright 
380cbef7084SJames Wright PetscErrorCode PhastaDatFileOpen(const MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], const PetscInt char_array_len, PetscInt dims[2],
3818b892a05SJames Wright                                  FILE **fp);
3828b892a05SJames Wright 
383cbef7084SJames Wright PetscErrorCode PhastaDatFileGetNRows(const MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], PetscInt *nrows);
3848b892a05SJames Wright 
385cbef7084SJames Wright PetscErrorCode PhastaDatFileReadToArrayReal(const MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], PetscReal array[]);
3864cc9442bSJames Wright 
3878b892a05SJames Wright // -----------------------------------------------------------------------------
3888b892a05SJames Wright // Turbulence Statistics Collection Functions
3898b892a05SJames Wright // -----------------------------------------------------------------------------
3908b892a05SJames Wright 
391731c13d7SJames Wright PetscErrorCode TurbulenceStatisticsSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem);
392f5452247SJames Wright PetscErrorCode TSMonitor_TurbulenceStatistics(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, void *ctx);
393f5452247SJames Wright PetscErrorCode TurbulenceStatisticsDestroy(User user, CeedData ceed_data);
394fd170fd0SJames Wright 
39577841947SLeila Ghaffari // -----------------------------------------------------------------------------
3964cc9442bSJames Wright // Data-Driven Subgrid Stress (DD-SGS) Modeling Functions
3974cc9442bSJames Wright // -----------------------------------------------------------------------------
398731c13d7SJames Wright PetscErrorCode VelocityGradientProjectionSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem, StateVariable state_var_input,
3997618d7b7SJames Wright                                                CeedElemRestriction elem_restr_input, CeedBasis basis_input, NodalProjectionData *pgrad_velo_proj);
4007618d7b7SJames Wright PetscErrorCode VelocityGradientProjectionApply(NodalProjectionData grad_velo_proj, Vec Q_loc, Vec VelocityGradient);
401052409adSJames Wright PetscErrorCode GridAnisotropyTensorProjectionSetupApply(Ceed ceed, User user, CeedData ceed_data, CeedElemRestriction *elem_restr_grid_aniso,
402052409adSJames Wright                                                         CeedVector *grid_aniso_vector);
403900aec75SJames Wright PetscErrorCode GridAnisotropyTensorCalculateCollocatedVector(Ceed ceed, User user, CeedData ceed_data, CeedElemRestriction *elem_restr_grid_aniso,
404900aec75SJames Wright                                                              CeedVector *aniso_colloc_ceed, PetscInt *num_comp_aniso);
4054cc9442bSJames Wright 
4064cc9442bSJames Wright // -----------------------------------------------------------------------------
407dada6cc0SJames Wright // Boundary Condition Related Functions
408dada6cc0SJames Wright // -----------------------------------------------------------------------------
409dada6cc0SJames Wright 
410dada6cc0SJames Wright // Setup StrongBCs that use QFunctions
411731c13d7SJames Wright PetscErrorCode SetupStrongBC_Ceed(Ceed ceed, CeedData ceed_data, DM dm, User user, ProblemData problem, SimpleBC bc);
412b7c563b6SJeremy L Thompson 
413731c13d7SJames Wright PetscErrorCode FreestreamBCSetup(ProblemData problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, const StatePrimitive *reference);
414731c13d7SJames Wright PetscErrorCode OutflowBCSetup(ProblemData problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, const StatePrimitive *reference);
415731c13d7SJames Wright PetscErrorCode SlipBCSetup(ProblemData problem, DM dm, void *ctx, CeedQFunctionContext newtonian_ig_qfctx);
4162b730f8bSJeremy L Thompson 
4174e9802d1SJames Wright // -----------------------------------------------------------------------------
4184e9802d1SJames Wright // Differential Filtering Functions
4194e9802d1SJames Wright // -----------------------------------------------------------------------------
4204e9802d1SJames Wright 
421731c13d7SJames Wright PetscErrorCode DifferentialFilterSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem);
4224e9802d1SJames Wright PetscErrorCode DifferentialFilterDataDestroy(DiffFilterData diff_filter);
4234e9802d1SJames Wright PetscErrorCode TSMonitor_DifferentialFilter(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, void *ctx);
4244e9802d1SJames Wright PetscErrorCode DifferentialFilterApply(User user, const PetscReal solution_time, const Vec Q, Vec Filtered_Solution);
425731c13d7SJames Wright PetscErrorCode DifferentialFilterMmsICSetup(ProblemData problem);
426