Actual source code: characteristicimpl.h
1: #pragma once
3: #include <petsccharacteristic.h>
4: #include <petsc/private/petscimpl.h>
6: /* Logging support */
7: PETSC_EXTERN PetscClassId CHARACTERISTIC_CLASSID;
8: PETSC_EXTERN PetscBool CharacteristicRegisterAllCalled;
9: PETSC_EXTERN PetscErrorCode CharacteristicRegisterAll(void);
10: PETSC_EXTERN PetscLogEvent CHARACTERISTIC_SetUp;
11: PETSC_EXTERN PetscLogEvent CHARACTERISTIC_Solve;
12: PETSC_EXTERN PetscLogEvent CHARACTERISTIC_QueueSetup;
13: PETSC_EXTERN PetscLogEvent CHARACTERISTIC_DAUpdate;
14: PETSC_EXTERN PetscLogEvent CHARACTERISTIC_HalfTimeLocal;
15: PETSC_EXTERN PetscLogEvent CHARACTERISTIC_HalfTimeRemote;
16: PETSC_EXTERN PetscLogEvent CHARACTERISTIC_HalfTimeExchange;
17: PETSC_EXTERN PetscLogEvent CHARACTERISTIC_FullTimeLocal;
18: PETSC_EXTERN PetscLogEvent CHARACTERISTIC_FullTimeRemote;
19: PETSC_EXTERN PetscLogEvent CHARACTERISTIC_FullTimeExchange;
21: #define MAX_COMPONENTS 10
23: typedef struct _p_Item {
24: PetscMPIInt proc; /* Relative processor from which data is required (mapped to absolute by neighbors) */
25: PetscInt i, j; /* The vertex for which we need field values */
26: PetscScalar x, y; /* Coordinates of a point on the characteristic */
27: PetscScalar u, v; /* Velocity of a point on the characteristic */
28: PetscScalar field[MAX_COMPONENTS]; /* Field being advected */
29: } CharacteristicPointDA2D;
31: typedef CharacteristicPointDA2D *Queue;
33: struct _CharacteristicOps {
34: PetscErrorCode (*view)(Characteristic, PetscViewer);
35: PetscErrorCode (*destroy)(Characteristic);
36: PetscErrorCode (*setup)(Characteristic);
37: };
39: struct _p_Characteristic {
40: PETSCHEADER(struct _CharacteristicOps);
41: PetscInt setupcalled;
42: PetscBool structured; /* Flag for mesh type */
43: int numIds; /* Number of integers necessary to identify a mesh element (from problem dimension) */
44: /* Velocity interpolation structures */
45: DM velocityDA; /* DM for the velocity field */
46: Vec velocity; /* Velocity field at t_n */
47: Vec velocityOld; /* Velocity field at t_n-1 */
48: PetscInt numVelocityComp; /* Number of velocity components (should be the mesh dimension) */
49: PetscInt *velocityComp; /* Components of the velocity in the DM */
50: PetscErrorCode (*velocityInterp)(Vec, PetscReal[], PetscInt, PetscInt[], PetscScalar[], void *);
51: PetscErrorCode (*velocityInterpLocal)(void *, PetscReal[], PetscInt, PetscInt[], PetscScalar[], void *);
52: void *velocityCtx; /* User context for velocity inteprolation */
53: /* Field interpolation structures */
54: DM fieldDA; /* DM for the field field */
55: Vec field; /* Field field at t_n */
56: Vec fieldOld; /* Field field at t_n-1 */
57: PetscInt numFieldComp; /* Number of field components (should be the mesh dimension) */
58: PetscInt *fieldComp; /* Components of the field in the DM */
59: PetscErrorCode (*fieldInterp)(Vec, PetscReal[], PetscInt, PetscInt[], PetscScalar[], void *);
60: PetscErrorCode (*fieldInterpLocal)(void *, PetscReal[], PetscInt, PetscInt[], PetscScalar[], void *);
61: void *fieldCtx; /* User context for field inteprolation */
62: /* Communication structures*/
63: MPI_Datatype itemType; /* Type corresponding to the item struct */
64: Queue queue;
65: PetscInt queueSize;
66: PetscInt queueMax;
67: Queue queueLocal; /* Queue of Items to receive from other processes */
68: PetscInt queueLocalSize;
69: PetscInt queueLocalMax;
70: Queue queueRemote; /* Queue of Items to send to other processes */
71: PetscInt queueRemoteSize;
72: PetscInt queueRemoteMax;
73: PetscMPIInt numNeighbors; /* Number of neighboring processes */
74: PetscMPIInt *neighbors; /* Ranks of neighbors */
75: PetscInt *needCount; /* Number of Items requested from other processes */
76: PetscInt *localOffsets; /* Offset into queue for each process (Prefix sums of need_count) */
77: PetscInt *fillCount; /* Number of Items requested by other processes */
78: PetscInt *remoteOffsets; /* Offset into remote queue for each process (Prefix sums of fill_count) */
79: MPI_Request *request; /* Requests for sizes/velocities/fields from other processes */
80: MPI_Status *status; /* Status structures for the persistent requests */
81: void *data; /* Holder for implementation class */
82: };
84: PETSC_EXTERN PetscErrorCode CharacteristicSetNeighbors(Characteristic, PetscInt, PetscMPIInt[]);
85: PETSC_EXTERN PetscErrorCode CharacteristicAddPoint(Characteristic, CharacteristicPointDA2D *);
86: PETSC_EXTERN PetscErrorCode CharacteristicSendCoordinatesBegin(Characteristic);
87: PETSC_EXTERN PetscErrorCode CharacteristicSendCoordinatesEnd(Characteristic);
88: PETSC_EXTERN PetscErrorCode CharacteristicGetValuesBegin(Characteristic);
89: PETSC_EXTERN PetscErrorCode CharacteristicGetValuesEnd(Characteristic);