1*2764a2aaSMatthew G. Knepley #include <petsc-private/petscdsimpl.h> /*I "petscds.h" I*/ 2*2764a2aaSMatthew G. Knepley 3*2764a2aaSMatthew G. Knepley PetscClassId PETSCDS_CLASSID = 0; 4*2764a2aaSMatthew G. Knepley 5*2764a2aaSMatthew G. Knepley PetscFunctionList PetscDSList = NULL; 6*2764a2aaSMatthew G. Knepley PetscBool PetscDSRegisterAllCalled = PETSC_FALSE; 7*2764a2aaSMatthew G. Knepley 8*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 9*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSRegister" 10*2764a2aaSMatthew G. Knepley /*@C 11*2764a2aaSMatthew G. Knepley PetscDSRegister - Adds a new PetscDS implementation 12*2764a2aaSMatthew G. Knepley 13*2764a2aaSMatthew G. Knepley Not Collective 14*2764a2aaSMatthew G. Knepley 15*2764a2aaSMatthew G. Knepley Input Parameters: 16*2764a2aaSMatthew G. Knepley + name - The name of a new user-defined creation routine 17*2764a2aaSMatthew G. Knepley - create_func - The creation routine itself 18*2764a2aaSMatthew G. Knepley 19*2764a2aaSMatthew G. Knepley Notes: 20*2764a2aaSMatthew G. Knepley PetscDSRegister() may be called multiple times to add several user-defined PetscDSs 21*2764a2aaSMatthew G. Knepley 22*2764a2aaSMatthew G. Knepley Sample usage: 23*2764a2aaSMatthew G. Knepley .vb 24*2764a2aaSMatthew G. Knepley PetscDSRegister("my_ds", MyPetscDSCreate); 25*2764a2aaSMatthew G. Knepley .ve 26*2764a2aaSMatthew G. Knepley 27*2764a2aaSMatthew G. Knepley Then, your PetscDS type can be chosen with the procedural interface via 28*2764a2aaSMatthew G. Knepley .vb 29*2764a2aaSMatthew G. Knepley PetscDSCreate(MPI_Comm, PetscDS *); 30*2764a2aaSMatthew G. Knepley PetscDSSetType(PetscDS, "my_ds"); 31*2764a2aaSMatthew G. Knepley .ve 32*2764a2aaSMatthew G. Knepley or at runtime via the option 33*2764a2aaSMatthew G. Knepley .vb 34*2764a2aaSMatthew G. Knepley -petscds_type my_ds 35*2764a2aaSMatthew G. Knepley .ve 36*2764a2aaSMatthew G. Knepley 37*2764a2aaSMatthew G. Knepley Level: advanced 38*2764a2aaSMatthew G. Knepley 39*2764a2aaSMatthew G. Knepley .keywords: PetscDS, register 40*2764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy() 41*2764a2aaSMatthew G. Knepley 42*2764a2aaSMatthew G. Knepley @*/ 43*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS)) 44*2764a2aaSMatthew G. Knepley { 45*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 46*2764a2aaSMatthew G. Knepley 47*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 48*2764a2aaSMatthew G. Knepley ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr); 49*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 50*2764a2aaSMatthew G. Knepley } 51*2764a2aaSMatthew G. Knepley 52*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 53*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetType" 54*2764a2aaSMatthew G. Knepley /*@C 55*2764a2aaSMatthew G. Knepley PetscDSSetType - Builds a particular PetscDS 56*2764a2aaSMatthew G. Knepley 57*2764a2aaSMatthew G. Knepley Collective on PetscDS 58*2764a2aaSMatthew G. Knepley 59*2764a2aaSMatthew G. Knepley Input Parameters: 60*2764a2aaSMatthew G. Knepley + prob - The PetscDS object 61*2764a2aaSMatthew G. Knepley - name - The kind of system 62*2764a2aaSMatthew G. Knepley 63*2764a2aaSMatthew G. Knepley Options Database Key: 64*2764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types 65*2764a2aaSMatthew G. Knepley 66*2764a2aaSMatthew G. Knepley Level: intermediate 67*2764a2aaSMatthew G. Knepley 68*2764a2aaSMatthew G. Knepley .keywords: PetscDS, set, type 69*2764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate() 70*2764a2aaSMatthew G. Knepley @*/ 71*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name) 72*2764a2aaSMatthew G. Knepley { 73*2764a2aaSMatthew G. Knepley PetscErrorCode (*r)(PetscDS); 74*2764a2aaSMatthew G. Knepley PetscBool match; 75*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 76*2764a2aaSMatthew G. Knepley 77*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 78*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 79*2764a2aaSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr); 80*2764a2aaSMatthew G. Knepley if (match) PetscFunctionReturn(0); 81*2764a2aaSMatthew G. Knepley 82*2764a2aaSMatthew G. Knepley if (!PetscDSRegisterAllCalled) {ierr = PetscDSRegisterAll();CHKERRQ(ierr);} 83*2764a2aaSMatthew G. Knepley ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr); 84*2764a2aaSMatthew G. Knepley if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name); 85*2764a2aaSMatthew G. Knepley 86*2764a2aaSMatthew G. Knepley if (prob->ops->destroy) { 87*2764a2aaSMatthew G. Knepley ierr = (*prob->ops->destroy)(prob);CHKERRQ(ierr); 88*2764a2aaSMatthew G. Knepley prob->ops->destroy = NULL; 89*2764a2aaSMatthew G. Knepley } 90*2764a2aaSMatthew G. Knepley ierr = (*r)(prob);CHKERRQ(ierr); 91*2764a2aaSMatthew G. Knepley ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr); 92*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 93*2764a2aaSMatthew G. Knepley } 94*2764a2aaSMatthew G. Knepley 95*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 96*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetType" 97*2764a2aaSMatthew G. Knepley /*@C 98*2764a2aaSMatthew G. Knepley PetscDSGetType - Gets the PetscDS type name (as a string) from the object. 99*2764a2aaSMatthew G. Knepley 100*2764a2aaSMatthew G. Knepley Not Collective 101*2764a2aaSMatthew G. Knepley 102*2764a2aaSMatthew G. Knepley Input Parameter: 103*2764a2aaSMatthew G. Knepley . prob - The PetscDS 104*2764a2aaSMatthew G. Knepley 105*2764a2aaSMatthew G. Knepley Output Parameter: 106*2764a2aaSMatthew G. Knepley . name - The PetscDS type name 107*2764a2aaSMatthew G. Knepley 108*2764a2aaSMatthew G. Knepley Level: intermediate 109*2764a2aaSMatthew G. Knepley 110*2764a2aaSMatthew G. Knepley .keywords: PetscDS, get, type, name 111*2764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate() 112*2764a2aaSMatthew G. Knepley @*/ 113*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name) 114*2764a2aaSMatthew G. Knepley { 115*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 116*2764a2aaSMatthew G. Knepley 117*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 118*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 119*2764a2aaSMatthew G. Knepley PetscValidCharPointer(name, 2); 120*2764a2aaSMatthew G. Knepley if (!PetscDSRegisterAllCalled) {ierr = PetscDSRegisterAll();CHKERRQ(ierr);} 121*2764a2aaSMatthew G. Knepley *name = ((PetscObject) prob)->type_name; 122*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 123*2764a2aaSMatthew G. Knepley } 124*2764a2aaSMatthew G. Knepley 125*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 126*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSView" 127*2764a2aaSMatthew G. Knepley /*@C 128*2764a2aaSMatthew G. Knepley PetscDSView - Views a PetscDS 129*2764a2aaSMatthew G. Knepley 130*2764a2aaSMatthew G. Knepley Collective on PetscDS 131*2764a2aaSMatthew G. Knepley 132*2764a2aaSMatthew G. Knepley Input Parameter: 133*2764a2aaSMatthew G. Knepley + prob - the PetscDS object to view 134*2764a2aaSMatthew G. Knepley - v - the viewer 135*2764a2aaSMatthew G. Knepley 136*2764a2aaSMatthew G. Knepley Level: developer 137*2764a2aaSMatthew G. Knepley 138*2764a2aaSMatthew G. Knepley .seealso PetscDSDestroy() 139*2764a2aaSMatthew G. Knepley @*/ 140*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v) 141*2764a2aaSMatthew G. Knepley { 142*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 143*2764a2aaSMatthew G. Knepley 144*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 145*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 146*2764a2aaSMatthew G. Knepley if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);} 147*2764a2aaSMatthew G. Knepley if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);} 148*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 149*2764a2aaSMatthew G. Knepley } 150*2764a2aaSMatthew G. Knepley 151*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 152*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSViewFromOptions" 153*2764a2aaSMatthew G. Knepley /* 154*2764a2aaSMatthew G. Knepley PetscDSViewFromOptions - Processes command line options to determine if/how a PetscDS is to be viewed. 155*2764a2aaSMatthew G. Knepley 156*2764a2aaSMatthew G. Knepley Collective on PetscDS 157*2764a2aaSMatthew G. Knepley 158*2764a2aaSMatthew G. Knepley Input Parameters: 159*2764a2aaSMatthew G. Knepley + prob - the PetscDS 160*2764a2aaSMatthew G. Knepley . prefix - prefix to use for viewing, or NULL to use prefix of 'rnd' 161*2764a2aaSMatthew G. Knepley - optionname - option to activate viewing 162*2764a2aaSMatthew G. Knepley 163*2764a2aaSMatthew G. Knepley Level: intermediate 164*2764a2aaSMatthew G. Knepley 165*2764a2aaSMatthew G. Knepley .keywords: PetscDS, view, options, database 166*2764a2aaSMatthew G. Knepley .seealso: VecViewFromOptions(), MatViewFromOptions() 167*2764a2aaSMatthew G. Knepley */ 168*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSViewFromOptions(PetscDS prob, const char prefix[], const char optionname[]) 169*2764a2aaSMatthew G. Knepley { 170*2764a2aaSMatthew G. Knepley PetscViewer viewer; 171*2764a2aaSMatthew G. Knepley PetscViewerFormat format; 172*2764a2aaSMatthew G. Knepley PetscBool flg; 173*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 174*2764a2aaSMatthew G. Knepley 175*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 176*2764a2aaSMatthew G. Knepley if (prefix) {ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject) prob), prefix, optionname, &viewer, &format, &flg);CHKERRQ(ierr);} 177*2764a2aaSMatthew G. Knepley else {ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject) prob), ((PetscObject) prob)->prefix, optionname, &viewer, &format, &flg);CHKERRQ(ierr);} 178*2764a2aaSMatthew G. Knepley if (flg) { 179*2764a2aaSMatthew G. Knepley ierr = PetscViewerPushFormat(viewer, format);CHKERRQ(ierr); 180*2764a2aaSMatthew G. Knepley ierr = PetscDSView(prob, viewer);CHKERRQ(ierr); 181*2764a2aaSMatthew G. Knepley ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr); 182*2764a2aaSMatthew G. Knepley ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 183*2764a2aaSMatthew G. Knepley } 184*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 185*2764a2aaSMatthew G. Knepley } 186*2764a2aaSMatthew G. Knepley 187*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 188*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetFromOptions" 189*2764a2aaSMatthew G. Knepley /*@ 190*2764a2aaSMatthew G. Knepley PetscDSSetFromOptions - sets parameters in a PetscDS from the options database 191*2764a2aaSMatthew G. Knepley 192*2764a2aaSMatthew G. Knepley Collective on PetscDS 193*2764a2aaSMatthew G. Knepley 194*2764a2aaSMatthew G. Knepley Input Parameter: 195*2764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for 196*2764a2aaSMatthew G. Knepley 197*2764a2aaSMatthew G. Knepley Options Database: 198*2764a2aaSMatthew G. Knepley 199*2764a2aaSMatthew G. Knepley Level: developer 200*2764a2aaSMatthew G. Knepley 201*2764a2aaSMatthew G. Knepley .seealso PetscDSView() 202*2764a2aaSMatthew G. Knepley @*/ 203*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob) 204*2764a2aaSMatthew G. Knepley { 205*2764a2aaSMatthew G. Knepley const char *defaultType; 206*2764a2aaSMatthew G. Knepley char name[256]; 207*2764a2aaSMatthew G. Knepley PetscBool flg; 208*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 209*2764a2aaSMatthew G. Knepley 210*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 211*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 212*2764a2aaSMatthew G. Knepley if (!((PetscObject) prob)->type_name) { 213*2764a2aaSMatthew G. Knepley defaultType = PETSCDSBASIC; 214*2764a2aaSMatthew G. Knepley } else { 215*2764a2aaSMatthew G. Knepley defaultType = ((PetscObject) prob)->type_name; 216*2764a2aaSMatthew G. Knepley } 217*2764a2aaSMatthew G. Knepley if (!PetscDSRegisterAllCalled) {ierr = PetscDSRegisterAll();CHKERRQ(ierr);} 218*2764a2aaSMatthew G. Knepley 219*2764a2aaSMatthew G. Knepley ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr); 220*2764a2aaSMatthew G. Knepley ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr); 221*2764a2aaSMatthew G. Knepley if (flg) { 222*2764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, name);CHKERRQ(ierr); 223*2764a2aaSMatthew G. Knepley } else if (!((PetscObject) prob)->type_name) { 224*2764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr); 225*2764a2aaSMatthew G. Knepley } 226*2764a2aaSMatthew G. Knepley if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);} 227*2764a2aaSMatthew G. Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 228*2764a2aaSMatthew G. Knepley ierr = PetscObjectProcessOptionsHandlers((PetscObject) prob);CHKERRQ(ierr); 229*2764a2aaSMatthew G. Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 230*2764a2aaSMatthew G. Knepley ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr); 231*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 232*2764a2aaSMatthew G. Knepley } 233*2764a2aaSMatthew G. Knepley 234*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 235*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetUp" 236*2764a2aaSMatthew G. Knepley /*@C 237*2764a2aaSMatthew G. Knepley PetscDSSetUp - Construct data structures for the PetscDS 238*2764a2aaSMatthew G. Knepley 239*2764a2aaSMatthew G. Knepley Collective on PetscDS 240*2764a2aaSMatthew G. Knepley 241*2764a2aaSMatthew G. Knepley Input Parameter: 242*2764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup 243*2764a2aaSMatthew G. Knepley 244*2764a2aaSMatthew G. Knepley Level: developer 245*2764a2aaSMatthew G. Knepley 246*2764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy() 247*2764a2aaSMatthew G. Knepley @*/ 248*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob) 249*2764a2aaSMatthew G. Knepley { 250*2764a2aaSMatthew G. Knepley const PetscInt Nf = prob->Nf; 251*2764a2aaSMatthew G. Knepley PetscInt dim, work, NcMax = 0, NqMax = 0, f; 252*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 253*2764a2aaSMatthew G. Knepley 254*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 255*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 256*2764a2aaSMatthew G. Knepley if (prob->setup) PetscFunctionReturn(0); 257*2764a2aaSMatthew G. Knepley /* Calculate sizes */ 258*2764a2aaSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 259*2764a2aaSMatthew G. Knepley prob->totDim = prob->totDimBd = prob->totComp = 0; 260*2764a2aaSMatthew G. Knepley ierr = PetscMalloc4(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisBd,Nf,&prob->basisDerBd);CHKERRQ(ierr); 261*2764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 262*2764a2aaSMatthew G. Knepley PetscFE fe = (PetscFE) prob->disc[f]; 263*2764a2aaSMatthew G. Knepley PetscFE feBd = (PetscFE) prob->discBd[f]; 264*2764a2aaSMatthew G. Knepley PetscQuadrature q; 265*2764a2aaSMatthew G. Knepley PetscInt Nq, Nb, Nc; 266*2764a2aaSMatthew G. Knepley 267*2764a2aaSMatthew G. Knepley /* TODO Dispatch on discretization type*/ 268*2764a2aaSMatthew G. Knepley ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr); 269*2764a2aaSMatthew G. Knepley ierr = PetscQuadratureGetData(q, NULL, &Nq, NULL, NULL);CHKERRQ(ierr); 270*2764a2aaSMatthew G. Knepley ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr); 271*2764a2aaSMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 272*2764a2aaSMatthew G. Knepley ierr = PetscFEGetDefaultTabulation(fe, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr); 273*2764a2aaSMatthew G. Knepley NqMax = PetscMax(NqMax, Nq); 274*2764a2aaSMatthew G. Knepley NcMax = PetscMax(NcMax, Nc); 275*2764a2aaSMatthew G. Knepley prob->totDim += Nb*Nc; 276*2764a2aaSMatthew G. Knepley prob->totComp += Nc; 277*2764a2aaSMatthew G. Knepley if (feBd) { 278*2764a2aaSMatthew G. Knepley ierr = PetscFEGetDimension(feBd, &Nb);CHKERRQ(ierr); 279*2764a2aaSMatthew G. Knepley ierr = PetscFEGetNumComponents(feBd, &Nc);CHKERRQ(ierr); 280*2764a2aaSMatthew G. Knepley ierr = PetscFEGetDefaultTabulation(feBd, &prob->basisBd[f], &prob->basisDerBd[f], NULL);CHKERRQ(ierr); 281*2764a2aaSMatthew G. Knepley prob->totDimBd += Nb*Nc; 282*2764a2aaSMatthew G. Knepley } 283*2764a2aaSMatthew G. Knepley } 284*2764a2aaSMatthew G. Knepley work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim)); 285*2764a2aaSMatthew G. Knepley /* Allocate works space */ 286*2764a2aaSMatthew G. Knepley ierr = PetscMalloc5(prob->totComp,&prob->u,prob->totComp,&prob->u_t,prob->totComp*dim,&prob->u_x,dim,&prob->x,work,&prob->refSpaceDer);CHKERRQ(ierr); 287*2764a2aaSMatthew G. Knepley ierr = PetscMalloc6(NqMax*NcMax,&prob->f0,NqMax*NcMax*dim,&prob->f1,NqMax*NcMax*NcMax,&prob->g0,NqMax*NcMax*NcMax*dim,&prob->g1,NqMax*NcMax*NcMax*dim,&prob->g2,NqMax*NcMax*NcMax*dim*dim,&prob->g3);CHKERRQ(ierr); 288*2764a2aaSMatthew G. Knepley if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);} 289*2764a2aaSMatthew G. Knepley prob->setup = PETSC_TRUE; 290*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 291*2764a2aaSMatthew G. Knepley } 292*2764a2aaSMatthew G. Knepley 293*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 294*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroyStructs_Static" 295*2764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob) 296*2764a2aaSMatthew G. Knepley { 297*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 298*2764a2aaSMatthew G. Knepley 299*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 300*2764a2aaSMatthew G. Knepley ierr = PetscFree4(prob->basis,prob->basisDer,prob->basisBd,prob->basisDerBd);CHKERRQ(ierr); 301*2764a2aaSMatthew G. Knepley ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr); 302*2764a2aaSMatthew G. Knepley ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr); 303*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 304*2764a2aaSMatthew G. Knepley } 305*2764a2aaSMatthew G. Knepley 306*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 307*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSEnlarge_Static" 308*2764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew) 309*2764a2aaSMatthew G. Knepley { 310*2764a2aaSMatthew G. Knepley PetscObject *tmpd, *tmpdbd; 311*2764a2aaSMatthew G. Knepley PointFunc *tmpobj, *tmpf, *tmpg; 312*2764a2aaSMatthew G. Knepley BdPointFunc *tmpfbd, *tmpgbd; 313*2764a2aaSMatthew G. Knepley PetscInt Nf = prob->Nf, f; 314*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 315*2764a2aaSMatthew G. Knepley 316*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 317*2764a2aaSMatthew G. Knepley if (Nf >= NfNew) PetscFunctionReturn(0); 318*2764a2aaSMatthew G. Knepley prob->setup = PETSC_FALSE; 319*2764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr); 320*2764a2aaSMatthew G. Knepley ierr = PetscMalloc1(NfNew, &tmpd);CHKERRQ(ierr); 321*2764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpd[f] = prob->disc[f]; 322*2764a2aaSMatthew G. Knepley for (f = Nf; f < NfNew; ++f) {ierr = PetscContainerCreate(PetscObjectComm((PetscObject) prob), (PetscContainer *) &tmpd[f]);CHKERRQ(ierr);} 323*2764a2aaSMatthew G. Knepley ierr = PetscFree(prob->disc);CHKERRQ(ierr); 324*2764a2aaSMatthew G. Knepley prob->Nf = NfNew; 325*2764a2aaSMatthew G. Knepley prob->disc = tmpd; 326*2764a2aaSMatthew G. Knepley ierr = PetscCalloc3(NfNew, &tmpobj, NfNew*2, &tmpf, NfNew*NfNew*4, &tmpg);CHKERRQ(ierr); 327*2764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f]; 328*2764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f]; 329*2764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f]; 330*2764a2aaSMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL; 331*2764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL; 332*2764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL; 333*2764a2aaSMatthew G. Knepley ierr = PetscFree3(prob->obj, prob->f, prob->g);CHKERRQ(ierr); 334*2764a2aaSMatthew G. Knepley prob->obj = tmpobj; 335*2764a2aaSMatthew G. Knepley prob->f = tmpf; 336*2764a2aaSMatthew G. Knepley prob->g = tmpg; 337*2764a2aaSMatthew G. Knepley ierr = PetscMalloc1(NfNew, &tmpdbd);CHKERRQ(ierr); 338*2764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpdbd[f] = prob->discBd[f]; 339*2764a2aaSMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpdbd[f] = NULL; 340*2764a2aaSMatthew G. Knepley ierr = PetscFree(prob->discBd);CHKERRQ(ierr); 341*2764a2aaSMatthew G. Knepley prob->discBd = tmpdbd; 342*2764a2aaSMatthew G. Knepley ierr = PetscCalloc2(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd);CHKERRQ(ierr); 343*2764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f]; 344*2764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f]; 345*2764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL; 346*2764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL; 347*2764a2aaSMatthew G. Knepley ierr = PetscFree2(prob->fBd, prob->gBd);CHKERRQ(ierr); 348*2764a2aaSMatthew G. Knepley prob->fBd = tmpfbd; 349*2764a2aaSMatthew G. Knepley prob->gBd = tmpgbd; 350*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 351*2764a2aaSMatthew G. Knepley } 352*2764a2aaSMatthew G. Knepley 353*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 354*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroy" 355*2764a2aaSMatthew G. Knepley /*@ 356*2764a2aaSMatthew G. Knepley PetscDSDestroy - Destroys a PetscDS object 357*2764a2aaSMatthew G. Knepley 358*2764a2aaSMatthew G. Knepley Collective on PetscDS 359*2764a2aaSMatthew G. Knepley 360*2764a2aaSMatthew G. Knepley Input Parameter: 361*2764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy 362*2764a2aaSMatthew G. Knepley 363*2764a2aaSMatthew G. Knepley Level: developer 364*2764a2aaSMatthew G. Knepley 365*2764a2aaSMatthew G. Knepley .seealso PetscDSView() 366*2764a2aaSMatthew G. Knepley @*/ 367*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob) 368*2764a2aaSMatthew G. Knepley { 369*2764a2aaSMatthew G. Knepley PetscInt f; 370*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 371*2764a2aaSMatthew G. Knepley 372*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 373*2764a2aaSMatthew G. Knepley if (!*prob) PetscFunctionReturn(0); 374*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1); 375*2764a2aaSMatthew G. Knepley 376*2764a2aaSMatthew G. Knepley if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);} 377*2764a2aaSMatthew G. Knepley ((PetscObject) (*prob))->refct = 0; 378*2764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr); 379*2764a2aaSMatthew G. Knepley for (f = 0; f < (*prob)->Nf; ++f) { 380*2764a2aaSMatthew G. Knepley ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr); 381*2764a2aaSMatthew G. Knepley ierr = PetscObjectDereference((*prob)->discBd[f]);CHKERRQ(ierr); 382*2764a2aaSMatthew G. Knepley } 383*2764a2aaSMatthew G. Knepley ierr = PetscFree((*prob)->disc);CHKERRQ(ierr); 384*2764a2aaSMatthew G. Knepley ierr = PetscFree((*prob)->discBd);CHKERRQ(ierr); 385*2764a2aaSMatthew G. Knepley ierr = PetscFree3((*prob)->obj,(*prob)->f,(*prob)->g);CHKERRQ(ierr); 386*2764a2aaSMatthew G. Knepley ierr = PetscFree2((*prob)->fBd,(*prob)->gBd);CHKERRQ(ierr); 387*2764a2aaSMatthew G. Knepley if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);} 388*2764a2aaSMatthew G. Knepley ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr); 389*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 390*2764a2aaSMatthew G. Knepley } 391*2764a2aaSMatthew G. Knepley 392*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 393*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSCreate" 394*2764a2aaSMatthew G. Knepley /*@ 395*2764a2aaSMatthew G. Knepley PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType(). 396*2764a2aaSMatthew G. Knepley 397*2764a2aaSMatthew G. Knepley Collective on MPI_Comm 398*2764a2aaSMatthew G. Knepley 399*2764a2aaSMatthew G. Knepley Input Parameter: 400*2764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object 401*2764a2aaSMatthew G. Knepley 402*2764a2aaSMatthew G. Knepley Output Parameter: 403*2764a2aaSMatthew G. Knepley . prob - The PetscDS object 404*2764a2aaSMatthew G. Knepley 405*2764a2aaSMatthew G. Knepley Level: beginner 406*2764a2aaSMatthew G. Knepley 407*2764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC 408*2764a2aaSMatthew G. Knepley @*/ 409*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob) 410*2764a2aaSMatthew G. Knepley { 411*2764a2aaSMatthew G. Knepley PetscDS p; 412*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 413*2764a2aaSMatthew G. Knepley 414*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 415*2764a2aaSMatthew G. Knepley PetscValidPointer(prob, 2); 416*2764a2aaSMatthew G. Knepley *prob = NULL; 417*2764a2aaSMatthew G. Knepley ierr = PetscDSInitializePackage();CHKERRQ(ierr); 418*2764a2aaSMatthew G. Knepley 419*2764a2aaSMatthew G. Knepley ierr = PetscHeaderCreate(p, _p_PetscDS, struct _PetscDSOps, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr); 420*2764a2aaSMatthew G. Knepley ierr = PetscMemzero(p->ops, sizeof(struct _PetscDSOps));CHKERRQ(ierr); 421*2764a2aaSMatthew G. Knepley 422*2764a2aaSMatthew G. Knepley p->Nf = 0; 423*2764a2aaSMatthew G. Knepley p->setup = PETSC_FALSE; 424*2764a2aaSMatthew G. Knepley 425*2764a2aaSMatthew G. Knepley *prob = p; 426*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 427*2764a2aaSMatthew G. Knepley } 428*2764a2aaSMatthew G. Knepley 429*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 430*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetNumFields" 431*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf) 432*2764a2aaSMatthew G. Knepley { 433*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 434*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 435*2764a2aaSMatthew G. Knepley PetscValidPointer(Nf, 2); 436*2764a2aaSMatthew G. Knepley *Nf = prob->Nf; 437*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 438*2764a2aaSMatthew G. Knepley } 439*2764a2aaSMatthew G. Knepley 440*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 441*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetSpatialDimension" 442*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim) 443*2764a2aaSMatthew G. Knepley { 444*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 445*2764a2aaSMatthew G. Knepley 446*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 447*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 448*2764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 449*2764a2aaSMatthew G. Knepley *dim = 0; 450*2764a2aaSMatthew G. Knepley if (prob->Nf) {ierr = PetscFEGetSpatialDimension((PetscFE) prob->disc[0], dim);CHKERRQ(ierr);} 451*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 452*2764a2aaSMatthew G. Knepley } 453*2764a2aaSMatthew G. Knepley 454*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 455*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalDimension" 456*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim) 457*2764a2aaSMatthew G. Knepley { 458*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 459*2764a2aaSMatthew G. Knepley 460*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 461*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 462*2764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 463*2764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 464*2764a2aaSMatthew G. Knepley *dim = prob->totDim; 465*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 466*2764a2aaSMatthew G. Knepley } 467*2764a2aaSMatthew G. Knepley 468*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 469*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalBdDimension" 470*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalBdDimension(PetscDS prob, PetscInt *dim) 471*2764a2aaSMatthew G. Knepley { 472*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 473*2764a2aaSMatthew G. Knepley 474*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 475*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 476*2764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 477*2764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 478*2764a2aaSMatthew G. Knepley *dim = prob->totDimBd; 479*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 480*2764a2aaSMatthew G. Knepley } 481*2764a2aaSMatthew G. Knepley 482*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 483*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalComponents" 484*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc) 485*2764a2aaSMatthew G. Knepley { 486*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 487*2764a2aaSMatthew G. Knepley 488*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 489*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 490*2764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 491*2764a2aaSMatthew G. Knepley PetscValidPointer(Nc, 2); 492*2764a2aaSMatthew G. Knepley *Nc = prob->totComp; 493*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 494*2764a2aaSMatthew G. Knepley } 495*2764a2aaSMatthew G. Knepley 496*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 497*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetDiscretization" 498*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) 499*2764a2aaSMatthew G. Knepley { 500*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 501*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 502*2764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 503*2764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 504*2764a2aaSMatthew G. Knepley *disc = prob->disc[f]; 505*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 506*2764a2aaSMatthew G. Knepley } 507*2764a2aaSMatthew G. Knepley 508*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 509*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdDiscretization" 510*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) 511*2764a2aaSMatthew G. Knepley { 512*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 513*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 514*2764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 515*2764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 516*2764a2aaSMatthew G. Knepley *disc = prob->discBd[f]; 517*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 518*2764a2aaSMatthew G. Knepley } 519*2764a2aaSMatthew G. Knepley 520*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 521*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetDiscretization" 522*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc) 523*2764a2aaSMatthew G. Knepley { 524*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 525*2764a2aaSMatthew G. Knepley 526*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 527*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 528*2764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 529*2764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 530*2764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 531*2764a2aaSMatthew G. Knepley if (prob->disc[f]) {ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);} 532*2764a2aaSMatthew G. Knepley prob->disc[f] = disc; 533*2764a2aaSMatthew G. Knepley ierr = PetscObjectReference(disc);CHKERRQ(ierr); 534*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 535*2764a2aaSMatthew G. Knepley } 536*2764a2aaSMatthew G. Knepley 537*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 538*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdDiscretization" 539*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdDiscretization(PetscDS prob, PetscInt f, PetscObject disc) 540*2764a2aaSMatthew G. Knepley { 541*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 542*2764a2aaSMatthew G. Knepley 543*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 544*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 545*2764a2aaSMatthew G. Knepley if (disc) PetscValidPointer(disc, 3); 546*2764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 547*2764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 548*2764a2aaSMatthew G. Knepley if (prob->discBd[f]) {ierr = PetscObjectDereference(prob->discBd[f]);CHKERRQ(ierr);} 549*2764a2aaSMatthew G. Knepley prob->discBd[f] = disc; 550*2764a2aaSMatthew G. Knepley ierr = PetscObjectReference(disc);CHKERRQ(ierr); 551*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 552*2764a2aaSMatthew G. Knepley } 553*2764a2aaSMatthew G. Knepley 554*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 555*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSAddDiscretization" 556*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc) 557*2764a2aaSMatthew G. Knepley { 558*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 559*2764a2aaSMatthew G. Knepley 560*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 561*2764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr); 562*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 563*2764a2aaSMatthew G. Knepley } 564*2764a2aaSMatthew G. Knepley 565*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 566*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSAddBdDiscretization" 567*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddBdDiscretization(PetscDS prob, PetscObject disc) 568*2764a2aaSMatthew G. Knepley { 569*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 570*2764a2aaSMatthew G. Knepley 571*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 572*2764a2aaSMatthew G. Knepley ierr = PetscDSSetBdDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr); 573*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 574*2764a2aaSMatthew G. Knepley } 575*2764a2aaSMatthew G. Knepley 576*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 577*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetObjective" 578*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f, 579*2764a2aaSMatthew G. Knepley void (**obj)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar obj[])) 580*2764a2aaSMatthew G. Knepley { 581*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 582*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 583*2764a2aaSMatthew G. Knepley PetscValidPointer(obj, 2); 584*2764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 585*2764a2aaSMatthew G. Knepley *obj = prob->obj[f]; 586*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 587*2764a2aaSMatthew G. Knepley } 588*2764a2aaSMatthew G. Knepley 589*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 590*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetObjective" 591*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f, 592*2764a2aaSMatthew G. Knepley void (*obj)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar obj[])) 593*2764a2aaSMatthew G. Knepley { 594*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 595*2764a2aaSMatthew G. Knepley 596*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 597*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 598*2764a2aaSMatthew G. Knepley PetscValidFunction(obj, 2); 599*2764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 600*2764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 601*2764a2aaSMatthew G. Knepley prob->obj[f] = obj; 602*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 603*2764a2aaSMatthew G. Knepley } 604*2764a2aaSMatthew G. Knepley 605*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 606*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetResidual" 607*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f, 608*2764a2aaSMatthew G. Knepley void (**f0)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar f0[]), 609*2764a2aaSMatthew G. Knepley void (**f1)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar f1[])) 610*2764a2aaSMatthew G. Knepley { 611*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 612*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 613*2764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 614*2764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];} 615*2764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];} 616*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 617*2764a2aaSMatthew G. Knepley } 618*2764a2aaSMatthew G. Knepley 619*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 620*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetResidual" 621*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f, 622*2764a2aaSMatthew G. Knepley void (*f0)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar f0[]), 623*2764a2aaSMatthew G. Knepley void (*f1)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar f1[])) 624*2764a2aaSMatthew G. Knepley { 625*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 626*2764a2aaSMatthew G. Knepley 627*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 628*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 629*2764a2aaSMatthew G. Knepley PetscValidFunction(f0, 3); 630*2764a2aaSMatthew G. Knepley PetscValidFunction(f1, 4); 631*2764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 632*2764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 633*2764a2aaSMatthew G. Knepley prob->f[f*2+0] = f0; 634*2764a2aaSMatthew G. Knepley prob->f[f*2+1] = f1; 635*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 636*2764a2aaSMatthew G. Knepley } 637*2764a2aaSMatthew G. Knepley 638*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 639*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetJacobian" 640*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g, 641*2764a2aaSMatthew G. Knepley void (**g0)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar g0[]), 642*2764a2aaSMatthew G. Knepley void (**g1)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar g1[]), 643*2764a2aaSMatthew G. Knepley void (**g2)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar g2[]), 644*2764a2aaSMatthew G. Knepley void (**g3)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar g3[])) 645*2764a2aaSMatthew G. Knepley { 646*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 647*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 648*2764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 649*2764a2aaSMatthew G. Knepley if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf); 650*2764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];} 651*2764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];} 652*2764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];} 653*2764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];} 654*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 655*2764a2aaSMatthew G. Knepley } 656*2764a2aaSMatthew G. Knepley 657*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 658*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetJacobian" 659*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g, 660*2764a2aaSMatthew G. Knepley void (*g0)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar g0[]), 661*2764a2aaSMatthew G. Knepley void (*g1)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar g1[]), 662*2764a2aaSMatthew G. Knepley void (*g2)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar g2[]), 663*2764a2aaSMatthew G. Knepley void (*g3)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], PetscScalar g3[])) 664*2764a2aaSMatthew G. Knepley { 665*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 666*2764a2aaSMatthew G. Knepley 667*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 668*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 669*2764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 670*2764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 671*2764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 672*2764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 673*2764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 674*2764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 675*2764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 676*2764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+0] = g0; 677*2764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+1] = g1; 678*2764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+2] = g2; 679*2764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+3] = g3; 680*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 681*2764a2aaSMatthew G. Knepley } 682*2764a2aaSMatthew G. Knepley 683*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 684*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdResidual" 685*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f, 686*2764a2aaSMatthew G. Knepley void (**f0)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar f0[]), 687*2764a2aaSMatthew G. Knepley void (**f1)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar f1[])) 688*2764a2aaSMatthew G. Knepley { 689*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 690*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 691*2764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 692*2764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];} 693*2764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];} 694*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 695*2764a2aaSMatthew G. Knepley } 696*2764a2aaSMatthew G. Knepley 697*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 698*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdResidual" 699*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f, 700*2764a2aaSMatthew G. Knepley void (*f0)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar f0[]), 701*2764a2aaSMatthew G. Knepley void (*f1)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar f1[])) 702*2764a2aaSMatthew G. Knepley { 703*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 704*2764a2aaSMatthew G. Knepley 705*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 706*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 707*2764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 708*2764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 709*2764a2aaSMatthew G. Knepley if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;} 710*2764a2aaSMatthew G. Knepley if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;} 711*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 712*2764a2aaSMatthew G. Knepley } 713*2764a2aaSMatthew G. Knepley 714*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 715*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdJacobian" 716*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 717*2764a2aaSMatthew G. Knepley void (**g0)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar g0[]), 718*2764a2aaSMatthew G. Knepley void (**g1)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar g1[]), 719*2764a2aaSMatthew G. Knepley void (**g2)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar g2[]), 720*2764a2aaSMatthew G. Knepley void (**g3)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar g3[])) 721*2764a2aaSMatthew G. Knepley { 722*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 723*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 724*2764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 725*2764a2aaSMatthew G. Knepley if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf); 726*2764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];} 727*2764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];} 728*2764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];} 729*2764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];} 730*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 731*2764a2aaSMatthew G. Knepley } 732*2764a2aaSMatthew G. Knepley 733*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 734*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdJacobian" 735*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 736*2764a2aaSMatthew G. Knepley void (*g0)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar g0[]), 737*2764a2aaSMatthew G. Knepley void (*g1)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar g1[]), 738*2764a2aaSMatthew G. Knepley void (*g2)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar g2[]), 739*2764a2aaSMatthew G. Knepley void (*g3)(const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], const PetscReal x[], const PetscReal n[], PetscScalar g3[])) 740*2764a2aaSMatthew G. Knepley { 741*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 742*2764a2aaSMatthew G. Knepley 743*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 744*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 745*2764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 746*2764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 747*2764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 748*2764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 749*2764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 750*2764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 751*2764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 752*2764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+0] = g0; 753*2764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+1] = g1; 754*2764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+2] = g2; 755*2764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+3] = g3; 756*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 757*2764a2aaSMatthew G. Knepley } 758*2764a2aaSMatthew G. Knepley 759*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 760*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetFieldOffset" 761*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) 762*2764a2aaSMatthew G. Knepley { 763*2764a2aaSMatthew G. Knepley PetscInt g; 764*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 765*2764a2aaSMatthew G. Knepley 766*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 767*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 768*2764a2aaSMatthew G. Knepley PetscValidPointer(off, 3); 769*2764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 770*2764a2aaSMatthew G. Knepley *off = 0; 771*2764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 772*2764a2aaSMatthew G. Knepley PetscFE fe = (PetscFE) prob->disc[g]; 773*2764a2aaSMatthew G. Knepley PetscInt Nb, Nc; 774*2764a2aaSMatthew G. Knepley 775*2764a2aaSMatthew G. Knepley ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr); 776*2764a2aaSMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 777*2764a2aaSMatthew G. Knepley *off += Nb*Nc; 778*2764a2aaSMatthew G. Knepley } 779*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 780*2764a2aaSMatthew G. Knepley } 781*2764a2aaSMatthew G. Knepley 782*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 783*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdFieldOffset" 784*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) 785*2764a2aaSMatthew G. Knepley { 786*2764a2aaSMatthew G. Knepley PetscInt g; 787*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 788*2764a2aaSMatthew G. Knepley 789*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 790*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 791*2764a2aaSMatthew G. Knepley PetscValidPointer(off, 3); 792*2764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 793*2764a2aaSMatthew G. Knepley *off = 0; 794*2764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 795*2764a2aaSMatthew G. Knepley PetscFE fe = (PetscFE) prob->discBd[g]; 796*2764a2aaSMatthew G. Knepley PetscInt Nb, Nc; 797*2764a2aaSMatthew G. Knepley 798*2764a2aaSMatthew G. Knepley ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr); 799*2764a2aaSMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 800*2764a2aaSMatthew G. Knepley *off += Nb*Nc; 801*2764a2aaSMatthew G. Knepley } 802*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 803*2764a2aaSMatthew G. Knepley } 804*2764a2aaSMatthew G. Knepley 805*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 806*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTabulation" 807*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer) 808*2764a2aaSMatthew G. Knepley { 809*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 810*2764a2aaSMatthew G. Knepley 811*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 812*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 813*2764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 814*2764a2aaSMatthew G. Knepley if (basis) {PetscValidPointer(basis, 2); *basis = prob->basis;} 815*2764a2aaSMatthew G. Knepley if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;} 816*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 817*2764a2aaSMatthew G. Knepley } 818*2764a2aaSMatthew G. Knepley 819*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 820*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdTabulation" 821*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer) 822*2764a2aaSMatthew G. Knepley { 823*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 824*2764a2aaSMatthew G. Knepley 825*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 826*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 827*2764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 828*2764a2aaSMatthew G. Knepley if (basis) {PetscValidPointer(basis, 2); *basis = prob->basisBd;} 829*2764a2aaSMatthew G. Knepley if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerBd;} 830*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 831*2764a2aaSMatthew G. Knepley } 832*2764a2aaSMatthew G. Knepley 833*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 834*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetEvaluationArrays" 835*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x) 836*2764a2aaSMatthew G. Knepley { 837*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 838*2764a2aaSMatthew G. Knepley 839*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 840*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 841*2764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 842*2764a2aaSMatthew G. Knepley if (u) {PetscValidPointer(u, 2); *u = prob->u;} 843*2764a2aaSMatthew G. Knepley if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;} 844*2764a2aaSMatthew G. Knepley if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;} 845*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 846*2764a2aaSMatthew G. Knepley } 847*2764a2aaSMatthew G. Knepley 848*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 849*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetWeakFormArrays" 850*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3) 851*2764a2aaSMatthew G. Knepley { 852*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 853*2764a2aaSMatthew G. Knepley 854*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 855*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 856*2764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 857*2764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;} 858*2764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;} 859*2764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;} 860*2764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;} 861*2764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;} 862*2764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;} 863*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 864*2764a2aaSMatthew G. Knepley } 865*2764a2aaSMatthew G. Knepley 866*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 867*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetRefCoordArrays" 868*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer) 869*2764a2aaSMatthew G. Knepley { 870*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 871*2764a2aaSMatthew G. Knepley 872*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 873*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 874*2764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 875*2764a2aaSMatthew G. Knepley if (x) {PetscValidPointer(x, 2); *x = prob->x;} 876*2764a2aaSMatthew G. Knepley if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;} 877*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 878*2764a2aaSMatthew G. Knepley } 879*2764a2aaSMatthew G. Knepley 880*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 881*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroy_Basic" 882*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy_Basic(PetscDS prob) 883*2764a2aaSMatthew G. Knepley { 884*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 885*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 886*2764a2aaSMatthew G. Knepley } 887*2764a2aaSMatthew G. Knepley 888*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 889*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSInitialize_Basic" 890*2764a2aaSMatthew G. Knepley PetscErrorCode PetscDSInitialize_Basic(PetscDS prob) 891*2764a2aaSMatthew G. Knepley { 892*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 893*2764a2aaSMatthew G. Knepley prob->ops->setfromoptions = NULL; 894*2764a2aaSMatthew G. Knepley prob->ops->setup = NULL; 895*2764a2aaSMatthew G. Knepley prob->ops->view = NULL; 896*2764a2aaSMatthew G. Knepley prob->ops->destroy = PetscDSDestroy_Basic; 897*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 898*2764a2aaSMatthew G. Knepley } 899*2764a2aaSMatthew G. Knepley 900*2764a2aaSMatthew G. Knepley /*MC 901*2764a2aaSMatthew G. Knepley PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions 902*2764a2aaSMatthew G. Knepley 903*2764a2aaSMatthew G. Knepley Level: intermediate 904*2764a2aaSMatthew G. Knepley 905*2764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType() 906*2764a2aaSMatthew G. Knepley M*/ 907*2764a2aaSMatthew G. Knepley 908*2764a2aaSMatthew G. Knepley #undef __FUNCT__ 909*2764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSCreate_Basic" 910*2764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob) 911*2764a2aaSMatthew G. Knepley { 912*2764a2aaSMatthew G. Knepley PetscDS_Basic *b; 913*2764a2aaSMatthew G. Knepley PetscErrorCode ierr; 914*2764a2aaSMatthew G. Knepley 915*2764a2aaSMatthew G. Knepley PetscFunctionBegin; 916*2764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCSPACE_CLASSID, 1); 917*2764a2aaSMatthew G. Knepley ierr = PetscNewLog(prob, &b);CHKERRQ(ierr); 918*2764a2aaSMatthew G. Knepley prob->data = b; 919*2764a2aaSMatthew G. Knepley 920*2764a2aaSMatthew G. Knepley ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr); 921*2764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 922*2764a2aaSMatthew G. Knepley } 923