Actual source code: dmnetworkimpl.h
1: #ifndef _NETWORKIMPL_H
2: #define _NETWORKIMPL_H
4: #include <petscmat.h>
5: #include <petscdmnetwork.h>
6: #include <petsc/private/dmpleximpl.h>
7: #include <petscctable.h>
9: PETSC_EXTERN PetscLogEvent DMNetwork_LayoutSetUp;
10: PETSC_EXTERN PetscLogEvent DMNetwork_SetUpNetwork;
11: PETSC_EXTERN PetscLogEvent DMNetwork_Distribute;
13: #define DMNETWORK_MAX_COMP_REGISTERED_DEFAULT 20
14: #define DMNETWORK_MAX_COMP_AT_POINT_DEFAULT 1
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)));
36: typedef struct _p_DMNetworkComponentValue *DMNetworkComponentValue;
37: struct _p_DMNetworkComponentValue {
38: void **data;
39: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
41: typedef struct {
42: char name[32 - sizeof(PetscInt)];
43: PetscInt size;
44: } DMNetworkComponent PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
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;
54: typedef struct {
55: PetscSection DofSection;
56: PetscSection GlobalDofSection;
57: ISLocalToGlobalMapping mapping;
58: PetscSF sf;
59: } DMNetworkEdgeInfo;
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;
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;
93: /* The data structure for DMNetwork is split into two parts:
94: 1. DMNetworkCloneShared : The part of the Network that holds information that is shared between
95: clones. Mostly topological data/reference counting information
97: 2. Everything else in the structure: The part of the network not shared between clones. This is the data on
98: the network, so dof and component type information.
99: */
100: typedef struct _p_DMNetworkCloneShared *DMNetworkCloneShared;
101: struct _p_DMNetworkCloneShared {
102: PetscInt refct; /* reference count for the shared data */
103: PetscInt NEdges, nEdges; /* Number of global/local edges */
104: PetscInt NVertices, nVertices; /* Number of global/local vertices */
105: PetscInt pStart, pEnd; /* Start and end indices for topological points */
106: PetscInt vStart, vEnd; /* Start and end indices for vertices */
107: PetscInt eStart, eEnd; /* Start and end indices for edges */
108: PetscBool distributecalled; /* Flag if DMNetworkDistribute() is called */
109: PetscInt *vltog; /* Maps vertex local ordering to global ordering, include ghost vertices */
111: PetscInt nsubnet, Nsubnet; /* Local and global number of subnetworks */
112: DMSubnetwork *subnet; /* Subnetworks */
113: PetscInt *subnetvtx, *subnetedge; /* Maps local vertex/edge to local subnetwork's vertex/edge */
114: SVtx *svtx; /* Array of vertices shared by subnetworks */
115: PetscInt nsvtx, Nsvtx; /* Local and global num of entries in svtx */
116: PetscInt *svertices; /* Array of local subnetwork vertices that are merged/shared */
117: PetscInt *sedgelist; /* Edge list of shared vertices */
118: PetscTable svtable; /* hash table for finding shared vertex info */
119: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
121: typedef struct {
122: DMNetworkCloneShared cloneshared;
123: DM plex; /* DM created from Plex. Note that it is not shared as when cloning the network
124: we also clone the underlying plex. */
125: PetscSection DataSection; /* Section for managing parameter distribution */
126: PetscSection DofSection; /* Section for managing data distribution */
127: PetscSection GlobalDofSection; /* Global Dof section */
129: DMNetworkVertexInfo vertex;
130: DMNetworkEdgeInfo edge;
132: PetscInt ncomponent; /* Number of components that have been registered */
133: DMNetworkComponent *component; /* List of components that have been registered */
134: DMNetworkComponentHeader header;
135: DMNetworkComponentValue cvalue;
136: DMNetworkComponentGenericDataType *componentdataarray; /* Array to hold the data */
137: PetscBool componentsetup; /* Flag for the setup of the component. Might differ from dmsetup information */
138: PetscInt max_comps_registered; /* Max. number of components that can be registered */
140: PetscBool userEdgeJacobian, userVertexJacobian; /* Global flag for using user's sub Jacobians */
141: Mat *Je; /* Pointer array to hold local sub Jacobians for edges, 3 elements for an edge */
142: Mat *Jv; /* Pointer array to hold local sub Jacobians for vertices, 1+2*nsupportedges for a vertex */
143: PetscInt *Jvptr; /* index of Jv for v-th vertex
144: Jvpt[v-vStart]: Jacobian(v,v)
145: Jvpt[v-vStart]+2i+1: Jacobian(v,e[i]), e[i]: i-th supporting edge
146: Jvpt[v-vStart]+2i+2: Jacobian(v,vc[i]), vc[i]: i-th connected vertex
147: */
148: } DM_Network;
150: PETSC_INTERN PetscErrorCode DMNetworkGetIndex(DM, PetscInt, PetscInt *);
151: PETSC_INTERN PetscErrorCode DMNetworkGetSubnetID(DM, PetscInt, PetscInt *);
153: PETSC_INTERN PetscErrorCode DMNetworkInitializeHeaderComponentData(DM);
154: /*
155: Setup the default non-topological data structures for the network. Only called in DMClone_Network,
156: as this assumes that the topological data structures have already been setup in DMNetworkLayoutSetUp.
157: which would normally set these defaults themselves.
158: */
159: PETSC_INTERN PetscErrorCode DMNetworkInitializeNonTopological(DM);
160: PETSC_INTERN PetscErrorCode DMNetworkInitializeToDefault(DM);
161: PETSC_INTERN PetscErrorCode DMNetworkInitializeToDefault_NonShared(DM);
163: #endif /* _NETWORKIMPL_H */