Actual source code: tscreate.c

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

 5:  #include src/ts/tsimpl.h

  7: static int TSPublish_Petsc(PetscObject obj)
  8: {
  9: #if defined(PETSC_HAVE_AMS)
 10:   TS   v = (TS) obj;
 11:   int  ierr;
 12: #endif  


 16: #if defined(PETSC_HAVE_AMS)
 17:   /* if it is already published then return */
 18:   if (v->amem >=0) return(0);

 20:   PetscObjectPublishBaseBegin(obj);
 21:   AMS_Memory_add_field((AMS_Memory)v->amem,"Step",&v->steps,1,AMS_INT,AMS_READ,
 22:                                 AMS_COMMON,AMS_REDUCT_UNDEF);
 23:   AMS_Memory_add_field((AMS_Memory)v->amem,"Time",&v->ptime,1,AMS_DOUBLE,AMS_READ,
 24:                                 AMS_COMMON,AMS_REDUCT_UNDEF);
 25:   AMS_Memory_add_field((AMS_Memory)v->amem,"CurrentTimeStep",&v->time_step,1,
 26:                                AMS_DOUBLE,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);
 27:   PetscObjectPublishBaseEnd(obj);
 28: #endif
 29:   return(0);
 30: }

 32: /*@C
 33:   TSCreate - This function creates an empty timestepper. The problem type can then be set with TSSetProblemType() and the 
 34:        type of solver can then be set with TSSetType().

 36:   Collective on MPI_Comm

 38:   Input Parameter:
 39: . comm - The communicator

 41:   Output Parameter:
 42: . ts   - The TS

 44:   Level: beginner

 46: .keywords: TS, create
 47: .seealso: TSSetType(), TSSetUp(), TSDestroy(), MeshCreate(), TSSetProblemType()
 48: @*/
 49: int TSCreate(MPI_Comm comm, TS *ts) {
 50:   TS  t;

 55:   *ts = PETSC_NULL;
 56: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
 57:   TSInitializePackage(PETSC_NULL);
 58: #endif

 60:   PetscHeaderCreate(t, _p_TS, struct _TSOps, TS_COOKIE, -1, "TS", comm, TSDestroy, TSView);
 61:   PetscLogObjectCreate(t);
 62:   PetscLogObjectMemory(t, sizeof(struct _p_TS));
 63:   PetscMemzero(t->ops, sizeof(struct _TSOps));
 64:   t->bops->publish    = TSPublish_Petsc;
 65:   t->type_name        = PETSC_NULL;
 66:   t->serialize_name   = PETSC_NULL;

 68:   t->ops->applymatrixbc = TSDefaultSystemMatrixBC;
 69:   t->ops->applyrhsbc    = TSDefaultRhsBC;
 70:   t->ops->applysolbc    = TSDefaultSolutionBC;
 71:   t->ops->prestep       = TSDefaultPreStep;
 72:   t->ops->update        = TSDefaultUpdate;
 73:   t->ops->poststep      = TSDefaultPostStep;

 75:   /* General TS description */
 76:   t->problem_type       = TS_LINEAR;
 77:   t->vec_sol            = PETSC_NULL;
 78:   t->vec_sol_always     = PETSC_NULL;
 79:   t->numbermonitors     = 0;
 80:   t->isGTS              = PETSC_FALSE;
 81:   t->isExplicit         = PETSC_NULL;
 82:   t->Iindex             = PETSC_NULL;
 83:   t->sles               = PETSC_NULL;
 84:   t->A                  = PETSC_NULL;
 85:   t->B                  = PETSC_NULL;
 86:   t->snes               = PETSC_NULL;
 87:   t->funP               = PETSC_NULL;
 88:   t->jacP               = PETSC_NULL;
 89:   t->setupcalled        = 0;
 90:   t->data               = PETSC_NULL;
 91:   t->user               = PETSC_NULL;
 92:   t->max_steps          = 5000;
 93:   t->max_time           = 5.0;
 94:   t->time_step          = .1;
 95:   t->time_step_old      = t->time_step;
 96:   t->initial_time_step  = t->time_step;
 97:   t->steps              = 0;
 98:   t->ptime              = 0.0;
 99:   t->linear_its         = 0;
100:   t->nonlinear_its      = 0;
101:   t->work               = PETSC_NULL;
102:   t->nwork              = 0;

104:   *ts = t;
105:   return(0);
106: }

108: /*@ 
109:   TSSerialize - This function stores or recreates a timestepper using a viewer for a binary file.

111:   Collective on MPI_Comm

113:   Input Parameters:
114: + comm   - The communicator for the ts object
115: . viewer - The viewer context
116: - store  - This flag is PETSC_TRUE is data is being written, otherwise it will be read

118:   Output Parameter:
119: . ts     - The ts

121:   Level: beginner

123: .keywords: TS, serialize
124: .seealso: PartitionSerialize(), TSSerialize()
125: @*/
126: int TSSerialize(MPI_Comm comm, TS *ts, PetscViewer viewer, PetscTruth store)
127: {
128:   int      (*serialize)(MPI_Comm, TS *, PetscViewer, PetscTruth);
129:   int        fd, len;
130:   char      *name;
131:   PetscTruth match;
132:   int        ierr;


138:   PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
139:   if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
140:   PetscViewerBinaryGetDescriptor(viewer, &fd);

142:   if (!TSSerializeRegisterAllCalled) {
143:     TSSerializeRegisterAll(PETSC_NULL);
144:   }
145:   if (!TSSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");

147:   if (store) {
149:     PetscStrlen((*ts)->class_name, &len);
150:     PetscBinaryWrite(fd, &len,                   1,   PETSC_INT,  0);
151:     PetscBinaryWrite(fd,  (*ts)->class_name,     len, PETSC_CHAR, 0);
152:     PetscStrlen((*ts)->serialize_name, &len);
153:     PetscBinaryWrite(fd, &len,                   1,   PETSC_INT,  0);
154:     PetscBinaryWrite(fd,  (*ts)->serialize_name, len, PETSC_CHAR, 0);
155:     PetscFListFind(comm, TSSerializeList, (*ts)->serialize_name, (void (**)(void)) &serialize);
156:     if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
157:     (*serialize)(comm, ts, viewer, store);
158:   } else {
159:     PetscBinaryRead(fd, &len,    1,   PETSC_INT);
160:     PetscMalloc((len+1) * sizeof(char), &name);
161:     name[len] = 0;
162:     PetscBinaryRead(fd,  name,   len, PETSC_CHAR);
163:     PetscStrcmp(name, "TS", &match);
164:     PetscFree(name);
165:     if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-ts object");
166:     /* Dispatch to the correct routine */
167:     PetscBinaryRead(fd, &len,    1,   PETSC_INT);
168:     PetscMalloc((len+1) * sizeof(char), &name);
169:     name[len] = 0;
170:     PetscBinaryRead(fd,  name,   len, PETSC_CHAR);
171:     PetscFListFind(comm, TSSerializeList, name, (void (**)(void)) &serialize);
172:     if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
173:     (*serialize)(comm, ts, viewer, store);
174:     PetscStrfree((*ts)->serialize_name);
175:     (*ts)->serialize_name = name;
176:   }

178:   return(0);
179: }