Actual source code: pcpatchimpl.h
1: /*
2: Data structure used for Patch preconditioner.
3: */
4: #ifndef PETSC_PCPATCHIMPL_H
5: #define PETSC_PCPATCHIMPL_H
6: #include <petsc/private/pcimpl.h>
7: #include <petsc/private/hashseti.h>
8: #include <petsc/private/hashmapi.h>
9: #include <petscksp.h>
11: typedef struct {
12: /* Topology */
13: PCPatchConstructType ctype; /* Algorithm for patch construction */
14: PetscErrorCode (*patchconstructop)(void *, DM, PetscInt, PetscHSetI); /* patch construction */
15: PetscErrorCode (*userpatchconstructionop)(PC, PetscInt *, IS **, IS *, void *ctx);
16: void *userpatchconstructctx;
17: IS *userIS;
18: PetscInt npatch; /* Number of patches */
19: PetscBool user_patches; /* Flag for user construction of patches */
20: PetscInt dim, codim; /* Dimension or codimension of mesh points to loop over; only one of them can be set */
21: PetscSection cellCounts; /* Maps patch -> # cells in patch */
22: IS cells; /* [patch][cell in patch]: Cell number */
23: IS extFacets;
24: IS intFacets;
25: IS intFacetsToPatchCell; /* Support of interior facet in local patch point numbering: AKA which two cells touch the facet (in patch local numbering of cells) */
26: PetscSection intFacetCounts;
27: PetscSection extFacetCounts;
28: PetscSection cellNumbering; /* Plex: NULL Firedrake: Numbering of cells in DM */
29: PetscSection pointCounts; /* Maps patch -> # points with dofs in patch */
30: IS points; /* [patch][point in patch]: Point number */
31: /* Dof layout */
32: PetscBool combined; /* Use a combined space with all fields */
33: PetscInt nsubspaces; /* Number of fields */
34: PetscSF sectionSF; /* Combined SF mapping process local to global */
35: PetscSection *dofSection; /* ?? For each field, patch -> # dofs in patch */
36: PetscInt *subspaceOffsets; /* Plex: NULL Firedrake: offset of each field in concatenated process local numbering for mixed spaces */
37: PetscInt **cellNodeMap; /* [field][cell][dof in cell]: global dofs in cell TODO Free this after its use in PCPatchCreateCellPatchDiscretisationInfo() */
38: IS dofs; /* [patch][cell in patch][dof in cell]: patch local dof */
39: IS offs; /* [patch][point in patch]: patch local offset (same layout as 'points', used for filling up patchSection) */
40: IS dofsWithArtificial;
41: IS offsWithArtificial;
42: IS dofsWithAll;
43: IS offsWithAll;
44: PetscSection patchSection; /* Maps points -> patch local dofs */
45: IS globalBcNodes; /* Global dofs constrained by global Dirichlet conditions TODO Replace these with process local constrained dofs */
46: IS ghostBcNodes; /* Global dofs constrained by global Dirichlet conditions on this process and possibly others (patch overlaps boundary) */
47: PetscSection gtolCounts; /* ?? Indices to extract from local to patch vectors */
48: PetscSection gtolCountsWithArtificial; /* ?? Indices to extract from local to patch vectors including those with artificial bcs*/
49: PetscSection gtolCountsWithAll; /* ?? Indices to extract from local to patch vectors including those in artificial or global bcs*/
50: IS gtol;
51: IS gtolWithArtificial;
52: IS gtolWithAll;
53: PetscInt *bs; /* [field] block size per field (can come from global operators?) */
54: PetscInt *nodesPerCell; /* [field] Dofs per cell TODO Change "node" to "dof" everywhere */
55: PetscInt totalDofsPerCell; /* Dofs per cell counting all fields */
56: PetscHSetI subspaces_to_exclude; /* If you don't want any other dofs from a particular subspace you can exclude them with this.
57: Used for Vanka in Stokes, for example, to eliminate all pressure dofs not on the vertex
58: you're building the patch around */
59: PetscInt vankadim; /* In Vanka construction, should we eliminate any entities of a certain dimension on the initial patch? */
60: PetscInt ignoredim; /* In Vanka construction, should we eliminate any entities of a certain dimension on the boundary? */
61: PetscInt pardecomp_overlap; /* In parallel decomposition construction, how much overlap? */
62: /* Patch system assembly */
63: PetscErrorCode (*usercomputeop)(PC, PetscInt, Vec, Mat, IS, PetscInt, const PetscInt *, const PetscInt *, void *);
64: void *usercomputeopctx;
65: PetscErrorCode (*usercomputef)(PC, PetscInt, Vec, Vec, IS, PetscInt, const PetscInt *, const PetscInt *, void *);
66: void *usercomputefctx;
67: /* Interior facet integrals: Jacobian */
68: PetscErrorCode (*usercomputeopintfacet)(PC, PetscInt, Vec, Mat, IS, PetscInt, const PetscInt *, const PetscInt *, void *);
69: void *usercomputeopintfacetctx;
70: /* Residual */
71: PetscErrorCode (*usercomputefintfacet)(PC, PetscInt, Vec, Vec, IS, PetscInt, const PetscInt *, const PetscInt *, void *);
72: void *usercomputefintfacetctx;
73: IS cellIS; /* Temporary IS for each cell patch */
74: PetscBool save_operators; /* Save all operators (or create/destroy one at a time?) */
75: PetscBool precomputeElementTensors; /* Precompute all element tensors (each cell is assembled exactly once)? */
76: IS allCells; /* Unique cells in union of all patches */
77: IS allIntFacets; /* Unique interior facets in union of all patches */
78: PetscBool partition_of_unity; /* Weight updates by dof multiplicity? */
79: PetscBool multiplicative; /* Gauss-Seidel instead of Jacobi? */
80: PCCompositeType local_composition_type; /* locally additive or multiplicative? */
81: /* Patch solves */
82: Vec cellMats; /* Cell element tensors */
83: PetscInt *precomputedTensorLocations; /* Locations of the precomputed tensors for each cell. */
84: Vec intFacetMats; /* interior facet element tensors */
85: PetscInt *precomputedIntFacetTensorLocations; /* Locations of the precomputed tensors for each interior facet. */
86: Mat *mat; /* System matrix for each patch */
87: Mat *matWithArtificial; /* System matrix including dofs with artificial bcs for each patch */
88: MatType sub_mat_type; /* Matrix type for patch systems */
89: Vec patchRHS, patchUpdate; /* Work vectors for RHS and solution on each patch */
90: IS *dofMappingWithoutToWithArtificial;
91: IS *dofMappingWithoutToWithAll;
92: Vec patchRHSWithArtificial; /* like patchRHS but extra entries to include dofs with artificial bcs*/
93: Vec *patch_dof_weights; /* Weighting for dof in each patch */
94: Vec localRHS, localUpdate; /* ??? */
95: Vec dof_weights; /* In how many patches does each dof lie? */
96: PetscBool symmetrise_sweep; /* Should we sweep forwards->backwards, backwards->forwards? */
97: PetscBool optionsSet; /* SetFromOptions was called on this PC */
98: IS iterationSet; /* Index set specifying how we iterate over patches */
99: PetscInt currentPatch; /* The current patch number when iterating */
100: PetscObject *solver; /* Solvers for each patch TODO Do we need a new KSP for each patch? */
101: PetscBool denseinverse; /* Should the patch inverse by applied by computing the inverse and a matmult? (Skips KSP/PC etc...) */
102: PetscErrorCode (*densesolve)(Mat, Vec, Vec); /* Matmult for dense solve (used with denseinverse) */
103: PetscErrorCode (*setupsolver)(PC);
104: PetscErrorCode (*applysolver)(PC, PetscInt, Vec, Vec);
105: PetscErrorCode (*resetsolver)(PC);
106: PetscErrorCode (*destroysolver)(PC);
107: PetscErrorCode (*updatemultiplicative)(PC, PetscInt, PetscInt);
108: /* Monitoring */
109: PetscBool viewPatches; /* View information about patch construction */
110: PetscBool viewCells; /* View cells for each patch */
111: PetscViewer viewerCells; /* Viewer for patch cells */
112: PetscViewerFormat formatCells; /* Format for patch cells */
113: PetscBool viewIntFacets; /* View intFacets for each patch */
114: PetscViewer viewerIntFacets; /* Viewer for patch intFacets */
115: PetscViewerFormat formatIntFacets; /* Format for patch intFacets */
116: PetscBool viewExtFacets; /* View extFacets for each patch */
117: PetscViewer viewerExtFacets; /* Viewer for patch extFacets */
118: PetscViewerFormat formatExtFacets; /* Format for patch extFacets */
119: PetscBool viewPoints; /* View points for each patch */
120: PetscViewer viewerPoints; /* Viewer for patch points */
121: PetscViewerFormat formatPoints; /* Format for patch points */
122: PetscBool viewSection; /* View global section for each patch */
123: PetscViewer viewerSection; /* Viewer for patch sections */
124: PetscViewerFormat formatSection; /* Format for patch sections */
125: PetscBool viewMatrix; /* View matrix for each patch */
126: PetscViewer viewerMatrix; /* Viewer for patch matrix */
127: PetscViewerFormat formatMatrix; /* Format for patch matrix */
128: /* Extra variables for SNESPATCH */
129: Vec patchState; /* State vectors for patch solvers */
130: Vec patchStateWithAll; /* State vectors for patch solvers with all boundary data */
131: Vec localState; /* Scatter vector for state */
132: Vec patchResidual; /* Work vectors for patch residual evaluation*/
133: const char *classname; /* "snes" or "pc" for options */
134: PetscBool isNonlinear; /* we need to do some things differently in nonlinear mode */
135: } PC_PATCH;
137: PETSC_EXTERN PetscLogEvent PC_Patch_CreatePatches;
138: PETSC_EXTERN PetscLogEvent PC_Patch_ComputeOp;
139: PETSC_EXTERN PetscLogEvent PC_Patch_Solve;
140: PETSC_EXTERN PetscLogEvent PC_Patch_Apply;
141: PETSC_EXTERN PetscLogEvent PC_Patch_Prealloc;
143: PETSC_EXTERN PetscErrorCode PCPatchComputeFunction_Internal(PC, Vec, Vec, PetscInt);
144: PETSC_EXTERN PetscErrorCode PCPatchComputeOperator_Internal(PC, Vec, Mat, PetscInt, PetscBool);
145: typedef enum {
146: SCATTER_INTERIOR,
147: SCATTER_WITHARTIFICIAL,
148: SCATTER_WITHALL
149: } PatchScatterType;
150: PETSC_EXTERN PetscErrorCode PCPatch_ScatterLocal_Private(PC, PetscInt, Vec, Vec, InsertMode, ScatterMode, PatchScatterType);
152: #endif // PETSC_PCPATCHIMPL_H