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