1 // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2 // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3 #pragma once 4 5 #include <ceed.h> 6 #include <bc_definition.h> 7 #include <honee-file.h> 8 #include <log_events.h> 9 #include <mat-ceed.h> 10 #include <petsc-ceed-utils.h> 11 #include <petscts.h> 12 #include <stdbool.h> 13 #include <time.h> 14 15 #include <petsc_ops.h> 16 #include "../qfunctions/newtonian_types.h" 17 18 #if PETSC_VERSION_LT(3, 22, 0) 19 #error "PETSc v3.22 or later is required" 20 #endif 21 22 // ----------------------------------------------------------------------------- 23 // Enums 24 // ----------------------------------------------------------------------------- 25 26 // Euler - test cases 27 typedef enum { 28 EULER_TEST_ISENTROPIC_VORTEX = 0, 29 EULER_TEST_1 = 1, 30 EULER_TEST_2 = 2, 31 EULER_TEST_3 = 3, 32 EULER_TEST_4 = 4, 33 EULER_TEST_5 = 5, 34 } EulerTestType; 35 static const char *const EulerTestTypes[] = {"ISENTROPIC_VORTEX", "1", "2", "3", "4", "5", "EulerTestType", "EULER_TEST_", NULL}; 36 37 // Advection - Wind types 38 static const char *const AdvDifWindTypes[] = {"ROTATION", "TRANSLATION", "BOUNDARY_LAYER", "WindType", "ADVDIF_WIND_", NULL}; 39 40 // Advection - Initial Condition Types 41 static const char *const AdvDifICTypes[] = {"SPHERE", "CYLINDER", "COSINE_HILL", "SKEW", "WAVE", 42 "BOUNDARY_LAYER", "AdvectionICType", "ADVDIF_IC_", NULL}; 43 44 // Advection - Wave Types 45 static const char *const AdvDifWaveTypes[] = {"SINE", "SQUARE", "AdvDifWaveType", "ADVDIF_WAVE_", NULL}; 46 47 // Advection - Bubble Continuity Types 48 static const char *const AdvDifBubbleContinuityTypes[] = { 49 "SMOOTH", "BACK_SHARP", "THICK", "COSINE", "BubbleContinuityType", "ADVDIF_BUBBLE_CONTINUITY_", NULL}; 50 51 // Stabilization methods 52 static const char *const StabilizationTypes[] = {"NONE", "SU", "SUPG", "StabilizationType", "STAB_", NULL}; 53 54 // Stabilization tau constants 55 static const char *const StabilizationTauTypes[] = {"CTAU", "ADVDIFF_SHAKIB", "StabilizationTauType", "STAB_TAU_", NULL}; 56 57 // Test mode type 58 typedef enum { 59 TESTTYPE_NONE = 0, 60 TESTTYPE_SOLVER = 1, 61 TESTTYPE_TURB_SPANSTATS = 2, 62 TESTTYPE_DIFF_FILTER = 3, 63 } TestType; 64 static const char *const TestTypes[] = {"NONE", "SOLVER", "TURB_SPANSTATS", "DIFF_FILTER", "TestType", "TESTTYPE_", NULL}; 65 66 // Subgrid-Stress mode type 67 typedef enum { 68 SGS_MODEL_NONE = 0, 69 SGS_MODEL_DATA_DRIVEN = 1, 70 } SGSModelType; 71 static const char *const SGSModelTypes[] = {"NONE", "DATA_DRIVEN", "SGSModelType", "SGS_MODEL_", NULL}; 72 73 // Subgrid-Stress mode type 74 typedef enum { 75 SGS_MODEL_DD_FUSED = 0, 76 SGS_MODEL_DD_SEQENTIAL_CEED = 1, 77 SGS_MODEL_DD_SEQENTIAL_TORCH = 2, 78 } SGSModelDDImplementation; 79 static const char *const SGSModelDDImplementations[] = {"FUSED", "SEQUENTIAL_CEED", "SEQUENTIAL_TORCH", "SGSModelDDImplementation", "SGS_MODEL_DD_", 80 NULL}; 81 82 // Mesh transformation type 83 typedef enum { 84 MESH_TRANSFORM_NONE = 0, 85 MESH_TRANSFORM_PLATEMESH = 1, 86 } MeshTransformType; 87 static const char *const MeshTransformTypes[] = {"NONE", "PLATEMESH", "MeshTransformType", "MESH_TRANSFORM_", NULL}; 88 89 static const char *const DifferentialFilterDampingFunctions[] = { 90 "NONE", "VAN_DRIEST", "MMS", "DifferentialFilterDampingFunction", "DIFF_FILTER_DAMP_", NULL}; 91 92 static const char *const DivDiffFluxProjectionMethods[] = {"NONE", "DIRECT", "INDIRECT", "DivDiffFluxProjectionMethod", "DIV_DIFF_FLUX_PROJ_", NULL}; 93 94 // ----------------------------------------------------------------------------- 95 // Structs 96 // ----------------------------------------------------------------------------- 97 // Structs declarations 98 typedef struct AppCtx_private *AppCtx; 99 typedef struct Honee_private *Honee; 100 typedef struct Units_private *Units; 101 typedef struct SimpleBC_private *SimpleBC; 102 typedef struct Physics_private *Physics; 103 typedef struct ProblemData_private *ProblemData; 104 105 // Application context from user command line options 106 struct AppCtx_private { 107 // libCEED arguments 108 char ceed_resource[PETSC_MAX_PATH_LEN]; // libCEED backend 109 PetscInt degree; 110 PetscInt q_extra; 111 // Solver arguments 112 MatType amat_type; 113 // Post-processing arguments 114 PetscInt checkpoint_interval; 115 PetscInt viz_refine; 116 PetscBool use_continue_file; 117 PetscInt cont_steps; 118 PetscReal cont_time; 119 char cont_file[PETSC_MAX_PATH_LEN]; 120 char output_dir[PETSC_MAX_PATH_LEN]; 121 PetscBool add_stepnum2bin; 122 PetscBool checkpoint_vtk; 123 // Problem type arguments 124 PetscFunctionList problems; 125 char problem_name[PETSC_MAX_PATH_LEN]; 126 // Test mode arguments 127 TestType test_type; 128 PetscScalar test_tol; 129 char test_file_path[PETSC_MAX_PATH_LEN]; 130 // Turbulent spanwise statistics 131 PetscBool turb_spanstats_enable; 132 PetscInt turb_spanstats_collect_interval; 133 PetscInt turb_spanstats_viewer_interval; 134 PetscViewer turb_spanstats_viewer; 135 PetscViewerFormat turb_spanstats_viewer_format; 136 // Wall forces 137 struct { 138 PetscInt num_wall; 139 PetscInt *walls; 140 PetscViewer viewer; 141 PetscViewerFormat viewer_format; 142 PetscBool header_written; 143 } wall_forces; 144 // Subgrid Stress Model 145 SGSModelType sgs_model_type; 146 PetscBool sgs_train_enable; 147 // Differential Filtering 148 PetscBool diff_filter_monitor; 149 MeshTransformType mesh_transform_type; 150 // Divergence of Diffusive Flux Projection 151 DivDiffFluxProjectionMethod divFdiffproj_method; 152 153 PetscInt check_step_interval; 154 }; 155 156 typedef struct { 157 DM dm; 158 PetscSF sf; // For communicating child data to parents 159 OperatorApplyContext op_stats_collect_ctx, op_proj_rhs_ctx; 160 PetscInt num_comp_stats; 161 Vec Child_Stats_loc, Parent_Stats_loc; 162 KSP ksp; // For the L^2 projection solve 163 CeedScalar span_width; // spanwise width of the child domain 164 PetscBool do_mms_test; 165 OperatorApplyContext mms_error_ctx; 166 CeedContextFieldLabel solution_time_label, previous_time_label; 167 } SpanStatsData; 168 169 typedef struct { 170 DM dm; 171 PetscInt num_comp; 172 OperatorApplyContext l2_rhs_ctx; 173 KSP ksp; 174 } *NodalProjectionData; 175 176 typedef struct DivDiffFluxProjectionData_private *DivDiffFluxProjectionData; 177 178 struct DivDiffFluxProjectionData_private { 179 PetscInt num_diff_flux_comps; 180 DivDiffFluxProjectionMethod method; 181 NodalProjectionData projection; 182 183 // CeedOperator Objects 184 CeedElemRestriction elem_restr_div_diff_flux; 185 CeedBasis basis_div_diff_flux; 186 CeedEvalMode eval_mode_div_diff_flux; 187 CeedVector div_diff_flux_ceed; 188 189 // Problem specific setup functions 190 PetscErrorCode (*CreateRHSOperator_Direct)(Honee, DivDiffFluxProjectionData, CeedOperator *); 191 PetscErrorCode (*CreateRHSOperator_Indirect)(Honee, DivDiffFluxProjectionData, CeedOperator *); 192 193 // Only used for direct method: 194 Vec DivDiffFlux_loc; 195 PetscMemType DivDiffFlux_memtype; 196 PetscBool ceed_vec_has_array; 197 198 // Only used for indirect method: 199 OperatorApplyContext calc_div_diff_flux; 200 }; 201 202 typedef PetscErrorCode (*SgsDDNodalStressEval)(Honee honee, Vec Q_loc, Vec VelocityGradient, Vec SGSNodal_loc); 203 typedef PetscErrorCode (*SgsDDNodalStressInference)(Vec DD_Inputs_loc, Vec DD_Outputs_loc, void *ctx); 204 typedef struct { 205 DM dm_sgs, dm_dd_inputs, dm_dd_outputs; 206 PetscInt num_comp_sgs, num_comp_inputs, num_comp_outputs; 207 OperatorApplyContext op_nodal_evaluation_ctx, op_nodal_dd_inputs_ctx, op_nodal_dd_outputs_ctx, op_sgs_apply_ctx; 208 CeedVector sgs_nodal_ceed, grad_velo_ceed; 209 SgsDDNodalStressEval sgs_nodal_eval; 210 SgsDDNodalStressInference sgs_nodal_inference; 211 void *sgs_nodal_inference_ctx; 212 PetscErrorCode (*sgs_nodal_inference_ctx_destroy)(void *ctx); 213 } *SgsDDData; 214 215 typedef struct { 216 DM dm_dd_training; 217 PetscInt num_comp_dd_inputs, write_data_interval, num_filter_widths; 218 PetscScalar filter_widths[16]; 219 OperatorApplyContext op_training_data_calc_ctx; 220 NodalProjectionData filtered_grad_velo_proj; 221 size_t training_data_array_dims[2]; 222 PetscBool overwrite_training_data; 223 } *SGS_DD_TrainingData; 224 225 typedef struct { 226 DM dm_filter; 227 PetscInt num_filtered_fields; 228 CeedInt *num_field_components; 229 PetscInt field_prim_state, field_velo_prod; 230 OperatorApplyContext op_rhs_ctx; 231 KSP ksp; 232 PetscObjectState X_loc_state; 233 PetscBool do_mms_test; 234 CeedContextFieldLabel filter_width_scaling_label; 235 } *DiffFilterData; 236 237 typedef struct { 238 void *client; 239 char rank_id_name[16]; 240 PetscInt collocated_database_num_ranks; 241 } *SmartSimData; 242 243 // PETSc user data 244 struct Honee_private { 245 MPI_Comm comm; 246 DM dm; 247 DM dm_viz; 248 Mat interp_viz; 249 Ceed ceed; 250 Units units; 251 Vec Q_loc, Q_dot_loc; 252 Physics phys; 253 AppCtx app_ctx; 254 CeedVector q_ceed, q_dot_ceed, g_ceed, x_ceed; 255 CeedOperator op_ifunction; 256 Mat mat_ijacobian; 257 KSP mass_ksp; 258 OperatorApplyContext op_rhs_ctx, op_strong_bc_ctx; 259 CeedScalar time_bc_set; 260 SpanStatsData spanstats; 261 NodalProjectionData grad_velo_proj; 262 SgsDDData sgs_dd_data; 263 DiffFilterData diff_filter; 264 SmartSimData smartsim; 265 SGS_DD_TrainingData sgs_dd_train; 266 DivDiffFluxProjectionData diff_flux_proj; 267 268 // old CeedData 269 CeedVector x_coord; 270 CeedBasis basis_x, basis_q; 271 CeedElemRestriction elem_restr_x, elem_restr_q; 272 OperatorApplyContext op_ics_ctx; 273 274 time_t start_time; 275 time_t max_wall_time; 276 PetscInt max_wall_time_interval; 277 }; 278 279 // Units 280 struct Units_private { 281 // fundamental units 282 PetscScalar meter; 283 PetscScalar kilogram; 284 PetscScalar second; 285 PetscScalar Kelvin; 286 // derived units 287 PetscScalar Pascal; 288 PetscScalar J_per_kg_K; 289 PetscScalar m_per_squared_s; 290 PetscScalar W_per_m_K; 291 PetscScalar Joule; 292 }; 293 294 // Boundary conditions 295 struct SimpleBC_private { 296 PetscInt num_inflow, num_outflow, num_freestream, num_slip; 297 PetscInt inflows[16], outflows[16], freestreams[16], slips[16]; 298 }; 299 300 // Struct that contains all enums and structs used for the physics of all problems 301 struct Physics_private { 302 PetscBool implicit; 303 StateVariable state_var; 304 CeedContextFieldLabel solution_time_label; 305 CeedContextFieldLabel stg_solution_time_label; 306 CeedContextFieldLabel timestep_size_label; 307 CeedContextFieldLabel ics_time_label; 308 }; 309 310 PetscErrorCode BoundaryConditionSetUp(Honee honee, ProblemData problem, AppCtx app_ctx, SimpleBC bc); 311 312 typedef struct { 313 CeedQFunctionUser qf_func_ptr; // !< QFunction function pointer 314 const char *qf_loc; // !< Absolute path to QFunction source file 315 CeedQFunctionContext qfctx; // !< QFunctionContext to attach to QFunction 316 } ProblemQFunctionSpec; 317 318 // Problem specific data 319 struct ProblemData_private { 320 CeedInt jac_data_size_vol, jac_data_size_sur; 321 ProblemQFunctionSpec ics, apply_vol_rhs, apply_vol_ifunction, apply_vol_ijacobian, apply_inflow, apply_outflow, apply_freestream, apply_slip, 322 apply_inflow_jacobian, apply_outflow_jacobian, apply_freestream_jacobian, apply_slip_jacobian; 323 bool compute_exact_solution_error; 324 PetscBool set_bc_from_ics, use_strong_bc_ceed; 325 PetscCount num_bc_defs; 326 BCDefinition *bc_defs; 327 PetscErrorCode (*print_info)(Honee, ProblemData, AppCtx); 328 PetscErrorCode (*create_mass_operator)(Honee, CeedOperator *); 329 }; 330 331 extern int FreeContextPetsc(void *); 332 333 // ----------------------------------------------------------------------------- 334 // Set up problems 335 // ----------------------------------------------------------------------------- 336 // Set up function for each problem 337 extern PetscErrorCode NS_TAYLOR_GREEN(ProblemData problem, DM dm, void *ctx, SimpleBC bc); 338 extern PetscErrorCode NS_GAUSSIAN_WAVE(ProblemData problem, DM dm, void *ctx, SimpleBC bc); 339 extern PetscErrorCode NS_CHANNEL(ProblemData problem, DM dm, void *ctx, SimpleBC bc); 340 extern PetscErrorCode NS_BLASIUS(ProblemData problem, DM dm, void *ctx, SimpleBC bc); 341 extern PetscErrorCode NS_NEWTONIAN_IG(ProblemData problem, DM dm, void *ctx, SimpleBC bc); 342 extern PetscErrorCode NS_DENSITY_CURRENT(ProblemData problem, DM dm, void *ctx, SimpleBC bc); 343 extern PetscErrorCode NS_EULER_VORTEX(ProblemData problem, DM dm, void *ctx, SimpleBC bc); 344 extern PetscErrorCode NS_SHOCKTUBE(ProblemData problem, DM dm, void *ctx, SimpleBC bc); 345 extern PetscErrorCode NS_ADVECTION(ProblemData problem, DM dm, void *ctx, SimpleBC bc); 346 extern PetscErrorCode NS_ADVECTION2D(ProblemData problem, DM dm, void *ctx, SimpleBC bc); 347 348 // Print function for each problem 349 extern PetscErrorCode PRINT_NEWTONIAN(Honee honee, ProblemData problem, AppCtx app_ctx); 350 extern PetscErrorCode PRINT_EULER_VORTEX(Honee honee, ProblemData problem, AppCtx app_ctx); 351 extern PetscErrorCode PRINT_SHOCKTUBE(Honee honee, ProblemData problem, AppCtx app_ctx); 352 extern PetscErrorCode PRINT_ADVECTION(Honee honee, ProblemData problem, AppCtx app_ctx); 353 extern PetscErrorCode PRINT_ADVECTION2D(Honee honee, ProblemData problem, AppCtx app_ctx); 354 355 PetscErrorCode PrintRunInfo(Honee honee, Physics phys_ctx, ProblemData problem, TS ts); 356 357 // ----------------------------------------------------------------------------- 358 // libCEED functions 359 // ----------------------------------------------------------------------------- 360 PetscErrorCode DMPlexCeedElemRestrictionCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field, 361 CeedElemRestriction *restriction); 362 PetscErrorCode DMPlexCeedElemRestrictionCoordinateCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, 363 CeedElemRestriction *restriction); 364 PetscErrorCode DMPlexCeedElemRestrictionQDataCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, 365 PetscInt q_data_size, CeedElemRestriction *restriction); 366 PetscErrorCode DMPlexCeedElemRestrictionCollocatedCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, 367 PetscInt q_data_size, CeedElemRestriction *restriction); 368 369 PetscErrorCode CreateBasisFromPlex(Ceed ceed, DM dm, DMLabel domain_label, CeedInt label_value, CeedInt height, CeedInt dm_field, CeedBasis *basis); 370 PetscErrorCode CreateCoordinateBasisFromPlex(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, CeedBasis *basis); 371 PetscErrorCode DMPlexCeedBasisCellToFaceCoordinateCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt face, 372 CeedBasis *basis); 373 PetscErrorCode DMPlexCeedBasisCellToFaceCreate(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt face, PetscInt dm_field, 374 CeedBasis *basis); 375 PetscErrorCode DMPlexCreateFaceLabel(DM dm, PetscInt dm_face, char **face_label_name); 376 PetscErrorCode DMLabelCreateGlobalValueArray(DM dm, DMLabel label, PetscInt *num_values, PetscInt **value_array); 377 378 PetscErrorCode SetupLibceed(Ceed ceed, DM dm, Honee honee, AppCtx app_ctx, ProblemData problem, SimpleBC bc); 379 380 PetscErrorCode QDataGet(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, CeedElemRestriction elem_restr_x, CeedBasis basis_x, 381 CeedVector x_coord, CeedElemRestriction *elem_restr_qd, CeedVector *q_data, CeedInt *q_data_size); 382 PetscErrorCode QDataGetNumComponents(DM dm, CeedInt *q_data_size); 383 PetscErrorCode QDataBoundaryGet(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, CeedElemRestriction elem_restr_x, CeedBasis basis_x, 384 CeedVector x_coord, CeedElemRestriction *elem_restr_qd, CeedVector *q_data, CeedInt *q_data_size); 385 PetscErrorCode QDataBoundaryGetNumComponents(DM dm, CeedInt *q_data_size); 386 PetscErrorCode QDataBoundaryGradientGetNumComponents(DM dm, CeedInt *q_data_size); 387 PetscErrorCode QDataBoundaryGradientGet(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, CeedVector x_coord, 388 CeedElemRestriction *elem_restr_qd, CeedVector *q_data, CeedInt *q_data_size); 389 PetscErrorCode QDataClearStoredData(); 390 // ----------------------------------------------------------------------------- 391 // Time-stepping functions 392 // ----------------------------------------------------------------------------- 393 PetscErrorCode RHS_NS(TS ts, PetscReal t, Vec Q, Vec G, void *user_data); 394 PetscErrorCode IFunction_NS(TS ts, PetscReal t, Vec Q, Vec Q_dot, Vec G, void *user_data); 395 PetscErrorCode TSMonitor_NS(TS ts, PetscInt step_no, PetscReal time, Vec Q, void *ctx); 396 PetscErrorCode TSSolve_NS(DM dm, Honee honee, AppCtx app_ctx, Physics phys, ProblemData problem, Vec *Q, PetscScalar *f_time, TS *ts); 397 PetscErrorCode UpdateBoundaryValues(Honee honee, Vec Q_loc, PetscReal t); 398 399 // ----------------------------------------------------------------------------- 400 // Setup DM 401 // ----------------------------------------------------------------------------- 402 PetscErrorCode CreateDM(MPI_Comm comm, ProblemData problem, MatType, VecType, DM *dm); 403 PetscErrorCode SetUpDM(DM dm, ProblemData problem, PetscInt degree, PetscInt q_extra, SimpleBC bc, Physics phys); 404 PetscErrorCode VizRefineDM(DM dm, Honee honee, ProblemData problem, SimpleBC bc, Physics phys); 405 406 PetscErrorCode DMSetupByOrderBegin_FEM(PetscBool setup_faces, PetscBool setup_coords, PetscInt degree, PetscInt coord_order, PetscInt q_extra, 407 PetscInt num_fields, const PetscInt *field_sizes, DM dm); 408 PetscErrorCode DMSetupByOrderEnd_FEM(PetscBool setup_coords, DM dm); 409 PetscErrorCode DMSetupByOrder_FEM(PetscBool setup_faces, PetscBool setup_coords, PetscInt degree, PetscInt coord_order, PetscInt q_extra, 410 PetscInt num_fields, const PetscInt *field_sizes, DM dm); 411 412 // ----------------------------------------------------------------------------- 413 // Process command line options 414 // ----------------------------------------------------------------------------- 415 PetscErrorCode ProcessCommandLineOptions(Honee honee, SimpleBC bc); 416 PetscErrorCode HoneeOptionsSetValueDefault(PetscOptions options, const char name[], const char value[]); 417 418 // ----------------------------------------------------------------------------- 419 // Miscellaneous utility functions 420 // ----------------------------------------------------------------------------- 421 PetscErrorCode GetInverseMultiplicity(Ceed ceed, DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field, 422 PetscBool get_global_multiplicity, CeedElemRestriction *elem_restr_inv_multiplicity, 423 CeedVector *inv_multiplicity); 424 PetscErrorCode ICs_FixMultiplicity(DM dm, Honee honee, Vec Q_loc, Vec Q, CeedScalar time); 425 426 PetscErrorCode DMPlexInsertBoundaryValues_FromICs(DM dm, PetscBool insert_essential, Vec Q_loc, PetscReal time, Vec face_geom_FVM, Vec cell_geom_FVM, 427 Vec grad_FVM); 428 429 PetscErrorCode RegressionTest(AppCtx app_ctx, Vec Q); 430 PetscErrorCode PrintError(DM dm, Honee honee, Vec Q, PetscScalar final_time); 431 PetscErrorCode PostProcess(TS ts, DM dm, ProblemData problem, Honee honee, Vec Q, PetscScalar final_time); 432 PetscErrorCode SetBCsFromICs(DM dm, Vec Q, Vec Q_loc); 433 PetscErrorCode HoneeMassQFunctionCreate(Ceed ceed, CeedInt N, CeedInt q_data_size, CeedQFunction *qf); 434 PetscErrorCode HoneeCalculateDomainSize(Honee honee, PetscScalar *volume); 435 PetscErrorCode NodalProjectionDataDestroy(NodalProjectionData context); 436 437 // ----------------------------------------------------------------------------- 438 // Turbulence Statistics Collection Functions 439 // ----------------------------------------------------------------------------- 440 PetscErrorCode TurbulenceStatisticsSetup(Ceed ceed, Honee honee, ProblemData problem); 441 PetscErrorCode TSMonitor_TurbulenceStatistics(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, void *ctx); 442 PetscErrorCode TurbulenceStatisticsDestroy(Honee honee); 443 444 // ----------------------------------------------------------------------------- 445 // Data-Driven Subgrid Stress (DD-SGS) Modeling Functions 446 // ----------------------------------------------------------------------------- 447 PetscErrorCode SgsDDSetup(Ceed ceed, Honee honee, ProblemData problem); 448 PetscErrorCode SgsDDDataDestroy(SgsDDData sgs_dd_data); 449 PetscErrorCode SgsDDApplyIFunction(Honee honee, const Vec Q_loc, Vec G_loc); 450 PetscErrorCode VelocityGradientProjectionSetup(Ceed ceed, Honee honee, ProblemData problem, StateVariable state_var_input, 451 CeedElemRestriction elem_restr_input, CeedBasis basis_input, NodalProjectionData *pgrad_velo_proj); 452 PetscErrorCode VelocityGradientProjectionApply(NodalProjectionData grad_velo_proj, Vec Q_loc, Vec VelocityGradient); 453 PetscErrorCode GridAnisotropyTensorProjectionSetupApply(Ceed ceed, Honee honee, CeedElemRestriction *elem_restr_grid_aniso, 454 CeedVector *grid_aniso_vector); 455 PetscErrorCode GridAnisotropyTensorCalculateCollocatedVector(Ceed ceed, Honee honee, CeedElemRestriction *elem_restr_grid_aniso, 456 CeedVector *aniso_colloc_ceed, PetscInt *num_comp_aniso); 457 458 // ----------------------------------------------------------------------------- 459 // Boundary Condition Related Functions 460 // ----------------------------------------------------------------------------- 461 PetscErrorCode SetupStrongBC_Ceed(Ceed ceed, DM dm, Honee honee, ProblemData problem, SimpleBC bc); 462 PetscErrorCode FreestreamBCSetup(ProblemData problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, const StatePrimitive *reference); 463 PetscErrorCode OutflowBCSetup(ProblemData problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, const StatePrimitive *reference); 464 PetscErrorCode SlipBCSetup(ProblemData problem, DM dm, void *ctx, CeedQFunctionContext newtonian_ig_qfctx); 465 466 // ----------------------------------------------------------------------------- 467 // Differential Filtering Functions 468 // ----------------------------------------------------------------------------- 469 PetscErrorCode DifferentialFilterSetup(Ceed ceed, Honee honee, ProblemData problem); 470 PetscErrorCode DifferentialFilterDataDestroy(DiffFilterData diff_filter); 471 PetscErrorCode TSMonitor_DifferentialFilter(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, void *ctx); 472 PetscErrorCode DifferentialFilterApply(Honee honee, const PetscReal solution_time, const Vec Q, Vec Filtered_Solution); 473 PetscErrorCode DifferentialFilterMmsICSetup(ProblemData problem); 474 475 // ----------------------------------------------------------------------------- 476 // SGS Data-Driven Training via SmartSim 477 // ----------------------------------------------------------------------------- 478 PetscErrorCode SmartSimSetup(Honee honee); 479 PetscErrorCode SmartSimDataDestroy(SmartSimData smartsim); 480 PetscErrorCode SGS_DD_TrainingSetup(Ceed ceed, Honee honee, ProblemData problem); 481 PetscErrorCode TSMonitor_SGS_DD_Training(TS ts, PetscInt step_num, PetscReal solution_time, Vec Q, void *ctx); 482 PetscErrorCode TSPostStep_SGS_DD_Training(TS ts); 483 PetscErrorCode SGS_DD_TrainingDataDestroy(SGS_DD_TrainingData sgs_dd_train); 484 485 // ----------------------------------------------------------------------------- 486 // Divergence of Diffusive Flux Projection 487 // ----------------------------------------------------------------------------- 488 PetscErrorCode DivDiffFluxProjectionCreate(Honee honee, PetscInt num_diff_flux_comps, DivDiffFluxProjectionData *pdiff_flux_proj); 489 PetscErrorCode DivDiffFluxProjectionGetOperatorFieldData(DivDiffFluxProjectionData diff_flux_proj, CeedElemRestriction *elem_restr, CeedBasis *basis, 490 CeedVector *vector, CeedEvalMode *eval_mode); 491 PetscErrorCode DivDiffFluxProjectionSetup(Honee honee, DivDiffFluxProjectionData diff_flux_proj); 492 PetscErrorCode DivDiffFluxProjectionApply(DivDiffFluxProjectionData diff_flux_proj, Vec Q_loc); 493 PetscErrorCode DivDiffFluxProjectionDataDestroy(DivDiffFluxProjectionData diff_flux_proj); 494 495 PetscErrorCode SetupMontiorTotalKineticEnergy(TS ts, PetscViewerAndFormat *ctx); 496 PetscErrorCode TSMonitor_TotalKineticEnergy(TS ts, PetscInt steps, PetscReal solution_time, Vec Q, PetscViewerAndFormat *ctx); 497