Date: 2024-07-30T17:31:09+00:00

Actual source code: petscdmmoab.h

      1: #pragma once

      3: #include <petscvec.h>
      4: #include <petscmat.h>
      5: #include <petscdm.h>
      6: #include <petscdt.h>

      8: #include <string>
      9: #include <moab/Core.hpp> /*I      "moab/Core.hpp"    I*/
     10: #ifdef MOAB_HAVE_MPI
     11:   #include <moab/ParallelComm.hpp> /*I      "moab/ParallelComm.hpp"    I*/
     12: #endif

     14: /* The MBERR macro is used to save typing. It checks a MOAB error code
     15:  * (rval) and calls SETERRQ if not MB_SUCCESS. A message (msg) can
     16:  * also be passed in. */
     17: #define MBERR(msg, rval) PetscCheck(rval == moab::MB_SUCCESS, PETSC_COMM_SELF, PETSC_ERR_LIB, "MOAB ERROR (%i): %s", (PetscErrorCode)rval, msg)
     18: #define MBERRNM(rval)    PetscCheck(rval == moab::MB_SUCCESS, PETSC_COMM_SELF, PETSC_ERR_LIB, "MOAB ERROR (%i)", rval)
     19: #define MBERRV(mbif, rval) \
     20:   do { \
     21:     if (rval != moab::MB_SUCCESS) { \
     22:       std::string emsg; \
     23:       mbif->get_last_error(emsg); \
     24:       SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "MOAB ERROR (%i): %s", (PetscErrorCode)rval, emsg.c_str()); \
     25:     } \
     26:   } while (0)
     27: #define MBERRVM(mbif, msg, rval) \
     28:   do { \
     29:     if (rval != moab::MB_SUCCESS) { \
     30:       std::string emsg; \
     31:       mbif->get_last_error(emsg); \
     32:       SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "MOAB ERROR (%i): %s :: %s", (PetscErrorCode)rval, msg, emsg.c_str()); \
     33:     } \
     34:   } while (0)

     36: /* define enums for options to read and write MOAB files in parallel */
     37: typedef enum {
     38:   READ_PART,
     39:   READ_DELETE,
     40:   BCAST_DELETE
     41: } MoabReadMode;
     42: static const char *const MoabReadModes[] = {"READ_PART", "READ_DELETE", "BCAST_DELETE", "MoabReadMode", "", 0};
     43: typedef enum {
     44:   WRITE_PART,
     45:   FORMAT
     46: } MoabWriteMode;
     47: static const char *const MoabWriteModes[] = {"WRITE_PART", "FORMAT", "MoabWriteMode", "", 0};

     49: PETSC_EXTERN PetscErrorCode DMMoabCreate(MPI_Comm, DM *);
     50: PETSC_EXTERN PetscErrorCode DMMoabCreateMoab(MPI_Comm, moab::Interface *, moab::Tag *, moab::Range *, DM *);
     51: PETSC_EXTERN PetscErrorCode DMMoabOutput(DM, const char *, const char *);

     53: PETSC_EXTERN PetscErrorCode DMMoabSetInterface(DM, moab::Interface *);
     54: PETSC_EXTERN PetscErrorCode DMMoabGetInterface(DM, moab::Interface **);
     55: #ifdef MOAB_HAVE_MPI
     56: PETSC_EXTERN PetscErrorCode DMMoabGetParallelComm(DM, moab::ParallelComm **);
     57: #endif

     59: PETSC_EXTERN PetscErrorCode DMMoabSetLocalVertices(DM, moab::Range *);
     60: PETSC_EXTERN PetscErrorCode DMMoabGetAllVertices(DM, moab::Range *);
     61: PETSC_EXTERN PetscErrorCode DMMoabGetLocalVertices(DM, const moab::Range **, const moab::Range **);
     62: PETSC_EXTERN PetscErrorCode DMMoabSetLocalElements(DM, moab::Range *);
     63: PETSC_EXTERN PetscErrorCode DMMoabGetLocalElements(DM, const moab::Range **);
     64: PETSC_EXTERN PetscErrorCode DMMoabSetLocalToGlobalTag(DM, moab::Tag);
     65: PETSC_EXTERN PetscErrorCode DMMoabGetLocalToGlobalTag(DM, moab::Tag *);
     66: PETSC_EXTERN PetscErrorCode DMMoabSetBlockSize(DM, PetscInt);
     67: PETSC_EXTERN PetscErrorCode DMMoabGetBlockSize(DM, PetscInt *);
     68: PETSC_EXTERN PetscErrorCode DMMoabSetBlockFills(DM, const PetscInt *, const PetscInt *);
     69: PETSC_EXTERN PetscErrorCode DMMoabGetHierarchyLevel(DM, PetscInt *);

     71: PETSC_EXTERN PetscErrorCode DMMoabGetDimension(DM, PetscInt *);
     72: PETSC_EXTERN PetscErrorCode DMMoabGetBoundaryEntities(DM, moab::Range *, moab::Range *, moab::Range *);
     73: PETSC_EXTERN PetscErrorCode DMMoabGetMaterialBlock(DM, const moab::EntityHandle, PetscInt *);

     75: PETSC_EXTERN PetscErrorCode DMMoabGetSize(DM, PetscInt *, PetscInt *);
     76: PETSC_EXTERN PetscErrorCode DMMoabGetLocalSize(DM, PetscInt *, PetscInt *, PetscInt *, PetscInt *);
     77: PETSC_EXTERN PetscErrorCode DMMoabGetOffset(DM, PetscInt *);

     79: PETSC_EXTERN PetscErrorCode DMMoabVecGetArrayRead(DM, Vec, void *);
     80: PETSC_EXTERN PetscErrorCode DMMoabVecRestoreArrayRead(DM, Vec, void *);
     81: PETSC_EXTERN PetscErrorCode DMMoabVecGetArray(DM, Vec, void *);
     82: PETSC_EXTERN PetscErrorCode DMMoabVecRestoreArray(DM, Vec, void *);

     84: PETSC_EXTERN PetscErrorCode DMMoabCreateVector(DM, moab::Tag, const moab::Range *, PetscBool, PetscBool, Vec *);
     85: PETSC_EXTERN PetscErrorCode DMMoabGetVecTag(Vec, moab::Tag *);
     86: PETSC_EXTERN PetscErrorCode DMMoabGetVecRange(Vec, moab::Range *);

     88: PETSC_EXTERN PetscErrorCode DMMoabSetFieldVector(DM, PetscInt, Vec);
     89: PETSC_EXTERN PetscErrorCode DMMoabSetGlobalFieldVector(DM, Vec);

     91: PETSC_EXTERN PetscErrorCode DMMoabCreateVertices(DM, const PetscReal *, PetscInt, moab::Range *);
     92: PETSC_EXTERN PetscErrorCode DMMoabCreateElement(DM, const moab::EntityType, const moab::EntityHandle *, PetscInt, moab::EntityHandle *);
     93: PETSC_EXTERN PetscErrorCode DMMoabCreateSubmesh(DM, DM *);
     94: PETSC_EXTERN PetscErrorCode DMMoabRenumberMeshEntities(DM);

     96: PETSC_EXTERN PetscErrorCode DMMoabGetFieldName(DM, PetscInt, const char **);
     97: PETSC_EXTERN PetscErrorCode DMMoabSetFieldName(DM, PetscInt, const char *);
     98: PETSC_EXTERN PetscErrorCode DMMoabSetFieldNames(DM, PetscInt, const char *[]);
     99: PETSC_EXTERN PetscErrorCode DMMoabGetFieldDof(DM, moab::EntityHandle, PetscInt, PetscInt *);
    100: PETSC_EXTERN PetscErrorCode DMMoabGetFieldDofs(DM, PetscInt, const moab::EntityHandle *, PetscInt, PetscInt *);
    101: PETSC_EXTERN PetscErrorCode DMMoabGetFieldDofsLocal(DM, PetscInt, const moab::EntityHandle *, PetscInt, PetscInt *);
    102: PETSC_EXTERN PetscErrorCode DMMoabGetDofs(DM, PetscInt, const moab::EntityHandle *, PetscInt *);
    103: PETSC_EXTERN PetscErrorCode DMMoabGetDofsLocal(DM, PetscInt, const moab::EntityHandle *, PetscInt *);
    104: PETSC_EXTERN PetscErrorCode DMMoabGetDofsBlocked(DM, PetscInt, const moab::EntityHandle *, PetscInt *);
    105: PETSC_EXTERN PetscErrorCode DMMoabGetDofsBlockedLocal(DM, PetscInt, const moab::EntityHandle *, PetscInt *);

    107: PETSC_EXTERN PetscErrorCode DMMoabGetVertexDofsBlocked(DM, PetscInt **);
    108: PETSC_EXTERN PetscErrorCode DMMoabGetVertexDofsBlockedLocal(DM, PetscInt **);

    110: /* discretization and assembly specific DMMoab interface functions */
    111: PETSC_EXTERN PetscErrorCode DMMoabGetElementConnectivity(DM, moab::EntityHandle, PetscInt *, const moab::EntityHandle **);
    112: PETSC_EXTERN PetscErrorCode DMMoabGetVertexConnectivity(DM, moab::EntityHandle, PetscInt *, moab::EntityHandle **);
    113: PETSC_EXTERN PetscErrorCode DMMoabRestoreVertexConnectivity(DM, moab::EntityHandle, PetscInt *, moab::EntityHandle **);
    114: PETSC_EXTERN PetscErrorCode DMMoabGetVertexCoordinates(DM, PetscInt, const moab::EntityHandle *, PetscReal *);
    115: PETSC_EXTERN PetscErrorCode DMMoabIsEntityOnBoundary(DM, const moab::EntityHandle, PetscBool *);
    116: PETSC_EXTERN PetscErrorCode DMMoabCheckBoundaryVertices(DM, PetscInt, const moab::EntityHandle *, PetscBool *);
    117: PETSC_EXTERN PetscErrorCode DMMoabGetBoundaryMarkers(DM, const moab::Range **, const moab::Range **, const moab::Range **);

    119: /* TODO: Replace nverts/coords with just moab::EntityHandle -- can also eliminate dim */
    120: /* TODO: Replace quad/npts with PetscDT */
    121: PETSC_EXTERN PetscErrorCode DMMoabFEMCreateQuadratureDefault(const PetscInt, const PetscInt, PetscQuadrature *);
    122: PETSC_EXTERN PetscErrorCode DMMoabFEMComputeBasis(const PetscInt, const PetscInt, const PetscReal *, const PetscQuadrature, PetscReal *, PetscReal *, PetscReal *, PetscReal **);
    123: PETSC_EXTERN PetscErrorCode DMMoabPToRMapping(const PetscInt, const PetscInt, const PetscReal *, const PetscReal *, PetscReal *, PetscReal *);

    125: /* DM utility creation interface */
    126: PETSC_EXTERN PetscErrorCode DMMoabCreateBoxMesh(MPI_Comm, PetscInt, PetscBool, const PetscReal *, PetscInt, PetscInt, DM *);
    127: PETSC_EXTERN PetscErrorCode DMMoabLoadFromFile(MPI_Comm, PetscInt, PetscInt, const char *, const char *, DM *);

    129: /* Uniform refinement hierarchy interface */
    130: PETSC_EXTERN PetscErrorCode DMMoabGenerateHierarchy(DM, PetscInt, PetscInt *);