xref: /petsc/src/dm/impls/network/networkcreate.c (revision 2f6eced2a19e978d64f27de66fbc6c26cc5c7934)
1 #define PETSCDM_DLL
2 #include <petsc/private/dmnetworkimpl.h>    /*I   "petscdmnetwork.h"   I*/
3 #include <petscdmda.h>
4 
5 PetscErrorCode  DMSetFromOptions_Network(PetscOptionItems *PetscOptionsObject,DM dm)
6 {
7   PetscErrorCode ierr;
8 
9   PetscFunctionBegin;
10   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
11   ierr = PetscOptionsHead(PetscOptionsObject,"DMNetwork Options");CHKERRQ(ierr);
12   ierr = PetscOptionsTail();CHKERRQ(ierr);
13   PetscFunctionReturn(0);
14 }
15 
16 /* External function declarations here */
17 extern PetscErrorCode DMCreateMatrix_Network(DM, Mat*);
18 extern PetscErrorCode DMDestroy_Network(DM);
19 extern PetscErrorCode DMView_Network(DM, PetscViewer);
20 extern PetscErrorCode DMGlobalToLocalBegin_Network(DM, Vec, InsertMode, Vec);
21 extern PetscErrorCode DMGlobalToLocalEnd_Network(DM, Vec, InsertMode, Vec);
22 extern PetscErrorCode DMLocalToGlobalBegin_Network(DM, Vec, InsertMode, Vec);
23 extern PetscErrorCode DMLocalToGlobalEnd_Network(DM, Vec, InsertMode, Vec);
24 extern PetscErrorCode DMSetUp_Network(DM);
25 extern PetscErrorCode DMClone_Network(DM, DM*);
26 
27 
28 static PetscErrorCode DMCreateGlobalVector_Network(DM dm,Vec *vec)
29 {
30   PetscErrorCode ierr;
31   DM_Network     *network = (DM_Network*) dm->data;
32 
33   PetscFunctionBegin;
34   ierr = DMCreateGlobalVector(network->plex,vec);CHKERRQ(ierr);
35   ierr = VecSetDM(*vec,dm);CHKERRQ(ierr);
36   PetscFunctionReturn(0);
37 }
38 
39 static PetscErrorCode DMCreateLocalVector_Network(DM dm,Vec *vec)
40 {
41   PetscErrorCode ierr;
42   DM_Network     *network = (DM_Network*) dm->data;
43 
44   PetscFunctionBegin;
45   ierr = DMCreateLocalVector(network->plex,vec);CHKERRQ(ierr);
46   ierr = VecSetDM(*vec,dm);CHKERRQ(ierr);
47   PetscFunctionReturn(0);
48 }
49 
50 PetscErrorCode DMInitialize_Network(DM dm)
51 {
52 
53   PetscFunctionBegin;
54 
55   dm->ops->view                            = NULL;
56   dm->ops->setfromoptions                  = DMSetFromOptions_Network;
57   dm->ops->clone                           = DMClone_Network;
58   dm->ops->setup                           = DMSetUp_Network;
59   dm->ops->createglobalvector              = DMCreateGlobalVector_Network;
60   dm->ops->createlocalvector               = DMCreateLocalVector_Network;
61   dm->ops->getlocaltoglobalmapping         = NULL;
62   dm->ops->createfieldis                   = NULL;
63   dm->ops->createcoordinatedm              = NULL;
64   dm->ops->getcoloring                     = 0;
65   dm->ops->creatematrix                    = DMCreateMatrix_Network;
66   dm->ops->createinterpolation             = 0;
67   dm->ops->getaggregates                   = 0;
68   dm->ops->getinjection                    = 0;
69   dm->ops->refine                          = 0;
70   dm->ops->coarsen                         = 0;
71   dm->ops->refinehierarchy                 = 0;
72   dm->ops->coarsenhierarchy                = 0;
73   dm->ops->globaltolocalbegin              = DMGlobalToLocalBegin_Network;
74   dm->ops->globaltolocalend                = DMGlobalToLocalEnd_Network;
75   dm->ops->localtoglobalbegin              = DMLocalToGlobalBegin_Network;
76   dm->ops->localtoglobalend                = DMLocalToGlobalEnd_Network;
77   dm->ops->destroy                         = DMDestroy_Network;
78   dm->ops->createsubdm                     = NULL;
79   dm->ops->locatepoints                    = NULL;
80   PetscFunctionReturn(0);
81 }
82 
83 PetscErrorCode DMClone_Network(DM dm, DM *newdm)
84 {
85   DM_Network     *network = (DM_Network *) dm->data;
86   PetscErrorCode ierr;
87 
88   PetscFunctionBegin;
89   network->refct++;
90   (*newdm)->data = network;
91   ierr = PetscObjectChangeTypeName((PetscObject) *newdm, DMNETWORK);CHKERRQ(ierr);
92   ierr = DMInitialize_Network(*newdm);CHKERRQ(ierr);
93   PetscFunctionReturn(0);
94 }
95 
96 /*MC
97   DMNETWORK = "network" - A DM object that encapsulates an unstructured network. The implementation is based on the DM object
98                           DMPlex that manages unstructured grids. Distributed networks use a non-overlapping partitioning of
99                           the edges. In the local representation, Vecs contain all unknowns in the interior and shared boundary.
100                           This is specified by a PetscSection object. Ownership in the global representation is determined by
101                           ownership of the underlying DMPlex points. This is specified by another PetscSection object.
102 
103   Level: intermediate
104 
105 .seealso: DMType, DMNetworkCreate(), DMCreate(), DMSetType()
106 M*/
107 
108 PETSC_EXTERN PetscErrorCode DMCreate_Network(DM dm)
109 {
110   DM_Network     *network;
111   PetscErrorCode ierr;
112 
113   PetscFunctionBegin;
114   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
115   ierr     = PetscNewLog(dm,&network);CHKERRQ(ierr);
116   dm->data = network;
117 
118   network->refct          = 1;
119   network->NNodes         = -1;
120   network->NEdges         = -1;
121   network->nNodes         = -1;
122   network->nEdges         = -1;
123 
124 
125   ierr = DMInitialize_Network(dm);CHKERRQ(ierr);
126   PetscFunctionReturn(0);
127 }
128 
129 /*@
130   DMNetworkCreate - Creates a DMNetwork object, which encapsulates an unstructured network.
131 
132   Collective on MPI_Comm
133 
134   Input Parameter:
135 . comm - The communicator for the DMNetwork object
136 
137   Output Parameter:
138 . network  - The DMNetwork object
139 
140   Level: beginner
141 
142 .keywords: DMNetwork, create
143 @*/
144 PetscErrorCode DMNetworkCreate(MPI_Comm comm, DM *network)
145 {
146   PetscErrorCode ierr;
147 
148   PetscFunctionBegin;
149   PetscValidPointer(network,2);
150   ierr = DMCreate(comm, network);CHKERRQ(ierr);
151   ierr = DMSetType(*network, DMNETWORK);CHKERRQ(ierr);
152   PetscFunctionReturn(0);
153 }
154