Actual source code: petscdmswarm.h

      1: #pragma once

      3: #include <petscdm.h>
      4: #include <petscdt.h>

      6: /* MANSEC = DM */
      7: /* SUBMANSEC = DMSwarm */

      9: typedef struct _p_DMSwarmDataField  *DMSwarmDataField;
     10: typedef struct _p_DMSwarmDataBucket *DMSwarmDataBucket;
     11: typedef struct _p_DMSwarmSort       *DMSwarmSort;

     13: /*E
     14:    DMSwarmType - Defines the type of `DMSWARM`

     16:    Values:
     17: +  `DMSWARM_BASIC` - defines N entries of varied data-types which the user may register.
     18: -  `DMSWARM_PIC`   - suitable for particle-in-cell methods. Configured as `DMSWARM_PIC`, the swarm will be aware of, another `DM` which serves as the background mesh.

     20:    Fields specific to particle-in-cell methods are registered by default. These include spatial coordinates, a unique identifier, a cell index and an index for
     21:    the owning rank. The background mesh will (by default) define the spatial decomposition of the points defined in the swarm. `DMSWARM_PIC` provides support
     22:    for particle-in-cell operations such as defining initial point coordinates, communicating particles between sub-domains, projecting particle data fields on to the mesh.

     24:    Level: beginner

     26: .seealso: [](ch_dmbase), `DMSWARM`, `DMSwarmSetType()`
     27: E*/
     28: typedef enum {
     29:   DMSWARM_BASIC,
     30:   DMSWARM_PIC
     31: } DMSwarmType;
     32: PETSC_EXTERN const char *DMSwarmTypeNames[];

     34: typedef enum {
     35:   DMSWARM_MIGRATE_BASIC,
     36:   DMSWARM_MIGRATE_DMCELLNSCATTER,
     37:   DMSWARM_MIGRATE_DMCELLEXACT,
     38:   DMSWARM_MIGRATE_USER
     39: } DMSwarmMigrateType;
     40: PETSC_EXTERN const char *DMSwarmMigrateTypeNames[];

     42: typedef enum {
     43:   DMSWARM_COLLECT_BASIC,
     44:   DMSWARM_COLLECT_DMDABOUNDINGBOX,
     45:   DMSWARM_COLLECT_GENERAL,
     46:   DMSWARM_COLLECT_USER
     47: } DMSwarmCollectType;
     48: PETSC_EXTERN const char *DMSwarmCollectTypeNames[];

     50: typedef enum {
     51:   DMSWARM_REMAP_NONE    = 0,
     52:   DMSWARM_REMAP_PFAK    = 1,
     53:   DMSWARM_REMAP_COLELLA = 2
     54: } DMSwarmRemapType;
     55: PETSC_EXTERN const char *DMSwarmRemapTypeNames[];

     57: /*E
     58:    DMSwarmPICLayoutType - Defines the method used to define particle coordinates within each cell. The layouts are constructured using the reference cell geometry

     60:    Values:
     61: +  `DMSWARMPIC_LAYOUT_REGULAR`     - defines points on a regular ijk mesh. In this case
     62:                                      the `fill_param` argument of `DMSwarmInsertPointsUsingCellDM()` defines the number of points in each spatial direction.
     63: .  `DMSWARMPIC_LAYOUT_GAUSS`       - defines points using an npoint Gauss-Legendre tensor product quadrature rule. In this case
     64:                                      the `fill_param` argument of `DMSwarmInsertPointsUsingCellDM()` defines the number of quadrature points in each spatial direction.
     65: -  `DMSWARMPIC_LAYOUT_SUBDIVISION` - defines points on the centroid of a sub-divided reference cell. In this case
     66:                                      the `fill_param` argument of `DMSwarmInsertPointsUsingCellDM()` defines the number times the reference cell is sub-divided.

     68:    Level: beginner

     70: .seealso: [](ch_dmbase), `DMSWARM`, `DM`, `DMSwarmInsertPointsUsingCellDM()`
     71: E*/
     72: typedef enum {
     73:   DMSWARMPIC_LAYOUT_REGULAR,
     74:   DMSWARMPIC_LAYOUT_GAUSS,
     75:   DMSWARMPIC_LAYOUT_SUBDIVISION
     76: } DMSwarmPICLayoutType;

     78: /*S
     79:     DMSwarmCellDM - PETSc object for defining a background `DM` for the `DMSWARM` particles

     81:     Level: intermediate

     83: .seealso: [](ch_dmbase), `DM`, `DMSwarmAddCellDM()`, `DMSwarmCellDMCreate()`
     84: S*/
     85: typedef struct _p_DMSwarmCellDM *DMSwarmCellDM;
     86: PETSC_EXTERN PetscClassId        DMSWARMCELLDM_CLASSID;

     88: PETSC_EXTERN const char DMSwarmField_pid[];
     89: PETSC_EXTERN const char DMSwarmField_rank[];
     90: PETSC_EXTERN const char DMSwarmPICField_coor[];

     92: PETSC_EXTERN PetscErrorCode DMSwarmCreateGlobalVectorFromField(DM, const char[], Vec *);
     93: PETSC_EXTERN PetscErrorCode DMSwarmDestroyGlobalVectorFromField(DM, const char[], Vec *);
     94: PETSC_EXTERN PetscErrorCode DMSwarmCreateLocalVectorFromField(DM, const char[], Vec *);
     95: PETSC_EXTERN PetscErrorCode DMSwarmDestroyLocalVectorFromField(DM, const char[], Vec *);
     96: PETSC_EXTERN PetscErrorCode DMSwarmCreateGlobalVectorFromFields(DM, PetscInt, const char *[], Vec *);
     97: PETSC_EXTERN PetscErrorCode DMSwarmDestroyGlobalVectorFromFields(DM, PetscInt, const char *[], Vec *);
     98: PETSC_EXTERN PetscErrorCode DMSwarmCreateLocalVectorFromFields(DM, PetscInt, const char *[], Vec *);
     99: PETSC_EXTERN PetscErrorCode DMSwarmDestroyLocalVectorFromFields(DM, PetscInt, const char *[], Vec *);

    101: PETSC_EXTERN PetscErrorCode DMSwarmInitializeFieldRegister(DM);
    102: PETSC_EXTERN PetscErrorCode DMSwarmFinalizeFieldRegister(DM);
    103: PETSC_EXTERN PetscErrorCode DMSwarmSetLocalSizes(DM, PetscInt, PetscInt);
    104: PETSC_EXTERN PetscErrorCode DMSwarmRegisterPetscDatatypeField(DM, const char[], PetscInt, PetscDataType);
    105: PETSC_EXTERN PetscErrorCode DMSwarmRegisterUserStructField(DM, const char[], size_t);
    106: PETSC_EXTERN PetscErrorCode DMSwarmRegisterUserDatatypeField(DM, const char[], size_t, PetscInt);
    107: PETSC_EXTERN PetscErrorCode DMSwarmGetField(DM, const char[], PetscInt *, PetscDataType *, void **);
    108: PETSC_EXTERN PetscErrorCode DMSwarmRestoreField(DM, const char[], PetscInt *, PetscDataType *, void **);
    109: PETSC_EXTERN PetscErrorCode DMSwarmGetFieldInfo(DM, const char[], PetscInt *, PetscDataType *);

    111: PETSC_EXTERN PetscErrorCode DMSwarmVectorDefineField(DM, const char[]);
    112: PETSC_EXTERN PetscErrorCode DMSwarmVectorDefineFields(DM, PetscInt, const char *[]);
    113: PETSC_EXTERN PetscErrorCode DMSwarmVectorGetField(DM, PetscInt *, const char **[]);

    115: PETSC_EXTERN PetscErrorCode DMSwarmAddPoint(DM);
    116: PETSC_EXTERN PetscErrorCode DMSwarmAddNPoints(DM, PetscInt);
    117: PETSC_EXTERN PetscErrorCode DMSwarmRemovePoint(DM);
    118: PETSC_EXTERN PetscErrorCode DMSwarmRemovePointAtIndex(DM, PetscInt);
    119: PETSC_EXTERN PetscErrorCode DMSwarmCopyPoint(DM, PetscInt, PetscInt);

    121: PETSC_EXTERN PetscErrorCode DMSwarmGetLocalSize(DM, PetscInt *);
    122: PETSC_EXTERN PetscErrorCode DMSwarmGetSize(DM, PetscInt *);
    123: PETSC_EXTERN PetscErrorCode DMSwarmGetMigrateType(DM, DMSwarmMigrateType *);
    124: PETSC_EXTERN PetscErrorCode DMSwarmSetMigrateType(DM, DMSwarmMigrateType);
    125: PETSC_EXTERN PetscErrorCode DMSwarmMigrate(DM, PetscBool);

    127: PETSC_EXTERN PetscErrorCode DMSwarmCollectViewCreate(DM);
    128: PETSC_EXTERN PetscErrorCode DMSwarmCollectViewDestroy(DM);
    129: PETSC_EXTERN PetscErrorCode DMSwarmSetCellDM(DM, DM);
    130: PETSC_EXTERN PetscErrorCode DMSwarmGetCellDM(DM, DM *);
    131: PETSC_EXTERN PetscErrorCode DMSwarmGetCellDMByName(DM, const char[], DMSwarmCellDM *);
    132: PETSC_EXTERN PetscErrorCode DMSwarmGetCellDMNames(DM, PetscInt *, const char **[]);
    133: PETSC_EXTERN PetscErrorCode DMSwarmSetCellDMActive(DM, const char[]);
    134: PETSC_EXTERN PetscErrorCode DMSwarmGetCellDMActive(DM, DMSwarmCellDM *);
    135: PETSC_EXTERN PetscErrorCode DMSwarmAddCellDM(DM, DMSwarmCellDM);

    137: PETSC_EXTERN PetscErrorCode DMSwarmGetType(DM, DMSwarmType *);
    138: PETSC_EXTERN PetscErrorCode DMSwarmSetType(DM, DMSwarmType);

    140: PETSC_EXTERN PetscErrorCode DMSwarmSetPointsUniformCoordinates(DM, PetscReal *, PetscReal *, PetscInt *, InsertMode);
    141: PETSC_EXTERN PetscErrorCode DMSwarmSetPointCoordinates(DM, PetscInt, PetscReal *, PetscBool, InsertMode);
    142: PETSC_EXTERN PetscErrorCode DMSwarmInsertPointsUsingCellDM(DM, DMSwarmPICLayoutType, PetscInt);
    143: PETSC_EXTERN PetscErrorCode DMSwarmSetPointCoordinatesCellwise(DM, PetscInt, PetscReal *);
    144: PETSC_EXTERN PetscErrorCode DMSwarmSetPointCoordinatesRandom(DM, PetscInt);
    145: PETSC_EXTERN PetscErrorCode DMSwarmViewFieldsXDMF(DM, const char *, PetscInt, const char **);
    146: PETSC_EXTERN PetscErrorCode DMSwarmViewXDMF(DM, const char *);

    148: PETSC_EXTERN PetscErrorCode DMSwarmSortDestroy(DMSwarmSort *);
    149: PETSC_EXTERN PetscErrorCode DMSwarmSortGetAccess(DM);
    150: PETSC_EXTERN PetscErrorCode DMSwarmSortRestoreAccess(DM);
    151: PETSC_EXTERN PetscErrorCode DMSwarmSortGetPointsPerCell(DM, PetscInt, PetscInt *, PetscInt **);
    152: PETSC_EXTERN PetscErrorCode DMSwarmSortRestorePointsPerCell(DM, PetscInt, PetscInt *, PetscInt **);
    153: PETSC_EXTERN PetscErrorCode DMSwarmSortGetNumberOfPointsPerCell(DM, PetscInt, PetscInt *);
    154: PETSC_EXTERN PetscErrorCode DMSwarmSortGetIsValid(DM, PetscBool *);
    155: PETSC_EXTERN PetscErrorCode DMSwarmSortGetSizes(DM, PetscInt *, PetscInt *);

    157: PETSC_EXTERN PetscErrorCode DMSwarmCreateMassMatrixSquare(DM, DM, Mat *);

    159: PETSC_EXTERN PetscErrorCode DMSwarmGetCellSwarm(DM, PetscInt, DM);
    160: PETSC_EXTERN PetscErrorCode DMSwarmRestoreCellSwarm(DM, PetscInt, DM);
    161: PETSC_EXTERN PetscErrorCode DMSwarmGetNumSpecies(DM, PetscInt *);
    162: PETSC_EXTERN PetscErrorCode DMSwarmSetNumSpecies(DM, PetscInt);
    163: PETSC_EXTERN PetscErrorCode DMSwarmGetCoordinateFunction(DM, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar[], void *));
    164: PETSC_EXTERN PetscErrorCode DMSwarmSetCoordinateFunction(DM, PetscErrorCode (*)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar[], void *));
    165: PETSC_EXTERN PetscErrorCode DMSwarmGetVelocityFunction(DM, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar[], void *));
    166: PETSC_EXTERN PetscErrorCode DMSwarmSetVelocityFunction(DM, PetscErrorCode (*)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar[], void *));
    167: PETSC_EXTERN PetscErrorCode DMSwarmComputeLocalSize(DM, PetscInt, PetscProbFn *);
    168: PETSC_EXTERN PetscErrorCode DMSwarmComputeLocalSizeFromOptions(DM);
    169: PETSC_EXTERN PetscErrorCode DMSwarmInitializeCoordinates(DM);
    170: PETSC_EXTERN PetscErrorCode DMSwarmInitializeVelocities(DM, PetscProbFn *, const PetscReal[]);
    171: PETSC_EXTERN PetscErrorCode DMSwarmInitializeVelocitiesFromOptions(DM, const PetscReal[]);

    173: PETSC_EXTERN PetscErrorCode DMSwarmCreatePointPerCellCount(DM, PetscInt *, PetscInt **);

    175: // Interface to internal storage
    176: PETSC_EXTERN PetscErrorCode DMSwarmDataFieldGetEntries(const DMSwarmDataField, void **);
    177: PETSC_EXTERN PetscErrorCode DMSwarmDataFieldRestoreEntries(const DMSwarmDataField, void **);
    178: PETSC_EXTERN PetscErrorCode DMSwarmDataBucketGetDMSwarmDataFieldByName(DMSwarmDataBucket, const char[], DMSwarmDataField *);
    179: PETSC_EXTERN PetscErrorCode DMSwarmDataBucketGetDMSwarmDataFieldIdByName(DMSwarmDataBucket, const char[], PetscInt *);
    180: PETSC_EXTERN PetscErrorCode DMSwarmDataBucketQueryDMSwarmDataFieldByName(DMSwarmDataBucket, const char[], PetscBool *);

    182: PETSC_EXTERN PetscErrorCode DMSwarmDuplicate(DM, DM *);
    183: PETSC_EXTERN PetscErrorCode DMSwarmRemap(DM);
    184: PETSC_EXTERN PetscErrorCode DMSwarmReplace(DM, DM *);

    186: PETSC_EXTERN PetscErrorCode DMSwarmComputeMoments(DM, const char[], const char[], PetscReal[]);

    188: PETSC_EXTERN PetscErrorCode DMSwarmCellDMCreate(DM, PetscInt, const char *[], PetscInt, const char *[], DMSwarmCellDM *);
    189: PETSC_EXTERN PetscErrorCode DMSwarmCellDMDestroy(DMSwarmCellDM *);
    190: PETSC_EXTERN PetscErrorCode DMSwarmCellDMView(DMSwarmCellDM, PetscViewer);
    191: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetDM(DMSwarmCellDM, DM *);
    192: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetFields(DMSwarmCellDM, PetscInt *, const char **[]);
    193: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetCoordinateFields(DMSwarmCellDM, PetscInt *, const char **[]);
    194: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetCellID(DMSwarmCellDM, const char *[]);
    195: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetSort(DMSwarmCellDM, DMSwarmSort *);
    196: PETSC_EXTERN PetscErrorCode DMSwarmCellDMSetSort(DMSwarmCellDM, DMSwarmSort);
    197: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetBlockSize(DMSwarmCellDM, DM, PetscInt *);