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