xref: /libCEED/examples/fluids/navierstokes.h (revision a5b0ec6f41c4198e9c6bd74b9679c3c63ae70b36)
15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, 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 
9d0593705SJames Wright #include <ceed-utils.h>
1077841947SLeila Ghaffari #include <ceed.h>
1191c97f41SJames Wright #include <mat-ceed.h>
1277841947SLeila Ghaffari #include <petscts.h>
1377841947SLeila Ghaffari #include <stdbool.h>
142b730f8bSJeremy L Thompson 
154021610dSJames Wright #include "./include/petsc_ops.h"
1697baf651SJames Wright #include "qfunctions/newtonian_types.h"
1777841947SLeila Ghaffari 
1849a40c8aSKenneth E. Jansen #if PETSC_VERSION_LT(3, 21, 0)
19fd9d666bSJames Wright #error "PETSc v3.21 or later is required"
2049a40c8aSKenneth E. Jansen #endif
2149a40c8aSKenneth E. Jansen 
2277841947SLeila Ghaffari // -----------------------------------------------------------------------------
2377841947SLeila Ghaffari // Enums
2477841947SLeila Ghaffari // -----------------------------------------------------------------------------
2577841947SLeila Ghaffari 
2677841947SLeila Ghaffari // Euler - test cases
2777841947SLeila Ghaffari typedef enum {
28bc7bbd5dSLeila Ghaffari   EULER_TEST_ISENTROPIC_VORTEX = 0,
2977841947SLeila Ghaffari   EULER_TEST_1                 = 1,
3077841947SLeila Ghaffari   EULER_TEST_2                 = 2,
3177841947SLeila Ghaffari   EULER_TEST_3                 = 3,
3277841947SLeila Ghaffari   EULER_TEST_4                 = 4,
3332f166c6SLeila Ghaffari   EULER_TEST_5                 = 5,
3477841947SLeila Ghaffari } EulerTestType;
352b730f8bSJeremy L Thompson static const char *const EulerTestTypes[] = {"isentropic_vortex", "test_1",      "test_2", "test_3", "test_4", "test_5",
362b730f8bSJeremy L Thompson                                              "EulerTestType",     "EULER_TEST_", NULL};
3777841947SLeila Ghaffari 
38700ae941SJames Wright // Advection - Wind types
39700ae941SJames Wright static const char *const WindTypes[] = {"rotation", "translation", "WindType", "WIND_", NULL};
40700ae941SJames Wright 
417b77ddfdSJames Wright // Advection - Initial Condition Types
427b77ddfdSJames Wright static const char *const AdvectionICTypes[] = {"sphere", "cylinder", "cosine_hill", "skew", "AdvectionICType", "ADVECTIONIC_", NULL};
43700ae941SJames Wright 
44700ae941SJames Wright // Advection - Bubble Continuity Types
4593639ffbSJames Wright static const char *const BubbleContinuityTypes[] = {"smooth", "back_sharp", "thick", "cosine", "BubbleContinuityType", "BUBBLE_CONTINUITY_", NULL};
46700ae941SJames Wright 
4777841947SLeila Ghaffari // Stabilization methods
482b730f8bSJeremy L Thompson static const char *const StabilizationTypes[] = {"none", "SU", "SUPG", "StabilizationType", "STAB_", NULL};
4977841947SLeila Ghaffari 
50b18328c4SJames Wright // Stabilization tau constants
51b18328c4SJames Wright static const char *const StabilizationTauTypes[] = {"Ctau", "AdvDiff_Shakib", "AdvDiff_Shakib_P", "StabilizationTauType", "STAB_TAU_", NULL};
52b18328c4SJames Wright 
5351b00d91SJames Wright // Test mode type
548fb33541SJames Wright typedef enum {
558fb33541SJames Wright   TESTTYPE_NONE           = 0,
568fb33541SJames Wright   TESTTYPE_SOLVER         = 1,
578fb33541SJames Wright   TESTTYPE_TURB_SPANSTATS = 2,
58970fa48bSJames Wright   TESTTYPE_DIFF_FILTER    = 3,
598fb33541SJames Wright } TestType;
60970fa48bSJames Wright static const char *const TestTypes[] = {"none", "solver", "turb_spanstats", "diff_filter", "TestType", "TESTTYPE_", NULL};
618fb33541SJames Wright 
622526956eSJames Wright // Subgrid-Stress mode type
6319ffbc25SJames Wright typedef enum {
6419ffbc25SJames Wright   SGS_MODEL_NONE        = 0,
6519ffbc25SJames Wright   SGS_MODEL_DATA_DRIVEN = 1,
6619ffbc25SJames Wright } SGSModelType;
6719ffbc25SJames Wright static const char *const SGSModelTypes[] = {"none", "data_driven", "SGSModelType", "SGS_MODEL_", NULL};
6819ffbc25SJames Wright 
692526956eSJames Wright // Mesh transformation type
702526956eSJames Wright typedef enum {
712526956eSJames Wright   MESH_TRANSFORM_NONE      = 0,
722526956eSJames Wright   MESH_TRANSFORM_PLATEMESH = 1,
732526956eSJames Wright } MeshTransformType;
742526956eSJames Wright static const char *const MeshTransformTypes[] = {"none", "platemesh", "MeshTransformType", "MESH_TRANSFORM_", NULL};
752526956eSJames Wright 
76bd882c8aSJames Wright static const char *const DifferentialFilterDampingFunctions[] = {
77bd882c8aSJames Wright     "none", "van_driest", "mms", "DifferentialFilterDampingFunction", "DIFF_FILTER_DAMP_", NULL};
78bd882c8aSJames Wright 
7977841947SLeila Ghaffari // -----------------------------------------------------------------------------
8075d1798cSJames Wright // Log Events
8175d1798cSJames Wright // -----------------------------------------------------------------------------
8275d1798cSJames Wright extern PetscLogEvent FLUIDS_CeedOperatorApply;
8375d1798cSJames Wright extern PetscLogEvent FLUIDS_CeedOperatorAssemble;
8475d1798cSJames Wright extern PetscLogEvent FLUIDS_CeedOperatorAssembleDiagonal;
8575d1798cSJames Wright extern PetscLogEvent FLUIDS_CeedOperatorAssemblePointBlockDiagonal;
86844b3d4aSRiccardo Balin extern PetscLogEvent FLUIDS_SmartRedis_Init;
87844b3d4aSRiccardo Balin extern PetscLogEvent FLUIDS_SmartRedis_Meta;
88844b3d4aSRiccardo Balin extern PetscLogEvent FLUIDS_SmartRedis_Train;
89844b3d4aSRiccardo Balin extern PetscLogEvent FLUIDS_TrainDataCompute;
903737f832SJames Wright extern PetscLogEvent FLUIDS_DifferentialFilter;
913737f832SJames Wright extern PetscLogEvent FLUIDS_VelocityGradientProjection;
9275d1798cSJames Wright PetscErrorCode       RegisterLogEvents();
9375d1798cSJames Wright 
9475d1798cSJames Wright // -----------------------------------------------------------------------------
9577841947SLeila Ghaffari // Structs
9677841947SLeila Ghaffari // -----------------------------------------------------------------------------
9777841947SLeila Ghaffari // Structs declarations
9877841947SLeila Ghaffari typedef struct AppCtx_private   *AppCtx;
9977841947SLeila Ghaffari typedef struct CeedData_private *CeedData;
10077841947SLeila Ghaffari typedef struct User_private     *User;
10177841947SLeila Ghaffari typedef struct Units_private    *Units;
10277841947SLeila Ghaffari typedef struct SimpleBC_private *SimpleBC;
10377841947SLeila Ghaffari typedef struct Physics_private  *Physics;
10477841947SLeila Ghaffari 
10577841947SLeila Ghaffari // Application context from user command line options
10677841947SLeila Ghaffari struct AppCtx_private {
10777841947SLeila Ghaffari   // libCEED arguments
10877841947SLeila Ghaffari   char     ceed_resource[PETSC_MAX_PATH_LEN];  // libCEED backend
10977841947SLeila Ghaffari   PetscInt degree;
11077841947SLeila Ghaffari   PetscInt q_extra;
111544be873SJed Brown   // Solver arguments
112544be873SJed Brown   MatType amat_type;
11377841947SLeila Ghaffari   // Post-processing arguments
11437cbb16aSJed Brown   PetscInt  checkpoint_interval;
11577841947SLeila Ghaffari   PetscInt  viz_refine;
11677841947SLeila Ghaffari   PetscInt  cont_steps;
1174de8550aSJed Brown   PetscReal cont_time;
11869293791SJames Wright   char      cont_file[PETSC_MAX_PATH_LEN];
11969293791SJames Wright   char      cont_time_file[PETSC_MAX_PATH_LEN];
12077841947SLeila Ghaffari   char      output_dir[PETSC_MAX_PATH_LEN];
12169293791SJames Wright   PetscBool add_stepnum2bin;
12237cbb16aSJed Brown   PetscBool checkpoint_vtk;
12377841947SLeila Ghaffari   // Problem type arguments
12477841947SLeila Ghaffari   PetscFunctionList problems;
12577841947SLeila Ghaffari   char              problem_name[PETSC_MAX_PATH_LEN];
12677841947SLeila Ghaffari   // Test mode arguments
1278fb33541SJames Wright   TestType    test_type;
12877841947SLeila Ghaffari   PetscScalar test_tol;
129b7d66439SJames Wright   char        test_file_path[PETSC_MAX_PATH_LEN];
130b7d66439SJames Wright   // Turbulent spanwise statistics
131b7d66439SJames Wright   PetscBool         turb_spanstats_enable;
132b7d66439SJames Wright   PetscInt          turb_spanstats_collect_interval;
133b7d66439SJames Wright   PetscInt          turb_spanstats_viewer_interval;
134b7d66439SJames Wright   PetscViewer       turb_spanstats_viewer;
135b7d66439SJames Wright   PetscViewerFormat turb_spanstats_viewer_format;
136ca69d878SAdeleke O. Bankole   // Wall forces
137ca69d878SAdeleke O. Bankole   struct {
138ca69d878SAdeleke O. Bankole     PetscInt          num_wall;
139ca69d878SAdeleke O. Bankole     PetscInt         *walls;
140ca69d878SAdeleke O. Bankole     PetscViewer       viewer;
141ca69d878SAdeleke O. Bankole     PetscViewerFormat viewer_format;
142ca69d878SAdeleke O. Bankole     PetscBool         header_written;
143ca69d878SAdeleke O. Bankole   } wall_forces;
14419ffbc25SJames Wright   // Subgrid Stress Model
14519ffbc25SJames Wright   SGSModelType sgs_model_type;
14628134cfaSJames Wright   PetscBool    sgs_train_enable;
1474e9802d1SJames Wright   // Differential Filtering
1484e9802d1SJames Wright   PetscBool         diff_filter_monitor;
1492526956eSJames Wright   MeshTransformType mesh_transform_type;
15077841947SLeila Ghaffari };
15177841947SLeila Ghaffari 
15277841947SLeila Ghaffari // libCEED data struct
15377841947SLeila Ghaffari struct CeedData_private {
15477841947SLeila Ghaffari   CeedVector           x_coord, q_data;
155e9c36be0SJames Wright   CeedBasis            basis_x, basis_q;
15677841947SLeila Ghaffari   CeedElemRestriction  elem_restr_x, elem_restr_q, elem_restr_qd_i;
1575263e9c6SJames Wright   OperatorApplyContext op_ics_ctx;
158e9c36be0SJames Wright   CeedQFunction        qf_setup_sur;
15977841947SLeila Ghaffari };
16077841947SLeila Ghaffari 
16151ee423eSJames Wright typedef struct {
16251ee423eSJames Wright   DM                    dm;
1631737222fSJames Wright   PetscSF               sf;  // For communicating child data to parents
164ed331efdSJames Wright   OperatorApplyContext  op_stats_collect_ctx, op_proj_rhs_ctx;
16551ee423eSJames Wright   PetscInt              num_comp_stats;
166ed331efdSJames Wright   Vec                   Child_Stats_loc, Parent_Stats_loc;
167a175e481SJames Wright   KSP                   ksp;         // For the L^2 projection solve
168a175e481SJames Wright   CeedScalar            span_width;  // spanwise width of the child domain
169b7d66439SJames Wright   PetscBool             do_mms_test;
1704021610dSJames Wright   OperatorApplyContext  mms_error_ctx;
171495b9769SJames Wright   CeedContextFieldLabel solution_time_label, previous_time_label;
172cbef7084SJames Wright } SpanStatsData;
17351ee423eSJames Wright 
174999ff5c7SJames Wright typedef struct {
175999ff5c7SJames Wright   DM                   dm;
176999ff5c7SJames Wright   PetscInt             num_comp;
177999ff5c7SJames Wright   OperatorApplyContext l2_rhs_ctx;
178999ff5c7SJames Wright   KSP                  ksp;
179999ff5c7SJames Wright } *NodalProjectionData;
180999ff5c7SJames Wright 
1816b3fb9aeSJames Wright typedef PetscErrorCode (*SgsDDNodalStressEval)(User user, Vec Q_loc, Vec VelocityGradient, Vec SGSNodal_loc);
1821250e899SJames Wright typedef PetscErrorCode (*SgsDDNodalStressInference)(Vec DD_Inputs_loc, Vec DD_Outputs_loc, void *ctx);
1839a17443dSJames Wright typedef struct {
1841250e899SJames Wright   DM                        dm_sgs, dm_dd_inputs, dm_dd_outputs;
1855f5d6789SAlex Lindsay   PetscInt                  num_comp_sgs, num_comp_inputs, num_comp_outputs;
1861250e899SJames Wright   OperatorApplyContext      op_nodal_evaluation_ctx, op_nodal_dd_inputs_ctx, op_nodal_dd_outputs_ctx, op_sgs_apply_ctx;
1871250e899SJames Wright   CeedVector                sgs_nodal_ceed, grad_velo_ceed;
1886b3fb9aeSJames Wright   SgsDDNodalStressEval      sgs_nodal_eval;
1891250e899SJames Wright   SgsDDNodalStressInference sgs_nodal_inference;
1901250e899SJames Wright   void                     *sgs_nodal_inference_ctx;
1911250e899SJames Wright   PetscErrorCode (*sgs_nodal_inference_ctx_destroy)(void *ctx);
192cbef7084SJames Wright } *SgsDDData;
1939a17443dSJames Wright 
1944e9802d1SJames Wright typedef struct {
195ee3b213aSJames Wright   DM                   dm_dd_training;
196c79b0730SJames Wright   PetscInt             num_comp_dd_inputs, write_data_interval, num_filter_widths;
197c79b0730SJames Wright   PetscScalar          filter_widths[16];
198ee3b213aSJames Wright   OperatorApplyContext op_training_data_calc_ctx;
199ee3b213aSJames Wright   NodalProjectionData  filtered_grad_velo_proj;
200ee3b213aSJames Wright   size_t               training_data_array_dims[2];
201ee3b213aSJames Wright   PetscBool            overwrite_training_data;
202ee3b213aSJames Wright } *SGS_DD_TrainingData;
203ee3b213aSJames Wright 
204ee3b213aSJames Wright typedef struct {
2054e9802d1SJames Wright   DM                    dm_filter;
20681530087SJames Wright   PetscInt              num_filtered_fields;
20781530087SJames Wright   CeedInt              *num_field_components;
208051427eeSJames Wright   PetscInt              field_prim_state, field_velo_prod;
2094e9802d1SJames Wright   OperatorApplyContext  op_rhs_ctx;
2104e9802d1SJames Wright   KSP                   ksp;
21156f5e811SJames Wright   PetscObjectState      X_loc_state;
2122029a677SJames Wright   PetscBool             do_mms_test;
213c79b0730SJames Wright   CeedContextFieldLabel filter_width_scaling_label;
2144e9802d1SJames Wright } *DiffFilterData;
2154e9802d1SJames Wright 
2168146534cSJames Wright typedef struct {
2178146534cSJames Wright   void    *client;
2188146534cSJames Wright   char     rank_id_name[16];
2198146534cSJames Wright   PetscInt collocated_database_num_ranks;
2208146534cSJames Wright } *SmartSimData;
2218146534cSJames Wright 
22277841947SLeila Ghaffari // PETSc user data
22377841947SLeila Ghaffari struct User_private {
22477841947SLeila Ghaffari   MPI_Comm             comm;
22577841947SLeila Ghaffari   DM                   dm;
22677841947SLeila Ghaffari   DM                   dm_viz;
22777841947SLeila Ghaffari   Mat                  interp_viz;
22877841947SLeila Ghaffari   Ceed                 ceed;
22977841947SLeila Ghaffari   Units                units;
23004292f7dSJames Wright   Vec                  Q_loc, Q_dot_loc;
23177841947SLeila Ghaffari   Physics              phys;
23277841947SLeila Ghaffari   AppCtx               app_ctx;
23391c97f41SJames Wright   CeedVector           q_ceed, q_dot_ceed, g_ceed, x_ceed;
234*a5b0ec6fSJames Wright   CeedOperator         op_ifunction;
23591c97f41SJames Wright   Mat                  mat_ijacobian;
23604292f7dSJames Wright   KSP                  mass_ksp;
2379ad5e8e4SJames Wright   OperatorApplyContext op_rhs_ctx, op_strong_bc_ctx;
23815637395SJames Wright   CeedScalar           time_bc_set;
239cbef7084SJames Wright   SpanStatsData        spanstats;
240999ff5c7SJames Wright   NodalProjectionData  grad_velo_proj;
241cbef7084SJames Wright   SgsDDData            sgs_dd_data;
2424e9802d1SJames Wright   DiffFilterData       diff_filter;
2438146534cSJames Wright   SmartSimData         smartsim;
244ee3b213aSJames Wright   SGS_DD_TrainingData  sgs_dd_train;
24577841947SLeila Ghaffari };
24677841947SLeila Ghaffari 
24777841947SLeila Ghaffari // Units
24877841947SLeila Ghaffari struct Units_private {
24977841947SLeila Ghaffari   // fundamental units
25077841947SLeila Ghaffari   PetscScalar meter;
25177841947SLeila Ghaffari   PetscScalar kilogram;
25277841947SLeila Ghaffari   PetscScalar second;
25377841947SLeila Ghaffari   PetscScalar Kelvin;
25477841947SLeila Ghaffari   // derived units
25577841947SLeila Ghaffari   PetscScalar Pascal;
25677841947SLeila Ghaffari   PetscScalar J_per_kg_K;
25777841947SLeila Ghaffari   PetscScalar m_per_squared_s;
25877841947SLeila Ghaffari   PetscScalar W_per_m_K;
25977841947SLeila Ghaffari   PetscScalar Joule;
26077841947SLeila Ghaffari };
26177841947SLeila Ghaffari 
26277841947SLeila Ghaffari // Boundary conditions
26377841947SLeila Ghaffari struct SimpleBC_private {
2642fe7aee7SLeila Ghaffari   PetscInt num_wall,  // Number of faces with wall BCs
2652fe7aee7SLeila Ghaffari       wall_comps[5],  // An array of constrained component numbers
2662fe7aee7SLeila Ghaffari       num_comps,
2677c5bba50SJames Wright       num_symmetry[3],  // Number of faces with symmetry BCs
2689f844368SJames Wright       num_inflow, num_outflow, num_freestream, num_slip;
2699f844368SJames Wright   PetscInt walls[16], symmetries[3][16], inflows[16], outflows[16], freestreams[16], slips[16];
27077841947SLeila Ghaffari };
27177841947SLeila Ghaffari 
27277841947SLeila Ghaffari // Struct that contains all enums and structs used for the physics of all problems
27377841947SLeila Ghaffari struct Physics_private {
27477841947SLeila Ghaffari   PetscBool             implicit;
27597baf651SJames Wright   StateVariable         state_var;
27611436a05SJames Wright   CeedContextFieldLabel solution_time_label;
277cd4035ffSJames Wright   CeedContextFieldLabel stg_solution_time_label;
27888626eedSJames Wright   CeedContextFieldLabel timestep_size_label;
279841e4c73SJed Brown   CeedContextFieldLabel ics_time_label;
280e334ad8fSJed Brown   CeedContextFieldLabel ijacobian_time_shift_label;
28177841947SLeila Ghaffari };
28277841947SLeila Ghaffari 
28391e5af17SJed Brown typedef struct {
28491e5af17SJed Brown   CeedQFunctionUser    qfunction;
28591e5af17SJed Brown   const char          *qfunction_loc;
286841e4c73SJed Brown   CeedQFunctionContext qfunction_context;
28791e5af17SJed Brown } ProblemQFunctionSpec;
28891e5af17SJed Brown 
28977841947SLeila Ghaffari // Problem specific data
290731c13d7SJames Wright typedef struct ProblemData_private *ProblemData;
291841e4c73SJed Brown struct ProblemData_private {
292e334ad8fSJed Brown   CeedInt              dim, q_data_size_vol, q_data_size_sur, jac_data_size_sur;
2931864f1c2SLeila Ghaffari   CeedScalar           dm_scale;
2942b730f8bSJeremy L Thompson   ProblemQFunctionSpec setup_vol, setup_sur, ics, apply_vol_rhs, apply_vol_ifunction, apply_vol_ijacobian, apply_inflow, apply_outflow,
2959f844368SJames Wright       apply_freestream, apply_slip, apply_inflow_jacobian, apply_outflow_jacobian, apply_freestream_jacobian, apply_slip_jacobian;
29677841947SLeila Ghaffari   bool      non_zero_time;
297752a08a7SJames Wright   PetscBool bc_from_ics, use_strong_bc_ceed, uses_newtonian;
298731c13d7SJames Wright   PetscErrorCode (*print_info)(User, ProblemData, AppCtx);
299b4e9a8f8SJames Wright   PetscErrorCode (*create_mass_operator)(User, CeedOperator *);
300841e4c73SJed Brown };
30177841947SLeila Ghaffari 
302841e4c73SJed Brown extern int FreeContextPetsc(void *);
303841e4c73SJed Brown 
30477841947SLeila Ghaffari // -----------------------------------------------------------------------------
30577841947SLeila Ghaffari // Set up problems
30677841947SLeila Ghaffari // -----------------------------------------------------------------------------
30777841947SLeila Ghaffari // Set up function for each problem
308731c13d7SJames Wright extern PetscErrorCode NS_TAYLOR_GREEN(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
309731c13d7SJames Wright extern PetscErrorCode NS_GAUSSIAN_WAVE(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
310731c13d7SJames Wright extern PetscErrorCode NS_CHANNEL(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
311731c13d7SJames Wright extern PetscErrorCode NS_BLASIUS(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
312731c13d7SJames Wright extern PetscErrorCode NS_NEWTONIAN_IG(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
313731c13d7SJames Wright extern PetscErrorCode NS_DENSITY_CURRENT(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
314731c13d7SJames Wright extern PetscErrorCode NS_EULER_VORTEX(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
315731c13d7SJames Wright extern PetscErrorCode NS_SHOCKTUBE(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
316731c13d7SJames Wright extern PetscErrorCode NS_ADVECTION(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
317731c13d7SJames Wright extern PetscErrorCode NS_ADVECTION2D(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
31877841947SLeila Ghaffari 
31977841947SLeila Ghaffari // Print function for each problem
320731c13d7SJames Wright extern PetscErrorCode PRINT_NEWTONIAN(User user, ProblemData problem, AppCtx app_ctx);
32177841947SLeila Ghaffari 
322731c13d7SJames Wright extern PetscErrorCode PRINT_EULER_VORTEX(User user, ProblemData problem, AppCtx app_ctx);
32377841947SLeila Ghaffari 
324731c13d7SJames Wright extern PetscErrorCode PRINT_SHOCKTUBE(User user, ProblemData problem, AppCtx app_ctx);
325019b7682STimothy Aiken 
326731c13d7SJames Wright extern PetscErrorCode PRINT_ADVECTION(User user, ProblemData problem, AppCtx app_ctx);
32777841947SLeila Ghaffari 
328731c13d7SJames Wright extern PetscErrorCode PRINT_ADVECTION2D(User user, ProblemData problem, AppCtx app_ctx);
32977841947SLeila Ghaffari 
330731c13d7SJames Wright PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData problem, MPI_Comm comm);
3312e31f396SJames Wright 
33277841947SLeila Ghaffari // -----------------------------------------------------------------------------
33377841947SLeila Ghaffari // libCEED functions
33477841947SLeila Ghaffari // -----------------------------------------------------------------------------
33577841947SLeila Ghaffari // Utility function to create local CEED restriction
336431cd09aSJames Wright PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt label_value, PetscInt dm_field,
337431cd09aSJames Wright                                          CeedElemRestriction *elem_restr);
33877841947SLeila Ghaffari 
339bb85d312SJames Wright PetscErrorCode DMPlexCeedElemRestrictionCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field,
340bb85d312SJames Wright                                                CeedElemRestriction *restriction);
341bb85d312SJames Wright PetscErrorCode DMPlexCeedElemRestrictionCoordinateCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height,
342bb85d312SJames Wright                                                          CeedElemRestriction *restriction);
343bb85d312SJames Wright PetscErrorCode DMPlexCeedElemRestrictionQDataCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height,
344bb85d312SJames Wright                                                     PetscInt q_data_size, CeedElemRestriction *restriction);
345bb85d312SJames Wright PetscErrorCode DMPlexCeedElemRestrictionCollocatedCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height,
346bb85d312SJames Wright                                                          PetscInt q_data_size, CeedElemRestriction *restriction);
34777841947SLeila Ghaffari 
3480814d5a7SKenneth E. Jansen PetscErrorCode CreateBasisFromPlex(Ceed ceed, DM dm, DMLabel domain_label, CeedInt label_value, CeedInt height, CeedInt dm_field, CeedBasis *basis);
3490814d5a7SKenneth E. Jansen 
350731c13d7SJames Wright PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, AppCtx app_ctx, ProblemData problem, SimpleBC bc);
35177841947SLeila Ghaffari 
35277841947SLeila Ghaffari // -----------------------------------------------------------------------------
35377841947SLeila Ghaffari // Time-stepping functions
35477841947SLeila Ghaffari // -----------------------------------------------------------------------------
35577841947SLeila Ghaffari // RHS (Explicit time-stepper) function setup
35677841947SLeila Ghaffari PetscErrorCode RHS_NS(TS ts, PetscReal t, Vec Q, Vec G, void *user_data);
35777841947SLeila Ghaffari 
35877841947SLeila Ghaffari // Implicit time-stepper function setup
3592b730f8bSJeremy L Thompson PetscErrorCode IFunction_NS(TS ts, PetscReal t, Vec Q, Vec Q_dot, Vec G, void *user_data);
36077841947SLeila Ghaffari 
36177841947SLeila Ghaffari // User provided TS Monitor
3622b730f8bSJeremy L Thompson PetscErrorCode TSMonitor_NS(TS ts, PetscInt step_no, PetscReal time, Vec Q, void *ctx);
36377841947SLeila Ghaffari 
36477841947SLeila Ghaffari // TS: Create, setup, and solve
3652b730f8bSJeremy L Thompson PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, Vec *Q, PetscScalar *f_time, TS *ts);
36677841947SLeila Ghaffari 
367a0b9a424SJames Wright // Update Boundary Values when time has changed
368a0b9a424SJames Wright PetscErrorCode UpdateBoundaryValues(User user, Vec Q_loc, PetscReal t);
369a0b9a424SJames Wright 
37077841947SLeila Ghaffari // -----------------------------------------------------------------------------
37177841947SLeila Ghaffari // Setup DM
37277841947SLeila Ghaffari // -----------------------------------------------------------------------------
3731864f1c2SLeila Ghaffari // Create mesh
374731c13d7SJames Wright PetscErrorCode CreateDM(MPI_Comm comm, ProblemData problem, MatType, VecType, DM *dm);
37577841947SLeila Ghaffari 
37677841947SLeila Ghaffari // Set up DM
377731c13d7SJames Wright PetscErrorCode SetUpDM(DM dm, ProblemData problem, PetscInt degree, PetscInt q_extra, SimpleBC bc, Physics phys);
378d68a66c4SJames Wright PetscErrorCode DMSetupByOrderBegin_FEM(PetscBool setup_faces, PetscBool setup_coords, PetscInt degree, PetscInt coord_order, PetscInt q_extra,
37985df0564SJames Wright                                        PetscInt num_fields, const PetscInt *field_sizes, DM dm);
380d68a66c4SJames Wright PetscErrorCode DMSetupByOrderEnd_FEM(PetscBool setup_coords, DM dm);
381d68a66c4SJames Wright PetscErrorCode DMSetupByOrder_FEM(PetscBool setup_faces, PetscBool setup_coords, PetscInt degree, PetscInt coord_order, PetscInt q_extra,
38285df0564SJames Wright                                   PetscInt num_fields, const PetscInt *field_sizes, DM dm);
38377841947SLeila Ghaffari 
38477841947SLeila Ghaffari // Refine DM for high-order viz
385731c13d7SJames Wright PetscErrorCode VizRefineDM(DM dm, User user, ProblemData problem, SimpleBC bc, Physics phys);
38677841947SLeila Ghaffari 
38777841947SLeila Ghaffari // -----------------------------------------------------------------------------
38877841947SLeila Ghaffari // Process command line options
38977841947SLeila Ghaffari // -----------------------------------------------------------------------------
39077841947SLeila Ghaffari // Register problems to be available on the command line
39177841947SLeila Ghaffari PetscErrorCode RegisterProblems_NS(AppCtx app_ctx);
39277841947SLeila Ghaffari 
39377841947SLeila Ghaffari // Process general command line options
3942b730f8bSJeremy L Thompson PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx, SimpleBC bc);
39577841947SLeila Ghaffari 
39677841947SLeila Ghaffari // -----------------------------------------------------------------------------
39777841947SLeila Ghaffari // Miscellaneous utility functions
39877841947SLeila Ghaffari // -----------------------------------------------------------------------------
3993a10b0eeSJames Wright PetscErrorCode GetInverseMultiplicity(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field,
4003a10b0eeSJames Wright                                       PetscBool get_global_multiplicity, CeedElemRestriction *elem_restr_inv_multiplicity,
4013a10b0eeSJames Wright                                       CeedVector *inv_multiplicity);
4022b730f8bSJeremy L Thompson PetscErrorCode ICs_FixMultiplicity(DM dm, CeedData ceed_data, User user, Vec Q_loc, Vec Q, CeedScalar time);
40377841947SLeila Ghaffari 
4043c9e7ad1SJames Wright PetscErrorCode DMPlexInsertBoundaryValues_FromICs(DM dm, PetscBool insert_essential, Vec Q_loc, PetscReal time, Vec face_geom_FVM, Vec cell_geom_FVM,
4052b730f8bSJeremy L Thompson                                                   Vec grad_FVM);
40677841947SLeila Ghaffari 
40777841947SLeila Ghaffari // Compare reference solution values with current test run for CI
4083c9e7ad1SJames Wright PetscErrorCode RegressionTest(AppCtx app_ctx, Vec Q);
40977841947SLeila Ghaffari 
41077841947SLeila Ghaffari // Get error for problems with exact solutions
4113c9e7ad1SJames Wright PetscErrorCode PrintError(CeedData ceed_data, DM dm, User user, Vec Q, PetscScalar final_time);
41277841947SLeila Ghaffari 
41377841947SLeila Ghaffari // Post-processing
414731c13d7SJames Wright PetscErrorCode PostProcess(TS ts, CeedData ceed_data, DM dm, ProblemData problem, User user, Vec Q, PetscScalar final_time);
41577841947SLeila Ghaffari 
41677841947SLeila Ghaffari // -- Gather initial Q values in case of continuation of simulation
41777841947SLeila Ghaffari PetscErrorCode SetupICsFromBinary(MPI_Comm comm, AppCtx app_ctx, Vec Q);
41877841947SLeila Ghaffari 
41977841947SLeila Ghaffari // Record boundary values from initial condition
4203c9e7ad1SJames Wright PetscErrorCode SetBCsFromICs(DM dm, Vec Q, Vec Q_loc);
42177841947SLeila Ghaffari 
4224de8550aSJed Brown // Versioning token for binary checkpoints
4230de6a49fSJames Wright extern const PetscInt32 FLUIDS_FILE_TOKEN;  // for backwards compatibility
4240de6a49fSJames Wright extern const PetscInt32 FLUIDS_FILE_TOKEN_32;
4250de6a49fSJames Wright extern const PetscInt32 FLUIDS_FILE_TOKEN_64;
4264de8550aSJed Brown 
427ef080ff9SJames Wright // Create appropriate mass qfunction based on number of components N
428ef080ff9SJames Wright PetscErrorCode CreateMassQFunction(Ceed ceed, CeedInt N, CeedInt q_data_size, CeedQFunction *qf);
429ef080ff9SJames Wright 
430999ff5c7SJames Wright PetscErrorCode NodalProjectionDataDestroy(NodalProjectionData context);
431999ff5c7SJames Wright 
432cbef7084SJames Wright PetscErrorCode PhastaDatFileOpen(const MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], const PetscInt char_array_len, PetscInt dims[2],
4338b892a05SJames Wright                                  FILE **fp);
4348b892a05SJames Wright 
435cbef7084SJames Wright PetscErrorCode PhastaDatFileGetNRows(const MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], PetscInt *nrows);
4368b892a05SJames Wright 
437cbef7084SJames Wright PetscErrorCode PhastaDatFileReadToArrayReal(const MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], PetscReal array[]);
4384cc9442bSJames Wright 
4398b892a05SJames Wright // -----------------------------------------------------------------------------
4408b892a05SJames Wright // Turbulence Statistics Collection Functions
4418b892a05SJames Wright // -----------------------------------------------------------------------------
4428b892a05SJames Wright 
443731c13d7SJames Wright PetscErrorCode TurbulenceStatisticsSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem);
444f5452247SJames Wright PetscErrorCode TSMonitor_TurbulenceStatistics(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, void *ctx);
445f5452247SJames Wright PetscErrorCode TurbulenceStatisticsDestroy(User user, CeedData ceed_data);
446fd170fd0SJames Wright 
44777841947SLeila Ghaffari // -----------------------------------------------------------------------------
4484cc9442bSJames Wright // Data-Driven Subgrid Stress (DD-SGS) Modeling Functions
4494cc9442bSJames Wright // -----------------------------------------------------------------------------
4504cc9442bSJames Wright 
451731c13d7SJames Wright PetscErrorCode SgsDDSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem);
452cbef7084SJames Wright PetscErrorCode SgsDDDataDestroy(SgsDDData sgs_dd_data);
4538f5ab23bSJames Wright PetscErrorCode SgsDDApplyIFunction(User user, const Vec Q_loc, Vec G_loc);
454731c13d7SJames Wright PetscErrorCode VelocityGradientProjectionSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem, StateVariable state_var_input,
4557618d7b7SJames Wright                                                CeedElemRestriction elem_restr_input, CeedBasis basis_input, NodalProjectionData *pgrad_velo_proj);
4567618d7b7SJames Wright PetscErrorCode VelocityGradientProjectionApply(NodalProjectionData grad_velo_proj, Vec Q_loc, Vec VelocityGradient);
457052409adSJames Wright PetscErrorCode GridAnisotropyTensorProjectionSetupApply(Ceed ceed, User user, CeedData ceed_data, CeedElemRestriction *elem_restr_grid_aniso,
458052409adSJames Wright                                                         CeedVector *grid_aniso_vector);
459900aec75SJames Wright PetscErrorCode GridAnisotropyTensorCalculateCollocatedVector(Ceed ceed, User user, CeedData ceed_data, CeedElemRestriction *elem_restr_grid_aniso,
460900aec75SJames Wright                                                              CeedVector *aniso_colloc_ceed, PetscInt *num_comp_aniso);
4614cc9442bSJames Wright 
4624cc9442bSJames Wright // -----------------------------------------------------------------------------
463dada6cc0SJames Wright // Boundary Condition Related Functions
464dada6cc0SJames Wright // -----------------------------------------------------------------------------
465dada6cc0SJames Wright 
466dada6cc0SJames Wright // Setup StrongBCs that use QFunctions
467731c13d7SJames Wright PetscErrorCode SetupStrongBC_Ceed(Ceed ceed, CeedData ceed_data, DM dm, User user, ProblemData problem, SimpleBC bc);
468b7c563b6SJeremy L Thompson 
469731c13d7SJames Wright PetscErrorCode FreestreamBCSetup(ProblemData problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, const StatePrimitive *reference);
470731c13d7SJames Wright PetscErrorCode OutflowBCSetup(ProblemData problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, const StatePrimitive *reference);
471731c13d7SJames Wright PetscErrorCode SlipBCSetup(ProblemData problem, DM dm, void *ctx, CeedQFunctionContext newtonian_ig_qfctx);
4722b730f8bSJeremy L Thompson 
4734e9802d1SJames Wright // -----------------------------------------------------------------------------
4744e9802d1SJames Wright // Differential Filtering Functions
4754e9802d1SJames Wright // -----------------------------------------------------------------------------
4764e9802d1SJames Wright 
477731c13d7SJames Wright PetscErrorCode DifferentialFilterSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem);
4784e9802d1SJames Wright PetscErrorCode DifferentialFilterDataDestroy(DiffFilterData diff_filter);
4794e9802d1SJames Wright PetscErrorCode TSMonitor_DifferentialFilter(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, void *ctx);
4804e9802d1SJames Wright PetscErrorCode DifferentialFilterApply(User user, const PetscReal solution_time, const Vec Q, Vec Filtered_Solution);
481731c13d7SJames Wright PetscErrorCode DifferentialFilterMmsICSetup(ProblemData problem);
4824e9802d1SJames Wright 
4838146534cSJames Wright // -----------------------------------------------------------------------------
4848146534cSJames Wright // SGS Data-Driven Training via SmartSim
4858146534cSJames Wright // -----------------------------------------------------------------------------
4868146534cSJames Wright PetscErrorCode SmartSimSetup(User user);
487b306c3f1SJames Wright PetscErrorCode SmartSimDataDestroy(SmartSimData smartsim);
488731c13d7SJames Wright PetscErrorCode SGS_DD_TrainingSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem);
489ee3b213aSJames Wright PetscErrorCode TSMonitor_SGS_DD_Training(TS ts, PetscInt step_num, PetscReal solution_time, Vec Q, void *ctx);
4901a7db67cSJames Wright PetscErrorCode TSPostStep_SGS_DD_Training(TS ts);
491ee3b213aSJames Wright PetscErrorCode SGS_DD_TrainingDataDestroy(SGS_DD_TrainingData sgs_dd_train);
492