xref: /honee/src/boundary_condition.c (revision ea615d4cc464aa6ad650c06fae6d120cc2465bc4)
1 // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2 // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
3 
4 #include <navierstokes.h>
5 
6 /**
7    @brief Add `BCDefinition` to a `PetscSegBuffer`
8 
9    @param[in]     bc_def      `BCDefinition` to add
10    @param[in,out] bc_defs_seg `PetscSegBuffer` to add to
11 **/
12 static PetscErrorCode AddBCDefinitionToSegBuffer(BCDefinition bc_def, PetscSegBuffer bc_defs_seg) {
13   BCDefinition *bc_def_ptr;
14 
15   PetscFunctionBeginUser;
16   if (bc_def == NULL) PetscFunctionReturn(PETSC_SUCCESS);
17   PetscCall(PetscSegBufferGet(bc_defs_seg, 1, &bc_def_ptr));
18   *bc_def_ptr = bc_def;
19   PetscFunctionReturn(PETSC_SUCCESS);
20 }
21 
22 /**
23    @brief Create and setup `BCDefinition`s and `SimpleBC` from commandline options
24 
25    @param[in]     honee   `Honee`
26    @param[in,out] problem `ProblemData`
27    @param[in]     app_ctx `AppCtx`
28    @param[in,out] bc      `SimpleBC`
29 **/
30 PetscErrorCode BoundaryConditionSetUp(Honee honee, ProblemData problem, AppCtx app_ctx, SimpleBC bc) {
31   PetscSegBuffer bc_defs_seg;
32   PetscBool      flg;
33   BCDefinition   bc_def;
34 
35   PetscFunctionBeginUser;
36   PetscCall(PetscSegBufferCreate(sizeof(BCDefinition), 4, &bc_defs_seg));
37 
38   PetscOptionsBegin(honee->comm, NULL, "Boundary Condition Options", NULL);
39 
40   PetscCall(PetscOptionsBCDefinition("-bc_wall", "Face IDs to apply wall BC", NULL, "wall", &bc_def, NULL));
41   PetscCall(AddBCDefinitionToSegBuffer(bc_def, bc_defs_seg));
42   if (bc_def) {
43     PetscInt num_essential_comps = 16, essential_comps[16];
44 
45     PetscCall(PetscOptionsIntArray("-wall_comps", "An array of constrained component numbers", NULL, essential_comps, &num_essential_comps, &flg));
46     PetscCall(BCDefinitionSetEssential(bc_def, num_essential_comps, essential_comps));
47 
48     app_ctx->wall_forces.num_wall = bc_def->num_label_values;
49     PetscCall(PetscMalloc1(bc_def->num_label_values, &app_ctx->wall_forces.walls));
50     PetscCall(PetscArraycpy(app_ctx->wall_forces.walls, bc_def->label_values, bc_def->num_label_values));
51   }
52 
53   {  // Symmetry Boundary Conditions
54     const char *deprecated[3] = {"-bc_slip_x", "-bc_slip_y", "-bc_slip_z"};
55     const char *flags[3]      = {"-bc_symmetry_x", "-bc_symmetry_y", "-bc_symmetry_z"};
56 
57     for (PetscInt j = 0; j < 3; j++) {
58       PetscCall(PetscOptionsDeprecated(deprecated[j], flags[j], "libCEED 0.12.0",
59                                        "Use -bc_symmetry_[x,y,z] for direct equivalency, or -bc_slip for weak, Riemann-based, direction-invariant "
60                                        "slip/no-penatration boundary conditions"));
61       PetscCall(PetscOptionsBCDefinition(flags[j], "Face IDs to apply symmetry BC", NULL, "symmetry", &bc_def, NULL));
62       if (!bc_def) {
63         PetscCall(PetscOptionsBCDefinition(deprecated[j], "Face IDs to apply symmetry BC", NULL, "symmetry", &bc_def, NULL));
64       }
65       PetscCall(AddBCDefinitionToSegBuffer(bc_def, bc_defs_seg));
66       if (bc_def) {
67         PetscInt essential_comps[1] = {j + 1};
68 
69         PetscCall(BCDefinitionSetEssential(bc_def, 1, essential_comps));
70       }
71     }
72   }
73 
74   // Inflow BCs
75   bc->num_inflow = 16;
76   PetscCall(PetscOptionsIntArray("-bc_inflow", "Face IDs to apply inflow BC", NULL, bc->inflows, &bc->num_inflow, NULL));
77   // Outflow BCs
78   bc->num_outflow = 16;
79   PetscCall(PetscOptionsIntArray("-bc_outflow", "Face IDs to apply outflow BC", NULL, bc->outflows, &bc->num_outflow, NULL));
80   // Freestream BCs
81   bc->num_freestream = 16;
82   PetscCall(PetscOptionsIntArray("-bc_freestream", "Face IDs to apply freestream BC", NULL, bc->freestreams, &bc->num_freestream, NULL));
83 
84   bc->num_slip = 16;
85   PetscCall(PetscOptionsIntArray("-bc_slip", "Face IDs to apply slip BC", NULL, bc->slips, &bc->num_slip, NULL));
86 
87   PetscOptionsEnd();
88 
89   PetscCall(PetscSegBufferGetSize(bc_defs_seg, &problem->num_bc_defs));
90   PetscCall(PetscSegBufferExtractAlloc(bc_defs_seg, &problem->bc_defs));
91   PetscCall(PetscSegBufferDestroy(&bc_defs_seg));
92 
93   //TODO: Verify that the BCDefinition don't have overlapping claims to boundary faces
94 
95   PetscFunctionReturn(PETSC_SUCCESS);
96 }
97