Actual source code: disccreate.c

  1: #ifdef PETSC_RCS_HEADER
  2: static char vcid[] = "$Id: disccreate.c,v 1.7 2000/01/10 03:54:25 knepley Exp $";
  3: #endif

 5:  #include src/grid/discretization/discimpl.h

  7: #undef  __FUNCT__
  9: /*@ 
 10:   DiscretizationCreate - This function creates an empty discretization. The type can then be set with DiscretizationSetType().

 12:   Collective on MPI_Comm

 14:   Input Parameter:
 15: . comm - The communicator

 17:   Output Parameter:
 18: . disc - The disc

 20:   Level: beginner

 22: .keywords: Discretization, create
 23: .seealso: DiscretizationSetType(), DiscretizationSetUp(), DiscretizationDestroy(), GridCreate()
 24: @*/
 25: int DiscretizationCreate(MPI_Comm comm, Discretization *disc) {
 26:   Discretization d;
 27:   int            ierr;

 31:   *disc = PETSC_NULL;
 32: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
 33:   GridInitializePackage(PETSC_NULL);
 34: #endif

 36:   PetscHeaderCreate(d, _Discretization, struct _DiscretizationOps, DISCRETIZATION_COOKIE, -1, "Discretization", comm, DiscretizationDestroy, DiscretizationView);
 37:   PetscLogObjectCreate(d);
 38:   PetscLogObjectMemory(d, sizeof(struct _Discretization));
 39:   PetscMemzero(d->ops, sizeof(struct _DiscretizationOps));
 40:   d->bops->publish    = PETSC_NULL /* DiscretizationPublish_Petsc */;
 41:   d->type_name        = PETSC_NULL;
 42:   d->serialize_name   = PETSC_NULL;

 44:   /* General discretization description */
 45:   d->data  = PETSC_NULL;
 46:   d->dim   = -1;
 47:   d->funcs = 0;
 48:   d->comp  = 0;
 49:   d->size  = 0;
 50:   d->field = -1;

 52:   /* Boundary integration */
 53:   d->bdDisc = PETSC_NULL;

 55:   /* Quadrature */
 56:   d->numQuadPoints     = 0;
 57:   d->quadPoints        = PETSC_NULL;
 58:   d->quadWeights       = PETSC_NULL;
 59:   d->quadShapeFuncs    = PETSC_NULL;
 60:   d->quadShapeFuncDers = PETSC_NULL;

 62:   /* Operators */
 63:   d->numOps = 0;
 64:   d->maxOps = 1;
 65:   PetscMalloc(d->maxOps * sizeof(Operator), &d->operators);

 67:   /* Storage */
 68:   d->funcVal  = PETSC_NULL;
 69:   d->fieldVal = PETSC_NULL;

 71:   *disc = d;
 72:   return(0);
 73: }

 75: #undef  __FUNCT__
 77: /*@ 
 78:   DiscretizationSerialize - This function stores or recreates a discretization using a viewer for a binary file.

 80:   Collective on MPI_Comm

 82:   Input Parameters:
 83: + comm   - The communicator for the disc object
 84: . viewer - The viewer context
 85: - store  - This flag is PETSC_TRUE is data is being written, otherwise it will be read

 87:   Output Parameter:
 88: . disc   - The discretization

 90:   Level: beginner

 92: .keywords: Discretization, serialize
 93: .seealso: PartitionSerialize(), DiscretizationSerialize()
 94: @*/
 95: int DiscretizationSerialize(MPI_Comm comm, Discretization *disc, PetscViewer viewer, PetscTruth store)
 96: {
 97:   int      (*serialize)(MPI_Comm, Discretization *, PetscViewer, PetscTruth);
 98:   int        fd, len;
 99:   char      *name;
100:   PetscTruth match;
101:   int        ierr;


107:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
108:   if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
109:   PetscViewerBinaryGetDescriptor(viewer, &fd);

111:   if (!DiscretizationSerializeRegisterAllCalled) {
112:     DiscretizationSerializeRegisterAll(PETSC_NULL);
113:   }
114:   if (!DiscretizationSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");

116:   if (store) {
118:     PetscStrlen((*disc)->class_name, &len);
119:     PetscBinaryWrite(fd, &len,                     1,   PETSC_INT,  0);
120:     PetscBinaryWrite(fd,  (*disc)->class_name,     len, PETSC_CHAR, 0);
121:     PetscStrlen((*disc)->serialize_name, &len);
122:     PetscBinaryWrite(fd, &len,                     1,   PETSC_INT,  0);
123:     PetscBinaryWrite(fd,  (*disc)->serialize_name, len, PETSC_CHAR, 0);
124:     PetscFListFind(comm, DiscretizationSerializeList, (*disc)->serialize_name, (void (**)(void)) &serialize);
125:     if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
126:     (*serialize)(comm, disc, viewer, store);
127:   } else {
128:     PetscBinaryRead(fd, &len,    1,   PETSC_INT);
129:     PetscMalloc((len+1) * sizeof(char), &name);
130:     name[len] = 0;
131:     PetscBinaryRead(fd,  name,   len, PETSC_CHAR);
132:     PetscStrcmp(name, "Discretization", &match);
133:     PetscFree(name);
134:     if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-disc object");
135:     /* Dispatch to the correct routine */
136:     PetscBinaryRead(fd, &len,    1,   PETSC_INT);
137:     PetscMalloc((len+1) * sizeof(char), &name);
138:     name[len] = 0;
139:     PetscBinaryRead(fd,  name,   len, PETSC_CHAR);
140:     PetscFListFind(comm, DiscretizationSerializeList, name, (void (**)(void)) &serialize);
141:     if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
142:     (*serialize)(comm, disc, viewer, store);
143:     PetscStrfree((*disc)->serialize_name);
144:     (*disc)->serialize_name = name;
145:   }

147:   return(0);
148: }