1 #pragma once 2 3 #include "petscistypes.h" 4 #include <petscmat.h> /*I "petscmat.h" I*/ 5 #include <petscdmnetwork.h> /*I "petscdmnetwork.h" I*/ 6 #include <petsc/private/dmpleximpl.h> /*I "petscdmplex.h" I*/ 7 #include <petsc/private/hashmapi.h> 8 9 PETSC_EXTERN PetscLogEvent DMNetwork_LayoutSetUp; 10 PETSC_EXTERN PetscLogEvent DMNetwork_SetUpNetwork; 11 PETSC_EXTERN PetscLogEvent DMNetwork_Distribute; 12 13 #define DMNETWORK_MAX_COMP_REGISTERED_DEFAULT 20 14 #define DMNETWORK_MAX_COMP_AT_POINT_DEFAULT 1 15 16 typedef struct _p_DMNetworkComponentHeader *DMNetworkComponentHeader; 17 struct _p_DMNetworkComponentHeader { 18 PetscInt index; /* index for user input global edge and vertex */ 19 PetscInt subnetid; /* Id for subnetwork */ 20 PetscInt ndata; /* number of components */ 21 PetscInt hsize; /* Size of the header */ 22 PetscInt maxcomps; /* Maximum components at this point (ndata <= maxcomps). maxcomps 23 is set initially to a default value and is incremented every time 24 ndata exceeds maxcomps */ 25 /* The following arrays store the different attributes for each component at the given point. 26 The length of these arrays equals maxcomps. The arrays are resized every time 27 ndata exceeds maxcomps 28 */ 29 PetscInt *size; /* component data struct sizes */ 30 PetscInt *key; /* component keys */ 31 PetscInt *offset; /* component offset in the vector */ 32 PetscInt *nvar; /* number of variables for the component */ 33 PetscInt *offsetvarrel; /* relative offset from the first component at this point */ 34 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar))); 35 36 typedef struct _p_DMNetworkComponentValue *DMNetworkComponentValue; 37 struct _p_DMNetworkComponentValue { 38 void **data; 39 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar))); 40 41 typedef struct { 42 char name[32 - sizeof(PetscInt)]; 43 PetscInt size; 44 } DMNetworkComponent PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar))); 45 46 /* Indexing data structures for vertex and edges */ 47 typedef struct { 48 PetscSection DofSection; 49 PetscSection GlobalDofSection; 50 ISLocalToGlobalMapping mapping; 51 PetscSF sf; 52 } DMNetworkVertexInfo; 53 54 typedef struct { 55 PetscSection DofSection; 56 PetscSection GlobalDofSection; 57 ISLocalToGlobalMapping mapping; 58 PetscSF sf; 59 } DMNetworkEdgeInfo; 60 61 /* 62 Shared vertex - a vertex in DMNetwork that is shared by 2 or more subnetworks. sv provides the mapping from the subnetwork vertices to the global DMNetwork vertex (merged network). 63 sv is organized as (see SVtxCreate()) 64 sv(net[0],idx[0]) --> sv(net[1],idx[1]) 65 --> sv(net[1],idx[1]) 66 ... 67 --> sv(net[n-1],idx[n-1]) 68 and net[0] < net[1] < ... < net[n-1] 69 where sv[0] has SVFROM type, sv[i], i>0, has SVTO type. 70 */ 71 typedef struct { 72 PetscInt gidx; /* global index of the shared vertices in dmplex */ 73 PetscInt n; /* number of subnetworks that share the common DMNetwork vertex */ 74 PetscInt *sv; /* array of size n: sv[2*i,2*i+1]=(net[i], idx[i]), i=0,...,n-1 */ 75 } SVtx; 76 typedef enum { 77 SVNONE = -1, 78 SVFROM = 0, 79 SVTO = 1 80 } SVtxType; 81 82 typedef struct { 83 PetscInt Nvtx, nvtx; /* Number of global/local vertices */ 84 PetscInt Nedge, nedge; /* Number of global/local edges */ 85 PetscInt eStart, eEnd; /* Range of edge numbers (start, end+1) */ 86 PetscInt vStart, vEnd; /* Range of vertex numbers (start, end+1) */ 87 PetscInt *edgelist; /* User provided list of edges. Each edge has the format [from to] where from and to are the vertices covering the edge in the subnet numbering */ 88 PetscInt *vertices; /* Vertices for this subnetwork. These are mapped to the vertex numbers for the whole network */ 89 PetscInt *edges; /* Edges for this subnetwork. These are mapped to the edge numbers for the whole network */ 90 char name[32 - sizeof(PetscInt)]; 91 } DMSubnetwork; 92 93 /* 94 Structure storing default viewing options for the DMNetwork 95 */ 96 typedef struct { 97 PetscBool showallranks; /* Shows each rank individually as well */ 98 PetscBool dontshowglobal; /* Don't show combined network */ 99 IS viewranks; /* IS containing the ranks to view the DMNetwork on */ 100 PetscBool shownovertices; 101 PetscBool shownonumbering; 102 } DMNetworkViewerOptions; 103 104 /* The data structure for DMNetwork is split into two parts: 105 1. DMNetworkCloneShared : The part of the Network that holds information that is shared between 106 clones. Mostly topological data/reference counting information 107 108 2. Everything else in the structure: The part of the network not shared between clones. This is the data on 109 the network, so dof and component type information. 110 */ 111 typedef struct _p_DMNetworkCloneShared *DMNetworkCloneShared; 112 struct _p_DMNetworkCloneShared { 113 PetscInt refct; /* reference count for the shared data */ 114 PetscInt NEdges, nEdges; /* Number of global/local edges */ 115 PetscInt NVertices, nVertices; /* Number of global/local vertices */ 116 PetscInt pStart, pEnd; /* Start and end indices for topological points */ 117 PetscInt vStart, vEnd; /* Start and end indices for vertices */ 118 PetscInt eStart, eEnd; /* Start and end indices for edges */ 119 PetscBool distributecalled; /* Flag if DMNetworkDistribute() is called */ 120 PetscInt *vltog; /* Maps vertex local ordering to global ordering, include ghost vertices */ 121 122 PetscInt nsubnet, Nsubnet; /* Local and global number of subnetworks */ 123 DMSubnetwork *subnet; /* Subnetworks */ 124 PetscInt *subnetvtx, *subnetedge; /* Maps local vertex/edge to local subnetwork's vertex/edge */ 125 SVtx *svtx; /* Array of vertices shared by subnetworks */ 126 PetscInt nsvtx, Nsvtx; /* Local and global num of entries in svtx */ 127 PetscInt *svertices; /* Array of local subnetwork vertices that are merged/shared */ 128 PetscInt *sedgelist; /* Edge list of shared vertices */ 129 PetscHMapI svtable; /* hash table for finding shared vertex info */ 130 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar))); 131 132 typedef struct { 133 DMNetworkCloneShared cloneshared; 134 DM plex; /* DM created from Plex. Note that it is not shared as when cloning the network 135 we also clone the underlying plex. */ 136 PetscSection DataSection; /* Section for managing parameter distribution */ 137 PetscSection DofSection; /* Section for managing data distribution */ 138 PetscSection GlobalDofSection; /* Global Dof section */ 139 140 DMNetworkVertexInfo vertex; 141 DMNetworkEdgeInfo edge; 142 143 PetscInt ncomponent; /* Number of components that have been registered */ 144 DMNetworkComponent *component; /* List of components that have been registered */ 145 DMNetworkComponentHeader header; 146 DMNetworkComponentValue cvalue; 147 DMNetworkComponentGenericDataType *componentdataarray; /* Array to hold the data */ 148 PetscBool componentsetup; /* Flag for the setup of the component. Might differ from dmsetup information */ 149 PetscInt max_comps_registered; /* Max. number of components that can be registered */ 150 151 PetscBool userEdgeJacobian, userVertexJacobian; /* Global flag for using user's sub Jacobians */ 152 Mat *Je; /* Pointer array to hold local sub Jacobians for edges, 3 elements for an edge */ 153 Mat *Jv; /* Pointer array to hold local sub Jacobians for vertices, 1+2*nsupportedges for a vertex */ 154 PetscInt *Jvptr; /* index of Jv for v-th vertex 155 Jvpt[v-vStart]: Jacobian(v,v) 156 Jvpt[v-vStart]+2i+1: Jacobian(v,e[i]), e[i]: i-th supporting edge 157 Jvpt[v-vStart]+2i+2: Jacobian(v,vc[i]), vc[i]: i-th connected vertex 158 */ 159 DMNetworkViewerOptions vieweroptions; 160 } DM_Network; 161 162 PETSC_INTERN PetscErrorCode DMNetworkGetIndex(DM, PetscInt, PetscInt *); 163 PETSC_INTERN PetscErrorCode DMNetworkGetSubnetID(DM, PetscInt, PetscInt *); 164 165 PETSC_INTERN PetscErrorCode DMNetworkInitializeHeaderComponentData(DM); 166 /* 167 Setup the default non-topological data structures for the network. Only called in DMClone_Network, 168 as this assumes that the topological data structures have already been setup in DMNetworkLayoutSetUp. 169 which would normally set these defaults themselves. 170 */ 171 PETSC_INTERN PetscErrorCode DMNetworkInitializeNonTopological(DM); 172 PETSC_INTERN PetscErrorCode DMNetworkInitializeToDefault(DM); 173 PETSC_INTERN PetscErrorCode DMNetworkInitializeToDefault_NonShared(DM); 174 175 PETSC_INTERN PetscErrorCode DMCreateCoordinateDM_Network(DM, DM *); 176