Actual source code: dmnetworkimpl.h

  1: #if !defined(_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: /* The maximum number of components registered and maximum number of components per network point */
 10: #define MAX_NETCOMPONENTS 36

 12: typedef struct _p_DMNetworkComponentHeader *DMNetworkComponentHeader;
 13: struct _p_DMNetworkComponentHeader {
 14:   PetscInt index;    /* index for user input global edge and vertex */
 15:   PetscInt subnetid; /* Id for subnetwork */
 16:   PetscInt ndata;    /* number of components */
 17:   PetscInt size[MAX_NETCOMPONENTS];
 18:   PetscInt key[MAX_NETCOMPONENTS];
 19:   PetscInt offset[MAX_NETCOMPONENTS];
 20:   PetscInt nvar[MAX_NETCOMPONENTS]; /* Number of variables */
 21:   PetscInt offsetvarrel[MAX_NETCOMPONENTS]; /* offset from the first variable of the network point */
 22: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double),sizeof(PetscScalar)));

 24: typedef struct _p_DMNetworkComponentValue *DMNetworkComponentValue;
 25: struct _p_DMNetworkComponentValue {
 26:   void* data[MAX_NETCOMPONENTS];
 27: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double),sizeof(PetscScalar)));

 29: typedef struct {
 30:   char     name[32-sizeof(PetscInt)];
 31:   PetscInt size;
 32: } DMNetworkComponent PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double),sizeof(PetscScalar)));

 34: /* Indexing data structures for vertex and edges */
 35: typedef struct {
 36:   PetscSection                      DofSection;
 37:   PetscSection                      GlobalDofSection;
 38:   ISLocalToGlobalMapping            mapping;
 39:   PetscSF                           sf;
 40: } DMNetworkVertexInfo;

 42: typedef struct {
 43:   PetscSection                      DofSection;
 44:   PetscSection                      GlobalDofSection;
 45:   ISLocalToGlobalMapping            mapping;
 46:   PetscSF                           sf;
 47: } DMNetworkEdgeInfo;

 49: /*
 50:   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).
 51:   sv is organized as (see SVtxCreate())
 52:         sv(net[0],idx[0]) --> sv(net[1],idx[1])
 53:                           --> sv(net[1],idx[1])
 54:                           ...
 55:                           --> sv(net[n-1],idx[n-1])
 56:         and net[0] < net[1] < ... < net[n-1]
 57:         where sv[0] has SVFROM type, sv[i], i>0, has SVTO type.
 58: */
 59: typedef struct {
 60:   PetscInt gidx;                /* global index of the shared vertices in dmplex */
 61:   PetscInt n;                   /* number of subnetworks that share the common DMNetwork vertex */
 62:   PetscInt *sv;                 /* array of size n: sv[2*i,2*i+1]=(net[i], idx[i]), i=0,...,n-1 */
 63: } SVtx;
 64: typedef enum {SVNONE=-1, SVFROM=0, SVTO=1} SVtxType;

 66: typedef struct {
 67:   PetscInt  Nvtx, nvtx;     /* Number of global/local vertices */
 68:   PetscInt  Nedge,nedge;    /* Number of global/local edges */
 69:   PetscInt  eStart, eEnd;   /* Range of edge numbers (start, end+1) */
 70:   PetscInt  vStart, vEnd;   /* Range of vertex numbers (start, end+1) */
 71:   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 */
 72:   PetscInt  *vertices;      /* Vertices for this subnetwork. These are mapped to the vertex numbers for the whole network */
 73:   PetscInt  *edges;         /* Edges for this subnetwork. These are mapped to the edge numbers for the whole network */
 74:   char      name[32-sizeof(PetscInt)];
 75: } DMSubnetwork;

 77: typedef struct {
 78:   PetscInt                          refct;               /* reference count */
 79:   PetscInt                          NEdges,nEdges;       /* Number of global/local edges */
 80:   PetscInt                          NVertices,nVertices; /* Number of global/local vertices */
 81:   PetscInt                          pStart,pEnd;         /* Start and end indices for topological points */
 82:   PetscInt                          vStart,vEnd;         /* Start and end indices for vertices */
 83:   PetscInt                          eStart,eEnd;         /* Start and end indices for edges */
 84:   DM                                plex;                /* DM created from Plex */
 85:   PetscSection                      DataSection;         /* Section for managing parameter distribution */
 86:   PetscSection                      DofSection;          /* Section for managing data distribution */
 87:   PetscSection                      GlobalDofSection;    /* Global Dof section */
 88:   PetscBool                         distributecalled;    /* Flag if DMNetworkDistribute() is called */
 89:   PetscInt                          *vltog;              /* Maps vertex local ordering to global ordering, include ghost vertices */

 91:   DMNetworkVertexInfo               vertex;
 92:   DMNetworkEdgeInfo                 edge;

 94:   PetscInt                          ncomponent; /* Number of components */
 95:   DMNetworkComponent                component[MAX_NETCOMPONENTS]; /* List of components */
 96:   DMNetworkComponentHeader          header;
 97:   DMNetworkComponentValue           cvalue;
 98:   PetscInt                          dataheadersize;
 99:   DMNetworkComponentGenericDataType *componentdataarray; /* Array to hold the data */

101:   PetscInt                          nsubnet,Nsubnet; /* Local and global number of subnetworks */
102:   DMSubnetwork                      *subnet;         /* Subnetworks */
103:   PetscInt                          *subnetvtx;      /* Maps local vertex to local subnetwork's vertex */
104:   SVtx                              *svtx;           /* Array of vertices shared by subnetworks */
105:   PetscInt                          nsvtx,Nsvtx;     /* Local and global num of entries in svtx */
106:   PetscInt                          *svertices;      /* Array of local subnetwork vertices that are merged/shared */
107:   PetscInt                          *sedgelist;      /* Edge list of shared vertices */
108:   PetscTable                        svtable;         /* hash table for finding shared vertex info */

110:   PetscBool                         userEdgeJacobian,userVertexJacobian;  /* Global flag for using user's sub Jacobians */
111:   Mat                               *Je;  /* Pointer array to hold local sub Jacobians for edges, 3 elements for an edge */
112:   Mat                               *Jv;  /* Pointer array to hold local sub Jacobians for vertices, 1+2*nsupportedges for a vertex */
113:   PetscInt                          *Jvptr;   /* index of Jv for v-th vertex
114:                                               Jvpt[v-vStart]:    Jacobian(v,v)
115:                                               Jvpt[v-vStart]+2i+1: Jacobian(v,e[i]),   e[i]: i-th supporting edge
116:                                               Jvpt[v-vStart]+2i+2: Jacobian(v,vc[i]), vc[i]: i-th connected vertex
117:                                               */
118: } DM_Network;

120: #endif /* _NETWORKIMPL_H */