xref: /honee/include/bc_definition.h (revision e5a8cae06a62eeac7fdfa27f57fc80d5b628dcec)
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 <petsc.h>
7 #include <petsc/private/petscimpl.h>
8 
9 typedef struct _p_BCDefinition *BCDefinition;
10 
11 typedef PetscErrorCode (*BCDefinitionCreateQFunction)(BCDefinition bc_def, CeedQFunction *qf);
12 typedef PetscErrorCode (*BCDefinitionAddIFunctionOperator)(BCDefinition bc_def, DMLabel orientation_label, PetscInt orientation, CeedQFunction qf,
13                                                            CeedOperator op, CeedOperator *sub_op);
14 typedef PetscErrorCode (*BCDefinitionAddIJacobianOperator)(BCDefinition bc_def, CeedOperator sub_op_ifunction, DMLabel orientation_label,
15                                                            PetscInt orientation, CeedQFunction qf, CeedOperator op);
16 
17 typedef struct _BCDefinitionOps *BCDefinitionOps;
18 struct _BCDefinitionOps {};
19 
20 struct _p_BCDefinition {
21   PETSCHEADER(struct _BCDefinitionOps);
22   char *name;
23   DM    dm;
24 
25   // Boundary ID information
26   PetscInt num_label_values, *label_values, dm_field;
27 
28   // Essential Boundary information
29   PetscInt num_essential_comps, *essential_comps;
30 
31   void                            *ctx;
32   PetscCtxDestroyFn               *DestroyCtx;
33   BCDefinitionCreateQFunction      CreateIFunctionQF, CreateIJacobianQF;
34   BCDefinitionAddIFunctionOperator AddIFunctionOperator;
35   BCDefinitionAddIJacobianOperator AddIJacobianOperator;
36 };
37 
38 /**
39    @brief Creates a `BCDefinition` from an array of integers in an option in the database
40 
41    Must be between `PetscOptionsBegin()` and `PetscOptionsEnd()`.
42 
43    @param[in]  opt    The option one is seeking
44    @param[in]  text   Short string describing option
45    @param[in]  man    Manual page for the option
46    @param[in]  name   String that sets the name of the `BCDefinition`
47    @param[out] bc_def Resulting `BCDefinition`, `NULL` if option is not set
48    @param[out] set    `PETSC_TRUE` if found, else `PETSC_FALSE`
49 **/
50 #define PetscOptionsBCDefinition(opt, text, man, name, bc_def, set) \
51   PetscOptionsBCDefinition_Private(PetscOptionsObject, opt, text, man, name, bc_def, set)
52 PetscErrorCode PetscOptionsBCDefinition_Private(PetscOptionItems PetscOptionsObject, const char opt[], const char text[], const char man[],
53                                                 const char name[], BCDefinition *bc_def, PetscBool *set);
54 
55 PetscErrorCode BCDefinitionCreate(MPI_Comm comm, const char *name, PetscInt num_label_values, PetscInt label_values[], BCDefinition *bc_def);
56 PetscErrorCode BCDefinitionGetInfo(BCDefinition bc_def, const char *name[], PetscInt *num_label_values, const PetscInt *label_values[]);
57 PetscErrorCode BCDefinitionView(BCDefinition bc_def, PetscViewer viewer);
58 PetscErrorCode BCDefinitionViewFromOptions(BCDefinition bc_def, PetscObject obj, const char name[]);
59 PetscErrorCode BCDefinitionDestroy(BCDefinition *bc_def);
60 
61 PetscErrorCode BCDefinitionSetEssential(BCDefinition bc_def, PetscInt num_essential_comps, PetscInt essential_comps[]);
62 PetscErrorCode BCDefinitionGetEssential(BCDefinition bc_def, PetscInt *num_essential_comps, const PetscInt *essential_comps[]);
63 
64 PetscErrorCode BCDefinitionSetDM(BCDefinition bc_def, DM dm);
65 PetscErrorCode BCDefinitionGetDM(BCDefinition bc_def, DM *dm);
66 
67 PetscErrorCode BCDefinitionSetContext(BCDefinition bc_def, PetscCtxDestroyFn *destroy_ctx, void *ctx);
68 PetscErrorCode BCDefinitionGetContext(BCDefinition bc_def, void *ctx);
69 
70 PetscErrorCode BCDefinitionSetIFunction(BCDefinition bc_def, BCDefinitionCreateQFunction create_qf, BCDefinitionAddIFunctionOperator add_op);
71 PetscErrorCode BCDefinitionSetIJacobian(BCDefinition bc_def, BCDefinitionCreateQFunction create_qf, BCDefinitionAddIJacobianOperator add_op);
72 PetscErrorCode BCDefinitionAddOperators(BCDefinition bc_def, CeedOperator op_ifunction, CeedOperator op_ijacobian);
73