xref: /honee/include/navierstokes.h (revision ae2b091fac884a554e48acc4b4c187524c2a2818)
1*ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2*ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
3149fb536SJames Wright #pragma once
4149fb536SJames Wright 
5149fb536SJames Wright #include <ceed.h>
6149fb536SJames Wright #include <bc_definition.h>
7149fb536SJames Wright #include <log_events.h>
8149fb536SJames Wright #include <mat-ceed.h>
9149fb536SJames Wright #include <petsc-ceed-utils.h>
10149fb536SJames Wright #include <petscts.h>
11149fb536SJames Wright #include <stdbool.h>
12149fb536SJames Wright 
13149fb536SJames Wright #include <petsc_ops.h>
14149fb536SJames Wright #include "../qfunctions/newtonian_types.h"
15149fb536SJames Wright 
16149fb536SJames Wright #if PETSC_VERSION_LT(3, 21, 0)
17149fb536SJames Wright #error "PETSc v3.21 or later is required"
18149fb536SJames Wright #endif
19149fb536SJames Wright 
20149fb536SJames Wright // -----------------------------------------------------------------------------
21149fb536SJames Wright // Enums
22149fb536SJames Wright // -----------------------------------------------------------------------------
23149fb536SJames Wright 
24149fb536SJames Wright // Euler - test cases
25149fb536SJames Wright typedef enum {
26149fb536SJames Wright   EULER_TEST_ISENTROPIC_VORTEX = 0,
27149fb536SJames Wright   EULER_TEST_1                 = 1,
28149fb536SJames Wright   EULER_TEST_2                 = 2,
29149fb536SJames Wright   EULER_TEST_3                 = 3,
30149fb536SJames Wright   EULER_TEST_4                 = 4,
31149fb536SJames Wright   EULER_TEST_5                 = 5,
32149fb536SJames Wright } EulerTestType;
33149fb536SJames Wright static const char *const EulerTestTypes[] = {"ISENTROPIC_VORTEX", "1", "2", "3", "4", "5", "EulerTestType", "EULER_TEST_", NULL};
34149fb536SJames Wright 
35149fb536SJames Wright // Advection - Wind types
36149fb536SJames Wright static const char *const WindTypes[] = {"ROTATION", "TRANSLATION", "WindType", "WIND_", NULL};
37149fb536SJames Wright 
38149fb536SJames Wright // Advection - Initial Condition Types
39149fb536SJames Wright static const char *const AdvectionICTypes[] = {"SPHERE", "CYLINDER", "COSINE_HILL", "SKEW", "AdvectionICType", "ADVECTIONIC_", NULL};
40149fb536SJames Wright 
41149fb536SJames Wright // Advection - Bubble Continuity Types
42149fb536SJames Wright static const char *const BubbleContinuityTypes[] = {"SMOOTH", "BACK_SHARP", "THICK", "COSINE", "BubbleContinuityType", "BUBBLE_CONTINUITY_", NULL};
43149fb536SJames Wright 
44149fb536SJames Wright // Stabilization methods
45149fb536SJames Wright static const char *const StabilizationTypes[] = {"NONE", "SU", "SUPG", "StabilizationType", "STAB_", NULL};
46149fb536SJames Wright 
47149fb536SJames Wright // Stabilization tau constants
48149fb536SJames Wright static const char *const StabilizationTauTypes[] = {"CTAU", "ADVDIFF_SHAKIB", "ADVDIFF_SHAKIB_P", "StabilizationTauType", "STAB_TAU_", NULL};
49149fb536SJames Wright 
50149fb536SJames Wright // Test mode type
51149fb536SJames Wright typedef enum {
52149fb536SJames Wright   TESTTYPE_NONE           = 0,
53149fb536SJames Wright   TESTTYPE_SOLVER         = 1,
54149fb536SJames Wright   TESTTYPE_TURB_SPANSTATS = 2,
55149fb536SJames Wright   TESTTYPE_DIFF_FILTER    = 3,
56149fb536SJames Wright } TestType;
57149fb536SJames Wright static const char *const TestTypes[] = {"NONE", "SOLVER", "TURB_SPANSTATS", "DIFF_FILTER", "TestType", "TESTTYPE_", NULL};
58149fb536SJames Wright 
59149fb536SJames Wright // Subgrid-Stress mode type
60149fb536SJames Wright typedef enum {
61149fb536SJames Wright   SGS_MODEL_NONE        = 0,
62149fb536SJames Wright   SGS_MODEL_DATA_DRIVEN = 1,
63149fb536SJames Wright } SGSModelType;
64149fb536SJames Wright static const char *const SGSModelTypes[] = {"NONE", "DATA_DRIVEN", "SGSModelType", "SGS_MODEL_", NULL};
65149fb536SJames Wright 
66149fb536SJames Wright // Subgrid-Stress mode type
67149fb536SJames Wright typedef enum {
68149fb536SJames Wright   SGS_MODEL_DD_FUSED           = 0,
69149fb536SJames Wright   SGS_MODEL_DD_SEQENTIAL_CEED  = 1,
70149fb536SJames Wright   SGS_MODEL_DD_SEQENTIAL_TORCH = 2,
71149fb536SJames Wright } SGSModelDDImplementation;
72149fb536SJames Wright static const char *const SGSModelDDImplementations[] = {"FUSED", "SEQUENTIAL_CEED", "SEQUENTIAL_TORCH", "SGSModelDDImplementation", "SGS_MODEL_DD_",
73149fb536SJames Wright                                                         NULL};
74149fb536SJames Wright 
75149fb536SJames Wright // Mesh transformation type
76149fb536SJames Wright typedef enum {
77149fb536SJames Wright   MESH_TRANSFORM_NONE      = 0,
78149fb536SJames Wright   MESH_TRANSFORM_PLATEMESH = 1,
79149fb536SJames Wright } MeshTransformType;
80149fb536SJames Wright static const char *const MeshTransformTypes[] = {"NONE", "PLATEMESH", "MeshTransformType", "MESH_TRANSFORM_", NULL};
81149fb536SJames Wright 
82149fb536SJames Wright static const char *const DifferentialFilterDampingFunctions[] = {
83149fb536SJames Wright     "NONE", "VAN_DRIEST", "MMS", "DifferentialFilterDampingFunction", "DIFF_FILTER_DAMP_", NULL};
84149fb536SJames Wright 
85149fb536SJames Wright // -----------------------------------------------------------------------------
86149fb536SJames Wright // Structs
87149fb536SJames Wright // -----------------------------------------------------------------------------
88149fb536SJames Wright // Structs declarations
89149fb536SJames Wright typedef struct AppCtx_private      *AppCtx;
90149fb536SJames Wright typedef struct CeedData_private    *CeedData;
91149fb536SJames Wright typedef struct User_private        *User;
92149fb536SJames Wright typedef struct Units_private       *Units;
93149fb536SJames Wright typedef struct SimpleBC_private    *SimpleBC;
94149fb536SJames Wright typedef struct Physics_private     *Physics;
95149fb536SJames Wright typedef struct ProblemData_private *ProblemData;
96149fb536SJames Wright 
97149fb536SJames Wright // Application context from user command line options
98149fb536SJames Wright struct AppCtx_private {
99149fb536SJames Wright   // libCEED arguments
100149fb536SJames Wright   char     ceed_resource[PETSC_MAX_PATH_LEN];  // libCEED backend
101149fb536SJames Wright   PetscInt degree;
102149fb536SJames Wright   PetscInt q_extra;
103149fb536SJames Wright   // Solver arguments
104149fb536SJames Wright   MatType amat_type;
105149fb536SJames Wright   // Post-processing arguments
106149fb536SJames Wright   PetscInt  checkpoint_interval;
107149fb536SJames Wright   PetscInt  viz_refine;
108149fb536SJames Wright   PetscInt  cont_steps;
109149fb536SJames Wright   PetscReal cont_time;
110149fb536SJames Wright   char      cont_file[PETSC_MAX_PATH_LEN];
111149fb536SJames Wright   char      cont_time_file[PETSC_MAX_PATH_LEN];
112149fb536SJames Wright   char      output_dir[PETSC_MAX_PATH_LEN];
113149fb536SJames Wright   PetscBool add_stepnum2bin;
114149fb536SJames Wright   PetscBool checkpoint_vtk;
115149fb536SJames Wright   // Problem type arguments
116149fb536SJames Wright   PetscFunctionList problems;
117149fb536SJames Wright   char              problem_name[PETSC_MAX_PATH_LEN];
118149fb536SJames Wright   // Test mode arguments
119149fb536SJames Wright   TestType    test_type;
120149fb536SJames Wright   PetscScalar test_tol;
121149fb536SJames Wright   char        test_file_path[PETSC_MAX_PATH_LEN];
122149fb536SJames Wright   // Turbulent spanwise statistics
123149fb536SJames Wright   PetscBool         turb_spanstats_enable;
124149fb536SJames Wright   PetscInt          turb_spanstats_collect_interval;
125149fb536SJames Wright   PetscInt          turb_spanstats_viewer_interval;
126149fb536SJames Wright   PetscViewer       turb_spanstats_viewer;
127149fb536SJames Wright   PetscViewerFormat turb_spanstats_viewer_format;
128149fb536SJames Wright   // Wall forces
129149fb536SJames Wright   struct {
130149fb536SJames Wright     PetscInt          num_wall;
131149fb536SJames Wright     PetscInt         *walls;
132149fb536SJames Wright     PetscViewer       viewer;
133149fb536SJames Wright     PetscViewerFormat viewer_format;
134149fb536SJames Wright     PetscBool         header_written;
135149fb536SJames Wright   } wall_forces;
136149fb536SJames Wright   // Subgrid Stress Model
137149fb536SJames Wright   SGSModelType sgs_model_type;
138149fb536SJames Wright   PetscBool    sgs_train_enable;
139149fb536SJames Wright   // Differential Filtering
140149fb536SJames Wright   PetscBool         diff_filter_monitor;
141149fb536SJames Wright   MeshTransformType mesh_transform_type;
142149fb536SJames Wright };
143149fb536SJames Wright 
144149fb536SJames Wright // libCEED data struct
145149fb536SJames Wright struct CeedData_private {
146149fb536SJames Wright   CeedVector           x_coord, q_data;
147149fb536SJames Wright   CeedBasis            basis_x, basis_q;
148149fb536SJames Wright   CeedElemRestriction  elem_restr_x, elem_restr_q, elem_restr_qd_i;
149149fb536SJames Wright   OperatorApplyContext op_ics_ctx;
150149fb536SJames Wright };
151149fb536SJames Wright 
152149fb536SJames Wright typedef struct {
153149fb536SJames Wright   DM                    dm;
154149fb536SJames Wright   PetscSF               sf;  // For communicating child data to parents
155149fb536SJames Wright   OperatorApplyContext  op_stats_collect_ctx, op_proj_rhs_ctx;
156149fb536SJames Wright   PetscInt              num_comp_stats;
157149fb536SJames Wright   Vec                   Child_Stats_loc, Parent_Stats_loc;
158149fb536SJames Wright   KSP                   ksp;         // For the L^2 projection solve
159149fb536SJames Wright   CeedScalar            span_width;  // spanwise width of the child domain
160149fb536SJames Wright   PetscBool             do_mms_test;
161149fb536SJames Wright   OperatorApplyContext  mms_error_ctx;
162149fb536SJames Wright   CeedContextFieldLabel solution_time_label, previous_time_label;
163149fb536SJames Wright } SpanStatsData;
164149fb536SJames Wright 
165149fb536SJames Wright typedef struct {
166149fb536SJames Wright   DM                   dm;
167149fb536SJames Wright   PetscInt             num_comp;
168149fb536SJames Wright   OperatorApplyContext l2_rhs_ctx;
169149fb536SJames Wright   KSP                  ksp;
170149fb536SJames Wright } *NodalProjectionData;
171149fb536SJames Wright 
172149fb536SJames Wright typedef PetscErrorCode (*SgsDDNodalStressEval)(User user, Vec Q_loc, Vec VelocityGradient, Vec SGSNodal_loc);
173149fb536SJames Wright typedef PetscErrorCode (*SgsDDNodalStressInference)(Vec DD_Inputs_loc, Vec DD_Outputs_loc, void *ctx);
174149fb536SJames Wright typedef struct {
175149fb536SJames Wright   DM                        dm_sgs, dm_dd_inputs, dm_dd_outputs;
176149fb536SJames Wright   PetscInt                  num_comp_sgs, num_comp_inputs, num_comp_outputs;
177149fb536SJames Wright   OperatorApplyContext      op_nodal_evaluation_ctx, op_nodal_dd_inputs_ctx, op_nodal_dd_outputs_ctx, op_sgs_apply_ctx;
178149fb536SJames Wright   CeedVector                sgs_nodal_ceed, grad_velo_ceed;
179149fb536SJames Wright   SgsDDNodalStressEval      sgs_nodal_eval;
180149fb536SJames Wright   SgsDDNodalStressInference sgs_nodal_inference;
181149fb536SJames Wright   void                     *sgs_nodal_inference_ctx;
182149fb536SJames Wright   PetscErrorCode (*sgs_nodal_inference_ctx_destroy)(void *ctx);
183149fb536SJames Wright } *SgsDDData;
184149fb536SJames Wright 
185149fb536SJames Wright typedef struct {
186149fb536SJames Wright   DM                   dm_dd_training;
187149fb536SJames Wright   PetscInt             num_comp_dd_inputs, write_data_interval, num_filter_widths;
188149fb536SJames Wright   PetscScalar          filter_widths[16];
189149fb536SJames Wright   OperatorApplyContext op_training_data_calc_ctx;
190149fb536SJames Wright   NodalProjectionData  filtered_grad_velo_proj;
191149fb536SJames Wright   size_t               training_data_array_dims[2];
192149fb536SJames Wright   PetscBool            overwrite_training_data;
193149fb536SJames Wright } *SGS_DD_TrainingData;
194149fb536SJames Wright 
195149fb536SJames Wright typedef struct {
196149fb536SJames Wright   DM                    dm_filter;
197149fb536SJames Wright   PetscInt              num_filtered_fields;
198149fb536SJames Wright   CeedInt              *num_field_components;
199149fb536SJames Wright   PetscInt              field_prim_state, field_velo_prod;
200149fb536SJames Wright   OperatorApplyContext  op_rhs_ctx;
201149fb536SJames Wright   KSP                   ksp;
202149fb536SJames Wright   PetscObjectState      X_loc_state;
203149fb536SJames Wright   PetscBool             do_mms_test;
204149fb536SJames Wright   CeedContextFieldLabel filter_width_scaling_label;
205149fb536SJames Wright } *DiffFilterData;
206149fb536SJames Wright 
207149fb536SJames Wright typedef struct {
208149fb536SJames Wright   void    *client;
209149fb536SJames Wright   char     rank_id_name[16];
210149fb536SJames Wright   PetscInt collocated_database_num_ranks;
211149fb536SJames Wright } *SmartSimData;
212149fb536SJames Wright 
213149fb536SJames Wright // PETSc user data
214149fb536SJames Wright struct User_private {
215149fb536SJames Wright   MPI_Comm             comm;
216149fb536SJames Wright   DM                   dm;
217149fb536SJames Wright   DM                   dm_viz;
218149fb536SJames Wright   Mat                  interp_viz;
219149fb536SJames Wright   Ceed                 ceed;
220149fb536SJames Wright   Units                units;
221149fb536SJames Wright   Vec                  Q_loc, Q_dot_loc;
222149fb536SJames Wright   Physics              phys;
223149fb536SJames Wright   AppCtx               app_ctx;
224149fb536SJames Wright   CeedVector           q_ceed, q_dot_ceed, g_ceed, x_ceed;
225149fb536SJames Wright   CeedOperator         op_ifunction;
226149fb536SJames Wright   Mat                  mat_ijacobian;
227149fb536SJames Wright   KSP                  mass_ksp;
228149fb536SJames Wright   OperatorApplyContext op_rhs_ctx, op_strong_bc_ctx;
229149fb536SJames Wright   CeedScalar           time_bc_set;
230149fb536SJames Wright   SpanStatsData        spanstats;
231149fb536SJames Wright   NodalProjectionData  grad_velo_proj;
232149fb536SJames Wright   SgsDDData            sgs_dd_data;
233149fb536SJames Wright   DiffFilterData       diff_filter;
234149fb536SJames Wright   SmartSimData         smartsim;
235149fb536SJames Wright   SGS_DD_TrainingData  sgs_dd_train;
236149fb536SJames Wright };
237149fb536SJames Wright 
238149fb536SJames Wright // Units
239149fb536SJames Wright struct Units_private {
240149fb536SJames Wright   // fundamental units
241149fb536SJames Wright   PetscScalar meter;
242149fb536SJames Wright   PetscScalar kilogram;
243149fb536SJames Wright   PetscScalar second;
244149fb536SJames Wright   PetscScalar Kelvin;
245149fb536SJames Wright   // derived units
246149fb536SJames Wright   PetscScalar Pascal;
247149fb536SJames Wright   PetscScalar J_per_kg_K;
248149fb536SJames Wright   PetscScalar m_per_squared_s;
249149fb536SJames Wright   PetscScalar W_per_m_K;
250149fb536SJames Wright   PetscScalar Joule;
251149fb536SJames Wright };
252149fb536SJames Wright 
253149fb536SJames Wright // Boundary conditions
254149fb536SJames Wright struct SimpleBC_private {
255149fb536SJames Wright   PetscInt num_inflow, num_outflow, num_freestream, num_slip;
256149fb536SJames Wright   PetscInt inflows[16], outflows[16], freestreams[16], slips[16];
257149fb536SJames Wright };
258149fb536SJames Wright 
259149fb536SJames Wright // Struct that contains all enums and structs used for the physics of all problems
260149fb536SJames Wright struct Physics_private {
261149fb536SJames Wright   PetscBool             implicit;
262149fb536SJames Wright   StateVariable         state_var;
263149fb536SJames Wright   CeedContextFieldLabel solution_time_label;
264149fb536SJames Wright   CeedContextFieldLabel stg_solution_time_label;
265149fb536SJames Wright   CeedContextFieldLabel timestep_size_label;
266149fb536SJames Wright   CeedContextFieldLabel ics_time_label;
267149fb536SJames Wright };
268149fb536SJames Wright 
269149fb536SJames Wright PetscErrorCode BoundaryConditionSetUp(User user, ProblemData problem, AppCtx app_ctx, SimpleBC bc);
270149fb536SJames Wright 
271149fb536SJames Wright typedef struct {
272149fb536SJames Wright   CeedQFunctionUser    qfunction;
273149fb536SJames Wright   const char          *qfunction_loc;
274149fb536SJames Wright   CeedQFunctionContext qfunction_context;
275149fb536SJames Wright } ProblemQFunctionSpec;
276149fb536SJames Wright 
277149fb536SJames Wright // Problem specific data
278149fb536SJames Wright struct ProblemData_private {
279149fb536SJames Wright   CeedInt              dim, q_data_size_vol, q_data_size_sur, jac_data_size_sur;
280149fb536SJames Wright   CeedScalar           dm_scale;
281149fb536SJames Wright   ProblemQFunctionSpec ics, apply_vol_rhs, apply_vol_ifunction, apply_vol_ijacobian, apply_inflow, apply_outflow, apply_freestream, apply_slip,
282149fb536SJames Wright       apply_inflow_jacobian, apply_outflow_jacobian, apply_freestream_jacobian, apply_slip_jacobian;
283149fb536SJames Wright   bool          compute_exact_solution_error;
284149fb536SJames Wright   PetscBool     set_bc_from_ics, use_strong_bc_ceed, uses_newtonian;
285149fb536SJames Wright   size_t        num_bc_defs;
286149fb536SJames Wright   BCDefinition *bc_defs;
287149fb536SJames Wright   PetscErrorCode (*print_info)(User, ProblemData, AppCtx);
288149fb536SJames Wright   PetscErrorCode (*create_mass_operator)(User, CeedOperator *);
289149fb536SJames Wright };
290149fb536SJames Wright 
291149fb536SJames Wright extern int FreeContextPetsc(void *);
292149fb536SJames Wright 
293149fb536SJames Wright // -----------------------------------------------------------------------------
294149fb536SJames Wright // Set up problems
295149fb536SJames Wright // -----------------------------------------------------------------------------
296149fb536SJames Wright // Set up function for each problem
297149fb536SJames Wright extern PetscErrorCode NS_TAYLOR_GREEN(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
298149fb536SJames Wright extern PetscErrorCode NS_GAUSSIAN_WAVE(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
299149fb536SJames Wright extern PetscErrorCode NS_CHANNEL(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
300149fb536SJames Wright extern PetscErrorCode NS_BLASIUS(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
301149fb536SJames Wright extern PetscErrorCode NS_NEWTONIAN_IG(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
302149fb536SJames Wright extern PetscErrorCode NS_DENSITY_CURRENT(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
303149fb536SJames Wright extern PetscErrorCode NS_EULER_VORTEX(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
304149fb536SJames Wright extern PetscErrorCode NS_SHOCKTUBE(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
305149fb536SJames Wright extern PetscErrorCode NS_ADVECTION(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
306149fb536SJames Wright extern PetscErrorCode NS_ADVECTION2D(ProblemData problem, DM dm, void *ctx, SimpleBC bc);
307149fb536SJames Wright 
308149fb536SJames Wright // Print function for each problem
309149fb536SJames Wright extern PetscErrorCode PRINT_NEWTONIAN(User user, ProblemData problem, AppCtx app_ctx);
310149fb536SJames Wright 
311149fb536SJames Wright extern PetscErrorCode PRINT_EULER_VORTEX(User user, ProblemData problem, AppCtx app_ctx);
312149fb536SJames Wright 
313149fb536SJames Wright extern PetscErrorCode PRINT_SHOCKTUBE(User user, ProblemData problem, AppCtx app_ctx);
314149fb536SJames Wright 
315149fb536SJames Wright extern PetscErrorCode PRINT_ADVECTION(User user, ProblemData problem, AppCtx app_ctx);
316149fb536SJames Wright 
317149fb536SJames Wright extern PetscErrorCode PRINT_ADVECTION2D(User user, ProblemData problem, AppCtx app_ctx);
318149fb536SJames Wright 
319149fb536SJames Wright PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData problem, TS ts);
320149fb536SJames Wright 
321149fb536SJames Wright // -----------------------------------------------------------------------------
322149fb536SJames Wright // libCEED functions
323149fb536SJames Wright // -----------------------------------------------------------------------------
324149fb536SJames Wright // Utility function to create local CEED restriction
325149fb536SJames Wright PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt label_value, PetscInt dm_field,
326149fb536SJames Wright                                          CeedElemRestriction *elem_restr);
327149fb536SJames Wright 
328149fb536SJames Wright PetscErrorCode DMPlexCeedElemRestrictionCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field,
329149fb536SJames Wright                                                CeedElemRestriction *restriction);
330149fb536SJames Wright PetscErrorCode DMPlexCeedElemRestrictionCoordinateCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height,
331149fb536SJames Wright                                                          CeedElemRestriction *restriction);
332149fb536SJames Wright PetscErrorCode DMPlexCeedElemRestrictionQDataCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height,
333149fb536SJames Wright                                                     PetscInt q_data_size, CeedElemRestriction *restriction);
334149fb536SJames Wright PetscErrorCode DMPlexCeedElemRestrictionCollocatedCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height,
335149fb536SJames Wright                                                          PetscInt q_data_size, CeedElemRestriction *restriction);
336149fb536SJames Wright 
337149fb536SJames Wright PetscErrorCode CreateBasisFromPlex(Ceed ceed, DM dm, DMLabel domain_label, CeedInt label_value, CeedInt height, CeedInt dm_field, CeedBasis *basis);
33821ba7ba4SJames Wright PetscErrorCode DMPlexCeedBasisCellToFaceCoordinateCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt face,
33921ba7ba4SJames Wright                                                          CeedBasis *basis);
34021ba7ba4SJames Wright PetscErrorCode DMPlexCeedBasisCellToFaceCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt face, PetscInt dm_field,
34121ba7ba4SJames Wright                                                CeedBasis *basis);
3425f65e1a7SJames Wright PetscErrorCode DMPlexCreateFaceLabel(DM dm, PetscInt dm_face, char **face_label_name);
3435f65e1a7SJames Wright PetscErrorCode DMLabelCreateGlobalValueArray(DM dm, DMLabel label, PetscInt *num_values, PetscInt **value_array);
344149fb536SJames Wright 
345149fb536SJames Wright PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, AppCtx app_ctx, ProblemData problem, SimpleBC bc);
346149fb536SJames Wright 
347149fb536SJames Wright PetscErrorCode QDataGet(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, CeedElemRestriction elem_restr_x, CeedBasis basis_x,
348149fb536SJames Wright                         CeedVector x_coord, CeedElemRestriction *elem_restr_qd, CeedVector *q_data, CeedInt *q_data_size);
349149fb536SJames Wright PetscErrorCode QDataGetNumComponents(DM dm, CeedInt *q_data_size);
350149fb536SJames Wright PetscErrorCode QDataBoundaryGet(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, CeedElemRestriction elem_restr_x, CeedBasis basis_x,
351149fb536SJames Wright                                 CeedVector x_coord, CeedElemRestriction *elem_restr_qd, CeedVector *q_data, CeedInt *q_data_size);
352149fb536SJames Wright PetscErrorCode QDataBoundaryGetNumComponents(DM dm, CeedInt *q_data_size);
353149fb536SJames Wright // -----------------------------------------------------------------------------
354149fb536SJames Wright // Time-stepping functions
355149fb536SJames Wright // -----------------------------------------------------------------------------
356149fb536SJames Wright // RHS (Explicit time-stepper) function setup
357149fb536SJames Wright PetscErrorCode RHS_NS(TS ts, PetscReal t, Vec Q, Vec G, void *user_data);
358149fb536SJames Wright 
359149fb536SJames Wright // Implicit time-stepper function setup
360149fb536SJames Wright PetscErrorCode IFunction_NS(TS ts, PetscReal t, Vec Q, Vec Q_dot, Vec G, void *user_data);
361149fb536SJames Wright 
362149fb536SJames Wright // User provided TS Monitor
363149fb536SJames Wright PetscErrorCode TSMonitor_NS(TS ts, PetscInt step_no, PetscReal time, Vec Q, void *ctx);
364149fb536SJames Wright 
365149fb536SJames Wright // TS: Create, setup, and solve
366149fb536SJames Wright PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, ProblemData problem, Vec *Q, PetscScalar *f_time, TS *ts);
367149fb536SJames Wright 
368149fb536SJames Wright // Update Boundary Values when time has changed
369149fb536SJames Wright PetscErrorCode UpdateBoundaryValues(User user, Vec Q_loc, PetscReal t);
370149fb536SJames Wright 
371149fb536SJames Wright // -----------------------------------------------------------------------------
372149fb536SJames Wright // Setup DM
373149fb536SJames Wright // -----------------------------------------------------------------------------
374149fb536SJames Wright // Create mesh
375149fb536SJames Wright PetscErrorCode CreateDM(MPI_Comm comm, ProblemData problem, MatType, VecType, DM *dm);
376149fb536SJames Wright 
377149fb536SJames Wright // Set up DM
378149fb536SJames Wright PetscErrorCode SetUpDM(DM dm, ProblemData problem, PetscInt degree, PetscInt q_extra, SimpleBC bc, Physics phys);
379149fb536SJames Wright PetscErrorCode DMSetupByOrderBegin_FEM(PetscBool setup_faces, PetscBool setup_coords, PetscInt degree, PetscInt coord_order, PetscInt q_extra,
380149fb536SJames Wright                                        PetscInt num_fields, const PetscInt *field_sizes, DM dm);
381149fb536SJames Wright PetscErrorCode DMSetupByOrderEnd_FEM(PetscBool setup_coords, DM dm);
382149fb536SJames Wright PetscErrorCode DMSetupByOrder_FEM(PetscBool setup_faces, PetscBool setup_coords, PetscInt degree, PetscInt coord_order, PetscInt q_extra,
383149fb536SJames Wright                                   PetscInt num_fields, const PetscInt *field_sizes, DM dm);
384149fb536SJames Wright 
385149fb536SJames Wright // Refine DM for high-order viz
386149fb536SJames Wright PetscErrorCode VizRefineDM(DM dm, User user, ProblemData problem, SimpleBC bc, Physics phys);
387149fb536SJames Wright 
388149fb536SJames Wright // -----------------------------------------------------------------------------
389149fb536SJames Wright // Process command line options
390149fb536SJames Wright // -----------------------------------------------------------------------------
391149fb536SJames Wright // Register problems to be available on the command line
392149fb536SJames Wright PetscErrorCode RegisterProblems_NS(AppCtx app_ctx);
393149fb536SJames Wright 
394149fb536SJames Wright // Process general command line options
395149fb536SJames Wright PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx, SimpleBC bc);
396149fb536SJames Wright 
397149fb536SJames Wright // -----------------------------------------------------------------------------
398149fb536SJames Wright // Miscellaneous utility functions
399149fb536SJames Wright // -----------------------------------------------------------------------------
400149fb536SJames Wright PetscErrorCode GetInverseMultiplicity(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field,
401149fb536SJames Wright                                       PetscBool get_global_multiplicity, CeedElemRestriction *elem_restr_inv_multiplicity,
402149fb536SJames Wright                                       CeedVector *inv_multiplicity);
403149fb536SJames Wright PetscErrorCode ICs_FixMultiplicity(DM dm, CeedData ceed_data, User user, Vec Q_loc, Vec Q, CeedScalar time);
404149fb536SJames Wright 
405149fb536SJames Wright PetscErrorCode DMPlexInsertBoundaryValues_FromICs(DM dm, PetscBool insert_essential, Vec Q_loc, PetscReal time, Vec face_geom_FVM, Vec cell_geom_FVM,
406149fb536SJames Wright                                                   Vec grad_FVM);
407149fb536SJames Wright 
408149fb536SJames Wright // Compare reference solution values with current test run for CI
409149fb536SJames Wright PetscErrorCode RegressionTest(AppCtx app_ctx, Vec Q);
410149fb536SJames Wright 
411149fb536SJames Wright // Get error for problems with exact solutions
412149fb536SJames Wright PetscErrorCode PrintError(CeedData ceed_data, DM dm, User user, Vec Q, PetscScalar final_time);
413149fb536SJames Wright 
414149fb536SJames Wright // Post-processing
415149fb536SJames Wright PetscErrorCode PostProcess(TS ts, CeedData ceed_data, DM dm, ProblemData problem, User user, Vec Q, PetscScalar final_time);
416149fb536SJames Wright 
417149fb536SJames Wright // -- Gather initial Q values in case of continuation of simulation
418149fb536SJames Wright PetscErrorCode SetupICsFromBinary(MPI_Comm comm, AppCtx app_ctx, Vec Q);
419149fb536SJames Wright 
420149fb536SJames Wright // Record boundary values from initial condition
421149fb536SJames Wright PetscErrorCode SetBCsFromICs(DM dm, Vec Q, Vec Q_loc);
422149fb536SJames Wright 
423149fb536SJames Wright // Versioning token for binary checkpoints
424149fb536SJames Wright extern const PetscInt32 FLUIDS_FILE_TOKEN;  // for backwards compatibility
425149fb536SJames Wright extern const PetscInt32 FLUIDS_FILE_TOKEN_32;
426149fb536SJames Wright extern const PetscInt32 FLUIDS_FILE_TOKEN_64;
427149fb536SJames Wright 
428149fb536SJames Wright // Create appropriate mass qfunction based on number of components N
429149fb536SJames Wright PetscErrorCode CreateMassQFunction(Ceed ceed, CeedInt N, CeedInt q_data_size, CeedQFunction *qf);
430149fb536SJames Wright 
431149fb536SJames Wright PetscErrorCode NodalProjectionDataDestroy(NodalProjectionData context);
432149fb536SJames Wright 
433149fb536SJames Wright PetscErrorCode PhastaDatFileOpen(const MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], const PetscInt char_array_len, PetscInt dims[2],
434149fb536SJames Wright                                  FILE **fp);
435149fb536SJames Wright 
436149fb536SJames Wright PetscErrorCode PhastaDatFileGetNRows(const MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], PetscInt *nrows);
437149fb536SJames Wright 
438149fb536SJames Wright PetscErrorCode PhastaDatFileReadToArrayReal(const MPI_Comm comm, const char path[PETSC_MAX_PATH_LEN], PetscReal array[]);
439149fb536SJames Wright 
440149fb536SJames Wright // -----------------------------------------------------------------------------
441149fb536SJames Wright // Turbulence Statistics Collection Functions
442149fb536SJames Wright // -----------------------------------------------------------------------------
443149fb536SJames Wright 
444149fb536SJames Wright PetscErrorCode TurbulenceStatisticsSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem);
445149fb536SJames Wright PetscErrorCode TSMonitor_TurbulenceStatistics(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, void *ctx);
446149fb536SJames Wright PetscErrorCode TurbulenceStatisticsDestroy(User user, CeedData ceed_data);
447149fb536SJames Wright 
448149fb536SJames Wright // -----------------------------------------------------------------------------
449149fb536SJames Wright // Data-Driven Subgrid Stress (DD-SGS) Modeling Functions
450149fb536SJames Wright // -----------------------------------------------------------------------------
451149fb536SJames Wright 
452149fb536SJames Wright PetscErrorCode SgsDDSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem);
453149fb536SJames Wright PetscErrorCode SgsDDDataDestroy(SgsDDData sgs_dd_data);
454149fb536SJames Wright PetscErrorCode SgsDDApplyIFunction(User user, const Vec Q_loc, Vec G_loc);
455149fb536SJames Wright PetscErrorCode VelocityGradientProjectionSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem, StateVariable state_var_input,
456149fb536SJames Wright                                                CeedElemRestriction elem_restr_input, CeedBasis basis_input, NodalProjectionData *pgrad_velo_proj);
457149fb536SJames Wright PetscErrorCode VelocityGradientProjectionApply(NodalProjectionData grad_velo_proj, Vec Q_loc, Vec VelocityGradient);
458149fb536SJames Wright PetscErrorCode GridAnisotropyTensorProjectionSetupApply(Ceed ceed, User user, CeedData ceed_data, CeedElemRestriction *elem_restr_grid_aniso,
459149fb536SJames Wright                                                         CeedVector *grid_aniso_vector);
460149fb536SJames Wright PetscErrorCode GridAnisotropyTensorCalculateCollocatedVector(Ceed ceed, User user, CeedData ceed_data, CeedElemRestriction *elem_restr_grid_aniso,
461149fb536SJames Wright                                                              CeedVector *aniso_colloc_ceed, PetscInt *num_comp_aniso);
462149fb536SJames Wright 
463149fb536SJames Wright // -----------------------------------------------------------------------------
464149fb536SJames Wright // Boundary Condition Related Functions
465149fb536SJames Wright // -----------------------------------------------------------------------------
466149fb536SJames Wright 
467149fb536SJames Wright // Setup StrongBCs that use QFunctions
468149fb536SJames Wright PetscErrorCode SetupStrongBC_Ceed(Ceed ceed, CeedData ceed_data, DM dm, User user, ProblemData problem, SimpleBC bc);
469149fb536SJames Wright 
470149fb536SJames Wright PetscErrorCode FreestreamBCSetup(ProblemData problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, const StatePrimitive *reference);
471149fb536SJames Wright PetscErrorCode OutflowBCSetup(ProblemData problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, const StatePrimitive *reference);
472149fb536SJames Wright PetscErrorCode SlipBCSetup(ProblemData problem, DM dm, void *ctx, CeedQFunctionContext newtonian_ig_qfctx);
473149fb536SJames Wright 
474149fb536SJames Wright // -----------------------------------------------------------------------------
475149fb536SJames Wright // Differential Filtering Functions
476149fb536SJames Wright // -----------------------------------------------------------------------------
477149fb536SJames Wright 
478149fb536SJames Wright PetscErrorCode DifferentialFilterSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem);
479149fb536SJames Wright PetscErrorCode DifferentialFilterDataDestroy(DiffFilterData diff_filter);
480149fb536SJames Wright PetscErrorCode TSMonitor_DifferentialFilter(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, void *ctx);
481149fb536SJames Wright PetscErrorCode DifferentialFilterApply(User user, const PetscReal solution_time, const Vec Q, Vec Filtered_Solution);
482149fb536SJames Wright PetscErrorCode DifferentialFilterMmsICSetup(ProblemData problem);
483149fb536SJames Wright 
484149fb536SJames Wright // -----------------------------------------------------------------------------
485149fb536SJames Wright // SGS Data-Driven Training via SmartSim
486149fb536SJames Wright // -----------------------------------------------------------------------------
487149fb536SJames Wright PetscErrorCode SmartSimSetup(User user);
488149fb536SJames Wright PetscErrorCode SmartSimDataDestroy(SmartSimData smartsim);
489149fb536SJames Wright PetscErrorCode SGS_DD_TrainingSetup(Ceed ceed, User user, CeedData ceed_data, ProblemData problem);
490149fb536SJames Wright PetscErrorCode TSMonitor_SGS_DD_Training(TS ts, PetscInt step_num, PetscReal solution_time, Vec Q, void *ctx);
491149fb536SJames Wright PetscErrorCode TSPostStep_SGS_DD_Training(TS ts);
492149fb536SJames Wright PetscErrorCode SGS_DD_TrainingDataDestroy(SGS_DD_TrainingData sgs_dd_train);
493