1ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2ae2b091fSJames 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> 7b7e55d06SJames Wright #include <dm-utils.h> 893ca29b6SJames Wright #include <honee-file.h> 978c5b8e5SJames Wright #include <honee.h> 10149fb536SJames Wright #include <log_events.h> 11149fb536SJames Wright #include <mat-ceed.h> 12149fb536SJames Wright #include <petsc-ceed-utils.h> 13149fb536SJames Wright #include <petscts.h> 14149fb536SJames Wright #include <stdbool.h> 15354560d1SJames Wright #include <time.h> 16149fb536SJames Wright 17149fb536SJames Wright #include <petsc_ops.h> 18149fb536SJames Wright #include "../qfunctions/newtonian_types.h" 19149fb536SJames Wright 20a7a18c73SJames Wright #if PETSC_VERSION_LT(3, 23, 0) 21a7a18c73SJames Wright #error "PETSc v3.23 or later is required" 22149fb536SJames Wright #endif 23149fb536SJames Wright 24149fb536SJames Wright // ----------------------------------------------------------------------------- 25149fb536SJames Wright // Enums 26149fb536SJames Wright // ----------------------------------------------------------------------------- 27149fb536SJames Wright 28149fb536SJames Wright // Euler - test cases 29149fb536SJames Wright typedef enum { 30149fb536SJames Wright EULER_TEST_ISENTROPIC_VORTEX = 0, 31149fb536SJames Wright EULER_TEST_1 = 1, 32149fb536SJames Wright EULER_TEST_2 = 2, 33149fb536SJames Wright EULER_TEST_3 = 3, 34149fb536SJames Wright EULER_TEST_4 = 4, 35149fb536SJames Wright EULER_TEST_5 = 5, 36149fb536SJames Wright } EulerTestType; 37149fb536SJames Wright static const char *const EulerTestTypes[] = {"ISENTROPIC_VORTEX", "1", "2", "3", "4", "5", "EulerTestType", "EULER_TEST_", NULL}; 38149fb536SJames Wright 39149fb536SJames Wright // Test mode type 40149fb536SJames Wright typedef enum { 41149fb536SJames Wright TESTTYPE_NONE = 0, 42149fb536SJames Wright TESTTYPE_SOLVER = 1, 43149fb536SJames Wright TESTTYPE_TURB_SPANSTATS = 2, 44149fb536SJames Wright TESTTYPE_DIFF_FILTER = 3, 45149fb536SJames Wright } TestType; 46149fb536SJames Wright static const char *const TestTypes[] = {"NONE", "SOLVER", "TURB_SPANSTATS", "DIFF_FILTER", "TestType", "TESTTYPE_", NULL}; 47149fb536SJames Wright 48149fb536SJames Wright // Subgrid-Stress mode type 49149fb536SJames Wright typedef enum { 50149fb536SJames Wright SGS_MODEL_NONE = 0, 51149fb536SJames Wright SGS_MODEL_DATA_DRIVEN = 1, 52149fb536SJames Wright } SGSModelType; 53149fb536SJames Wright static const char *const SGSModelTypes[] = {"NONE", "DATA_DRIVEN", "SGSModelType", "SGS_MODEL_", NULL}; 54149fb536SJames Wright 55149fb536SJames Wright // Subgrid-Stress mode type 56149fb536SJames Wright typedef enum { 57149fb536SJames Wright SGS_MODEL_DD_FUSED = 0, 58149fb536SJames Wright SGS_MODEL_DD_SEQENTIAL_CEED = 1, 59149fb536SJames Wright SGS_MODEL_DD_SEQENTIAL_TORCH = 2, 60149fb536SJames Wright } SGSModelDDImplementation; 61149fb536SJames Wright static const char *const SGSModelDDImplementations[] = {"FUSED", "SEQUENTIAL_CEED", "SEQUENTIAL_TORCH", "SGSModelDDImplementation", "SGS_MODEL_DD_", 62149fb536SJames Wright NULL}; 63149fb536SJames Wright 64149fb536SJames Wright // Mesh transformation type 65149fb536SJames Wright typedef enum { 66149fb536SJames Wright MESH_TRANSFORM_NONE = 0, 67149fb536SJames Wright MESH_TRANSFORM_PLATEMESH = 1, 68149fb536SJames Wright } MeshTransformType; 69149fb536SJames Wright static const char *const MeshTransformTypes[] = {"NONE", "PLATEMESH", "MeshTransformType", "MESH_TRANSFORM_", NULL}; 70149fb536SJames Wright 71149fb536SJames Wright // ----------------------------------------------------------------------------- 72149fb536SJames Wright // Structs 73149fb536SJames Wright // ----------------------------------------------------------------------------- 74149fb536SJames Wright // Structs declarations 75149fb536SJames Wright typedef struct AppCtx_private *AppCtx; 76149fb536SJames Wright typedef struct Units_private *Units; 77149fb536SJames Wright typedef struct SimpleBC_private *SimpleBC; 78149fb536SJames Wright typedef struct Physics_private *Physics; 79149fb536SJames Wright typedef struct ProblemData_private *ProblemData; 80149fb536SJames Wright 81149fb536SJames Wright // Application context from user command line options 82149fb536SJames Wright struct AppCtx_private { 83149fb536SJames Wright // libCEED arguments 84149fb536SJames Wright char ceed_resource[PETSC_MAX_PATH_LEN]; // libCEED backend 85149fb536SJames Wright PetscInt degree; 86149fb536SJames Wright PetscInt q_extra; 87149fb536SJames Wright // Solver arguments 88149fb536SJames Wright MatType amat_type; 89149fb536SJames Wright // Post-processing arguments 90149fb536SJames Wright PetscInt checkpoint_interval; 91149fb536SJames Wright PetscInt viz_refine; 92481d14cbSJames Wright PetscBool use_continue_file; 93149fb536SJames Wright PetscInt cont_steps; 94149fb536SJames Wright PetscReal cont_time; 95149fb536SJames Wright char cont_file[PETSC_MAX_PATH_LEN]; 96149fb536SJames Wright char output_dir[PETSC_MAX_PATH_LEN]; 97149fb536SJames Wright PetscBool add_stepnum2bin; 98149fb536SJames Wright PetscBool checkpoint_vtk; 99149fb536SJames Wright // Problem type arguments 100149fb536SJames Wright PetscFunctionList problems; 101149fb536SJames Wright char problem_name[PETSC_MAX_PATH_LEN]; 102149fb536SJames Wright // Test mode arguments 103149fb536SJames Wright TestType test_type; 104149fb536SJames Wright PetscScalar test_tol; 105149fb536SJames Wright char test_file_path[PETSC_MAX_PATH_LEN]; 106149fb536SJames Wright // Wall forces 107149fb536SJames Wright struct { 108149fb536SJames Wright PetscInt num_wall; 109149fb536SJames Wright PetscInt *walls; 110149fb536SJames Wright PetscViewer viewer; 111149fb536SJames Wright PetscViewerFormat viewer_format; 112149fb536SJames Wright PetscBool header_written; 113149fb536SJames Wright } wall_forces; 114149fb536SJames Wright // Subgrid Stress Model 115149fb536SJames Wright SGSModelType sgs_model_type; 116149fb536SJames Wright PetscBool sgs_train_enable; 117149fb536SJames Wright // Differential Filtering 118149fb536SJames Wright PetscBool diff_filter_monitor; 119149fb536SJames Wright MeshTransformType mesh_transform_type; 1208c85b835SJames Wright // Divergence of Diffusive Flux Projection 1218c85b835SJames Wright DivDiffFluxProjectionMethod divFdiffproj_method; 1228b774af8SJames Wright 1238b774af8SJames Wright PetscInt check_step_interval; 124149fb536SJames Wright }; 125149fb536SJames Wright 126149fb536SJames Wright typedef struct { 127149fb536SJames Wright DM dm; 128149fb536SJames Wright PetscInt num_comp; 129149fb536SJames Wright OperatorApplyContext l2_rhs_ctx; 130149fb536SJames Wright KSP ksp; 131149fb536SJames Wright } *NodalProjectionData; 132149fb536SJames Wright 13336038bbcSJames Wright typedef struct DivDiffFluxProjectionData_private *DivDiffFluxProjectionData; 13436038bbcSJames Wright 13536038bbcSJames Wright struct DivDiffFluxProjectionData_private { 1368c85b835SJames Wright PetscInt num_diff_flux_comps; 1378c85b835SJames Wright DivDiffFluxProjectionMethod method; 1388c85b835SJames Wright NodalProjectionData projection; 13936038bbcSJames Wright 14036038bbcSJames Wright // CeedOperator Objects 14136038bbcSJames Wright CeedElemRestriction elem_restr_div_diff_flux; 14236038bbcSJames Wright CeedBasis basis_div_diff_flux; 14336038bbcSJames Wright CeedEvalMode eval_mode_div_diff_flux; 1448c85b835SJames Wright CeedVector div_diff_flux_ceed; 14536038bbcSJames Wright 14636038bbcSJames Wright // Problem specific setup functions 147e3663b90SJames Wright PetscErrorCode (*CreateRHSOperator_Direct)(Honee, DivDiffFluxProjectionData, CeedOperator *); 148e3663b90SJames Wright PetscErrorCode (*CreateRHSOperator_Indirect)(Honee, DivDiffFluxProjectionData, CeedOperator *); 14936038bbcSJames Wright 1508c85b835SJames Wright // Only used for direct method: 1518c85b835SJames Wright Vec DivDiffFlux_loc; 1528c85b835SJames Wright PetscMemType DivDiffFlux_memtype; 1538c85b835SJames Wright PetscBool ceed_vec_has_array; 15436038bbcSJames Wright 15536038bbcSJames Wright // Only used for indirect method: 15636038bbcSJames Wright OperatorApplyContext calc_div_diff_flux; 15736038bbcSJames Wright }; 1588c85b835SJames Wright 1590c373b74SJames Wright typedef PetscErrorCode (*SgsDDNodalStressEval)(Honee honee, Vec Q_loc, Vec VelocityGradient, Vec SGSNodal_loc); 160149fb536SJames Wright typedef PetscErrorCode (*SgsDDNodalStressInference)(Vec DD_Inputs_loc, Vec DD_Outputs_loc, void *ctx); 161149fb536SJames Wright typedef struct { 162149fb536SJames Wright DM dm_sgs, dm_dd_inputs, dm_dd_outputs; 163149fb536SJames Wright PetscInt num_comp_sgs, num_comp_inputs, num_comp_outputs; 164149fb536SJames Wright OperatorApplyContext op_nodal_evaluation_ctx, op_nodal_dd_inputs_ctx, op_nodal_dd_outputs_ctx, op_sgs_apply_ctx; 165149fb536SJames Wright CeedVector sgs_nodal_ceed, grad_velo_ceed; 166149fb536SJames Wright SgsDDNodalStressEval sgs_nodal_eval; 167149fb536SJames Wright SgsDDNodalStressInference sgs_nodal_inference; 168149fb536SJames Wright void *sgs_nodal_inference_ctx; 169149fb536SJames Wright PetscErrorCode (*sgs_nodal_inference_ctx_destroy)(void *ctx); 170149fb536SJames Wright } *SgsDDData; 171149fb536SJames Wright 172149fb536SJames Wright typedef struct { 173149fb536SJames Wright DM dm_dd_training; 174149fb536SJames Wright PetscInt num_comp_dd_inputs, write_data_interval, num_filter_widths; 175149fb536SJames Wright PetscScalar filter_widths[16]; 176149fb536SJames Wright OperatorApplyContext op_training_data_calc_ctx; 177149fb536SJames Wright NodalProjectionData filtered_grad_velo_proj; 178149fb536SJames Wright size_t training_data_array_dims[2]; 179149fb536SJames Wright PetscBool overwrite_training_data; 180149fb536SJames Wright } *SGS_DD_TrainingData; 181149fb536SJames Wright 182149fb536SJames Wright typedef struct { 183149fb536SJames Wright DM dm_filter; 184149fb536SJames Wright PetscInt num_filtered_fields; 185149fb536SJames Wright CeedInt *num_field_components; 186149fb536SJames Wright PetscInt field_prim_state, field_velo_prod; 187149fb536SJames Wright OperatorApplyContext op_rhs_ctx; 188149fb536SJames Wright KSP ksp; 189149fb536SJames Wright PetscObjectState X_loc_state; 190149fb536SJames Wright PetscBool do_mms_test; 191149fb536SJames Wright CeedContextFieldLabel filter_width_scaling_label; 192149fb536SJames Wright } *DiffFilterData; 193149fb536SJames Wright 194149fb536SJames Wright typedef struct { 195149fb536SJames Wright void *client; 196149fb536SJames Wright char rank_id_name[16]; 197149fb536SJames Wright PetscInt collocated_database_num_ranks; 198149fb536SJames Wright } *SmartSimData; 199149fb536SJames Wright 200*6a9fb8efSJames Wright typedef struct _HoneeOps *HoneeOps; 201*6a9fb8efSJames Wright struct _HoneeOps {}; 202*6a9fb8efSJames Wright 203*6a9fb8efSJames Wright PetscErrorCode HoneeInit(MPI_Comm comm, Honee *honee); 204*6a9fb8efSJames Wright PetscErrorCode HoneeDestroy(Honee *honee); 205*6a9fb8efSJames Wright 206149fb536SJames Wright // PETSc user data 2070c373b74SJames Wright struct Honee_private { 208*6a9fb8efSJames Wright PETSCHEADER(struct _HoneeOps); 209149fb536SJames Wright MPI_Comm comm; 210149fb536SJames Wright DM dm; 211149fb536SJames Wright DM dm_viz; 212149fb536SJames Wright Mat interp_viz; 213149fb536SJames Wright Ceed ceed; 214149fb536SJames Wright Units units; 215149fb536SJames Wright Vec Q_loc, Q_dot_loc; 216149fb536SJames Wright Physics phys; 217149fb536SJames Wright AppCtx app_ctx; 218149fb536SJames Wright CeedVector q_ceed, q_dot_ceed, g_ceed, x_ceed; 219149fb536SJames Wright CeedOperator op_ifunction; 220149fb536SJames Wright Mat mat_ijacobian; 221149fb536SJames Wright KSP mass_ksp; 222149fb536SJames Wright OperatorApplyContext op_rhs_ctx, op_strong_bc_ctx; 223149fb536SJames Wright CeedScalar time_bc_set; 224149fb536SJames Wright NodalProjectionData grad_velo_proj; 225149fb536SJames Wright SgsDDData sgs_dd_data; 226149fb536SJames Wright DiffFilterData diff_filter; 227149fb536SJames Wright SmartSimData smartsim; 228149fb536SJames Wright SGS_DD_TrainingData sgs_dd_train; 2298c85b835SJames Wright DivDiffFluxProjectionData diff_flux_proj; 230e3663b90SJames Wright 23178c5b8e5SJames Wright ProblemData problem_data; 23278c5b8e5SJames Wright 233e3663b90SJames Wright // old CeedData 234e3663b90SJames Wright CeedVector x_coord; 235e3663b90SJames Wright CeedBasis basis_x, basis_q; 236e3663b90SJames Wright CeedElemRestriction elem_restr_x, elem_restr_q; 237e3663b90SJames Wright OperatorApplyContext op_ics_ctx; 238354560d1SJames Wright 2394c6ae86eSJames Wright PetscBool set_poststep; 240354560d1SJames Wright time_t start_time; 241354560d1SJames Wright time_t max_wall_time; 242354560d1SJames Wright PetscInt max_wall_time_interval; 243149fb536SJames Wright }; 244149fb536SJames Wright 245149fb536SJames Wright // Units 246149fb536SJames Wright struct Units_private { 247149fb536SJames Wright // fundamental units 248149fb536SJames Wright PetscScalar meter; 249149fb536SJames Wright PetscScalar kilogram; 250149fb536SJames Wright PetscScalar second; 251149fb536SJames Wright PetscScalar Kelvin; 252149fb536SJames Wright // derived units 253149fb536SJames Wright PetscScalar Pascal; 254149fb536SJames Wright PetscScalar J_per_kg_K; 255149fb536SJames Wright PetscScalar m_per_squared_s; 256149fb536SJames Wright PetscScalar W_per_m_K; 257149fb536SJames Wright PetscScalar Joule; 258149fb536SJames Wright }; 259149fb536SJames Wright 260149fb536SJames Wright // Struct that contains all enums and structs used for the physics of all problems 261149fb536SJames Wright struct Physics_private { 262149fb536SJames Wright PetscBool implicit; 263149fb536SJames Wright StateVariable state_var; 264149fb536SJames Wright CeedContextFieldLabel solution_time_label; 265149fb536SJames Wright CeedContextFieldLabel stg_solution_time_label; 266149fb536SJames Wright CeedContextFieldLabel timestep_size_label; 267149fb536SJames Wright CeedContextFieldLabel ics_time_label; 268149fb536SJames Wright }; 269149fb536SJames Wright 2705e79d562SJames Wright typedef struct { 2715e79d562SJames Wright Honee honee; 2721abc2837SJames Wright CeedInt num_comps_jac_data; 2735e79d562SJames Wright CeedQFunctionContext qfctx; 2745e79d562SJames Wright void *ctx; 2755e79d562SJames Wright PetscCtxDestroyFn *DestroyCtx; 2765e79d562SJames Wright } *HoneeBCStruct; 2775e79d562SJames Wright 278d3c60affSJames Wright PetscErrorCode BoundaryConditionSetUp(Honee honee, ProblemData problem, AppCtx app_ctx); 2795e79d562SJames Wright PetscErrorCode HoneeBCDestroy(void **ctx); 2805e79d562SJames Wright PetscErrorCode HoneeBCCreateIFunctionQF(BCDefinition bc_def, CeedQFunctionUser qf_func_ptr, const char *qf_loc, CeedQFunctionContext qfctx, 2815e79d562SJames Wright CeedQFunction *qf_ifunc); 2825e79d562SJames Wright PetscErrorCode HoneeBCCreateIJacobianQF(BCDefinition bc_def, CeedQFunctionUser qf_func_ptr, const char *qf_loc, CeedQFunctionContext qfctx, 2835e79d562SJames Wright CeedQFunction *qf_ijac); 2845e79d562SJames Wright PetscErrorCode HoneeBCAddIFunctionOp(BCDefinition bc_def, DMLabel domain_label, PetscInt label_value, CeedQFunction qf_ifunc, CeedOperator op_ifunc, 2855e79d562SJames Wright CeedOperator *sub_op_ifunc); 2865e79d562SJames Wright PetscErrorCode HoneeBCAddIJacobianOp(BCDefinition bc_def, CeedOperator sub_op_ifunc, DMLabel domain_label, PetscInt label_value, 2875e79d562SJames Wright CeedQFunction qf_ijac, CeedOperator op_ijac); 288149fb536SJames Wright 289149fb536SJames Wright typedef struct { 290e07531f7SJames Wright CeedQFunctionUser qf_func_ptr; // !< QFunction function pointer 291e07531f7SJames Wright const char *qf_loc; // !< Absolute path to QFunction source file 292e07531f7SJames Wright CeedQFunctionContext qfctx; // !< QFunctionContext to attach to QFunction 293149fb536SJames Wright } ProblemQFunctionSpec; 294149fb536SJames Wright 295149fb536SJames Wright // Problem specific data 296149fb536SJames Wright struct ProblemData_private { 2971abc2837SJames Wright CeedInt num_comps_jac_data; 298d6cac220SJames Wright ProblemQFunctionSpec ics, apply_vol_rhs, apply_vol_ifunction, apply_vol_ijacobian; 299149fb536SJames Wright bool compute_exact_solution_error; 30028160fc2SJames Wright PetscBool set_bc_from_ics, use_strong_bc_ceed; 301ddb7a641SJames Wright PetscCount num_bc_defs; 302149fb536SJames Wright BCDefinition *bc_defs; 3030c373b74SJames Wright PetscErrorCode (*print_info)(Honee, ProblemData, AppCtx); 3040c373b74SJames Wright PetscErrorCode (*create_mass_operator)(Honee, CeedOperator *); 305149fb536SJames Wright }; 306149fb536SJames Wright 307149fb536SJames Wright extern int FreeContextPetsc(void *); 308149fb536SJames Wright 309149fb536SJames Wright // ----------------------------------------------------------------------------- 310149fb536SJames Wright // Set up problems 311149fb536SJames Wright // ----------------------------------------------------------------------------- 312149fb536SJames Wright // Set up function for each problem 313d3c60affSJames Wright extern PetscErrorCode NS_TAYLOR_GREEN(ProblemData problem, DM dm, void *ctx); 314d3c60affSJames Wright extern PetscErrorCode NS_GAUSSIAN_WAVE(ProblemData problem, DM dm, void *ctx); 315d3c60affSJames Wright extern PetscErrorCode NS_CHANNEL(ProblemData problem, DM dm, void *ctx); 316d3c60affSJames Wright extern PetscErrorCode NS_BLASIUS(ProblemData problem, DM dm, void *ctx); 317d3c60affSJames Wright extern PetscErrorCode NS_NEWTONIAN_IG(ProblemData problem, DM dm, void *ctx); 318d3c60affSJames Wright extern PetscErrorCode NS_DENSITY_CURRENT(ProblemData problem, DM dm, void *ctx); 319d3c60affSJames Wright extern PetscErrorCode NS_EULER_VORTEX(ProblemData problem, DM dm, void *ctx); 320d3c60affSJames Wright extern PetscErrorCode NS_SHOCKTUBE(ProblemData problem, DM dm, void *ctx); 321d3c60affSJames Wright extern PetscErrorCode NS_ADVECTION(ProblemData problem, DM dm, void *ctx); 322149fb536SJames Wright 323149fb536SJames Wright // Print function for each problem 3240c373b74SJames Wright extern PetscErrorCode PRINT_NEWTONIAN(Honee honee, ProblemData problem, AppCtx app_ctx); 3250c373b74SJames Wright extern PetscErrorCode PRINT_EULER_VORTEX(Honee honee, ProblemData problem, AppCtx app_ctx); 3260c373b74SJames Wright extern PetscErrorCode PRINT_SHOCKTUBE(Honee honee, ProblemData problem, AppCtx app_ctx); 3270c373b74SJames Wright extern PetscErrorCode PRINT_ADVECTION(Honee honee, ProblemData problem, AppCtx app_ctx); 3280c373b74SJames Wright extern PetscErrorCode PRINT_ADVECTION2D(Honee honee, ProblemData problem, AppCtx app_ctx); 329149fb536SJames Wright 3300c373b74SJames Wright PetscErrorCode PrintRunInfo(Honee honee, Physics phys_ctx, ProblemData problem, TS ts); 331149fb536SJames Wright 332149fb536SJames Wright // ----------------------------------------------------------------------------- 333149fb536SJames Wright // libCEED functions 334149fb536SJames Wright // ----------------------------------------------------------------------------- 335d3c60affSJames Wright PetscErrorCode SetupLibceed(Ceed ceed, DM dm, Honee honee, AppCtx app_ctx, ProblemData problem); 336149fb536SJames Wright 337149fb536SJames Wright PetscErrorCode QDataGet(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, CeedElemRestriction elem_restr_x, CeedBasis basis_x, 338149fb536SJames Wright CeedVector x_coord, CeedElemRestriction *elem_restr_qd, CeedVector *q_data, CeedInt *q_data_size); 339149fb536SJames Wright PetscErrorCode QDataGetNumComponents(DM dm, CeedInt *q_data_size); 340149fb536SJames Wright PetscErrorCode QDataBoundaryGet(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, CeedElemRestriction elem_restr_x, CeedBasis basis_x, 341149fb536SJames Wright CeedVector x_coord, CeedElemRestriction *elem_restr_qd, CeedVector *q_data, CeedInt *q_data_size); 342149fb536SJames Wright PetscErrorCode QDataBoundaryGetNumComponents(DM dm, CeedInt *q_data_size); 3438c85b835SJames Wright PetscErrorCode QDataBoundaryGradientGetNumComponents(DM dm, CeedInt *q_data_size); 3448c85b835SJames Wright PetscErrorCode QDataBoundaryGradientGet(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, CeedVector x_coord, 34500dbc7b1SJames Wright CeedElemRestriction *elem_restr_qd, CeedVector *q_data, CeedInt *q_data_size); 346e816a7e4SJames Wright PetscErrorCode QDataClearStoredData(); 347149fb536SJames Wright // ----------------------------------------------------------------------------- 348149fb536SJames Wright // Time-stepping functions 349149fb536SJames Wright // ----------------------------------------------------------------------------- 350149fb536SJames Wright PetscErrorCode RHS_NS(TS ts, PetscReal t, Vec Q, Vec G, void *user_data); 351149fb536SJames Wright PetscErrorCode IFunction_NS(TS ts, PetscReal t, Vec Q, Vec Q_dot, Vec G, void *user_data); 352149fb536SJames Wright PetscErrorCode TSMonitor_NS(TS ts, PetscInt step_no, PetscReal time, Vec Q, void *ctx); 3532a9a4b51SJames Wright PetscErrorCode TSSolve_NS(DM dm, Honee honee, AppCtx app_ctx, Physics phys, ProblemData problem, Vec Q, PetscScalar *f_time, TS *ts); 3540c373b74SJames Wright PetscErrorCode UpdateBoundaryValues(Honee honee, Vec Q_loc, PetscReal t); 355149fb536SJames Wright 356149fb536SJames Wright // ----------------------------------------------------------------------------- 357149fb536SJames Wright // Setup DM 358149fb536SJames Wright // ----------------------------------------------------------------------------- 359149fb536SJames Wright PetscErrorCode CreateDM(MPI_Comm comm, ProblemData problem, MatType, VecType, DM *dm); 360d3c60affSJames Wright PetscErrorCode SetUpDM(DM dm, ProblemData problem, PetscInt degree, PetscInt q_extra, Physics phys); 361d3c60affSJames Wright PetscErrorCode VizRefineDM(DM dm, Honee honee, ProblemData problem, Physics phys); 3624cb09fddSJames Wright 363149fb536SJames Wright PetscErrorCode DMSetupByOrderBegin_FEM(PetscBool setup_faces, PetscBool setup_coords, PetscInt degree, PetscInt coord_order, PetscInt q_extra, 364149fb536SJames Wright PetscInt num_fields, const PetscInt *field_sizes, DM dm); 365149fb536SJames Wright PetscErrorCode DMSetupByOrderEnd_FEM(PetscBool setup_coords, DM dm); 366149fb536SJames Wright PetscErrorCode DMSetupByOrder_FEM(PetscBool setup_faces, PetscBool setup_coords, PetscInt degree, PetscInt coord_order, PetscInt q_extra, 367149fb536SJames Wright PetscInt num_fields, const PetscInt *field_sizes, DM dm); 368149fb536SJames Wright 369149fb536SJames Wright // ----------------------------------------------------------------------------- 370149fb536SJames Wright // Process command line options 371149fb536SJames Wright // ----------------------------------------------------------------------------- 372d3c60affSJames Wright PetscErrorCode ProcessCommandLineOptions(Honee honee); 37359572072SJames Wright PetscErrorCode HoneeOptionsSetValueDefault(PetscOptions options, const char name[], const char value[]); 374149fb536SJames Wright 375149fb536SJames Wright // ----------------------------------------------------------------------------- 376149fb536SJames Wright // Miscellaneous utility functions 377149fb536SJames Wright // ----------------------------------------------------------------------------- 378149fb536SJames Wright PetscErrorCode GetInverseMultiplicity(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field, 379149fb536SJames Wright PetscBool get_global_multiplicity, CeedElemRestriction *elem_restr_inv_multiplicity, 380149fb536SJames Wright CeedVector *inv_multiplicity); 381e3663b90SJames Wright PetscErrorCode ICs_FixMultiplicity(DM dm, Honee honee, Vec Q_loc, Vec Q, CeedScalar time); 382149fb536SJames Wright 383149fb536SJames Wright PetscErrorCode DMPlexInsertBoundaryValues_FromICs(DM dm, PetscBool insert_essential, Vec Q_loc, PetscReal time, Vec face_geom_FVM, Vec cell_geom_FVM, 384149fb536SJames Wright Vec grad_FVM); 385149fb536SJames Wright 386149fb536SJames Wright PetscErrorCode RegressionTest(AppCtx app_ctx, Vec Q); 387e3663b90SJames Wright PetscErrorCode PrintError(DM dm, Honee honee, Vec Q, PetscScalar final_time); 388e3663b90SJames Wright PetscErrorCode PostProcess(TS ts, DM dm, ProblemData problem, Honee honee, Vec Q, PetscScalar final_time); 389149fb536SJames Wright PetscErrorCode SetBCsFromICs(DM dm, Vec Q, Vec Q_loc); 39064dd23feSJames Wright PetscErrorCode HoneeMassQFunctionCreate(Ceed ceed, CeedInt N, CeedInt q_data_size, CeedQFunction *qf); 39125125139SJames Wright PetscErrorCode HoneeCalculateDomainSize(Honee honee, PetscScalar *volume); 392149fb536SJames Wright PetscErrorCode NodalProjectionDataDestroy(NodalProjectionData context); 393149fb536SJames Wright 394149fb536SJames Wright // ----------------------------------------------------------------------------- 395149fb536SJames Wright // Turbulence Statistics Collection Functions 396149fb536SJames Wright // ----------------------------------------------------------------------------- 39778c5b8e5SJames Wright PetscErrorCode SpanwiseStatisticsSetup_Turbulence(TS ts, PetscViewerAndFormat *ctx); 39878c5b8e5SJames Wright PetscErrorCode TSMonitor_TurbulenceSpanwiseStatistics(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, PetscViewerAndFormat *ctx); 399149fb536SJames Wright 400149fb536SJames Wright // ----------------------------------------------------------------------------- 401149fb536SJames Wright // Data-Driven Subgrid Stress (DD-SGS) Modeling Functions 402149fb536SJames Wright // ----------------------------------------------------------------------------- 403e3663b90SJames Wright PetscErrorCode SgsDDSetup(Ceed ceed, Honee honee, ProblemData problem); 404149fb536SJames Wright PetscErrorCode SgsDDDataDestroy(SgsDDData sgs_dd_data); 4050c373b74SJames Wright PetscErrorCode SgsDDApplyIFunction(Honee honee, const Vec Q_loc, Vec G_loc); 406e3663b90SJames Wright PetscErrorCode VelocityGradientProjectionSetup(Ceed ceed, Honee honee, ProblemData problem, StateVariable state_var_input, 407149fb536SJames Wright CeedElemRestriction elem_restr_input, CeedBasis basis_input, NodalProjectionData *pgrad_velo_proj); 408149fb536SJames Wright PetscErrorCode VelocityGradientProjectionApply(NodalProjectionData grad_velo_proj, Vec Q_loc, Vec VelocityGradient); 409e3663b90SJames Wright PetscErrorCode GridAnisotropyTensorProjectionSetupApply(Ceed ceed, Honee honee, CeedElemRestriction *elem_restr_grid_aniso, 410149fb536SJames Wright CeedVector *grid_aniso_vector); 411e3663b90SJames Wright PetscErrorCode GridAnisotropyTensorCalculateCollocatedVector(Ceed ceed, Honee honee, CeedElemRestriction *elem_restr_grid_aniso, 412149fb536SJames Wright CeedVector *aniso_colloc_ceed, PetscInt *num_comp_aniso); 413149fb536SJames Wright 414149fb536SJames Wright // ----------------------------------------------------------------------------- 415149fb536SJames Wright // Boundary Condition Related Functions 416149fb536SJames Wright // ----------------------------------------------------------------------------- 417d3c60affSJames Wright PetscErrorCode SetupStrongBC_Ceed(Ceed ceed, DM dm, Honee honee, ProblemData problem); 418d4e423e7SJames Wright PetscErrorCode FreestreamBCSetup(BCDefinition bc_def, ProblemData problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, 419d4e423e7SJames Wright const StatePrimitive *reference); 420f978755dSJames Wright PetscErrorCode OutflowBCSetup(BCDefinition bc_def, ProblemData problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, 421f978755dSJames Wright const StatePrimitive *reference); 4225e79d562SJames Wright PetscErrorCode SlipBCSetup(BCDefinition bc_def, ProblemData problem, DM dm, void *ctx, CeedQFunctionContext newtonian_ig_qfctx); 423149fb536SJames Wright 424149fb536SJames Wright // ----------------------------------------------------------------------------- 425149fb536SJames Wright // Differential Filtering Functions 426149fb536SJames Wright // ----------------------------------------------------------------------------- 427e3663b90SJames Wright PetscErrorCode DifferentialFilterSetup(Ceed ceed, Honee honee, ProblemData problem); 428149fb536SJames Wright PetscErrorCode DifferentialFilterDataDestroy(DiffFilterData diff_filter); 429149fb536SJames Wright PetscErrorCode TSMonitor_DifferentialFilter(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, void *ctx); 4300c373b74SJames Wright PetscErrorCode DifferentialFilterApply(Honee honee, const PetscReal solution_time, const Vec Q, Vec Filtered_Solution); 431149fb536SJames Wright PetscErrorCode DifferentialFilterMmsICSetup(ProblemData problem); 432149fb536SJames Wright 433149fb536SJames Wright // ----------------------------------------------------------------------------- 434149fb536SJames Wright // SGS Data-Driven Training via SmartSim 435149fb536SJames Wright // ----------------------------------------------------------------------------- 4360c373b74SJames Wright PetscErrorCode SmartSimSetup(Honee honee); 437149fb536SJames Wright PetscErrorCode SmartSimDataDestroy(SmartSimData smartsim); 438e3663b90SJames Wright PetscErrorCode SGS_DD_TrainingSetup(Ceed ceed, Honee honee, ProblemData problem); 439149fb536SJames Wright PetscErrorCode TSMonitor_SGS_DD_Training(TS ts, PetscInt step_num, PetscReal solution_time, Vec Q, void *ctx); 440149fb536SJames Wright PetscErrorCode TSPostStep_SGS_DD_Training(TS ts); 441149fb536SJames Wright PetscErrorCode SGS_DD_TrainingDataDestroy(SGS_DD_TrainingData sgs_dd_train); 4428c85b835SJames Wright 4438c85b835SJames Wright // ----------------------------------------------------------------------------- 4448c85b835SJames Wright // Divergence of Diffusive Flux Projection 4458c85b835SJames Wright // ----------------------------------------------------------------------------- 4460c373b74SJames Wright PetscErrorCode DivDiffFluxProjectionCreate(Honee honee, PetscInt num_diff_flux_comps, DivDiffFluxProjectionData *pdiff_flux_proj); 4470880fbb6SJames Wright PetscErrorCode DivDiffFluxProjectionGetOperatorFieldData(DivDiffFluxProjectionData diff_flux_proj, CeedElemRestriction *elem_restr, CeedBasis *basis, 4480880fbb6SJames Wright CeedVector *vector, CeedEvalMode *eval_mode); 449e3663b90SJames Wright PetscErrorCode DivDiffFluxProjectionSetup(Honee honee, DivDiffFluxProjectionData diff_flux_proj); 45036038bbcSJames Wright PetscErrorCode DivDiffFluxProjectionApply(DivDiffFluxProjectionData diff_flux_proj, Vec Q_loc); 4518c85b835SJames Wright PetscErrorCode DivDiffFluxProjectionDataDestroy(DivDiffFluxProjectionData diff_flux_proj); 45225125139SJames Wright 45325125139SJames Wright PetscErrorCode SetupMontiorTotalKineticEnergy(TS ts, PetscViewerAndFormat *ctx); 45425125139SJames Wright PetscErrorCode TSMonitor_TotalKineticEnergy(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, PetscViewerAndFormat *ctx); 45587fd7f33SJames Wright 45687fd7f33SJames Wright PetscErrorCode SetupMontiorCfl(TS ts, PetscViewerAndFormat *ctx); 45787fd7f33SJames Wright PetscErrorCode TSMonitor_Cfl(TS ts, PetscInt step, PetscReal solution_time, Vec Q, PetscViewerAndFormat *ctx); 45816cb6b6bSJames Wright 45916cb6b6bSJames Wright PetscErrorCode KSPPostSolve_Honee(KSP ksp, Vec rhs, Vec x, void *ctx); 460