Actual source code: petscdmswarm.h
1: #pragma once
3: #include <petscdm.h>
4: #include <petscdt.h>
6: typedef struct _p_DMSwarmDataField *DMSwarmDataField;
7: typedef struct _p_DMSwarmDataBucket *DMSwarmDataBucket;
8: typedef struct _p_DMSwarmSort *DMSwarmSort;
10: /* SUBMANSEC = DMSwarm */
12: /*E
13: DMSwarmType - Defines the type of `DMSWARM`
15: Values:
16: + `DMSWARM_BASIC` - defines N entries of varied data-types which the user may register.
17: - `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.
19: 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
20: the owning rank. The background mesh will (by default) define the spatial decomposition of the points defined in the swarm. `DMSWARM_PIC` provides support
21: for particle-in-cell operations such as defining initial point coordinates, communicating particles between sub-domains, projecting particle data fields on to the mesh.
23: Level: beginner
25: .seealso: [](ch_dmbase), `DMSWARM`, `DMSwarmSetType()`
26: E*/
27: typedef enum {
28: DMSWARM_BASIC = 0,
29: DMSWARM_PIC
30: } DMSwarmType;
32: typedef enum {
33: DMSWARM_MIGRATE_BASIC = 0,
34: DMSWARM_MIGRATE_DMCELLNSCATTER,
35: DMSWARM_MIGRATE_DMCELLEXACT,
36: DMSWARM_MIGRATE_USER
37: } DMSwarmMigrateType;
39: typedef enum {
40: DMSWARM_COLLECT_BASIC = 0,
41: DMSWARM_COLLECT_DMDABOUNDINGBOX,
42: DMSWARM_COLLECT_GENERAL,
43: DMSWARM_COLLECT_USER
44: } DMSwarmCollectType;
46: /*E
47: DMSwarmPICLayoutType - Defines the method used to define particle coordinates within each cell. The layouts are constructured using the reference cell geometry
49: Values:
50: + `DMSWARMPIC_LAYOUT_REGULAR` - defines points on a regular ijk mesh. In this case
51: the `fill_param` argument of `DMSwarmInsertPointsUsingCellDM()` defines the number of points in each spatial direction.
52: . `DMSWARMPIC_LAYOUT_GAUSS` - defines points using an npoint Gauss-Legendre tensor product quadrature rule. In this case
53: the `fill_param` argument of `DMSwarmInsertPointsUsingCellDM()` defines the number of quadrature points in each spatial direction.
54: - `DMSWARMPIC_LAYOUT_SUBDIVISION` - defines points on the centroid of a sub-divided reference cell. In this case
55: the `fill_param` argument of `DMSwarmInsertPointsUsingCellDM()` defines the number times the reference cell is sub-divided.
57: Level: beginner
59: .seealso: [](ch_dmbase), `DMSWARM`, `DM`, `DMSwarmInsertPointsUsingCellDM()`
60: E*/
61: typedef enum {
62: DMSWARMPIC_LAYOUT_REGULAR = 0,
63: DMSWARMPIC_LAYOUT_GAUSS,
64: DMSWARMPIC_LAYOUT_SUBDIVISION
65: } DMSwarmPICLayoutType;
67: /*S
68: DMSwarmCellDM - PETSc object for defining a backgroudn DM for the DMSwarm particles
70: Level: intermediate
72: .seealso: [](ch_dmbase), `DM`, `DMSwarmAddCellDM()`, `DMSwarmCellDMCreate()`
73: S*/
74: typedef struct _p_DMSwarmCellDM *DMSwarmCellDM;
75: PETSC_EXTERN PetscClassId DMSWARMCELLDM_CLASSID;
77: PETSC_EXTERN const char *DMSwarmTypeNames[];
78: PETSC_EXTERN const char *DMSwarmMigrateTypeNames[];
79: PETSC_EXTERN const char *DMSwarmCollectTypeNames[];
81: PETSC_EXTERN const char DMSwarmField_pid[];
82: PETSC_EXTERN const char DMSwarmField_rank[];
83: PETSC_EXTERN const char DMSwarmPICField_coor[];
85: PETSC_EXTERN PetscErrorCode DMSwarmCreateGlobalVectorFromField(DM, const char[], Vec *);
86: PETSC_EXTERN PetscErrorCode DMSwarmDestroyGlobalVectorFromField(DM, const char[], Vec *);
87: PETSC_EXTERN PetscErrorCode DMSwarmCreateLocalVectorFromField(DM, const char[], Vec *);
88: PETSC_EXTERN PetscErrorCode DMSwarmDestroyLocalVectorFromField(DM, const char[], Vec *);
89: PETSC_EXTERN PetscErrorCode DMSwarmCreateGlobalVectorFromFields(DM, PetscInt, const char *[], Vec *);
90: PETSC_EXTERN PetscErrorCode DMSwarmDestroyGlobalVectorFromFields(DM, PetscInt, const char *[], Vec *);
91: PETSC_EXTERN PetscErrorCode DMSwarmCreateLocalVectorFromFields(DM, PetscInt, const char *[], Vec *);
92: PETSC_EXTERN PetscErrorCode DMSwarmDestroyLocalVectorFromFields(DM, PetscInt, const char *[], Vec *);
94: PETSC_EXTERN PetscErrorCode DMSwarmInitializeFieldRegister(DM);
95: PETSC_EXTERN PetscErrorCode DMSwarmFinalizeFieldRegister(DM);
96: PETSC_EXTERN PetscErrorCode DMSwarmSetLocalSizes(DM, PetscInt, PetscInt);
97: PETSC_EXTERN PetscErrorCode DMSwarmRegisterPetscDatatypeField(DM, const char[], PetscInt, PetscDataType);
98: PETSC_EXTERN PetscErrorCode DMSwarmRegisterUserStructField(DM, const char[], size_t);
99: PETSC_EXTERN PetscErrorCode DMSwarmRegisterUserDatatypeField(DM, const char[], size_t, PetscInt);
100: PETSC_EXTERN PetscErrorCode DMSwarmGetField(DM, const char[], PetscInt *, PetscDataType *, void **);
101: PETSC_EXTERN PetscErrorCode DMSwarmRestoreField(DM, const char[], PetscInt *, PetscDataType *, void **);
102: PETSC_EXTERN PetscErrorCode DMSwarmGetFieldInfo(DM, const char[], PetscInt *, PetscDataType *);
104: PETSC_EXTERN PetscErrorCode DMSwarmVectorDefineField(DM, const char[]);
105: PETSC_EXTERN PetscErrorCode DMSwarmVectorDefineFields(DM, PetscInt, const char *[]);
106: PETSC_EXTERN PetscErrorCode DMSwarmVectorGetField(DM, PetscInt *, const char **[]);
108: PETSC_EXTERN PetscErrorCode DMSwarmAddPoint(DM);
109: PETSC_EXTERN PetscErrorCode DMSwarmAddNPoints(DM, PetscInt);
110: PETSC_EXTERN PetscErrorCode DMSwarmRemovePoint(DM);
111: PETSC_EXTERN PetscErrorCode DMSwarmRemovePointAtIndex(DM, PetscInt);
112: PETSC_EXTERN PetscErrorCode DMSwarmCopyPoint(DM dm, PetscInt, PetscInt);
114: PETSC_EXTERN PetscErrorCode DMSwarmGetLocalSize(DM, PetscInt *);
115: PETSC_EXTERN PetscErrorCode DMSwarmGetSize(DM, PetscInt *);
116: PETSC_EXTERN PetscErrorCode DMSwarmGetMigrateType(DM, DMSwarmMigrateType *);
117: PETSC_EXTERN PetscErrorCode DMSwarmSetMigrateType(DM, DMSwarmMigrateType);
118: PETSC_EXTERN PetscErrorCode DMSwarmMigrate(DM, PetscBool);
120: PETSC_EXTERN PetscErrorCode DMSwarmCollectViewCreate(DM);
121: PETSC_EXTERN PetscErrorCode DMSwarmCollectViewDestroy(DM);
122: PETSC_EXTERN PetscErrorCode DMSwarmSetCellDM(DM, DM);
123: PETSC_EXTERN PetscErrorCode DMSwarmGetCellDM(DM, DM *);
124: PETSC_EXTERN PetscErrorCode DMSwarmSetCellDMActive(DM, const char[]);
125: PETSC_EXTERN PetscErrorCode DMSwarmGetCellDMActive(DM, DMSwarmCellDM *);
126: PETSC_EXTERN PetscErrorCode DMSwarmAddCellDM(DM, DMSwarmCellDM);
128: PETSC_EXTERN PetscErrorCode DMSwarmSetType(DM, DMSwarmType);
130: PETSC_EXTERN PetscErrorCode DMSwarmSetPointsUniformCoordinates(DM, PetscReal *, PetscReal *, PetscInt *, InsertMode);
131: PETSC_EXTERN PetscErrorCode DMSwarmSetPointCoordinates(DM, PetscInt, PetscReal *, PetscBool, InsertMode);
132: PETSC_EXTERN PetscErrorCode DMSwarmInsertPointsUsingCellDM(DM, DMSwarmPICLayoutType, PetscInt);
133: PETSC_EXTERN PetscErrorCode DMSwarmSetPointCoordinatesCellwise(DM, PetscInt, PetscReal *);
134: PETSC_EXTERN PetscErrorCode DMSwarmSetPointCoordinatesRandom(DM, PetscInt);
135: PETSC_EXTERN PetscErrorCode DMSwarmViewFieldsXDMF(DM, const char *, PetscInt, const char **);
136: PETSC_EXTERN PetscErrorCode DMSwarmViewXDMF(DM, const char *);
138: PETSC_EXTERN PetscErrorCode DMSwarmSortDestroy(DMSwarmSort *);
139: PETSC_EXTERN PetscErrorCode DMSwarmSortGetAccess(DM);
140: PETSC_EXTERN PetscErrorCode DMSwarmSortRestoreAccess(DM);
141: PETSC_EXTERN PetscErrorCode DMSwarmSortGetPointsPerCell(DM, PetscInt, PetscInt *, PetscInt **);
142: PETSC_EXTERN PetscErrorCode DMSwarmSortRestorePointsPerCell(DM, PetscInt, PetscInt *, PetscInt **);
143: PETSC_EXTERN PetscErrorCode DMSwarmSortGetNumberOfPointsPerCell(DM, PetscInt, PetscInt *);
144: PETSC_EXTERN PetscErrorCode DMSwarmSortGetIsValid(DM, PetscBool *);
145: PETSC_EXTERN PetscErrorCode DMSwarmSortGetSizes(DM, PetscInt *, PetscInt *);
147: PETSC_EXTERN PetscErrorCode DMSwarmCreateMassMatrixSquare(DM, DM, Mat *);
149: PETSC_EXTERN PetscErrorCode DMSwarmGetCellSwarm(DM, PetscInt, DM);
150: PETSC_EXTERN PetscErrorCode DMSwarmRestoreCellSwarm(DM, PetscInt, DM);
151: PETSC_EXTERN PetscErrorCode DMSwarmGetNumSpecies(DM, PetscInt *);
152: PETSC_EXTERN PetscErrorCode DMSwarmSetNumSpecies(DM, PetscInt);
153: PETSC_EXTERN PetscErrorCode DMSwarmGetCoordinateFunction(DM, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar[], void *));
154: PETSC_EXTERN PetscErrorCode DMSwarmSetCoordinateFunction(DM, PetscErrorCode (*)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar[], void *));
155: PETSC_EXTERN PetscErrorCode DMSwarmGetVelocityFunction(DM, PetscErrorCode (**)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar[], void *));
156: PETSC_EXTERN PetscErrorCode DMSwarmSetVelocityFunction(DM, PetscErrorCode (*)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar[], void *));
157: PETSC_EXTERN PetscErrorCode DMSwarmComputeLocalSize(DM, PetscInt, PetscProbFunc);
158: PETSC_EXTERN PetscErrorCode DMSwarmComputeLocalSizeFromOptions(DM);
159: PETSC_EXTERN PetscErrorCode DMSwarmInitializeCoordinates(DM);
160: PETSC_EXTERN PetscErrorCode DMSwarmInitializeVelocities(DM, PetscProbFunc, const PetscReal[]);
161: PETSC_EXTERN PetscErrorCode DMSwarmInitializeVelocitiesFromOptions(DM, const PetscReal[]);
163: PETSC_EXTERN PetscErrorCode DMSwarmCreatePointPerCellCount(DM, PetscInt *, PetscInt **);
165: // Interface to internal storage
166: PETSC_EXTERN PetscErrorCode DMSwarmDataFieldGetEntries(const DMSwarmDataField, void **);
167: PETSC_EXTERN PetscErrorCode DMSwarmDataFieldRestoreEntries(const DMSwarmDataField, void **);
168: PETSC_EXTERN PetscErrorCode DMSwarmDataBucketGetDMSwarmDataFieldByName(DMSwarmDataBucket, const char[], DMSwarmDataField *);
169: PETSC_EXTERN PetscErrorCode DMSwarmDataBucketGetDMSwarmDataFieldIdByName(DMSwarmDataBucket, const char[], PetscInt *);
170: PETSC_EXTERN PetscErrorCode DMSwarmDataBucketQueryDMSwarmDataFieldByName(DMSwarmDataBucket, const char[], PetscBool *);
172: PETSC_EXTERN PetscErrorCode DMSwarmReplace(DM, DM *);
174: PETSC_EXTERN PetscErrorCode DMSwarmComputeMoments(DM, const char[], const char[], PetscReal[]);
176: PETSC_EXTERN PetscErrorCode DMSwarmCellDMCreate(DM, PetscInt, const char *[], PetscInt, const char *[], DMSwarmCellDM *);
177: PETSC_EXTERN PetscErrorCode DMSwarmCellDMDestroy(DMSwarmCellDM *);
178: PETSC_EXTERN PetscErrorCode DMSwarmCellDMView(DMSwarmCellDM, PetscViewer);
179: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetDM(DMSwarmCellDM, DM *);
180: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetFields(DMSwarmCellDM, PetscInt *, const char **[]);
181: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetCoordinateFields(DMSwarmCellDM, PetscInt *, const char **[]);
182: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetCellID(DMSwarmCellDM, const char *[]);
183: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetSort(DMSwarmCellDM, DMSwarmSort *);
184: PETSC_EXTERN PetscErrorCode DMSwarmCellDMSetSort(DMSwarmCellDM, DMSwarmSort);
185: PETSC_EXTERN PetscErrorCode DMSwarmCellDMGetBlockSize(DMSwarmCellDM, DM, PetscInt *);